:root {
  color-scheme: dark;
  --ink: #171222;
  --base: #14121d;
  --surface: #201b2a;
  --surface-2: #2a2335;
  --rule: #453b54;
  --paper: #f7edd5;
  --white: #fff8e9;
  --muted: #c3b5ce;
  --pink: #f791cc;
  --accent: #ec559f;
  --gold: #eec37c;
  --success: #a1e4c0;
  --danger: #ffafc7;
  --radius: 14px;
  --display: "Arial Black", Impact, "Segoe UI", sans-serif;
  --body: "Aptos", "Segoe UI", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; color: var(--white); background: var(--base); font: 1rem/1.55 var(--body); }
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { line-height: 1.14; }
h1 { font-family: var(--display); font-size: clamp(2.3rem, 5vw, 4.65rem); letter-spacing: -.07em; font-weight: 900; }
h2 { font-size: clamp(1.38rem, 3vw, 2rem); letter-spacing: -.035em; }
h3 { font-size: 1.13rem; }
p { color: var(--muted); }
a { color: var(--pink); text-underline-offset: .22em; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }
button, input, select, textarea, .button { min-width: 0; }
button, .button { cursor: pointer; }
button:disabled { opacity: .52; cursor: not-allowed; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}
input, select, textarea {
  display: block;
  width: 100%;
  border-radius: 9px;
  border: 1px solid var(--rule);
  padding: .64rem .72rem;
  background: #171321;
  color: var(--white);
}
select { appearance: none; padding-right: 2.2rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 10'%3E%3Cpath d='M1 2l6 6 6-6' fill='none' stroke='%23f791cc' stroke-width='1.8'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-size: 12px 9px; background-position: right .85rem center; }
input[type="checkbox"] { display: inline-block; width: 1.15rem; height: 1.15rem; margin: .12rem 0 0; padding: 0; accent-color: var(--accent); flex: 0 0 auto; }
textarea { resize: vertical; min-height: 5rem; }
label { font-size: .91rem; color: var(--muted); font-weight: 650; }
label > input, label > select, label > textarea { margin-top: .33rem; font-weight: 400; }
.check { display: flex; align-items: flex-start; gap: .6rem; font-weight: 500; }
.check input { margin-top: .2rem; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 43px;
  padding: .52rem .92rem;
  gap: .43rem;
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--white);
  text-decoration: none;
  font-weight: 700;
  font-size: .93rem;
  line-height: 1.3;
  text-align: center;
}
.button:hover { background-color: #382c44; border-color: var(--pink); }
.button.primary { background: var(--pink); color: #25172b; border-color: #f4a5d7; }
.button.primary:hover { background: #ffd0e9; }
.button.ghost { background: transparent; }
.button.danger { color: var(--danger); }
.button.icon { width: 43px; min-width: 43px; padding: .42rem; }
.button.icon svg, .nav-button svg, .brand-mark svg { width: 1.16em; height: 1.16em; flex: 0 0 auto; }
.stack { display: grid; gap: 1rem; min-width: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.between { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.skip-link:focus { position: fixed; top: .7rem; left: .7rem; z-index: 20; background: var(--paper); padding: .5rem; color: var(--ink); }
.muted { color: var(--muted); }
.loading { display: grid; min-height: 100dvh; place-items: center; }
.tag { display: inline-flex; align-self: flex-start; color: var(--pink); font-size: .77rem; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.error { color: var(--danger); }
.note { font-size: .9rem; color: var(--muted); }
.alert { padding: .8rem 1rem; border: 1px solid var(--rule); border-radius: 9px; background: var(--surface-2); }
.alert p { color: inherit; }
.alert.error { border-color: #8e5775; }

.login-shell { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, .8fr); min-height: 100dvh; }
.login-art {
  isolation: isolate;
  display: grid;
  position: relative;
  align-content: space-between;
  min-height: 540px;
  padding: clamp(1.25rem, 5vw, 4.7rem);
  overflow: hidden;
  background: #251a2f;
  border-right: 1px solid var(--rule);
}
.login-art::before, .hero::before {
  pointer-events: none;
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(90deg, rgba(24,16,33,.96) 0%, rgba(24,16,33,.77) 37%, rgba(24,16,33,.13) 100%),
    url("assets/captain.webp") right center / cover no-repeat,
    radial-gradient(circle at 83% 36%, #9a376b 0, transparent 49%),
    repeating-linear-gradient(-37deg, transparent 0 12px, rgba(250,211,235,.1) 13px 14px, transparent 15px 22px),
    #34233f;
}
.login-art::after, .hero::after {
  pointer-events: none;
  content: "";
  position: absolute;
  inset: 12px;
  z-index: -1;
  border: 1px solid #fae4eb50;
  border-radius: inherit;
}
.login-copy { max-width: 33rem; padding: 4rem 0 1.5rem; }
.login-copy h1 { max-width: 12ch; margin: .6rem 0 .9rem; text-shadow: 1px 3px #1e1430; }
.login-copy p { color: #f3ddeb; max-width: 30rem; }
.brand { display: flex; align-items: center; gap: .63rem; text-decoration: none; color: var(--white); font-weight: 850; letter-spacing: -.035em; line-height: 1.1; }
.brand-mark { width: 2.6rem; height: 2.6rem; display: grid; place-items: center; color: #2d1c32; border: 2px solid #fbb4dc; border-radius: 50%; background: var(--pink); box-shadow: 2px 2px #0e0b15; font-size: 1.35rem; }
.brand small { display: block; color: var(--muted); font-size: .73rem; font-weight: 650; letter-spacing: .03em; margin-top: .2rem; }
.login-pane { display: grid; place-items: center; padding: clamp(1.35rem, 6vw, 4rem); }
.login-form { max-width: 24rem; width: 100%; gap: 1.1rem; }
.login-form h2 { font-size: 2rem; }
.login-form .button { width: 100%; }

.app-header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 1rem; min-height: 68px; padding: .65rem clamp(1rem, 3vw, 2.5rem); background: #171421; border-bottom: 1px solid #342b40; }
.app-header .brand { flex: 1; min-width: max-content; }
.account-button { color: var(--gold); }
.app-layout { max-width: 1550px; min-height: calc(100dvh - 68px); display: grid; grid-template-columns: 224px minmax(0, 1fr); margin: 0 auto; }
.sidebar { align-self: start; position: sticky; top: 68px; padding: 1.6rem .9rem; min-height: calc(100dvh - 68px); border-right: 1px solid #352c42; }
.nav { display: grid; gap: .35rem; }
.nav h2 { margin: 0 .55rem .4rem; font-size: .73rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.nav-button { display: flex; align-items: center; position: relative; width: 100%; min-height: 45px; text-align: left; gap: .65rem; border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--muted); padding: .56rem .67rem; font-size: .95rem; font-weight: 750; }
.nav-button:hover { background: #241e2d; color: var(--white); }
.nav-button[aria-current="page"] { background: #36243b; color: var(--pink); border-color: #573855; }
.nav-button svg { font-size: 1.15rem; }
.app-main { min-width: 0; width: 100%; padding: 1.55rem clamp(1.15rem, 3.4vw, 3.6rem) 3rem; }
.app-main > .stack { max-width: 1200px; margin-inline: auto; gap: 1.28rem; }
.save-state { color: var(--muted); font-size: .79rem; line-height: 1.2; text-align: right; }
.save-state[data-tone="ok"] { color: var(--success); }
.save-state[data-tone="error"] { color: var(--danger); }

.hero { min-height: 280px; position: relative; isolation: isolate; display: grid; align-items: end; padding: clamp(1.3rem, 4.4vw, 3.4rem); border-radius: var(--radius); overflow: hidden; border: 1px solid #66516b; }
.hero-copy { max-width: 31rem; }
.hero h1 { margin: .38rem 0 .62rem; font-size: clamp(2.2rem, 5vw, 4.35rem); }
.hero p { color: #efdaea; max-width: 28rem; margin-bottom: 1.15rem; }
.section-head { display: grid; gap: .24rem; }
.title-input { font-family: var(--display); font-weight: 900; font-size: clamp(1.7rem, 3.3vw, 3.1rem); letter-spacing: -.045em; width: min(34rem, 100%); color: var(--white); }
.toolbar { align-items: flex-start; }
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1rem; min-width: 0; }
.card.paper { background: var(--paper); color: var(--ink); border-color: #ccb68a; }
.card.paper p { color: #584759; }
.card.paper .button { color: var(--ink); border-color: #bea98f; background: #f3dfc1; }
.card.paper .button:hover { background: #efd2ac; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 245px), 1fr)); gap: .86rem; }
.story-card { display: grid; gap: .55rem; align-content: space-between; min-height: 9.4rem; overflow-wrap: anywhere; border-top: 3px solid var(--accent); }
.story-card p { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.story-card .stats { color: #f1ccdf; font-size: .84rem; }
.empty { padding: 1.55rem; border: 1px dashed #6a536f; }
.empty p { margin: .32rem 0 .8rem; }
.tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--rule); gap: .45rem; }
.tab { min-height: 42px; border: 0; border-bottom: 2px solid transparent; background: transparent; padding: .52rem .6rem; color: var(--muted); font-weight: 750; }
.tab[aria-selected="true"] { border-color: var(--pink); color: var(--pink); }
.editor-grid { display: grid; grid-template-columns: minmax(180px, 235px) minmax(0, 1fr); align-items: start; gap: 1rem; }
.chapter { min-width: 0; display: grid; gap: .43rem; border-top: 1px solid var(--rule); padding: .66rem 0 0; }
.chapter h3 { overflow-wrap: anywhere; }
.scene-link { display: block; border: 1px solid var(--rule); width: 100%; min-height: 42px; padding: .39rem .55rem; border-radius: 8px; color: var(--muted); background: #1c1625; text-align: left; overflow-wrap: anywhere; }
.scene-link[aria-current="true"] { color: var(--pink); background: #37223c; border-color: #7b5077; }
.field-row { display: flex; align-items: start; gap: .65rem; flex-wrap: wrap; }
.field-row > label { flex: 1 1 10rem; }
.writing { min-height: clamp(12rem, 42vh, 27rem); font-family: Georgia, "Times New Roman", serif; font-size: 1.08rem; line-height: 1.75; background: #f9efd9; color: #272032; border-color: #e1cda8; }
.panel-editor { display: grid; gap: .55rem; }
.panel-preview { border: 1px solid #64526a; background: #0e0c14; border-radius: 8px; aspect-ratio: 4/3; display: grid; place-items: center; overflow: hidden; }
.panel-preview img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.panel-preview p { padding: .6rem; text-align: center; }
.asset-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 195px), 1fr)); }
.asset-card { display: grid; gap: .5rem; align-content: start; overflow-wrap: anywhere; }
.asset-card img { border-radius: 8px; width: 100%; aspect-ratio: 4/3; object-fit: contain; background: #100e17; }
.asset-card .button { width: 100%; }
.action-box { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 310px), 1fr)); gap: 1rem; align-items: start; }
.chat { min-width: 0; max-width: 54rem; }
.transcript { min-height: 12rem; max-height: 50vh; overflow-y: auto; padding: .3rem 0 .6rem; display: grid; gap: .8rem; align-content: start; }
.bubble { padding: .67rem .87rem; border-radius: 13px; max-width: min(46rem, 94%); background: #2b2338; border: 1px solid #50405e; }
.bubble.mine { justify-self: end; background: #38263c; border-color: #70485f; }
.bubble strong { display: block; margin-bottom: .16rem; color: var(--pink); font-size: .85rem; }
.bubble p { color: var(--white); white-space: pre-wrap; overflow-wrap: anywhere; }
.context { border: 1px solid var(--rule); border-radius: 8px; padding: .57rem .7rem; background: #191521; }
.context p { margin-top: .43rem; }
.service-list { display: grid; gap: .47rem; padding-left: 1.15rem; word-break: break-word; }
.manager-preview { display: grid; gap: 1rem; }
.manager-preview img { max-width: 23rem; width: 100%; margin: 0 auto; }
.banner { min-width: 0; }
.banner:empty { display: none; }
.manager-tools { margin-top: .8rem; }
.account-form { max-width: 34rem; width: 100%; }
.search-label { width: min(18rem, 100%); }
.poster-options { border: 1px solid var(--rule); border-radius: 9px; padding: .64rem; }
.poster-options > summary { cursor: pointer; color: var(--pink); }

@media screen { #print { display: none; } }

@media (max-width: 930px) {
  .app-layout { grid-template-columns: 170px minmax(0, 1fr); }
  .sidebar { padding-inline: .55rem; }
  .editor-grid { grid-template-columns: 168px minmax(0, 1fr); }
}
@media (max-width: 740px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-art { min-height: clamp(15rem, 52vh, 22rem); border-right: 0; border-bottom: 1px solid var(--rule); padding: 1.2rem 1.35rem; }
  .login-copy { padding: 2.7rem 0 .6rem; }
  .login-copy h1 { font-size: clamp(1.85rem, 9vw, 3.35rem); }
  .login-pane { padding: 1.25rem; }
  .app-layout { display: block; }
  .app-header { min-height: 57px; padding-inline: .78rem; gap: .52rem; }
  .app-header .brand-mark { width: 2.1rem; height: 2.1rem; font-size: 1.18rem; }
  .app-header .brand small { display: none; }
  .app-header .button { min-height: 41px; }
  .sidebar { position: sticky; top: 57px; z-index: 4; min-height: 0; padding: .35rem .48rem; background: #171421; border: 0; border-bottom: 1px solid var(--rule); }
  .nav { display: flex; gap: .24rem; flex-wrap: wrap; justify-content: space-between; }
  .nav h2 { display: none; }
  .nav-button { justify-content: center; gap: .3rem; padding: .38rem; text-align: center; font-size: .81rem; width: auto; flex: 1 1 auto; }
  .nav-button svg { font-size: .9rem; }
  .app-main { padding: 1rem .82rem 2rem; }
  .hero { min-height: 230px; padding-inline: 1.25rem; }
  .hero::after, .login-art::after { inset: 7px; }
  .editor-grid { grid-template-columns: 1fr; }
  .chapter-list { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%, 138px),1fr)); gap: .75rem; }
  .save-state { max-width: 7rem; }
  .toolbar .row { width: 100%; }
}
@media (max-width: 380px) {
  .nav-button { min-height: 41px; }
  .nav-button svg { display: none; }
  .app-header .brand { font-size: .94rem; }
  .button { font-size: .86rem; padding-inline: .56rem; }
  .save-state { max-width: 5.5rem; }
}

@media print {
  @page { margin: 17mm; size: A4; }
  @page poster { size: A4; margin: 8mm; }
  body { color: #111; background: #fff; font: 11pt/1.5 Georgia, serif; }
  #app, .skip-link, #announcement { display: none !important; }
  #print:not([hidden]) { display: block; }
  #print h1 { font: bold 32pt/1.1 Georgia, serif; letter-spacing: normal; }
  #print h2 { font-size: 20pt; margin: .9em 0 .25em; }
  #print h3 { font-size: 14pt; margin: .85em 0 .3em; }
  #print h2, #print h3 { break-after: avoid; }
  #print p { color: #161616; white-space: pre-wrap; overflow-wrap: anywhere; }
  #print .print-chapter { margin-top: 1em; }
  #print .print-panels { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 5mm; margin: 4mm 0; align-items: start; }
  #print figure { break-inside: avoid; margin: 0; border: 1px solid #222; padding: 2mm; }
  #print figure img { width: 100%; max-height: 95mm; object-fit: contain; }
  #print .print-poster { page: poster; break-inside: avoid; }
  #print .print-poster img { width: 100%; height: auto; max-height: 280mm; object-fit: contain; }
  #print figcaption { padding: 1mm; font-size: .9em; }
  #print blockquote { margin: .35em 0 0; padding-inline-start: .55em; border-inline-start: 1px solid #333; white-space: pre-wrap; }
}
