  /* Atkinson Hyperlegible Next (SIL OFL): latin + latin-ext, one variable file each for 400-600. Relative paths. */
  @font-face{font-family:"Atkinson Hyperlegible Next";font-style:normal;font-weight:400 600;font-display:swap;
    src:url("fonts/atkinson-hyperlegible-next-ext.woff2") format("woff2");
    unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C4,U+2113,U+2C60-2C7F,U+A720-A7FF;}
  @font-face{font-family:"Atkinson Hyperlegible Next";font-style:normal;font-weight:400 600;font-display:swap;
    src:url("fonts/atkinson-hyperlegible-next.woff2") format("woff2");
    unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;}
  :root{--bg:#f7f4ef;--surface:#fffdf9;--ink:#1f1d1a;--muted:#6f6a62;
    --line:rgba(31,29,26,.09);--accent:#5f7a94;--accent-soft:rgba(95,122,148,.12);--radius:20px;
    --on-accent:#fff;--press:rgba(0,0,0,.04);--fill:rgba(31,29,26,.04);--fill-strong:rgba(31,29,26,.09);
    --track:rgba(31,29,26,.1);--circle-border:rgba(31,29,26,.45);--backdrop:rgba(31,29,26,.35);
    --shadow:rgba(0,0,0,.15);--toast-bg:#26241f;--toast-ink:#f7f4ef;--toast-undo:#8fd3bd;--qr-bg:#fff;--qr-ink:#000;
    --tier-short:#a37464;--tier-full:#5f7a94;--tier-standard:#7e8c62;--tier-survival:#a39063;
    --ov-0:#8ca8d1;--ov-1:#7bb58b;--ov-2:#e2b067;--ov-3:#a78bbd;--ov-4:#6fb6b6;--ov-5:#8c9eba;--ov-6:#d19e8c;--ov-7:#c8a38b;--ov-8:#b5b57b;--ov-9:#8b9a8b;--ov-10:#c294b1;--ov-11:#9f9f9f;--ov-12:#7e9e9e;--ov-13:#b6a87e;--ov-14:#92a89e;--ov-15:#c88c8c;--ov-16:#a3a3b5;--ov-17:#879e94;--ov-18:#d1b28c;--ov-19:#9eb1c8;
    color-scheme:light;}
  :root[data-theme="dark"]{--bg:#1a1917;--surface:#242220;--ink:#ece8e1;--muted:#9d978d;
    --line:rgba(236,232,225,.1);--accent:#8fa9c4;--accent-soft:rgba(143,169,196,.16);
    --on-accent:#14130f;--press:rgba(255,255,255,.07);--fill:rgba(236,232,225,.06);--fill-strong:rgba(236,232,225,.12);
    --track:rgba(236,232,225,.14);--circle-border:rgba(236,232,225,.3);--backdrop:rgba(0,0,0,.55);
    --shadow:rgba(0,0,0,.5);--toast-bg:#3a3732;--toast-ink:#f1ede6;--toast-undo:#8fd3bd;--qr-bg:#fff;--qr-ink:#000;
    --tier-full:#97aec4;--tier-standard:#b3bf9b;--tier-short:#c7a193;--tier-survival:#c8b893;
    --ov-0:#9cb7dd;--ov-1:#a7d2b3;--ov-2:#f1c689;--ov-3:#bfa8d2;--ov-4:#a4d6d6;--ov-5:#aab9d0;--ov-6:#ddad9c;--ov-7:#d8b7a2;--ov-8:#d2d2a7;--ov-9:#b7c2b7;--ov-10:#d2a8c2;--ov-11:#bdbdbd;--ov-12:#b2c7c7;--ov-13:#d2c7a8;--ov-14:#b4c5bd;--ov-15:#d8a2a2;--ov-16:#b4b4c5;--ov-17:#b5c5be;--ov-18:#ddc09c;--ov-19:#a8bbd2;
    color-scheme:dark;}
  *{box-sizing:border-box;-webkit-tap-highlight-color:transparent;}
  html,body{margin:0;padding:0;background:var(--bg);color:var(--ink);
    font-family:"Atkinson Hyperlegible Next",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
    font-size:16px;line-height:1.45;-webkit-font-smoothing:antialiased;}

  .app{max-width:430px;margin:0 auto;
    padding-top:max(24px, env(safe-area-inset-top, 0px));
    padding-right:max(18px, env(safe-area-inset-right, 0px));
    padding-bottom:max(48px, env(safe-area-inset-bottom, 0px));
    padding-left:max(18px, env(safe-area-inset-left, 0px));
    min-height:100vh;min-height:100dvh;
    display:flex;flex-direction:column;}

  .hidden{display:none !important;}
  button{font:inherit;color:inherit;cursor:pointer;border:none;background:none;}
  .ghost{font-size:13px;color:var(--muted);padding:8px 10px;border-radius:10px;}
  .ghost:active{background:var(--press);}
  .card{background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);
    padding:20px;box-shadow:0 1px 2px rgba(31,29,26,.03),0 8px 24px -18px rgba(31,29,26,.18);}
  .eyebrow{font-size:13px;font-weight:600;color:var(--accent);margin-bottom:10px;}

  #capacity{display:flex;flex-direction:column;flex:0 0 auto;}
  #capacity h1{font-size:26px;font-weight:600;letter-spacing:-.02em;margin:0 0 24px;line-height:1.25;}
  .tiers{display:flex;flex-direction:column;gap:10px;}
  .tier{display:flex;align-items:center;gap:14px;width:100%;min-height:60px;padding:0 18px;
    background:var(--surface);border:1px solid var(--line);border-radius:16px;
    font-size:17px;font-weight:500;text-align:left;transition:transform .12s ease,border-color .12s ease;}
  .tier:active{transform:scale(.985);border-color:var(--tier-color);}
  /* Day-shape strip: blocks in the tier colour show how much the day holds (no numbers). */
  .tier .swatch{display:flex;gap:3px;width:52px;flex:none;align-items:center;}
  .tier .swatch i{display:block;width:8px;height:16px;border-radius:3px;background:var(--tier-color);flex:none;}
  .same-as{display:flex;align-items:center;gap:12px;width:100%;min-height:52px;padding:0 18px;
    background:transparent;border:1.5px dashed var(--line);border-radius:16px;
    font-size:14px;font-weight:500;text-align:left;color:var(--muted);margin-bottom:8px;}
  .same-as .swatch{width:10px;height:10px;border-radius:50%;flex:none;background:var(--muted);opacity:.55;}
  .same-as strong{color:var(--ink);font-weight:600;}
  .same-as:active{background:var(--press);}
  .hint{margin:20px 0 0;font-size:13px;color:var(--muted);text-align:center;}
  .later-link{display:flex;justify-content:center;align-items:center;gap:6px;margin-top:10px;
    padding:10px;font-size:13px;color:var(--muted);border-radius:10px;width:100%;}
  .later-link:active{background:var(--press);}

  /* Bottom menu: fixed bar outside .app, shown only on the capacity and day screens (refreshNav). */
  :root{--nav-h:calc(58px + env(safe-area-inset-bottom, 0px));}
  #bottom-nav{position:fixed;left:0;right:0;bottom:0;width:100%;
    height:var(--nav-h);padding:0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);z-index:50;
    display:flex;background:var(--surface);border-top:1px solid var(--line);}
  .nav-btn{flex:1 1 0;min-width:0;display:flex;flex-direction:column;align-items:center;justify-content:center;
    gap:3px;color:var(--muted);font-size:11px;border-radius:0;}
  .nav-btn svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;}
  .nav-btn:active{background:var(--press);}
  .nav-btn.active{color:var(--accent);}
  .nav-btn span{white-space:nowrap;}
  body:has(#bottom-nav:not(.hidden)) .app{padding-bottom:calc(var(--nav-h) + 24px);}
  body:has(#bottom-nav:not(.hidden)) .toast:not(.toast-raised){bottom:calc(var(--nav-h) + 10px);}
  @media (max-height:480px){ .nav-btn span{display:none;} :root{--nav-h:calc(42px + env(safe-area-inset-bottom, 0px));} }

  #checkin{margin-top:22px;}
  #capacity:not(.hidden) ~ #checkin{margin-top:auto;padding-top:22px;}
  /* The check-in belongs to the capacity/day screens, never to the drill-down screens. */
  body:has(#later:not(.hidden), #week:not(.hidden), #med-history:not(.hidden), #meds-screen:not(.hidden), #firstweek:not(.hidden), #settings:not(.hidden), #journal:not(.hidden), #summary:not(.hidden)) #checkin{display:none !important;}
  .checkin-card{border-color:var(--accent-soft);}
  .checkin-q{font-size:22px;font-weight:600;letter-spacing:-.02em;line-height:1.3;margin-bottom:20px;}
  .checkin-opts{display:flex;flex-direction:column;gap:8px;margin-bottom:12px;}
  .checkin-opt{min-height:52px;padding:0 18px;background:var(--surface);
    border:1px solid var(--line);border-radius:14px;font-size:16px;font-weight:500;
    text-align:left;display:flex;align-items:center;transition:transform .12s ease,border-color .12s ease;}
  .checkin-opt:active{transform:scale(.985);border-color:var(--accent);}
  .checkin-skip{display:block;width:100%;padding:10px;font-size:13px;color:var(--muted);
    text-align:center;border-radius:10px;}
  .checkin-skip:active{background:var(--press);}

  #capacity-footer{display:flex;gap:8px;justify-content:center;flex-wrap:wrap;
    padding-top:14px;margin-top:18px;border-top:1px solid var(--line);flex:0 0 auto;}
  #capacity.hidden ~ #capacity-footer{display:none;}
  #capacity-footer .ghost{font-size:12px;opacity:.7;}
  body:not(.demo-mode) #capacity-footer{display:none !important;}

  body:not(.demo-mode) .demo-btn{display:none !important;}
  body:not(.demo-mode) #day-footer{display:none !important;}

  /* Line icons that replace emoji (pill, lock); colour and size follow the surrounding text. */
  .ui-icon{width:1.1em;height:1.1em;vertical-align:-.17em;fill:none;stroke:currentColor;stroke-width:1.7;
    stroke-linecap:round;stroke-linejoin:round;flex:none;}
  .label-pill{margin-right:6px;}
  .med-row .med-icon{display:inline-flex;}
  /* Invisible 44px tap area around small quiet buttons; the look and layout stay the same. */
  #btn-change{position:relative;}
  #btn-change::before{content:"";position:absolute;left:-12px;right:0;top:50%;
    height:44px;transform:translateY(-50%);}
  #btn-change{-webkit-touch-callout:none;user-select:none;}
  #btn-change.demo-on{color:var(--accent);}
  #btn-change.demo-on::after{content:"";display:inline-block;width:5px;height:5px;
    border-radius:50%;background:var(--accent);margin-left:6px;vertical-align:middle;opacity:.8;}

  header{display:flex;align-items:center;justify-content:space-between;margin-bottom:18px;}
  .chip{display:flex;align-items:center;gap:9px;font-size:13px;font-weight:600;color:var(--muted);}
  .chip .swatch{width:10px;height:10px;border-radius:50%;background:var(--accent);}
  .hdr-right{display:flex;align-items:center;gap:12px;}
  /* Settings gear (top of the capacity and day screens): 44px tap area that never grows the header. */
  .gear-slot{display:inline-flex;flex:none;}
  .gear-btn{position:relative;display:inline-flex;align-items:center;justify-content:flex-end;
    width:30px;height:22px;margin:-3px 0;padding:0;color:var(--muted);border-radius:10px;}
  .gear-btn::before{content:"";position:absolute;left:-12px;right:0;top:50%;height:44px;transform:translateY(-50%);}
  .gear-btn:active{background:var(--press);}
  .gear-btn svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;}
  /* Small phones: three header icons and "Change" leave the day label on one line. */
  @media (max-width:340px){
    #day > header .hdr-right{gap:6px;}
    #day > header .gear-btn{width:24px;justify-content:center;}
    #day > header .gear-btn::before{left:-6px;} /* never past the right edge: that would scroll sideways */
    #day > header #btn-change{padding-left:4px;padding-right:4px;}
    #day > header #btn-change::before{left:-3px;}
    #day > header .chip{gap:6px;white-space:nowrap;}
  }
  .cap-head{display:flex;align-items:flex-start;gap:12px;}
  .cap-head h1{flex:1 1 auto;min-width:0;}
  .cap-head .gear-btn{margin-top:5px;}
  .now{margin-bottom:22px;border-color:var(--accent-soft);}
  /* Next step on the Now card (C13): one line, one tick, no counts. */
  .now-step{display:flex;align-items:center;gap:10px;width:100%;min-height:40px;padding:6px 10px;margin:0 0 8px;
    background:var(--fill);border-radius:10px;font-size:14px;color:var(--ink);text-align:left;}
  .now-step:active{background:var(--press);}
  .now-step:focus-visible{outline:2px solid var(--accent);outline-offset:2px;}
  .now-step-tick{flex:none;width:18px;height:18px;border-radius:50%;border:1.7px solid var(--muted);
    transition:background .15s ease,border-color .15s ease;}
  .now-step.is-ticked .now-step-tick{background:var(--accent);border-color:var(--accent);}
  .now-step.is-ticked .now-step-text{color:var(--muted);}
  .now-step-text{flex:1 1 auto;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
  .now-label{font-size:24px;font-weight:600;letter-spacing:-.02em;line-height:1.2;
    margin-bottom:6px;overflow-wrap:break-word;}
  .now-meta{font-size:13px;color:var(--muted);display:flex;align-items:center;gap:8px;
    min-height:18px;margin-bottom:14px;flex-wrap:wrap;}
  .bar{height:4px;border-radius:2px;background:var(--track);overflow:hidden;margin-bottom:16px;}
  .bar-fill{height:100%;width:0%;background:var(--accent);border-radius:2px;transition:width .1s linear;}
  .prompt-text{font-size:13px;color:var(--muted);margin-bottom:10px;min-height:18px;}
  .prompt-buttons{display:flex;gap:10px;}
  .soft.more-one{width:100%;flex:none;margin-top:8px;}
  .soft,.primary{min-height:46px;flex:1;border-radius:13px;font-size:15px;font-weight:600;
    display:flex;align-items:center;justify-content:center;transition:transform .1s ease;}
  .soft{background:transparent;border:1px solid var(--line);color:var(--ink);}
  .primary{background:var(--accent);color:var(--on-accent);}
  .soft:active,.primary:active{transform:scale(.98);}
  .soft .extend-badge{color:var(--accent);font-weight:700;margin-left:4px;}
  .not-today{display:block;width:100%;padding:12px;margin-top:10px;
    font-size:13px;color:var(--muted);text-align:center;border-radius:10px;}
  .not-today:active{background:var(--press);}
  .section{margin-bottom:18px;}
  .section-head{display:flex;justify-content:space-between;align-items:baseline;
    font-size:13px;font-weight:600;
    color:var(--muted);margin-bottom:8px;padding:0 2px;}
  .section-head .meta{font-weight:600;letter-spacing:.02em;text-transform:none;font-size:12px;}
  ul{list-style:none;margin:0;padding:0;}

  .calibration-note{display:flex;align-items:center;gap:8px;padding:10px 12px;margin-bottom:8px;
    background:var(--accent-soft);border-radius:12px;font-size:13px;color:var(--ink);line-height:1.35;}
  .calibration-note > span{flex:1;}
  .calibration-note button{font-size:12px;font-weight:600;color:var(--accent);padding:4px 8px;border-radius:8px;background:transparent;}
  .calibration-note button:active{background:var(--press);}
  .calibration-note .dismiss{opacity:.5;font-size:15px;padding:2px 6px;color:var(--muted);font-weight:400;}

  /* Section cards (2026-11-28): each day list sits in a soft card; rows have no divider lines. */
  #routine-list,#task-list,#evening-list{background:var(--surface);border:1px solid var(--line);
    border-radius:var(--radius);padding:4px;}
  #routine-list:empty,#task-list:empty,#evening-list:empty{display:none;}
  .row{display:flex;align-items:flex-start;gap:8px;padding:10px;
    border-radius:12px;font-size:15px;
    -webkit-tap-highlight-color:transparent;transition:background .12s ease;
    position: relative;}
  .row + .row{margin-top:2px;}
  @media (max-width:340px){ .row{padding-left:8px;padding-right:8px;} }
  .row.current{background:var(--accent-soft);}
  .row .now-tag{flex:0 0 100%;font-size:13px;color:var(--accent);}
  .row .label-text{font-weight:500;}
  .row .substeps{font-weight:400;}
  .row .time{flex:0 0 56px;min-width:0;font-size:13px;color:var(--muted);padding-top:3px;
    font-variant-numeric:tabular-nums;text-align:right;white-space:nowrap;overflow:hidden;}
  .row .circle{width:18px;height:18px;border-radius:50%;border:1.5px solid var(--circle-border);
    flex:none;margin-top:2px;transition:all .2s ease; position: relative; z-index: 3; cursor: pointer;}
  .row.current .circle{border-color:var(--accent);border-width:2px;}
  .row.current .time{color:var(--accent);font-weight:600;}
  .row.done{opacity:.38;}
  .row.done .circle{background:var(--accent);border-color:var(--accent);}
  .row.done .label-text{text-decoration:line-through;}
  .row .label{flex:1;min-width:0;line-height:1.35;
    position: relative; display: flex; align-items: flex-start; gap: 6px;}
  .row .right{flex:none;font-size:13px;color:var(--muted);padding-top:3px;white-space:nowrap;
    display:flex;align-items:center;gap:6px; position: relative; z-index: 3;}

  .nested-child { padding-left: 20px; }

  .relation-btn { display: flex; gap: 2px; align-items: center; justify-content: center; 
                  padding: 4px; margin: -4px 0 -4px -4px; justify-content: flex-start;
                  cursor: pointer; border-radius: 8px; flex: none; z-index: 4;}
  .row.has-rel { gap: 4px; }
  .row.has-rel .time { flex: 0 0 auto; text-align: left; margin-right: 4px; }
  .relation-btn:active { background: var(--press); }
  /* "Times in the list: Hidden": the empty time cell keeps its 56px column on every row, and the relation
     icons sit inside that column, so circles line up with the rows that have no icons. */
  .row.has-rel.no-time { gap: 8px; }
  .row.has-rel.no-time .time { flex: 0 0 56px; margin-right: 0; }
  .row.has-rel.no-time .relation-btn { position: absolute; left: 2px; top: 10px; }
  .row.nested-child.has-rel.no-time .relation-btn { left: 2px; }
  .relation-btn svg { width: 18px; height: 18px; flex: none; }
  /* One circle column (2026-11-26): every row keeps the 56px time column, so circles and names line up.
     Items inside another item are not indented (the "inside" icon says so). When any row shows both
     overlap icons and a time, all rows get a 42px left gutter and the icons sit in it. */
  .nested-child { padding-left: 2px; }
  .row.has-rel { gap: 8px; }
  .row.has-rel .time { flex: 0 0 56px; text-align: right; margin-right: 0; }
  .row.has-rel .relation-btn { position: absolute; left: 2px; top: 10px; }
  .day-scrollable:has(.row.has-rel:not(.no-time)) .row { padding-left: 42px; }

  .label-text{position: relative; z-index: 2; cursor: pointer; flex: 1; min-width: 0;
    word-break: normal; overflow-wrap: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;}

  .anchor-row{background:var(--fill); cursor: default;}
  .anchor-row.current{background:var(--accent-soft);}
  .anchor-row .label-text{font-weight: 600; color: var(--ink); cursor: default;}
  .anchor-row .lock{font-size: 14px; opacity: 0.6; margin-top: 3px; flex: none; position: relative; z-index: 3;
    width: 18px; display: flex; justify-content: center;}

  .substeps{font-size:12px;color:var(--muted);margin-top:3px;overflow-wrap:break-word;word-break:normal;}
  /* Steps under a task (C13): one line each, indented under the name, a small circle that fills when ticked. */
  .row .label:has(.steps-line),.row .label:has(.now-tag){flex-wrap:wrap;row-gap:0;}
  .row .label .steps-line{flex:0 0 100%;min-width:0;list-style:none;margin:4px 0 0;padding:0 0 0 14px;cursor:pointer;}
  .steps-line .step-item{position:relative;padding-left:14px;font-size:13px;line-height:1.35;color:var(--muted);
    margin-top:3px;overflow-wrap:break-word;}
  .steps-line .step-item::before{content:"";position:absolute;left:0;top:.38em;width:7px;height:7px;border-radius:50%;
    border:1.2px solid var(--circle-border);box-sizing:border-box;}
  .steps-line .step-done-text{opacity:.55;text-decoration:line-through;}
  .steps-line .step-done-text::before{background:var(--accent);border-color:var(--accent);}
  .add-task{display:block;width:100%;padding:10px;margin-top:8px;
    font-size:13px;color:var(--muted);text-align:center;border-radius:10px;
    border:1px dashed var(--line);background:transparent;}
  .add-task:active{background:var(--press);}
  .buffer{display:block;width:100%;min-height:44px;background:transparent;border:1.5px dashed var(--line);
    border-radius:14px;padding:13px;text-align:center;font:inherit;font-size:13px;color:var(--muted);margin-bottom:18px;}
  .buffer:active{background:var(--press);}
  .buffer.unavailable{opacity:.6;}
  .buffer.hidden{display:none;}
  /* Breather mode: the timer, Extend and "Move on" are offered; Not now, Half task time and Change of plans are not. */
  .now.breathing .now-links{display:none !important;}
  /* Anchor mode: the Now card shows the anchor. Only "Finished early" (hold) and "Start/Continue <task> anyway". */
  .now.anchor-mode #btn-move, .now.anchor-mode #btn-extend, .now.anchor-mode #extend-row,
  .now.anchor-mode .now-links:not(.anchor-links){display:none !important;}
  .now:not(.anchor-mode) #btn-anchor-finish, .now:not(.anchor-mode) .anchor-links{display:none !important;}
  /* After an anchor, a paused task offers Resume; Extend and Half task time wait until it runs again. */
  .now.anchor-paused #btn-extend, .now.anchor-paused #extend-row, .now.anchor-paused #btn-shrink{display:none !important;}
  #btn-anchor-finish{position:relative; overflow:hidden; touch-action:none; user-select:none; -webkit-user-select:none; -webkit-touch-callout:none;}
  #btn-anchor-finish .anchor-finish-fill{position:absolute; left:0; top:0; bottom:0; width:0; background:var(--accent-soft);}
  #btn-anchor-finish.holding .anchor-finish-fill{width:100%; transition:width 1s linear;}
  #btn-anchor-finish .anchor-finish-text{position:relative;}
  .locked{opacity:.72;}
  /* Evening before "Start evening": rows can be edited, not ticked. */
  .row.pending .circle{visibility:hidden;}
  /* No start time yet, unless the item is (or becomes) a medication or an anchor. */
  .edit-panel.no-start:not(.is-med):not(.is-anchor) #edit-start-field{display:none;}
  .survival-line{text-align:center;padding:40px 20px 36px;}
  .survival-line p{margin:0;font-size:21px;font-weight:400;line-height:1.5;color:var(--ink);letter-spacing:-.01em;}
  footer{display:flex;gap:8px;justify-content:center;margin-top:30px;padding-top:18px;
    border-top:1px solid var(--line);flex-wrap:wrap;}
  footer .ghost{font-size:12px;opacity:.7;}

  .extend-row{margin-top:14px;padding-top:14px;border-top:1px solid var(--line);}
  .extend-slider{width:100%;height:44px;appearance:none;-webkit-appearance:none;
    background:transparent;outline:none;padding:0;margin:0;cursor:pointer;}
  .extend-slider::-webkit-slider-runnable-track{height:4px;border-radius:2px;background:var(--track);}
  .extend-slider::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;
    width:24px;height:24px;border-radius:50%;background:var(--accent);
    margin-top:-10px;box-shadow:0 2px 6px var(--shadow);cursor:pointer;}
  .extend-slider::-moz-range-track{height:4px;border-radius:2px;background:var(--track);}
  .extend-slider::-moz-range-thumb{width:24px;height:24px;border-radius:50%;
    background:var(--accent);border:none;box-shadow:0 2px 6px var(--shadow);cursor:pointer;}
  .extend-slider-wrap{position:relative;}
  .extend-slider-range{position:relative;height:14px;margin:2px 12px 0 12px;}
  .extend-slider-range span{position:absolute;transform:translateX(-50%);
    font-size:10px;color:var(--muted);opacity:.7;top:0;
    font-variant-numeric:tabular-nums;white-space:nowrap;}

  .reset-wrap{display:flex;flex-direction:column;min-height:calc(100vh - 72px);
    min-height:calc(100dvh - 72px);justify-content:space-between;padding:80px 0 32px;text-align:center;}
  .reset-content{margin:auto 0;}
  .reset-primary{font-size:40px;font-weight:600;letter-spacing:-.03em;line-height:1.15;margin-bottom:16px;}
  .reset-secondary{font-size:17px;color:var(--muted);line-height:1.5;}
  .reset-later{font-size:13px;color:var(--muted);margin-top:20px;line-height:1.5;}
  .reset-done{list-style:none;margin:20px auto 0;padding:0;max-width:300px;font-size:14px;
    color:var(--muted);line-height:1.6;}
  .change-opt{display:block;width:100%;min-height:56px;padding:10px 16px;margin-bottom:10px;
    text-align:left;font-size:16px;font-weight:600;color:var(--ink);background:var(--bg);
    border:1px solid var(--line);border-radius:12px;}
  .change-opt:active{transform:scale(.99);}
  .change-sub{display:block;font-size:12px;font-weight:400;color:var(--muted);margin-top:2px;}
  .reset-footer{display:flex;flex-direction:column;gap:14px;align-items:center;padding-top:20px;}
  .reset-foot{font-size:13px;color:var(--muted);margin:0 0 4px;}
  .reset-back{min-height:46px;padding:0 30px;border-radius:13px;font-size:15px;
    font-weight:600;border:1px solid var(--line);background:transparent;color:var(--ink);}
  .reset-back:active{transform:scale(.98);}

  .firstweek-wrap{display:flex;flex-direction:column;min-height:calc(100vh - 72px);
    min-height:calc(100dvh - 72px);}
  .firstweek-head{display:flex;align-items:center;justify-content:space-between;padding:0 0 22px;}
  .firstweek-head .back{font-size:14px;color:var(--muted);padding:8px 10px;margin-left:-10px;
    border-radius:10px;display:flex;align-items:center;gap:4px;}
  .firstweek-head .back:active{background:var(--press);}
  .firstweek-title{font-size:30px;font-weight:600;letter-spacing:-.025em;line-height:1.2;margin:0 0 10px;}
  .firstweek-sub{font-size:14px;color:var(--muted);margin:0 0 40px;line-height:1.55;}
  .firstweek-body{flex:1;}
  .firstweek-para{font-size:18px;line-height:1.7;color:var(--ink);margin:0 0 22px;letter-spacing:-.005em;}
  .firstweek-para:last-child{margin-bottom:0;}
  .firstweek-foot{padding:40px 0 4px;display:flex;flex-direction:column;align-items:center;gap:16px;}
  .firstweek-once{font-size:12px;color:var(--muted);opacity:.7;margin:0;text-align:center;}
  .firstweek-gotit{width:100%;min-height:48px;border-radius:13px;font-size:15px;font-weight:600;
    background:var(--accent);color:var(--on-accent);display:flex;align-items:center;justify-content:center;
    transition:transform .1s ease;}
  .firstweek-gotit:active{transform:scale(.98);}

  /* Sideways moves on these screens are swipes between views (see SWIPES in app.js). */
  #week,#meds-screen,#med-history{touch-action:pan-y pinch-zoom;}
  /* After a swipe only: the new view slides in. On the history screen the head and view buttons stay still. */
  @keyframes swipe-from-right{from{opacity:0;transform:translateX(24px);}to{opacity:1;transform:none;}}
  @keyframes swipe-from-left{from{opacity:0;transform:translateX(-24px);}to{opacity:1;transform:none;}}
  .swipe-from-right,.swipe-from-left{overflow-x:clip;}
  #week.swipe-from-right .hist-seg ~ *,#meds-screen.swipe-from-right > *,#med-history.swipe-from-right > *{animation:swipe-from-right .2s ease-out;}
  #week.swipe-from-left .hist-seg ~ *,#meds-screen.swipe-from-left > *,#med-history.swipe-from-left > *{animation:swipe-from-left .2s ease-out;}
  @media (prefers-reduced-motion: reduce){
    #week .hist-seg ~ *,#meds-screen > *,#med-history > *{animation:none !important;}
  }
  .later-wrap{display:flex;flex-direction:column;min-height:calc(100vh - 72px);
    min-height:calc(100dvh - 72px);}
  .later-head{display:flex;align-items:center;justify-content:space-between;padding:0 0 22px;}
  .later-head h1{font-size:24px;font-weight:600;letter-spacing:-.02em;margin:0;}
  .later-wrap > h1{font-size:24px;font-weight:600;letter-spacing:-.02em;margin:0 0 12px;line-height:1.25;}
  .later-head .back{font-size:14px;color:var(--muted);padding:8px 10px;margin-left:-10px;
    border-radius:10px;display:flex;align-items:center;gap:4px;}
  .later-head .back:active{background:var(--press);}
  .later-sub{font-size:14px;color:var(--muted);line-height:1.55;margin:0 0 22px;}
  .later-item{background:var(--surface);border:1px solid var(--line);border-radius:16px;
    padding:16px 18px;margin-bottom:10px;}
  .later-item .label{font-size:16px;font-weight:500;margin-bottom:14px;line-height:1.35;
    overflow-wrap:break-word;word-break:normal;}
  .later-item .actions{display:flex;gap:8px;}
  .later-item .actions button{flex:1;min-height:38px;border-radius:10px;font-size:14px;font-weight:600;}
  .later-item .actions .today{background:var(--accent-soft);color:var(--accent);}
  .later-item .actions .release{background:transparent;border:1px solid var(--line);color:var(--muted);}
  .later-item .actions .today:disabled{opacity:.4;}
  .later-foot{font-size:13px;color:var(--muted);text-align:center;padding:28px 0 16px;opacity:.7;}
  .later-empty{text-align:center;padding:70px 20px;}
  .later-empty p{font-size:17px;color:var(--muted);margin:0;line-height:1.5;}

  .settings-list{display:flex;flex-direction:column;gap:10px;margin-bottom:22px;}
  /* Settings groups: a heading plus its rows; two columns of groups on wide screens. */
  .settings-col,.settings-group{display:flex;flex-direction:column;gap:10px;min-width:0;}
  .settings-col{gap:18px;}
  #settings .settings-list{gap:18px;}
  .settings-group > .section-head{margin-bottom:-2px;}
  .settings-group:has(> #install-row.hidden){display:none;}
  .settings-row{display:flex;align-items:flex-start;gap:12px;padding:14px 16px;
    background:var(--surface);border:1px solid var(--line);border-radius:14px;cursor:pointer;
    transition:border-color .12s ease;}
  .settings-row:active{border-color:var(--accent-soft);}
  .settings-row.static{cursor:default;flex-direction:column;gap:10px;}
  .settings-row.static:active{border-color:var(--line);}
  .settings-row.static > .settings-text{display:flex;flex-direction:column;gap:3px;}
  .seg{display:flex;gap:4px;padding:3px;background:var(--fill);border-radius:12px;width:100%;}
  .seg-opt{flex:1;min-width:0;position:relative;cursor:pointer;}
  .seg-opt input{position:absolute;opacity:0;inset:0;width:100%;height:100%;margin:0;cursor:pointer;}
  .seg-opt span{display:flex;align-items:center;justify-content:center;min-height:38px;padding:0 6px;
    border-radius:9px;font-size:14px;font-weight:600;color:var(--muted);text-align:center;}
  .seg-opt input:checked + span{background:var(--accent-soft);color:var(--accent);}
  .seg-opt input:focus-visible + span{outline:2px solid var(--accent);outline-offset:1px;}  .settings-row input[type="checkbox"]{width:22px;height:22px;accent-color:var(--accent);
    cursor:pointer;flex:none;margin-top:1px;}
  .settings-row > span{flex:1;display:flex;flex-direction:column;gap:3px;min-width:0;}
  .install-btn{align-self:flex-start;min-height:38px;padding:0 18px;border:0;border-radius:10px;
    background:var(--accent-soft);color:var(--accent);font:inherit;font-size:14px;font-weight:600;cursor:pointer;}
  .install-btn:focus-visible{outline:2px solid var(--accent);outline-offset:1px;}
  /* C16: backup buttons and the reminder's "On" / "At" fields. Scoped so the short-screen edit-sheet sizes don't apply. */
  .backup-btns{display:flex;flex-wrap:wrap;gap:8px;}
  .install-btn:active{transform:scale(.98);}
  /* C6: the sync code and its entry field. */
  .sync-block{display:flex;flex-direction:column;gap:10px;align-self:stretch;}
  .sync-block .edit-input{width:100%;min-height:44px;margin-bottom:0;}
  .sync-qr{align-self:center;width:220px;max-width:100%;}
  .sync-qr svg{display:block;width:100%;height:auto;border-radius:12px;}
  .qr-bg{fill:var(--qr-bg);}
  .qr-ink{fill:var(--qr-ink);}
  .sync-code{font-size:15px;font-weight:600;color:var(--ink);background:var(--fill);border-radius:12px;
    padding:12px;line-height:1.6;overflow-wrap:anywhere;user-select:all;}
  .backup-when{display:flex;flex-direction:column;gap:10px;align-self:stretch;}
  .backup-field .edit-label{font-size:13px;margin-bottom:6px;letter-spacing:normal;}
  .backup-field .time-field{margin-bottom:0;}
  .backup-field .time-field .edit-input{min-height:44px;margin-bottom:0;}
  #backup-day-seg .seg-opt span{padding:0;}
  .settings-label{font-size:15px;font-weight:500;color:var(--ink);line-height:1.3;}
  .settings-sub{font-size:12px;color:var(--muted);line-height:1.4;}

  .med-history-wrap{display:flex;flex-direction:column;min-height:calc(100vh - 72px);
    min-height:calc(100dvh - 72px);}
  .med-history-head{display:flex;align-items:center;justify-content:space-between;padding:0 0 22px;}
  .med-history-head .back{font-size:14px;color:var(--muted);padding:8px 10px;margin-left:-10px;
    border-radius:10px;display:flex;align-items:center;gap:4px;}
  .med-history-head .back:active{background:var(--press);}
  .med-history-count{font-size:12px;color:var(--muted);font-weight:600;}
  .med-history-title{font-size:24px;font-weight:600;letter-spacing:-.02em;margin:0;}
  .med-history-sub{font-size:14px;color:var(--muted);line-height:1.55;margin:6px 0 22px;}
  .med-history-item{background:var(--surface);border:1px solid var(--line);border-radius:16px;
    padding:16px 18px;margin-bottom:10px;}
  .med-history-item .when{font-size:16px;font-weight:500;line-height:1.35;}
  /* Journal: one input + "Add note" row, used on the finished-day card, Reset screen and Journal screen. */
  .note-form{display:flex;flex-direction:column;gap:8px;align-items:flex-end;}
  .note-form.hidden{display:none;}
  .note-form .edit-input{width:100%;box-sizing:border-box;margin:0;}
  /* Note fields wrap and grow (fitNote); no inner scroll or drag handle. */
  textarea.edit-input.note-text{display:block;flex:none;box-sizing:border-box;padding:11px 14px;line-height:1.4;
    resize:none;overflow:hidden;}
  .note-form .note-add{flex:0 0 auto;width:auto;min-height:46px;padding:0 14px;white-space:nowrap;}
  .reset-note{margin-top:18px;text-align:left;}
  #now-note{margin-top:14px;}
  #journal .section-head{margin-top:18px;}
  /* Note | Entry switch, and the two groups under a day on the Journal screen. */
  .kind-seg .seg-opt input:disabled{cursor:default;}
  .kind-seg .seg-opt input:disabled + span{opacity:.4;}
  .journal-group{font-size:13px;font-weight:600;color:var(--muted);margin:0 0 6px;padding:0 2px;}
  .journal-entry .journal-text{white-space:pre-wrap;}
  .journal-entry .source{text-align:right;}
  /* Finished-day card only: a long entry can outgrow the screen, so that card scrolls (it holds no task). */
  body:has(#day:not(.hidden)) #now-card:has(#now-note:not(.hidden) textarea[data-kind="entry"]){
    flex:0 1 auto;min-height:0;overflow-y:auto;}
  body:has(#day:not(.hidden)) #day:has(#now-note:not(.hidden) textarea[data-kind="entry"]) .day-scrollable{flex:1 1 0;}
  /* Appointment summary: date, three choices, Save, then the text exactly as it will be saved. */
  #summary-save{flex:none;}
  #summary-save:disabled{opacity:.4;}
  .summary-preview{margin:14px 0 16px;padding:14px 16px;background:var(--surface);border:1px solid var(--line);
    border-radius:14px;font-size:13px;line-height:1.55;white-space:pre-wrap;overflow-wrap:anywhere;}
  button.journal-note{display:block;width:100%;text-align:left;color:var(--ink);min-height:44px;}
  button.journal-note:active{background:var(--press);}
  .journal-text{display:block;font-size:15px;font-weight:500;line-height:1.4;overflow-wrap:anywhere;}
  .journal-note .source{display:block;}
  .journal-edit{margin:0 0 10px;}
  .meds-form.journal-edit .edit-input{margin:0;}
  .cal-journal span:first-child{overflow-wrap:anywhere;}
  #cal-daylist .journal-edit{margin:6px 0 0;}
  .meds-form{display:flex;flex-direction:column;gap:8px;background:var(--surface);border:1px solid var(--line);
    border-radius:16px;padding:14px;margin:12px 0;}
  .meds-form .edit-input{width:100%;box-sizing:border-box;}
  .med-history-item .source{font-size:12px;color:var(--muted);margin-top:4px;}
  .med-history-item .actions{display:flex;gap:8px;margin-top:12px;}
  .med-history-item .actions button{flex:1;min-height:38px;border-radius:10px;
    font-size:14px;font-weight:600;}
  .med-history-item .actions .edit{background:var(--accent-soft);color:var(--accent);}
  .med-history-item .actions .remove{background:transparent;border:1px solid var(--line);
    color:var(--muted);}
  .med-history-empty{text-align:center;padding:70px 20px;}
  .med-history-empty p{font-size:17px;color:var(--muted);margin:0;line-height:1.5;}
  .med-history-foot{font-size:13px;color:var(--muted);text-align:center;padding:28px 0 16px;opacity:.7;}

  .week-grid{display:flex;gap:8px;align-items:flex-end;height:160px;margin-bottom:26px;justify-content:center;}
  .week-day{flex:1;display:flex;flex-direction:column;align-items:center;
    height:100%;justify-content:flex-end;gap:8px;max-width:34px;}
  .week-bar{width:100%;border-radius:8px;background:var(--accent);min-height:12px;
    transition:height .3s ease, background .3s ease;}
  .week-bar.empty{background:transparent;border:1.5px dashed var(--line);height:22%;}
  .week-day.is-today .week-bar{box-shadow:0 0 0 3px var(--bg), 0 0 0 5px var(--accent-soft);}
  .week-day-label{font-size:12px;color:var(--muted);font-weight:600;white-space:nowrap;}
  .week-day.is-today .week-day-label{color:var(--accent);}
  .week-observation{font-size:15px;color:var(--ink);line-height:1.55;text-align:center;
    padding:0 8px;margin:0;font-weight:500;}
  .week-sub-observation{font-size:13px;color:var(--muted);line-height:1.55;text-align:center;
    padding:0 12px;margin:10px 0 0;min-height:20px;}
  .week-legend{display:flex;justify-content:center;gap:14px;flex-wrap:wrap;margin-top:22px;
    padding-top:18px;border-top:1px solid var(--line);}
  .week-legend-item{display:flex;align-items:center;gap:6px;font-size:11px;color:var(--muted);}
  .week-legend-item .dot{width:8px;height:8px;border-radius:50%;}

  /* Month and year history */
  .hist-seg{margin:0 0 22px;}
  .cal-view{margin-bottom:8px;}
  #med-older{margin-top:22px;}
  .cal-nav{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px;}
  .cal-title{font-size:16px;font-weight:600;letter-spacing:-.01em;}
  .cal-arrow{min-width:44px;min-height:44px;border-radius:12px;font-size:24px;line-height:1;color:var(--ink);
    background:var(--fill);}
  .cal-arrow:disabled{opacity:.35;cursor:not-allowed;}
  .cal-arrow:active:not(:disabled){background:var(--press);}
  .cal-grid{display:grid;grid-template-columns:repeat(7,1fr);gap:4px 2px;}
  .cal-head{margin-bottom:4px;}
  .cal-head span{text-align:center;font-size:11px;font-weight:600;color:var(--muted);letter-spacing:.05em;}
  .cal-cell{display:flex;flex-direction:column;align-items:center;gap:3px;padding:3px 0;border-radius:10px;
    min-height:44px;color:var(--ink);}
  .cal-cell:active{background:var(--press);}
  .cal-cell.selected{background:var(--accent-soft);}
  .cal-num{display:inline-flex;align-items:center;justify-content:center;min-width:20px;height:20px;border-radius:50%;
    font-size:11px;color:var(--muted);line-height:1;}
  .cal-num.is-today{background:var(--accent);color:var(--on-accent);font-weight:700;}
  /* Days with notes: a short bar under the number, inside the cell gap, so rows keep their height. */
  .cal-num.has-note{position:relative;}
  .cal-num.has-note::after,.week-legend-item .note-mark{width:12px;height:2px;border-radius:1px;background:var(--accent);}
  .cal-num.has-note::after{content:"";position:absolute;left:50%;bottom:0;transform:translateX(-50%);}
  /* On today the bar sits inside the solid circle, so it never merges with the circle or the dot below. */
  .cal-num.is-today.has-note::after{bottom:2px;width:8px;background:var(--on-accent);}
  .week-legend-item .note-mark{display:inline-block;}
  .mini-name.has-note{text-decoration:underline;text-decoration-color:var(--accent);text-decoration-thickness:2px;
    text-underline-offset:4px;}
  .cal-notes-head{display:flex;align-items:center;justify-content:space-between;width:100%;margin-top:10px;
    font-size:13px;font-weight:600;color:var(--muted);text-align:left;border-radius:10px;}
  button.cal-notes-head{min-height:44px;padding:0 8px;margin-left:-8px;width:calc(100% + 16px);}
  button.cal-notes-head:active{background:var(--press);}
  .cal-dot{position:relative;display:inline-block;width:14px;height:14px;border-radius:50%;box-sizing:border-box;
    border:1.5px dashed var(--line);background:transparent;}
  .cal-dot.reset{border-style:solid;border-width:2px;background:transparent;}
  .cal-dot.is-today{box-shadow:none;}
  .cal-mark{position:absolute;left:50%;top:50%;width:4px;height:4px;transform:translate(-50%,-50%);border-radius:50%;
    background:var(--muted);}
  .cal-dot[style*="background"] .cal-mark{background:var(--bg);}
  .cal-mark.med{width:12px;height:1.5px;border-radius:1px;transform:translate(-50%,-50%) rotate(-45deg);}
  .cal-mark.med + .cal-mark:not(.med){box-shadow:0 0 0 1px var(--bg);}
  .mini-grid .cal-mark.med + .cal-mark:not(.med){box-shadow:0 0 0 .75px var(--bg);}
  .week-legend-item .dot.cal-mark-dot.med::after{width:10px;height:1.5px;border-radius:1px;transform:translate(-50%,-50%) rotate(-45deg);}
  .week-legend-item .dot.cal-mark-dot{position:relative;width:12px;height:12px;box-sizing:border-box;
    background:transparent;border:1.5px dashed var(--line);}
  .week-legend-item .dot.cal-mark-dot::after{content:"";position:absolute;left:50%;top:50%;width:4px;height:4px;
    transform:translate(-50%,-50%);border-radius:50%;background:var(--muted);}
  .year-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:14px 10px;}
  .mini-month{display:flex;flex-direction:column;align-items:center;gap:6px;padding:8px 4px 10px;border-radius:12px;
    color:var(--ink);}
  .mini-month:active{background:var(--press);}
  .mini-name{font-size:12px;font-weight:600;color:var(--muted);letter-spacing:.04em;text-transform:uppercase;}
  .mini-grid{display:grid;grid-template-columns:repeat(7,9px);gap:3px;}
  .mini-grid .cal-dot{width:9px;height:9px;border-width:1px;box-shadow:none;}
  .mini-grid .cal-dot:not(.reset){border:none;background:var(--line);}
  .mini-grid .cal-dot.reset{border-width:1.5px;}
  .mini-grid .cal-dot.is-today{box-shadow:0 0 0 1px var(--bg), 0 0 0 2.5px var(--accent);}
  /* Year markers: bigger and darker than in Month so they read on the small pale dots. */
  .mini-grid .cal-mark{width:3.5px;height:3.5px;background:var(--ink);}
  .mini-grid .cal-mark.med{width:9px;height:1.5px;}
  .mini-grid .cal-dot[style*="background"] .cal-mark{background:var(--bg);}
  @media (max-width:340px){.mini-grid{gap:2px;}}
  .cal-add{display:block;width:100%;margin-top:10px;min-height:44px;border-radius:12px;font-size:14px;font-weight:600;
    color:var(--accent);background:var(--accent-soft);}
  .cal-add:active{filter:brightness(.95);}
  button.cal-daylist-row{width:100%;text-align:left;background:transparent;color:var(--ink);border-radius:10px;
    padding:8px 8px;margin:0 -8px;width:calc(100% + 16px);min-height:44px;}
  button.cal-daylist-row:active{background:var(--press);}
  /* The calendar uses the same sheet as the day view; only "Keep for" (saved day-type lists) and the scope select are never shown. */
  .edit-panel:is(.cal-mode,.med-mode) #edit-keep-field,
  #edit-scope-field{display:none !important;}
  .cal-daylist{margin-top:14px;padding:14px 16px;border-radius:14px;background:var(--fill);}
  .cal-daylist-title{font-size:14px;font-weight:600;margin-bottom:8px;}
  .cal-daylist-sub{font-size:13px;font-weight:600;color:var(--muted);margin:8px 0 4px;}
  .cal-daylist-row{display:flex;flex-direction:column;gap:1px;font-size:14px;padding:4px 0;}
  .cal-today-row{display:flex;justify-content:center;margin-top:10px;}
  .cal-today-btn{min-height:36px;padding:0 18px;border:1px solid var(--line);border-radius:10px;
    font-size:14px;font-weight:600;color:var(--ink);background:transparent;}
  .cal-today-btn:active{background:var(--press);}
  .cal-daylist-row.cal-daylist-tier{flex-direction:row;align-items:center;gap:0;}
  .cal-daylist-tierdot{display:inline-block;width:10px;height:10px;border-radius:50%;margin-right:8px;flex:none;box-sizing:border-box;}
  .cal-daylist-tierdot.reset{border:1.5px solid;background:transparent;}
  .cal-daylist-name{display:flex;align-items:center;min-width:0;}
  .cal-daylist-name .lock{font-size:12px;opacity:.6;margin-right:6px;flex:none;}
  .cal-daylist-meta{font-size:12px;color:var(--muted);}
  .cal-daylist-empty{font-size:14px;color:var(--muted);}
  @media (min-width:768px) and (orientation:landscape){.year-grid{grid-template-columns:repeat(4,1fr);}}

  .reentry-wrap{display:flex;flex-direction:column;min-height:calc(100vh - 72px);
    min-height:calc(100dvh - 72px);justify-content:space-between;padding:100px 0 32px;text-align:center;}
  .reentry-content{margin:auto 0;}
  .reentry-primary{font-size:34px;font-weight:600;letter-spacing:-.025em;line-height:1.2;margin-bottom:14px;}
  .reentry-secondary{font-size:17px;color:var(--muted);line-height:1.5;padding:0 12px;}
  .reentry-footer{display:flex;flex-direction:column;gap:14px;align-items:center;padding-top:24px;}
  .reentry-pick{width:100%;min-height:48px;border-radius:13px;font-size:15px;font-weight:600;
    background:var(--accent);color:var(--on-accent);display:flex;align-items:center;justify-content:center;
    transition:transform .1s ease;}
  .reentry-pick:active{transform:scale(.98);}
  .reentry-later{font-size:13px;color:var(--muted);padding:10px;}

  .edit-sheet{position:fixed;inset:0;z-index:100;display:flex;align-items:flex-end;justify-content:center;}
  .edit-backdrop{position:absolute;inset:0;background:var(--backdrop);}
  .edit-panel{position:relative;width:100%;max-width:430px;background:var(--surface);
    border-top-left-radius:22px;border-top-right-radius:22px;
    padding:24px 20px max(28px, calc(env(safe-area-inset-bottom, 0px) + 16px));
    box-shadow:0 -8px 32px var(--shadow);animation:slideUp .22s ease;
    max-height:calc(100vh - 20px);max-height:calc(100dvh - 20px);
    overflow-y:auto;-webkit-overflow-scrolling:touch;}
  @keyframes slideUp{from{transform:translateY(20px);opacity:0;}to{transform:translateY(0);opacity:1;}}
  .edit-title{font-size:20px;font-weight:600;letter-spacing:-.02em;margin-bottom:20px;}
  .tidy-sub{font-size:14px;color:var(--muted);line-height:1.55;margin:-12px 0 16px;}
  #park-hint{margin:-8px 0 8px;}
  #tidy-list{margin-bottom:12px;}
  .edit-label{display:block;font-size:13px;font-weight:600;color:var(--muted);margin-bottom:6px;}
  .edit-input{width:100%;min-height:46px;padding:0 14px;border:1px solid var(--line);
    border-radius:12px;font:inherit;font-size:16px;color:var(--ink);background:var(--bg);
    margin-bottom:16px;outline:none;}
  .edit-input:focus{border-color:var(--accent);}
  .edit-input:disabled{opacity:.55;cursor:not-allowed;}
  /* The native time/date input is only the hidden value store; .time-field and .date-field are what the user sees. */
  .hidden-field{position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);
    opacity:0;pointer-events:none;}
  .time-field{display:flex;gap:8px;margin-bottom:16px;}
  .time-field .edit-input{width:auto;flex:1 1 0;min-width:0;margin-bottom:0;padding:0 8px;}
  .date-field{margin-bottom:16px;}
  .date-btn{display:block;text-align:left;margin-bottom:0;cursor:pointer;}
  .date-pop{margin-top:8px;padding:10px 8px;border:1px solid var(--line);border-radius:12px;background:var(--bg);}
  .date-pop .cal-nav{margin-bottom:6px;}
  .date-pop .cal-cell{min-height:36px;padding:2px 0;justify-content:center;}
  .edit-checkbox-row{display:flex;align-items:center;gap:8px;margin-bottom:16px;}
  .edit-checkbox-row input[type="checkbox"]{width:18px;height:18px;accent-color:var(--accent);cursor:pointer;}
  .edit-checkbox-row input[type="checkbox"]:disabled{cursor:not-allowed;opacity:.55;}
  .edit-checkbox-row label{font-size:14px;font-weight:500;cursor:pointer;}
  .edit-actions{display:flex;gap:8px;margin-top:8px;}
  .edit-btn{flex:1;min-height:46px;border-radius:12px;font-size:15px;font-weight:600;}
  .edit-delete{background:transparent;border:1px solid var(--line);color:var(--muted);
    flex:0 0 auto;padding:0 16px;}
  .edit-cancel{background:transparent;border:1px solid var(--line);color:var(--ink);}
  .edit-save{background:var(--accent);color:var(--on-accent);}
  .edit-save:disabled{opacity:.4;}

  .edit-panel.med-mode .edit-field[data-field="label"],
  .edit-panel.med-mode .edit-field[data-field="minutes"],
  .edit-panel.med-mode .edit-checkbox-row {display:none;}
  .edit-panel.med-mode #edit-steps-field,.edit-panel.is-med #edit-steps-field,.edit-panel.is-anchor #edit-steps-field{display:none;}
  /* Steps (C13): one row per step in the Add/Edit sheet; tick, text, remove. */
  .steps-list{display:flex;flex-direction:column;gap:8px;}
  .steps-list:empty{display:none;}
  .step-row{display:flex;align-items:center;gap:8px;}
  .step-row input[type="checkbox"]{flex:none;width:18px;height:18px;margin:0;accent-color:var(--accent);cursor:pointer;}
  .step-row .edit-input{flex:1 1 auto;min-width:0;margin-bottom:0;}
  .step-row.is-done .edit-input{color:var(--muted);text-decoration:line-through;}
  .step-remove{flex:none;width:44px;height:44px;display:flex;align-items:center;justify-content:center;
    color:var(--muted);border-radius:10px;font-size:16px;}
  .step-remove:active{background:var(--press);}
  .edit-panel:is(.cal-mode,.steps-locked) .step-row input[type="checkbox"]{display:none;}
  .add-task.add-step{margin-top:8px;margin-bottom:16px;min-height:44px;}
  .steps-list:empty + .add-step{margin-top:0;}
  .edit-panel.med-mode #edit-window-field {display:none;}

  .edit-panel.is-med .edit-field[data-field="minutes"] {display:none;}
  .edit-panel.med-mode #edit-recur-block {display:none;}
  .edit-panel.is-med #edit-anchor-row {display:none;}
  .edit-panel.is-anchor .edit-field[data-field="minutes"],
  .edit-panel.is-anchor #edit-med-row,
  .edit-panel.is-anchor #edit-window-field,
  .edit-panel.is-anchor #edit-keep-field {display:none !important;}
  #edit-recur-block .edit-field.hidden{display:none;}
  #edit-repeat-unit{width:auto;flex:1;margin-bottom:0;}
  #edit-repeat-every{width:70px;margin-bottom:0;text-align:center;}
  .center-dialog{position:fixed;inset:0;z-index:150;display:flex;align-items:center;justify-content:center;padding:20px;}
  .center-panel{position:relative;width:100%;max-width:340px;background:var(--surface);border-radius:18px;
    padding:20px;box-shadow:0 8px 32px var(--shadow);display:flex;flex-direction:column;gap:8px;
    animation:popIn .15s ease-out;max-height:calc(100vh - 40px);max-height:calc(100dvh - 40px);overflow-y:auto;}
  .center-panel .edit-btn{flex:0 0 auto;}
  .edit-confirm-text{font-size:15px;font-weight:600;color:var(--ink);margin-bottom:6px;}
  #edit-repeat-end-type{margin-bottom:8px;}
  #edit-repeat-end-date,#edit-repeat-end-count{margin-bottom:16px;}
  #edit-repeat-end-type.no-extra{margin-bottom:16px;}
  .tier-chips{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:16px;}
  #edit-section-field .seg,#edit-keep-field .seg{margin-bottom:16px;}
  #edit-do-next:not(.hidden) + #edit-keep-field{margin-top:8px;}
  .tier-chip{position:relative;cursor:pointer;}
  .tier-chip input{position:absolute;opacity:0;pointer-events:none;}
  .tier-chip span{display:inline-block;min-height:36px;line-height:34px;padding:0 14px;border:1px solid var(--line);
    border-radius:18px;font-size:14px;font-weight:500;color:var(--ink);background:var(--bg);}
  .tier-chip input:checked + span{background:var(--accent);border-color:var(--accent);color:var(--on-accent);}
  .tier-chip input:focus-visible + span{outline:2px solid var(--accent);outline-offset:2px;}
  /* Weekday chips: one letter each, seven in a row down to 320px wide. */
  #edit-weekday-chips{gap:4px;}
  #edit-weekday-chips .tier-chip span{min-width:36px;padding:0;text-align:center;}

  .window-row{display:flex;align-items:center;gap:8px;margin-bottom:16px;}
  .window-row .edit-input{width:80px;margin-bottom:0;text-align:center;}
  .window-row .window-unit{font-size:13px;color:var(--muted);font-weight:500;}

  .toast{position:fixed;left:50%;bottom:max(22px, calc(env(safe-area-inset-bottom, 0px) + 8px));
    transform:translateX(-50%);
    width:calc(100% - 36px);max-width:400px;background:var(--toast-bg);color:var(--toast-ink);
    border-radius:14px;padding:14px 16px;display:flex;align-items:center;gap:12px;
    font-size:14px;line-height:1.35;box-shadow:0 12px 32px -12px rgba(0,0,0,.45);
    animation:rise .22s ease;z-index:200;}
  @keyframes rise{from{opacity:0;transform:translate(-50%,8px);}to{opacity:1;transform:translate(-50%,0);}}
  .toast.toast-raised{bottom:auto;top:max(22px, calc(env(safe-area-inset-top, 0px) + 8px));animation:rise-top .22s ease;}
  /* Any open sheet keeps its buttons free, whichever came first: the message moves to the top. */
  body:has(#edit-sheet:not(.hidden), #change-sheet:not(.hidden), #park-sheet:not(.hidden), #step-sheet:not(.hidden), #more-sheet:not(.hidden), #tidy-sheet:not(.hidden), #exit-sheet:not(.hidden)) .toast{
    bottom:auto !important;top:max(22px, calc(env(safe-area-inset-top, 0px) + 8px));animation-name:rise-top;}
  @keyframes rise-top{from{opacity:0;transform:translate(-50%,-8px);}to{opacity:1;transform:translate(-50%,0);}}
  .toast span{flex:1;}
  .toast .undo{flex:none;font-size:13px;font-weight:700;color:var(--toast-undo);padding:4px 6px;}

  .now-header{display:flex;align-items:baseline;gap:10px;margin-bottom:2px;}
  #now-card .now-header .eyebrow{margin-bottom:0;flex:none;position:relative;top:-1px;}
  #now-card .now-label{font-size:22px;margin-bottom:0;flex:1 1 auto;min-width:0;line-height:1.15;}
  #now-card .now-meta{margin-bottom:6px;font-size:12px;}
  #now-card .bar{margin-bottom:8px;}
  #now-card .prompt-text{margin-bottom:4px;min-height:0;}
  #now-card .prompt-text:empty{display:none;margin-bottom:0;}
  #now-card .prompt-buttons{gap:8px;margin-bottom:4px;}
  #now-card .soft,#now-card .primary{min-height:40px;font-size:14px;}
  #now-card .extend-row{margin-top:0;padding-top:0;border-top:none;}
  #now-card .extend-slider{height:28px;}
  #now-card .extend-slider-range{height:12px;margin:0 12px 2px 12px;}
  #now-card .extend-slider-range span{font-size:9px;}
  #now-card .not-today{padding:12px 6px;margin-top:8px;font-size:13px;}
  /* Spacing rule: slider numbers -> "Not now" row and row -> "Change of plans" row are the
     same distance (about 35px text centre to text centre) at the default height tier. */
  #now-card .now-links{display:flex;gap:6px;margin-top:13px;}
  #now-card .now-links + .now-links{margin-top:2px;}
  #now-card .now-links .not-today{flex:1 1 0;width:auto;min-width:0;margin-top:0;padding:7px 6px;}
  #now-card .now-links .not-today.hidden{display:none;}
  /* "Start <task> too": its own row, only while a task inside the running one can be started. */
  #now-card .now-links.hidden{display:none;}
  #btn-nested{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
  .now-also{font-size:12px;color:var(--muted);margin:-2px 0 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
  /* A running task that is not shown and is out of time: its name and its own "Done". */
  .now-ended{display:flex;flex-direction:column;gap:4px;margin-top:8px;}
  .now-ended.hidden{display:none;}
  .ended-row{display:flex;align-items:center;gap:8px;padding:4px 4px 4px 10px;background:var(--fill);border-radius:10px;}
  .ended-text{flex:1 1 auto;min-width:0;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
  #now-card .ended-done{flex:none;width:auto;padding:0 16px;}
  .now.breathing .now-ended,.now.anchor-mode .now-ended,#day.focus .now-ended{display:none;}
  /* Rows the plan just moved: a short tint. */
  .row.moved{background:var(--accent-soft);}
  .row.moved .time{color:var(--accent);font-weight:600;}
  /* Focus mode: blocks for the other running tasks (in start order, around the Now card) and the start buttons. */
  .focus-runs{display:none;}
  .focus-leave,#day.focus .focus-enter{display:none;}
  #day.focus .focus-leave{display:inline;}
  /* The screen names itself; sized like the other screen titles (.later-head h1). */
  .focus-title{display:none;font-size:24px;font-weight:600;letter-spacing:-.02em;margin:0;}
  #day.focus .focus-title{display:block;}
  .run-block{display:flex;align-items:center;gap:12px;width:100%;min-height:56px;padding:10px 16px;text-align:left;
    background:var(--surface);border:1px solid var(--line);border-radius:16px;}
  .run-block:active:not(:disabled){transform:scale(.99);}
  .run-block:disabled{cursor:default;}
  .run-block:focus-visible,#btn-focus:focus-visible{outline:2px solid var(--accent);outline-offset:2px;}
  .run-name{flex:1 1 auto;min-width:0;font-size:15px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
  .run-time{flex:none;font-size:13px;color:var(--muted);}
  .soft.run-start{flex:none;width:100%;padding:0 14px;}
  .run-start span{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}

  #medication-strip{display:flex; flex-direction:column; margin-bottom:8px; background:var(--fill); border-radius:10px; padding:4px; cursor:pointer;}
  .med-row{display:flex; align-items:center; gap:8px; padding:4px 8px; font-size:12px; color:var(--muted); border-radius:6px;}
  .med-row.due{background:var(--fill); color:var(--ink); font-weight:500;}
  .med-row.active{color:var(--accent); font-weight:600;}
  .med-row.wearing-off{color:var(--muted); font-weight:500;}
  .med-row .med-icon{font-size:13px; flex:none;}
  .med-row .med-label{flex:1 1 auto; min-width:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
  .med-row .med-status{flex:none;}
  .med-row button{flex:none; font-size:11px; padding:2px 8px; border-radius:6px; background:var(--accent); color:var(--on-accent); font-weight:600;}
  .med-row .med-chevron{flex:none; font-size:14px; opacity:.5; padding:4px; cursor:pointer; display:inline-flex; align-items:center;}

  #wait-guard{display:flex; align-items:center; gap:8px;
    padding:6px 10px; margin-bottom:8px;
    background:var(--fill); border-radius:10px;
    font-size:12px; color:var(--muted);}
  #wait-guard.warn{background:var(--fill); color:var(--muted);}
  #wait-guard.stop{background:var(--fill-strong); color:var(--ink); font-weight:600;}
  #wait-guard .lock{flex:none; font-size:12px; opacity:.6;}
  #wait-guard.stop .lock{opacity:.85;}
  #wait-guard .anchor-note{flex:1 1 auto; min-width:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
  #wait-guard .anchor-finish{flex:none; position:relative; overflow:hidden; font-size:12px; line-height:1.2; padding:3px 9px; border-radius:10px; color:var(--muted); border:1px solid var(--line); background:transparent; touch-action:none; user-select:none; -webkit-user-select:none; -webkit-touch-callout:none;}
  #wait-guard .anchor-finish:active{background:var(--press);}
  #wait-guard .anchor-finish:focus-visible{outline:2px solid var(--accent); outline-offset:2px;}
  #wait-guard .anchor-finish-fill{position:absolute; left:0; top:0; bottom:0; width:0; background:var(--accent-soft);}
  #wait-guard .anchor-finish.holding .anchor-finish-fill{width:100%; transition:width 1s linear;}
  #wait-guard .anchor-finish-text{position:relative;}
  /* Anchor kit: the "Get ready" line may wrap to two lines; "Take 10m" looks like "Finished early". */
  #wait-guard.two-line .guard-text{min-width:0; overflow:hidden; display:-webkit-box; -webkit-box-orient:vertical; -webkit-line-clamp:2; overflow-wrap:anywhere;}
  #wait-guard .guard-take{flex:none; font-size:12px; line-height:1.2; padding:3px 9px; border-radius:10px; color:var(--muted); border:1px solid var(--line); background:transparent;}
  #wait-guard .guard-take:active{background:var(--press);}
  #wait-guard .guard-take:focus-visible{outline:2px solid var(--accent); outline-offset:2px;}

  .relation-popover{position:fixed; z-index:300; background:var(--surface); border:2px solid var(--ink); border-radius:12px; padding:12px; box-shadow:0 8px 24px var(--shadow); font-size:13px; animation:popIn .15s ease-out; max-width: calc(100vw - 40px); width: max-content;}
  @keyframes popIn{from{opacity:0;transform:scale(0.95);}to{opacity:1;transform:scale(1);}}
  .relation-popover ul{list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:6px;}
  .relation-popover li{display:flex; gap:6px; align-items:center; color:var(--ink); line-height:1.35; width: 100%;}
  .relation-popover li svg{width:14px; height:14px; flex:none; margin-top:0;}
  .relation-popover li span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .relation-popover .popover-arrow{position:absolute; width:0; height:0; border-left:8px solid transparent; border-right:8px solid transparent; border-top:8px solid var(--ink);}

  body:has(#day:not(.hidden)){overflow:hidden;}
  body:has(#day:not(.hidden)) .app{
    height:100vh;
    height:100dvh;
    height:var(--app-height, 100dvh);
    overflow:hidden;
    padding-bottom:max(12px, env(safe-area-inset-bottom, 0px));
  }
  body:has(#day:not(.hidden)):has(#bottom-nav:not(.hidden)) .app{
    height:calc(100dvh - var(--nav-h));
    height:calc(var(--app-height, 100dvh) - var(--nav-h));
    min-height:0;
    padding-bottom:8px;
  }
  body:has(#day:not(.hidden)) #day{display:flex !important;flex-direction:column;
    flex:1 1 auto;min-height:0;gap:12px;}
  body:has(#day:not(.hidden)) #day > header{flex:0 0 auto;margin-bottom:0;}
  body:has(#day:not(.hidden)) #now-card{flex:0 0 auto;max-height:36vh;max-height:36dvh;
    overflow-y:auto;-webkit-overflow-scrolling:touch;margin-bottom:0;padding:12px 14px;}
  
  body:has(#day:not(.hidden)):has(#wait-guard:not(.hidden)) #now-card{
    max-height:calc(36vh + 42px);
    max-height:calc(36dvh + 42px);}
    
  body:has(#day:not(.hidden)) #now-card.med-expanded {
    flex: 1 1 auto !important;
    max-height: none !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  body:has(#day:not(.hidden)) #now-card.med-expanded #medication-strip {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
  }
  body:has(#day:not(.hidden)) #now-card.med-expanded #now-prompt {
    margin-top: auto;
    flex: 0 0 auto;
  }
  
  @media (max-width: 767px) and (orientation: portrait) {
    body:has(#day:not(.hidden)):has(.med-expanded) .day-scrollable {
      flex: 0 0 0;
      min-height: 0;
      padding: 0;
      margin: 0;
      overflow: hidden;
      pointer-events: none;
    }
  }
  
  /* Small Now card while the list is scrolled (portrait phones only). Toggled by app.js: .now-compact = small bar,
     .now-open = full card the user opened by tapping the bar (chevron points up to close it again). */
  .now-toggle,.now-short{display:none;}
  .now-toggle svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;}
  @media (max-width: 767px) and (orientation: portrait) {
    /* While the list scrolls, app.js sets the card height (inline) and --now-fade; the content fades out as it is clipped.
       The list keeps its content at finger speed through an inline padding-top, so scroll anchoring must stay off. */
    body:has(#day:not(.hidden)) .day-scrollable{overflow-anchor:none;}
    body:has(#day:not(.hidden)) #now-card.now-shrinking{overflow:hidden;max-height:none !important;}
    #now-card.now-shrinking > *{opacity:var(--now-fade,1);}
    @keyframes now-bar-in{from{opacity:0;}to{opacity:1;}}
    #now-card.now-compact .now-toggle,#now-card.now-compact .now-header,#now-card.now-compact #now-prompt{animation:now-bar-in .18s ease-out;}
    @media (prefers-reduced-motion: reduce){
      #now-card.now-compact .now-toggle,#now-card.now-compact .now-header,#now-card.now-compact #now-prompt{animation:none;}
    }
    body:has(#day:not(.hidden)) #now-card.now-compact{display:flex;align-items:center;gap:6px;
      max-height:none !important;overflow:hidden;padding:4px 8px 4px 4px;}
    #now-card.now-compact .now-toggle{display:flex;flex:none;width:40px;height:44px;align-items:center;
      justify-content:center;color:var(--ink);padding:0;border-radius:10px;}
    #now-card.now-compact .now-toggle:active{background:var(--press);}
    #now-card.now-compact .now-header{flex:1 1 auto;min-width:0;display:flex;align-items:baseline;gap:8px;margin:0;}
    #now-card.now-compact .eyebrow{display:none;}
    #now-card.now-compact .now-label{flex:0 1 auto;font-size:16px;margin:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
    #now-card.now-compact .now-short{display:block;flex:none;font-size:12px;color:var(--muted);white-space:nowrap;}
    #now-card.now-compact :is(.now-meta,.bar,.now-step,#wait-guard,#medication-strip,#prompt-text,#btn-trial-done,#btn-extend,#extend-row,.now-links,#evening-prompt,.now-also,.now-ended){display:none !important;}
    #now-card.now-compact #now-prompt{flex:none;margin:0;}
    #now-card.now-compact .prompt-buttons{margin:0;}
    #now-card.now-compact #btn-move{min-height:44px;padding:0 14px;font-size:14px;flex:none;}
    #now-card.now-compact #btn-anchor-finish{min-height:44px;padding:0 14px;font-size:14px;flex:none;}
    body:has(#day:not(.hidden)) #now-card.now-open{position:relative;}
    #now-card.now-open .now-toggle{display:flex;position:absolute;top:2px;right:4px;width:40px;height:40px;
      align-items:center;justify-content:center;color:var(--ink);padding:0;border-radius:10px;z-index:2;}
    #now-card.now-open .now-toggle:active{background:var(--press);}
    #now-card.now-open .now-toggle svg{transform:rotate(180deg);}
    #now-card.now-open .now-header{padding-right:40px;}
  }
  body:has(#day:not(.hidden)) .day-scrollable{flex:1 1 auto;min-height:0;
    overflow-y:auto;-webkit-overflow-scrolling:touch;padding-bottom:8px;}
  body:has(#day:not(.hidden)) .day-scrollable > *:last-child{margin-bottom:0;}

  @media (max-height: 720px){
    body:has(#day:not(.hidden)) #now-card{padding:10px 12px; max-height:38vh; max-height:38dvh;}
    body:has(#day:not(.hidden)):has(#wait-guard:not(.hidden)) #now-card{
      max-height:calc(38vh + 38px);
      max-height:calc(38dvh + 38px);}
    #now-card .now-label{font-size:19px;}
    #now-card .now-meta{font-size:11.5px;margin-bottom:5px;}
    #now-card .bar{margin-bottom:6px;}
    #now-card .soft,#now-card .primary{min-height:36px;font-size:13px;}
    #now-card .extend-slider{height:24px;}
    #now-card .extend-slider-range{display:none;}
    #now-card .not-today{padding:8px 4px;margin-top:6px;font-size:12px;}
    #now-card .now-links{margin-top:6px;gap:4px;}
    #now-card .now-links + .now-links{margin-top:3px;}
    #now-card .now-links .not-today{padding:8px 4px;}
    #now-card .prompt-buttons{gap:6px;}
    #medication-strip{padding:3px;}
    #wait-guard{padding:5px 9px; font-size:11.5px; margin-bottom:6px;}
    #now-card .now-step{min-height:34px;padding:4px 9px;font-size:12.5px;margin-bottom:6px;}
  }
  @media (max-height: 620px){
    body:has(#day:not(.hidden)) #now-card{padding:8px 12px; max-height:42vh; max-height:42dvh;}
    body:has(#day:not(.hidden)):has(#wait-guard:not(.hidden)) #now-card{
      max-height:calc(42vh + 34px);
      max-height:calc(42dvh + 34px);}
    #now-card .now-label{font-size:18px;}
    #now-card .now-meta{font-size:11px;margin-bottom:4px;}
    #now-card .soft,#now-card .primary{min-height:32px;font-size:12.5px;}
    #now-card .extend-slider{height:20px;}
    #now-card .not-today{padding:6px 4px;margin-top:4px;font-size:11.5px;}
    #now-card .now-links{margin-top:4px;}
    #now-card .now-links + .now-links{margin-top:2px;}
    #now-card .now-links .not-today{padding:6px 4px;}
    #medication-strip{padding:2px;}
    #wait-guard{padding:4px 8px; font-size:11px; margin-bottom:4px;}
    #now-card .now-step{min-height:30px;padding:3px 8px;font-size:12px;margin-bottom:4px;gap:8px;}
    #now-card .now-step-tick{width:15px;height:15px;}
  }
  /* Portrait phones: the Now card must never scroll. Its content needs a fixed amount of room
     (two button rows, up to 2 med rows, the wait-guard), not a share of the screen height, so a
     vh-based cap clipped it on 360x740-800 phones. Let it size to its content; the schedule list
     below scrolls instead. Landscape and tablets keep their own layout (max-height:none). */
  @media (max-width: 767px) and (orientation: portrait){
    body:has(#day:not(.hidden)) #now-card{max-height:none !important;}
  }
  @media (min-width: 768px), (orientation: landscape) and (max-height: 600px){
    body:has(#day:not(.hidden)) .app{
      max-width:1200px;
      padding-top:max(10px, env(safe-area-inset-top, 0px));
      padding-right:max(10px, env(safe-area-inset-right, 0px));
      padding-bottom:max(10px, env(safe-area-inset-bottom, 0px));
      padding-left:max(10px, env(safe-area-inset-left, 0px));
    }
    body:has(#day:not(.hidden)):has(#bottom-nav:not(.hidden)) .app{padding-bottom:8px;}
    body:has(#day:not(.hidden)) #day{display:grid !important;
      grid-template-columns:1fr 1fr;grid-template-rows:auto 1fr;gap:10px;}
    body:has(#day:not(.hidden)) #day > header{grid-column:1 / -1;grid-row:1;}
    body:has(#day:not(.hidden)) #now-card{grid-column:1;grid-row:2;
      max-height:none;min-height:0;overflow-y:auto;}
    body:has(#day:not(.hidden)) .day-scrollable{grid-column:2;grid-row:2;
      min-height:0;overflow-y:auto;}
    body:has(#day:not(.hidden)):has(#checkin:not(.hidden)) #day{
      display:flex !important;flex-direction:column;}
    body:has(#day:not(.hidden)):has(#checkin:not(.hidden)) #now-card{
      max-height:33vh;max-height:33dvh;flex:0 0 auto;}
    body:has(#day:not(.hidden)):has(#checkin:not(.hidden)):has(#wait-guard:not(.hidden)) #now-card{
      max-height:calc(33vh + 42px);
      max-height:calc(33dvh + 42px);}
    body:has(#day:not(.hidden)):has(#wait-guard:not(.hidden)) #now-card{
      max-height:none;}
    /* Pin "Change of plans" to the bottom of the tall side card */
    body:has(#day:not(.hidden)) #now-card{display:flex;flex-direction:column;}
    body:has(#day:not(.hidden)) #now-card > #now-prompt:not(.hidden),
    body:has(#day:not(.hidden)) #now-card > #evening-prompt:not(.hidden){
      display:flex;flex-direction:column;flex:1 1 auto;}
    body:has(#day:not(.hidden)) #now-card .not-today{margin-top:auto;}
    body:has(#day:not(.hidden)) #now-card .now-links{margin-top:auto;}
    body:has(#day:not(.hidden)) #now-card .now-links + .now-links{margin-top:4px;}
    body:has(#day:not(.hidden)) #now-card .now-links .not-today{margin-top:0;}
  }

  /* Focus mode: after the Day screen's own layouts, so it wins in portrait, landscape and wide. The screen scrolls
     as one column; the header keeps only the title and the leave button, and the list is hidden. */
  body:has(#day.focus:not(.hidden)) #day.focus{display:flex !important;flex-direction:column;
    overflow-y:auto;-webkit-overflow-scrolling:touch;width:100%;max-width:520px;margin:0 auto;}
  body:has(#day:not(.hidden)) #day.focus > *{flex:0 0 auto;}
  body:has(#day:not(.hidden)) #day.focus #now-card{max-height:none !important;overflow:visible;}
  #day.focus > header{justify-content:space-between;}
  #day.focus .day-scrollable,#day.focus .chip,#day.focus #btn-park,#day.focus #btn-change,#day.focus .gear-slot,
  #day.focus #nested-links,#day.focus .now-also{display:none !important;}
  #day.focus .focus-runs:not(.hidden){display:flex;flex-direction:column;gap:10px;}

  /* Sideways moves on the Day screen are the swipe into and out of focus mode. */
  #day{touch-action:pan-y pinch-zoom;}
  #day.swipe-from-right > *{animation:swipe-from-right .2s ease-out;}
  #day.swipe-from-left > *{animation:swipe-from-left .2s ease-out;}
  @media (prefers-reduced-motion: reduce){ #day > *{animation:none !important;} }

  @media (max-height: 500px){
    .edit-panel{padding:14px 16px max(14px, calc(env(safe-area-inset-bottom, 0px) + 8px));}
    .edit-title{font-size:17px;margin-bottom:10px;}
    .edit-label{font-size:10px;margin-bottom:3px;letter-spacing:.06em;}
    .edit-input{min-height:36px;padding:0 10px;margin-bottom:8px;font-size:15px;}
    #edit-section-field .seg,#edit-keep-field .seg{margin-bottom:8px;}
    .edit-checkbox-row{margin-bottom:8px;gap:6px;}
    .edit-checkbox-row input[type="checkbox"]{width:16px;height:16px;}
    .edit-checkbox-row label{font-size:13px;}
    .edit-actions{margin-top:4px;gap:6px;}
    .edit-btn{min-height:38px;font-size:14px;}
    #edit-do-next{min-height:38px;font-size:14px;}
    .change-opt{min-height:40px;padding:4px 12px;margin-bottom:6px;font-size:14px;}
    .change-sub{display:none;}
    .tidy-sub{font-size:13px;margin:-4px 0 10px;}
    #tidy-list .settings-row{padding:10px 14px;}
    .reset-done{margin-top:10px;font-size:12px;line-height:1.4;}
    .window-row{margin-bottom:8px;}
    .window-row .edit-input{min-height:36px;}
  }

  /* C14: wide screens and landscape phones. Same rule as the Day screen; portrait phones are untouched.
     The Day screen has its own wider, more specific .app rule above. */
  @media (min-width: 768px), (orientation: landscape) and (max-height: 600px){
    .app{max-width:760px;}
    body:has(#week:not(.hidden)) .app{max-width:900px;}
    .later-wrap,.med-history-wrap,.reset-wrap,.firstweek-wrap,.reentry-wrap{min-height:0;}
    #capacity .tiers{display:grid;grid-template-columns:1fr 1fr;gap:10px;}
    .settings-list{display:grid;grid-template-columns:1fr 1fr;gap:10px;align-items:start;}
    #later-list,#meds-list{display:grid;grid-template-columns:1fr 1fr;column-gap:10px;align-items:start;}
    /* Month: calendar on the left, the picked day on the right */
    #week .later-wrap:has(#cal-daylist:not(.hidden)){display:grid;grid-template-columns:1fr 1fr;
      column-gap:24px;align-content:start;}
    #week .later-wrap:has(#cal-daylist:not(.hidden)) > *{grid-column:1 / -1;}
    #week .later-wrap:has(#cal-daylist:not(.hidden)) > #cal-view{grid-column:1;grid-row:5;}
    #week .later-wrap:has(#cal-daylist:not(.hidden)) > #cal-daylist{grid-column:2;grid-row:5;
      margin-top:0;align-self:start;}
    /* Older doses, month view: calendar on the left, the picked day on the right */
    #med-older.has-day:not(.hidden){display:grid;grid-template-columns:1fr 1fr;column-gap:24px;align-items:start;}
    #med-older .cal-daylist{margin-top:0;}
    /* Week: the bars on the left, the legend as a vertical list on the right */
    #week .later-wrap:has(#week-grid:not(.hidden)){display:grid;grid-template-columns:1fr 200px;
      column-gap:24px;align-content:start;}
    #week .later-wrap:has(#week-grid:not(.hidden)) > *{grid-column:1 / -1;}
    #week .later-wrap:has(#week-grid:not(.hidden)) > #week-grid{grid-column:1;grid-row:5;}
    #week .later-wrap:has(#week-grid:not(.hidden)) > .week-legend{grid-column:2;grid-row:5;
      flex-direction:column;align-items:flex-start;justify-content:center;gap:12px;
      margin-top:0;padding-top:0;border-top:0;align-self:center;}
    /* Medications: the add/edit form is a dialog on top, like the task sheet */
    #meds-backdrop{display:none;position:fixed;inset:0;z-index:99;background:var(--backdrop);}
    #meds-screen .later-wrap:has(#meds-form:not(.hidden)) #meds-backdrop{display:block;}
    #meds-form{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);z-index:100;
      width:min(520px, calc(100vw - 40px));max-height:calc(100vh - 40px);max-height:calc(100dvh - 40px);
      overflow-y:auto;margin:0;padding:24px 22px;border-radius:22px;box-shadow:0 12px 40px var(--shadow);
      background:var(--surface);}    /* Sheets become centred dialogs */
    .edit-sheet{align-items:center;padding:20px;}
    .edit-panel{max-width:520px;border-radius:22px;
      max-height:calc(100vh - 40px);max-height:calc(100dvh - 40px);
      box-shadow:0 12px 40px var(--shadow);}
  }
