:root {
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface2: #ebebe7;
  --text: #1d1d1f;
  --muted: #6c6c71;
  --line: #e1e1dc;
  --accent: #2f6f5e;
  --accent-soft: #dcebe5;
  --on-accent: #ffffff;
  --mistake: #b0502a;
  --mistake-soft: #f6e4db;
  --concept: #35609f;
  --concept-soft: #e0e8f5;
  --danger: #c0392b;
  --bar: #2f6f5e;
  --bar2: #c0673d;
  --bar-track: #ebebe6;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
  --tabh: 58px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111112;
    --surface: #1c1c1e;
    --surface2: #2a2a2d;
    --text: #f2f2f4;
    --muted: #9c9ca2;
    --line: #2f2f33;
    --accent: #5db89c;
    --accent-soft: #1d3a31;
    --on-accent: #0c1f19;
    --mistake: #f0946c;
    --mistake-soft: #3b251b;
    --concept: #8ab1ea;
    --concept-soft: #1e2b41;
    --danger: #ff6b5b;
    --bar: #5db89c;
    --bar2: #e89266;
    --bar-track: #2a2a2d;
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  touch-action: manipulation;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: inherit; }
button:disabled { opacity: 0.3; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, p { margin: 0; }

.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.chev { width: 18px; height: 18px; color: var(--muted); }

#app { max-width: 720px; margin: 0 auto; min-height: 100vh; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 12px 6px 16px;
}
.top.sub { display: grid; grid-template-columns: minmax(90px, 1fr) minmax(0, 2.2fr) minmax(90px, 1fr); padding-left: 12px; }
.subj-btn { flex: 1; min-width: 0; min-height: 48px; display: flex; align-items: center; gap: 4px; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.subj-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subj-btn .ic { color: var(--muted); width: 20px; height: 20px; }
.icon-btn { width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; color: var(--muted); }
.icon-btn.danger { color: var(--danger); }
.back-btn { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); font-size: 17px; margin-left: -4px; }
.text-btn { min-height: 44px; padding: 0 4px; color: var(--accent); font-size: 17px; }
.text-btn.strong { font-weight: 600; }
.top-title { font-weight: 600; font-size: 17px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { display: flex; justify-content: flex-end; }

/* ---------- main ---------- */
.main { padding: 6px 16px calc(env(safe-area-inset-bottom) + 40px); }
.main.with-tabs { padding-bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 96px); }
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; margin: 4px 0 10px; overflow-wrap: anywhere; }
.sub-title { margin: -6px 0 16px; }
.sec { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 10px; }
.main > .sec { margin: 22px 4px 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.strong { font-weight: 600; }
.accent { color: var(--accent); }
.center { text-align: center; margin-top: 20px; }
.hint { color: var(--muted); margin: 4px 2px 12px; }
.help { color: var(--muted); font-size: 14px; margin-top: 8px; }
.count { color: var(--muted); font-size: 14px; margin: 0 4px 8px; }
.foot { color: var(--muted); font-size: 14px; text-align: center; margin: -2px 0 16px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; line-height: 1.6; }
.banner { background: var(--accent-soft); border-radius: 14px; padding: 12px 14px; font-size: 14px; margin: 4px 0 12px; line-height: 1.45; }

/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; max-width: 180px; height: var(--tabh); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 500; color: var(--muted); text-align: center; }
.tab.on { color: var(--accent); }
.tab .ic { width: 25px; height: 25px; }
.fab {
  position: fixed; z-index: 25;
  right: max(16px, calc(50vw - 344px));
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 16px);
  height: 56px; padding: 0 24px 0 18px; border-radius: 28px;
  display: flex; align-items: center; gap: 6px;
  background: var(--accent); color: var(--on-accent);
  font-size: 18px; font-weight: 600; box-shadow: var(--shadow);
}
.fab .ic { width: 24px; height: 24px; stroke-width: 2.4; }

/* ---------- controls ---------- */
.search { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; margin: 2px 0 10px; border-radius: 12px; background: var(--surface2); color: var(--muted); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: none; background: none; font-size: 16px; color: var(--text); }
.search input::-webkit-search-decoration { -webkit-appearance: none; }

.seg { display: flex; gap: 3px; padding: 3px; margin: 0 0 12px; border-radius: 12px; background: var(--surface2); }
.seg > button { flex: 1; min-height: 38px; padding: 0 6px; border-radius: 9px; border: 0; background: none; font-size: 15px; font-weight: 500; color: var(--muted); text-align: center; }
.seg > button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.seg.inline { margin: 0; flex: 0 0 150px; }

.filters { display: flex; gap: 8px; margin-bottom: 12px; }
.sel { position: relative; display: block; flex: 1; min-width: 0; }
.sel select {
  width: 100%; height: 44px; padding: 0 34px 0 12px;
  -webkit-appearance: none; appearance: none;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  font-size: 16px; text-overflow: ellipsis;
}
.sel::after { content: ""; position: absolute; right: 15px; top: 50%; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-70%) rotate(45deg); pointer-events: none; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 0 16px; border-radius: 12px; background: var(--surface2); font-size: 16px; font-weight: 600; text-align: center; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.big { min-height: 54px; font-size: 17px; }
.btn.wide { display: flex; width: 100%; margin: 0 0 12px; }
.btn.danger-text { background: none; color: var(--danger); font-weight: 500; margin-top: 8px; }
.btn .ic { stroke-width: 2.2; }

.field { margin-bottom: 20px; }
.lbl { font-size: 14px; font-weight: 600; color: var(--muted); margin: 0 2px 7px; }
.opt { font-weight: 400; }
.group-lbl { margin: 14px 4px 6px; }
.in { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 16px; outline: none; resize: none; }
.in:focus { border-color: var(--accent); }
textarea.in { min-height: 88px; line-height: 1.45; }
.pp-row { display: flex; gap: 8px; align-items: center; }
.add-row { display: flex; gap: 8px; margin: 10px 0 4px; }
.add-row .in { flex: 1; min-width: 0; }
.row-btns { display: flex; justify-content: space-between; margin: 0 0 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; min-height: 42px; padding: 0 15px; border: 1px solid var(--line); border-radius: 21px; background: var(--surface); font-size: 15px; font-weight: 500; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip.add { border-style: dashed; color: var(--accent); padding-left: 11px; }
.chip.add .ic { width: 18px; height: 18px; }
.seg > .chip { border: 0; border-radius: 9px; min-height: 38px; background: none; justify-content: center; color: var(--muted); }
.seg > .chip.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.chips.static { margin-bottom: 14px; }
.chips.static .chip { min-height: 30px; padding: 0 11px; font-size: 14px; }

/* ---------- lists ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 14px; overflow: hidden; }
.card.pad { padding: 14px 16px 16px; }
.list > * + * { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 54px; padding: 9px 12px 9px 14px; text-align: left; }
.row .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row.entry { padding: 10px 12px; }
.thumb { width: 58px; height: 58px; flex: none; border-radius: 10px; object-fit: cover; background: var(--surface2); display: flex; align-items: center; justify-content: center; color: var(--muted); }
.rowtext { flex: 1; min-width: 0; }
.rowtitle { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rowsub { margin-top: 3px; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-block; margin-right: 6px; padding: 1px 7px; border-radius: 6px; font-size: 12px; font-weight: 600; vertical-align: 1px; }
.badge.mistake { background: var(--mistake-soft); color: var(--mistake); }
.badge.concept { background: var(--concept-soft); color: var(--concept); }
.add-link { color: var(--accent); font-weight: 500; }
.add-link .ic { width: 20px; height: 20px; }
.edit-row { gap: 4px; padding-right: 6px; }
.in.slim { padding: 8px 10px; flex: 1; min-width: 0; }

.row.check .box { width: 26px; height: 26px; flex: none; border: 2px solid var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.row.check .box .ic { width: 18px; height: 18px; stroke-width: 2.8; }
.row.check.done .box { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.row.check.done .grow { color: var(--muted); text-decoration: line-through; }

/* ---------- photos ---------- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.ph { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface2); }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph.add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: 1.5px dashed var(--line); background: none; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; }
.ph.add .ic { width: 28px; height: 28px; }
.ph.busy { display: flex; align-items: center; justify-content: center; }
.ph-x { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 15px; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.55); color: #fff; }
.ph-x .ic { width: 16px; height: 16px; stroke-width: 2.4; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.entry-head { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: 6px; font-size: 15px; }
.full-photos { display: flex; flex-direction: column; gap: 10px; margin: 4px 0 18px; }
.full-ph { display: block; width: 100%; }
.full-ph img { display: block; width: 100%; min-height: 120px; border-radius: 12px; background: var(--surface2); }
.block { margin-bottom: 18px; }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 17px; line-height: 1.5; }

/* ---------- summary ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 16px; }
.num { font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-row { display: block; width: 100%; text-align: left; }
.bar-top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 5px; font-size: 16px; }
.bar-name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-name .muted { font-weight: 400; }
.bar-val { white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-extra { margin-top: 4px; }
.bar { height: 10px; border-radius: 5px; background: var(--bar-track); overflow: hidden; }
.bar.big { height: 12px; border-radius: 6px; margin-top: 8px; }
.bar > div { height: 100%; border-radius: inherit; background: var(--bar); }
.bar.alt > div { background: var(--bar2); }
.bar.none > div { background: var(--muted); opacity: 0.5; }
.prog-top { display: flex; justify-content: space-between; }
.trend { display: flex; align-items: flex-end; gap: 6px; margin-top: 12px; }
.tcol { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.tarea { width: 100%; height: 130px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.tval { font-size: 13px; font-weight: 600; margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.tbar { width: 100%; max-width: 34px; min-height: 3px; border-radius: 5px 5px 2px 2px; background: var(--bar); }
.tlab { margin-top: 5px; font-size: 11px; line-height: 1.2; color: var(--muted); text-align: center; }
.ov-head { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 32px; font-size: 18px; }
.ov-sub { margin: 0 0 12px; }
.status { display: flex; gap: 6px; align-items: center; font-weight: 600; margin-bottom: 6px; }
.status .ic { color: var(--accent); stroke-width: 2.6; }
.card.pad > .muted.small { margin-bottom: 14px; }
.card.pad > .muted.small:last-child { margin: 2px 0 0; }

/* ---------- dialogs, sheets, toasts ---------- */
.dlg-wrap, .sheet-wrap { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, 0.42); }
.dlg { width: 100%; max-width: 380px; padding: 20px; border-radius: 18px; background: var(--surface); }
.dlg h2 { font-size: 19px; margin-bottom: 6px; overflow-wrap: anywhere; }
.dlg p { color: var(--muted); margin-bottom: 4px; }
.dlg .in { margin-top: 10px; }
.dlg-btns { display: flex; gap: 10px; margin-top: 18px; }
.dlg-btns .btn { flex: 1; }
.busy-dlg { display: flex; align-items: center; gap: 12px; max-width: 320px; }
.sheet-wrap { align-items: flex-end; padding: 0; }
.sheet { width: 100%; max-width: 720px; max-height: 88vh; overflow: auto; padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px); border-radius: 20px 20px 0 0; background: var(--bg); }
.sheet h2 { font-size: 19px; margin-bottom: 14px; }
.sheet p { margin-bottom: 10px; }
.sheet .card { margin-bottom: 0; }
@media (min-width: 760px) {
  .sheet-wrap { align-items: center; padding: 16px; }
  .sheet { max-width: 480px; border-radius: 20px; }
}
.years { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 6px 0 16px; }
.year { min-height: 50px; display: flex; align-items: center; justify-content: center; gap: 3px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 16px; font-weight: 600; }
.year.done { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.year .ic { width: 18px; height: 18px; stroke-width: 2.6; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 150;
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 84px);
  display: flex; align-items: center; gap: 14px; max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-weight: 500; box-shadow: var(--shadow);
}
.toast-btn { color: var(--accent-soft); font-weight: 700; }

/* ---------- photo viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 200; background: #000; }
.v-stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.v-img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; user-select: none; -webkit-user-select: none; -webkit-user-drag: none; }
.v-btn { position: absolute; width: 44px; height: 44px; border-radius: 22px; display: flex; align-items: center; justify-content: center; background: rgba(40, 40, 40, 0.7); color: #fff; }
.v-close { top: calc(env(safe-area-inset-top) + 10px); right: 12px; }
.v-prev { left: 12px; bottom: calc(env(safe-area-inset-bottom) + 16px); }
.v-next { right: 12px; bottom: calc(env(safe-area-inset-bottom) + 16px); }
.v-next .ic { color: #fff; width: 22px; height: 22px; }
.v-count { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 28px); color: #ddd; font-size: 14px; }
