:root {
  --bg: #f4f1ea;
  --bg-accent: #ece6da;
  --card: #ffffff;
  --ink: #2a2622;
  --ink-soft: #6b6358;
  --line: #e3ddd1;
  --brand: #5b6cff;
  --brand-deep: #3f4ed6;
  --brand-soft: #eef0ff;
  --good: #2f9e5e;
  --bad: #d24b4b;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(42, 38, 34, 0.08);
}

* {
  box-sizing: border-box;
}

/* Visible focus ring for keyboard users (mouse clicks stay clean). */
:focus-visible {
  outline: 3px solid rgba(91, 108, 255, 0.55);
  outline-offset: 2px;
  border-radius: 6px;
}

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--bg-accent), transparent 60%),
    var(--bg);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 32px 20px 48px;
}

.app {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header */
.app__header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.app__title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: clamp(1.9rem, 6vw, 2.6rem);
  letter-spacing: -0.01em;
  margin: 0;
}

.help-btn {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--brand);
  background: var(--card);
  color: var(--brand-deep);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, transform 0.15s ease;
}

.help-btn:hover {
  background: var(--brand-soft);
  transform: translateY(-1px);
}

.app__subtitle {
  text-align: center;
  color: var(--ink-soft);
  margin: -8px 0 0;
  font-size: 0.98rem;
}

/* Trainer switcher */
.trainer-switch {
  display: inline-flex;
  align-self: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
  box-shadow: var(--shadow);
}

.trainer-switch__btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 10px 22px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.trainer-switch__btn + .trainer-switch__btn {
  border-left: 1px solid var(--line);
}

.trainer-switch__btn:hover {
  background: var(--bg-accent);
}

.trainer-switch__btn.is-active {
  background: var(--brand);
  color: #fff;
}

/* Trainer panels (each wraps that trainer's cards) */
.trainer {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.trainer[hidden] {
  display: none;
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Playback controls */
.play-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.play-btn {
  flex: 1 1 auto;
  min-width: 200px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--brand), var(--brand-deep));
  color: #fff;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 16px 24px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 8px 18px rgba(91, 108, 255, 0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

.play-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 22px rgba(91, 108, 255, 0.34);
}

.play-btn__icon {
  font-size: 0.85em;
}

.replay-btn {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.98rem;
  font-weight: 500;
  padding: 16px 18px;
  cursor: pointer;
  transition: background 0.12s ease;
}

.replay-btn:not(:disabled):hover {
  background: var(--bg-accent);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Audio status */
.audio-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: -8px 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  min-height: 20px;
}

.audio-status--hidden {
  display: none;
}

.audio-status--error {
  color: var(--bad);
}

.audio-status__spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.audio-status--error .audio-status__spinner,
.audio-status--ready .audio-status__spinner {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Answers */
.answers {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  min-height: 48px;
}

.answer-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.1s ease,
    color 0.12s ease;
}

.answer-btn .answer-btn__name {
  font-weight: 400;
  color: var(--ink-soft);
  margin-left: 6px;
  font-size: 0.85em;
}

/* Keyboard hint badge (the number key that selects this answer). */
.answer-btn__key {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  margin-right: 7px;
  border-radius: 5px;
  background: var(--bg-accent);
  color: var(--ink-soft);
  font-size: 0.7rem;
  font-weight: 700;
  vertical-align: middle;
  transition: background 0.12s ease, color 0.12s ease;
}

.answer-btn.is-correct .answer-btn__key,
.answer-btn.is-incorrect .answer-btn__key {
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
}

.answer-btn:not(:disabled):hover {
  border-color: var(--brand);
  background: var(--brand-soft);
  transform: translateY(-1px);
}

.answer-btn:disabled {
  cursor: default;
  opacity: 1; /* keep revealed colors readable */
}

.answer-btn.is-correct {
  background: var(--good);
  border-color: var(--good);
  color: #fff;
  animation: pop 0.32s ease;
}

.answer-btn.is-correct .answer-btn__name {
  color: rgba(255, 255, 255, 0.85);
}

.answer-btn.is-incorrect {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}

.answer-btn.is-incorrect .answer-btn__name {
  color: rgba(255, 255, 255, 0.85);
}

.answer-btn.is-dimmed {
  opacity: 0.45;
}

/* Tentative selection (inversion mode, before both picks are in) */
.answer-btn.is-selected {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-deep);
}

/* Inversion answer row */
.answers--inversions {
  margin-top: -8px;
}

.answers[hidden] {
  display: none;
}

/* Feedback + advance */
.round-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
}

.feedback {
  margin: 0;
  font-weight: 600;
  font-size: 1rem;
}

.feedback.is-correct,
.feedback.is-incorrect {
  animation: feedback-in 0.28s ease;
}

.feedback.is-correct {
  color: var(--good);
}

.feedback.is-incorrect {
  color: var(--bad);
}

.next-btn {
  flex: none;
  border: none;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 0.98rem;
  font-weight: 600;
  padding: 12px 20px;
  cursor: pointer;
  transition: opacity 0.12s ease, transform 0.1s ease;
}

.next-btn:not(:disabled):hover {
  transform: translateY(-1px);
}

@media (max-width: 480px) {
  .round-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .next-btn {
    width: 100%;
  }
}

/* Staff */
.staff {
  border: 1px dashed var(--line);
  border-radius: 12px;
  min-height: 140px;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 16px;
}

.staff svg {
  animation: staff-in 0.35s ease;
}

/* Settings */
.settings__title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.2rem;
  margin: 0;
}

.settings__group {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.settings__label {
  font-weight: 600;
  font-size: 0.9rem;
  width: 80px;
  flex: none;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.seg-btn {
  border: none;
  background: var(--card);
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px 18px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.seg-btn + .seg-btn {
  border-left: 1px solid var(--line);
}

.seg-btn:hover {
  background: var(--bg-accent);
}

.seg-btn.is-active {
  background: var(--brand);
  color: #fff;
}

.toggles {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
  cursor: pointer;
}

.toggle.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.toggle.is-disabled input {
  cursor: not-allowed;
}

/* Stats */
.stats__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stats__title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.2rem;
  margin: 0;
}

.reset-btn {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.reset-btn:hover {
  background: #fdeaea;
  border-color: var(--bad);
  color: var(--bad);
}

.stats__overall {
  margin: 0;
  font-size: 1rem;
  color: var(--ink);
}

.stats__overall strong {
  font-size: 1.15rem;
}

.stats__overall--empty {
  color: var(--ink-soft);
  font-style: italic;
}

.stats__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}

.stat-row__label {
  font-weight: 600;
}

.stat-row__bar {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-accent);
  overflow: hidden;
}

.stat-row__fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--brand-deep));
  transition: width 0.3s ease;
}

.stat-row__count {
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Placeholders */
.placeholder {
  color: var(--ink-soft);
  font-size: 0.92rem;
  text-align: center;
  margin: 0;
  font-style: italic;
}

/* Help modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 26, 22, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fade-in 0.15s ease;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(30, 26, 22, 0.3);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px 28px 24px;
  animation: pop-in 0.16s ease;
}

.modal__close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.12s ease;
}

.modal__close:hover {
  background: var(--bg-accent);
}

.modal__title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.5rem;
  margin: 0 36px 8px 0;
}

.modal__body {
  color: var(--ink);
  font-size: 0.96rem;
  line-height: 1.55;
}

.modal__body h3 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.05rem;
  margin: 20px 0 6px;
}

.modal__body p {
  margin: 0 0 10px;
}

.modal__body ol,
.modal__body ul {
  margin: 0 0 10px;
  padding-left: 22px;
}

.modal__body li {
  margin-bottom: 4px;
}

.install-btn {
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--brand), var(--brand-deep));
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 11px 18px;
  cursor: pointer;
  margin: 4px 0 10px;
  box-shadow: 0 6px 14px rgba(91, 108, 255, 0.28);
  transition: transform 0.12s ease;
}

.install-btn:hover {
  transform: translateY(-1px);
}

.install-btn[hidden] {
  display: none;
}

.install-steps {
  margin-top: 4px;
}

.kbd {
  display: inline-block;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg);
  padding: 0 6px;
  font-size: 0.85em;
  font-weight: 600;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes feedback-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

@keyframes staff-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* Footer */
.app__footer {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.app__footer p {
  margin: 0;
}

/* Responsive */
@media (max-width: 480px) {
  body {
    padding: 20px 14px 36px;
  }

  .card {
    padding: 18px;
  }

  .play-btn,
  .replay-btn {
    flex: 1 1 100%;
    min-width: 0;
  }
}
