/* shadcn/ui-style design tokens (zinc dark base + indigo primary + gold accent).
   The whole app reads these variables, so the palette stays cohesive. */
:root {
  --bg: #09090b;          /* background (zinc-950) */
  --panel: #101014;       /* card / raised surface */
  --panel-2: #18181b;     /* secondary / inset surface (zinc-900) */
  --ink: #fafafa;         /* foreground */
  --muted: #a1a1aa;       /* muted-foreground (zinc-400) */
  --accent: #f2ca50;      /* signature gold (Stitch questkeeper) */
  --accent-2: #f2ca50;    /* primary = gold, monochrome like the Stitch design */
  --accent-rgb: 242,202,80;
  --accent-2-rgb: 242,202,80;
  --primary-fg: #1a1508;  /* dark text on gold buttons */
  --hp: #ef4444;          /* red-500 */
  --mp: #3b82f6;          /* blue-500 */
  --xp: #f2ca50;
  --destructive: #ef4444;
  --border: #27272a;      /* zinc-800 */
  --input: #1c1c20;
  --ring: #f2ca50;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0,0,0,.45), 0 1px 0 rgba(255,255,255,.02) inset;
  --font-display: "Playfair Display", Georgia, "Times New Roman", serif;
  --sidebar-w: 240px;
}

/* ===== Persistent left-nav sidebar (Stitch app shell) ===== */
body:has(#sidebar) { padding-left: var(--sidebar-w); }   /* only the app, not login */
.material-symbols-outlined { font-family: "Material Symbols Outlined"; font-weight: 400; font-style: normal; font-size: 20px; line-height: 1; vertical-align: -4px; }
#sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; gap: 4px; z-index: 8; }
.sb-logo { padding: 6px 8px 14px; }
.sb-logo .brand { font-family: var(--font-display); font-size: 20px; font-weight: 700; color: var(--ink); background: none; border: none; padding: 0; cursor: pointer; text-align: left; }
.sb-logo .brand:hover { filter: none; color: var(--accent); }
.sb-cta { display: flex; align-items: center; gap: 10px; width: 100%; justify-content: flex-start; padding: 11px 14px; margin-bottom: 8px; font-size: 14px; font-weight: 600; }
.sb-nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.sb-label { font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); padding: 12px 12px 4px; opacity: .7; }
.sb-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; justify-content: flex-start; background: none; border: none; color: var(--muted); padding: 9px 12px; border-radius: 9px; font-size: 14px; cursor: pointer; }
.sb-item:hover { background: var(--panel-2); color: var(--ink); }
.sb-item.active { background: rgba(var(--accent-2-rgb),.14); color: var(--accent-2); }
.sb-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); padding-top: 8px; }
.sb-user { padding: 8px 12px 2px; }
.sb-user .user-badge { color: var(--accent); font-weight: 600; font-size: 13px; }

/* Mobile chrome: hamburger + sheet toggle + drawer backdrop */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0; background: none; border: 1px solid var(--border); color: var(--ink); border-radius: 9px; }
.icon-btn:hover { background: var(--panel-2); filter: none; }
.hspacer { flex: 1; }
.mobile-only { display: none !important; }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; }
.drawer-backdrop.hidden { display: none; }
.mobile-tabs { display: none; }
/* (Responsive @media block lives at the very end of this file so it overrides
   later same-specificity rules like .disc-page.) */

/* ===== Theme palettes (from the Stitch designs) — applied via [data-theme] ===== */

/* Arcane Glass — deep navy + luminous cyan */
[data-theme="arcane"] {
  --bg: #051424; --panel: #0d1c2d; --panel-2: #16273a;
  --ink: #d4e4fa; --muted: #9fb3c4;
  --accent: #a4e6ff; --accent-2: #00d1ff;
  --accent-rgb: 164,230,255; --accent-2-rgb: 0,209,255;
  --primary-fg: #003543;
  --hp: #ff6b7d; --mp: #4cd6ff; --xp: #a4e6ff; --destructive: #ff6b7d;
  --border: #26384c; --input: #16273a; --ring: #00d1ff;
  --font-display: "JetBrains Mono", ui-monospace, "Cascadia Code", monospace;
}

/* Ethereal Forest — mossy dark green + mint & gold */
[data-theme="forest"] {
  --bg: #0f1512; --panel: #1b211e; --panel-2: #262b28;
  --ink: #dfe4df; --muted: #aeb8af;
  --accent: #fabd00; --accent-2: #a1d1b4;
  --accent-rgb: 250,189,0; --accent-2-rgb: 161,209,180;
  --primary-fg: #063824;
  --hp: #e5606f; --mp: #7fb5d8; --xp: #fabd00; --destructive: #e5606f;
  --border: #333b35; --input: #262b28; --ring: #a1d1b4;
  --font-display: "EB Garamond", Georgia, "Times New Roman", serif;
}

/* Grimdark Parchment — charred black + blood red */
[data-theme="grimdark"] {
  --bg: #131313; --panel: #1b1a1a; --panel-2: #242322;
  --ink: #e5e2e1; --muted: #b6a4a1;
  --accent: #ffb4a8; --accent-2: #b3271b;
  --accent-rgb: 255,180,168; --accent-2-rgb: 179,39,27;
  --primary-fg: #ffffff;
  --hp: #d93a34; --mp: #b8a463; --xp: #ffb4a8; --destructive: #d93a34;
  --border: #38302f; --input: #242322; --ring: #b3271b;
  --font-display: "Playfair Display", Georgia, "Times New Roman", serif;
}

/* Theme picker (Account settings) */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.theme-card { text-align: left; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; cursor: pointer; transition: border-color .12s, transform .12s; color: var(--ink); }
.theme-card:hover { transform: translateY(-2px); }
.theme-card.on { border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2); }
.theme-swatch { display: flex; gap: 4px; margin-bottom: 8px; }
.theme-swatch span { width: 22px; height: 22px; border-radius: 5px; border: 1px solid rgba(255,255,255,.12); }
.theme-name { font-size: 13px; font-weight: 600; }
.theme-desc { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Serif/display headings driven by the per-theme --font-display */
.modal-card h2, .char-name, .camp-title, .camp-detail-head h2, .disc-header h2,
.prof-h3, #profName, .rail-head, .le-name, h2.brand { font-family: var(--font-display); letter-spacing: .2px; }
.camp-title { font-weight: 700; }
/* Refined thin scrollbars with a gold-hover thumb (Stitch style) */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

* { box-sizing: border-box; }
/* Lock the document so only inner panels scroll — stops the whole UI (header +
   composer) from sliding/rubber-banding when you drag the chat on mobile. */
html { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  height: 100vh;            /* fallback for older engines */
  height: 100dvh;          /* dynamic viewport — fills the real screen in a mobile PWA (no dead space) */
  display: flex;
  flex-direction: column;
  overflow: hidden;         /* the document itself never scrolls; .chat / drawers scroll internally */
  overscroll-behavior: none; /* no bounce/rubber-band chaining to the page */
  touch-action: manipulation; /* disable double-tap-to-zoom (with the viewport meta, no pinch either) */
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring); border-radius: var(--radius); }

header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  /* keep the bar out of the notch / rounded corners in a full-bleed PWA */
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
header h1, .brand { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; display: flex; align-items: center; gap: 6px; font-family: var(--font-display); }
.tagline { color: var(--muted); font-size: 13px; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
header button { white-space: nowrap; }
.user-badge { color: var(--accent); font-size: 13px; font-weight: 600; white-space: nowrap; }
.user-badge:empty { display: none; }

/* header nav + shadcn-style dropdown menus */
.nav { display: flex; align-items: center; gap: 8px; }
.menu { position: relative; }
.menu > [data-menu-trigger] { display: inline-flex; align-items: center; gap: 5px; }
.chev { font-size: 10px; opacity: .7; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 5px; box-shadow: var(--shadow); z-index: 30;
  display: none; flex-direction: column; gap: 2px;
}
.menu.open .menu-list { display: flex; }
.menu-item {
  background: transparent; border: none; color: var(--ink); text-align: left;
  padding: 8px 10px; border-radius: 7px; font-size: 13px; font-weight: 500; cursor: pointer;
}
.menu-item:hover { background: var(--panel-2); filter: none; }

/* chat control: per-message actions, swipes, inline edit */
.msg { position: relative; }
/* Float the hover toolbar just ABOVE the bubble's top-right so it never covers
   the text (translateY(-100%) lifts it clear of the first line). */
.msg-actions { position: absolute; top: -6px; right: 6px; transform: translateY(-100%);
  display: none; gap: 3px; z-index: 3; padding: 3px; border-radius: 9px;
  background: var(--panel); border: 1px solid var(--border); box-shadow: 0 6px 18px rgba(0,0,0,.5); }
/* Transparent bridge across the gap to the bubble so the toolbar stays visible
   while the mouse travels up to it (no hover dead-zone). */
.msg-actions::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 12px; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { display: flex; }
.msg-actions:hover { display: flex; }
.msg.user .msg-actions { right: auto; left: 6px; }
button.micro {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
  border-radius: 7px; padding: 3px; min-width: 27px; height: 27px; line-height: 1;
  cursor: pointer;
}
button.micro:hover { background: var(--panel-2); color: var(--ink); filter: none; }
button.micro.danger:hover { background: var(--hp); color: #fff; border-color: var(--hp); }
button.micro:disabled { opacity: .35; cursor: not-allowed; }
button.micro .material-symbols-outlined { font-size: 18px; vertical-align: 0; }
.swipe-bar { display: flex; align-items: center; gap: 6px; margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--border); }
.swipe-count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.swipe-bar .regen { margin-left: auto; }
.edit-ta {
  width: 100%; background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--accent-2); border-radius: 8px; padding: 8px; font: inherit; resize: vertical;
}
.edit-actions { display: flex; gap: 8px; margin-top: 8px; }
button.sm { padding: 5px 12px; font-size: 13px; }

button {
  background: var(--accent-2);
  color: var(--primary-fg);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 15px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
  transition: filter .15s ease, background .15s ease, box-shadow .15s ease, border-color .15s ease;
}
button:hover { filter: brightness(1.08); }
button.ghost, button.secondary { background: transparent; border: 1px solid var(--border); color: var(--ink); font-weight: 500; }
button.ghost:hover, button.secondary:hover { background: var(--panel-2); filter: none; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* unified shadcn-style form controls + focus ring */
input, textarea, select {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--input);
  border-radius: var(--radius);
  padding: 9px 11px;
  font-family: inherit;
  font-size: 14px;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none; border-color: var(--ring);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring);
}
input[type="file"] { padding: 7px; }

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;   /* minmax(0,..) lets the column shrink below content width (no right overflow) */
  min-height: 0;
  min-width: 0;
}

/* Chat */
#chatCol { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--border); }
.chat { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
/* Center the conversation column so it reads down the middle, not edge-to-edge. */
.chat, #composer, .combat-bar { align-self: center; width: 100%; max-width: 900px; }
/* dismissible inline notice (errors / timeouts / tips) */
.chat-notice { align-self: center; width: 100%; max-width: 900px; display: flex; align-items: flex-start; gap: 10px;
  background: rgba(239,68,68,.10); border: 1px solid var(--hp); color: var(--ink);
  border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.45; }
.chat-notice .notice-x { margin-left: auto; background: transparent; border: none; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 13px; }
.chat-notice .notice-x:hover { color: var(--ink); filter: none; }

/* Focus mode: hide the side panels for a distraction-free centered read. */
body.focus-mode { padding-left: 0; }
body.focus-mode #sidebar, body.focus-mode #sheet { display: none; }
body.focus-mode main { grid-template-columns: minmax(0, 1fr); }
body.focus-mode #chatCol { border-right: none; }
.desktop-only { display: inline-flex; }
.icon-btn.on { background: rgba(var(--accent-2-rgb), .16); color: var(--accent-2); border-color: var(--accent-2); }
.msg { max-width: 80%; padding: 12px 15px; border-radius: 12px; line-height: 1.55; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: rgba(var(--accent-2-rgb),.1); border: 1px solid rgba(var(--accent-2-rgb),.4); color: var(--ink); border-bottom-right-radius: 3px; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.msg.assistant { white-space: normal; }
.msg { overflow-wrap: anywhere; word-break: break-word; }   /* long tokens/URLs wrap instead of forcing the column wide */
.msg.assistant .syslog { display: block; color: var(--accent); font-family: ui-monospace, monospace; font-size: 13px; margin: 2px 0; overflow-wrap: anywhere; }

/* markdown */
.msg.assistant .md-p { margin: 0 0 10px; }
.msg.assistant .md-p:last-child { margin-bottom: 0; }
.msg.assistant .md-h { font-weight: 700; margin: 12px 0 6px; line-height: 1.3; color: #fff; }
.msg.assistant .md-h:first-child { margin-top: 0; }
.msg.assistant .md-h1 { font-size: 19px; }
.msg.assistant .md-h2 { font-size: 17px; }
.msg.assistant .md-h3 { font-size: 15px; }
.msg.assistant .md-h4, .msg.assistant .md-h5, .msg.assistant .md-h6 { font-size: 14px; color: var(--muted); }
.msg.assistant .md-list { margin: 4px 0 10px; padding-left: 22px; }
.msg.assistant .md-list li { margin: 3px 0; }
.msg.assistant .md-hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.msg.assistant strong { color: #fff; font-weight: 700; }
.msg.assistant em { font-style: italic; color: #cfd2de; }
.msg.assistant code { background: var(--panel-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 4px; font-family: ui-monospace, monospace; font-size: 12.5px; }
.msg.assistant del { opacity: .6; }
.msg.assistant a { color: var(--accent-2); text-decoration: underline; }
.empty { color: var(--muted); text-align: center; margin: auto; max-width: 360px; }
.empty p { margin: 8px 0; }
.empty button { margin: 0 4px; }

/* --- interactive tutorial (coach-mark tour) --- */
#wbTour { position: fixed; inset: 0; z-index: 4000; }
#wbTour .wbt-backdrop { position: absolute; inset: 0; background: rgba(4,5,7,.55); }
/* The ring dims everything OUTSIDE it via a huge box-shadow, spotlighting the anchor. */
#wbTour .wbt-ring { position: absolute; border-radius: 10px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(4,5,7,.62), 0 0 0 2px var(--accent) inset;
  transition: top .2s, left .2s, width .2s, height .2s; }
#wbTour .wbt-card { position: absolute; width: min(340px, calc(100vw - 32px));
  background: var(--panel, #16181d); border: 1px solid var(--border, #2a2d35);
  border-radius: 14px; padding: 16px 16px 14px; box-shadow: 0 12px 40px rgba(0,0,0,.5);
  color: var(--text, #e8eaee); }
#wbTour .wbt-step { font-size: 11px; font-weight: 700; letter-spacing: .5px;
  color: var(--accent); text-transform: uppercase; }
#wbTour .wbt-title { font-size: 17px; font-weight: 700; margin: 4px 0 6px; }
#wbTour .wbt-body { font-size: 14px; line-height: 1.5; color: var(--muted, #aab); }
#wbTour .wbt-body b { color: var(--text, #e8eaee); }
#wbTour .wbt-body .wbt-ex { display: inline-block; margin-top: 6px; padding: 2px 6px;
  border-radius: 6px; background: rgba(255,255,255,.05); font-family: "JetBrains Mono", monospace; font-size: 12px; }
#wbTour .wbt-actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
#wbTour .wbt-skip { margin-right: auto; background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 13px; padding: 6px 4px; }
#wbTour .wbt-skip:hover { color: var(--text); }
#wbTour .wbt-card button.primary, #wbTour .wbt-card button.ghost {
  padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; }
#wbTour .wbt-card button.ghost { background: transparent; border: 1px solid var(--border, #2a2d35); color: var(--text); }
#wbTour .wbt-card button.primary { background: var(--accent); border: 1px solid var(--accent); color: #1a1400; }
/* replay entry point in the sidebar */
#tutorialBtn .material-symbols-outlined { font-size: 20px; }

.combat-bar { padding: 10px 20px; border-top: 1px solid var(--hp); background: rgba(224,85,107,.06); display: flex; flex-direction: column; gap: 7px; }
.combat-bar .cb-row { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.cb-lab { font-size: 12px; color: var(--muted); }
.cb-targets { display: flex; flex-wrap: wrap; gap: 7px; }
.tgt { flex: 1 1 130px; text-align: left; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; cursor: pointer; color: var(--ink); }
.tgt.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: rgba(200,162,74,.1); }
.tgt-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.tgt-name { font-weight: 600; font-size: 13px; }
.tgt-ac { font-size: 11px; color: var(--muted); }
.tgt-hp { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.tgt-bar { flex: 1; height: 6px; background: rgba(0,0,0,.35); border-radius: 3px; overflow: hidden; }
.tgt-fill { display: block; height: 100%; background: var(--hp); }
.tgt-num { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cb-allies { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.cb-allies-lbl { font-size: 10px; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); margin-right: 2px; }
.ally { display: inline-flex; align-items: center; gap: 6px; background: rgba(95,208,122,.08); border: 1px solid rgba(95,208,122,.35); border-radius: 999px; padding: 3px 9px; font-size: 12px; }
.ally-name { font-weight: 600; color: var(--ink); }
.ally-hp { display: inline-flex; align-items: center; gap: 5px; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ally-bar { width: 34px; height: 5px; background: rgba(0,0,0,.35); border-radius: 3px; overflow: hidden; }
.ally-fill { display: block; height: 100%; background: #5fd07a; }
.ally.down { opacity: .5; border-color: var(--border); background: transparent; }
.ally.down .ally-name { text-decoration: line-through; }
.cb-btn { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--border); color: var(--ink); border-radius: 8px; padding: 7px 11px; font-size: 13px; font-weight: 600; cursor: pointer; }
.cb-btn.atk { border-color: var(--accent); }
.cb-btn.spell { border-color: var(--accent-2); }
.cb-btn.gen { font-weight: 500; color: var(--muted); }
.cb-btn:hover:not(:disabled) { filter: brightness(1.2); }
.cb-btn:disabled { opacity: .4; cursor: not-allowed; }
.cb-sub { font-size: 11px; color: var(--muted); font-weight: 400; }
.cb-generic { border-top: 1px dashed var(--border); padding-top: 7px; }
.cb-dying { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.dying-lbl { color: var(--hp); font-weight: 700; font-size: 13px; }

#composer { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--panel); }
#input { flex: 1; resize: none; background: var(--panel-2); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 14px; font-family: inherit; }

/* Sheet */
#sheet { overflow-y: auto; padding: 16px; background: var(--panel); }
.sheet-head { border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 12px; }
.char-name { font-size: 20px; font-weight: 700; color: var(--accent); }
.char-sub { color: var(--muted); font-size: 13px; }
#sheet h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); border-bottom: 1px solid var(--border); padding-bottom: 4px; }

.bars { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 68px 1fr auto; align-items: center; gap: 8px; font-size: 12px; }
.bar { height: 12px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.bar .fill { height: 100%; width: 0; transition: width .4s ease; }
.bar.hp .fill, .bar.bar-hp .fill { background: var(--hp); }
.bar.mp .fill, .bar.bar-mp .fill { background: var(--mp); }
.bar.xp .fill, .bar.bar-xp .fill { background: var(--xp); }
.bar.bar-green .fill { background: #5fd07a; }
.bar.bar-purple .fill { background: #a679f0; }
.bar.bar-teal .fill { background: #3fc7c0; }
.bar.bar-orange .fill { background: #e8954a; }
.bar-row > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- D&D 5e sheet --- */
.c5-top { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 10px; }
.c5-stat { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 2px; text-align: center; }
.c5-stat .k { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.c5-stat .v { font-size: 18px; font-weight: 700; }

.abilities { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.abil { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 4px; text-align: center; position: relative; }
.abil-name { font-size: 11px; color: var(--muted); font-weight: 600; }
.abil-mod { font-size: 22px; font-weight: 700; line-height: 1.1; }
.abil-score { font-size: 12px; color: var(--muted); }
.abil-save { font-size: 10px; color: var(--accent-2); margin-top: 2px; }
.save-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-left: 3px; vertical-align: middle; }

.rollable { cursor: pointer; transition: background .1s; }
.rollable:hover { background: rgba(var(--accent-2-rgb),.14); border-radius: 6px; outline: 1px solid var(--accent-2); }
.hint-roll { font-size: 9px; color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 400; }
.roll-chip { align-self: center; background: var(--panel-2); border: 1px solid var(--accent-2); border-radius: 14px; padding: 5px 14px; font-size: 13px; color: var(--ink); }
.roll-chip .crit { color: #5fd07a; font-weight: 700; }
.roll-chip .fumble { color: var(--hp); font-weight: 700; }

/* explicit dice rolls shown under a message (visible to everyone) */
.rolls-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.rolls-strip .rs-label { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-right: 2px; }
.roll-chip.mini { align-self: auto; padding: 3px 9px; font-size: 12px; border-radius: 10px; font-family: ui-monospace, monospace; }
.roll-chip .rc-lab { font-weight: 700; color: var(--accent); }
.roll-chip .rc-hit { color: #5fd07a; font-weight: 700; }
.roll-chip .rc-miss { color: var(--hp); font-weight: 700; }
.roll-chip .rc-res { color: var(--accent-2); font-weight: 600; }

/* admin engine-actions panel — hidden unless the Engine Debug toggle is on */
.engine-panel { display: none; margin-top: 8px; border: 1px solid var(--border); border-radius: 9px; background: rgba(0,0,0,.22); font-family: ui-monospace, monospace; font-size: 11.5px; }
body.debug-on .engine-panel { display: block; }
.engine-panel > summary { cursor: pointer; padding: 6px 10px; color: var(--accent-2); user-select: none; list-style: none; }
.engine-panel > summary::-webkit-details-marker { display: none; }
.engine-panel > summary::before { content: "▸ "; }
.engine-panel[open] > summary::before { content: "▾ "; }
.eng-list, .eng-combat, .eng-tray { padding: 4px 10px 8px; display: flex; flex-direction: column; gap: 5px; }
.eng-call { border-left: 2px solid var(--accent-2); padding: 2px 0 2px 8px; }
.eng-call.bad { border-left-color: var(--hp); }
.eng-tool { color: var(--ink); font-weight: 700; }
.eng-args { color: var(--muted); word-break: break-word; }
.eng-out { color: #8fd6a0; word-break: break-word; white-space: pre-wrap; }
.eng-combat { border-top: 1px dashed var(--border); color: var(--muted); }
.eng-tray { border-top: 1px dashed var(--border); }
/* debug sub-sections: lorebook activations + NPC events */
.eng-sec { border-top: 1px dashed var(--border); padding: 6px 10px 4px; }
.eng-h { font-size: 10px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); margin-bottom: 4px; }
.eng-sec .eng-list, .eng-sec .eng-combat { padding: 0; }
.eng-tok { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.eng-tok b { color: var(--ink); }
.eng-lore { padding: 2px 0; word-break: break-word; }
.eng-lore-name { color: var(--ink); font-weight: 700; }
.eng-trig { color: var(--accent); }
.eng-lore.off { opacity: .55; }
.eng-drop { color: var(--hp); }
.eng-npc { padding: 2px 0; color: var(--ink); border-left: 2px solid var(--accent); padding-left: 8px; }
.sb-item.on { background: rgba(var(--accent-2-rgb), .14); color: var(--accent-2); }

.spell-group { margin: 5px 0; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.spell-group .sg-lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; margin-right: 4px; }
.prof-box { font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.prof-box .pv-line { margin: 3px 0; line-height: 1.4; }
.prof-box .pv-line i { color: var(--muted); font-style: normal; font-weight: 600; }
.bf-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.entity.active-chat { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.chip-open { color: var(--accent); font-size: 12px; font-weight: 700; }

/* clickable feature/trait/condition/spell + info popover */
.info { cursor: pointer; }
.feat-list li.info { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.feat-list li.info:hover { border-left-color: var(--accent); background: rgba(var(--accent-2-rgb),.1); }
.info-i { color: var(--accent-2); font-size: 12px; flex: 0 0 auto; }
.badge.info:hover, .tag.info:hover { filter: brightness(1.25); outline: 1px solid var(--accent-2); }
.info-pop { position: fixed; z-index: 40; width: 300px; max-width: 88vw; background: var(--panel); border: 1px solid var(--accent-2); border-radius: 10px; padding: 12px 14px; box-shadow: 0 8px 30px rgba(0,0,0,.5); font-size: 13px; line-height: 1.5; }
.info-pop .ip-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.info-pop .ip-head b { font-size: 15px; color: var(--accent); }
.info-pop .ip-src { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); border: 1px solid var(--border); border-radius: 10px; padding: 1px 7px; }
.info-pop .ip-body { color: var(--ink); }

/* feats in level-up */
.feat-desc { font-size: 12.5px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin: 6px 0; line-height: 1.45; }
.feat-row { margin: 8px 0; }
.feat-pick { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; }
.feat-lang { width: 120px; background: var(--panel-2); color: var(--ink); border: 1px solid var(--border); border-radius: 6px; padding: 4px 7px; }
.power-toggle.on { background: var(--hp); color: #fff; border-color: var(--hp); }

/* bestiary */
.best-controls { display: flex; gap: 8px; margin-bottom: 10px; }
.best-controls input { flex: 1 1 auto; min-width: 0; background: var(--panel-2); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.best-controls select { flex: 0 0 auto; width: auto; min-width: 140px; background: var(--panel-2); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.best-layout { display: grid; grid-template-columns: 240px 1fr; gap: 12px; height: 62vh; }
.best-list { overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
.best-row { display: flex; flex-direction: column; align-items: flex-start; width: 100%; text-align: left; background: none; border: none; color: var(--ink); padding: 6px 9px; border-radius: 6px; cursor: pointer; }
.best-row:hover { background: var(--panel-2); }
.best-row.sel { background: rgba(200,162,74,.14); outline: 1px solid var(--accent); }
.br-name { font-weight: 600; font-size: 13px; }
.br-meta { font-size: 11px; color: var(--muted); }
.best-detail { overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.statblock { color: var(--ink); font-size: 13px; }
.statblock .sb-head h3 { margin: 0; color: var(--accent); font-size: 22px; }
.statblock .sb-meta { font-style: italic; color: var(--muted); margin-bottom: 8px; }
.statblock .sb-top, .statblock .sb-details { border-top: 1px solid var(--accent); border-bottom: 1px solid var(--accent); padding: 6px 0; margin: 6px 0; }
.statblock .sb-line { margin: 2px 0; }
.statblock .sb-line b, .statblock .sb-abil .k { color: var(--accent); }
.statblock .sb-abilities { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; text-align: center; margin: 8px 0; }
.statblock .sb-abil .k { font-weight: 700; font-size: 12px; }
.statblock .sb-abil .v { font-size: 13px; }
.statblock .sb-section { margin-top: 12px; }
.statblock .sb-section h4 { color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 3px; margin: 8px 0 6px; font-variant: small-caps; }
.statblock .sb-section p { margin: 5px 0; line-height: 1.5; }
.statblock .sb-section i { color: var(--ink); }

/* sheet header with level-up button */
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.sheet-head .sh-text { min-width: 0; }
#levelUpBtn { flex: 0 0 auto; border-color: var(--accent); color: var(--accent); }
#levelUpBtn:hover { background: rgba(200,162,74,.15); }
#levelUpBtn.ready { background: var(--accent); color: #1a1400; border-color: var(--accent); animation: lvlpulse 1.4s ease-in-out infinite; }
@keyframes lvlpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(200,162,74,.5); } 50% { box-shadow: 0 0 0 5px rgba(200,162,74,0); } }
.chip.xp-ready b { color: var(--accent); }
.chip.levelup-ready { background: var(--accent); color: #1a1400; font-weight: 700; cursor: pointer; }

/* level-up modal */
#levelBody h2 { margin: 0 0 10px; }
.lvl-arrow { color: var(--accent); font-size: 15px; }
.lvl-sec { margin: 12px 0; }
.lvl-sec h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.lvl-note { color: #5fd07a; margin: 8px 0; font-size: 13px; }
.hp-choice { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.asi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.asi-cell { display: flex; align-items: center; justify-content: space-between; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; }

/* class table */
.ct-tabs { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 12px; }
.ct-scroll { max-height: 60vh; overflow-y: auto; }
.ct-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ct-table th { position: sticky; top: 0; background: var(--panel); text-align: left; padding: 6px 8px; border-bottom: 2px solid var(--border); color: var(--muted); }
.ct-table td { padding: 5px 8px; border-bottom: 1px solid rgba(255,255,255,.04); vertical-align: top; }
.ct-table tbody tr:hover { background: rgba(var(--accent-2-rgb),.06); }
.ct-feat { color: var(--ink); }
.ct-feat:hover { color: var(--accent-2); text-decoration: underline; }

.skill-list { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.skill-list li { display: flex; align-items: center; gap: 7px; padding: 3px 2px; border-bottom: 1px solid rgba(255,255,255,.03); }
.skill-list .sk-name { flex: 1; }
.skill-list b { font-variant-numeric: tabular-nums; }
.pf { width: 9px; height: 9px; border-radius: 50%; border: 1px solid var(--muted); flex: 0 0 auto; }
.pf.on { background: var(--accent); border-color: var(--accent); }
.pf.exp { background: var(--accent-2); border-color: var(--accent-2); box-shadow: 0 0 0 2px rgba(var(--accent-2-rgb),.3); }

.death-saves { display: flex; align-items: center; gap: 12px; margin-top: 8px; font-size: 13px; }
.ds-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1px solid var(--muted); margin: 0 1px; }
.ds-dot.on-succ { background: #5fd07a; border-color: #5fd07a; }
.ds-dot.on-fail { background: var(--hp); border-color: var(--hp); }

.slots-row, .tag-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.slot-pill { background: var(--panel-2); border: 1px solid var(--accent-2); color: var(--accent-2); border-radius: 10px; padding: 2px 9px; font-size: 12px; }
.tag { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-size: 12px; }
.chip.insp { background: rgba(200,162,74,.15); border: 1px solid var(--accent); color: var(--accent); }

.attacks, .feat-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.attacks li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; margin-bottom: 5px; }
.attacks .atk-detail { color: var(--muted); font-size: 12px; }
.feat-list li { padding: 4px 8px; border-left: 2px solid var(--accent-2); margin-bottom: 5px; background: var(--panel-2); border-radius: 0 6px 6px 0; }

.encounter { background: rgba(224,85,107,.08); border: 1px solid var(--hp); border-radius: 10px; padding: 10px; margin-bottom: 14px; }
.enc-head { font-weight: 700; color: var(--hp); margin-bottom: 8px; }
.enemy { margin-bottom: 8px; }
.enemy:last-child { margin-bottom: 0; }
.enemy-top { display: flex; justify-content: space-between; align-items: baseline; }
.bar.bar-enemy .fill { background: var(--hp); }
.badge.sm { font-size: 10px; padding: 1px 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { background: var(--panel-2); border: 1px solid var(--border); border-radius: 14px; padding: 3px 10px; font-size: 12px; }
.chip .ck { color: var(--muted); }
.chip b { color: var(--accent); }
.chip.coin { border-color: var(--accent); background: rgba(200,162,74,.12); }
.status-line { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.badge { background: rgba(224,85,107,.15); color: var(--hp); border: 1px solid var(--hp); border-radius: 12px; padding: 2px 9px; font-size: 11px; }

.meta-row { display: flex; justify-content: space-between; margin-top: 10px; font-size: 14px; }
.gold b { color: var(--accent); }
.status { color: var(--hp); font-size: 12px; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; text-align: center; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-size: 18px; font-weight: 700; }

.slots, .inv, .skills, .events { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.slots li { display: flex; justify-content: space-between; padding: 4px 0; color: var(--muted); }
.slots li b { color: var(--ink); font-weight: 600; }
.inv li, .skills li { padding: 5px 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; margin-bottom: 5px; display: flex; justify-content: space-between; }
.inv li { align-items: flex-start; gap: 8px; }
.inv-name { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.inv-note { font-size: 11px; color: var(--muted); line-height: 1.35; }
.inv .qty { color: var(--accent); flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.inv-name { flex: 1 1 auto; }
/* manual inventory edit controls */
.inv-ctl { flex: 0 0 auto; display: inline-flex; gap: 3px; align-items: center; margin-left: 4px; }
.inv-btn { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px;
  line-height: 1; padding: 3px 5px; border-radius: 5px; opacity: .55; transition: opacity .12s, background .12s, color .12s; }
.inv-btn:hover { opacity: 1; background: var(--panel); color: var(--ink); }
.inv-btn.inv-del:hover { color: var(--danger, #e5484d); background: rgba(229,72,77,.12); }
.inv-add { border: 1px solid var(--border); background: var(--panel-2); color: var(--muted); cursor: pointer;
  font-size: 13px; line-height: 1; width: 22px; height: 22px; border-radius: 5px; vertical-align: middle; margin-left: 4px; }
.inv-add:hover { color: var(--accent); border-color: var(--accent); }
.inv-add-inline { border: none; background: transparent; color: var(--accent); cursor: pointer; font: inherit;
  font-size: 12px; text-decoration: underline; padding: 0 0 0 4px; }
/* add/edit item dialog */
.item-editor-card { text-align: left; min-width: 280px; max-width: 92vw; }
.item-editor-card h3 { margin: 0 0 10px; font-size: 15px; }
.ie-l { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.ie-l input { font: inherit; font-size: 14px; color: var(--ink); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; }
.ie-l input:focus { outline: none; border-color: var(--accent); }
.ie-row { display: flex; gap: 10px; }
.ie-qtyl { flex: 0 0 84px; }
.ie-notel { flex: 1 1 auto; }
.events { counter-reset: ev; }
.events li { padding: 6px 8px; border-left: 2px solid var(--accent); margin-bottom: 6px; background: var(--panel-2); border-radius: 0 6px 6px 0; }

/* Freeform (narrative-only) profile sheet */
body.freeform #engineToggle { display: none; }
.pf-sec { margin-bottom: 14px; }
.pf-h { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 5px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.pf-status { font-size: 13.5px; line-height: 1.5; color: var(--ink); }
.pf-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.pf-list li { font-size: 13px; line-height: 1.45; color: var(--ink); padding-left: 13px; position: relative; }
.pf-list li::before { content: "•"; position: absolute; left: 0; color: var(--accent); }
.pf-empty { font-size: 12.5px; color: var(--muted); font-style: italic; }
.pf-coins { display: flex; gap: 8px; }
.pf-coins .coin { display: inline-flex; align-items: baseline; gap: 1px; font-size: 14px; font-weight: 700;
  font-variant-numeric: tabular-nums; padding: 3px 9px; border-radius: 7px; background: var(--panel-2); border: 1px solid var(--border); }
.pf-coins .coin i { font-style: normal; font-size: 10px; font-weight: 600; color: var(--muted); }
.pf-coins .gp { color: #e8c15a; } .pf-coins .sp { color: #c9cdd6; } .pf-coins .cp { color: #c8895a; }
/* --- Creator Studio (dashboard hub) --- */
.dash-tiles { display: flex; flex-wrap: wrap; gap: 10px; }
.dash-quotas { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 10px; }
.quota { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.quota .quota-track { width: 90px; height: 6px; border-radius: 3px; background: rgba(255,255,255,.08); overflow: hidden; }
.quota .quota-fill { height: 100%; background: var(--accent); }
.quota .quota-fill.high { background: #e6a03c; } .quota .quota-fill.full { background: #dc5050; }
.quota b { color: var(--text); }
.dash-section { margin-top: 22px; }
.dash-section h3 { margin: 0 0 10px; }
.dash-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.dash-lore-list { display: flex; flex-direction: column; gap: 8px; }
.badge.warn { background: rgba(220,80,80,.15); border: 1px solid #dc5050; color: #ff8b8b;
  font-size: 10px; padding: 1px 6px; border-radius: 999px; }

/* builder: greeting variants + prompt dialog input */
.cb-greetings { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.cb-greet { display: flex; gap: 6px; align-items: flex-start; }
.cb-greet textarea { flex: 1; }
.prompt-input { width: 100%; margin: 10px 0 4px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border, #2a2d35); background: var(--panel-2, #101216); color: var(--text); }

/* lorebook entry editor: location-lock disclosure */
.le-loc { margin-top: 10px; border-top: 1px solid var(--border, #2a2d35); padding-top: 8px; }
.le-loc summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.le-loc .le-form-row { margin-top: 8px; }

/* Free-trial countdown in the header — clicking it opens Settings to add a key. */
.trial-chip { margin-right: 8px; padding: 4px 10px; border-radius: 999px; cursor: pointer;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: rgba(200,162,74,.12); border: 1px solid var(--accent); color: var(--accent); }
.trial-chip:hover { filter: brightness(1.2); }
.trial-chip.low { background: rgba(230,160,60,.16); border-color: #e6a03c; color: #e6a03c; }
.trial-chip.out { background: rgba(220,80,80,.16); border-color: #dc5050; color: #ff8b8b; }
@media (max-width: 560px) { .trial-chip { font-size: 11px; padding: 3px 8px; } }

.pf-coins .coin.cred { color: #5ad1c9; letter-spacing: .3px; }
.money-edit { cursor: pointer; }
.money-edit:hover { filter: brightness(1.15); outline: 1px dashed var(--accent); outline-offset: 2px; border-radius: 6px; }
.me-coins { gap: 8px; } .me-coins .ie-l { flex: 1; }

/* manual Memory box */
.memory-box textarea { width: 100%; resize: vertical; min-height: 70px; font-size: 13px; line-height: 1.45; }
.memory-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.memory-status { margin-right: auto; }

.muted { color: var(--muted); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.75); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 20px; }
.modal.hidden { display: none; }
.hidden { display: none !important; }
.greeting-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.greeting-edit { margin-top: 6px; }
.greeting-edit textarea { width: 100%; background: var(--panel-2); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 8px; font-family: inherit; font-size: 13px; resize: vertical; margin-bottom: 6px; }
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: 420px; max-width: 92vw; max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-card.xwide { width: 900px; max-height: 92vh; overflow-y: auto; }
.modal-card h2 { font-size: 18px; font-weight: 700; }

/* --- 5e character builder --- */
.builder { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
.build-form h4 { margin: 14px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); border-bottom: 1px solid var(--border); padding-bottom: 3px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bf-row { display: grid; grid-template-columns: 1.2fr 1fr 1fr 1fr; gap: 8px; }
.bf-row label, .build-form > label { display: block; font-size: 12px; color: var(--muted); }
.bf-row input, .bf-row select, .build-form select, .build-form input, .build-form textarea { width: 100%; margin-top: 3px; background: var(--panel-2); color: var(--ink); border: 1px solid var(--border); border-radius: 7px; padding: 7px; font-family: inherit; font-size: 13px; }
.bf-traits { margin-top: 6px; font-style: italic; }
.method-btns { display: flex; gap: 5px; }
.mbtn { background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); border-radius: 6px; padding: 3px 8px; font-size: 11px; cursor: pointer; font-weight: 600; }
.mbtn.on { background: var(--accent-2); color: var(--primary-fg); border-color: var(--accent-2); }
.abil-grid-b { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; }
.abil-b { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px; text-align: center; }
.ab-name { font-size: 11px; color: var(--muted); font-weight: 700; }
.abil-b select { width: auto; margin: 3px auto; }
.stepper { display: inline-flex; align-items: center; gap: 8px; margin: 3px 0; }
.stepper button { background: var(--panel); border: 1px solid var(--border); color: var(--ink); border-radius: 5px; width: 22px; height: 22px; cursor: pointer; padding: 0; }
.stepper b { min-width: 18px; display: inline-block; }
.ab-tot { font-size: 13px; font-weight: 700; }
.ab-mod { color: var(--accent-2); }
.ab-race { display: block; font-size: 9px; color: var(--accent); font-weight: 400; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent-2); width: 15px; height: 15px; margin: 0; cursor: pointer; }
/* checkboxes/radios must stay their natural size even inside modals, where
   `.modal-card input { width:100% }` (for text fields) would otherwise stretch them. */
.modal-card input[type="checkbox"], .modal-card input[type="radio"] { width: 15px; height: 15px; flex: 0 0 auto; padding: 0; margin: 0; }
/* plain inline checkbox labels (e.g. Half-Elf ASI picks) */
.ck { font-size: 13px; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.ck input { vertical-align: -2px; }
.ck.granted { color: var(--accent); }

/* modern selectable card grid — skills / expertise / spells */
.skill-pick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 4px; }
.skill-pick.spells { max-height: 260px; overflow-y: auto; padding: 2px; }
.skill-pick .ck {
  display: flex; align-items: center; gap: 9px; margin: 0;
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2);
  transition: border-color .12s ease, background .12s ease, box-shadow .12s ease;
}
.skill-pick .ck:hover { border-color: var(--accent-2); background: var(--panel); }
.skill-pick .ck:has(input:checked) { border-color: var(--accent-2); background: rgba(109,124,255,.14); box-shadow: inset 0 0 0 1px var(--accent-2); }
.skill-pick .ck.granted { color: var(--accent); }
.skill-pick .ck.granted:has(input:checked) { border-color: var(--accent); background: rgba(var(--accent-rgb),.14); box-shadow: inset 0 0 0 1px var(--accent); }
.skill-pick .ck input:disabled { opacity: .6; }
.skill-pick .ck-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skill-pick .ck .muted { flex: 0 0 auto; margin-left: auto; font-size: 11px; padding: 1px 7px; border: 1px solid var(--border); border-radius: 999px; }

.lore-attach .chk { display: inline-flex; align-items: center; }

.build-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.build-preview { background: var(--panel-2); border: 1px solid var(--accent-2); border-radius: 12px; padding: 14px; font-size: 12.5px; }

/* saved-character cards (right rail) */
.persona-cards { display: flex; flex-direction: column; gap: 8px; }
.rail-head { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-top: 2px; }
.persona-card { position: relative; width: 100%; text-align: left; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; cursor: pointer; transition: border-color .12s ease, background .12s ease, box-shadow .12s ease; }
.persona-card:hover { border-color: var(--accent-2); }
.persona-card.active { border-color: var(--accent-2); background: rgba(109,124,255,.14); box-shadow: inset 0 0 0 1px var(--accent-2); }
.persona-card.new { text-align: center; color: var(--accent-2); font-weight: 600; border-style: dashed; background: transparent; }
.persona-card.new:hover { background: rgba(109,124,255,.1); filter: none; }
.pc-name { font-weight: 600; font-size: 14px; color: var(--ink); }
.pc-sub { font-size: 12px; margin-top: 2px; }
.pc-del { position: absolute; top: 7px; right: 7px; padding: 0 6px; font-size: 12px; line-height: 1.7; background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 6px; }
.pc-del:hover { border-color: var(--destructive); color: var(--destructive); background: transparent; filter: none; }
.pv-head b { font-size: 16px; color: var(--accent); }
.pv-stats { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 10px 0; }
.pv-stats b { color: var(--ink); font-size: 14px; }
.pv-stats span { color: var(--muted); }
.pv-abils { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 10px; }
.pv-ab { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 3px 5px; text-align: center; font-size: 11px; }
.pv-ab i { color: var(--muted); font-style: normal; }
.pv-ab b { color: var(--accent-2); }
.pv-line { margin: 5px 0; line-height: 1.4; }
.pv-line i { color: var(--muted); font-style: normal; font-weight: 600; }
.modal-card h2 { margin: 0 0 16px; }
.modal-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.modal-card input, .modal-card textarea { width: 100%; margin-top: 5px; background: var(--panel-2); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 9px; font-family: inherit; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.modal-note { color: var(--muted); font-size: 13px; margin: -6px 0 16px; }
.modal-card small.hint { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.settings-h { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); border-bottom: 1px solid var(--border); padding-bottom: 4px; }
#settingsModal .chk-row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; font-size: 13px; color: var(--ink); cursor: pointer; }
#settingsModal .chk-row input { margin-top: 3px; flex: 0 0 auto; }
.modal-actions .spacer { flex: 1; }
.test-result { font-size: 13px; min-height: 18px; margin: 4px 0 10px; font-family: ui-monospace, monospace; white-space: pre-wrap; word-break: break-word; }
.test-result.ok { color: #5fd07a; }
.test-result.err { color: var(--hp); }
/* BYOK (bring-your-own-key) panel */
#byokStatus { display: block; margin-bottom: 10px; }
#byokStatus.byok-none { color: var(--accent); }
.byok-adv { margin: 6px 0 10px; }
.byok-adv summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.byok-adv label { display: block; margin-top: 8px; }
#adminSettings { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 4px; }

/* Entity managers (characters / personas / lorebooks) */
.modal-card.wide { width: 600px; max-height: 86vh; overflow-y: auto; }
.import-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.import-row .or { color: var(--muted); font-size: 12px; }
.entity-list { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.entity { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.entity-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row-actions { display: flex; align-items: center; gap: 6px; }
button.sm { padding: 4px 10px; font-size: 12px; }
button.danger { background: transparent; border-color: var(--hp); color: var(--hp); }
button.danger-solid { background: var(--destructive); color: #fff; border-color: var(--destructive); }
button.danger-solid:hover { filter: brightness(1.08); }
/* in-app confirmation dialog (replaces native confirm) */
.confirm-modal { z-index: 100; }
.confirm-card { width: 380px; }
.confirm-msg { margin: 0 0 18px; font-size: 14.5px; line-height: 1.5; color: var(--ink); }
.small { font-size: 12px; }
.muted.small, .small.muted { color: var(--muted); }
.lore-attach { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.chk { font-size: 13px; display: inline-flex; align-items: center; gap: 7px; cursor: pointer; padding: 5px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.chk:hover { border-color: var(--accent-2); }
select { width: 100%; margin-top: 5px; background: var(--panel-2); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 9px; font-family: inherit; font-size: 14px; }

.thinking { color: var(--muted); font-style: italic; }
.thinking::after { content: ""; }
.caret { display: inline-block; width: 7px; height: 1.05em; margin-left: 1px; background: var(--accent); vertical-align: text-bottom; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* engine-mode toggle + tool trace */
.composer-actions { display: flex; gap: 8px; align-items: center; }
.engine-toggle { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.engine-toggle:hover { filter: brightness(1.15); }
.engine-toggle.on { background: rgba(var(--accent-2-rgb),.18); color: var(--accent-2); border-color: var(--accent-2); font-weight: 600; }
.tool-trace { margin-top: 8px; font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace; border-top: 1px dashed var(--border); padding-top: 5px; }

/* --- Discovery --- */
/* Full-page discovery home (Stitch layout) */
.disc-page { position: fixed; top: 0; right: 0; bottom: 0; left: var(--sidebar-w); z-index: 9; background: var(--bg); display: flex; flex-direction: column; }
.disc-page.hidden { display: none; }
.disc-topbar { display: flex; align-items: center; gap: 16px; padding: 13px 28px; border-bottom: 1px solid var(--border); background: var(--panel); flex: 0 0 auto; }
.disc-page-title { margin: 0; font-size: 22px; }
.disc-scroll { flex: 1; overflow-y: auto; padding: 24px 28px 64px; }
.disc-section { font-family: var(--font-display); font-size: 20px; margin: 28px 0 14px; }
.disc-scroll > .disc-section:first-child, .disc-scroll .disc-rail-wrap > .disc-section { margin-top: 6px; }
.disc-scroll .discover-grid { max-height: none; overflow: visible; }
.disc-hero { position: relative; min-height: 300px; border-radius: 16px; overflow: hidden; border: 1px solid var(--border); background: var(--panel-2); background-size: cover; background-position: center; display: flex; align-items: flex-end; }
.disc-hero.no-cover { background: radial-gradient(130% 130% at 82% -10%, rgba(var(--accent-rgb),.22), transparent 55%), var(--panel-2); }
.hero-inner { padding: 34px 36px; max-width: 640px; }
.hero-label { color: var(--accent); font-size: 12px; letter-spacing: 1.6px; text-transform: uppercase; font-weight: 700; margin-bottom: 10px; }
.hero-title { font-family: var(--font-display); font-size: 46px; line-height: 1.05; margin: 0 0 12px; text-shadow: 0 2px 24px rgba(0,0,0,.7); }
.hero-meta { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.hero-tagline { font-size: 15px; color: var(--ink); opacity: .9; margin: 0 0 14px; }
.hero-tags { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.hero-tag { background: rgba(0,0,0,.45); border: 1px solid var(--border); color: var(--ink); padding: 4px 12px; border-radius: 999px; font-size: 12px; }
.hero-actions { display: flex; gap: 12px; }
.hero-actions button { padding: 11px 20px; font-size: 14px; }
.disc-rail { display: flex; gap: 16px; overflow-x: auto; padding: 2px 2px 10px; }
.disc-rail .camp-card { flex: 0 0 250px; }
.disc-header { display: flex; align-items: center; gap: 14px; }
.disc-header h2 { margin: 0; }
.disc-tabs { display: flex; gap: 6px; }
.disc-tab { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer; }
.disc-tab.on { background: rgba(var(--accent-2-rgb),.18); color: var(--accent-2); border-color: var(--accent-2); font-weight: 600; }
.discover-controls { display: flex; gap: 10px; margin: 14px 0 10px; }
.discover-controls input { flex: 1 1 auto; min-width: 0; }
.discover-controls select { flex: 0 0 auto; width: auto; min-width: 160px; }
.disc-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.disc-chip { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 4px 11px; font-size: 12px; cursor: pointer; }
.disc-chip:hover { filter: brightness(1.2); }
.disc-chip.on { background: rgba(var(--accent-2-rgb),.2); color: var(--accent-2); border-color: var(--accent-2); }
.discover-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; max-height: 60vh; overflow-y: auto; padding: 2px; }
.camp-card { position: relative; background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; transition: border-color .12s, transform .12s; }
.camp-card:hover { border-color: var(--accent-2); transform: translateY(-2px); }
.camp-cover { height: 120px; margin: -14px -14px 4px; border-radius: 12px 12px 0 0; background-size: cover; background-position: center; background-color: var(--panel); }
.camp-cover.placeholder { display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--panel) 0%, var(--panel-2) 100%); }
.camp-cover.placeholder span { font-family: var(--font-display); font-size: 34px; font-weight: 700; color: rgba(var(--accent-rgb),.5); }
.camp-detail-cover { height: 160px; margin: -4px 0 12px; border-radius: 12px; background-size: cover; background-position: center; background-color: var(--panel-2); }
/* --- Image upload widgets --- */
.cb-cover { display: flex; gap: 12px; align-items: flex-start; }
.cb-cover-img { width: 160px; height: 90px; border-radius: 8px; background-size: cover; background-position: center; background-color: var(--panel); border: 1px solid var(--border); flex: 0 0 auto; }
.cb-cover-img.empty { background: repeating-linear-gradient(45deg, var(--panel), var(--panel) 8px, var(--panel-2) 8px, var(--panel-2) 16px); }
.cb-cover-actions { display: flex; flex-direction: column; gap: 8px; }
.ac-avatar-row { display: flex; gap: 12px; align-items: center; }
.ac-avatar-preview { width: 56px; height: 56px; border-radius: 50%; background-size: cover; background-position: center; background-color: var(--panel-2); border: 1px solid var(--border); flex: 0 0 auto; }
.ac-avatar-preview.empty { background: var(--panel-2); }
.ac-avatar-fields { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.camp-title { font-weight: 700; font-size: 15px; line-height: 1.25; padding-right: 26px; }
.camp-tagline { color: var(--muted); font-size: 13px; line-height: 1.4; flex: 1; }
.camp-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.camp-tag { background: rgba(var(--accent-2-rgb),.12); color: var(--accent-2); border-radius: 999px; padding: 2px 8px; font-size: 11px; }
.camp-foot { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 8px; }
.camp-foot .creator { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.camp-fav { position: absolute; top: 10px; right: 10px; background: none; border: none; font-size: 18px; line-height: 1; cursor: pointer; color: var(--muted); }
.camp-fav.on { color: #ff6b8a; }

/* --- Reviews --- */
.camp-reviews { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.rev-h { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.rev-form { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.rev-stars { display: flex; gap: 3px; margin-bottom: 8px; }
.rev-star { font-size: 20px; color: var(--border); cursor: pointer; line-height: 1; }
.rev-star.on { color: #ffca4a; }
.rev-form textarea { width: 100%; padding: 8px 10px; }
.rev-form-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.rev-list { display: flex; flex-direction: column; gap: 10px; max-height: 34vh; overflow-y: auto; }
.rev-item { border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.rev-item-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.rev-item-stars { color: #ffca4a; font-size: 12px; }
.rev-body { font-size: 13px; color: var(--ink); margin-top: 4px; line-height: 1.4; white-space: pre-wrap; }

/* --- Reporting / moderation --- */
.report-row { margin-top: 10px; }
.report-link { color: var(--muted); cursor: pointer; font-size: 12px; text-decoration: none; }
.report-link:hover { color: var(--hp); text-decoration: underline; }
.report-link.mini { margin-left: auto; font-size: 13px; }
.report-actions { display: flex; gap: 6px; }

/* --- Creator dashboard --- */
.dash-thumb { width: 52px; height: 30px; border-radius: 5px; background-size: cover; background-position: center; background-color: var(--panel-2); }
.dash-thumb.empty { background: repeating-linear-gradient(45deg, var(--panel), var(--panel) 5px, var(--panel-2) 5px, var(--panel-2) 10px); }

/* --- Collections --- */
.coll-new { display: flex; gap: 8px; margin-bottom: 14px; }
.coll-new input { flex: 1; padding: 9px 11px; }
.coll-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.coll-card { position: relative; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; cursor: pointer; transition: border-color .12s; }
.coll-card:hover { border-color: var(--accent-2); }
.coll-name { font-weight: 700; margin-bottom: 4px; padding-right: 20px; }
.coll-del { position: absolute; top: 8px; right: 8px; background: none; border: none; color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .12s; }
.coll-card:hover .coll-del { opacity: 1; }
.coll-del:hover { color: var(--hp); }
.coll-detailhead { margin-bottom: 12px; }
.collect-pop { position: fixed; z-index: 100; width: 240px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.collect-h { font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.collect-list { display: flex; flex-direction: column; gap: 4px; max-height: 200px; overflow-y: auto; margin-bottom: 8px; }
.collect-item { display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.collect-new { display: flex; gap: 6px; border-top: 1px solid var(--border); padding-top: 8px; }
.collect-new input { flex: 1; padding: 6px 8px; font-size: 13px; }
.camp-detail-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.camp-detail-head h2 { margin: 0; }
.camp-detail-meta { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin: 8px 0 12px; flex-wrap: wrap; }
.camp-desc { white-space: pre-wrap; line-height: 1.5; max-height: 40vh; overflow-y: auto; }
/* visibility badge + publish controls in the Library */
.vis-badge { font-size: 11px; border-radius: 999px; padding: 2px 9px; border: 1px solid var(--border); color: var(--muted); }
.vis-badge.public { background: rgba(80,200,120,.15); color: #6fe0a0; border-color: rgba(80,200,120,.4); }
.vis-badge.unlisted { background: rgba(230,180,80,.15); color: #f0c86a; border-color: rgba(230,180,80,.4); }
.publish-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.publish-row select, .publish-row input { padding: 6px 9px; font-size: 13px; }
.publish-row .tagline-in { flex: 1; min-width: 160px; }

/* --- Account settings --- */
.acct-section { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 4px; }
.acct-section label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.acct-section input, .acct-section textarea { padding: 9px 11px; }
.acct-divider { border: none; border-top: 1px solid var(--border); margin: 18px 0 10px; }
#accountModal h3 { margin: 0 0 4px; font-size: 15px; }
#acHandle { font-weight: 400; }

/* --- Admin panel --- */
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; margin: 4px 0 6px; }
.stat-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; text-align: center; }
.stat-n { font-size: 22px; font-weight: 700; color: var(--accent-2); }
.stat-k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 3px; }
.admin-body { max-height: 52vh; overflow: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.admin-table th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
.admin-table tbody tr:hover { background: var(--panel-2); }
.mini-select { padding: 3px 6px; font-size: 12px; border-radius: 6px; background: var(--panel-2); color: var(--ink); border: 1px solid var(--border); }

/* --- Lorebook editor --- */
.le-name { font-size: 18px; font-weight: 700; padding: 8px 12px; min-width: 240px; }
.le-layout { display: flex; gap: 14px; margin: 14px 0; }
.le-sidebar { width: 220px; flex: 0 0 220px; display: flex; flex-direction: column; gap: 8px; }
.le-entry-list { overflow-y: auto; max-height: 44vh; display: flex; flex-direction: column; gap: 3px; }
.le-entry-item { display: flex; align-items: center; gap: 7px; padding: 7px 9px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.le-entry-item:hover { background: var(--panel-2); }
.le-entry-item.on { background: rgba(var(--accent-2-rgb),.16); }
.le-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.le-dot { width: 8px; height: 8px; border-radius: 50%; background: #5ec97a; flex: 0 0 auto; }
.le-dot.off { background: var(--muted); }
.le-dot.const { box-shadow: 0 0 0 2px rgba(240,200,106,.55); }
.le-tag { font-size: 10px; color: #f0c86a; }
.le-form { flex: 1; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; max-height: 44vh; padding-right: 4px; min-width: 0; }
.le-form > label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.le-form input, .le-form textarea, .le-form select { padding: 8px 10px; }
.le-form-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.le-form-row .chk { flex-direction: row; align-items: center; gap: 5px; font-size: 12px; }
.le-test { border-top: 1px solid var(--border); padding-top: 12px; }
.le-test-row { display: flex; gap: 8px; }
.le-test-row input { flex: 1; }
.le-test-result { margin-top: 10px; }
.le-test-summary { margin-bottom: 8px; }
.le-test-list { display: flex; flex-wrap: wrap; gap: 6px; }
.le-test-chip { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); }
.le-test-chip.chosen { background: rgba(80,200,120,.15); border-color: rgba(80,200,120,.4); color: #8fe0a8; }
.le-test-chip.dropped { color: var(--muted); opacity: .7; }

/* --- Chronicle (long-term memory viewer/editor) --- */
.chron-list { display: flex; flex-direction: column; gap: 12px; max-height: 66vh; overflow-y: auto; padding: 2px; }
.chron-item { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; border-left: 3px solid var(--accent); }
.chron-item.off { opacity: .55; }
.chron-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.chron-num { font-family: var(--font-display); font-size: 13px; color: var(--accent); white-space: nowrap; }
.chron-title { flex: 1; font-weight: 600; font-size: 15px; background: transparent; border: none; border-bottom: 1px solid transparent; color: var(--ink); padding: 4px 2px; }
.chron-title:hover, .chron-title:focus { border-bottom-color: var(--border); outline: none; }
.chron-pin { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.chron-summary { width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; color: var(--ink); padding: 9px; font-family: inherit; font-size: 13px; line-height: 1.5; resize: vertical; }
.chron-keys-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.chron-keys-row .material-symbols-outlined { font-size: 18px; color: var(--muted); }
.chron-keys { flex: 1; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; color: var(--accent-2); font-size: 12px; padding: 6px 12px; }

/* --- Character library actions --- */
.pc-actions { position: absolute; top: 6px; right: 6px; display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.persona-card:hover .pc-actions { opacity: 1; }
.pc-mini { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 4px; border-radius: 5px; line-height: 1; }
.pc-mini:hover { background: var(--panel); color: var(--accent-2); }
.pc-actions .pc-del { position: static; top: auto; right: auto; }
.rail-head { display: flex; align-items: center; gap: 8px; }
.rail-head .ghost { margin-left: auto; }

/* --- Campaign builder --- */
.cb-form { display: flex; flex-direction: column; gap: 12px; max-height: 66vh; overflow-y: auto; padding: 4px 2px; }
.cb-form > label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.cb-form input, .cb-form textarea, .cb-form select { padding: 9px 11px; font-size: 14px; }
.cb-form textarea { resize: vertical; }
.cb-row { display: flex; gap: 14px; flex-wrap: wrap; }
.cb-row > label { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.cb-adv { border: 1px solid var(--border); border-radius: 9px; padding: 6px 12px; }
.cb-adv summary { cursor: pointer; font-size: 13px; color: var(--muted); padding: 4px 0; }
.cb-adv[open] { padding-bottom: 12px; }
.cb-adv label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.cb-lorebooks { display: flex; flex-wrap: wrap; gap: 6px 16px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.cb-lorebooks .chk { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }
.cb-preview { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.cb-preview-out { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; line-height: 1.5; max-height: 30vh; overflow-y: auto; }
.cb-preview-row { display: flex; gap: 8px; }
.cb-preview-row input { flex: 1; padding: 8px 10px; }
.prev-you { color: var(--muted); margin-bottom: 6px; }
.prev-dm { color: var(--ink); line-height: 1.5; }

/* --- Creator profile --- */
.creator-link { color: var(--accent-2); cursor: pointer; text-decoration: none; }
.creator-link:hover { text-decoration: underline; }
.prof-head { display: flex; gap: 16px; align-items: center; margin: 8px 0 6px; }
.prof-avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.prof-avatar.ph { display: flex; align-items: center; justify-content: center; background: var(--panel-2); border: 1px solid var(--border); font-size: 26px; font-weight: 700; color: var(--accent-2); }
.prof-meta { display: flex; flex-direction: column; gap: 4px; }
.prof-handle { color: var(--muted); font-size: 13px; }
.prof-bio { font-size: 14px; line-height: 1.4; }
.prof-stats { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 2px; }
.prof-h3 { margin: 14px 0 10px; font-size: 15px; }

/* ============================================================
   Responsive: phones & small tablets (kept LAST so it wins)
   ============================================================ */
@media (max-width: 820px) {
  .mobile-only { display: inline-flex !important; }
  .desktop-only { display: none !important; }
  body:has(#sidebar) { padding-left: 0; }
  /* Composer: give the input the full row; the Engine/Send buttons drop below it
     so the placeholder/text isn't squeezed and clipped on narrow screens. */
  #composer { flex-wrap: wrap; padding: 10px 12px; gap: 8px;
    /* clear the home indicator + rounded corners in a full-bleed standalone PWA */
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right)); }
  #input { flex: 1 1 100%; min-height: 46px; }
  .composer-actions { flex: 1 1 100%; justify-content: flex-end; }
  .composer-actions #sendBtn { flex: 1; }
  /* Zoom out on phones: smaller reading text + tighter gutters so more fits. */
  .chat { padding: 12px 12px; gap: 10px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right)); }
  .chat, #composer, .combat-bar, .chat-notice { max-width: 100%; }
  .msg { max-width: 94%; font-size: 14px; line-height: 1.5; padding: 10px 12px; }
  .msg.assistant .syslog { font-size: 11.5px; }
  .msg.user { font-size: 14px; }
  /* bottom tab bar + z-index layering (nav < backdrop < drawers < modals) */
  /* bottom bar is hidden during immersive chat; it appears on the browse/explore
     screen (Discovery). From the chat, navigation is via the top hamburger. */
  .mobile-tabs { display: none; position: fixed; left: 0; right: 0; bottom: 0; height: 58px; background: var(--panel); border-top: 1px solid var(--border); z-index: 24; padding-bottom: env(safe-area-inset-bottom, 0); }
  body:has(#discoverModal:not(.hidden)) .mobile-tabs { display: flex; }
  .mobile-tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: none; border: none; border-radius: 0; color: var(--muted); font-size: 10px; font-weight: 500; font-family: inherit; }
  .mobile-tabs button:hover { filter: none; color: var(--ink); }
  .mobile-tabs button.on { color: var(--accent-2); }
  .mobile-tabs button .material-symbols-outlined { font-size: 22px; }
  .mobile-tabs .mt-cta { flex: 0 0 60px; }
  .mobile-tabs .mt-cta .material-symbols-outlined { display: flex; align-items: center; justify-content: center; width: 46px; height: 46px; margin-top: -16px; border-radius: 50%; background: var(--accent-2); color: var(--primary-fg); font-size: 26px; box-shadow: 0 4px 14px rgba(0,0,0,.45); }
  .disc-scroll { padding-bottom: 74px; }
  .drawer-backdrop { z-index: 26; }
  #sidebar, #sheet { z-index: 30; }
  .modal { z-index: 40; }
  /* left sidebar becomes an off-canvas drawer */
  #sidebar { transform: translateX(-100%); transition: transform .22s ease; z-index: 30; box-shadow: 0 0 44px rgba(0,0,0,.6); width: min(260px, 84vw); }
  body.nav-open #sidebar { transform: translateX(0); }
  /* chat goes full width; the character sheet becomes a right drawer */
  main { grid-template-columns: minmax(0, 1fr); }
  #chatCol { border-right: none; }
  #sheet { position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 90vw); transform: translateX(100%); transition: transform .22s ease; z-index: 30; border-left: 1px solid var(--border); box-shadow: 0 0 44px rgba(0,0,0,.6); }
  body.sheet-open #sheet { transform: translateX(0); }
  /* full-page discovery spans the screen */
  .disc-page { left: 0; }
  .disc-topbar { padding: 12px 16px; flex-wrap: wrap; gap: 10px; }
  .disc-page-title { font-size: 18px; }
  .disc-scroll { padding: 16px 16px 48px; }
  .disc-hero { min-height: 220px; }
  .hero-title { font-size: 30px; }
  .hero-inner { padding: 22px 20px; }
  .disc-rail .camp-card { flex-basis: 200px; }
  /* modals fill the screen; multi-column inner layouts stack */
  .modal { padding: 10px; align-items: flex-start; }
  .modal-card, .modal-card.wide, .modal-card.xwide { width: 100%; max-width: 100%; padding: 18px; }
  .builder { grid-template-columns: 1fr; }
  .best-layout { grid-template-columns: 1fr; height: auto; }
  .best-list { max-height: 30vh; }
  .best-detail { max-height: 46vh; }
  .le-layout { flex-direction: column; }
  .le-sidebar { width: 100%; flex: 1 1 auto; }
  .two-col { grid-template-columns: 1fr; }
  .discover-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .discover-controls { flex-wrap: wrap; }
  .discover-controls select { flex: 1 1 auto; min-width: 130px; }
  .admin-body { overflow-x: auto; }
  .cb-cover { flex-wrap: wrap; }
}
