:root {
  --bg: #f5f1e8;
  --surface: #fffdf8;
  --ink: #1f2a2e;
  --muted: #5b6669;
  --line: #ddd5c4;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe4;
  --warm: #a8532a;
  --warm-soft: #f6e3d6;
  --focus: #1b5fd1;
  --hover: rgba(47, 111, 94, .08);
  --shadow: 0 1px 2px rgba(31, 42, 46, .05), 0 4px 12px -4px rgba(31, 42, 46, .1);
  --radius: 20px;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --scale: 1;
  --track: 0;
  --leading: 1.5;
  font-size: calc(17px * var(--scale));
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151b1d;
    --surface: #1e2629;
    --ink: #ecebe6;
    --muted: #a3acad;
    --line: #34403f;
    --accent: #7cc4ad;
    --accent-ink: #0e1a17;
    --accent-soft: #23362f;
    --warm: #e39a6f;
    --warm-soft: #3a2a21;
    --focus: #8ab4ff;
    --hover: rgba(124, 196, 173, .1);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px -4px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

:root[data-contrast="high"] {
  --bg: #000;
  --surface: #000;
  --ink: #fff;
  --muted: #fff;
  --line: #fff;
  --accent: #ffe600;
  --accent-ink: #000;
  --accent-soft: #222;
  --warm: #ffe600;
  --warm-soft: #000;
  --focus: #00e5ff;
  --hover: #222;
  --shadow: none;
  color-scheme: dark;
}

:root[data-spacing="roomy"] { --track: .06em; --leading: 1.85; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: var(--leading);
  letter-spacing: var(--track);
  word-spacing: calc(var(--track) * 2);
  min-height: 100vh;
  caret-color: var(--accent);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: var(--accent-ink); }
* { scrollbar-color: var(--line) transparent; }

h1, h2 { line-height: 1.2; margin: 0 0 .5rem; text-wrap: balance; }
h1 { font-size: 2rem; letter-spacing: calc(var(--track) - .01em); }
h2 { font-size: 1.05rem; }
p { margin: 0 0 1rem; text-wrap: pretty; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 8px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); color: var(--ink); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: 8px; }

/* ---------- Header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  max-width: 42rem; margin: 0 auto; padding: 1.25rem 1rem 2rem;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.15rem; color: var(--accent); }
.brand span { color: var(--ink); }
.top-actions { display: flex; gap: .25rem; flex-wrap: wrap; }
.top-actions button { white-space: nowrap; }

main { max-width: 42rem; margin: 0 auto; padding: 0 1rem 5rem; outline: none; }

.screen { animation: rise .45s var(--ease) both; }
@keyframes rise { from { opacity: .4; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.lede { color: var(--muted); font-size: 1.05rem; max-width: 60ch; margin-bottom: 1.5rem; }
.hint { color: var(--muted); font-size: .88rem; }
.muted { color: var(--muted); }

/* ---------- Controls ---------- */
button {
  font: inherit; letter-spacing: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; text-align: center;
  border-radius: 999px; padding: .7rem 1.25rem; min-height: 46px;
  border: 1.5px solid transparent;
  transition: background-color .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease), transform .12s var(--ease), box-shadow .18s var(--ease);
}
button:active { transform: scale(.98); }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 3px 8px -3px rgba(0, 0, 0, .18); }
.primary:hover { filter: brightness(1.08); }
.secondary { background: var(--accent-soft); color: var(--ink); border-color: transparent; }
.secondary:hover { border-color: var(--accent); }
.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.ghost:hover { border-color: var(--accent); background: var(--hover); }
.quiet { background: transparent; color: var(--muted); padding: .5rem .85rem; min-height: 42px; }
.quiet:hover, .quiet[aria-expanded="true"] { color: var(--ink); background: var(--hover); }
.quiet[aria-expanded="true"] { color: var(--accent); }
.small { padding: .4rem 1rem; min-height: 40px; font-size: .92rem; }
.danger { color: var(--warm); }
.icon { background: transparent; color: var(--muted); border-color: var(--line); padding: 0; width: 46px; }
.icon:hover { color: var(--ink); border-color: var(--accent); background: var(--hover); }
kbd {
  font-family: inherit; font-size: .72em; font-weight: 400; line-height: 1;
  padding: .2rem .38rem; border-radius: 5px; margin-left: .15rem;
  border: 1px solid currentColor; opacity: .55;
}
@media (hover: none) { .actions kbd { display: none; } }

.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.row + .hint { margin-top: 1rem; }
.spacer { flex: 1; }

textarea, input[type="text"] {
  width: 100%; font: inherit; letter-spacing: inherit; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px;
  padding: .9rem 1rem; line-height: var(--leading);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
textarea::placeholder, input::placeholder { color: var(--muted); opacity: .8; }
textarea:focus, input[type="text"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--hover); }

/* ---------- Dump ---------- */
.dump-box { position: relative; margin-bottom: 1.25rem; }
#dump { resize: vertical; min-height: 13rem; padding-bottom: 2.4rem; display: block; box-shadow: var(--shadow); }
#dump:focus { box-shadow: 0 0 0 4px var(--hover), var(--shadow); }
.dump-count {
  position: absolute; right: 1rem; bottom: .7rem; margin: 0;
  font-size: .85rem; font-weight: 700; color: var(--accent); pointer-events: none;
}

/* ---------- Energy: segmented control ---------- */
.energy { border: 0; padding: 0; margin: 0 0 1.25rem; min-width: 0; }
.energy legend { font-weight: 700; margin-bottom: .6rem; padding: 0; }
.segmented {
  display: inline-flex; flex-wrap: wrap; gap: 4px;
  padding: 4px; border-radius: 26px; background: var(--surface); border: 1.5px solid var(--line);
  max-width: 100%;
}
.segmented label { position: relative; flex: 1 1 auto; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: flex; align-items: center; justify-content: center; white-space: nowrap;
  padding: .45rem 1.1rem; border-radius: 999px; min-height: 40px; color: var(--muted);
  transition: background-color .2s var(--ease), color .2s var(--ease);
}
.segmented label:hover span { color: var(--ink); background: var(--hover); }
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.segmented input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- The one card ---------- */
.card {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2rem 2rem 2.1rem; box-shadow: var(--shadow); margin-bottom: 1.25rem;
}
.card.swap { animation: swap .5s var(--ease) both; }
@keyframes swap { from { opacity: .35; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card-meta { padding-right: 3rem; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin-bottom: 1rem; min-height: 1.75rem; }
.badge {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .82rem; font-weight: 700; padding: .2rem .7rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--ink);
}
.badge.urgent { background: var(--warm-soft); color: var(--warm); }
:root[data-contrast="high"] .badge,
:root[data-contrast="high"] .secondary { border: 1.5px solid var(--accent); }
:root[data-contrast="high"] .primary { box-shadow: none; }
.part { font-size: .88rem; color: var(--muted); max-width: 36ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track { display: inline-flex; gap: 4px; }
.track i { width: 18px; height: 5px; border-radius: 3px; background: var(--line); }
.track i.done { background: var(--accent); }
.track i.now { background: var(--accent); opacity: .45; }

.step-text { font-size: 2.15rem; line-height: 1.15; margin-bottom: .6rem; overflow-wrap: anywhere; outline: none; max-width: 24ch; }
.why { color: var(--muted); margin-bottom: 1.75rem; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
#btn-read { position: absolute; top: 1.35rem; right: 1.35rem; width: 42px; min-height: 42px; }
.smaller { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px dashed var(--line); }
.smaller label { font-weight: 700; display: block; margin-bottom: .25rem; }

.timebar { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: var(--accent-soft); }
.timebar span { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: left; transition: transform 1s linear; }

/* ---------- Timer ---------- */
.timer { margin-bottom: 2.75rem; min-height: 46px; }
.chip-group { display: inline-flex; gap: .4rem; flex-wrap: wrap; }
.timer-btns { display: inline-flex; gap: .5rem; margin-left: auto; }
.chip { background: transparent; color: var(--ink); border-color: var(--line); padding: .4rem 1rem; min-height: 40px; }
.chip:hover { border-color: var(--accent); background: var(--hover); }
.clock { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }

/* ---------- Wins ---------- */
.wins h2 { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.pill { background: var(--accent-soft); color: var(--ink); border-radius: 999px; padding: 0 .55rem; font-size: .82rem; font-variant-numeric: tabular-nums; min-width: 1.6rem; text-align: center; }
#wins-list { list-style: none; padding: 0; color: var(--muted); margin: 0; display: grid; gap: .35rem; }
#wins-list li { display: flex; gap: .6rem; align-items: flex-start; }
#wins-list svg { flex: none; color: var(--accent); margin-top: .2em; }
#wins-list li.fresh { animation: win .7s var(--ease) both; }
@keyframes win { from { color: var(--accent); transform: translateX(-4px); } to { color: var(--muted); transform: none; } }
.wins-empty { color: var(--muted); font-size: .92rem; display: none; }
.wins.empty .wins-empty { display: block; }

/* ---------- All clear ---------- */
.clear { text-align: center; padding-top: 3rem; }
.clear .lede { margin-inline: auto; }
.summit { color: var(--accent); margin-bottom: 1rem; }

/* ---------- Panels & drawer ---------- */
.panel {
  max-width: calc(42rem - 2rem); margin: -1rem auto 2rem; padding: 1.25rem 1.5rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  width: calc(100% - 2rem); box-shadow: var(--shadow);
}
.settings-grid { display: grid; gap: .5rem 1.5rem; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); margin: .75rem 0 1rem; }
.switch, .range { display: flex; gap: .65rem; align-items: center; min-height: 44px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.range input { flex: 1; accent-color: var(--accent); }
.panel .hint { margin: 0; }

.scrim { position: fixed; inset: 0; background: rgba(15, 20, 22, .35); z-index: 4; animation: fade .25s var(--ease) both; }
@keyframes fade { from { opacity: 0; } }
.drawer {
  position: fixed; inset: 0 0 0 auto; width: min(440px, 100%);
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: -12px 0 40px -12px rgba(0,0,0,.25);
  padding: 1.25rem 1.5rem; overflow-y: auto; z-index: 5; animation: slide .35s var(--ease) both;
}
@keyframes slide { from { transform: translateX(24px); opacity: .5; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .25rem; }
.drawer-head h2 { margin: 0; font-size: 1.3rem; }
.all-list { list-style: none; padding: 0; margin: .5rem 0 1.75rem; }
.all-list li { border-bottom: 1px solid var(--line); padding: .75rem 0; display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center; }
.all-list .txt { flex: 1 1 11rem; min-width: 0; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.all-list .meta { font-size: .8rem; color: var(--muted); }
.all-list .ops { display: flex; flex-wrap: wrap; gap: .3rem; margin-left: auto; flex: 0 1 auto; min-width: 0; }
.all-list .ops button { padding: .3rem .85rem; min-height: 40px; font-size: .84rem; }
.all-list .sub { padding-left: 1.25rem; font-size: .95rem; }
.all-list .done-t { text-decoration: line-through; text-decoration-color: var(--line); color: var(--muted); }
.add label { font-weight: 700; display: block; margin-bottom: .4rem; }
.add textarea { margin-bottom: .6rem; }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
:root[data-motion="off"] *, :root[data-motion="off"] *::before, :root[data-motion="off"] *::after { animation: none !important; transition: none !important; }

@media (max-width: 560px) {
  .top { padding-bottom: 1.25rem; }
  .top-actions .quiet span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .top-actions .quiet { width: 44px; padding: 0; }
  h1 { font-size: 1.65rem; }
  .step-text { font-size: 1.7rem; }
  .card { padding: 1.5rem 1.25rem 1.6rem; }
  .actions button:not(.icon) { flex: 1 1 100%; min-width: 0; padding-inline: .9rem; }
  .actions kbd { display: none; }
  .card-meta[hidden] + .step-text { padding-right: 2.75rem; }
  #btn-read { top: 1rem; right: 1rem; }
  .segmented { display: flex; width: 100%; }
  .segmented span { padding: .45rem .75rem; }
  #timer-note { display: none; }
}

@media (max-width: 360px) {
  .card { padding: 1.25rem 1rem 1.4rem; }
  .panel { padding: 1rem; }
  .drawer { padding: 1rem; }
}
