:root {
  --bg: #0b0b12;
  --surface: #16161f;
  --surface-2: #1f1f2b;
  --line: #2e2e3d;
  --text: #f4f4f7;
  --muted: #9a9aae;
  --accent: #f5c451;
  --correct: #2fbf6b;
  --wrong: #e5484d;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app { max-width: 620px; margin: 0 auto; padding: 20px 18px 40px; }

/* Wider than a phone: give the scoreboard table room for every column. */
@media (min-width: 621px) {
  #app { max-width: 760px; }
}

.screen { display: flex; flex-direction: column; min-height: 92vh; }
.screen[hidden] { display: none; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; margin-bottom: 20px;
}

.brand {
  font-size: 30px; line-height: 1.1; font-weight: 800;
  letter-spacing: -0.02em; margin: 8px 0 0;
}
.brand span { color: var(--accent); }

.screen-title { font-size: 20px; font-weight: 700; margin: 0; }

.btn-back {
  background: none; border: 0; color: var(--muted);
  font-size: 16px; font-weight: 600; padding: 8px 4px; cursor: pointer;
}
.btn-back:active { color: var(--text); }

.round-tag {
  font-size: 14px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--accent);
}

.penalty-chip {
  margin-left: auto; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 6px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}

/* ---------- layout ---------- */
.stack { display: flex; flex-direction: column; gap: 16px; flex: 1; }
.stack-center { justify-content: center; text-align: center; }

.lede { color: var(--muted); font-size: 16px; margin: 0; }
.kicker {
  font-size: 12px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted); margin: 0;
}

.progress {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px;
  font-size: 17px; line-height: 1.5;
}
.progress strong { color: var(--accent); font-size: 22px; }
.progress .warn { color: var(--wrong); font-weight: 600; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 700; border-radius: var(--radius);
  border: 1px solid transparent; padding: 18px 20px;
  cursor: pointer; text-align: center; width: 100%;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-huge { font-size: 22px; padding: 24px 20px; }

.btn-primary { background: var(--accent); color: #1a1405; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-quiet { background: none; color: var(--muted); font-weight: 600; font-size: 15px; padding: 12px; }
.btn-correct { background: var(--correct); color: #04220f; }
.btn-wrong { background: var(--wrong); color: #2b0406; }

.btn-reveal-answer small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-top: 4px; }

.verdict-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: auto; }

/* ---------- penalty picker ---------- */
.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.choice {
  font: inherit; font-size: 20px; font-weight: 800;
  padding: 26px 12px; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  border: 2px solid var(--line); cursor: pointer;
}
.choice.is-active { background: var(--accent); color: #1a1405; border-color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-label {
  font-size: 12px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted);
}
.field input {
  font: inherit; font-size: 18px; padding: 18px 16px;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
}
.field input::placeholder { color: #5c5c72; }
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

#btn-reveal { margin-top: auto; }

/* ---------- question ---------- */
.question-text {
  font-size: clamp(30px, 8vw, 46px); font-weight: 800;
  line-height: 1.15; letter-spacing: -0.02em; margin: 4px 0 8px;
}

.reveal {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.bride-answer { padding: 6px 4px; }
.bride-answer p { font-size: 26px; font-weight: 700; margin: 6px 0 0; color: var(--accent); }

/* ---------- penalty screen ---------- */
.screen-penalty { justify-content: center; }
.penalty-kicker {
  font-size: 14px; font-weight: 800; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--wrong); margin: 0;
}
.penalty-text {
  font-size: clamp(34px, 10vw, 60px); font-weight: 900;
  line-height: 1.1; letter-spacing: -0.02em; margin: 12px 0 32px;
}

/* ---------- scoreboard ---------- */
.tally { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tally-cell {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; text-align: center;
}
.tally-num { display: block; font-size: 42px; font-weight: 900; line-height: 1; }
.tally-correct .tally-num { color: var(--correct); }
.tally-wrong .tally-num { color: var(--wrong); }
.tally-label {
  font-size: 12px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted);
}

.filter-row { display: flex; gap: 8px; }
.filter {
  font: inherit; font-size: 14px; font-weight: 700;
  padding: 10px 16px; border-radius: 999px;
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--line); cursor: pointer;
}
.filter.is-active { background: var(--text); color: var(--bg); border-color: var(--text); }

.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.results { border-collapse: collapse; width: 100%; font-size: 14px; }
.results th, .results td {
  text-align: left; padding: 12px;
  border-bottom: 1px solid var(--line); vertical-align: top;
}
.results th {
  font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); background: var(--surface-2); white-space: nowrap;
}
.results tbody tr:last-child td { border-bottom: 0; }
.results .col-n { width: 1%; }
.results .col-q { min-width: 150px; font-weight: 600; }
.results .col-a { min-width: 110px; color: var(--accent); }
.results .col-p { min-width: 160px; color: var(--muted); }
.results .col-r { width: 1%; }
.results .muted { color: #5c5c72; }

.pill {
  display: inline-block; font-size: 11px; font-weight: 800;
  letter-spacing: 0.08em; text-transform: uppercase;
  padding: 5px 10px; border-radius: 999px; white-space: nowrap;
}
.pill-correct { background: rgba(47, 191, 107, 0.16); color: var(--correct); }
.pill-wrong { background: rgba(229, 72, 77, 0.16); color: var(--wrong); }
.pill-type { background: var(--surface-2); color: var(--muted); margin-right: 6px; }

.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* Phones: the table becomes stacked cards so nothing hides off-screen. */
@media (max-width: 620px) {
  .table-wrap { border: 0; overflow-x: visible; }
  .results, .results tbody, .results tr, .results td { display: block; width: 100%; }
  .results thead { display: none; }

  .results tr {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
  }

  .results td {
    border: 0; padding: 6px 0;
    display: grid; grid-template-columns: 92px 1fr;
    gap: 12px; align-items: baseline;
  }
  .results td::before {
    content: attr(data-label);
    font-size: 11px; font-weight: 700; letter-spacing: 0.1em;
    text-transform: uppercase; color: var(--muted);
  }
  .results td .cell-body { display: block; }
  .results td.col-q { font-size: 17px; }
  .results td.empty { display: block; }
  .results td.empty::before { content: none; }
}

/* ---------- questions editor ---------- */
#questions-list { display: flex; flex-direction: column; gap: 14px; }

.q-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.q-card.is-played { opacity: 0.62; }

.q-head { display: flex; align-items: center; gap: 10px; }
.q-num {
  font-size: 13px; font-weight: 800; letter-spacing: 0.06em; color: var(--muted);
}
.pill-played { background: var(--surface-2); color: var(--muted); }

.q-delete {
  margin-left: auto; font: inherit; font-size: 13px; font-weight: 700;
  background: none; border: 0; color: var(--wrong);
  padding: 6px 4px; cursor: pointer;
}

.q-field { gap: 6px; }
.q-field .field-label { font-size: 10px; }
.q-field input, .q-field textarea {
  font: inherit; font-size: 16px; padding: 12px 14px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
  width: 100%; resize: none; line-height: 1.4;
}
.q-field textarea { overflow: hidden; }
.q-field input:focus, .q-field textarea:focus {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

#questions-summary { font-size: 14px; }

/* ---------- sync status ---------- */
.sync-line {
  font-size: 12px; font-weight: 700; letter-spacing: .04em;
  padding: 10px 14px; border-radius: 999px; text-align: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
}
.sync-ok { color: var(--correct); border-color: rgba(47,191,107,.35); }
.sync-bad { color: var(--wrong); border-color: rgba(229,72,77,.35); }
.sync-off { color: var(--muted); }

/* ---------- toggle ---------- */
.toggle {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-title { display: block; font-size: 16px; font-weight: 700; }
.toggle-sub { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.switch {
  margin-left: auto; flex: 0 0 auto; width: 52px; height: 30px;
  border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--line); position: relative; transition: background .15s;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--muted); transition: transform .15s, background .15s;
}
.toggle input:checked ~ .switch { background: var(--accent); border-color: var(--accent); }
.toggle input:checked ~ .switch::after { transform: translateX(22px); background: #1a1405; }
.toggle input:focus-visible ~ .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- backend cards ---------- */
#admin-list { display: flex; flex-direction: column; gap: 14px; }

.a-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.a-card.is-played { border-color: #3b3b50; }
.a-head { display: flex; align-items: center; gap: 8px; }
.a-question { font-size: 17px; font-weight: 700; margin: 0; line-height: 1.3; }
.a-answer { font-size: 15px; color: var(--accent); margin: -6px 0 0; }

.seg-wrap { display: flex; flex-direction: column; gap: 6px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg-btn {
  font: inherit; font-size: 14px; font-weight: 700;
  padding: 12px 6px; border-radius: 12px;
  background: var(--bg); color: var(--muted);
  border: 1px solid var(--line); cursor: pointer;
}
.seg-btn.is-active { background: var(--text); color: var(--bg); border-color: var(--text); }
.seg-btn:nth-child(2).is-active { background: var(--correct); color: #04220f; border-color: var(--correct); }
.seg-btn:nth-child(3).is-active { background: var(--wrong); color: #2b0406; border-color: var(--wrong); }
.seg-wrap + .seg-wrap .seg-btn:nth-child(2).is-active,
.seg-wrap + .seg-wrap .seg-btn:nth-child(3).is-active {
  background: var(--accent); color: #1a1405; border-color: var(--accent);
}

.lede.small { font-size: 13px; }

/* ---------- add-question form ---------- */
.add-box {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.add-title { font-size: 17px; font-weight: 800; margin: 0; }
.add-box textarea {
  font: inherit; font-size: 16px; padding: 12px 14px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); width: 100%;
  resize: vertical; line-height: 1.4;
}
.add-box input:focus, .add-box textarea:focus {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

.form-note { font-size: 13px; margin: 0; min-height: 1em; }
.form-note.is-good { color: var(--correct); }
.form-note.is-bad { color: var(--wrong); }

.q-save { margin-top: 4px; }
.q-save:disabled { opacity: 1; background: var(--surface-2); color: var(--muted); }

/* Questions may be written with deliberate line breaks (e.g. trap cards).
   pre-line keeps the newlines while still collapsing stray spaces. */
.question-text,
.penalty-text,
.bride-answer p,
.a-question,
.results .col-q { white-space: pre-line; }
