/* LoveStory web — mobile-first. Pink = brand, blue = conversation. */
:root {
  --pink: #FF4F91; --pink-deep: #E93679; --pink-soft: #FFF0F6; --pink-pale: #FFE0EC;
  --blue: #1687F8; --blue-deep: #0866D8; --in-bg: #EAF3FF; --out-bg: #1687F8; --out-text: #FFFFFF;
  --text: #20263A; --muted: #7A8295; --bg: #FFF0F6; --surface: #FFFFFF; --line: #EADDE4; --chat-bg: #F4F8FF;
  --shadow: 0 6px 24px rgba(32, 38, 58, .08); --radius: 18px;
  --font: "Poppins", "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text: #E8ECF5; --muted: #98A2B8; --bg: #101827; --surface: #172235; --line: #26344B;
    --in-bg: #1D2A3D; --chat-bg: #101827; --pink-soft: #2A1A26; --pink-pale: #3A2232; --shadow: 0 6px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --text: #E8ECF5; --muted: #98A2B8; --bg: #101827; --surface: #172235; --line: #26344B;
  --in-bg: #1D2A3D; --chat-bg: #101827; --pink-soft: #2A1A26; --pink-pale: #3A2232; --shadow: 0 6px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--pink-deep); }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: .2em 0 .4em; }
h1 { font-size: 1.7rem; letter-spacing: -.02em; }
h2 { font-size: 1.2rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.wrap { max-width: 640px; margin: 0 auto; padding: calc(12px + var(--safe-top)) 16px calc(24px + var(--safe-bottom)); }
.topbar + .wrap { padding-top: 12px; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; font-weight: 700; color: var(--pink-deep); margin: 0 0 .2em; }
.fineprint { font-size: .8rem; color: var(--muted); text-align: center; margin: 1.5rem auto; max-width: 30rem; }
.notice { background: var(--pink-pale); border-radius: 12px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.error { color: #C62828; font-weight: 600; margin: 0; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin: 16px 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.prose { max-width: 38rem; } .prose li { margin: .3em 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 10px 20px;
  border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); color: var(--text); font: 600 1rem var(--font);
  text-decoration: none; cursor: pointer; transition: transform .12s ease, box-shadow .2s ease; -webkit-tap-highlight-color: transparent; }
.btn:active { transform: scale(.98); }
.btn-primary { background: linear-gradient(135deg, var(--pink), var(--pink-deep)); border-color: transparent; color: #fff; box-shadow: 0 6px 18px rgba(233,54,121,.3); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--pink-deep); }
.btn-lg { min-height: 54px; font-size: 1.08rem; padding: 12px 28px; }
.btn-small { min-height: 36px; padding: 6px 14px; font-size: .9rem; }
.btn-danger { background: #C62828; color: #fff; border-color: transparent; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .92rem; }
.field input, .field select, .field textarea { font: 400 16px var(--font); /* 16px stops iOS zoom */ padding: 12px 14px;
  border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); color: var(--text); width: 100%; }
.field input:focus, .field select:focus { outline: 2px solid var(--pink); outline-offset: 1px; }
.check { display: flex; gap: 10px; align-items: center; }
.check input { width: 22px; height: 22px; accent-color: var(--pink); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-top)) 16px 8px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 1.15rem; }
.brand b { color: var(--pink); }
.topnav { display: flex; gap: 4px; }
.topnav a { text-decoration: none; color: var(--text); padding: 8px 10px; border-radius: 10px; font-weight: 600; font-size: .92rem; }
.topnav a:hover { background: var(--pink-pale); }
.foot { text-align: center; font-size: .78rem; color: var(--muted); padding: 0 16px calc(20px + var(--safe-bottom)); }
.foot a { color: var(--muted); }

/* Landing */
.hero { text-align: center; padding-top: 4vh; }
.hero-logo { filter: drop-shadow(0 10px 24px rgba(233,54,121,.35)); animation: beat 2.4s ease-in-out infinite; }
@keyframes beat { 0%, 100% { transform: scale(1); } 12% { transform: scale(1.06); } 24% { transform: scale(1); } 36% { transform: scale(1.04); } }
.wordmark { font-size: 2.6rem; font-weight: 800; letter-spacing: -.04em; margin: .2em 0 0; }
.wordmark span { color: var(--pink); }
.tagline { color: var(--muted); font-style: italic; margin-top: .2em; }
.hero-card { background: var(--surface); border-radius: 24px; box-shadow: var(--shadow); padding: 24px 20px; margin: 24px 0; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.hero-card h2 { font-size: 1.4rem; margin: 0; } .hero-card p { margin: 0 0 6px; }
.features { list-style: none; padding: 0; display: grid; gap: 10px; text-align: left; }
.features li { background: var(--surface); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; }
.features span { color: var(--muted); font-size: .9rem; }

/* Onboarding */
.onboard { max-width: 28rem; margin: 6vh auto 0; text-align: center; }
.onboard .stack { text-align: left; margin-top: 16px; }
.onboard-logo { margin-bottom: 8px; }
.step { color: var(--pink-deep); font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.gender-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.gender-card { display: flex; flex-direction: column; gap: 4px; align-items: center; padding: 22px 12px; border-radius: 20px;
  background: var(--surface); box-shadow: var(--shadow); text-decoration: none; color: var(--text); border: 2px solid transparent; transition: border-color .2s, transform .15s; }
.gender-card:hover, .gender-card:focus { border-color: var(--pink); transform: translateY(-2px); }
.gender-card span { color: var(--muted); font-size: .88rem; }
.gender-emoji { font-size: 2.4rem; }
.meet { text-align: center; max-width: 30rem; margin: 3vh auto 0; }
.meet-avatar { border-radius: 50%; box-shadow: 0 12px 32px rgba(32,38,58,.18); border: 5px solid var(--surface); }
.meet h1 small { font-weight: 400; color: var(--muted); }
.meet-tagline { color: var(--pink-deep); font-weight: 600; margin-top: 0; }
.meet-bio { text-align: left; }
.meet-note { background: var(--pink-pale); border-radius: 16px; padding: 4px 16px; margin: 16px 0; font-style: italic; }

/* Home */
.greeting { margin-top: 8px; }
.chatrow { display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: var(--radius); padding: 12px 14px;
  text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
.chatrow .avatar { border-radius: 50%; flex: none; }
.chatrow-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.preview { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .92rem; }
.chatrow-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: .75rem; color: var(--muted); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 4px rgba(22,135,248,.18); }
.story-card { display: flex; gap: 14px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin: 16px 0; }
.story-card-body { flex: 1; min-width: 0; } .story-card h2 { margin: 0 0 4px; } .story-card p { margin: 0 0 8px; }
.progress { height: 8px; background: var(--pink-pale); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--pink), var(--pink-deep)); border-radius: 99px; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.tiles a { display: flex; flex-direction: column; align-items: center; gap: 4px; background: var(--surface); border-radius: 16px; padding: 14px 4px;
  text-decoration: none; color: var(--text); font-size: .8rem; font-weight: 600; box-shadow: var(--shadow); }
.tiles span { font-size: 1.4rem; }

/* Episode covers (drawn with gradients — no image downloads needed) */
.cover { flex: none; width: 76px; height: 96px; border-radius: 14px; display: grid; place-items: center; color: #fff;
  font-weight: 800; font-size: 1.8rem; position: relative; overflow: hidden; box-shadow: inset 0 -30px 40px rgba(0,0,0,.12); }
.cover::after { content: ""; position: absolute; width: 60px; height: 60px; right: -18px; top: -18px; border-radius: 50%; background: rgba(255,255,255,.18); }
.cover-1 { background: linear-gradient(160deg, #FF8A65, #FF4F91); } .cover-2 { background: linear-gradient(160deg, #42A5F5, #1687F8); }
.cover-3 { background: linear-gradient(160deg, #FF4F91, #AB47BC); } .cover-4 { background: linear-gradient(160deg, #FFB74D, #FF7043); }
.cover-5 { background: linear-gradient(160deg, #7E57C2, #3949AB); } .cover-6 { background: linear-gradient(160deg, #26A69A, #00796B); }
.cover-7 { background: linear-gradient(160deg, #EF5350, #B71C1C); } .cover-8 { background: linear-gradient(160deg, #37474F, #1A237E); }
.cover-9 { background: linear-gradient(160deg, #90A4AE, #546E7A); } .cover-10 { background: linear-gradient(160deg, #66BB6A, #2E7D32); }
.cover-11 { background: linear-gradient(160deg, #FFCA28, #FF8F00); } .cover-12 { background: linear-gradient(160deg, #FF80AB, #E93679); }

.episodes { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.episode { display: flex; gap: 14px; background: var(--surface); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.episode h2 { margin: 0 0 4px; font-size: 1.05rem; } .episode p { margin: 0 0 8px; font-size: .92rem; }
.episode.locked { opacity: .6; } .episode.locked .cover { filter: grayscale(.7); }
.episode.current { outline: 2px solid var(--pink); }
.episode-body { flex: 1; min-width: 0; }

/* Relationship */
.rel-head { display: flex; align-items: center; gap: 14px; } .rel-head .avatar { border-radius: 50%; }
.meters { display: grid; gap: 12px; margin: 12px 0 24px; }
.meter { background: var(--surface); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.meter p { margin: 4px 0 0; }
.meter-top { display: flex; justify-content: space-between; }
.bar { height: 10px; background: var(--pink-pale); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--pink), var(--pink-deep)); transition: width .6s ease; }
.meter-trust .bar span, .meter-stability .bar span { background: linear-gradient(90deg, #42A5F5, var(--blue-deep)); }
.meter-jealousy .bar span { background: linear-gradient(90deg, #FFB74D, #F4511E); }
.memories { list-style: none; padding: 0; display: grid; gap: 8px; }
.memories li { background: var(--surface); border-left: 4px solid var(--pink); border-radius: 10px; padding: 10px 12px; font-size: .94rem; }

/* Endings */
.endings { list-style: none; padding: 0; display: grid; gap: 10px; }
.ending-card { background: var(--surface); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.ending-card p { margin: 4px 0 0; color: var(--muted); }
.ending-card .kind { font-size: .75rem; margin-left: 8px; color: var(--pink-deep); font-weight: 700; text-transform: uppercase; }
.hidden-ending { opacity: .55; }
.ending { text-align: center; max-width: 32rem; margin: 4vh auto 0; }
.ending h1 { font-size: 2.2rem; }
.ending-summary { font-size: 1.1rem; font-style: italic; }
.ending .memories { text-align: left; }
.journey { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 18px 0; }
.journey div { background: var(--surface); border-radius: 14px; padding: 10px 4px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.journey b { font-size: 1.4rem; color: var(--pink-deep); } .journey span { font-size: .75rem; color: var(--muted); }
.savecode code { display: block; font-size: 1.15rem; letter-spacing: .06em; background: var(--pink-pale); padding: 12px; border-radius: 12px; text-align: center; word-break: break-all; user-select: all; -webkit-user-select: all; }
.danger-zone { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 16px; }

/* ------------------------------------------------------------------ Chat */
.chat-body { background: var(--chat-bg); overscroll-behavior: none; }
.chat { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 760px; margin: 0 auto; background: var(--chat-bg); }
.chat-head { flex: none; display: flex; align-items: center; gap: 10px; padding: calc(8px + var(--safe-top)) 12px 8px;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep)); color: #fff; box-shadow: 0 2px 12px rgba(8,102,216,.25); z-index: 3; }
.chat-head .back { color: #fff; text-decoration: none; font-size: 2rem; line-height: 1; padding: 0 6px 4px 0; }
.chat-head .avatar { border-radius: 50%; border: 2px solid rgba(255,255,255,.7); background: #fff; }
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.who b { font-size: 1.05rem; } .status { font-size: .78rem; opacity: .85; }
.status.typing-now { font-style: italic; }
.head-btn { color: #fff; text-decoration: none; font-size: 1.2rem; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; }
.head-btn:hover { background: rgba(255,255,255,.15); }
.thread { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 12px 20px; display: flex; flex-direction: column; gap: 4px; }
.earlier { align-self: center; font-size: .85rem; padding: 6px 14px; border-radius: 99px; background: var(--surface); text-decoration: none; margin-bottom: 8px; box-shadow: var(--shadow); }

.msg { max-width: 82%; display: flex; flex-direction: column; animation: pop .22s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.msg.in { align-self: flex-start; } .msg.out { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 9px 14px; border-radius: 20px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1rem; line-height: 1.4; }
.msg.in .bubble { background: var(--in-bg); color: var(--text); border-bottom-left-radius: 6px; }
.msg.out .bubble { background: var(--out-bg); color: var(--out-text); border-bottom-right-radius: 6px; }
.msg time { font-size: .68rem; color: var(--muted); margin: 2px 8px 6px; }
.msg-other .bubble { background: var(--surface); border: 1.5px solid var(--pink-pale); }
.msg-name { font-size: .72rem; font-weight: 700; color: var(--pink-deep); margin: 4px 10px 2px; }
.msg-narration { align-self: center; max-width: 92%; text-align: center; font-style: italic; color: var(--muted); margin: 8px 0; font-size: .95rem; line-height: 1.5; }
.msg-system { align-self: center; max-width: 90%; text-align: center; font-size: .75rem; color: var(--muted); margin: 4px 0; }
.flash { background: var(--pink-pale); padding: 6px 12px; border-radius: 99px; color: var(--text); }
.ev { align-self: center; margin: 14px 0 8px; }
.ev span { font-size: .74rem; font-weight: 600; color: var(--muted); background: var(--surface); padding: 4px 12px; border-radius: 99px; box-shadow: 0 1px 4px rgba(0,0,0,.05); }
.ev-mode span { color: var(--pink-deep); background: var(--pink-pale); }
.ev-divider span { font-style: italic; }
.ev-ending span { color: #fff; background: linear-gradient(135deg, var(--pink), var(--pink-deep)); }
.ev-episode { align-self: stretch; display: flex; gap: 14px; background: var(--surface); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); margin: 18px 0 10px; }
.ev-episode h3 { margin: 0 0 4px; } .ev-episode p { margin: 0; font-size: .9rem; color: var(--muted); }
.ev-episode .eyebrow { color: var(--pink-deep); }
.ev-episode .cover { width: 64px; height: 80px; font-size: 1.5rem; }
/* in-person speech: quote-style bubbles */
.msg.speech .bubble::before { content: "“"; opacity: .6; }
.msg.speech .bubble::after { content: "”"; opacity: .6; }
.msg-media { margin: 0 0 4px; border-radius: 16px; overflow: hidden; max-width: 260px; background: var(--in-bg); }
.msg-media img { display: block; width: 100%; height: auto; }
.msg-media figcaption { display: none; padding: 30px 20px; text-align: center; color: var(--muted); font-size: .85rem; }
.msg-media.missing img { display: none; } .msg-media.missing figcaption { display: block; }
.typing .bubble { display: flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .4; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: .9; transform: translateY(-3px); } }

.dock { flex: none; background: var(--surface); border-top: 1px solid var(--line); padding: 10px 12px calc(10px + var(--safe-bottom)); box-shadow: 0 -4px 16px rgba(0,0,0,.04); }
.choices { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; }
.choices.waiting { display: none; }
.your-move { margin: 0 0 2px; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--pink-deep); display: flex; align-items: center; gap: 6px; }
.your-move span { animation: beat 2.4s infinite; display: inline-block; }
.choice { text-align: left; font: 500 .98rem/1.35 var(--font); padding: 12px 16px; border-radius: 16px; border: 1.5px solid color-mix(in srgb, var(--blue) 35%, transparent);
  background: var(--surface); color: var(--text); cursor: pointer; transition: background .15s, border-color .15s, transform .1s; -webkit-tap-highlight-color: transparent; }
.choice:hover, .choice:focus-visible { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 8%, var(--surface)); outline: none; }
.choice:active { transform: scale(.99); }
.choice.action { font-style: italic; border-style: dashed; }
.choice[disabled] { opacity: .5; }
.dock-end { text-align: center; } .dock-end p { margin: 0 0 8px; color: var(--muted); }
.next-ep { display: flex; flex-direction: column; gap: 8px; text-align: center; }
.next-ep p { margin: 0; }
.dock-wait { text-align: center; font-size: .82rem; color: var(--muted); padding: 6px 0; }
.offline-banner { position: fixed; left: 50%; transform: translateX(-50%); top: calc(64px + var(--safe-top)); background: #20263A; color: #fff; padding: 6px 14px; border-radius: 99px; font-size: .8rem; z-index: 9; }

@media (min-width: 700px) {
  h1 { font-size: 2rem; }
  .gender-grid { gap: 18px; }
  .meters { grid-template-columns: 1fr 1fr; }
  .chat { box-shadow: 0 0 40px rgba(0,0,0,.06); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Character picker (forms wrapping buttons) */
.gender-grid form { display: flex; }
button.gender-card { width: 100%; font: inherit; cursor: pointer; }
.gender-card .avatar { border-radius: 50%; margin-bottom: 6px; }

/* Simulated typing bar (iMessage style) */
.type-hint { margin: 0 0 8px; font-size: .78rem; color: var(--muted); text-align: center; }
.typebar { display: flex; align-items: center; gap: 8px; }
.type-input { flex: 1; min-width: 0; font: 400 16px var(--font); padding: 10px 16px; border-radius: 22px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text); outline: none; }
.type-input:focus { border-color: var(--blue); }
.type-send, .type-cancel { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; font-size: 1.1rem; cursor: pointer; }
.type-cancel { background: transparent; color: var(--muted); font-size: 1.6rem; }
.type-send { background: var(--line); color: #fff; transition: background .2s, transform .15s; }
.typebar.ready .type-send { background: var(--blue); transform: scale(1.06); }
.type-send:disabled { cursor: default; }
