:root {
  --bg: #1b1f24;        /* graphite wall */
  --raise: #232930;     /* surfaces that hold controls */
  --raise-2: #2d343c;
  --rule: #353d46;
  --chalk: #e8eae4;     /* primary text */
  --dust: #98a1a9;      /* secondary text */
  --tape: #6e9ef0;      /* the one accent: tape on the wall */
  --tape-soft: rgba(110, 158, 240, 0.16);
  --ply: #c8a87a;       /* plywood: links and history */
  --flag: #e6b24e;      /* warnings only */
  --flag-soft: rgba(230, 178, 78, 0.12);
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "Barlow", system-ui, sans-serif;
  --nav-h: 68px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--chalk);
  font: 400 17px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}
main { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 28px) 20px 0; }

h1, h2, h3 { font-family: var(--display); font-weight: 700; margin: 0; line-height: 1.05; letter-spacing: 0.005em; }
h1 { font-size: 44px; }
h2 { font-size: 28px; }
h3 { font-size: 21px; font-weight: 600; }
p { margin: 0; }
.dust { color: var(--dust); }
.num { font-family: var(--display); font-variant-numeric: tabular-nums; }
section { margin-top: 36px; }
section > h2, section > h3 { margin-bottom: 12px; }

/* ---------- header ---------- */
.dayhead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.dayhead .date { color: var(--dust); font-size: 15px; }
.plan-type { margin-top: 20px; font-family: var(--display); font-size: 64px; font-weight: 700; line-height: 0.95; }
.plan-type.is-rest { color: var(--dust); }
.plan-goal { margin-top: 10px; font-size: 18px; max-width: 34ch; }

/* ---------- steps ---------- */
.steps { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.steps li { border-bottom: 1px solid var(--rule); }
.steps label { display: flex; gap: 14px; align-items: flex-start; padding: 13px 2px; cursor: pointer; }
.steps input { appearance: none; flex: none; width: 22px; height: 22px; margin: 2px 0 0; border: 2px solid var(--rule); border-radius: 50%; transition: background .15s, border-color .15s; }
.steps input:checked { background: var(--tape); border-color: var(--tape); box-shadow: inset 0 0 0 4px var(--bg); }
.steps input:checked + span { color: var(--dust); text-decoration: line-through; text-decoration-color: var(--rule); }

/* ---------- notices ---------- */
.notice { margin-top: 20px; padding: 14px 16px; border-left: 3px solid var(--flag); background: var(--flag-soft); border-radius: 0 10px 10px 0; font-size: 16px; }
.notice + .notice { margin-top: 10px; }
.notice.calm { border-color: var(--tape); background: var(--tape-soft); }
.notice button { margin-top: 10px; }

/* ---------- route line (signature) ---------- */
.route { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: end; }
.route svg { display: block; overflow: visible; }
.route .hp { font-family: var(--display); font-weight: 700; font-size: 88px; line-height: 0.85; font-variant-numeric: tabular-nums; }
.route .hp small { font-size: 30px; color: var(--dust); font-weight: 600; margin-left: 4px; }
.route .meta { margin-top: 10px; color: var(--dust); font-size: 15px; line-height: 1.6; }
.route .meta strong { color: var(--chalk); font-weight: 500; }
.route .name { font-family: var(--display); font-size: 22px; font-weight: 600; margin-bottom: 14px; }
.route .sent-tag { color: var(--tape); }
.dot-done { fill: var(--tape); }
.dot-open { fill: none; stroke: var(--rule); stroke-width: 1.5; }
.dot-top { fill: var(--tape); }
.spine { stroke: var(--rule); stroke-width: 1.5; }
.spine-done { stroke: var(--tape); stroke-width: 2.5; }
.link-bar { stroke: var(--ply); stroke-width: 4; stroke-linecap: round; }
.link-bar.old { opacity: 0.32; }
.hp-mark { fill: var(--chalk); }
@media (prefers-reduced-motion: no-preference) {
  .rise .spine-done { animation: rise 900ms cubic-bezier(.2,.7,.2,1) both; }
  .rise .dot-done { animation: pop 300ms ease-out both; }
}
@keyframes rise { from { stroke-dashoffset: var(--len); } to { stroke-dashoffset: 0; } }
@keyframes pop { from { opacity: 0; } to { opacity: 1; } }

/* ---------- timer ---------- */
.timer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; background: var(--raise); border-radius: 18px; }
.timer .clock { font-family: var(--display); font-size: 52px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.timer.done .clock { color: var(--tape); }
.timer .btns { display: flex; gap: 8px; }

/* ---------- buttons & inputs ---------- */
button, .btn {
  font: 600 16px/1 var(--body); color: var(--chalk); background: var(--raise-2);
  border: 0; border-radius: 12px; padding: 13px 18px; cursor: pointer; text-decoration: none; display: inline-block;
  -webkit-tap-highlight-color: transparent; transition: transform .08s, background .15s;
}
button:active, .btn:active { transform: scale(0.97); }
button.primary { background: var(--tape); color: #10213f; }
button.ghost { background: none; color: var(--dust); padding-inline: 8px; }
button.danger { background: none; color: var(--flag); padding-inline: 0; }
button.wide { width: 100%; padding: 17px; font-size: 17px; border-radius: 14px; }
button:disabled { opacity: .45; }
:focus-visible { outline: 2px solid var(--tape); outline-offset: 2px; }

label.field { display: block; margin-top: 18px; }
label.field > span { display: block; font-size: 14px; color: var(--dust); margin-bottom: 6px; }
input[type=text], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; font: 400 17px/1.3 var(--body); color: var(--chalk); background: var(--raise);
  border: 1px solid transparent; border-radius: 10px; padding: 13px 14px; appearance: none; -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--tape); outline: none; }
input[type=date] { min-height: 49px; }
textarea { min-height: 88px; resize: vertical; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--dust) 50%), linear-gradient(135deg, var(--dust) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* segmented choice chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 11px 15px; border-radius: 999px; background: var(--raise); color: var(--dust); font-weight: 500; }
.chips button[aria-pressed=true] { background: var(--chalk); color: var(--bg); }
.chips.flag button[aria-pressed=true]:not([data-v=none]) { background: var(--flag); color: #2a1e05; }
.energy button { flex: 1; font-family: var(--display); font-size: 20px; padding: 10px 0; }

.toggle { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin-top: 22px; }
.switch { appearance: none; width: 52px; height: 32px; border-radius: 99px; background: var(--raise-2); position: relative; margin: 0; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--chalk); transition: transform .2s; }
.switch:checked { background: var(--tape); }
.switch:checked::after { transform: translateX(20px); }

/* ---------- link editor ---------- */
.links { display: grid; gap: 10px; }
.link-row { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 8px; align-items: center; background: var(--raise); border-radius: 14px; padding: 8px; }
.stepper { display: grid; grid-template-columns: 38px 1fr 38px; align-items: center; text-align: center; }
.stepper button { padding: 0; height: 38px; background: var(--raise-2); border-radius: 10px; font-size: 20px; }
.stepper output { cursor: pointer; font-family: var(--display); font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.link-row .to { color: var(--dust); font-size: 14px; }
.link-row .x { background: none; color: var(--dust); padding: 8px; font-size: 20px; }
.link-row.full { box-shadow: inset 0 0 0 1.5px var(--tape); }
.link-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.link-actions button { flex: 1; font-size: 15px; padding: 12px 10px; }

.sticky-save { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); margin-top: 20px; padding: 18px 0 12px; background: linear-gradient(to bottom, transparent, var(--bg) 22px); }

/* ---------- lists ---------- */
.list { list-style: none; padding: 0; margin: 0; }
.list > li { border-top: 1px solid var(--rule); }
.list > li:last-child { border-bottom: 1px solid var(--rule); }
.list a, .list button.item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 16px 2px; color: inherit; text-decoration: none; width: 100%; background: none; border-radius: 0; text-align: left; font: inherit; }
.list .t { font-family: var(--display); font-size: 22px; font-weight: 600; line-height: 1.1; }
.list .s { color: var(--dust); font-size: 15px; grid-column: 1; }
.list .r { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-family: var(--display); font-size: 26px; font-weight: 600; text-align: right; }
.list .r small { display: block; font-family: var(--body); font-size: 13px; color: var(--dust); font-weight: 400; }
.pill { display: inline-block; font-size: 13px; padding: 2px 9px; border-radius: 99px; background: var(--raise-2); color: var(--dust); margin-left: 6px; vertical-align: 2px; }
.pill.pain { background: var(--flag-soft); color: var(--flag); }

/* ---------- charts ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { fill: var(--dust); font: 500 12px var(--body); }
.chart .grid { stroke: var(--rule); stroke-width: 1; }
.chart .top { stroke: var(--rule); stroke-dasharray: 3 5; }
.chart .line { fill: none; stroke: var(--tape); stroke-width: 2.5; stroke-linejoin: round; }
.chart .pt { fill: var(--bg); stroke: var(--tape); stroke-width: 2; }
.chart .bar-hard { fill: var(--tape); }
.chart .bar-light { fill: var(--ply); opacity: .75; }
.legend { display: flex; gap: 18px; margin-top: 10px; font-size: 14px; color: var(--dust); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { padding: 14px 0 0; border-top: 2px solid var(--rule); }
.stats b { display: block; font-family: var(--display); font-size: 34px; font-weight: 600; line-height: 1; }
.stats span { font-size: 14px; color: var(--dust); }

/* ---------- schedule ---------- */
.week { display: grid; gap: 8px; }
.week label { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 12px; }
.week label span { font-family: var(--display); font-size: 20px; font-weight: 600; }
.week label.is-today span { color: var(--tape); }

/* ---------- nav ---------- */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(27, 31, 36, 0.92); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--rule);
}
#nav[hidden] { display: none; }
#nav a { color: var(--dust); text-decoration: none; text-align: center; font-size: 13px; font-weight: 500; padding: 10px 0; -webkit-tap-highlight-color: transparent; }
#nav a[aria-current=page] { color: var(--chalk); }
#nav .log-tab span { display: inline-grid; place-items: center; width: 58px; height: 42px; border-radius: 14px; background: var(--tape); color: #10213f; font: 700 18px var(--display); }
#nav .log-tab[aria-current=page] span { background: var(--chalk); color: var(--bg); }

/* ---------- toast & login ---------- */
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); transform: translate(-50%, 20px);
  background: var(--chalk); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; max-width: calc(100% - 40px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--flag); color: #2a1e05; }

.login { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; }
.login svg { margin-bottom: 24px; }
.login p { margin: 8px 0 20px; }

.back { background: none; color: var(--dust); padding: 0; margin-bottom: 18px; font-weight: 500; }
.split { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.empty { padding: 28px 0; color: var(--dust); }
