/* Palette props are registered so colors glide when the fire changes */
@property --f1 { syntax: "<color>"; inherits: true; initial-value: #e4561f; }
@property --f2 { syntax: "<color>"; inherits: true; initial-value: #f8a23a; }
@property --f3 { syntax: "<color>"; inherits: true; initial-value: #ffe7ad; }
@property --glow-a { syntax: "<color>"; inherits: true; initial-value: #e8662f; }
@property --glow-b { syntax: "<color>"; inherits: true; initial-value: #f4ad4c; }
@property --spark { syntax: "<color>"; inherits: true; initial-value: #f4ad4c; }
@property --spark2 { syntax: "<color>"; inherits: true; initial-value: #ff8a3d; }
@property --ember { syntax: "<color>"; inherits: true; initial-value: #e8662f; }
@property --gold { syntax: "<color>"; inherits: true; initial-value: #f4ad4c; }

:root {
  --bg: #16110d;
  --bg-2: #211912;
  --card: #2a1f17;
  --line: #3d2e22;
  --text: #f4e9d8;
  --muted: #b9a68f;
  --on-ember: #fff8ee;
  --heat: 0; /* 0..1, set per level */
  color-scheme: dark;
  transition: --f1 .7s ease, --f2 .7s ease, --f3 .7s ease, --glow-a .9s ease, --glow-b .9s ease,
    --spark .9s ease, --spark2 .9s ease, --ember .7s ease, --gold .7s ease;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 Figtree, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* Fire glow behind everything, warmer as you go deeper */
.glow {
  position: fixed; inset: auto -20vw -40vh -20vw; height: 90vh; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 35% 100%, color-mix(in srgb, var(--glow-a) calc(20% + var(--heat) * 30%), transparent) 0%, transparent 60%),
    radial-gradient(ellipse at 65% 100%, color-mix(in srgb, var(--glow-b) calc(12% + var(--heat) * 20%), transparent) 0%, transparent 60%);
  animation: breathe 5s ease-in-out infinite;
}
@keyframes breathe { 50% { opacity: .82; transform: scale(1.03); } }

.sparks { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.sparks i {
  position: absolute; bottom: -10px; width: 3px; height: 3px; border-radius: 50%;
  background: var(--spark); box-shadow: 0 0 6px 1px var(--spark);
  animation: rise linear infinite; opacity: 0;
}
.sparks i:nth-child(even) { background: var(--spark2); box-shadow: 0 0 6px 1px var(--spark2); }
@keyframes rise {
  0% { transform: translate(0, 0); opacity: 0; }
  10% { opacity: .9; }
  100% { transform: translate(var(--drift), -75vh); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .sparks { display: none; }
  .glow { animation: none; }
  .flame .f1, .flame .f2, .flame .f3, .flame .halo path { animation: none; }
}

.view {
  position: relative; z-index: 1;
  max-width: 640px; margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  min-height: 100dvh;
}

/* Home */
.brand { text-align: center; padding: 18px 0 0; }
h1, h2, .question {
  font-family: Fraunces, Georgia, serif;
  font-variation-settings: "SOFT" 100;
  font-weight: 600; letter-spacing: -.01em;
}
h1 { font-size: 2.3rem; margin: 0; }
h2 { font-size: 1.9rem; margin: 10px 0 4px; line-height: 1.15; }
.tag { color: var(--muted); margin: 2px 0 0; font-size: 1rem; }

.stage { position: relative; margin: 0 -16px; --flame-h: min(46vh, 380px); }
.flame {
  position: absolute; left: 50%; top: 8px; height: var(--flame-h); aspect-ratio: 200 / 320;
  transform: translateX(-50%); pointer-events: none; z-index: 1;
}
.flame svg { width: 100%; height: 100%; overflow: visible; }
.flame .f1, .flame .f2, .flame .f3 {
  transform-box: fill-box; transform-origin: 50% 100%;
  animation: lick 2.2s ease-in-out infinite;
}
.flame .f1 { fill: var(--f1); }
.flame .f2 { opacity: .95; }
.flame .f2 { fill: var(--f2); animation-duration: 1.6s; animation-delay: -.4s; }
.flame .f3 { fill: var(--f3); animation-duration: 1.1s; animation-delay: -.2s; }
.flame .halo path { fill: var(--glow-a); opacity: .55; filter: blur(22px); transform-box: fill-box; transform-origin: 50% 100%; animation: lick 3s ease-in-out infinite; }
.flame .logs rect { fill: #5a3a26; }
.flame .logs rect + rect { fill: #74492f; }
@keyframes lick {
  0%, 100% { transform: scale(1, 1) skewX(0); }
  25% { transform: scale(.96, 1.05) skewX(-2.5deg); }
  50% { transform: scale(1.03, .95) skewX(2deg); }
  75% { transform: scale(.98, 1.07) skewX(-1deg); }
}
/* gutters down, changes color, flares back */
.flame > svg { transform-origin: 50% 90%; }
.flame.gutter > svg { animation: gutter .7s cubic-bezier(.3, .7, .3, 1); }
@keyframes gutter {
  0% { transform: scale(1); filter: brightness(1); }
  30% { transform: scale(.72, .42); filter: brightness(.55); }
  65% { transform: scale(1.06, 1.14); filter: brightness(1.25); }
  100% { transform: scale(1); filter: brightness(1); }
}
.flame.ignite > svg { animation: ignite .5s ease-in forwards; }
@keyframes ignite {
  40% { transform: scale(1.12, 1.3); filter: brightness(1.4); }
  100% { transform: scale(1.5, 2.2); filter: brightness(2); opacity: 0; }
}

.track {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
}
.track::-webkit-scrollbar { display: none; }
.slide {
  flex: 0 0 100%; scroll-snap-align: center; scroll-snap-stop: always;
  background: none; border: 0; padding: 0 28px 4px; text-align: center;
  display: flex; flex-direction: column; align-items: center;
}
.slide:focus-visible { outline: none; }
.slide:focus-visible h3 { text-decoration: underline; text-decoration-color: var(--ember); text-underline-offset: 6px; }
.slide .space { height: calc(var(--flame-h) + 26px); width: 100%; }
.slide .meta { font-size: .74rem; color: var(--gold); text-transform: uppercase; letter-spacing: .14em; font-weight: 600; }
.slide h3 { margin: 4px 0 6px; font: 600 2rem/1.1 Fraunces, Georgia, serif; font-variation-settings: "SOFT" 100; }
.slide p { margin: 0; color: var(--muted); font-size: .98rem; max-width: 34ch; }
.slide .season { display: inline-block; margin-top: 10px; font-size: .78rem; color: var(--gold); font-style: italic; font-family: Fraunces, Georgia, serif; }

.arrow {
  position: absolute; top: calc(var(--flame-h) / 2 - 22px); z-index: 2;
  width: 44px; height: 44px; border: 0; background: none; color: var(--muted);
  font: 300 2.4rem/1 Fraunces, Georgia, serif; opacity: .55; transition: opacity .2s, color .2s;
}
.arrow:hover { opacity: 1; color: var(--text); }
.arrow:disabled { opacity: 0; pointer-events: none; }
.arrow.prev { left: 10px; }
.arrow.next { right: 10px; }

.dots { display: flex; justify-content: center; gap: 10px; margin-top: 18px; }
.dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--line); transition: background .4s, box-shadow .4s, transform .4s; }
.dots span.on { background: var(--ember); box-shadow: 0 0 10px var(--ember); transform: scale(1.25); }
.tap-hint { text-align: center; color: var(--muted); font-size: .85rem; margin: 12px 0 0; font-family: Fraunces, Georgia, serif; font-style: italic; }

.privacy { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 22px; opacity: .8; }

/* Shared bits */
.back {
  background: none; border: 0; color: var(--muted); padding: 6px 0; font-size: .95rem;
}
.back:hover { color: var(--text); }
.sub { color: var(--muted); margin: 0 0 22px; }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }
.hint.center { text-align: center; min-height: 1.3em; }
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 14px 18px; font-weight: 600; transition: transform .1s ease, background .2s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(180deg, color-mix(in srgb, var(--ember) 80%, white), var(--ember)); border-color: var(--ember); color: var(--on-ember); }
.btn.primary:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: transparent; }
.btn.small { padding: 10px 14px; font-size: .9rem; }
.btn.wide { width: 100%; margin-top: 26px; font-size: 1.05rem; }
.btn.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--ember) 25%, transparent), 0 0 24px color-mix(in srgb, var(--ember) 50%, transparent); } }
.linkish { background: none; border: 0; color: var(--gold); display: block; margin: 18px auto 0; font-weight: 600; }

/* Setup */
.field-label { display: block; font-weight: 600; margin-bottom: 8px; }
.field-label span { color: var(--muted); font-weight: 400; }
.name-row { display: flex; gap: 8px; }
.name-row input {
  flex: 1; min-width: 0; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font: inherit; font-size: 16px;
}
.name-row input:focus { outline: 2px solid var(--ember); outline-offset: 1px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  background: var(--card); border: 1px solid var(--line); border-radius: 99px;
  padding: 6px 8px 6px 14px; display: inline-flex; align-items: center; gap: 6px;
}
.chip button { background: none; border: 0; color: var(--muted); font-size: 1.1rem; line-height: 1; padding: 0 4px; }
.toggle {
  display: flex; gap: 12px; align-items: flex-start; margin-top: 24px; padding: 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2); font-size: .92rem; color: var(--muted);
}
.toggle b { color: var(--text); font-weight: 600; }
.toggle input { width: 20px; height: 20px; accent-color: var(--ember); margin-top: 2px; flex: none; }

/* Play */
.topbar { display: flex; align-items: center; gap: 10px; }
.deck-name { flex: 1; text-align: center; color: var(--muted); font-size: .9rem; font-weight: 600; letter-spacing: .04em; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 10px; width: 38px; height: 38px; display: grid; place-items: center; color: var(--muted); }
.icon-btn svg { width: 18px; height: 18px; }

.meter { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 18px 0 8px; }
.meter button {
  background: none; border: 0; padding: 0; display: grid; gap: 6px; text-align: center;
  color: var(--muted); font-size: .78rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
}
.meter .bar { height: 6px; border-radius: 99px; background: var(--line); transition: background .5s ease, box-shadow .5s ease; }
.meter .lit .bar { background: linear-gradient(90deg, var(--ember), var(--gold)); box-shadow: 0 0 10px color-mix(in srgb, var(--ember) 60%, transparent); }
.meter .current { color: var(--gold); }

.card {
  min-height: 44vh; display: flex; flex-direction: column; justify-content: center;
  padding: 24px 6px;
}
.who {
  color: var(--gold); font-weight: 600; font-size: .9rem; letter-spacing: .08em; text-transform: uppercase;
  margin: 0 0 14px; min-height: 1.4em;
}
.question {
  font-size: clamp(1.7rem, 7vw, 2.6rem); line-height: 1.2; margin: 0; text-wrap: balance;
}
.card.enter .question, .card.enter .who { animation: fadeUp .5s ease both; }
.card.enter .question { animation-delay: .05s; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.journal-box { margin: -10px 0 18px; }
.journal-box textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 14px; font: inherit; font-size: 16px; resize: vertical;
}
.journal-box textarea:focus { outline: 2px solid var(--ember); outline-offset: 1px; }
.journal-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.saved { color: var(--gold); font-size: .85rem; }
#play.solo .card { min-height: 30vh; }

/* Journal history */
.entry { border-top: 1px solid var(--line); padding: 16px 0; }
.entry .date { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.entry h4 { margin: 4px 0 6px; font: 600 1.15rem/1.3 Fraunces, Georgia, serif; }
.entry p { margin: 0; white-space: pre-wrap; }
.entry .del { background: none; border: 0; color: var(--muted); font-size: .8rem; padding: 6px 0 0; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* Big screen (TV / laptop on the coffee table) */
body.tv .view#play { max-width: 1200px; }
body.tv .question { font-size: clamp(2.4rem, 5.2vw, 5rem); }
body.tv .who { font-size: clamp(1rem, 1.6vw, 1.6rem); }
body.tv .card { min-height: 62vh; text-align: center; }
body.tv .controls { max-width: 520px; margin: 0 auto; }
body.tv .meter { max-width: 720px; margin-left: auto; margin-right: auto; }
