/* =========================================================
   墨屿 · OC 世界创作台
   A paper-and-ink design system for worldbuilders.
   ========================================================= */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --paper:      #F4EFE4;
  --paper-2:    #FBF8F1;
  --paper-3:    #EFE7D8;
  --paper-4:    #E7DDCB;
  --ink:        #211E19;
  --ink-2:      #57503F;
  --ink-3:      #8C8272;
  --ink-4:      #ADA28F;
  --line:       #E3DAC9;
  --line-2:     #D3C6AE;
  --accent:     #A84B2F;
  --accent-2:   #8C3A21;
  --accent-soft:#F3E2D8;
  --jade:       #3E6455;
  --jade-soft:  #DFE8E2;
  --gold:       #A8823F;
  --danger:     #A33A2B;

  --sans: "Inter", "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --mono: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas, monospace;

  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  --shadow-xs: 0 1px 1px rgba(61, 47, 29, .05);
  --shadow-sm: 0 2px 6px -2px rgba(61, 47, 29, .14), 0 1px 2px rgba(61, 47, 29, .05);
  --shadow-md: 0 18px 40px -24px rgba(45, 34, 20, .45), 0 4px 12px -6px rgba(45, 34, 20, .18);
  --shadow-lg: 0 40px 80px -40px rgba(40, 30, 18, .55), 0 8px 24px -12px rgba(40, 30, 18, .2);

  --sidebar-w: 254px;
  --rail-w: 374px;
  --topbar-h: 58px;
}

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.62;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

#app { position: relative; z-index: 1; min-height: 100vh; }

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
::selection { background: rgba(168, 75, 47, .18); }

:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 65%, transparent);
  outline-offset: 2px;
}

/* thin scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 20px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-4); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------ type ------------------------------ */

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.28; letter-spacing: .01em; }

.display {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: .04em;
}

.serif { font-family: var(--serif); }
.mono { font-family: var(--mono); }

.eyebrow {
  font-size: 11px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 600;
}

.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.strong { font-weight: 600; color: var(--ink); }
.accent { color: var(--accent); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------------------------- markdown ---------------------------- */

.markdown { font-size: 14.5px; line-height: 1.85; color: var(--ink-2); overflow-wrap: anywhere; }
.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 {
  color: var(--ink); font-family: var(--serif); margin: 1.5em 0 .55em; letter-spacing: .03em;
}
.markdown h1 { font-size: 24px; }
.markdown h2 { font-size: 19px; padding-bottom: .3em; border-bottom: 1px solid var(--line); }
.markdown h3 { font-size: 16px; }
.markdown h4 { font-size: 14px; }
.markdown p { margin: 0 0 .85em; }
.markdown strong { color: var(--ink); font-weight: 600; }
.markdown em { color: var(--ink-2); }
.markdown a { color: var(--accent); border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.markdown a:hover { border-bottom-color: var(--accent); }
.markdown ul, .markdown ol { margin: 0 0 .9em; padding-left: 1.35em; }
.markdown li { margin: .18em 0; }
.markdown li::marker { color: var(--ink-4); }
.markdown blockquote {
  margin: 1.1em 0; padding: .55em 1em .55em 1.15em;
  border-left: 2px solid var(--accent);
  background: linear-gradient(90deg, rgba(168, 75, 47, .055), transparent 80%);
  color: var(--ink-2); font-family: var(--serif); font-size: 15px;
}
.markdown blockquote p { margin: 0; }
.markdown code {
  font-family: var(--mono); font-size: .88em; padding: .12em .38em;
  background: var(--paper-3); border: 1px solid var(--line); border-radius: 5px;
}
.markdown pre {
  margin: 1em 0; padding: 14px 16px; background: #28241E; color: #EDE6D8;
  border-radius: var(--r-md); overflow: auto; font-size: 12.5px; line-height: 1.7;
}
.markdown pre code { background: none; border: 0; padding: 0; color: inherit; font-size: inherit; }
.markdown hr { border: 0; height: 1px; background: var(--line); margin: 1.8em 0; }
.markdown img { border-radius: var(--r-md); margin: 1em 0; border: 1px solid var(--line); }
.markdown table { width: 100%; border-collapse: collapse; margin: 1em 0; font-size: 13px; }
.markdown th, .markdown td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; }
.markdown th { background: var(--paper-3); font-weight: 600; color: var(--ink); }

/* ----------------------------- forms ------------------------------ */

.input, .textarea, .select {
  width: 100%; padding: 8px 11px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink);
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-4); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--line-2); }
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: #fff;
  box-shadow: 0 0 0 3px rgba(168, 75, 47, .09);
}
.textarea { resize: vertical; min-height: 84px; line-height: 1.7; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238C8272' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.field-hint { font-size: 11.5px; color: var(--ink-4); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

.input-bare {
  width: 100%; border: 0; background: transparent; padding: 0; color: var(--ink);
}
.input-bare:focus { outline: none; }
.title-input {
  font-family: var(--serif); font-size: 34px; font-weight: 600; letter-spacing: .04em;
  line-height: 1.3;
}
.title-input::placeholder { color: var(--ink-4); }

/* ---------------------------- buttons ----------------------------- */

.btn {
  --btn-bg: transparent;
  --btn-fg: var(--ink-2);
  --btn-bd: var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 13px;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-bd); border-radius: var(--r-sm);
  font-size: 13px; font-weight: 500; white-space: nowrap; cursor: pointer;
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .1s ease, box-shadow .16s ease;
  user-select: none;
}
.btn:hover { background: var(--paper-2); border-color: var(--line-2); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; flex: none; }

.btn-primary { --btn-bg: var(--ink); --btn-fg: #FAF6EC; --btn-bd: var(--ink); }
.btn-primary:hover { background: #332E25; border-color: #332E25; color: #fff; box-shadow: var(--shadow-sm); }

.btn-accent { --btn-bg: var(--accent); --btn-fg: #fff; --btn-bd: var(--accent); }
.btn-accent:hover { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

.btn-ghost { --btn-bd: transparent; }
.btn-ghost:hover { background: rgba(70, 55, 35, .06); border-color: transparent; }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 6px; }
.btn-sm svg { width: 13px; height: 13px; }
.btn-lg { height: 40px; padding: 0 18px; font-size: 14px; }

.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: var(--r-sm); color: var(--ink-3); }
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon:hover { color: var(--ink); }

.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, var(--line)); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); color: var(--danger); }

.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.is-loading { pointer-events: none; opacity: .7; }

.link-btn {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--accent); font-size: 13px; border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.link-btn:hover { border-color: var(--accent); }

/* ----------------------------- chips ------------------------------ */

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px;
  border-radius: 999px;
  background: var(--paper-3);
  border: 1px solid transparent;
  color: var(--ink-2);
  font-size: 11.5px; font-weight: 500;
  white-space: nowrap;
}
.chip-outline { background: transparent; border-color: var(--line); }
.chip-accent { background: var(--accent-soft); color: var(--accent-2); }
.chip-jade { background: var(--jade-soft); color: var(--jade); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  display: inline-flex; align-items: center; height: 21px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 4px;
  font-size: 11.5px; color: var(--ink-3); background: var(--paper-2);
}

/* ----------------------------- avatar ----------------------------- */

.avatar {
  --c: var(--jade);
  position: relative; flex: none;
  width: 40px; height: 40px; border-radius: 50%;
  background: radial-gradient(120% 120% at 28% 22%, color-mix(in srgb, var(--c) 72%, #fff), var(--c) 78%);
  color: #FBF7EC; display: grid; place-items: center;
  font-family: var(--serif); font-size: 16px; font-weight: 600; letter-spacing: .02em;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25), 0 1px 2px rgba(50, 35, 20, .18);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: radial-gradient(90% 60% at 30% 10%, rgba(255,255,255,.22), transparent 60%);
}
.avatar-sm { width: 26px; height: 26px; font-size: 11px; }
.avatar-md { width: 34px; height: 34px; font-size: 14px; }
.avatar-lg { width: 56px; height: 56px; font-size: 21px; }
.avatar-xl { width: 88px; height: 88px; font-size: 32px; }

.avatar-stack { display: flex; align-items: center; }
.avatar-stack > * { margin-left: -8px; box-shadow: 0 0 0 2px var(--paper-2); }
.avatar-stack > *:first-child { margin-left: 0; }

/* ----------------------------- covers ----------------------------- */

.cover-art {
  --c: var(--accent);
  position: relative; overflow: hidden;
  background:
    radial-gradient(85% 120% at 12% 8%, color-mix(in srgb, var(--c) 26%, transparent), transparent 58%),
    radial-gradient(70% 90% at 92% 92%, color-mix(in srgb, var(--c) 14%, transparent), transparent 62%),
    linear-gradient(158deg, #FCF7EC 0%, #EFE5D4 100%);
}
.cover-art::before {
  content: ""; position: absolute; inset: 0;
  background-image: repeating-linear-gradient(0deg, rgba(60, 45, 28, .055) 0 1px, transparent 1px 9px);
  opacity: .55;
}
.cover-art::after {
  content: ""; position: absolute; width: 62%; aspect-ratio: 1; border-radius: 50%;
  right: -14%; top: -28%;
  border: 1px solid color-mix(in srgb, var(--c) 22%, transparent);
  box-shadow: 0 0 0 26px color-mix(in srgb, var(--c) 4%, transparent), 0 0 0 52px color-mix(in srgb, var(--c) 3%, transparent);
}
.cover-art > * { position: relative; z-index: 1; }

/* ============================== shell ============================= */

.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.app.with-rail { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--rail-w); }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--paper-3);
  border-right: 1px solid var(--line-2);
  padding: 16px 12px 12px;
  z-index: 20;
}

.sidebar-head { padding: 2px 8px 14px; display: flex; align-items: center; justify-content: space-between; }

.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: #FBF7EC;
  display: grid; place-items: center;
  font-family: var(--serif); font-size: 17px; font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18), 0 2px 6px -2px rgba(140, 58, 33, .5);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-family: var(--serif); font-size: 18px; font-weight: 600; letter-spacing: .18em; }
.brand-sub { font-size: 9.5px; letter-spacing: .26em; color: var(--ink-4); text-transform: uppercase; }

.world-switch { position: relative; margin-bottom: 14px; }
.world-switch-btn {
  width: 100%; display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; background: var(--paper-2);
  border: 1px solid var(--line-2); border-radius: var(--r-md);
  cursor: pointer; text-align: left;
  box-shadow: var(--shadow-xs);
  transition: border-color .15s ease, background .15s ease;
}
.world-switch-btn:hover { border-color: var(--ink-4); background: #fff; }
.world-switch-cover {
  width: 30px; height: 30px; border-radius: 7px; flex: none;
  display: grid; place-items: center;
  font-family: var(--serif); font-size: 14px; color: #fff;
  background: linear-gradient(145deg, color-mix(in srgb, var(--c, var(--accent)) 70%, #fff), var(--c, var(--accent)));
}
.world-switch-meta { min-width: 0; flex: 1; }
.world-switch-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.world-switch-sub { font-size: 10.5px; color: var(--ink-4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.world-switch-btn > svg { color: var(--ink-4); }

.nav { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; flex: 1; margin: 0 -4px; padding: 0 4px; }
.nav-label {
  font-size: 10px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--ink-4); font-weight: 600; padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  height: 34px; padding: 0 10px; border-radius: var(--r-sm);
  color: var(--ink-2); font-size: 13.5px; cursor: pointer;
  transition: background .14s ease, color .14s ease;
  position: relative;
  border: 0; background: transparent; width: 100%; text-align: left;
  font-family: inherit;
}
.nav-item svg { width: 16px; height: 16px; color: var(--ink-3); transition: color .14s ease; }
.nav-item:hover { background: rgba(64, 49, 30, .055); color: var(--ink); }
.nav-item:hover svg { color: var(--ink-2); }
.nav-item.is-active { background: var(--paper-2); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-xs); }
.nav-item.is-active svg { color: var(--accent); }
.nav-item.is-active::before {
  content: ""; position: absolute; left: -4px; top: 9px; bottom: 9px; width: 2px;
  background: var(--accent); border-radius: 2px;
}
.nav-count { margin-left: auto; font-size: 11px; color: var(--ink-4); font-variant-numeric: tabular-nums; }
.nav-item.is-active .nav-count { color: var(--ink-3); }
.nav-sep { height: 1px; background: var(--line); margin: 12px 10px; }

.sidebar-foot { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.user-chip {
  display: flex; align-items: center; gap: 9px; padding: 6px 8px;
  border-radius: var(--r-sm); cursor: pointer; width: 100%; background: none; border: 0; text-align: left;
}
.user-chip:hover { background: rgba(64, 49, 30, .055); }
.user-chip-meta { min-width: 0; flex: 1; }
.user-chip-name { font-size: 12.5px; font-weight: 600; }
.user-chip-sub { font-size: 10.5px; color: var(--ink-4); }

/* main column */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; background: var(--paper-2); }

.topbar {
  height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper-2) 88%, transparent);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 15;
}
.crumbs { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-3); min-width: 0; }
.crumbs a { color: var(--ink-3); transition: color .14s ease; white-space: nowrap; }
.crumbs a:hover { color: var(--ink); }
.crumbs .sep { color: var(--ink-4); font-size: 11px; }
.crumbs .current { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.content { flex: 1; padding: 34px 44px 96px; }
.content-narrow { max-width: 940px; margin: 0 auto; }
.content-wide { max-width: 1320px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.page-title { font-family: var(--serif); font-size: 28px; font-weight: 600; letter-spacing: .05em; }
.page-sub { color: var(--ink-3); font-size: 13px; margin-top: 5px; }

.view-enter { animation: viewIn .32s cubic-bezier(.22, .8, .3, 1) both; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}

/* --------------------------- right rail --------------------------- */

.rail {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--paper-3);
  border-left: 1px solid var(--line-2);
  z-index: 18;
}
.rail-head {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 8px;
  padding: 0 16px; border-bottom: 1px solid var(--line);
}
.rail-title { font-family: var(--serif); font-size: 15px; font-weight: 600; letter-spacing: .08em; }
.rail-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.ai-messages { flex: 1; overflow-y: auto; padding: 18px 16px 10px; display: flex; flex-direction: column; gap: 14px; }
.ai-msg { display: flex; flex-direction: column; gap: 5px; }
.ai-msg-role { font-size: 10px; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-4); font-weight: 600; }
.ai-bubble {
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 3px 12px 12px 12px; padding: 10px 12px;
  font-size: 13px; line-height: 1.75; color: var(--ink-2); overflow-wrap: anywhere;
}
.ai-msg.user .ai-bubble { background: var(--ink); color: #F6EFE2; border-color: var(--ink); border-radius: 12px 3px 12px 12px; }
.ai-msg.user { align-items: flex-end; }
.ai-msg.user .ai-msg-role { color: var(--ink-4); }
.ai-bubble .markdown { font-size: 13px; }
.ai-bubble .markdown h2 { font-size: 15px; border: 0; }
.ai-bubble .markdown h3 { font-size: 13.5px; }
.ai-bubble .markdown p:last-child { margin-bottom: 0; }
.ai-cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }

.ai-compose { flex: none; padding: 12px 14px 16px; border-top: 1px solid var(--line); background: var(--paper-3); }
.ai-quick { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 9px; }
.ai-quick .chip { cursor: pointer; background: var(--paper-2); border-color: var(--line); }
.ai-quick .chip:hover { border-color: var(--ink-4); color: var(--ink); }
.ai-input-wrap {
  background: var(--paper-2); border: 1px solid var(--line-2); border-radius: var(--r-md);
  padding: 8px 9px 7px; transition: border-color .15s ease, box-shadow .15s ease;
}
.ai-input-wrap:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); box-shadow: 0 0 0 3px rgba(168, 75, 47, .07); }
.ai-input {
  width: 100%; border: 0; background: transparent; resize: none; outline: none;
  min-height: 52px; max-height: 160px; font-size: 13px; line-height: 1.65;
}
.ai-input-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.ai-send {
  margin-left: auto; width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center; border: 1px solid var(--ink); background: var(--ink); color: #FBF7EC; cursor: pointer;
}
.ai-send:hover { background: #332E25; }
.ai-send:disabled { opacity: .35; cursor: default; }
.ai-send svg { width: 14px; height: 14px; }

.ai-hint { font-size: 11px; color: var(--ink-4); }

/* --------------------------- overlays ---------------------------- */

.toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 8px;
  background: var(--ink); color: #F8F2E6; font-size: 13px;
  padding: 9px 15px; border-radius: 999px;
  box-shadow: var(--shadow-md);
  animation: toastIn .28s cubic-bezier(.2, .9, .3, 1) both;
  max-width: 80vw;
}
.toast.is-error { background: var(--danger); }
.toast.is-out { animation: toastOut .22s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(38, 30, 20, .34);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 9vh 20px 40px;
  animation: fadeIn .18s ease both;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 520px;
  background: var(--paper-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: modalIn .26s cubic-bezier(.2, .9, .3, 1) both;
  overflow: hidden;
}
.modal-wide { max-width: 760px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.985); } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 22px 12px;
}
.modal-title { font-family: var(--serif); font-size: 18px; font-weight: 600; letter-spacing: .06em; }
.modal-body { padding: 8px 22px 4px; max-height: 62vh; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 16px 22px 20px; }
.modal-foot .left { margin-right: auto; }

.search-palette {
  width: 100%; max-width: 580px; background: var(--paper-2);
  border: 1px solid var(--line-2); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  overflow: hidden; animation: modalIn .22s cubic-bezier(.2, .9, .3, 1) both;
}
.palette-input-wrap { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.palette-input { flex: 1; border: 0; background: transparent; outline: none; font-size: 15px; }
.palette-results { max-height: 52vh; overflow-y: auto; padding: 8px; }
.palette-group-label { font-size: 10px; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-4); font-weight: 600; padding: 10px 10px 4px; }
.palette-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-sm);
  cursor: pointer; color: var(--ink-2); width: 100%; text-align: left;
  border: 0; background: transparent; font: inherit;
}
.palette-item.is-active, .palette-item:hover { background: var(--paper-3); color: var(--ink); }
.palette-item-title { font-size: 13.5px; font-weight: 500; }
.palette-item-sub { font-size: 11.5px; color: var(--ink-4); margin-left: auto; }
.palette-empty { padding: 26px; text-align: center; color: var(--ink-4); font-size: 13px; }

/* ------------------------------ empty ---------------------------- */

.empty { text-align: center; padding: 54px 20px; color: var(--ink-3); }
.empty-icon {
  width: 46px; height: 46px; margin: 0 auto 14px; border-radius: 50%;
  display: grid; place-items: center; background: var(--paper-3); color: var(--ink-4);
  border: 1px dashed var(--line-2);
}
.empty-icon svg { width: 20px; height: 20px; }
.empty-title { font-family: var(--serif); font-size: 16px; color: var(--ink-2); margin-bottom: 4px; }
.empty-desc { font-size: 12.5px; max-width: 320px; margin: 0 auto; line-height: 1.7; }
.empty .btn { margin-top: 16px; }

/* --------------------------- utilities --------------------------- */

.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.hairline { height: 1px; background: var(--line); border: 0; margin: 0; }
.scroll-x { overflow-x: auto; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ============================== auth ============================== */

.auth { min-height: 100vh; display: grid; grid-template-columns: 1.02fr 1fr; }
.auth-side {
  position: relative; overflow: hidden;
  background: #221E18; color: #EDE5D5;
  padding: 46px 52px;
  display: flex; flex-direction: column;
}
.auth-side::before {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(70% 60% at 78% 18%, rgba(168, 75, 47, .38), transparent 66%),
    radial-gradient(50% 50% at 12% 88%, rgba(62, 100, 85, .28), transparent 70%);
}
.auth-side::after {
  content: ""; position: absolute; inset: 0; opacity: .5;
  background-image: repeating-linear-gradient(115deg, rgba(255, 255, 255, .028) 0 1px, transparent 1px 7px);
}
.auth-side > * { position: relative; z-index: 1; }
.auth-side .brand-name { color: #F6EFE2; }
.auth-side .brand-sub { color: rgba(246, 239, 226, .45); }
.auth-side .brand-mark { background: #A84B2F; }
.auth-quote { margin-top: auto; }
.auth-quote .display { font-size: 40px; line-height: 1.5; letter-spacing: .08em; color: #F6EFE2; }
.auth-quote p { color: rgba(237, 229, 213, .55); font-size: 12.5px; letter-spacing: .16em; margin-top: 20px; }
.auth-seal {
  position: absolute; right: 54px; bottom: 50px; width: 64px; height: 64px;
  border: 1px solid rgba(237, 229, 213, .28); border-radius: 6px;
  display: grid; place-items: center; font-family: var(--serif); font-size: 26px;
  color: rgba(237, 229, 213, .65); letter-spacing: 0;
}
.auth-main { display: grid; place-items: center; padding: 48px 40px; background: var(--paper-2); }
.auth-card { width: 100%; max-width: 364px; }
.auth-title { font-family: var(--serif); font-size: 27px; letter-spacing: .07em; margin-bottom: 6px; }
.auth-sub { color: var(--ink-3); font-size: 13px; margin-bottom: 26px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form .btn { width: 100%; margin-top: 8px; height: 38px; }
.auth-foot { margin-top: 18px; font-size: 12.5px; color: var(--ink-3); text-align: center; }
.auth-foot .link-btn { font-size: 12.5px; }
.auth-error {
  display: none; background: color-mix(in srgb, var(--danger) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
  color: var(--danger); border-radius: var(--r-sm); padding: 8px 10px; font-size: 12.5px;
}
.auth-error.show { display: block; }
.auth-demo {
  margin-top: 26px; padding: 12px 14px;
  border: 1px dashed var(--line-2); border-radius: var(--r-md);
  background: var(--paper-3); font-size: 12px; color: var(--ink-3); line-height: 1.7;
}
.auth-demo b { color: var(--ink-2); font-weight: 600; }
.auth-demo code {
  font-family: var(--mono); background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px; color: var(--ink-2);
}

/* ============================= library ============================ */

.lib { min-height: 100vh; background: var(--paper); padding-bottom: 80px; }
.lib-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 44px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(10px);
}
.lib-top-user { display: flex; align-items: center; gap: 10px; }
.lib-main { max-width: 1240px; margin: 0 auto; padding: 0 44px; }
.lib-hero { padding: 62px 0 34px; max-width: 760px; }
.lib-hero .display { font-size: 44px; line-height: 1.34; letter-spacing: .07em; }
.lib-hero .display em { font-style: normal; color: var(--accent); }
.lib-sub { margin-top: 14px; color: var(--ink-3); font-size: 14px; letter-spacing: .02em; }
.lib-hero-rule { width: 54px; height: 2px; background: var(--accent); margin: 22px 0 0; }

.lib-section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 16px; }
.lib-section-title { font-family: var(--serif); font-size: 17px; letter-spacing: .1em; color: var(--ink-2); }
.lib-section-title span { color: var(--ink-4); font-family: var(--sans); font-size: 12px; margin-left: 8px; letter-spacing: 0; }

.world-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(286px, 1fr)); gap: 22px; }
.world-card {
  position: relative; display: flex; flex-direction: column;
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--r-lg);
  overflow: hidden; cursor: pointer;
  transition: transform .22s cubic-bezier(.2, .8, .3, 1), box-shadow .22s ease, border-color .22s ease;
}
.world-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--line-2); }
.world-card-cover { height: 152px; position: relative; }
.world-card-cover .wc-genre { position: absolute; left: 14px; top: 14px; }
.wc-glyph {
  position: absolute; right: 18px; bottom: 12px;
  font-family: var(--serif); font-size: 54px; line-height: 1;
  color: color-mix(in srgb, var(--c) 30%, transparent);
  letter-spacing: 0;
  user-select: none;
}
.world-card-body { padding: 14px 16px 15px; display: flex; flex-direction: column; gap: 5px; flex: 1; }
.world-card-title { font-family: var(--serif); font-size: 19px; font-weight: 600; letter-spacing: .06em; }
.world-card-sub { font-size: 12px; color: var(--ink-3); }
.world-card-foot {
  display: flex; align-items: center; gap: 12px; margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--line); font-size: 11px; color: var(--ink-4);
}
.world-card-foot b { color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }

.new-world-card {
  display: grid; place-items: center; min-height: 262px;
  border: 1px dashed var(--line-2); border-radius: var(--r-lg);
  color: var(--ink-3); cursor: pointer; background: transparent;
  transition: border-color .2s ease, background .2s ease, color .2s ease;
}
.new-world-card:hover { border-color: var(--accent); background: rgba(168, 75, 47, .035); color: var(--accent); }
.new-world-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.new-world-inner .plus {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line-2);
  display: grid; place-items: center; background: var(--paper-2);
}
.new-world-card:hover .plus { border-color: var(--accent); }
.new-world-inner span { font-size: 12.5px; letter-spacing: .08em; }

.recent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 12px; }
.recent-card {
  display: flex; align-items: center; gap: 10px; padding: 11px 13px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper-2);
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.recent-card:hover { border-color: var(--line-2); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.recent-card .recent-icon { width: 30px; height: 30px; }
.recent-card-title { display: block; font-size: 13px; color: var(--ink); }
.recent-card-sub { display: block; font-size: 10.5px; color: var(--ink-4); margin-top: 1px; }
.recent-card-time { font-size: 10.5px; color: var(--ink-4); flex: none; }

/* ============================= overview =========================== */

.hero-card {
  position: relative; border: 1px solid var(--line); border-radius: var(--r-lg);
  overflow: hidden; background: var(--paper-2);
}
.hero-cover { height: 206px; position: relative; }
.hero-cover-top {
  position: absolute; top: 16px; left: 30px; right: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; z-index: 4;
}
.hero-cover-top .eyebrow { color: color-mix(in srgb, var(--c) 52%, var(--ink-3)); }
.hero-cover-top .btn { background: color-mix(in srgb, var(--paper-2) 75%, transparent); backdrop-filter: blur(4px); }
.hero-cover-title {
  position: absolute; left: 30px; bottom: 20px;
  font-family: var(--serif); font-size: 48px; font-weight: 600; letter-spacing: .14em;
  color: color-mix(in srgb, var(--ink) 84%, var(--c));
  z-index: 2; text-shadow: 0 1px 0 rgba(251, 248, 241, .5);
}
.hero-fade {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 35%, rgba(251, 248, 241, .55) 72%, var(--paper-2) 100%);
}
.hero-inner { padding: 4px 30px 22px; }
.hero-title { font-family: var(--serif); font-size: 38px; font-weight: 600; letter-spacing: .1em; line-height: 1.25; }
.hero-sub { color: var(--ink-2); font-size: 14px; margin-top: 2px; font-family: var(--serif); letter-spacing: .05em; }
.hero-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; font-size: 11.5px; color: var(--ink-3); }
.hero-meta .divider { width: 1px; height: 11px; background: var(--line-2); }
.hero-actions { display: flex; gap: 8px; align-items: center; }

.stats {
  display: grid; grid-template-columns: repeat(6, 1fr);
  margin-top: 18px; background: var(--paper-2);
  border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden;
}
.stat { padding: 14px 17px; border-right: 1px solid var(--line); transition: background .15s ease; cursor: pointer; }
.stat:last-child { border-right: 0; }
.stat:hover { background: var(--paper-3); }
.stat-num { font-family: var(--serif); font-size: 23px; line-height: 1.2; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-num small { font-size: 12px; color: var(--ink-4); margin-left: 3px; font-family: var(--sans); }
.stat-label { font-size: 10.5px; letter-spacing: .14em; color: var(--ink-4); margin-top: 3px; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1fr) 316px; gap: 24px; margin-top: 24px; align-items: start; }
.panel { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper-2); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.panel-title { font-size: 11.5px; font-weight: 600; letter-spacing: .16em; color: var(--ink-2); text-transform: uppercase; }
.panel-body { padding: 16px; }
.panel-body.tight { padding: 8px 10px; }

.side-list { display: flex; flex-direction: column; }
.side-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 6px;
  border-radius: var(--r-sm); cursor: pointer; color: var(--ink-2);
}
.side-row:hover { background: var(--paper-3); }
.side-row + .side-row { border-top: 1px solid color-mix(in srgb, var(--line) 65%, transparent); }
.side-row-main { min-width: 0; flex: 1; }
.side-row-title { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-row-sub { font-size: 11px; color: var(--ink-4); }

.recent-list { display: flex; flex-direction: column; }
.recent-row { display: flex; gap: 10px; padding: 11px 6px; cursor: pointer; border-radius: var(--r-sm); align-items: flex-start; }
.recent-row:hover { background: var(--paper-3); }
.recent-row + .recent-row { border-top: 1px solid color-mix(in srgb, var(--line) 65%, transparent); }
.recent-icon {
  width: 28px; height: 28px; border-radius: 7px; flex: none;
  display: grid; place-items: center; background: var(--paper-3); color: var(--ink-3);
}
.recent-icon svg { width: 14px; height: 14px; }
.recent-main { min-width: 0; flex: 1; }
.recent-title { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-sub { font-size: 11px; color: var(--ink-4); margin-top: 1px; }
.recent-time { font-size: 10.5px; color: var(--ink-4); flex: none; padding-top: 2px; }

.cast-strip { display: flex; flex-wrap: wrap; gap: 10px; }
.cast-chip { display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px 5px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper-2); cursor: pointer; }
.cast-chip:hover { border-color: var(--line-2); background: #fff; }
.cast-name { font-size: 12px; color: var(--ink-2); }

.mini-timeline { display: flex; flex-direction: column; gap: 0; }
.mini-event { display: grid; grid-template-columns: 54px 1fr; gap: 10px; padding: 8px 0; cursor: pointer; }
.mini-event + .mini-event { border-top: 1px dashed var(--line); }
.mini-year { font-family: var(--serif); font-size: 12px; color: var(--ink-4); padding-top: 1px; }
.mini-title { font-size: 12.5px; color: var(--ink-2); }
.mini-event:hover .mini-title { color: var(--accent); }

/* ============================ characters ========================== */

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--ink-4); pointer-events: none; }
.search-box .input { padding-left: 31px; height: 34px; width: 240px; }
.toolbar-spacer { flex: 1; }

.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 18px; }
.char-card {
  position: relative; display: flex; flex-direction: column;
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--r-md);
  overflow: hidden; cursor: pointer;
  transition: transform .2s cubic-bezier(.2, .8, .3, 1), box-shadow .2s ease, border-color .2s ease;
}
.char-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--line-2); }
.char-portrait { height: 150px; position: relative; display: grid; place-items: center; }
.char-portrait .avatar { width: 66px; height: 66px; font-size: 25px; box-shadow: 0 0 0 4px rgba(251, 248, 241, .8), 0 6px 16px -8px rgba(40, 30, 18, .5); }
.char-portrait .cp-index {
  position: absolute; right: 12px; top: 10px; font-family: var(--serif); font-size: 11px;
  color: color-mix(in srgb, var(--c) 55%, var(--ink-3)); letter-spacing: .1em;
}
.char-status { position: absolute; left: 10px; top: 10px; font-size: 10px; padding: 2px 7px; border-radius: 999px; background: rgba(251, 248, 241, .8); color: var(--ink-3); border: 1px solid var(--line); }
.char-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.char-name { font-family: var(--serif); font-size: 18px; letter-spacing: .06em; display: flex; align-items: baseline; gap: 7px; }
.char-alias { font-size: 10.5px; color: var(--ink-4); font-family: var(--sans); letter-spacing: 0; }
.char-role { font-size: 11.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.char-quote {
  font-family: var(--serif); font-size: 12px; color: var(--ink-3); margin-top: 7px; line-height: 1.6;
  padding-left: 8px; border-left: 2px solid color-mix(in srgb, var(--c) 35%, transparent);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.char-tags { margin-top: 9px; display: flex; gap: 5px; flex-wrap: wrap; }
.char-foot { margin-top: auto; padding-top: 9px; display: flex; align-items: center; justify-content: space-between; font-size: 10.5px; color: var(--ink-4); }

/* character editor */
.editor-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 8px; }
.editor-head-main { flex: 1; min-width: 0; }
.editor-head-actions { display: flex; align-items: center; gap: 8px; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 336px; gap: 40px; align-items: start; }
.form-section { margin-top: 28px; }
.form-section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.form-section-title { font-size: 10.5px; letter-spacing: .2em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; white-space: nowrap; }
.form-section-line { flex: 1; height: 1px; background: var(--line); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-tight { display: flex; flex-direction: column; gap: 8px; }

.preview-card { position: sticky; top: calc(var(--topbar-h) + 18px); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--paper-2); }
.preview-cover { height: 180px; display: grid; place-items: center; position: relative; }
.preview-cover .avatar { width: 78px; height: 78px; font-size: 30px; box-shadow: 0 0 0 5px rgba(251, 248, 241, .75), 0 10px 24px -14px rgba(40, 30, 18, .55); }
.preview-body { padding: 16px 18px 18px; }
.preview-name { font-family: var(--serif); font-size: 22px; letter-spacing: .07em; }
.preview-alias { font-size: 11px; color: var(--ink-4); margin-top: 2px; }
.preview-quote { font-family: var(--serif); font-size: 12.5px; color: var(--ink-3); border-left: 2px solid var(--line-2); padding-left: 10px; margin-top: 14px; line-height: 1.7; }
.preview-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.preview-meta dt { font-size: 10px; letter-spacing: .12em; color: var(--ink-4); }
.preview-meta dd { margin: 1px 0 0; font-size: 12px; color: var(--ink-2); }

.gallery-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.gallery-item { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--paper-3); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }
.gallery-item .gx {
  position: absolute; right: 3px; top: 3px; width: 20px; height: 20px; border-radius: 5px;
  display: grid; place-items: center; background: rgba(30, 25, 18, .55); color: #fff; cursor: pointer;
  opacity: 0; transition: opacity .15s ease; border: 0;
}
.gallery-item:hover .gx { opacity: 1; }
.gallery-add { display: grid; place-items: center; border: 1px dashed var(--line-2); color: var(--ink-4); cursor: pointer; background: transparent; }
.gallery-add:hover { border-color: var(--accent); color: var(--accent); background: rgba(168, 75, 47, .03); }

.tag-input { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper-2); align-items: center; }
.tag-input:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); background: #fff; box-shadow: 0 0 0 3px rgba(168, 75, 47, .08); }
.tag-input input { flex: 1; min-width: 90px; border: 0; background: transparent; outline: none; height: 24px; font-size: 13px; }
.tag-input .chip { height: 23px; }
.chip-x { border: 0; background: none; color: currentColor; opacity: .55; cursor: pointer; padding: 0; display: grid; place-items: center; }
.chip-x:hover { opacity: 1; }
.chip-x svg { width: 10px; height: 10px; }

.autosave { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-4); white-space: nowrap; flex: none; }
.autosave .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--jade); opacity: .8; }
.autosave.is-saving .dot { background: var(--gold); animation: pulse 1s infinite; }
.autosave.is-dirty .dot { background: var(--ink-4); }
@keyframes pulse { 50% { opacity: .25; } }

/* ============================== graph ============================= */

.graph-wrap {
  position: relative; height: calc(100vh - var(--topbar-h)); overflow: hidden;
  background-color: var(--paper-2);
  background-image: radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--ink-4) 32%, transparent) 1px, transparent 0);
  background-size: 22px 22px;
}
.graph-svg { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.graph-svg.is-panning { cursor: grabbing; }
.graph-edge { fill: none; stroke: color-mix(in srgb, var(--ink-3) 55%, transparent); stroke-width: 1.4; }
.gedge.is-strong .graph-edge { stroke-width: 2.1; }
.gedge.is-hostile .graph-edge { stroke: #8C3A21; stroke-dasharray: 5 4; }
.graph-edge-label { font-size: 10.5px; fill: var(--ink-3); }
.graph-edge-bg { fill: var(--paper-2); stroke: var(--line); stroke-width: 1; }
[data-labels] { pointer-events: none; }
[data-labels] .gedge.is-hostile .graph-edge-label { fill: var(--accent-2); }
.gnode { cursor: grab; }
.gnode.is-dragging { cursor: grabbing; }
.gnode circle.node-bg { fill: var(--c); stroke: var(--paper-2); stroke-width: 3; transition: stroke .15s ease; }
.gnode:hover circle.node-bg { stroke: #fff; }
.gnode.is-selected circle.node-bg { stroke: #fff; stroke-width: 3; }
.gnode text.node-name { font-size: 12px; fill: var(--ink); font-weight: 500; paint-order: stroke; stroke: var(--paper-2); stroke-width: 3px; }
.gnode text.node-glyph { font-family: var(--serif); font-size: 22px; fill: #FBF7EC; pointer-events: none; }
.gnode .node-ring { fill: none; stroke: color-mix(in srgb, var(--c) 32%, transparent); stroke-width: 1; }
.graph-toolbar {
  position: absolute; left: 20px; top: 20px; display: flex; gap: 4px; padding: 5px;
  background: var(--paper-2); border: 1px solid var(--line-2); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm); z-index: 5;
}
.graph-toolbar .btn { height: 30px; }
.graph-side {
  position: absolute; right: 18px; top: 18px; width: 306px; max-height: calc(100% - 36px);
  background: var(--paper-2); border: 1px solid var(--line-2); border-radius: var(--r-md);
  box-shadow: var(--shadow-md); z-index: 6; display: flex; flex-direction: column; overflow: hidden;
  animation: viewIn .22s ease both;
}
.graph-side-head { padding: 14px 15px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.graph-side-body { padding: 14px 15px; overflow-y: auto; }
.graph-side-section { margin-top: 16px; }
.graph-legend {
  position: absolute; left: 20px; bottom: 18px; z-index: 5;
  display: flex; gap: 12px; align-items: center; padding: 7px 12px;
  background: color-mix(in srgb, var(--paper-2) 88%, transparent); border: 1px solid var(--line);
  border-radius: 999px; font-size: 10.5px; color: var(--ink-3); backdrop-filter: blur(6px);
}
.legend-swatch { display: inline-flex; align-items: center; gap: 5px; }
.legend-line { width: 18px; height: 1.5px; background: var(--ink-3); }
.legend-line.dashed { background: repeating-linear-gradient(90deg, var(--ink-3) 0 4px, transparent 4px 7px); }
.graph-hint { position: absolute; right: 20px; bottom: 20px; font-size: 10.5px; color: var(--ink-4); z-index: 5; }

.relation-row { display: flex; align-items: flex-start; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); }
.relation-row:first-child { border-top: 0; }
.relation-kind { font-size: 10px; color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); border-radius: 4px; padding: 1px 5px; white-space: nowrap; margin-top: 2px; }
.relation-text { font-size: 12px; color: var(--ink-2); line-height: 1.6; }

/* =============================== wiki ============================= */

.wiki { display: grid; grid-template-columns: 288px minmax(0, 1fr); height: calc(100vh - var(--topbar-h)); }
.wiki-side { border-right: 1px solid var(--line); background: var(--paper); display: flex; flex-direction: column; min-height: 0; }
.wiki-side-head { padding: 14px 14px 10px; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--line); }
.wiki-side-head .search-box { flex: 1; }
.wiki-side-head .input { width: 100%; height: 30px; font-size: 12.5px; }
.wiki-cats { display: flex; gap: 5px; flex-wrap: wrap; padding: 10px 14px 8px; }
.wiki-cat { font-size: 11px; padding: 2px 8px; border-radius: 999px; cursor: pointer; color: var(--ink-3); border: 1px solid transparent; }
.wiki-cat:hover { color: var(--ink); background: var(--paper-3); }
.wiki-cat.is-active { background: var(--ink); color: #F7F0E2; }
.wiki-list { overflow-y: auto; padding: 4px 8px 20px; flex: 1; }
.wiki-item { padding: 9px 10px; border-radius: var(--r-sm); cursor: pointer; display: flex; flex-direction: column; gap: 2px; border: 1px solid transparent; }
.wiki-item:hover { background: var(--paper-3); }
.wiki-item.is-active { background: var(--paper-2); border-color: var(--line); box-shadow: var(--shadow-xs); }
.wiki-item-title { font-size: 13px; color: var(--ink); display: flex; align-items: center; gap: 6px; }
.wiki-item-sub { font-size: 10.5px; color: var(--ink-4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wiki-pin { color: var(--accent); font-size: 9px; }

.wiki-main { overflow-y: auto; background: var(--paper-2); }
.wiki-inner { max-width: 880px; margin: 0 auto; padding: 32px 46px 120px; }
.wiki-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 6px; }
.wiki-head .input-bare { font-family: var(--serif); font-size: 31px; font-weight: 600; letter-spacing: .05em; }
.wiki-meta-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0 20px; }
.wiki-summary { font-size: 13px; color: var(--ink-3); border-left: 2px solid var(--line-2); padding-left: 12px; margin: 16px 0 20px; font-family: var(--serif); line-height: 1.8; }
.wiki-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.wiki-toolbar .seg { display: inline-flex; align-items: center; gap: 2px; background: var(--paper-3); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg-btn { border: 0; background: transparent; padding: 3px 10px; border-radius: 6px; font-size: 11.5px; color: var(--ink-3); cursor: pointer; height: 24px; }
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-active { background: var(--ink); color: #FBF7EC; font-weight: 500; }

.md-editor { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; background: var(--paper-2); min-height: 440px; }
.md-editor textarea {
  border: 0; border-right: 1px solid var(--line); padding: 20px; resize: none;
  font-family: var(--mono); font-size: 13px; line-height: 1.85; background: transparent; outline: none; min-height: 440px;
}
.md-preview { padding: 20px 24px; overflow-y: auto; max-height: 70vh; }
.md-editor.is-single { grid-template-columns: 1fr; }
.md-editor.is-single textarea { border-right: 0; }

/* ============================= timeline =========================== */

.timeline { position: relative; max-width: 880px; margin: 8px auto 0; }
.tl-rail { position: absolute; left: 92px; top: 10px; bottom: 30px; width: 1px; background: var(--line-2); }
.tl-item { display: grid; grid-template-columns: 92px minmax(0, 1fr); position: relative; padding-bottom: 20px; }
.tl-year { text-align: right; padding-right: 24px; font-family: var(--serif); font-size: 12.5px; color: var(--ink-4); padding-top: 14px; letter-spacing: .05em; }
.tl-dot {
  position: absolute; left: 87px; top: 19px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--paper-2); border: 1.5px solid var(--ink-4); z-index: 1;
}
.tl-item.major .tl-dot { border-color: var(--accent); background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.tl-card {
  margin-left: 32px; border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--paper-2); padding: 14px 17px; cursor: pointer;
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
.tl-card:hover { border-color: var(--line-2); box-shadow: var(--shadow-sm); transform: translateX(2px); }
.tl-date { font-size: 10.5px; letter-spacing: .12em; color: var(--ink-4); text-transform: uppercase; }
.tl-title { font-family: var(--serif); font-size: 17px; letter-spacing: .04em; margin: 3px 0 5px; }
.tl-desc { font-size: 12.5px; color: var(--ink-3); line-height: 1.75; }
.tl-people { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.tl-people .avatar { width: 22px; height: 22px; font-size: 9px; }
.tl-people-name { font-size: 10.5px; color: var(--ink-4); margin-left: 2px; }

/* ============================== stories =========================== */

.story-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.story-card {
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper-2);
  overflow: hidden; cursor: pointer; transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
  display: flex; flex-direction: column;
}
.story-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--line-2); }
.story-cover { height: 96px; position: relative; }
.story-cover .story-glyph { position: absolute; right: 16px; bottom: 8px; font-family: var(--serif); font-size: 40px; color: color-mix(in srgb, var(--c) 26%, transparent); }
.story-body { padding: 14px 16px 16px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.story-title { font-family: var(--serif); font-size: 19px; letter-spacing: .05em; }
.story-summary { font-size: 12px; color: var(--ink-3); line-height: 1.7; }
.story-foot { margin-top: auto; padding-top: 10px; display: flex; align-items: center; gap: 10px; font-size: 10.5px; color: var(--ink-4); border-top: 1px solid var(--line); }

.writing { display: grid; grid-template-columns: 252px minmax(0, 1fr); height: calc(100vh - var(--topbar-h)); }
.writing-side { border-right: 1px solid var(--line); background: var(--paper); display: flex; flex-direction: column; min-height: 0; }
.writing-side-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.writing-side-title { font-family: var(--serif); font-size: 15px; letter-spacing: .05em; }
.chapter-list { overflow-y: auto; padding: 8px; flex: 1; }
.chapter-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--r-sm);
  cursor: pointer; font-size: 12.5px; color: var(--ink-2); border: 1px solid transparent;
}
.chapter-item:hover { background: var(--paper-3); }
.chapter-item.is-active { background: #fff; border-color: var(--line-2); box-shadow: var(--shadow-sm); color: var(--ink); }
.chapter-num { font-family: var(--serif); font-size: 10.5px; color: var(--ink-4); width: 16px; flex: none; }
.chapter-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-words { font-size: 10px; color: var(--ink-4); font-variant-numeric: tabular-nums; }
.writing-main { overflow-y: auto; background: var(--paper-2); }
.writing-inner { max-width: 760px; margin: 0 auto; padding: 30px 40px 120px; }
.writing-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.writing-title { font-family: var(--serif); font-size: 29px; font-weight: 600; letter-spacing: .05em; width: 100%; border: 0; background: transparent; outline: none; }
.writing-textarea {
  width: 100%; min-height: 62vh; border: 0; background: transparent; resize: none; outline: none;
  font-family: var(--serif); font-size: 15.5px; line-height: 2.05; color: var(--ink-2); letter-spacing: .01em;
}
.writing-bar {
  position: sticky; bottom: 0; margin: 20px -40px -120px; padding: 10px 40px;
  background: color-mix(in srgb, var(--paper-2) 92%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); display: flex; align-items: center; gap: 14px;
  font-size: 11px; color: var(--ink-4);
}

/* ============================= settings =========================== */

.settings { max-width: 800px; display: flex; flex-direction: column; gap: 20px; }
.settings-section { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper-2); overflow: hidden; }
.settings-head { padding: 15px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.settings-title { font-family: var(--serif); font-size: 16px; letter-spacing: .06em; }
.settings-desc { font-size: 11.5px; color: var(--ink-4); margin-top: 2px; }
.settings-body { padding: 20px; display: flex; flex-direction: column; gap: 15px; }
.provider-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.provider-preset {
  border: 1px solid var(--line); background: var(--paper-2); border-radius: 999px;
  padding: 3px 11px; font-size: 11.5px; color: var(--ink-3); cursor: pointer;
}
.provider-preset:hover { border-color: var(--line-2); color: var(--ink); }
.provider-preset.is-active { background: var(--ink); border-color: var(--ink); color: #F7F0E2; }
.ai-status { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ink-3); }
.ai-status .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-4); }
.ai-status.is-on .dot { background: var(--jade); box-shadow: 0 0 0 3px var(--jade-soft); }
.danger-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-top: 1px solid var(--line); }
.danger-row:first-child { border-top: 0; padding-top: 0; }

/* =========================== responsive =========================== */

@media (max-width: 1320px) {
  .app.with-rail { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .app.with-rail .rail {
    position: fixed; right: 0; top: 0; width: var(--rail-w); height: 100vh;
    box-shadow: var(--shadow-lg); transform: translateX(100%); transition: transform .26s cubic-bezier(.2, .8, .3, 1);
  }
  .app.with-rail.rail-open .rail { transform: none; }
}

@media (max-width: 1080px) {
  :root { --sidebar-w: 238px; }
  .content { padding: 28px 30px 90px; }
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
  .editor-grid { grid-template-columns: minmax(0, 1fr); }
  .preview-card { position: static; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat:nth-child(3) { border-right: 0; }
  .stat:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .wiki { grid-template-columns: 240px minmax(0, 1fr); }
}

@media (max-width: 820px) {
  .app, .app.with-rail { grid-template-columns: 1fr; }
  .sidebar {
    display: flex; position: fixed; left: 0; top: 0; bottom: 0; width: 282px;
    transform: translateX(-100%); transition: transform .24s cubic-bezier(.2, .8, .3, 1);
    z-index: 70; box-shadow: var(--shadow-lg);
  }
  .app.mobile-nav-open .sidebar { transform: none; }
  .mobile-menu { display: inline-flex; margin-left: -4px; }
  .mobile-scrim {
    display: block; position: fixed; inset: 0; z-index: 65;
    background: rgba(34, 27, 18, .38); opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
  }
  .app.mobile-nav-open .mobile-scrim { opacity: 1; pointer-events: auto; }
  .app.with-rail .rail { width: min(374px, 92vw); }
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .lib-top, .lib-main, .lib-hero { padding-left: 22px; padding-right: 22px; }
  .lib-hero .display { font-size: 32px; }
  .content { padding: 20px 18px 80px; }
  .topbar { padding: 0 14px; }
  .wiki, .writing { grid-template-columns: 1fr; height: auto; }
  .wiki-side, .writing-side { border-right: 0; border-bottom: 1px solid var(--line); max-height: 240px; }
  .graph-wrap { height: calc(100vh - var(--topbar-h)); }
  .modal-backdrop { padding-top: 5vh; }
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
  .search-box .input { width: 100%; }
  .timeline .tl-rail { left: 56px; }
  .tl-item { grid-template-columns: 56px 1fr; }
  .tl-year { padding-right: 16px; font-size: 11px; }
  .tl-dot { left: 51px; }
  .tl-card { margin-left: 20px; }
}

/* ============================ additions =========================== */

.app:not(.rail-open) .rail { display: none; }

.content.is-full {
  padding: 0;
  flex: 1;
  min-height: 0;
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.content.is-full > * { flex: 1; min-height: 0; }

.rail-head > svg { color: var(--accent); flex: none; }
.rail-head .ai-status { margin-left: 4px; }
.ai-status .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-4); flex: none; }
.ai-status.is-on .dot { background: var(--jade); box-shadow: 0 0 0 3px var(--jade-soft); }
.ai-status { max-width: 96px; overflow: hidden; }
.ai-status span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ai-welcome { padding: 22px 4px; color: var(--ink-3); }
.ai-welcome-mark {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: #FBF7EC; font-family: var(--serif); font-size: 20px;
  margin-bottom: 14px; box-shadow: 0 6px 18px -10px rgba(140, 58, 33, .8);
}
.ai-welcome-title { font-family: var(--serif); font-size: 16px; color: var(--ink); letter-spacing: .03em; margin-bottom: 8px; }
.ai-welcome p { font-size: 12.5px; line-height: 1.85; margin: 0 0 14px; }
.ai-welcome-list { display: flex; flex-direction: column; gap: 7px; font-size: 11.5px; color: var(--ink-4); border-top: 1px dashed var(--line); padding-top: 12px; }

.ai-note {
  margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--line);
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  font-size: 11px; color: var(--ink-4);
}
.ai-note .link-btn { font-size: 11px; }

.world-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 60;
  background: var(--paper-2); border: 1px solid var(--line-2); border-radius: var(--r-md);
  box-shadow: var(--shadow-md); padding: 6px;
  animation: modalIn .16s cubic-bezier(.2, .9, .3, 1) both;
}
.world-menu-label { font-size: 9.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-4); font-weight: 600; padding: 6px 8px 4px; }
.world-menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 8px; border: 0; border-radius: 6px; background: none;
  cursor: pointer; text-align: left; color: var(--ink-2); font-size: 12.5px;
}
.world-menu-item:hover { background: var(--paper-3); }
.world-menu-item.is-active { background: var(--paper-3); }
.world-menu-glyph {
  width: 26px; height: 26px; border-radius: 6px; flex: none;
  display: grid; place-items: center; color: #fff; font-family: var(--serif); font-size: 12px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--c) 72%, #fff), var(--c));
}
.world-menu-title { display: block; color: var(--ink); font-size: 12.5px; font-weight: 500; }
.world-menu-sub { display: block; color: var(--ink-4); font-size: 10px; }
.world-menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.world-menu .nav-item { height: 30px; font-size: 12.5px; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  background: var(--c); border: 2px solid var(--paper-2);
  box-shadow: 0 0 0 1px var(--line-2);
  transition: transform .14s ease, box-shadow .14s ease;
}
.swatch:hover { transform: scale(1.08); }
.swatch.is-active { box-shadow: 0 0 0 2px var(--ink); transform: scale(1.05); }

.palette-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line-2); margin: 0 9px 0 5px; flex: none; }

/* keep full-height views usable when the rail is open */
@media (max-width: 1320px) {
  .graph-side { right: 18px; }
}

.mobile-menu { display: none; }
.mobile-scrim { display: none; }

/* ========================= page details ========================== */

.hero-glyph {
  position: absolute;
  right: 42px;
  bottom: -18px;
  font-family: var(--serif);
  font-size: 158px;
  line-height: 1;
  color: color-mix(in srgb, var(--c) 14%, transparent);
  pointer-events: none;
  user-select: none;
  z-index: 0;
}
.hero-cover .hero-actions { z-index: 4; }
.hero-meta svg { vertical-align: -2px; }

.quick-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.quick-actions .btn { background: transparent; }
.quick-actions .btn:hover { background: var(--paper-2); }

.quote-panel {
  background:
    linear-gradient(160deg, rgba(168, 75, 47, .045), transparent 70%),
    var(--paper-2);
}

.export-options { display: flex; flex-direction: column; gap: 10px; }
.export-card {
  display: flex; align-items: center; gap: 13px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--paper-2); color: var(--ink-2);
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.export-card:hover { border-color: var(--line-2); background: #fff; transform: translateY(-1px); }
.export-icon {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: grid; place-items: center; background: var(--paper-3); color: var(--ink-3);
}
.export-title { display: block; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.export-desc { display: block; font-size: 11.5px; color: var(--ink-4); line-height: 1.6; margin-top: 2px; }

/* character editor */

.char-editor .editor-form > section + section { margin-top: 30px; }
.char-editor .form-section:first-child { margin-top: 0; }
.preview-avatar {
  border: 0; background: none; padding: 0; cursor: pointer; position: relative; z-index: 2;
  border-radius: 50%;
}
.preview-avatar:hover { transform: scale(1.02); }
.preview-hint {
  position: absolute; bottom: 10px; left: 0; right: 0; text-align: center;
  font-size: 10px; color: var(--ink-4); letter-spacing: .08em; opacity: 0;
  transition: opacity .18s ease; z-index: 2;
}
.preview-card:hover .preview-hint { opacity: 1; }
.preview-role { font-size: 11.5px; color: var(--ink-3); margin-top: 6px; letter-spacing: .02em; }
.preview-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 12px; }
.preview-relations { margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--line); }
.preview-relations .relation-row { padding: 7px 0; }
.preview-relations .relation-text a { color: var(--ink); border-bottom: 1px dashed var(--line-2); }
.preview-relations .relation-text a:hover { color: var(--accent); border-color: var(--accent); }

.relation-row .chip-x { opacity: 0; transition: opacity .14s ease; }
.relation-row:hover .chip-x { opacity: .8; }

/* graph */

.graph-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: color-mix(in srgb, var(--paper-2) 80%, transparent);
  backdrop-filter: blur(2px); z-index: 8;
}
.graph-empty .empty { max-width: 360px; }
.graph-wrap .graph-side { animation: modalIn .2s ease both; }
.gnode image { pointer-events: none; }
.graph-side .relation-text a { color: var(--ink); border-bottom: 1px dashed var(--line-2); }

/* chips toggle */

.chip.is-on { background: var(--ink); border-color: var(--ink); color: #F7F0E2; }

/* writing */

.writing-bar .autosave { color: var(--ink-4); }
.writing-head .autosave { margin-left: auto; }
.writing-side-head .writing-side-title { font-size: 14.5px; }
.chapter-item.is-active .chapter-words { color: var(--ink-3); }
.chapter-item.is-active .chapter-num { color: var(--accent); }

/* settings */

.profile-avatar { border: 0; background: none; padding: 0; cursor: pointer; }
.profile-avatar:hover { filter: brightness(1.03); }
.settings .field-row { align-items: start; }
.settings-head .ai-status { max-width: 320px; }

/* misc */

.is-loading { position: relative; color: transparent !important; }
.is-loading::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 14px; height: 14px;
  border-radius: 50%; border: 2px solid rgba(140, 130, 114, .35);
  border-top-color: var(--ink-2); animation: spin .7s linear infinite;
}
.btn-primary.is-loading::after, .btn-accent.is-loading::after, .btn-danger.is-loading::after {
  border-color: rgba(255, 255, 255, .3); border-top-color: #fff;
}
@keyframes spin { to { transform: rotate(360deg); } }

.eyebrow + .page-title { margin-top: 4px; }
.page-head .eyebrow { margin-bottom: 2px; }

.content-slot { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.content-slot > .content { flex: 1; }

@media (max-width: 820px) {
  .mobile-menu { display: inline-flex; }
  .mobile-scrim { display: block; }
  .hero-cover { height: 176px; }
  .hero-cover-top { left: 20px; right: 12px; top: 12px; }
  .hero-cover-top .eyebrow { font-size: 9px; max-width: 45%; line-height: 1.6; }
  .hero-cover-top .btn { height: 28px; padding: 0 9px; font-size: 11px; }
  .hero-cover-title { font-size: 34px; left: 20px; bottom: 16px; letter-spacing: .1em; }
  .hero-inner { padding: 2px 20px 18px; }
  .hero-meta { font-size: 10.5px; gap: 8px; }
  .quick-actions { gap: 6px; }
  .quick-actions .btn { height: 30px; font-size: 12px; }
  .stat { padding: 11px 12px; }
  .stat-num { font-size: 20px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .toolbar { gap: 8px; }
}

/* custom cover images */

.cover-img, .hero-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; z-index: 0;
}
.world-card-cover.has-image .wc-glyph { display: none; }
.world-card-cover.has-image .wc-genre { background: rgba(251, 248, 241, .88); backdrop-filter: blur(4px); border-color: transparent; }
.hero-cover.has-image .hero-fade {
  background: linear-gradient(180deg, rgba(18, 13, 9, .08) 0%, rgba(18, 13, 9, .16) 32%, rgba(18, 13, 9, .62) 64%, rgba(18, 13, 9, .9) 100%);
}
.hero-cover.has-image .hero-cover-title { color: #FBF7EC; text-shadow: 0 2px 18px rgba(0, 0, 0, .7), 0 1px 3px rgba(0, 0, 0, .55); }
.hero-cover.has-image .hero-cover-top .eyebrow { color: rgba(251, 247, 236, .95); text-shadow: 0 1px 10px rgba(0, 0, 0, .7); }
.hero-cover.has-image .hero-cover-top .btn { background: rgba(251, 247, 236, .92); border-color: transparent; color: var(--ink); }

.cover-field { display: flex; flex-direction: column; gap: 8px; }
.cover-preview {
  position: relative; height: 126px; border-radius: var(--r-md);
  border: 1px dashed var(--line-2); overflow: hidden;
  display: grid; place-items: center; text-align: center;
  color: var(--ink-4); font-size: 12px; line-height: 1.8;
  background:
    radial-gradient(80% 100% at 20% 10%, color-mix(in srgb, var(--c, var(--accent)) 12%, transparent), transparent 65%),
    var(--paper-3);
}
.cover-preview.has-image { border-style: solid; border-color: var(--line); }
.cover-preview img { width: 100%; height: 100%; object-fit: cover; }
.cover-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

