:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --paper-deep: #eee8dc;
  --ink: #22201d;
  --muted: #746f67;
  --line: #dcd4c6;
  --accent: #6d4aff;
  --accent-rgb: 109, 74, 255;
  --accent-dark: #5231d7;
  --accent-soft: #ece7ff;
  --green: #278b64;
  --green-soft: #e2f4eb;
  --red: #c24f54;
  --red-soft: #fae7e7;
  --gold: #9a6100;
  --gold-soft: #fff0d0;
  --white: #fffdf8;
  --shadow: 0 24px 60px rgba(67, 54, 33, 0.1);
  --radius: 28px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 9% 8%, rgba(var(--accent-rgb), 0.09), transparent 26rem),
    radial-gradient(circle at 92% 88%, rgba(236, 171, 90, 0.12), transparent 28rem),
    var(--paper);
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", Avenir, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, select, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100% - 32px, 920px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 0 max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.app-header, .header-controls, .status-row, footer, .card-actions, .card-sound, .auto-next-control {
  display: flex;
  align-items: center;
}

.app-header { justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.header-controls { gap: 12px; }

.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 15px; color: white; background: var(--accent);
  box-shadow: 0 9px 20px rgba(var(--accent-rgb), .28);
  font: 700 25px/1 Georgia, serif; transform: rotate(-3deg);
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 19px; letter-spacing: -.02em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }

.lesson-picker { display: grid; gap: 5px; }
.lesson-picker span { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.lesson-picker select {
  min-width: 148px; padding: 9px 34px 9px 12px; border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); background: rgba(255, 253, 248, .75); font-weight: 650;
}

.language-toggle { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper-deep); }
.language-toggle button {
  width: 36px; height: 34px; padding: 0; border: 0; border-radius: 9px; color: var(--muted); background: transparent;
  font-size: 12px; font-weight: 850; cursor: pointer;
}
.language-toggle button.is-active { color: var(--accent-dark); background: var(--white); box-shadow: 0 2px 8px rgba(60, 50, 35, .1); }

main { width: min(100%, 760px); margin: auto; }

.mode-tabs {
  width: fit-content; margin: 0 auto 18px; padding: 5px; display: flex; gap: 4px;
  border: 1px solid var(--line); border-radius: 16px; background: rgba(238, 232, 220, .72);
}
.mode-tab {
  padding: 10px 15px; border: 0; border-radius: 11px; color: var(--muted); background: transparent;
  font-size: 14px; font-weight: 750; cursor: pointer;
}
.mode-tab span { margin-right: 5px; }
.mode-tab b, .primary-button b { font: inherit; }
.mode-tab.is-active { color: var(--accent-dark); background: var(--white); box-shadow: 0 3px 12px rgba(60, 50, 35, .08); }

.practice-view {
  min-height: 555px; padding: clamp(24px, 5vw, 46px); border: 1px solid rgba(220, 212, 198, .9);
  border-radius: var(--radius); background: rgba(255, 253, 248, .88); box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}
.practice-view.is-hidden, .is-hidden { display: none !important; }

.direction-picker {
  width: fit-content; margin: -18px 0 28px; padding: 4px; display: flex; gap: 4px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--paper-deep);
}
.direction-picker button {
  min-height: 40px; padding: 8px 12px; display: flex; align-items: center; gap: 5px;
  border: 0; border-radius: 10px; color: var(--muted); background: transparent;
  font-size: 12px; font-weight: 800; cursor: pointer;
}
.direction-picker button b { margin-left: 3px; font: inherit; }
.direction-picker button.is-active { color: var(--accent-dark); background: var(--white); box-shadow: 0 2px 8px rgba(60, 50, 35, .1); }
.direction-arrow { color: var(--accent); }

.status-row { justify-content: space-between; gap: 18px; }
.eyebrow { margin: 0 0 5px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
h1 { margin: 0; font: 600 clamp(24px, 5vw, 34px)/1.12 Georgia, "Times New Roman", serif; letter-spacing: -.025em; }

.game-stats { flex: none; display: grid; grid-template-columns: repeat(4, minmax(58px, 1fr)); gap: 7px; }
.score-pill, .counter-pill {
  flex: none; min-width: 66px; padding: 9px 10px; border-radius: 14px; text-align: center; background: var(--accent-soft); color: var(--accent-dark);
}
.score-pill span, .score-pill small { display: block; }
.score-pill span { font-size: 22px; font-weight: 850; line-height: 1; }
.score-pill small { margin-top: 3px; font-size: 10px; font-weight: 750; text-transform: uppercase; }
.counter-pill { min-width: auto; font-size: 13px; font-weight: 750; }
.streak-pill { transition: color .2s ease, background .2s ease, transform .2s ease; }
.streak-pill.is-hot { color: var(--gold); background: var(--gold-soft); transform: translateY(-2px); }
.lives-pill { color: var(--red); background: var(--red-soft); }
.lives-pill.is-low { box-shadow: inset 0 0 0 1px var(--red); }
.high-score-pill { color: var(--ink); background: var(--paper-deep); }

.sound-stage { position: relative; min-height: 190px; display: grid; place-content: center; justify-items: center; }
.sound-stage p { margin: 13px 0 0; color: var(--muted); font-size: 13px; font-weight: 650; }
.play-orbit { position: relative; width: 142px; height: 142px; display: grid; place-items: center; }
.sound-rings { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.sound-rings i { position: absolute; border: 1px solid rgba(var(--accent-rgb), .13); border-radius: 50%; }
.sound-rings i:nth-child(1) { width: 96px; height: 96px; background: var(--accent-soft); border: 0; }
.sound-rings i:nth-child(2) { width: 132px; height: 132px; }
.sound-rings i:nth-child(3) { width: 168px; height: 168px; opacity: .55; }

.play-button {
  position: relative; z-index: 1; width: 70px; height: 70px; display: grid; place-items: center; border: 0; border-radius: 50%;
  color: white; background: var(--accent); box-shadow: 0 12px 25px rgba(var(--accent-rgb), .34); cursor: pointer;
  transition: transform .16s ease, background .16s ease;
}
.play-button:hover { background: var(--accent-dark); transform: scale(1.04); }
.play-button:active { transform: scale(.96); }
.play-button svg { width: 29px; height: 29px; margin-left: 3px; fill: currentColor; }
.play-button.is-playing { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 12px 35px rgba(var(--accent-rgb), .58); transform: scale(1.04); } }
.speed-button {
  position: relative; z-index: 2; min-width: 46px; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 11px;
  color: var(--muted); background: var(--white); font-size: 12px; font-weight: 850; cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background .15s ease, transform .15s ease;
}
.speed-button:hover { border-color: var(--accent); color: var(--accent-dark); transform: translateY(-1px); }
.speed-button.is-active { border-color: var(--accent); color: white; background: var(--accent); }
.play-orbit .speed-button { position: absolute; top: calc(50% - 17px); left: calc(50% + 54px); }

.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.choice-button {
  min-height: 58px; padding: 12px 15px; border: 1px solid var(--line); border-radius: 15px;
  color: var(--ink); background: var(--white); text-align: left; line-height: 1.25; font-weight: 700; cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.choice-button:hover:not(:disabled) { border-color: var(--accent); background: #faf8ff; transform: translateY(-1px); }
.choice-button:disabled { cursor: default; opacity: .72; }
.choice-button.is-correct { border-color: var(--green); color: #176c4b; background: var(--green-soft); opacity: 1; }
.choice-button.is-wrong { border-color: var(--red); color: #9e373c; background: var(--red-soft); opacity: 1; }

.feedback { min-height: 47px; padding: 11px 2px 0; color: var(--muted); font-size: 14px; }
.feedback strong { color: var(--ink); }
.feedback .correct-copy { color: var(--green); }
.feedback .wrong-copy { color: var(--red); }
.score-details, .round-summary { display: block; margin-top: 5px; }
.score-details { color: var(--accent-dark); font-size: 12px; }
.round-summary { padding: 8px 10px; border-radius: 10px; color: var(--ink); background: var(--gold-soft); }

.primary-button, .secondary-button {
  min-height: 49px; padding: 12px 18px; border-radius: 14px; font-weight: 800; cursor: pointer;
}
.primary-button { width: 100%; border: 0; color: white; background: var(--ink); }
.primary-button:hover { background: #3b3834; }
.primary-button span { float: right; }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: var(--white); }

.cards-heading { margin-bottom: 24px; }
.flashcard {
  min-height: 310px; padding: 22px; display: grid; grid-template-rows: auto 1fr; border: 1px solid var(--line);
  border-radius: 22px; background: linear-gradient(145deg, #fffdf8, #f2ede4); overflow: hidden;
}
.card-sound { gap: 10px; color: var(--muted); font-size: 12px; font-weight: 700; }
.card-sound .speed-button { margin-left: auto; }
.play-button-small { width: 43px; height: 43px; box-shadow: 0 8px 17px rgba(var(--accent-rgb), .25); }
.play-button-small svg { width: 20px; height: 20px; }
.card-hidden, .card-answer { align-self: center; text-align: center; }
.question-mark {
  width: 72px; height: 72px; margin: auto; display: grid; place-items: center; border-radius: 24px;
  color: var(--accent); background: var(--accent-soft); font: 700 40px/1 Georgia, serif; transform: rotate(2deg);
}
.card-hidden p { color: var(--muted); font-size: 14px; }
.card-answer #card-target { margin: 0; font: 600 clamp(30px, 7vw, 46px)/1.1 Georgia, serif; }
.card-answer #card-dutch { margin: 0; color: var(--muted); font-size: 17px; font-weight: 650; }
.divider { width: 36px; height: 2px; margin: 20px auto; display: block; background: var(--accent); }
.card-actions { gap: 10px; margin-top: 14px; }
.card-actions > * { flex: 1; }

.auto-next-control {
  gap: 12px; margin-top: 22px; padding: 15px 17px; border-radius: 16px; background: var(--paper-deep); cursor: pointer;
}
.auto-next-control input { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; flex: none; width: 44px; height: 25px; border-radius: 99px; background: #c9c0b2; transition: background .2s ease; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px; border-radius: 50%; background: white; transition: transform .2s ease; }
.auto-next-control input:checked + .switch { background: var(--accent); }
.auto-next-control input:checked + .switch::after { transform: translateX(19px); }
.auto-next-control strong, .auto-next-control small { display: block; }
.auto-next-control strong { font-size: 13px; }
.auto-next-control small { margin-top: 2px; color: var(--muted); font-size: 11px; }

footer { justify-content: space-between; gap: 20px; padding: 20px 8px 0; color: var(--muted); font-size: 11px; }
.toast {
  position: fixed; z-index: 10; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); width: min(calc(100% - 32px), 480px);
  padding: 13px 16px; border-radius: 13px; color: white; background: #332f2c; box-shadow: 0 12px 30px rgba(0,0,0,.2);
  font-size: 13px; text-align: center; transform: translate(-50%, 150%); transition: transform .25s ease;
}
.toast.is-visible { transform: translate(-50%, 0); }

:focus-visible { outline: 3px solid rgba(var(--accent-rgb), .35); outline-offset: 3px; }

@media (max-width: 600px) {
  .app-shell { width: min(100% - 20px, 920px); padding-top: max(15px, env(safe-area-inset-top)); }
  .app-header { flex-wrap: wrap; margin-bottom: 18px; }
  .brand small, .lesson-picker span { display: none; }
  .header-controls { width: 100%; gap: 7px; }
  .lesson-picker { min-width: 0; flex: 1; }
  .lesson-picker select { width: 100%; min-width: 0; }
  .mode-tabs { width: 100%; }
  .mode-tab { flex: 1; padding-inline: 8px; font-size: 13px; }
  .practice-view { min-height: 0; padding: 23px 18px; border-radius: 23px; }
  .direction-picker { width: 100%; margin: -7px 0 23px; }
  .direction-picker button { flex: 1; justify-content: center; }
  .direction-picker button b { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .status-row { align-items: flex-start; flex-wrap: wrap; }
  .game-stats { width: 100%; }
  .sound-stage { min-height: 178px; }
  .choice-grid { grid-template-columns: 1fr; gap: 9px; }
  .choice-button { min-height: 53px; }
  .flashcard { min-height: 290px; }
  .card-actions { display: grid; grid-template-columns: 1fr; }
  footer { padding-bottom: 4px; }
  footer span:last-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Written recall: a score and progress trail around the answer, without a timer. */
.mode-tabs { max-width: 100%; }
.mode-tab { min-width: 0; }
.written-help { color: var(--muted); line-height: 1.55; font-size: 1rem; }
.written-scoreboard { display: grid; grid-template-columns: 1fr 1.2fr .7fr; gap: 12px; margin: 24px 0 18px; }
.written-scoreboard > div { padding: 14px 8px; border-radius: 15px; background: var(--accent-soft); text-align: center; }
.written-scoreboard strong { display: block; color: var(--accent-dark); font-size: clamp(1.25rem, 4vw, 1.8rem); font-variant-numeric: tabular-nums; }
.written-scoreboard span { display: block; margin-top: 4px; font-size: .875rem; }
.written-progress-label, .written-directions, .written-word-progress { font-size: .875rem; line-height: 1.5; }
#written-progress { width: 100%; height: 15px; margin: 9px 0 4px; accent-color: var(--accent); }
.written-directions { color: var(--muted); margin-bottom: 25px; }
.written-prompt { margin: 12px 0; font-size: clamp(1.65rem, 5vw, 2.3rem); font-weight: 750; line-height: 1.3; overflow-wrap: anywhere; }
.written-word-progress { color: var(--accent-dark); font-weight: 650; }
#written-form label { display: block; margin: 20px 0 8px; font-size: 1rem; font-weight: 650; }
#written-answer { width: 100%; min-height: 54px; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; background: var(--white); color: var(--ink); font-size: 1.125rem; }
#written-answer:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
#written-answer[readonly] { background: var(--paper-deep); }
.written-accents { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.written-accents button { min-width: 38px; min-height: 40px; border: 1px solid var(--line); border-radius: 9px; background: var(--white); color: var(--ink); font-size: 1rem; cursor: pointer; }
.written-note { color: var(--muted); font-size: .875rem; line-height: 1.5; }
.written-actions { display: flex; gap: 10px; }
.written-actions .primary-button { flex: 1; width: auto; }
.written-actions .secondary-button { flex: 1; }
#written-view button:disabled { opacity: .5; cursor: default; }
.written-feedback { margin: 16px 0; line-height: 1.5; border-radius: 14px; font-size: 1rem; }
.written-feedback:empty { margin: 0; }
.written-feedback:not(:empty) { padding: 16px; }
.written-feedback.is-correct { color: #176c4b; background: var(--green-soft); }
.written-feedback.is-wrong { color: #9e373c; background: var(--red-soft); }
.written-feedback > * { display: block; }
.written-feedback > span { margin-top: 6px; }
.written-reward { font-size: .875rem; font-weight: 700; }
.written-complete { text-align: center; padding: 24px 10px; color: #176c4b; }
.written-trophy { display: block; font-size: 3.5rem; }
.written-overview { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 18px; }
.written-overview summary { cursor: pointer; font-weight: 700; }
.written-table-wrap { overflow-x: auto; }
.written-overview table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: .875rem; }
.written-overview th, .written-overview td { padding: 12px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.written-overview td { white-space: nowrap; font-variant-numeric: tabular-nums; }
.written-overview th { font-weight: 650; }
.written-overview small { display: block; margin-top: 4px; font-size: .875rem; color: var(--muted); font-weight: 400; }
.written-overview .is-mastered { color: #176c4b; font-weight: 750; }
.written-reset { margin-top: 20px; padding: 10px 0; border: 0; background: none; color: var(--muted); text-decoration: underline; font-size: .875rem; cursor: pointer; }
@keyframes written-flash { 0%, 100% { box-shadow: var(--shadow); } 45% { box-shadow: 0 0 0 5px var(--green-soft), 0 0 30px rgba(39,139,100,.3); } }
@keyframes written-pop { 0% { transform: translateY(5px) scale(.96); } 55% { transform: translateY(-3px) scale(1.04); } 100% { transform: none; } }
@keyframes written-gold { 0%, 100% { box-shadow: var(--shadow); } 45% { box-shadow: 0 0 0 6px var(--gold-soft), 0 0 36px rgba(154,97,0,.25); } }
.celebrate-correct { animation: written-flash .65s ease-out; }
.celebrate-word { animation: written-gold .85s ease-out; }
.celebrate-correct .written-reward, .celebrate-word .written-reward { animation: written-pop .45s ease-out; }
@media (max-width: 600px) {
  .mode-tab { font-size: .875rem; padding-inline: 6px; }
  .mode-tab span { display: block; margin: 0 0 3px; }
  .written-scoreboard { gap: 6px; }
  .written-actions { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  .celebrate-correct, .celebrate-word, .celebrate-correct .written-reward, .celebrate-word .written-reward { animation: none; }
}

/* Text quiz prompt and example-sentence hints */
.prompt-row { display: flex; align-items: center; gap: 12px; }
.prompt-row > p { flex: 1; min-width: 0; }
.quiz-word { margin: 22px 0 18px; font: 600 clamp(30px, 7vw, 44px)/1.15 Georgia, serif; overflow-wrap: anywhere; }
.hint-button {
  flex: none; width: 40px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 50%;
  color: var(--accent-dark); background: var(--accent-soft); font-size: 19px; font-weight: 800; cursor: pointer;
}
.hint-button[aria-expanded="true"] { color: var(--white); background: var(--accent); border-color: var(--accent); }
/* Neutral colours, so a hint never reads as right/wrong feedback. */
.hint { margin: 0 0 16px; padding: 11px 14px; border-left: 3px solid var(--line); border-radius: 0 12px 12px 0; background: var(--paper-deep); color: var(--ink); font-size: 16px; line-height: 1.45; }
.hint:empty { display: none; }
.hint strong { color: var(--ink); }
.hint-blank { display: inline-block; min-width: 3.5em; border-bottom: 2px solid var(--muted); color: transparent; }
.card-plural { margin: 6px 0 0; color: var(--muted); font-size: 15px; }
.card-plural:empty { display: none; }
.card-answer .hint { margin: 16px auto 0; max-width: 32em; text-align: left; }

/* Different words answered correctly in the current quiz run */
.run-progress { margin: 14px 0 0; color: var(--muted); font-size: .875rem; font-weight: 650; }
.run-progress label { display: block; }
#run-progress { width: 100%; height: 10px; margin: 6px 0 0; accent-color: var(--green); }

/* Extra quiz tabs (der/die/das, spelling) */
.quiz-prompt { flex: 1; min-width: 0; }
.quiz-word-detail { margin: -10px 0 18px; color: var(--muted); font-size: 16px; font-weight: 650; }
.quiz-word-detail:empty { display: none; }
.choice-grid.is-articles { grid-template-columns: repeat(3, 1fr); }
.choice-grid.is-articles .choice-button { text-align: center; font-size: 20px; }
.choice-grid.is-articles .choice-letter { display: none; }
.mode-tab b { hyphens: auto; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .mode-tabs { gap: 2px; padding: 4px; }
  .mode-tab { padding-inline: 3px; font-size: 12px; }
}
