/* Focus Ladder styles. Themes, text size, font and motion are controlled by
   data attributes on <html> so settings apply instantly and persist. */

:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1d1d1b;
  --muted: #5a5952;
  --line: #d8d4c8;
  --accent: #1f5f4f;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe4;
  --warn: #8a4b08;
  --warn-soft: #f7e7d1;
  --focus: #0b57d0;
  --done: #2b6f4f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.06);
  --base: 17px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --motion: 180ms;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1e2126;
  --surface-2: #262a30;
  --text: #f1f1ec;
  --muted: #b3b3aa;
  --line: #3a3f47;
  --accent: #6fcfae;
  --accent-ink: #0d1f19;
  --accent-soft: #1f3b32;
  --warn: #f2b56b;
  --warn-soft: #3a2a14;
  --focus: #8ab4f8;
  --done: #6fcfae;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

html[data-theme="contrast"] {
  --bg: #000000;
  --surface: #000000;
  --surface-2: #101010;
  --text: #ffffff;
  --muted: #ffffff;
  --line: #ffffff;
  --accent: #ffff00;
  --accent-ink: #000000;
  --accent-soft: #000000;
  --warn: #ffb000;
  --warn-soft: #000000;
  --focus: #00ffff;
  --done: #00ff66;
  --shadow: none;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #15171a;
    --surface: #1e2126;
    --surface-2: #262a30;
    --text: #f1f1ec;
    --muted: #b3b3aa;
    --line: #3a3f47;
    --accent: #6fcfae;
    --accent-ink: #0d1f19;
    --accent-soft: #1f3b32;
    --warn: #f2b56b;
    --warn-soft: #3a2a14;
    --focus: #8ab4f8;
    --done: #6fcfae;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

html[data-size="small"] { --base: 15px; }
html[data-size="medium"] { --base: 17px; }
html[data-size="large"] { --base: 20px; }
html[data-size="xlarge"] { --base: 24px; }

html[data-font="hyperlegible"] { --font: "Atkinson Hyperlegible", ui-sans-serif, system-ui, sans-serif; }
html[data-font="mono"] { --font: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

html[data-motion="off"] { --motion: 0ms; }
@media (prefers-reduced-motion: reduce) {
  html[data-motion="auto"] { --motion: 0ms; }
}

* { box-sizing: border-box; }

/* Author display rules must never defeat the hidden attribute. */
[hidden] { display: none !important; }

html { font-size: var(--base); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }

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

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  z-index: 100;
  font-weight: 600;
}
.skip-link:focus { top: 1rem; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}
.brand svg { width: 1.6em; height: 1.6em; }

nav.app-nav { display: flex; gap: 0.4rem; flex-wrap: wrap; }

main#main {
  flex: 1;
  width: 100%;
  max-width: 46rem;
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 2.5rem) clamp(1rem, 4vw, 2rem) 3rem;
}
main#main:focus { outline: none; }
/* Headings receive programmatic focus on view changes for screen readers;
   they are not interactive, so no ring. */
h1[tabindex="-1"]:focus { outline: none; }

footer.app-footer {
  padding: 1rem clamp(1rem, 4vw, 2.5rem);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  justify-content: space-between;
}

h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.2; margin: 0 0 0.5rem; }
h2 { font-size: 1.25rem; margin: 1.6rem 0 0.5rem; }
p.lede { color: var(--muted); margin: 0 0 1.4rem; font-size: 1.05rem; }

button, .button {
  font: inherit;
  font-weight: 600;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 0.65rem 1.1rem;
  border-radius: 10px;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  transition: background var(--motion), border-color var(--motion), transform var(--motion);
}
button:hover, .button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }
button[disabled] { opacity: 0.6; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-size: 1.05rem;
  padding: 0.8rem 1.4rem;
}
button.quiet { border-color: transparent; background: transparent; color: var(--muted); }
button.quiet:hover { color: var(--text); border-color: var(--line); }
button.danger { color: var(--warn); border-color: var(--warn); }

kbd {
  font: inherit;
  font-size: 0.78em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 0.4em;
  color: var(--muted);
  background: var(--surface-2);
}
html[data-theme="contrast"] kbd { color: var(--text); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1rem, 3vw, 1.6rem);
}

label, legend { font-weight: 600; display: block; margin-bottom: 0.35rem; }
.hint { color: var(--muted); font-size: 0.92rem; margin: 0.25rem 0 0; }

textarea, input[type="text"], input[type="password"], input[type="url"], select {
  font: inherit;
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
}
textarea { min-height: 9rem; resize: vertical; line-height: 1.5; }
textarea:focus, input:focus, select:focus { border-color: var(--focus); }

.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.8rem 0 1.2rem; }
.chips button { font-weight: 500; padding: 0.45rem 0.8rem; border-radius: 999px; min-height: 40px; }

.mode {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  margin-bottom: 1rem;
}
.mode .dot { width: 0.6em; height: 0.6em; border-radius: 50%; background: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.2rem; align-items: center; }

/* Ladder view */
.task { margin-top: 1.4rem; }
.task-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem 0.8rem; }
.task-head h2 { margin: 0; }
.badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line);
}
.badge.deadline { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.setup { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
html[data-theme="contrast"] .badge { color: var(--text); border-color: var(--line); }

ol.rungs { list-style: none; margin: 0.8rem 0 0; padding: 0; counter-reset: rung; }
ol.rungs li {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto;
  gap: 0.6rem;
  align-items: start;
  padding: 0.7rem 0.4rem;
  border-top: 1px solid var(--line);
}
ol.rungs li:first-child { border-top: 0; }
ol.rungs .num {
  counter-increment: rung;
  width: 2rem; height: 2rem;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid; place-items: center;
  font-weight: 700; font-size: 0.9rem;
  color: var(--muted);
}
ol.rungs .num::before { content: counter(rung); }
ol.rungs li.done .num { background: var(--done); border-color: var(--done); color: var(--accent-ink); }
ol.rungs li.done .num::before { content: "\2713"; }
ol.rungs li.skipped .num::before { content: "\2192"; }
ol.rungs li.done .text { text-decoration: line-through; color: var(--muted); }
ol.rungs .meta { color: var(--muted); font-size: 0.88rem; }

.add-rung { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
.add-rung input { flex: 1; }

/* Focus view */
.progress { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-weight: 600; margin-bottom: 0.8rem; }
.progress-bar { height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; margin-bottom: 1.4rem; }
.progress-bar > div { height: 100%; background: var(--accent); transition: width var(--motion); }

.rung-card { text-align: left; }
.rung-card .kind { margin-bottom: 0.8rem; display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.rung-card h1 { font-size: clamp(1.5rem, 4.5vw, 2.3rem); margin: 0 0 0.6rem; }
.rung-card .why { color: var(--muted); margin: 0; }
.rung-card .minutes { font-weight: 700; color: var(--accent); }
html[data-theme="contrast"] .rung-card .minutes { color: var(--text); }

.timer {
  margin-top: 1.2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.timer .time { font-variant-numeric: tabular-nums; font-size: 1.6rem; font-weight: 700; min-width: 4.5ch; }
.timer-bar { flex: 1 1 10rem; height: 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.timer-bar > div { height: 100%; background: var(--accent); transition: width 1s linear; }
html[data-motion="off"] .timer-bar > div { transition: none; }

.focus-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0.6rem; margin-top: 1.4rem; }
.focus-actions button { padding: 0.9rem 0.6rem; flex-direction: column; gap: 0.15rem; min-height: 64px; }
.focus-actions button small { font-weight: 500; color: inherit; opacity: 0.85; font-size: 0.8rem; }

details.peek { margin-top: 1.2rem; color: var(--muted); }
details.peek summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }

/* Done view */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: 0.8rem; margin: 1.2rem 0; }
.stats .card { text-align: center; padding: 1rem; }
.stats .big { font-size: 2rem; font-weight: 800; display: block; color: var(--accent); }
html[data-theme="contrast"] .stats .big { color: var(--text); }

/* Dialogs */
dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(92vw, 36rem);
  max-height: 90vh;
  overflow: hidden; /* only .dialog-body scrolls, so there is one scrollbar */
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog .dialog-body { padding: clamp(1rem, 3vw, 1.6rem); max-height: 90vh; overflow: auto; }
dialog .dialog-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.6rem; }
dialog h2 { margin: 0; }

fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 0.8rem 1rem 1rem; margin: 0 0 1rem; }
.radios { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.radios label {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-weight: 500; margin: 0;
  padding: 0.45rem 0.8rem; border: 2px solid var(--line); border-radius: 999px; min-height: 44px; cursor: pointer;
}
.radios input { margin: 0; width: 1.1rem; height: 1.1rem; }
.radios label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
html[data-theme="contrast"] .radios label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.check { display: flex; align-items: center; gap: 0.6rem; font-weight: 500; min-height: 44px; }
.check input { width: 1.2rem; height: 1.2rem; margin: 0; }

.field { margin-bottom: 0.9rem; }
.row { display: flex; gap: 0.5rem; align-items: end; }
.row > * { flex: 1; }
.row > button { flex: 0 0 auto; }

.notice { padding: 0.8rem 1rem; border-radius: 10px; background: var(--accent-soft); border: 1px solid transparent; margin: 0.8rem 0; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
html[data-theme="contrast"] .notice { border-color: var(--line); color: var(--text); }

.stuck-options { display: grid; gap: 0.6rem; margin-top: 0.8rem; }
.stuck-options button { justify-content: flex-start; text-align: left; font-weight: 500; padding: 0.9rem 1rem; }

.help h2 { margin-top: 1.4rem; }
.help ul { padding-left: 1.2rem; }
.help li { margin: 0.3rem 0; }

@media (max-width: 480px) {
  nav.app-nav button { padding: 0.5rem 0.7rem; }
  .focus-actions { grid-template-columns: 1fr 1fr; }
}
