/* ============================================
   Dino Flip Facts - Styles
   A kid-friendly flash card game
   ============================================ */

/* ---------- Variables & Theme ---------- */
:root {
  /* Colors - Light Mode (Dino Green Theme) */
  --bg: #f5f7f2;
  --bg-card: #ffffff;
  --bg-card-back: #2d8a4e;
  --text: #1a3326;
  --text-muted: #5a7a66;
  --text-card-back: #fff;
  --accent: #ff6b35;
  --accent-hover: #e85a2a;
  --border: #d4e5d9;
  --shadow: rgba(0, 0, 0, 0.1);
  --shadow-lg: rgba(0, 0, 0, 0.15);
  --blob-one: rgba(255, 107, 53, 0.12);
  --blob-two: rgba(45, 138, 78, 0.1);
  --grid-color: rgba(0, 0, 0, 0.03);
  --progress-bg: #d4e5d9;
  --progress-fill: #2d8a4e;
  --btn-secondary-bg: #fff;
  --btn-secondary-text: #1a3326;
  --pill-bg: rgba(45, 138, 78, 0.12);
  --pill-text: #2d8a4e;
}

[data-theme="dark"] {
  /* Colors - Dark Mode (Jungle Night) */
  --bg: #0d1f15;
  --bg-card: #162b1e;
  --bg-card-back: #22c55e;
  --text: #e8f5ec;
  --text-muted: #8fb89e;
  --text-card-back: #0d1f15;
  --accent: #ff8c5a;
  --accent-hover: #ff6b35;
  --border: #2a4a36;
  --shadow: rgba(0, 0, 0, 0.4);
  --shadow-lg: rgba(0, 0, 0, 0.5);
  --blob-one: rgba(255, 140, 90, 0.08);
  --blob-two: rgba(34, 197, 94, 0.06);
  --grid-color: rgba(255, 255, 255, 0.02);
  --progress-bg: #2a4a36;
  --progress-fill: #22c55e;
  --btn-secondary-bg: #162b1e;
  --btn-secondary-text: #e8f5ec;
  --pill-bg: rgba(34, 197, 94, 0.15);
  --pill-text: #22c55e;
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Baloo 2", system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  overflow-x: hidden;
  transition:
    background-color 0.3s ease,
    color 0.3s ease;
}

/* ---------- Background Effects ---------- */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: -2;
  display: none; /* Hidden for playful vibe */
}

.bg-blob {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  z-index: -1;
}

.blob-one {
  width: 400px;
  height: 400px;
  background: var(--blob-one);
  top: -100px;
  right: -100px;
}

.blob-two {
  width: 300px;
  height: 300px;
  background: var(--blob-two);
  bottom: 10%;
  left: -50px;
}

/* ---------- Page Layout ---------- */
.page {
  max-width: 600px;
  margin: 0 auto;
  padding: 1rem;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header / Hero ---------- */
.hero {
  text-align: center;
  padding: 1.5rem 0 1rem;
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-mark {
  font-family: "Bungee", cursive;
  font-size: 1.75rem;
  color: var(--accent);
  background: var(--pill-bg);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-text {
  font-family: "Bungee", cursive;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: 0.02em;
}

.hero h1 {
  font-family: "Bungee", cursive;
  font-size: clamp(1.5rem, 5vw, 2rem);
  line-height: 1.2;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.hero p {
  color: var(--text-muted);
  font-size: 1rem;
  max-width: 30ch;
  margin: 0 auto 1rem;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.pill {
  background: var(--pill-bg);
  color: var(--pill-text);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
}

/* ---------- Theme Toggle ---------- */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 0.25rem;
}

.theme-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.theme-track {
  width: 2.5rem;
  height: 1.5rem;
  background: var(--border);
  border-radius: 999px;
  position: relative;
  transition: background-color 0.2s ease;
}

.theme-thumb {
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.1rem;
  height: 1.1rem;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px var(--shadow);
}

.theme-toggle[aria-pressed="true"] .theme-track {
  background: var(--accent);
}

.theme-toggle[aria-pressed="true"] .theme-thumb {
  transform: translateX(1rem);
}

/* ---------- Game / Card Area ---------- */
.game {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding-bottom: 1rem;
}

.card-area {
  perspective: 1200px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 280px;
}

/* ---------- Flash Card ---------- */
.card {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 3 / 4;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  outline: none;
}

.card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
  border-radius: 1.5rem;
}

.card[aria-pressed="true"] {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 1.5rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow:
    0 10px 40px var(--shadow-lg),
    0 2px 8px var(--shadow);
}

.card-front {
  background: var(--bg-card);
  border: 2px solid var(--border);
}

.card-back {
  background: var(--bg-card-back);
  color: var(--text-card-back);
  transform: rotateY(180deg);
}

.card-badge {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: var(--pill-bg);
  color: var(--pill-text);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
}

.card-badge.alt {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.card h2 {
  font-family: "Baloo 2", system-ui, sans-serif;
  font-weight: 700;
  font-size: clamp(1.75rem, 6vw, 2.25rem);
  line-height: 1.2;
  margin-bottom: 0.75rem;
}

.card-front h2 {
  color: var(--accent);
}

.card p {
  font-size: 1rem;
  line-height: 1.5;
  max-width: 26ch;
}

#card-clue {
  font-size: clamp(1.5rem, 5vw, 1.85rem);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1rem;
  line-height: 1.3;
}

/* ---------- Card Images & Hints ---------- */
.card-hint-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.card-hint-section[hidden] {
  display: none;
}

.card-hint-media {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: center;
  margin-top: 0.5rem;
}

.card-hint-media[hidden] {
  display: none;
}

.card-image-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 0.75rem;
}

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

.card-image {
  width: min(180px, 60%);
  height: auto;
  border-radius: 1rem;
  box-shadow: 0 4px 12px var(--shadow);
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
}

.card-image.hint {
  width: min(200px, 65%);
}

.card-image.answer {
  border-color: rgba(255, 255, 255, 0.4);
}

#card-fact {
  font-size: clamp(1.1rem, 3.5vw, 1.25rem);
  opacity: 0.95;
}

.card-hint {
  position: absolute;
  bottom: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.8;
}

.card-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin: 0.75rem 0;
}

.icon-btn {
  width: 3rem;
  height: 3rem;
  border: 0;
  background: var(--pill-bg);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  font-size: 1.5rem;
  transition:
    transform 0.15s,
    background 0.15s;
}

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

.icon-btn:active {
  transform: scale(0.9);
}

.icon-btn.speaking {
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

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

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

.card-meta {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  font-size: 0.8rem;
  opacity: 0.9;
}

.card-meta span {
  background: rgba(255, 255, 255, 0.15);
  padding: 0.2rem 0.5rem;
  border-radius: 0.5rem;
}

/* ---------- Controls ---------- */
.controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.progress {
  width: 100%;
  max-width: 340px;
}

.progress-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  text-align: center;
}

.progress-bar {
  height: 0.5rem;
  background: var(--progress-bg);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--progress-fill);
  border-radius: 999px;
  transition: width 0.3s ease;
  width: 0%;
}

.button-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  font-family: "Baloo 2", sans-serif;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.6rem 1.25rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn.primary:active {
  transform: translateY(0);
}

.btn.secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  border: 2px solid var(--border);
}

.btn.secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.helper {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 30ch;
}

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  padding: 1.5rem 0 1rem;
  margin-top: auto;
}

.footer-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.footer-links span {
  font-size: 1.25rem;
  user-select: none;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.15s ease;
}

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

.footer-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.7;
}

/* ---------- Animations ---------- */
@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.card[aria-pressed="false"]:not(:hover) .card-hint {
  animation: bounce 2s ease-in-out infinite;
}

/* ---------- Responsive ---------- */
@media (min-width: 480px) {
  .page {
    padding: 1.5rem;
  }

  .card-area {
    min-height: 340px;
  }

  .card {
    max-width: 380px;
  }
}

@media (min-width: 640px) {
  .hero {
    padding: 2rem 0 1.5rem;
  }

  .card-face {
    padding: 2rem;
  }
}

/* ---------- Level Selection ---------- */
.level-select {
  margin-top: 1.5rem;
}

.level-label {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.level-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.level-btn {
  font-size: 1.1rem;
  padding: 0.75rem 1.5rem;
  min-width: 140px;
}

#advanced-btn {
  background: var(--bg-card-back);
}

#advanced-btn:hover {
  background: #16a34a;
}

/* ---------- Fullscreen Mode ---------- */
.exit-btn {
  display: none;
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow);
  transition: transform 0.15s ease;
}

.exit-btn:hover {
  transform: scale(1.1);
}

.swipe-hint {
  display: none;
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: var(--pill-bg);
  color: var(--pill-text);
  padding: 0.4rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  gap: 0.5rem;
  align-items: center;
}

.swipe-arrow {
  opacity: 0.7;
}

/* Fullscreen active state */
body.fullscreen {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

body.fullscreen .hero,
body.fullscreen .footer {
  display: none !important;
}

body.fullscreen .bg-grid,
body.fullscreen .bg-blob {
  display: none;
}

body.fullscreen .page {
  max-width: 100%;
  padding: 0;
  padding-top: env(safe-area-inset-top, 0);
  height: 100dvh;
  height: 100vh; /* Fallback */
}

body.fullscreen .game {
  height: 100%;
  padding: 1rem;
  padding-top: calc(env(safe-area-inset-top, 0) + 3.5rem);
  padding-bottom: env(safe-area-inset-bottom, 1rem);
  justify-content: center;
  gap: 1rem;
}

body.fullscreen .exit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  top: calc(env(safe-area-inset-top, 0) + 0.75rem);
  right: calc(env(safe-area-inset-right, 0) + 0.75rem);
}

body.fullscreen .swipe-hint {
  display: flex;
  top: calc(env(safe-area-inset-top, 0) + 0.75rem);
}

body.fullscreen .card-area {
  flex: 1;
  min-height: 0;
  max-height: calc(100dvh - 200px);
  max-height: calc(100vh - 200px); /* Fallback */
}

body.fullscreen .card {
  max-width: min(420px, 90vw);
  max-height: 100%;
  aspect-ratio: 3 / 4;
}

body.fullscreen .controls {
  padding-bottom: env(safe-area-inset-bottom, 0.5rem);
  flex-shrink: 0;
}

body.fullscreen .helper {
  display: none;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
