/* ═══════════════════════════════════════════════════════════════════════════
   Tiny Tale Toy – Main Stylesheet
   Dark spellbook / parchment aesthetic with animated particles + transitions
═══════════════════════════════════════════════════════════════════════════ */

/* ── Design Tokens ────────────────────────────────────────────────────── */
:root {
  --bg-deep:       #0a0812;
  --bg-mid:        #120f1e;
  --bg-card:       #1a1530;
  --bg-page:       #1e1838;

  --gold-bright:   #f5c842;
  --gold-mid:      #c8943a;
  --gold-dim:      #7a5c20;

  --purple-bright: #a855f7;
  --purple-mid:    #7c3aed;
  --purple-dim:    #3b1e6e;

  --teal-bright:   #38bdf8;
  --teal-dim:      #0e4a6e;

  --text-primary:  #f0e9d6;
  --text-secondary:#b0a090;
  --text-dim:      #6b6070;

  --border-glow:   rgba(168, 85, 247, 0.35);
  --border-gold:   rgba(245, 200, 66, 0.3);

  --radius-sm:  8px;
  --radius-md:  14px;
  --radius-lg:  22px;
  --radius-xl:  32px;

  --shadow-glow: 0 0 40px rgba(168, 85, 247, 0.25);
  --shadow-gold: 0 0 30px rgba(245, 200, 66, 0.2);

  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Genre colour overrides */
[data-active-genre="Sci-Fi"]    { --gold-bright: #38bdf8; --gold-mid: #0ea5e9; --purple-bright: #06b6d4; }
[data-active-genre="Horror"]    { --gold-bright: #ef4444; --gold-mid: #b91c1c; --purple-bright: #f87171; }
[data-active-genre="Comedy"]    { --gold-bright: #facc15; --gold-mid: #f59e0b; --purple-bright: #fb923c; }
[data-active-genre="Fairy Tale"]{ --gold-bright: #f9a8d4; --gold-mid: #ec4899; --purple-bright: #d946ef; }
[data-active-genre="Pirate"]    { --gold-bright: #fb923c; --gold-mid: #d97706; --purple-bright: #f59e0b; }

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: 'Lora', Georgia, serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Particle Canvas ──────────────────────────────────────────────────── */
#particles-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

/* ── App Root ─────────────────────────────────────────────────────────── */
#app {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* ── Screen System ────────────────────────────────────────────────────── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(24px);
  transition: opacity var(--transition-slow), transform var(--transition-slow);
  overflow-y: auto;
}

.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

.screen.exit {
  opacity: 0;
  transform: translateY(-24px);
}

/* ═══════════════════════════════════════════════════════════════════════
   SCREEN 1 – Welcome
═══════════════════════════════════════════════════════════════════════ */
.welcome-card {
  width: 100%;
  max-width: 680px;
  background: linear-gradient(145deg, var(--bg-card), var(--bg-mid));
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-xl);
  padding: 44px 40px 40px;
  box-shadow: var(--shadow-glow), 0 24px 80px rgba(0,0,0,0.6);
  animation: float 6s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}

.logo-area {
  text-align: center;
  margin-bottom: 36px;
}

.book-icon {
  font-size: 3.5rem;
  margin-bottom: 12px;
  display: block;
  filter: drop-shadow(0 0 16px var(--gold-bright));
  animation: pulse-glow 2.5s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 16px var(--gold-bright)); }
  50%       { filter: drop-shadow(0 0 32px var(--gold-bright)); }
}

.app-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 700;
  background: linear-gradient(135deg, var(--gold-bright), var(--purple-bright));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.04em;
  line-height: 1.1;
}

.app-subtitle {
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 6px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.app-tagline {
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 10px;
}

.aws-badge {
  background: linear-gradient(90deg, #ff9900, #ffb347);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 600;
}

/* ── Form Groups ──────────────────────────────────────────────────────── */
.form-group { margin-bottom: 24px; }

.form-label {
  font-family: 'Cinzel', serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gold-mid);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 12px;
}

/* ── Genre Grid ───────────────────────────────────────────────────────── */
.genre-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.genre-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 10px;
  background: var(--bg-deep);
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.genre-btn:hover {
  border-color: var(--purple-bright);
  color: var(--text-primary);
  background: var(--purple-dim);
  transform: translateY(-2px);
}

.genre-btn.active {
  border-color: var(--gold-bright);
  color: var(--gold-bright);
  background: linear-gradient(135deg, rgba(245,200,66,0.12), rgba(168,85,247,0.08));
  box-shadow: 0 0 16px rgba(245,200,66,0.2);
}

.genre-icon { font-size: 1.5rem; }

/* ── Protagonist Grid ─────────────────────────────────────────────────── */
.protagonist-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.proto-btn {
  padding: 10px 8px;
  background: var(--bg-deep);
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.proto-btn:hover {
  border-color: var(--teal-bright);
  color: var(--teal-bright);
  background: var(--teal-dim);
}

.proto-btn.active {
  border-color: var(--purple-bright);
  color: var(--purple-bright);
  background: linear-gradient(135deg, rgba(168,85,247,0.15), rgba(124,58,237,0.08));
  box-shadow: 0 0 12px rgba(168,85,247,0.25);
}

/* ── Begin Button ─────────────────────────────────────────────────────── */
.begin-btn {
  width: 100%;
  padding: 18px 24px;
  margin-top: 8px;
  background: linear-gradient(135deg, var(--purple-mid), var(--gold-mid));
  border: none;
  border-radius: var(--radius-lg);
  color: white;
  font-family: 'Cinzel', serif;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: all var(--transition);
  box-shadow: 0 8px 32px rgba(124,58,237,0.4);
  position: relative;
  overflow: hidden;
}

.begin-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}

.begin-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 40px rgba(124,58,237,0.5); }
.begin-btn:hover::before { opacity: 1; }
.begin-btn:active { transform: translateY(0); }
.begin-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-arrow {
  font-size: 1.2rem;
  transition: transform var(--transition);
}
.begin-btn:hover .btn-arrow { transform: translateX(4px); }

/* ═══════════════════════════════════════════════════════════════════════
   SCREEN 2 – Story
═══════════════════════════════════════════════════════════════════════ */
.story-container {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100vh;
  padding: 20px 0;
  gap: 16px;
}

/* ── Story Header ─────────────────────────────────────────────────────── */
.story-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.restart-btn {
  background: transparent;
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: 'Inter', sans-serif;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 7px 14px;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.02em;
}
.restart-btn:hover { border-color: var(--purple-bright); color: var(--purple-bright); }

.chapter-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#chapter-label {
  font-family: 'Cinzel', serif;
  font-size: 0.82rem;
  color: var(--gold-bright);
  font-weight: 600;
  letter-spacing: 0.08em;
}

.chapter-dots {
  display: flex;
  gap: 6px;
}

.chapter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-glow);
  transition: all var(--transition);
}

.chapter-dot.filled {
  background: var(--gold-bright);
  border-color: var(--gold-bright);
  box-shadow: 0 0 8px var(--gold-bright);
}

.genre-tag {
  background: linear-gradient(135deg, var(--purple-dim), var(--bg-card));
  border: 1px solid var(--border-glow);
  border-radius: 20px;
  padding: 5px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--purple-bright);
  letter-spacing: 0.06em;
}

/* ── Story Book ───────────────────────────────────────────────────────── */
.story-book {
  flex: 1;
  min-height: 0;
  background: linear-gradient(160deg, var(--bg-page), var(--bg-card));
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-gold), inset 0 1px 0 rgba(255,255,255,0.05);
  position: relative;
  overflow: hidden;
}

.story-book::before {
  content: '';
  position: absolute;
  left: 48px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: linear-gradient(to bottom, transparent, var(--border-gold), transparent);
  opacity: 0.5;
}

.book-page {
  height: 100%;
  overflow-y: auto;
  padding: 28px 32px 28px 64px;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dim) transparent;
}

.book-page::-webkit-scrollbar { width: 4px; }
.book-page::-webkit-scrollbar-track { background: transparent; }
.book-page::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 2px; }

/* ── Story History ────────────────────────────────────────────────────── */
.story-history { margin-bottom: 20px; }

.history-chapter {
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px dashed rgba(245,200,66,0.15);
  opacity: 0.65;
  font-family: 'Lora', serif;
  font-size: 0.88rem;
  line-height: 1.75;
  color: var(--text-secondary);
  font-style: italic;
}

.history-choice {
  margin-top: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  color: var(--gold-dim);
  font-style: normal;
}

.history-choice::before { content: '➤ You chose: '; }

/* ── Current Story Text ───────────────────────────────────────────────── */
.story-text {
  font-family: 'Lora', serif;
  font-size: clamp(0.95rem, 2.5vw, 1.05rem);
  line-height: 1.85;
  color: var(--text-primary);
}

.cursor {
  display: inline-block;
  color: var(--gold-bright);
  font-weight: 300;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.cursor.hidden { display: none; }

/* ── Loading State ────────────────────────────────────────────────────── */
.loading-state {
  display: none;
  justify-content: center;
  align-items: center;
  padding: 12px;
  flex-shrink: 0;
}

.loading-state.visible { display: flex; }

.quill-loader {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-glow);
  border-radius: 30px;
  padding: 10px 22px;
}

.quill {
  font-size: 1.3rem;
  animation: quill-write 0.8s ease-in-out infinite alternate;
  display: inline-block;
}

@keyframes quill-write {
  from { transform: rotate(-10deg) translateY(0); }
  to   { transform: rotate(10deg)  translateY(-4px); }
}

.loading-text {
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* ── Choices Area ─────────────────────────────────────────────────────── */
.choices-area {
  flex-shrink: 0;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--transition), transform var(--transition);
  pointer-events: none;
}

.choices-area.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

.choices-label {
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  color: var(--gold-dim);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  text-align: center;
  margin-bottom: 10px;
}

.choices-grid {
  display: grid;
  gap: 8px;
}

.choice-btn {
  width: 100%;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--bg-card), var(--bg-mid));
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'Lora', serif;
  font-size: 0.9rem;
  font-style: italic;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  overflow: hidden;
}

.choice-btn::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--purple-bright);
  transform: scaleY(0);
  transition: transform var(--transition);
  border-radius: 0 2px 2px 0;
}

.choice-letter {
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
  font-style: normal;
  font-weight: 700;
  color: var(--gold-bright);
  background: rgba(245,200,66,0.1);
  border: 1px solid rgba(245,200,66,0.3);
  border-radius: 4px;
  padding: 2px 7px;
  flex-shrink: 0;
}

.choice-btn:hover {
  border-color: var(--purple-bright);
  background: linear-gradient(135deg, var(--purple-dim), var(--bg-card));
  transform: translateX(4px);
  box-shadow: 0 4px 20px rgba(168,85,247,0.2);
}

.choice-btn:hover::before { transform: scaleY(1); }
.choice-btn:active { transform: translateX(2px); }

/* ═══════════════════════════════════════════════════════════════════════
   SCREEN 3 – Ending
═══════════════════════════════════════════════════════════════════════ */
.ending-container {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 20px 0;
  max-height: 100vh;
  overflow-y: auto;
}

.ending-header {
  text-align: center;
}

.ending-icon {
  font-size: 3rem;
  animation: trophy-bounce 1s ease-out;
  display: block;
  margin-bottom: 12px;
}

@keyframes trophy-bounce {
  0%   { transform: scale(0.3) rotate(-15deg); opacity: 0; }
  60%  { transform: scale(1.2) rotate(5deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.ending-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 700;
  background: linear-gradient(135deg, var(--gold-bright), var(--purple-bright));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.ending-subtitle {
  font-family: 'Lora', serif;
  font-size: 1rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 8px;
}

.full-story-card {
  width: 100%;
  background: linear-gradient(145deg, var(--bg-page), var(--bg-card));
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  max-height: 40vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dim) transparent;
}

.full-story-title {
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  color: var(--gold-bright);
  margin-bottom: 16px;
  letter-spacing: 0.06em;
}

.full-story-text p {
  font-family: 'Lora', serif;
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.full-story-text p:last-child { margin-bottom: 0; }

.ending-actions {
  display: flex;
  gap: 12px;
  width: 100%;
  flex-wrap: wrap;
}

.share-btn, .play-again-btn {
  flex: 1;
  min-width: 140px;
  padding: 15px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.share-btn {
  background: transparent;
  border: 1px solid var(--gold-bright);
  color: var(--gold-bright);
}
.share-btn:hover { background: rgba(245,200,66,0.1); transform: translateY(-2px); }

.play-again-btn {
  background: linear-gradient(135deg, var(--purple-mid), var(--gold-mid));
  color: white;
  box-shadow: 0 6px 24px rgba(124,58,237,0.35);
}
.play-again-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 32px rgba(124,58,237,0.45); }

/* ── Copy Toast ───────────────────────────────────────────────────────── */
.copy-toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-card);
  border: 1px solid var(--gold-bright);
  border-radius: 30px;
  padding: 10px 24px;
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  color: var(--gold-bright);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 100;
  pointer-events: none;
}

.copy-toast.show { transform: translateX(-50%) translateY(0); }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .welcome-card { padding: 28px 20px 24px; }
  .genre-grid { grid-template-columns: repeat(2, 1fr); }
  .protagonist-grid { grid-template-columns: repeat(2, 1fr); }
  .book-page { padding: 20px 18px 20px 44px; }
  .story-book::before { left: 32px; }
  .ending-actions { flex-direction: column; }
}

/* ── Entrance animations for choice buttons ───────────────────────────── */
@keyframes slide-up-fade {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.choice-btn { animation: slide-up-fade 0.4s ease both; }
.choice-btn:nth-child(1) { animation-delay: 0.05s; }
.choice-btn:nth-child(2) { animation-delay: 0.12s; }
.choice-btn:nth-child(3) { animation-delay: 0.19s; }
