:root {
  --bg: #f6f4f1;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --line: #e4e0da;
  --accent: #7a1f1f;
  --accent-soft: #f3e3e1;
  --link: #0b57d0;
  --done: #1f7a4a;
  --done-soft: #e2f3ea;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --card: #1f2229;
    --text: #ececef;
    --muted: #9a9aa3;
    --line: #2e323b;
    --accent: #e08b80;
    --accent-soft: #3a2626;
    --link: #8ab4f8;
    --done: #5fd39a;
    --done-soft: #1d3329;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 780px; margin: 0 auto; padding: 0 16px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding-top: max(10px, env(safe-area-inset-top));
}
.title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
h1 { font-size: 1.15rem; white-space: nowrap; margin: 0; color: var(--accent); letter-spacing: -0.01em; }
.progress-text { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.bar { height: 5px; background: var(--line); border-radius: 99px; margin: 8px 0 10px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--done); border-radius: 99px; transition: width .3s; }

.chips {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 99px; padding: 7px 14px; font: inherit; font-size: .9rem; cursor: pointer;
  min-height: 38px; display: inline-flex; align-items: center; gap: 6px;
}
.chip small { color: var(--muted); font-size: .75rem; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip[aria-pressed="true"] small { color: rgba(255,255,255,.8); }
@media (prefers-color-scheme: dark) { .chip[aria-pressed="true"] { color: #16181d; } .chip[aria-pressed="true"] small { color: rgba(0,0,0,.6); } }

/* controls */
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 16px 0 6px; }
.seg { display: inline-flex; background: var(--line); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: .9rem;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; min-height: 36px;
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.search {
  flex: 1 1 160px; min-width: 0; font: inherit; font-size: 16px; /* 16px stops iOS zoom */
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); min-height: 40px;
}
.hide-done { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--muted); cursor: pointer; }
.hide-done input { width: 18px; height: 18px; accent-color: var(--done); }

/* info box */
.info { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin: 10px 0 0; }
.info:first-child { margin-top: 14px; }
.info summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.info p, .info ol { margin: .6em 0; color: var(--muted); font-size: .95rem; }
.info ol { padding-left: 1.3em; }
.info li { margin: .3em 0; }
.info b { color: var(--text); }

/* sessions */
.session { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin: 14px 0; overflow: hidden; }
.session-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.session-head h2 { font-size: 1rem; margin: 0; }
.session-head .count { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.tier { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); margin-left: 8px; vertical-align: 2px; }
.tier.t2 { background: var(--line); color: var(--text); }
.tier.t3, .tier.t4 { background: transparent; border: 1px solid var(--line); color: var(--muted); }

.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row.done { background: var(--done-soft); }
.tick {
  flex: none; width: 28px; height: 28px; margin: 0; accent-color: var(--done); cursor: pointer;
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-variant-numeric: tabular-nums; }
.row.done .row-title { color: var(--done); }
.row-sub { font-size: .78rem; color: var(--muted); }
.actions { display: flex; gap: 8px; flex: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 14px;
  border-radius: 10px; font-size: .9rem; font-weight: 600; text-decoration: none; white-space: nowrap;
  border: 1px solid var(--line); color: var(--link); background: var(--card);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #16181d; } }
.btn.disabled { color: var(--muted); border-style: dashed; pointer-events: none; font-weight: 400; }
.btn:focus-visible, .chip:focus-visible, .seg button:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.empty, .loading, .notice { color: var(--muted); text-align: center; padding: 40px 10px; }
.notice { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-top: 20px; }
.notice h2 { color: var(--text); font-size: 1.1rem; }
.notice .bar { max-width: 320px; margin: 16px auto; }

.foot { color: var(--muted); font-size: .8rem; padding-top: 10px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.link { background: none; border: 0; padding: 0; color: var(--link); font: inherit; cursor: pointer; text-decoration: underline; }

/* phones: stack the buttons under the title */
@media (max-width: 520px) {
  .row { flex-wrap: wrap; }
  .row-main { flex: 1 1 calc(100% - 40px); }
  .actions { width: 100%; padding-left: 40px; }
  .actions .btn { flex: 1; }
  .controls .seg { width: 100%; }
  .controls .seg button { flex: 1; }
}
