:root {
  color-scheme: light;
  --bg: #efe7da;
  --bg-2: #fbf7f1;
  --ink: #1c2421;
  --muted: #5c675f;
  --line: #e0d5c6;
  --moss: #1d5c45;
  --moss-ink: #f4fbf7;
  --moss-soft: #e4f2ea;
  --clay: #b85a2a;
  --clay-soft: #f8ebe3;
  --flag: #8a4518;
  --flag-bg: #f6e6d4;
  --shadow: 0 10px 30px rgba(28, 36, 33, 0.08);
  --bar: 64px;
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #101412;
    --bg-2: #1a211e;
    --ink: #f4efe6;
    --muted: #aeb8b1;
    --line: #2d3833;
    --moss: #8ed4b6;
    --moss-ink: #10241c;
    --moss-soft: #17352b;
    --clay: #f0a36a;
    --clay-soft: #2c2118;
    --flag: #f0c08a;
    --flag-bg: #3a2a1c;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
}

body {
  padding-bottom: calc(var(--bar) + env(safe-area-inset-bottom));
}

button, input, select { font: inherit; color: inherit; }

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

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

.app {
  width: min(480px, 100%);
  margin: 0 auto;
  padding: 14px 16px 28px;
}

.top-row, .item-top, .group-toggle, .dialog-bar, .goal-switch, .backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.date, .blurb, .cue, .note-body, .help, .history-item, .source {
  color: var(--muted);
}

.date {
  margin: 0;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 8px;
  font-family: var(--serif);
  font-size: 1.85rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.streak {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: right;
}

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

.score {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.score b { font-variant-numeric: tabular-nums; }

.score .hint { display: block; margin-top: 2px; color: var(--muted); font-size: 0.88rem; }

.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  margin: 0 0 12px;
}

.week button {
  min-height: 52px;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
}

.week button strong {
  display: block;
  color: var(--ink);
  font-size: 0.78rem;
}

.week button em {
  font-style: normal;
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
}

.week button[aria-current="date"] {
  background: var(--moss-soft);
  color: var(--moss);
}

.week button[aria-current="date"] strong { color: var(--moss); }

.week button.is-viewed {
  box-shadow: inset 0 0 0 2px var(--clay);
}

.week button.qualified em { color: var(--moss); }

.meter { margin: 0 0 14px; }

.meter-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.88rem;
}

.meter-label b { font-variant-numeric: tabular-nums; }

.track {
  height: 12px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--clay);
}

.meter.hit .fill { background: var(--moss); }

.meter.hit .goal-hit { color: var(--moss); font-weight: 700; }

.clinician {
  margin: 0 0 14px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.clinician summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-weight: 650;
}

.clinician p { margin: 0 0 12px; color: var(--muted); font-size: 0.92rem; }

.group { margin: 0 0 8px; }

.group-toggle {
  width: 100%;
  min-height: 52px;
  text-align: left;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}

.group-toggle h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
}

.group-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}

.blurb { margin: 0 0 8px; font-size: 0.9rem; }

.item {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 6px;
  padding: 8px 0 12px;
  border-top: 1px solid var(--line);
}

.item.is-done { background: linear-gradient(90deg, var(--moss-soft), transparent 70%); }

.check {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
}

.box {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid var(--ink);
  display: grid;
  place-items: center;
  background: var(--bg-2);
}

.check[aria-pressed="true"] .box {
  background: var(--moss);
  border-color: var(--moss);
  color: var(--moss-ink);
}

.check svg { width: 16px; height: 16px; opacity: 0; }
.check[aria-pressed="true"] svg { opacity: 1; }

.item h3 { margin: 2px 0; font-size: 1rem; font-weight: 650; line-height: 1.25; }

.pts {
  flex: none;
  min-width: 46px;
  text-align: center;
  border-radius: 999px;
  background: var(--clay-soft);
  color: var(--clay);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 6px;
  font-variant-numeric: tabular-nums;
}

.dose, .weight, .cue, .ladder-note { margin: 0 0 4px; font-size: 0.92rem; }
.dose { font-variant-numeric: tabular-nums; }
.weight { color: var(--ink); }

.edit, .steps-toggle, .text-btn {
  min-height: 44px;
  color: var(--moss);
  font-weight: 700;
  text-align: left;
}

.steps { list-style: none; margin: 4px 0 0; padding: 0; }
.steps li { border-top: 1px dashed var(--line); }
.step {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}
.step .mini {
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 6px;
  border: 2px solid var(--ink);
}
.step[aria-pressed="true"] .mini { background: var(--moss); border-color: var(--moss); }

.note {
  margin: 8px 0;
  padding: 12px;
  border-radius: 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}
.note h3 { margin: 0 0 4px; font-size: 0.95rem; }
.note-body { margin: 0; font-size: 0.92rem; }
.flag {
  display: inline-block;
  margin: 0 0 6px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--flag-bg);
  color: var(--flag);
  font-size: 0.78rem;
  font-weight: 750;
}

.ladder {
  margin-top: 6px;
}
.ladder label { display: block; font-size: 0.82rem; font-weight: 700; margin-bottom: 4px; }

select, input[type="text"], input[type="number"] {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 10px 12px;
}

.field { margin-bottom: 10px; }
.field span { display: block; font-size: 0.82rem; font-weight: 700; margin-bottom: 4px; }

.viewing {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--clay-soft);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar) + env(safe-area-inset-bottom) + 10px);
  transform: translateX(-50%);
  width: min(440px, calc(100% - 24px));
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
  box-shadow: var(--shadow);
  z-index: 5;
  pointer-events: none;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.tabbar button {
  width: min(220px, 46vw);
  min-height: 48px;
  border-radius: 14px;
  font-weight: 750;
}

.tabbar button[aria-current="page"], .goal-switch button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

.goal-switch button, .backup-row button, .primary, .danger, .ghost {
  min-height: 48px;
  border-radius: 12px;
  padding: 0 12px;
  font-weight: 750;
}

.goal-switch { margin: 8px 0; }
.goal-switch button { flex: 1; border: 1px solid var(--line); }
.backup-row { margin: 8px 0 16px; }
.backup-row button, .ghost { border: 1px solid var(--line); background: var(--bg); flex: 1; }
.primary { width: 100%; background: var(--moss); color: var(--moss-ink); }
.danger { width: 100%; background: transparent; color: var(--clay); border: 1px solid var(--clay); }

.footer-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

dialog {
  border: 0;
  padding: 0;
  color: var(--ink);
  background: var(--bg-2);
  max-width: 480px;
}

dialog::backdrop { background: rgba(12, 16, 14, 0.48); }

dialog.settings {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  margin: 0;
}

dialog.sheet {
  width: min(480px, 100%);
  max-height: 92vh;
  margin-top: auto;
  margin-bottom: 0;
  border-radius: 18px 18px 0 0;
}

.dialog-body { padding: 8px 16px 24px; overflow: auto; max-height: calc(92vh - 60px); }
dialog.settings .dialog-body { max-height: calc(100vh - 64px); }

.dialog-bar {
  position: sticky;
  top: 0;
  padding: 12px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  z-index: 1;
}

.dialog-bar h2 { margin: 0; font-family: var(--serif); font-size: 1.4rem; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.chips button {
  min-width: 46px;
  min-height: 44px;
  padding: 0 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
}
.chips button[aria-pressed="true"] { background: var(--moss); color: var(--moss-ink); border-color: var(--moss); }
.chips.bjj button[aria-pressed="true"] { background: var(--clay); color: #fff; border-color: var(--clay); }

@media (prefers-color-scheme: dark) {
  .chips.bjj button[aria-pressed="true"] { color: #2a1408; }
}

.help { margin: 0 0 12px; font-size: 0.88rem; }
.history { list-style: none; margin: 8px 0 0; padding: 0; }
.history-item { padding: 8px 0; border-top: 1px solid var(--line); font-size: 0.9rem; }
.error { color: var(--clay); font-weight: 700; }

.banner {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--flag-bg);
  color: var(--flag);
}

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 8;
}

@media (prefers-reduced-motion: reduce) {
  .confetti { display: none; }
}

@media (min-width: 520px) {
  body { background: color-mix(in srgb, var(--bg) 70%, #cfc5b6); }
  .app, .tabbar { background: var(--bg); }
  .tabbar { width: min(480px, 100%); left: 50%; transform: translateX(-50%); border: 1px solid var(--line); border-bottom: 0; }
}
