:root {
  --bg: #0e0f0c;
  --panel: #16170f;
  --panel-2: #1d1f15;
  --line: #2d2f22;
  --text: #ece7d2;
  --muted: #8f8b74;
  --amber: #ffb400;
  --red: #ff4a32;
  --green: #7fdc8a;
  --radius: 14px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --stencil: 'Saira Stencil One', 'Impact', 'Arial Black', sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 50% -200px, #2a210a55, transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button, select { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

.hazard {
  height: 8px;
  background: repeating-linear-gradient(-45deg, var(--amber) 0 14px, #111 14px 28px);
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Header */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
h1 {
  font-family: var(--stencil);
  font-weight: 400;
  font-size: clamp(34px, 9vw, 52px);
  line-height: 1;
  margin: 0;
  letter-spacing: 0.04em;
  color: var(--amber);
}
.blink { animation: blink 1.1s steps(1) infinite; color: var(--red); }
@keyframes blink { 50% { opacity: 0; } }
.sub { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

/* Buttons */
.ghost, .primary {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  white-space: nowrap;
}
.ghost:hover { border-color: var(--muted); }
.primary { background: var(--amber); color: #120f00; border-color: var(--amber); font-weight: 800; }
.primary:hover { filter: brightness(1.08); }
.ghost small, .primary small { opacity: 0.6; font-size: 11px; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 8px; }
button:focus-visible, select:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* Century range */
.controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.controls label { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase; }
.controls select {
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 16px; /* prevents iOS zoom on focus */
  text-transform: none;
  letter-spacing: 0;
  width: 100%;
}
.dash { color: var(--muted); padding-bottom: 10px; }

/* Cards */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.target { text-align: center; position: relative; overflow: hidden; }
.target-head { display: flex; justify-content: space-between; align-items: center; }
.tag { font-size: 11px; letter-spacing: 0.2em; color: var(--muted); }
.timer { font-variant-numeric: tabular-nums; color: var(--amber); font-weight: 600; }
.date {
  font-family: var(--stencil);
  font-size: clamp(30px, 9.5vw, 58px);
  line-height: 1.1;
  margin: 14px 0 4px;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}
.date .yr { color: var(--amber); }
.date-iso { color: var(--muted); font-size: 13px; }
.hints { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.hints:empty { display: none; }
.hint { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--panel-2); border-left: 3px solid var(--amber); text-align: left; }

/* Day buttons */
.days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.day {
  min-height: 72px;
  padding: 8px 2px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform 0.08s, border-color 0.15s, background 0.15s;
  user-select: none;
}
.day:active { transform: scale(0.96); }
.day:hover:not(:disabled) { border-color: var(--amber); }
.day .num { font-size: 11px; color: var(--muted); }
.day .abbr { font-weight: 800; font-size: 15px; letter-spacing: 0.04em; }
.day .cw { font-size: 10px; color: var(--muted); }
.day:disabled { cursor: default; opacity: 0.45; }
.day.correct { opacity: 1; background: #12301a; border-color: var(--green); color: var(--green); }
.day.wrong { opacity: 1; background: #3a1410; border-color: var(--red); color: var(--red); }

.actions { display: flex; gap: 10px; justify-content: space-between; }
.actions button { flex: 1; }

/* Result */
.result.ok { border-color: var(--green); }
.result.bad { border-color: var(--red); }
.verdict { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.verdict h2 { font-family: var(--stencil); font-weight: 400; margin: 0; font-size: 28px; letter-spacing: 0.03em; }
.result.ok .verdict h2 { color: var(--green); }
.result.bad .verdict h2 { color: var(--red); }
.verdict .meta { color: var(--muted); font-size: 13px; }
.verdict-line { margin: 6px 0 0; }

.working { margin-top: 14px; }
.working summary { cursor: pointer; color: var(--amber); padding: 6px 0; min-height: 32px; }
.solve { display: grid; grid-template-columns: 1fr; gap: 16px; margin-top: 10px; }
@media (min-width: 640px) {
  .solve { grid-template-columns: 1fr 200px; align-items: start; }
}
.steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; counter-reset: s; }
.steps li { position: relative; padding-left: 38px; }
.steps li::before {
  counter-increment: s;
  content: counter(s);
  position: absolute; left: 0; top: 0;
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800; font-size: 13px;
  background: var(--amber); color: #120f00;
}
.steps h4 { margin: 0 0 2px; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.steps p { margin: 2px 0; }
.calc { font-variant-numeric: tabular-nums; background: var(--panel-2); border-radius: 8px; padding: 6px 10px; margin: 6px 0; display: block; overflow-x: auto; }
.hl { color: var(--amber); font-weight: 600; }
.ans { color: var(--green); font-weight: 800; }
.err { color: var(--red); font-weight: 800; }

.dial { width: 100%; max-width: 220px; margin: 0 auto; display: block; }
.dial text { font-family: var(--mono); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; justify-content: center; font-size: 11px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  align-items: center;
  border-top: 1px dashed var(--line);
  padding-top: 12px;
}
.stats div { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.stats b { font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats b small { font-size: 12px; color: var(--muted); font-weight: 600; }
.stats span { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.stats-actions { display: flex; justify-content: center; gap: 12px; margin-top: -8px; }
.stats-actions .link { font-size: 13px; }
#statsBtn { color: var(--amber); }

/* Detailed stats */
.stats-panel h2 { font-family: var(--stencil); font-weight: 400; color: var(--amber); margin: 0 0 10px; font-size: 26px; text-transform: uppercase; letter-spacing: 0.03em; }
.stats-panel h3 { margin: 20px 0 8px; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.stats-panel p.muted { margin: 6px 0; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; min-width: 0; }
.tile .k { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.tile b { font-size: 22px; font-variant-numeric: tabular-nums; line-height: 1.3; }
.tile b small { font-size: 14px; color: var(--muted); }
.tile > small { font-size: 11px; color: var(--muted); line-height: 1.35; }

.recent {
  position: relative;
  height: 96px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  border-bottom: 1px solid var(--line);
}
.recent .bar { flex: 1; min-width: 2px; max-width: 14px; border-radius: 3px 3px 0 0; }
.bar.ok { background: var(--green); }
.bar.bad { background: repeating-linear-gradient(-45deg, var(--red) 0 3px, #a8301f 3px 6px); }
.recent .bar.cut { border-radius: 0; box-shadow: inset 0 3px 0 var(--text); }
.avgline { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--amber); pointer-events: none; }
.avgline em { position: absolute; right: 0; bottom: 2px; font-style: normal; font-size: 10px; color: var(--amber); background: var(--panel); padding: 0 4px; }
.legend.left { justify-content: flex-start; margin-top: 8px; }
.legend i.miss { background: repeating-linear-gradient(-45deg, var(--red) 0 2px, #a8301f 2px 4px); border-radius: 2px; }

.offby { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; height: 110px; }
.offby .col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; min-height: 0; }
.offby .col b { font-size: 12px; font-variant-numeric: tabular-nums; }
.offby .bar { width: 60%; max-width: 36px; border-radius: 3px 3px 0 0; min-height: 0; }
.offby .col small { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); width: 100%; text-align: center; padding-top: 2px; }

.bds { display: grid; grid-template-columns: 1fr; column-gap: 24px; }
@media (min-width: 640px) { .bds { grid-template-columns: 1fr 1fr; } }
.bd { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.bd th, .bd td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.bd thead th { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.bd tbody th { color: var(--muted); font-weight: 600; }
.bd .n, .bd .t, .bd .pc { text-align: right; }
.bd .acc { width: 100%; }
.bd .acc .pc { display: inline-block; width: 3.5em; }
.bd tr.none { opacity: 0.4; }
.bd.causes th { white-space: normal; }
.meter { display: inline-block; vertical-align: middle; width: calc(100% - 3.8em); min-width: 40px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--green); border-radius: 3px; }
.flag { display: inline-block; margin-left: 6px; padding: 0 5px; border-radius: 4px; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; border: 1px solid var(--amber); color: var(--amber); }
.flag.bad { border-color: var(--red); color: var(--red); }

/* Manual */
.manual h2 { font-family: var(--stencil); font-weight: 400; color: var(--amber); margin: 0 0 8px; font-size: 26px; }
.manual h3 { margin: 18px 0 6px; font-size: 14px; letter-spacing: 0.06em; }
.manual p { margin: 6px 0; }
.muted { color: var(--muted); font-size: 13px; }
code { color: var(--amber); }
.mini { margin: 6px 0; padding-left: 22px; }
.tbl { border-collapse: collapse; width: 100%; font-size: 13px; }
.tbl th, .tbl td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { color: var(--muted); font-weight: 600; }

/* Drill switch */
.modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.modes button {
  min-height: 40px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
}
.modes button:hover:not([aria-pressed="true"]) { color: var(--text); }
.modes button[aria-pressed="true"] { background: var(--amber); color: #120f00; font-weight: 800; }

/* Offset drill */
.day.offset .abbr { font-size: 20px; font-variant-numeric: tabular-nums; }
.day .cw.keep { display: block; font-size: 11px; }
.solve.single { grid-template-columns: 1fr; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip {
  min-width: 34px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.chip.zero { color: var(--muted); border-style: dashed; }
.chip.on { border-color: var(--amber); color: var(--amber); font-weight: 800; }

/* Month code drill: the full code table on a miss */
.codes { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 10px 0 4px; }
.chip.code { display: flex; flex-direction: column; align-items: center; font-weight: 800; font-size: 16px; padding: 4px 2px; min-width: 0; }
.chip.code small { font-size: 10px; font-weight: 600; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.chip.code.on small { color: var(--amber); }
/* Add method under the full-date working */
.addm { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.addm h4 { margin: 0 0 2px; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.addm p { margin: 2px 0; }

@media (max-width: 480px) {
  body { font-size: 14px; }
  .card { padding: 14px; }
  .days { gap: 4px; }
  .day { min-height: 64px; border-radius: 10px; }
  .day .cw { display: none; }
  .day .abbr { font-size: 13px; }
  .tbl.months th, .tbl.months td { padding: 6px 4px; }
  .top { gap: 8px; }
  .top .ghost { padding: 8px 12px; font-size: 13px; }
  .stats b { font-size: 16px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .bd th, .bd td { padding: 4px 3px; }
}

/* keyboard shortcut labels only matter with a keyboard */
@media (hover: none) {
  .ghost small, .primary small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .blink { animation: none; }
  .day { transition: none; }
}
