:root {
  color-scheme: light;
  --bg: #f8f7fc;
  --surface: #ffffff;
  --surface-soft: #f0edff;
  --ink: #202034;
  --muted: #747287;
  --line: #e7e3f0;
  --primary: #6555d9;
  --primary-dark: #4d3fb9;
  --accent: #f26f58;
  --accent-soft: #fff0ec;
  --green: #2e8b67;
  --green-soft: #e8f6ef;
  --yellow: #eba84f;
  --shadow: 0 18px 50px rgba(57, 48, 105, .10);
  --shadow-small: 0 7px 24px rgba(57, 48, 105, .08);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --max: 1180px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171622;
  --surface: #211f30;
  --surface-soft: #2c2844;
  --ink: #f5f2ff;
  --muted: #aaa6bd;
  --line: #373449;
  --primary: #9788ff;
  --primary-dark: #b4a9ff;
  --accent: #ff8973;
  --accent-soft: #392824;
  --green: #65c99c;
  --green-soft: #1f3a30;
  --yellow: #f4bd70;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
  --shadow-small: 0 7px 24px rgba(0, 0, 0, .2);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 82% 6%, rgba(101, 85, 217, .08), transparent 24rem),
    radial-gradient(circle at 4% 20%, rgba(242, 111, 88, .06), transparent 20rem),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }
button { color: inherit; }
svg { width: 1.25rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }

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

.skip-link {
  position: fixed;
  z-index: 1000;
  top: .75rem;
  left: .75rem;
  transform: translateY(-180%);
  background: var(--ink);
  color: var(--surface);
  padding: .65rem 1rem;
  border-radius: 10px;
}
.skip-link:focus { transform: none; }

.site-header {
  width: min(calc(100% - 40px), var(--max));
  height: 82px;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .7rem;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -.04em;
}

.brand-mark {
  display: grid;
  width: 35px;
  height: 35px;
  place-items: center;
  border-radius: 11px 11px 11px 3px;
  background: var(--primary);
  box-shadow: 0 5px 14px rgba(101, 85, 217, .25);
  color: white;
  font-family: Georgia, serif;
  font-style: italic;
}

.header-actions { display: flex; align-items: center; gap: .65rem; }
.icon-button, .saved-button {
  height: 42px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .55);
  border-radius: 13px;
}
[data-theme="dark"] .icon-button,
[data-theme="dark"] .saved-button { background: rgba(33, 31, 48, .7); }
.icon-button { width: 42px; display: grid; place-items: center; }
.saved-button {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 .8rem;
  font-size: .88rem;
  font-weight: 700;
}
.saved-button svg { color: var(--yellow); }
.saved-count {
  min-width: 21px;
  padding: .05rem .35rem;
  border-radius: 20px;
  background: var(--surface-soft);
  color: var(--primary);
  font-size: .74rem;
  text-align: center;
}

main { overflow: hidden; }
.hero {
  width: min(calc(100% - 40px), var(--max));
  margin: 3.5rem auto 4.7rem;
  display: grid;
  grid-template-columns: 1.35fr .65fr;
  align-items: end;
  gap: 4rem;
}
.eyebrow, .section-kicker {
  display: block;
  margin-bottom: .8rem;
  color: var(--primary);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .15em;
  text-transform: uppercase;
}
.eyebrow span { margin-right: .25rem; color: var(--accent); }
.hero h1 {
  max-width: 720px;
  margin: 0;
  font-size: clamp(3rem, 6.3vw, 5.75rem);
  line-height: .96;
  letter-spacing: -.065em;
}
.hero h1 em {
  color: var(--primary);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
}
.hero-copy > p {
  max-width: 610px;
  margin: 1.5rem 0 0;
  color: var(--muted);
  font-size: 1.06rem;
}
.hero-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 1.15rem 0;
  border-block: 1px solid var(--line);
}
.hero-stats div { padding-inline: 1.1rem; text-align: center; }
.hero-stats div + div { border-left: 1px solid var(--line); }
.hero-stats strong { display: block; font-size: 1.55rem; line-height: 1.15; letter-spacing: -.04em; }
.hero-stats span { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }

.study-shell {
  position: relative;
  padding: 4.75rem max(20px, calc((100vw - var(--max)) / 2));
  background: var(--surface-soft);
}
.study-shell::before, .study-shell::after {
  position: absolute;
  content: "";
  border-radius: 50%;
  background: var(--primary);
  opacity: .08;
}
.study-shell::before { width: 250px; height: 250px; top: -140px; right: -85px; }
.study-shell::after { width: 150px; height: 150px; bottom: -90px; left: -65px; }

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}
.section-kicker { margin-bottom: .25rem; }
.section-heading h2 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.45rem);
  line-height: 1.12;
  letter-spacing: -.045em;
}
.shuffle-button, .random-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  height: 44px;
  padding: 0 1rem;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  font-size: .84rem;
  font-weight: 700;
}
.shuffle-button svg, .random-button svg { width: 1rem; color: var(--primary); }

.deck {
  position: relative;
  max-width: 720px;
  margin: 2.3rem auto 1.25rem;
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr) 50px;
  gap: 1.15rem;
  align-items: center;
}
.deck::before, .deck::after {
  position: absolute;
  z-index: 0;
  content: "";
  height: 88%;
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-small);
}
.deck::before { left: 92px; right: 92px; bottom: -16px; opacity: .5; }
.deck::after { left: 115px; right: 115px; bottom: -29px; opacity: .3; }
.deck-arrow {
  position: relative;
  z-index: 2;
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-small);
}
.deck-arrow:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-2px); }

.flash-card {
  position: relative;
  z-index: 2;
  min-height: 405px;
  padding: 2.1rem 2.5rem 2.2rem;
  overflow: hidden;
  border: 1px solid rgba(101, 85, 217, .12);
  border-radius: var(--radius-xl);
  outline: none;
  background:
    linear-gradient(145deg, rgba(101, 85, 217, .03), transparent 42%),
    var(--surface);
  box-shadow: var(--shadow);
  transition: transform .2s ease, opacity .2s ease;
}
.flash-card:focus-visible { box-shadow: 0 0 0 4px rgba(101, 85, 217, .2), var(--shadow); }
.flash-card.card-out { transform: translateX(-14px); opacity: .15; }
.card-progress {
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--line);
}
.card-progress span { display: block; height: 100%; width: 5%; background: var(--primary); transition: width .3s ease; }
.card-topline { display: flex; align-items: center; justify-content: space-between; }
.card-number { color: var(--muted); font-size: .69rem; font-weight: 700; letter-spacing: .1em; }
.save-word, .speak-button {
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
}
.save-word { width: 38px; height: 38px; color: var(--muted); }
.save-word.active { color: var(--yellow); }
.save-word.active svg { fill: currentColor; }
.card-question {
  display: flex;
  min-height: 235px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.part-badge, .mini-part {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .28rem .65rem;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .64rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.word-line { display: flex; align-items: center; gap: .65rem; }
.current-word {
  margin: .65rem 0 .25rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.4rem, 8vw, 4rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -.04em;
}
.speak-button {
  width: 43px;
  height: 43px;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--primary);
}
.speak-button.speaking { animation: pulse 1s ease infinite; }
@keyframes pulse { 50% { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(101, 85, 217, .08); } }
.pronunciation { color: var(--muted); font-size: .84rem; }
.tap-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  color: var(--muted);
  font-size: .73rem;
  font-weight: 600;
}
.tap-hint svg { width: .9rem; }
.card-answer {
  padding: 1.4rem 0 .35rem;
  border-top: 1px solid var(--line);
  animation: answer-in .25s ease both;
}
@keyframes answer-in { from { opacity: 0; transform: translateY(8px); } }
.flash-card.revealed .card-question { min-height: 130px; }
.flash-card.revealed .tap-hint { display: none; }
.answer-label {
  color: var(--primary);
  font-size: .63rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.definition { margin: .32rem 0 1rem; font-family: Georgia, "Times New Roman", serif; font-size: 1.2rem; line-height: 1.45; }
.example { margin: .32rem 0 .85rem; color: var(--muted); font-size: .92rem; font-style: italic; }
.synonyms { display: flex; flex-wrap: wrap; gap: .4rem; }
.synonyms span { padding: .2rem .55rem; border-radius: 7px; background: var(--surface-soft); color: var(--primary); font-size: .7rem; }

.study-actions {
  position: relative;
  z-index: 2;
  max-width: 570px;
  margin: 2.8rem auto 0;
  display: grid;
  grid-template-columns: 1fr 1.3fr 1fr;
  gap: .65rem;
}
.study-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  font-size: .78rem;
  font-weight: 700;
}
.reveal-button { border-color: var(--primary); background: var(--primary); color: white; }
.know-button { border-color: rgba(46, 139, 103, .2); color: var(--green); }
.review-button { color: var(--accent); }
.key-hint { margin-left: .45rem; padding: .15rem .35rem; border-radius: 4px; background: rgba(255,255,255,.18); font-size: .61rem; }
.keyboard-help { position: relative; z-index: 2; margin: .9rem 0 0; color: var(--muted); font-size: .7rem; text-align: center; }
kbd { padding: .05rem .3rem; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); font-family: inherit; }

.library {
  width: min(calc(100% - 40px), var(--max));
  margin: 0 auto;
  padding: 6rem 0 5rem;
}
.library-title { margin-bottom: 1.8rem; }
.result-count { color: var(--muted); font-size: .8rem; }
.search-row { display: grid; grid-template-columns: 1fr auto; gap: .7rem; }
.search-box {
  position: relative;
  display: flex;
  height: 54px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-small);
}
.search-box > svg { width: 1.1rem; margin-left: 1.05rem; color: var(--muted); }
.search-box input {
  width: 100%;
  height: 100%;
  padding: 0 .8rem;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}
.search-box input::placeholder { color: var(--muted); }
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(101, 85, 217, .1); }
.search-shortcut { margin-right: .8rem; padding: .2rem .45rem; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); font-size: .65rem; white-space: nowrap; }
.random-button { height: 54px; box-shadow: var(--shadow-small); }
.filter-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.2rem 0 1.5rem; }
.filter-chips { display: flex; gap: .45rem; flex-wrap: wrap; }
.filter-chip {
  padding: .48rem .85rem;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  color: var(--muted);
  font-size: .75rem;
  font-weight: 700;
}
.filter-chip.active { border-color: var(--primary); background: var(--primary); color: white; }
.sort-select {
  padding: .5rem 2rem .5rem .75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: 0;
  background: var(--surface);
  color: var(--muted);
  font-size: .74rem;
}
.word-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
.word-card {
  position: relative;
  min-height: 218px;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-small);
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.word-card:hover { transform: translateY(-3px); border-color: rgba(101, 85, 217, .35); box-shadow: var(--shadow); }
.word-card-top { display: flex; align-items: center; justify-content: space-between; }
.mini-part { background: var(--surface-soft); color: var(--primary); }
.word-card-actions { display: flex; gap: .1rem; }
.word-card-actions button {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
}
.word-card-actions button:hover { background: var(--surface-soft); color: var(--primary); }
.word-card-actions button.active { color: var(--yellow); }
.word-card-actions button.active svg { fill: currentColor; }
.word-card h3 { margin: 1rem 0 .45rem; font-family: Georgia, "Times New Roman", serif; font-size: 1.65rem; font-weight: 500; letter-spacing: -.03em; }
.word-card .grid-definition { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.55; }
.word-card .grid-example {
  margin: .9rem 0 0;
  padding-top: .75rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .72rem;
  font-style: italic;
}
.load-more {
  display: block;
  min-width: 190px;
  height: 45px;
  margin: 2rem auto 0;
  border: 1px solid var(--primary);
  border-radius: 12px;
  background: transparent;
  color: var(--primary);
  font-size: .8rem;
  font-weight: 800;
}
.empty-state { padding: 4rem 1rem; text-align: center; }
.empty-state > span { color: var(--primary); font-size: 3rem; }
.empty-state h3 { margin: .5rem 0 .2rem; }
.empty-state p { margin: 0; color: var(--muted); }
.empty-state button { margin-top: 1rem; padding: .55rem 1rem; border: 0; border-radius: 9px; background: var(--primary); color: white; }

footer {
  width: min(calc(100% - 40px), var(--max));
  min-height: 110px;
  margin: auto;
  display: flex;
  align-items: center;
  gap: 2rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .73rem;
}
.footer-brand { margin-right: auto; }
footer p span { color: var(--accent); }

.toast {
  position: fixed;
  z-index: 100;
  right: 1.25rem;
  bottom: 1.25rem;
  max-width: calc(100% - 2.5rem);
  padding: .75rem 1rem;
  border-radius: 11px;
  background: var(--ink);
  box-shadow: var(--shadow);
  color: var(--surface);
  font-size: .78rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(15px);
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: none; }
.noscript-message { margin: 1rem; padding: 1rem; border: 1px solid var(--line); background: var(--surface); }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; gap: 2rem; margin-block: 2.5rem 3.5rem; }
  .hero-copy > p { max-width: 520px; }
  .hero-stats { max-width: 500px; }
  .word-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 580px) {
  .site-header { width: min(calc(100% - 28px), var(--max)); height: 70px; }
  .saved-button > span:not(.saved-count) { display: none; }
  .hero { width: min(calc(100% - 32px), var(--max)); margin-top: 2rem; }
  .hero h1 { font-size: clamp(2.8rem, 15vw, 4.2rem); }
  .hero-copy > p { font-size: .94rem; }
  .hero-stats div { padding-inline: .6rem; }
  .hero-stats strong { font-size: 1.35rem; }
  .study-shell { padding: 3.6rem 16px 4rem; }
  .section-heading { align-items: center; }
  .section-heading h2 { font-size: 1.7rem; }
  .shuffle-button { width: 43px; padding: 0; }
  .shuffle-button svg { width: 1.15rem; }
  .shuffle-button { font-size: 0; }
  .deck { grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: 1.6rem; }
  .flash-card { grid-column: 1 / -1; grid-row: 1; min-height: 385px; padding: 1.6rem 1.35rem 1.8rem; }
  .deck-arrow { grid-row: 2; width: 44px; height: 44px; margin-top: .4rem; }
  .deck-prev { justify-self: end; }
  .deck-next { justify-self: start; }
  .deck::before { left: 24px; right: 24px; bottom: 64px; }
  .deck::after { display: none; }
  .current-word { font-size: clamp(2.25rem, 13vw, 3.6rem); overflow-wrap: anywhere; }
  .card-question { min-height: 225px; }
  .flash-card.revealed .card-question { min-height: 120px; }
  .study-actions { margin-top: 1.3rem; grid-template-columns: 1fr 1fr; }
  .reveal-button { grid-column: 1 / -1; grid-row: 1; }
  .keyboard-help { display: none; }
  .library { width: min(calc(100% - 32px), var(--max)); padding-block: 4rem 3.5rem; }
  .library-title { align-items: end; }
  .search-row { grid-template-columns: 1fr; }
  .search-shortcut { display: none; }
  .random-button { height: 46px; }
  .filter-row { align-items: stretch; flex-direction: column; }
  .filter-chips { flex-wrap: nowrap; padding-bottom: .3rem; overflow-x: auto; scrollbar-width: none; }
  .filter-chips::-webkit-scrollbar { display: none; }
  .filter-chip { flex: 0 0 auto; }
  .sort-select { align-self: flex-end; }
  .word-grid { grid-template-columns: 1fr; }
  .word-card { min-height: 0; }
  footer { min-height: 150px; align-items: flex-start; flex-direction: column; justify-content: center; gap: .35rem; }
  .footer-brand { margin-right: 0; margin-bottom: .5rem; }
  footer p { margin: 0; }
}

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