:root {
  --paper: #f4f1ea;
  --paper-deep: #e9e4da;
  --ink: #202521;
  --muted: #788078;
  --line: #ddd8cc;
  --white: #fffdf8;
  --sage: #5d7768;
  --sage-dark: #3d594a;
  --sage-soft: #dce7df;
  --coral: #d77962;
  --yellow: #f4c866;
  --shadow: 0 22px 65px rgba(47, 57, 49, 0.11);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
  background: var(--paper);
}

button { font: inherit; }

button:focus-visible {
  outline: 3px solid rgba(215, 121, 98, 0.55);
  outline-offset: 3px;
}

.app-shell { min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 84px;
  padding: 18px clamp(20px, 5vw, 74px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.55);
}

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 2px solid var(--sage-dark);
  border-radius: 14px 14px 17px 9px;
  color: var(--sage-dark);
  background: var(--yellow);
  font: 900 22px/1 Georgia, serif;
  transform: rotate(-5deg);
  box-shadow: 3px 4px 0 var(--sage-dark);
}
.brand-mark::after { position: absolute; top: 4px; right: 6px; width: 5px; height: 5px; border-radius: 50%; content: ""; background: var(--white); opacity: .9; }

.eyebrow {
  margin: 0 0 4px;
  color: var(--sage);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.3px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font: 700 21px/1.1 Georgia, serif; letter-spacing: 0; }
h2 { max-width: 500px; margin-bottom: 0; font: 700 37px/1.04 Georgia, serif; letter-spacing: 0; }

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.accent-switch { display: flex; align-items: center; gap: 5px; margin-left: 18px; color: var(--muted); font-size: 11px; font-weight: 800; }
.accent-label { margin-right: 3px; text-transform: uppercase; letter-spacing: .7px; }
.accent-switch button { min-width: 36px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: var(--white); cursor: pointer; font-size: 11px; font-weight: 800; }
.accent-switch button[aria-pressed="true"] { border-color: var(--sage-dark); color: var(--white); background: var(--sage-dark); }
@media (max-width: 620px) { .topbar { flex-wrap: wrap; gap: 10px; } .topbar-status { order: 3; width: 100%; } .accent-switch { margin-left: auto; } }

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #78a67d; box-shadow: 0 0 0 4px rgba(120, 166, 125, 0.14); }

.layout {
  display: grid;
  grid-template-columns: minmax(220px, 270px) minmax(0, 1fr);
  gap: clamp(28px, 5vw, 78px);
  width: min(1320px, calc(100% - 40px));
  margin: 0 auto;
  padding: clamp(28px, 6vw, 72px) 0 48px;
}

.sidebar { display: flex; min-height: 610px; flex-direction: column; }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; font-size: 12px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; }
.count-pill { display: inline-grid; place-items: center; min-width: 28px; height: 23px; padding: 0 7px; border-radius: 999px; color: var(--sage-dark); background: var(--sage-soft); font-size: 11px; }
.category-list { display: grid; gap: 6px; }
.category-button {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 47px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: .2s ease;
}
.category-button:hover { color: var(--ink); background: rgba(255, 253, 248, .72); }
.category-button.is-active { border-color: var(--line); color: var(--ink); background: var(--white); box-shadow: 0 7px 25px rgba(47, 57, 49, .06); }
.category-icon { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 8px; color: var(--sage-dark); background: var(--sage-soft); font-size: 15px; }
.category-name { font-size: 13px; font-weight: 700; }
.category-count { color: #9da49b; font-size: 11px; }
.category-button.is-active .category-count { color: var(--sage); }
.mode-switch { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; margin-bottom: 26px; padding: 4px; border-radius: 10px; background: var(--paper-deep); }
.mode-button { min-height: 34px; padding: 5px 4px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; cursor: pointer; font-size: 10px; font-weight: 800; line-height: 1.1; }
.mode-button span { display: inline-grid; place-items: center; min-width: 15px; height: 15px; margin-left: 2px; border-radius: 8px; color: var(--white); background: var(--coral); font-size: 9px; }
.mode-button.is-active { color: var(--ink); background: var(--white); box-shadow: 0 2px 7px rgba(47, 57, 49, .08); }
.sidebar-footer { margin-top: auto; padding-top: 30px; }
.mini-progress-label { display: flex; justify-content: space-between; margin-bottom: 9px; color: var(--muted); font-size: 11px; font-weight: 700; }
.mini-progress-label strong { color: var(--sage-dark); }
.progress-track, .deck-progress-track { overflow: hidden; height: 6px; border-radius: 99px; background: var(--paper-deep); }
.progress-track span, .deck-progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--sage); transition: width .35s ease; }
.sidebar-note { max-width: 175px; margin: 17px 0 0; color: #9da49b; font: italic 14px/1.45 Georgia, serif; }

.workspace { width: min(760px, 100%); }
.workspace-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 27px; }
.deck-tools { display: flex; gap: 8px; }
.tool-button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 8px; border: 0; color: var(--muted); background: transparent; cursor: pointer; font-size: 12px; font-weight: 700; }
.tool-button:hover { color: var(--ink); }

.deck-meta { display: grid; grid-template-columns: auto minmax(90px, 1fr) auto; align-items: center; gap: 16px; margin-bottom: 16px; }
.stage-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; margin: 0 0 18px; }
.stage-chip { display: grid; min-height: 72px; gap: 3px; padding: 9px 6px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: rgba(255, 253, 248, .45); cursor: pointer; text-align: left; }
.stage-chip strong { color: var(--ink); font-size: 11px; }
.stage-chip span { color: #98a197; font-size: 10px; font-weight: 650; }
.stage-chip em { color: var(--sage); font-size: 9px; font-style: normal; font-weight: 800; text-transform: uppercase; }
.stage-chip:hover:not(:disabled) { border-color: var(--sage); background: var(--white); }
.stage-chip.is-active { border-color: var(--sage-dark); background: var(--sage-dark); box-shadow: 0 6px 15px rgba(61, 89, 74, .15); }
.stage-chip.is-active strong, .stage-chip.is-active span, .stage-chip.is-active em { color: var(--white); }
.stage-chip.is-locked { cursor: not-allowed; opacity: .52; }
button:disabled { cursor: not-allowed; opacity: .48; }
.deck-position { color: var(--sage-dark); font-size: 12px; font-weight: 800; }
.muted { color: #a4aa9f; }
.deck-progress-track { height: 5px; }
.deck-filter { display: flex; gap: 4px; padding: 3px; border-radius: 9px; background: var(--paper-deep); }
.filter-button { padding: 6px 9px; border: 0; border-radius: 7px; color: #8d958b; background: transparent; cursor: pointer; font-size: 11px; font-weight: 750; }
.filter-button.is-active { color: var(--ink); background: var(--white); box-shadow: 0 2px 7px rgba(47, 57, 49, .08); }

.word-card { overflow: hidden; border: 1px solid var(--line); border-radius: 17px; background: var(--white); box-shadow: var(--shadow); }
.card-topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 24px 14px; }
.category-label { color: var(--coral); font-size: 11px; font-weight: 850; letter-spacing: 1px; text-transform: uppercase; }
.learned-toggle { display: inline-flex; align-items: center; gap: 7px; border: 0; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; font-weight: 750; }
.learned-toggle:hover { color: var(--sage-dark); }
.check-icon { display: grid; place-items: center; width: 19px; height: 19px; border: 1px solid #c7cdc4; border-radius: 6px; color: transparent; font-size: 12px; transition: .2s ease; }
.learned-toggle.is-learned .check-icon { border-color: var(--sage); color: var(--white); background: var(--sage); }
.learned-toggle.is-learned { color: var(--sage-dark); }

.image-button { position: relative; display: block; width: calc(100% - 48px); aspect-ratio: 16 / 9; margin: 0 24px; overflow: hidden; padding: 0; border: 0; border-radius: 11px; background: #d9ddd6; cursor: pointer; }
.image-button img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }
.image-button.is-fallback { display: grid; place-items: center; background: var(--sage-soft); }
.image-button.is-fallback img { display: none; }
.image-button.is-fallback::before { content: attr(data-emoji); color: var(--sage-dark); font-size: 72px; }
.image-button:hover img { transform: scale(1.025); }
.image-button::after { position: absolute; inset: 0; content: ""; background: linear-gradient(180deg, transparent 56%, rgba(28, 38, 32, .2)); pointer-events: none; }
.image-overlay { position: absolute; right: 14px; bottom: 12px; z-index: 1; display: inline-flex; align-items: center; gap: 7px; padding: 8px 10px; border-radius: 8px; color: var(--white); background: rgba(33, 43, 36, .77); font-size: 11px; font-weight: 800; }
.play-symbol { font-size: 10px; }

.word-content { padding: 23px 24px 5px; }
.word-row { display: flex; align-items: center; gap: 14px; }
.word-row h3 { margin-bottom: 0; font: 700 46px/.98 Georgia, serif; letter-spacing: 0; }
.dictionary-translation { margin: 5px 0 16px; color: var(--coral); font: 700 25px/1.2 Georgia, serif; }
.dictionary-details { display: grid; grid-template-columns: max-content 1fr; gap: 10px; align-items: start; padding: 13px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.part-of-speech { padding: 4px 7px; border-radius: 5px; color: var(--sage-dark); background: var(--sage-soft); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.dictionary-definition { color: var(--muted); font-size: 14px; line-height: 1.45; }
.icon-button { display: grid; place-items: center; width: 35px; height: 35px; border: 1px solid var(--line); border-radius: 50%; color: var(--sage-dark); background: var(--paper); cursor: pointer; font-size: 12px; transition: .2s ease; }
.icon-button:hover { color: var(--white); border-color: var(--sage); background: var(--sage); }
.ipa-line { display: flex; flex-wrap: wrap; align-items: center; gap: 1px; min-height: 42px; margin-top: 13px; color: var(--sage-dark); font: 24px/1.3 Georgia, serif; }
.ipa-slash { color: #a6afa4; }
.ipa-tokens { display: inline-flex; flex-wrap: wrap; align-items: center; }
.phoneme-button { min-width: 22px; padding: 3px 2px; border: 0; border-radius: 5px; color: var(--sage-dark); background: transparent; cursor: pointer; font: inherit; line-height: 1; }
.phoneme-button:hover, .phoneme-button:focus-visible { color: var(--white); background: var(--coral); }
.stress-mark { display: inline-block; padding: 3px 1px; color: #9ba59a; }
.phoneme-hint { margin: 7px 0 0; color: #9ca49c; font-size: 11px; font-weight: 650; }
.phoneme-example { min-height: 25px; margin-top: 8px; color: var(--coral); font-size: 12px; font-weight: 750; }
.phoneme-example:empty { display: none; }

.card-actions { display: flex; justify-content: space-between; gap: 12px; padding: 19px 24px 24px; }
.nav-button, .primary-button { min-height: 43px; padding: 9px 14px; border-radius: 9px; cursor: pointer; font-size: 12px; font-weight: 800; }
.nav-button { border: 1px solid var(--line); color: var(--muted); background: transparent; }
.nav-button:hover { color: var(--ink); background: var(--paper); }
.primary-button { border: 1px solid var(--sage-dark); color: var(--white); background: var(--sage-dark); box-shadow: 0 6px 15px rgba(61, 89, 74, .18); }
.primary-button:hover { background: var(--sage); }
.keyboard-hint { display: flex; align-items: center; justify-content: center; gap: 7px; margin-top: 16px; color: #a3aaa2; font-size: 11px; font-weight: 650; }
.keyboard-hint span:not(.hint-divider) { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 4px; border: 1px solid #d3d0c7; border-radius: 4px; color: var(--muted); background: rgba(255, 253, 248, .65); font-size: 10px; }
.keyboard-hint .hint-divider { width: 1px; height: 14px; margin: 0 5px; background: var(--line); }
.exam-intro, .exam-result { padding: clamp(30px, 6vw, 62px) clamp(22px, 5vw, 52px); border: 1px solid var(--line); border-radius: 17px; background: var(--white); box-shadow: var(--shadow); text-align: center; }
.exam-intro h3, .exam-result h3, .wrong-heading h3 { margin-bottom: 11px; font: 700 31px/1.08 Georgia, serif; }
.exam-intro p:not(.eyebrow), .exam-result p:not(.eyebrow) { max-width: 450px; margin: 0 auto 22px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.exam-session { overflow: hidden; border: 1px solid var(--line); border-radius: 17px; background: var(--white); box-shadow: var(--shadow); }
.exam-status { display: flex; justify-content: space-between; padding: 19px 23px 12px; color: var(--sage-dark); font-size: 12px; font-weight: 800; }
.exam-session > .deck-progress-track { height: 5px; margin: 0 23px; }
.exam-card { padding: 26px 23px 23px; }
.exam-word-row { display: flex; align-items: center; justify-content: center; gap: 13px; margin-top: 8px; }
.exam-word-row h3 { margin: 0; font: 700 45px/1 Georgia, serif; }
.exam-prompt { margin: 12px 0 20px; color: var(--muted); font-size: 12px; font-weight: 700; text-align: center; }
.exam-answer-row { display: flex; gap: 10px; margin: 20px 0 15px; }
.exam-answer-input { flex: 1; min-width: 0; min-height: 45px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--white); font-size: 17px; }
.exam-answer-input:focus { outline: 3px solid rgba(93, 119, 104, .2); border-color: var(--sage); }
.exam-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.exam-choice { position: relative; overflow: hidden; aspect-ratio: 4 / 3; padding: 0; border: 2px solid transparent; border-radius: 9px; background: var(--paper-deep); cursor: pointer; }
.exam-choice img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s ease; }
.exam-choice.is-fallback { display: grid; place-items: center; color: var(--sage-dark); background: var(--sage-soft); font-size: 22px; font-weight: 900; }
.exam-choice.is-fallback::before { content: attr(data-code); }
.exam-choice.is-fallback img { display: none; }
.exam-choice:hover:not(:disabled) img { transform: scale(1.03); }
.exam-choice:hover:not(:disabled) { border-color: var(--sage); }
.exam-choice.is-correct { border-color: #5e9e6a; box-shadow: 0 0 0 3px rgba(94, 158, 106, .17); }
.exam-choice.is-wrong { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(215, 121, 98, .17); }
.exam-feedback { margin: 16px 0 12px; padding: 10px 12px; border-radius: 8px; font-size: 12px; font-weight: 800; text-align: center; }
.exam-feedback.is-correct { color: #2e7340; background: #e2f0df; }
.exam-feedback.is-wrong { color: #984d3d; background: #fae5df; }
.exam-card > .primary-button { display: block; margin-left: auto; }
.result-mark { display: grid; place-items: center; width: 49px; height: 49px; margin: 0 auto 16px; border: 2px solid var(--sage-dark); border-radius: 15px 15px 19px 9px; color: var(--sage-dark); background: var(--yellow); box-shadow: 3px 4px 0 var(--sage-dark); font-size: 12px; font-weight: 900; }
.wrong-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.wrong-heading h3 { max-width: 460px; margin-bottom: 0; font-size: 27px; }
.wrong-summary { margin: 17px 0; color: var(--muted); font-size: 13px; font-weight: 650; }
.wrong-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.wrong-item { overflow: hidden; padding: 0 0 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--white); cursor: pointer; text-align: left; }
.wrong-item:hover { border-color: var(--sage); transform: translateY(-1px); }
.wrong-item img { display: block; width: 100%; aspect-ratio: 4 / 3; margin-bottom: 8px; object-fit: cover; background: var(--sage-soft); }
.wrong-item.is-fallback img { display: none; }
.wrong-item.is-fallback::before { display: grid; place-items: center; aspect-ratio: 4 / 3; margin-bottom: 8px; content: attr(data-code); color: var(--sage-dark); background: var(--sage-soft); font-size: 20px; font-weight: 900; }
.wrong-item span, .wrong-item strong, .wrong-item small { display: block; padding: 0 9px; }
.wrong-item span { font: 700 19px/1.05 Georgia, serif; }
.wrong-item strong { margin-top: 4px; color: var(--coral); font-size: 13px; }
.wrong-item small { margin-top: 5px; color: var(--muted); font-size: 9px; font-weight: 700; line-height: 1.35; }
.empty-state { padding: 55px 24px; border: 1px solid var(--line); border-radius: 17px; background: var(--white); box-shadow: var(--shadow); text-align: center; }
.empty-state-mark { display: grid; place-items: center; width: 42px; height: 42px; margin: 0 auto 15px; border-radius: 50%; color: var(--white); background: var(--sage); font-size: 19px; font-weight: 900; }
.empty-state h3 { margin-bottom: 8px; font: 700 25px/1.1 Georgia, serif; }
.empty-state p { margin-bottom: 0; color: var(--muted); font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 5; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--white); box-shadow: 0 10px 30px rgba(47, 57, 49, .14); font-size: 12px; font-weight: 700; opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: .25s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; gap: 28px; padding-top: 28px; }
  .sidebar { min-height: 0; }
  .category-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .category-button { grid-template-columns: 27px 1fr; }
  .category-count { display: none; }
  .sidebar-footer { display: none; }
  .workspace { width: 100%; }
}

@media (max-width: 580px) {
  .topbar { min-height: 70px; padding: 14px 18px; }
  .topbar-status { font-size: 0; }
  .topbar-status .status-dot { width: 9px; height: 9px; }
  .layout { width: min(100% - 28px, 760px); padding-top: 22px; }
  h2 { font-size: 31px; }
  .workspace-heading { align-items: start; flex-direction: column; gap: 14px; }
  .deck-tools { align-self: end; margin-top: -41px; }
  .deck-meta { grid-template-columns: auto 1fr; gap: 9px 12px; }
  .stage-strip { gap: 5px; }
  .stage-chip { min-height: 64px; padding: 8px 4px; }
  .stage-chip strong { font-size: 10px; }
  .stage-chip span, .stage-chip em { font-size: 8px; }
  .deck-filter { grid-column: 1 / -1; justify-self: stretch; justify-content: stretch; }
  .filter-button { flex: 1; }
  .category-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .category-button { min-height: 43px; }
  .card-topline, .word-content, .card-actions { padding-left: 17px; padding-right: 17px; }
  .word-row h3 { font-size: 39px; }
  .ipa-line { font-size: 22px; }
  .nav-button span { display: none; }
  .exam-intro h3, .exam-result h3 { font-size: 27px; }
  .exam-card { padding: 22px 15px 17px; }
  .exam-answer-row { flex-direction: column; }
  .exam-session > .deck-progress-track, .exam-status { margin-left: 15px; margin-right: 15px; }
  .exam-status { padding-left: 0; padding-right: 0; }
  .exam-word-row h3 { font-size: 39px; }
  .wrong-heading { align-items: start; flex-direction: column; }
  .wrong-heading .primary-button { width: 100%; }
  .wrong-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

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