:root {
  color-scheme: light dark;
  --page: light-dark(#f5f2e9, #191d1b);
  --surface: light-dark(#fffdf8, #252b28);
  --surface-soft: light-dark(#f8f4e9, #303733);
  --text: light-dark(#20262d, #f4f1e8);
  --muted: light-dark(#66707a, #b7c3bd);
  --border: light-dark(#d8d1c3, #4a534e);
  --blue: light-dark(#38689e, #8ab7e8);
  --blue-text: light-dark(#ffffff, #14202c);
  --green: light-dark(#34765d, #8fd2b2);
  --error: light-dark(#a23535, #ff9b9b);
  --ball: #ffb36b;
  --ball-edge: #c96c2c;
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, sans-serif;
  color: var(--text);
  background: var(--page);
}

* { box-sizing: border-box; }
body { min-width: 320px; margin: 0; background: var(--page); }
button, input { font: inherit; }
button { touch-action: manipulation; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.app { min-height: 100vh; }
.topbar { position: relative; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px clamp(16px,4vw,36px); border-bottom: 1px solid var(--border); background: var(--surface); }
.brand, .settings { appearance: none; border: 0; background: transparent; cursor: pointer; }
.brand { color: var(--text); padding: 7px 0; font-size: 20px; font-weight: 500; }
.settings { min-height: 44px; border-radius: 10px; color: var(--blue); padding: 8px 10px; font-weight: 500; }
.settings:hover { background: color-mix(in srgb, var(--blue) 9%, transparent); }

.progress { display: grid; grid-template-columns: repeat(2,1fr); gap: 7px; padding: 12px clamp(16px,4vw,36px) 0; }
.progress span { height: 5px; border-radius: 999px; background: color-mix(in srgb, var(--border) 76%, transparent); }
.progress span.active { background: var(--blue); }
.app[data-screen="exercise"] .progress { visibility: hidden; }

main { padding: clamp(24px,4vw,46px) clamp(12px,5vw,48px) 36px; }
.screen { max-width: 820px; margin: 0 auto; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; text-align: center; font-size: clamp(27px,4.4vw,38px); font-weight: 500; }
.lead { max-width: 620px; margin: 0 auto 26px; color: var(--muted); text-align: center; }
.panel { border: 1px solid var(--border); border-radius: 20px; background: var(--surface); padding: clamp(18px,4vw,29px); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.panel h2 { margin: 0; font-size: 21px; font-weight: 500; }
.panel-tools { display: flex; align-items: center; justify-content: flex-end; gap: 14px; flex-wrap: wrap; }
.count { color: var(--green); font-size: 14px; font-weight: 500; white-space: nowrap; }
.text-action { appearance: none; border: 0; background: transparent; color: var(--blue); padding: 6px 0; cursor: pointer; font-size: 14px; font-weight: 500; }
.section-label { margin: 18px 0 4px; font-size: 14px; font-weight: 500; }
.section-label.first { margin-top: 0; }
.note { margin: 0 0 11px; color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { appearance: none; min-width: 50px; min-height: 44px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-soft); color: var(--text); padding: 7px 12px; cursor: pointer; font-size: 18px; font-weight: 500; }
.chip[aria-pressed="true"] { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 14%, var(--surface)); color: var(--blue); }
.chip[aria-pressed="true"]::before { content: "✓ "; font-size: 13px; }
.custom-chip { display: inline-flex; align-items: center; gap: 2px; }
.remove-chip { appearance: none; width: 42px; height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; font-size: 20px; }

.suggestions { margin-top: 18px; border-block: 1px solid var(--border); padding: 13px 0; }
.suggestions summary { color: var(--blue); cursor: pointer; font-weight: 500; }
.suggestions-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.suggestions-head .note { margin: 0; }
.suggestions .chips { margin-top: 10px; }
.add-row { display: grid; grid-template-columns: 1fr auto; gap: 9px; }
.add-row input { min-width: 0; min-height: 48px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); color: var(--text); padding: 10px 13px; font-size: 16px; }
.add-row input[aria-invalid="true"] { border-color: var(--error); }
.message { min-height: 21px; margin: 6px 0 4px; color: var(--error); font-size: 13px; }
.message.note-message { color: var(--green); }

.actions { display: flex; align-items: center; gap: 12px; margin-top: 20px; }
.actions.end { justify-content: flex-end; }
.actions.centered { justify-content: center; }
.button { appearance: none; min-height: 48px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 10px 18px; cursor: pointer; font-weight: 500; }
.button.primary { border-color: var(--blue); background: var(--blue); color: var(--blue-text); }
.button.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.button:disabled { opacity: .5; cursor: not-allowed; }

.options { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; }
.options.two { grid-template-columns: repeat(2,1fr); }
.option { appearance: none; min-height: 76px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-soft); color: var(--text); padding: 10px; cursor: pointer; }
.option[aria-pressed="true"] { border: 2px solid var(--blue); background: color-mix(in srgb, var(--blue) 12%, var(--surface)); }
.option strong { display: block; font-size: 24px; font-weight: 500; }
.option span { color: var(--muted); font-size: 13px; }
.combination-count { margin: 20px 0 0; color: var(--muted); text-align: center; font-size: 14px; }
.word-mode-note { margin-top: 9px; }

.app[data-screen="exercise"] main { padding-top: clamp(18px,2.2vw,30px); }
.exercise { width: 100%; max-width: 1280px; }
.stage { position: relative; height: clamp(400px,min(42vw,calc(100vh - 250px)),590px); overflow: hidden; border-radius: 24px; background: linear-gradient(180deg,#88d8f5 0,#e8f8ff 73%,#91d66e 73%,#60ac4d 100%); }
.stage::after { content: ""; position: absolute; z-index: 1; inset: 73% 0 0; opacity: .4; background: repeating-linear-gradient(82deg,transparent 0 10px,#4a9d43 11px 13px,transparent 14px 25px); }
.sun { position: absolute; z-index: 1; top: 6.5%; left: 23%; width: clamp(74px,7.4%,96px); height: auto; aspect-ratio: 1; border-radius: 50%; background: #ffdd62; box-shadow: 0 0 0 clamp(12px,1.05vw,17px) #ffdd623d; }
.cloud { position: absolute; z-index: 1; top: 12.8%; left: 34%; width: clamp(104px,10.7%,138px); height: auto; aspect-ratio: 92 / 34; border-radius: 50%; background: #fff; }
.cloud::before, .cloud::after { content: ""; position: absolute; border-radius: 50%; background: #fff; }
.cloud::before { width: 46%; aspect-ratio: 1; left: 13%; top: -59%; }
.cloud::after { width: 57%; aspect-ratio: 1; right: 9%; top: -82%; }
.tree { position: absolute; z-index: 1; left: 7%; bottom: 12.5%; width: clamp(58px,5.8%,76px); height: auto; aspect-ratio: 38 / 105; border-radius: 34% 34% 10% 10%; background: #96633b; }
.tree::before, .tree::after { content: ""; position: absolute; border-radius: 48% 52% 46% 54%; }
.tree::before { z-index: -1; width: 250%; aspect-ratio: 1.25; left: -105%; top: -62%; background: #55a958; }
.tree::after { z-index: -2; width: 220%; aspect-ratio: 1.18; left: 12%; top: -82%; background: #65b965; }
.stage canvas { position: absolute; z-index: 3; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.syllable-ball { position: absolute; z-index: 7; width: clamp(102px,8.2vw,124px); aspect-ratio: 1; display: grid; place-items: center; opacity: 0; color: #25312b; font-size: clamp(42px,3.4vw,52px); font-weight: 500; }
.syllable-ball::before { content: ""; position: absolute; inset: 0; z-index: -1; border: 4px solid var(--ball-edge); border-radius: 50%; background: var(--ball); box-shadow: inset -11px -11px 0 #c96c2c38,7px 9px 0 #26332d20; }
.syllable-ball.ready, .syllable-ball.landed { opacity: 1; }
.syllable-ball.landed { top: auto; bottom: 24px; }
.syllable-ball.waiting { visibility: hidden; }
.syllable-ball.unused { display: none; }
.syllable-ball.long { font-size: clamp(30px,2.6vw,40px); }
.exercise-controls { display: flex; flex-direction: column; align-items: center; gap: 15px; padding-top: 18px; }
.hint { margin: 0; color: var(--muted); text-align: center; font-size: clamp(17px,1.6vw,21px); }
.next { appearance: none; min-width: 72px; height: 72px; border: 0; border-radius: 999px; background: var(--green); color: light-dark(#fff,#15221a); cursor: pointer; font-size: 38px; box-shadow: 0 6px 0 light-dark(#24553e,#3f7052); }
.next.round-button { min-width: 168px; height: 50px; padding: 0 18px; font-size: 16px; font-weight: 500; }

@media (max-width: 680px) {
  .topbar { padding: 13px 14px; }
  main { padding: 24px 12px; }
  .panel-head { flex-direction: column; }
  .panel-tools { justify-content: flex-start; }
  .options { grid-template-columns: 1fr; }
  .options.two { grid-template-columns: 1fr; }
  .add-row { grid-template-columns: 1fr; }
  .add-row .button { width: 100%; }
  .stage { height: 360px; min-height: 0; border-radius: 20px; }
  .syllable-ball { width: 76px; height: 76px; font-size: 29px; }
  .syllable-ball.long { font-size: 23px; }
  .hint { font-size: 16px; }
  .next { min-width: 58px; height: 58px; font-size: 31px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}

.selection > .panel + .panel { margin-top: 20px; }
