:root {
  --ground: #EDF0EA;
  --surface: #F8FAF6;
  --surface-2: #E2E8E0;
  --ink: #1F2A24;
  --ink-2: #46544B;
  --muted: #6E7B72;
  --line: #CDD6CB;
  --moss: #3E6B4F;
  --moss-ink: #FFFFFF;
  --honey: #B87A12;
  --honey-soft: #F3E2BC;
  --plum: #7A4E6E;
  --danger: #A23B3B;
  --radius-lg: 22px;
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 48px;
  --font: 'Atkinson Hyperlegible', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --display: 'Young Serif', Georgia, 'Times New Roman', serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #151B19;
    --surface: #1E2724;
    --surface-2: #28332F;
    --ink: #E6ECE5;
    --ink-2: #B9C4BC;
    --muted: #8D9A92;
    --line: #34413B;
    --moss: #8CC09F;
    --moss-ink: #10221A;
    --honey: #E8B54A;
    --honey-soft: #3A3120;
    --plum: #C99BBE;
    --danger: #E58A8A;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 17px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--moss); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; margin: 0; line-height: 1.2; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0; }
a { color: var(--moss); }
.muted { color: var(--muted); }
.small { font-size: .9rem; }

#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 20px) 18px calc(var(--safe-bottom) + 104px);
  outline: none;
}
#view > * + * { margin-top: 22px; }

/* ---------- tabs ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 6px calc(var(--safe-bottom) + 6px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
#tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 52px; justify-content: center;
  color: var(--muted); text-decoration: none; font-size: .78rem; border-radius: var(--radius-sm);
}
#tabs a .ti { font-size: 1.3rem; line-height: 1; }
#tabs a.on { color: var(--ink); }
#tabs a.on .ti { color: var(--moss); }

/* ---------- common ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 700;
}
.btn.primary { background: var(--moss); border-color: var(--moss); color: var(--moss-ink); }
.btn.big { width: 100%; min-height: 58px; font-size: 1.1rem; }
.btn.quiet { background: transparent; border-color: transparent; color: var(--moss); padding: 0 10px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.panel {
  background: var(--surface); border-radius: var(--radius-lg); padding: 18px;
  border: 1px solid var(--line);
}
.stack > * + * { margin-top: 14px; }
input[type=text], input[type=password], input[type=time], input[type=number], textarea {
  width: 100%; min-height: var(--tap); padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
textarea { min-height: 84px; resize: vertical; }
label.field { display: block; }
label.field > span { display: block; font-weight: 700; margin-bottom: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
}
.chip[aria-pressed=true] { background: var(--moss); border-color: var(--moss); color: var(--moss-ink); }

/* ---------- today ---------- */
.greet h1 { font-size: 2.1rem; }
.greet p { margin-top: 4px; color: var(--ink-2); }
.daynav { display: flex; align-items: center; justify-content: space-between; }
.daynav button { min-width: var(--tap); min-height: var(--tap); border: 0; background: none; font-size: 1.4rem; color: var(--ink-2); border-radius: 50%; }
.daynav button:disabled { opacity: .25; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: grid; grid-template-columns: 54px 1fr auto; gap: 12px; align-items: start;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.timeline li:last-child { border-bottom: 0; }
.timeline .t { color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 1px; }
.timeline .what b { font-weight: 700; }
.timeline .what .sub { display: block; color: var(--muted); font-size: .9rem; }
.timeline .del { border: 0; background: none; color: var(--muted); min-width: 40px; min-height: 40px; border-radius: 50%; font-size: 1.1rem; }
.timeline .del.confirm { color: var(--danger); font-size: .85rem; font-weight: 700; width: auto; padding: 0 8px; }
.empty { padding: 28px 8px; text-align: center; color: var(--muted); }
.mini-spoons { display: inline-flex; gap: 2px; vertical-align: -2px; margin-right: 6px; }
.mini-spoons i { width: 6px; height: 14px; border-radius: 3px 3px 2px 2px; background: var(--line); display: block; }
.mini-spoons i.on { background: var(--honey); }

/* ---------- check-in: spoons ---------- */
.spoons { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; align-items: end; }
.spoon {
  position: relative; border: 0; padding: 0; background: none; height: 74px;
  display: flex; align-items: flex-end; justify-content: center; border-radius: 10px;
}
.spoon svg { width: 100%; max-width: 30px; height: 70px; }
.spoon svg path { fill: var(--surface-2); stroke: var(--line); stroke-width: 1; transition: fill .15s; }
.spoon.on svg path { fill: var(--honey); stroke: var(--honey); }
.spoon-readout { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.spoon-readout output { font-family: var(--display); font-size: 2rem; line-height: 1; }
.spoon-readout output small { font-family: var(--font); font-size: .95rem; color: var(--muted); }
.zero { white-space: nowrap; min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px dashed var(--line); background: none; color: var(--muted); font-size: .9rem; }
.zero[aria-pressed=true] { border-style: solid; border-color: var(--plum); color: var(--plum); }

.scale { border: 0; margin: 0; padding: 0; }
.scale legend { padding: 0; font-weight: 700; margin-bottom: 6px; width: 100%; }
.scale legend .ends { float: right; font-weight: 400; color: var(--muted); font-size: .85rem; padding-top: 2px; }
.scale .steps { display: grid; grid-template-columns: repeat(11, 1fr); gap: 3px; }
.scale .steps button {
  min-height: 42px; border: 1px solid var(--line); background: var(--surface); padding: 0;
  border-radius: 8px; font-variant-numeric: tabular-nums; font-size: .92rem; color: var(--ink-2);
}
.scale .steps button[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: var(--surface); font-weight: 700; }

.faces { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.faces button { min-height: 52px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); font-size: .85rem; color: var(--ink-2); padding: 4px; }
.faces button[aria-pressed=true] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.timepair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stepper { display: inline-flex; align-items: center; gap: 12px; }
.stepper button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 1.3rem; }
.stepper output { min-width: 2ch; text-align: center; font-weight: 700; font-size: 1.2rem; }

/* ---------- sheet ---------- */
#sheet-backdrop { position: fixed; inset: 0; background: rgb(10 15 12 / .45); z-index: 20; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: calc(100dvh - var(--safe-top) - 24px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--ground); border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(var(--safe-bottom) + 20px);
  max-width: 600px; margin: 0 auto;
  animation: rise .22s ease-out;
}
#sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
#sheet .sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
#sheet .sheet-head button { border: 0; background: none; color: var(--muted); min-width: 44px; min-height: 44px; font-size: 1.4rem; }
#sheet .stack > * + * { margin-top: 22px; }
#sheet .actions { position: sticky; bottom: calc(-20px - var(--safe-bottom)); padding: 14px 0 calc(var(--safe-bottom) + 4px); background: linear-gradient(transparent, var(--ground) 30%); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #sheet { animation: none; } * { transition: none !important; } }

/* ---------- log grid ---------- */
.kinds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kind {
  aspect-ratio: 1 / .86; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-weight: 700; color: var(--ink);
}
.kind .em { font-size: 1.8rem; line-height: 1; }

/* ---------- talk ---------- */
.talk { display: flex; flex-direction: column; min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 150px); }
.talk-head { display: flex; justify-content: space-between; align-items: center; }
.msgs { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 14px 0; }
.msg { max-width: 86%; padding: 11px 15px; border-radius: 20px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--moss); color: var(--moss-ink); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.pending { color: var(--muted); }
.logged { align-self: flex-start; display: flex; flex-direction: column; gap: 4px; margin: -4px 0 4px 6px; }
.logged span { font-size: .85rem; color: var(--ink-2); padding-left: 14px; position: relative; }
.logged span::before { content: ''; position: absolute; left: 0; top: .5em; width: 7px; height: 7px; border-radius: 50%; background: var(--honey); }
.logged span.gone { text-decoration: line-through; color: var(--muted); }
.logged span.gone::before { background: var(--line); }
.composer {
  position: sticky; bottom: calc(var(--safe-bottom) + 76px);
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: end;
  background: var(--ground); padding-top: 8px;
}
.composer textarea { min-height: 52px; max-height: 160px; border-radius: 24px; padding: 13px 16px; resize: none; }
.round { width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 1.25rem; display: grid; place-items: center; padding: 0; }
.round.primary { background: var(--moss); color: var(--moss-ink); border-color: var(--moss); }
.round.listening { background: var(--plum); border-color: var(--plum); color: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--plum) 25%, transparent); } }
.hint { font-size: .85rem; color: var(--muted); text-align: center; }

/* ---------- patterns ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .series { fill: none; stroke: var(--honey); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--honey); stroke: var(--surface); stroke-width: 2; }
.chart .bar { fill: var(--moss); }
.chart .cross { visibility: hidden; stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .cross.on { visibility: visible; }
.chart .tip {
  position: absolute; top: 0; pointer-events: none; transform: translateX(-50%);
  background: var(--ink); color: var(--surface); padding: 6px 10px; border-radius: 8px; font-size: .85rem; white-space: nowrap;
}
.finding { padding: 14px 0; border-bottom: 1px solid var(--line); }
.finding:last-child { border-bottom: 0; }
.finding .badge { display: inline-block; font-size: .78rem; padding: 2px 9px; border-radius: 999px; margin-bottom: 6px; border: 1px solid var(--line); color: var(--ink-2); }
.finding .badge.strong { background: var(--moss); color: var(--moss-ink); border-color: var(--moss); }
.finding .badge.possible { background: var(--honey-soft); border-color: var(--honey-soft); color: var(--ink); }
.summary h1, .summary h2, .summary h3 { font-size: 1.15rem; margin: 18px 0 6px; }
.summary p { margin: 8px 0; }
.summary ul { padding-left: 1.2em; margin: 8px 0; }
.summary li { margin: 6px 0; }
.progress { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--moss); border-radius: 6px; }
.tod { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.tod div { padding: 10px 4px; border-radius: var(--radius-sm); background: var(--surface-2); }
.tod b { display: block; font-family: var(--display); font-weight: 400; font-size: 1.4rem; }

/* ---------- me ---------- */
.times { display: flex; flex-direction: column; gap: 8px; }
.times .row input { flex: 1; }
.steps-list { padding-left: 1.3em; margin: 0; }
.steps-list li { margin: 8px 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; word-break: break-all; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }

/* ---------- login ---------- */
.login { min-height: 80dvh; display: flex; flex-direction: column; justify-content: center; }
.login .mark { width: 88px; height: 88px; border-radius: 24px; margin-bottom: 18px; }
.login form > * + * { margin-top: 14px; }
.error { color: var(--danger); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 86px); z-index: 30;
  background: var(--ink); color: var(--surface); padding: 12px 18px; border-radius: 999px; font-weight: 700;
  max-width: calc(100vw - 32px); text-align: center;
}
