:root {
  --bg-1: #0e1530;
  --bg-2: #1b2a5c;
  --ink: #15203f;
  --ink-soft: #5b6688;
  --paper: #ffffff;
  --paper-2: #f2f4fb;
  --line: #dde2f0;
  --brand: #ff6b4a;
  --brand-ink: #ffffff;
  --good: #1fb36b;
  --bad: #e5484d;
  --gold: #f5b82e;
  --silver: #b8c2d6;
  --bronze: #d38b5d;
  /* answer colours: A coral, B cyan, C violet, D lime */
  --opt-0: #ff6b4a;
  --opt-1: #0aa2c0;
  --opt-2: #8b5cf6;
  --opt-3: #6ca31a;
  --radius: 16px;
  --font: 'Prompt', system-ui, -apple-system, 'Segoe UI', 'Noto Sans Thai', sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: var(--font);
  color: #fff;
  background: radial-gradient(1200px 700px at 20% 0%, var(--bg-2), var(--bg-1));
  background-color: var(--bg-1);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button, input, select { font: inherit; }

button {
  cursor: pointer;
  border: 0;
  border-radius: 12px;
  padding: 0.7em 1.4em;
  font-weight: 600;
  background: var(--brand);
  color: var(--brand-ink);
  transition: transform 0.08s ease, filter 0.15s ease, opacity 0.15s;
}
button:hover { filter: brightness(1.06); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: default; transform: none; }
button.ghost { background: rgba(255, 255, 255, 0.12); color: #fff; }
button.light { background: var(--paper); color: var(--ink); }

input[type='text'], input[type='password'], input[type='tel'], select {
  width: 100%;
  padding: 0.75em 0.9em;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 1.15rem;
}
input:focus, select:focus { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); border-color: var(--brand); }

.hidden { display: none !important; }

/* ---------- brand ---------- */

.logo {
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: 2.6rem;
  line-height: 1;
}
.logo .ai { color: var(--brand); }
.tagline { opacity: 0.7; font-size: 0.95rem; }

/* ---------- player ---------- */

.player {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.p-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  font-size: 0.95rem;
  min-height: 52px;
}
.p-top .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-top .score { background: rgba(255,255,255,0.14); padding: 3px 12px; border-radius: 999px; font-weight: 600; white-space: nowrap; }

.lang-toggle { display: inline-flex; background: rgba(255,255,255,0.12); border-radius: 999px; padding: 3px; }
.lang-toggle button { background: transparent; color: #fff; padding: 4px 12px; border-radius: 999px; font-size: 0.85rem; }
.lang-toggle button.on { background: #fff; color: var(--ink); }

.p-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  gap: 14px;
}

.card {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 22px 20px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}
.card label { font-weight: 600; }
.card .hint { color: var(--ink-soft); font-size: 0.9rem; margin-top: -6px; }
.card button { width: 100%; font-size: 1.15rem; }
.card .err { color: var(--bad); font-weight: 600; font-size: 0.95rem; }

.pin-input { text-align: center; letter-spacing: 0.3em; font-size: 1.8rem !important; font-weight: 700; }

.big { font-size: 2rem; font-weight: 800; line-height: 1.2; }
.mid { font-size: 1.25rem; font-weight: 600; }
.soft { opacity: 0.75; }

.p-question-text {
  font-size: 1.05rem;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 10px 14px;
  width: 100%;
  max-width: 560px;
}

.p-answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  flex: 1;
  max-height: 520px;
}
.p-answers.two { grid-template-columns: 1fr; }

.opt-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius);
  min-height: 96px;
  padding: 12px;
  color: #fff;
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.3;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18);
}
.opt-btn .letter, .opt .letter {
  display: inline-grid;
  place-items: center;
  width: 2em;
  height: 2em;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  font-weight: 800;
  flex: none;
}
.opt-btn.no-text .letter { width: 3em; height: 3em; font-size: 1.4rem; }

.bg-0 { background: var(--opt-0); }
.bg-1 { background: var(--opt-1); }
.bg-2 { background: var(--opt-2); }
.bg-3 { background: var(--opt-3); }

.result {
  border-radius: var(--radius);
  padding: 26px 20px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.result.good { background: var(--good); }
.result.bad { background: var(--bad); }
.result.none { background: #47527a; }
.result .icon { font-size: 3rem; line-height: 1; }
.result .pts { font-size: 1.6rem; font-weight: 800; background: rgba(0,0,0,0.18); padding: 2px 16px; border-radius: 999px; }

.pill { display: inline-block; background: rgba(255,255,255,0.14); border-radius: 999px; padding: 4px 14px; font-weight: 600; }

.timer-bar { width: 100%; max-width: 560px; height: 8px; background: rgba(255,255,255,0.15); border-radius: 99px; overflow: hidden; }
.timer-bar > div { height: 100%; background: #fff; border-radius: 99px; transition: width 0.1s linear; }

.banner {
  position: fixed;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  background: #fff3cd;
  color: #5c4500;
  padding: 6px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.spinner {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 5px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.pop { animation: pop 0.35s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- host ---------- */

.host {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.h-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  gap: 12px;
  flex-wrap: wrap;
}
.h-top .logo { font-size: 1.8rem; }
.h-top .tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.h-top .tools button { padding: 6px 12px; font-size: 0.9rem; }

.h-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 24px 24px;
  gap: 18px;
  min-height: 0;
}

.h-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 24px 20px;
}
.h-bottom .right { display: flex; gap: 10px; }
.h-bottom button.primary { font-size: 1.3rem; padding: 0.6em 2em; }

/* setup */
.setup { max-width: 760px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.setup .card { max-width: none; }
.quiz-list { display: flex; flex-direction: column; gap: 8px; max-height: 45vh; overflow: auto; }
.quiz-item {
  display: flex; align-items: center; gap: 12px;
  border: 2px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer;
}
.quiz-item:has(input:checked) { border-color: var(--brand); background: #fff6f3; }
.quiz-item .meta { color: var(--ink-soft); font-size: 0.9rem; }
.quiz-item.broken { opacity: 0.6; cursor: not-allowed; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 400 !important; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }
.errors { background: #fdecec; color: #8a1c1c; border-radius: 10px; padding: 10px 14px; font-size: 0.9rem; white-space: pre-wrap; }

/* lobby */
.lobby { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: start; }
.join-box {
  background: var(--paper); color: var(--ink); border-radius: 20px; padding: 18px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 24px; flex-wrap: wrap;
}
.join-box .label { color: var(--ink-soft); font-size: 1.1rem; font-weight: 600; }
.join-box .url { font-size: clamp(1.8rem, 3.6vw, 3.2rem); font-weight: 800; line-height: 1.1; }
.join-box .pin { font-size: clamp(3rem, 7vw, 6.5rem); font-weight: 800; letter-spacing: 0.06em; line-height: 1; }
.qr { background: #fff; border-radius: 20px; padding: 12px; width: clamp(180px, 22vw, 320px); }
.qr img { width: 100%; display: block; }
.lobby-players { display: flex; flex-wrap: wrap; gap: 10px; align-content: flex-start; }
.chip {
  background: rgba(255,255,255,0.14); color: #fff; padding: 8px 16px; border-radius: 999px;
  font-size: 1.15rem; font-weight: 600;
}
.chip:hover { background: var(--bad); }
.count-badge { font-size: 1.4rem; font-weight: 700; display: flex; gap: 8px; align-items: baseline; }
.count-badge b { font-size: 2.6rem; }

/* question */
.q-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.q-text {
  background: var(--paper); color: var(--ink); border-radius: 20px;
  padding: clamp(16px, 2.5vw, 32px);
  text-align: center;
  font-size: clamp(1.6rem, 3.4vw, 3rem); font-weight: 700; line-height: 1.25;
}
.sub { display: block; font-size: 0.6em; font-weight: 500; color: var(--ink-soft); margin-top: 0.3em; }
.opt .sub { color: rgba(255, 255, 255, 0.88); font-size: 0.7em; margin-top: 0.15em; }
.explain .sub { color: rgba(255, 255, 255, 0.75); font-size: 0.8em; }
.q-mid { display: flex; align-items: center; justify-content: space-between; gap: 24px; flex: 1; min-height: 120px; }
.timer {
  width: clamp(90px, 10vw, 150px); aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center; font-size: clamp(2rem, 4vw, 3.4rem); font-weight: 800;
  background: conic-gradient(var(--brand) var(--p, 100%), rgba(255,255,255,0.12) 0);
  position: relative;
}
.timer span { position: relative; z-index: 1; }
.timer::before { content: ''; position: absolute; inset: 9px; border-radius: 50%; background: var(--bg-1); }
.answered-box { text-align: center; }
.answered-box b { display: block; font-size: clamp(2.2rem, 4.5vw, 3.6rem); line-height: 1; }
.badge-pts { background: var(--gold); color: var(--ink); padding: 4px 14px; border-radius: 999px; font-weight: 700; }

.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.opt {
  display: flex; align-items: center; gap: 16px;
  border-radius: 16px; padding: clamp(12px, 1.8vw, 22px) 20px;
  font-size: clamp(1.2rem, 2.3vw, 2rem); font-weight: 600; color: #fff; line-height: 1.25;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,0.18);
  position: relative; overflow: hidden;
}
.opt .txt { flex: 1; }
.opt .n { font-weight: 800; font-size: 0.9em; background: rgba(0,0,0,0.2); padding: 2px 12px; border-radius: 999px; }
.opt.dim { opacity: 0.35; }
.opt.right { outline: 5px solid #fff; }
.opt .tick { font-size: 1.1em; }
.opt .bar { position: absolute; left: 0; bottom: 0; height: 6px; background: rgba(255,255,255,0.75); }

.explain {
  background: rgba(255,255,255,0.12); border-left: 6px solid var(--gold);
  border-radius: 12px; padding: 12px 18px; font-size: clamp(1rem, 1.7vw, 1.5rem);
}

/* leaderboard */
.board { display: flex; flex-direction: column; gap: 10px; max-width: 900px; width: 100%; margin: 0 auto; }
.board h2 { text-align: center; font-size: clamp(2rem, 4vw, 3.2rem); margin: 0 0 8px; }
.board-row {
  display: flex; align-items: center; gap: 16px;
  background: var(--paper); color: var(--ink); border-radius: 14px;
  padding: 12px 22px; font-size: clamp(1.2rem, 2.2vw, 1.9rem); font-weight: 700;
  animation: slide 0.4s ease both;
}
.board-row .rk { width: 2em; color: var(--ink-soft); }
.board-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-row .fire { font-size: 0.75em; color: var(--brand); }
@keyframes slide { from { transform: translateX(-30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* podium */
.podium { display: flex; justify-content: center; align-items: flex-end; gap: clamp(10px, 2vw, 28px); flex: 1; min-height: 300px; }
.step { display: flex; flex-direction: column; align-items: center; gap: 10px; width: clamp(140px, 22vw, 280px); animation: rise 0.7s cubic-bezier(.2,1.2,.4,1) both; }
.step .nm { font-size: clamp(1.2rem, 2.4vw, 2.2rem); font-weight: 800; text-align: center; word-break: break-word; }
.step .pts { opacity: 0.85; font-weight: 600; }
.step .block { width: 100%; border-radius: 16px 16px 0 0; display: grid; place-items: center; font-size: clamp(2.5rem, 5vw, 4.5rem); font-weight: 800; color: var(--ink); }
.step.p1 .block { height: 34vh; background: var(--gold); }
.step.p2 .block { height: 24vh; background: var(--silver); }
.step.p3 .block { height: 16vh; background: var(--bronze); }
.step.p1 { animation-delay: 2.2s; }
.step.p2 { animation-delay: 1.2s; }
.step.p3 { animation-delay: 0.3s; }
@keyframes rise { from { transform: translateY(60px); opacity: 0; } to { transform: none; opacity: 1; } }
.rest { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

@media (max-width: 800px) {
  .lobby { grid-template-columns: 1fr; }
  .opts { grid-template-columns: 1fr; }
  .h-main, .h-top, .h-bottom { padding-left: 16px; padding-right: 16px; }
}
