:root {
  --bg: #FFFFFF;
  --ink: #16161A;
  --muted: #4A4A50;
  --faint: #6A6A70;
  --tile: #F4F4F1;
  --tile-hover: #ECECE7;
  --line: #DCDCD5;
  --rule: #EDEDE8;
  --off: #DCDCD5;
  --red: #E5484D;

  --yellow: #E9B949;
  --green: #5FAF7A;
  --blue: #5B8DEF;
  --purple: #9B6BD3;
  --yellow-band: #F3D27A;
  --green-band: #A3D7B1;
  --blue-band: #B3CBF6;
  --purple-band: #D3BDEE;
  --yellow-tint: #FCF6E6;
  --green-tint: #EEF7F1;
  --blue-tint: #EEF3FD;
  --purple-tint: #F4EFFB;

  --radius: 12px;
  --tile-h: 80px;
  --tile-size: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Instrument Sans', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* Header */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 4px 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
  min-height: 44px;
}
.mark { width: 20px; height: 20px; flex: none; overflow: visible; }
.mark .bar { fill: var(--off); transition: fill 0.5s ease; }
.mark .bar.on[data-color="yellow"] { fill: var(--yellow); }
.mark .bar.on[data-color="green"] { fill: var(--green); }
.mark .bar.on[data-color="blue"] { fill: var(--blue); }
.mark .bar.on[data-color="purple"] { fill: var(--purple); }
.mark .line { fill: var(--ink); }
.mark.full .bar[data-color="yellow"] { fill: var(--yellow); }
.mark.full .bar[data-color="green"] { fill: var(--green); }
.mark.full .bar[data-color="blue"] { fill: var(--blue); }
.mark.full .bar[data-color="purple"] { fill: var(--purple); }

.nav { display: flex; }
.nav button {
  border: 0;
  background: transparent;
  min-width: 44px;
  height: 44px;
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  font-size: 14px;
  font-weight: 500;
}
.nav button:hover { background: var(--tile); }
.nav svg { width: 20px; height: 20px; fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.nav span { display: none; }

/* Main column */
.app {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 4px 16px 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.dateline { margin: 0; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.lede { margin: -10px 0 0; font-size: 15px; color: var(--muted); }

/* Solved bands */
.bands { display: flex; flex-direction: column; gap: 8px; }
.bands:empty { display: none; }
.band {
  border-radius: var(--radius);
  padding: 11px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  animation: rise 0.45s cubic-bezier(.2,.8,.2,1);
}
.band[data-color="yellow"] { background: var(--yellow-band); }
.band[data-color="green"] { background: var(--green-band); }
.band[data-color="blue"] { background: var(--blue-band); }
.band[data-color="purple"] { background: var(--purple-band); }
.band-head { display: flex; justify-content: space-between; gap: 12px; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
.band-head .years { white-space: nowrap; font-variant-numeric: tabular-nums; }
.band-cards { font-size: 14px; color: rgba(22,22,26,0.78); }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* Tiles */
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tile {
  height: var(--tile-h);
  border: 0;
  border-radius: var(--radius);
  background: var(--tile);
  color: var(--ink);
  padding: 4px 5px;
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s, transform 0.15s;
  overflow: hidden;
}
.tile span { display: block; font-size: var(--tile-size); overflow-wrap: normal; word-break: keep-all; hyphens: manual; }
.tile:hover { background: var(--tile-hover); }
.tile[aria-pressed="true"] { background: var(--ink); color: #fff; transform: scale(0.97); }
.tile.jump { animation: jump 0.32s ease; }
.tile.shake, .mark.shake { animation: shake 0.42s ease; }
.tile.leaving { animation: leave 0.3s ease forwards; }
@keyframes jump { 40% { transform: translateY(-6px) scale(0.97); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes leave { to { opacity: 0; transform: scale(0.9); } }

/* Mistakes + controls */
.mistakes { display: flex; justify-content: center; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.mistakes .pips { display: flex; gap: 5px; }
.mistakes .pip { width: 20px; height: 5px; border-radius: 3px; background: #E4E4DE; transition: background 0.3s; }
.mistakes .pip.used { background: var(--red); }
.controls { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.btn {
  height: 48px;
  padding: 0 18px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 15px;
  font-weight: 500;
}
.btn:hover:not(:disabled) { background: var(--tile); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; padding: 0 26px; }
.btn.primary:hover:not(:disabled) { background: #2C2C33; }
.btn:disabled { opacity: 0.4; }
.btn.wide { flex: 1; }

/* Timeline */
.timeline { margin: auto 0 0; display: flex; flex-direction: column; gap: 6px; }
.track { position: relative; height: 36px; }
.track.big { height: 76px; }
.track .era { position: absolute; top: 0; bottom: 0; border-radius: 8px; background: var(--tile); }
.track .break { position: absolute; top: 0; bottom: 0; width: 3%; display: grid; place-items: center; }
.track .break svg { width: 10px; height: 20px; fill: none; stroke: #B9B9B2; stroke-width: 1.5; stroke-linecap: round; }
.track .span {
  position: absolute;
  top: 7px;
  bottom: 7px;
  min-width: 6px;
  border-radius: 5px;
  animation: grow 0.5s cubic-bezier(.2,.8,.2,1);
  transform-origin: left center;
}
.track.big .span { top: 12px; bottom: 12px; }
.span[data-color="yellow"] { background: var(--yellow); }
.span[data-color="green"] { background: var(--green); }
.span[data-color="blue"] { background: var(--blue); }
.span[data-color="purple"] { background: var(--purple); }
@keyframes grow { from { transform: scaleX(0); opacity: 0; } }
.ticks { position: relative; height: 26px; line-height: 12px; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.ticks span:first-child { transform: none; }
.ticks span:last-child { transform: translateX(-100%); }

/* Results */
.result-head { display: flex; flex-direction: column; gap: 4px; }
.result-head h2 { margin: 0; font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.result-head p { margin: 0; font-size: 15px; color: var(--muted); }
.depth { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.shovels { display: inline-flex; gap: 2px; }
.shovel { width: 18px; height: 18px; color: var(--ink); }
.shovel.off { color: #D6D6CF; }
.results { display: flex; flex-direction: column; gap: 10px; }
.result {
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.result[data-color="yellow"] { background: var(--yellow-tint); }
.result[data-color="green"] { background: var(--green-tint); }
.result[data-color="blue"] { background: var(--blue-tint); }
.result[data-color="purple"] { background: var(--purple-tint); }
.result h3 { margin: 0 0 2px; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
.result h3 .label { display: flex; align-items: baseline; gap: 8px; }
.result h3 .dot { flex: none; width: 10px; height: 10px; border-radius: 3px; }
.result[data-color="yellow"] .dot { background: var(--yellow); }
.result[data-color="green"] .dot { background: var(--green); }
.result[data-color="blue"] .dot { background: var(--blue); }
.result[data-color="purple"] .dot { background: var(--purple); }
.result h3 .years { white-space: nowrap; font-variant-numeric: tabular-nums; }
.row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.row .when { color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.fact { margin: 2px 0 0; padding-top: 7px; border-top: 1px solid rgba(22,22,26,0.08); font-size: 13.5px; color: var(--muted); }
.note { margin: 0; font-size: 12.5px; color: var(--faint); }
.note.anniversary { color: var(--ink); font-weight: 500; }
.after { text-align: center; margin: 0; font-size: 13px; color: var(--faint); }

/* Hint popover */
.hint {
  position: fixed;
  z-index: 20;
  max-width: 260px;
  background: var(--ink);
  color: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 6px 20px rgba(22,22,26,0.18);
  pointer-events: none;
}
.hint strong { display: block; font-weight: 600; margin-bottom: 2px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  top: calc(12px + env(safe-area-inset-top));
  transform: translate(-50%, -12px);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Sheets */
.sheet {
  border: 0;
  padding: 0;
  margin: auto auto 0;
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  border-radius: 20px 20px 0 0;
  background: var(--bg);
  color: var(--ink);
}
.sheet::backdrop { background: rgba(22,22,26,0.32); }
.sheet[open] { animation: up 0.25s cubic-bezier(.2,.8,.2,1); }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet-inner { padding: 14px 20px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 18px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.close { width: 44px; height: 44px; border: 0; border-radius: 22px; background: var(--tile); display: grid; place-items: center; }
.close svg { width: 16px; height: 16px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.sheet-body { display: flex; flex-direction: column; gap: 20px; }

.stat-row { margin: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat-row div { display: flex; flex-direction: column; gap: 2px; }
.stat-row dd { order: -1; }
.stat-row dt { font-size: 12px; color: var(--faint); line-height: 1.2; }
.stat-row dd { margin: 0; font-size: 30px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.dist { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.dist figcaption { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.dist .bar-row { display: grid; grid-template-columns: 56px minmax(0, 1fr); align-items: center; gap: 10px; }
.dist .bar-label { font-size: 12px; color: var(--muted); }
.dist .bar { height: 24px; min-width: 24px; border-radius: 6px; background: #E4E4DE; padding-right: 8px; display: flex; justify-content: flex-end; align-items: center; font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
.dist .bar.hi { background: var(--ink); color: #fff; }
.tiles2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mini { border-radius: 12px; background: var(--tile); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.mini.purple { background: var(--purple-tint); }
.mini b { font-size: 22px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.mini span { font-size: 13px; color: var(--muted); }
.small { margin: 0; font-size: 12px; color: var(--faint); text-align: center; }
.link-btn { align-self: center; border: 0; background: none; min-height: 44px; padding: 0 12px; font-size: 13px; color: var(--faint); text-decoration: underline; text-underline-offset: 3px; }

.archive { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.archive a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
  min-height: 52px;
}
.archive a:hover { background: var(--tile); }
.archive .a-date { font-weight: 500; }
.archive .a-num { display: block; font-size: 12px; color: var(--faint); font-weight: 400; }
.archive .status { font-size: 12px; color: var(--faint); min-width: 72px; text-align: right; }
.archive .status.won { color: #2F7A47; font-weight: 500; }
.archive .status.lost { color: #B4363A; }
.archive .shovels .shovel { width: 14px; height: 14px; }

.help { display: flex; flex-direction: column; gap: 14px; font-size: 15px; }
.help p { margin: 0; }
.help ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; color: var(--muted); }
.help .swatches { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.help .swatches i { width: 28px; height: 10px; border-radius: 3px; display: inline-block; }

.credit { text-align: center; font-size: 12px; color: var(--faint); padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); }

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

@media (min-width: 720px) {
  :root { --tile-h: 92px; --tile-size: 16px; --radius: 14px; }
  .top { padding: 10px 24px; border-bottom: 1px solid var(--rule); }
  .brand { font-size: 20px; }
  .nav span { display: inline; }
  .nav svg { display: none; }
  .app { padding-top: 24px; gap: 20px; }
  .grid { gap: 10px; }
  .band-head { font-size: 20px; }
  .band-cards { font-size: 16px; }
  .sheet { margin: auto; border-radius: 20px; }
  .lede { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
