*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

:root {
  /* Layout */
  --sidebar-w: 220px;
  --topbar-h: 50px;

  /* Core surfaces (darkest → lightest) */
  --sidebar-bg: #111111;
  --page-bg: #1e1e1e;
  --card-bg: #252525;
  --surface-sunken: #1b1b1b;
  --surface-raised: #333333;
  --border: #404040;

  /* Text scale */
  --white: #ffffff;
  --text-main: #dedede;
  --text-body: #b0b0b0;
  --text-secondary: #a0a0a0;
  --text-muted: #909090;
  --text-dim: #9a9a9a;
  --text-placeholder: #777777;

  /* Sidebar */
  --sidebar-text: #b8b8b8;
  --sidebar-hover: rgba(255,255,255,0.07);
  --sidebar-divider: rgba(255,255,255,0.07);
  --sidebar-label: rgba(220,220,220,0.8);
  --sidebar-label-hover: rgba(235,235,235,0.9);
  --sidebar-active-bg: rgba(255,255,255,0.1);
  --sidebar-active-text: #ffffff;

  /* Accent */
  --accent: #7c6fff;

  /* Badge colours */
  --badge-green-bg:      #162a20;  --badge-green-fg:      #60c87a;
  --badge-blue-bg:       #12223a;  --badge-blue-fg:       #60a0e8;
  --badge-purple-bg:     #22103a;  --badge-purple-fg:     #c060f0;
  --badge-orange-bg:     #2a1a08;  --badge-orange-fg:     #e09050;
  --badge-red-bg:        #280c0c;  --badge-red-fg:        #e05858;
  --badge-legendary-bg:  #2a0a0a;  --badge-legendary-fg:  #f06060;

  /* Fonts */
  --font-base: 'Ubuntu', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Font scale */
  --text-icon:    9px;
  --text-xs:     12px;
  --text-sm:     14px;
  --text-base:   16px;
  --text-md:     18px;
  --text-stat:   21px;
  --text-display:28px;
  --text-lg:     26px;
  --text-xl:     42px;

  /* Character banner gradients */
  --char-kael-gradient: linear-gradient(135deg, #3d3b8e, #7c6fff);
  --char-lyra-gradient: linear-gradient(135deg, #2d6a4f, #52b788);
  --char-zoya-gradient: linear-gradient(135deg, #7b2d2d, #c44d4d);
  --char-brom-gradient: linear-gradient(135deg, #4a4a2d, #9e9a52);
}

body {
  font-family: var(--font-base);
  font-size: var(--text-base);
  background: var(--page-bg);
  color: var(--text-body);
}

/* ─── SIDEBAR ─── */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
}

.sb-brand {
  padding: 1.1rem 1rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border-bottom: 1px solid var(--sidebar-divider);
  flex-shrink: 0;
}
.sb-brand-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-base);
  flex-shrink: 0;
}
.sb-brand-name { color: var(--white); font-weight: 700; font-size: var(--text-base); }
.sb-brand-sub { color: var(--sidebar-text); font-size: var(--text-xs); margin-top: 1px; }

.sb-section { padding: 1rem 0 0.25rem; flex-shrink: 0; }

.sb-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.48rem 1rem;
  color: var(--sidebar-text);
  text-decoration: none;
  cursor: pointer;
  font-size: var(--text-base);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background 0.1s, color 0.1s;
}
.sb-link:hover { background: var(--sidebar-hover); color: var(--text-main); }
.sb-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: 600; }
.sb-link svg { width: 14px; height: 14px; opacity: 0.6; flex-shrink: 0; }
.sb-link.active svg { opacity: 1; }

.sb-sub .sb-link { padding-left: 2.3rem; }

.sb-footer { margin-top: auto; flex-shrink: 0; }
.sb-footer-inner {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--sidebar-divider);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  background: none;
  border-left: none;
  border-right: none;
  border-bottom: none;
  cursor: pointer;
  text-align: left;
  font-family: var(--font-base);
  font-size: var(--text-base);
  color: inherit;
  text-decoration: none;
}
.sb-footer-inner:hover { background: var(--sidebar-hover); }

/* ─── USER DRAWER ─── */
.sb-footer-drawer {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.2s ease;
}
.sb-footer-drawer.open { max-height: 200px; }
.sb-drawer-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 1rem;
  color: var(--sidebar-text);
  font-size: var(--text-base);
  cursor: pointer;
  text-decoration: none;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-base);
}
.sb-drawer-item:hover { background: var(--sidebar-hover); color: var(--text-main); }
.sb-drawer-icon { width: 16px; text-align: center; flex-shrink: 0; opacity: 0.7; }
.sb-drawer-sep { height: 1px; background: var(--sidebar-divider); margin: 0.2rem 0; }
.sb-drawer-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: var(--text-xs);
  padding: 0.2rem 0.35rem;
  flex-shrink: 0;
  opacity: 0.6;
  transition: transform 0.2s, opacity 0.15s;
  border-radius: 4px;
}
.sb-footer-inner.open .sb-drawer-toggle { transform: rotate(180deg); opacity: 0.9; }
.sb-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.sb-avatar {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--text-xs); color: var(--white);
  flex-shrink: 0;
}
.sb-user-name { color: var(--text-main); font-size: 13px; font-weight: 600; }
.sb-user-role { color: var(--sidebar-text); font-size: var(--text-xs); }

/* ─── COLLAPSIBLE SIDEBAR SECTIONS ─── */
.sb-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 1rem 0.45rem;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--sidebar-label);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.15s;
}
.sb-collapse-btn:hover { color: var(--sidebar-label-hover); }
.sb-chevron {
  font-size: var(--text-icon);
  transition: transform 0.2s;
  opacity: 0.6;
}
.sb-collapse-btn.collapsed .sb-chevron { transform: rotate(-90deg); }
.sb-sub { overflow: hidden; }
.sb-sub.hidden { display: none; }

/* ─── TOPBAR ─── */
#topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  z-index: 100;
  gap: 0.75rem;
}
.tb-breadcrumb { flex: 1; font-size: var(--text-sm); color: var(--text-muted); }
.tb-breadcrumb strong { color: var(--text-main); }
.tb-breadcrumb a { color: var(--text-muted); text-decoration: none; }
.tb-breadcrumb a:hover { color: var(--text-body); }
.tb-breadcrumb .bc-sep { color: var(--text-dim); margin: 0 0.3rem; }
.tb-actions { display: flex; align-items: center; gap: 0.6rem; }

/* ─── MAIN ─── */
#main {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  padding: 1.75rem max(2rem, calc((100% - 1400px) / 2));
  min-height: calc(100vh - var(--topbar-h));
}

.page-title { font-size: var(--text-lg); font-weight: 700; color: var(--text-main); margin-bottom: 0.15rem; }
.page-sub { font-size: var(--text-sm); color: var(--text-muted); margin-bottom: 1.5rem; }

/* ─── CARD ─── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
}
.card-header {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-body { padding: 1.25rem; }
.card-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: var(--text-sm);
  color: var(--accent);
}

/* ─── STAT CARD ─── */
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: 9px;
  padding: 1.1rem 1.25rem;
}
.stat-label { font-size: var(--text-xs); color: var(--text-body); margin-bottom: 0.25rem; }
.stat-value { font-size: var(--text-xl); font-weight: 700; color: var(--text-main); line-height: 1; }
.stat-link { margin-top: 0.6rem; font-size: var(--text-xs); color: var(--accent); }

/* ─── GRID ─── */
.grid { display: grid; gap: 1rem; }
.g2  { grid-template-columns: 1fr 1fr; }
.g3  { grid-template-columns: repeat(3, 1fr); }
.g4  { grid-template-columns: repeat(4, 1fr); }
.g1-2 { grid-template-columns: 1fr 2fr; }

/* ─── TABLE ─── */
.wf-table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.wf-table th {
  text-align: left;
  padding: 0.55rem 1.25rem;
  border-bottom: 2px solid var(--border);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  background: var(--surface-sunken);
}
.wf-table th:first-child { border-radius: 9px 0 0 0; }
.wf-table th:last-child  { border-radius: 0 9px 0 0; }
.wf-table th a, .wf-table th a:visited { color: var(--text-dim); text-decoration: none; }
.wf-table th a:hover { color: var(--text-main); }
.wf-table th[data-sort-col]:hover { color: var(--text-main); }
.wf-table td {
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.wf-table tr:last-child td { border-bottom: none; }
.wf-table tr:hover td { background: var(--surface-raised); }

/* .table-scroll wrapper lets tables scroll on mobile without breaking banner clipping on .card */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ─── BADGE ─── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  font-size: var(--text-xs);
  font-weight: 600;
}
.badge-green     { background: var(--badge-green-bg);     color: var(--badge-green-fg);     }
.badge-blue      { background: var(--badge-blue-bg);      color: var(--badge-blue-fg);      }
.badge-purple    { background: var(--badge-purple-bg);    color: var(--badge-purple-fg);    }
.badge-orange    { background: var(--badge-orange-bg);    color: var(--badge-orange-fg);    }
.badge-red       { background: var(--badge-red-bg);       color: var(--badge-red-fg);       }
.badge-gray      { background: var(--surface-raised);     color: var(--text-muted);         }
.badge-legendary { background: var(--badge-legendary-bg); color: var(--badge-legendary-fg); }

/* ─── BUTTON ─── */
.btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  border-radius: 6px;
  font-size: var(--text-base);
  cursor: pointer;
  color: var(--text-main);
  text-decoration: none;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.btn:hover:not(.btn-primary) { background: var(--border); border-color: var(--text-dim); color: var(--text-main); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--white); }
.btn-primary:hover { filter: brightness(1.15); }
.btn-sm { padding: 0.28rem 0.65rem; font-size: var(--text-xs); }
.filter-btn { color: var(--text-muted); border-color: transparent; background: transparent; }
.filter-btn.active { color: var(--text-main); background: rgba(255,255,255,0.07); border-color: var(--border); font-weight: 600; }

/* ─── ACCESSIBILITY ─── */
.visually-hidden {
  position: absolute !important; width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important; overflow: hidden !important;
  clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important;
}

/* ─── FOCUS ─── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ─── SEARCH BAR ─── */
.search-bar {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.42rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-sunken);
  font-size: var(--text-base);
  color: var(--text-placeholder);
}

/* ─── SESSION ROW ─── */
.session-row {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}
.session-row:last-child { border-bottom: none; }
.session-num {
  width: 34px; height: 34px;
  background: var(--surface-raised);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--text-sm); color: var(--text-muted);
  flex-shrink: 0;
}
.session-info { flex: 1; }
.session-title { font-weight: 600; font-size: var(--text-base); color: var(--text-main); }
.session-date { font-size: var(--text-sm); color: var(--text-muted); margin-top: 1px; }

/* ─── CHAR CARD ─── */
.char-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.char-banner { height: 56px; }
.banner-swatch.swatch-active { border-color: var(--text-main) !important; }
.char-body { padding: 0.75rem 1rem 1rem; }
.char-avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--surface-raised);
  border: 3px solid var(--card-bg);
  margin-top: -26px;
  margin-bottom: 0.4rem;
  overflow: hidden;
}
.char-avatar img { width: 100%; height: 100%; object-fit: cover; }
.char-name { font-weight: 700; font-size: var(--text-base); color: var(--text-main); }
.char-class { font-size: var(--text-sm); color: var(--text-muted); margin-bottom: 0.4rem; }
.char-detail { font-size: var(--text-sm); color: var(--text-dim); }

/* ─── NPC AVATAR ─── */
.npc-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface-raised);
  flex-shrink: 0;
  overflow: hidden;
}
.npc-avatar img { width: 100%; height: 100%; object-fit: cover; }
.npc-info { display: flex; align-items: center; gap: 0.75rem; }
.npc-name { font-weight: 600; color: var(--text-main); }
.npc-pronouns { font-size: var(--text-xs); color: var(--text-muted); }

/* ─── TOOLBAR ROW ─── */
.toolbar { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
.toolbar-left { display: flex; align-items: center; gap: 0.5rem; flex: 1; }
.toolbar-right { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }

/* ─── FILTER SELECT (toolbar dropdowns) ─── */
select.btn-filter {
  appearance: none;
  -webkit-appearance: none;
  padding: 0.4rem 1.8rem 0.4rem 0.9rem;
  border: 1px solid var(--border);
  background: var(--surface-raised) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23909090'/%3E%3C/svg%3E") no-repeat right 0.65rem center;
  border-radius: 6px;
  font-size: var(--text-base);
  cursor: pointer;
  color: var(--text-main);
  font-family: var(--font-base);
}
select.btn-filter:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─── DETAIL LAYOUT ─── */
.detail-sidebar {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 1.25rem;
}
.detail-section-title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.detail-section-title:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.detail-val { font-size: var(--text-base); color: var(--text-main); }
.detail-muted { font-size: var(--text-xs); color: var(--text-muted); }

/* ─── DASHBOARD TABS ─── */
.dash-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.75rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.25rem;
  width: fit-content;
}
.dash-tab {
  padding: 0.38rem 1.1rem;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.1s, color 0.1s;
}
.dash-tab.active { background: var(--surface-raised); color: var(--text-main); font-weight: 600; }

/* ─── PLAYER HERO CARD ─── */
.player-hero {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.player-hero-banner { height: 110px; }
.player-hero-body {
  padding: 0 1.5rem 1.5rem;
  display: flex;
  align-items: flex-end;
  gap: 1.25rem;
}
.player-hero-avatar {
  width: 76px; height: 76px;
  border-radius: 50%;
  background: var(--surface-raised);
  border: 4px solid var(--card-bg);
  margin-top: -38px;
  flex-shrink: 0;
  overflow: hidden;
}
.player-hero-avatar img { width: 100%; height: 100%; object-fit: cover; }
.player-hero-name { font-size: var(--text-lg); font-weight: 700; color: var(--text-main); line-height: 1.1; }
.player-hero-sub { font-size: var(--text-base); color: var(--text-muted); margin-top: 0.3rem; }
.player-hero-stat { text-align: center; }
.player-hero-stat-label { font-size: var(--text-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.15rem; }
.player-hero-stat-val { font-size: var(--text-lg); font-weight: 700; color: var(--text-main); }

/* ─── STORYBOOK RECAP ─── */
.story-back { font-size: var(--text-sm); color: var(--accent); text-decoration: none; display: inline-block; margin-bottom: 1rem; }
.story-meta-bar {
  font-size: var(--text-xs);
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 0.6rem;
}
.story-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 1.5rem;
  line-height: 1.15;
}
.chapter-nav { display: flex; gap: 0.5rem; margin-bottom: 2.5rem; flex-wrap: wrap; }
.chapter-pill {
  padding: 0.3rem 0.9rem;
  font-size: var(--text-sm);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  background: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.chapter-pill.active,
.chapter-pill:hover { background: var(--surface-raised); color: var(--text-main); border-color: var(--text-dim); }
.prose-wrap { max-width: 720px; display: flex; flex-direction: column; gap: 3rem; }
.chapter-eyebrow {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 0.4rem;
}
.chapter-heading {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 1.5rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}

/* ─── SECTION LABEL ─── */
.section-label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* ─── SECTION TITLE ─── */
.section-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.75rem;
}

/* ─── BANNER CARD TOP ─── */
.banner-card-top {
  height: 80px;
  background: var(--surface-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: var(--text-xs);
  overflow: hidden;
}
.banner-card-top img { width: 100%; height: 100%; object-fit: cover; }

/* ─── FORM FIELDS ─── */
.wf-field { margin-bottom: 1rem; }
.wf-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.wf-input {
  display: block;
  width: 100%;
  padding: 0.48rem 0.75rem;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-main);
  font-size: var(--text-base);
}
.wf-input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.wf-input.error { border-color: var(--badge-red-fg); }
.wf-error { font-size: var(--text-sm); color: var(--badge-red-fg); margin-top: 0.3rem; }
.wf-hint { font-size: var(--text-sm); color: var(--text-muted); margin-top: 0.3rem; }
.wf-input[type="date"] { color-scheme: dark; }
.wf-textarea { resize: vertical; min-height: 100px; }

/* ─── RICH TEXT EDITOR ─── */
.rte-wrap { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface-sunken); }
.rte-toolbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  align-items: center;
}
.rte-tool-btn {
  padding: 0.22rem 0.5rem;
  border: none;
  background: none;
  color: var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 600;
  transition: background 0.1s, color 0.1s;
}
.rte-tool-btn:hover,
.rte-tool-btn.active { background: var(--surface-raised); color: var(--text-main); }
.rte-divider { width: 1px; background: var(--border); margin: 0 0.15rem; align-self: stretch; }
.rte-body { min-height: 260px; padding: 1rem; color: var(--text-body); font-size: var(--text-base); line-height: 1.7; }

/* ─── FORM ACTIONS + GRID ─── */
.form-actions { display: flex; align-items: center; gap: 0.5rem; padding-top: 1.25rem; }
.form-grid { display: grid; gap: 1rem; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ─── LOGIN PAGE ─── */
body.login-mode #sidebar,
body.login-mode #topbar { display: none; }
body.login-mode #main {
  margin-left: 0;
  margin-top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}
.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
}
.login-brand { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 2rem; }

/* ─── MOBILE SIDEBAR ─── */
.topbar-hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-lg);
  flex-shrink: 0;
  margin-right: 0.25rem;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 150;
}

/* ─── FLASH MESSAGES ─── */
.flash-messages { margin-bottom: 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; }
.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  border-radius: 7px;
  font-size: var(--text-sm);
  border: 1px solid;
  animation: flashSlideDown 0.2s ease-out;
}
.flash-success { background: var(--badge-green-bg);  border-color: var(--badge-green-fg);  color: var(--badge-green-fg);  }
.flash-error,
.flash-danger  { background: var(--badge-red-bg);    border-color: var(--badge-red-fg);    color: var(--badge-red-fg);    }
.flash-warning { background: var(--badge-orange-bg); border-color: var(--badge-orange-fg); color: var(--badge-orange-fg); }
.flash-info    { background: var(--badge-blue-bg);   border-color: var(--badge-blue-fg);   color: var(--badge-blue-fg);   }
.flash-close {
  background: none; border: none; cursor: pointer;
  font-size: var(--text-base); color: inherit; opacity: 0.7; flex-shrink: 0; padding: 0 0.25rem;
}
.flash-close:hover { opacity: 1; }

/* ─── ANIMATIONS ─── */
@keyframes pageFadeIn {
  from { opacity: 0; transform: translateX(10px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes flashSlideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.page-fade-in { animation: pageFadeIn 0.18s ease-out both; }

/* ─── HTMX LOADING STATE ─── */
#items-container.htmx-request { opacity: 0.5; transition: opacity 0.15s ease; }

/* ─── TIPTAP EDITOR ─── */
#tiptap-editor {
  background-color: var(--surface-sunken) !important;
  color: var(--text-body);
  border-color: var(--border) !important;
}
#tiptap-toolbar {
  background-color: var(--card-bg) !important;
  border-color: var(--border) !important;
}

/* ─── UTILITIES ─── */
.text-truncate-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ─── CHARACTER SHEET ─── */
.prof-dot {
  width: 8px; height: 8px; border-radius: 50%;
  border: 1px solid var(--text-dim);
  flex-shrink: 0; display: inline-block;
}
.prof-dot.proficient { background: var(--badge-green-fg);  border-color: var(--badge-green-fg);  }
.prof-dot.expertise  { background: var(--badge-orange-fg); border-color: var(--badge-orange-fg); }
.sheet-label {
  font-size: var(--text-icon);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}
.tab-scroll { overflow-y: auto; }
.combat-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr;
  gap: 0.5rem;
}
.combat-grid .card-header { padding: 0.15rem 0.25rem; }
.combat-grid .card-body   { padding: 0.75rem 0.4rem; }
.character-sheet {
  max-width: 1000px; margin: 0 auto;
  display: flex; flex-direction: column;
  height: calc(100dvh - var(--topbar-h) - 3.5rem);
}
.character-sheet .card { border-width: 2px; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.hp-low      { color: var(--badge-orange-fg); }
.hp-critical { color: var(--badge-red-fg); }

/* ─── RECAP CONTENT ─── */
.recap-content p            { margin-bottom: 0.75rem; }
.recap-content p:last-child { margin-bottom: 0; }
.recap-content ul,
.recap-content ol           { padding-left: 1.5rem; margin-bottom: 0.75rem; }
.recap-content blockquote   { border-left: 3px solid var(--accent); padding-left: 1rem; color: var(--text-muted); margin: 0.75rem 0; }
.recap-content h1,
.recap-content h2,
.recap-content h3           { margin-top: 1rem; margin-bottom: 0.5rem; font-weight: 600; color: var(--text-main); }
.recap-content hr           { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ─── RESPONSIVE: TABLET (768px) ─── */
@media (max-width: 768px) {
  .topbar-hamburger { display: flex; }
  #sidebar { transform: translateX(-100%); transition: transform 0.22s ease; }
  #sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  #topbar { left: 0; }
  #main { margin-left: 0; padding: 1.25rem 1rem; }
  .tb-breadcrumb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55vw; }
  .g4 { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: var(--text-lg); }
}

/* ─── RESPONSIVE: MOBILE (640px) ─── */
@media (max-width: 640px) {
  #main { padding: 1rem 0.75rem; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .g1-2 { grid-template-columns: 1fr; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .form-grid-3 { grid-template-columns: 1fr; }
  .toolbar { flex-wrap: wrap; gap: 0.6rem; }
  .toolbar-left { flex-wrap: wrap; flex: 1 1 100%; }
  .toolbar-right { flex: 1 1 100%; }
  .toolbar-right .btn { width: 100%; justify-content: center; }
  .search-bar { width: 100% !important; min-width: 0; }
  .wf-table { min-width: 480px; }
  .stat-value { font-size: var(--text-base); }
  .story-title { font-size: var(--text-lg); }
  .page-title { font-size: var(--text-sm); }
  .player-hero-body { flex-wrap: wrap; }
  .player-hero-avatar { margin-top: -28px; }
  .chapter-nav { gap: 0.35rem; }
  .story-meta-bar { font-size: var(--text-xs); }
  .login-card { max-width: 100%; }
  .tab-scroll { max-height: none; }
}

/* ─── DIALOG (native <dialog>) ─── */
dialog {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card-bg);
  color: var(--text-main);
  padding: 0;
  max-width: 520px;
  width: calc(100% - 2rem);
  box-shadow: 0 8px 32px rgba(0,0,0,.55);
  margin: auto;
}
dialog::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
dialog[open] { animation: dlg-in 0.16s ease; }
@keyframes dlg-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
dialog.dialog-fullscreen {
  max-width: 100dvw; width: 100dvw;
  max-height: 100dvh; height: 100dvh;
  border-radius: 0; border: none; margin: 0; inset: 0;
}
dialog.dialog-fullscreen[open] {
  display: flex; flex-direction: column;
}
.dialog-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: var(--text-base);
}
.dialog-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 1.1rem; line-height: 1; cursor: pointer;
  padding: 0.15rem 0.4rem; border-radius: 4px;
}
.dialog-close:hover { color: var(--text-main); background: var(--surface-raised); }
.dialog-body { padding: 1.25rem; overflow-y: auto; }
.dialog-footer {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* ─── CHECKBOXES / RADIO ─── */
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 14px; height: 14px; flex-shrink: 0; cursor: pointer; }
.check-group-wrap ul { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem; margin: 0; }
.check-group-wrap ul li { display: flex; align-items: center; }
.check-group-wrap ul li label { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; font-size: var(--text-sm); color: var(--text-body); }

/* ─── LORE BODY ─── */
.lore-body p            { margin-bottom: 0.75rem; }
.lore-body p:last-child { margin-bottom: 0; }

/* ─── MAPS ─── */
.map-thumb { width:100%; height:160px; object-fit:cover; cursor:pointer; transition:opacity 0.15s; display:block; }
.map-thumb:hover { opacity: 0.85; }

/* ─── PARTY — DRAG AND DROP ─── */
.drop-zone { min-height: 48px; border-radius: 6px; transition: background 0.15s, outline 0.15s; }
.drop-zone-active { outline: 2px dashed var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent) !important; }
[draggable="true"] { cursor: grab; }
[draggable="true"]:active { cursor: grabbing; }

/* ─── CYCLE — TIME BADGES ─── */
.time-badge { display:inline-block; padding:0.15em 0.55em; border-radius:4px; font-size:var(--text-xs); font-weight:700; }
.time-morning   { background:#3a2e00; color:#f5c542; }
.time-afternoon { background:var(--badge-orange-bg); color:var(--badge-orange-fg); }
.time-evening   { background:var(--badge-purple-bg); color:var(--badge-purple-fg); }
.time-night     { background:var(--surface-raised); color:var(--text-muted); }

/* ─── CHARACTER SHEET — TABS ─── */
.tab-btn {
  flex: 1; text-align: center;
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 0.55rem 0.5rem; cursor: pointer; font-size: var(--text-sm);
  color: var(--text-muted); margin-bottom: -1px; white-space: nowrap;
}
.tab-btn:hover { color: var(--text-body); }
.tab-btn.active { color: var(--text-main); border-bottom-color: var(--accent); font-weight: 600; }

/* ─── PROSEMIRROR (recap editor) ─── */
.ProseMirror { outline: none; min-height: 280px; }
.ProseMirror p { margin-bottom: 0.75rem; }
.ProseMirror ul, .ProseMirror ol { padding-left: 1.5rem; margin-bottom: 0.75rem; }
.ProseMirror blockquote { border-left: 3px solid var(--accent); padding-left: 1rem; color: var(--text-muted); margin: 0.75rem 0; }
.ProseMirror hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.ProseMirror h1, .ProseMirror h2, .ProseMirror h3 { margin-top: 1rem; margin-bottom: 0.5rem; font-weight: 600; color: var(--text-main); }

/* ─── NPC TABLE ─── */
.npc-row td { vertical-align: middle; }
.npc-avatar-initials {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface-raised);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--text-xs);
  color: var(--text-muted);
}
.npc-row-actions { display: flex; gap: 0.3rem; justify-content: flex-end; }
