:root {
  --bg: #f6f4f1; --panel: #ffffff; --line: #e3ded7; --text: #1d1c1a; --sub: #6f6a63;
  --accent: #c8432b; --accent-ink: #ffffff; --on: #2f8a57; --on-bg: #e2f2e8; --row-done: #f0f7f2;
  --ca: #c96a1f; --cb: #2f74c8; --chip: #ece7e0; --fs: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141517; --panel: #1d1f22; --line: #2e3135; --text: #ecebe8; --sub: #9a968f;
    --accent: #e0563a; --on: #5cc488; --on-bg: #1f3a2a; --row-done: #19261e; --chip: #2a2d31;
    --ca: #f0a060; --cb: #6aa8f0; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141517; --panel: #1d1f22; --line: #2e3135; --text: #ecebe8; --sub: #9a968f;
  --accent: #e0563a; --on: #5cc488; --on-bg: #1f3a2a; --row-done: #19261e; --chip: #2a2d31;
  --ca: #f0a060; --cb: #6aa8f0; color-scheme: dark;
}
:root[data-size="large"] { --fs: 19px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font: var(--fs)/1.55 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden; overscroll-behavior: none;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
h1 { font-size: 1.1em; margin: 0; }

/* ---- 一覧 ---- */
.top { padding: 10px 16px 8px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.prog { display: flex; flex-direction: column; gap: 4px; border: 0; background: none; padding: 0; text-align: left; }
.prog span { font-size: .9em; color: var(--sub); }
.prog b.n { color: var(--text); font-size: 1.2em; }
.prog i { display: block; height: 6px; background: var(--chip); border-radius: 3px; overflow: hidden; }
.prog i b { display: block; height: 100%; width: 0; background: var(--on); transition: width .2s; }
input[type="search"] { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border: 0; background: var(--chip); padding: 6px 14px; border-radius: 999px; font-size: .9em; }
.chips button.on { background: var(--text); color: var(--bg); }
.filters { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.seg { display: inline-flex; background: var(--chip); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; font-size: .9em; }
.seg button.on { background: var(--panel); box-shadow: 0 1px 2px #0003; font-weight: 600; }
.seg.small button { padding: 4px 10px; }
select { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 5px 8px; font-size: .9em; }

.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 8px; }
.grp { position: sticky; top: 0; z-index: 1; background: var(--bg); color: var(--sub); font-size: .8em; padding: 10px 16px 4px; display: flex; justify-content: space-between; }
.row { display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); min-height: 60px; }
.row.done { background: var(--row-done); }
.row .nm { flex: 1; min-width: 0; }
.row .nm div { overflow-wrap: anywhere; }
.row small { display: block; color: var(--sub); font-size: .78em; }
.has { font-style: normal; font-size: .7em; border: 1px solid var(--sub); color: var(--sub); border-radius: 4px; padding: 0 3px; margin-left: 4px; vertical-align: 2px; }
.ca { color: var(--ca); } .cb { color: var(--cb); }
.chks { display: flex; gap: 6px; flex: none; }
.chk { width: 48px; height: 48px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel); font-weight: 600; color: var(--sub); }
.chk.on { border-color: var(--on); background: var(--on-bg); color: var(--on); }
.chks.big .chk { width: 56px; height: 52px; }
.empty { color: var(--sub); padding: 24px 16px; }
.nextbar { padding: 8px 16px; background: var(--panel); border-top: 1px solid var(--line); }
.primary { width: 100%; border: 0; border-radius: 12px; padding: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ---- 詳細 ---- */
.dtop { display: flex; align-items: center; gap: 8px; padding: 6px 12px; padding-top: max(6px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--line); }
.dtop h1 { flex: 1; min-width: 0; font-size: 1.05em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon { border: 0; background: none; font-size: 1.4em; width: 44px; height: 44px; }
#stage { position: relative; height: 45dvh; flex: none; background: #15171a; touch-action: none; }
#view { width: 100%; height: 100%; display: block; }
#loadMsg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #bbb; font-size: .9em; padding: 16px; text-align: center; }
.views { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; gap: 6px; }
.views button { border: 0; background: #000a; color: #eee; border-radius: 8px; padding: 6px 12px; font-size: .85em; }
.views button:last-child { margin-left: auto; }
.dbody { flex: 1; overflow-y: auto; padding: 12px 16px 16px; touch-action: pan-y; }
.dbody .sub { color: var(--sub); font-size: .8em; overflow-wrap: anywhere; }
.dbody dl { margin: 10px 0 0; }
.dbody dt { font-size: .8em; color: var(--sub); margin-top: 10px; }
.dbody dd { margin: 2px 0 0; }
.dbody details { border-top: 1px solid var(--line); padding: 8px 0; }
.dbody details:first-of-type { margin-top: 12px; }
.dbody summary { font-weight: 600; padding: 4px 0; }
.dbody details p { margin: 4px 0 0; }
.dbody .note { color: var(--sub); font-size: .85em; margin-top: 12px; }
.dfoot { display: flex; gap: 10px; align-items: center; padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
.dfoot .primary { flex: 1; }

/* ---- 記録 ---- */
.rec { flex: 1; overflow-y: auto; padding: 4px 16px 24px; }
.rec section { border-bottom: 1px solid var(--line); padding: 14px 0; }
.rec h2 { font-size: .85em; color: var(--sub); margin: 0 0 8px; font-weight: 600; }
.rec .line { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 6px 0; }
.rec .btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 14px; }
.rec .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.rec .stat b { font-size: 1.3em; }
.rec .bars div { display: grid; grid-template-columns: 4em 1fr 4.5em; gap: 8px; align-items: center; font-size: .9em; margin: 4px 0; }
.rec .bars i { display: block; height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.rec .bars i b { display: block; height: 100%; background: var(--on); }
.rec .small { color: var(--sub); font-size: .8em; }
.cal { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; width: max-content; }
.cal span { width: 18px; height: 18px; border-radius: 3px; background: var(--chip); }
.cal span.l1 { background: color-mix(in srgb, var(--on) 35%, var(--chip)); }
.cal span.l2 { background: color-mix(in srgb, var(--on) 65%, var(--chip)); }
.cal span.l3 { background: var(--on); }
.cal span.today { outline: 2px solid var(--text); outline-offset: -1px; }
.calwrap { overflow-x: auto; }

/* ---- タブ ---- */
#tabs { display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#tabs button { flex: 1; border: 0; background: none; padding: 12px 0; color: var(--sub); font-weight: 600; }
#tabs button.on { color: var(--accent); }
body.detail #tabs { display: none; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #000d; color: #fff; padding: 8px 14px; border-radius: 10px; font-size: .9em; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }
