/* WaiSut - ไวสุด */
:root {
  --bg: #070b16;
  --bg2: #0e1426;
  --surface: #151d35;
  --surface2: #1d2745;
  --line: #2a3556;
  --text: #eef2ff;
  --muted: #93a0c4;
  --gold: #ffd028;
  --gold-deep: #ff9f1c;
  --mint: #23e5a4;
  --danger: #ff4d6d;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --font: system-ui, -apple-system, "Segoe UI", "Leelawadee UI", "Noto Sans Thai",
    "Sarabun", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(1100px 700px at 12% -10%, #1b2652 0%, transparent 60%),
    radial-gradient(900px 620px at 92% 8%, #2a1c46 0%, transparent 58%),
    var(--bg);
  background-attachment: fixed;
}

.tabnum {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ---------- โครงหน้า ---------- */
.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 18px 40px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 18px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--gold), var(--gold-deep));
  display: grid;
  place-items: center;
  font-size: 19px;
  box-shadow: 0 6px 18px rgba(255, 160, 28, 0.35);
}

.brand-name {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg2) 100%);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
}
.screen.on {
  display: flex;
}

h1 {
  font-size: 26px;
  margin: 0 0 6px;
  font-weight: 800;
}
h2 {
  font-size: 18px;
  margin: 0 0 12px;
  font-weight: 700;
}
p.lead {
  color: var(--muted);
  margin: 0 0 20px;
  line-height: 1.6;
  font-size: 15px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 7px;
  font-weight: 600;
}

input[type="text"] {
  width: 100%;
  background: var(--bg);
  border: 2px solid var(--line);
  color: var(--text);
  border-radius: 14px;
  padding: 15px 16px;
  font-size: 17px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus {
  border-color: var(--gold);
}
input.code {
  text-transform: uppercase;
  letter-spacing: 8px;
  text-align: center;
  font-size: 28px;
  font-weight: 800;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 16px 20px;
  font-size: 17px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  background: linear-gradient(145deg, var(--gold), var(--gold-deep));
  color: #241a00;
  transition: transform 0.08s, filter 0.15s;
  touch-action: manipulation;
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn.ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.danger {
  background: linear-gradient(145deg, #ff6b81, var(--danger));
  color: #fff;
}
.btn.mint {
  background: linear-gradient(145deg, #4dffc3, var(--mint));
  color: #00291c;
}
.btn.sm {
  width: auto;
  padding: 10px 16px;
  font-size: 14px;
  border-radius: 11px;
}

.row {
  display: flex;
  gap: 10px;
}
.row > * {
  flex: 1;
}
.stack > * + * {
  margin-top: 14px;
}
.center {
  text-align: center;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 13px;
}
.hide {
  display: none !important;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.dot.ok {
  background: var(--mint);
  box-shadow: 0 0 10px var(--mint);
}
.dot.bad {
  background: var(--danger);
}
.dot.warn {
  background: var(--gold);
}

/* ---------- ปุ่มยักษ์ของผู้เล่น ---------- */
.arena {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 10px 0;
}

.bigbtn {
  width: min(78vw, 320px);
  height: min(78vw, 320px);
  border-radius: 50%;
  border: 0;
  font-family: inherit;
  font-size: clamp(38px, 13vw, 62px);
  font-weight: 900;
  letter-spacing: 2px;
  color: #2a1c00;
  background: radial-gradient(circle at 34% 28%, #fff3b0 0%, var(--gold) 42%, var(--gold-deep) 100%);
  box-shadow:
    0 0 0 10px rgba(255, 208, 40, 0.12),
    0 0 0 22px rgba(255, 208, 40, 0.06),
    0 26px 60px rgba(255, 159, 28, 0.4);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.06s ease-out, box-shadow 0.15s;
  animation: breathe 2.4s ease-in-out infinite;
}
.bigbtn:active {
  transform: scale(0.94);
}
.bigbtn.waiting {
  background: radial-gradient(circle at 34% 28%, #46527c 0%, #2b3457 60%, #1c2340 100%);
  color: #8f9cc4;
  box-shadow: none;
  animation: none;
  cursor: not-allowed;
}
.bigbtn.done {
  background: radial-gradient(circle at 34% 28%, #6bffd0 0%, var(--mint) 45%, #0fae7c 100%);
  color: #00291c;
  animation: none;
  box-shadow: 0 22px 55px rgba(35, 229, 164, 0.35);
}
.bigbtn.foul {
  background: radial-gradient(circle at 34% 28%, #ff9aac 0%, var(--danger) 50%, #b3122f 100%);
  color: #fff;
  animation: none;
}

@keyframes breathe {
  0%,
  100% {
    box-shadow:
      0 0 0 10px rgba(255, 208, 40, 0.12),
      0 0 0 22px rgba(255, 208, 40, 0.06),
      0 26px 60px rgba(255, 159, 28, 0.4);
  }
  50% {
    box-shadow:
      0 0 0 16px rgba(255, 208, 40, 0.18),
      0 0 0 34px rgba(255, 208, 40, 0.08),
      0 26px 70px rgba(255, 159, 28, 0.55);
  }
}

.countdown {
  font-size: clamp(90px, 34vw, 190px);
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(180deg, #fff, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: pop 0.6s ease-out;
}
@keyframes pop {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  60% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.result-rank {
  font-size: clamp(64px, 22vw, 120px);
  font-weight: 900;
  line-height: 1;
  color: var(--gold);
}
.result-time {
  font-size: clamp(30px, 10vw, 46px);
  font-weight: 800;
  letter-spacing: 1px;
}

/* ---------- ตาราง ---------- */
.board {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.board th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.board td {
  padding: 10px;
  border-bottom: 1px solid rgba(42, 53, 86, 0.5);
  font-size: 15px;
}
.board tr:last-child td {
  border-bottom: 0;
}
.board .r {
  width: 58px;
  font-weight: 900;
  color: var(--muted);
}
.board .t {
  text-align: right;
  font-weight: 700;
  white-space: nowrap;
}
.board .n {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 1px;
  white-space: nowrap;
}
.board tr.me {
  background: rgba(255, 208, 40, 0.09);
}
.board tr.foul td {
  color: var(--danger);
  opacity: 0.75;
}
.board tr.p1 .r {
  color: var(--gold);
}
.board tr.p2 .r {
  color: #d8e0f5;
}
.board tr.p3 .r {
  color: #e0a86a;
}

/* ---------- โฮสต์ / จอโปรเจกเตอร์ ---------- */
.host {
  max-width: 1400px;
  margin: 0 auto;
  padding: 18px;
}
.host-grid {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 18px;
  align-items: start;
}
@media (max-width: 900px) {
  .host-grid {
    grid-template-columns: 1fr;
  }
}

.qrbox {
  background: #fff;
  border-radius: 18px;
  padding: 14px;
  display: grid;
  place-items: center;
}
.qrbox svg {
  width: 100%;
  height: auto;
  display: block;
}

.codebig {
  font-size: clamp(40px, 7vw, 68px);
  font-weight: 900;
  letter-spacing: 12px;
  color: var(--gold);
  text-align: center;
  line-height: 1.1;
}

.joinurl {
  text-align: center;
  font-size: 15px;
  color: var(--muted);
  word-break: break-all;
  margin-top: 6px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.stat {
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
}
.stat .v {
  font-size: 30px;
  font-weight: 900;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat .k {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
  font-weight: 700;
  letter-spacing: 0.6px;
}

.ctlgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

select {
  width: 100%;
  background: var(--bg);
  border: 2px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 13px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.switch input {
  width: 20px;
  height: 20px;
  accent-color: var(--gold);
}

.hostboard-wrap {
  max-height: 62vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.bigclock {
  font-size: clamp(34px, 5vw, 56px);
  font-weight: 900;
  text-align: center;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}

.statusline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

/* โหมดเต็มจอ: ซ่อนแผงควบคุม เหลือแต่ QR + ตาราง */
body.stage .host-controls {
  display: none;
}
body.stage .host-grid {
  grid-template-columns: minmax(340px, 460px) 1fr;
}
body.stage .codebig {
  font-size: clamp(56px, 9vw, 110px);
}
body.stage .board td {
  font-size: clamp(18px, 2.1vw, 30px);
  padding: 12px 14px;
}
body.stage .board .r {
  width: 90px;
}
body.stage .hostboard-wrap {
  max-height: 84vh;
}
body.stage .stat .v {
  font-size: clamp(34px, 4vw, 56px);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 90;
  box-shadow: var(--shadow);
  max-width: 90vw;
}
.toast.on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}


/* ---------- เลือกโหมดเกม (หน้าโฮสต์) ---------- */
.modepick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modebtn {
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 16px 10px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.modebtn .mi { font-size: 26px; }
.modebtn .mt { font-size: 15px; font-weight: 800; margin-top: 6px; }
.modebtn .md { font-size: 11px; color: var(--muted); margin-top: 2px; font-weight: 600; }
.modebtn.on { border-color: var(--gold); background: rgba(255, 208, 40, 0.09); }

.modecard { transition: border-color 0.15s, transform 0.08s; }
.modecard:active { transform: scale(0.99); }

/* ---------- คลังคำถาม (หน้าโฮสต์) ---------- */
.qlist { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.qitem {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.qitem .qn {
  flex: none; width: 26px; height: 26px; border-radius: 8px;
  background: var(--surface2); display: grid; place-items: center;
  font-weight: 800; font-size: 12px;
}
.qitem .qq { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.qitem .qa { flex: none; font-size: 11px; color: var(--mint); font-weight: 700; }
.qitem.played { opacity: 0.45; }
.qitem.played .qa::after { content: " · เล่นแล้ว"; color: var(--muted); }
.qitem.current { border-color: var(--gold); background: rgba(255, 208, 40, 0.08); }
