:root {
  color-scheme: light;
  --bg: #f7efe7;
  --panel: #fffaf2;
  --ink: #263238;
  --muted: #667579;
  --mint: #d6f1de;
  --sky: #dceeff;
  --peach: #ffcfad;
  --berry: #a64263;
  --leaf: #2f7d5b;
  --border: #eadccf;
  --shadow: 0 14px 32px rgba(60, 45, 35, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.56), rgba(255, 255, 255, 0)),
    var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 18px;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
}

.brand {
  color: var(--leaf);
  font-size: 1.25rem;
  font-weight: 800;
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 10px;
}

.nav-links a {
  border: 2px solid transparent;
  border-radius: 999px;
  padding: 10px 18px;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.nav-links a[aria-current="page"] {
  background: var(--sky);
  border-color: #b8d8f5;
}

.nav-logout {
  margin: 0;
}

.nav-logout button {
  border: 2px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 10px 18px;
}

.nav-logout button:hover,
.nav-logout button:focus-visible {
  background: var(--sky);
  border-color: #b8d8f5;
}

.page-shell {
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px 24px 48px;
}

.flash-stack {
  display: grid;
  gap: 10px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 24px;
}

.flash {
  border-radius: 8px;
  padding: 14px 16px;
  font-weight: 700;
}

.flash-error {
  background: #ffe0dd;
  color: #8f2f25;
}

.flash-success {
  background: var(--mint);
  color: #1f684b;
}

.flash-notice {
  background: #fff1ba;
  color: #71550a;
}

.create-panel {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(320px, 1fr);
  gap: 32px;
  align-items: center;
  min-height: 68vh;
}

.mode-choice {
  display: grid;
  align-content: center;
  gap: 30px;
  min-height: 68vh;
}

.mode-choice-header {
  display: grid;
  justify-items: center;
  gap: 10px;
  text-align: center;
}

.mode-choice-header .eyebrow {
  margin: 0;
}

.mode-choice-header h1 {
  margin: 0;
  font-size: clamp(2.6rem, 7vw, 4.8rem);
  line-height: 1;
}

.mode-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
  width: min(100%, 860px);
  margin: 0 auto;
}

.mode-card {
  display: grid;
  gap: 12px;
  min-height: 230px;
  border: 2px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 28px;
  text-decoration: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.mode-card:hover,
.mode-card:focus-visible {
  border-color: var(--leaf);
  box-shadow: 0 14px 32px rgba(60, 45, 35, 0.16), 0 0 0 5px rgba(47, 125, 91, 0.1);
  transform: translateY(-3px);
}

.mode-card-parent {
  background: var(--mint);
}

.mode-card-child {
  background: var(--sky);
}

.mode-card-label {
  align-self: end;
  font-size: 2.4rem;
  font-weight: 900;
  line-height: 1;
}

.mode-card-copy {
  color: var(--muted);
  font-weight: 800;
  line-height: 1.3;
}

.create-copy h1,
.library-heading h1,
.detail-content h1 {
  margin: 0;
  font-size: clamp(2.3rem, 7vw, 5rem);
  line-height: 1;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--berry);
  font-size: 0.9rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.create-note,
.form-note,
.wait-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.35;
}

.form-note {
  margin: 0;
  font-size: 0.92rem;
}

.create-form {
  display: grid;
  gap: 14px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-layout {
  display: grid;
  min-height: 64vh;
  place-items: center;
}

.login-form {
  display: grid;
  gap: 14px;
  width: min(100%, 460px);
  background: var(--panel);
  border: 2px solid #dce4dd;
  border-radius: 8px;
  padding: 28px;
}

.login-form h1 {
  margin: 0;
}

.create-form label,
.login-form label,
.filter-bar label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.create-form input,
.create-form select,
.login-form input,
.filter-bar input,
.filter-bar select {
  width: 100%;
  border: 2px solid #d5c7b9;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 15px 16px;
  outline: none;
}

.create-form input:focus,
.create-form select:focus,
.login-form input:focus,
.filter-bar input:focus,
.filter-bar select:focus {
  border-color: var(--leaf);
  box-shadow: 0 0 0 4px rgba(47, 125, 91, 0.15);
}

.primary-button,
.play-button,
.filter-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  border: 0;
  border-radius: 999px;
  background: var(--leaf);
  color: #ffffff;
  cursor: pointer;
  font-weight: 900;
  text-decoration: none;
}

.primary-button:hover,
.play-button:hover,
.filter-button:hover {
  filter: brightness(0.94);
}

.primary-button:disabled {
  cursor: wait;
  filter: saturate(0.65);
  opacity: 0.86;
}

.wait-overlay[hidden] {
  display: none;
}

.wait-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(247, 239, 231, 0.92);
  padding: 24px;
}

.wait-panel {
  display: grid;
  justify-items: center;
  gap: 16px;
  width: min(100%, 440px);
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 30px 24px;
  text-align: center;
}

.wait-panel h2 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.wait-panel p {
  margin: 0;
}

.wait-panel [data-progress-status] {
  color: var(--berry);
  font-size: 1.2rem;
  font-weight: 900;
}

.wait-picture {
  position: relative;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  background: var(--sky);
}

.wait-picture::before,
.wait-picture::after,
.wait-picture span {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: var(--leaf);
  animation: bounce-dot 1.1s infinite ease-in-out;
}

.wait-picture::before {
  width: 20px;
  height: 20px;
  left: 18px;
  top: 34px;
}

.wait-picture span {
  width: 24px;
  height: 24px;
  left: 32px;
  top: 26px;
  background: var(--berry);
  animation-delay: 0.16s;
}

.wait-picture::after {
  width: 20px;
  height: 20px;
  right: 18px;
  top: 34px;
  background: var(--peach);
  animation-delay: 0.32s;
}

.progress-track {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: min(100%, 300px);
  margin-top: 6px;
}

.progress-track span {
  height: 12px;
  border-radius: 999px;
  background: #e3d5c8;
}

.progress-track span.is-active {
  background: var(--berry);
  animation: pulse-bar 1s infinite ease-in-out;
}

.progress-track span.is-done {
  background: var(--leaf);
}

body.is-generating {
  cursor: wait;
}

@keyframes bounce-dot {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

@keyframes pulse-bar {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.library-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin: 20px 0 24px;
}

.secondary-link {
  border-radius: 999px;
  background: var(--peach);
  padding: 12px 18px;
  font-weight: 900;
  text-decoration: none;
}

.filter-bar {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto minmax(180px, 240px) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 28px;
  background: rgba(255, 250, 242, 0.72);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}

.filter-button {
  min-height: 48px;
  padding: 0 22px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 22px;
}

.vocab-card {
  display: grid;
  gap: 14px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.vocab-card:hover,
.vocab-card:focus-within {
  border-color: #c4daca;
  background: #fffdf8;
  box-shadow: 0 10px 26px rgba(60, 45, 35, 0.14), 0 0 0 4px rgba(47, 125, 91, 0.1);
  transform: translateY(-2px);
}

.vocab-card.is-playing {
  border-color: var(--berry);
  background: #fffaf8;
  box-shadow: 0 12px 28px rgba(60, 45, 35, 0.16), 0 0 0 5px rgba(166, 66, 99, 0.16);
}

.image-play-button,
.detail-image-button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: var(--sky);
  cursor: pointer;
  overflow: hidden;
  padding: 0;
}

.image-play-button img,
.detail-image-button img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.card-audio {
  display: none;
}

.card-detail-link {
  justify-self: start;
  border: 1px solid #d7c8ba;
  border-radius: 999px;
  background: #fffaf2;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  padding: 8px 12px;
  text-decoration: none;
  white-space: nowrap;
}

.card-detail-link:hover,
.card-detail-link:focus-visible {
  border-color: var(--leaf);
  color: var(--leaf);
}

.card-body {
  display: grid;
  gap: 4px;
}

.translated-word {
  color: var(--ink);
  font-size: 1.75rem;
  font-weight: 900;
  line-height: 1.05;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.source-word,
.english-word {
  margin: 0;
  color: var(--muted);
  font-size: 1.1rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.language-badge {
  justify-self: start;
  margin: 4px 0 0;
  border-radius: 999px;
  background: var(--mint);
  color: #236548;
  padding: 7px 11px;
  font-size: 0.86rem;
  font-weight: 900;
}

.card-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.card-footer .language-badge {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-footer-child {
  grid-template-columns: minmax(0, 1fr);
}

.play-button {
  width: 100%;
  background: var(--berry);
}

.play-button-large {
  width: min(100%, 280px);
  min-height: 68px;
  font-size: 1.3rem;
}

audio {
  width: 100%;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.admin-actions form {
  margin: 0;
}

.admin-actions button {
  border: 1px solid #d7c8ba;
  border-radius: 999px;
  background: #fffaf2;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 7px 10px;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(300px, 1fr);
  gap: 34px;
  align-items: center;
  margin-top: 28px;
}

.detail-content {
  display: grid;
  gap: 18px;
}

.detail-content h1 {
  overflow-wrap: anywhere;
}

.detail-source,
.detail-english {
  margin: 0;
  color: var(--muted);
  font-size: 2rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.detail-date {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.translation-editor {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.translation-editor summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  border: 1px solid #d7c8ba;
  border-radius: 999px;
  background: #fffaf2;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 800;
  padding: 7px 12px;
}

.translation-editor summary::marker {
  color: var(--berry);
}

.translation-editor[open] summary {
  margin-bottom: 12px;
}

.translation-edit-form {
  display: grid;
  gap: 8px;
}

.translation-edit-form label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.translation-edit-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
}

.translation-edit-row input {
  min-width: 0;
  border: 2px solid #d5c7b9;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 13px 14px;
  outline: none;
}

.translation-edit-row input:focus {
  border-color: var(--leaf);
  box-shadow: 0 0 0 4px rgba(47, 125, 91, 0.15);
}

.translation-edit-row .primary-button {
  min-height: 52px;
  padding: 0 18px;
  white-space: normal;
}

.detail-actions {
  margin-top: 12px;
}

.game-layout {
  display: grid;
  gap: 22px;
  margin: 24px auto 0;
  max-width: 1120px;
}

.game-header {
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
}

.game-header .eyebrow {
  margin: 0;
}

.game-header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1;
}

.game-replay-button {
  min-height: 50px;
  border: 0;
  border-radius: 999px;
  background: var(--berry);
  color: #ffffff;
  cursor: pointer;
  font-weight: 900;
  padding: 0 20px;
}

.game-replay-button:hover {
  filter: brightness(0.94);
}

.game-header audio {
  display: none;
}

.game-feedback {
  min-height: 1.4em;
  margin: 0;
  color: var(--berry);
  font-weight: 900;
  text-align: center;
}

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

.game-choice {
  position: relative;
  min-width: 0;
  border: 3px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.game-choice:hover,
.game-choice:focus-visible {
  border-color: #c4daca;
  box-shadow: 0 10px 26px rgba(60, 45, 35, 0.14), 0 0 0 5px rgba(47, 125, 91, 0.1);
  transform: translateY(-3px);
}

.game-choice img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.game-choice.is-correct {
  animation: celebrate-choice 680ms ease-out;
  border-color: var(--leaf);
  box-shadow: 0 12px 28px rgba(60, 45, 35, 0.16), 0 0 0 7px rgba(47, 125, 91, 0.2);
}

.game-choice.is-incorrect {
  animation: shake-choice 320ms ease-in-out;
  border-color: var(--berry);
}

@keyframes shake-choice {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-8px);
  }
  70% {
    transform: translateX(8px);
  }
}

@keyframes celebrate-choice {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.035);
  }
  100% {
    transform: scale(1);
  }
}

.empty-state {
  display: grid;
  justify-items: start;
  gap: 14px;
  border: 2px dashed #d7c8ba;
  border-radius: 8px;
  padding: 32px;
  background: rgba(255, 250, 242, 0.62);
}

.empty-state h2 {
  margin: 0;
  font-size: 2rem;
}

.site-footer {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 24px 28px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

@media (max-width: 760px) {
  body {
    font-size: 17px;
  }

  .site-header,
  .library-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-links {
    width: 100%;
  }

  .nav-links a {
    flex: 1;
    text-align: center;
  }

  .nav-logout {
    flex: 1;
  }

  .nav-logout button {
    width: 100%;
  }

  .create-panel,
  .detail-layout,
  .mode-choice-grid {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .filter-bar {
    grid-template-columns: 1fr;
  }

  .game-choices {
    gap: 10px;
  }

  .translation-edit-row {
    grid-template-columns: 1fr;
  }

  .create-form {
    padding: 20px;
  }
}
