:root {
  color-scheme: light;
  --ink: #18231f;
  --muted: #66716c;
  --paper: #fffdf8;
  --canvas: #e8e3da;
  --accent: #ff6647;
  --accent-dark: #d94a2f;
  --mint: #aee8d1;
  --yes: #17825f;
  --no: #c74735;
  --line: rgba(24, 35, 31, 0.13);
  --shadow: 0 22px 55px rgba(43, 39, 31, 0.16);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 102, 71, 0.13), transparent 32%),
    radial-gradient(circle at 82% 88%, rgba(23, 130, 95, 0.1), transparent 30%),
    var(--canvas);
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid #2469d8;
  outline-offset: 3px;
}

.app-shell {
  position: relative;
  width: min(100%, 430px);
  height: 100dvh;
  min-height: 560px;
  margin: 0 auto;
  overflow: hidden;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  height: 100%;
}

.screen.is-active {
  display: flex;
}

.start-screen,
.tutorial-screen,
.result-screen,
.error-screen {
  flex-direction: column;
  padding:
    max(24px, env(safe-area-inset-top))
    24px
    max(22px, env(safe-area-inset-bottom));
}

.tutorial-screen {
  flex-direction: column;
  justify-content: space-between;
  isolation: isolate;
}

.tutorial-heading {
  text-align: center;
}

.tutorial-heading .eyebrow {
  margin-bottom: 8px;
}

.tutorial-heading h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 8vw, 2.35rem);
  font-weight: 500;
  letter-spacing: -0.035em;
}

.tutorial-heading h1 strong {
  color: var(--accent-dark);
  font-family: Inter, ui-sans-serif, sans-serif;
  font-size: 0.86em;
  font-weight: 850;
  letter-spacing: 0.015em;
  text-transform: uppercase;
}

.tutorial-heading > p:last-child,
.tutorial-actions > p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.tutorial-stage {
  position: relative;
  display: grid;
  min-height: 0;
  flex: 1;
  place-items: center;
  margin-block: 12px;
}

.tutorial-card {
  position: relative;
  display: grid;
  width: min(100%, 374px);
  aspect-ratio: 4 / 5;
  place-items: center;
  overflow: hidden;
  border: 6px solid #fffdf8;
  border-radius: 26px;
  background:
    radial-gradient(circle at 48% 38%, #fff7c7 0 22%, transparent 23%),
    linear-gradient(145deg, #ffe49a, #ffd16f);
  box-shadow:
    0 24px 45px rgba(35, 42, 38, 0.18),
    0 6px 14px rgba(35, 42, 38, 0.1),
    0 0 0 1px rgba(24, 35, 31, 0.08);
  animation: tutorial-swipe 6.4s ease-in-out infinite;
  will-change: transform;
}

.tutorial-emoji {
  font-size: clamp(7rem, 32vw, 9.2rem);
  filter: drop-shadow(0 8px 8px rgba(111, 77, 20, 0.14));
  line-height: 1;
}

.tutorial-stamp {
  position: absolute;
  z-index: 1;
  top: 24px;
  padding: 6px 10px;
  border: 3px solid currentColor;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.88);
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  opacity: 0;
}

.tutorial-stamp--yes {
  left: 18px;
  color: var(--yes);
  transform: rotate(-7deg);
  animation: tutorial-yes-stamp 6.4s ease-in-out infinite;
}

.tutorial-stamp--no {
  right: 18px;
  color: var(--no);
  transform: rotate(7deg);
  animation: tutorial-no-stamp 6.4s ease-in-out infinite;
}

.tutorial-direction {
  position: absolute;
  z-index: 2;
  top: 50%;
  padding: 8px 10px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 6px 18px rgba(35, 42, 38, 0.13);
  font-size: 0.94rem;
  font-weight: 900;
  letter-spacing: 0.055em;
  line-height: 1;
  transform: translateY(-50%);
  text-transform: uppercase;
}

.tutorial-direction--no {
  left: -12px;
  color: var(--no);
}

.tutorial-direction--yes {
  right: -12px;
  color: var(--yes);
}

.tutorial-actions {
  display: grid;
  gap: 11px;
}

.tutorial-actions > p {
  margin: 0;
  text-align: center;
}

.tutorial-answer-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tutorial-answer {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 5px 16px rgba(32, 39, 35, 0.08);
  font-weight: 850;
}

.tutorial-answer span {
  display: inline-grid;
  width: 24px;
  height: 24px;
  margin-inline: 8px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
}

.tutorial-answer--no {
  animation: tutorial-no-button 6.4s ease-in-out infinite;
}

.tutorial-answer--no span {
  background: var(--no);
}

.tutorial-answer--yes {
  animation: tutorial-yes-button 6.4s ease-in-out infinite;
}

.tutorial-answer--yes span {
  background: var(--yes);
}

@keyframes tutorial-swipe {
  0%, 7%, 24%, 32%, 49%, 100% {
    transform: translateX(0) rotate(0);
  }
  15% {
    transform: translateX(18px) rotate(3deg);
  }
  40% {
    transform: translateX(-18px) rotate(-3deg);
  }
}

@keyframes tutorial-yes-stamp {
  0%, 7%, 24%, 100% { opacity: 0; }
  13%, 19% { opacity: 1; }
}

@keyframes tutorial-no-stamp {
  0%, 32%, 49%, 100% { opacity: 0; }
  38%, 44% { opacity: 1; }
}

@keyframes tutorial-yes-button {
  0%, 55%, 70%, 100% {
    border-color: var(--line);
    box-shadow: 0 5px 16px rgba(32, 39, 35, 0.08);
    transform: translateY(0);
  }
  61%, 66% {
    border-color: var(--yes);
    box-shadow: 0 0 0 4px rgba(23, 130, 95, 0.13), 0 9px 20px rgba(23, 130, 95, 0.16);
    transform: translateY(-2px);
  }
}

@keyframes tutorial-no-button {
  0%, 72%, 88%, 100% {
    border-color: var(--line);
    box-shadow: 0 5px 16px rgba(32, 39, 35, 0.08);
    transform: translateY(0);
  }
  78%, 84% {
    border-color: var(--no);
    box-shadow: 0 0 0 4px rgba(199, 71, 53, 0.12), 0 9px 20px rgba(199, 71, 53, 0.15);
    transform: translateY(-2px);
  }
}

.start-screen {
  justify-content: space-between;
  isolation: isolate;
}

.start-screen::before,
.start-screen::after {
  position: absolute;
  z-index: -1;
  content: "";
  border-radius: 999px;
  filter: blur(1px);
}

.start-screen::before {
  top: -95px;
  right: -90px;
  width: 250px;
  height: 250px;
  background: var(--mint);
}

.start-screen::after {
  bottom: 125px;
  left: -115px;
  width: 220px;
  height: 220px;
  background: #ffd28b;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  color: #fff;
  background: var(--ink);
  font-family: Georgia, serif;
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.start-copy {
  margin-top: auto;
  margin-bottom: auto;
  padding-block: 24px;
}

.start-copy h1,
.result-top h1,
.error-screen h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.6rem, 12vw, 4rem);
  font-weight: 600;
  line-height: 0.96;
  letter-spacing: -0.055em;
}

.start-copy h1 span {
  color: var(--accent-dark);
}

.start-lede {
  margin: 24px 0 0;
  color: #38443f;
  font-size: 1.05rem;
  line-height: 1.55;
}

.challenge-size {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin: 22px 0 0;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.challenge-size span {
  color: var(--accent);
}

.start-actions {
  position: relative;
  z-index: 1;
}

.primary-button {
  display: flex;
  width: 100%;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border: 0;
  border-radius: 17px;
  color: #fff;
  background: var(--ink);
  box-shadow: 0 10px 24px rgba(24, 35, 31, 0.18);
  font-weight: 800;
  cursor: pointer;
}

.primary-button:hover:not(:disabled) {
  background: #2c3934;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.gesture-note,
.swipe-hint {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  text-align: center;
}

.game-screen {
  display: none;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 8px;
  padding:
    max(12px, env(safe-area-inset-top))
    16px
    max(12px, env(safe-area-inset-bottom));
}

.game-screen.is-active {
  display: grid;
}

.progress-stack {
  display: grid;
  gap: 8px;
}

.progress-row {
  display: grid;
  gap: 5px;
}

.progress-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.67rem;
  letter-spacing: 0.02em;
}

.progress-label strong {
  overflow: hidden;
  max-width: 65%;
  color: var(--ink);
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: #e6e2da;
}

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

.progress-row--overall .progress-track {
  height: 3px;
}

.progress-row--overall .progress-track span {
  background: var(--ink);
}

.question {
  min-height: 52px;
  margin: 0;
  padding: 9px 8px 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.22rem, 5.5vw, 1.55rem);
  font-weight: 500;
  line-height: 1.15;
  text-align: center;
}

.question strong {
  color: var(--accent-dark);
  font-family: Inter, ui-sans-serif, sans-serif;
  font-size: 0.86em;
  font-weight: 850;
  letter-spacing: 0.025em;
}

.card-stage {
  position: relative;
  display: flex;
  min-height: 0;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 2px 4px;
}

.image-card {
  --drag-x: 0px;
  --drag-rotation: 0deg;
  --yes-opacity: 0;
  --no-opacity: 0;
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  max-width: 100%;
  place-items: center;
  overflow: visible;
  padding: 8px;
  border: 0;
  background: transparent;
  cursor: grab;
  touch-action: pan-y;
  transform: translateX(var(--drag-x)) rotate(var(--drag-rotation));
  user-select: none;
  will-change: transform;
}

.image-card.is-dragging {
  cursor: grabbing;
}

.image-card.is-returning,
.image-card.is-exiting {
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.image-card.is-correct .image-frame {
  border-color: rgba(23, 130, 95, 0.82);
}

.image-card.is-incorrect .image-frame {
  border-color: rgba(199, 71, 53, 0.82);
}

.image-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  width: auto;
  height: calc(100% - 28px);
  min-width: 0;
  min-height: 0;
  max-width: calc(100% - 28px);
  max-height: calc(100% - 28px);
  aspect-ratio: 17 / 25;
  place-items: center;
  padding: 10px;
  border: 1px solid rgba(78, 63, 43, 0.14);
  border-radius: 26px;
  background: #f1e8da;
  box-shadow:
    0 22px 42px rgba(35, 42, 38, 0.15),
    0 6px 14px rgba(35, 42, 38, 0.09);
  transform: translate(-50%, -50%);
  transition: border-color 140ms ease;
}

.image-card img {
  grid-area: 1 / 1;
  display: block;
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 2 / 3;
  object-fit: contain;
  border: 0;
  border-radius: 18px;
  background: #e8dece;
  box-shadow: 0 0 0 1px rgba(56, 45, 31, 0.1);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.image-card img[hidden] {
  display: none;
}

.image-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.image-fallback[hidden] {
  display: none;
}

.image-fallback > span {
  color: var(--accent);
  font-size: 3rem;
}

.image-fallback strong {
  margin-top: 8px;
  color: var(--ink);
}

.image-fallback small {
  margin-top: 5px;
  line-height: 1.4;
}

.swipe-stamp {
  position: absolute;
  z-index: 2;
  top: 28px;
  padding: 7px 12px;
  border: 3px solid currentColor;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.8);
  font-size: 1.55rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  pointer-events: none;
}

.swipe-stamp--no {
  right: 22px;
  color: var(--no);
  opacity: var(--no-opacity);
  transform: rotate(8deg);
}

.swipe-stamp--yes {
  left: 22px;
  color: var(--yes);
  opacity: var(--yes-opacity);
  transform: rotate(-8deg);
}

.answer-feedback,
.word-summary {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 16px;
  display: flex;
  width: calc(100% - 36px);
  max-width: 340px;
  flex-direction: column;
  gap: 3px;
  padding: 11px 14px;
  border-radius: 14px;
  color: #fff;
  box-shadow: 0 8px 25px rgba(22, 28, 25, 0.24);
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, 8px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.answer-feedback.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.answer-feedback.is-correct {
  background: rgba(20, 112, 81, 0.96);
}

.answer-feedback.is-incorrect {
  background: rgba(175, 55, 41, 0.97);
}

.answer-feedback span {
  font-size: 0.72rem;
  line-height: 1.25;
}

.word-summary {
  display: none;
  top: 50%;
  bottom: auto;
  gap: 5px;
  padding: 20px;
  background: rgba(24, 35, 31, 0.96);
  opacity: 1;
  transform: translate(-50%, -50%);
}

.word-summary[hidden] {
  display: none;
}

.word-summary.is-visible {
  display: flex;
}

.word-summary strong {
  font-size: 1.15rem;
  letter-spacing: 0.06em;
}

.word-summary span {
  font-size: 0.82rem;
}

.swipe-hint {
  min-height: 16px;
  margin: 0;
  transition: opacity 160ms ease;
}

.swipe-hint span {
  color: var(--accent);
}

.swipe-hint.is-hidden {
  opacity: 0;
}

.answer-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.answer-button {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 5px 16px rgba(32, 39, 35, 0.08);
  font-weight: 850;
  cursor: pointer;
}

.answer-button span {
  display: inline-grid;
  width: 26px;
  height: 26px;
  margin-inline: 8px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
}

.answer-button--no span {
  background: var(--no);
}

.answer-button--yes span {
  background: var(--yes);
}

.answer-button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 7px 18px rgba(32, 39, 35, 0.12);
}

.answer-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.result-screen {
  gap: 14px;
  overflow-y: auto;
}

.result-top h1 {
  font-size: clamp(2.4rem, 11vw, 3.5rem);
}

.result-message {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.result-stat {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 11px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: #f4efe5;
}

.result-stat--remembered {
  background: var(--mint);
}

.result-stat--missed {
  background: #ffe5dc;
}

.result-stat span {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 750;
  line-height: 1.15;
  text-transform: uppercase;
}

.result-stat strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 600;
  line-height: 1;
}

.accuracy-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 3px;
}

.accuracy-line span {
  color: var(--accent-dark);
  font-size: 1.3rem;
  font-weight: 900;
}

.review-panel,
.download-panel {
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
}

.review-panel p {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.review-panel div {
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 750;
  line-height: 1.55;
}

.review-panel.has-missed {
  border-color: rgba(199, 71, 53, 0.28);
  background: #fff7f4;
}

.review-panel.has-missed p {
  color: var(--no);
}

.review-panel ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.review-panel li {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--no);
  font-size: 0.86rem;
  font-weight: 850;
  letter-spacing: 0.025em;
}

.review-panel li::before {
  color: var(--accent);
  content: "•";
  font-size: 1.1rem;
  line-height: 1;
}

.download-panel {
  background: #f4efe5;
}

.download-panel h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
}

.download-panel p {
  margin: 6px 0 12px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.store-links {
  display: flex;
  gap: 9px;
}

.store-links a {
  display: grid;
  min-height: 44px;
  flex: 1;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: var(--ink);
  font-size: 0.76rem;
  font-weight: 800;
  text-decoration: none;
}

.next-round-actions {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.next-round-actions > p {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
  text-align: center;
}

.error-screen {
  justify-content: center;
}

.error-screen h1 {
  font-size: 2.5rem;
}

.error-screen p:last-child {
  color: var(--muted);
  line-height: 1.5;
}

@media (max-height: 680px) {
  .game-screen {
    gap: 5px;
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .question {
    min-height: 42px;
    font-size: 1.1rem;
  }

  .answer-button {
    min-height: 48px;
  }
}

@media (min-width: 431px) {
  body {
    padding-block: 18px;
  }

  .app-shell {
    height: calc(100dvh - 36px);
    min-height: 620px;
    border-radius: 30px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
