/* HowStuffWorks — Claudeway
   Warm, approachable design for curious kids and their parents. */

:root {
  --bg: #FDF8F3;
  --surface: #FFFFFF;
  --ink: #1F1B2E;
  --ink-muted: #5A5670;
  --ink-soft: #8A869A;
  --line: rgba(31, 27, 46, 0.08);
  --line-strong: rgba(31, 27, 46, 0.18);
  --accent: #534AB7;
  --accent-soft: #EEEDFE;
  --warm: #EF9F27;
  --success: #3B6D11;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(31, 27, 46, 0.04), 0 8px 24px rgba(31, 27, 46, 0.06);
  --font-display: 'Fraunces', 'Georgia', serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
}

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600&family=Inter:wght@400;500;600&display=swap');

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
}

/* ---------- HOME ---------- */

.home {
  max-width: 680px;
  margin: 0 auto;
  padding: 6rem 1.5rem 3rem;
  text-align: center;
}

.brand h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 3.2rem;
  letter-spacing: -0.03em;
  margin: 0;
  line-height: 1;
}
.brand h1 span { color: var(--warm); font-style: italic; }

.tagline {
  margin: 0.5rem 0 2.5rem;
  color: var(--ink-muted);
  font-size: 1.05rem;
}

.ask-form {
  display: flex;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.4rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.75rem;
}
.ask-form input {
  flex: 1;
  border: none;
  outline: none;
  padding: 0.85rem 1rem;
  font: inherit;
  font-size: 1.05rem;
  background: transparent;
  color: var(--ink);
}
.ask-form input::placeholder { color: var(--ink-soft); }
.ask-form button[type="submit"] {
  background: var(--ink);
  color: var(--surface);
  border-radius: 10px;
  padding: 0 1.5rem;
  font-weight: 500;
  transition: background 0.15s;
}
.ask-form button[type="submit"]:hover { background: var(--accent); }

.mic-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: var(--ink-muted);
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.mic-btn:hover { color: var(--accent); background: var(--accent-soft); }
.mic-btn.mic-listening {
  color: #e84040;
  background: #fde8e8;
  animation: mic-pulse 1s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232, 64, 64, 0.35); }
  50%       { box-shadow: 0 0 0 7px rgba(232, 64, 64, 0); }
}

.examples { margin-top: 1rem; }
.examples-label {
  color: var(--ink-soft);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.examples ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}
.chip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-size: 0.92rem;
  color: var(--ink-muted);
  transition: all 0.15s;
}
.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.home footer {
  margin-top: 4rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* ---------- LOADING ---------- */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(253, 248, 243, 0.95);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 1000;
  overflow-y: auto;
  padding: 1.2rem 1rem 2rem;
  -webkit-overflow-scrolling: touch;
}
.loading[hidden] { display: none; }
.loading-inner {
  text-align: center;
  max-width: 420px;
}
.loading-inner #game {
  display: block;
  margin: 1rem auto 0.5rem;
  border: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  background: #1F1B2E;
  outline: none;
  touch-action: none;
  max-width: 100%;
  position: relative;
  z-index: 1001;
  pointer-events: auto;
}
.loading-inner #game:focus { box-shadow: 0 0 0 3px var(--accent-soft); }
.loading-inner .game-hint { font-size: 0.85rem; }

.dpad {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 1rem auto 0;
  user-select: none;
  position: relative;
  z-index: 1001;
  pointer-events: auto;
  touch-action: none;
}
.dpad-middle {
  display: flex;
  gap: 6px;
  align-items: center;
}
.dpad-middle .dpad-spacer {
  width: 60px;
  height: 60px;
}
.dpad-btn {
  width: 64px;
  height: 64px;
  font-size: 1.4rem;
  background: var(--surface);
  border: 2px solid var(--line-strong);
  border-radius: 12px;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  box-shadow: 0 2px 6px rgba(31,27,46,0.12);
  transition: background 0.1s, border-color 0.1s;
  -webkit-tap-highlight-color: transparent;
  pointer-events: auto;
  user-select: none;
}
.dpad-btn:active,
.dpad-btn.pressed { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Suppress Safari long-press context menu and text selection on game controls */
.dpad, .dpad-btn {
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.loading-inner { text-align: center; }
.loading-inner p { margin: 0.4rem 0; }
.loading-inner p.muted { color: var(--ink-soft); font-size: 0.9rem; }

.loading-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: center;
  margin: 0.6rem 0 0.4rem;
  position: relative;
  z-index: 1002;
}
.loading-actions button { pointer-events: auto; }
.big-btn {
  font-size: 1.15rem;
  font-weight: 700;
  padding: 0.85rem 1.6rem;
  min-width: 220px;
  border-radius: 12px;
  animation: ready-pulse 1.4s ease-in-out infinite;
}
@keyframes ready-pulse {
  0%, 100% { transform: scale(1);   box-shadow: 0 4px 14px rgba(127, 119, 221, 0.35); }
  50%      { transform: scale(1.04); box-shadow: 0 6px 20px rgba(127, 119, 221, 0.55); }
}
.secondary {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  padding: 0.5rem 1rem;
  border-radius: 10px;
  font-size: 0.95rem;
  cursor: pointer;
}
.secondary:hover { background: var(--line); color: var(--ink); }
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 1.25rem;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- LESSON ---------- */

.lesson {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.lesson-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.back {
  font-size: 0.9rem;
  color: var(--ink-muted);
  padding-top: 0.3rem;
  white-space: nowrap;
}
.lesson-titles { flex: 1; }
.lesson-titles .question {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0 0 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.lesson-titles h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 2rem;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.15;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 0.75rem;
}
.controls button {
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  transition: all 0.15s;
}
.controls button:hover { border-color: var(--accent); color: var(--accent); }
.controls button.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.controls button.primary:hover { background: var(--accent); border-color: var(--accent); }
.controls button.playing { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.controls .status {
  flex: 1;
  font-size: 0.88rem;
  color: var(--ink-muted);
  min-width: 140px;
}
.controls .speed {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
}
.controls .speed input { width: 70px; }

.progress {
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 25%;
  transition: width 0.35s ease;
}

.deck {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 520px;
  padding: 2rem;
}
.slide { display: none; }
.slide.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.slide-head { margin-bottom: 1rem; }
.slide-num {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0 0 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.slide h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.6rem;
  margin: 0 0 0.2rem;
  letter-spacing: -0.015em;
}
.slide-sub {
  color: var(--ink-muted);
  margin: 0;
  font-size: 0.95rem;
}

.illustration {
  margin: 1.5rem 0;
  display: flex;
  justify-content: center;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 1rem;
}
.illustration svg,
.illustration .slide-image { max-width: 100%; height: auto; display: block; border-radius: 6px; }

.slide.active .slide-image {
  animation: floatImage 4s ease-in-out infinite;
}
@keyframes floatImage {
  0%   { transform: translateY(0px) scale(1); }
  50%  { transform: translateY(-8px) scale(1.02); }
  100% { transform: translateY(0px) scale(1); }
}

.slide-image-missing {
  padding: 2rem;
  color: var(--ink-soft);
  font-style: italic;
}

.explanation {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--ink);
  margin: 0 0 1rem;
}
.explanation em { font-style: normal; color: var(--accent); font-weight: 500; }

.fun-fact {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  color: var(--ink);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.fun-fact strong { color: var(--accent); font-weight: 600; }

.deck-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0.25rem;
  margin-top: 0.25rem;
}
.deck-nav button {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  font-size: 0.9rem;
  border: 1px solid transparent;
}
.deck-nav button:hover { color: var(--accent); border-color: var(--line-strong); }
.dots { display: flex; gap: 0.45rem; align-items: center; }
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line-strong);
  padding: 0;
  transition: all 0.15s;
}
.dot.on { background: var(--accent); transform: scale(1.3); }
.dot:hover { background: var(--accent); }

.next-question {
  margin-top: 2rem;
  text-align: center;
}
.new-question-link {
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.lesson-meta {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

/* ---------- ERROR ---------- */
.error-page {
  max-width: 600px;
  margin: 0 auto;
  padding: 5rem 1.5rem;
  text-align: center;
}
.error-page h1 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  margin: 0 0 0.5rem;
}
.error-page .question { color: var(--ink-muted); }
.error-detail {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 1rem;
  text-align: left;
  font-size: 0.85rem;
  color: var(--ink-muted);
  overflow-x: auto;
  margin: 1.5rem 0;
}
.btn {
  display: inline-block;
  background: var(--ink);
  color: var(--surface);
  padding: 0.7rem 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.btn:hover { background: var(--accent); text-decoration: none; }

/* ---------- Feedback ---------- */
.feedback {
  margin-top: 2rem;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.feedback h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--ink);
}
.feedback-buttons {
  display: flex;
  gap: 0.5rem;
}
.fb-btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
}
.fb-btn.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.fb-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.feedback textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  resize: vertical;
}
#fb-submit {
  align-self: flex-start;
  padding: 0.55rem 1.1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
#fb-submit:hover:not(:disabled) {
  background: #6257c9;
}
#fb-submit:disabled {
  background: var(--line);
  color: var(--ink-soft);
  cursor: not-allowed;
}
.fb-status.success {
  color: var(--success);
  font-weight: 600;
}
.fb-status {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
  min-height: 1.2em;
}

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
  /* Home */
  .home { padding: 3.5rem 1rem 2rem; }
  .brand h1 { font-size: 2.2rem; }
  .tagline { font-size: 0.97rem; }
  .ask-form { flex-wrap: wrap; padding: 0.35rem; }
  .ask-form input { font-size: 1rem; padding: 0.75rem 0.75rem; }
  .ask-form button { width: 100%; padding: 0.75rem; border-radius: 8px; margin-top: 0.25rem; }

  /* Loading game — narrower screens */
  .loading-inner #game { width: 100%; max-width: 320px; }

  /* Lesson header */
  .lesson { padding: 1.25rem 1rem 2.5rem; }
  .lesson-header { flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
  .back { padding-top: 0; }
  .lesson-titles h1 { font-size: 1.45rem; }

  /* Controls — stack into two rows */
  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.75rem;
  }
  .controls .btn-row {
    display: flex;
    gap: 0.5rem;
  }
  .controls .btn-row button { flex: 1; }
  .controls .speed { display: none; }
  .controls .status {
    display: block;
    min-width: 0;
    font-size: 0.83rem;
    text-align: center;
  }

  /* Deck */
  .deck { padding: 1.1rem; min-height: 0; }
  .slide h2 { font-size: 1.35rem; }
  .explanation { font-size: 1rem; }

  /* Nav */
  .deck-nav { padding: 0.75rem 0; }
  .deck-nav button { padding: 0.6rem 0.9rem; font-size: 0.88rem; }

  /* Feedback */
  .feedback { padding: 1rem; }
  .feedback-buttons { flex-wrap: wrap; }
  .fb-btn { flex: 1; text-align: center; }
}
