:root {
  color-scheme: light;
  --ink: #173f35;
  --ink-2: #28564a;
  --paper: #f6f2e8;
  --card: #fffdf8;
  --muted: #6f786f;
  --line: #d9ddd3;
  --sun: #f8d46b;
  --coral: #ee745f;
  --mint: #a8d5bd;
  --success: #237a57;
  --danger: #b64336;
  --shadow: 0 14px 34px rgba(23, 63, 53, .11);
  --radius: 24px;
  font-family: "Trebuchet MS", "Aptos", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--paper); }
body { margin: 0; min-height: 100%; color: var(--ink); background: var(--paper); }
button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--coral); outline-offset: 3px; }

.app-shell { width: min(100%, 760px); min-height: 100vh; margin: 0 auto; padding: 0 20px 104px; }
.topbar { height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { border: 0; background: transparent; display: flex; align-items: center; gap: 11px; font-weight: 900; font-size: 1.04rem; cursor: pointer; padding: 6px; }
.brand-mark { width: 37px; height: 37px; display: grid; place-items: center; border-radius: 12px; background: var(--ink); color: var(--sun); font-family: Georgia, serif; font-size: 1.35rem; }
.top-actions { display: flex; gap: 8px; }
.icon-button { min-height: 42px; border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 0 12px; cursor: pointer; font-size: .82rem; font-weight: 800; }

.bottom-nav { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 20; width: min(calc(100% - 28px), 720px); display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 7px; background: rgba(255, 253, 248, .96); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.bottom-nav button { min-height: 54px; border: 0; border-radius: 14px; background: transparent; cursor: pointer; color: var(--muted); font-weight: 800; }
.bottom-nav button.active { background: var(--ink); color: white; }

.eyebrow { margin: 0 0 7px; color: var(--coral); font-size: .78rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-family: Georgia, serif; font-size: clamp(2.25rem, 9vw, 4.5rem); line-height: .97; letter-spacing: -.045em; }
h2 { font-family: Georgia, serif; font-size: clamp(1.65rem, 5vw, 2.35rem); letter-spacing: -.025em; }
.lead { max-width: 570px; color: var(--ink-2); font-size: 1.06rem; line-height: 1.55; }

.hero { padding: 28px 0 24px; }
.gentle-note { display: inline-flex; align-items: center; gap: 9px; margin-top: 8px; padding: 10px 13px; border: 1px solid #eadcae; background: #fff7d7; border-radius: 13px; font-size: .86rem; font-weight: 800; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: clamp(20px, 5vw, 30px); }
.section-title { display: flex; align-items: end; justify-content: space-between; gap: 14px; margin: 30px 0 14px; }
.section-title h2 { margin: 0; font-size: 1.42rem; }
.section-title span { color: var(--muted); font-size: .86rem; }

.mode-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 11px; }
.mode-card { min-height: 148px; padding: 17px; text-align: left; border: 1px solid var(--line); border-radius: 20px; background: var(--card); cursor: pointer; transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
.mode-card:hover { transform: translateY(-3px); border-color: var(--ink-2); box-shadow: 0 9px 22px rgba(23,63,53,.09); }
.mode-card.selected { border: 2px solid var(--ink); background: #f0f7f2; }
.mode-card strong { display: block; margin: 10px 0 5px; font-size: 1.04rem; }
.mode-card small { color: var(--muted); line-height: 1.35; }
.mode-symbol { font-family: Georgia, serif; font-size: 1.8rem; font-weight: 900; }

.controls-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; }
.field label { display: block; margin-bottom: 6px; font-size: .78rem; font-weight: 900; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
select { width: 100%; height: 52px; padding: 0 13px; border: 1px solid var(--line); border-radius: 14px; background: white; color: var(--ink); font-weight: 800; }
.field-label, .lesson-count span { display: block; margin-bottom: 6px; font-size: .78rem; font-weight: 900; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.level-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.level-choice { min-height: 58px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 14px; background: white; color: var(--ink); cursor: pointer; text-align: left; }
.level-choice strong, .level-choice small { display: block; }
.level-choice small { margin-top: 2px; color: var(--muted); font-size: .72rem; }
.level-choice.selected { border: 2px solid var(--ink); background: #f0f7f2; }
.level-choice:disabled { cursor: not-allowed; opacity: .52; background: #f2f2ee; }
.lesson-start-row { grid-template-columns: 1fr auto; margin-top: 12px; }
.lesson-count { min-height: 52px; display: flex; flex-direction: column; justify-content: center; padding: 7px 13px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.lesson-count span { margin: 0 0 2px; }
.lesson-count strong { font-size: 1rem; }
.primary, .secondary, .answer-button { min-height: 52px; border-radius: 15px; cursor: pointer; font-weight: 900; }
.primary { border: 0; padding: 0 24px; background: var(--ink); color: white; box-shadow: 0 7px 0 #0d2d26; }
.primary:active { transform: translateY(4px); box-shadow: 0 3px 0 #0d2d26; }
.secondary { border: 1px solid var(--line); padding: 0 18px; background: var(--card); }

.path { display: grid; gap: 12px; }
.path-row { display: grid; grid-template-columns: 54px 1fr auto; align-items: center; gap: 15px; padding: 15px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; }
.level-badge { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px; background: var(--mint); font-family: Georgia, serif; font-size: 1.18rem; font-weight: 900; }
.path-row:nth-child(2) .level-badge { background: #f8dca0; }
.path-row:nth-child(3) .level-badge { background: #f4b5a8; }
.path-row:nth-child(4) .level-badge { background: #c8bfdf; }
.path-copy strong { display: block; margin-bottom: 3px; }
.path-copy small { color: var(--muted); }
.progress-mini { width: 84px; height: 8px; overflow: hidden; border-radius: 99px; background: #e8ebe5; }
.progress-mini span { display: block; height: 100%; border-radius: inherit; background: var(--ink); }

.lesson-wrap { padding-top: 10px; }
.lesson-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 13px; margin-bottom: 20px; }
.close-button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); cursor: pointer; font-size: 1.3rem; }
.progress-track { height: 12px; overflow: hidden; border-radius: 99px; background: #e1e6df; }
.progress-track span { display: block; height: 100%; background: var(--coral); border-radius: inherit; transition: width .3s ease; }
.counter { font-weight: 900; font-variant-numeric: tabular-nums; }
.lesson-card { min-height: 470px; display: flex; flex-direction: column; justify-content: center; }
.prompt { color: var(--muted); font-weight: 900; letter-spacing: .04em; text-transform: uppercase; font-size: .78rem; }
.word-display { margin: 8px 0 2px; font-family: Georgia, serif; font-size: clamp(3rem, 14vw, 6rem); line-height: 1; letter-spacing: -.045em; overflow-wrap: anywhere; }
.ipa { margin: 8px 0 7px; color: var(--coral); font-family: Georgia, serif; font-size: 1.42rem; }
.word-meta { color: var(--muted); }
.speak-button { align-self: flex-start; min-height: 48px; margin-top: 12px; padding: 0 15px; border: 1px solid var(--line); border-radius: 14px; background: #fff7d7; cursor: pointer; font-weight: 900; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; margin-top: 28px; }
.answer-button { border: 2px solid var(--line); background: white; padding: 12px; text-align: left; }
.answer-button:hover { border-color: var(--ink); }
.answer-button.correct { border-color: var(--success); background: #e4f5eb; color: #14543a; }
.answer-button.wrong { border-color: var(--danger); background: #fde7e2; color: #76291f; }
.feedback { margin-top: 18px; padding: 15px; border-radius: 15px; background: #eef6ef; line-height: 1.45; }
.feedback strong { display: block; margin-bottom: 3px; }
.lesson-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 16px; }

.complete { text-align: center; padding: 48px 22px; }
.complete-mark { width: 78px; height: 78px; display: grid; place-items: center; margin: 0 auto 20px; border-radius: 50%; background: var(--sun); font-family: Georgia, serif; font-size: 2.3rem; font-weight: 900; }
.complete h2 { margin-bottom: 8px; }
.complete p { color: var(--muted); }

.search-bar { position: sticky; top: 4px; z-index: 4; margin-bottom: 16px; }
.search-bar input { width: 100%; height: 56px; padding: 0 18px; border: 1px solid var(--line); border-radius: 17px; background: var(--card); box-shadow: 0 8px 22px rgba(23,63,53,.07); color: var(--ink); font-size: 1rem; }
.word-list { display: grid; gap: 8px; }
.word-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 15px; background: var(--card); }
.word-row strong { display: block; }
.word-row small { color: var(--muted); }
.tag { padding: 5px 8px; border-radius: 8px; background: #ecf3ee; font-size: .75rem; font-weight: 900; }
.sound-small { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; background: white; cursor: pointer; }

.ipa-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ipa-tile { min-height: 110px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); cursor: pointer; padding: 14px; text-align: left; }
.ipa-tile strong { display: block; color: var(--coral); font-family: Georgia, serif; font-size: 1.75rem; }
.ipa-tile span { display: block; margin: 5px 0; font-weight: 900; }
.ipa-tile small { color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 11px; }
.stat { padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.stat strong { display: block; font-family: Georgia, serif; font-size: 2rem; }
.stat span { color: var(--muted); font-size: .83rem; }
.empty { padding: 35px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 18px; }

.toast { position: fixed; left: 50%; bottom: 91px; transform: translate(-50%, 20px); z-index: 30; opacity: 0; pointer-events: none; padding: 11px 15px; border-radius: 12px; background: var(--ink); color: white; font-weight: 800; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

body.calm * { animation: none !important; transition: none !important; }
body.calm .bottom-nav { backdrop-filter: none; }

@media (max-width: 620px) {
  .app-shell { padding-inline: 14px; }
  .topbar { height: 68px; }
  .brand > span:last-child { display: none; }
  .mode-grid { grid-template-columns: 1fr; }
  .mode-card { min-height: 104px; }
  .level-choices { grid-template-columns: repeat(2, 1fr); }
  .controls-row { grid-template-columns: 1fr 1fr; }
  .controls-row .primary { grid-column: 1 / -1; }
  .answers { grid-template-columns: 1fr; }
  .lesson-card { min-height: 450px; }
  .ipa-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-grid { grid-template-columns: 1fr; }
  .word-row { grid-template-columns: 1fr auto; }
  .word-row .tag { display: none; }
}

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

/* Additive learning controls: existing palette, type and layout retained. */
.preferences { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 12px; }
.preferences summary, .library-filters summary, .word-details summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 800; }
.preferences summary::before, .library-filters summary::before, .word-details summary::before { content: '+ '; margin-right: 8px; }
.preferences[open] > summary::before, .library-filters[open] > summary::before, .word-details[open] > summary::before { content: '− '; }
summary:focus-visible { outline: 3px solid var(--coral); outline-offset: 3px; }
.preferences-grid { display: grid; gap: 14px; padding-top: 8px; }
.preferences-grid > label { min-height: 44px; display: flex; align-items: center; gap: 10px; }
.preferences-grid input[type='checkbox'] { width: 22px; height: 22px; accent-color: var(--ink); }
.content-note { font-size: .85rem; line-height: 1.5; color: var(--ink-2); margin: 14px 0 0; overflow-wrap: anywhere; }
.approx { font-size: .92rem; line-height: 1.5; color: var(--ink-2); margin: 6px 0; overflow-wrap: anywhere; }
.audio-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.typed-form { display: grid; gap: 10px; margin-top: 24px; }
.typed-form input { min-height: 52px; width: 100%; padding: 12px; border: 2px solid var(--line); border-radius: 15px; background: white; color: var(--ink); }
.context-prompt { font-size: clamp(1.8rem, 7vw, 3.2rem); line-height: 1.2; }
.fallback-button { margin-top: 14px; }
.word-mark { margin-top: 14px; }
.word-details { margin-top: 8px; font-size: .85rem; }
.word-list .ipa { font-size: 1.12rem; }
.library-filters { margin-bottom: 16px; padding: 12px 18px; }
.storage-warning { display: block; line-height: 1.5; margin-bottom: 12px; }
.file-button { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px; min-width: 0; }
.file-button input { max-width: 100%; width: 180px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.word-row > div, .field { min-width: 0; }
.word-row small { overflow-wrap: anywhere; }
button:disabled { cursor: default; }
.lesson-actions { flex-wrap: wrap; }
.icon-button, .sound-small { min-height: 44px; }
.sound-small { min-width: 44px; }

