:root {
  --bg: #fbf7f2;
  --card: #ffffff;
  --text: #2b2420;
  --muted: #857a72;
  --line: #ece4dc;
  --accent: #f26b5b;
  --accent-ink: #ffffff;
  --soft: #fdebe7;
  --danger: #d64545;
  --ok: #2f9461;
  --warn: #e39a17;
  --shadow: 0 1px 2px rgba(60, 40, 20, .05), 0 4px 14px rgba(60, 40, 20, .05);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171311;
    --card: #231d1a;
    --text: #f3ece6;
    --muted: #a69a91;
    --line: #382f2a;
    --soft: #3a2420;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; min-height: 100vh;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

/* ---------- frame ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar h1 { font-size: 26px; margin: 0; letter-spacing: -.015em; }
.icon-btn { border: 0; background: none; padding: 8px; border-radius: 12px; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
#offline { background: var(--warn); color: #fff; font-size: 13px; text-align: center; padding: 6px 12px; position: sticky; top: 0; z-index: 6; }
main { padding: 0 16px calc(env(safe-area-inset-bottom) + 100px); max-width: 680px; margin: 0 auto; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; text-decoration: none; }
.tabbar a.active { color: var(--accent); }

/* ---------- building blocks ---------- */
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; font-weight: 650; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
h2 .link { text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 600; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 0; text-decoration: none; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden; }
.card + .card { margin-top: 10px; }
.pad { padding: 14px; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); min-height: 52px; cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 560; overflow-wrap: anywhere; }
.row .sub { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 8px; margin-top: 1px; }
.row.done .title { text-decoration: line-through; color: var(--muted); }
.row.blocked .title { color: var(--muted); }
.row.static { cursor: default; }
.empty { padding: 18px 14px; color: var(--muted); text-align: center; font-size: 15px; }
.sub .late { color: var(--danger); font-weight: 600; }
.sub .soon { color: var(--warn); font-weight: 600; }
.bar { width: 4px; align-self: stretch; border-radius: 4px; flex: none; }
.time { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); width: 64px; flex: none; }

.check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); background: none; flex: none; display: grid; place-items: center; cursor: pointer; padding: 0; color: transparent; }
.check svg { width: 16px; height: 16px; stroke-width: 3; }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.mini { border: 1px solid var(--line); background: none; border-radius: 999px; font-size: 12px; padding: 3px 10px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.mini.on { background: var(--soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.del { border: 0; background: none; color: var(--muted); padding: 6px; cursor: pointer; border-radius: 8px; display: grid; place-items: center; }
.del svg { width: 18px; height: 18px; }

.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--accent); white-space: nowrap; letter-spacing: .02em; }
.pill.doing { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.waiting { background: color-mix(in srgb, var(--muted) 16%, transparent); color: var(--muted); }
.pill.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }

.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: 700; flex: none; font-size: 13px; }
.avatar.sm { width: 22px; height: 22px; font-size: 11px; }
.avatar.lg { width: 44px; height: 44px; font-size: 18px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 6px; scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: 14px; white-space: nowrap; color: var(--text); text-decoration: none; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
label.chip input { display: none; }
label.chip:has(input:checked) { background: var(--accent); color: #fff; border-color: var(--accent); }

.btn { border: 0; border-radius: 12px; padding: 12px 16px; background: var(--accent); color: var(--accent-ink); font-weight: 650; cursor: pointer; text-align: center; text-decoration: none; display: inline-block; }
.btn.ghost { background: var(--soft); color: var(--accent); }
.btn.plain { background: none; color: var(--muted); }
.btn.danger { background: none; color: var(--danger); }
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; display: block; }
.btn:disabled { opacity: .5; }
.fab {
  position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom) + 78px); z-index: 4; width: 56px; height: 56px;
  border-radius: 18px; border: 0; background: var(--accent); color: #fff; box-shadow: 0 6px 18px rgba(242, 107, 91, .4);
  display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 28px; height: 28px; }

input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); outline: none; min-height: 46px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.inline-add { display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid var(--line); }
.inline-add input { flex: 1; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two .field { min-width: 0; }
.checkline { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 15px; cursor: pointer; }
.checkline input { width: 20px; height: 20px; accent-color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); margin: -6px 0 14px; }
.small { font-size: 13px; color: var(--muted); }
.code { font: 600 15px ui-monospace, Menlo, Consolas, monospace; word-break: break-all; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; user-select: all; }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: .15s; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(18px); }

.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 9px 4px; border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.picker { max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; }
.picker label { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 15px; cursor: pointer; }
.picker label:last-child { border-bottom: 0; }
.picker input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.picker .grp { font-size: 12px; font-weight: 700; color: var(--muted); padding: 8px 12px 4px; text-transform: uppercase; letter-spacing: .05em; background: var(--bg); }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }

dialog { border: 0; padding: 0; width: min(560px, 100%); max-width: 100%; margin: auto auto 0; border-radius: 22px 22px 0 0; background: var(--card); color: var(--text); max-height: 92vh; overscroll-behavior: contain; }
@media (min-width: 620px) { dialog { margin: auto; border-radius: 22px; } }
dialog::backdrop { background: rgba(0, 0, 0, .38); }
#sheet-form { padding: 20px 18px calc(env(safe-area-inset-bottom) + 18px); }
#sheet-form h3 { margin: 0 0 14px; font-size: 21px; overflow-wrap: anywhere; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; flex-wrap: wrap; }
.actions .spacer { flex: 1; }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 86px); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px); text-align: center; z-index: 50; }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- screens ---------- */
.hero { padding: 48px 4px 0; text-align: center; }
.hero img { width: 84px; height: 84px; border-radius: 22px; }
.hero h1 { font-size: 30px; margin: 14px 0 6px; letter-spacing: -.02em; }
.hero p { color: var(--muted); margin: 0 0 24px; }
.who-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.who-grid button { border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 18px 8px; display: grid; justify-items: center; gap: 8px; cursor: pointer; font-weight: 600; }
.notice { background: var(--soft); border-radius: var(--radius); padding: 14px; display: flex; gap: 12px; align-items: center; margin-top: 14px; }
.notice p { margin: 0; flex: 1; font-size: 14px; }
.greet { margin: 4px 4px 0; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.stats div { padding: 14px 6px; }
.stats b { display: block; font-size: 26px; letter-spacing: -.02em; }
.stats span { font-size: 12px; color: var(--muted); }
.verdict { text-align: center; font-weight: 700; font-size: 18px; padding: 14px 14px 0; }
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 150px; padding: 16px 14px 10px; }
.bars div { display: grid; gap: 4px; justify-items: center; align-content: end; height: 100%; font-size: 11px; color: var(--muted); cursor: pointer; }
.bars i { display: block; width: 100%; max-width: 34px; background: var(--accent); border-radius: 6px 6px 2px 2px; min-height: 3px; opacity: .85; }
.bars .sel i { opacity: 1; box-shadow: 0 0 0 2px var(--text); }
.bars b { font-size: 12px; color: var(--text); }

/* calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; }
.cal-head b { font-size: 18px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; padding: 6px; }
.cal .dow { font-size: 11px; color: var(--muted); padding: 4px 0; font-weight: 700; }
.cal button { border: 0; background: none; padding: 6px 0 8px; border-radius: 10px; cursor: pointer; display: grid; justify-items: center; gap: 3px; min-height: 46px; }
.cal button.out { opacity: .35; }
.cal button .n { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; font-size: 15px; }
.cal button.today .n { color: var(--accent); font-weight: 800; }
.cal button.sel .n { background: var(--accent); color: #fff; }
.cal .dots { display: flex; gap: 2px; height: 6px; }
.cal .dots i { width: 5px; height: 5px; border-radius: 50%; display: block; }

/* meals */
.meal-day { display: flex; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); align-items: center; }
.meal-day:last-child { border-bottom: 0; }
.meal-day .d { width: 48px; flex: none; text-align: center; }
.meal-day .d b { display: block; font-size: 20px; }
.meal-day .d span { font-size: 12px; color: var(--muted); text-transform: uppercase; font-weight: 700; }
.meal-day.today .d { color: var(--accent); }
.meal-day .meals { flex: 1; display: grid; gap: 4px; min-width: 0; }
.meal-pill { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--bg); cursor: pointer; border: 0; text-align: left; width: 100%; }
.meal-pill .slot { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; width: 52px; flex: none; }
.meal-pill.add { color: var(--muted); background: none; border: 1px dashed var(--line); }

/* dependency map */
.map-wrap { overflow: auto; -webkit-overflow-scrolling: touch; }
.map-wrap svg { width: auto; height: auto; display: block; stroke: none; }
.map-node { cursor: pointer; }
.map-node rect { stroke-width: 2; }
.map-node text { font: 600 13px system-ui, -apple-system, sans-serif; fill: var(--text); }
.map-node text.s { font-weight: 500; font-size: 11px; fill: var(--muted); }
.map-edge { fill: none; stroke: var(--muted); stroke-width: 1.6; opacity: .55; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); padding: 10px 14px; border-top: 1px solid var(--line); }
.legend span { display: inline-flex; gap: 5px; align-items: center; }
.legend i { width: 12px; height: 12px; border-radius: 4px; border: 2px solid; display: inline-block; }

.comment { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.comment:last-child { border-bottom: 0; }
.comment .meta { font-size: 12px; color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; margin-bottom: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.colors label { cursor: pointer; }
.colors input { display: none; }
.colors .dot { width: 32px; height: 32px; border: 3px solid transparent; }
.colors input:checked + .dot { border-color: var(--text); }
ol.steps { padding-left: 20px; margin: 8px 0; }
ol.steps li { margin-bottom: 6px; font-size: 15px; }
