:root {
  --bg: #eef3e8;
  --card: #ffffff;
  --ink: #23302a;
  --muted: #6b766f;
  --line: #d6dfd2;
  --accent: #2e7d32;
  --gold: #ffb300;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: radial-gradient(circle at 50% 0, #fbfdf6 0, var(--bg) 60%) fixed;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

h1 { text-align: center; margin: 28px 0 4px; font-size: 34px; }
h2 { font-size: 17px; margin: 20px 0 8px; }
.sub { text-align: center; color: var(--muted); margin: 0 0 20px; }
.app-version { text-align: center; color: var(--muted); font-size: 11px; margin: -12px 0 16px; opacity: .7; }
.hint { color: var(--muted); font-size: 14px; }
.center { text-align: center; }

input, button {
  font: inherit; border-radius: 12px; border: 1px solid var(--line);
  padding: 11px 14px; background: var(--card); color: var(--ink);
}
input { width: 100%; }
button { cursor: pointer; font-weight: 600; box-shadow: 0 3px 0 rgba(0, 0, 0, .12); transition: transform .08s, box-shadow .08s; }
button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .12); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.big { width: 100%; padding: 14px; font-size: 17px; }

.screen { max-width: 520px; margin: 0 auto; padding: 16px; }
.field { display: block; margin-bottom: 12px; font-weight: 600; }
.field input { margin-top: 6px; font-weight: normal; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.row > * { flex: 1; }
.row.small button { font-size: 13px; padding: 8px; }
.or { text-align: center; color: var(--muted); margin: 20px 0 4px; font-size: 13px; }

.rules { margin-top: 24px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.rules summary { font-weight: 700; cursor: pointer; }
.rules li { margin: 6px 0; font-size: 14px; }

/* ── Phòng chờ ── */
.roomcode { text-align: center; color: var(--muted); margin-top: 8px; }
.roomcode b { display: block; font-size: 56px; letter-spacing: .15em; color: var(--accent); }
.seats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seat {
  border-radius: 16px; padding: 12px; min-height: 108px;
  background: var(--card); border: 3px solid var(--c);
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--c) 55%, #000);
}
.seat .color { font-weight: 800; color: var(--c); display: flex; align-items: center; gap: 6px; }
.seat .color::before { content: ''; width: 14px; height: 14px; border-radius: 50%; background: var(--c); }
.seat .who { font-size: 16px; font-weight: 700; }
.seat .who.empty { color: var(--muted); font-weight: 500; }
.seat.mine { background: color-mix(in srgb, var(--c) 12%, #fff); }
.seat button { padding: 6px 10px; font-size: 13px; }
.seat .btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }

/* ── Màn chơi: canvas 3D toàn màn hình, HUD đè lên ── */
#game { position: fixed; inset: 0; overflow: hidden; background: linear-gradient(#cfe6c4, #93b98a); }
#stage { position: absolute; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

#hudTop {
  position: absolute; top: 0; left: 0; right: 0;
  padding: max(8px, env(safe-area-inset-top)) 96px 6px 10px;
  pointer-events: none;
}
#turnLine {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, .92); border-radius: 999px; padding: 6px 14px;
  font-weight: 800; font-size: 16px; box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
#turnLine .dot { width: 14px; height: 14px; border-radius: 50%; }
.timer { height: 6px; margin-top: 6px; max-width: 260px; background: rgba(255, 255, 255, .6); border-radius: 99px; overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; background: var(--accent); transition: width .25s linear; }
.timer.low i { background: #e53935; }

.audio-btns { position: absolute; top: max(8px, env(safe-area-inset-top)); right: 10px; display: flex; gap: 6px; }
.icon-btn { width: 40px; height: 40px; padding: 0; border-radius: 50%; font-size: 18px; background: rgba(255, 255, 255, .92); }
.icon-btn.off { opacity: .5; }

#hudBottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
#hudBottom > * { pointer-events: auto; }
.players { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; pointer-events: none !important; }
.pchip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, .9); border-radius: 999px; padding: 4px 10px 4px 4px;
  font-size: 13px; font-weight: 700; border: 2px solid transparent;
}
.pchip.cur { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 35%, transparent); }
.pchip.off { opacity: .55; }
.pchip .ava { width: 24px; height: 24px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font-size: 13px; }
.pchip .home { font-weight: 600; color: var(--muted); }

#action button { font-size: 19px; padding: 14px 30px; border-radius: 999px; }
#action { text-align: center; max-width: 100%; }
#action .pick {
  display: inline-block; background: rgba(255, 255, 255, .95); border-radius: 16px; padding: 10px 18px;
  font-weight: 700; box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
#action .wait { background: rgba(255, 255, 255, .85); border-radius: 999px; padding: 8px 16px; color: var(--muted); font-weight: 600; }
#action button.primary { animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }

#lastLog {
  background: rgba(0, 0, 0, .45); color: #fff; border-radius: 10px; padding: 4px 10px;
  font-size: 13px; max-width: 100%; pointer-events: none !important;
}
#lastLog:empty { display: none; }
#logBox { background: rgba(255, 255, 255, .95); border-radius: 12px; padding: 6px 10px; width: min(100%, 460px); font-size: 13px; }
#logBox summary { cursor: pointer; font-weight: 700; color: var(--muted); }
#log { list-style: none; padding: 0; margin: 6px 0 0; max-height: 30vh; overflow: auto; }
#log li { padding: 3px 0; border-bottom: 1px solid var(--line); }

.win {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0, 0, 0, .35);
}
.win .box {
  background: #fff; border-radius: 20px; padding: 22px 26px; text-align: center; width: min(90vw, 360px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3); animation: pop .4s ease-out;
}
.win .box .big { font-size: 56px; }
.win .box h3 { margin: 6px 0 14px; font-size: 22px; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: #e65100; color: #fff; text-align: center; padding: 6px; font-size: 14px;
}
.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 60;
  background: #263238; color: #fff; padding: 10px 16px; border-radius: 12px;
  max-width: calc(100vw - 32px); font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
}

/* Điện thoại xoay ngang: HUD dưới thu gọn sang phải */
@media (orientation: landscape) and (max-height: 600px) {
  #hudTop { padding-right: 10px; }
  #hudBottom { left: auto; top: 60px; width: 280px; align-items: stretch; justify-content: flex-end; }
  .players { justify-content: flex-end; }
  #action { text-align: center; }
  #log { max-height: 40vh; }
}
