:root {
  --bg: #0c0a0d;
  --panel: rgba(20, 14, 16, 0.82);
  --panel-solid: #171013;
  --line: rgba(217, 180, 90, 0.22);
  --gold: #d9b45a;
  --gold-hi: #f1d488;
  --cream: #f3ead6;
  --muted: #b5a88f;
  --red: #c4122b;
  --green: #2f8452;
  --danger: #e0574f;
  --radius: 14px;
  --serif: Georgia, "Times New Roman", "Liberation Serif", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }

/* ---------- lớp HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#plates, #labels { position: absolute; inset: 0; pointer-events: none; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 8px 14px;
  transition: background 0.15s, transform 0.08s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(217, 180, 90, 0.5); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.gold {
  background: linear-gradient(180deg, #e6c56f, #b98f35);
  color: #1b1408;
  border-color: #f1d488;
  font-weight: 700;
}
.btn.gold:hover { background: linear-gradient(180deg, #f1d488, #c99d40); }
.btn.icon { padding: 7px 10px; font-size: 16px; line-height: 1; }
.btn.on { border-color: var(--gold); color: var(--gold-hi); }

/* ---------- thanh trên ---------- */
#topbar {
  position: absolute; top: 12px; left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.brand { padding: 8px 14px; display: flex; align-items: center; gap: 12px; }
.brand h1 { font-family: var(--serif); font-size: 18px; margin: 0; color: var(--gold-hi); letter-spacing: 0.06em; }
.brand .meta { font-size: 12px; color: var(--muted); }
.tools { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; padding: 6px; max-width: fit-content; }

/* ---------- bảng tên người chơi ---------- */
.plate {
  position: absolute;
  transform: translate(-50%, -100%);
  min-width: 128px;
  padding: 7px 12px 8px;
  text-align: center;
  border-radius: 12px;
  background: rgba(16, 11, 13, 0.86);
  border: 1px solid var(--line);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
  transition: border-color 0.2s, box-shadow 0.2s, opacity 0.2s;
}
.plate .name { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; justify-content: center; max-width: 150px; }
.plate .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plate .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4); }
.plate .stack { font-family: var(--serif); font-size: 16px; color: var(--gold-hi); margin-top: 1px; }
.plate .status { font-size: 11px; color: var(--muted); min-height: 14px; margin-top: 1px; }
.plate .badge { position: absolute; top: -9px; right: -8px; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 8px; background: var(--gold); color: #1b1408; }
.plate.turn { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(217, 180, 90, 0.35), 0 8px 22px rgba(0, 0, 0, 0.5); }
.plate.folded, .plate.away { opacity: 0.55; }
.plate.winner { border-color: #7bdc9a; box-shadow: 0 0 0 2px rgba(123, 220, 154, 0.4), 0 0 28px rgba(123, 220, 154, 0.35); }
.plate.me .name::after { content: 'Bạn'; font-size: 10px; font-weight: 700; margin-left: 4px; padding: 1px 5px; border-radius: 6px; background: rgba(217, 180, 90, 0.2); color: var(--gold-hi); }
.plate .timer { position: absolute; left: 8px; right: 8px; bottom: 3px; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.plate .timer i { display: block; height: 100%; background: var(--gold); transform-origin: left; }
.plate .timer i.low { background: var(--danger); }
.plate .gain { position: absolute; left: 50%; top: -26px; transform: translateX(-50%); font-family: var(--serif); font-weight: 700; color: #8cf0ab; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8); animation: floatUp 2.4s ease-out forwards; white-space: nowrap; }
.emote { position: absolute; left: 50%; top: -46px; transform: translateX(-50%); font-size: 34px; animation: emotePop 2.6s ease-out forwards; }

.seat-btn {
  position: absolute; transform: translate(-50%, -50%);
  pointer-events: auto;
  border: 1px dashed rgba(217, 180, 90, 0.6);
  background: rgba(16, 11, 13, 0.7);
  color: var(--gold-hi);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
}
.seat-btn:hover { background: rgba(217, 180, 90, 0.18); }

.chip-label {
  position: absolute; transform: translate(-50%, -50%);
  font-size: 12px; font-weight: 700; font-family: var(--serif);
  padding: 2px 7px; border-radius: 8px;
  background: rgba(10, 8, 9, 0.72); color: var(--cream);
  border: 1px solid rgba(255, 255, 255, 0.12);
  white-space: nowrap;
}
.chip-label.pot { font-size: 15px; padding: 4px 12px; color: var(--gold-hi); border-color: var(--line); }

/* ---------- thanh hành động ---------- */
#bottom {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: min(640px, calc(100vw - 24px));
  pointer-events: none;
}
#bottom > * { pointer-events: auto; }
.hint {
  padding: 6px 14px; border-radius: 999px; font-size: 13px;
  background: rgba(16, 11, 13, 0.8); border: 1px solid var(--line); color: var(--cream);
}
.hint b { color: var(--gold-hi); font-family: var(--serif); }
#advice { display: none; width: 100%; padding: 8px 12px; font-size: 13px; line-height: 1.45; }
#advice.show { display: block; animation: slideUp 0.22s ease-out; }
#advice p { margin: 0; }
#advice p + p { margin-top: 3px; color: var(--muted); }
#advice b { color: var(--gold-hi); }
#coach { display: none; width: 100%; padding: 10px 14px; font-size: 13px; line-height: 1.5; max-height: 36vh; overflow-y: auto; }
#coach.show { display: block; animation: slideUp 0.22s ease-out; }
.coach-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.coach-title { font-family: var(--serif); color: var(--gold-hi); font-size: 16px; }
.coach-step { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; }
#coach-text { margin: 0 0 8px; }
#coach-text b { color: var(--gold-hi); }
.coach-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
#coach-exit { margin-right: auto; padding: 5px 10px; font-size: 12px; color: var(--muted); }
#actions.lesson-hide { display: none !important; }
#actions.lesson-lock .btn:not(.lesson-allowed), #actions.lesson-lock input { opacity: 0.35; pointer-events: none; }
#actions .lesson-allowed { outline: 2px solid var(--gold-hi); animation: lessonPulse 1.2s ease-in-out infinite; }
@keyframes lessonPulse { 50% { box-shadow: 0 0 14px rgba(241, 212, 136, 0.8); } }
#actions { width: 100%; padding: 10px; display: none; }
#actions.show { display: block; animation: slideUp 0.22s ease-out; }
.act-row { display: flex; gap: 8px; }
.act-row .btn { flex: 1; padding: 12px 10px; font-weight: 700; font-size: 15px; }
.btn.fold { background: rgba(224, 87, 79, 0.16); border-color: rgba(224, 87, 79, 0.5); }
.btn.fold:hover { background: rgba(224, 87, 79, 0.28); }
.btn.call { background: rgba(47, 132, 82, 0.3); border-color: rgba(98, 190, 130, 0.6); }
.btn.call:hover { background: rgba(47, 132, 82, 0.45); }
.raise-box { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.raise-box .presets { display: flex; gap: 6px; }
.raise-box .presets .btn { padding: 6px 10px; font-size: 12px; }
.raise-box input[type=range] { flex: 1; min-width: 140px; accent-color: var(--gold); }
.raise-box input[type=number] {
  width: 96px; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35); text-align: right;
}
.kbd { font-size: 10px; opacity: 0.55; margin-left: 4px; font-weight: 400; }

/* ---------- chat ---------- */
#chat {
  position: absolute; left: 12px; bottom: 12px;
  width: min(300px, calc(100vw - 24px));
  display: flex; flex-direction: column;
  max-height: 46vh;
}
#chat.collapsed .chat-body { display: none; }
#chat.collapsed { width: auto; }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.chat-head .unread { background: var(--red); color: white; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 6px; }
.chat-body { display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--line); }
#chat-log { overflow-y: auto; padding: 8px 12px; font-size: 13px; line-height: 1.4; flex: 1; min-height: 120px; max-height: 30vh; }
#chat-log .sys { color: var(--gold); font-style: italic; opacity: 0.85; }
#chat-log .who { font-weight: 700; }
.chat-input { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chat-input input { flex: 1; min-width: 0; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.35); }
.emotes { display: flex; gap: 2px; padding: 0 8px 8px; flex-wrap: wrap; }
.emotes button { border: none; background: transparent; font-size: 20px; padding: 2px 4px; border-radius: 6px; }
.emotes button:hover { background: rgba(255, 255, 255, 0.1); }

/* ---------- banner, toast ---------- */
#banner {
  position: absolute; top: 74px; left: 50%; transform: translateX(-50%);
  padding: 10px 22px; font-family: var(--serif); font-size: 18px; color: var(--gold-hi);
  display: none; text-align: center; max-width: calc(100vw - 24px);
}
#banner.show { display: block; animation: fadeInOut 4.5s ease forwards; }
#toasts { position: fixed; z-index: 18; top: 74px; right: 12px; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none; }
.toast { padding: 8px 14px; font-size: 13px; animation: fadeInOut 3.5s ease forwards; }
.toast.error { border-color: rgba(224, 87, 79, 0.6); }

/* ---------- sảnh chờ ---------- */
#lobby {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(5, 3, 4, 0.55); backdrop-filter: blur(3px); z-index: 10; padding: 16px;
}
#lobby.show { display: flex; }
.lobby-card { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px 24px; position: relative; }
.lobby-card h2 { font-family: var(--serif); font-weight: 400; color: var(--gold-hi); margin: 0 0 4px; font-size: 26px; }
.lobby-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.lobby-card h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field input[type=text], .field input[type=number] {
  padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.35); color: var(--cream);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5); }
.colors button.sel { border-color: var(--cream); }
.addr { font-family: ui-monospace, Menlo, Consolas, monospace; background: rgba(0, 0, 0, 0.4); padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); color: var(--gold-hi); display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; word-break: break-all; }
.players { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.players .row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.04); }
.players .row .tag { margin-left: auto; font-size: 11px; color: var(--muted); }
.bot-box { display: flex; flex-direction: column; gap: 10px; }
.bot-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.bot-row .field { flex: 1; min-width: 140px; }
.bot-row .btn { flex: 1; }
.field select { padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line); background: #1d1418; color: var(--cream); }
.players .row .rm { margin-left: 8px; padding: 3px 8px; font-size: 12px; }
.plate .bot { font-size: 11px; margin-right: 2px; }
.lobby-actions { display: flex; gap: 8px; margin-top: 20px; justify-content: flex-end; flex-wrap: wrap; }
.close-x { position: absolute; top: 12px; right: 14px; border: none; background: none; font-size: 22px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.note { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ---------- hướng dẫn "Cách chơi" ---------- */
#guide {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(5, 3, 4, 0.6); backdrop-filter: blur(3px); z-index: 15; padding: 16px;
}
#guide.show { display: flex; }
.guide-card {
  width: min(560px, 100%); position: relative; display: flex; flex-direction: column;
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
  padding: 20px 24px 14px;
}
.guide-scroll { overflow-y: auto; min-height: 0; flex: 1; }
.guide-step { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.guide-card h2 { font-family: var(--serif); font-weight: 400; color: var(--gold-hi); margin: 4px 0 10px; font-size: 24px; padding-right: 28px; }
.guide-body p { margin: 0 0 8px; font-size: 15px; line-height: 1.5; }
.guide-body b { color: var(--gold-hi); }
.guide-note { display: none; font-size: 12px; color: var(--gold); margin-top: 6px; }
.guide-note.show { display: block; }
.guide-nav { display: flex; align-items: center; gap: 8px; padding-top: 12px; margin-top: 8px; border-top: 1px solid var(--line); }
.guide-dots { display: flex; gap: 8px; flex: 1; justify-content: center; }
.guide-dots button { position: relative; width: 10px; height: 10px; padding: 0; border-radius: 50%; border: 1px solid var(--line); background: transparent; }
.guide-dots button::after { content: ''; position: absolute; inset: -8px; }
.guide-dots button.on { background: var(--gold); border-color: var(--gold); }

.guide-visual { margin: 6px 0 12px; }
.guide-visual.goal { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-end; }
.guide-visual .vg-group { display: flex; flex-direction: column; gap: 4px; }
.guide-visual .vg-cards { display: flex; gap: 4px; }
.guide-visual .vg-group small { color: var(--muted); font-size: 11px; }
.gc { display: block; width: 30px; height: 42px; border-radius: 4px; }
.gc.back { background: repeating-linear-gradient(45deg, #8a1520, #8a1520 4px, #a8303b 4px, #a8303b 8px); border: 1px solid var(--cream); }
.gc.up { background: var(--cream); border: 1px solid rgba(0, 0, 0, 0.4); }
.guide-visual.flow { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.guide-visual.flow .step { padding: 4px 9px; border-radius: 999px; background: rgba(217, 180, 90, 0.14); border: 1px solid var(--line); font-size: 12px; }
.guide-visual.flow .arr { color: var(--muted); font-style: normal; }
.guide-visual.actions { display: flex; gap: 8px; pointer-events: none; }
.guide-visual.actions .btn { flex: 1; text-align: center; font-weight: 700; font-size: 14px; padding: 10px 6px; }
.guide-visual.ranks { display: flex; flex-direction: column; gap: 4px; }
.rk-row { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border-radius: 8px; background: rgba(255, 255, 255, 0.04); }
.rk-n { width: 16px; text-align: center; color: var(--muted); font-size: 12px; flex: none; }
.rk-name { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; line-height: 1.2; }
.rk-name small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }
.rk-cards { display: flex; gap: 2px; flex: none; }
.mini-card { width: 28px; height: 39px; border-radius: 3px; flex: none; }
.mini-card.text { display: inline-flex; align-items: center; justify-content: center; background: var(--cream); color: #1a1a1f; font-size: 11px; font-weight: 700; }
.mini-card.text.red { color: var(--red); }
.guide-visual.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; }
.key-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.key-row kbd { min-width: 24px; padding: 2px 6px; text-align: center; border-radius: 6px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); font-family: ui-monospace, Menlo, Consolas, monospace; }

#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 10px; background: var(--bg); z-index: 20; font-family: var(--serif); color: var(--gold-hi); font-size: 20px; transition: opacity 0.4s; }
/* ẩn hẳn sau khi mờ dần: opacity 0 vẫn phủ cả màn hình và chạy animation vô hạn */
#loading.hide { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity 0.4s, visibility 0s 0.4s; }
#loading.hide .suits { animation: none; }
#loading .suits { font-size: 28px; letter-spacing: 10px; animation: pulse 1.2s ease-in-out infinite; }

@keyframes slideUp { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fadeInOut { 0% { opacity: 0; transform: translate(var(--tx, 0), -6px); } 10% { opacity: 1; transform: translate(var(--tx, 0), 0); } 80% { opacity: 1; } 100% { opacity: 0; } }
#banner.show { --tx: -50%; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, 8px); } 15% { opacity: 1; transform: translate(-50%, 0); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -16px); } }
@keyframes emotePop { 0% { opacity: 0; transform: translate(-50%, 10px) scale(0.5); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.15); } 25% { transform: translate(-50%, 0) scale(1); } 85% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -20px); } }
@keyframes pulse { 50% { opacity: 0.4; } }

@media (max-width: 720px) {
  .brand .meta { display: none; }
  .brand { padding: 6px 10px; }
  .brand h1 { font-size: 14px; white-space: nowrap; }
  .grid2 { grid-template-columns: 1fr; }
  .lobby-card { padding: 18px 16px; }
  .plate { min-width: 96px; padding: 5px 8px 7px; }
  .plate .name { font-size: 11px; max-width: 100px; }
  .plate .stack { font-size: 13px; }
  .tools .label { display: none; }
  .tools { flex-wrap: wrap; padding: 3px; gap: 3px; }
  .tools .btn.icon { padding: 7px 5px; }
  #chat { width: min(260px, calc(100vw - 24px)); top: 60px; bottom: auto; }
  #bottom { bottom: 8px; }
  .act-row .btn { font-size: 13px; padding: 11px 6px; }
  .kbd { display: none; }
  #advice { font-size: 12px; padding: 6px 10px; }
  #coach { font-size: 12px; padding: 8px 10px; max-height: 38vh; }
  .guide-card { padding: 16px 14px 10px; }
  .guide-card h2 { font-size: 20px; margin-bottom: 8px; }
  .guide-body p { font-size: 14px; margin-bottom: 6px; line-height: 1.45; }
  .guide-nav { gap: 6px; flex-wrap: wrap; }
  .guide-nav .btn { padding: 8px 10px; }
  .guide-dots { order: -1; flex: 0 0 100%; gap: 10px; }
  .guide-dots button::after { inset: -5px; }
  #guide-skip { margin-right: auto; }
  .guide-visual.keys { grid-template-columns: 1fr; }
  .rk-row { gap: 6px; padding: 2px 4px; }
  .mini-card { width: 24px; height: 34px; }
}
