/* Rungs — styles.css
   Tokens (light on :root, dark twice), reset, layout, components, row states,
   chips, drag-and-drop, FLIP hooks, toasts, menu, sheet, week strip, progress,
   responsive, print, reduced motion. No @import, no url(). */

/* ---------- 1. Tokens ---------- */
:root {
  color-scheme: light dark;
  --bg: #F6F4EF; --surface: #FFFFFF; --surface-2: #EFECE5; --border: #E4E0D7; --border-strong: #CFC9BD;
  --ink: #1C1917; --ink-2: #57534E; --ink-3: #6F6960;
  --accent: #0F766E; --accent-hover: #115E59; --accent-soft: #D9F0EA; --accent-ink: #FFFFFF;
  --success: #15803D; --success-soft: #DCF5E3; --danger: #B91C1C; --danger-soft: #FDE8E8;
  --tone-overdue-bg: #FDE8E8; --tone-overdue-text: #9B1C1C; --tone-overdue-dot: #DC2626;
  --tone-today-bg: #FEF0DC;   --tone-today-text: #9A4B00;   --tone-today-dot: #EA8A00;
  --tone-soon-bg: #FBF3D0;    --tone-soon-text: #7A5A00;    --tone-soon-dot: #D4A017;
  --tone-week-bg: #EFECE5;    --tone-week-text: #57534E;
  --tone-later-text: #6F6960;
  --toast-bg: #1C1917; --toast-text: #F6F4EF; --toast-action: #5EEAD4;
  --focus: #0F766E; --focus-ring: 0 0 0 3px #D9F0EA;
  --shadow-sm: 0 1px 2px rgba(28,25,23,.06);
  --shadow-md: 0 4px 12px rgba(28,25,23,.08), 0 1px 3px rgba(28,25,23,.06);
  --shadow-drag: 0 12px 32px rgba(28,25,23,.18), 0 2px 6px rgba(28,25,23,.10);
  --shadow-lg: 0 24px 48px rgba(28,25,23,.22);

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease-out: cubic-bezier(.2,.7,.2,1);
  --ease-spring: cubic-bezier(.34,1.56,.64,1);
  --dur-1: 120ms; --dur-2: 200ms; --dur-3: 220ms;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141311; --surface: #1E1C19; --surface-2: #262320; --border: #2E2B26; --border-strong: #3E3A33;
    --ink: #EDE9E1; --ink-2: #B5AEA2; --ink-3: #8B857A;
    --accent: #2DD4BF; --accent-hover: #5EEAD4; --accent-soft: #163B36; --accent-ink: #0B1F1C;
    --success: #4ADE80; --success-soft: #14301F; --danger: #F87171; --danger-soft: #3B1F1D;
    --tone-overdue-bg: #3B1F1D; --tone-overdue-text: #FCA5A5; --tone-overdue-dot: #F87171;
    --tone-today-bg: #3A2814;   --tone-today-text: #FDBA74;   --tone-today-dot: #FB923C;
    --tone-soon-bg: #3A3212;    --tone-soon-text: #FDE68A;    --tone-soon-dot: #FACC15;
    --tone-week-bg: #262320;    --tone-week-text: #B5AEA2;
    --tone-later-text: #B5AEA2;
    --toast-bg: #2E2B26; --toast-text: #EDE9E1; --toast-action: #5EEAD4;
    --focus: #2DD4BF; --focus-ring: 0 0 0 3px #163B36;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.45);
    --shadow-md: 0 4px 12px rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4);
    --shadow-drag: 0 12px 32px rgba(0,0,0,.6), 0 2px 6px rgba(0,0,0,.4);
    --shadow-lg: 0 24px 48px rgba(0,0,0,.65);
  }
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141311; --surface: #1E1C19; --surface-2: #262320; --border: #2E2B26; --border-strong: #3E3A33;
  --ink: #EDE9E1; --ink-2: #B5AEA2; --ink-3: #8B857A;
  --accent: #2DD4BF; --accent-hover: #5EEAD4; --accent-soft: #163B36; --accent-ink: #0B1F1C;
  --success: #4ADE80; --success-soft: #14301F; --danger: #F87171; --danger-soft: #3B1F1D;
  --tone-overdue-bg: #3B1F1D; --tone-overdue-text: #FCA5A5; --tone-overdue-dot: #F87171;
  --tone-today-bg: #3A2814;   --tone-today-text: #FDBA74;   --tone-today-dot: #FB923C;
  --tone-soon-bg: #3A3212;    --tone-soon-text: #FDE68A;    --tone-soon-dot: #FACC15;
  --tone-week-bg: #262320;    --tone-week-text: #B5AEA2;
  --tone-later-text: #B5AEA2;
  --toast-bg: #2E2B26; --toast-text: #EDE9E1; --toast-action: #5EEAD4;
  --focus: #2DD4BF; --focus-ring: 0 0 0 3px #163B36;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.45);
  --shadow-md: 0 4px 12px rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4);
  --shadow-drag: 0 12px 32px rgba(0,0,0,.6), 0 2px 6px rgba(0,0,0,.4);
  --shadow-lg: 0 24px 48px rgba(0,0,0,.65);
}

/* ---------- 2. Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-sans); font-size: 14px; line-height: 1.4;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
body.is-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
ol, ul { list-style: none; margin: 0; padding: 0; }
svg.icon { width: 16px; height: 16px; display: block; flex: none; }
kbd {
  font-family: var(--font-mono); font-size: 11px; line-height: 1.4; padding: 1px 6px; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-2); white-space: nowrap;
}
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
[hidden] { display: none !important; }
.tabular, .seg-count, .rank, .chip, .day-num, .day-count, #progress-text, .done-meta, .section-count { font-variant-numeric: tabular-nums; }

/* ---------- 3. Layout ---------- */
main#app { max-width: 720px; margin: 0 auto; padding: 32px 20px 96px; }

/* Header */
header#topbar { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 20px; }
.wordmark { display: flex; align-items: center; gap: 8px; font-size: 22px; font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; color: var(--ink); }
.wordmark .icon-ladder { width: 20px; height: 20px; color: var(--accent); }
.week-line { margin-top: 6px; font-size: 13px; color: var(--ink-2); }
.topbar-actions { display: flex; gap: 4px; align-items: center; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2); transition: background var(--dur-1), color var(--dur-1);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn[aria-expanded="true"] { background: var(--surface-2); color: var(--ink); }
.menu-wrap { position: relative; }
#menu {
  position: absolute; right: 0; top: calc(100% + 6px); width: 220px; padding: 6px; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-md);
  animation: pop-in var(--dur-2) var(--ease-out);
}
#menu [role="menuitem"] {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 10px; border-radius: 8px; font-size: 13px; text-align: left; color: var(--ink);
}
#menu [role="menuitem"]:hover { background: var(--surface-2); }
#menu [role="menuitem"]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; background: var(--accent-soft); color: var(--accent); }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* Week strip */
nav#week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 12px; }
.day {
  min-height: 56px; border-radius: 10px; padding: 6px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 2px solid transparent; color: var(--ink); transition: background var(--dur-1), border-color var(--dur-1);
}
.day:hover { background: var(--surface-2); }
.day.is-today { border-color: var(--accent); background: var(--accent-soft); }
.day[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.day[aria-pressed="true"] .day-name, .day[aria-pressed="true"] .day-num { color: inherit; }
.day-name { font-size: 11px; font-weight: 500; color: var(--ink-3); text-transform: none; }
.day-name .long { display: inline; } .day-name .short { display: none; }
.day-num { font-size: 16px; font-weight: 600; line-height: 1.2; }
.day.is-past .day-num { color: var(--ink-3); }
.day-count { font-size: 12px; font-weight: 500; line-height: 18px; padding: 0 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.day-count.is-overdue { background: var(--tone-overdue-bg); color: var(--tone-overdue-text); }
.day[aria-pressed="true"] .day-count { background: rgba(255,255,255,.22); color: inherit; }

/* Progress */
div#progress { margin-bottom: 24px; display: flex; flex-direction: column; gap: 6px; }
.progress-track { height: 3px; border-radius: 2px; background: var(--border-strong); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width 300ms var(--ease-out), background var(--dur-2); }
.progress-fill.is-complete { background: var(--success); }
#progress-text { align-self: flex-end; font-size: 12px; color: var(--ink-2); }

/* Composer */
form#quick-add-form {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 8px; box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
}
form#quick-add-form:focus-within { border-color: var(--accent); box-shadow: var(--shadow-md); }
.composer-row { display: flex; align-items: center; gap: 8px; }
#quick-add {
  flex: 1 1 auto; min-width: 0; min-height: 40px; padding: 0 8px; font-size: 16px; border: 0; background: transparent; color: var(--ink); outline: none;
}
#quick-add::placeholder { color: var(--ink-3); }
#quick-add.shake { animation: shake 300ms var(--ease-out); }
@keyframes shake { 0% { transform: translateX(0); } 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } 100% { transform: translateX(0); } }
.composer-divider { width: 1px; height: 24px; background: var(--border); flex: none; }
#quick-date { min-width: 150px; font-size: 14px; border: 0; background: transparent; color: var(--ink-2); padding: 4px 6px; border-radius: 8px; outline: none; }
#quick-date:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
#quick-submit {
  height: 34px; padding: 0 14px; background: var(--accent); color: var(--accent-ink); font-size: 14px; font-weight: 600; border-radius: 10px; flex: none;
  transition: background var(--dur-1);
}
#quick-submit:hover { background: var(--accent-hover); }
#quick-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 4px 0; }
.qchip {
  font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2);
  transition: background var(--dur-1), color var(--dur-1);
}
.qchip:hover { color: var(--ink); }
.qchip.is-active { background: var(--accent-soft); color: var(--accent); }
.qchip--clear { background: transparent; border: 1px dashed var(--border-strong); }
#quick-preview { min-height: 18px; padding: 6px 8px 0; font-size: 12px; color: var(--ink-3); }
#quick-hint { padding: 4px 8px 2px; font-size: 12px; color: var(--ink-3); }
#quick-hint kbd { font-size: 10px; padding: 0 5px; }

/* Filter bar */
div#filter-bar {
  position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 0; border-bottom: 1px solid var(--border); margin-top: 24px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.seg { display: inline-flex; padding: 4px; gap: 2px; background: var(--surface-2); border-radius: 10px; }
.seg-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 7px; font-size: 14px; font-weight: 500; color: var(--ink-2);
  transition: background var(--dur-1), color var(--dur-1), box-shadow var(--dur-1);
}
.seg-btn:hover { color: var(--ink); }
.seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.seg-count { font-size: 12px; font-weight: 500; color: var(--ink-2); }
.seg-dot { display: none; width: 6px; height: 6px; border-radius: 50%; background: var(--tone-overdue-dot); }
.seg-btn.has-overdue .seg-dot { display: inline-block; }
.seg-btn.has-overdue .seg-count { color: var(--tone-overdue-text); }
#day-filter-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--accent-soft); color: var(--accent);
}
#day-filter-chip:hover { background: var(--accent); color: var(--accent-ink); }

/* Sections */
section#ladder-section { margin-top: 20px; }
section#done-section, section#archive-section { margin-top: 28px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; min-height: 24px; }
.section-label { display: flex; align-items: center; gap: 6px; }
.section-label h2, .section-count, .archive-week h3 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.ladder-hint { font-size: 11px; color: var(--ink-3); }
.grip-glyph { letter-spacing: -0.2em; margin-right: 0.2em; } /* the trailing negative spacing would otherwise eat the space before "or" */
.ghost-btn { font-size: 12px; font-weight: 500; color: var(--ink-2); padding: 4px 8px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px; transition: color var(--dur-1), background var(--dur-1); }
.ghost-btn:hover { color: var(--ink); background: var(--surface-2); }
.ghost-btn--danger:hover { color: var(--danger); }
#done-toggle { width: 24px; height: 24px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-3); margin-left: -4px; }
#done-toggle:hover { background: var(--surface-2); color: var(--ink); }
#done-toggle .icon { transition: transform var(--dur-2) var(--ease-out); }
#done-toggle[aria-expanded="false"] .icon { transform: rotate(-90deg); }

/* ---------- 4. Ladder rows ---------- */
ol#ladder, ol#done-list { position: relative; list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
#ladder::before { content: ""; position: absolute; left: 21px; top: 24px; bottom: 24px; width: 2px; background: var(--border); z-index: 0; }
#ladder.is-short::before { display: none; }
li.task {
  position: relative; z-index: 1; min-height: 48px; padding: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  display: grid; grid-template-columns: 24px 20px minmax(0, 1fr) auto auto auto 20px; column-gap: 12px; align-items: center;
  touch-action: pan-y;
  transition: border-color var(--dur-1), box-shadow var(--dur-1), background var(--dur-1);
}
li.task, li.archived { scroll-margin-top: 64px; } /* #filter-bar is sticky + opaque (~59px) */
li.task > .edit, li.task > .delete { margin-left: -6px; }
li.task:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
li.task.is-selected { border-color: var(--accent); box-shadow: var(--focus-ring); }
li.task:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
li.task.is-lifted { z-index: 10; box-shadow: var(--shadow-drag); transition: none; cursor: grabbing; border-color: var(--accent); }
#ladder.is-dragging-list li.task { transition: transform 160ms var(--ease-out); }
#ladder.is-dragging-list li.task.is-lifted { transition: none; }
li.task.just-added, li.task.just-moved { animation: flash 600ms var(--ease-out); }
@keyframes flash { from { background: var(--accent-soft); } to { background: var(--surface); } }
.flip-moving { transition: transform var(--dur-3) var(--ease-out), box-shadow var(--dur-3); }

.rank {
  width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border);
  transition: opacity var(--dur-2), background var(--dur-1), color var(--dur-1);
}
.rank.rank--1 { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.rank.rank--top { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.rank.rank--done { background: var(--success-soft); color: var(--success); border-color: transparent; }
.rank.rank--done .icon { width: 14px; height: 14px; }

.check {
  width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--ink-3); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; color: var(--accent-ink);
  transition: border-color var(--dur-1), background var(--dur-1), transform 220ms var(--ease-spring);
}
.check:hover { border-color: var(--accent); }
.check .icon { width: 14px; height: 14px; opacity: 0; }
.check .icon .tick { stroke-dasharray: 24; stroke-dashoffset: 24; }
.check[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.check[aria-checked="true"] .icon { opacity: 1; }
.check[aria-checked="true"] .icon .tick { stroke-dashoffset: 0; }
li.task.is-done:not(.was-done) .check[aria-checked="true"] { animation: check-pop 220ms var(--ease-spring); }
li.task.is-done:not(.was-done) .check[aria-checked="true"] .icon .tick { animation: draw-tick 180ms var(--ease-out) 80ms both; }
@keyframes check-pop { 0% { transform: scale(1); } 50% { transform: scale(.88); } 100% { transform: scale(1); } }
@keyframes draw-tick { from { stroke-dashoffset: 24; } to { stroke-dashoffset: 0; } }

.title {
  font-size: 15px; font-weight: 400; line-height: 1.4; color: var(--ink); min-width: 0; position: relative;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; overflow-wrap: anywhere;
  transition: color var(--dur-2);
}
.title::after { content: ""; position: absolute; left: 0; top: 55%; height: 1.5px; width: 0; background: currentColor; transition: width 240ms var(--ease-out); pointer-events: none; }
li.task.is-done .title { color: var(--ink-3); }
li.task.is-done .title::after { width: 100%; }
li.task.is-done:not(.was-done) .rank:not(.rank--done) { opacity: 0; }
#done-list li.task .title { color: var(--ink-3); text-decoration: line-through; }
#done-list li.task .title::after { display: none; }
#done-list li.task { grid-template-columns: 24px 20px minmax(0, 1fr) auto auto 20px; } /* rank check title meta × + an empty grip-width track so × lines up with the ladder */
.title-edit {
  font-size: 15px; line-height: 1.4; padding: 2px 6px; margin: -2px -6px; width: calc(100% + 12px); min-width: 0;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; color: var(--ink); outline: none;
}
.title-edit:focus { border-color: var(--accent); box-shadow: var(--focus-ring); }
.edit-preview { grid-column: 3 / -1; font-size: 12px; color: var(--ink-3); padding-top: 4px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 500; white-space: nowrap;
  border: 1px solid transparent; transition: filter var(--dur-1);
}
.chip:hover { filter: brightness(.96); }
.chip-dot { display: none; width: 6px; height: 6px; border-radius: 50%; }
.chip--overdue { background: var(--tone-overdue-bg); color: var(--tone-overdue-text); }
.chip--overdue .chip-dot { display: inline-block; background: var(--tone-overdue-dot); }
.chip--today { background: var(--tone-today-bg); color: var(--tone-today-text); }
.chip--today .chip-dot { display: inline-block; background: var(--tone-today-dot); }
.chip--soon { background: var(--tone-soon-bg); color: var(--tone-soon-text); }
.chip--soon .chip-dot { display: inline-block; background: var(--tone-soon-dot); }
.chip--week { background: var(--tone-week-bg); color: var(--tone-week-text); }
.chip--later { background: transparent; color: var(--tone-later-text); border-color: var(--border); }
.add-date {
  font-size: 12px; padding: 2px 8px; border-radius: 6px; border: 1px dashed var(--border); color: var(--ink-3); white-space: nowrap;
  opacity: 0; transition: opacity var(--dur-1), color var(--dur-1), border-color var(--dur-1);
}
.add-date:hover { color: var(--ink); border-color: var(--border-strong); }
.done-meta { font-size: 12px; font-weight: 500; color: var(--ink-3); white-space: nowrap; }
.deadline-editor { display: inline-flex; align-items: center; gap: 4px; }
.deadline-edit {
  width: 210px; font-size: 12px; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--ink); outline: none;
}
.deadline-edit:focus { border-color: var(--accent); box-shadow: var(--focus-ring); }
.deadline-edit.is-invalid { border-color: var(--danger); animation: shake 200ms var(--ease-out); }
.deadline-edit::placeholder { color: var(--ink-3); }
.deadline-native { font-size: 12px; padding: 2px 4px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--ink); }
.deadline-cal { width: 24px; height: 24px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-3); }
.deadline-cal:hover { color: var(--ink); background: var(--surface-2); }

li.task > .edit, li.task > .delete {
  width: 24px; height: 24px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-3);
  opacity: 0; transition: opacity var(--dur-1), color var(--dur-1), background var(--dur-1);
}
li.task > .edit:hover { color: var(--ink); background: var(--surface-2); }
li.task > .delete:hover { color: var(--danger); background: var(--danger-soft); }
.grip {
  width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-3); cursor: grab;
  touch-action: none; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
  padding: 12px 10px; margin: -12px -10px; box-sizing: content-box;
  opacity: 0; transition: opacity var(--dur-1), color var(--dur-1);
}
.grip:hover { color: var(--ink); }
.grip:active, li.task.is-lifted .grip { cursor: grabbing; }
li.task:hover > .edit, li.task:hover > .delete, li.task:hover > .grip, li.task:hover > .add-date,
li.task.is-selected > .edit, li.task.is-selected > .delete, li.task.is-selected > .grip, li.task.is-selected > .add-date,
li.task:focus-within > .edit, li.task:focus-within > .delete, li.task:focus-within > .grip, li.task:focus-within > .add-date,
li.task.is-lifted > .grip { opacity: 1; }
@media (pointer: coarse) {
  li.task > .edit, li.task > .delete, li.task > .grip, li.task > .add-date { opacity: 1; }
  li.task > .edit, li.task > .delete { width: 40px; height: 40px; }
  .check, .chip, .add-date { position: relative; }
  .check::before, .chip::before, .add-date::before { content: ""; position: absolute; inset: -10px; }
}

/* Empty state */
#empty {
  border: 1px dashed var(--border-strong); border-radius: 12px; padding: 40px 24px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
#empty h3 { font-size: 17px; font-weight: 600; color: var(--ink); }
#empty p { font-size: 14px; color: var(--ink-2); max-width: 420px; }
#empty .kbd-hint { font-size: 12px; color: var(--ink-3); }
#empty .empty-ladder { width: 48px; height: 64px; margin-bottom: 8px; }
#empty .empty-check { width: 40px; height: 40px; border-radius: 50%; background: var(--success-soft); color: var(--success); display: inline-flex; align-items: center; justify-content: center; margin-bottom: 8px; }
#empty .empty-check .icon { width: 20px; height: 20px; }

/* Archive */
#archive-list { overflow-x: auto; display: flex; flex-direction: column; gap: 20px; }
.archive-week h3 { margin-bottom: 8px; }
.archive-week ul { display: flex; flex-direction: column; gap: 4px; }
li.archived {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; column-gap: 12px; align-items: center;
  padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--ink-3); font-size: 14px;
}
li.archived .title { font-size: 14px; color: var(--ink-3); }
li.archived .restore { font-size: 12px; font-weight: 500; color: var(--ink-2); padding: 4px 8px; border-radius: 6px; }
li.archived .restore:hover { background: var(--surface-2); color: var(--ink); }
li.archived .delete { width: 24px; height: 24px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-3); }
li.archived .delete:hover { color: var(--danger); background: var(--danger-soft); }
.archive-empty { font-size: 14px; color: var(--ink-3); padding: 16px 0; }

/* Footer */
footer#footer { margin-top: 48px; font-size: 12px; color: var(--ink-3); text-align: center; }
#footer-status.is-danger { color: var(--danger); font-weight: 500; }

/* ---------- 5. Overlays ---------- */
div#toasts { position: fixed; bottom: 24px; left: 16px; right: 16px; z-index: 40; display: flex; flex-direction: column; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 14px; border-radius: 12px; max-width: 100%;
  background: var(--toast-bg); color: var(--toast-text); box-shadow: var(--shadow-md); font-size: 13px; font-weight: 500;
  animation: toast-in var(--dur-2) var(--ease-out);
}
.toast.is-leaving { animation: toast-out var(--dur-2) var(--ease-out) forwards; }
.toast-text { min-width: 0; overflow-wrap: anywhere; }
.toast-undo { font-size: 13px; font-weight: 600; color: var(--toast-action); padding: 2px 4px; border-radius: 6px; white-space: nowrap; }
.toast-undo:hover { text-decoration: underline; }
.toast kbd { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.18); color: inherit; }
.toast-close { width: 24px; height: 24px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; color: inherit; opacity: .7; }
.toast-close:hover { opacity: 1; background: rgba(255,255,255,.12); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(12px); } }

aside#shortcuts {
  position: fixed; top: 0; right: 0; height: 100%; width: 320px; z-index: 35; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); border-radius: 16px 0 0 16px;
  animation: sheet-in 160ms var(--ease-out);
}
@keyframes sheet-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 16px 8px 20px; }
.sheet-head h2 { font-size: 15px; font-weight: 600; }
.sheet-body { padding: 0 20px 32px; overflow-x: auto; }
.sheet-body h3 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); margin: 18px 0 6px; }
.kbd-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kbd-table td { padding: 5px 0; vertical-align: top; color: var(--ink-2); }
.kbd-table td:first-child { white-space: nowrap; padding-right: 12px; color: var(--ink); width: 1%; }

#error-banner { margin: 16px auto; max-width: 720px; padding: 12px 16px; border-radius: 12px; background: var(--danger-soft); color: var(--danger); font-size: 14px; font-family: var(--font-mono); white-space: pre-wrap; }

/* ---------- 6. Responsive ---------- */
@media (max-width: 560px) {
  main#app { padding: 24px 16px 96px; }
  .composer-row { flex-wrap: wrap; }
  #quick-add { flex-basis: 100%; }
  .composer-divider { display: none; }
  #quick-date { flex: 1 1 auto; }
  .day-name .long { display: none; } .day-name .short { display: inline; }
  .seg-btn { font-size: 13px; padding: 5px 9px; }
  .ladder-hint { display: none; }
  li.task {
    grid-template-columns: 22px 20px minmax(0, 1fr) auto; padding: 8px; column-gap: 10px; row-gap: 6px;
    grid-template-areas: "rank check title grip" "rank check chip actions";
  }
  li.task > .rank { grid-area: rank; width: 22px; height: 22px; }
  li.task > .check { grid-area: check; }
  li.task > .title, li.task > .title-edit { grid-area: title; }
  li.task > .chip, li.task > .add-date, li.task > .deadline-editor, li.task > .done-meta { grid-area: chip; justify-self: start; }
  li.task > .edit { grid-area: actions; justify-self: end; margin-right: 34px; }
  li.task > .delete { grid-area: actions; justify-self: end; }
  li.task > .grip { grid-area: grip; justify-self: end; }
  li.task > .edit, li.task > .delete, li.task > .grip, li.task > .add-date { opacity: 1; }
  li.task > .edit, li.task > .delete { width: 40px; height: 40px; margin-left: 0; }
  li.task > .edit { margin-right: 40px; }
  .check, .chip, .add-date { position: relative; }
  .check::before, .chip::before, .add-date::before { content: ""; position: absolute; inset: -10px; }
  li.task > .deadline-editor { justify-self: stretch; min-width: 0; }
  .deadline-edit { flex: 1 1 0; min-width: 0; width: auto; }
  .edit-preview { grid-column: 1 / -1; }
  #done-list li.task { grid-template-columns: 22px 20px minmax(0, 1fr) auto; }
  aside#shortcuts { width: 100%; border-radius: 0; }
}

/* ---------- 7. Print ---------- */
@media print {
  /* Paper is always the light palette. The rules below assume dark ink on white, and
     WebKit does not print backgrounds by default, so a pinned (or system) dark theme
     would otherwise put near-white titles on a white sheet. Both dark selectors are
     re-declared here so this beats :root[data-theme="dark"] and the
     prefers-color-scheme block at equal specificity. */
  :root, :root[data-theme="dark"], :root:not([data-theme="light"]) {
    color-scheme: light;
    --bg: #fff; --surface: #fff; --surface-2: #fff; --border: #999; --border-strong: #666;
    --ink: #000; --ink-2: #333; --ink-3: #555;
    --accent: #000; --accent-hover: #000; --accent-soft: #fff; --accent-ink: #fff;
    --success: #000; --success-soft: #fff; --danger: #000; --danger-soft: #fff;
    --tone-overdue-bg: #fff; --tone-overdue-text: #000; --tone-overdue-dot: #000;
    --tone-today-bg: #fff;   --tone-today-text: #000;   --tone-today-dot: #000;
    --tone-soon-bg: #fff;    --tone-soon-text: #000;    --tone-soon-dot: #000;
    --tone-week-bg: #fff;    --tone-week-text: #000;
    --tone-later-text: #000;
    --toast-bg: #fff; --toast-text: #000; --toast-action: #000;
    --focus: #000; --focus-ring: none;
    --shadow-sm: none; --shadow-md: none; --shadow-drag: none; --shadow-lg: none;
  }
  body { background: #fff; color: #000; }
  .topbar-actions, #quick-add-form, #filter-bar, #toasts, #shortcuts, #live, .grip, li.task > .edit, li.task > .delete, .add-date, #btn-archive-all, #done-toggle, #footer, #ladder::before, .ladder-hint { display: none !important; }
  li.task { background: #fff; box-shadow: none; border-color: #999; break-inside: avoid; grid-template-columns: 24px 12px minmax(0, 1fr) auto; }
  .check { width: 12px; height: 12px; border-radius: 2px; border: 1px solid #000; background: #fff; }
  .check .icon { display: none; }
  /* the variants are more specific than a bare .rank, so they have to be named here too:
     otherwise rung 1 prints as accent-coloured ink on an unprinted background */
  .rank, .rank.rank--1, .rank.rank--top, .rank.rank--done { background: #fff; color: #000; border: 1px solid #000; }
  .chip { border: 1px solid #999; background: #fff; color: #000; }
  main#app { padding: 0; max-width: none; }
}

/* ---------- 8. Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; scroll-behavior: auto !important; }
}
html[data-motion="none"] *, html[data-motion="none"] *::before, html[data-motion="none"] *::after {
  transition-duration: 0ms !important; animation-duration: 0ms !important; scroll-behavior: auto !important;
}
