:root {
  --page: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #f1f4f8;
  --surface-raised: #ffffff;
  --ink: #111827;
  --muted: #667085;
  --line: #d8dee8;
  --line-strong: #b7c0ce;
  --accent: #2f5daa;
  --accent-strong: #244a87;
  --accent-soft: #dbe7fb;
  --on-accent: #ffffff;
  --success: #0f766e;
  --success-soft: #ccfbf1;
  --warning: #b45309;
  --audio: #111827;
  --audio-strong: #374151;
  --wash-one: rgba(47, 93, 170, 0.1);
  --wash-two: rgba(11, 31, 58, 0.06);
  --panel-alpha: rgba(255, 255, 255, 0.94);
  --toast: #111827;
  --toast-action: #93c5fd;
  --shadow: 0 24px 80px rgba(17, 24, 39, 0.12);
  --shadow-soft: 0 1px 2px rgba(17, 24, 39, 0.06);
  --color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

[data-theme="dark"] {
  --page: #0b0f17;
  --surface: #121821;
  --surface-soft: #1b2430;
  --surface-raised: #161d27;
  --ink: #f5f7fb;
  --muted: #a1acbb;
  --line: #273343;
  --line-strong: #3a4656;
  --accent: #8eb3ff;
  --accent-strong: #b8cdfd;
  --accent-soft: #172641;
  --on-accent: #07111f;
  --success: #5eead4;
  --success-soft: #123a36;
  --warning: #fbbf24;
  --audio: #60a5fa;
  --audio-strong: #93c5fd;
  --wash-one: rgba(47, 93, 170, 0.18);
  --wash-two: rgba(142, 179, 255, 0.08);
  --panel-alpha: rgba(18, 24, 33, 0.92);
  --toast: #f5f7fb;
  --toast-action: #2f5daa;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.3);
  --color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
  color-scheme: var(--color-scheme);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, var(--wash-one), transparent 34rem),
    radial-gradient(circle at bottom right, var(--wash-two), transparent 32rem),
    var(--page);
}

button,
select {
  font: inherit;
}

button {
  border: 0;
}

select,
button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: 100%;
  max-width: 64rem;
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2.5rem);
  display: grid;
  align-content: center;
}

.panel {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--panel-alpha);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.setup-panel,
.prefs-panel {
  padding: clamp(1.25rem, 4vw, 2.5rem);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: clamp(1rem, 3vw, 1.5rem);
}

.study-bar {
  min-height: 4rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
}

.brand-lockup,
.study-tools {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}

.study-tools {
  justify-content: flex-end;
}

.brand-mark {
  width: 2.3rem;
  height: 2.3rem;
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  box-shadow: var(--shadow-soft);
  border-radius: 8px;
}

.brand-mark-icon {
  width: 100%;
  height: 100%;
  display: block;
}

.brand-mark-bg {
  fill: #0b1f3a;
}

.brand-mark-light {
  stroke: #ffffff;
}

.brand-mark-blue {
  stroke: #2f5daa;
}

.brand-mark-nodes {
  fill: #ffffff;
  stroke: #0b1f3a;
}

.brand {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 760;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.title {
  margin: 0;
  font-size: 3.15rem;
  line-height: 1;
  letter-spacing: 0;
}

.copy {
  max-width: 38rem;
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 1.06rem;
  line-height: 1.65;
}

.form-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  margin-top: 1.75rem;
}

.field {
  min-width: 0;
  display: grid;
  gap: 0.45rem;
}

.field label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.select {
  width: 100%;
  min-width: 0;
  min-height: 2.85rem;
  padding: 0 2.4rem 0 0.9rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.theme-field {
  min-width: 0;
  margin: 1.25rem 0 0;
  padding: 0;
  border: 0;
}

.theme-field legend {
  margin-bottom: 0.55rem;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.theme-options {
  display: inline-grid;
  max-width: 100%;
  padding: 0.25rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.25rem;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.theme-option {
  min-width: 0;
  min-height: 2.4rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.7rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease,
    transform 140ms ease;
}

.theme-option:has(input:checked) {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: var(--shadow-soft);
}

.theme-option:has(input:focus-visible) {
  outline: 3px solid rgba(26, 115, 232, 0.28);
  outline-offset: 3px;
}

.theme-option:hover {
  background: var(--surface);
}

.theme-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-swatch {
  width: 1.1rem;
  height: 1.1rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 50%;
}

.theme-swatch-color {
  background: var(--swatch);
}

.theme-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
  font-weight: 760;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.75rem;
}

.button {
  min-width: 3rem;
  min-height: 2.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0 1rem;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  font-weight: 760;
  transition:
    transform 140ms ease,
    background 140ms ease,
    box-shadow 140ms ease;
}

.button:focus-visible,
.audio-button:focus-visible {
  outline: 3px solid rgba(26, 115, 232, 0.28);
  outline-offset: 3px;
}

.learned-button:focus-visible,
.toast-button:focus-visible {
  outline: 3px solid rgba(24, 116, 106, 0.28);
  outline-offset: 3px;
}

.button:hover {
  background: var(--accent-strong);
  box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 22%, transparent);
}

.button:active {
  transform: translateY(1px);
}

.button.secondary {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
}

.button.secondary:hover {
  background: var(--surface-soft);
  box-shadow: none;
}

.button.danger {
  color: #ffffff;
  background: #dc2626;
}

.button.danger:hover {
  background: #b91c1c;
  box-shadow: 0 10px 24px rgba(220, 38, 38, 0.22);
}

.icon-button {
  width: 2.85rem;
  height: 2.85rem;
  padding: 0;
  font-size: 1.35rem;
}

.flashcard-view {
  min-height: calc(100vh - clamp(2rem, 6vw, 4rem));
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

.progress-track {
  height: 0.45rem;
  overflow: hidden;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.progress-track span {
  height: 100%;
  display: block;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: inherit;
  transition: width 220ms ease;
}

.card-wrap {
  display: grid;
  place-items: center;
  min-height: 27rem;
  padding: clamp(1.25rem, 4vw, 3rem) 0;
}

.word-card {
  width: min(100%, 46rem);
  min-height: min(54vh, 30rem);
  padding: clamp(1.35rem, 5vw, 3rem);
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 1.35rem;
  text-align: center;
  user-select: none;
  touch-action: pan-y;
}

.word-stack {
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 1rem;
}

.word-row {
  max-width: 100%;
  display: grid;
  grid-template-columns: minmax(0, auto) 3.15rem;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
}

.position {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 760;
}

.word {
  min-width: 0;
  max-width: 100%;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 5.6rem;
  font-weight: 840;
  line-height: 0.95;
  letter-spacing: 0;
}

.transcription {
  margin: -0.35rem 0 0;
  color: var(--muted);
  font-size: 1.35rem;
  font-weight: 650;
  line-height: 1.25;
}

.sentences {
  width: min(100%, 40rem);
  margin: 0;
  padding: 0.9rem 1rem;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 1.04rem;
  line-height: 1.5;
  list-style: none;
  text-align: left;
  box-shadow: var(--shadow-soft);
}

.sentences li {
  padding: 0.15rem 0;
}

.sentences .sentence-with-audio {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 0.65rem;
}

.sentences li + li {
  margin-top: 0.45rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
}

.sentences strong {
  color: var(--ink);
  font-weight: 820;
}

.sentence-text {
  min-width: 0;
}

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

.card-actions {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.audio-button,
.learned-button {
  width: 3.15rem;
  height: 3.15rem;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: #ffffff;
  background: var(--audio);
  border: 0;
  border-radius: 8px;
  box-shadow: 0 12px 24px color-mix(in srgb, var(--audio) 18%, transparent);
  cursor: pointer;
  transition:
    transform 140ms ease,
    background 140ms ease,
    box-shadow 140ms ease;
}

.learned-button {
  color: var(--success);
  background: var(--success-soft);
  box-shadow: var(--shadow-soft);
}

.audio-button:hover {
  background: var(--audio-strong);
  box-shadow: 0 10px 22px color-mix(in srgb, var(--audio) 32%, transparent);
}

.learned-button:hover {
  color: var(--on-accent);
  background: var(--success);
  box-shadow: 0 10px 22px color-mix(in srgb, var(--success) 24%, transparent);
}

.audio-button:active,
.learned-button:active {
  transform: translateY(1px) scale(0.98);
}

.word-audio-button {
  align-self: center;
  margin-top: 0.35rem;
}

.sentence-audio-button {
  width: 2rem;
  height: 2rem;
  margin-top: 0.12rem;
  border-radius: 7px;
  box-shadow: none;
}

.sentence-audio-button .speaker-icon {
  width: 1.05rem;
  height: 1.05rem;
}

.speaker-icon {
  width: 1.55rem;
  height: 1.55rem;
  display: block;
  fill: currentColor;
}

.speaker-icon path + path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.settings-icon {
  width: 1.35rem;
  height: 1.35rem;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.check-icon {
  width: 1.45rem;
  height: 1.45rem;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status {
  min-height: 1.5rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.status.warning {
  color: var(--warning);
}

.nav-row {
  display: grid;
  grid-template-columns: 3.25rem minmax(0, 1fr) 3.25rem;
  align-items: center;
  gap: 0.9rem;
  margin-top: 0.25rem;
}

.nav-row .position {
  text-align: center;
}

.empty-state {
  align-self: center;
  padding: clamp(1.5rem, 5vw, 3rem);
  text-align: center;
}

.empty-state .title {
  font-size: 2.35rem;
}

.learned-panel {
  margin-top: 1.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.reset-panel {
  margin-top: 1.75rem;
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.learned-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.section-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.section-copy {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.compact-button {
  min-height: 2.4rem;
  padding: 0 0.8rem;
  font-size: 0.9rem;
}

.compact-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.learned-details {
  margin-top: 1rem;
}

.learned-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 780;
}

.learned-list {
  max-height: 18rem;
  margin: 0.9rem 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-raised);
  box-shadow: var(--shadow-soft);
}

.learned-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.6rem;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--line);
}

.learned-item:first-child {
  border-top: 0;
}

.learned-word {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 740;
}

.learned-index {
  margin-right: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.undo-toast {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 10;
  width: min(calc(100vw - 2rem), 32rem);
  min-height: 3.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.85rem 0.75rem 1rem;
  color: var(--surface);
  background: var(--toast);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(17, 24, 39, 0.26);
  transform: translateX(-50%);
}

.toast-button {
  min-height: 2.25rem;
  padding: 0 0.7rem;
  color: var(--toast-action);
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.toast-button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.hidden {
  display: none !important;
}

@media (max-width: 42rem) {
  .app-shell {
    align-content: stretch;
    justify-items: stretch;
    overflow-x: hidden;
  }

  .setup-panel,
  .prefs-panel {
    width: calc(100vw - 2rem);
  }

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

  .title,
  .copy {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .topbar {
    align-items: flex-start;
  }

  .brand {
    max-width: 12rem;
    font-size: 1rem;
  }

  .card-wrap {
    min-height: 24rem;
    padding: 1rem 0;
  }

  .word-card {
    min-height: 24rem;
    padding: 1.25rem;
  }

  .title {
    font-size: 2.15rem;
  }

  .copy {
    font-size: 1rem;
  }

  .word {
    font-size: 3.25rem;
  }

  .transcription {
    font-size: 1.08rem;
  }

  .word-row {
    grid-template-columns: minmax(0, auto) 2.85rem;
    gap: 0.65rem;
  }

  .word-audio-button {
    width: 2.85rem;
    height: 2.85rem;
  }

  .sentences {
    font-size: 0.96rem;
    padding: 0.8rem;
  }

  .study-bar {
    align-items: center;
  }

  .study-tools {
    gap: 0.5rem;
  }

  .study-tools > .position {
    display: none;
  }

  .learned-header,
  .learned-item,
  .reset-panel,
  .undo-toast {
    align-items: stretch;
  }

  .learned-header,
  .reset-panel {
    flex-direction: column;
  }

  .learned-item {
    flex-direction: column;
  }

  .learned-item .compact-button,
  .learned-header .compact-button {
    width: 100%;
  }
}

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