:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #1f1c18;
  --muted: #6b645a;
  --line: #e3ddd3;
  --accent: #b5532a;
  --accent-ink: #ffffff;
  --done: #2f7a4f;
  --sp: #8a5a00;
  --trial: #6a3fa0;
  --boss: #9b2c2c;
  --chip: #efe9df;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161412; --card: #211e1a; --ink: #eee8de; --muted: #a59d90; --line: #36312a;
    --accent: #e0814f; --accent-ink: #1a1410; --done: #5fbf86; --sp: #e2b046; --trial: #b892e8; --boss: #ef7d7d;
    --chip: #2c2823; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161412; --card: #211e1a; --ink: #eee8de; --muted: #a59d90; --line: #36312a;
  --accent: #e0814f; --accent-ink: #1a1410; --done: #5fbf86; --sp: #e2b046; --trial: #b892e8; --boss: #ef7d7d;
  --chip: #2c2823; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 12px; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.title { font-weight: 700; line-height: 1.1; }
.sub { font-size: 12px; color: var(--muted); }
.badge { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 99px; background: var(--chip); color: var(--muted); vertical-align: 2px; }
.run-pick select {
  min-height: 44px; max-width: 46vw; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
}

.timer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 12px 16px 0; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.timer-read { display: flex; gap: 18px; flex-wrap: wrap; }
.lbl { font-size: 12px; color: var(--muted); display: block; }
.num { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 20px; }
.timer.running { border-color: var(--accent); }

main { max-width: 760px; margin: 0 auto; padding: 0 16px; }
h2 { font-size: 18px; margin: 22px 0 10px; }
.hint { color: var(--muted); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; min-width: 48px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--boss); }
.btn:focus-visible, .chip:focus-visible, .tabs button:focus-visible, .item:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.stack { display: grid; gap: 10px; }
input[type="text"], textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
}
textarea { resize: vertical; min-height: 220px; }
.row input[type="text"] { flex: 1; }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.bar { height: 4px; background: var(--chip); border-radius: 4px; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--done); }

.filters { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chip {
  flex: none; min-height: 40px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--chip); cursor: pointer;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

details.act { background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin: 10px 0; box-shadow: var(--shadow); }
details.act > summary {
  list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center;
  min-height: 52px; padding: 0 14px; font-weight: 700;
}
details.act > summary::-webkit-details-marker { display: none; }
details.act > summary::after { content: "▾"; color: var(--muted); margin-left: 8px; transition: transform .15s; }
details.act[open] > summary::after { transform: rotate(180deg); }
.act-count { margin-left: auto; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.act-count.full { color: var(--done); }
.items { list-style: none; margin: 0; padding: 0 6px 6px; }
.item { display: flex; gap: 12px; align-items: flex-start; padding: 10px 8px; border-top: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.item input { width: 26px; height: 26px; margin: 2px 0 0; flex: none; accent-color: var(--done); cursor: pointer; }
.item .name { font-weight: 600; }
.item .where { font-size: 14px; color: var(--muted); }
.item .reward { font-size: 13px; margin-top: 2px; }
.item.done .name { text-decoration: line-through; text-decoration-thickness: 1px; color: var(--muted); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; margin-right: 6px; border: 1px solid currentColor; vertical-align: 1px; }
.tag.gold { color: var(--sp); } .tag.violet { color: var(--trial); } .tag.red { color: var(--boss); } .tag.grey { color: var(--muted); }
.item.skipped { opacity: .6; }
.warn { color: var(--boss); font-weight: 600; }

.goals, .runs, .sessions { list-style: none; padding: 0; margin: 10px 0; }
.goals li, .runs li {
  display: flex; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px 6px 6px 12px; margin: 8px 0;
}
.goals li label { flex: 1; display: flex; gap: 12px; align-items: center; min-height: 44px; cursor: pointer; }
.goals li input { width: 24px; height: 24px; accent-color: var(--done); }
.goals li.done span { text-decoration: line-through; color: var(--muted); }
.sessions li { display: flex; justify-content: space-between; padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.sessions li .num { font-size: 14px; }

.foot { text-align: center; font-size: 12px; color: var(--muted); padding: 24px 16px 12px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { min-height: 60px; border: 0; background: none; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button.on { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 9;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }

@media (min-width: 700px) {
  .timer { max-width: 728px; margin: 12px auto 0; }
  .top { padding-left: max(16px, calc(50vw - 364px)); padding-right: max(16px, calc(50vw - 364px)); }
  .summary { grid-template-columns: repeat(3, minmax(0, 200px)); }
  .tabs { max-width: 760px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-radius: 14px 14px 0 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.field { display: grid; gap: 6px; margin: 10px 0; font-weight: 600; }
.field textarea { min-height: 110px; font-weight: 400; }
.field select { min-height: 48px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 400; }
.items.plain { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 0 6px; }
.items.plain li:first-child .item { border-top: 0; }
.tips { padding-left: 20px; margin: 8px 0; }
.tips li { margin: 8px 0; }
.cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); display: grid; gap: 8px; }
.card.current { border-color: var(--accent); }
.card-head { display: flex; gap: 10px; align-items: center; }
.card-head .grow { flex: 1; min-width: 0; }
.card-head small { display: block; color: var(--muted); }
.card-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; }
.card-line .num { font-size: 15px; }
.mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.mini .stat { padding: 6px 8px; }
.mini .stat b { font-size: 16px; }
.mini .stat span { font-size: 11px; }
.pill { font-size: 12px; font-weight: 700; color: var(--accent); }
.plan-peek { margin: 0; font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 14px; }
