:root {
  color-scheme: dark;
  --bg: #121416;
  --card: #1c1f23;
  --card-2: #23272c;
  --line: #2e3238;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #3ddc97;
  --accent-ink: #052a1a;
  --accent-soft: rgba(61, 220, 151, 0.14);
  --warn: #f2b84b;
  --warn-soft: rgba(242, 184, 75, 0.14);
  --kaza: #ff8a5b;
  --kaza-soft: rgba(255, 138, 91, 0.16);
  --danger: #ff6b6b;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f5f2;
    --card: #ffffff;
    --card-2: #f0f2ee;
    --line: #e2e5df;
    --text: #1b1f1c;
    --muted: #646b66;
    --accent: #0f9d63;
    --accent-ink: #ffffff;
    --accent-soft: rgba(15, 157, 99, 0.12);
    --warn: #b7791f;
    --warn-soft: rgba(183, 121, 31, 0.12);
    --kaza: #d4582a;
    --kaza-soft: rgba(212, 88, 42, 0.12);
    --danger: #d43c3c;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h2 { font-size: 18px; margin: 0 0 4px; font-weight: 650; }
h3 { margin: 0 0 6px; font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
[hidden] { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.loc {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0;
  background: none; border: 0; padding: 6px 0; font-size: 17px; font-weight: 600;
}
.loc span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loc svg { color: var(--accent); flex: none; }
.sync { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: transparent; flex: none; }
.sync.syncing { background: var(--warn); }
.sync.error { background: var(--danger); }

main { max-width: 560px; margin: 0 auto; padding: 4px 16px calc(96px + var(--safe-b)); }
.view { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  border: 1px solid var(--line);
}
a.card { color: inherit; text-decoration: none; display: block; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card-2); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.kaza { background: var(--kaza); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.icon-btn { background: none; border: 0; padding: 6px; color: var(--muted); border-radius: 10px; }

/* install */
.install { position: relative; }
.install-close { position: absolute; top: 8px; right: 8px; }
.install-head { display: flex; gap: 12px; align-items: center; padding-right: 28px; }
.install-head img { border-radius: 11px; flex: none; }
.install-title { font-weight: 650; }
.install-steps { margin: 12px 0 0; padding-left: 20px; display: grid; gap: 4px; }
.install .btn { margin-top: 12px; width: 100%; }

/* hero */
.hero { text-align: center; padding: 20px 16px; background: linear-gradient(160deg, var(--accent-soft), transparent 70%), var(--card); }
.hero-label { font-size: 15px; color: var(--muted); }
.hero-name { font-size: 22px; font-weight: 700; margin-top: 2px; }
.hero-count { font-size: 46px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -1px; line-height: 1.15; margin: 6px 0 2px; }
.hero-count.warn { color: var(--warn); }
.hero-sub { color: var(--muted); font-size: 14.5px; }
.bar { height: 6px; background: var(--card-2); border-radius: 6px; overflow: hidden; margin: 14px 0 0; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.bar.kaza > span { background: var(--kaza); }
.hero .btn { margin-top: 16px; min-width: 60%; }
.hero-done { margin-top: 14px; color: var(--accent); font-weight: 600; display: inline-flex; gap: 6px; align-items: center; }

/* missed */
.missed h2 { font-size: 16px; }
.missed ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.missed li { display: flex; align-items: center; gap: 8px; }
.missed li > span { flex: 1; }
.missed .btn { min-height: 36px; padding: 0 12px; font-size: 14px; }

/* times */
.seg { display: flex; margin: 12px -16px 0; border-bottom: 1px solid var(--line); }
.seg button { flex: 1; background: none; border: 0; padding: 12px 0; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.seg button[aria-selected='true'] { color: var(--text); border-bottom-color: var(--accent); }
.tlist { list-style: none; margin: 0; padding: 0; }
.tlist li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.tlist li:last-child { border-bottom: 0; }
.tlist .name { flex: 1; font-size: 18px; }
.tlist .time { font-size: 18px; font-variant-numeric: tabular-nums; }
.tlist li.now .name, .tlist li.now .time { color: var(--accent); font-weight: 700; }
.tlist li.past .name, .tlist li.past .time { color: var(--muted); }
.check {
  width: 34px; height: 34px; flex: none; border-radius: 50%; border: 2px solid var(--line);
  background: none; display: grid; place-items: center; padding: 0; font-weight: 700; font-size: 14px;
}
.check svg { width: 18px; height: 18px; stroke-width: 2.6; }
.check.eda { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check.kaza { background: var(--kaza-soft); border-color: var(--kaza); color: var(--kaza); }
.check.due { border-color: var(--accent); }
.check.late { border-color: var(--warn); border-style: dashed; }
.check:disabled { opacity: 0.35; cursor: default; }
.check-gap { width: 34px; flex: none; }
.month { overflow-x: auto; margin: 0 -16px; }
.month table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14.5px; }
.month th { font-weight: 500; color: var(--muted); font-size: 12.5px; text-align: left; padding: 10px 6px; }
.month td { padding: 9px 6px; border-top: 1px solid var(--line); white-space: nowrap; }
.month th:first-child, .month td:first-child { padding-left: 16px; }
.month tr.today td { background: var(--accent-soft); font-weight: 700; }
.foot { margin: 12px 0 0; }

/* habit */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 14px; }
.stat { background: var(--card-2); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--muted); }
.grid { display: grid; grid-template-columns: 44px repeat(14, 1fr); gap: 3px; align-items: center; font-size: 11.5px; color: var(--muted); }
.grid .cell { aspect-ratio: 1; border-radius: 4px; background: var(--card-2); }
.grid .cell.eda { background: var(--accent); }
.grid .cell.kaza { background: var(--kaza); }
.grid .cell.off { opacity: 0.35; }
.grid .cell.today { outline: 1.5px solid var(--muted); outline-offset: 1px; }
.grid .d { text-align: center; }
.legend { display: flex; gap: 14px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.nudge { display: flex !important; align-items: center; gap: 14px; }
.nudge .ring { width: 54px; height: 54px; flex: none; }
.nudge .ring svg { width: 54px; height: 54px; transform: rotate(-90deg); }
.nudge > div { flex: 1; }
.nudge .chev { color: var(--muted); }

/* kaza */
.kaza-sum { text-align: center; }
.kaza-sum .big { font-size: 48px; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -1px; line-height: 1.1; }
.kaza-sum .bar { margin-top: 14px; }
.kaza-sum .meta { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px; color: var(--muted); }
.kaza-sum .eta { margin-top: 12px; font-size: 14.5px; }
.klist { list-style: none; margin: 8px 0 0; padding: 0; }
.klist li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.klist li:last-child { border-bottom: 0; }
.klist .kname { flex: 1; min-width: 0; }
.klist .kname b { font-size: 17px; }
.klist .kname div { font-size: 12.5px; color: var(--muted); }
.klist .left { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }
.klist .minus { width: 36px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: none; font-size: 20px; color: var(--muted); }
.klist .plus { min-height: 40px; padding: 0 14px; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 110px; margin-top: 14px; position: relative; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.chart .col i { display: block; width: 100%; background: var(--kaza); border-radius: 4px 4px 2px 2px; min-height: 2px; opacity: 0.9; }
.chart .col.zero i { background: var(--card-2); }
.chart .col span { font-size: 10.5px; color: var(--muted); }
.chart .goal { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--muted); opacity: 0.6; }
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.field { display: grid; gap: 4px; font-size: 13.5px; color: var(--muted); }
.field input { width: 100%; min-height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card-2); font-size: 17px; color: var(--text); }
.check-row { display: flex; gap: 10px; align-items: center; margin: 6px 0 2px; }
.check-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.manual { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 12px; }

/* settings */
.setting { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.setting > div:first-child { flex: 1; }
.inline { display: flex; align-items: center; gap: 10px; }
input[type='time'], select {
  min-height: 38px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2);
}
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 14px; background: var(--line); transition: background 0.15s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.loc-now { display: flex; align-items: center; gap: 12px; margin: 8px 0 12px; }
.loc-now > div { flex: 1; min-width: 0; }
.loc-now #set-loc-name { font-weight: 600; font-size: 17px; }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--card-2); border-radius: 12px; padding: 0 12px; }
.search svg { color: var(--muted); flex: none; width: 20px; height: 20px; }
.search input { flex: 1; min-width: 0; border: 0; background: none; min-height: 44px; outline: none; font-size: 16px; }
.results { list-style: none; margin: 6px 0 0; padding: 0; }
.results button { width: 100%; text-align: left; background: none; border: 0; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.results button div { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.push-state { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 10px 0 14px; }
.push-state p { margin: 0; flex-basis: 100%; }
.remind { list-style: none; margin: 0; padding: 0; }
.remind li { border-top: 1px solid var(--line); padding: 10px 0; }
.remind .r-name { font-weight: 650; margin-bottom: 6px; }
.remind .r-row { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.remind .r-row > span { flex: 1; }
.remind select { min-width: 84px; }
.adjust { list-style: none; margin: 10px 0 0; padding: 0; }
.adjust li { display: flex; align-items: center; padding: 6px 0; }
.adjust li > span { flex: 1; }
.adjust .base { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 12px; font-size: 14px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stepper button { width: 40px; height: 38px; border: 0; background: var(--card-2); font-size: 19px; }
.stepper span { min-width: 54px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.code-row { display: flex; gap: 8px; margin-top: 12px; }
.code-row code, .code-row input {
  flex: 1; min-width: 0; min-height: 42px; display: flex; align-items: center; padding: 0 12px; border-radius: 12px;
  background: var(--card-2); border: 1px solid var(--line); font-family: ui-monospace, Menlo, monospace; font-size: 14px; overflow-wrap: anywhere;
}

/* tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  padding: 6px 8px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; max-width: 180px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600; border-radius: 12px;
}
.tabs a[aria-current='page'] { color: var(--accent); }
.tabs a[aria-current='page'] svg { background: var(--accent-soft); border-radius: 12px; }
.tabs svg { width: 46px; height: 28px; padding: 3px 12px; }

/* sheet + toast */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; background: var(--card); border-radius: 22px 22px 0 0; padding: 22px 16px calc(16px + var(--safe-b)); animation: up 0.18s ease-out; }
.sheet-actions { display: grid; gap: 8px; margin-top: 14px; }
.sheet-actions .btn { width: 100%; min-height: 48px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-b)); z-index: 15;
  display: flex; align-items: center; gap: 14px; max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; font-size: 14.5px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 0; filter: brightness(0.8); }
@media (prefers-color-scheme: light) { .toast button { filter: none; color: #3ddc97; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
