:root {
  --paper: #f1ede3;
  --surface: #fbf9f3;
  --surface-soft: #f6f1e7;
  --ink: #1d2620;
  --muted: #6d746b;
  --line: #d8d2c4;
  --line-strong: #bdb5a4;
  --accent: #b9482b;
  --accent-soft: #f4e3dc;
  --green: #2c6748;
  --green-soft: #e3eee6;
  --gold: #c9a227;
  --shadow: 0 24px 60px -32px rgba(29, 38, 32, 0.4);
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua",
    Palatino, Georgia, serif;
  --font-sans: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Roboto Mono",
    Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100svh;
  padding: clamp(14px, 3vw, 32px);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(1100px 680px at 12% -12%, #fcf2d9 0%, transparent 62%),
    radial-gradient(900px 620px at 108% 4%, #e4ede2 0%, transparent 58%),
    var(--paper);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.55;
  background-image:
    linear-gradient(rgba(29, 38, 32, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(29, 38, 32, 0.028) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 35%, black, transparent);
}

button {
  font: inherit;
  color: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.page {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  min-height: calc(100svh - clamp(28px, 6vw, 64px));
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */

.topbar {
  position: sticky;
  top: clamp(8px, 2vw, 20px);
  z-index: 10;
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 13px 18px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  background: rgba(251, 249, 243, 0.86);
  border: 1px solid rgba(216, 210, 196, 0.9);
  border-radius: 999px;
  box-shadow: 0 14px 36px -26px rgba(29, 38, 32, 0.45);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.stat {
  font-size: 0.88rem;
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.stat strong {
  color: var(--ink);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.stat-left {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.stat-center {
  justify-self: center;
  font-variant-numeric: tabular-nums;
}

.history-btn {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.history-btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--muted);
}

.history-btn:hover {
  border-color: var(--line-strong);
  background: #fffdf8;
  transform: translateY(-1px);
}

/* ---------- Stage / question ---------- */

.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(36px, 7vh, 76px) 0 clamp(24px, 5vh, 56px);
}

.screen {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  animation: rise 380ms cubic-bezier(0.2, 0.7, 0.25, 1) both;
}

.question-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.range {
  margin: 0 0 clamp(14px, 2.5vh, 24px);
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.range::before,
.range::after {
  content: "";
  width: 26px;
  height: 1px;
  background: var(--line-strong);
}

.date {
  margin: 0 0 clamp(28px, 5vh, 44px);
  font-family: var(--font-display);
  font-size: clamp(2.55rem, 7.4vw, 4.5rem);
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.answers {
  width: 100%;
  display: grid;
  gap: 10px;
}

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

.answers.symmetric .answer[data-day="0"] {
  grid-column: 1 / -1;
}

.answers.linear {
  grid-template-columns: minmax(0, 1fr);
  max-width: 440px;
  margin: 0 auto;
}

.answers.linear .answer[data-day="0"] {
  order: 0;
}
.answers.linear .answer[data-day="1"] {
  order: 1;
}
.answers.linear .answer[data-day="2"] {
  order: 2;
}
.answers.linear .answer[data-day="3"] {
  order: 3;
}
.answers.linear .answer[data-day="4"] {
  order: 4;
}
.answers.linear .answer[data-day="5"] {
  order: 5;
}
.answers.linear .answer[data-day="6"] {
  order: 6;
}

.answer {
  min-height: 58px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(251, 249, 243, 0.78);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.65) inset;
  cursor: pointer;
  transition:
    border-color 150ms ease,
    background 150ms ease,
    transform 150ms ease,
    box-shadow 150ms ease;
}

.answer:hover {
  border-color: var(--line-strong);
  background: #fffdf8;
  transform: translateY(-2px);
  box-shadow: 0 9px 22px -16px rgba(29, 38, 32, 0.6);
}

.answer:active {
  transform: translateY(0);
  box-shadow: none;
}

.day-num {
  width: 21px;
  height: 21px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
}

.day-dash {
  margin: 0 7px;
  color: var(--line-strong);
  font-size: 0.75rem;
  white-space: pre;
}

.day-name {
  font-size: 0.98rem;
  font-weight: 560;
  letter-spacing: -0.012em;
}

.controls {
  width: 100%;
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 520;
  cursor: pointer;
  transition:
    color 150ms ease,
    background 150ms ease,
    border-color 150ms ease;
}

.ctrl-btn:hover {
  color: var(--ink);
  background: rgba(251, 249, 243, 0.7);
  border-color: var(--line);
}

.layout-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.25;
  stroke-linejoin: round;
}

.arrow {
  font-size: 0.95em;
  transition: transform 150ms ease;
}

.ctrl-btn:hover .arrow,
.text-link:hover .arrow {
  transform: translateX(2px);
}

.text-link {
  margin-top: clamp(26px, 4vh, 40px);
  padding: 7px 2px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-bottom: 1px solid var(--line-strong);
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 520;
  cursor: pointer;
  transition:
    color 150ms ease,
    border-color 150ms ease;
}

.text-link:hover {
  color: var(--ink);
  border-color: var(--ink);
}

/* ---------- Result ---------- */

.result-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.status {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid #bfd8c8;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  line-height: 1;
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status.incorrect {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: #e8c7bb;
}

.picked {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.87rem;
}

.result-prompt {
  margin: clamp(26px, 5vh, 42px) 0 14px;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 3.4vw, 1.85rem);
  letter-spacing: -0.02em;
  color: var(--muted);
}

.answer-card {
  padding: clamp(20px, 4vw, 32px) clamp(28px, 6vw, 52px);
  border-radius: 18px;
  background:
    linear-gradient(140deg, rgba(255, 255, 255, 0.07), transparent 55%),
    var(--ink);
  color: #fbf9f3;
  box-shadow:
    0 26px 50px -30px rgba(29, 38, 32, 0.85),
    0 1px 0 rgba(255, 255, 255, 0.12) inset;
  font-family: var(--font-display);
  font-size: clamp(2rem, 5.6vw, 3.1rem);
  line-height: 1.1;
  letter-spacing: -0.025em;
  position: relative;
  overflow: hidden;
}

.answer-card::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--gold);
  opacity: 0.9;
}

.answer-num {
  color: #d8bd72;
  font-family: var(--font-mono);
  font-size: 0.55em;
  letter-spacing: 0;
  vertical-align: 0.12em;
}

.elapsed {
  margin: 18px 0 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

.divider {
  width: 100%;
  height: 1px;
  margin: clamp(28px, 5vh, 42px) 0 clamp(24px, 4vh, 34px);
  border: none;
  background: var(--line);
}

.primary-btn {
  min-width: 210px;
  padding: 13px 24px;
  border: 1px solid var(--ink);
  border-radius: 12px;
  background: var(--ink);
  color: var(--surface);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition:
    transform 150ms ease,
    background 150ms ease,
    box-shadow 150ms ease;
}

.primary-btn:hover {
  background: #2b372f;
  transform: translateY(-2px);
  box-shadow: 0 12px 24px -16px rgba(29, 38, 32, 0.9);
}

.primary-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

/* ---------- Dialogs ---------- */

.modal {
  width: min(760px, calc(100vw - 28px));
  max-width: none;
  max-height: calc(100dvh - 28px);
  margin: auto;
  padding: 0;
  border: none;
  border-radius: 24px;
  background: transparent;
  color: var(--ink);
  overflow: visible;
}

.how-modal {
  width: min(700px, calc(100vw - 28px));
}

.modal::backdrop {
  background: rgba(21, 27, 23, 0.52);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.modal[open] .modal-shell {
  animation: pop 260ms cubic-bezier(0.2, 0.8, 0.25, 1) both;
}

.modal-shell {
  max-height: calc(100dvh - 28px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 24px 26px 20px;
}

.eyebrow {
  margin: 0 0 5px;
  font-family: var(--font-mono);
  font-size: 0.63rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.modal-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 3.4vw, 2rem);
  font-weight: 400;
  letter-spacing: -0.03em;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition:
    color 150ms ease,
    background 150ms ease,
    border-color 150ms ease;
}

.icon-btn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
}

.icon-btn:hover {
  color: var(--ink);
  background: var(--surface-soft);
  border-color: var(--line-strong);
}

.clear-btn {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 550;
  cursor: pointer;
  transition:
    color 150ms ease,
    background 150ms ease,
    border-color 150ms ease;
}

.clear-btn:hover {
  color: var(--accent);
  border-color: #e1bfb4;
  background: rgba(185, 72, 43, 0.06);
}

/* History summary */

.summary {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0 26px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  overflow: hidden;
}

.summary-item {
  padding: 13px 15px;
  border-left: 1px solid var(--line);
}

.summary-item:first-child {
  border-left: none;
}

.summary-label {
  margin: 0 0 5px;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.summary-value {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.98rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.summary-value small {
  margin-left: 4px;
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--muted);
}

.history-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 20px 26px 24px;
}

.history-list-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 0.59rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.history-list {
  min-height: 150px;
  max-height: min(43dvh, 380px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--line);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 68px;
  align-items: center;
  gap: 12px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
}

.history-row:last-child {
  border-bottom: none;
}

.history-date {
  min-width: 0;
  font-family: var(--font-display);
  font-size: 0.98rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta {
  margin-top: 2px;
  font-size: 0.67rem;
  color: var(--muted);
}

.outcome {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.57rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.outcome.correct {
  color: var(--green);
  background: var(--green-soft);
}

.outcome.incorrect {
  color: var(--accent);
  background: var(--accent-soft);
}

.outcome.skipped {
  color: var(--muted);
  background: #ece7da;
}

.history-time {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.history-empty {
  padding: 42px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.87rem;
  line-height: 1.55;
}

/* Walkthrough */

.how-content {
  min-height: 0;
  padding: 0 26px 28px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.how-date {
  margin: 0 0 18px;
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
  font-family: var(--font-display);
  font-size: 1.14rem;
  letter-spacing: -0.015em;
}

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: step;
}

.steps li {
  position: relative;
  padding: 0 0 18px 38px;
  counter-increment: step;
  font-size: 0.86rem;
  line-height: 1.58;
  color: #3d463f;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 23px;
  height: 23px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--muted);
}

.steps li::after {
  content: "";
  position: absolute;
  left: 11px;
  top: 27px;
  bottom: 1px;
  width: 1px;
  background: var(--line);
}

.steps li:last-child {
  padding-bottom: 0;
}

.steps li:last-child::after {
  display: none;
}

.steps strong {
  color: var(--ink);
  font-weight: 650;
}

.calc {
  display: inline-block;
  margin: 3px 0;
  padding: 2px 7px;
  border-radius: 5px;
  background: #ece7da;
  font-family: var(--font-mono);
  font-size: 0.82em;
  color: var(--ink);
}

.how-final {
  margin-top: 20px;
  padding: 15px 17px;
  border-radius: 12px;
  background: var(--ink);
  color: #fbf9f3;
  font-size: 0.88rem;
  line-height: 1.5;
}

.how-final strong {
  color: #e1c67a;
  font-weight: 600;
}

.reference {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.reference h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.02rem;
  font-weight: 400;
  letter-spacing: -0.01em;
}

.reference p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.5;
}

.doomsday-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
  gap: 6px;
}

.dd-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--muted);
  white-space: nowrap;
}

.dd-item strong {
  color: var(--ink);
  font-weight: 600;
}

/* ---------- Focus / motion ---------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 620px) {
  .topbar {
    gap: 8px;
    padding: 11px 14px;
  }

  .stat {
    font-size: 0.79rem;
  }

  .history-btn {
    padding: 6px 10px;
    font-size: 0.72rem;
  }

  .history-btn svg {
    width: 14px;
    height: 14px;
  }

  .stage {
    padding-top: 40px;
  }

  .date {
    margin-bottom: 30px;
  }

  .answer {
    min-height: 54px;
  }

  .day-name {
    font-size: 0.92rem;
  }

  .summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 0 18px;
  }

  .summary-item {
    padding: 11px 13px;
  }

  .summary-item:nth-child(3) {
    border-left: none;
  }

  .summary-item:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }

  .modal-head {
    padding: 20px 18px 16px;
  }

  .history-body {
    padding: 16px 18px 20px;
  }

  .how-content {
    padding: 0 18px 22px;
  }

  .history-list {
    max-height: 40dvh;
  }
}

@media (max-width: 420px) {
  body {
    padding: 10px;
  }

  .page {
    min-height: calc(100svh - 20px);
  }

  .topbar {
    border-radius: 18px;
    grid-template-columns: auto 1fr auto;
  }

  .stat-left {
    gap: 4px;
  }

  .history-btn {
    padding: 6px 9px;
    gap: 5px;
  }

  .history-btn svg {
    display: none;
  }

  .date {
    font-size: clamp(2.35rem, 11.5vw, 3rem);
  }

  .answers {
    gap: 8px;
  }

  .answer {
    padding: 9px 8px;
  }

  .day-dash {
    margin: 0 5px;
  }

  .day-num {
    width: 19px;
    height: 19px;
  }

  .status {
    letter-spacing: 0.14em;
  }

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

  .history-time {
    grid-column: 2;
    grid-row: 1;
  }

  .history-row .outcome {
    grid-column: 1;
    grid-row: 2;
    justify-self: start;
    margin-top: 3px;
  }

  .history-date {
    grid-column: 1;
    grid-row: 1;
  }

  .modal {
    width: calc(100vw - 20px);
  }

  .modal-shell {
    border-radius: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
