:root {
  --sky: #dceff7;
  --mist: #f4f7f1;
  --paper: #ffffff;
  --ink: #22302a;
  --ink-soft: #55625a;
  --leaf: #2f6b3b;
  --leaf-light: #dfeedd;
  --soil: #5a3e2b;
  --marigold: #f2b01e;
  --marigold-deep: #d99a0b;
  --wrong: #b3261e;
  --wrong-bg: #fde3e1;
  --line: #d9e2d6;
  --focus: #1d5fd1;
  --passage-size: 34px;
  --ui: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, sans-serif;
  --mono: "Atkinson Hyperlegible Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
html[data-size="m"] { --passage-size: 30px; }
html[data-size="l"] { --passage-size: 36px; }
html[data-size="xl"] { --passage-size: 44px; }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--ui);
  font-size: 19px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--mist);
}
h1, h2 { line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: 40px; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 20px; font-weight: 600; }
p { margin: 0 0 .6em; }
.soft { color: var(--ink-soft); }
.unit { font-size: 17px; font-weight: 400; color: var(--ink-soft); }

/* ---- Screens -------------------------------------------------------- */
.screen { display: none; min-height: 100vh; }
body[data-screen="loading"] #screen-loading,
body[data-screen="nokey"] #screen-nokey,
body[data-screen="home"] #screen-home,
body[data-screen="practice"] #screen-practice,
body[data-screen="result"] #screen-result,
body[data-screen="words"] #screen-words,
body[data-screen="settings"] #screen-settings { display: block; }
.screen-center { display: none; padding: 48px 20px; }
body[data-screen="loading"] #screen-loading,
body[data-screen="nokey"] #screen-nokey,
body[data-screen="result"] #screen-result,
body[data-screen="words"] #screen-words,
body[data-screen="settings"] #screen-settings { display: grid; place-items: center; }

/* Practice, result, and settings screens sit on a soft, blurred copy of the garden. */
#screen-practice, #screen-result, #screen-words, #screen-settings, #screen-nokey {
  background:
    linear-gradient(rgba(244, 247, 241, .78), rgba(244, 247, 241, .9)),
    url("assets/garden/background-small.webp") center bottom / cover no-repeat;
}

.card {
  background: var(--paper);
  border-radius: 20px;
  padding: 36px 40px;
  box-shadow: 0 1px 2px rgba(34, 48, 42, .06), 0 12px 40px rgba(34, 48, 42, .1);
}
.card.narrow { width: min(560px, 100%); }
.card.wide { width: min(980px, 100%); }

/* ---- Buttons -------------------------------------------------------- */
.btn {
  font: inherit;
  font-weight: 600;
  min-height: 52px;
  padding: 12px 26px;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
}
.btn-primary { background: var(--marigold); color: #2a2104; font-size: 21px; }
.btn-primary:hover { background: var(--marigold-deep); }
.btn-quiet { background: transparent; color: var(--leaf); border-color: var(--line); }
.btn-quiet:hover { border-color: var(--leaf); }
.btn-link { background: none; border: none; color: var(--ink-soft); text-decoration: underline; min-height: 44px; padding: 8px 12px; }
.btn:focus-visible, textarea:focus-visible, input:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 20px; }

/* ---- Home: the garden ------------------------------------------------ */
.garden-wrap { position: relative; height: min(64vh, 640px); min-height: 360px; overflow: hidden; background: #8aa86f; }
.garden { position: absolute; inset: 0; }
.garden svg { width: 100%; height: 100%; display: block; }
.garden-heading {
  position: absolute; left: 0; right: 0; top: 0;
  padding: 26px 32px 60px;
  background: linear-gradient(rgba(20, 34, 22, .42), rgba(20, 34, 22, 0));
  color: #fff;
}
.garden-heading h1 { text-shadow: 0 1px 12px rgba(0, 0, 0, .35); margin-bottom: 4px; }
.plant-count { font-size: 19px; margin: 0; text-shadow: 0 1px 8px rgba(0, 0, 0, .4); }
.offline-badge {
  position: absolute; right: 20px; bottom: 16px; max-width: 360px;
  background: rgba(255, 255, 255, .92); border-radius: 12px; padding: 10px 14px; font-size: 16px; margin: 0;
}

/* Time of day: the same photo, different light. */
body[data-daypart="morning"] .garden svg { filter: saturate(1.04) brightness(1.03); }
body[data-daypart="evening"] .garden svg { filter: sepia(.28) saturate(1.2) hue-rotate(-12deg) brightness(.94); }
body[data-daypart="night"] .garden svg { filter: brightness(.62) saturate(.75) hue-rotate(8deg); }

.grow {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: grow 1100ms cubic-bezier(.2, .8, .25, 1) both;
}
@keyframes grow {
  from { transform: scale(.05, .05); opacity: 0; }
  60% { opacity: 1; }
  to { transform: scale(1, 1); opacity: 1; }
}

.dashboard {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 32px 48px;
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 18px 40px;
  align-items: start;
}
.road-top { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.road-number { font-size: 34px; font-weight: 800; margin: 0; }
.meter { position: relative; height: 22px; border-radius: 999px; background: var(--leaf-light); margin: 10px 0 30px; }
.meter-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #6aa84f, var(--leaf)); width: 0; transition: width 900ms ease; }
.meter-marks { position: absolute; left: 0; right: 0; top: 26px; font-size: 14px; color: var(--ink-soft); }
.meter-marks span { position: absolute; transform: translateX(-50%); }
.meter-marks span:last-child { transform: translateX(-100%); font-weight: 600; color: var(--leaf); }
.sparkline { width: 100%; height: 48px; display: block; }
.facts { display: grid; gap: 10px; }
.facts p { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin: 0; }
.fact-label { color: var(--ink-soft); }
.fact-value { font-weight: 800; font-size: 24px; }
.home-note { grid-column: 1 / -1; font-size: 21px; margin: 0; }
.dashboard .actions { grid-column: 1 / -1; margin-top: 4px; }

.welcome {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 20px;
  background: rgba(20, 34, 22, .35);
  backdrop-filter: blur(3px);
  z-index: 10;
}
.welcome[hidden] { display: none; }
.welcome-card { background: var(--paper); border-radius: 22px; padding: 40px 44px; text-align: center; width: min(520px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.welcome-card .btn { margin-top: 12px; }

/* ---- Practice ------------------------------------------------------- */
#screen-practice { padding: 24px 32px 40px; }
.practice-top { max-width: 1040px; margin: 0 auto 18px; display: flex; align-items: center; gap: 20px; }
.round-label { font-size: 21px; font-weight: 600; margin: 0; flex: 1; }
.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0; }
.steps li { width: 14px; height: 14px; border-radius: 50%; background: #b9c6b6; }
.steps li.done { background: var(--leaf); }
.steps li.now { background: var(--marigold); box-shadow: 0 0 0 4px rgba(242, 176, 30, .3); }

.passage-card {
  max-width: 1040px; margin: 0 auto; position: relative;
  background: var(--paper); border-radius: 20px; padding: 36px 44px;
  box-shadow: 0 1px 2px rgba(34, 48, 42, .06), 0 12px 40px rgba(34, 48, 42, .1);
}
.passage {
  font-family: var(--mono);
  font-size: var(--passage-size);
  line-height: 1.7;
  margin: 0;
  color: #8f9a92;
  word-break: normal;
}
.passage { position: relative; }
.passage.timed { max-height: calc(1.7em * 3); overflow: hidden; scroll-behavior: smooth; }
.passage .word { display: inline-block; white-space: pre; }
.passage .ch { position: relative; border-radius: 3px; }
.passage .ch.ok { color: var(--ink); }
.passage .ch.bad { color: var(--wrong); background: var(--wrong-bg); text-decoration: underline 3px; text-underline-offset: 6px; }
.passage .ch.sp.bad::after { content: "\00b7"; position: absolute; left: 0; right: 0; text-align: center; color: var(--wrong); }
.passage .ch.cur { box-shadow: inset 0 -4px 0 var(--marigold); color: var(--ink); background: rgba(242, 176, 30, .18); animation: caret 1.1s ease-in-out infinite; }
@keyframes caret { 50% { box-shadow: inset 0 -4px 0 rgba(242, 176, 30, .35); } }
.rep-toast { position: absolute; right: 28px; bottom: 14px; margin: 0; font-size: 19px; font-weight: 600; color: var(--leaf); }
.caps-hint { max-width: 1040px; margin: 14px auto 0; background: #fff4d6; border-radius: 12px; padding: 10px 16px; font-weight: 600; }

.keyboard { max-width: 860px; margin: 28px auto 0; display: grid; gap: 7px; user-select: none; }
.keyboard[hidden] { display: none; }
.kb-row { display: flex; gap: 7px; justify-content: center; }
.kb-key {
  flex: 1 1 0; min-width: 0; height: 50px; display: grid; place-items: center;
  border-radius: 9px; background: rgba(255, 255, 255, .85); border: 1px solid var(--line);
  font-size: 18px; color: var(--ink-soft);
  transition: background 120ms, transform 120ms;
}
.kb-backspace, .kb-tab, .kb-caps, .kb-enter { flex-grow: 1.6; font-size: 14px; }
.kb-shiftl, .kb-shiftr { flex-grow: 2.2; font-size: 14px; }
.kb-space { flex: 0 1 46%; }
.kb-home { box-shadow: inset 0 -3px 0 var(--line); }
.kb-next { background: var(--marigold); color: #2a2104; border-color: var(--marigold-deep); font-weight: 800; transform: translateY(-1px); }

.timer { max-width: 1040px; margin: 0 auto 14px; display: flex; align-items: center; gap: 14px; }
.timer[hidden] { display: none; }
.timer-track { flex: 1; height: 10px; border-radius: 999px; background: rgba(47, 107, 59, .15); overflow: hidden; }
.timer-fill { height: 100%; width: 100%; background: var(--leaf); border-radius: 999px; transition: width 100ms linear; }
.timer-text { margin: 0; min-width: 160px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 20px 0 8px; }
.choices .btn { width: 100%; }

/* ---- Result --------------------------------------------------------- */
.result-card {
  width: min(980px, 100%);
  display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 36px; align-items: center;
  background: var(--paper); border-radius: 22px; padding: 32px 40px;
  box-shadow: 0 1px 2px rgba(34, 48, 42, .06), 0 12px 40px rgba(34, 48, 42, .1);
}
.result-plant {
  height: 380px; border-radius: 16px; overflow: hidden; position: relative;
  background: url("assets/garden/background-small.webp") 50% 92% / 260% auto no-repeat;
  display: grid; align-items: end; justify-items: center;
}
.result-plant .plant-photo { height: 82%; width: auto; max-width: 90%; object-fit: contain; margin-bottom: 6%; animation: grow 1100ms cubic-bezier(.2, .8, .25, 1) both; transform-origin: 50% 100%; }
.result-plant .name-badge { align-self: center; font-size: 64px; font-weight: 800; color: #fff; text-shadow: 0 2px 16px rgba(0, 0, 0, .45); }
.result-kicker { font-size: 19px; font-weight: 600; color: var(--leaf); margin-bottom: 4px; }
.result-big { font-size: 64px; font-weight: 800; line-height: 1.05; margin-bottom: 6px; }
.result-acc { font-size: 21px; color: var(--ink-soft); }
.result-note { font-size: 23px; margin-top: 10px; }

/* ---- Words & settings ----------------------------------------------- */
.two-col { display: grid; grid-template-columns: 1fr 1.6fr; gap: 20px; margin-top: 16px; }
.two-col label { display: grid; gap: 8px; font-weight: 600; }
textarea {
  font: 18px/1.5 var(--ui); color: var(--ink);
  border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; resize: vertical; width: 100%;
}
.toggle { display: flex; align-items: center; gap: 14px; font-size: 21px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle input, .sizes input { width: 26px; height: 26px; accent-color: var(--leaf); }
.sizes { border: none; padding: 16px 0 0; margin: 0; display: flex; gap: 22px; flex-wrap: wrap; }
.sizes legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.sizes label { display: flex; gap: 8px; align-items: center; font-size: 19px; cursor: pointer; }

@media (max-width: 860px) {
  .dashboard { grid-template-columns: 1fr; padding: 22px 16px 40px; }
  .result-card { grid-template-columns: 1fr; padding: 24px 18px; }
  .result-plant { height: 280px; }
  .two-col { grid-template-columns: 1fr; }
  #screen-practice { padding: 16px; }
  .passage-card { padding: 24px 20px; }
  .card { padding: 28px 22px; }
  h1 { font-size: 32px; }
  .garden-heading { padding: 18px 16px 50px; }
}

@media (prefers-reduced-motion: reduce) {
  .grow, .result-plant .plant-photo { animation: none; }
  .passage .ch.cur { animation: none; }
  .meter-fill { transition: none; }
}
