/* Colours live here so light and dark mode only change one place. */
:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1c2321;
  --muted: #5d6865;
  --line: #dcdad2;
  --control: #76817d;  /* edges of boxes you can type or tap in */
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --accent-soft: #e0efe9;
  --warn: #9a5b00;
  --warn-soft: #fbeed3;
  --danger: #a3322b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131816;
    --card: #1d2422;
    --text: #edf1ef;
    --muted: #a3afab;
    --line: #313b38;
    --control: #8a9793;
    --accent: #58c2a6;
    --accent-text: #08201a;
    --accent-soft: #1d3a32;
    --warn: #f0b95a;
    --warn-soft: #3a2d12;
    --danger: #f08a82;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Leave room for the tab bar and the phone's home indicator. */
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

h1, h2, h3, p { margin: 0; }

.top {
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
}
.top h1 { font-size: 28px; }

main {
  padding: 4px 16px 16px;
  max-width: 640px;
  margin: 0 auto;
  outline: none;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { font-size: 20px; margin-bottom: 6px; }
.card h3 { font-size: 17px; }
.card p + p { margin-top: 8px; }

.eyebrow {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}
.muted { color: var(--muted); font-size: 15px; }

/* ---------- Buttons ---------- */
.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--control);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn.danger { color: var(--danger); }
.btn.small {
  display: inline-block;
  width: auto;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 15px;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Progress bar ---------- */
.bar {
  height: 10px;
  border-radius: 5px;
  background: var(--line);
  overflow: hidden;
  margin: 10px 0 6px;
}
.bar > div {
  height: 100%;
  background: var(--accent);
  border-radius: 5px;
}

/* ---------- Stages and lessons ---------- */
details.stage {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 12px;
  overflow: hidden;
}
details.stage > summary {
  list-style: none;
  padding: 14px 16px;
  cursor: pointer;
}
details.stage > summary::-webkit-details-marker { display: none; }
.stage-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.stage-head h3 { flex: 1; }
.count { font-size: 14px; color: var(--muted); white-space: nowrap; }

.lesson {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 16px;
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.lesson .tick {
  flex: none;
  width: 26px;
  height: 26px;
  border: 2px solid var(--control);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-text);
}
.lesson.done .tick {
  background: var(--accent);
  border-color: var(--accent);
}
.lesson.next .tick { border-color: var(--accent); }
.lesson .name { flex: 1; }
.lesson .num { color: var(--muted); font-size: 14px; }
.lesson.done .name { color: var(--muted); }

.tag {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
}
.tag.tricky { background: var(--warn-soft); color: var(--warn); }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; margin-top: 14px; }
textarea, input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--control);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;   /* 17px also stops iPhones zooming in on focus */
  resize: vertical;
}
.check {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  font-weight: 400;
}
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

.counter {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
  text-align: right;
}
.status { min-height: 22px; margin-top: 10px; font-size: 15px;
  color: var(--muted); }
.manual-copy { margin-bottom: 14px; }
.card.warn { background: var(--warn-soft); border-color: var(--warn); }
.warn-text { margin-top: 12px; color: var(--warn); font-weight: 600; }
.card:focus-visible { outline: 3px solid var(--accent);
  outline-offset: 2px; }

/* ---------- Notes ---------- */
.note dt {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 10px;
}
.note dd { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.note dl { margin: 0; }
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
ul.plain { margin: 8px 0 0; padding-left: 20px; }
ul.plain li { margin-bottom: 4px; }

/* ---------- Lesson pop-up ---------- */
dialog {
  width: min(100% - 24px, 560px);
  max-height: 88vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.sheet { padding: 20px 18px; }
.sheet h2 { font-size: 21px; margin-bottom: 8px; }

/* ---------- Bottom tabs ---------- */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1;
  min-height: 60px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.tabs button span { display: block; font-size: 18px; line-height: 1.2; }
.tabs button[aria-current="page"] { color: var(--accent); font-weight: 700; }

/* ---------- Little pop-up message ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 22px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
#toast.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}

/* Anything marked hidden stays hidden, even buttons. */
[hidden] { display: none !important; }
.tabs button:disabled { opacity: .4; cursor: default; }
.btn:disabled { opacity: .5; cursor: default; }

/* Test build only */
.test-banner {
  margin: 0;
  padding: calc(6px + env(safe-area-inset-top)) 16px 6px;
  background: var(--warn-soft);
  color: var(--warn);
  border-bottom: 1px solid var(--warn);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}
