:root {
  --bg: #f4ede1; --card: #fffaf2; --text: #2a211b; --muted: #7d6e62; --line: #e4d6c2;
  --accent: #b23a2a; --accent-soft: #f6dfd6; --ink-red: #b8261b; --ink-black: #1d1b1a;
  --wood: #ebc98e; --wood-edge: #c99a55; --wood-line: #6b4423;
  --ok: #1f8a5b; --warn: #c27c0e;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171310; --card: #221c17; --text: #f1e7da; --muted: #a8998b; --line: #3a3028;
    --accent: #e0644f; --accent-soft: #3d2620;
    --wood: #d6b273; --wood-edge: #a77c3d;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
[hidden] { display: none !important; }
h1 { font-size: 26px; margin: 8px 0 6px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; margin: 6px 0 0; }

button, input, select {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px;
}
button { padding: 8px 12px; cursor: pointer; min-height: 38px; white-space: nowrap; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.on { background: var(--accent-soft); border-color: var(--accent); }
button.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
button.big { width: 100%; padding: 12px; font-size: 16px; }
input { padding: 9px 11px; min-width: 0; }
input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }

.logo {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto;
  background: radial-gradient(circle at 40% 35%, #fff8e8, #e8cf9e); color: var(--ink-red);
  border: 3px solid var(--ink-red); font: 32px "Kaiti SC", "STKaiti", "KaiTi", serif;
}
.logo.sm { width: 28px; height: 28px; font-size: 16px; border-width: 2px; margin: 0; display: inline-grid; }

/* ---------- Sảnh ---------- */
.lobby { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.lobby-card { width: 100%; max-width: 400px; text-align: center; padding: 28px 22px; }
.lobby-card .field { display: block; text-align: left; font-weight: 600; margin: 18px 0 12px; }
.lobby-card .field input { display: block; width: 100%; margin-top: 6px; font-weight: 400; }
.or { margin: 18px 0 12px; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 10px; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* ---------- Trận ---------- */
.top {
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--card);
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.roominfo { display: flex; align-items: center; gap: 8px; }
.roominfo b { letter-spacing: .12em; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); }
.conn.ok { background: var(--ok); }
.settings { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 13px; color: var(--muted); }
.settings label { display: flex; align-items: center; gap: 5px; cursor: pointer; }

.layout {
  display: grid; grid-template-columns: minmax(0, 580px) minmax(280px, 380px);
  gap: 16px; justify-content: center; padding: 16px; align-items: start;
}
.board-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 10px 16px; }
}

.board-wrap {
  position: relative; background: var(--wood); border-radius: 12px;
  border: 4px solid var(--wood-edge); box-shadow: 0 6px 20px rgba(60, 35, 10, .18);
}
#board { display: block; width: 100%; height: auto; touch-action: manipulation; user-select: none; }
.grid-line { stroke: var(--wood-line); stroke-width: 1.4; fill: none; }
.grid-border { stroke: var(--wood-line); stroke-width: 3; fill: none; }
.river { fill: var(--wood-line); opacity: .7; font: 30px "Kaiti SC", "STKaiti", "KaiTi", serif; }

.piece { cursor: pointer; transition: transform .28s cubic-bezier(.3, .7, .3, 1); }
.piece .disc { fill: url(#pieceFill); stroke: #8a6a3e; stroke-width: 2; filter: url(#shadow); }
.piece .ring { fill: none; stroke-width: 1.6; }
.piece text { font: 600 31px "Kaiti SC", "STKaiti", "KaiTi", "Songti SC", serif; text-anchor: middle; dominant-baseline: central; }
.piece.r .ring, .piece.r text { stroke: var(--ink-red); fill: var(--ink-red); }
.piece.r .ring { fill: none; }
.piece.b .ring, .piece.b text { stroke: var(--ink-black); fill: var(--ink-black); }
.piece.b .ring { fill: none; }
.piece text { stroke: none; }

.mark-last { fill: none; stroke: #2f6fd6; stroke-width: 2.5; stroke-dasharray: 6 4; }
.mark-sel { fill: none; stroke: #2f6fd6; stroke-width: 3.5; }
.mark-dot { fill: #1f8a5b; opacity: .8; }
.mark-cap { fill: none; stroke: #1f8a5b; stroke-width: 3.5; }
.mark-check { fill: rgba(220, 30, 20, .35); stroke: #e0281c; stroke-width: 3; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.floaters { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: 8px; }
.floater {
  position: absolute; bottom: 8%; padding: 6px 12px; border-radius: 18px; white-space: nowrap;
  background: rgba(255, 255, 255, .95); color: #2a211b; box-shadow: 0 3px 12px rgba(0, 0, 0, .2);
  font-weight: 600; animation: rise 2.8s ease-out forwards; transform: translateX(-50%);
}
.floater small { display: block; font-weight: 400; font-size: 11px; color: #7d6e62; }
@keyframes rise {
  0% { opacity: 0; translate: 0 20px; }
  12% { opacity: 1; translate: 0 0; }
  80% { opacity: 1; }
  100% { opacity: 0; translate: 0 -260px; }
}
.flash {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font: 800 clamp(34px, 9vw, 64px) sans-serif; color: #e0281c; opacity: 0;
  text-shadow: 0 0 6px #fff, 0 0 18px #fff;
}
.flash.go { animation: flash 1.5s ease-out; }
@keyframes flash { 0% { opacity: 0; scale: .6; } 15% { opacity: 1; scale: 1.08; } 70% { opacity: 1; scale: 1; } 100% { opacity: 0; } }

.pbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-height: 56px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.pbar.turn { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.chip {
  width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 40% 35%, #fff8e8, #e8cf9e); border: 2px solid;
  font: 20px "Kaiti SC", "STKaiti", "KaiTi", serif;
}
.chip.r { color: var(--ink-red); border-color: var(--ink-red); }
.chip.b { color: var(--ink-black); border-color: var(--ink-black); }
.who { flex: 1; min-width: 0; }
.who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { color: var(--muted); }
.turnflag { font-size: 12px; font-weight: 700; color: #fff; background: var(--accent); border-radius: 8px; padding: 3px 8px; }

.score:empty { display: none; }
.score {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  font-weight: 600; color: var(--muted); font-size: 14px;
}
.score b { font: 800 22px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); }
.score .r { color: var(--ink-red); }
.who small .away { color: #e0281c; font-weight: 600; }
.banner:empty { display: none; }
.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px;
  padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft); text-align: center; font-weight: 600;
}
.actions, .reacts { display: flex; flex-wrap: wrap; gap: 6px; }
.actions:empty { display: none; }
.actions label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-left: auto; }
.reacts button { padding: 6px 10px; font-size: 13px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; border-radius: 0; }
.seg button + button { border-left: 1px solid var(--line); }
.people { display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.team-h { font-size: 12px; font-weight: 700; color: var(--muted); margin-top: 4px; }
.team-h.r { color: var(--ink-red); }
.people .pp { display: flex; align-items: center; gap: 6px; }
.people .pp.off { opacity: .45; }
.tag { font-size: 11px; border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; color: var(--muted); }

.chatlog {
  height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
  font-size: 14px; margin-bottom: 8px; padding-right: 4px;
}
.chatlog .sys { color: var(--muted); font-style: italic; font-size: 13px; }
.chatlog .n { font-weight: 700; }
.chatlog .n.r { color: var(--ink-red); }
@media (prefers-color-scheme: dark) {
  .chatlog .n.r, .team-h.r { color: #ff8a78; }
}
.talk { touch-action: none; user-select: none; -webkit-user-select: none; }
.talk.rec, .rec { background: #e0281c !important; color: #fff; border-color: #e0281c; }

.vrow { display: flex; align-items: center; gap: 6px; padding: 8px 0; border-top: 1px solid var(--line); }
.vrow:first-child { border-top: 0; }
.vrow .lbl { flex: 1; min-width: 0; }
.vrow .lbl small { display: block; color: var(--muted); font-size: 12px; }
.vrow .lbl small.has { color: var(--ok); }

.moves { margin: 0; padding-left: 28px; max-height: 200px; overflow-y: auto; font-size: 14px; columns: 1; }
.moves li { padding: 1px 0; }
.moves li span { display: inline-block; min-width: 46%; }

.toasts { position: fixed; left: 50%; bottom: 16px; translate: -50% 0; display: flex; flex-direction: column; gap: 6px; z-index: 10; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: #2a211b; color: #fff; padding: 9px 14px; border-radius: 10px; font-size: 14px; animation: toastIn .2s; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); }
.toast.err { background: #a8241a; }
@keyframes toastIn { from { opacity: 0; translate: 0 8px; } }

/* ---------- Gọi thoại, đồng hồ, giục ---------- */
.mic.live { background: var(--ok); border-color: var(--ok); color: #fff; }
select { padding: 8px 10px; min-height: 38px; }
.pbar.speaking, .people .pp.speaking .dot { box-shadow: 0 0 0 3px var(--ok); }
.pbar.speaking.turn { box-shadow: 0 0 0 3px var(--ok), 0 0 0 5px var(--accent-soft); }
.people .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; transition: background .1s; }
.people .pp.speaking .dot { background: var(--ok); }
.people .pname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .mute { margin-left: auto; min-height: 28px; padding: 2px 8px; }
.tag.warn { color: var(--warn); border-color: var(--warn); }
.clock {
  font: 700 18px ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums;
  padding: 3px 8px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line);
}
.pbar.turn .clock { background: var(--accent); border-color: var(--accent); color: #fff; }
.clock.low { color: #fff; background: #e0281c !important; border-color: #e0281c; animation: pulse 1s infinite; }
.reacts .nudge { font-weight: 700; border-color: var(--accent); color: var(--accent); }
.board-wrap.shake { animation: shake .35s; }
@keyframes shake {
  20% { translate: -5px 2px; } 40% { translate: 4px -2px; } 60% { translate: -3px 1px; } 80% { translate: 2px 0; }
}
