@font-face {
  font-family: "Berkshire Swash";
  src: url("assets/fonts/berkshire-swash-latin-400.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: light;
  --page-top: #f7f8fb;
  --text: #19202a;
  --muted: #69717d;
  --line: rgba(25, 32, 42, 0.12);
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --shadow: 0 24px 80px rgba(38, 47, 64, 0.14);
  --pink: #ffd8e4;
  --pink-deep: #b73d67;
  --blue: #d9e9ff;
  --blue-deep: #2866b3;
  --green: #d9f1df;
  --green-deep: #2f7a47;
  --yellow: #fff0bd;
  --yellow-deep: #8b6818;
  --neutral-card: #f7f8fb;
  --accent: #1f7a68;
  --accent-dark: #155c4e;
  --danger: #b44242;
  --swipe-low: rgba(180, 66, 66, 0.2);
  --swipe-mid: rgba(139, 104, 24, 0.2);
  --swipe-high: rgba(47, 122, 71, 0.2);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page-top);
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  background:
    linear-gradient(180deg, var(--page-top) 0%, #f5faf8 5%, rgba(232, 244, 240, 0.92) 17%, rgba(247, 248, 251, 0.98) 48%, rgba(244, 236, 226, 0.86) 100%),
    linear-gradient(135deg, rgba(232, 244, 240, 0.55), rgba(247, 248, 251, 0.96) 42%, rgba(244, 236, 226, 0.62));
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(32px + env(safe-area-inset-top)) 0 calc(32px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

.app-title {
  margin-bottom: 0;
  color: var(--accent-dark);
  font-family: "Berkshire Swash", Georgia, serif;
  font-size: clamp(2.75rem, 2rem + 3vw, 3.5rem);
  font-weight: 400;
  line-height: 1.04;
}

.app-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
}

body.is-studying .app-title {
  font-size: 2rem;
}

h2 {
  margin-bottom: 22px;
  font-size: clamp(1.35rem, 3vw, 2.1rem);
  line-height: 1.18;
  letter-spacing: 0;
}

.stats {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(76px, 1fr));
  gap: 10px;
}

.stats div {
  min-width: 76px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(18px);
  text-align: center;
}

.stats span {
  display: block;
  font-size: 1.35rem;
  font-weight: 760;
}

.stats small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}

.setup-view,
.study-view {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}

.panel,
.card-stack {
  width: min(680px, 100%);
}

.panel,
.word-card {
  border: 1px solid rgba(255, 255, 255, 0.74);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.intro-panel {
  padding: clamp(28px, 7vw, 54px);
  border-radius: 28px;
}

.custom-manager-panel {
  width: min(760px, 100%);
  padding: clamp(24px, 6vw, 44px);
  border-radius: 28px;
}

.custom-manager-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 26px;
}

.custom-manager-header h2,
.custom-manager-header p,
.custom-import-form h3,
.custom-import-form p {
  margin: 0;
}

.custom-manager-header p,
.custom-wordbook-row small,
.format-help,
.import-status {
  color: var(--muted);
}

.custom-manager-header p {
  margin-top: 6px;
}


.custom-wordbook-list {
  border-top: 1px solid var(--line);
}

.custom-wordbook-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.custom-wordbook-row > div {
  min-width: 0;
}

.custom-wordbook-row.is-aggregate {
  margin: 12px 0 10px;
  padding: 18px;
  border-bottom: 0;
  border-radius: 16px;
  background: rgba(31, 122, 104, 0.09);
}

.custom-wordbook-row.is-selected strong {
  color: var(--accent);
}

.custom-wordbook-row strong,
.custom-wordbook-row small {
  display: block;
}

.custom-wordbook-row strong {
  overflow-wrap: anywhere;
}

.custom-wordbook-row small {
  margin-top: 4px;
}

.custom-import-form {
  display: grid;
  gap: 10px;
  margin-top: 30px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.custom-import-form h3 {
  margin-bottom: 6px;
}

.custom-import-form label {
  margin-top: 4px;
  font-weight: 720;
}

.custom-import-form input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--text);
  font: inherit;
}

.custom-import-form input[type="file"] {
  padding: 9px 10px;
}

.format-help,
.import-status {
  font-size: 0.86rem;
  line-height: 1.45;
}

.custom-import-form .primary-button {
  margin-top: 8px;
}

.import-status:not(:empty) {
  min-height: 1.3em;
}

.wordbook-section {
  margin-bottom: 26px;
}

.wordbook-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.wordbook-option {
  min-height: 78px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  text-align: left;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.wordbook-option span,
.wordbook-option small {
  display: block;
}

.wordbook-option span {
  font-weight: 760;
}

.wordbook-option small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.25;
}

.wordbook-option.is-selected {
  border-color: rgba(31, 122, 104, 0.4);
  background: var(--accent);
  color: white;
}

.wordbook-option.is-selected small {
  color: rgba(255, 255, 255, 0.82);
}

.wordbook-summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.count-picker {
  display: grid;
  grid-template-columns: repeat(5, minmax(48px, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}

.count-option,
.primary-button,
.choice-button,
.answer-button {
  min-width: 0;
  padding: 10px 12px;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.count-option {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  font-weight: 720;
}

.count-option.is-selected,
.primary-button,
.answer-button.primary {
  background: var(--accent);
  color: white;
}

.primary-button {
  width: 100%;
  font-weight: 760;
}

.browse-button {
  margin-top: 10px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.count-option:hover,
.wordbook-option:hover,
.primary-button:hover,
.choice-button:hover,
.answer-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.hidden {
  display: none;
}

.study-view {
  grid-template-rows: auto minmax(0, 1fr);
  align-content: stretch;
  gap: 12px;
  padding-bottom: 28px;
}

body.is-studying .app-shell {
  height: 100vh;
  height: 100svh;
  min-height: 420px;
  grid-template-rows: auto minmax(0, 1fr);
  padding-top: calc(20px + env(safe-area-inset-top));
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  gap: 16px;
}

.session-strip {
  width: min(680px, 100%);
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 12px;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
}

.progress-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.progress-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(25, 32, 42, 0.11);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 220ms ease;
}

.card-stack {
  --deep-stack-bg: #f4f5f7;
  --swipe-intensity: 0;
  position: relative;
  isolation: isolate;
  container-type: size;
  height: 100%;
  min-height: 0;
  max-height: 760px;
}

.card-stack::before,
.card-stack::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 30px;
  background: var(--deep-stack-bg);
  box-shadow: 0 18px 56px rgba(38, 47, 64, 0.09);
  pointer-events: none;
  z-index: -1;
}

.card-stack::before {
  inset: 12px 18px -14px;
  transform: translateY(12px) scale(0.97);
  opacity: 0.9;
}

.card-stack::after {
  background: #eceff2;
  inset: 24px 34px -26px;
  transform: translateY(22px) scale(0.92);
  opacity: 0.74;
}

.word-card {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: clamp(18px, 2.5vw, 28px);
  border-radius: 30px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 18px;
  position: relative;
  z-index: 1;
  transform-origin: center;
  transition: box-shadow 180ms ease, opacity 180ms ease;
  will-change: transform;
  overflow: hidden;
}

.card-stack > .word-card:not(.next-card-preview) {
  z-index: 2;
}

.next-card-preview {
  position: absolute;
  inset: 0;
  height: 100%;
  min-height: 0;
  z-index: 1;
  pointer-events: none;
  opacity: calc(0.48 + var(--swipe-intensity) * 0.5);
  transform: scale(calc(0.985 + var(--swipe-intensity) * 0.015));
  transform-origin: center;
  box-shadow: 0 20px 62px rgba(38, 47, 64, 0.1);
  filter: saturate(0.96);
  overflow: hidden;
  clip-path: inset(0 round 30px);
  transition: opacity 160ms ease, transform 160ms ease, filter 160ms ease;
}

.next-card-preview.is-empty {
  display: none;
}

.next-card-preview .preview-content {
  align-self: stretch;
}

.next-card-preview .feedback {
  overflow-wrap: anywhere;
  visibility: hidden;
}

.card-stack.is-peeking .next-card-preview {
  filter: saturate(1);
}

.word-card.is-entering {
  animation: card-enter 280ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.word-card.is-swipeable {
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.word-card.is-dragging {
  cursor: grabbing;
  box-shadow: 0 28px 88px rgba(38, 47, 64, 0.18);
}

.word-card.is-dragging[data-swipe-intent="left"] {
  box-shadow: var(--shadow), -18px 20px 60px var(--swipe-low);
}

.word-card.is-dragging[data-swipe-intent="down"] {
  box-shadow: var(--shadow), 0 28px 68px var(--swipe-mid);
}

.word-card.is-dragging[data-swipe-intent="right"] {
  box-shadow: var(--shadow), 18px 20px 60px var(--swipe-high);
}

.word-card.feminine {
  background: linear-gradient(180deg, var(--pink), #fff7fa);
  background-color: #fff7fa;
}

.word-card.masculine {
  background: linear-gradient(180deg, var(--blue), #f7fbff);
  background-color: #f7fbff;
}

.word-card.neuter {
  background: linear-gradient(180deg, var(--green), #f8fff9);
  background-color: #f8fff9;
}

.word-card.plural {
  background: linear-gradient(180deg, var(--yellow), #fffdf4);
  background-color: #fffdf4;
}

.word-card.neutral {
  background: var(--surface-strong);
}

@keyframes card-enter {
  from {
    opacity: 0;
    transform: translate3d(0, 18px, 0) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

.card-top {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
}

.mode-pill {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border-radius: 999px;
  padding: 6px 11px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 700;
}

.card-content {
  align-self: stretch;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(25, 32, 42, 0.25) transparent;
  touch-action: pan-y;
  overflow-wrap: anywhere;
}

.card-content::-webkit-scrollbar { width: 6px; }
.card-content::-webkit-scrollbar-thumb {
  background: rgba(25, 32, 42, 0.25);
  border-radius: 999px;
}
.learn-details { min-width: 0; }
.learn-details > :last-child { margin-bottom: 0; }
.feedback:empty { display: none; }

.vocab-figure {
  margin: 0 0 20px;
  display: grid;
  place-items: center;
}

.vocab-image {
  width: min(100%, 300px);
  aspect-ratio: 1;
  display: block;
  border-radius: 24px;
  box-shadow: 0 18px 48px rgba(25, 32, 42, 0.12);
  object-fit: cover;
}

.word-line {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.word {
  min-width: 0;
  max-width: 100%;
  font-size: clamp(2rem, 4vw, 3.3rem);
  line-height: 1.1;
  font-weight: 820;
  letter-spacing: 0;
}

.speak-button {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: 0 10px 28px rgba(25, 32, 42, 0.08);
  color: var(--text);
  font-size: 1.25rem;
  display: inline-grid;
  place-items: center;
}

.speaker-icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.meaning {
  margin-bottom: 22px;
  color: var(--muted);
  font-size: clamp(1.05rem, 3vw, 1.3rem);
}

.plural-form {
  margin: -12px 0 18px;
  color: rgba(105, 113, 125, 0.9);
  font-size: 0.92rem;
  font-weight: 650;
}

.plural-form span {
  color: rgba(105, 113, 125, 0.72);
  font-weight: 720;
}

.memory-aid {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid rgba(25, 32, 42, 0.09);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.58);
}

.memory-title {
  margin-bottom: 8px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 780;
}

.memory-parts {
  display: grid;
  gap: 6px;
}

.memory-part,
.memory-note {
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.35;
}

.memory-part strong {
  color: var(--text);
  font-weight: 760;
}

.memory-part span::before {
  content: " = ";
  color: var(--muted);
}

.example {
  padding-top: 18px;
  border-top: 1px solid rgba(25, 32, 42, 0.11);
}

.example strong {
  display: block;
  margin-bottom: 8px;
  font-size: clamp(1.15rem, 3.2vw, 1.55rem);
  line-height: 1.42;
}

.example span {
  color: var(--muted);
  line-height: 1.65;
}

.prompt {
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 1.02rem;
  font-weight: 680;
}

.quiz-word {
  margin-bottom: 18px;
  max-width: 100%;
  font-size: clamp(1.9rem, 4vw, 3.3rem);
  line-height: 1.05;
  font-weight: 810;
}

.choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.choice-button {
  min-height: 64px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  text-align: left;
  padding: 14px 16px;
  font-weight: 680;
}

.choice-button.article-choice {
  text-align: center;
  font-size: 1.35rem;
}

.fill-form {
  display: grid;
  gap: 14px;
}

.fill-input {
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.76);
  padding: 0 18px;
  color: var(--text);
  font-size: 1.18rem;
  outline: none;
}

.fill-input:focus {
  border-color: rgba(31, 122, 104, 0.54);
  box-shadow: 0 0 0 4px rgba(31, 122, 104, 0.13);
}

.feedback {
  min-height: 28px;
  color: var(--muted);
  font-weight: 680;
}

.feedback.correct {
  color: var(--green-deep);
}

.feedback.wrong {
  color: var(--danger);
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  position: relative;
  z-index: 2;
}

.answer-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  font-weight: 760;
}

.answer-button.low {
  color: var(--danger);
}

.answer-button.mid {
  color: var(--yellow-deep);
}

.answer-button.high {
  color: var(--green-deep);
}

.is-reviewing-missed .actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 22px, 680px);
    padding: calc(18px + env(safe-area-inset-top)) 0 calc(24px + env(safe-area-inset-bottom));
    gap: 18px;
  }

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

  .stats {
    width: 100%;
  }

  .wordbook-picker {
    grid-template-columns: 1fr;
  }

  .wordbook-option {
    min-height: 66px;
  }

  .intro-panel,
  .custom-manager-panel,
  .word-card {
    border-radius: 22px;
  }

  .custom-wordbook-row {
    grid-template-columns: 1fr;
  }

  .custom-wordbook-row .answer-button {
    width: 100%;
  }

  .card-stack::before,
  .card-stack::after {
    border-radius: 22px;
  }

  .count-picker {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 7px;
  }

  .count-option {
    min-width: 0;
    padding: 0;
  }

  .word-card {
    min-height: 0;
  }

  .choices,
  .actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body.is-studying .app-shell {
    width: min(100% - 16px, 680px);
    min-height: 360px;
    padding: calc(8px + env(safe-area-inset-top)) 0 calc(10px + env(safe-area-inset-bottom));
    grid-template-rows: 1fr;
    gap: 0;
  }

  body.is-studying .topbar {
    display: none;
  }

  body.is-studying .study-view {
    gap: 8px;
    padding-bottom: 24px;
  }

  body.is-studying .session-strip {
    grid-template-columns: 36px 1fr 36px;
    gap: 8px;
  }

  body.is-studying .icon-button {
    width: 36px;
    height: 36px;
    font-size: 1.05rem;
  }

  body.is-studying .progress-wrap {
    gap: 8px;
    font-size: 0.82rem;
  }

  body.is-studying .progress-track {
    height: 7px;
  }

  body.is-studying .word-card {
    padding: 12px 14px 14px;
    border-radius: 20px;
    gap: 8px;
  }

  body.is-studying .card-content {
    align-self: stretch;
  }

  body.is-studying .card-stack::before,
  body.is-studying .card-stack::after {
    border-radius: 20px;
  }

  body.is-studying .next-card-preview {
    clip-path: inset(0 round 20px);
  }

  body.is-studying .mode-pill {
    min-height: 24px;
    padding: 4px 9px;
    font-size: 0.74rem;
  }

  body.is-studying .vocab-figure {
    margin-bottom: 8px;
  }

  body.is-studying .vocab-image {
    width: min(100%, 190px);
    border-radius: 16px;
    box-shadow: 0 10px 28px rgba(25, 32, 42, 0.12);
  }

  body.is-studying .word-line {
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
  }

  body.is-studying .word {
    font-size: clamp(1.95rem, 9.4vw, 2.55rem);
    text-align: center;
  }

  body.is-studying .speak-button {
    width: 40px;
    height: 40px;
  }

  body.is-studying .speaker-icon {
    width: 21px;
    height: 21px;
  }

  body.is-studying .meaning {
    margin-bottom: 8px;
    font-size: 0.98rem;
    text-align: center;
  }

  body.is-studying .plural-form {
    margin: -4px 0 8px;
    font-size: 0.78rem;
    text-align: center;
  }

  body.is-studying .memory-aid {
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 12px;
  }

  body.is-studying .memory-title {
    margin-bottom: 5px;
    font-size: 0.7rem;
  }

  body.is-studying .memory-parts {
    gap: 3px;
  }

  body.is-studying .memory-part,
  body.is-studying .memory-note {
    font-size: 0.82rem;
    line-height: 1.24;
  }

  body.is-studying .example {
    padding-top: 8px;
  }

  body.is-studying .example strong {
    margin-bottom: 4px;
    font-size: 0.96rem;
    line-height: 1.28;
  }

  body.is-studying .example span {
    display: block;
    font-size: 0.9rem;
    line-height: 1.35;
  }

  body.is-studying .feedback {
    min-height: 20px;
    font-size: 0.88rem;
  }

  body.is-studying .actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  body.is-studying .answer-button,
  body.is-studying .choice-button {
    min-height: 40px;
    border-radius: 12px;
    padding: 8px 9px;
    font-size: 0.92rem;
  }
}

@media (max-height: 620px) {
  body.is-studying .vocab-image {
    width: min(100%, 160px);
  }

  body.is-studying .word {
    font-size: clamp(1.8rem, 8.4vw, 2.35rem);
  }

  body.is-studying .memory-aid {
    padding: 7px 9px;
  }

  body.is-studying .example strong {
    font-size: 0.92rem;
  }

  body.is-studying .example span {
    font-size: 0.84rem;
  }
}

/* Adapt the layout to available width and card height, including short laptops. */
.actions:has(> :last-child:nth-child(2)) {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.actions > :only-child { grid-column: 1 / -1; }
.image-quiz .prompt { margin-bottom: 14px; }
.image-quiz .word-line { margin-bottom: 16px; }
.image-quiz .quiz-word { margin-bottom: 0; overflow-wrap: anywhere; }
.quiz-picture { width: min(100%, 240px, 34cqh); margin: 0 auto 18px; }
.quiz-picture img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; border-radius: 16px; }
.image-quiz .choices { width: min(100%, 520px); margin-inline: auto; }
.image-quiz .image-choices { width: min(100%, 440px, 74cqh); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.image-quiz .image-word-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body.is-studying .image-quiz .image-choice { position: relative; padding: 0; overflow: hidden; aspect-ratio: 1; min-height: 44px; border-radius: 16px; background: #fff; }
.image-choice img { display: block; width: 100%; height: 100%; object-fit: contain; }
body.is-studying .image-quiz .image-word-choice { min-height: 48px; overflow-wrap: anywhere; }
.image-quiz .choice-button:disabled { opacity: 1; cursor: default; transform: none; }
.image-quiz .choice-button:disabled:not(.is-correct):not(.is-wrong) { color: var(--text); }
.image-quiz .choice-button.is-correct { border: 2px solid var(--accent-dark); }
.image-quiz .choice-button.is-wrong { border: 2px solid #a13c35; }
.choice-result:not(:empty) { display: block; margin-top: 6px; font-size: 0.78rem; font-weight: 650; }
.image-choice .choice-result:not(:empty) { position: absolute; inset: auto 0 0; padding: 6px; background: rgba(255, 255, 255, 0.94); }
.text-question-button { justify-self: center; min-height: 44px; padding: 8px 16px; color: var(--muted); background: transparent; border: 0; text-decoration: underline; text-underline-offset: 4px; font: inherit; }
button:focus-visible {
  outline: 3px solid var(--accent-dark);
  outline-offset: 3px;
}

@media (min-width: 961px) {
  .intro-panel {
    width: min(1040px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    gap: 36px;
    padding: 36px;
  }
  .wordbook-section { margin-bottom: 0; }
  .session-settings {
    min-width: 0;
    border-left: 1px solid var(--line);
    padding-left: 36px;
  }
  .session-strip, .card-stack { width: min(1040px, 100%); }
  .word-card { gap: 12px; }
  .learn-content:has(.vocab-figure) {
    display: grid;
    grid-template-columns: minmax(180px, 0.7fr) minmax(0, 1.5fr);
    align-items: start;
    gap: 28px;
  }
  .vocab-figure { margin: 0; }
  .vocab-image { width: min(100%, 260px); }
  .meaning { margin-bottom: 18px; font-size: 1.15rem; }
  .example strong { font-size: 1.2rem; }
}

@media (min-width: 721px) and (max-width: 960px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .stats { width: 100%; }
  body.is-studying .topbar { flex-direction: row; align-items: center; }
  body.is-studying .stats { width: auto; }
  .vocab-image { width: min(100%, 190px); }
  .word { font-size: 2.4rem; }
  .learn-content:has(.vocab-figure) {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    align-items: start;
    gap: 20px;
  }
  .vocab-figure { margin: 0; }
  .example strong { font-size: 1.1rem; }
}

@container (min-width: 700px) and (max-height: 580px) {
  .word-card { padding: 20px 24px; gap: 10px; }
  .word { font-size: 2.5rem; }
  .word-line { gap: 8px; margin-bottom: 8px; }
  .meaning { margin-bottom: 12px; font-size: 1rem; }
  .plural-form { margin: -4px 0 10px; font-size: 0.85rem; }
  .memory-aid { margin-bottom: 10px; padding: 9px 12px; }
  .memory-title { margin-bottom: 4px; }
  .memory-parts { gap: 3px; }
  .memory-part, .memory-note { font-size: 0.88rem; }
  .example { padding-top: 10px; }
  .example strong { font-size: 1.05rem; margin-bottom: 4px; line-height: 1.35; }
  .example span { font-size: 0.95rem; line-height: 1.4; }
  .vocab-image { width: min(100%, 220px); }
}

@media (max-height: 620px) and (min-width: 721px) {
  body.is-studying .topbar { display: none; }
  body.is-studying .app-shell {
    grid-template-rows: minmax(0, 1fr);
    padding-top: calc(10px + env(safe-area-inset-top));
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 0;
  }
  body.is-studying .word-card { padding: 16px 22px; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

@media (min-width: 721px) and (max-width: 960px) and (max-height: 420px) {
  body.is-studying .app-shell { min-height: 360px; }
}

.wordbook-option:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}


/* Keep language controls available without taking space from desktop cards. */
.app-shell { position: relative; }
.topbar { padding-right: 148px; }

.language-switcher {
  position: absolute;
  top: calc(32px + env(safe-area-inset-top));
  right: 0;
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

body.is-studying .language-switcher {
  top: calc(20px + env(safe-area-inset-top));
}

.language-switcher button {
  min-height: 34px;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
}

.language-switcher button:hover { background: var(--neutral-card); }
.language-switcher button[aria-pressed="true"] {
  background: var(--accent);
  color: white;
  font-weight: 700;
}

@media (max-width: 720px) {
  .app-shell { grid-template-rows: auto auto minmax(0, 1fr); }
  .topbar { padding-right: 0; }
  .language-switcher { position: static; justify-self: end; }
  .language-switcher button { min-height: 44px; }
  body.is-studying .app-shell {
    grid-template-rows: minmax(0, 1fr);
    gap: 0;
  }
  body.is-studying .language-switcher {
    position: absolute;
    top: calc(8px + env(safe-area-inset-top));
    width: 120px;
  }
  body.is-studying .language-switcher button {
    flex: 1;
    padding: 4px 6px;
    font-size: 0.8rem;
  }
  body.is-studying .session-strip { padding-right: 128px; min-height: 52px; }
  body.is-studying .study-view { padding-bottom: 22px; }
  body.is-studying .card-stack::before { inset: 0; transform: translateY(7px); }
  body.is-studying .card-stack::after { inset: 0; transform: translateY(15px); }
}

@media (max-height: 620px) and (min-width: 721px) {
  body.is-studying .language-switcher {
    top: calc(10px + env(safe-area-inset-top));
  }
  body.is-studying .session-strip { padding-right: 148px; }
}
