/* Daybook — reads like a Notion page: white space, plain type, colour only where it means something. */
:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f5;
  --hover: #efefed;
  --text: #37352f;
  --text-strong: #191711;
  --muted: #787774;
  --faint: #a5a49f;
  --line: #e9e9e7;
  --accent: #2383e2;
  --accent-soft: rgba(35, 131, 226, 0.1);
  --accent-text: #ffffff;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs: 16px;
  --tap: 48px;
  --radius: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191919; --bg-soft: #202020; --hover: #2a2a2a; --text: #e3e2e0; --text-strong: #f5f5f4;
    --muted: #9b9a97; --faint: #6f6e69; --line: #2f2f2f; --accent: #529cca; --accent-soft: rgba(82, 156, 202, 0.16); --accent-text: #0f1a22;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #191919; --bg-soft: #202020; --hover: #2a2a2a; --text: #e3e2e0; --text-strong: #f5f5f4;
  --muted: #9b9a97; --faint: #6f6e69; --line: #2f2f2f; --accent: #529cca; --accent-soft: rgba(82, 156, 202, 0.16); --accent-text: #0f1a22;
  color-scheme: dark;
}
:root[data-size="small"] { --fs: 15px; }
:root[data-size="large"] { --fs: 18px; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: var(--fs); line-height: 1.55; -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: contain; -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { color: var(--text-strong); line-height: 1.25; margin: 0; }
p { margin: 0 0 .6em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: .875em; }
.tiny { font-size: .78em; }
.accent { color: var(--accent); }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.hstack { display: flex; align-items: center; gap: 8px; }
.vstack { display: flex; flex-direction: column; gap: 8px; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- shell */
.shell { min-height: 100dvh; }
.main { padding: 0 16px calc(84px + env(safe-area-inset-bottom)); }
.col { max-width: 720px; margin: 0 auto; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--bg); display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; }
.topbar .title { font-weight: 600; font-size: .95em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--bg); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; text-decoration: none; color: var(--muted); font-size: .72em; }
.tabbar a.on { color: var(--text-strong); }
.tabbar a.on svg { color: var(--accent); }
.sidebar { display: none; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; flex: none; }
.sync-dot.ok { background: transparent; border: 1px solid var(--faint); }
.sync-dot.pending { background: var(--accent); }
.sync-dot.syncing { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 248px 1fr; }
  .sidebar { display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh; overflow: auto; background: var(--bg-soft); border-right: 1px solid var(--line); padding: 14px 8px; font-size: .9em; }
  .sidebar .brand { display: flex; align-items: center; gap: 8px; padding: 6px 10px 14px; font-weight: 600; color: var(--text-strong); }
  .sidebar .brand img { width: 22px; height: 22px; border-radius: 4px; }
  .sidebar a { display: flex; align-items: center; gap: 10px; padding: 5px 10px; border-radius: var(--radius); text-decoration: none; color: var(--text); min-height: 32px; }
  .sidebar a:hover { background: var(--hover); }
  .sidebar a.on { background: var(--hover); color: var(--text-strong); font-weight: 600; }
  .sidebar a.sub { padding-left: 34px; color: var(--muted); }
  .sidebar .group { margin: 16px 10px 4px; font-size: .78em; color: var(--muted); font-weight: 600; }
  .sidebar .foot { margin-top: auto; padding: 10px; color: var(--muted); font-size: .85em; }
  .tabbar, .topbar .phone-only { display: none; }
  .topbar { padding: 10px 24px; }
  .main { padding: 0 24px 64px; }
  :root { --tap: 36px; }
}

/* ---------------------------------------------------------------- page pattern */
.page-head { padding: 28px 0 14px; }
.page-icon { font-size: 2.2em; line-height: 1; margin-bottom: 10px; display: block; }
.page-icon svg { width: 40px; height: 40px; color: var(--muted); }
.page-title { font-size: 1.9em; font-weight: 700; letter-spacing: -.01em; }
.page-sub { color: var(--muted); margin-top: 4px; }
.section { margin: 18px 0; }
.section-title { font-size: .8em; font-weight: 600; color: var(--muted); margin: 0 0 6px; text-transform: none; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.empty { color: var(--muted); padding: 18px 0; }

/* folding toggles */
.toggle { border-top: 1px solid var(--line); }
.toggle:last-child { border-bottom: 1px solid var(--line); }
.toggle > .toggle-head { display: flex; align-items: center; gap: 8px; min-height: var(--tap); cursor: pointer; user-select: none; padding: 4px 2px; background: none; border: 0; width: 100%; text-align: left; }
.toggle > .toggle-head:hover { background: var(--hover); }
.toggle > .toggle-head .chev { transition: transform .15s; color: var(--muted); flex: none; }
.toggle.open > .toggle-head .chev { transform: rotate(90deg); }
.toggle > .toggle-body { padding: 2px 0 12px 26px; }
.toggle-title { font-weight: 600; flex: 1; min-width: 0; color: var(--text-strong); }
.toggle-meta { color: var(--muted); font-size: .9em; font-variant-numeric: tabular-nums; }
.toggle.current > .toggle-head .toggle-title { color: var(--accent); }

/* ---------------------------------------------------------------- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: .88em; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; cursor: default; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); border-radius: var(--radius); border: 0; background: transparent; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.chip { display: inline-flex; align-items: center; gap: 4px; min-height: 30px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-size: .85em; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text-strong); }
.input, .select, .textarea { width: 100%; min-height: var(--tap); padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg); }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: .85em; color: var(--muted); }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; min-width: 0; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); cursor: pointer; }
.switch input { width: 40px; height: 22px; appearance: none; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; transition: background .15s; flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--bg); transition: left .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 21px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius); }
.stepper button { width: 40px; height: 40px; border: 0; background: none; cursor: pointer; font-size: 1.1em; color: var(--muted); }
.stepper button:hover { background: var(--hover); color: var(--text); }
.stepper input { width: 52px; text-align: center; border: 0; background: none; font-variant-numeric: tabular-nums; height: 40px; }
.stepper .unit { color: var(--muted); font-size: .8em; padding-right: 8px; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin: 12px 0; }
.card.soft { background: var(--bg-soft); border-color: transparent; }
.card-title { font-weight: 600; color: var(--text-strong); margin-bottom: 4px; }
.notice { padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 var(--radius) var(--radius) 0; margin: 10px 0; }
.kbd { font-family: var(--mono); font-size: .85em; background: var(--bg-soft); border: 1px solid var(--line); padding: 1px 5px; border-radius: 4px; }

/* ---------------------------------------------------------------- checkbox rows */
.cb { width: 22px; height: 22px; border-radius: 4px; border: 1.5px solid var(--faint); display: inline-flex; align-items: center; justify-content: center; flex: none; background: var(--bg); transition: background .15s, border-color .15s; cursor: pointer; padding: 0; }
.cb svg { width: 14px; height: 14px; color: var(--accent-text); opacity: 0; transition: opacity .15s; }
.cb.on { background: var(--accent); border-color: var(--accent); }
.cb.on svg { opacity: 1; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 4px 2px; border-radius: var(--radius); transition: opacity .35s ease, transform .35s ease; user-select: none; -webkit-user-select: none; position: relative; }
.row:hover { background: var(--hover); }
.row .cb-hit { display: flex; align-items: center; justify-content: center; width: 36px; height: var(--tap); margin: -4px -6px -4px -2px; cursor: pointer; background: none; border: 0; padding: 0; flex: none; }
.row .row-main { flex: 1; min-width: 0; cursor: pointer; padding: 4px 0; background: none; border: 0; text-align: left; align-self: stretch; min-height: var(--tap); display: flex; flex-direction: column; justify-content: center; }
.row .row-title { display: block; color: var(--text-strong); }
.row .row-meta { display: block; color: var(--muted); font-size: .82em; }
.row.done { opacity: .45; }
.row.done .row-title { color: var(--text); }
.row .row-actions { display: flex; align-items: center; gap: 0; flex: none; }
.row .more { opacity: 0; }
.row:hover .more, .row .more:focus { opacity: 1; }
@media (hover: none) { .row .more { display: none; } }
.row-steps { margin: 0 0 8px 36px; padding: 6px 0 6px 12px; border-left: 2px solid var(--line); color: var(--muted); font-size: .9em; }
.row-steps li { list-style: none; padding: 2px 0; }
.chev-btn svg { transition: transform .15s; }
.chev-btn.open svg { transform: rotate(90deg); }
.add-row { color: var(--muted); }

/* ---------------------------------------------------------------- top strip */
.strip { display: grid; grid-template-columns: 1.3fr 1fr .9fr; gap: 8px; margin: 4px 0 8px; }
.counter { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 58px; cursor: pointer; background: var(--bg); text-align: left; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.counter:hover { background: var(--hover); }
.counter > span { display: block; }
.counter .label { font-size: .72em; color: var(--muted); display: block; }
.counter .value { font-weight: 600; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.bar { position: relative; height: 4px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: visible; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 2px; transition: width .25s; }
.bar > b { position: absolute; top: -3px; width: 1px; height: 10px; background: var(--muted); }
.counter .dots, .dots { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.dots i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--faint); }
.dots i.on { background: var(--accent); border-color: var(--accent); }

/* ---------------------------------------------------------------- sheets & toasts */
.backdrop { position: fixed; inset: 0; background: rgba(15, 15, 15, .35); z-index: 60; animation: fade .15s; }
.sheet { position: fixed; z-index: 61; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow: auto; background: var(--bg); border-radius: 14px 14px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease-out; }
.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 10px; }
.sheet-title { font-weight: 600; font-size: 1.05em; margin-bottom: 10px; color: var(--text-strong); }
@media (min-width: 900px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 12vh; transform: translateX(-50%); width: min(520px, 92vw); border-radius: 10px; border: 1px solid var(--line); animation: fade .15s; }
  .sheet .grab { display: none; }
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.toast { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text-strong); color: var(--bg); padding: 8px 14px; border-radius: 8px; z-index: 80; font-size: .9em; max-width: calc(100vw - 32px); animation: fade .15s; }
@media (min-width: 900px) { .toast { bottom: 24px; } }
.menu-list { display: flex; flex-direction: column; }
.menu-list button, .menu-list a { display: flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 0 6px; border: 0; background: none; text-align: left; cursor: pointer; border-radius: var(--radius); text-decoration: none; color: var(--text); }
.menu-list button:hover, .menu-list a:hover { background: var(--hover); }

/* ---------------------------------------------------------------- focus mode */
.focus { position: fixed; inset: 0; z-index: 70; background: var(--bg); display: flex; flex-direction: column; padding: calc(env(safe-area-inset-top) + 12px) 20px calc(env(safe-area-inset-bottom) + 20px); }
.focus-body { flex: 1; display: flex; flex-direction: column; justify-content: center; max-width: 520px; width: 100%; margin: 0 auto; }
.focus-title { font-size: 2em; font-weight: 700; color: var(--text-strong); margin: 8px 0; }
.focus-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; max-width: 520px; width: 100%; margin: 0 auto; }
.focus-actions .btn { min-height: 56px; }

/* ---------------------------------------------------------------- training */
.ex { border-top: 1px solid var(--line); padding: 8px 0; }
.ex-head { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; min-height: var(--tap); }
.ex-name { font-weight: 600; color: var(--text-strong); }
.ex-line { color: var(--muted); font-size: .86em; }
.ex-tag { display: inline-block; font-size: .72em; padding: 0 6px; border-radius: 4px; background: var(--bg-soft); color: var(--muted); margin-left: 6px; vertical-align: 2px; font-weight: 500; }
.ex-tag.go { background: var(--accent-soft); color: var(--accent); }
.ex-body { padding: 6px 0 4px 34px; }
.set-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 4px 0; }
.set-row .n { width: 22px; color: var(--muted); font-size: .85em; font-variant-numeric: tabular-nums; }
.set-row .cb { width: 30px; height: 30px; }
.cue { white-space: pre-line; color: var(--muted); font-size: .88em; margin: 6px 0; }
.block-label { font-size: .78em; font-weight: 600; color: var(--muted); margin: 18px 0 4px; display: flex; justify-content: space-between; align-items: center; }

/* ---------------------------------------------------------------- reading */
.md { line-height: 1.7; }
.md.serif { font-family: var(--serif); font-size: 1.06em; }
.md h1 { font-size: 1.6em; margin: .6em 0 .4em; }
.md h2 { font-size: 1.25em; margin: 1.1em 0 .4em; }
.md h3 { font-size: 1.05em; margin: 1em 0 .3em; }
.md ul, .md ol { padding-left: 1.3em; margin: .3em 0 .8em; }
.md li { margin: .25em 0; }
.md strong { color: var(--text-strong); }
.md code { font-family: var(--mono); font-size: .85em; background: var(--bg-soft); padding: 1px 4px; border-radius: 4px; }
.md blockquote { margin: .6em 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.reader .toggle > .toggle-body { padding-left: 4px; }
.reader .toggle-title { font-size: 1.12em; }
.split { display: grid; gap: 16px; }
@media (min-width: 900px) { .split { grid-template-columns: 1fr 1fr; } .split .textarea { min-height: 60vh; font-family: var(--mono); font-size: .9em; } }
.diff-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.diff-card.accepted { border-color: var(--accent); }
.diff-card.rejected { opacity: .55; }
.diff-old, .diff-new { white-space: pre-wrap; font-size: .9em; padding: 6px 8px; border-radius: 4px; margin: 4px 0; }
.diff-old { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--faint); background: var(--bg-soft); }
.diff-new { border-left: 3px solid var(--accent); background: var(--accent-soft); color: var(--text-strong); }
.diff-ctx { font-size: .75em; color: var(--muted); }

/* ---------------------------------------------------------------- words */
.flash { border: 1px solid var(--line); border-radius: 12px; min-height: 240px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; margin: 12px 0; }
.flash .w { font-size: 2.1em; font-weight: 700; color: var(--text-strong); line-height: 1.2; }
.flash .m { font-size: 1.2em; margin-top: 12px; }
.word-row { display: flex; align-items: baseline; gap: 12px; padding: 8px 2px; border-top: 1px solid var(--line); min-height: var(--tap); cursor: pointer; }
.word-row .w { font-weight: 600; color: var(--text-strong); min-width: 30%; }
.word-row .m.hide { color: transparent; background: var(--bg-soft); border-radius: 4px; }

/* ---------------------------------------------------------------- charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 10px; font-family: var(--sans); }
.chart .axis { stroke: var(--line); }
.chart .bar-rect { fill: var(--accent); }
.chart .bar-bg { fill: var(--bg-soft); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .line2 { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 3 3; }
.chart .pt { fill: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 600px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat .k { font-size: .75em; color: var(--muted); }
.stat .v { font-size: 1.35em; font-weight: 700; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.grid-month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; max-width: 240px; }
.grid-month i { aspect-ratio: 1; border-radius: 3px; background: var(--bg-soft); display: block; }
.grid-month i.on { background: var(--accent); }
.grid-month i.off { visibility: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: .9em; }
.table th, .table td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.table th { color: var(--muted); font-weight: 500; font-size: .85em; }

/* ---------------------------------------------------------------- login */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 360px; }
.login-box img { width: 56px; height: 56px; border-radius: 10px; margin-bottom: 18px; }
