:root {
  --bg-top: #fff4db;
  --bg-mid: #ffe2cf;
  --bg-bottom: #d5f8ef;
  --panel: rgba(255, 255, 255, 0.72);
  --ink: #1f2f3d;
  --ink-soft: #425768;
  --accent: #ff6f61;
  --accent-deep: #dd4a3f;
  --accent-alt: #189d8d;
  --success: #0f9f6f;
  --danger: #b83445;
  --shadow: 0 24px 50px rgba(28, 45, 58, 0.18);
  --radius: 24px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
}

body {
  color: var(--ink);
  font-family: "Manrope", "Segoe UI", sans-serif;
  background: linear-gradient(165deg, var(--bg-top), var(--bg-mid), var(--bg-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(8px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(14px);
  pointer-events: none;
}

body::before {
  width: 320px;
  height: 320px;
  background: rgba(255, 111, 97, 0.28);
  top: -60px;
  right: -50px;
}

body::after {
  width: 280px;
  height: 280px;
  background: rgba(24, 157, 141, 0.25);
  left: -50px;
  bottom: -50px;
}

/* ── App Shell: fills viewport, no scroll ── */
.app-shell {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Hero: compact on mobile ── */
.hero {
  text-align: center;
  flex-shrink: 0;
}

.eyebrow {
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-alt);
  font-size: 0.65rem;
}

h1 {
  line-height: 1.05;
  font-size: 1.15rem;
  font-family: "Fraunces", Georgia, serif;
  margin: 2px 0;
}

.hero > p {
  display: none;
}

/* ── Stats: single horizontal row ── */
.stats {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(4, 1fr);
  flex-shrink: 0;
  margin: 6px 0;
}

.stats article {
  background: rgba(255, 255, 255, 0.8);
  border-radius: 10px;
  padding: 4px 2px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.9);
}

.stats .label {
  display: block;
  color: var(--ink-soft);
  font-size: 0.6rem;
  line-height: 1.2;
}

.stats strong {
  font-size: 1rem;
  font-family: "Fraunces", Georgia, serif;
  line-height: 1.2;
}

/* ── Game Zone: fills remaining space ── */
.game-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Flashcard: grows to fill available space ── */
.flashcard {
  border: 0;
  background: transparent;
  width: 100%;
  max-width: 280px;
  flex: 1;
  min-height: 0;
  border-radius: 16px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.65s ease;
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

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

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  overflow: hidden;
  backface-visibility: hidden;
}

.card-front {
  background: linear-gradient(135deg, #f8fbff, #dceeff);
}

.card-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-loading {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.85);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700;
  color: var(--accent-deep);
  font-size: 0.8rem;
  max-width: 82%;
  text-align: center;
}

.image-loading.hidden {
  display: none;
}

.tap-note {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #ffffff;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
}

.card-back {
  transform: rotateY(180deg);
  background: radial-gradient(circle at top left, #ffffff, #e7fff5 65%);
  display: grid;
  place-content: center;
  text-align: center;
  gap: 4px;
  padding: 14px;
}

.spanish-word {
  font-size: clamp(1.5rem, 7vw, 2.2rem);
  font-family: "Fraunces", Georgia, serif;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.english-word {
  font-size: 0.9rem;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

/* ── Guess Form ── */
.guess-form {
  width: 100%;
  flex-shrink: 0;
}

.guess-form label {
  font-weight: 700;
  font-size: 0.8rem;
  display: block;
  margin-bottom: 3px;
}

.guess-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

input {
  border: 1px solid rgba(40, 60, 80, 0.22);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.92);
  min-height: 40px;
}

input:focus {
  outline: 2px solid rgba(24, 157, 141, 0.3);
  border-color: var(--accent-alt);
}

/* ── Action Buttons ── */
.actions {
  display: flex;
  justify-content: center;
  gap: 6px;
  width: 100%;
  flex-shrink: 0;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  min-height: 38px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  flex: 1;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #ffa06f);
  color: #fff;
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-deep), #f27f57);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  border: 1px solid rgba(40, 60, 80, 0.15);
}

.btn-secondary:hover {
  border-color: rgba(24, 157, 141, 0.45);
  color: var(--accent-alt);
}

/* ── Hint / Status ── */
.hint-text,
.status-text {
  min-height: 1.2em;
  font-weight: 600;
  text-align: center;
  font-size: 0.78rem;
  flex-shrink: 0;
  line-height: 1.3;
}

.hint-text {
  color: var(--accent-alt);
}

.status-text {
  color: var(--ink-soft);
}

.status-text.success {
  color: var(--success);
}

.status-text.error {
  color: var(--danger);
}

/* ── SEO Links: hidden on mobile, visible on desktop ── */
.seo-links {
  display: none;
}

/* ════════════════════════════════════════════
   TABLET (481px+)
   ════════════════════════════════════════════ */
@media (min-width: 481px) {
  body {
    padding:
      max(14px, env(safe-area-inset-top))
      max(14px, env(safe-area-inset-right))
      max(14px, env(safe-area-inset-bottom))
      max(14px, env(safe-area-inset-left));
  }

  .app-shell {
    padding: 14px 18px;
    border-radius: 20px;
  }

  .eyebrow {
    font-size: 0.72rem;
  }

  h1 {
    font-size: 1.35rem;
  }

  .stats .label {
    font-size: 0.7rem;
  }

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

  .flashcard {
    max-width: 340px;
  }

  .btn {
    font-size: 0.9rem;
    padding: 10px 16px;
    min-height: 42px;
    flex: 0 1 auto;
  }

  .guess-form label {
    font-size: 0.85rem;
  }

  .hint-text,
  .status-text {
    font-size: 0.85rem;
  }
}

/* ════════════════════════════════════════════
   DESKTOP (761px+)
   ════════════════════════════════════════════ */
@media (min-width: 761px) {
  body {
    padding:
      max(24px, env(safe-area-inset-top))
      max(24px, env(safe-area-inset-right))
      max(24px, env(safe-area-inset-bottom))
      max(24px, env(safe-area-inset-left));
  }

  .app-shell {
    max-width: 680px;
    padding: 20px 28px;
    border-radius: var(--radius);
  }

  .hero > p {
    display: block;
    max-width: 54ch;
    color: var(--ink-soft);
    font-size: 0.92rem;
    margin: 4px auto 0;
  }

  h1 {
    font-size: clamp(1.6rem, 3vw, 2.2rem);
    margin: 4px 0;
  }

  .eyebrow {
    font-size: 0.78rem;
  }

  .stats {
    margin: 10px 0;
    gap: 10px;
  }

  .stats article {
    padding: 10px 6px;
    border-radius: 14px;
  }

  .stats .label {
    font-size: 0.78rem;
  }

  .stats strong {
    font-size: 1.3rem;
  }

  .game-zone {
    gap: 10px;
  }

  .flashcard {
    max-width: 480px;
    border-radius: 20px;
  }

  .card-face {
    border-radius: 20px;
  }

  .guess-form label {
    font-size: 0.9rem;
  }

  .guess-row {
    gap: 10px;
  }

  input {
    padding: 10px 14px;
    border-radius: 12px;
    min-height: 44px;
  }

  .btn {
    border-radius: 12px;
    padding: 11px 20px;
    font-size: 0.96rem;
    min-height: 44px;
  }

  .hint-text,
  .status-text {
    font-size: 0.9rem;
  }

}

/* ════════════════════════════════════════════
   LARGE DESKTOP (1024px+) — show SEO links
   ════════════════════════════════════════════ */
@media (min-width: 1024px) and (min-height: 900px) {
  .seo-links {
    display: block;
    flex-shrink: 0;
    margin-top: 12px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 18px;
    padding: 16px;
  }

  .seo-links h2 {
    margin: 0 0 8px;
    font-family: "Fraunces", Georgia, serif;
    font-size: 1.1rem;
  }

  .seo-links p {
    margin: 0 0 10px;
    color: var(--ink-soft);
    font-size: 0.85rem;
  }

  .seo-links ul {
    padding-left: 18px;
    display: grid;
    gap: 6px;
  }

  .seo-links a {
    color: var(--accent-deep);
    font-weight: 700;
    font-size: 0.85rem;
  }

  .seo-links a:hover {
    color: var(--accent-alt);
  }
}

/* ════════════════════════════════════════════
   LANDSCAPE PHONES
   ════════════════════════════════════════════ */
@media (max-height: 500px) and (orientation: landscape) {
  .app-shell {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px;
    align-items: flex-start;
    align-content: flex-start;
  }

  .hero {
    width: 100%;
    display: none;
  }

  .stats {
    width: 100%;
    margin: 0;
    gap: 4px;
  }

  .stats article {
    padding: 2px;
  }

  .stats .label {
    font-size: 0.55rem;
  }

  .stats strong {
    font-size: 0.85rem;
  }

  .game-zone {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    width: 100%;
  }

  .flashcard {
    max-width: none;
    width: auto;
    height: 100%;
    max-height: 100%;
    flex: 0 0 auto;
    aspect-ratio: 3 / 4;
  }

  .guess-form {
    flex: 1;
    min-width: 200px;
  }

  .actions {
    width: auto;
    flex: 1;
    min-width: 200px;
  }

  .hint-text,
  .status-text {
    width: 100%;
    font-size: 0.7rem;
    min-height: 1em;
  }
}

/* ════════════════════════════════════════════
   VERY TALL PHONES (>750px viewport height) — give card more room
   ════════════════════════════════════════════ */
@media (min-height: 750px) and (max-width: 480px) {
  .app-shell {
    padding: 14px;
  }

  h1 {
    font-size: 1.25rem;
  }

  .stats {
    margin: 8px 0;
  }

  .stats article {
    padding: 6px 2px;
  }

  .game-zone {
    gap: 8px;
  }

  .flashcard {
    max-width: 300px;
  }
}

/* ════════════════════════════════════════════
   VERY SHORT PHONES (<600px viewport height)
   ════════════════════════════════════════════ */
@media (max-height: 600px) and (orientation: portrait) {
  .hero {
    display: none;
  }

  .stats {
    margin: 3px 0;
  }

  .stats article {
    padding: 2px;
  }

  .stats .label {
    font-size: 0.55rem;
  }

  .stats strong {
    font-size: 0.85rem;
  }

  .game-zone {
    gap: 4px;
  }

  .hint-text,
  .status-text {
    font-size: 0.7rem;
    min-height: 1em;
  }

  .btn {
    padding: 6px 10px;
    min-height: 34px;
    font-size: 0.8rem;
  }

  input {
    padding: 6px 8px;
    min-height: 34px;
  }
}
