:root {
  --ink: #24312d;
  --cream: #fffbf2;
  --yellow: #ffd650;
  --green: #8bcfa8;
  --orange: #f58d65;
  --paper-shadow: 0 18px 42px rgba(36, 49, 45, 0.16);
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100svh;
  margin: 0;
  color: var(--ink);
  font-family: ui-rounded, "Hiragino Maru Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  background:
    radial-gradient(circle at 8% 8%, #ffe08a 0 5.2rem, transparent 5.25rem),
    radial-gradient(circle at 92% 17%, #bce5ca 0 7.2rem, transparent 7.25rem),
    linear-gradient(140deg, #fff9e8, #fffdf8 60%, #f0fff5);
}

.app-shell {
  width: min(100%, 580px);
  min-height: 100svh;
  margin: 0 auto;
  padding: 2.6rem 1.25rem 2rem;
  text-align: center;
}

.page-header { margin-bottom: 1.05rem; }

.eyebrow {
  margin: 0 0 .35rem;
  color: #537464;
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .14em;
}

h1 {
  margin: 0;
  font-family: ui-rounded, "Arial Rounded MT Bold", sans-serif;
  font-size: clamp(2.25rem, 9vw, 3.7rem);
  letter-spacing: -.055em;
  line-height: 1;
}

.instructions { margin: .6rem 0 0; color: #587267; font-size: .9rem; font-weight: 800; }

.study-area { display: grid; justify-items: center; }

.counter {
  min-width: 4.7rem;
  margin: 0 0 .7rem;
  padding: .32rem .78rem;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  font-weight: 800;
}

.flashcard {
  width: min(100%, 420px);
  aspect-ratio: 1 / 1.08;
  padding: 0;
  border: 0;
  border-radius: 1.6rem;
  background: transparent;
  cursor: pointer;
  perspective: 1200px;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}

.flashcard:focus-visible { outline: 5px solid #f58d65; outline-offset: 5px; }

.card-inner {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  border: 3px solid var(--ink);
  border-radius: 1.6rem;
  box-shadow: var(--paper-shadow);
  transform-style: preserve-3d;
  transition: transform 440ms cubic-bezier(.22, .76, .3, 1);
}

.flashcard.is-flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  display: flex;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 1.38rem;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-front { flex-direction: column; background: white; }

.card-front img {
  width: min(84%, 330px);
  max-height: 78%;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.tap-hint, .listen-hint {
  position: absolute;
  bottom: 1.1rem;
  color: #587267;
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .04em;
}

.card-back {
  flex-direction: column;
  gap: .8rem;
  background: var(--green);
  transform: rotateY(180deg);
}

.word {
  max-width: 90%;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-family: ui-rounded, "Arial Rounded MT Bold", sans-serif;
  font-size: clamp(2.8rem, 14vw, 5.4rem);
  font-weight: 900;
  letter-spacing: -.06em;
  line-height: 1;
}

.listen-hint { color: #345e49; }

.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: .55rem;
  align-items: center;
  margin: 1.35rem auto 0;
}

.control-button {
  min-height: 3.5rem;
  padding: .7rem .65rem;
  border: 2px solid var(--ink);
  border-radius: .9rem;
  color: var(--ink);
  font: inherit;
  font-size: clamp(.78rem, 3vw, .95rem);
  font-weight: 800;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.control-button:hover { transform: translateY(-2px); box-shadow: 0 4px 0 var(--ink); }
.control-button:active { transform: translateY(1px); box-shadow: none; }
.control-button:focus-visible { outline: 4px solid #f58d65; outline-offset: 2px; }
.secondary { background: white; }
.shuffle { background: var(--yellow); white-space: nowrap; }
.primary { background: var(--orange); }
.icon-button { font-size: 1.55rem; line-height: 1; }

.keyboard-note { margin: 1.35rem 0 0; color: #587267; font-size: .78rem; font-weight: 700; }

@media (max-width: 640px) {
  body { overflow: hidden; }

  .app-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: .7rem;
    height: 100svh;
    padding: max(.7rem, env(safe-area-inset-top)) 1rem max(.75rem, env(safe-area-inset-bottom));
  }

  .page-header { margin: 0; }
  .eyebrow { margin-bottom: .2rem; font-size: .66rem; }
  h1 { font-size: clamp(2rem, 10vw, 2.65rem); }
  .instructions { margin-top: .35rem; font-size: .78rem; }

  .study-area {
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
    width: 100%;
  }

  .counter { margin-bottom: .55rem; padding: .22rem .65rem; font-size: .85rem; }

  .flashcard {
    width: min(100%, 430px);
    height: 100%;
    max-height: 505px;
    min-height: 0;
    aspect-ratio: auto;
  }

  .card-inner { border-width: 2.5px; border-radius: 1.35rem; }
  .card-face { border-radius: 1.18rem; }
  .card-front img { width: min(90%, 355px); max-height: 80%; }
  .tap-hint, .listen-hint { bottom: .82rem; font-size: .72rem; }

  .bottom-dock {
    padding-top: .25rem;
    border-top: 1px solid rgba(36, 49, 45, .16);
  }

  .controls {
    grid-template-columns: 3.5rem minmax(0, 1fr) 3.5rem;
    gap: .65rem;
    margin: 0;
  }

  .control-button { min-height: 3.65rem; border-radius: 1.1rem; }
  .shuffle { font-size: .95rem; }
  .keyboard-note { display: none; }
}

@media (max-height: 640px) and (max-width: 640px) {
  .app-shell { gap: .45rem; }
  .eyebrow { display: none; }
  .instructions { display: none; }
  .counter { margin-bottom: .35rem; }
  .flashcard { max-height: none; }
  .control-button { min-height: 3.25rem; }
}

@media (prefers-reduced-motion: reduce) { .card-inner, .control-button { transition: none; } }
