:root {
  --bg: #120b1a;
  --bg-2: #1c1128;
  --ember: #ff7a2f;
  --ember-hot: #ffce6b;
  --gold: #ffd166;
  --ink: #f4ead9;
  --muted: #b6a7c4;
  --panel: rgba(38, 24, 56, 0.72);
  --panel-line: rgba(255, 190, 120, 0.22);
  --danger: #e0506b;
  --ok: #66d6a4;
  font-size: 17px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(120% 90% at 50% 0%, #2a1636 0%, var(--bg) 55%, #0a0610 100%);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", "Georgia", serif;
  overflow: hidden;
}

.app { height: 100%; }

.screen { display: none; height: 100%; flex-direction: column; }
.screen.active { display: flex; }

/* ---------------- buttons ---------------- */
button { font-family: inherit; cursor: pointer; border: 0; }
.btn-primary {
  background: linear-gradient(180deg, var(--ember-hot), var(--ember));
  color: #2a1204; font-weight: 700; font-size: 1.05rem;
  padding: 0.8rem 1.6rem; border-radius: 999px;
  box-shadow: 0 6px 22px rgba(255, 122, 47, 0.4);
}
.btn-primary:active { transform: translateY(1px); }
.btn-ghost {
  background: var(--panel); color: var(--ink); border: 1px solid var(--panel-line);
  padding: 0.55rem 0.95rem; border-radius: 12px;
}
.btn-ghost:active { background: rgba(255, 190, 120, 0.14); }

/* ---------------- welcome ---------------- */
.welcome-card {
  margin: auto; max-width: 560px; text-align: center; padding: 2rem;
}
.crest { font-size: 4rem; filter: drop-shadow(0 0 24px var(--ember)); animation: flick 3s infinite ease-in-out; }
.welcome-card h1 { font-size: 3rem; margin: 0.3rem 0; letter-spacing: 0.04em;
  background: linear-gradient(90deg, var(--gold), var(--ember)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { color: var(--muted); line-height: 1.6; }
.field { display: block; text-align: left; margin: 1.6rem 0; }
.field span { display: block; color: var(--muted); margin-bottom: 0.4rem; font-size: 0.9rem; }
.field input {
  width: 100%; padding: 0.85rem 1rem; border-radius: 14px; font-family: inherit; font-size: 1.1rem;
  background: rgba(0,0,0,0.35); border: 1px solid var(--panel-line); color: var(--ink);
}
.mini { color: var(--muted); font-size: 0.85rem; }

/* ---------------- topbar ---------------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.45rem 1rem; border-bottom: 1px solid var(--panel-line); flex: 0 0 auto;
}
.who { color: var(--muted); letter-spacing: 0.03em; font-size: 0.9rem; }
.who #hero-name { color: var(--gold); }
.dot { margin: 0 0.35rem; }
.clock {
  font-variant-numeric: tabular-nums; font-size: 1rem; color: var(--ember-hot);
  background: rgba(0,0,0,0.3); padding: 0.2rem 0.7rem; border-radius: 999px; border: 1px solid var(--panel-line);
}
.clock.low { color: var(--danger); animation: pulse 1s infinite; }

/* ---------------- stage ---------------- */
.stage { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center;
  padding: 0.35rem 0.6rem 0.2rem; overflow: hidden; min-height: 0; gap: 0.25rem; }
.cast { display: flex; gap: 1.1rem; align-items: flex-end; flex: 0 0 auto; }
.avatar { margin: 0; text-align: center; }
.avatar figcaption { color: var(--muted); font-size: 0.7rem; margin-top: 0.1rem; }
.cinder { position: relative; width: 58px; height: 58px; }
.flame {
  position: absolute; left: 50%; bottom: 10px; width: 34px; height: 34px; transform: translateX(-50%);
  background: radial-gradient(circle at 50% 70%, #fff3c4 0%, var(--ember-hot) 32%, var(--ember) 62%, transparent 76%);
  border-radius: 50% 50% 42% 42% / 60% 60% 40% 40%;
  filter: blur(0.4px) drop-shadow(0 0 12px var(--ember));
  animation: flick 1.8s infinite ease-in-out; transition: height 0.6s, width 0.6s, filter 0.6s;
}
.cinder::after { content: "🐉"; position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); font-size: 1.1rem; }
.cinder.worried .flame { filter: grayscale(0.4) drop-shadow(0 0 6px #6b5a7a); }
.cinder.sleepy .flame { opacity: 0.5; }
.npc-glyph { width: 58px; height: 58px; display: grid; place-items: center; font-size: 1.9rem;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 50%; }

.scene-line { max-width: 720px; text-align: center; margin: 0.15rem 0 0; flex: 0 0 auto; }
#scene-goal { color: var(--gold); font-style: italic; margin: 0; font-size: 0.92rem; line-height: 1.3; }

.gamebar { display: flex; align-items: center; justify-content: center; gap: 0.5rem; margin-top: 0.25rem; }
.hp { width: 120px; height: 8px; background: rgba(255,255,255,0.12); border: 1px solid var(--panel-line); border-radius: 6px; overflow: hidden; }
.hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #e5484d, #ff7a2f); transition: width 0.4s ease; }
.hp-label { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.04em; }
.level-label { font-size: 0.72rem; color: var(--gold); letter-spacing: 0.05em; }

.dialogue { flex: 1 1 auto; min-height: 0; width: 100%; max-width: 760px; overflow-y: auto;
  padding: 0.35rem 0.4rem 0.6rem; display: flex; flex-direction: column; gap: 0.55rem; }

.bubble { max-width: 84%; padding: 0.65rem 0.95rem; border-radius: 16px; line-height: 1.45; font-size: 1.12rem; animation: rise 0.35s ease; }
.npc-bubble { align-self: flex-start; background: var(--panel); border: 1px solid var(--panel-line); border-bottom-left-radius: 5px; }
.child-bubble { align-self: flex-end; background: rgba(255, 122, 47, 0.16); border: 1px solid rgba(255, 122, 47, 0.4); border-bottom-right-radius: 5px; }
.child-bubble .tag { display:block; font-size: 0.72rem; color: var(--ember-hot); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 0.15rem; }
.bubble.thinking { color: var(--muted); font-style: italic; }

/* ---------------- spell slot (the on-screen objective) ---------------- */
.spell-slot {
  width: 100%; max-width: 760px; margin: 0; flex: 0 0 auto;
  display: flex; flex-direction: row; gap: 0.5rem; align-items: center; justify-content: center; flex-wrap: wrap;
  padding: 0.35rem 0.8rem; border-radius: 12px; text-align: center;
  animation: rise 0.3s ease; transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.spell-slot[hidden] { display: none; }
.spell-badge {
  font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700;
}
.spell-cue { font-size: 0.98rem; line-height: 1.3; }
.spell-model { font-size: 0.9rem; color: var(--ember-hot); font-style: italic; }
.spell-model[hidden] { display: none; }

/* CAST: the child must speak the key - glow, pull the eye here. */
.spell-slot.cast {
  background: linear-gradient(180deg, rgba(255, 122, 47, 0.18), rgba(255, 122, 47, 0.06));
  border: 1px solid rgba(255, 170, 90, 0.55);
  box-shadow: 0 0 26px rgba(255, 122, 47, 0.28);
}
.spell-slot.cast .spell-badge { color: var(--ember-hot); }
.spell-slot.cast .spell-cue { color: #fff2df; }

/* FREE: story time - dim, unobtrusive. */
.spell-slot.free {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-line);
}
.spell-slot.free .spell-badge { color: var(--muted); }
.spell-slot.free .spell-cue { color: var(--muted); font-style: italic; }


/* ---------------- controls ---------------- */
.controls { display: flex; align-items: center; gap: 0.7rem; padding: 0.5rem 1rem 0.7rem; justify-content: center; flex-wrap: wrap; flex: 0 0 auto; }
.mic {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.1rem;
  width: 78px; height: 78px; border-radius: 50%; color: #2a1204; font-weight: 700;
  background: radial-gradient(circle at 50% 35%, var(--ember-hot), var(--ember));
  box-shadow: 0 8px 22px rgba(255, 122, 47, 0.4);
  transition: transform 0.12s, box-shadow 0.3s;
}
.mic .mic-icon { font-size: 1.25rem; }
.mic .mic-label { font-size: 0.62rem; }
.mic:active, .mic.recording { transform: scale(0.94); box-shadow: 0 0 0 8px rgba(255, 122, 47, 0.18), 0 0 34px var(--ember); }
.mic.recording { animation: pulse 1.2s infinite; }
.mic.processing { background: radial-gradient(circle at 50% 35%, #b8a6d6, #7a66a8); box-shadow: 0 0 0 6px rgba(180, 160, 220, 0.18); animation: pulse 0.9s infinite; }
.mic:disabled { cursor: default; }
.controls-side { display: flex; flex-direction: column; gap: 0.35rem; }
.controls-side .btn-ghost { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.text-fallback { display: flex; gap: 0.5rem; width: 100%; max-width: 520px; justify-content: center; }
.text-fallback input { flex: 1; padding: 0.5rem 0.8rem; border-radius: 12px; background: rgba(0,0,0,0.35); border: 1px solid var(--panel-line); color: var(--ink); font-family: inherit; }

/* ---------------- codex ---------------- */
.codex-toggle { position: fixed; right: 0.8rem; bottom: 0.8rem; font-size: 1.3rem; width: 46px; height: 46px; border-radius: 50%; background: var(--panel); border: 1px solid var(--panel-line); z-index: 20; }
.copy-toggle { position: fixed; right: 3.9rem; bottom: 0.8rem; font-size: 1.15rem; width: 46px; height: 46px; border-radius: 50%; background: var(--panel); border: 1px solid var(--panel-line); z-index: 20; }
.copy-toggle:active { background: rgba(255, 190, 120, 0.14); }
.toast { position: fixed; right: 1rem; bottom: 5.2rem; background: rgba(10, 6, 16, 0.92); color: var(--ink); padding: 0.5rem 0.95rem; border-radius: 10px; border: 1px solid var(--panel-line); font-size: 0.9rem; opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; pointer-events: none; z-index: 60; }
.toast.show { opacity: 1; transform: translateY(0); }
.codex {
  position: fixed; top: 0; right: 0; height: 100%; width: min(360px, 88vw); z-index: 30;
  background: linear-gradient(180deg, #241634, #160d22); border-left: 1px solid var(--panel-line);
  padding: 1.4rem; transform: translateX(105%); transition: transform 0.35s ease; overflow-y: auto;
}
.codex.open { transform: translateX(0); }
.codex h2 { margin-top: 0; color: var(--gold); }
.codex h3 { color: var(--muted); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 0.4rem; }
.codex-close { position: absolute; top: 1rem; right: 1rem; background: none; color: var(--muted); font-size: 1.2rem; }
.stat-row { display: flex; gap: 1rem; margin-bottom: 1.2rem; }
.stat { flex: 1; text-align: center; background: rgba(0,0,0,0.3); border: 1px solid var(--panel-line); border-radius: 14px; padding: 0.7rem; }
.stat-num { display: block; font-size: 1.6rem; color: var(--ember-hot); }
.stat-label { color: var(--muted); font-size: 0.75rem; }
.chip-list { list-style: none; padding: 0; margin: 0 0 1.2rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip-list li { background: rgba(255, 209, 102, 0.12); border: 1px solid rgba(255, 209, 102, 0.35); color: var(--gold); padding: 0.35rem 0.75rem; border-radius: 999px; font-size: 0.85rem; }
.chip-list li.empty { background: none; border: none; color: var(--muted); }

/* ---------------- modal ---------------- */
.modal { position: fixed; inset: 0; background: rgba(6, 3, 12, 0.82); display: none; place-items: center; z-index: 40; backdrop-filter: blur(4px); }
.modal.open { display: grid; }
.modal-card { max-width: 520px; width: 90%; background: linear-gradient(180deg, #2a1838, #180e24); border: 1px solid var(--panel-line); border-radius: 22px; padding: 2rem; text-align: center; animation: rise 0.4s ease; }
.modal-card h2 { color: var(--gold); margin-top: 0; }
.rewards { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.6rem; margin: 1rem 0; }
.rewards .reward { background: rgba(255,209,102,0.12); border: 1px solid rgba(255,209,102,0.35); color: var(--gold); padding: 0.5rem 0.9rem; border-radius: 999px; font-size: 0.9rem; }

@keyframes flick { 0%,100% { transform: translateX(-50%) scale(1); } 50% { transform: translateX(-50%) scale(1.06, 0.95); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (max-width: 520px) {
  :root { font-size: 16px; }
  .cast { gap: 0.9rem; }
  .cinder, .npc-glyph { width: 50px; height: 50px; }
  .npc-glyph { font-size: 1.6rem; }
  .mic { width: 70px; height: 70px; }
  .bubble { font-size: 1.02rem; padding: 0.55rem 0.8rem; }
}