:root {
  --bg: #0d0a10;
  --bg-2: #151018;
  --panel: #1c1521;
  --panel-2: #241a2c;
  --border: #382a40;
  --accent: #b3294e;       /* crimson */
  --accent-2: #7b1f3a;     /* deep wine */
  --accent-glow: rgba(179,41,78,.35);
  --gold: #c9a96a;
  --text: #ece6f0;
  --muted: #9c8fa8;
  --muted-2: #6f6478;
  --danger: #e0566b;
  --ok: #6bbf8a;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0,0,0,.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: radial-gradient(1200px 700px at 80% -10%, #2a1424 0%, transparent 55%),
              radial-gradient(1000px 600px at -10% 110%, #1a1030 0%, transparent 50%),
              var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1,h2,h3,h4 { font-family: 'Cormorant Garamond', Georgia, serif; font-weight: 600; line-height: 1.15; }
::selection { background: var(--accent-glow); }

/* Scrollbar */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: #3a2c43; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #4d3a59; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px;
  background: rgba(13,10,16,.82); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; cursor: pointer; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-size: 18px;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.brand h1 { font-size: 22px; letter-spacing: .5px; }
.brand small { color: var(--muted); font-family: 'Inter'; font-size: 11px; letter-spacing: 2px; text-transform: uppercase; display: block; margin-top: -3px;}
.nav { display: flex; align-items: center; gap: 10px; }
.nav .user-chip { color: var(--muted); font-size: 13px; margin-right: 4px; }

.container { max-width: 1080px; margin: 0 auto; padding: 32px 22px 80px; }
.container.narrow { max-width: 760px; }
.reader-container { max-width: 820px; margin: 0 auto; padding: 24px 22px 100px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 11px 20px; border-radius: 10px; transition: all .18s ease;
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; box-shadow: 0 8px 24px var(--accent-glow);
}
.btn.primary:hover { box-shadow: 0 10px 30px var(--accent-glow); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); background: rgba(224,86,107,.1); }
.btn.sm { padding: 7px 13px; font-size: 13px; }
.btn.lg { padding: 14px 30px; font-size: 16px; }
.btn.block { width: 100%; }

/* ---------- Cards / panels ---------- */
.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 26px; box-shadow: var(--shadow);
}

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .hero { text-align: center; margin-bottom: 26px; }
.auth-card .hero .logo-lg {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 16px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-size: 32px; box-shadow: 0 10px 30px var(--accent-glow);
}
.auth-card h2 { font-size: 34px; }
.auth-card .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.tabs { display: flex; gap: 6px; background: var(--bg-2); padding: 5px; border-radius: 12px; margin-bottom: 22px; }
.tabs button { flex: 1; padding: 10px; border: none; background: transparent; color: var(--muted); font-weight: 600; border-radius: 8px; cursor: pointer; font-family: inherit; }
.tabs button.active { background: var(--panel-2); color: var(--text); }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--text); }
.field .hint { font-size: 12px; color: var(--muted-2); margin-top: 5px; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=number], textarea, select {
  width: 100%; font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px;
  transition: border-color .15s; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
textarea { resize: vertical; min-height: 78px; line-height: 1.5; }
select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg fill='%239c8fa8' height='20' viewBox='0 0 24 24' width='20' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 36px; }

/* ---------- Stepper ---------- */
.stepper { display: flex; align-items: center; gap: 6px; margin-bottom: 28px; flex-wrap: wrap; }
.step-pill { display: flex; align-items: center; gap: 8px; padding: 7px 13px; border-radius: 30px; font-size: 12.5px; font-weight: 600; color: var(--muted); background: var(--bg-2); border: 1px solid var(--border); cursor: pointer; transition: all .15s; }
.step-pill .num { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; background: var(--panel-2); }
.step-pill.active { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; }
.step-pill.active .num { background: rgba(255,255,255,.25); }
.step-pill.done { color: var(--gold); border-color: var(--accent-2); }

.step-head { margin-bottom: 18px; }
.step-head h3 { font-size: 28px; }
.step-head p { color: var(--muted); font-size: 14px; }

/* ---------- Length tier cards ---------- */
.tier-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(225px,1fr)); gap: 14px; }
.tier-card { position: relative; text-align: left; padding: 18px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--panel); cursor: pointer; transition: all .18s; }
.tier-card:hover { border-color: var(--accent-2); transform: translateY(-2px); }
.tier-card.selected { border-color: var(--accent); background: linear-gradient(180deg, var(--panel-2), var(--panel)); box-shadow: 0 0 0 3px var(--accent-glow); }
.tier-card h4 { font-size: 20px; margin-bottom: 4px; }
.tier-card .words { color: var(--gold); font-size: 13px; font-weight: 600; font-family: 'Inter'; }
.tier-card .read { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.tier-card .rec-badge { position: absolute; top: -9px; right: 12px; background: linear-gradient(135deg,var(--gold),#9b7d44); color: #1a1208; font-size: 10px; font-weight: 800; letter-spacing: .5px; padding: 3px 9px; border-radius: 20px; text-transform: uppercase; }

/* ---------- Chips (tropes) ---------- */
.chip-grid { display: flex; flex-wrap: wrap; gap: 9px; }
.chip { padding: 8px 14px; border-radius: 30px; border: 1px solid var(--border); background: var(--bg-2); color: var(--muted); font-size: 13px; cursor: pointer; transition: all .15s; user-select: none; }
.chip:hover { border-color: var(--accent-2); color: var(--text); }
.chip.selected { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }

/* ---------- Accordion ---------- */
.accordion { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 14px; overflow: hidden; background: var(--panel); }
.accordion-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; cursor: pointer; user-select: none; }
.accordion-head h4 { font-size: 19px; display: flex; align-items: center; gap: 10px; }
.accordion-head .ico { font-size: 18px; }
.accordion-head .arrow { transition: transform .2s; color: var(--muted); }
.accordion.open .accordion-head .arrow { transform: rotate(180deg); }
.accordion-body { display: none; padding: 4px 18px 20px; border-top: 1px solid var(--border); }
.accordion.open .accordion-body { display: block; }

/* ---------- Sliders ---------- */
.slider-row { display: grid; grid-template-columns: 130px 1fr 42px; align-items: center; gap: 14px; margin-bottom: 14px; }
.slider-row label { font-size: 13px; font-weight: 600; }
.slider-row .val { color: var(--gold); font-weight: 700; text-align: right; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 6px; border-radius: 4px; background: var(--border); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: linear-gradient(135deg,var(--accent),var(--accent-2)); cursor: pointer; box-shadow: 0 2px 8px var(--accent-glow); }
input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border: none; border-radius: 50%; background: var(--accent); cursor: pointer; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 620px){ .grid-2 { grid-template-columns: 1fr; } }

.step-actions { display: flex; justify-content: space-between; margin-top: 28px; gap: 12px; }

.mode-toggle { display: flex; gap: 8px; justify-content: center; margin-bottom: 26px; }
.mode-toggle button { padding: 9px 20px; border-radius: 30px; border: 1px solid var(--border); background: var(--bg-2); color: var(--muted); font-weight: 600; cursor: pointer; font-family: inherit; font-size: 13px; }
.mode-toggle button.active { background: var(--panel-2); color: var(--text); border-color: var(--accent-2); }

/* ---------- Dashboard ---------- */
.dash-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; flex-wrap: wrap; gap: 14px; }
.dash-head h2 { font-size: 32px; }
.story-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px,1fr)); gap: 18px; }
.story-card { background: linear-gradient(180deg, var(--panel), var(--bg-2)); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: all .18s; display: flex; flex-direction: column; }
.story-card:hover { border-color: var(--accent-2); transform: translateY(-3px); box-shadow: var(--shadow); }
.story-card .spine { height: 5px; width: 48px; border-radius: 4px; background: linear-gradient(90deg,var(--accent),var(--gold)); margin-bottom: 14px; }
.story-card h4 { font-size: 23px; margin-bottom: 6px; }
.story-card .meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.story-card .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.story-card .tag { font-size: 11px; padding: 3px 9px; border-radius: 20px; background: var(--bg-2); color: var(--muted); border: 1px solid var(--border); }
.story-card .actions { margin-top: auto; display: flex; gap: 8px; }
.badge { font-size: 11px; padding: 3px 9px; border-radius: 20px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.badge.complete { background: rgba(107,191,138,.15); color: var(--ok); }
.badge.generating { background: rgba(201,169,106,.15); color: var(--gold); }
.badge.draft { background: var(--bg-2); color: var(--muted); }
.badge.error { background: rgba(224,86,107,.15); color: var(--danger); }

.empty-state { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty-state .big { font-size: 56px; margin-bottom: 14px; }
.empty-state h3 { font-size: 26px; color: var(--text); margin-bottom: 8px; }

/* ---------- Generation progress ---------- */
.gen-wrap { max-width: 720px; margin: 30px auto; }
.progress-bar { height: 10px; background: var(--bg-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.progress-bar .fill { height: 100%; width: 5%; background: linear-gradient(90deg, var(--accent-2), var(--accent), var(--gold)); transition: width .5s ease; border-radius: 6px; }
.gen-status { display: flex; align-items: center; gap: 12px; margin: 18px 0; font-size: 15px; }
.spinner { width: 20px; height: 20px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.gen-chapters { margin-top: 22px; }
.gen-chapter-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; background: var(--panel); animation: fadein .4s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px);} to {opacity:1; transform:none;} }
.gen-chapter-item .check { color: var(--ok); font-size: 18px; }
.gen-chapter-item .ttl { font-weight: 600; }
.gen-chapter-item .wc { color: var(--muted); font-size: 12px; margin-left: auto; }

/* ---------- Reader ---------- */
.reader-head { text-align: center; margin-bottom: 8px; }
.reader-head h2 { font-size: 42px; }
.reader-head .tagline { color: var(--gold); font-style: italic; font-family: 'Cormorant Garamond'; font-size: 19px; }
.reader-head .meta { color: var(--muted); font-size: 13px; margin-top: 10px; }
.reader-toolbar { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 22px 0 30px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.chapter { margin-bottom: 50px; }
.chapter .ch-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; }
.chapter h3 { font-size: 30px; color: var(--text); }
.chapter .prose { font-family: 'Cormorant Garamond', Georgia, serif; font-size: 20px; line-height: 1.75; color: #ddd4e2; }
.chapter .prose p { margin-bottom: 16px; text-indent: 1.4em; }
.chapter .prose p:first-of-type { text-indent: 0; }
.premise-box { background: var(--panel); border-left: 3px solid var(--accent); border-radius: 8px; padding: 18px 20px; margin-bottom: 36px; font-family: 'Cormorant Garamond'; font-size: 19px; font-style: italic; color: var(--muted); }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(120px); background: var(--panel-2); border: 1px solid var(--border); color: var(--text); padding: 13px 22px; border-radius: 12px; box-shadow: var(--shadow); z-index: 999; transition: transform .3s ease; font-size: 14px; max-width: 90vw; }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--danger); }
.toast.ok { border-color: var(--ok); }

.loading-full { min-height: 60vh; display: grid; place-items: center; }
.center { text-align: center; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }
.muted { color: var(--muted); }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: grid; place-items: center; z-index: 200; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px; max-width: 460px; width: 100%; box-shadow: var(--shadow); }
.modal h3 { font-size: 24px; margin-bottom: 8px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

@media (max-width: 620px){
  .reader-head h2 { font-size: 32px; }
  .chapter .prose { font-size: 18px; }
  .dash-head h2 { font-size: 26px; }
  .brand h1 { font-size: 18px; }
}
