/* Anchor. Calm by default: one accent colour, no red, nothing flashes or bounces.
   Layout follows the screen, not the device: one pane under 700 points wide (the folded Duo,
   any phone), two panes from 700 (the open Duo, iPads), three from 1100. When Safari reports
   fold segments, the panes snap to each side of the fold instead of a fixed split. */

:root {
  --bg: #F5F2EC;
  --surface: #FFFFFF;
  --surface-2: #ECE8E0;
  --ink: #1F2328;
  --ink-2: #5B616A;
  --line: #DED8CC;
  --accent: #2F7D72;
  --accent-ink: #FFFFFF;
  --accent-soft: #DDEEEA;
  --warm: #7E5410;      /* heads-up text */
  --warm-soft: #F6EAD2;
  --warm-fill: #D9A441; /* heads-up ring */
  --rest: #5F86B8;      /* break ring */
  --fs: 17px;
  --gut: 16px;
  --r: 14px;
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171B; --surface: #1E2127; --surface-2: #2A2E36; --ink: #ECEAE6; --ink-2: #A4A9B1;
    --line: #333844; --accent: #6CC3B5; --accent-ink: #0F1A18; --accent-soft: #1E3934;
    --warm: #E7BC6A; --warm-soft: #3A3121; --warm-fill: #D9A441; --rest: #8FB0DC;
    color-scheme: dark;
  }
}
html[data-low-stim] {
  --accent: #5F656C; --accent-ink: #FFFFFF; --accent-soft: var(--surface-2);
  --warm: var(--ink-2); --warm-soft: var(--surface-2); --warm-fill: #A3A8AE; --rest: #A3A8AE;
}
@media (prefers-color-scheme: dark) {
  html[data-low-stim] { --accent: #A3A8AE; --accent-ink: #15171B; --warm-fill: #6E737A; --rest: #6E737A; }
}
html[data-size="l"] { --fs: 19px; }
html[data-size="xl"] { --fs: 22px; }

*, *::before, *::after { box-sizing: border-box; }
html { font-size: var(--fs); height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", sans-serif;
  font-size: 1rem; line-height: 1.45; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
input, textarea { font: inherit; font-size: max(16px, 1rem); color: var(--ink); } /* 16px stops iOS zooming in */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; }
.ico { width: 1.25em; height: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.sa-probe { position: fixed; top: 0; left: 0; visibility: hidden; pointer-events: none; padding: var(--sa-t) var(--sa-r) var(--sa-b) var(--sa-l); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
html[data-low-stim] *, html[data-low-stim] *::before, html[data-low-stim] *::after { transition: none !important; animation: none !important; }

/* ---------- Shell: one pane (folded Duo, any phone) ----------
   The app is a fixed box and only the panes scroll. Safari nudges the page itself after a
   fold; with nothing at page level to scroll, that nudge can't move your place. */
.app {
  position: fixed; inset: 0; display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "bar" "main" "tabs";
}
.bar {
  grid-area: bar; display: flex; align-items: center; gap: 8px;
  padding: calc(var(--sa-t) + 8px) max(var(--gut), var(--sa-r)) 6px max(var(--gut), var(--sa-l));
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; color: var(--accent); }
.brand .ico { width: 1.35em; height: 1.35em; }
.grow { flex: 1; }
.pane { grid-area: main; display: none; flex-direction: column; min-width: 0; min-height: 0; }
.scroll {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 0 max(var(--gut), var(--sa-r)) 32px max(var(--gut), var(--sa-l));
}
.app[data-tab="plan"] .pane-plan,
.app[data-tab="now"] .pane-now,
.app[data-tab="parked"] .pane-parked { display: flex; }

.tabs {
  grid-area: tabs; display: flex; gap: 4px; background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px max(8px, var(--sa-r)) calc(6px + var(--sa-b)) max(8px, var(--sa-l));
}
.tabs button {
  flex: 1; min-height: 50px; border: 0; background: none; border-radius: 12px; color: var(--ink-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .78rem; font-weight: 600;
}
.tabs button[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.tabs b { font-weight: 700; }

/* ---------- Two panes: the open Duo, iPads, a phone on its side ---------- */
@media (min-width: 700px), (horizontal-viewport-segments: 2), (vertical-viewport-segments: 2) {
  .app {
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    grid-template-areas: "bar now" "main now" "tabs now";
  }
  .bar { padding-right: var(--gut); }
  .tabs { padding-right: 8px; }
  .pane-now { grid-area: now; display: flex; border-left: 1px solid var(--line); }
  .pane-now .scroll {
    padding-top: calc(var(--sa-t) + 2px); padding-bottom: calc(var(--sa-b) + 24px);
    padding-left: calc(var(--gut) + 8px); padding-right: max(calc(var(--gut) + 8px), var(--sa-r));
  }
  .pane-plan .scroll, .pane-parked .scroll { padding-right: var(--gut); }
  .app[data-tab] .pane-plan, .app[data-tab] .pane-parked { display: none; }
  .app[data-side="plan"] .pane-plan, .app[data-side="parked"] .pane-parked { display: flex; }
  .tabs .tab-now { display: none; }
}

/* ---------- Three panes: big iPads ---------- */
@media (min-width: 1100px) {
  .app {
    grid-template-columns: minmax(0, 4fr) minmax(0, 5fr) minmax(0, 4fr);
    grid-template-areas: "bar now park" "main now park" "main now park";
  }
  .app[data-side] .pane-plan, .app[data-side] .pane-parked { display: flex; }
  .pane-parked { grid-area: park; border-left: 1px solid var(--line); }
  .pane-parked .scroll { padding-top: calc(var(--sa-t) + 2px); padding-right: max(var(--gut), var(--sa-r)); }
  .tabs { display: none; }
}

/* ---------- Half-folded like a book: a pane on each side, nothing across the fold ---------- */
@media (horizontal-viewport-segments: 2) {
  :root { --fold: calc(env(viewport-segment-left 1 0, 0px) - env(viewport-segment-right 0 0, 0px)); }
  .app {
    grid-template-columns: env(viewport-segment-width 0 0) var(--fold) env(viewport-segment-width 1 0);
    grid-template-areas: "bar . now" "main . now" "tabs . now";
  }
  .app[data-side] .pane-plan, .app[data-side] .pane-parked { display: none; }
  .app[data-side="plan"] .pane-plan, .app[data-side="parked"] .pane-parked { display: flex; }
  .pane-parked { grid-area: main; border-left: 0; }
  .pane-now { border-left: 0; }
  .tabs { display: flex; }
}
/* ---------- Half-folded like a laptop: Now on top, the plan below ---------- */
@media (vertical-viewport-segments: 2) {
  :root { --fold-h: calc(env(viewport-segment-top 0 1, 0px) - env(viewport-segment-bottom 0 0, 0px)); }
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: env(viewport-segment-height 0 0) var(--fold-h) auto minmax(0, 1fr) auto;
    grid-template-areas: "now" "." "bar" "main" "tabs";
  }
  .app[data-side] .pane-plan, .app[data-side] .pane-parked { display: none; }
  .app[data-side="plan"] .pane-plan, .app[data-side="parked"] .pane-parked { display: flex; }
  .pane-parked { grid-area: main; border-left: 0; }
  .pane-now { border-left: 0; }
  .pane-now .scroll { padding-bottom: 12px; padding-left: max(var(--gut), var(--sa-l)); }
  .bar { padding-top: 8px; padding-right: max(var(--gut), var(--sa-r)); }
  .tabs { display: flex; }
}

/* ---------- Content ---------- */
.h { font-size: 1.5rem; line-height: 1.2; margin: 10px 0 4px; letter-spacing: -0.01em; }
.hint { color: var(--ink-2); font-size: .9rem; margin: 4px 0 12px; }
.kicker { color: var(--ink-2); font-size: .88rem; font-weight: 600; margin: 14px 0 4px; overflow-wrap: anywhere; }
.big-q { font-size: 1.35rem; font-weight: 700; line-height: 1.25; margin: 18px 0 6px; }
.now-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.step-text { font-size: 1.6rem; font-weight: 700; line-height: 1.25; margin: 2px 0 6px; overflow-wrap: anywhere; }
.since { color: var(--ink-2); font-size: .88rem; margin: 0 0 14px; min-height: 1.3em; }
.then { color: var(--ink-2); font-size: .92rem; margin: 16px 0 0; padding-top: 12px; border-top: 1px dashed var(--line); overflow-wrap: anywhere; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.row > .btn { flex: 1 1 auto; }
.row.end { justify-content: flex-end; }
.row.end > .btn { flex: 0 1 auto; }

.btn {
  min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 600; text-align: center;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.big { width: 100%; min-height: 60px; font-size: 1.15rem; border-radius: 16px; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: .88rem; }
.btn:active, .chip:active, .tabs button:active { transform: scale(.98); }
.chip {
  min-height: 40px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: .88rem; font-weight: 600; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.icon-btn {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 12px; background: none; color: var(--ink-2);
  display: inline-grid; place-items: center;
}
.icon-btn.sm { width: 40px; height: 40px; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 10px 0; min-height: 44px; text-align: left; }
.back { display: inline-flex; align-items: center; gap: 2px; margin-left: -6px; }
.title-btn { border: 0; background: none; padding: 0; font: inherit; text-align: left; overflow-wrap: anywhere; }

.add { display: flex; gap: 8px; margin: 8px 0 12px; }
.add input {
  flex: 1; min-width: 0; min-height: 48px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
}
.add input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
}
.item.is-current { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.item-main {
  flex: 1; min-width: 0; min-height: 52px; border: 0; background: none; text-align: left;
  padding: 6px 4px 6px 14px; display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.item-title { font-weight: 600; overflow-wrap: anywhere; }
.item-meta { font-size: .82rem; color: var(--ink-2); }
.pill { font-size: .78rem; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.empty { color: var(--ink-2); padding: 16px; border: 1px dashed var(--line); border-radius: var(--r); }
.done-today { margin-top: 20px; color: var(--ink-2); }
.done-today summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
.list.quiet .item { background: transparent; }
.pick { display: grid; gap: 8px; margin-top: 6px; }
.pick .btn { justify-content: flex-start; text-align: left; }

.steps { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 6px; }
.step { display: flex; align-items: center; gap: 2px; padding: 2px 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.tick { width: 44px; height: 44px; flex: none; border: 0; background: none; display: grid; place-items: center; }
.tick .ico { width: 26px; height: 26px; padding: 3px; border-radius: 50%; border: 2px solid var(--line); stroke: transparent; }
.step.done .tick .ico { background: var(--accent); border-color: var(--accent); stroke: var(--accent-ink); }
.step-txt { flex: 1; min-width: 0; min-height: 44px; border: 0; background: none; text-align: left; padding: 10px 4px; overflow-wrap: anywhere; }
.step.done .step-txt { color: var(--ink-2); text-decoration: line-through; text-decoration-color: var(--line); }
.icon-sp { width: 40px; flex: none; }

.crumb { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; font-size: .92rem; margin: 8px 0; overflow-wrap: anywhere; }
.card { border-radius: var(--r); padding: 12px 16px 14px; margin: 10px 0; background: var(--accent-soft); }
.card.body { background: var(--warm-soft); }
.card .crumb { background: var(--surface); }
.card p { margin: 4px 0; overflow-wrap: anywhere; }
.card-title { font-weight: 700; }

/* ---------- Visual timer: a 60-minute face, the coloured wedge is the time left ---------- */
[data-timer-host] { container-type: inline-size; } /* measured inside the safe areas, not the pane */
.timer {
  margin: 22px 0 8px; padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface);
  display: grid; justify-items: center; gap: 12px;
}
.timer-side { display: grid; gap: 6px; justify-items: center; width: 100%; }
.ring { width: min(200px, 56vw, 27vh); height: auto; aspect-ratio: 1; display: block; }
.ring-face { fill: var(--surface-2); }
.ring-fill { fill: var(--accent); }
.ring-ticks line { stroke: var(--ink-2); stroke-width: 1.6; stroke-linecap: round; opacity: .5; }
.ring-hub { fill: var(--surface); }
.timer[data-state="soon"] .ring-fill { fill: var(--warm-fill); }
.timer[data-state="break"] .ring-fill { fill: var(--rest); }
.timer-big { font-size: 2rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; text-align: center; }
.timer[data-state="idle"] .timer-big { font-size: 1.25rem; }
.timer-small { color: var(--ink-2); font-size: .9rem; text-align: center; }
.timer-note { font-size: .9rem; color: var(--warm); background: var(--warm-soft); padding: 8px 12px; border-radius: 10px; text-align: center; }
.timer[data-state="over"] .timer-note, .timer[data-state="break-over"] .timer-note { color: var(--ink); background: var(--accent-soft); }
.timer-acts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; width: 100%; margin-top: 4px; }
.timer-acts .btn { flex: 1 1 76px; white-space: nowrap; }
/* Room to spare (the open Duo, a big phone in a browser): ring on the left, words on the right. */
@container (min-width: 420px) {
  .timer { grid-template-columns: auto minmax(0, 1fr); align-items: center; justify-items: stretch; gap: 16px; }
  .ring { width: min(170px, 38cqw); }
  .timer-side { justify-items: start; }
  .timer-big, .timer-small, .timer-note { text-align: left; }
  .timer-acts { justify-content: flex-start; }
}

/* ---------- Stand: half-fold it on a desk, or tap Stand. Big timer, one step, screen stays on ---------- */
.stand {
  position: fixed; inset: 0; z-index: 30; background: var(--bg); overflow-y: auto;
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 8px;
  padding: calc(var(--sa-t) + 12px) max(var(--gut), var(--sa-r)) calc(var(--sa-b) + 12px) max(var(--gut), var(--sa-l));
}
.stand-a, .stand-b { min-width: 0; min-height: 0; display: flex; flex-direction: column; justify-content: center; }
.stand .timer { margin: 0; border: 0; background: none; grid-template-columns: none; justify-items: center; }
.stand .timer-side { justify-items: center; }
.stand .timer-big, .stand .timer-small, .stand .timer-note { text-align: center; }
.stand .timer-acts { justify-content: center; }
.stand .ring { width: min(76vw, 44vh, 380px); }
.stand .timer-big { font-size: 2.6rem; }
.stand .step-text { font-size: 1.9rem; }
@media (orientation: landscape) {
  .stand { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 24px; }
  .stand .ring { width: min(38vw, 58vh, 380px); }
}
@media (horizontal-viewport-segments: 2) {
  .stand { grid-template-columns: env(viewport-segment-width 0 0) var(--fold) env(viewport-segment-width 1 0); grid-template-rows: minmax(0, 1fr); gap: 0; padding: 0; }
  .stand-a { grid-column: 1; padding: calc(var(--sa-t) + 12px) var(--gut) calc(var(--sa-b) + 12px) max(var(--gut), var(--sa-l)); }
  .stand-b { grid-column: 3; padding: calc(var(--sa-t) + 12px) max(var(--gut), var(--sa-r)) calc(var(--sa-b) + 12px) var(--gut); }
  .stand .ring { width: min(80%, 60vh, 380px); }
}
@media (vertical-viewport-segments: 2) {
  .stand { grid-template-columns: minmax(0, 1fr); grid-template-rows: env(viewport-segment-height 0 0) var(--fold-h) env(viewport-segment-height 0 1); gap: 0; padding: 0; }
  .stand-a { grid-row: 1; padding: calc(var(--sa-t) + 8px) max(var(--gut), var(--sa-r)) 8px max(var(--gut), var(--sa-l)); }
  .stand-b { grid-row: 3; padding: 8px max(var(--gut), var(--sa-r)) calc(var(--sa-b) + 8px) max(var(--gut), var(--sa-l)); justify-content: flex-start; }
  .stand .ring { width: min(70vw, 32vh, 300px); }
}

/* ---------- Sheets, settings, toast ---------- */
/* Near the top, so the keyboard never covers it, and inside the safe areas: folded, the Duo's
   camera strip takes 84 points down the right-hand side. */
dialog.sheet {
  border: 0; padding: 0; color: var(--ink); background: var(--surface); border-radius: 20px;
  position: fixed; top: calc(var(--sa-t) + 12px); bottom: auto;
  left: calc(var(--sa-l) + 12px); right: calc(var(--sa-r) + 12px);
  width: auto; max-width: 520px; margin: 0 auto;
  max-height: calc(100dvh - var(--sa-t) - var(--sa-b) - 24px);
  box-shadow: 0 12px 48px rgba(0, 0, 0, .25);
}
dialog.sheet::backdrop { background: rgba(10, 12, 16, .35); }
@media (horizontal-viewport-segments: 2) {
  dialog.sheet { left: calc(env(viewport-segment-left 1 0) + 12px); }
}
.sheet-in { padding: 18px; display: grid; gap: 6px; max-height: inherit; overflow-y: auto; }
.sheet h3 { margin: 0; font-size: 1.15rem; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin: -6px -8px 0 0; }
.sheet textarea { width: 100%; resize: vertical; min-height: 3.2em; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
.sheet textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.toggle { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle input { width: 24px; height: 24px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.toggle small, .field small { display: block; color: var(--ink-2); font-size: .82rem; }
.field { display: grid; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { min-height: 40px; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-weight: 600; font-size: .88rem; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.sheet details { border-bottom: 1px solid var(--line); padding: 2px 0 8px; }
.sheet summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
.device dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; font-size: .85rem; margin: 0 0 8px; }
.device dt { color: var(--ink-2); }
.device dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.about { margin-top: 12px; }

.toast {
  position: fixed; left: calc(50% + (var(--sa-l) - var(--sa-r)) / 2); transform: translateX(-50%);
  bottom: calc(var(--sa-b) + 78px); z-index: 40;
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px - var(--sa-l) - var(--sa-r));
  padding: 6px 6px 6px 16px; border-radius: 14px; background: var(--ink); color: var(--bg);
  font-size: .92rem; box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}
.toast span { padding: 8px 0; }
.toast .link { color: var(--accent-soft); padding: 8px 12px; min-height: 40px; }
@media (horizontal-viewport-segments: 2) { .toast { left: calc(env(viewport-segment-width 0 0) / 2); max-width: calc(env(viewport-segment-width 0 0) - 32px); } }

@media (max-width: 360px) { .chip .long { display: none; } }
