:root {
  --night: #0b0f2a; --indigo: #151a4a; --indigo2: #1f2566; --line: #3a3f85;
  --ember: #ff9b3d; --amber: #ffcf8a; --glow: #ffb25a;
  --text: #f6e7cf; --muted: #b8b3d8; --danger: #8c3a3a;
  --r: 22px; --nav-h: 76px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Quicksand", "Varela Round", "Trebuchet MS", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { color-scheme: dark; background: var(--night); }
body {
  margin: 0; min-height: 100dvh; font-family: var(--font); font-size: 18px; line-height: 1.5; color: var(--text);
  background: radial-gradient(120% 80% at 50% 110%, #5a2d4a 0%, #231d5c 38%, var(--night) 75%); background-attachment: fixed;
  overflow-x: hidden;
}
h1, h2, h3 { font-weight: 800; line-height: 1.2; margin: 0 0 .4em; letter-spacing: .01em; }
h1 { font-size: 1.9rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.1rem; }
p { margin: 0 0 .8em; }
a { color: var(--amber); }
.muted { color: var(--muted); } .fine { color: var(--muted); font-size: .85rem; } .center { text-align: center; }
.error { color: #ffb4a8; min-height: 1.4em; margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }

/* twinkling sky + embers */
#sky, #embers { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
#sky {
  background-image:
    radial-gradient(1.5px 1.5px at 8% 12%, #fff3d6 50%, transparent 51%), radial-gradient(1px 1px at 22% 30%, #fff3d6 50%, transparent 51%),
    radial-gradient(2px 2px at 36% 8%, #ffe9b8 50%, transparent 51%), radial-gradient(1px 1px at 48% 22%, #fff3d6 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 61% 14%, #fff3d6 50%, transparent 51%), radial-gradient(1px 1px at 74% 34%, #ffe9b8 50%, transparent 51%),
    radial-gradient(2px 2px at 86% 10%, #fff3d6 50%, transparent 51%), radial-gradient(1px 1px at 94% 26%, #fff3d6 50%, transparent 51%),
    radial-gradient(1px 1px at 14% 52%, #fff3d6 50%, transparent 51%), radial-gradient(1.5px 1.5px at 68% 56%, #ffe9b8 50%, transparent 51%),
    radial-gradient(1px 1px at 30% 66%, #fff3d6 50%, transparent 51%), radial-gradient(1px 1px at 88% 70%, #fff3d6 50%, transparent 51%);
  animation: twinkle 9s ease-in-out infinite alternate;
}
#embers i { position: absolute; bottom: -20px; border-radius: 50%; background: radial-gradient(circle, #ffd28a, #ff8a2b 60%, transparent 70%); opacity: 0; animation: rise linear infinite; }
@keyframes twinkle { from { opacity: .55; } to { opacity: 1; } }
@keyframes rise { 0% { transform: translate(0, 0); opacity: 0; } 12% { opacity: .55; } 80% { opacity: .25; } 100% { transform: translate(30px, -105vh); opacity: 0; } }
.tw { animation: tw 7s ease-in-out infinite alternate; } @keyframes tw { from { opacity: .35; } to { opacity: 1; } }
.fly { animation: fly 12s ease-in-out infinite alternate; } @keyframes fly { 0% { transform: translate(0, 0); opacity: .15; } 50% { opacity: .9; } 100% { transform: translate(18px, -14px); opacity: .25; } }
.flame { transform-origin: 200px 205px; animation: flick 3.4s ease-in-out infinite alternate; } @keyframes flick { from { transform: scale(1, .96); } to { transform: scale(1.03, 1.04); } }
.wave { animation: wv 9s ease-in-out infinite alternate; } .wave2 { animation: wv 12s ease-in-out infinite alternate-reverse; } @keyframes wv { from { transform: translateX(-14px); } to { transform: translateX(14px); } }
.bob { animation: bob 7s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; } @keyframes bob { from { transform: translateY(-2px) rotate(-1deg); } to { transform: translateY(3px) rotate(1deg); } }
.drift-slow { animation: dr 30s ease-in-out infinite alternate; } @keyframes dr { from { transform: translateX(-12px); } to { transform: translateX(12px); } }
.snow circle { animation: snow 14s linear infinite; } @keyframes snow { from { transform: translate(0, -20px); opacity: 0; } 10% { opacity: .9; } to { transform: translate(14px, 240px); opacity: .2; } }
.sway { animation: sway 6s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: bottom; } @keyframes sway { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
.spin { animation: spin 40s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; scroll-behavior: auto !important; } #embers { display: none; } }

#app { position: relative; z-index: 1; min-height: 100dvh; }
.page { max-width: 640px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 20px) 18px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px); display: flex; flex-direction: column; gap: 14px; }
.page.center { align-items: center; justify-content: center; text-align: center; min-height: 100dvh; padding-bottom: 40px; }
.page.auth { max-width: 460px; margin: 0 auto; }
.top { padding-top: 6px; } .top h1 { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.row { display: flex; align-items: center; } .gap { gap: 12px; } .grow { flex: 1; min-width: 0; }
.row.gap > .btn { flex: 1; }
.brand { font-size: 3rem; margin: 0; color: var(--amber); text-shadow: 0 0 24px rgba(255, 178, 90, .45); }
.tagline { color: var(--muted); max-width: 22em; margin: 0 auto 10px; }
.logo.big { width: 112px; height: 112px; filter: drop-shadow(0 0 22px rgba(255, 207, 138, .35)); }
.logo { width: 64px; height: 64px; }
.back { align-self: flex-start; background: none; border: 0; padding: 8px; margin-left: -8px; color: var(--amber); }
.step { color: var(--ember); font-weight: 700; margin: 0; }
.link { text-align: center; padding: 10px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 56px; padding: 12px 24px; border-radius: 30px; border: 0; font-weight: 800; font-size: 1.05rem; text-decoration: none;
  color: #2a1500; background: linear-gradient(180deg, #ffd28a, var(--ember)); box-shadow: 0 6px 22px rgba(255, 155, 61, .25); transition: transform .25s ease, box-shadow .4s ease; }
.btn:active { transform: scale(.98); } .btn:disabled { opacity: .6; }
.btn.big { min-height: 64px; font-size: 1.15rem; width: 100%; }
.btn.alt { background: var(--indigo2); color: var(--text); box-shadow: inset 0 0 0 2px var(--line); }
.btn.ghost { background: transparent; color: var(--amber); box-shadow: none; }
.btn.danger { background: var(--danger); color: #ffe9e0; box-shadow: none; }
.btn.glow { animation: breathe 5s ease-in-out infinite alternate; } @keyframes breathe { from { box-shadow: 0 6px 22px rgba(255, 155, 61, .2); } to { box-shadow: 0 6px 40px rgba(255, 155, 61, .5); } }
.icon-btn { background: transparent; border: 0; width: 52px; height: 52px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--text); flex: none; }
.icon-btn:active { background: rgba(255, 255, 255, .08); }
.icon-btn.heart.on { color: #ff8fa8; } .icon-btn.heart.on svg { fill: #ff8fa8; }
.icon-btn.lg { width: 64px; height: 64px; }
.ico { display: inline-flex; } .ico svg { display: block; }

/* fields */
.lbl { display: flex; flex-direction: column; gap: 6px; font-weight: 700; color: var(--amber); font-size: .95rem; text-align: left; }
.field, select.field { width: 100%; min-height: 54px; padding: 10px 16px; border-radius: 18px; border: 2px solid var(--line); background: #10143d; color: var(--text); font: inherit; font-size: 1.05rem; font-weight: 500; }
input[type=range] { width: 100%; accent-color: var(--ember); height: 40px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; min-height: 48px; } .check input { width: 26px; height: 26px; accent-color: var(--ember); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; } .chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { flex: none; min-height: 46px; padding: 6px 18px; border-radius: 24px; border: 2px solid var(--line); background: transparent; color: var(--text); font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.chip.on { background: var(--ember); border-color: var(--ember); color: #2a1500; }

/* cards */
.card { background: linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .03)); border: 1px solid rgba(255, 207, 138, .15); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.card h2 { margin: 0; }
.list { display: flex; flex-direction: column; gap: 12px; }
.row-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 207, 138, .12); border-radius: 20px; color: var(--text); text-decoration: none; }
.row-card p { margin: 0; font-size: .9rem; }
.avatar { width: 56px; height: 56px; border-radius: 50%; overflow: hidden; flex: none; background: #26285f; display: flex; align-items: center; justify-content: center; }
.avatar svg { width: 100%; height: 100%; object-fit: cover; } .avatar.sm { width: 46px; height: 46px; font-size: 1.3rem; color: var(--amber); }
.code { font-size: 2rem; letter-spacing: .15em; font-weight: 800; color: var(--amber); text-align: center; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px 0; color: var(--muted); text-align: center; }

/* builder */
.dots { display: flex; justify-content: center; gap: 4px; }
.dot { width: 36px; height: 36px; background: none; border: 0; position: relative; } .dot::after { content: ""; position: absolute; inset: 12px; border-radius: 50%; background: var(--line); transition: all .5s; }
.dot.done::after { background: var(--amber); } .dot.on::after { inset: 8px; background: var(--ember); box-shadow: 0 0 14px var(--ember); }
.q { text-align: center; margin: 4px 0; } .q.sm { text-align: left; margin-top: 14px; font-size: 1.1rem; color: var(--amber); }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; } .grid.wide { grid-template-columns: repeat(2, 1fr); }
.pick { background: rgba(255, 255, 255, .06); border: 3px solid transparent; border-radius: 26px; padding: 10px; min-height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; transition: all .5s ease; }
.pick .art { width: 100%; display: flex; justify-content: center; } .pick .art svg { width: 100%; max-width: 120px; max-height: 120px; border-radius: 18px; }
.grid.wide .art svg { max-width: none; height: 92px; width: 100%; } .pick .lab { font-weight: 800; line-height: 1.15; } .pick .sub { font-size: .85rem; color: var(--muted); }
.pick.on { border-color: var(--ember); background: rgba(255, 155, 61, .14); box-shadow: 0 0 30px rgba(255, 155, 61, .25); }
.pick:active { transform: scale(.98); }
.mins { width: 96px; height: 96px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffe3ae, var(--ember)); color: #2a1500; font-size: 2.6rem; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.summary { margin-top: 6px; text-align: center; } .summary p { margin: 0; }
.hscroll { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.mini { flex: none; width: 150px; text-decoration: none; color: var(--text); font-size: .9rem; font-weight: 700; line-height: 1.2; }
.mini .thumb { border-radius: 16px; overflow: hidden; margin-bottom: 6px; } .thumb svg { display: block; width: 100%; height: auto; }
.weave { position: fixed; inset: 0; z-index: 50; background: rgba(8, 10, 32, .94); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 20px; animation: fadein 1.2s ease; }
@keyframes fadein { from { opacity: 0; } }

/* library */
.story-card { position: relative; display: flex; flex-direction: column; border-radius: 24px; overflow: hidden; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 207, 138, .14); }
.story-link { color: var(--text); text-decoration: none; position: relative; display: block; }
.story-link .thumb svg { aspect-ratio: 400 / 190; }
.thumb-wrap { position: relative; } .thumb-animal { position: absolute; bottom: 8px; left: 12px; width: 70px; height: 70px; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .5)); } .thumb-animal svg { width: 100%; height: 100%; }
.story-card .meta { padding: 10px 16px 14px; min-height: 76px; } .meta h3 { margin: 0 0 2px; } .meta p { margin: 0; font-size: .9rem; }
.story-card > .icon-btn { position: absolute; top: 6px; background: rgba(10, 12, 40, .6); } .story-card > .icon-btn.heart { right: 62px; } .story-card > .icon-btn:last-child { right: 6px; }
.badge { display: inline-flex; align-items: center; margin-left: 10px; color: var(--amber); }

/* bottom nav */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around; padding: 8px 6px calc(env(safe-area-inset-bottom) + 8px); min-height: var(--nav-h);
  background: linear-gradient(180deg, rgba(11, 15, 42, .85), rgba(11, 15, 42, .98)); border-top: 1px solid rgba(255, 207, 138, .14); backdrop-filter: blur(10px); }
.bottom-nav a { flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-radius: 18px; text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 700; }
.bottom-nav a.on { color: var(--ember); background: rgba(255, 155, 61, .12); }

/* sheet */
.sheet-back { position: fixed; inset: 0; z-index: 60; background: rgba(4, 5, 20, .6); display: flex; align-items: flex-end; justify-content: center; opacity: 0; transition: opacity .3s ease; }
.sheet-back.open { opacity: 1; }
.sheet { width: 100%; max-width: 640px; max-height: 88dvh; overflow: auto; background: #141846; border-radius: 28px 28px 0 0; padding: 12px 20px calc(env(safe-area-inset-bottom) + 24px); border-top: 1px solid rgba(255, 207, 138, .25); transform: translateY(40px); transition: transform .35s ease; }
.sheet-back.open .sheet { transform: none; }
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; } .sheet h2 { text-align: center; }
.sheet-body { display: flex; flex-direction: column; gap: 14px; }
.gate-q { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 1.6rem; font-weight: 800; color: var(--amber); }
.gate-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px); transform: translate(-50%, 20px); z-index: 80; max-width: min(92vw, 520px); background: #2a2f78; color: var(--text); border: 1px solid var(--line); padding: 14px 20px; border-radius: 20px; opacity: 0; transition: all .5s ease; pointer-events: none; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body.in-player #toast { bottom: 130px; }

/* player */
.player { max-width: 640px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; padding: env(safe-area-inset-top) 14px 0; }
.player-top { display: flex; align-items: center; gap: 4px; min-height: 60px; } .player-top h1 { flex: 1; font-size: 1.15rem; margin: 0; text-align: center; }
.stage { position: relative; border-radius: 26px; overflow: hidden; aspect-ratio: 400 / 215; box-shadow: 0 8px 40px rgba(0, 0, 0, .4); flex: none; border: 1px solid rgba(255, 207, 138, .15); }
.scene-wrap, .scene-wrap svg { width: 100%; height: 100%; display: block; } .scene-wrap svg { object-fit: cover; }
.fig { position: absolute; bottom: 4%; opacity: 0; transition: opacity 3s ease, transform 4s ease; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .5)); pointer-events: none; }
.fig svg { width: 100%; height: 100%; display: block; }
.fig.hero { width: 20%; left: 26%; transform: translateX(-40px); } .fig.friend { width: 22%; left: 52%; transform: translateX(40px); }
.fig.in { opacity: 1; transform: none; }
.fig.prop-wrap { top: 8%; bottom: auto; left: 0; right: 0; height: 18%; opacity: 1; }
.prop-drift { position: absolute; width: 11%; aspect-ratio: 1; left: -12%; animation: drift 22s ease-in-out forwards; opacity: 0; } .prop-drift svg { width: 100%; height: 100%; }
@keyframes drift { 0% { left: -12%; opacity: 0; } 15% { opacity: .9; } 85% { opacity: .9; } 100% { left: 100%; opacity: 0; } }
.progress { height: 4px; background: rgba(255, 255, 255, .08); border-radius: 2px; margin: 10px 4px; flex: none; } .progress i { display: block; height: 100%; width: 0; background: var(--ember); border-radius: 2px; transition: width 1.5s ease; }
.story-text { flex: 1; overflow-y: auto; padding: 8px 6px 130px; font-size: clamp(1.25rem, 4.6vw, 1.55rem); line-height: 1.75; scroll-behavior: smooth; mask-image: linear-gradient(transparent, #000 5%, #000 92%, transparent); }
.story-text p { margin: 0 0 1.1em; }
.sent { color: #a9a4cc; transition: color 1s ease, text-shadow 1s ease; border-radius: 8px; cursor: pointer; }
.sent.now { color: #fff0d2; text-shadow: 0 0 18px rgba(255, 178, 90, .7); background: rgba(255, 155, 61, .12); box-decoration-break: clone; -webkit-box-decoration-break: clone; padding: 2px 3px; }
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; align-items: center; justify-content: center; gap: 14px; padding: 16px 12px calc(env(safe-area-inset-bottom) + 16px); background: linear-gradient(0deg, rgba(11, 15, 42, .98) 55%, transparent); }
.play-btn { width: 88px; height: 88px; border-radius: 50%; border: 0; background: radial-gradient(circle at 35% 30%, #ffe3ae, var(--ember)); color: #2a1500; display: flex; align-items: center; justify-content: center; box-shadow: 0 0 34px rgba(255, 155, 61, .45); animation: breathe 5s ease-in-out infinite alternate; }
.dim { position: fixed; inset: 0; z-index: 40; background: #000; opacity: 0; pointer-events: none; transition: opacity 3s ease; }
.dim.black { pointer-events: auto; }
body.in-player .bottom-nav { display: none; }
.rec .story-text { padding-bottom: 20px; flex: 1; min-height: 160px; font-size: 1.35rem; max-height: 46dvh; }
.rec-time { text-align: center; font-size: 2.2rem; font-weight: 800; color: var(--amber); font-variant-numeric: tabular-nums; }
.rec-bar { display: flex; flex-direction: column; gap: 12px; align-items: center; padding: 8px 0 calc(env(safe-area-inset-bottom) + 24px); }
.rec-btn { width: 96px; height: 96px; border-radius: 50%; border: 5px solid var(--text); background: transparent; display: flex; align-items: center; justify-content: center; }
.rec-btn i { width: 60px; height: 60px; border-radius: 50%; background: #e0574f; transition: all .4s ease; } .rec-btn.on i { width: 34px; height: 34px; border-radius: 9px; animation: breathe 2s ease-in-out infinite alternate; }
.audio { width: 100%; } .rec .row { width: 100%; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(4, 1fr); } .grid.wide { grid-template-columns: repeat(2, 1fr); } .list { display: grid; grid-template-columns: 1fr; } .page { max-width: 760px; } }
