/* English ↔ Spanish flashcards · premium navy + gold */
@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;0,9..40,800;1,9..40,400&family=Instrument+Serif:ital@0;1&display=swap");

:root {
  --bg-deep: #07080d;
  --bg-mid: #0e1018;
  --bg-top: #141824;

  --panel: rgba(26, 29, 40, 0.78);
  --panel2: rgba(18, 20, 30, 0.88);
  --text: rgba(250, 248, 244, 0.96);
  --muted: rgba(178, 172, 160, 0.82);

  --accent: #d4a853;
  --accent-bright: #ebc97a;
  --accent-soft: rgba(212, 168, 83, 0.16);
  --danger: #e89580;
  --good: #5ecf9a;
  --shadow:
    0 28px 70px rgba(0, 0, 0, 0.58),
    0 10px 28px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
  --radius: 20px;

  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(212, 168, 83, 0.22);
  --surface: rgba(34, 37, 50, 0.92);
  --surface-hover: rgba(46, 50, 66, 0.96);
  --surface-ghost: rgba(16, 18, 26, 0.72);
  --link-hover: #f2ddb0;

  --paper1: linear-gradient(168deg, #fffefb 0%, #f9f6f0 46%, #f0ebe2 100%);
  --paper2: linear-gradient(198deg, #ffffff 0%, #f7f4ee 52%, #ede8df 100%);
  --paperInk: rgba(26, 24, 20, 0.92);

  --flipSuccess: rgba(94, 207, 154, 0.22);
  --flipSuccessDeep: rgba(48, 160, 110, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-family: "DM Sans", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial,
    sans-serif;
  color: var(--text);
  min-height: 100%;
  background-color: var(--bg-deep);
  background-image:
    radial-gradient(110% 80% at 50% -20%, rgba(212, 168, 83, 0.14), transparent 52%),
    radial-gradient(70% 55% at 100% 0%, rgba(88, 72, 140, 0.12), transparent 48%),
    radial-gradient(65% 50% at 0% 100%, rgba(40, 48, 72, 0.45), transparent 50%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 44%, var(--bg-deep) 100%);
  display: grid;
  place-items: center;
  padding: 20px 16px 28px;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 0;
}

.app {
  width: min(760px, 100%);
  display: grid;
  gap: 16px;
  position: relative;
  z-index: 1;
}

.header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 18px 18px 16px;
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(22px) saturate(1.15);
  -webkit-backdrop-filter: blur(22px) saturate(1.15);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.headerCompact {
  gap: 6px;
  padding: 10px 12px 12px;
}

.title {
  margin: 0;
  font-family: "Instrument Serif", Georgia, "Times New Roman", serif;
  font-weight: 400;
  letter-spacing: -0.02em;
  font-size: clamp(26px, 3.6vw, 34px);
  background: linear-gradient(135deg, #faf6ef 0%, #e8c97a 55%, #c9a04a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.titleCenter {
  width: 100%;
  text-align: center;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  max-width: 38rem;
}

.subtitleTight {
  max-width: 36rem;
}

.stats {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.statsRow {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  width: 100%;
}

/* Sentence pages: stats on one row, navigation vs deck actions grouped */
.phraseToolbar {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.phraseToolbar-stats {
  justify-content: center;
}

.phraseToolbar-rows {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 100%;
}

.btnCluster {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
}

.btnCluster-actions {
  border-color: var(--border-strong);
}

/* Topics hub — grouped vocabulary subsets */
.topicHubPanel {
  width: 100%;
}

.topicHubSections {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
  max-width: 100%;
}

.topicSection {
  padding: 18px 0 22px;
  border-bottom: 1px solid var(--border);
}

.topicSection:last-child {
  border-bottom: none;
  padding-bottom: 8px;
}

.topicSectionHead {
  margin-bottom: 14px;
  text-align: left;
  max-width: 40rem;
}

.topicSectionTitle {
  margin: 0 0 6px;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: clamp(18px, 2.6vw, 22px);
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--accent-bright);
}

.topicSectionSubtitle {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
}

.topicSectionGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  width: 100%;
}

.topicPickCard {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  gap: 6px;
  padding: 14px 16px;
  min-height: 100px;
  text-decoration: none;
  color: inherit;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel2);
  transition:
    border-color 0.22s ease,
    background 0.22s ease,
    transform 0.2s ease,
    box-shadow 0.22s ease;
}

.topicPickCard:hover {
  border-color: rgba(212, 168, 83, 0.42);
  background: var(--surface-hover);
  box-shadow:
    0 14px 36px rgba(0, 0, 0, 0.42),
    0 0 0 1px rgba(212, 168, 83, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transform: translateY(-2px);
}

.topicPickTitle {
  font-weight: 780;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.topicPickMeta {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.topicPickBlurb {
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
  margin-top: 2px;
}

.phraseToolbar-sep {
  display: none;
  width: 1px;
  height: 28px;
  background: var(--border);
  flex-shrink: 0;
}

@media (min-width: 520px) {
  .phraseToolbar-sep {
    display: block;
  }
}

/* Sentence deck pages: one flat row of actions (replaces nested clusters on small screens) */
.phraseToolbar-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.phraseToolbar-navBtn {
  flex: 0 1 auto;
}

/* Main deck, sentences, writing: one centered horizontal row of tabs/buttons */
body.deckPage .phraseToolbar,
body.phrasePage .phraseToolbar,
body.writingPage .header.headerCompact {
  align-items: center;
  gap: 6px;
}

body.writingPage .stats.writingStats {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: 2px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

body.deckPage .phraseToolbar-actions,
body.phrasePage .phraseToolbar-actions,
body.writingPage .phraseToolbar-actions {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  overflow: visible;
  padding: 4px 2px 8px;
}

body.deckPage .phraseToolbar-actionsInner,
body.phrasePage .phraseToolbar-actionsInner,
body.writingPage .phraseToolbar-actionsInner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  max-width: 100%;
}

body.deckPage .phraseToolbar-actionsInner .phraseToolbar-nav,
body.phrasePage .phraseToolbar-actionsInner .phraseToolbar-nav,
body.writingPage .phraseToolbar-actionsInner .phraseToolbar-nav {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

body.deckPage .phraseToolbar-actionsInner .phraseToolbar-nav > a.btn,
body.deckPage .phraseToolbar-actionsInner .phraseToolbar-nav > button.btn,
body.phrasePage .phraseToolbar-actionsInner .phraseToolbar-nav > a.btn,
body.phrasePage .phraseToolbar-actionsInner .phraseToolbar-nav > button.btn,
body.writingPage .phraseToolbar-actionsInner .phraseToolbar-nav > a.btn,
body.writingPage .phraseToolbar-actionsInner .phraseToolbar-nav > button.btn {
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
  white-space: nowrap;
  min-height: 38px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.2;
  border-radius: 12px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Sentence toolbar: every control fills its slot; label centered (links + buttons) */
.phraseToolbar-nav > a.btn,
.phraseToolbar-nav > button.btn {
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  box-sizing: border-box;
}

.stat {
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--panel2);
  border: 1px solid var(--border);
  min-width: 72px;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

a.statLink {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

a.statLink:hover {
  background: var(--accent-soft);
  border-color: rgba(212, 168, 83, 0.38);
}

a.statLink:focus-visible {
  outline: 2px solid rgba(212, 168, 83, 0.55);
  outline-offset: 2px;
}

.hiddenHub {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 22rem;
  margin: 4px auto 0;
}

.hiddenHubCard {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
}

.hiddenHubTitle {
  font-weight: 700;
  font-size: 15px;
}

.hiddenHubMeta {
  font-size: 12px;
}

.hiddenHubBack {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.statLabel {
  font-size: 11px;
  color: var(--muted);
}

.statValue {
  font-size: 17px;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent-bright);
}

.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  color: var(--text);
  background: var(--surface);
  padding: 10px 12px;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 650;
  letter-spacing: 0.01em;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease,
    box-shadow 140ms ease;
  user-select: none;
}

.btnSm {
  padding: 7px 11px;
  border-radius: 12px;
  font-size: 13px;
}

.btn:hover {
  transform: translateY(-1px);
  background: var(--surface-hover);
  border-color: rgba(212, 168, 83, 0.35);
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.38),
    0 0 0 1px rgba(212, 168, 83, 0.06);
}

.btn:active {
  transform: translateY(0px);
}

.btn.ghost {
  background: var(--surface-ghost);
}

.btn.danger {
  border-color: rgba(240, 168, 154, 0.35);
  background: rgba(60, 28, 24, 0.65);
  color: rgba(255, 232, 226, 0.96);
}

.btn.danger:hover {
  border-color: rgba(255, 190, 175, 0.45);
  background: rgba(80, 36, 30, 0.75);
}

.btn.primary,
.btn.navBtn.primary {
  border-color: rgba(212, 168, 83, 0.5);
  background: linear-gradient(180deg, rgba(212, 168, 83, 0.22) 0%, rgba(212, 168, 83, 0.1) 100%);
  color: rgba(255, 248, 235, 0.98);
  box-shadow: 0 4px 16px rgba(212, 168, 83, 0.12);
}

.btn.primary:hover,
.btn.navBtn.primary:hover {
  border-color: rgba(235, 201, 122, 0.62);
  background: linear-gradient(180deg, rgba(212, 168, 83, 0.32) 0%, rgba(212, 168, 83, 0.16) 100%);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.stage {
  display: block;
}

.panel {
  border-radius: var(--radius);
  padding: 16px;
  background: var(--panel);
  backdrop-filter: blur(20px) saturate(1.12);
  -webkit-backdrop-filter: blur(20px) saturate(1.12);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.studyPanel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.studyRow {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 12px;
  max-width: 100%;
}

.studyControlBar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 14px;
  width: min(400px, 100%);
}

.topicDrop {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
}

.topicDropBtn,
.studyControlBar .studyFlipBtn {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 10px 14px;
  font-size: 16px;
  font-weight: 700;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.studyControlBar .studyFlipBtn,
.studyControlBar .studyNextBtn {
  flex: 1 1 0;
}

.studyControlBar--solo {
  justify-content: flex-end;
}

.studyControlBar--solo .studyNextBtn,
.studyControlBar--solo #stepBtn {
  flex: 0 1 auto;
  width: min(140px, 42%);
  min-width: 110px;
}

.topicDropBtnText {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.topicDropChev {
  flex-shrink: 0;
  font-size: 11px;
  opacity: 0.85;
  transition: transform 0.2s ease;
}

.topicDrop.isOpen .topicDropChev {
  transform: rotate(180deg);
}

.topicDrop.isOpen .topicDropBtn {
  border-color: rgba(235, 201, 122, 0.62);
  box-shadow:
    0 0 0 3px rgba(212, 168, 83, 0.16),
    0 4px 16px rgba(212, 168, 83, 0.12);
}

.topicDropMenu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: min(280px, 92vw);
  max-height: min(320px, 50vh);
  overflow: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  border-radius: 14px;
  background: linear-gradient(180deg, #fcfbfa 0%, #f5f3f0 100%);
  border: 1px solid rgba(212, 168, 83, 0.35);
  box-shadow:
    0 16px 40px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  -webkit-overflow-scrolling: touch;
  color: #1a1814;
}

.topicDropGroupLabel {
  margin: 0;
  padding: 8px 12px 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #6b6560;
}

.topicDropItem {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #1a1814;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition:
    background 0.12s ease,
    color 0.12s ease;
}

.topicDropItem:hover:not(:disabled) {
  background: rgba(212, 168, 83, 0.2);
  color: #1f1808;
}

.topicDropItem.isSelected {
  background: rgba(212, 168, 83, 0.32);
  color: #1f1808;
}

.topicDropItem:disabled {
  color: #9a948c;
  opacity: 0.65;
  cursor: not-allowed;
}

.topicDropItemCount {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #2d7a52;
}

.topicDropItemLabel {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mobile-only Flip | Next row (hidden on wider viewports). */
.studyTouchBar {
  display: none;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  margin-bottom: 2px;
}

.studyTouchBar .btn {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  min-height: 50px;
  font-size: 16px;
  border-radius: 14px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.studyHint {
  flex: 1;
  margin: 0;
  font-size: 12px;
  text-align: center;
  line-height: 1.45;
  min-width: 200px;
}

.studyHintSolo {
  flex: none;
  width: 100%;
  margin-bottom: 4px;
}

.navBtn {
  min-width: 110px;
  font-variant-numeric: tabular-nums;
}

.deckHelpNote {
  margin: 0 auto;
  padding: 0 clamp(12px, 4vw, 20px);
  max-width: 34rem;
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.deckHelpNote kbd {
  font-size: 11px;
}

.flashcardStage {
  display: grid;
  place-items: center;
  padding: 10px 0 6px;
  min-height: min(380px, 52vh);
}

.flashcardHit {
  width: min(520px, 100%);
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 24px;
  outline: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.flashcardHit:not(:disabled):hover {
  outline: 1px solid rgba(212, 168, 83, 0.35);
  box-shadow:
    0 16px 48px rgba(0, 0, 0, 0.52),
    0 0 40px rgba(212, 168, 83, 0.08);
}

.flashcardHit:not(:disabled):hover:has(.flashcardInner.isFlipped) {
  outline: 1px solid rgba(94, 207, 154, 0.45);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.52);
}

.flashcardHit:is(:disabled) {
  cursor: default;
}

.flashcardHit:focus-visible {
  border-radius: 24px;
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.15),
    0 12px 40px rgba(0, 0, 0, 0.5);
}

.flashcardHit:focus-visible:has(.flashcardInner.isFlipped) {
  box-shadow:
    0 0 0 3px rgba(72, 200, 140, 0.4),
    0 12px 40px rgba(0, 0, 0, 0.5);
}

.flashcard3d {
  perspective: 1400px;
  perspective-origin: 50% 50%;
  /* Avoid compositor quirks on some GPUs when flipping */
  transform: translateZ(0);
  border-radius: 22px;
  /* Keep glow off `filter` — filter + preserve-3d often paints faces transparent after a tab switch */
  isolation: isolate;
  transition: box-shadow 0.45s ease;
}

/* Green success bloom while the Spanish face is showing */
.flashcard3d:has(.flashcardInner.isFlipped) {
  box-shadow:
    0 0 0 1px rgba(94, 207, 154, 0.4),
    0 18px 48px rgba(0, 0, 0, 0.48),
    0 0 60px rgba(94, 207, 154, 0.22),
    0 0 100px rgba(48, 160, 110, 0.1);
}

.flashcardInner {
  position: relative;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform 0.58s cubic-bezier(0.22, 1, 0.36, 1);
  border-radius: 22px;
  min-height: min(340px, 44vh);
  width: 100%;
}

.flashcardInner.isFlipped {
  transform: rotateY(180deg);
  -webkit-transform: rotateY(180deg);
}

.flashFace {
  position: absolute;
  inset: 0;
  min-width: 0;
  border-radius: 22px;
  display: grid;
  place-items: center;
  align-content: center;
  padding: clamp(18px, 4vw, 36px);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  hyphens: none;
  -webkit-hyphens: none;
  color: var(--paperInk);
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.98) inset,
    0 24px 56px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(212, 168, 83, 0.08);
}

.flashFaceFront {
  background: var(--paper1);
  transform: rotateY(0deg) translateZ(4px);
  -webkit-transform: rotateY(0deg) translateZ(4px);
}

.flashFaceBack {
  background:
    radial-gradient(120% 90% at 10% 0%, var(--flipSuccess), transparent 55%),
    radial-gradient(95% 80% at 100% 100%, var(--flipSuccessDeep), transparent 50%),
    linear-gradient(168deg, #ffffff 0%, #f4faf7 42%, #e8f5ee 100%);
  border-color: rgba(56, 175, 125, 0.28);
  transform: rotateY(180deg) translateZ(4px);
  -webkit-transform: rotateY(180deg) translateZ(4px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.95) inset,
    0 0 0 1px rgba(94, 207, 154, 0.22),
    0 24px 56px rgba(0, 0, 0, 0.5),
    0 0 48px rgba(94, 207, 154, 0.16);
}

.flashLabel {
  position: absolute;
  top: clamp(14px, 3vw, 22px);
  left: clamp(14px, 3vw, 22px);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0.5;
  color: rgba(120, 100, 70, 0.9);
}

.flashWord {
  margin: 0;
  padding: 0 clamp(14px, 3vw, 28px);
  font-size: clamp(26px, 4vw, 42px);
  font-weight: 850;
  line-height: 1.15;
  letter-spacing: -0.035em;
  text-align: center;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: normal;
  hyphens: none;
  -webkit-hyphens: none;
  -moz-hyphens: none;
}

.flashWordEs {
  font-family: ui-sans-serif, system-ui, "SF Pro Text", Segoe UI, Roboto, "Noto Sans", sans-serif;
}

/* Full-sentence cards: slightly smaller type than main deck; wrap at spaces, never auto-hyphens */
.phrasePage .flashFace {
  padding: clamp(16px, 3.5vw, 28px);
  hyphens: none;
  -webkit-hyphens: none;
}

body.phrasePage .flashFace .flashWord {
  font-size: clamp(15px, 2.4vw, 22px);
  line-height: 1.28;
  letter-spacing: -0.02em;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: normal;
  hyphens: none !important;
  -webkit-hyphens: none !important;
  -moz-hyphens: none !important;
}

.phrasePage .flashcardStage {
  min-height: min(400px, 56vh);
}

.phrasePage .flashcardInner {
  min-height: min(360px, 50vh);
}

/* Separate text layering from curved faces — avoids “mirrored/backward” glyph bugs in some browsers. */
.flashFace .flashWord {
  transform: translateZ(8px);
  -webkit-font-smoothing: antialiased;
}

.flashCornerTag {
  position: absolute;
  bottom: clamp(14px, 3vw, 22px);
  right: clamp(14px, 3vw, 22px);
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 750;
  border-radius: 999px;
  color: rgba(22, 24, 32, 0.75);
  background: rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.footer {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.footerBar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 16px;
  padding: 12px 14px;
}

.footerLead {
  color: var(--muted);
  font-size: 12px;
  margin-right: 4px;
}

.footerLink,
.btnLink {
  appearance: none;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.footerLink:hover,
.btnLink:hover {
  color: var(--link-hover);
}

.btnLink {
  display: inline-block;
}

.btnLink input {
  display: none;
}

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--panel2);
  border: 1px solid var(--border-strong);
  color: var(--text);
}

.muted {
  color: var(--muted);
}

a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.inlineLink {
  color: var(--accent);
  text-underline-offset: 3px;
}

.inlineLink:hover {
  color: var(--link-hover);
}

.saveToast {
  font-weight: 750;
  color: var(--good);
  letter-spacing: 0.02em;
  min-height: 1.2em;
}

.miniHelp {
  margin-top: 8px;
  min-height: 1.25em;
  display: flex;
  justify-content: center;
  align-items: center;
}

.miniHelp:empty,
.miniHelp:not(:has(.saveToast:not(:empty))) {
  margin-top: 0;
  min-height: 0;
}

/* ——— Phones & tablets (wide enough to catch phones in landscape) ——— */
@media (max-width: 768px) {
  /* Reduces double-tap zoom on controls while keeping pinch-zoom. */
  html {
    touch-action: manipulation;
    overflow-x: hidden;
    width: 100%;
  }

  body {
    padding: max(8px, env(safe-area-inset-top, 0px)) max(8px, env(safe-area-inset-right, 0px))
      max(10px, env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
  }

  .app {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    gap: 10px;
  }

  .header,
  .stage,
  .panel,
  .studyPanel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .panel {
    padding: 10px 8px;
  }

  .title {
    font-size: clamp(22px, 6vw, 28px);
  }

  .desktopOnlyControl {
    display: none !important;
  }

  /* Sentence deck header: hide long instruction block on narrow viewports */
  body.phrasePage .header .subtitle {
    display: none !important;
    margin: 0 !important;
    padding: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
    border: 0 !important;
  }

  body.phrasePage .header.headerCompact,
  body.deckPage .header.headerCompact {
    gap: 4px;
  }

  .studyTouchBar {
    display: none !important;
  }

  .deckHelpNote {
    display: none !important;
  }

  .footer.footerBar {
    display: none;
  }

  .keyboardHelpBlock {
    display: none !important;
  }

  .miniHelpDesktopOnly {
    display: none !important;
  }

  .headerCompact {
    padding: 8px 10px 10px;
  }

  .headerCompact .stats.statsRow {
    margin-top: 2px;
    padding-top: 6px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
    justify-items: stretch;
  }

  .headerCompact .stats.statsRow > .stat {
    min-width: 0;
    width: 100%;
  }

  .headerCompact .stats.statsRow > a.btn,
  .headerCompact .stats.statsRow > button.btn {
    display: flex !important;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    font-size: 12px;
    justify-content: center !important;
    align-items: center !important;
    text-align: center;
    padding: 8px 6px;
  }

  .stats.statsRow,
  .phraseToolbar-stats {
    gap: 5px;
    row-gap: 6px;
  }

  .stat {
    min-width: 58px;
    padding: 6px 7px;
  }

  .phrasePage .phraseToolbar,
  .deckPage .phraseToolbar {
    margin-top: 0;
    padding-top: 4px;
    gap: 4px;
  }

  .phrasePage .phraseToolbar-stats,
  .deckPage .phraseToolbar-stats {
    flex-wrap: nowrap;
    justify-content: center;
    gap: 5px;
    width: 100%;
  }

  .phrasePage .phraseToolbar-stats .stat,
  .deckPage .phraseToolbar-stats .stat {
    flex: 1 1 0;
    min-width: 0;
    padding: 6px 4px;
  }

  .phrasePage .phraseToolbar-stats .statLabel,
  .deckPage .phraseToolbar-stats .statLabel {
    font-size: 9px;
  }

  .phrasePage .phraseToolbar-stats .statValue,
  .deckPage .phraseToolbar-stats .statValue {
    font-size: 13px;
  }

  body.deckPage .phraseToolbar-actions,
  body.phrasePage .phraseToolbar-actions,
  body.writingPage .phraseToolbar-actions {
    justify-content: center;
    padding: 2px 0 6px;
    overflow: visible;
  }

  body.deckPage .phraseToolbar-actionsInner,
  body.phrasePage .phraseToolbar-actionsInner,
  body.writingPage .phraseToolbar-actionsInner {
    gap: 5px 4px;
  }

  body.deckPage .phraseToolbar-actionsInner .phraseToolbar-nav,
  body.phrasePage .phraseToolbar-actionsInner .phraseToolbar-nav,
  body.writingPage .phraseToolbar-actionsInner .phraseToolbar-nav {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
  }

  body.deckPage .phraseToolbar-actionsInner .phraseToolbar-nav > a.btn,
  body.deckPage .phraseToolbar-actionsInner .phraseToolbar-nav > button.btn,
  body.phrasePage .phraseToolbar-actionsInner .phraseToolbar-nav > a.btn,
  body.phrasePage .phraseToolbar-actionsInner .phraseToolbar-nav > button.btn,
  body.writingPage .phraseToolbar-actionsInner .phraseToolbar-nav > a.btn,
  body.writingPage .phraseToolbar-actionsInner .phraseToolbar-nav > button.btn {
    min-height: 34px;
    font-size: 11px;
    font-weight: 650;
    padding: 6px 8px;
    line-height: 1.15;
  }

  body.writingPage .headerCompact .stats.writingStats {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: 280px;
    margin-inline: auto;
  }

  body.writingPage .headerCompact .stats.writingStats > .stat {
    flex: 1 1 0;
    min-width: 0;
  }

  .btnSm {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 14px;
  }

  .topicSectionGrid {
    grid-template-columns: 1fr;
  }

  .topicSectionHead {
    text-align: center;
    margin-left: auto;
    margin-right: auto;
  }

  .studyRow {
    margin-bottom: 10px;
    width: 100%;
    max-width: 100%;
    padding: 0 2px;
  }

  .studyControlBar {
    width: 100%;
    max-width: 100%;
    gap: 10px;
  }

  .studyHint {
    min-width: 0;
  }

  .navBtn {
    min-width: 0;
  }

  .topicDropMenu {
    min-width: 100%;
  }

  .studyControlBar {
    display: flex !important;
    width: 100%;
    max-width: 100%;
    gap: 8px;
  }

  .studyControlBar .studyFlipBtn,
  .studyControlBar .studyNextBtn,
  .studyControlBar #stepBtn {
    display: inline-flex !important;
    min-height: 44px;
    font-size: 15px;
  }

  .studyControlBar--solo .studyNextBtn,
  .studyControlBar--solo #stepBtn {
    width: min(140px, 40%);
    min-width: 100px;
  }

  body.phrasePage .studyPanel[aria-label="Sentence flashcards"] .studyControlBar--solo {
    justify-content: center;
    width: 100%;
  }

  body.phrasePage .studyPanel[aria-label="Sentence flashcards"] .studyControlBar--solo #stepBtn {
    width: auto;
    max-width: none;
  }

  .topicDropBtn {
    min-height: 44px;
    font-size: 14px;
  }

  .topicDropItem {
    min-height: 44px;
    padding: 12px;
  }

  .topicDropMenu {
    max-height: min(280px, 50dvh);
  }

  .btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .studyPanel > .flashcardStage {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    padding-inline: max(8px, env(safe-area-inset-left, 0px)) max(8px, env(safe-area-inset-right, 0px));
    box-sizing: border-box;
  }

  .flashcardStage {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 100%;
    min-height: min(320px, 46svh);
    padding: 6px 0 4px;
    overflow: visible;
  }

  .flashcardHit {
    touch-action: manipulation;
    display: block;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    border-radius: 20px;
  }

  .flashcard3d {
    width: 100%;
    perspective: 1200px;
    border-radius: 20px;
    overflow: visible;
  }

  .flashcard3d:has(.flashcardInner.isFlipped) {
    box-shadow:
      0 0 0 1px rgba(94, 207, 154, 0.35),
      0 12px 32px rgba(0, 0, 0, 0.45),
      0 0 40px rgba(94, 207, 154, 0.12);
  }

  .flashcardInner {
    width: 100%;
    min-height: min(280px, 42svh);
    height: min(360px, 52svh);
    max-height: min(400px, 56svh);
    aspect-ratio: auto;
    border-radius: 20px;
    transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .flashFace {
    padding: clamp(16px, 4vw, 28px);
    border-radius: 20px;
  }

  .flashFaceFront {
    transform: rotateY(0deg) translateZ(2px);
    -webkit-transform: rotateY(0deg) translateZ(2px);
  }

  .flashFaceBack {
    transform: rotateY(180deg) translateZ(2px);
    -webkit-transform: rotateY(180deg) translateZ(2px);
  }

  .flashFace .flashWord {
    transform: translateZ(3px);
  }

  .phrasePage .flashcardStage {
    min-height: min(300px, 44svh);
    padding-top: 4px;
  }

  .phrasePage .flashcardHit {
    width: 100%;
    max-width: 100%;
  }

  .phrasePage .flashcardInner {
    min-height: min(260px, 40svh);
    height: min(340px, 50svh);
    max-height: min(380px, 54svh);
    transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .flashWord {
    font-size: clamp(20px, 5.5vw, 32px);
    padding: 0 clamp(12px, 3.5vw, 20px);
    line-height: 1.18;
  }

  body.phrasePage .flashFace .flashWord {
    font-size: clamp(15px, 4vw, 22px);
    line-height: 1.24;
    letter-spacing: -0.02em;
    padding: 0 clamp(10px, 3vw, 16px);
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: normal;
    hyphens: none !important;
    -webkit-hyphens: none !important;
    -moz-hyphens: none !important;
  }

  .flashLabel {
    top: 10px;
    left: 10px;
    font-size: 9px;
  }

  .flashCornerTag {
    bottom: 10px;
    right: 10px;
    font-size: 10px;
    padding: 3px 8px;
  }

  body.matchingPage .app,
  body.matchingPage .matchPanel {
    max-width: 100%;
    min-width: 0;
  }

  body.writingPage .app,
  body.writingPage .writePanel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .miniHelp {
    font-size: 11px;
    margin-top: 6px;
  }

  .phraseToolbar-rows {
    flex-direction: column;
    gap: 8px;
  }

  .phraseToolbar-sep {
    display: none !important;
  }

  .btnCluster {
    width: 100%;
    max-width: 100%;
    justify-content: center;
  }

  /* Flip/Next in header / phrase toolbar (saved, hidden lists, etc.) */
  .statsRow .navBtn.primary,
  .statsRow #stepBtn,
  .phraseToolbar-rows .navBtn.primary,
  .phraseToolbar-rows #stepBtn {
    min-height: 48px;
    padding-left: 16px;
    padding-right: 16px;
  }
}

@media (max-width: 480px) {
  body {
    padding-left: max(6px, env(safe-area-inset-left, 0px));
    padding-right: max(6px, env(safe-area-inset-right, 0px));
  }

  .panel {
    padding: 8px 6px;
  }

  .studyPanel > .flashcardStage {
    padding-inline: max(6px, env(safe-area-inset-left, 0px)) max(6px, env(safe-area-inset-right, 0px));
  }

  .flashcardHit {
    width: 100%;
    max-width: 100%;
  }

  .flashcardInner {
    min-height: min(260px, 40svh);
    height: min(340px, 50svh);
    max-height: min(380px, 54svh);
  }

  .phrasePage .flashcardInner {
    min-height: min(240px, 38svh);
    height: min(320px, 48svh);
    max-height: min(360px, 52svh);
  }

  .flashWord {
    font-size: clamp(18px, 5.2vw, 28px);
  }

  body.phrasePage .flashFace .flashWord {
    font-size: clamp(14px, 3.8vw, 20px);
  }

  body.deckPage .phraseToolbar-actionsInner .phraseToolbar-nav > a.btn,
  body.deckPage .phraseToolbar-actionsInner .phraseToolbar-nav > button.btn,
  body.phrasePage .phraseToolbar-actionsInner .phraseToolbar-nav > a.btn,
  body.phrasePage .phraseToolbar-actionsInner .phraseToolbar-nav > button.btn {
    min-height: 32px;
    font-size: 10px;
    padding: 5px 7px;
  }

  body.matchingPage .matchList {
    grid-template-rows: repeat(5, minmax(60px, 1fr));
    gap: 8px;
  }

  body.matchingPage .matchChoice {
    min-height: 60px;
    padding: 10px 8px;
  }

  body.matchingPage .matchText {
    font-size: clamp(14px, 3.6vw, 17px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .flashcardInner {
    transition: transform 0.25s linear;
  }

  .flashcardInner.isFlipped {
    transform: rotateY(180deg);
    -webkit-transform: rotateY(180deg);
  }

  .flashcard3d:has(.flashcardInner.isFlipped) {
    box-shadow: none;
  }
}

/* ——— Matching cards (Duolingo-style) ——— */
body.matchingPage .app {
  width: min(820px, 100%);
}

/* White game island on dark matching page */
body.matchingPage .matchPanel {
  --match-text: rgba(22, 26, 34, 0.92);
  --match-muted: rgba(88, 96, 112, 0.86);
  --match-border: rgba(22, 28, 40, 0.1);
  --match-border-strong: rgba(22, 28, 40, 0.14);
  --match-surface: #f6f7f9;
  --match-surface-hover: #eef0f4;

  width: 100%;
  padding: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #fafbfc 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 28px 64px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  color: var(--match-text);
}

body.matchingPage .matchPanel .muted {
  color: var(--match-muted);
}

body.matchingPage .matchPanel .btn {
  background: #ffffff;
  color: var(--match-text);
  border-color: var(--match-border-strong);
}

body.matchingPage .matchPanel .btn:hover {
  background: var(--match-surface-hover);
  border-color: rgba(180, 130, 50, 0.35);
}

body.matchingPage .matchPanel .matchTopicBar,
body.matchingPage .matchPanel .matchTopRow,
body.matchingPage .matchPanel .matchStat,
body.matchingPage .matchPanel .matchEmpty,
body.matchingPage .matchPanel .matchChoice,
body.matchingPage .matchPanel .matchColTitle,
body.matchingPage .matchPanel .matchToast,
body.matchingPage .matchPanel .matchStatValue {
  color: var(--match-text);
}

.matchTopicBar {
  padding: 14px 14px 12px;
  margin: -2px -2px 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, #f8f9fc 0%, #f0f2f6 100%);
  border: 1px solid var(--match-border);
  box-shadow: 0 4px 14px rgba(22, 28, 40, 0.05);
}

.matchTopicBarMain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}

.matchTopicLabel {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--match-muted, var(--muted));
  flex: 0 0 auto;
}

.matchTopicSelectWrap {
  position: relative;
  flex: 1 1 220px;
  min-width: min(100%, 280px);
}

.matchTopicSelectWrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid rgba(22, 26, 34, 0.4);
  border-bottom: 2px solid rgba(22, 26, 34, 0.4);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.matchTopicSelect {
  appearance: none;
  width: 100%;
  padding: 12px 40px 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--match-border-strong, rgba(22, 28, 40, 0.14));
  background: linear-gradient(180deg, #ffffff 0%, #f6f7f9 100%);
  color: var(--match-text, rgba(22, 26, 34, 0.92));
  font: inherit;
  font-size: 15px;
  font-weight: 750;
  letter-spacing: -0.02em;
  cursor: pointer;
  box-shadow:
    0 4px 12px rgba(22, 28, 40, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease,
    background 140ms ease;
}

.matchTopicSelect:hover {
  border-color: rgba(180, 130, 50, 0.4);
}

.matchTopicSelect:focus-visible {
  outline: none;
  border-color: rgba(180, 130, 50, 0.55);
  box-shadow:
    0 0 0 4px rgba(212, 168, 83, 0.16),
    0 4px 12px rgba(22, 28, 40, 0.06);
}

.matchTopicBlurb {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.45;
  max-width: 42rem;
}

.matchTopicPool {
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--good);
}

.matchEmpty {
  padding: 28px 18px;
  text-align: center;
  border-radius: 14px;
  border: 1px dashed var(--match-border-strong, rgba(22, 28, 40, 0.14));
  background: rgba(246, 247, 249, 0.9);
  margin-bottom: 8px;
}

.matchEmptyTitle {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 850;
  letter-spacing: -0.02em;
  color: var(--match-text, rgba(22, 26, 34, 0.92));
}

.matchEmptyText {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  max-width: 28rem;
  margin-left: auto;
  margin-right: auto;
}

.matchPlayArea {
  display: block;
}

.matchTopRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--match-border, rgba(22, 28, 40, 0.1));
  margin-bottom: 12px;
}

.matchStats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.matchStat {
  padding: 8px 10px;
  border-radius: 14px;
  background: var(--match-surface, #f6f7f9);
  border: 1px solid var(--match-border, rgba(22, 28, 40, 0.1));
  min-width: 110px;
}

.matchStatLabel {
  font-size: 11px;
  color: var(--match-muted, rgba(88, 96, 112, 0.86));
}

.matchStatValue {
  font-size: 16px;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
}

.matchControls {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.matchGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.matchCol {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.matchColHead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 2px;
}

.matchColTitle {
  font-weight: 850;
  letter-spacing: -0.02em;
}

.matchColHint {
  font-size: 12px;
}

.matchList {
  display: grid;
  grid-template-rows: repeat(5, minmax(66px, 1fr));
  gap: 10px;
}

.matchChoice {
  appearance: none;
  border: 2px solid var(--match-border, rgba(22, 28, 40, 0.1));
  background: linear-gradient(180deg, #ffffff 0%, #f8f9fc 100%);
  box-shadow:
    0 6px 16px rgba(22, 28, 40, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.85);
  border-radius: 14px;
  padding: 14px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  color: var(--match-text, rgba(22, 26, 34, 0.92));
  text-align: left;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    box-shadow 140ms ease,
    opacity 220ms ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.matchChoice:hover {
  transform: translateY(-1px);
  border-color: rgba(180, 130, 50, 0.32);
  background: linear-gradient(180deg, #ffffff 0%, #faf8f4 100%);
  box-shadow:
    0 8px 20px rgba(22, 28, 40, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.matchChoice:active {
  transform: translateY(0px);
}

.matchChoice:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(212, 168, 83, 0.18);
  border-color: rgba(180, 130, 50, 0.45);
}

.matchNum {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: rgba(22, 26, 34, 0.88);
  background: linear-gradient(180deg, #f8f9fc 0%, #e8ecf2 100%);
  border: 1px solid var(--match-border-strong, rgba(22, 28, 40, 0.12));
  flex: 0 0 auto;
}

.matchText {
  font-weight: 850;
  letter-spacing: -0.02em;
  line-height: 1.12;
  font-size: 18px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.matchChoice.isSelected {
  border-color: rgba(180, 130, 50, 0.48);
  box-shadow:
    0 0 0 4px rgba(212, 168, 83, 0.14),
    0 6px 16px rgba(22, 28, 40, 0.06);
  background:
    radial-gradient(140% 85% at 0% 0%, rgba(212, 168, 83, 0.12), transparent 56%),
    linear-gradient(180deg, #ffffff 0%, #faf7f0 100%);
  color: var(--match-text, rgba(22, 26, 34, 0.92));
}

.matchChoice.isCorrect {
  border-color: rgba(18, 140, 85, 0.55);
  box-shadow:
    0 0 0 4px rgba(40, 200, 140, 0.18),
    0 16px 34px rgba(20, 140, 90, 0.12),
    0 0 0 1px rgba(255, 255, 255, 0.65) inset;
  background:
    radial-gradient(140% 95% at 0% 0%, rgba(40, 200, 140, 0.35), transparent 58%),
    linear-gradient(180deg, rgba(230, 255, 242, 1), rgba(205, 250, 226, 0.98));
  color: rgba(10, 45, 28, 0.92);
}

.matchChoice.isWrong {
  border-color: rgba(200, 72, 58, 0.55);
  box-shadow:
    0 0 0 4px rgba(235, 90, 75, 0.16),
    0 16px 34px rgba(190, 55, 45, 0.12),
    0 0 0 1px rgba(255, 255, 255, 0.65) inset;
  background:
    radial-gradient(140% 95% at 0% 0%, rgba(235, 100, 85, 0.38), transparent 58%),
    linear-gradient(180deg, rgba(255, 236, 232, 1), rgba(255, 218, 212, 0.98));
  color: rgba(72, 18, 12, 0.92);
}

.matchChoice.isWrong .matchNum {
  color: rgba(72, 18, 12, 0.9);
  background: linear-gradient(180deg, #fff0ee 0%, #ffd4cc 100%);
  border-color: rgba(200, 72, 58, 0.22);
}

.matchChoice.isCorrect .matchNum {
  color: rgba(10, 45, 28, 0.9);
  background: linear-gradient(180deg, #eefff6 0%, #c8f5dc 100%);
  border-color: rgba(18, 140, 85, 0.22);
}

.matchChoice.isFading {
  opacity: 0.2;
  transform: translateY(2px) scale(0.99);
}

@keyframes matchShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  50% {
    transform: translateX(6px);
  }
  75% {
    transform: translateX(-4px);
  }
}

.matchChoice.isShake {
  animation: matchShake 220ms ease;
}

.matchToastRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  min-height: 22px;
}

.matchToast {
  font-weight: 850;
  letter-spacing: -0.01em;
  color: var(--match-text, rgba(22, 26, 34, 0.92));
}

.matchKeyHint {
  font-size: 12px;
}

/* Desktop: preserve pre-mobile layouts (≥769px only; mobile rules stay in max-width blocks). */
@media (min-width: 769px) {
  .studyControlBar--solo {
    width: 100%;
    justify-content: center;
  }

  .studyControlBar--solo .studyNextBtn,
  .studyControlBar--solo #stepBtn {
    flex: 0 0 auto;
    width: auto;
    min-width: 110px;
    max-width: none;
  }

  /* Matching desktop test: cleaner board, larger tiles */
  body.matchingPage .app {
    width: min(900px, 100%);
  }

  body.matchingPage .matchTopRow {
    display: none;
  }

  body.matchingPage .matchGrid {
    gap: 14px;
  }

  body.matchingPage .matchList {
    grid-template-rows: repeat(5, minmax(84px, 1fr));
    gap: 12px;
  }

  body.matchingPage .matchChoice {
    min-height: 84px;
    padding: 16px 14px;
    gap: 14px;
    border-radius: 16px;
  }

  body.matchingPage .matchNum {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  body.matchingPage .matchText {
    font-size: 20px;
    line-height: 1.15;
  }
}

@media (max-width: 768px) {
  .matchTopicBarMain {
    flex-direction: column;
    align-items: stretch;
  }
  .matchTopicSelectWrap {
    flex: 1 1 auto;
    min-width: 0;
  }
  .matchGrid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    min-width: 0;
  }

  .matchCol {
    min-width: 0;
  }

  .matchColHead {
    justify-content: center;
    padding: 0 1px;
  }

  .matchColTitle {
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  body.matchingPage .matchTopRow {
    display: none;
  }

  body.matchingPage .matchToastRow {
    display: none;
  }

  body.matchingPage .matchPanel {
    padding: 10px 8px;
  }

  body.matchingPage .matchGrid {
    gap: 8px;
  }

  body.matchingPage .matchList {
    grid-template-rows: repeat(5, minmax(68px, 1fr));
    gap: 9px;
  }

  body.matchingPage .matchChoice {
    min-height: 68px;
    padding: 11px 9px;
    gap: 0;
    border-radius: 12px;
    justify-content: center;
  }

  body.matchingPage .matchNum {
    display: none;
  }

  body.matchingPage .matchText {
    font-size: clamp(15px, 3.8vw, 18px);
    font-weight: 800;
    line-height: 1.2;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow-wrap: anywhere;
  }

  body.matchingPage .matchChoice.isCorrect {
    border-color: rgba(12, 130, 72, 0.78);
    box-shadow:
      0 0 0 4px rgba(34, 190, 120, 0.32),
      0 10px 24px rgba(16, 120, 72, 0.22),
      0 0 0 1px rgba(255, 255, 255, 0.5) inset;
    background:
      radial-gradient(120% 90% at 50% 0%, rgba(48, 210, 140, 0.55), transparent 62%),
      linear-gradient(180deg, #c8f5dc 0%, #8ee8b8 100%);
    color: rgba(6, 52, 32, 0.96);
  }
}

@media (prefers-reduced-motion: reduce) {
  .matchChoice {
    transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
  }
  .matchChoice:hover {
    transform: none;
  }
  .matchChoice.isShake {
    animation: none;
  }
}

@media (max-width: 768px) {
  .matchTopicSelect {
    min-height: 48px;
    font-size: 16px;
  }

  body.writingPage .header .subtitle {
    display: none !important;
  }

  body.writingPage .stats.statsRow {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* ——— Writing practice ——— */
body.writingPage .app {
  width: min(640px, 100%);
}

body.writingPage .writePanel {
  --write-text: #1a1814;
  --write-muted: #6b6560;
  --write-line: rgba(26, 24, 20, 0.08);
  --write-gold: #c9a04a;
  --write-gold-soft: rgba(201, 160, 74, 0.12);
  --write-green: #2d8a5e;
  --write-green-soft: rgba(45, 138, 94, 0.1);

  padding: 0;
  background: #fcfbfa;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  box-shadow:
    0 32px 80px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(212, 168, 83, 0.06) inset;
  color: var(--write-text);
  overflow: hidden;
}

.writeHeader {
  padding: 18px 22px 0;
  background: linear-gradient(180deg, #ffffff 0%, #fcfbfa 100%);
  border-bottom: 1px solid var(--write-line);
}

.writeProgressTrack {
  height: 3px;
  border-radius: 999px;
  background: rgba(26, 24, 20, 0.06);
  overflow: hidden;
  margin-bottom: 16px;
}

.writeProgressFill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #d4a853 0%, #e8c97a 100%);
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.writeTopRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
}

.writeMeta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.writeStep {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--write-muted);
}

.writeTag {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--write-gold-soft);
  color: #8a6a2e;
  letter-spacing: 0.02em;
  text-transform: lowercase;
}

.writeAttempts {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.writeAttempt {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(26, 24, 20, 0.1);
  transition:
    background 0.25s ease,
    transform 0.25s ease,
    box-shadow 0.25s ease;
}

.writeAttempt.isActive {
  background: var(--write-gold);
  box-shadow: 0 0 0 3px var(--write-gold-soft);
}

.writeAttempt.isSpent {
  background: transparent;
  border: 1.5px solid rgba(26, 24, 20, 0.15);
  box-shadow: none;
}

.writePromptCard {
  margin: 22px 22px 0;
  padding: 22px 24px;
  border-radius: 14px;
  background: #ffffff;
  border: 1px solid var(--write-line);
  box-shadow: 0 2px 12px rgba(26, 24, 20, 0.04);
}

.writePromptLabel {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--write-muted);
  margin-bottom: 12px;
}

.writePromptText {
  margin: 0;
  padding: 0;
  border: none;
  font-family: "DM Sans", ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(21px, 4vw, 27px);
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.03em;
  color: var(--write-text);
}

.writeForm {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 22px 22px;
}

.writeInputLabel {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--write-muted);
}

.writeInput {
  width: 100%;
  min-height: 108px;
  padding: 16px 18px;
  font: inherit;
  font-size: 17px;
  line-height: 1.5;
  letter-spacing: -0.015em;
  color: var(--write-text);
  background: #ffffff;
  border: 1.5px solid var(--write-line);
  border-radius: 12px;
  resize: vertical;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.writeInput::placeholder {
  color: rgba(107, 101, 96, 0.45);
}

.writeInput:focus {
  outline: none;
  border-color: rgba(201, 160, 74, 0.55);
  box-shadow: 0 0 0 3px rgba(201, 160, 74, 0.14);
}

.writeInput:disabled {
  background: #f5f4f2;
  color: var(--write-muted);
  cursor: not-allowed;
}

.writeInput--nudge {
  animation: writeInputNudge 0.42s ease;
}

@keyframes writeInputNudge {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-4px);
  }
  40% {
    transform: translateX(4px);
  }
  60% {
    transform: translateX(-3px);
  }
  80% {
    transform: translateX(3px);
  }
}

.writeFormActions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

body.writingPage .writePanel .writeSubmitBtn {
  flex: 1;
  min-height: 48px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #1f1808;
  background: linear-gradient(180deg, #e8c97a 0%, #d4a853 100%);
  border: 1px solid rgba(180, 130, 40, 0.35);
  box-shadow: 0 4px 14px rgba(201, 160, 74, 0.25);
}

body.writingPage .writePanel .writeSubmitBtn:hover:not(:disabled) {
  background: linear-gradient(180deg, #f0d48a 0%, #dbb05e 100%);
  border-color: rgba(201, 160, 74, 0.5);
}

body.writingPage .writePanel .writeSubmitBtn:disabled {
  opacity: 0.45;
  transform: none;
  box-shadow: none;
}

body.writingPage .writePanel .writeContinueBtn {
  flex: 1;
  min-height: 48px;
  font-size: 15px;
  font-weight: 700;
  color: var(--write-green);
  background: #ffffff;
  border: 1.5px solid rgba(45, 138, 94, 0.35);
}

body.writingPage .writePanel .writeContinueBtn:hover {
  background: var(--write-green-soft);
  border-color: rgba(45, 138, 94, 0.5);
}

/* Coach panel (hints, success, answer) */
.writeCoach {
  margin: 0 22px 22px;
  border-radius: 14px;
  border: 1px solid var(--write-line);
  background: #ffffff;
  box-shadow: 0 4px 20px rgba(26, 24, 20, 0.05);
  overflow: hidden;
  animation: writeCoachIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes writeCoachIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.writeCoachMain {
  display: flex;
  gap: 14px;
  padding: 16px 18px;
  align-items: flex-start;
}

.writeCoachIcon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--write-gold-soft);
  position: relative;
}

.writeCoachIcon::after {
  font-size: 18px;
  line-height: 1;
}

.writeCoachIcon--hint {
  background: rgba(201, 160, 74, 0.14);
}

.writeCoachIcon--hint::after {
  content: "◆";
  font-size: 11px;
  color: var(--write-gold);
}

.writeCoachIcon--success {
  background: var(--write-green-soft);
}

.writeCoachIcon--success::after {
  content: "✓";
  font-size: 17px;
  font-weight: 800;
  color: var(--write-green);
}

.writeCoachIcon--answer {
  background: rgba(45, 138, 94, 0.12);
}

.writeCoachIcon--answer::after {
  content: "→";
  font-size: 16px;
  font-weight: 700;
  color: var(--write-green);
}

.writeCoachCopy {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
}

.writeCoachEyebrow {
  margin: 0 0 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--write-muted);
}

.writeCoachTitle {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.3;
  color: var(--write-text);
}

.writeCoachList {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.writeCoachList li {
  position: relative;
  padding-left: 14px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--write-muted);
}

.writeCoachList li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--write-gold);
  opacity: 0.75;
}

.writeCoachNote {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--write-muted);
}

.writeCoachAnswer {
  padding: 14px 18px 16px;
  border-top: 1px solid rgba(45, 138, 94, 0.15);
  background: linear-gradient(180deg, #f8fcfa 0%, #f0f8f4 100%);
}

.writeCoachAnswerLabel {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(45, 138, 94, 0.85);
}

.writeCoachAnswerText {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.02em;
  color: var(--write-text);
}

.writeCoach--hint {
  border-color: rgba(201, 160, 74, 0.22);
}

.writeCoach--hint .writeCoachEyebrow {
  color: #9a7330;
}

.writeCoach--hint .writeCoachTitle {
  color: #3d3420;
}

.writeRevealBtn {
  flex-shrink: 0;
  align-self: flex-start;
  width: 64px;
  height: 64px;
  margin-top: 2px;
  padding: 6px;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.15;
  text-align: center;
  color: #ffffff;
  background: linear-gradient(180deg, #3a9d6a 0%, var(--write-green) 100%);
  box-shadow: 0 4px 12px rgba(45, 138, 94, 0.35);
  cursor: pointer;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    opacity 0.15s ease;
}

.writeRevealBtn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(45, 138, 94, 0.45);
}

.writeRevealBtn:active:not(:disabled) {
  transform: translateY(0);
}

.writeRevealBtn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.writeCoach--success {
  border-color: rgba(45, 138, 94, 0.28);
}

.writeCoach--success .writeCoachEyebrow {
  color: var(--write-green);
}

.writeCoach--success .writeCoachTitle {
  color: var(--write-green);
}

.writeCoach--answer {
  border-color: rgba(45, 138, 94, 0.22);
}

.writeCoach--answerOnly .writeCoachMain {
  display: none;
}

.writeAnswerBox {
  margin: 0 18px 12px;
  padding: 18px 20px;
  border-radius: 12px;
  background: linear-gradient(180deg, #eef9f2 0%, #dff3e8 100%);
  border: 1.5px solid rgba(45, 138, 94, 0.4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.writeAnswerBoxText {
  margin: 0;
  font-size: clamp(19px, 4vw, 23px);
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: -0.02em;
  color: #1a4d32;
}

.writeCoach--answerOnly > .writeCoachNote {
  margin: 0;
  padding: 0 20px 18px;
  font-size: 13px;
  color: var(--write-muted);
}

.writeCoach--answerOnly {
  border-color: rgba(45, 138, 94, 0.28);
}

.writeCoach--answerOnly .writeAnswerBox {
  margin-top: 18px;
}

@media (max-width: 768px) {
  body.writingPage .writePanel {
    border-radius: 16px;
  }

  .writeHeader,
  .writeForm {
    padding-left: 16px;
    padding-right: 16px;
  }

  .writePromptCard {
    margin-left: 16px;
    margin-right: 16px;
    padding: 18px;
  }

  .writeCoach {
    margin-left: 16px;
    margin-right: 16px;
    margin-bottom: 16px;
  }

  .writeAnswerBox {
    margin-left: 16px;
    margin-right: 16px;
  }

  .writeFormActions {
    flex-direction: column;
  }

  body.writingPage .writePanel .writeSubmitBtn,
  body.writingPage .writePanel .writeContinueBtn {
    width: 100%;
    min-height: 50px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .writeProgressFill {
    transition: none;
  }

  .writeCoach,
  .writeInput--nudge {
    animation: none;
  }
}
