/* Vocabulary Builder v3 — premium editorial restyle
   Plain CSS, no external dependencies. Mobile-first. */

:root {
  --ink-900: #051a20;
  --ink-800: #07242b;
  --ink-700: #0a2e36;
  --ink-600: #103c46;
  --ink-500: #17505c;
  --gold: #d9b36a;
  --gold-soft: #e8cd92;
  --gold-deep: #b48f48;
  --cream: #f3ead8;
  --cream-dim: #c9c1ae;
  --cream-faint: #8fa7a6;
  --teal: #57c7b8;
  --teal-soft: rgba(87, 199, 184, 0.16);
  --good: #7fcf8f;
  --good-bg: rgba(127, 207, 143, 0.16);
  --bad: #e8736b;
  --bad-bg: rgba(232, 115, 107, 0.16);
  --glass: rgba(243, 234, 216, 0.05);
  --glass-strong: rgba(243, 234, 216, 0.09);
  --line: rgba(243, 234, 216, 0.14);
  --line-gold: rgba(217, 179, 106, 0.45);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.5);
  --font-display: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--cream);
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(87, 199, 184, 0.12), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(217, 179, 106, 0.08), transparent 55%),
    linear-gradient(180deg, var(--ink-700) 0%, var(--ink-800) 40%, var(--ink-900) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img {
  max-width: 100%;
  display: block;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.15;
  margin: 0 0 0.5em;
  color: var(--cream);
  letter-spacing: 0.005em;
}

p {
  margin: 0 0 1em;
}

a {
  color: var(--teal);
  text-decoration-color: rgba(87, 199, 184, 0.45);
  text-underline-offset: 3px;
  transition: color 0.2s var(--ease);
}

a:hover {
  color: var(--gold-soft);
}

::selection {
  background: var(--gold);
  color: var(--ink-900);
}

[hidden] {
  display: none !important;
}

/* Focus */
:focus {
  outline: none;
}

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

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -4rem;
  z-index: 100;
  background: var(--gold);
  color: var(--ink-900);
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
  transition: top 0.2s var(--ease);
}

.skip-link:focus {
  top: 0.75rem;
}

.visually-hidden,
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Layout */
.wrap,
main,
.container {
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: 1rem;
}

main {
  padding-bottom: 4rem;
}

/* Hero */
.hero,
header.hero,
.banner {
  position: relative;
  isolation: isolate;
  margin: 1rem auto 0;
  max-width: 1120px;
  width: calc(100% - 2rem);
  min-height: 220px;
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1.5rem 1.25rem 1.4rem;
  background-color: var(--ink-700);
  background-image:
    linear-gradient(180deg, rgba(5, 26, 32, 0.15) 0%, rgba(5, 26, 32, 0.55) 55%, rgba(5, 26, 32, 0.92) 100%),
    linear-gradient(90deg, rgba(7, 36, 43, 0.75) 0%, rgba(7, 36, 43, 0) 70%),
    url('img/hero.jpg');
  background-size: cover;
  background-position: center;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
}

.hero::after,
.banner::after {
  content: '';
  position: absolute;
  left: 1.25rem;
  right: 1.25rem;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold) 20%, var(--gold-soft) 50%, var(--gold) 80%, transparent);
  opacity: 0.9;
  z-index: 1;
}

.hero img.hero-img,
.hero > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: -1;
}

.hero h1,
.banner h1 {
  font-size: clamp(1.9rem, 6vw, 3.2rem);
  margin: 0 0 0.25rem;
  color: var(--cream);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
}

.hero h1 em,
.hero h1 span.accent {
  color: var(--gold);
  font-style: italic;
}

.hero p,
.hero .tagline,
.banner p {
  margin: 0;
  max-width: 46ch;
  color: var(--cream-dim);
  font-size: 1rem;
}

.eyebrow {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.5rem;
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin: 1rem auto 0;
  max-width: 1120px;
  width: calc(100% - 2rem);
}

.hero .stats {
  width: 100%;
  margin-top: 1rem;
}

.stat {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  text-align: left;
}

.stat b,
.stat strong,
#stat-total,
#stat-langs,
#stat-mastered {
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--gold);
  font-size: 1.5rem;
  line-height: 1.1;
}

.stat span,
.stat small,
.stat .label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cream-faint);
  margin-top: 0.2rem;
}

/* Tabs */
#tabs,
.tabs {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 0.25rem;
  margin: 1.25rem auto 0;
  max-width: 1120px;
  width: calc(100% - 2rem);
  padding: 0.35rem 0.25rem 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, rgba(7, 36, 43, 0.92), rgba(7, 36, 43, 0.78));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
}

#tabs::-webkit-scrollbar,
.tabs::-webkit-scrollbar {
  display: none;
}

#tabs button,
#tabs [role='tab'],
.tab {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: 1 0 auto;
  min-height: 46px;
  padding: 0.65rem 1.1rem;
  background: transparent;
  border: 0;
  border-radius: 10px 10px 0 0;
  color: var(--cream-dim);
  font-family: var(--font-display);
  font-size: 1.02rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}

#tabs button::after,
#tabs [role='tab']::after,
.tab::after {
  content: '';
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--gold);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.3s var(--ease);
}

#tabs button:hover,
#tabs [role='tab']:hover,
.tab:hover {
  color: var(--cream);
  background: var(--glass);
}

#tabs button[aria-selected='true'],
#tabs [role='tab'][aria-selected='true'],
#tabs button.active,
#tabs button.is-active,
.tab.active,
.tab.is-active,
.tab[aria-selected='true'] {
  color: var(--gold-soft);
}

#tabs button[aria-selected='true']::after,
#tabs [role='tab'][aria-selected='true']::after,
#tabs button.active::after,
#tabs button.is-active::after,
.tab.active::after,
.tab.is-active::after,
.tab[aria-selected='true']::after {
  transform: scaleX(1);
}

/* Panels */
#panel-browse,
#panel-flash,
#panel-quiz,
#panel-add,
.panel {
  max-width: 1120px;
  width: calc(100% - 2rem);
  margin: 0 auto;
  padding: 1.25rem 0 2rem;
  animation: panel-in 0.45s var(--ease) both;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Toolbar / controls */
.toolbar,
.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

input,
select,
textarea,
button {
  font-family: inherit;
  font-size: 1rem;
  color: inherit;
}

#q,
#deck,
#sort,
#add-form input,
#add-form select,
#add-form textarea,
.input,
.select {
  width: 100%;
  min-height: 46px;
  padding: 0.65rem 0.9rem;
  color: var(--cream);
  background: rgba(5, 26, 32, 0.6);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}

#q::placeholder,
#add-form input::placeholder,
#add-form textarea::placeholder {
  color: var(--cream-faint);
  opacity: 0.85;
}

#q:hover,
#deck:hover,
#sort:hover,
#add-form input:hover,
#add-form select:hover,
#add-form textarea:hover {
  border-color: var(--line-gold);
}

#q:focus,
#deck:focus,
#sort:focus,
#add-form input:focus,
#add-form select:focus,
#add-form textarea:focus {
  border-color: var(--gold);
  background: rgba(5, 26, 32, 0.85);
  box-shadow: 0 0 0 3px rgba(217, 179, 106, 0.22);
}

#q:focus-visible,
#deck:focus-visible,
#sort:focus-visible,
#add-form input:focus-visible,
#add-form select:focus-visible,
#add-form textarea:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

#q[type='search']::-webkit-search-cancel-button {
  filter: invert(0.85) sepia(0.4);
  cursor: pointer;
}

select,
#deck,
#sort,
#a-lang,
#a-pos {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.4rem;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--gold) 50%),
    linear-gradient(135deg, var(--gold) 50%, transparent 50%);
  background-position: calc(100% - 20px) 52%, calc(100% - 14px) 52%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

select option {
  background: var(--ink-800);
  color: var(--cream);
}

textarea {
  resize: vertical;
  min-height: 90px;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cream-dim);
}

/* Chips */
#chips,
.chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  margin: 0 0 1rem;
  padding: 0.15rem 0.1rem 0.5rem;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-500) transparent;
  -webkit-overflow-scrolling: touch;
}

#chips::-webkit-scrollbar,
.chips::-webkit-scrollbar {
  height: 6px;
}

#chips::-webkit-scrollbar-thumb,
.chips::-webkit-scrollbar-thumb {
  background: var(--ink-500);
  border-radius: 6px;
}

.chip,
#chips button {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 38px;
  padding: 0.4rem 0.9rem;
  background: var(--glass);
  color: var(--cream-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s var(--ease);
}

.chip:hover,
#chips button:hover {
  color: var(--cream);
  border-color: var(--line-gold);
  background: var(--glass-strong);
  transform: translateY(-1px);
}

.chip[aria-pressed='true'],
.chip.active,
.chip.is-active,
#chips button[aria-pressed='true'],
#chips button.active,
#chips button.is-active {
  color: var(--ink-900);
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  border-color: var(--gold);
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(217, 179, 106, 0.3);
}

.chip .n,
.chip .count,
#chips button .n {
  font-size: 0.75rem;
  opacity: 0.7;
}

#count {
  margin: 0 0 0.9rem;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--cream-faint);
}

/* Grid */
#grid,
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

#grid-empty,
#flash-empty,
#quiz-empty,
.empty {
  padding: 2.5rem 1.25rem;
  text-align: center;
  color: var(--cream-dim);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.1rem;
  background: var(--glass);
  border: 1px dashed var(--line-gold);
  border-radius: var(--radius);
}

/* Word cards */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.1rem 1.1rem 1rem;
  background: linear-gradient(160deg, rgba(243, 234, 216, 0.08), rgba(243, 234, 216, 0.025));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.25s var(--ease), border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 1.1rem;
  right: 1.1rem;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: 0;
  transition: opacity 0.3s var(--ease);
}

.card:hover,
.card:focus-within {
  transform: translateY(-4px);
  border-color: var(--line-gold);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(217, 179, 106, 0.12);
}

.card:hover::before,
.card:focus-within::before {
  opacity: 1;
}

.card-open {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
  color: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
}

.card-open:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
}

.card .word,
.card h3,
.card .c-word {
  font-family: var(--font-display);
  font-size: 1.45rem;
  line-height: 1.15;
  color: var(--cream);
  margin: 0;
  padding-right: 2.6rem;
  overflow-wrap: anywhere;
}

.card .pos,
.card .c-pos {
  font-style: italic;
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--teal);
}

.card .def,
.card .c-def,
.card p {
  margin: 0;
  color: var(--cream-dim);
  font-size: 0.95rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-foot,
.card .meta,
.card .c-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--cream-faint);
}

.xp,
.card .xp {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--gold);
}

.mastery {
  color: var(--cream-faint);
  font-size: 0.78rem;
}

/* Language badge with colored dot */
.badge,
.lang-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  width: fit-content;
  padding: 0.2rem 0.65rem 0.2rem 0.5rem;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--cream-dim);
  background: rgba(5, 26, 32, 0.55);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.badge::before,
.lang-badge::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot, var(--teal));
  box-shadow: 0 0 8px var(--dot, var(--teal));
  flex: none;
}

.badge[data-lang='English'],
.badge[data-lang='en'] { --dot: #57c7b8; }
.badge[data-lang='French'],
.badge[data-lang='fr'] { --dot: #6ea8ff; }
.badge[data-lang='Spanish'],
.badge[data-lang='es'] { --dot: #f0a35e; }
.badge[data-lang='Italian'],
.badge[data-lang='it'] { --dot: #7fcf8f; }
.badge[data-lang='German'],
.badge[data-lang='de'] { --dot: #e8cd92; }
.badge[data-lang='Portuguese'],
.badge[data-lang='pt'] { --dot: #e8736b; }
.badge[data-lang='Latin'],
.badge[data-lang='la'] { --dot: #c79bf2; }
.badge[data-lang='Greek'],
.badge[data-lang='el'] { --dot: #5fb6e8; }
.badge[data-lang='Arabic'],
.badge[data-lang='ar'] { --dot: #d9b36a; }
.badge[data-lang='Japanese'],
.badge[data-lang='ja'] { --dot: #f28fb0; }
.badge[data-lang='Chinese'],
.badge[data-lang='zh'] { --dot: #ef6b6b; }
.badge[data-lang='Russian'],
.badge[data-lang='ru'] { --dot: #8ab4f8; }
.badge[data-lang='Haitian Creole'],
.badge[data-lang='ht'] { --dot: #4fd1c5; }
.badge[data-lang='Korean'],
.badge[data-lang='ko'] { --dot: #b4e07a; }
.badge[data-lang='Hindi'],
.badge[data-lang='hi'] { --dot: #f4b860; }

/* Audio buttons */
.btn-audio {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  color: var(--gold);
  background: rgba(5, 26, 32, 0.6);
  border: 1px solid var(--line-gold);
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.card .btn-audio {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
}

.btn-audio:hover {
  color: var(--ink-900);
  background: var(--gold);
  border-color: var(--gold);
  transform: scale(1.08);
}

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

.btn-audio.playing,
.btn-audio[aria-pressed='true'] {
  color: var(--ink-900);
  background: var(--teal);
  border-color: var(--teal);
  animation: pulse 1.2s ease-in-out infinite;
}

.btn-audio[disabled],
.btn-audio[aria-disabled='true'] {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(87, 199, 184, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(87, 199, 184, 0); }
}

/* Buttons */
button {
  cursor: pointer;
}

.btn,
#q-next,
#a-download,
#a-copy,
#f-prev,
#f-next,
#f-shuffle,
#f-know,
#f-learning,
#d-close,
#add-form button[type='submit'] {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 46px;
  padding: 0.65rem 1.2rem;
  color: var(--cream);
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  transition: all 0.2s var(--ease);
}

.btn:hover,
#q-next:hover,
#a-download:hover,
#a-copy:hover,
#f-prev:hover,
#f-next:hover,
#f-shuffle:hover,
#d-close:hover {
  border-color: var(--line-gold);
  color: var(--gold-soft);
  transform: translateY(-1px);
}

.btn:active,
#q-next:active,
#f-prev:active,
#f-next:active {
  transform: translateY(0) scale(0.98);
}

.btn-primary,
#q-next,
#add-form button[type='submit'] {
  color: var(--ink-900);
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  border-color: var(--gold);
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(217, 179, 106, 0.28);
}

.btn-primary:hover,
#q-next:hover,
#add-form button[type='submit']:hover {
  color: var(--ink-900);
  background: linear-gradient(180deg, #f0d9a3, var(--gold-soft));
  box-shadow: 0 8px 24px rgba(217, 179, 106, 0.4);
}

button[disabled],
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
}

/* Flashcards */
#flash-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
}

.fc-wrap,
.flash-stage {
  width: 100%;
  max-width: 560px;
  perspective: 1400px;
}

#fc,
.fcard {
  position: relative;
  display: block;
  width: 100%;
  max-width: 560px;
  min-height: 340px;
  margin: 0 auto;
  padding: 0;
  color: var(--cream);
  background: none;
  border: 0;
  text-align: center;
  cursor: pointer;
  perspective: 1400px;
  -webkit-tap-highlight-color: transparent;
}

#fc .fc-inner,
.fcard .fc-inner,
.fcard-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.7s var(--ease);
}

#fc.flipped .fc-inner,
#fc.is-flipped .fc-inner,
#fc[aria-pressed='true'] .fc-inner,
.fcard.flipped .fc-inner,
.fcard.is-flipped .fc-inner,
.fcard.flipped .fcard-inner,
.fcard.is-flipped .fcard-inner {
  transform: rotateY(180deg);
}

/* If the markup has no inner wrapper, flip the card itself */
#fc,
.fcard {
  transform-style: preserve-3d;
  transition: transform 0.7s var(--ease);
}

#fc.flipped:not(:has(.fc-inner)),
.fcard.flipped:not(:has(.fc-inner)):not(:has(.fcard-inner)),
#fc.is-flipped:not(:has(.fc-inner)),
.fcard.is-flipped:not(:has(.fc-inner)):not(:has(.fcard-inner)) {
  transform: rotateY(180deg);
}

.fc-face,
.fcard-face,
#fc > .front,
#fc > .back,
.fcard > .front,
.fcard > .back {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.75rem 1.5rem;
  border-radius: 24px;
  border: 1px solid var(--line-gold);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.fc-front,
.fcard-front,
#fc > .front,
.fcard > .front {
  background:
    radial-gradient(400px 220px at 50% 0%, rgba(217, 179, 106, 0.16), transparent 70%),
    linear-gradient(160deg, var(--ink-600), var(--ink-700));
}

.fc-back,
.fcard-back,
#fc > .back,
.fcard > .back,
#f-back {
  background:
    radial-gradient(400px 220px at 50% 0%, rgba(87, 199, 184, 0.16), transparent 70%),
    linear-gradient(160deg, var(--ink-700), var(--ink-800));
  transform: rotateY(180deg);
}

#f-back {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.75rem 1.5rem;
  border-radius: 24px;
  border: 1px solid var(--line-gold);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  overflow: auto;
}

.fc-face::before,
.fcard-face::before,
#f-back::before {
  content: '';
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  bottom: 12px;
  border: 1px solid rgba(217, 179, 106, 0.2);
  border-radius: 16px;
  pointer-events: none;
}

#f-lang {
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
}

#f-word {
  font-family: var(--font-display);
  font-size: clamp(2rem, 9vw, 3.2rem);
  line-height: 1.1;
  color: var(--cream);
  margin: 0;
  overflow-wrap: anywhere;
}

#f-pos,
#f-pos-label {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--teal);
  font-size: 1rem;
}

#f-def {
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 4vw, 1.4rem);
  line-height: 1.4;
  color: var(--cream);
  margin: 0;
}

#f-ex {
  max-width: 44ch;
  margin: 0;
  font-style: italic;
  color: var(--cream-dim);
  font-size: 0.98rem;
}

#fc .hint,
.fc-hint {
  position: absolute;
  bottom: 1.1rem;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--cream-faint);
}

#fc:hover {
  filter: brightness(1.04);
}

/* Progress bar */
#f-bar,
.bar {
  position: relative;
  width: 100%;
  max-width: 560px;
  height: 6px;
  background: rgba(243, 234, 216, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

#f-bar > *,
.bar > span,
.bar > i,
.bar-fill {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  border-radius: inherit;
  transition: width 0.45s var(--ease);
}

progress#f-bar {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
}

progress#f-bar::-webkit-progress-bar {
  background: rgba(243, 234, 216, 0.1);
  border-radius: 999px;
}

progress#f-bar::-webkit-progress-value {
  background: linear-gradient(90deg, var(--teal), var(--gold));
  border-radius: 999px;
}

progress#f-bar::-moz-progress-bar {
  background: linear-gradient(90deg, var(--teal), var(--gold));
  border-radius: 999px;
}

.fc-controls,
.flash-controls,
.f-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  max-width: 560px;
}

#f-know {
  color: var(--ink-900);
  background: linear-gradient(180deg, #a6e3b1, var(--good));
  border-color: var(--good);
  font-weight: 600;
}

#f-know:hover {
  color: var(--ink-900);
  box-shadow: 0 6px 18px rgba(127, 207, 143, 0.3);
}

#f-learning {
  color: var(--gold-soft);
  background: rgba(217, 179, 106, 0.12);
  border-color: var(--line-gold);
}

#f-learning:hover {
  background: rgba(217, 179, 106, 0.22);
  color: var(--gold-soft);
}

/* Quiz */
#quiz-main {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#q-def {
  margin: 0;
  padding: 1.4rem 1.25rem;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 4.2vw, 1.5rem);
  line-height: 1.4;
  color: var(--cream);
  background: linear-gradient(160deg, rgba(243, 234, 216, 0.08), rgba(243, 234, 216, 0.025));
  border: 1px solid var(--line-gold);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#q-choices {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

#q-choices button,
#q-choices .choice,
.choice {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: 54px;
  padding: 0.8rem 1.1rem;
  text-align: left;
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--cream);
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: all 0.2s var(--ease);
}

#q-choices button:hover:not([disabled]),
.choice:hover:not([disabled]) {
  border-color: var(--gold);
  background: var(--glass-strong);
  transform: translateX(4px);
}

#q-choices button.correct,
#q-choices .correct,
.choice.correct {
  color: var(--cream);
  background: linear-gradient(90deg, rgba(217, 179, 106, 0.28), var(--good-bg));
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--good), 0 6px 20px rgba(127, 207, 143, 0.2);
  opacity: 1;
  animation: pop 0.35s var(--ease);
}

#q-choices button.wrong,
#q-choices .wrong,
.choice.wrong {
  color: var(--cream);
  background: var(--bad-bg);
  border-color: var(--bad);
  box-shadow: 0 0 0 1px var(--bad);
  opacity: 1;
  animation: shake 0.4s var(--ease);
}

#q-choices button[disabled]:not(.correct):not(.wrong) {
  opacity: 0.5;
}

@keyframes pop {
  0% { transform: scale(0.97); }
  60% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

#q-score {
  font-family: var(--font-display);
  color: var(--gold);
  letter-spacing: 0.06em;
  font-size: 1rem;
}

#q-feedback {
  min-height: 1.5em;
  margin: 0;
  font-family: var(--font-display);
  font-style: italic;
  color: var(--cream-dim);
}

#q-feedback.good,
#q-feedback.correct {
  color: var(--good);
}

#q-feedback.bad,
#q-feedback.wrong {
  color: var(--bad);
}

/* Add form */
#add-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  max-width: 680px;
  margin: 0 auto;
  padding: 1.4rem 1.2rem;
  background: linear-gradient(160deg, rgba(243, 234, 216, 0.07), rgba(243, 234, 216, 0.02));
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

#add-form .field,
#add-form .row {
  display: flex;
  flex-direction: column;
}

#add-form fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

#add-form legend {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--gold-soft);
  margin-bottom: 0.5rem;
}

#add-result {
  max-width: 680px;
  margin: 1rem auto 0;
  padding: 1rem 1.2rem;
  background: rgba(5, 26, 32, 0.6);
  border: 1px solid var(--line-gold);
  border-radius: var(--radius);
}

#add-result pre,
#add-result code {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.85rem;
  color: var(--teal);
  white-space: pre-wrap;
  word-break: break-word;
}

#add-result pre {
  margin: 0 0 0.8rem;
  padding: 0.8rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-sm);
  max-height: 260px;
  overflow: auto;
}

#a-msg {
  min-height: 1.4em;
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--cream-dim);
}

#a-msg.error {
  color: var(--bad);
}

#a-msg.ok,
#a-msg.success {
  color: var(--good);
}

/* Detail dialog */
#detail {
  width: min(94vw, 640px);
  max-height: 90vh;
  padding: 0;
  color: var(--cream);
  background:
    radial-gradient(500px 240px at 50% 0%, rgba(217, 179, 106, 0.12), transparent 70%),
    linear-gradient(170deg, var(--ink-600), var(--ink-800));
  border: 1px solid var(--line-gold);
  border-radius: 22px;
  box-shadow: var(--shadow-lg), 0 0 80px rgba(0, 0, 0, 0.6);
  overflow: auto;
}

#detail[open] {
  animation: dialog-in 0.35s var(--ease) both;
}

#detail::backdrop {
  background: rgba(3, 14, 18, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

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

#detail .detail-body,
#detail > div,
#detail > article {
  position: relative;
  padding: 1.75rem 1.4rem 1.5rem;
}

#d-word {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 7vw, 2.6rem);
  margin: 0 2.5rem 0.25rem 0;
  color: var(--cream);
  overflow-wrap: anywhere;
}

#d-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--cream-faint);
  letter-spacing: 0.04em;
}

#d-def {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: 1.25rem;
  line-height: 1.45;
  color: var(--cream);
}

#d-etym,
#d-ex {
  margin: 0 0 1rem;
  padding: 0.8rem 1rem;
  background: rgba(5, 26, 32, 0.45);
  border-left: 2px solid var(--gold);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--cream-dim);
  font-size: 0.97rem;
}

#d-etym {
  border-left-color: var(--teal);
}

#d-ex {
  font-style: italic;
}

#d-decks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 1.1rem;
  padding: 0;
  list-style: none;
}

#d-decks > *,
#d-decks .deck-tag {
  padding: 0.2rem 0.7rem;
  font-size: 0.78rem;
  color: var(--teal);
  background: var(--teal-soft);
  border: 1px solid rgba(87, 199, 184, 0.3);
  border-radius: 999px;
}

#d-notion {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-right: 0.6rem;
  color: var(--gold-soft);
  text-decoration: none;
  border-bottom: 1px solid var(--line-gold);
  padding-bottom: 1px;
}

#d-notion:hover {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

#d-audio {
  width: 44px;
  height: 44px;
}

#d-close {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
  font-size: 1.3rem;
  line-height: 1;
  border-radius: 50%;
}

/* Footer */
footer {
  max-width: 1120px;
  margin: 2rem auto 0;
  padding: 1.5rem 1rem 2.5rem;
  text-align: center;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: var(--cream-faint);
  border-top: 1px solid var(--line);
}

footer::before {
  content: '';
  display: block;
  width: 60px;
  height: 2px;
  margin: 0 auto 1rem;
  background: var(--gold);
  opacity: 0.7;
}

/* Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--ink-500) transparent;
}

/* Tablet */
@media (min-width: 600px) {
  .wrap,
  main,
  .container {
    padding-inline: 1.5rem;
  }

  .hero,
  header.hero,
  .banner {
    min-height: 280px;
    padding: 2rem 2rem 1.8rem;
  }

  .hero::after,
  .banner::after {
    left: 2rem;
    right: 2rem;
  }

  .toolbar,
  .controls {
    grid-template-columns: 2fr 1fr 1fr;
  }

  #grid,
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.1rem;
  }

  .stat b,
  .stat strong,
  #stat-total,
  #stat-langs,
  #stat-mastered {
    font-size: 1.9rem;
  }

  #q-choices {
    grid-template-columns: 1fr 1fr;
  }

  #add-form {
    padding: 1.8rem;
    grid-template-columns: 1fr 1fr;
  }

  #add-form .full,
  #add-form .field-wide,
  #add-form button[type='submit'],
  #add-form textarea,
  #add-form #a-def {
    grid-column: 1 / -1;
  }

  #fc,
  .fcard {
    min-height: 380px;
  }
}

/* Desktop */
@media (min-width: 960px) {
  #grid,
  .grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .hero,
  header.hero,
  .banner {
    min-height: 340px;
    padding: 2.5rem 2.75rem 2.2rem;
  }

  .hero::after,
  .banner::after {
    left: 2.75rem;
    right: 2.75rem;
  }

  #fc,
  .fcard {
    min-height: 420px;
  }
}

/* Touch devices: no hover lift stickiness */
@media (hover: none) {
  .card:hover {
    transform: none;
  }

  #q-choices button:hover:not([disabled]) {
    transform: none;
  }
}

/* High contrast preference */
@media (prefers-contrast: more) {
  :root {
    --line: rgba(243, 234, 216, 0.4);
    --line-gold: rgba(217, 179, 106, 0.8);
    --cream-dim: #e6dec9;
    --cream-faint: #c3d3d1;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  #fc,
  .fcard,
  #fc .fc-inner,
  .fcard .fc-inner,
  .fcard-inner {
    transition: none !important;
  }

  .card:hover,
  .card:focus-within,
  .btn-audio:hover,
  .chip:hover {
    transform: none;
  }
}

/* Print */
@media print {
  body {
    background: #fff;
    color: #000;
  }

  .hero,
  #tabs,
  .btn-audio,
  #chips,
  .toolbar {
    display: none !important;
  }

  .card {
    break-inside: avoid;
    background: none;
    border: 1px solid #999;
    box-shadow: none;
    color: #000;
  }

  .card .word,
  .card h3,
  .card p {
    color: #000;
  }
}
