/* I Will Win — shared styles for the player and host pages */

:root {
  --bg: #15123b;
  --bg-glow: #2d2580;
  --surface: rgba(255, 255, 255, 0.07);
  --surface-2: rgba(255, 255, 255, 0.12);
  --border: rgba(255, 255, 255, 0.14);
  --text: #f6f4ff;
  --muted: #b8b3e2;
  --gold: #ffc940;
  --gold-ink: #2b1e00;
  --good: #1fa463;
  --bad: #d93d42;
  --c0: #d8452f;
  --c1: #1b7cc0;
  --c2: #0e8a6c;
  --c3: #7c4fe0;
  --radius: 16px;
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(1200px 640px at 50% -12%, var(--bg-glow) 0%, var(--bg) 62%) fixed, var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

.app {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}
body.host .app { max-width: 1180px; padding-inline: 24px; }

.screen { flex: 1; display: flex; flex-direction: column; gap: 16px; }
.screen.center { align-items: center; justify-content: center; text-align: center; }

/* ---------- text ---------- */
.logo { font-size: clamp(2.2rem, 9vw, 3.4rem); font-weight: 900; letter-spacing: -0.02em; line-height: 1; }
.logo span { color: var(--gold); }
.logo.small { font-size: 1.25rem; }
.tagline { color: var(--muted); margin-top: 8px; }
.big { font-size: clamp(1.8rem, 7vw, 2.6rem); font-weight: 850; line-height: 1.1; }
.title { font-size: 1.5rem; font-weight: 800; }
.eyebrow { color: var(--muted); font-size: 0.85rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.error { color: #ff9b9e; font-weight: 600; }
.hint { color: var(--muted); font-size: 0.9rem; }
.badge {
  display: inline-block; padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 0.85rem; letter-spacing: 0.05em;
}

/* ---------- forms and buttons ---------- */
.card {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.form { display: flex; flex-direction: column; gap: 12px; max-width: 380px; }
.input {
  width: 100%; padding: 14px 16px; border-radius: 12px; border: 2px solid var(--border);
  background: rgba(0, 0, 0, 0.25); font-size: 1.1rem; outline: none; text-align: center;
}
.input:focus { border-color: var(--gold); }
.input.pin { font-size: 1.6rem; font-weight: 800; letter-spacing: 0.3em; }
.btn {
  border: 0; border-radius: 12px; padding: 14px 20px; font-weight: 800; font-size: 1.05rem;
  background: var(--surface-2); cursor: pointer; transition: transform 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; filter: none; }
.btn-primary { background: var(--gold); color: var(--gold-ink); }
.btn-ghost { background: transparent; border: 2px solid var(--border); }
.btn-danger { background: transparent; border: 2px solid rgba(217, 61, 66, 0.6); color: #ffb3b5; }
.btn-small { padding: 8px 14px; font-size: 0.9rem; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }

/* ---------- banners ---------- */
.status {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20; text-align: center;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
  background: var(--gold); color: var(--gold-ink); font-weight: 800;
}
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  z-index: 20; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: #fff; color: #1b1840; font-weight: 700; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}
.notice { border-left: 4px solid var(--gold); text-align: left; }
.notice h3 { margin-bottom: 4px; }

/* ---------- player top bar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: 12px; background: var(--surface); font-weight: 700;
  align-self: stretch;
}
.tb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-score { color: var(--gold); white-space: nowrap; }

/* ---------- lobby ---------- */
.nick-tag {
  font-size: 1.5rem; font-weight: 800; padding: 10px 22px; border-radius: 999px;
  background: var(--surface-2); max-width: 100%; overflow-wrap: anywhere;
}
.dots { display: flex; gap: 8px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--gold); animation: bounce 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-6px); } }

/* ---------- question ---------- */
.q-text { font-size: clamp(1.25rem, 5vw, 1.7rem); font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; }
.countdown-num {
  width: 120px; height: 120px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 4px solid var(--gold); font-size: 3.2rem; font-weight: 900;
}
.timer { display: flex; align-items: center; gap: 12px; }
.timer-bar { flex: 1; height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.timer-bar-fill { height: 100%; background: var(--gold); transform-origin: left center; }
.timer-num { min-width: 2.2ch; text-align: right; font-weight: 900; font-size: 1.4rem; font-variant-numeric: tabular-nums; }

.choices { display: grid; gap: 12px; grid-template-columns: 1fr; flex: 1; align-content: stretch; }
.choice {
  display: flex; align-items: center; gap: 14px; min-height: 72px; padding: 14px 16px;
  border: 0; border-radius: var(--radius); color: #fff; text-align: left; font-weight: 800; font-size: 1.15rem;
  cursor: pointer; box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.22); transition: transform 0.08s, filter 0.15s;
}
button.choice:hover { filter: brightness(1.1); }
button.choice:active { transform: scale(0.97); }
button.choice:disabled { cursor: default; opacity: 0.45; transform: none; filter: none; }
.choice .letter {
  flex: none; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.22); font-weight: 900;
}
.choice-text { overflow-wrap: anywhere; }
.choice-0 { background: var(--c0); }
.choice-1 { background: var(--c1); }
.choice-2 { background: var(--c2); }
.choice-3 { background: var(--c3); }

.locked { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; }
.choice-chip {
  width: 84px; height: 84px; border-radius: 22px; display: grid; place-items: center;
  font-size: 2.4rem; font-weight: 900; color: #fff;
}

/* ---------- result ---------- */
.result-icon {
  width: 110px; height: 110px; border-radius: 50%; display: grid; place-items: center;
  font-size: 3.5rem; font-weight: 900; background: var(--surface-2);
}
.result.correct .result-icon { background: var(--good); }
.result.wrong .result-icon { background: var(--bad); }
.points { font-size: 2.2rem; font-weight: 900; color: var(--gold); }
.streak { font-weight: 700; }
.rank-line { padding: 10px 18px; border-radius: 999px; background: var(--surface-2); font-weight: 700; }

/* ---------- leaderboard ---------- */
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; width: 100%; }
.board li {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 12px;
  background: var(--surface); font-weight: 700;
}
.board li.me { background: var(--gold); color: var(--gold-ink); }
.b-rank { width: 2.2ch; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.board li.me .b-rank { color: inherit; }
.b-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.b-score { font-variant-numeric: tabular-nums; }
.me-row { text-align: center; font-weight: 700; padding: 12px; border-radius: 12px; border: 2px dashed var(--border); }
.final-rank { font-size: 4.5rem; font-weight: 900; line-height: 1; color: var(--gold); }

/* ---------- host ---------- */
.host-head {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding-bottom: 14px; margin-bottom: 18px; border-bottom: 1px solid var(--border);
}
.host-head .info { flex: 1; display: flex; gap: 10px; flex-wrap: wrap; color: var(--muted); font-weight: 700; }
.host-head .info b { color: var(--text); }

.setup-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.quiz-card { display: flex; flex-direction: column; gap: 10px; }
.quiz-card h3 { font-size: 1.2rem; }
.error-list { margin: 0; padding-left: 20px; color: #ffb3b5; font-family: ui-monospace, monospace; font-size: 0.9rem; }

.host-lobby { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); align-items: start; }
.join-box { text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.join-url { font-size: 1.4rem; font-weight: 800; overflow-wrap: anywhere; }
.pin-big { font-size: clamp(3rem, 8vw, 5rem); font-weight: 900; letter-spacing: 0.06em; color: var(--gold); line-height: 1; }
.link-row { display: flex; gap: 8px; width: 100%; }
.link-row .input { font-size: 0.9rem; text-align: left; padding: 10px 12px; }
.link-row .btn { white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; border: 0;
  background: var(--surface-2); font-weight: 700; cursor: pointer; max-width: 100%;
}
.chip:hover { background: rgba(217, 61, 66, 0.45); }
.chip .x { opacity: 0.6; }
.chip.offline { opacity: 0.5; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.host-stage { display: flex; flex-direction: column; gap: 20px; flex: 1; }
.host-q { text-align: center; font-size: clamp(1.6rem, 3.4vw, 2.6rem); font-weight: 850; line-height: 1.2; overflow-wrap: anywhere; }
.host-mid { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.host-timer {
  width: 110px; height: 110px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 4px solid var(--gold); font-size: 2.8rem; font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.answered { text-align: center; }
.answered b { display: block; font-size: 2.6rem; line-height: 1; }
.host-choices { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.host-choices .choice { cursor: default; min-height: 84px; font-size: 1.35rem; position: relative; overflow: hidden; }
.host-choices .choice.dim { opacity: 0.35; }
.host-choices .choice.is-correct { outline: 4px solid #fff; outline-offset: 3px; }
.host-choices .count { margin-left: auto; font-size: 1.5rem; font-weight: 900; padding-left: 12px; }
.host-choices .tick { margin-left: 8px; }
.host-board { max-width: 720px; margin: 0 auto; width: 100%; }
.host-board .board li { font-size: 1.2rem; padding: 14px 20px; }

.podium { display: flex; justify-content: center; align-items: flex-end; gap: 14px; margin: 10px 0 6px; }
.podium-col { display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(30%, 220px); }
.podium-name { font-weight: 800; font-size: 1.2rem; text-align: center; overflow-wrap: anywhere; }
.podium-score { color: var(--muted); font-weight: 700; }
.podium-block {
  width: 100%; border-radius: 14px 14px 0 0; display: grid; place-items: center;
  font-size: 2.6rem; font-weight: 900; color: var(--gold-ink);
}
.podium-col.p1 .podium-block { height: 190px; background: var(--gold); }
.podium-col.p2 .podium-block { height: 140px; background: #d9dbe8; }
.podium-col.p3 .podium-block { height: 105px; background: #e0a36a; }

@media (min-width: 560px) {
  .player .choices.n3, .player .choices.n4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .host-lobby { grid-template-columns: 1fr; }
  .host-choices { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- question images ---------- */
.q-image {
  display: block; max-width: 100%; max-height: 32vh; margin: 0 auto; border-radius: 12px;
  object-fit: contain; background: rgba(255, 255, 255, 0.06); cursor: zoom-in;
}
.player .screen.has-image .choices { flex: none; }
.player .screen.has-image .choice { min-height: 56px; }
.host .host-stage > .q-image { max-height: 46vh; }
.host-mid .img-wrap { flex: 1; min-width: 0; display: flex; justify-content: center; }
.host-mid .img-wrap .q-image { max-height: 40vh; }
.host-mid .side { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.img-wrap.small .q-image { max-height: 26vh; }
.zoom {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(5, 4, 20, 0.94); cursor: zoom-out;
}
.zoom img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.zoom-close {
  position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px;
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--surface-2);
  font-size: 1.6rem; cursor: pointer;
}

/* ---------- quiz cards (host setup + teacher list) ---------- */
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.card-actions .btn { text-decoration: none; text-align: center; }
a.btn { display: inline-block; text-decoration: none; color: inherit; }
a.btn-primary { color: var(--gold-ink); }
.ok-text { color: #7ee2a8; font-weight: 700; }
.warn-text { color: #ffd66b; font-weight: 700; }
.empty a.btn { margin-top: 12px; }

/* ---------- teacher mode ---------- */
body.teacher .app { max-width: 920px; }
.brand-link { color: inherit; text-decoration: none; }
.teacher-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.editor { padding-bottom: 60px; }
.editor-bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: 12px; background: rgba(28, 24, 74, 0.96);
  border: 1px solid var(--border); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.save-status { color: var(--muted); font-weight: 700; font-size: 0.9rem; flex: 1; min-width: 140px; }
.save-status.ok { color: #7ee2a8; }
.save-status.error { color: #ff9b9e; }
.summary { border: 0; border-radius: 999px; padding: 8px 14px; font-weight: 800; cursor: pointer; }
.summary.ok { background: rgba(31, 164, 99, 0.25); color: #9bf0c0; cursor: default; }
.summary.warn { background: rgba(255, 201, 64, 0.18); color: #ffe39a; }
.field-label { display: block; font-size: 0.85rem; font-weight: 700; color: var(--muted); margin: 0 0 6px; }
.input.left { text-align: left; }
textarea.input { resize: vertical; min-height: 70px; line-height: 1.4; }
.title-input { font-size: 1.35rem; font-weight: 800; }
.input.needs-fix:not(:focus) { border-color: rgba(255, 201, 64, 0.55); }
.q-list { display: flex; flex-direction: column; gap: 16px; }
.q-card { display: flex; flex-direction: column; gap: 12px; }
.q-card.has-issues { border-color: rgba(255, 201, 64, 0.4); }
.q-card.drag-over { outline: 3px dashed var(--gold); outline-offset: 4px; }
.q-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.q-card-head h3 { flex: 1; font-size: 1.1rem; }
.icon-btn {
  width: 38px; height: 38px; flex: none; border-radius: 10px; border: 0; background: var(--surface-2);
  font-weight: 800; font-size: 1.05rem; cursor: pointer;
}
.icon-btn:hover { filter: brightness(1.2); }
.icon-btn:disabled { opacity: 0.3; cursor: default; filter: none; }
.drop-zone {
  width: 100%; display: flex; flex-direction: column; gap: 4px; align-items: center;
  padding: 18px; border: 2px dashed var(--border); border-radius: 12px; background: transparent;
  color: var(--muted); font-weight: 700; cursor: pointer;
}
.drop-zone:hover { border-color: var(--gold); color: var(--text); }
.drop-zone.busy { cursor: progress; border-style: solid; }
.image-preview { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.image-preview img { max-height: 200px; max-width: 100%; border-radius: 10px; cursor: zoom-in; background: rgba(255, 255, 255, 0.06); }
.image-actions { display: flex; flex-direction: column; gap: 8px; }
.answers { display: flex; flex-direction: column; gap: 8px; }
.answer-row { display: flex; align-items: center; gap: 8px; }
.answer-row .letter {
  flex: none; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  font-weight: 900; color: #fff;
}
.answer-row .input { flex: 1; min-width: 0; padding: 11px 14px; font-size: 1rem; }
.answer-row.is-correct .input { border-color: var(--good); }
.correct-btn {
  flex: none; padding: 10px 12px; border-radius: 10px; border: 2px solid var(--border);
  background: transparent; color: var(--muted); font-weight: 800; cursor: pointer; white-space: nowrap;
}
.correct-btn:hover { border-color: var(--good); color: var(--text); }
.correct-btn[aria-pressed="true"] { background: var(--good); border-color: var(--good); color: #fff; }
.add-answer { align-self: flex-start; }
.time-row { display: flex; align-items: center; gap: 12px; }
.time-row .field-label { margin: 0; }
select.input { width: auto; text-align: left; padding: 10px 12px; font-size: 1rem; }
.issues {
  margin: 0; padding: 10px 14px 10px 32px; border-radius: 10px;
  background: rgba(255, 201, 64, 0.12); color: #ffe39a; font-weight: 600; font-size: 0.95rem;
}
.add-row { display: flex; gap: 12px; flex-wrap: wrap; }

@media (max-width: 480px) {
  .correct-btn { padding: 10px 8px; font-size: 0.9rem; }
  .answer-row { gap: 6px; }
  .answer-row .letter { width: 34px; height: 34px; }
}
