:root {
  --bg: #16121c; --panel: #211b2a; --panel2: #2b2337; --ink: #ece6f3; --muted: #9b90ab;
  --accent: #e0466e; --accent2: #8f6bd8; --ok: #4fbf8a; --bad: #e06a4a; --line: #3a3048;
  --box: rgba(18, 14, 26, .86);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1.2em; }
button { font: inherit; color: var(--ink); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 14px; cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.icon { padding: 6px 10px; background: transparent; border: none; font-size: 20px; }
button:disabled { opacity: .5; }
input, textarea { font: inherit; color: var(--ink); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; width: 100%; }
textarea { resize: none; max-height: 120px; }
.screen { min-height: 100%; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin: 16px; }
.card.center { max-width: 360px; margin: 18vh auto; text-align: center; display: grid; gap: 12px; }
.card h1 { margin: 0; letter-spacing: .08em; }
.bar { position: sticky; top: 0; z-index: 5; background: rgba(22,18,28,.96); border-bottom: 1px solid var(--line);
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); }
.bar h2 { margin: 0; font-size: 18px; }
.list { display: grid; gap: 10px; margin: 16px; }
.save { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; }
.save .grow { flex: 1; cursor: pointer; }
.save small { color: var(--muted); }
.create { display: grid; gap: 10px; }
.create label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
select { font: inherit; color: var(--ink); background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 9px 10px; }
.small { font-size: 13px; margin: 0; }
.skill { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.skill span { flex: 1; text-transform: capitalize; }
.skill button { padding: 2px 12px; }
.skill b { min-width: 18px; text-align: center; }
h3 { margin: 6px 0 8px; font-size: 15px; color: var(--accent2); text-transform: uppercase; letter-spacing: .06em; }

/* ---------- VN stage */
#game { height: 100dvh; overflow: hidden; }
#stage { position: relative; height: 100dvh; overflow: hidden; background: #0d0a12; user-select: none; }
.bg { position: absolute; inset: 0; background-size: cover; background-position: center; transition: opacity .9s ease; }
#bg2 { opacity: 0; }
#stage::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to bottom, rgba(0,0,0,.45), transparent 18%, transparent 55%, rgba(0,0,0,.55)); }
#sprites { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
#sprites .sprite { pointer-events: auto; }
.sprite { position: absolute; bottom: 0; height: 78%; translate: -50% 0; opacity: 0; pointer-events: auto;
  transition: left .5s ease, translate .5s ease, opacity .45s ease, filter .35s ease, scale .35s ease; transform-origin: 50% 100%; }
.sprite.on { opacity: 1; }
.sprite.enter { translate: -50% 26px; }
.sprite.leave { opacity: 0; translate: -50% 14px; }
.sprite.dim { filter: brightness(.55) saturate(.7); scale: .96; }
.sprite .face { display: block; height: 100%; width: auto; max-width: 92vw; object-fit: contain; object-position: bottom;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,.5)); transform-origin: 50% 100%; animation: breathe 5.2s ease-in-out infinite; transition: opacity .38s ease; }
.sprite .face.next { position: absolute; left: 0; top: 0; opacity: 0; }
.sprite .face.next.on { opacity: 1; }
.sprite .face.going { opacity: 0; }
@keyframes breathe { 0%, 100% { scale: 1 1; } 50% { scale: 1.004 1.011; } }
.sprite.talk { animation: bob .5s ease; }
.sprite.hop { animation: hop .5s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes bob { 40% { transform: translateY(-6px); } }
@keyframes hop { 30% { transform: translateY(-20px); } 62% { transform: translateY(0); } 80% { transform: translateY(-5px); } }
#sprites.n3 .sprite { height: 70%; }
#sprites.n3 .sprite .face { max-width: 46vw; }
.sprite .ph-name { display: none; }
.sprite.ph .ph-name { display: block; position: absolute; left: 50%; top: 2%; translate: -50% 0; white-space: nowrap; z-index: 1;
  font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: rgba(13,10,18,.7); border: 1px solid rgba(255,255,255,.14);
  max-width: 30vw; white-space: normal; text-align: center; line-height: 1.25; }
#sprites:not(.n3) .sprite.ph .ph-name { max-width: 60vw; }
#stage.awaiting .sprite.on:not(.talk):not(.hop) { animation: listen 3.2s ease-in-out infinite; }
@keyframes listen { 0%, 100% { rotate: 0deg; } 50% { rotate: -.8deg; } }
#stage.awaiting .box { animation: boxglow 2.2s ease-in-out infinite; }
@keyframes boxglow { 50% { border-color: var(--accent2); box-shadow: 0 0 18px rgba(143,107,216,.25); } }

/* time-of-day light over the background */
.tint { position: absolute; inset: 0; pointer-events: none; transition: background 1.6s ease, opacity 1.6s ease; mix-blend-mode: soft-light; opacity: .9; }
.tint[data-slot="dawn"] { background: linear-gradient(to bottom, rgba(120,90,200,.45), rgba(255,160,120,.45)); }
.tint[data-slot="morning"] { background: linear-gradient(to bottom, rgba(255,240,200,.35), rgba(170,210,255,.2)); }
.tint[data-slot="afternoon"] { background: transparent; }
.tint[data-slot="evening"] { background: linear-gradient(to bottom, rgba(120,40,140,.5), rgba(255,120,60,.55)); }
.tint[data-slot="night"] { background: linear-gradient(to bottom, rgba(10,20,70,.85), rgba(40,30,90,.7)); mix-blend-mode: multiply; opacity: .75; }

/* scene title card */
.title { position: absolute; z-index: 4; left: 50%; top: 30%; translate: -50% 0; text-align: center; pointer-events: none; opacity: 0;
  text-shadow: 0 2px 12px rgba(0,0,0,.8); display: grid; gap: 4px; }
.title b { font-size: 24px; letter-spacing: .08em; text-transform: uppercase; }
.title span { font-size: 15px; color: #e4dcef; } .title small { font-size: 12px; color: var(--accent2); letter-spacing: .1em; text-transform: uppercase; }
.title.show { animation: card 3s ease forwards; }
@keyframes card { 0% { opacity: 0; translate: -50% 8px; } 18%, 72% { opacity: 1; translate: -50% 0; } 100% { opacity: 0; translate: -50% -6px; } }

/* dice */
.die { position: absolute; z-index: 6; left: 50%; top: 34%; width: 74px; height: 74px; margin-left: -37px; display: grid; place-items: center;
  font-size: 30px; font-weight: 800; color: #fff; pointer-events: none; background: linear-gradient(135deg, var(--accent2), var(--accent));
  clip-path: polygon(50% 0, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%); filter: drop-shadow(0 8px 18px rgba(0,0,0,.5)); }
.die.roll { animation: tumble .7s linear infinite; }
.die.land { animation: landed .45s cubic-bezier(.3, 1.6, .5, 1); }
.die.land.ok { background: linear-gradient(135deg, #3fae7d, #2a7d6a); } .die.land.bad { background: linear-gradient(135deg, #e06a4a, #a83a4a); }
@keyframes tumble { from { rotate: 0deg; scale: .9; } to { rotate: 360deg; scale: .9; } }
@keyframes landed { 0% { scale: 1.5; } 100% { scale: 1; } }
#stage.shake { animation: shake .5s ease; }
@keyframes shake { 15% { translate: -9px 0; } 30% { translate: 8px 3px; } 45% { translate: -6px -2px; } 60% { translate: 5px 0; } 80% { translate: -2px 0; } }
.flash { position: absolute; inset: 0; z-index: 6; pointer-events: none; background: radial-gradient(circle, rgba(255,245,210,.9), rgba(255,220,150,.35) 60%, transparent); opacity: 0; }
.flash.go { animation: flash .7s ease-out; }
@keyframes flash { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }

/* relationship feedback */
.pop { position: absolute; bottom: 62%; translate: -50% 0; font-size: 30px; pointer-events: none; animation: popup 1.8s ease-out forwards; z-index: 2; }
.pop.down { filter: grayscale(.3); }
@keyframes popup { 0% { opacity: 0; translate: -50% 10px; scale: .6; } 20% { opacity: 1; scale: 1.15; } 100% { opacity: 0; translate: -50% -70px; scale: 1; } }
.pops { position: absolute; z-index: 5; top: calc(122px + env(safe-area-inset-top)); left: 50%; translate: -50% 0; display: grid; gap: 6px; justify-items: center; pointer-events: none; }
.relmsg { background: var(--box); border: 1px solid var(--line); border-radius: 999px; padding: 4px 14px; font-size: 13.5px; animation: relmsg 3.8s ease forwards; white-space: nowrap; }
@keyframes relmsg { 0% { opacity: 0; translate: 0 -8px; } 10%, 80% { opacity: 1; translate: 0 0; } 100% { opacity: 0; } }

/* choices slide in one by one */
.choices button.choice { animation: chin .35s ease both; }
@keyframes chin { from { opacity: 0; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }

/* painting a scene image: a soft shimmer over the stage */
#stage.painting::before { content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.10) 45%, rgba(143,107,216,.12) 55%, transparent 70%);
  background-size: 250% 100%; animation: shimmer 2.4s linear infinite; }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -100% 0; } }

/* animations always play: the OS 'reduce motion' setting is ignored on purpose (owner's choice) */

.scene-img { margin: 0 0 14px; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }
.scene-img img { width: 100%; display: block; }
ul.plain { margin: 0; padding-left: 18px; } ul.plain li { margin: 4px 0; }
.bond { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px; margin-bottom: 10px; }
.bond img { width: 54px; height: 54px; border-radius: 12px; object-fit: cover; object-position: top; }
.bond .grow { flex: 1; }
.meter { height: 6px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin: 3px 0 5px; }
.meter i { display: block; height: 100%; background: var(--accent); }
.meter.trust i { background: var(--accent2); } .meter.attr i { background: #f39a3d; }
.bond small { color: var(--muted); }
table.dice { width: 100%; border-collapse: collapse; font-size: 14px; }
table.dice td, table.dice th { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: left; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.gallery figure { margin: 0; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--panel); }
.gallery img { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; }
.gallery figcaption { font-size: 11px; color: var(--muted); padding: 3px 6px; }
.toast { position: absolute; z-index: 6; top: calc(56px + env(safe-area-inset-top)); right: 12px; background: var(--accent2);
  border-color: var(--accent2); border-radius: 999px; padding: 6px 14px; font-size: 14px; animation: drop .35s ease; }
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.94); display: flex; align-items: center; justify-content: center; z-index: 20; }
.viewer img { max-width: 100%; max-height: 100%; }

/* =================================================================== login + stories (home) screen */
.login { padding: 30px 24px; }
.logo { width: 54px; height: 54px; margin: 0 auto 4px; border-radius: 16px; display: grid; place-items: center; font-size: 26px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); box-shadow: 0 10px 30px rgba(224,70,110,.3); }
.logo.sm { width: 30px; height: 30px; border-radius: 9px; font-size: 15px; margin: 0; box-shadow: none; }
.home { min-height: 100%; background: radial-gradient(1100px 500px at 85% -10%, rgba(143,107,216,.12), transparent 60%), var(--bg); }
.homebar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  background: rgba(22,18,28,.9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { flex: 1; display: flex; align-items: center; gap: 10px; font-size: 17px; }
.hbtn { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; padding: 7px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 14px; }
.hbtn:hover { border-color: var(--accent2); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 18px 20px 70px; }
.hsec { margin: 26px 0; }
.hsec > h2, .tools summary h2 { margin: 0; font-size: 20px; }
.lead { color: var(--muted); margin: 4px 0 14px; font-size: 14px; }
.home button:hover:not(:disabled) { border-color: var(--accent2); }
.home button.big { padding: 13px 18px; font-size: 16px; }
.home .chip { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: #d9cfe6; margin: 0 4px 4px 0; }

/* GM control strip */
.gm { display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; }
.gm-status { flex: 1; min-width: 220px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; }
.gm-status .sep { color: var(--line); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); } .dot.bad { background: var(--bad); }
.bad-t { color: var(--bad); }
.spin.sm { width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); display: inline-block; animation: hspin .9s linear infinite; }
@keyframes hspin { to { transform: rotate(360deg); } }
.gm-links { display: flex; gap: 6px; flex-wrap: wrap; }
.gm-links a { color: var(--ink); text-decoration: none; font-size: 13px; padding: 6px 11px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; }
.gm-links a:hover { border-color: var(--accent2); }

/* continue: save cards */
.saves { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin-top: 12px; }
.scard { display: grid; grid-template-columns: 112px 1fr; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.scover { border: none; border-radius: 0; padding: 0; background: linear-gradient(160deg, #3a2d52, #1c1625) center / cover; position: relative; min-height: 104px; }
.scover .play { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; color: #fff; background: rgba(0,0,0,.28); opacity: .85; }
.scover:hover .play { background: rgba(224,70,110,.35); }
.sbody { padding: 10px 12px; display: grid; gap: 4px; align-content: center; min-width: 0; }
.sname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sname-in { padding: 6px 8px; font-weight: 600; }
.sacts { display: flex; gap: 6px; margin-top: 4px; }
.sacts button { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.sacts button.primary { flex: 1; }
.danger { color: var(--bad); }

/* new game: campaign cards + character maker */
.camps { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.ccamp { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; display: grid; transition: border-color .15s, box-shadow .15s; }
.ccamp.on { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224,70,110,.18); }
.ccover { border: none; border-radius: 0; padding: 0; aspect-ratio: 16 / 7; background: linear-gradient(160deg, #3a2d52, #1c1625) center / cover; position: relative; text-align: left; }
.ccover span { position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 14px 10px; font-weight: 700; font-size: 17px; color: #fff;
  background: linear-gradient(to top, rgba(10,8,14,.88), transparent); text-shadow: 0 1px 4px #000; }
.cmeta { padding: 10px 14px 14px; display: grid; gap: 8px; }
.cacts { display: flex; gap: 6px; flex-wrap: wrap; }
.cacts button { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.maker { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr); gap: 22px; margin-top: 18px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; padding: 20px; }
.mk-intro h3 { color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 18px; margin-bottom: 8px; }
.mk-intro p { font-size: 14px; line-height: 1.6; }
.cast { margin-top: 10px; }
.mk-form { display: grid; gap: 12px; }
.mk-form label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.mk-form label small { font-size: 12px; }
.mk-form textarea { max-height: none; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.skills { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; }
.skills .skill { gap: 10px; }
.skills .skill button { width: 34px; height: 30px; padding: 0; border-radius: 8px; background: var(--bg); }
.skills .skill b { min-width: 22px; font-size: 15px; }
.skills > .muted { margin-bottom: 2px; }
.tools summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 12px; padding: 4px 0; }
.tools summary::-webkit-details-marker { display: none; }
.tools summary::after { content: "▾"; color: var(--muted); margin-left: auto; transition: transform .15s; }
.tools[open] summary::after { transform: rotate(180deg); }
.toolgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.toolgrid .card { margin: 12px 0 0; }
.hmsg { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  z-index: 40; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 18px; max-width: 92vw; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45); transition: opacity .2s, transform .2s; }
.hmsg.on { opacity: 1; transform: translate(-50%, 0); }
.hmsg.bad { border-color: var(--bad); color: #ffb39e; }
@media (max-width: 760px) {
  .wrap { padding: 12px 14px 60px; }
  .maker { grid-template-columns: 1fr; padding: 16px; gap: 14px; }
  .two { grid-template-columns: 1fr; }
  .saves, .camps { grid-template-columns: 1fr; }
  .hbtn span { display: none; }
  .gm-links { overflow-x: auto; flex-wrap: nowrap; width: 100%; scrollbar-width: none; }
}
.mk-cover { aspect-ratio: 16 / 9; border-radius: 12px; margin-bottom: 14px; background: linear-gradient(160deg, #3a2d52, #1c1625) center / cover;
  border: 1px solid var(--line); }
.gm { min-width: 0; } .gm-links { min-width: 0; }
@media (max-width: 760px) { .gm-links { flex: 1 1 100%; } .home { overflow-x: hidden; } }


/* ✦ Use AI on the Stories screen (Forge brief) */
.aisug { color: #d9c8ff; border: 1px solid rgba(143,107,216,.55); background: linear-gradient(135deg, rgba(143,107,216,.22), rgba(224,70,110,.14)); }
.aisug.mini { padding: 0 8px; font-size: 12px; border-radius: 8px; margin-left: 6px; vertical-align: middle; }
.fgai { display: flex; gap: 6px; margin: 6px 0; } .fgai input { flex: 1; min-width: 0; }

/* ■ Stop for running art batches */
.stopbtn { margin-left: 6px; padding: 1px 9px; font-size: 12px; border-radius: 8px; color: #f3a58f; border: 1px solid rgba(224,106,74,.6); background: rgba(224,106,74,.12); }

/* ---- combat effects (fx.js) */
.fxc { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none; }
.fxframe { position: absolute; inset: 0; z-index: 4; pointer-events: none; opacity: 0; mix-blend-mode: screen; }
.fxframe.go { animation: fxframe 90ms ease-out; }
@keyframes fxframe { 0% { opacity: 1; } 100% { opacity: 0; } }
.fximg { position: absolute; z-index: 4; left: 50%; top: 42%; translate: -50% -50%; max-width: 90%; max-height: 80%; pointer-events: none;
  animation: fximg .7s ease-out forwards; }
@keyframes fximg { 0% { opacity: 0; scale: .7; } 12% { opacity: 1; scale: 1.05; } 70% { opacity: 1; } 100% { opacity: 0; scale: 1.1; } }
#stage.jolt { animation: jolt .18s ease; }
@keyframes jolt { 30% { translate: 6px -3px; } 70% { translate: -4px 2px; } }
#stage.shake-hard { animation: shakehard .7s ease; }
@keyframes shakehard { 10% { translate: -16px 6px; } 25% { translate: 14px -8px; } 40% { translate: -11px 4px; } 55% { translate: 9px 2px; } 70% { translate: -5px -2px; } 85% { translate: 3px 0; } }
#stage.invert #bg, #stage.invert #bg2, #stage.invert #sprites { filter: invert(1) contrast(1.4) grayscale(.6); }
#stage.bleed::before { content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(140,0,12,.6)); animation: bleed .9s ease-out forwards; }
@keyframes bleed { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }
#stage.rush #bg, #stage.rush #bg2 { animation: rush .38s ease; }
@keyframes rush { 40% { scale: 1.06; filter: blur(2px); } }

/* rewind / reroll and the "previously" card */
.prevcard { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 18px; background: rgba(8,6,12,.72);
  animation: fadein .35s ease; }
.previn { max-width: 560px; width: 100%; background: var(--box); border: 1px solid var(--line); border-radius: 18px; padding: 18px 18px 14px;
  display: grid; gap: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.previn small { color: var(--accent2); text-transform: uppercase; letter-spacing: .12em; font-size: 12px; }
.previn #prevText { font-style: italic; color: #e4dcef; line-height: 1.55; max-height: 50dvh; overflow-y: auto; }
.previn .hint { color: var(--muted); font-size: 12px; text-align: right; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* =================================================================== VN interface v2
   One structure, three layouts: phone portrait (default), phone landscape, desktop (wide screens).
   Dock = dialogue box + your input + quick menu. Choices float over the scene above it. */
:root { --text-font: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", sans-serif; }
#stage { --dock: 250px; }
.bg { transition: opacity .9s ease, filter .4s ease; }
#sprites { transition: filter .4s ease; }
#stage.choosing .bg, #stage.choosing #sprites { filter: brightness(.6) saturate(.85); }
#stage::after { transition: opacity .25s; }

/* ---- top bar */
.hud { position: absolute; top: 0; left: 0; right: 0; z-index: 6; display: flex; align-items: flex-start; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 0 calc(10px + env(safe-area-inset-left));
  pointer-events: none; transition: opacity .25s; }
.hud > * { pointer-events: auto; }
.hbtn2 { display: flex; align-items: center; justify-content: center; gap: 6px; height: 40px; min-width: 40px; padding: 0 12px;
  border-radius: 12px; background: rgba(14,11,20,.55); border: 1px solid rgba(255,255,255,.09); font-size: 18px; line-height: 1;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.hbtn2 span { font-size: 13px; }
.hbtn2:hover { background: rgba(40,30,56,.8); }
.where { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; padding-top: 3px; text-shadow: 0 1px 6px #000; pointer-events: none; }
.where b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.where span { font-size: 12px; color: #d8cfe6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.banner { position: absolute; z-index: 6; top: calc(58px + env(safe-area-inset-top)); left: 50%; translate: -50% 0; width: min(520px, calc(100% - 24px));
  background: rgba(16,12,24,.9); border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 12px;
  padding: 8px 12px; font-size: 14px; animation: drop .35s ease; backdrop-filter: blur(8px); }
.banner.ok { border-left-color: var(--ok); } .banner.bad { border-left-color: var(--bad); }
.banner.chance, .bl-roll.chance { border-left-color: #e8c35a; }
.banner .why { display: block; color: var(--muted); font-size: 12px; }
@keyframes drop { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

/* ---- dock */
.dock { position: absolute; z-index: 5; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; transition: opacity .25s; }
.box { --who: transparent; position: relative; display: flex; flex-direction: column; cursor: pointer; height: 172px; padding: 18px 18px 12px;
  background: linear-gradient(to bottom, rgba(18,14,27,.80), rgba(11,9,17,.94)); border-top: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(10px) saturate(1.1); -webkit-backdrop-filter: blur(10px) saturate(1.1); }
.box::before { content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 2px; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--who) 25%, var(--who) 75%, transparent); }
#stage.awaiting .box { animation: boxglow 2.2s ease-in-out infinite; }
@keyframes boxglow { 50% { box-shadow: inset 0 0 0 1px rgba(143,107,216,.55), 0 0 22px rgba(143,107,216,.22); } }
.nameplate { position: absolute; bottom: 100%; left: 14px; padding: 6px 16px 4px; font-weight: 700; font-size: 15px; letter-spacing: .03em;
  color: #fff; background: rgba(18,14,27,.88); border: 1px solid rgba(255,255,255,.08); border-bottom: none; border-radius: 12px 12px 0 0;
  box-shadow: inset 0 3px 0 var(--who); text-shadow: 0 1px 3px #000; max-width: 70%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line { flex: 1; min-height: 0; overflow-y: auto; white-space: pre-wrap; font-family: var(--text-font); font-size: 17px; line-height: 1.6;
  color: #f4effa; text-shadow: 0 1px 2px rgba(0,0,0,.65); scrollbar-width: none; overscroll-behavior: contain; }
.line::-webkit-scrollbar { display: none; }
.line.narr { color: #dcd3e8; }
.line.you { color: #e6d8ff; font-style: italic; }
.line em { color: #b7abc9; font-style: italic; }
.line q { quotes: "\201C" "\201D"; color: #fff; }
.line b { color: #fff; }
.ctc { display: inline-block; width: 0; height: 0; margin-left: 9px; vertical-align: middle; border: 6px solid transparent;
  border-top: 8px solid var(--accent); border-bottom: 0; animation: ctc 1s ease-in-out infinite; }
@keyframes ctc { 50% { translate: 0 4px; opacity: .5; } }
.wait { position: absolute; right: 18px; bottom: 12px; }
.wait span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent2); margin-left: 3px; animation: b 1.2s infinite ease-in-out; }
.wait span:nth-child(2) { animation-delay: .2s; } .wait span:nth-child(3) { animation-delay: .4s; }
@keyframes b { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.inputrow { display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px 6px; background: rgba(11,9,17,.96); }
#imgBtn { width: 44px; height: 44px; font-size: 20px; display: grid; place-items: center; flex: none; }
#act { min-height: 44px; font-size: 16px; line-height: 1.4; padding: 11px 14px; border-radius: 14px; scrollbar-width: none; overflow-y: auto;
  background: rgba(43,35,55,.9); }  /* 16px stops iOS zooming into the field */
#act::-webkit-scrollbar { display: none; }
#act:focus { outline: none; border-color: var(--accent2); }
.send { min-width: 48px; min-height: 44px; padding: 10px 14px; flex: none; }

.quick { display: flex; padding: 2px 4px calc(2px + env(safe-area-inset-bottom)); background: rgba(11,9,17,.97); border-top: 1px solid rgba(255,255,255,.05); }
.quick button { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 50px; padding: 4px 0; background: transparent; border: none; border-radius: 10px; color: #d6cde3; }
.quick button i { font-style: normal; font-size: 17px; line-height: 1; font-weight: 600; }
.quick button span { font-size: 10px; letter-spacing: .05em; color: var(--muted); text-transform: uppercase; }
.quick button.on { color: #fff; background: rgba(143,107,216,.3); } .quick button.on span { color: #e6dcf6; }
.quick button.off i { text-decoration: line-through; opacity: .6; }
.quick button:disabled { opacity: .28; }
.quick button:not(:disabled):active { background: rgba(255,255,255,.08); }

/* ---- choices */
.choiceLayer { position: absolute; z-index: 5; left: 0; right: 0; top: calc(58px + env(safe-area-inset-top)); bottom: calc(var(--dock) + 26px);
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center; padding: 0 12px; pointer-events: none; transition: opacity .25s; }
.choices { pointer-events: auto; display: grid; gap: 9px; width: min(660px, 100%); max-height: 100%; overflow-y: auto; overflow-x: hidden; padding: 4px; scrollbar-width: none; }
.choices button.choice { display: flex; align-items: center; gap: 12px; text-align: left; min-height: 50px; padding: 11px 16px; border-radius: 14px;
  font-size: 15.5px; line-height: 1.35; background: rgba(20,15,30,.84); border: 1px solid rgba(255,255,255,.13); color: #f2ecf8;
  box-shadow: 0 6px 20px rgba(0,0,0,.35); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: background .15s, border-color .15s, translate .15s; animation: chin .35s ease both; }
.choices button.choice kbd { display: none; flex: none; width: 24px; height: 24px; place-items: center; border-radius: 7px; font: 600 12px var(--text-font);
  color: #cdb8ff; background: rgba(143,107,216,.16); border: 1px solid rgba(143,107,216,.45); }
.choices button.choice:hover, .choices button.choice:focus-visible { background: rgba(224,70,110,.26); border-color: var(--accent); outline: none; }
.choices button.choice:active { background: var(--accent); }
@keyframes chin { from { opacity: 0; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }

/* ---- hide the interface to look at the scene (tap anywhere to bring it back) */
#stage.noui .hud, #stage.noui .dock, #stage.noui .choiceLayer, #stage.noui .banner, #stage.noui .toast, #stage.noui::after { opacity: 0; pointer-events: none; }
#stage.noui .choiceLayer * { pointer-events: none; }
#stage.noui.choosing .bg, #stage.noui.choosing #sprites { filter: none; }

/* ---- backlog */
.backlog { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; background: rgba(9,7,14,.92);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); animation: fadein .2s ease; }
.blhead { display: flex; align-items: center; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; border-bottom: 1px solid rgba(255,255,255,.07); }
.blhead b { font-size: 14px; letter-spacing: .16em; text-transform: uppercase; color: #bfa8f0; }
.blhead .grow { flex: 1; color: var(--muted); }
.bllist { flex: 1; overflow-y: auto; padding: 18px 16px 28px; overscroll-behavior: contain; }
.bl-e { display: grid; gap: 2px; max-width: 760px; margin: 0 auto 15px; font-family: var(--text-font); line-height: 1.65; }
.bl-who { font-weight: 700; font-size: 13.5px; color: var(--who); letter-spacing: .02em; }
.bl-e.narr .bl-who { display: none; }
.bl-t { white-space: pre-wrap; font-size: 16.5px; color: #eee8f5; }
.bl-e.narr .bl-t { color: #c9c0d6; }
.bl-e.you .bl-t { color: #e6d8ff; font-style: italic; padding: 7px 12px; background: rgba(143,107,216,.12); border-left: 3px solid var(--accent2); border-radius: 4px 10px 10px 4px; }
.bl-t em { color: #ada2bf; } .bl-t q { quotes: "\201C" "\201D"; color: #fff; } .bl-t b { color: #fff; }
.bl-scene { display: flex; align-items: center; gap: 12px; max-width: 760px; margin: 28px auto 18px; color: var(--muted); font-size: 11.5px;
  letter-spacing: .14em; text-transform: uppercase; white-space: nowrap; }
.bl-scene::before, .bl-scene::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, transparent, rgba(255,255,255,.2), transparent); }
.bl-scene b { color: #e4dcef; font-weight: 600; letter-spacing: .08em; overflow: hidden; text-overflow: ellipsis; }
.bl-roll { max-width: 760px; margin: 0 auto 15px; font-size: 13px; color: #cfc6dc; padding: 6px 12px; border-radius: 10px;
  background: rgba(255,255,255,.05); border-left: 3px solid var(--muted); }
.bl-roll.ok { border-left-color: var(--ok); } .bl-roll.bad { border-left-color: var(--bad); }
.bl-img { max-width: 420px; margin: 0 auto 18px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); cursor: zoom-in; }
.bl-img img { width: 100%; display: block; }
.bl-empty { text-align: center; color: var(--muted); margin-top: 20vh; }
.blfoot { display: flex; justify-content: center; padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(255,255,255,.07); }
.blfoot button { border-radius: 999px; padding: 10px 24px; background: rgba(43,35,55,.9); }

/* ---- journal panel */
.panel { position: absolute; inset: 0; z-index: 15; display: flex; flex-direction: column; background: rgba(14,11,20,.98);
  padding-top: env(safe-area-inset-top); animation: up .25s ease; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.tabs { display: flex; gap: 2px; padding: 4px 6px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button { flex: 1 0 auto; background: transparent; border: none; color: var(--muted); padding: 12px; font-size: 14px; border-radius: 0; }
.tabs button.on { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.tabs #closePanel { flex: none; position: sticky; right: 0; width: 44px; font-size: 18px; background: rgba(14,11,20,.98); }
.tab { flex: 1; overflow-y: auto; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); font-size: 15.5px; line-height: 1.6; }

/* =================================================================== phone, landscape: box and quick menu side by side */
@media (orientation: landscape) and (max-height: 520px) {
  .dock { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .box { grid-column: 1; grid-row: 1; height: 112px; padding: 13px 18px 8px calc(18px + env(safe-area-inset-left)); }
  .line { font-size: 15.5px; line-height: 1.52; }
  .nameplate { font-size: 14px; padding: 4px 14px 3px; }
  .quick { grid-column: 2; grid-row: 1; display: grid; grid-template-columns: repeat(4, 46px); align-content: center; gap: 2px;
    padding: 4px calc(6px + env(safe-area-inset-right)) 4px 6px; border-top: 1px solid rgba(255,255,255,.08); }
  .quick button { min-height: 50px; }
  .inputrow { grid-column: 1 / -1; grid-row: 2; padding: 6px calc(10px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left)); }
  .choiceLayer { bottom: calc(var(--dock) + 14px); top: calc(50px + env(safe-area-inset-top)); }
  .choices { grid-template-columns: 1fr 1fr; width: min(940px, 100%); gap: 7px; }
  .choices button.choice { min-height: 42px; font-size: 14px; padding: 8px 12px; }
  #stage.choosing .box { height: 70px; padding-top: 10px; padding-bottom: 6px; }  /* room for the choices: the last line stays, smaller */
  #stage.choosing .line { font-size: 14px; line-height: 1.45; }
  #stage.choosing .quick { grid-template-columns: repeat(4, 40px); } #stage.choosing .quick button { min-height: 32px; } #stage.choosing .quick button span { display: none; }
  .sprite { height: 94%; } #sprites.n3 .sprite { height: 86%; } #sprites.n3 .sprite .face { max-width: 24vw; }
  .hbtn2 span { display: none; }
  .hbtn2 { height: 36px; min-width: 36px; }
}

/* =================================================================== desktop: a centred VN text box, choices mid-screen, journal drawer */
@media (min-width: 900px) and (min-height: 560px) {
  #stage { --dock: 270px; }
  .hud { padding: 16px 20px 0; }
  .where b { font-size: 17px; } .where span { font-size: 13px; }
  .hbtn2 { height: 42px; padding: 0 16px; }
  .dock { left: 50%; right: auto; translate: -50% 0; width: min(1120px, calc(100vw - 56px)); bottom: 14px; }
  .box { height: 206px; padding: 30px 48px 20px; border: 1px solid rgba(255,255,255,.09); border-radius: 18px;
    background: linear-gradient(to bottom, rgba(18,14,27,.78), rgba(11,9,17,.9)); box-shadow: 0 18px 50px rgba(0,0,0,.45); }
  .box::before { left: 24px; right: 24px; top: 0; }
  .nameplate { left: 32px; bottom: calc(100% - 1px); font-size: 17px; padding: 7px 22px 5px; }
  .line { font-size: 20px; line-height: 1.72; }
  .ctc { border-width: 7px; border-top-width: 9px; }
  .inputrow { margin-top: 10px; padding: 0; background: none; }
  #act { background: rgba(18,14,27,.88); border-color: rgba(255,255,255,.12); backdrop-filter: blur(10px); }
  .quick { justify-content: flex-end; gap: 2px; padding: 6px 6px 0; background: none; border: none; }
  .quick button { flex: none; flex-direction: row; gap: 6px; min-height: 0; padding: 5px 11px; border-radius: 8px; color: #c3b9d2; text-shadow: 0 1px 3px #000; }
  .quick button i { font-size: 13px; }
  .quick button span { font-size: 11.5px; letter-spacing: .14em; color: inherit; }
  .quick button:not(:disabled):hover { color: #fff; background: rgba(255,255,255,.07); }
  .choiceLayer { bottom: calc(var(--dock) + 30px); justify-content: center; }
  .choices { gap: 11px; }
  .choices button.choice { font-size: 17px; padding: 14px 20px; min-height: 56px; }
  .choices button.choice kbd { display: grid; }
  .choices button.choice:hover { translate: 4px 0; }
  .sprite { height: 90%; }
  .panel { left: auto; width: 460px; border-left: 1px solid var(--line); box-shadow: -24px 0 60px rgba(0,0,0,.5); animation: slidein .25s ease; }
  @keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
  .blhead { padding: 16px 28px 14px; }
  .bllist { padding: 26px 28px 40px; scrollbar-width: thin; }
  .bl-e { grid-template-columns: 170px minmax(0, 1fr); column-gap: 24px; max-width: 980px; margin-bottom: 16px; }
  .bl-who { text-align: right; font-size: 14.5px; padding-top: 3px; }
  .bl-e.narr .bl-who { display: block; }
  .bl-t { font-size: 18px; max-width: 72ch; }
  .bl-scene, .bl-roll { max-width: 980px; }
  .bl-roll { margin-left: max(0px, calc((100% - 980px) / 2 + 194px)); }
}

.fglink { display: inline-block; text-align: center; text-decoration: none; color: #fff; background: var(--accent); border-radius: 12px; padding: 11px 16px; font-weight: 600; }
