:root {
  --bg: #f4ecd8; --paper: #fffaf0; --ink: #3b2a18; --muted: #85745c; --line: #e2d3b2;
  --red: #a8322a; --red2: #c0453a; --green: #2e6a2b; --gold: #e2b23c; --board: #e5d9bb;
  --shadow: 0 6px 24px rgba(70, 45, 15, .14);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 15px; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 14px; min-height: 44px; font-weight: 600; color: var(--ink); transition: background .15s, transform .05s; }
.btn:hover { background: #fbf5e8; }
.btn:active { transform: translateY(1px); }
.btn.pri { background: var(--red); border-color: var(--red); color: #fff; }
.btn.pri:hover { background: var(--red2); }
.btn.ok { background: var(--green); border-color: var(--green); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { min-height: 34px; padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.icon { width: 44px; padding: 0; font-size: 20px; }
input.txt { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; background: #fff; }
input.txt:focus { outline: 2px solid var(--gold); border-color: var(--gold); }
.link { background: none; border: 0; color: var(--red); text-decoration: underline; padding: 8px; }

/* ---------- Trang chủ ---------- */
.home { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px 40px; gap: 18px; }
.brand { text-align: center; max-width: 520px; }
.brand .tiles { display: flex; justify-content: center; gap: 0; margin-bottom: 10px; }
.brand .tiles svg { width: 74px; height: 74px; display: block; }
.brand h1 { font-size: 40px; margin: 6px 0 4px; letter-spacing: -.5px; color: var(--red); font-weight: 800; }
.brand p { margin: 0; color: var(--muted); line-height: 1.5; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: 100%; max-width: 380px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.card label { font-weight: 600; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.or { text-align: center; color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; }
.row > input { flex: 1; text-transform: uppercase; letter-spacing: 2px; }

/* ---------- Phòng ---------- */
.room { display: grid; grid-template-columns: minmax(0, 1fr) 330px; grid-template-rows: 54px 1fr; height: 100dvh; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 12px; background: var(--paper); border-bottom: 1px solid var(--line); min-width: 0; }
.top .logo { font-weight: 800; color: var(--red); text-decoration: none; font-size: 18px; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px; }
.top .logo img { width: 26px; height: 26px; border-radius: 6px; flex: none; }
.top .code { color: var(--muted); font-size: 13px; white-space: nowrap; }
.top .code b { color: var(--ink); letter-spacing: 1.5px; }
.top .deck { font-size: 13px; background: #f1e6cb; border-radius: 99px; padding: 4px 10px; white-space: nowrap; }
.top .tools { margin-left: auto; display: flex; gap: 4px; }
.top .tools .btn { min-height: 38px; padding: 4px 10px; font-size: 13px; }
.stage { position: relative; overflow: hidden; background-color: var(--board); background-image: radial-gradient(rgba(120, 90, 40, .13) 1px, transparent 1.4px); background-size: 22px 22px; }
#board { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
#board.dragging { cursor: grabbing; }
.side { background: var(--paper); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }

.players { padding: 10px; display: flex; flex-direction: column; gap: 6px; border-bottom: 1px solid var(--line); }
.pl { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 10px; border: 2px solid transparent; background: #fff; min-width: 0; }
.pl.on { border-color: var(--pc); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pc) 18%, transparent); }
.pl .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--pc); flex: none; box-shadow: inset 0 0 0 2px rgba(255,255,255,.6); }
.pl .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.pl .tag { font-size: 11px; color: var(--muted); background: #f3ead6; padding: 1px 6px; border-radius: 99px; white-space: nowrap; }
.pl .tag.off { background: #f6dcd6; color: #8c3220; }
.pl .mp { display: inline-flex; align-items: center; font-size: 12px; color: var(--muted); white-space: nowrap; }
.pl .mp svg { width: 18px; height: 18px; }
.pl .sc { font-weight: 800; font-size: 18px; min-width: 34px; text-align: right; }

.turn { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.turn .head { display: flex; align-items: center; gap: 12px; }
.turn .prev { width: 84px; height: 84px; flex: none; border-radius: 8px; box-shadow: var(--shadow); background: #fff; }
.turn .prev svg { width: 84px; height: 84px; display: block; border-radius: 8px; }
.turn .who { font-weight: 700; font-size: 16px; line-height: 1.3; }
.turn .hint { color: var(--muted); font-size: 13px; line-height: 1.45; margin-top: 2px; }
.turn .acts { display: flex; gap: 8px; flex-wrap: wrap; }
.turn .acts .btn { flex: 1; min-width: 0; }
.turn .acts .btn.icon { flex: none; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--red); }
.mine-banner { background: #fff3cf; border: 1px solid #f0d58a; border-radius: 10px; padding: 6px 10px; font-weight: 700; color: #7a5200; }

.feed { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; padding: 10px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; min-height: 44px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--red); }
.badge { background: var(--red); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; margin-left: 4px; }
.list { flex: 1; overflow-y: auto; padding: 8px 12px; font-size: 13px; line-height: 1.45; }
.list .it { padding: 4px 0; border-bottom: 1px dashed #efe4cb; display: flex; gap: 6px; align-items: baseline; }
.list .it .d { width: 8px; height: 8px; border-radius: 50%; flex: none; transform: translateY(-1px); }
.list .it b { font-weight: 700; }
.chatform { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chatform input { flex: 1; min-width: 0; }

/* ---------- SVG bàn chơi ---------- */
.cell { fill: rgba(255, 255, 255, .28); stroke: #fff; stroke-width: 3.5; stroke-dasharray: 9 6; cursor: pointer; animation: pulse 1.6s ease-in-out infinite; }
.cell.fit { fill: rgba(255, 246, 200, .55); stroke: var(--gold); }
@keyframes pulse { 50% { fill-opacity: .55; } }
.tentbox { fill: none; stroke: var(--gold); stroke-width: 5; pointer-events: none; }
.tent { cursor: pointer; }
.lastp { fill: none; stroke-width: 4.5; pointer-events: none; }
.spot { cursor: pointer; }
.spot circle.hit { fill: transparent; stroke: none; }
.spot circle:not(.hit) { fill: rgba(255, 255, 255, .82); stroke: #3b2a18; stroke-width: 2; stroke-dasharray: 4 3; }
.spot text { font-size: 15px; font-weight: 800; fill: #3b2a18; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.spot:hover circle:not(.hit) { fill: #fff3cf; }
.ghost-mp { opacity: .85; pointer-events: none; }
.fx { font-weight: 800; font-size: 36px; paint-order: stroke; stroke: #fff; stroke-width: 6px; text-anchor: middle; pointer-events: none; transform-box: fill-box; animation: rise 2.6s ease-out forwards; }
@keyframes rise { 0% { opacity: 0; transform: translateY(12px) scale(.8); } 12% { opacity: 1; transform: translateY(0) scale(1.08); } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(-70px) scale(1); } }

/* ---------- Phòng chờ / hộp thoại ---------- */
.overlay { position: absolute; inset: 0; display: flex; align-items: flex-start; justify-content: center; padding: 28px 16px; overflow-y: auto; }
.lobby { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 460px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.lobby h2 { margin: 0; font-size: 22px; }
.lobby h2 span { color: var(--red); letter-spacing: 2px; }
.invite { display: flex; gap: 8px; }
.invite input { flex: 1; min-width: 0; font-size: 13px; }
.plist { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.plist li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: #fff; border: 1px solid #f0e6cf; }
.plist .dot { width: 14px; height: 14px; border-radius: 50%; }
.plist .nm { flex: 1; font-weight: 600; }
.plist .x { background: none; border: 0; color: var(--muted); font-size: 18px; width: 36px; height: 36px; border-radius: 8px; }
.plist .x:hover { background: #f6dcd6; color: var(--red); }
.plist .empty { color: var(--muted); font-style: italic; background: transparent; border-style: dashed; }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.setrow > span { font-weight: 600; font-size: 13px; color: var(--muted); }
.seg { display: inline-flex; background: #f1e6cb; border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { white-space: nowrap; border: 0; background: transparent; padding: 6px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); min-height: 36px; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.seg button:disabled { cursor: default; }
.note { font-size: 13px; color: var(--muted); line-height: 1.5; }

.modal { position: fixed; inset: 0; background: rgba(40, 25, 10, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal .box { background: var(--paper); border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto; padding: 20px; position: relative; }
.modal .box h2 { margin: 0 0 12px; font-size: 20px; }
.modal .box h3 { margin: 16px 0 6px; font-size: 15px; }
.modal .box p, .modal .box li { line-height: 1.55; }
.modal .box ul { padding-left: 20px; margin: 6px 0; }
.modal .close { position: absolute; top: 10px; right: 10px; }
.reswrap { overflow-x: auto; margin: 0 -4px; }
.res { width: 100%; border-collapse: collapse; font-size: 14px; margin: 6px 0 14px; }
.res th, .res td { padding: 7px 6px; text-align: right; border-bottom: 1px solid #efe4cb; white-space: nowrap; }
.res th:first-child, .res td:first-child { text-align: left; }
.res td.n { font-weight: 700; }
.res tr.win td { background: #fff3cf; }
.res td .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 10px; }
.tgrid .t { text-align: center; font-size: 12px; color: var(--muted); }
.tgrid svg { width: 100%; aspect-ratio: 1; display: block; border-radius: 6px; }
.tgrid .t.zero svg { opacity: .3; filter: grayscale(1); }
.tgrid b { color: var(--ink); font-size: 14px; }

.banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: #3b2a18; color: #fff; padding: 8px 14px; border-radius: 99px; font-size: 13px; box-shadow: var(--shadow); z-index: 5; white-space: nowrap; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: #3b2a18; color: #fff; padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.mtoggle { display: none; }

/* ---------- Điện thoại / máy tính bảng dọc ---------- */
@media (max-width: 860px) {
  .room { grid-template-columns: minmax(0, 1fr); grid-template-rows: 50px minmax(0, 1fr) auto; }
  .side, .players, .turn, .top { min-width: 0; }
  .top .tools { gap: 3px; }
  .top .tools .btn { min-height: 36px; padding: 3px 8px; font-size: 13px; }
  .top { gap: 8px; padding: 0 8px; }
  .top .code { display: none; }
  .top .logo { font-size: 16px; }
  .top .tools .btn { padding: 4px 8px; }
  .side { border-left: 0; border-top: 1px solid var(--line); max-height: 48dvh; }
  .players { flex-direction: row; overflow-x: auto; padding: 8px; gap: 6px; scrollbar-width: none; }
  .players::-webkit-scrollbar { display: none; }
  .pl { flex: none; padding: 5px 8px; gap: 6px; }
  .pl .nm { max-width: 92px; }
  .pl .tag { display: none; }
  .pl .tag.off { display: inline; }
  .pl .sc { font-size: 16px; min-width: 0; }
  .turn { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); gap: 8px; }
  .turn .prev, .turn .prev svg { width: 64px; height: 64px; }
  .turn .who { font-size: 15px; }
  .feed { display: none; }
  .side.showfeed .feed { display: flex; position: fixed; inset: 50px 0 0 0; background: var(--paper); z-index: 40; }
  .mtoggle { display: inline-flex; }
  .top .tools .lbl { display: none; }
  .top .tools .btn.icon-sm { width: 36px; padding: 0; }
}
@media (max-width: 560px) {
  .top .deck .dl { display: none; }
}
@media (max-width: 480px) {
  .top .tools .btn.opt { display: none; }
  .top .logo .lt { display: none; }
  .top .tools #bFit { width: 38px; padding: 0; }
}
@media (max-width: 480px) {
  .res th, .res td { padding: 7px 4px; font-size: 13px; }
  .modal .box { padding: 18px 14px; }
}
@media (max-width: 400px) {
  .top .deck { padding: 3px 7px; font-size: 12px; }
  .top .tools .btn.opt { display: none; }
}
