/* ===== CSS Custom Properties ===== */
:root {
  --color-bg: #f0f4ff;
  --color-surface: #ffffff;
  --color-primary: #4a6cf7;
  --color-primary-light: #6b8cff;
  --color-secondary: #10b981;
  --color-accent: #f59e0b;
  --color-text: #1e293b;
  --color-text-light: #64748b;
  --color-border: #e2e8f0;
  --color-progress-bg: #e2e8f0;
  --color-progress-fill: #4a6cf7;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

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

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overflow-x: hidden;
}

/* ===== Top Navigation ===== */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.top-nav a {
  color: #fff;
  text-decoration: none;
  font-size: 1.5rem;
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.top-nav a:hover {
  background: rgba(255, 255, 255, 0.15);
}

.top-nav .nav-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-left: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-body {
  padding-top: 56px;
}

/* ===== Landing Page Card Grid ===== */
.landing-header {
  text-align: center;
  padding: 40px 20px 20px;
}

.landing-header h1 {
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 700;
  color: var(--color-text);
}

.landing-header p {
  font-size: 1.1rem;
  color: var(--color-text-light);
  margin-top: 8px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 28px 24px;
  text-decoration: none;
  color: var(--color-text);
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 2px solid transparent;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--color-primary-light);
}

.card .card-icon {
  font-size: 2.5rem;
  line-height: 1;
}

.card .card-title {
  font-size: 1.35rem;
  font-weight: 700;
}

.card .card-desc {
  font-size: 0.95rem;
  color: var(--color-text-light);
  line-height: 1.45;
}

/* ===== Full-screen Activity Layout ===== */
.activity-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 56px);
  padding: 20px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

/* ===== Large Number / Word Display ===== */
.big-text {
  font-size: clamp(3rem, 18vw, 10rem);
  font-weight: 800;
  text-align: center;
  line-height: 1.1;
  color: var(--color-text);
  word-break: break-word;
  padding: 0 20px;
  transition: opacity 0.15s;
}

.big-text.equation {
  font-size: clamp(1.8rem, 8vw, 5rem);
}

/* ===== Progress Bar ===== */
.progress-wrapper {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 20px 24px;
  z-index: 50;
}

.progress-bar {
  width: 100%;
  height: 16px;
  background: var(--color-progress-bg);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
  border-radius: 8px;
  transition: width 0.3s ease;
  min-width: 0;
}

.progress-label {
  text-align: center;
  font-size: 0.85rem;
  color: var(--color-text-light);
  margin-top: 6px;
}

/* ===== Settings Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 28px;
  min-width: 280px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
}

.modal h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.modal-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s;
  background: none;
  color: var(--color-text);
  width: 100%;
  text-align: left;
}

.modal-option:hover {
  border-color: var(--color-primary-light);
  background: #f0f4ff;
}

.modal-option.selected {
  border-color: var(--color-primary);
  background: #eef2ff;
}

.modal-cancel {
  margin-top: 16px;
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-border);
  color: var(--color-text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.modal-cancel:hover {
  background: #cbd5e1;
}

/* ===== Confetti Canvas ===== */
.confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 300;
}

/* ===== Sam the Cat / Lyon ===== */
.story-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 56px);
  padding: 20px;
  cursor: pointer;
  gap: 20px;
}

.story-image-wrapper {
  position: relative;
  width: 100%;
  max-width: 600px;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  background: #e2e8f0;
}

.story-image-wrapper img,
.story-image-wrapper video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.story-image-wrapper img.fade-out {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.story-image-wrapper img.fade-in {
  opacity: 1;
  transition: opacity 0.3s ease;
}

.story-caption {
  font-size: clamp(1.5rem, 5vw, 3rem);
  font-weight: 700;
  text-align: center;
  max-width: 600px;
  line-height: 1.3;
}

/* ===== Lyon Quiz ===== */
.lyon-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 56px);
  padding: 20px 20px 110px;
  cursor: pointer;
  gap: 16px;
}

.lyon-question {
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  font-weight: 600;
  text-align: center;
  white-space: pre-line;
  flex: 0 0 auto;
}

.lyon-media {
  position: relative;
  width: 100%;
  max-width: 550px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lyon-media img,
.lyon-media video {
  max-width: 100%;
  max-height: 50vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.lyon-media img.lyon-back {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: opacity 0.3s ease;
}

.lyon-media img.lyon-front {
  position: relative;
  transition: opacity 0.3s ease;
}

.lyon-answer {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 600;
  text-align: center;
  white-space: pre-line;
  color: var(--color-primary);
  opacity: 0;
  transition: opacity 0.5s ease;
  flex: 0 0 auto;
  min-height: 1.5em;
}

.lyon-answer.visible {
  opacity: 1;
}

/* ===== Uppercase-Lowercase Letter Game ===== */
.letter-options {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-top: 40px;
  flex-wrap: wrap;
}

.letter-option {
  width: 140px;
  height: 140px;
  border: 3px solid var(--color-primary);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: clamp(3rem, 10vw, 5rem);
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s, border-color 0.2s, color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  box-shadow: var(--shadow-md);
  -webkit-tap-highlight-color: transparent;
  font-family: var(--font-family);
}

.letter-option:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-lg);
}

.letter-option:active {
  transform: scale(0.95);
}

.letter-option.correct {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.letter-option.wrong {
  animation: letter-shake 0.5s;
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}

.letter-option.disabled {
  pointer-events: none;
  opacity: 0.6;
}

@keyframes letter-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

@media (max-width: 600px) {
  .letter-options {
    gap: 16px;
    margin-top: 24px;
  }

  .letter-option {
    width: 120px;
    height: 120px;
  }
}

/* ===== Tap Hint ===== */
.tap-hint {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
  color: var(--color-text-light);
  opacity: 0.6;
  pointer-events: none;
  z-index: 10;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .card-grid {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .progress-wrapper {
    padding: 12px 16px 20px;
  }
}
