:root {
  --bg: #f3e6c8;
  --bg-deep: #e6d3a4;
  --paper: #fffaf0;
  --ink: #2c2416;
  --muted: #7a6d58;
  --line: #e4d6b4;
  --accent: #d3542c;
  --accent-ink: #fffaf0;
  --good: #2f6d4f;
  --good-soft: #e5f2ea;
  --bad: #a33b32;
  --bad-soft: #f8e6e3;
  --key: #fffdf8;
  --shadow: 0 12px 32px rgba(70, 48, 16, 0.12);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: Nunito, system-ui, sans-serif;
  font-weight: 700;
  background:
    radial-gradient(1200px 500px at 50% -10%, #fbf3dd, transparent 70%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

#app {
  min-height: 100dvh;
  min-height: 100svh;
}

.boot {
  margin: 0;
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

.screen {
  width: min(440px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  min-height: 100svh;
  padding: calc(1.25rem + var(--safe-top)) 1.1rem calc(1.25rem + var(--safe-bottom));
  display: flex;
  flex-direction: column;
}

.screen--home {
  justify-content: center;
  gap: 1.2rem;
}

.screen--catalog {
  justify-content: flex-start;
  gap: 1.2rem;
  padding-top: calc(1.6rem + var(--safe-top));
}

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tag-filter__btn {
  min-height: 40px;
  padding: 0.45rem 0.85rem;
  border-radius: 12px;
  background: rgba(255, 250, 240, 0.72);
  color: var(--muted);
  box-shadow: none;
  outline: 1px solid var(--line);
  font-size: 0.95rem;
}

.tag-filter__btn.is-active {
  background: var(--accent);
  color: var(--accent-ink);
  outline-color: transparent;
  box-shadow: 0 8px 18px rgba(211, 84, 44, 0.22);
}

.tag-filter__btn:active {
  transform: translateY(1px);
}

.filter-empty {
  margin: 0.4rem 0 0;
  color: var(--muted);
  text-align: center;
}

.quiz-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.quiz-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.95rem;
  text-align: left;
  min-height: 84px;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.quiz-card__mark {
  width: 52px;
  height: 52px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: #f7edd6;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.45rem;
}

.quiz-card__body {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.quiz-card__body strong {
  font-size: 1.12rem;
}

.quiz-card__body span {
  color: var(--muted);
  font-size: 0.95rem;
}

.quiz-card__tags {
  color: var(--ink) !important;
  opacity: 0.72;
  font-size: 0.82rem !important;
  font-weight: 700;
}

.quiz-card.is-soon {
  opacity: 0.62;
  box-shadow: none;
  outline: 1px dashed var(--line);
}

.mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
  font-family: Fraunces, Georgia, serif;
  font-size: 1.7rem;
  font-weight: 700;
}

.hero h1 {
  margin: 0.35rem 0 0.4rem;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(2rem, 8vw, 2.6rem);
  line-height: 1.1;
  font-weight: 700;
}

.hero p,
.lede {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.45;
  max-width: 28ch;
}

.lobby-meta {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.card {
  margin: 0;
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.2rem;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.stats dt,
.summary-grid dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.stats dd,
.summary-grid dd {
  margin: 0.15rem 0 0;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.25rem;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.btn {
  min-height: 56px;
  padding: 0.85rem 1.2rem;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.15rem;
  box-shadow: 0 10px 22px rgba(211, 84, 44, 0.28);
}

.btn--ghost {
  color: var(--ink);
  background: var(--paper);
}

.btn--small {
  min-height: 44px;
  padding: 0.55rem 0.9rem;
  border-radius: 12px;
  font-size: 0.95rem;
}

.btn--primary.btn--small {
  font-size: 0.98rem;
  box-shadow: 0 6px 14px rgba(211, 84, 44, 0.2);
}

.section-title {
  margin: 0 0 0.55rem;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.2rem;
  font-weight: 700;
  text-align: left;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.screen.has-nav {
  position: relative;
}

.screen.has-nav.screen--history {
  padding-top: calc(3.5rem + var(--safe-top));
}

.nav-mini {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.nav-mini__end {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
}

.screen.has-nav > .nav-mini {
  position: absolute;
  top: calc(0.85rem + var(--safe-top));
  left: 1.1rem;
  right: 1.1rem;
  z-index: 2;
}

.topbar .nav-mini {
  flex: none;
  justify-content: flex-start;
  gap: 0.35rem;
}

.topbar .nav-mini__end {
  margin-left: 0;
}

.nav-mini__btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--shadow);
  color: var(--ink);
  line-height: 0;
}

.nav-mini__btn svg {
  display: block;
}

.nav-mini__btn:active {
  transform: translateY(1px);
}

.exit-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgba(44, 36, 22, 0.42);
}

.exit-dialog {
  width: min(340px, 100%);
  padding: 1.35rem 1.2rem 1.15rem;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
  text-align: center;
}

.exit-dialog h2 {
  margin: 0;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.55rem;
  line-height: 1.15;
}

.exit-dialog p {
  margin: 0.55rem 0 1.15rem;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.4;
}

.exit-dialog .actions {
  gap: 0.55rem;
}

.screen--play {
  gap: 0.85rem;
  position: relative;
}

.advance-catch {
  position: absolute;
  left: 0;
  right: 0;
  top: 4.2rem;
  bottom: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0.7rem;
  padding: 0 1rem calc(1.4rem + var(--safe-bottom));
  background: transparent;
  cursor: pointer;
}

.advance-catch__label {
  color: var(--good);
  font-size: 1.05rem;
}

.advance-timer {
  display: grid;
  place-items: center;
  line-height: 0;
  filter: drop-shadow(0 6px 14px rgba(47, 109, 79, 0.22));
}

.advance-timer svg {
  display: block;
  transform: rotate(-90deg);
}

.advance-timer__track {
  fill: none;
  stroke: rgba(47, 109, 79, 0.18);
  stroke-width: 4;
}

.advance-timer__ring {
  fill: none;
  stroke: var(--good);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 94.2;
  stroke-dashoffset: 0;
  animation: advance-ring 3s linear forwards;
}

@keyframes advance-ring {
  to {
    stroke-dashoffset: 94.2;
  }
}

@media (prefers-reduced-motion: reduce) {
  .advance-timer__ring {
    animation: none;
    stroke-dashoffset: 0;
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  position: relative;
  z-index: 8;
}

.progress {
  display: flex;
  gap: 0.35rem;
  flex: 1;
  min-width: 0;
}

.progress span {
  flex: 1;
  height: 8px;
  border-radius: 99px;
  background: rgba(44, 36, 22, 0.12);
}

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

.progress span.is-now {
  background: var(--accent);
}

.fs-toggle {
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 0.35rem;
  line-height: 0;
}

html:fullscreen .fs-toggle,
html:-webkit-full-screen .fs-toggle,
html.is-fullscreen .fs-toggle {
  display: none;
}

html:fullscreen,
html:-webkit-full-screen {
  background: var(--bg);
}

html:fullscreen body,
html:-webkit-full-screen body,
html:fullscreen #app,
html:-webkit-full-screen #app,
html:fullscreen .screen,
html:-webkit-full-screen .screen {
  min-height: 100%;
  height: 100%;
}

html.is-fullscreen .screen--play {
  overscroll-behavior: none;
}

.prompt-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  gap: 0.75rem;
  min-height: 0;
  padding: 1rem 0.6rem;
}

.prompt {
  margin: 0;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(3.2rem, 14vw, 4.6rem);
  line-height: 1;
  font-weight: 700;
}

.answer {
  min-height: 3.4rem;
  font-family: Fraunces, Georgia, serif;
  font-size: 2.4rem;
  letter-spacing: 0.04em;
}

.answer.is-empty {
  color: #cbb892;
}

.feedback {
  min-height: 1.5rem;
  font-size: 1.05rem;
}

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

.reveal-label {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.reveal {
  margin: 0;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(5.2rem, 28vw, 8rem);
  line-height: 0.9;
  font-weight: 700;
  color: var(--ink);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
}

.answer--text {
  font-family: Nunito, system-ui, sans-serif;
  font-size: clamp(1.55rem, 7vw, 2.2rem);
  letter-spacing: 0.02em;
  text-transform: none;
}

.textpad {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.textpad__row {
  display: flex;
  justify-content: center;
  gap: 0.28rem;
}

.textpad__row--ok .key--ok {
  min-width: min(100%, 220px);
  flex: 1;
}

.textpad--pl .key,
.textpad--pl .key--letter {
  min-height: 42px;
}

.key--space {
  flex: 1.3;
  min-width: 0;
  font-family: Nunito, system-ui, sans-serif;
  font-size: 0.95rem;
  text-transform: none;
}

.key--letter {
  flex: 1 1 0;
  min-width: 0;
  min-height: 46px;
  padding: 0;
  font-size: clamp(0.95rem, 3.6vw, 1.2rem);
  font-family: Nunito, system-ui, sans-serif;
  text-transform: lowercase;
}

.key {
  min-height: 58px;
  border-radius: 16px;
  background: var(--key);
  box-shadow: 0 2px 0 #d9c79a, var(--shadow);
  font-size: 1.45rem;
}

.key:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #d9c79a;
}

.key--ok {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 2px 0 #9d3a1c, 0 10px 22px rgba(211, 84, 44, 0.22);
}

.key--ok:disabled {
  opacity: 0.4;
}

.prompt--choice {
  font-size: clamp(2.6rem, 12vw, 3.8rem);
}

.prompt--expr {
  font-size: clamp(1.55rem, 6.8vw, 2.5rem);
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.prompt--text {
  font-size: clamp(1.25rem, 5.2vw, 1.85rem);
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.prompt--mixed {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(2.5rem, 11vw, 3.8rem);
  line-height: 1;
  letter-spacing: 0;
}

.prompt--to-mixed {
  font-size: clamp(1.85rem, 8vw, 2.75rem);
}

.mixed {
  display: inline-flex;
  align-items: center;
  gap: 0.22em;
}

.mixed__eq {
  font-size: 0.78em;
  padding: 0 0.04em;
}

.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.5em;
  line-height: 1;
  min-width: 1.35em;
}

.frac__top,
.frac__bot {
  padding: 0 0.28em;
}

.frac__bar {
  align-self: stretch;
  height: 0;
  margin: 0.07em 0;
  border-top: max(2px, 0.12em) solid currentColor;
}

.slot {
  min-width: 0.85em;
  margin: 0;
  padding: 0 0.06em 0.02em;
  border-bottom: 0.07em solid transparent;
  border-radius: 0.08em;
  font: inherit;
  line-height: 1;
  color: inherit;
}

.slot.is-empty {
  color: #cbb892;
}

.slot.is-active {
  border-bottom: max(3px, 0.08em) solid var(--accent);
  border-radius: 0.12em;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.frac__top .slot {
  min-width: 1.15em;
  min-height: 1.15em;
}

.reveal--mixed {
  display: flex;
  justify-content: center;
  font-size: clamp(3.2rem, 16vw, 5.2rem);
  line-height: 1;
}

.reveal--mixed .frac {
  font-size: 0.7em;
}

.review .mixed {
  font-size: 1.2rem;
  gap: 0.18em;
}

.review .frac {
  font-size: 0.62em;
}

.prompt-translation {
  margin: 0.55rem 0 0;
  max-width: 36rem;
  font-family: Nunito, system-ui, sans-serif;
  font-size: clamp(0.95rem, 3.6vw, 1.15rem);
  font-weight: 600;
  line-height: 1.35;
  color: color-mix(in srgb, var(--ink) 62%, transparent);
  text-wrap: balance;
}

.reveal--text {
  font-size: clamp(1.6rem, 7vw, 2.6rem);
  line-height: 1.2;
}

.choices--text {
  gap: 0.5rem;
}

.choice--text {
  min-height: 64px;
  padding: 0.55rem 0.65rem;
  font-size: clamp(0.95rem, 3.8vw, 1.25rem);
  line-height: 1.2;
  font-weight: 600;
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.choice {
  min-height: 72px;
  border-radius: 16px;
  background: var(--key);
  box-shadow: 0 2px 0 #d9c79a, var(--shadow);
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(1.6rem, 7vw, 2rem);
}

.choice:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #d9c79a;
}

.choice.is-correct {
  background: var(--good-soft);
  color: var(--good);
  box-shadow: 0 2px 0 #8bb89a;
}

.choice.is-wrong {
  background: var(--bad-soft);
  color: var(--bad);
  box-shadow: 0 2px 0 #d7a39d;
}

.choice.is-idle {
  opacity: 0.45;
}

.choice--mixed {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 84px;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(1.4rem, 6.2vw, 1.85rem);
  line-height: 1;
}

.choice--mixed .frac {
  font-size: 0.52em;
}

.screen--summary {
  justify-content: center;
  gap: 1.1rem;
  text-align: center;
}

.screen--summary.has-misses {
  justify-content: flex-start;
  padding-top: calc(3.5rem + var(--safe-top));
}

.misses {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: 100%;
}

.score-big {
  margin: 0;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(3.4rem, 16vw, 5rem);
  line-height: 1;
}

.score-caption {
  margin: 0.3rem 0 0;
  color: var(--muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  text-align: left;
}

.screen--history {
  justify-content: flex-start;
  gap: 1rem;
  text-align: center;
}

.screen--history .lede {
  margin-inline: auto;
}

.history {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.history-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  text-align: left;
  min-height: 72px;
  padding: 0.85rem 1rem;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.history-item__score {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.45rem;
  min-width: 4.2rem;
}

.history-item__meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.history-item__meta strong {
  color: var(--ink);
}

.review-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  text-align: left;
}

.review {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "prompt mark"
    "answer answer";
  gap: 0.15rem 0.7rem;
  padding: 0.75rem 0.9rem;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.review.is-good {
  background: var(--good-soft);
}

.review.is-bad {
  background: var(--bad-soft);
}

.review__prompt {
  grid-area: prompt;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}

.review__mark {
  grid-area: mark;
  color: var(--good);
}

.review.is-bad .review__mark {
  color: var(--bad);
}

.review__answer {
  grid-area: answer;
  color: var(--muted);
  font-size: 0.95rem;
}

.review__pair {
  grid-area: answer;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.2rem;
}

.review__yours,
.review__expected {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
}

.review__label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.review__yours strong,
.review__expected strong {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.2rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.review__yours strong {
  color: var(--bad);
}

.review__expected strong {
  color: var(--good);
}

.flash-good .prompt-wrap {
  background: var(--good-soft);
  border-radius: var(--radius);
}

.flash-bad .prompt-wrap {
  background: var(--bad-soft);
  border-radius: var(--radius);
}

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

@media (min-height: 780px) {
  .key {
    min-height: 68px;
  }

  .choice {
    min-height: 84px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .key:active,
  .choice:active:not(:disabled) {
    transform: none;
  }
}
