/* ── tokens ─────────────────────────────────────────────────── */
:root {
  color-scheme: light;
  --plane:      #f9f9f7;
  --surface:    #fcfcfb;
  --surface-2:  #f0efec;
  --ink:        #0b0b0b;
  --ink-2:      #52514e;
  --ink-mute:   #898781;
  --hair:       #e1e0d9;
  --axis:       #c3c2b7;

  --good:       #0ca30c;
  --critical:   #d03b3b;
  --warning:    #fab219;
  --good-text:  #006300;

  --series:     #2a78d6;
  --seq-0:      #f0efec;
  --seq-1:      #cde2fb;
  --seq-2:      #9ec5f4;
  --seq-3:      #5598e7;
  --seq-4:      #2a78d6;
  --seq-5:      #1c5cab;

  --radius: 16px;
  --tabbar-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:     #0d0d0d;
    --surface:   #1a1a19;
    --surface-2: #262624;
    --ink:       #ffffff;
    --ink-2:     #c3c2b7;
    --ink-mute:  #898781;
    --hair:      #2c2c2a;
    --axis:      #383835;
    --good-text: #0ca30c;
    --series:    #3987e5;
    --seq-0:     #262624;
    --seq-1:     #104281;
    --seq-2:     #184f95;
    --seq-3:     #256abf;
    --seq-4:     #3987e5;
    --seq-5:     #6da7ec;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:     #0d0d0d;  --surface:   #1a1a19;  --surface-2: #262624;
  --ink:       #ffffff;  --ink-2:     #c3c2b7;  --ink-mute:  #898781;
  --hair:      #2c2c2a;  --axis:      #383835;  --good-text: #0ca30c;
  --series:    #3987e5;
  --seq-0: #262624; --seq-1: #104281; --seq-2: #184f95;
  --seq-3: #256abf; --seq-4: #3987e5; --seq-5: #6da7ec;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* An id rule that sets `display` outbids the UA's [hidden] rule, which silently
 * pins the toast and sheet open. Toggling .hidden must always win. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--plane);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior-y: none;
  overflow: hidden;              /* only #screens scrolls — see #app */
}
button { font: inherit; color: inherit; }

/* Pinned to the viewport rather than sized in viewport units. With
 * viewport-fit=cover and a translucent status bar the web view is the whole
 * display, but 100dvh does not measure the whole display — the column came up
 * short by the top inset and the tab bar floated above the bottom edge.
 * inset:0 has no such gap to fall into. */
#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; overflow: hidden;
}
#screens {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;      /* a scrollbar arriving must not reflow the row */
  padding: max(12px, env(safe-area-inset-top)) 16px 24px;
}
#screens > .screen { max-width: 560px; width: 100%; margin: 0 auto; }

.screen-head { margin: 6px 0 18px; }
.screen-head h1 { margin: 0; font-size: 30px; letter-spacing: -0.02em; }
.head-sub { color: var(--ink-2); font-size: 14px; margin-top: 2px; }

/* ── the big button ─────────────────────────────────────────── */
.big-button-wrap { display: flex; justify-content: center; margin: 8px 0 20px; }
.big-button {
  width: min(270px, 74vw); aspect-ratio: 1; border-radius: 50%;
  border: none; background: var(--good); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; cursor: pointer; transition: transform .12s ease, background .2s ease;
  box-shadow: 0 10px 30px -10px rgba(0,0,0,.45);
}
.big-button:active { transform: scale(.965); }
.big-button.is-in { background: var(--critical); }
.bb-action { font-size: 30px; font-weight: 700; letter-spacing: .01em; }
.bb-timer  { font-size: 21px; font-variant-numeric: tabular-nums; opacity: .95; }
.bb-hint   { font-size: 13px; opacity: .85; max-width: 76%; text-align: center; }

/* ── buttons ────────────────────────────────────────────────── */
.row-actions { display: flex; gap: 10px; margin-bottom: 18px; }
.row-actions.stack { flex-direction: column; }
.btn {
  flex: 1; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--hair);
  background: var(--surface); cursor: pointer; font-size: 15px; font-weight: 500;
}
.btn:active { background: var(--surface-2); }
.btn-primary { background: var(--series); border-color: var(--series); color: #fff; }
.btn-danger  { color: var(--critical); }
.btn-block   { width: 100%; }

/* ── cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--hair);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.card-tap { display: block; width: 100%; text-align: left; cursor: pointer; }
.card h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; color: var(--ink-2); }

.today-top { display: flex; justify-content: space-between; align-items: flex-start; }
.hero { font-size: 40px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.05; }
.hero-sub { color: var(--ink-2); font-size: 14px; margin-top: 2px; }
.today-pct { font-size: 22px; font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.meter { height: 10px; border-radius: 999px; background: var(--surface-2); margin: 14px 0 10px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; background: var(--series); width: 0; transition: width .3s ease; }
.meter-fill.is-met { background: var(--good); }
.guidance { margin: 0; font-size: 15px; color: var(--ink); }
.guidance strong { font-weight: 650; }

.chip-main { font-weight: 600; font-size: 16px; }
.chip-sub  { color: var(--ink-2); font-size: 14px; margin-top: 3px; }

.banner {
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
  border: 1px solid var(--warning); background: color-mix(in srgb, var(--warning) 12%, var(--surface));
  font-size: 14px;
}
.banner b { display: block; margin-bottom: 4px; }

/* ── history ────────────────────────────────────────────────── */
.day { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.day-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; width: 100%; background: none; border: none; text-align: left; cursor: pointer; }
.day-date { flex: 1; }
.day-date b { display: block; font-size: 16px; }
.day-date span { color: var(--ink-2); font-size: 13px; }
.day-hours { display: block; font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }
.day-flag { display: block; font-size: 12px; color: var(--ink-2); text-align: right; margin-top: 1px; }
.day-flag.met { color: var(--good-text); }
.day-body { border-top: 1px solid var(--hair); padding: 6px 16px 12px; }
.sess { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--hair); }
.sess:last-child { border-bottom: none; }
.sess-time { flex: 1; font-variant-numeric: tabular-nums; }
.sess-dur { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.sess-tag { font-size: 11px; color: var(--ink-mute); border: 1px solid var(--hair); border-radius: 6px; padding: 1px 5px; }
.linkbtn { background: none; border: none; color: var(--series); cursor: pointer; padding: 4px 6px; font-size: 14px; }

/* ── stats ──────────────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 14px; }
.tile-val { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile-lab { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.tile-note { color: var(--ink-mute); font-size: 12px; margin-top: 4px; }

.chart { position: relative; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 150px; position: relative; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.bar {
  background: var(--series); border-radius: 4px 4px 0 0; min-height: 2px;
  border-bottom: 2px solid var(--surface);
}
.bar.empty { background: var(--surface-2); }
.target-line { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--axis); }
.target-lab { position: absolute; right: 0; font-size: 11px; color: var(--ink-mute); transform: translateY(-100%); background: var(--surface); padding: 0 3px; }
.xlabels { display: flex; gap: 3px; margin-top: 6px; }
.xlabels span { flex: 1; text-align: center; font-size: 10px; color: var(--ink-mute); font-variant-numeric: tabular-nums; }

.heat { display: flex; gap: 2px; }
.heat-cell { flex: 1; height: 34px; border-radius: 3px; background: var(--seq-0); }
.legend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); margin-top: 10px; }
.legend .swatches { display: flex; gap: 2px; }
.legend i { width: 16px; height: 10px; border-radius: 2px; display: block; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th, table.tbl td { text-align: left; padding: 7px 4px; border-bottom: 1px solid var(--hair); }
table.tbl th { color: var(--ink-2); font-weight: 500; font-size: 12px; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── aligner grid ───────────────────────────────────────────── */
.agrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.acell {
  aspect-ratio: 1; border-radius: 12px; border: 1px solid var(--hair);
  background: var(--surface); display: flex; flex-direction: column;
  align-items: center; justify-content: center; cursor: pointer; position: relative;
}
.acell b { font-size: 18px; }
.acell small { font-size: 10px; color: var(--ink-2); }
.acell.done { background: var(--surface-2); }
.acell.current { border-color: var(--series); border-width: 2px; }
.acell .redo { position: absolute; top: 3px; right: 5px; font-size: 10px; color: var(--warning); }
.acell .hasnote { position: absolute; bottom: 3px; right: 5px; font-size: 9px; color: var(--ink-mute); }

.stint-row { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--hair); font-size: 14px; }
.stint-row:last-child { border-bottom: none; }
.stint-n { font-weight: 650; min-width: 74px; }
.stint-meta { flex: 1; color: var(--ink-2); font-size: 13px; }

/* ── tab bar ────────────────────────────────────────────────── */
#tabbar {
  flex: 0 0 auto; z-index: 20;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--hair);
  /* Keeps the labels clear of the home indicator; the bar's own background
   * continues underneath it to the physical bottom of the screen. */
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; cursor: pointer; padding: 7px 2px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10px; color: var(--ink-mute); height: var(--tabbar-h);
}
.tab-ico { font-size: 17px; line-height: 1; }
.tab.is-active { color: var(--series); }

/* ── sheet + toast ──────────────────────────────────────────── */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  max-width: 560px; margin: 0 auto;
  box-shadow: 0 -8px 40px -12px rgba(0,0,0,.5);
}
#sheet h2 { margin: 0 0 4px; font-size: 20px; }
#sheet .sheet-sub { color: var(--ink-2); font-size: 14px; margin: 0 0 16px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px; font: inherit; color: var(--ink);
  background: var(--plane); border: 1px solid var(--hair); border-radius: 10px;
}
.field textarea { min-height: 80px; resize: vertical; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.chip {
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--hair);
  background: var(--plane); font-size: 14px; cursor: pointer;
}
.chip:active, .chip.on { background: var(--series); color: #fff; border-color: var(--series); }
.err { color: var(--critical); font-size: 14px; margin: 0 0 12px; }

#toast {
  position: fixed; left: 16px; right: 16px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  z-index: 40; background: var(--ink); color: var(--plane);
  border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; gap: 12px;
  max-width: 528px; margin: 0 auto; font-size: 14px;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,.5);
}
#toast button { background: none; border: none; color: var(--plane); font-weight: 650; text-decoration: underline; cursor: pointer; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.empty-note { color: var(--ink-2); text-align: center; padding: 32px 16px; font-size: 15px; }
