:root {
  --bg: #0e0a0b; --bg2: #161012; --panel: #1b1416; --panel2: #241a1d; --line: #33262a;
  --text: #f2e9e4; --muted: #a8968f; --dim: #74645e;
  --ember: #ff7a45; --rose: #e0386b; --grad: linear-gradient(135deg, #ff9a3d 0%, #ff6a45 45%, #e0386b 100%);
  --ok: #5ccf96; --bad: #ff6b6b; --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; background: radial-gradient(1200px 600px at 80% -10%, rgba(224,56,107,.12), transparent 60%),
       radial-gradient(900px 500px at -10% 110%, rgba(255,122,69,.08), transparent 60%), var(--bg); background-attachment: fixed; }
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
::selection { background: rgba(255,122,69,.35); }

/* ---- chrome ---- */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 12px 22px;
  background: rgba(14,10,11,.78); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid rgba(51,38,42,.7); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .3px; text-decoration: none; font-size: 17px; }
.brand svg { width: 22px; height: 22px; }
.top nav { display: flex; gap: 4px; margin-left: 10px; }
.top nav a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 9px; }
.top nav a.on, .top nav a:hover { color: var(--text); background: var(--panel2); }
.top .grow { flex: 1; min-width: 0; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 32px 22px 80px; }
h1 { font-size: 28px; margin: 0 0 6px; letter-spacing: -.3px; }
.sub { color: var(--muted); margin: 0 0 26px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--panel2);
  border-radius: 11px; padding: 9px 16px; cursor: pointer; text-decoration: none; white-space: nowrap; transition: border-color .15s, transform .1s; }
.btn:hover { border-color: var(--dim); }
.btn:active { transform: scale(.98); }
.btn.fire { background: var(--grad); border: 0; color: #fff; font-weight: 650; box-shadow: 0 6px 24px rgba(224,56,107,.28); }
.btn.fire:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 9px; }
.btn.icon { padding: 7px; width: 36px; height: 36px; }
.btn.on { border-color: var(--ember); color: var(--ember); }
.btn:disabled { opacity: .45; cursor: default; }
.btn svg { width: 18px; height: 18px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
label.f { display: flex; flex-direction: column; gap: 7px; font-size: 12px; font-weight: 650; color: var(--muted); letter-spacing: .5px; text-transform: uppercase; }
label.f > span.h { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--dim); font-size: 12px; }
input[type=text], input[type=email], input[type=number], textarea, select {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 11px; padding: 11px 13px; outline: none;
  text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 15px; }
input:focus, textarea:focus, select:focus { border-color: var(--ember); }
textarea { resize: vertical; min-height: 110px; line-height: 1.55; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hint { color: var(--dim); font-size: 13px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg button { border: 0; background: none; cursor: pointer; padding: 7px 13px; border-radius: 9px; color: var(--muted); }
.seg button.on { background: var(--panel2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.04) inset; }

.toast { position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 50;
  background: var(--panel2); border: 1px solid var(--line); padding: 11px 18px; border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.5);
  transition: all .25s; max-width: min(560px, 90vw); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: var(--bad); color: #ffb3b3; }

.modal { position: fixed; inset: 0; z-index: 40; background: rgba(5,3,4,.7); display: flex; align-items: center; justify-content: center; padding: 20px; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; width: min(560px, 100%); max-height: 92vh; overflow: auto; padding: 24px; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.sheet.wide { width: min(1000px, 100%); }
.sheet h2 { margin: 0 0 16px; font-size: 19px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.x { border: 0; background: none; color: var(--muted); font-size: 24px; cursor: pointer; line-height: 1; }

/* ---- auth ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: min(420px, 100%); padding: 32px; }
.auth .logo { width: 46px; height: 46px; margin-bottom: 14px; }
.auth h1 { font-size: 26px; }

/* ---- library ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.story-card { position: relative; border-radius: 16px; overflow: hidden; background: var(--panel); border: 1px solid var(--line); text-decoration: none; display: flex; flex-direction: column; transition: transform .15s, border-color .15s; }
.story-card:hover { transform: translateY(-2px); border-color: #4a363c; }
.story-card .cover { aspect-ratio: 16/9; background: var(--grad); opacity: .9; position: relative; overflow: hidden; }
.story-card .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.story-card .cover .ph { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--serif); font-size: 44px; color: rgba(255,255,255,.85); }
.story-card .meta { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; }
.story-card .t { font-family: var(--serif); font-size: 19px; font-weight: 600; }
.story-card .p { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.faces { display: flex; }
.faces img, .faces span { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; border: 2px solid var(--panel); margin-left: -6px; background: var(--panel2); }
.faces > :first-child { margin-left: 0; }
.prog { height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; }
.prog i { display: block; height: 100%; background: var(--grad); }
.empty { border: 1px dashed var(--line); border-radius: 16px; padding: 48px 24px; text-align: center; color: var(--muted); }

/* ---- character picker / tiles ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: flex; align-items: center; gap: 8px; padding: 4px 13px 4px 4px; border-radius: 99px; border: 1px solid var(--line); background: var(--bg2); cursor: pointer; user-select: none; }
.chip img, .chip .dot { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--line); }
.chip.on { border-color: var(--ember); background: rgba(255,122,69,.12); }
.chip.dim { opacity: .5; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.tile { position: relative; aspect-ratio: 3/4; border-radius: 14px; overflow: hidden; background: var(--panel2); border: 1px solid var(--line); cursor: pointer; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .cap { position: absolute; inset: auto 0 0 0; padding: 26px 12px 10px; background: linear-gradient(transparent, rgba(0,0,0,.8)); font-size: 13px; }
.tile .cap b { display: block; font-size: 15px; }
.tile .tag { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.65); font-size: 11px; padding: 2px 8px; border-radius: 7px; }
.tile.sel { outline: 2px solid var(--ember); outline-offset: -2px; }
.tile .act { position: absolute; inset: auto 8px 8px 8px; }
.tile .act .btn { width: 100%; background: rgba(0,0,0,.7); border-color: transparent; }
.shimmer { background: linear-gradient(110deg, var(--panel2) 30%, #3a2a2f 50%, var(--panel2) 70%); background-size: 200% 100%; animation: sh 1.6s linear infinite; }
@keyframes sh { to { background-position: -200% 0; } }

/* ---- reader ---- */
.reader-top .title { font-family: var(--serif); font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.presence { display: flex; align-items: center; }
.presence .av { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff;
  border: 2px solid var(--bg); margin-left: -8px; position: relative; }
.presence .av:first-child { margin-left: 0; }
.presence .av::after { content: ""; position: absolute; right: -1px; bottom: -1px; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); border: 2px solid var(--bg); }
.presence .label { margin-left: 10px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.story { max-width: 1240px; margin: 0 auto; padding: 26px 26px 140px; }
.story-head { text-align: center; padding: 40px 0 30px; }
.story-head h1 { font-family: var(--serif); font-size: clamp(30px, 4vw, 46px); font-weight: 600; margin-bottom: 10px; }
.story-head .by { color: var(--muted); }
.sec { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 44px; padding: 34px 0; border-top: 1px solid rgba(51,38,42,.55); }
.sec:first-of-type { border-top: 0; }
.sec .text { font-family: var(--serif); font-size: 20px; line-height: 1.78; color: #efe4de; }
.sec .text p { margin: 0 0 1.05em; opacity: 0; transform: translateY(6px); animation: rise .9s ease forwards; }
.sec .num { font-family: var(--sans); font-size: 12px; letter-spacing: 2px; color: var(--dim); margin-bottom: 14px; text-transform: uppercase; }
@keyframes rise { to { opacity: 1; transform: none; } }
.sec .visual { position: sticky; top: 84px; align-self: start; }
.frame { position: relative; aspect-ratio: 16/9; border-radius: 16px; overflow: hidden; background: var(--panel2); box-shadow: 0 20px 60px rgba(0,0,0,.45); }
.frame .glow { position: absolute; inset: 0; background: radial-gradient(60% 80% at 50% 60%, rgba(255,122,69,.18), transparent 70%), var(--panel2); }
.frame .glow::after { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 35%, rgba(255,255,255,.04) 50%, transparent 65%); background-size: 200% 100%; animation: sh 2.4s linear infinite; }
.frame .state { position: absolute; inset: auto 0 0 0; padding: 12px 14px; font-size: 12px; color: var(--muted); z-index: 2; }
.frame.shown .state:not(:empty) { background: linear-gradient(transparent, rgba(0,0,0,.75)); color: #e8dcd6; }
.frame img, .frame video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; filter: blur(24px) saturate(.6); transform: scale(1.04);
  transition: opacity 4.5s ease, filter 6s ease, transform 8s ease; }
.frame.shown img, .frame.shown video { opacity: 1; filter: none; transform: none; }
.frame .unmute { position: absolute; right: 10px; bottom: 10px; z-index: 2; }
.tools { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; opacity: .0; transition: opacity .2s; }
.sec:hover .tools, .tools:focus-within, .touch .tools { opacity: 1; }
.err { color: #ffb3b3; font-size: 13px; }
.next { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 46px 0 10px; }
.btn.continue { font-size: 19px; padding: 17px 44px; border-radius: 99px; }
.pulse { color: var(--muted); display: flex; align-items: center; gap: 10px; }
.pulse i { width: 9px; height: 9px; border-radius: 50%; background: var(--ember); animation: pl 1.4s ease-in-out infinite; }
@keyframes pl { 50% { opacity: .25; transform: scale(.7); } }
.the-end { text-align: center; font-family: var(--serif); font-size: 24px; color: var(--muted); padding: 50px 0; }
.composer { width: min(760px, 100%); }
.composer textarea { font-family: var(--serif); font-size: 18px; min-height: 180px; }
.revealed-by { text-align: center; color: var(--dim); font-size: 12px; padding-top: 8px; }

.sec.textonly { grid-template-columns: minmax(0, 720px); justify-content: center; }
.sec.textonly .visual { display: none; }
.autoline { display: block; height: 1px; }
details.composer summary { list-style: none; }
details.composer summary::-webkit-details-marker { display: none; }

@media (max-width: 860px), (orientation: portrait) and (max-width: 1100px) {
  .detgrid { grid-template-columns: 1fr !important; }
  .sec { grid-template-columns: 1fr; gap: 18px; }
  .sec .visual { position: static; }
  .sec .text { font-size: 18.5px; }
  .story { padding: 10px 18px 120px; }
  .top { padding: 10px 14px; gap: 8px; }
  .top nav { margin-left: 2px; gap: 0; }
  .top nav a { padding: 6px 8px; font-size: 14px; }
  .brand .bt, .top .btn .bt { display: none; }
  .presence .label { display: none; }
  .two { grid-template-columns: 1fr; }
  .wrap { padding: 22px 16px 70px; }
  .tools { opacity: 1; }
}
.chap { text-align: center; padding: 70px 0 6px; border-top: 1px solid rgba(51,38,42,.55); }
.chap:first-child { border-top: 0; padding-top: 10px; }
.chap-n { font-size: 12px; letter-spacing: 3px; text-transform: uppercase; color: var(--ember); }
.chap-t { font-family: var(--serif); font-size: clamp(26px, 3.2vw, 38px); margin-top: 8px; }
.chap-t:empty { display: none; }
.sec.first-in-chap { border-top: 0; }
.edit-area { font-family: var(--serif); font-size: 18px; line-height: 1.7; min-height: 220px; }
.chap .chap-edit { margin-top: 10px; opacity: 0; transition: opacity .2s; }
.chap:hover .chap-edit, .touch .chap .chap-edit { opacity: 1; }
.polish-opts { font-family: var(--sans); font-size: 14px; color: var(--muted); }
.polish-opts .seg button { padding: 5px 10px; font-size: 13px; }
.polish-text { font-family: var(--serif); font-size: 17px; line-height: 1.7; white-space: pre-wrap; }
.polish-text.mine { background: var(--bg2); border: 1px solid var(--line); border-radius: 11px; padding: 11px 13px; color: var(--muted); max-height: 60vh; overflow: auto; }
.frame.shown { cursor: zoom-in; }
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(5,3,4,.94); display: flex; align-items: center; justify-content: center; }
.lb-stage { position: absolute; inset: 56px 64px; display: flex; align-items: center; justify-content: center; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 10px; box-shadow: 0 30px 90px rgba(0,0,0,.6); }
.lb-btn { position: absolute; z-index: 2; border: 0; background: rgba(255,255,255,.08); color: #fff; cursor: pointer; border-radius: 50%;
  width: 46px; height: 46px; font-size: 28px; line-height: 1; display: grid; place-items: center; }
.lb-btn:hover { background: rgba(255,255,255,.18); }
.lb-x { top: 14px; right: 16px; }
.lb-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 12px; top: 50%; transform: translateY(-50%); }
.lb-count { position: absolute; bottom: 16px; left: 0; right: 0; text-align: center; color: var(--muted); font-size: 13px; }
@media (max-width: 860px) { .lb-stage { inset: 56px 8px 44px; } .lb-prev, .lb-next { top: auto; bottom: 6px; transform: none; } }
.gnav { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 3; display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.55); border-radius: 99px; padding: 3px 6px; color: #f2e9e4; font-size: 12px; }
.gnav .gbtn { border: 0; background: none; color: #f2e9e4; font-size: 22px; line-height: 1; width: 28px; height: 28px; cursor: pointer; border-radius: 50%; }
.gnav .gbtn:hover { background: rgba(255,255,255,.15); }
.manage { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.mitem { position: relative; aspect-ratio: 16/10; border-radius: 10px; overflow: hidden; background: var(--panel2); border: 1px solid var(--line); }
.mitem img, .mitem video { width: 100%; height: 100%; object-fit: cover; display: block; }
.mitem .mact { position: absolute; inset: auto 6px 6px 6px; display: flex; gap: 4px; justify-content: center; }
.mitem .mact .btn { background: rgba(0,0,0,.7); border-color: transparent; padding: 3px 8px; }
