/* ==========================================================================
   Kartička — immersive, minimal flashcards
   Dark-first, mobile-first. SVG-driven layout with a full-screen card and
   a slide-out settings/filter panel (bottom sheet on mobile, side panel
   on desktop).
   ========================================================================== */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;

  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 24px;
  --radius-full: 999px;

  --ease: cubic-bezier(0.22, 0.7, 0.3, 1);
  --speed: 0.22s;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --topbar-h: 60px;
}

:root[data-theme="dark"] {
  --bg: #08101f;
  --bg-glow: radial-gradient(120% 62% at 50% 12%, rgba(38, 84, 128, 0.55) 0%, rgba(20, 42, 70, 0.28) 42%, transparent 72%);
  --bg-ambient: radial-gradient(90% 90% at 82% 88%, rgba(20, 60, 110, 0.18), transparent 55%),
                radial-gradient(80% 80% at 12% 90%, rgba(60, 40, 90, 0.12), transparent 55%);

  --surface: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.06);
  --surface-3: rgba(255, 255, 255, 0.08);
  --surface-solid: #121a2c;

  --text: #eaf2fc;
  --text-soft: #a3b3d0;
  --text-faint: #7180a0;

  --accent: #58a6ef;
  --accent-strong: #77b9ff;
  --accent-contrast: #071120;
  --accent-soft: rgba(88, 166, 239, 0.16);

  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --hairline: rgba(255, 255, 255, 0.07);

  --shadow-card: 0 30px 80px -30px rgba(0, 0, 0, 0.8);
  --shadow-pop: 0 20px 60px -20px rgba(0, 0, 0, 0.7);
  --ring: rgba(88, 166, 239, 0.65);
  --toast-bg: #eaf2fc;
  --toast-text: #071120;
  --fav: #f5c451;
  --fav-bg: rgba(245, 196, 81, 0.16);
  --chip-bg: rgba(255, 255, 255, 0.05);
  --chip-border: rgba(255, 255, 255, 0.12);
  --overlay: rgba(3, 7, 16, 0.62);
}

:root[data-theme="light"] {
  --bg: #eef2f9;
  --bg-glow: radial-gradient(120% 62% at 50% 12%, rgba(150, 190, 235, 0.5) 0%, rgba(210, 225, 245, 0.22) 45%, transparent 72%);
  --bg-ambient: radial-gradient(90% 90% at 82% 88%, rgba(120, 170, 230, 0.14), transparent 55%),
                radial-gradient(80% 80% at 12% 90%, rgba(170, 150, 220, 0.1), transparent 55%);

  --surface: rgba(255, 255, 255, 0.6);
  --surface-2: rgba(255, 255, 255, 0.74);
  --surface-3: rgba(20, 40, 80, 0.06);
  --surface-solid: #ffffff;

  --text: #16233c;
  --text-soft: #53617e;
  --text-faint: #8795b0;

  --accent: #1f6fce;
  --accent-strong: #0f5bb3;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(31, 111, 206, 0.1);

  --border: rgba(20, 45, 90, 0.1);
  --border-strong: rgba(20, 45, 90, 0.16);
  --hairline: rgba(20, 45, 90, 0.08);

  --shadow-card: 0 24px 60px -26px rgba(30, 50, 100, 0.35);
  --shadow-pop: 0 18px 50px -20px rgba(30, 50, 100, 0.4);
  --ring: rgba(31, 111, 206, 0.5);
  --toast-bg: #16233c;
  --toast-text: #f4f7fd;
  --fav: #d99a06;
  --fav-bg: rgba(217, 154, 6, 0.14);
  --chip-bg: #ffffff;
  --chip-border: rgba(20, 45, 90, 0.14);
  --overlay: rgba(20, 30, 55, 0.35);
}

/* ---------- base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

/* A closed <dialog> must never stay rendered — class display rules (e.g.
   .menu-dialog { display:flex }) must not keep the sheet on screen after
   it has been closed, or it would cover the card. */
dialog:not([open]) {
  display: none !important;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-glow), var(--bg-ambient);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  transition: color 0.3s ease, background-color 0.3s ease;
}

h1, h2, h3, p {
  margin: 0;
}

button {
  font-family: inherit;
}

:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
  border-radius: var(--radius-s);
}

.skip-link {
  position: fixed;
  top: -100px;
  left: var(--space-4);
  z-index: 200;
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius-s);
  text-decoration: none;
  font-weight: 700;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: auto;
}

/* ---------- stage (immersive full-screen canvas) ---------- */

.stage {
  position: relative;
  height: 100dvh;
  overflow: hidden;
}

.stage-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: clamp(12px, 3.2vw, 22px) clamp(14px, 4vw, 28px);
  padding-right: 76px; /* clear the absolute favorite star */
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding-top: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  background: var(--surface-3);
  color: var(--text-soft);
  border: 1px solid var(--hairline);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.badge-level-a1 { color: #5fd39a; }
.badge-level-a2 { color: #55c4d6; }
.badge-level-b1 { color: #7fb3ff; }
.badge-level-b2 { color: #b79aff; }
.badge-level-c1 { color: #ff9a69; }
:root[data-theme="light"] .badge-level-a1 { color: #0c8a52; }
:root[data-theme="light"] .badge-level-a2 { color: #0c7d8c; }
:root[data-theme="light"] .badge-level-b1 { color: #0b5bb0; }
:root[data-theme="light"] .badge-level-b2 { color: #6a3fb5; }
:root[data-theme="light"] .badge-level-c1 { color: #c2410c; }

.topbar-actions {
  display: flex;
  gap: var(--space-2);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-full);
  background: var(--surface-3);
  color: var(--text-soft);
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: background var(--speed) ease, color var(--speed) ease, border-color var(--speed) ease, transform 0.1s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn svg {
  width: 19px;
  height: 19px;
}

.icon-btn-accent {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.icon-sun {
  display: none;
}

:root[data-theme="dark"] .icon-sun {
  display: block;
}

:root[data-theme="dark"] .icon-moon {
  display: none;
}

.btn-fav {
  position: absolute;
  top: clamp(14px, 3.4vw, 24px);
  right: clamp(14px, 4vw, 28px);
  z-index: 21;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-full);
  background: var(--surface-3);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--text-faint);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  transition: all var(--speed) ease;
}

.btn-fav:hover {
  color: var(--fav);
  border-color: var(--fav);
}

.btn-fav.is-favorite {
  color: var(--fav);
  background: var(--fav-bg);
  border-color: transparent;
}

/* card area */

.stage-center {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr;
  place-items: center;
  /* Kept as separate longhand properties: a shorthand with calc()+env()
     inside was not applied by the browser and left the padding at 0. */
  padding-top: calc(var(--topbar-h) + 12px);
  padding-inline: var(--space-4);
  padding-bottom: max(116px, env(safe-area-inset-bottom));
}

.card {
  position: relative;
  width: min(100%, 760px);
  height: 100%;
  max-height: 740px;
  perspective: 1600px;
}

/* CEFR level chip pinned to the card's top-left corner. */
.card-level {
  position: absolute;
  top: clamp(12px, 2.6vw, 20px);
  left: clamp(14px, 3vw, 24px);
  z-index: 6;
  background: var(--surface-3);
  border: 1px solid var(--hairline);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

/* Entry animation (randomised) when the card is shown. */
.card.card-enter-1 { animation: cardInRight 0.45s var(--ease); }
.card.card-enter-2 { animation: cardInScale 0.45s var(--ease); }
.card.card-enter-3 { animation: cardInUp 0.45s var(--ease); }

@keyframes cardInRight {
  from { opacity: 0; transform: translateX(56px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes cardInScale {
  from { opacity: 0; transform: scale(0.94); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes cardInUp {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-flip-zone {
  position: absolute;
  inset: 0;
  z-index: 0;
  border: none;
  background: transparent;
  border-radius: var(--radius-l);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.card-inner {
  position: absolute;
  inset: 0;
  z-index: 1;
  transform-style: preserve-3d;
  transition: transform 0.6s var(--ease);
  border-radius: var(--radius-l);
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(var(--space-5), 6vh, var(--space-7, 48px));
  border-radius: var(--radius-l);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface) 0%, rgba(255, 255, 255, 0.02) 100%);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-card);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.card-face::-webkit-scrollbar {
  display: none;
}

.card-back {
  background: linear-gradient(180deg, var(--surface-2) 0%, rgba(255, 255, 255, 0.03) 100%);
  transform: rotateY(180deg);
}

.card:has(.card-flip-zone:focus-visible) .card-inner {
  box-shadow: 0 0 0 4px var(--ring), var(--shadow-card);
}

/* front face — centered composition */

.card-front {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.front-word {
  font-size: clamp(2.5rem, 8vw, 3.8rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--text);
  overflow-wrap: anywhere;
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.25);
}

.front-sentence {
  margin-top: clamp(var(--space-4), 4vh, var(--space-6));
  padding-left: var(--space-4);
  border-left: 3px solid var(--accent);
  text-align: left;
  max-width: 32ch;
  font-size: clamp(1.02rem, 3.4vw, 1.22rem);
  line-height: 1.5;
  color: var(--text-soft);
}

.front-actions {
  display: flex;
  gap: var(--space-3);
  margin-top: clamp(var(--space-5), 6vh, var(--space-6));
  flex-wrap: wrap;
  justify-content: center;
}

.front-hint {
  position: absolute;
  bottom: clamp(16px, 4vh, 32px);
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-faint);
  pointer-events: none;
  user-select: none;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 11px 20px;
  background: var(--surface-3);
  color: var(--text);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: transform 0.1s ease, background var(--speed) ease, color var(--speed) ease, border-color var(--speed) ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.btn-tts:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-tts.is-speaking {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  animation: pulse 1.1s ease infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-soft); }
  50% { box-shadow: 0 0 0 12px transparent; }
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-strong);
  color: var(--accent-contrast);
}

.btn-ghost {
  align-self: center;
  margin-top: auto;
  background: transparent;
  color: var(--text-soft);
  border-color: var(--border-strong);
}

.btn-ghost:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* back face — structured info */

.card-back {
  align-items: stretch;
  text-align: left;
  justify-content: flex-start;
}

.back-word-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}

.back-word {
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 800;
  color: var(--text);
  overflow-wrap: anywhere;
}

.back-transcription {
  font-size: 1rem;
  color: var(--text-faint);
  font-family: var(--font-serif);
  font-style: italic;
  overflow-wrap: anywhere;
}

.back-block {
  margin-bottom: var(--space-4);
}

.back-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 2px;
}

.back-translation {
  font-size: clamp(1.15rem, 4.4vw, 1.45rem);
  font-weight: 700;
  color: var(--text);
  overflow-wrap: anywhere;
}

.back-sentence-translation {
  font-size: 0.98rem;
  color: var(--text-soft);
  overflow-wrap: anywhere;
}

.back-grammar,
.back-notes {
  font-size: 0.86rem;
  color: var(--text-soft);
  margin-bottom: var(--space-3);
  overflow-wrap: anywhere;
}

.back-notes {
  padding: var(--space-3) var(--space-4);
  background: var(--accent-soft);
  border-radius: var(--radius-s);
  color: var(--text);
}

.back-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--space-5);
}

.tag-chip {
  padding: 3px 11px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  border: 1px solid var(--hairline);
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-soft);
}

/* ---------- stage bottom ---------- */

.stage-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4) max(var(--space-4), env(safe-area-inset-bottom));
  pointer-events: none;
}

.progress-label {
  order: 1;
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
  letter-spacing: 0.06em;
  pointer-events: auto;
}

.swipe-hint {
  order: 2;
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  transition: color var(--speed) ease, background var(--speed) ease;
  pointer-events: auto;
}

.swipe-hint svg {
  width: 15px;
  height: 15px;
}

.swipe-hint:hover {
  color: var(--text-soft);
  background: var(--surface-3);
}

/* only show the swipe hint on touch/small screens */
@media (min-width: 641px) {
  .swipe-hint {
    display: none;
  }
}

/* ---------- desktop edge navigation ---------- */

.edge {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  width: 52px;
  height: 72px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-m);
  background: var(--surface-3);
  color: var(--text-soft);
  font-size: 2rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--speed) ease, background var(--speed) ease, color var(--speed) ease;
}

.edge:hover,
.edge:focus-visible {
  opacity: 1;
  background: var(--surface-2);
  color: var(--text);
}

.edge-prev {
  left: max(8px, env(safe-area-inset-left));
}

.edge-next {
  right: max(8px, env(safe-area-inset-right));
}

@media (min-width: 641px) {
  .edge {
    opacity: 1;
  }
}

@media (max-width: 640px) {
  .edge {
    display: none;
  }
}

/* ---------- loading / empty / error ---------- */

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  color: var(--text-faint);
  font-weight: 600;
}

.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  text-align: center;
  width: min(100%, 520px);
  padding: var(--space-6);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-l);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  color: var(--text-soft);
}

.empty-icon {
  font-size: 2.4rem;
}

.empty-state h2 {
  color: var(--text);
  font-size: 1.25rem;
}

.empty-state p {
  margin-bottom: var(--space-3);
}

.error-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background: var(--bg);
  background-image: var(--bg-glow);
}

.error-box {
  max-width: 520px;
  width: 100%;
  padding: var(--space-6);
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-pop);
  text-align: center;
  color: var(--text);
}

.error-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 120, 90, 0.14);
  color: #ff9a69;
  font-size: 1.7rem;
  font-weight: 800;
}

.error-box h1 {
  font-size: 1.35rem;
  margin-bottom: var(--space-3);
}

.error-box p {
  color: var(--text-soft);
  margin-bottom: var(--space-3);
}

.error-tip {
  font-size: 0.88rem;
}

.error-box code {
  background: var(--surface-3);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.9em;
}

.error-box .btn {
  margin-top: var(--space-2);
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 90;
  transform: translate(-50%, 16px);
  max-width: min(90vw, 440px);
  padding: 10px 20px;
  background: var(--toast-bg);
  color: var(--toast-text);
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-pop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s var(--ease);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- menu dialog (settings & filters) ---------- */

.menu-dialog {
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--text);
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: 100%;
  max-height: 88dvh;
  border-radius: 22px 22px 0 0;
  overflow: hidden;
  box-shadow: var(--shadow-pop);
}

.menu-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: calc(var(--space-4) + 12px) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--hairline);
  /* Grabber affordance for the "swipe down to close" gesture. */
}

.menu-head::before {
  content: "";
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 42px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
}

.menu-head h2 {
  font-size: 1.05rem;
}

.menu-body {
  padding: var(--space-4) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom));
  /* As a flex item the body must be allowed to shrink below its content
     height (min-height:auto would prevent it), so tall content scrolls
     instead of being clipped by the dialog. */
  min-height: 0;
  flex: 1 1 auto;
  max-height: calc(88dvh - 64px);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.menu-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.menu-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  border: 1px solid var(--chip-border);
  border-radius: var(--radius-full);
  background: var(--chip-bg);
  color: var(--text-soft);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--speed) ease;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chip.is-active,
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.menu-select-wrap {
  position: relative;
}

.menu-select {
  appearance: none;
  width: 100%;
  padding: 12px 38px 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-m);
  background: var(--surface-3) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m7 10 5 5 5-5' fill='none' stroke='%2399a6c2' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 14px center / 18px;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.menu-select:hover {
  border-color: var(--accent);
}

.menu-action {
  appearance: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-m);
  background: var(--surface-3);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--speed) ease;
}

.menu-action:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.menu-action svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface-3);
  cursor: pointer;
  transition: border-color var(--speed) ease;
}

.switch-row:hover {
  border-color: var(--border-strong);
}

.switch-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.switch {
  appearance: none;
  position: relative;
  width: 46px;
  height: 27px;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  transition: background var(--speed) ease, border-color var(--speed) ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--text-soft);
  transition: transform var(--speed) var(--ease), background var(--speed) ease;
}

.switch:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.switch:checked::after {
  transform: translateX(19px);
  background: var(--accent-contrast);
}

.switch:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

.menu-ghost-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-m);
  background: none;
  color: var(--text-faint);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--speed) ease;
}

.menu-ghost-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.menu-status {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-top: var(--space-2);
  border-top: 1px solid var(--hairline);
}

.menu-status-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.menu-privacy-btn {
  appearance: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 12px 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-m);
  background: none;
  color: var(--text-soft);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all var(--speed) ease;
}

.menu-privacy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.menu-privacy-btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

/* privacy dialog */

.privacy-lead {
  color: var(--text-soft);
  line-height: 1.55;
  margin-bottom: var(--space-4);
}

.privacy-lead strong {
  color: var(--text);
}

.privacy-summary {
  padding: var(--space-3) var(--space-4);
  background: var(--accent-soft);
  border-radius: var(--radius-s);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: var(--space-4);
}

.privacy-body h3 {
  font-size: 1rem;
  margin: var(--space-5) 0 var(--space-2);
}

.privacy-body h3:first-of-type {
  margin-top: var(--space-2);
}

.privacy-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  color: var(--text-soft);
  font-size: 0.92rem;
  line-height: 1.5;
}

.privacy-list li {
  position: relative;
  padding-left: 22px;
}

.privacy-list li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.56em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.75;
}

.privacy-list code {
  background: var(--surface-3);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.9em;
}

.status-tts-btn {
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--accent);
  text-align: left;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
  transition: color var(--speed) ease;
}

.status-tts-btn:hover {
  color: var(--accent-strong);
  text-decoration: underline solid;
}

.status-muted {
  font-size: 0.84rem;
  color: var(--text-faint);
  overflow-wrap: anywhere;
}

/* ---------- generic dialogs ---------- */

.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  background: var(--surface-solid);
  color: var(--text);
  padding: 0;
  width: min(92vw, 560px);
  box-shadow: var(--shadow-pop);
}

.dialog-wide {
  width: min(94vw, 720px);
}

.dialog::backdrop,
.menu-dialog::backdrop {
  background: var(--overlay);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

.dialog[open],
.menu-dialog[open] {
  animation: dialog-in 0.24s var(--ease);
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--hairline);
}

.dialog-head h2 {
  font-size: 1.1rem;
}

.dialog-body {
  padding: var(--space-4) var(--space-5) var(--space-5);
  max-height: 68vh;
  overflow-y: auto;
}

.search-box {
  position: relative;
  margin-bottom: var(--space-3);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 19px;
  height: 19px;
  color: var(--text-faint);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 44px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-m);
  background: var(--surface-3);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color var(--speed) ease, box-shadow var(--speed) ease;
}

.search-input::placeholder {
  color: var(--text-faint);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.search-hint {
  font-size: 0.82rem;
  color: var(--text-faint);
  margin-bottom: var(--space-3);
}

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

.search-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface-3);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  transition: border-color var(--speed) ease, background var(--speed) ease;
}

.search-item:hover,
.search-item.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.search-item-word {
  font-weight: 800;
  font-size: 1rem;
  flex: none;
}

.search-item-translation {
  color: var(--text-soft);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-item .badge {
  flex: none;
}

.search-empty {
  text-align: center;
  color: var(--text-faint);
  padding: var(--space-5) 0;
}

/* help */

.help-body h3 {
  font-size: 1rem;
  margin: var(--space-5) 0 var(--space-2);
}

.help-body h3:first-child {
  margin-top: 0;
}

.help-body p {
  color: var(--text-soft);
  margin-bottom: var(--space-3);
}

.help-body code {
  background: var(--surface-3);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.9em;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-bottom: var(--space-2);
}

.help-table th,
.help-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--hairline);
}

.help-table th {
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.help-table td:first-child {
  font-weight: 700;
  white-space: nowrap;
}

.help-table td:last-child {
  color: var(--text-soft);
}

.help-keys {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  color: var(--text-soft);
  font-size: 0.92rem;
}

kbd {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 7px;
  background: var(--surface-3);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 700;
}

/* voice picker */

.voice-rate-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-soft);
}

.voice-rate-row input[type="range"] {
  flex: 1;
  min-width: 120px;
  accent-color: var(--accent);
  cursor: pointer;
}

.voice-rate-value {
  flex: none;
  min-width: 52px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.voice-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 42vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.voice-group {
  padding: 12px 4px 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.voice-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 7px 8px 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface-3);
  transition: border-color var(--speed) ease, background var(--speed) ease;
}

.voice-item:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.voice-item-main {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.voice-item input[type="radio"] {
  flex: none;
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.voice-name {
  font-weight: 700;
  font-size: 0.93rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-lang {
  flex: none;
  font-size: 0.76rem;
  color: var(--text-faint);
  background: var(--surface-3);
  padding: 1px 8px;
  border-radius: var(--radius-full);
}

.voice-preview {
  appearance: none;
  flex: none;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  background: var(--surface-3);
  color: var(--text-soft);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all var(--speed) ease;
}

.voice-preview:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.voice-preview:active {
  transform: scale(0.92);
}

/* noscript */

.noscript {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background: var(--bg);
  color: var(--text);
  font-weight: 700;
  text-align: center;
}

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  .stage-center {
    padding-top: calc(var(--topbar-h) + 8px);
    padding-inline: var(--space-3);
    padding-bottom: max(128px, env(safe-area-inset-bottom));
  }

  .stage-top {
    padding-right: 64px;
  }

  .btn-fav {
    top: clamp(10px, 3vw, 16px);
  }

  .topbar-actions {
    gap: 6px;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
  }

  .menu-dialog {
    /* bottom sheet: anchored to the bottom, full width */
    inset: auto 0 0 0;
    margin: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 22px 22px 0 0;
  }

  .menu-dialog[open] {
    display: flex;
    flex-direction: column;
  }
}

@media (min-width: 641px) {
  /* menu becomes a side panel anchored top-right */
  .menu-dialog {
    position: fixed;
    top: calc(var(--topbar-h) + 10px);
    right: 20px;
    left: auto;
    bottom: auto;
    width: min(360px, 92vw);
    max-height: calc(100dvh - var(--topbar-h) - 40px);
    border-radius: var(--radius-l);
  }

  .menu-body {
    max-height: calc(100dvh - var(--topbar-h) - 40px - 64px);
  }

  .empty-state {
    width: min(100%, 600px);
  }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .card-inner {
    transition: none;
  }
}
