:root {
  --bg: #120f0d;
  --panel: #1d1916;
  --panel-2: #26211d;
  --line: #3a332d;
  --text: #f6efe7;
  --muted: #b5a99c;
  --accent: #f2a541;
  --accent-ink: #1b1209;
  --danger: #e2574c;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Noto Sans SC", sans-serif; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; }

/* Home and join */
.card-view { max-width: 460px; margin: 0 auto; padding: 32px 20px 40px; display: flex; flex-direction: column; gap: 14px; }
.brand { font-weight: 800; letter-spacing: .02em; color: var(--accent); }
h1 { font-size: 1.7rem; line-height: 1.2; margin: 4px 0 0; }
.lede { color: var(--muted); margin: 0 0 6px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
input, select { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; color: var(--text); }
.primary, .ghost { border-radius: 999px; padding: 13px 18px; font-weight: 700; text-align: center; text-decoration: none; display: block; }
.primary { background: var(--accent); color: var(--accent-ink); }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.fine { color: var(--muted); font-size: .8rem; margin: 4px 0 0; }

/* Room */
#room { height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; gap: 10px; }
.title { display: flex; align-items: center; gap: 8px; font-weight: 700; min-width: 0; }
.title span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { background: var(--panel-2); border-radius: 999px; padding: 1px 9px; font-size: .8rem; color: var(--muted); }
.chip { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 7px 14px; font-weight: 700; }

#stage { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; overflow: hidden; flex: none; }
#film-video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
#subtitle { position: absolute; left: 6%; right: 6%; bottom: 7%; text-align: center; font-size: clamp(14px, 3.6vw, 26px);
  font-weight: 600; text-shadow: 0 1px 3px #000, 0 0 8px #000; pointer-events: none; white-space: pre-line; }
#subtitle:empty { display: none; }
.stage-note { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: rgba(0,0,0,.45); font-weight: 600; }
.unmute { position: absolute; top: 10px; right: 10px; background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 8px 14px; font-weight: 700; }
#reactions-layer { position: absolute; inset: 0; pointer-events: none; }
.float { position: absolute; bottom: 8%; font-size: 34px; animation: rise 2.6s ease-out forwards; }
@keyframes rise { from { transform: translateY(0) scale(.8); opacity: 1; } to { transform: translateY(-220px) scale(1.25); opacity: 0; } }

#transport { display: flex; align-items: center; gap: 10px; padding: 8px 14px; }
#transport .host-only { display: flex; gap: 6px; }
.icon { background: var(--panel-2); border-radius: 999px; min-width: 42px; height: 38px; padding: 0 10px; font-weight: 700; }
.icon.big { background: var(--accent); color: var(--accent-ink); min-width: 52px; }
#scrub { flex: 1; accent-color: var(--accent); padding: 0; border: 0; background: none; min-width: 60px; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; white-space: nowrap; }

/* Below the film: one row of faces, then the chat filling the rest. */
#below { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#tiles { flex: none; display: flex; gap: 8px; padding: 6px 14px; overflow-x: auto; scrollbar-width: none; }
.tile { position: relative; flex: 1 0 84px; max-width: 150px; height: 104px; background: var(--panel); border-radius: var(--radius); overflow: hidden; border: 2px solid transparent; }
.tile.speaking { border-color: var(--accent); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .initial { position: absolute; inset: 0; display: grid; place-items: center; font-size: 2rem; font-weight: 800; color: var(--muted); }
.tile.has-video .initial { display: none; }
.tile .name { position: absolute; left: 6px; bottom: 6px; right: 6px; font-size: .75rem; background: rgba(0,0,0,.55); border-radius: 8px; padding: 2px 7px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .badge { position: absolute; top: 6px; left: 6px; font-size: .65rem; background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 1px 6px; font-weight: 800; }

.bottombar { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); justify-content: center; }
.tool { background: var(--panel-2); border-radius: 10px; padding: 8px 11px; font-size: .85rem; font-weight: 700; }
.tool[aria-pressed="false"] { background: var(--danger); }
.tool.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.emoji-row { display: flex; gap: 2px; }
.react { background: transparent; font-size: 22px; padding: 2px 4px; }

#feed { flex: 1; min-height: 132px; display: flex; flex-direction: column; margin: 4px 14px 10px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
#chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
  font-size: 15px; line-height: 1.4; overscroll-behavior: contain; }
#chat-log > :first-child { margin-top: auto; } /* newest messages sit next to the input, like any chat */
#chat-log:empty::before { content: attr(data-empty); margin: auto; color: var(--muted); font-size: 14px; text-align: center; }
.m { animation: msg-in .25s ease-out; overflow-wrap: anywhere; }
.m b { color: var(--accent); margin-right: 4px; }
.m.note { align-self: center; color: var(--muted); font-size: 13px; text-align: center; }
.m.meal { align-self: center; background: rgba(242,165,65,.16); color: var(--accent); border-radius: 999px; padding: 4px 12px; font-size: 14px; font-weight: 700; text-align: center; }
.m.cohost { display: flex; gap: 8px; align-items: flex-start; background: var(--panel-2); border-left: 3px solid var(--accent); border-radius: 10px; padding: 8px 10px; }
.cohost-avatar { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.cohost-name { font-size: 12px; font-weight: 800; color: var(--accent); }
.cohost-tag { font-weight: 600; color: var(--muted); }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
#chat-form { display: flex; gap: 8px; padding: 8px; border-top: 1px solid var(--line); }
#chat-form input { flex: 1; min-width: 0; padding: 10px 12px; }
#chat-form .primary { padding: 10px 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#stats { position: fixed; top: 54px; right: 8px; background: rgba(18,15,13,.92); border: 1px solid var(--line); border-radius: 10px; z-index: 6; }
#stats pre { margin: 0; padding: 10px 12px; font-size: 11.5px; line-height: 1.5; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 10; padding: 16px; }
.sheet { width: min(420px, 100%); max-height: 92dvh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.sheet h2 { margin: 0 0 4px; font-size: 1.25rem; }

/* Language switch */
.row-between { display: flex; align-items: center; justify-content: space-between; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.lang-toggle { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; font-size: .8rem; font-weight: 700; }

/* Invite QR */
.qr-block { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px 0; }
.qr { width: 200px; height: 200px; background: #fff; border-radius: 12px; padding: 8px; }
.qr svg { width: 100%; height: 100%; display: block; }
.fine.link { word-break: break-all; text-align: center; }

/* Shared meal */
.meal-card { display: flex; gap: 12px; align-items: center; background: var(--panel-2); border-radius: 12px; padding: 12px; }
.meal-emoji { font-size: 30px; white-space: nowrap; }
.meal-name { font-weight: 800; }
.meal-price { color: var(--accent); font-weight: 700; margin-top: 2px; }
#meal-homes { display: flex; flex-direction: column; gap: 6px; }
#meal-homes label { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: .95rem; }
#meal-homes input { width: 18px; height: 18px; accent-color: var(--accent); padding: 0; }
.meal-total { display: flex; justify-content: space-between; color: var(--muted); }
.meal-total b { color: var(--text); }
.opt { position: relative; width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: left;
  background: var(--panel-2); border-radius: 12px; padding: 12px 14px; overflow: hidden; border: 2px solid transparent; }
.opt.mine { border-color: var(--accent); }
.opt .bar { position: absolute; inset: 0 auto 0 0; background: rgba(242,165,65,.22); width: 0; transition: width .4s; }
.opt span { position: relative; }
.opt .count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Landscape phones, tablets and laptops: film on the left, faces and chat on the right. */
@media (orientation: landscape) and (min-width: 640px) {
  #room { display: grid; grid-template-columns: minmax(0, 1fr) clamp(260px, 30vw, 400px);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    grid-template-areas: "top top" "stage below" "transport below" ". below" "bar bar"; }
  .topbar { grid-area: top; }
  #stage { grid-area: stage; max-height: calc(100dvh - 170px); }
  #transport { grid-area: transport; }
  #below { grid-area: below; padding-top: 2px; }
  #feed { margin-bottom: 8px; }
  .bottombar { grid-area: bar; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .topbar { padding: 4px 12px; }
  .tile { height: 72px; flex-basis: 64px; }
  #feed { min-height: 96px; }
}

/* Board view */
.text-link { color: var(--accent); text-decoration: none; font-weight: 700; font-size: .85rem; }
.board-page { overflow-y: auto; }
.board { max-width: 1040px; margin: 0 auto; padding: 28px 20px 48px; display: flex; flex-direction: column; gap: 18px; }
.board h1 { margin: 6px 0 0; }
.board h2 { font-size: 1.1rem; margin: 10px 0 10px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: .82rem; }
.stat-value { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 4px; }
.stat-sub { color: var(--muted); font-size: .8rem; }
.vote-block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.vote-film { font-weight: 800; }
.vbar { position: relative; display: flex; justify-content: space-between; gap: 12px; background: var(--panel-2); border-radius: 10px; padding: 10px 12px; overflow: hidden; }
.vbar-fill { position: absolute; inset: 0 auto 0 0; background: rgba(242,165,65,.18); }
.vbar.lead .vbar-fill { background: rgba(242,165,65,.36); }
.vbar-label, .vbar-n { position: relative; }
.vbar-n { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.board-table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.board-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.board-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
.lang-split { display: flex; gap: 8px; flex-wrap: wrap; }
.lang-chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; }
