:root {
  --bg: #10161d;
  --surface: #151e27;
  --surface-strong: #0b1117;
  --panel: #f8fbfc;
  --panel-soft: #edf3f6;
  --text: #18222d;
  --page-text: #eef6fa;
  --muted: #687681;
  --line: #c7d3db;
  --line-dark: rgba(238, 246, 250, 0.18);
  --brand: #df2634;
  --brand-strong: #b81827;
  --accent: #39c8f2;
  --track: #121a22;
  --danger: #b42318;
  --ok: #1f7a5a;
  --shadow: 0 22px 44px rgba(3, 8, 13, 0.28);
}

* { box-sizing: border-box; }

body {
  display: flex;
  flex-direction: column;
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background:
    linear-gradient(135deg, rgba(57, 200, 242, 0.16), transparent 34%, rgba(223, 38, 52, 0.14)),
    linear-gradient(180deg, #17222d 0%, var(--bg) 58%, #0b1117 100%);
}

a { color: var(--brand); }
a:hover { color: var(--brand-strong); }

.site-header {
  border-bottom: 1px solid var(--line-dark);
  background: rgba(11, 17, 23, 0.88);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.wrap {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 68px;
}

.brand {
  font-weight: 800;
  font-size: 1.25rem;
  text-decoration: none;
  color: var(--accent);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.nav a, .nav button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--page-text);
  border-radius: 999px;
  padding: 8px 11px;
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}

.nav a:hover, .nav button:hover {
  border-color: var(--line-dark);
  background: rgba(238, 246, 250, 0.08);
  color: #fff;
}

main.wrap {
  flex: 1;
  padding: 24px 0 44px;
}

.play-hero {
  display: block;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  margin-top: 18px;
  padding: 34px;
}

.home-summary-panel {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: minmax(260px, 0.8fr) minmax(420px, 1fr);
  gap: 28px;
  align-items: end;
  padding: 24px 28px;
}

.home-summary-copy h1 {
  margin: 0 0 14px;
  font-size: 3rem;
  line-height: 1.02;
}

.home-summary-copy > p:last-child {
  max-width: 56ch;
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.45;
}

.home-summary-stock h2 {
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.start-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  max-width: 720px;
  margin-top: 0;
}

.question-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.preset-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  padding: 6px 10px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.preset-button:hover,
.preset-button.active {
  border-color: var(--brand);
  background: #fff1f2;
  color: var(--brand-strong);
}

.start-form .btn {
  min-height: 48px;
}

.field-questions input {
  max-width: 180px;
}

.field-mode select {
  max-width: 420px;
}

.check-option {
  display: inline-flex;
  align-items: flex-start;
  gap: 11px;
  max-width: 520px;
  margin: 0;
  padding: 2px 0;
  color: var(--text);
  cursor: pointer;
}

.check-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.check-mark {
  position: relative;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex: 0 0 auto;
  border: 1px solid #8fa2af;
  border-radius: 5px;
  background: #fff;
  box-shadow: inset 0 0 0 2px #fff;
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.check-mark::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  opacity: 0;
  transform: rotate(45deg) scale(0.8);
  transition: opacity 140ms ease, transform 140ms ease;
}

.check-option input:checked + .check-mark {
  border-color: #0f7d93;
  background: #0f7d93;
  box-shadow: inset 0 0 0 2px #0f7d93;
}

.check-option input:checked + .check-mark::after {
  opacity: 1;
  transform: rotate(45deg) scale(1);
}

.check-option input:focus-visible + .check-mark {
  outline: 3px solid rgba(57, 200, 242, 0.28);
  outline-offset: 3px;
}

.check-copy {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  min-width: 0;
  line-height: 1.28;
}

.check-title {
  display: block;
  font-weight: 800;
}

.check-help {
  display: block;
  color: var(--muted);
  font-size: 0.93rem;
  font-weight: 500;
}

.start-actions {
  display: flex;
  justify-content: flex-start;
  padding-top: 4px;
}

.start-actions .btn {
  min-width: 172px;
}

.info-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.7fr);
  gap: 18px;
  margin-top: 0;
  align-items: stretch;
}

.leaderboard-panel {
  margin-top: 18px;
}

.leaderboard-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.leaderboard-filter label {
  margin: 0;
}

.leaderboard-filter select {
  width: auto;
  min-width: 180px;
}

.leaderboard-dedupe-option {
  align-items: center;
  max-width: none;
  min-height: 43px;
}

.leaderboard-dedupe-option .check-mark {
  margin-top: 0;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 18px;
  align-items: start;
}

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

.panel-quiet {
  box-shadow: none;
}

.panel + .panel { margin-top: 16px; }

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

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

.form-grid {
  display: grid;
  gap: 14px;
}

label {
  display: block;
  font-weight: 700;
  margin-bottom: 5px;
}

.field-help {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

input[type="text"], input[type="password"], input[type="email"], input[type="number"], input[type="file"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.choice-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice-list label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  font-weight: 600;
  background: #fff;
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--brand-strong);
  background: var(--brand);
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  color: #fff;
  background: var(--brand-strong);
}

.btn.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

.btn.secondary:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.message {
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 10px 12px;
  background: #fff;
}

.message.error { border-color: #f0b8b2; color: var(--danger); }
.message.success { border-color: #b7dcc9; color: var(--ok); }

.errorlist {
  margin: 7px 0 0;
  padding-left: 18px;
  color: var(--danger);
  font-weight: 700;
}

.leaderboard, .data-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard th, .leaderboard td, .data-table th, .data-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 6px;
  text-align: left;
  vertical-align: top;
}

.sort-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: inherit;
  text-decoration: none;
}

.sort-link:hover {
  color: var(--brand-strong);
}

.sort-link.active::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 6px solid currentColor;
}

.sort-link.active.asc::after {
  transform: rotate(180deg);
}

.quiz-image {
  width: 100%;
  max-height: 64vh;
  object-fit: contain;
  background: #10201c;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: zoom-in;
  user-select: none;
  -webkit-user-drag: none;
}

.question-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.question-header h1 {
  margin-bottom: 6px;
}

.question-nav-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.answer-form {
  margin-top: 14px;
}

.question-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.question-strip a {
  min-width: 36px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  background: #fff;
  text-decoration: none;
}

.question-strip a.done { background: #e2f3e9; color: var(--ok); border-color: #b7dcc9; }
.question-strip a.current { background: var(--brand); color: #fff; }

.question-strip .question-finish {
  border-color: var(--brand);
  color: var(--brand-strong);
  font-weight: 800;
  padding-inline: 14px;
}

.question-strip .question-finish:hover {
  background: var(--brand);
  color: #fff;
}

.station-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-soft);
  margin-bottom: 10px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

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

.home-stock-metrics {
  grid-template-columns: minmax(180px, 320px);
}

.metric {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 12px;
}

.metric strong {
  display: block;
  font-size: 1.6rem;
}

.table-action {
  padding: 7px 10px;
  white-space: nowrap;
}

.site-footer {
  border-top: 1px solid var(--line-dark);
  color: rgba(238, 246, 250, 0.78);
  background: rgba(11, 17, 23, 0.94);
  padding: 16px 0;
}

.site-footer .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  justify-content: space-between;
  align-items: center;
  font-size: 0.92rem;
}

.image-overlay[hidden] {
  display: none;
}

.image-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-rows: auto 1fr;
  background: rgba(5, 9, 14, 0.96);
  color: var(--page-text);
}

.image-overlay-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--line-dark);
  background: rgba(11, 17, 23, 0.92);
}

.image-overlay .btn.secondary {
  background: rgba(238, 246, 250, 0.08);
  border-color: var(--line-dark);
  color: var(--page-text);
}

.image-overlay .btn.secondary:hover {
  background: rgba(238, 246, 250, 0.16);
  color: #fff;
}

.image-overlay-stage {
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.image-overlay-stage.dragging {
  cursor: grabbing;
}

.image-overlay-stage img {
  max-width: 96vw;
  max-height: calc(100vh - 92px);
  object-fit: contain;
  transform-origin: center;
  user-select: none;
  pointer-events: none;
  will-change: transform;
}

body.overlay-open {
  overflow: hidden;
}

@media (max-width: 800px) {
  .site-header .wrap { align-items: flex-start; flex-direction: column; padding: 12px 0; }
  .nav { margin-left: 0; }
  .grid { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
  .home-summary-panel { grid-template-columns: 1fr; padding: 22px; }
  .home-summary-copy h1 { font-size: 2.2rem; }
  .play-hero { padding: 22px; }
  .question-header { flex-direction: column; }
  .question-nav-buttons { justify-content: flex-start; }
  .start-actions { justify-content: stretch; }
  .start-actions .btn { width: 100%; }
  .metrics-inline { grid-template-columns: 1fr; }
}
