:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1f2a44;
  --muted: #6b7280;
  --accent: #e4572e;
  --accent-ink: #ffffff;
  --guess: #2f6fde;
  --line: #d9d4c7;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.top {
  text-align: center;
  padding: 18px 16px 4px;
}
.top h1 { margin: 0; font-size: 1.7rem; letter-spacing: 0.02em; }
.meta { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 8px 16px 40px;
}

h2 { font-size: 1.05rem; margin: 24px 0 8px; }

.lead {
  text-align: center;
  color: var(--muted);
  margin: 14px 0 8px;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.fact-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.fact-card .frame {
  display: block;
  margin-top: 6px;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
}

.guess-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 18px 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.multiplier {
  display: block;
  text-align: center;
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 36px;
  accent-color: var(--accent);
  margin: 4px 0 0;
}

.scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
}

.direction {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}
.direction button {
  font: inherit;
  font-size: 0.95rem;
  padding: 12px 6px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.direction button[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

button.primary, button.secondary {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 15px;
  font: inherit;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
}
button.primary {
  border: 0;
  background: var(--ink);
  color: #fff;
}
button.primary:disabled { opacity: 0.35; cursor: not-allowed; }
button.secondary {
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
}

/* Results */
.score-box { text-align: center; margin-top: 8px; }
.score { font-size: 3.4rem; font-weight: 800; line-height: 1; color: var(--accent); }
.score-label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; }
.verdict { font-size: 1.15rem; font-weight: 600; margin: 10px 0 0; }

.compare-lines {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-top: 16px;
}
.compare-lines p { margin: 6px 0; }

.numberline {
  position: relative;
  height: 74px;
  margin: 18px 6px 0;
}
.numberline .track {
  position: absolute;
  top: 34px; left: 0; right: 0;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, #cfd8e8, #f0e6d6 50%, #f6cdbf);
}
.numberline .tick {
  position: absolute;
  top: 28px; width: 2px; height: 18px;
  background: var(--muted);
  transform: translateX(-1px);
}
.numberline .marker {
  position: absolute;
  top: 26px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 3px solid #fff;
  transform: translateX(-50%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.numberline .marker span {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.numberline .marker.actual { background: var(--accent); }
.numberline .marker.actual span { top: -22px; color: var(--accent); }
.numberline .marker.guess { background: var(--guess); }
.numberline .marker.guess span { top: 22px; color: var(--guess); }
.numberline .ends {
  position: absolute;
  top: 56px; left: -6px; right: -6px;
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--muted);
}

.placeholder {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 4px 16px 10px;
  margin-top: 20px;
  color: var(--muted);
}
.placeholder h2 { color: var(--ink); margin-top: 12px; }

.detail {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.detail h3 { margin: 0 0 2px; font-size: 1rem; }
.detail .odds { font-weight: 700; color: var(--accent); margin: 0; }
.detail .context { font-size: 0.8rem; color: var(--muted); margin: 0 0 8px; }
.detail p { margin: 6px 0; font-size: 0.95rem; }
.detail a { color: var(--guess); word-break: break-word; }

/* Game switcher */
.tabs {
  display: inline-flex;
  gap: 4px;
  margin: 8px 0 2px;
  padding: 4px;
  border-radius: 999px;
  background: #e9e4d8;
}
.tabs a {
  padding: 6px 16px;
  border-radius: 999px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}
.tabs a[aria-current="page"] { background: var(--ink); color: #fff; }

/* Rank game */
:root { --good: #2e9e5b; --good-bg: #e3f5ea; --miss: #a0452e; --miss-bg: #f6e4dd; }

.instructions { margin: 12px 0 4px; font-size: 0.95rem; }
.frame-note { margin: 0 0 12px; color: var(--muted); font-size: 0.85rem; }

.rank-end {
  text-align: center;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 6px 0;
}

.rank-list, .answer-list { list-style: none; margin: 0; padding: 0; }

.rank-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 8px 8px 8px 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: background 0.25s, border-color 0.25s;
}
.rank-item .pos {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--bg);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
}
.rank-item .text { flex: 1; font-weight: 600; font-size: 0.98rem; line-height: 1.3; }
.rank-item:not(.locked) { cursor: grab; user-select: none; -webkit-user-select: none; }
.rank-item .handle {
  flex: none;
  width: 44px; height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  font-size: 1.3rem;
  cursor: grab;
  touch-action: none; /* finger drags the card instead of scrolling the page */
}
.rank-item.dragging {
  position: relative;
  z-index: 2;
  cursor: grabbing;
  border-color: var(--guess);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  transition: none;
}
.rank-list.is-dragging .rank-item:not(.dragging) { transition: transform 0.15s ease; }
.rank-item.locked { background: var(--good-bg); border-color: var(--good); }
.rank-item.locked .pos { background: var(--good); color: #fff; }
.rank-item.locked .lock { flex: none; width: 44px; text-align: center; color: var(--good); font-weight: 800; font-size: 1.2rem; }
.rank-item.missed .lock { flex: none; width: 44px; text-align: center; color: var(--miss); font-weight: 800; font-size: 1.2rem; }
.rank-item.just-moved { border-color: var(--guess); }
.rank-item.missed { background: var(--miss-bg); border-color: var(--miss); }
.rank-item.missed .pos { background: var(--miss); color: #fff; }
.final-list { margin-bottom: 20px; }
.final-list .rank-item { cursor: default; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 24px;
  width: fit-content;
  max-width: 480px;
  margin: 0 auto;
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  z-index: 10;
}

.feedback { text-align: center; font-weight: 600; min-height: 1.4em; margin: 12px 0 0; }

.error { text-align: center; color: var(--muted); margin: 40px 0; }

.grid {
  font-family: inherit;
  font-size: 1.4rem;
  line-height: 1.25;
  letter-spacing: 2px;
  margin: 10px 0 0;
}

.answer-list .detail { display: flex; gap: 12px; }
.answer-list .detail .pos {
  flex: none;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--line);
  display: grid;
  place-items: center;
  font-weight: 700;
}
.answer-list .detail.got .pos { background: var(--good); color: #fff; }
.answer-list .detail .body { flex: 1; min-width: 0; }

/* Access code screen */
.unlock { display: flex; flex-direction: column; gap: 12px; margin-top: 32px; }
.unlock label { font-weight: 600; text-align: center; }
.unlock input {
  font: inherit;
  font-size: 1.1rem;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  text-align: center;
}
.unlock-error { margin: 0; min-height: 1.4em; text-align: center; color: var(--miss); font-weight: 600; }

/* Shown when all six are ranked correctly */
.celebrate {
  margin: 16px 0;
  padding: 18px 16px;
  text-align: center;
  background: var(--good-bg);
  border: 2px solid var(--good);
  border-radius: var(--radius);
  animation: celebrate-pop 0.5s ease-out;
}
.celebrate .trophy { font-size: 3rem; line-height: 1; }
.celebrate-title { margin: 8px 0 0; font-size: 1.25rem; font-weight: 800; color: var(--good); }
.celebrate-note { margin: 4px 0 0; }
@keyframes celebrate-pop {
  0% { transform: scale(0.85); opacity: 0; }
  70% { transform: scale(1.04); opacity: 1; }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) { .celebrate { animation: none; } }
