/* ============================================================
   EMBER — design system
   Palette: pornhub-style minimalism. Near-black surfaces,
   white/black contrast buttons, one pastel accent per character.
   Typography: Fraunces (display serif) + DM Sans (body grotesk).
   ============================================================ */

:root {
  /* surfaces */
  --bg: #0a0a0b;
  --surface-1: #131316;
  --surface-2: #1b1b20;
  --surface-3: #25252b;
  --border: #2a2a30;
  --border-strong: #3a3a42;
  --border-focus: #5a5a66;

  /* text */
  --fg: #fafafa;
  --fg-muted: #a4a4ab;
  --fg-dim: #6a6a72;
  --fg-faint: #4a4a52;

  /* brand single-accent (used very sparingly) */
  --brand: #e9d5a1;          /* pale gold — fantasy-coded */
  --brand-strong: #f5e6b8;
  --brand-on: #1a1505;       /* text color on --brand */

  /* per-character accent (overridden inline via --accent) */
  --accent: #e9d5a1;
  --accent-on: #0a0a0b;

  /* status */
  --danger: #f87171;
  --success: #86efac;
  --warning: #fcd34d;

  /* type */
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-body: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "JetBrains Mono", "SF Mono", monospace;

  /* spacing (8pt) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;
  --s-8: 40px;
  --s-9: 48px;
  --s-10: 64px;
  --s-11: 80px;
  --s-12: 96px;

  /* radius */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-pill: 999px;

  /* shadow */
  --shadow-1: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 0 0 1px var(--border);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-3: 0 12px 48px rgba(0, 0, 0, 0.6);

  /* motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* fluid spacing — scales hero/section/gutter padding with viewport */
  --pad-section: clamp(32px, 6vw, 64px);
  --pad-hero:    clamp(40px, 9vw, 96px);
  --pad-gutter:  clamp(16px, 3vw, 24px);
}

/* ---------------- reset ---------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: dark; -webkit-font-smoothing: antialiased; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  font-weight: 400;
  font-feature-settings: "ss01", "cv11";
  min-height: 100vh;
}
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
::selection { background: var(--brand); color: var(--brand-on); }

/* subtle film-grain texture for warmth (disabled on iOS — causes compositing bugs) */
body::before {
  content: "";
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='1' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: -1;
  opacity: 0.4;
}
@supports (-webkit-touch-callout: none) {
  /* iOS Safari — disable grain texture completely */
  body::before { display: none; }
  /* iOS Safari — solid header, no backdrop-filter issues */
  .header {
    background: var(--surface-1) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    position: fixed !important;
    top: 0; left: 0; right: 0;
    z-index: 9999 !important;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }
  body {
    padding-top: calc(60px + env(safe-area-inset-top, 0px));
  }
}
body > * { position: relative; z-index: 1; }
.header { position: relative; z-index: 9999; }

/* ---------------- typography ---------------- */
.h-display { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.02em; line-height: 1.05; font-variation-settings: "opsz" 144, "SOFT" 30; }
.h-display-lg { font-size: clamp(40px, 6vw, 72px); }
.h-display-md { font-size: clamp(28px, 4vw, 44px); }
h1, .h1 { font-family: var(--font-display); font-size: 32px; line-height: 1.15; font-weight: 600; letter-spacing: -0.015em; margin: 0; }
h2, .h2 { font-family: var(--font-display); font-size: 22px; line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h3, .h3 { font-size: 16px; line-height: 1.3; font-weight: 600; margin: 0; letter-spacing: -0.005em; }
.muted { color: var(--fg-muted); }
.dim { color: var(--fg-dim); }
.label {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--fg-dim);
}
.mono { font-family: var(--font-mono); font-size: 12px; }

/* ---------------- layout ---------------- */
.container { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 var(--pad-gutter); }
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.row { display: flex; align-items: center; gap: var(--s-3); }
.spread { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); }
.divider { height: 1px; background: var(--border); margin: var(--s-7) 0; }

/* ---------------- standardized page header (use on every page top) ---------------- */
.page-head {
  padding: var(--pad-section) 0 var(--s-6);
}
.page-head h1 { margin: 0; }
.page-head .label { display: block; margin-bottom: 8px; }
.page-head p {
  max-width: 60ch;
  margin: var(--s-3) 0 0;
  font-size: 16px;
  line-height: 1.6;
  color: var(--fg-muted);
}

/* ---------------- header ---------------- */
.header {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
}
.header-inner {
  display: flex; align-items: center; gap: var(--s-7);
  height: 60px;
}
.brand-mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
  display: inline-flex; align-items: center; gap: var(--s-2);
}
.brand-mark::before {
  content: "";
  width: 14px; height: 14px;
  background: var(--brand);
  border-radius: 3px;
  transform: rotate(45deg);
}
.brand-beta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-dim);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 2px 5px;
  margin-left: var(--s-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.nav-tabs { display: flex; gap: var(--s-2); margin-left: var(--s-4); }
.nav-tab {
  padding: 8px 14px;
  border-radius: var(--r-md);
  font-size: 14px; font-weight: 500;
  color: var(--fg-muted);
  background: transparent;
  border: none;
  transition: all 0.15s var(--ease);
}
.nav-tab:hover { color: var(--fg); background: var(--surface-1); }
.nav-tab[aria-current="true"] { color: var(--fg); background: var(--surface-2); }
.header-spacer { flex: 1; }
.header-actions { display: flex; align-items: center; gap: var(--s-2); }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2);
  height: 38px;
  padding: 0 16px;
  border-radius: var(--r-md);
  font-size: 14px; font-weight: 600;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg);
  transition: all 0.15s var(--ease);
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.btn-primary:hover { background: var(--brand); color: var(--brand-on); border-color: var(--brand); }

.btn-accent {
  background: var(--accent);
  color: var(--accent-on);
  border-color: var(--accent);
}

.btn-secondary {
  background: var(--surface-1);
  border-color: var(--border);
  color: var(--fg);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-strong); }

.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
}
.btn-ghost:hover { background: var(--surface-1); color: var(--fg); }

.btn-icon {
  width: 38px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.btn-icon-lg {
  width: 40px; height: 40px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg);
  cursor: pointer;
  transition: all 0.15s var(--ease);
  flex-shrink: 0;
}
.btn-icon-lg:hover { border-color: var(--border-strong); background: var(--surface-3); color: var(--brand); }
.btn-icon-lg .icon { width: 18px; height: 18px; }
.icon { display: inline-block; vertical-align: middle; flex-shrink: 0; }

.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; border-radius: var(--r-sm); }
.btn-lg { height: 48px; padding: 0 22px; font-size: 15px; border-radius: var(--r-lg); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---------------- inputs ---------------- */
.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field-label {
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
}
.field-label .req { color: var(--brand); }
.field-help {
  font-size: 12px;
  color: var(--fg-dim);
  line-height: 1.5;
}
.input, .select {
  width: 100%;
  height: 38px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0 12px;
  font-size: 14px;
  color: var(--fg);
  transition: all 0.15s var(--ease);
  font-family: inherit;
}
.textarea {
  width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--fg);
  transition: all 0.15s var(--ease);
  font-family: inherit;
}
.input:disabled { color: var(--fg-muted); cursor: not-allowed; }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--border-focus);
  background: var(--surface-2);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.input::placeholder, .textarea::placeholder { color: var(--fg-faint); }
.row-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-4);
  align-items: start;
}
.row-fields .field { align-self: start; }
@media (max-width: 640px) { .row-fields { grid-template-columns: 1fr; } }

/* ---------------- chips/tags ---------------- */
.chip {
  display: inline-flex; align-items: center;
  min-height: 30px;
  padding: 4px 12px;
  border-radius: var(--r-pill);
  font-size: 12px; font-weight: 500;
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  transition: all 0.15s var(--ease);
}
.chip:hover { background: var(--surface-2); color: var(--fg); }
.chip.is-on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chip-x { margin-left: 6px; opacity: 0.6; cursor: pointer; }
.chip-x:hover { opacity: 1; }

/* ---------------- card / character ---------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr));
  gap: var(--s-5);
}
@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}
@media (min-width: 960px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}
.char-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: all 0.2s var(--ease);
  display: flex; flex-direction: column;
  position: relative;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(255,255,255,0.06);
}
.char-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-3px);
  box-shadow: var(--shadow-3);
}
@media (hover: none) {
  .char-card:hover {
    transform: none;
    box-shadow: none;
  }
}
.char-card-cover {
  position: relative;
  aspect-ratio: 4/5;
  background: var(--surface-2);
  overflow: hidden;
}
.char-card-cover img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform 0.4s var(--ease);
}
.char-card:hover .char-card-cover img { transform: scale(1.04); }
.char-card-fallback {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-size: 56px; font-weight: 700;
  color: var(--accent-on);
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #000));
}
.char-card-accent {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--accent);
}
.char-card-tag {
  position: absolute; top: 12px; right: 12px;
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  background: rgba(0,0,0,0.7);
  border: 1px solid rgba(255,255,255,0.12);
  backdrop-filter: blur(8px);
  padding: 4px 8px;
  border-radius: var(--r-pill);
  color: var(--fg);
}
.char-card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.char-card-name {
  font-family: var(--font-display);
  font-size: 18px; font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: var(--fg);
}
.char-card-tagline {
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.char-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}
.char-card-chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.char-card-chip.is-more { color: var(--fg-dim); font-family: var(--font-mono); }
.char-card-foot {
  display: flex; align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  margin-top: auto;
  border-top: 1px solid var(--border);
}
.char-card-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-dim);
}
.char-card-creator {
  font-size: 12px;
  color: var(--fg-dim);
}

/* "create your own" card */
.char-card.create-card {
  background:
    repeating-linear-gradient(45deg, transparent 0 8px, rgba(255,255,255,0.02) 8px 9px),
    var(--surface-1);
  border-style: dashed;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--s-9) var(--s-4);
  min-height: 100%;
}
.create-card-plus {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 1.5px solid var(--brand);
  display: grid; place-items: center;
  margin: 0 auto var(--s-4);
  font-size: 28px;
  color: var(--brand);
}
.create-card-title {
  font-family: var(--font-display);
  font-size: 20px;
  margin-bottom: var(--s-2);
}

/* ---------------- hero ---------------- */
.hero {
  padding: var(--pad-hero) 0 var(--pad-section);
  text-align: center;
}
.hero-eyebrow {
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--fg-dim);
  margin-bottom: var(--s-4);
}
.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(40px, 7vw, 88px);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.0;
  margin: 0 auto;
  max-width: 14ch;
  font-variation-settings: "opsz" 144, "SOFT" 50;
}
.hero h1 em {
  font-style: italic;
  color: var(--brand);
  font-variation-settings: "opsz" 144, "SOFT" 80;
}
.hero-sub {
  margin: var(--s-6) auto 0;
  max-width: 52ch;
  font-size: 17px;
  line-height: 1.6;
  color: var(--fg-muted);
}
.hero-actions {
  margin-top: var(--s-7);
  display: flex; justify-content: center; gap: var(--s-3); flex-wrap: wrap;
}

/* section heads */
.section { padding: var(--pad-section) 0; }
.section-head {
  display: flex; align-items: end; justify-content: space-between;
  margin-bottom: var(--s-6);
  gap: var(--s-4);
  flex-wrap: wrap;
}
.section-head .label { display: block; margin-bottom: 8px; }

/* ---------------- chat layout ---------------- */
.chat-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100vh - 60px);
  height: calc(100dvh - 60px);
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--pad-gutter);
  box-sizing: border-box;
  gap: 0;
}
@media (max-width: 880px) {
  .chat-shell { grid-template-columns: 1fr; padding: 0; }
}

/* mobile chat list drawer trigger — visible only when off-canvas mode is active */
.chat-drawer-toggle {
  display: none;
  width: 38px; height: 38px;
  align-items: center; justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--fg);
  flex-shrink: 0;
  transition: all 0.15s var(--ease);
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(255,255,255,0.06);
  touch-action: manipulation;
}
.chat-drawer-toggle:hover { background: var(--surface-3); border-color: var(--border-strong); }
.chat-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 59;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fadeIn 0.18s var(--ease);
}

.chat-sidebar {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg) 0 0 var(--r-lg);
  border-right: none;
  overflow-y: auto;
  padding: var(--s-6);
  margin: var(--s-4) 0;
}
.chat-main {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 0 var(--r-lg) var(--r-lg) 0;
  margin: var(--s-4) 0;
  overflow: hidden;
}
@media (max-width: 880px) {
  .chat-drawer-toggle { display: inline-flex; }
  .chat-sidebar {
    position: fixed;
    top: calc(60px + env(safe-area-inset-top, 0px)); bottom: 0; left: 0;
    width: min(320px, 86vw);
    margin: 0;
    border-radius: 0;
    border: none;
    border-right: 1px solid var(--border);
    z-index: 60;
    transform: translateX(-105%);
    transition: transform 0.28s var(--ease);
    background: var(--surface-1);
    overflow-y: auto;
  }
  .chat-sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow-3); }
  .chat-main {
    margin: 0;
    border-radius: 0;
    border-left: none;
    min-height: calc(100dvh - 60px);
  }
}
.chat-sidebar-cover {
  aspect-ratio: 4/5;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface-2);
  margin-bottom: var(--s-4);
  position: relative;
  border: 1px solid var(--border);
}
.chat-sidebar-cover img { width: 100%; height: 100%; object-fit: cover; }
.chat-side-name { font-family: var(--font-display); font-size: 22px; font-weight: 600; line-height: 1.15; }
.chat-side-tagline { font-size: 13px; color: var(--fg-muted); margin-top: var(--s-2); line-height: 1.5; }
.chat-side-meta {
  display: flex; gap: var(--s-3); margin-top: var(--s-4);
  font-family: var(--font-mono); font-size: 11px;
  color: var(--fg-dim);
}

.chat-main { display: flex; flex-direction: column; min-width: 0; }
.chat-main .chat-bar { background: transparent; }
.chat-main .chat-input { background: transparent; }

/* Focus mode: scene background active → hide sidebar, centre the chat */
.chat-shell.has-bg {
  grid-template-columns: 1fr;
}
.chat-shell.has-bg .chat-sidebar {
  display: none;
}
.chat-shell.has-bg .chat-main {
  max-width: 880px;
  margin: var(--s-4) auto;
  border-radius: var(--r-lg);
  background: rgba(19, 19, 22, 0.78);
  backdrop-filter: blur(8px) saturate(140%);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
}
.chat-shell.has-bg .chat-bar {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}
.chat-shell.has-bg .chat-input {
  border-top-color: rgba(255, 255, 255, 0.08);
}
.chat-bar {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-6);
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  min-height: 60px;
}
.chat-bar-actions {
  display: flex; align-items: center; gap: var(--s-2);
}
.chat-bar-status {
  font-family: var(--font-mono); font-size: 11px; color: var(--fg-dim);
  display: inline-flex; align-items: center; gap: 6px;
}
.chat-bar-status::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 25%, transparent);
}
.chat-stream {
  flex: 1; overflow-y: auto;
  padding: var(--s-7) var(--s-6);
  display: flex; flex-direction: column; gap: var(--s-6);
  max-width: 760px; margin: 0 auto; width: 100%;
}

.msg { display: flex; gap: var(--s-3); align-items: flex-start; }
.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-size: 14px; font-weight: 600;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg-body { flex: 1; min-width: 0; }
.msg-name {
  font-size: 12px; font-weight: 600;
  color: var(--fg-muted);
  margin-bottom: 4px;
}
.msg-content {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--fg);
}
.msg.is-user .msg-content {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--fg);
}
.msg-content em {
  color: var(--fg-muted);
  font-style: italic;
}

.msg-actions {
  margin-top: 8px;
  display: flex; gap: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.msg:hover .msg-actions { opacity: 1; }
.msg-action {
  padding: 6px 10px;
  min-width: 30px;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  font-size: 11px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
}
.msg-action:hover { background: var(--surface-2); color: var(--fg); }
.msg-action.starred { color: var(--brand); border-color: var(--brand); }

/* typing indicator — refined wave */
.msg.is-typing .msg-content {
  background: var(--surface-2);
  border-color: var(--border);
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 16px;
}
.typing-waves {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 20px;
}
.typing-waves span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent), 0 0 12px var(--accent);
  opacity: 0.25;
  animation: typingWave 1.2s infinite ease-in-out both;
  position: relative;
}
.typing-waves span:nth-child(1) { animation-delay: -0.24s; }
.typing-waves span:nth-child(2) { animation-delay: -0.12s; }
.typing-waves span:nth-child(3) { animation-delay: 0s; }
@keyframes typingWave {
  0%, 80%, 100% { transform: translateY(6px) scale(0.6); opacity: 0.25; box-shadow: 0 0 3px var(--accent), 0 0 6px var(--accent); }
  40% { transform: translateY(-8px) scale(1.1); opacity: 1; box-shadow: 0 0 10px var(--accent), 0 0 20px var(--accent); }
}
.typing-waves span::after {
  content: '';
  position: absolute;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  animation: typingTrail 1.2s infinite ease-in-out both;
}
@keyframes typingTrail {
  0%, 100% { transform: scale(1); opacity: 0; }
  50% { transform: scale(2.5); opacity: 0.15; }
}

.chat-input {
  border-top: 1px solid var(--border);
  padding: var(--s-4) var(--s-6);
  background: var(--surface-1);
}
.chat-input-wrap {
  display: flex; align-items: flex-end; gap: var(--s-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 8px;
  max-width: 760px; margin: 0 auto;
  transition: border-color 0.15s var(--ease);
}
.chat-input-wrap:focus-within { border-color: var(--border-focus); }
.chat-input-text {
  flex: 1;
  background: transparent;
  border: none;
  resize: none;
  padding: 8px 10px;
  font-size: 15px; line-height: 1.5;
  color: var(--fg);
  outline: none;
  min-height: 40px;
  max-height: 200px;
  font-family: var(--font-body);
}
.chat-input-text::placeholder { color: var(--fg-faint); }
.chat-input-actions { display: flex; gap: 4px; align-items: center; }
.chat-disclosure {
  text-align: center;
  font-size: 11px; color: var(--fg-dim);
  margin-top: var(--s-2);
}

/* ---------------- create page ---------------- */
.create-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(280px, 28vw, 360px);
  gap: var(--s-7);
  padding: var(--pad-section) 0;
  align-items: start;
}
@media (max-width: 960px) { .create-shell { grid-template-columns: 1fr; gap: var(--s-6); } }

.form-section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-6);
  margin-bottom: var(--s-5);
}
.form-section-head { margin-bottom: var(--s-5); }
.form-section-title { font-family: var(--font-display); font-size: 22px; font-weight: 600; line-height: 1.2; }
.form-section-sub { font-size: 13px; color: var(--fg-muted); margin-top: 4px; }
.form-section > .field + .field { margin-top: var(--s-4); }
.form-section > .row-fields + .field,
.form-section > .field + .row-fields { margin-top: var(--s-4); }
/* nested fields inside grids stay flush — the grid handles spacing */
.row-fields > .field { margin-top: 0 !important; }

.locked-banner {
  display: flex; gap: var(--s-3); align-items: flex-start;
  background: color-mix(in srgb, var(--brand) 10%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--brand) 30%, var(--border));
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  font-size: 13px;
  color: var(--fg-muted);
  margin-bottom: var(--s-4);
}
.locked-banner b { color: var(--brand); font-weight: 600; }

/* image manager */
.images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--s-3);
  margin-top: var(--s-4);
}
.image-tile {
  position: relative;
  aspect-ratio: 4/5;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.image-tile:hover { border-color: var(--border-strong); }
.image-tile.is-primary { border-color: var(--brand); border-width: 2px; }
.image-tile img { width: 100%; height: 100%; object-fit: cover; }
.image-tile-badge {
  position: absolute; bottom: 6px; left: 6px;
  background: rgba(0,0,0,0.75);
  font-size: 9px; font-family: var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 6px;
  border-radius: var(--r-xs);
  color: var(--fg);
}
.image-tile-x {
  position: absolute; top: 6px; right: 6px;
  background: rgba(0,0,0,0.75);
  border: none;
  color: var(--fg);
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 14px; line-height: 1;
  display: grid; place-items: center;
  cursor: pointer;
}

.image-add-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
  margin-top: var(--s-4);
}
.image-empty {
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--s-7) var(--s-4);
  text-align: center;
  color: var(--fg-dim);
  font-size: 13px;
}

/* preview rail (right column) */
.preview-rail {
  position: sticky; top: 80px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.preview-cover {
  aspect-ratio: 4/5;
  background: var(--surface-2);
  position: relative;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-size: 64px; font-weight: 600;
  color: var(--fg-faint);
}
.preview-cover img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.preview-meta { padding: var(--s-5); }
.preview-name { font-family: var(--font-display); font-size: 22px; font-weight: 600; line-height: 1.2; }
.preview-tagline { font-size: 13px; color: var(--fg-muted); margin-top: var(--s-2); line-height: 1.5; }
.preview-tags { margin-top: var(--s-4); display: flex; flex-wrap: wrap; gap: 6px; }

/* color picker swatches */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 32px; height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--c);
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.swatch:hover { transform: scale(1.1); }
.swatch.is-on { border-color: var(--fg); box-shadow: 0 0 0 1px var(--bg); }

/* aesthetic style options */
.style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.style-option {
  padding: 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all 0.15s var(--ease);
  text-align: left;
}
.style-option:hover { border-color: var(--border-strong); background: var(--surface-2); }
.style-option.is-on { border-color: var(--fg); background: var(--surface-2); }
.style-option-title { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.style-option-sub { font-size: 11px; color: var(--fg-dim); }

/* spinner */
.spin {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--fg);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* toast */
.toasts {
  position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  font-size: 13px;
  box-shadow: var(--shadow-3);
  pointer-events: auto;
  animation: toast-in 0.2s var(--ease);
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* footer */
.footer {
  margin-top: var(--s-12);
  padding: var(--s-7) 0;
  border-top: 1px solid var(--border);
  color: var(--fg-dim);
  font-size: 12px;
}
.footer-inner { display: flex; justify-content: space-between; align-items: center; gap: var(--s-4); flex-wrap: wrap; }
.footer-links { display: flex; gap: var(--s-4); }
.footer a:hover { color: var(--fg); }

/* ---------------- drawers (chat settings) ---------------- */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease);
}
.drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 12px; right: 12px; bottom: 12px;
  width: 420px;
  max-width: calc(100vw - 24px);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  z-index: 90;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-3);
  transform: translateX(calc(100% + 12px));
  transition: transform 0.3s var(--ease);
}
.drawer.is-open { transform: translateX(0); }

.drawer-head {
  display: flex; align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer-title {
  font-size: 16px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.drawer-title-icon { opacity: 0.7; }
.drawer-x {
  margin-left: auto;
  background: transparent; border: none;
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  color: var(--fg-muted);
  font-size: 18px;
  cursor: pointer;
  display: grid; place-items: center;
}
.drawer-x:hover { background: var(--surface-2); color: var(--fg); }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 20px;
}

.drawer-foot {
  display: flex; justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* tabs (backend selector) */
.tabs {
  display: flex; gap: 6px;
  padding: 14px 0;
}
.tab {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: var(--r-md);
  font-size: 13px; font-weight: 500;
  color: var(--fg-muted);
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.tab:hover { color: var(--fg); border-color: var(--border-strong); }
.tab.is-on {
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  border-color: color-mix(in srgb, var(--brand) 50%, var(--border));
}

/* accordion */
.acc {
  border-bottom: 1px solid var(--border);
}
.acc-head {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  padding: 14px 0;
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.acc-head:hover { color: var(--brand); }
.acc-head .label-icon { display: inline-flex; align-items: center; gap: 8px; }
.acc-arrow {
  color: var(--fg-muted);
  font-size: 12px;
  transition: transform 0.2s var(--ease);
}
.acc.is-open .acc-arrow { transform: rotate(180deg); }
.acc-body {
  display: none;
  padding: 0 0 16px;
}
.acc.is-open .acc-body { display: block; }

/* toggle */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px; font-weight: 600;
}
.toggle {
  position: relative;
  width: 40px; height: 22px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  border: none;
  cursor: pointer;
  transition: background 0.2s var(--ease);
  padding: 0;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--fg);
  transition: transform 0.2s var(--ease);
}
.toggle.is-on { background: color-mix(in srgb, var(--brand) 70%, var(--surface-3)); }
.toggle.is-on::after { transform: translateX(18px); background: var(--brand); }

/* slider with value */
.slider-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.slider-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: var(--r-xs);
  min-width: 50px; text-align: center;
}
.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--surface-3);
  border-radius: var(--r-pill);
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
  border: none;
}
.slider::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
  border: none;
}

/* color row */
.color-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.color-row:last-child { border-bottom: none; }
.color-row-label { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.color-swatch {
  width: 22px; height: 22px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.color-swatch input {
  position: absolute; inset: 0;
  opacity: 0; cursor: pointer;
}

/* preview pane */
.preview-pane {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px;
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 14px;
}
.preview-pane .label { display: block; margin-bottom: 6px; color: var(--fg-dim); }

/* ---------------- auth modal ---------------- */
.auth-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
}
.auth-modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 400px; max-width: calc(100vw - 32px);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  padding: 32px 28px;
  z-index: 101;
  box-shadow: var(--shadow-3);
}
.auth-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  color: var(--fg-muted);
  cursor: pointer;
}
.auth-close:hover { background: var(--surface-2); color: var(--fg); }
.btn-with-icon {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
.btn-with-icon .icon { flex-shrink: 0; }
.auth-h {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
  margin: 0;
}
.auth-divider {
  display: flex; align-items: center;
  gap: 12px;
  margin: 20px 0 0;
  color: var(--fg-dim);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1;
  height: 1px; background: var(--border);
}
.auth-avatar {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent, var(--brand));
  color: var(--bg);
  font-weight: 600; font-size: 12px;
}

/* storyteller / world cards */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
  gap: var(--s-5);
}
@media (min-width: 768px) {
  .tile-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}
@media (min-width: 1024px) {
  .tile-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}
.tile {
  display: block;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-6);
  transition: all 0.2s var(--ease);
  position: relative;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
}
.tile:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow-2); }
.tile-accent {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--accent, var(--brand));
}
.tile-eyebrow {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--fg-dim);
  margin-bottom: 8px;
}
.tile-title {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.tile-blurb {
  margin-top: var(--s-3);
  font-size: 14px; line-height: 1.55;
  color: var(--fg-muted);
}
.tile-foot {
  margin-top: var(--s-5);
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--font-mono); font-size: 11px;
  color: var(--fg-dim);
}
.storyteller-avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--accent, var(--brand));
  color: var(--bg);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-size: 28px; font-weight: 600;
  margin-bottom: var(--s-4);
}
.storyteller-handle {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-dim);
  margin-top: 2px;
}

/* ---------------- versions list ---------------- */
.versions-list { display: flex; flex-direction: column; gap: var(--s-3); }
.version-row {
  display: flex;
  gap: var(--s-4);
  align-items: flex-start;
  padding: var(--s-4) var(--s-5);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.version-row.is-current {
  border-color: color-mix(in srgb, var(--brand) 35%, var(--border));
  background: color-mix(in srgb, var(--brand) 4%, var(--surface-1));
}
.version-row-num {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center; justify-content: center;
  min-width: 38px; height: 38px;
  padding: 0 10px;
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--fg-muted);
  border: 1px solid var(--border);
}
.version-row.is-current .version-row-num {
  background: var(--brand);
  color: var(--brand-on);
  border-color: var(--brand);
}
.version-row-body { flex: 1; min-width: 0; }
.version-row-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.version-row-title { font-size: 14px; font-weight: 600; }
.version-row-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-dim);
}
.version-row-note {
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.55;
  white-space: pre-wrap;
}
.version-row-actions {
  margin-top: var(--s-3);
  display: flex; gap: var(--s-2);
}

/* version banner inside chat */
.version-banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  margin: 0 var(--s-6);
  background: color-mix(in srgb, var(--brand) 12%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--brand) 30%, var(--border));
  border-radius: var(--r-md);
  font-size: 13px;
}
.version-banner b { color: var(--brand); }

/* ---------------- "My Chats" feed ---------------- */
.chats-feed {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.chat-row {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-4) var(--s-5);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  text-decoration: none;
  color: inherit;
  transition: all 0.15s var(--ease);
  position: relative;
}
.chat-row:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  transform: translateX(2px);
}
.chat-row-accent {
  position: absolute; left: 0; top: 14px; bottom: 14px;
  width: 3px;
  background: var(--accent, var(--brand));
  border-radius: 0 var(--r-xs) var(--r-xs) 0;
}
.chat-row-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.chat-row-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-row-body { flex: 1; min-width: 0; }
.chat-row-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px;
}
.chat-row-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
}
.chat-row-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-dim);
  flex-shrink: 0;
}
.chat-row-snippet {
  margin-top: 4px;
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chat-row-snippet .who {
  color: var(--fg-dim);
  font-weight: 500;
  margin-right: 4px;
}
.chat-row-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-dim);
  margin-top: 4px;
  letter-spacing: 0.04em;
}
.chat-row-cta {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  display: flex; align-items: center; gap: 4px;
}

/* ---------------- world tile + bg gallery ---------------- */
.world-tile {
  position: relative;
  display: block;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s var(--ease);
}
.world-tile:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow-2); }
.world-tile-hero {
  aspect-ratio: 16/9;
  background-size: cover;
  background-position: center;
  position: relative;
}
.world-tile-hero::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, transparent 40%, rgba(10,10,11,0.85) 100%);
}
.world-tile-body {
  padding: var(--s-5);
  position: relative;
}
.world-tile-eyebrow {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent, var(--fg-dim));
  margin-bottom: 6px;
}
.world-tile-title {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.world-tile-blurb {
  margin-top: 10px;
  font-size: 14px; line-height: 1.55;
  color: var(--fg-muted);
}
.world-tile-foot {
  margin-top: var(--s-4);
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--font-mono); font-size: 11px;
  color: var(--fg-dim);
}
.world-tile-avatars { display: flex; }
.world-tile-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--surface-1);
  background: var(--surface-2);
  margin-left: -10px;
  overflow: hidden;
}
.world-tile-avatar:first-child { margin-left: 0; }
.world-tile-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* World detail hero */
.world-hero {
  position: relative;
  aspect-ratio: 21/9;
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-top: var(--s-4);
  background-size: cover;
  background-position: center;
  background-color: #1a1a2e;
  background-image: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  border: 1px solid var(--border);
}
.world-hero::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, transparent 30%, rgba(10,10,11,0.9) 100%);
}
.world-hero-text {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: var(--s-7);
  z-index: 1;
}
.world-hero-text h1 {
  margin: 0 0 var(--s-3);
  font-family: var(--font-display);
  font-size: clamp(32px, 5vw, 56px);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
  max-width: 24ch;
}
.world-hero-text p {
  font-size: 16px; line-height: 1.6;
  color: var(--fg-muted);
  max-width: 60ch;
}
@media (max-width: 720px) {
  .world-hero { aspect-ratio: 4/3; }
  .world-hero-text { padding: var(--s-5); }
}

/* Background gallery (used on world detail + chat customize drawer) */
.bg-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--s-3);
}
.bg-tile {
  position: relative;
  display: block;
  aspect-ratio: 16/9;
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  transition: all 0.15s var(--ease);
  text-decoration: none;
  color: inherit;
}
.bg-tile:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.bg-tile.is-on { border-color: var(--brand); border-width: 2px; }
.bg-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bg-tile-label {
  position: absolute;
  bottom: 6px; left: 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--fg);
  background: rgba(0,0,0,0.7);
  padding: 3px 8px;
  border-radius: var(--r-pill);
  backdrop-filter: blur(4px);
}
.bg-tile-check {
  position: absolute;
  top: 6px; right: 6px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-on);
  display: none;
  align-items: center; justify-content: center;
}
.bg-tile.is-on .bg-tile-check { display: flex; }
.bg-tile-world {
  position: absolute;
  top: 6px; left: 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg);
  background: rgba(0,0,0,0.7);
  padding: 2px 6px;
  border-radius: var(--r-xs);
  backdrop-filter: blur(4px);
}

/* customize drawer — section subhead */
.drawer-subsection-head {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--fg-dim);
  margin: var(--s-4) 0 var(--s-2);
}
.drawer-subsection-head:first-child { margin-top: 0; }

/* ---------------- nav bell + notifications ---------------- */
.nav-bell {
  position: relative;
  width: 38px; height: 38px;
  display: inline-grid; place-items: center;
  border-radius: var(--r-md);
  color: var(--fg-muted);
  transition: all 0.15s var(--ease);
}
.nav-bell:hover { background: var(--surface-2); color: var(--fg); }
.nav-bell-dot {
  position: absolute;
  top: 6px; right: 6px;
  background: var(--brand);
  color: var(--brand-on);
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-mono);
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: var(--r-pill);
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg);
}

/* notifications page */
.notif-list { display: flex; flex-direction: column; gap: var(--s-3); }
.notif-item {
  display: flex; gap: var(--s-4);
  padding: var(--s-4) var(--s-5);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  text-decoration: none;
  color: inherit;
  transition: all 0.15s var(--ease);
  position: relative;
}
.notif-item:hover { border-color: var(--border-strong); background: var(--surface-2); }
.notif-item.is-unread { border-color: color-mix(in srgb, var(--brand) 30%, var(--border)); }
.notif-item.is-unread::before {
  content: "";
  position: absolute; left: -1px; top: 16px; bottom: 16px;
  width: 3px;
  background: var(--brand);
  border-radius: 0 var(--r-xs) var(--r-xs) 0;
}
.notif-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-size: 18px; font-weight: 600;
}
.notif-avatar img { width: 100%; height: 100%; object-fit: cover; }
.notif-body { flex: 1; min-width: 0; }
.notif-title {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px;
  font-size: 14px; font-weight: 600;
  color: var(--fg);
}
.notif-title-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-dim);
  font-weight: 400;
  flex-shrink: 0;
}
.notif-text {
  margin-top: 4px;
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.notif-empty {
  text-align: center;
  padding: var(--s-9) var(--s-4);
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  color: var(--fg-dim);
}

/* ---------------- comments ---------------- */
.comments {
  display: flex; flex-direction: column;
  gap: var(--s-4);
  margin-top: var(--s-4);
}
.comment-form {
  display: flex; gap: var(--s-3);
  align-items: flex-start;
}
.comment-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-on);
  display: grid; place-items: center;
  font-weight: 600;
  font-family: var(--font-display);
  flex-shrink: 0;
}
.comment-form textarea {
  flex: 1;
  min-height: 70px;
}
.comment {
  display: flex; gap: var(--s-3);
  padding: var(--s-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.comment-content { flex: 1; min-width: 0; }
.comment-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.comment-author { font-size: 13px; font-weight: 600; }
.comment-time { font-family: var(--font-mono); font-size: 11px; color: var(--fg-dim); }
.comment-body { font-size: 14px; line-height: 1.55; white-space: pre-wrap; }
.comment-actions {
  display: flex; gap: 8px; margin-top: 6px;
  font-size: 11px;
}
.comment-action {
  background: transparent; border: none;
  color: var(--fg-dim);
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.comment-action:hover { color: var(--fg); }
.comment-action.is-danger:hover { color: var(--danger); }

/* ---------------- character profile page ---------------- */
.charprof-shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: var(--s-7);
  padding: var(--s-6) 0 var(--s-9);
}
@media (max-width: 880px) {
  .charprof-shell { grid-template-columns: 1fr; gap: var(--s-5); }
}
.charprof-cover {
  position: sticky; top: 80px;
  aspect-ratio: 4/5;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-size: 80px; font-weight: 600;
  color: var(--fg-faint);
}
.charprof-cover img { width: 100%; height: 100%; object-fit: cover; }
@media (max-width: 880px) { .charprof-cover { position: static; max-width: 360px; margin: 0 auto; } }

.charprof-head {
  display: flex; flex-direction: column; gap: var(--s-3);
  padding-bottom: var(--s-5);
  border-bottom: 1px solid var(--border);
}
.charprof-eyebrow {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent, var(--fg-dim));
  display: inline-flex; align-items: center; gap: 8px;
}
.charprof-name {
  font-family: var(--font-display);
  font-size: clamp(36px, 5vw, 56px);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
  margin: 0;
}
.charprof-title {
  font-size: 17px;
  color: var(--fg-muted);
  font-style: italic;
}
.charprof-tagline {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 18px;
  line-height: 1.5;
  color: var(--fg);
  max-width: 60ch;
  margin-top: var(--s-2);
}
.charprof-cta {
  display: flex; align-items: center; gap: var(--s-3);
  margin-top: var(--s-4);
}
.charprof-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  margin-top: var(--s-5);
}
@media (max-width: 560px) { .charprof-stats { grid-template-columns: repeat(2, 1fr); } }
.charprof-stat {
  padding: var(--s-3) var(--s-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  display: flex; flex-direction: column; gap: 2px;
}
.charprof-stat-num {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1;
}
.charprof-stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
}
.charprof-section {
  margin-top: var(--s-7);
}
.charprof-section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--fg-dim);
  margin-bottom: var(--s-3);
}
.charprof-prose {
  font-size: 15px;
  line-height: 1.7;
  color: var(--fg);
  max-width: 70ch;
}
.charprof-greeting {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5) var(--s-6);
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
  position: relative;
}
.charprof-greeting em { color: var(--fg-muted); font-style: italic; }
.charprof-greeting::before {
  content: "First message";
  position: absolute; top: -10px; left: 16px;
  background: var(--bg);
  padding: 0 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--fg-dim);
}

/* profile */
.profile-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: var(--s-9);
  padding: var(--s-9) 0;
  align-items: start;
}
@media (max-width: 900px) { .profile-shell { grid-template-columns: 1fr; } }
.profile-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-6);
  text-align: center;
  position: sticky; top: 80px;
}
.profile-avatar {
  width: clamp(72px, 18vw, 96px);
  height: clamp(72px, 18vw, 96px);
  border-radius: 50%;
  background: var(--brand);
  color: var(--bg);
  margin: 0 auto var(--s-4);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-size: clamp(30px, 7vw, 40px); font-weight: 600;
}
.profile-name {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 600;
}
.profile-handle {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--fg-dim);
  margin-top: 4px;
}
.profile-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: var(--s-5);
  padding: var(--s-4) 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.profile-stat-num {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 600;
  letter-spacing: -0.01em;
}
.profile-stat-label {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
}

/* persona tabs / settings tabs */
.persona-tabs {
  display: flex; gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--s-5);
  flex-wrap: wrap;
}
.persona-tab {
  padding: 10px 16px;
  background: transparent; border: none;
  color: var(--fg-muted);
  font-size: 14px; font-weight: 500;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
  font-family: inherit;
}
.persona-tab:hover { color: var(--fg); }
.persona-tab.is-on {
  color: var(--fg);
  border-bottom-color: var(--brand);
}
.settings-tabs { margin-bottom: var(--s-6); }
.settings-pane.hidden { display: none; }

/* ---------------- popover menu (icon-button → menu) ---------------- */
.popover {
  position: relative;
  display: inline-block;
}
.popover-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 6px;
  min-width: min(240px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  box-shadow: var(--shadow-3);
  z-index: 60;
  display: none;
  animation: popIn 0.12s var(--ease);
}
.popover.is-open .popover-menu { display: block; }
@media (max-width: 480px) {
  .popover-menu { right: auto; left: 0; }
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.popover-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  color: var(--fg);
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s ease;
}
.popover-item:hover { background: var(--surface-3); }
.popover-item:hover .popover-item-icon { color: var(--brand); }
.popover-item.is-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.popover-item-icon {
  flex-shrink: 0;
  color: var(--fg-muted);
  display: inline-flex;
  margin-top: 1px;
}
.popover-item-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  gap: 2px;
}
.popover-item-sub {
  font-size: 12px;
  color: var(--fg-dim);
  font-weight: 400;
}
.popover-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

/* ---------------- a11y / focus ---------------- */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
button:focus-visible,
a:focus-visible,
.btn:focus-visible,
.chip:focus-visible,
.tab:focus-visible,
.nav-tab:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.input:focus-visible,
.textarea:focus-visible,
.cselect-trigger:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
.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;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .char-card:hover, .tile:hover { transform: none; }
}

/* ---------------- custom dropdown (EmberSelect) ---------------- */
.cselect {
  position: relative;
  display: block;
  width: 100%;
}
.cselect-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 38px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0 12px;
  font-size: 14px;
  color: var(--fg);
  cursor: pointer;
  text-align: left;
  gap: 10px;
  transition: all 0.15s var(--ease);
  font-family: inherit;
  white-space: nowrap;
}
/* small size — matches .btn-sm at 30px */
.cselect.is-sm .cselect-trigger {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
  border-radius: var(--r-sm);
}
.cselect.is-sm .cselect-arrow { font-size: 10px; }
.cselect-trigger:hover { border-color: var(--border-strong); }
.cselect.is-open .cselect-trigger {
  border-color: var(--border-focus);
  background: var(--surface-2);
}
.cselect-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cselect-label.is-placeholder { color: var(--fg-faint); }
.cselect-arrow {
  color: var(--fg-muted);
  font-size: 11px;
  transition: transform 0.2s var(--ease);
  flex-shrink: 0;
}
.cselect.is-open .cselect-arrow { transform: rotate(180deg); }
.cselect-menu {
  position: absolute;
  top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  z-index: 50;
  box-shadow: var(--shadow-3);
  padding: 4px;
  max-height: 280px;
  overflow-y: auto;
  display: none;
}
.cselect.is-open .cselect-menu { display: block; }
.cselect-option {
  display: block;
  width: 100%;
  padding: 9px 10px;
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  color: var(--fg);
  text-align: left;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.1s ease;
}
.cselect-option:hover { background: var(--surface-3); }
.cselect-option.is-on {
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 8%, transparent);
}
.cselect-option-sub {
  display: block;
  font-size: 11px;
  color: var(--fg-dim);
  margin-top: 2px;
}
/* hide native select if used as fallback */
select.cselect-native { display: none; }

/* ---------------- wizard (multi-step create) ---------------- */
.wizard-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(280px, 28vw, 360px);
  gap: var(--s-7);
  padding: var(--s-6) 0 var(--s-9);
  align-items: stretch;
}
@media (max-width: 960px) {
  .wizard-shell { grid-template-columns: 1fr; gap: var(--s-5); }
}
.wizard {
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  height: auto;
  min-height: min(560px, calc(100dvh - 140px));
  overflow: hidden;
}
@media (min-width: 960px) {
  .wizard { height: calc(100dvh - 160px); max-height: 880px; }
}
.wizard-progress {
  padding: var(--s-5) var(--s-6);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-shrink: 0;
}
.wizard-step-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s var(--ease);
}
.wizard-step-dot .num {
  display: inline-grid;
  place-items: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--fg-muted);
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
}
.wizard-step-dot:hover { color: var(--fg); border-color: var(--border-strong); }
.wizard-step-dot.is-on {
  color: var(--fg);
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.wizard-step-dot.is-on .num { background: var(--brand); color: var(--brand-on); }
.wizard-step-dot.is-done .num { background: var(--success); color: var(--bg); }
.wizard-step-dot.is-done .num::before { content: "✓"; }
.wizard-step-dot.is-done .num span { display: none; }

.wizard-progress-rail {
  flex: 1;
  height: 2px;
  background: var(--border);
  border-radius: var(--r-pill);
  overflow: hidden;
  margin-left: var(--s-3);
}
.wizard-progress-fill {
  height: 100%;
  background: var(--brand);
  width: 0%;
  transition: width 0.3s var(--ease);
}

.wizard-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding: var(--s-5) var(--s-7);
}
.wizard-step {
  display: none;
  animation: stepIn 0.2s var(--ease);
}
.wizard-step.is-active { display: block; }
@keyframes stepIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.wizard-step-eyebrow {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--fg-dim);
  margin-bottom: var(--s-2);
}
.wizard-step-title {
  font-family: var(--font-display);
  font-size: 24px; font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
  margin-bottom: 4px;
}
.wizard-step-sub {
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.5;
  margin-bottom: var(--s-5);
  max-width: 60ch;
}
/* compact field spacing inside the wizard */
.wizard-body .field { margin-top: var(--s-3); }
.wizard-body .field:first-of-type { margin-top: 0; }
.wizard-body .row-fields { margin-top: var(--s-3); }
.wizard-body .field-help { font-size: 11px; margin-top: 4px; }
.wizard-body .textarea { min-height: 64px; }

.wizard-foot {
  padding: var(--s-4) var(--s-6);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex-shrink: 0;
  background: rgba(0,0,0,0.15);
}
.wizard-foot-left, .wizard-foot-right {
  display: flex; align-items: center; gap: var(--s-2);
}
.wizard-step-counter {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-dim);
}

/* preview rail in wizard */
.wizard-preview {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: auto;
  min-height: 0;
}
@media (min-width: 960px) {
  .wizard-preview { height: calc(100dvh - 160px); min-height: 520px; max-height: 880px; }
}
.wizard-preview-cover {
  aspect-ratio: 4/5;
  flex-shrink: 0;
  background: var(--surface-2);
  position: relative;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-size: 64px; font-weight: 600;
  color: var(--fg-faint);
  overflow: hidden;
}
.wizard-preview-cover img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.wizard-preview-meta { padding: var(--s-5); flex: 1; min-height: 0; overflow-y: auto; }

/* ---------------- hamburger toggle (visible on mobile only) ---------------- */
.nav-toggle {
  display: none;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--fg);
  flex-shrink: 0;
  transition: all 0.15s var(--ease);
  position: relative;
  z-index: 100;
  pointer-events: auto;
  touch-action: manipulation;
}
.nav-toggle:hover { background: var(--surface-1); border-color: var(--border-strong); }
.nav-overlay {
  position: fixed; inset: calc(60px + env(safe-area-inset-top, 0px)) 0 0 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 99;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fadeIn 0.18s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------------- mobile breakpoints / overflow fixes ---------------- */
/* hamburger nav activates at <=880px so iPad portrait (768) gets mobile chrome */
@media (max-width: 880px) {
  .chat-shell {
    grid-template-columns: 1fr;
    height: calc(100dvh - 60px - env(safe-area-inset-top, 0px));
    padding: 0;
  }
  .chat-shell .chat-sidebar { display: none; }
  .chat-shell .chat-main {
    margin: 0;
    border: none;
    border-radius: 0;
    height: 100%;
  }
  .chat-stream {
    padding: var(--s-5) var(--s-4);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .chat-input {
    padding: var(--s-3) var(--s-4);
    position: sticky;
    bottom: 0;
    background: var(--surface-1);
    z-index: 10;
  }
  .chat-bar {
    padding: var(--s-3) var(--s-4);
    position: sticky;
    top: 0;
    z-index: 10;
  }
  /* Mobile-specific touch improvements */
  .chat-input-text {
    font-size: 16px; /* Prevents iOS zoom on focus */
    min-height: 44px;
  }
  .btn-icon, .btn-icon-lg {
    min-width: 44px;
    min-height: 44px;
  }
  /* Ensure message actions are visible on touch */
  .msg-actions {
    opacity: 1;
  }
  /* Allow horizontal scroll for long messages */
  .msg-content {
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
  }
}

@media (max-width: 880px) {
  .header-inner { gap: var(--s-3); }
  .header { background: var(--surface-1); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .nav-toggle { display: inline-flex; }
  .nav-tabs {
    position: fixed; top: calc(60px + env(safe-area-inset-top, 0px)); left: 0; right: 0;
    margin-left: 0; gap: 4px;
    flex-direction: column; align-items: stretch;
    background: var(--surface-1);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: var(--s-3) var(--s-4);
    transform: translateY(-110%);
    transition: transform 0.25s var(--ease);
    z-index: 100;
    max-height: calc(100dvh - 60px - env(safe-area-inset-top, 0px));
    overflow-y: auto;
  }
  .nav-tabs.is-open { transform: translateY(0); }
  .nav-tab { padding: 12px 14px; font-size: 15px; min-height: 48px; border-radius: var(--r-md); }
  .header-actions .btn-sm { padding: 0 10px; }
  .header-actions span:not(.brand-mark):not(.auth-avatar) { display: none; }
}

@media (max-width: 720px) {
  .container { padding: 0 var(--s-4); }
  .hero { padding: var(--s-9) 0 var(--s-6); }
  .grid { gap: var(--s-4); }
  .form-section { padding: var(--s-5); }
  .row-fields { grid-template-columns: 1fr; gap: var(--s-3); }
  .drawer { top: 8px; right: 8px; bottom: 8px; left: 8px; width: auto; max-width: none; }
  .auth-modal { padding: 24px 20px; width: calc(100vw - 24px); }
  .image-add-buttons { grid-template-columns: 1fr; }
  .chat-shell { grid-template-columns: 1fr; height: calc(100dvh - 60px - env(safe-area-inset-top, 0px)); padding: 0; }
  .chat-sidebar { display: none; }
  .header-actions .btn-sm { padding: 0 10px; }
  .header-actions span:not(.brand-mark):not(.auth-avatar) { display: none; }
}

@media (max-width: 480px) {
  .hero h1 { font-size: 36px; line-height: 1.05; }
  .header-actions .btn:not(:last-child) { display: none; }
  .wizard-progress { padding: var(--s-3) var(--s-4); flex-wrap: wrap; }
  .wizard-step-dot { padding: 4px 8px; font-size: 11px; }
  .wizard-body { padding: var(--s-5) var(--s-4); }
  .wizard-foot { padding: var(--s-3) var(--s-4); }
  .wizard-progress-rail { flex-basis: 100%; order: 99; margin-left: 0; }
  .section-head { flex-wrap: wrap; }
  .chat-bar { flex-wrap: wrap; row-gap: 8px; }
}

/* iPad portrait + small laptop (intermediate breakpoint, fixes the 880↔1000 gap) */
@media (max-width: 960px) {
  .charprof-shell { grid-template-columns: 1fr; gap: var(--s-5); }
  .charprof-cover { position: static; max-width: min(360px, 100%); margin: 0 auto; }
  .profile-shell { grid-template-columns: 1fr; gap: var(--s-6); }
  .charprof-stats { grid-template-columns: repeat(2, 1fr); }
}

/* ultra-small phones (iPhone SE 1st gen and similar) */
@media (max-width: 360px) {
  .hero h1 { font-size: 28px; }
  .h-display-lg { font-size: clamp(28px, 8vw, 36px); }
  h1, .h1 { font-size: 26px; }
  h2, .h2 { font-size: 19px; }
  .container { padding: 0 12px; }
  .auth-modal { padding: 20px 16px; }
  .popover-menu { min-width: 0; max-width: calc(100vw - 24px); }
  .wizard-body { padding: var(--s-4) var(--s-3); }
  .wizard-progress { padding: var(--s-3) var(--s-3); }
  .wizard-foot { padding: var(--s-3) var(--s-3); flex-wrap: wrap; gap: var(--s-2); }
  .wizard-foot-left, .wizard-foot-right { flex-wrap: wrap; }
  .btn-sm { padding: 0 10px; font-size: 12px; }
}

/* prevent horizontal overflow site-wide */
html, body { overflow-x: hidden; max-width: 100vw; }
.container { max-width: min(1280px, 100%); }
img, video, iframe { max-width: 100%; height: auto; }
input, textarea, select, button { max-width: 100%; }
.textarea { word-wrap: break-word; overflow-wrap: break-word; }
/* let flex/grid children shrink past their content width — kills 99% of horizontal overflow */
.chat-stream, .chat-main, .chat-sidebar, .wizard-body, .msg-body,
.msg-content, .charprof-bio, .field, .row-fields > * {
  min-width: 0;
}
.msg-content, .chat-side-tagline, .charprof-bio, .notif-text {
  word-break: break-word; overflow-wrap: anywhere;
}

/* ensure tap targets are reasonable on touch */
@media (pointer: coarse) {
  .btn-sm { min-height: 36px; }
  .btn { min-height: 44px; }
  .chip { min-height: 44px; }
  .nav-tab { min-height: 44px; }
  .msg-action { min-width: 44px; min-height: 44px; padding: 10px 14px; }
  .popover-item { min-height: 44px; }
  .cselect-option { min-height: 44px; }
  .btn-icon, .btn-icon-lg { min-width: 44px; min-height: 44px; }
  .nav-bell { min-width: 44px; min-height: 44px; }
  .msg-avatar { width: 40px; height: 40px; }
  .image-tile-x { width: 44px; height: 44px; font-size: 18px; top: 8px; right: 8px; }
  .color-swatch { width: 44px; height: 44px; }
  .chat-input-text { font-size: 16px; } /* prevents iOS auto-zoom on focus */
  .input, .select { font-size: 16px; }
  .textarea { font-size: 16px; }
}

/* utility */
.hidden { display: none !important; }
.center-text { text-align: center; }
.gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }
.flex-wrap { flex-wrap: wrap; }
.full { width: 100%; }
.mt-2 { margin-top: var(--s-2); }
.mt-3 { margin-top: var(--s-3); }
.mt-4 { margin-top: var(--s-4); }
.mt-5 { margin-top: var(--s-5); }
