:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --ink: #18202a;
  --muted: #687383;
  --panel: #ffffff;
  --line: #d9e0e7;
  --accent: #147a7e;
  --accent-2: #d64759;
  --good: #1f8a4c;
  --warn: #c56a12;
  --shadow: 0 18px 42px rgba(31, 45, 61, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

textarea,
input[type="text"],
input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: white;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

a {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.topbar,
.player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.03;
}

h2 {
  font-size: 18px;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.navlinks {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.admin-layout,
.history-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.4fr);
  gap: 18px;
  padding: 24px clamp(18px, 4vw, 48px);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 20px;
  box-shadow: var(--shadow);
}

.main-question {
  grid-row: span 2;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 12px;
  background: #e7f4f3;
  color: #07595d;
  font-size: 13px;
  font-weight: 900;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.control-grid .danger {
  grid-column: 1 / -1;
  background: var(--accent-2);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.stats strong {
  display: block;
  font-size: 28px;
}

.stats span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.option-list,
.screen-options,
.answer-grid,
.question-list {
  display: grid;
  gap: 12px;
}

.option-row,
.screen-option {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfd;
}

.option-row span,
.screen-option span,
.answer-card span {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: #e8edf2;
  color: var(--ink);
  font-weight: 900;
}

.correct {
  border-color: rgba(31, 138, 76, 0.6);
  background: #edf9f1;
}

.bars {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 180px) 1fr 34px;
  align-items: center;
  gap: 10px;
}

.bar-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-row div {
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf2;
}

.bar-row i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.question-list button {
  width: 100%;
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  text-align: left;
}

.question-list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.question-list-row.active .question-open {
  border-color: var(--accent);
  background: #e7f4f3;
}

.secondary-button {
  background: #e8edf2;
  color: var(--ink);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 52px;
  min-width: 52px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  text-align: center;
}

.question-editor {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.question-editor label,
.editor-option {
  display: grid;
  gap: 8px;
}

.question-editor label span,
.editor-label {
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  color: var(--muted);
}

.question-editor-full {
  grid-column: 1 / -1;
}

.editor-options {
  display: grid;
  gap: 10px;
}

.editor-option {
  grid-template-columns: 28px 24px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.editor-option > span {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #e8edf2;
  font-weight: 900;
}

.editor-option input[type="radio"] {
  width: 18px;
  height: 18px;
  margin: 0;
}

.question-editor-actions {
  display: flex;
  justify-content: flex-start;
}

.leaderboard {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.rank-list {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.rank-list li {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) minmax(86px, auto);
  grid-template-areas:
    "rank name score"
    "rank meta score";
  align-items: center;
  column-gap: 12px;
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.rank-list li:first-child {
  border-color: rgba(31, 138, 76, 0.45);
  background: #edf9f1;
}

.rank-position {
  grid-area: rank;
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: var(--ink);
  color: white;
  font-weight: 900;
}

.rank-name {
  grid-area: name;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 900;
}

.rank-meta {
  grid-area: meta;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.rank-list strong {
  grid-area: score;
  justify-self: end;
  font-size: 26px;
}

.rank-list .empty-row {
  display: block;
  min-height: 0;
  color: var(--muted);
  font-weight: 800;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.metric-grid div {
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfd;
}

.metric-grid strong {
  display: block;
  font-size: 30px;
  line-height: 1;
}

.metric-grid span,
.metric-grid small {
  display: block;
  margin-top: 8px;
}

.metric-grid span {
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.metric-grid small {
  color: var(--muted);
  font-weight: 700;
  line-height: 1.25;
}

.join-surface,
.player-surface {
  min-height: 100vh;
  background: linear-gradient(160deg, #f7fafb 0%, #e6f1f0 52%, #f8ecee 100%);
}

.join-box {
  width: min(440px, calc(100vw - 32px));
  margin: 0 auto;
  padding-top: 16vh;
}

.join-box form {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 20px;
  box-shadow: var(--shadow);
}

.join-box input {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  font-size: 20px;
}

.error {
  color: var(--accent-2);
  font-weight: 800;
}

.player-header {
  align-items: flex-start;
}

.score-chip {
  min-width: 96px;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  padding: 12px;
  text-align: center;
}

.score-chip strong {
  display: block;
  font-size: 30px;
}

.score-chip span {
  font-size: 12px;
  font-weight: 800;
}

.player-main {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 24px 16px;
}

.player-main section + section {
  margin-top: 20px;
}

.player-main h2 {
  font-size: clamp(26px, 7vw, 44px);
  line-height: 1.08;
}

.player-stats-panel h2 {
  margin-bottom: 14px;
  font-size: 20px;
}

.player-metric-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.timer-line {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 0 14px;
  background: #e7f4f3;
  color: #07595d;
  font-weight: 900;
}

.answer-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.answer-card {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  min-height: 96px;
  gap: 12px;
  padding: 16px;
  background: white;
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow);
}

.answer-card.selected {
  outline: 4px solid var(--accent);
}

.answer-card strong {
  overflow-wrap: anywhere;
}

.result-strip {
  margin-top: 18px;
  border-radius: 8px;
  padding: 14px;
  background: white;
  font-weight: 900;
}

.result-strip.good {
  background: #edf9f1;
  color: var(--good);
}

.result-strip.bad {
  background: #fff0f2;
  color: var(--accent-2);
}

.screen-surface {
  min-height: 100vh;
  background: #f8fafc;
  color: #14213d;
}

.screen-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.8fr);
  gap: 32px;
  min-height: 100vh;
  padding: clamp(24px, 5vw, 64px);
}

.screen-layout h1 {
  font-size: clamp(42px, 6vw, 82px);
}

.screen-layout aside {
  display: grid;
  gap: 16px;
  align-self: start;
}

.screen-side-panel {
  border: 1px solid rgba(20, 33, 61, 0.12);
  border-radius: 12px;
  background: white;
  padding: 18px;
  box-shadow: var(--shadow);
}

.screen-side-panel h2 {
  margin-bottom: 0;
}

.screen-leaderboard {
  margin-top: 8px;
}

.screen-leaderboard li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
}

.screen-leaderboard li span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.screen-leaderboard li strong {
  font-size: 28px;
}

.screen-join-promo {
  display: grid;
  justify-items: start;
  gap: 18px;
  margin: 28px 0 18px;
}

.screen-join-promo img {
  width: min(320px, 48vw);
  height: auto;
  border: 1px solid rgba(20, 33, 61, 0.12);
  border-radius: 18px;
  background: white;
  padding: 14px;
  box-shadow: var(--shadow);
}

.screen-join-promo p {
  margin-bottom: 0;
  color: rgba(20, 33, 61, 0.72);
  font-size: clamp(18px, 2vw, 24px);
  font-weight: 700;
}

.screen-option {
  min-height: 88px;
  border-color: rgba(20, 33, 61, 0.12);
  background: white;
  font-size: clamp(22px, 3vw, 36px);
}

.screen-surface .screen-option.correct {
  border-color: rgba(31, 138, 76, 0.85);
  background: rgba(31, 138, 76, 0.18);
}

.screen-stats {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.correct-answer {
  display: grid;
  gap: 6px;
  margin-top: 16px;
  border-radius: 10px;
  padding: 14px;
  border: 1px solid rgba(31, 138, 76, 0.55);
  background: rgba(31, 138, 76, 0.14);
}

.correct-answer span {
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  opacity: 0.92;
}

.correct-answer strong {
  font-size: clamp(18px, 2.2vw, 28px);
  line-height: 1.12;
}

.screen-surface .leaderboard li,
.screen-surface .bar-row {
  color: #14213d;
}

.screen-surface .screen-stats {
  margin-top: 0;
}

.screen-surface .screen-stats div {
  border-color: rgba(20, 33, 61, 0.12);
  background: white;
  text-align: center;
}

.screen-surface .screen-stats strong {
  font-size: clamp(26px, 3.6vw, 44px);
}

.screen-surface .leaderboard li {
  border-bottom-color: rgba(20, 33, 61, 0.12);
}

.screen-surface .bars {
  margin-top: 16px;
}

.screen-surface .bar-row {
  grid-template-columns: minmax(0, 1.2fr) 1.6fr 44px;
}

.screen-surface .bar-row span {
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.screen-surface .bar-row div {
  background: rgba(20, 33, 61, 0.1);
}

.screen-final {
  display: grid;
  gap: 28px;
  min-height: 100vh;
  padding: clamp(24px, 5vw, 64px);
}

.screen-final h1 {
  margin-bottom: 24px;
  font-size: clamp(46px, 7vw, 96px);
}

.screen-rank-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.screen-rank-list li {
  min-height: 92px;
  border-color: rgba(20, 33, 61, 0.12);
  background: white;
}

.screen-rank-list li:first-child {
  border-color: rgba(31, 138, 76, 0.85);
  background: rgba(31, 138, 76, 0.18);
}

.screen-rank-list .rank-position {
  background: #14213d;
  color: white;
}

.screen-rank-list .rank-meta {
  color: rgba(20, 33, 61, 0.62);
}

.screen-rank-list strong {
  font-size: 34px;
}

.screen-metric-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.screen-metric-grid div {
  border-color: rgba(20, 33, 61, 0.12);
  background: white;
}

.screen-metric-grid span,
.screen-metric-grid small {
  color: rgba(20, 33, 61, 0.64);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  white-space: nowrap;
}

@media (max-width: 860px) {
  .topbar,
  .player-header,
  .screen-layout {
    display: grid;
  }

  .admin-layout,
  .history-layout,
  .screen-layout {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .answer-grid {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .question-editor,
  .question-list-row {
    grid-template-columns: 1fr;
  }

  .screen-rank-list {
    grid-template-columns: 1fr;
  }
}
