/*
 * Handcrafted codex theme
 * A quiet campaign-book presentation layered over the existing feature CSS.
 * Functional feature styles remain in their original files.
 */
:root {
  --ink-black: var(--cx-field);
  --ink-deep: var(--cx-surface);
  --ink-panel: var(--cx-surface);
  --ink-panel-raised: var(--cx-surface);
  --ink-hover: var(--cx-surface);
  --brass: var(--cx-accent-deep);
  --brass-bright: var(--cx-accent);
  --brass-dim: var(--cx-accent-dim);
  --paper: var(--cx-accent-bright);
  --paper-muted: var(--cx-accent);
  --paper-dim: var(--cx-accent-deep);
  --rule: var(--cx-accent-dim);
  --rule-strong: var(--cx-accent-dim);
  --danger: var(--cx-danger);
  --success: var(--cx-success);
  --info: #6d829b;
  --font-display: "Cinzel", Georgia, serif;
  --font-body: "EB Garamond", Georgia, serif;
  --font-prose: "Crimson Pro", Georgia, serif;
  --shell-height: 64px;
  --topbar-height: 42px;
  --content-width: 1380px;

  /* bridge legacy feature tokens */
  --bg-deep: var(--ink-black);
  --bg-surface: var(--ink-deep);
  --bg-card: var(--ink-panel);
  --bg-card-hover: var(--ink-hover);
  --border: var(--rule);
  --border-glow: var(--rule-strong);
  --gold: var(--brass);
  --gold-bright: var(--brass-bright);
  --gold-dim: var(--brass-dim);
  --text-primary: var(--paper);
  --text-secondary: var(--paper-muted);
  --text-dim: var(--paper-dim);
  --red: var(--cx-danger-deep);
  --red-bright: var(--danger);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(color-mix(in srgb,var(--cx-field) 94%,transparent), color-mix(in srgb,var(--cx-field) 97%,transparent)),
    url('../bg_texture.jpg') center / 700px auto repeat;
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.62;
}
body::before { display: none; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; }
::selection { background: color-mix(in srgb,var(--cx-accent-deep) 32%,transparent); }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--brass-bright);
  outline-offset: 3px;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}
.ui-icon {
  width: 17px;
  height: 17px;
  display: block;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.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;
}

/* ── Application shell: horizontal, website-like, not dashboard-like ── */
#app { min-height: 100vh; }
#sidebar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 500;
  width: 100%;
  height: var(--shell-height);
  display: flex;
  align-items: stretch;
  overflow: visible;
  padding: 0;
  background: color-mix(in srgb,var(--cx-field) 97%,transparent);
  border: 0;
  border-bottom: 1px solid var(--rule-strong);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  backdrop-filter: blur(12px);
}
#sidebar-header {
  width: 270px;
  min-width: 270px;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 18px;
  border: 0;
  border-right: 1px solid var(--rule);
}
#sidebar-header::before { display: none; }
.brand-home {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
  text-align: left;
  cursor: pointer;
}
.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--brass-bright);
  border: 1px solid var(--brass-dim);
  border-radius: 50%;
}
.brand-mark .ui-icon { width: 15px; height: 15px; }
.brand-copy { min-width: 0; }
#sidebar-header .world-name {
  display: block;
  margin-bottom: 2px;
  color: var(--paper-dim);
  font-family: var(--font-display);
  font-size: 8px;
  letter-spacing: .16em;
  line-height: 1.1;
  text-transform: uppercase;
}
#sidebar-header .campaign-title {
  display: block;
  overflow: hidden;
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .055em;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#sidebar-header .campaign-subtitle { display: none; }
.search-field { display: none; }

#nav-groups {
  min-width: 0;
  display: flex;
  align-items: stretch;
  flex: 1;
  overflow: visible;
}
.nav-section { position: relative; flex: 0 0 auto; }
.nav-section-label {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 18px;
  color: var(--paper-muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .11em;
  text-transform: uppercase;
  cursor: pointer;
}
.nav-section-label::after {
  content: '';
  width: 4px;
  height: 4px;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  opacity: .65;
}
.nav-section:hover > .nav-section-label,
.nav-section.open > .nav-section-label {
  color: var(--paper);
  border-bottom-color: var(--brass);
}
.nav-dropdown {
  display: none;
  position: absolute;
  top: calc(100% - 1px);
  left: 0;
  min-width: 230px;
  padding: 8px 0;
  background: var(--cx-surface);
  border: 1px solid var(--rule-strong);
  border-top: 2px solid var(--brass);
  box-shadow: 0 18px 45px rgba(0, 0, 0, .42);
}
.nav-section:hover > .nav-dropdown,
.nav-section.open > .nav-dropdown { display: block; }
.nav-item {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 8px 18px;
  color: var(--paper-muted);
  background: transparent;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
}
.nav-item .ui-icon { display: none; }
.nav-item:hover {
  color: var(--paper);
  background: color-mix(in srgb,var(--cx-accent-deep) 7%,transparent);
  border-left-color: var(--brass-dim);
}
.nav-item.active {
  color: var(--brass-bright);
  background: color-mix(in srgb,var(--cx-accent-deep) 9%,transparent);
  border-left-color: var(--brass);
}

#main {
  margin: 0;
  padding-top: var(--shell-height);
}
#topbar {
  position: relative;
  top: auto;
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 28px;
  background: color-mix(in srgb,var(--cx-field) 74%,transparent);
  border-bottom: 1px solid var(--rule);
}
#topbar::after { display: none; }
#topbar .breadcrumb {
  margin: 0;
  color: var(--paper-dim);
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: .11em;
  text-transform: uppercase;
}
#topbar .breadcrumb::before,
#topbar .breadcrumb::after { display: none; }
#topbar .breadcrumb strong { color: var(--paper-muted); font-weight: 600; }
.status-badge {
  position: static;
  color: var(--paper-dim);
  background: transparent;
  border: 0;
  border-radius: 0;
  font-family: var(--font-body);
  font-size: 13px;
  font-style: italic;
}
#content {
  width: min(100%, var(--content-width));
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 36px 28px 70px;
}
.page-loader {
  padding: 80px 20px;
  color: var(--paper-dim);
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: .12em;
  text-align: center;
  text-transform: uppercase;
}

/* ── Shared page language ── */
.page {
  padding: 30px;
  color: var(--paper);
  background: color-mix(in srgb,var(--cx-surface) 94%,transparent);
  border: 1px solid var(--rule);
  border-radius: 2px;
  box-shadow: 0 20px 55px rgba(0, 0, 0, .22);
}
.page:not(#page-home).active {
  padding: 30px;
  background: color-mix(in srgb,var(--cx-surface) 94%,transparent);
  border: 1px solid var(--rule);
  border-radius: 2px;
  box-shadow: 0 20px 55px rgba(0, 0, 0, .22);
}
.page-header {
  margin-bottom: 34px;
  padding: 0 0 20px;
  border-bottom: 1px solid var(--rule-strong);
}
.page-eyebrow,
.eyebrow {
  margin-bottom: 8px;
  color: var(--brass);
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .18em;
  text-transform: uppercase;
}
.page-title {
  margin: 0 0 10px;
  color: var(--paper);
  background: none;
  font-family: var(--font-display);
  font-size: clamp(29px, 3vw, 43px);
  font-weight: 600;
  letter-spacing: .01em;
  line-height: 1.12;
  -webkit-text-fill-color: currentColor;
}
.page-description {
  max-width: 760px;
  color: var(--paper-muted);
  font-family: var(--font-prose);
  font-size: 18px;
  font-style: italic;
  line-height: 1.55;
}
.section { margin-bottom: 38px; }
.section-title,
.section-header {
  margin-bottom: 16px;
  padding-bottom: 8px;
  color: var(--brass-bright);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.card,
.stat-block,
.ability,
.nation-card,
.img-card,
.inv-card,
.award-card,
.session-card,
.leg-item-card,
.atlas-world-card,
.gallery-upload,
.gallery-item,
.char-sheet,
.player-notes {
  color: var(--paper);
  background: var(--ink-panel);
  border: 1px solid var(--rule);
  border-radius: 2px;
  box-shadow: none;
}
.card,
.stat-block,
.ability,
.nation-card { padding: 18px 20px; }
.card::before { display: none; }
.card:hover,
.nation-card:hover,
.ability:hover,
.inv-card:hover,
.award-card:hover,
.session-card:hover,
.leg-item-card:hover,
.atlas-world-card:hover,
.realm-card:hover {
  transform: none;
  background: var(--ink-panel-raised);
  border-color: var(--rule-strong);
  box-shadow: none;
}
.card-title,
.stat-block-header,
.nation-name,
.ability-name,
.inv-card-title,
.award-title,
.leg-item-name {
  color: var(--paper);
  background: none;
  font-family: var(--font-display);
  font-weight: 600;
  -webkit-text-fill-color: currentColor;
}
.card-tag,
.stat-label,
.card-meta,
.pill { color: var(--paper-dim); }
.pill {
  padding: 2px 7px;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 1px;
  font-size: 9px;
}
.lore-block {
  margin: 20px 0;
  padding: 18px 22px;
  color: var(--paper-muted);
  background: color-mix(in srgb,var(--cx-accent-deep) 5.5%,transparent);
  border: 0;
  border-left: 2px solid var(--brass);
  font-family: var(--font-prose);
  font-style: italic;
}
.prose { color: var(--paper); }
.prose strong { color: var(--brass-bright); }
.prose h3 { color: var(--brass-bright); }
.timeline-dot { box-shadow: none; }

/* Buttons and inputs */
.button,
.wiki-button,
.new-session-btn,
.char-save-btn,
.inv-btn,
.home-action,
.atlas-button,
.gallery-button,
button[class*="btn"] {
  min-height: 39px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  color: var(--paper);
  background: transparent;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  box-shadow: none;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .09em;
  line-height: 1.15;
  text-transform: uppercase;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: color 150ms ease, background 150ms ease, border-color 150ms ease;
}
.button:hover,
.wiki-button:hover,
.new-session-btn:hover,
.char-save-btn:hover,
.inv-btn:hover,
.home-action:hover,
.atlas-button:hover,
.gallery-button:hover,
button[class*="btn"]:hover {
  transform: none;
  color: var(--paper);
  background: color-mix(in srgb,var(--cx-accent-deep) 8%,transparent);
  border-color: var(--brass);
  filter: none;
}
.button-primary,
.wiki-button,
.char-save-btn,
.inv-btn.gold,
.home-action.primary {
  color: var(--cx-surface);
  background: var(--brass);
  border-color: var(--brass);
}
.button-primary:hover,
.wiki-button:hover,
.char-save-btn:hover,
.inv-btn.gold:hover,
.home-action.primary:hover {
  color: var(--cx-field);
  background: var(--brass-bright);
  border-color: var(--brass-bright);
}
.button-danger { color: var(--cx-danger); border-color: var(--cx-danger-deep); }
.button-danger:hover { background: color-mix(in srgb,var(--cx-danger) 9%,transparent); border-color: var(--danger); }
.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--paper-muted);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
}

input,
select,
textarea,
#search-box,
.home-search input,
.atlas-search,
.field input,
.field select,
.field textarea,
.gallery-upload input[type="file"],
.gallery-upload input[type="text"],
.gallery-upload textarea {
  width: 100%;
  color: var(--paper);
  background: var(--cx-field);
  border: 1px solid var(--rule);
  border-radius: 2px;
  outline: 0;
}
input,
select,
textarea { padding: 10px 12px; }
input:focus,
select:focus,
textarea:focus,
#search-box:focus,
.home-search input:focus,
.atlas-search:focus { border-color: var(--brass); box-shadow: none; }
input::placeholder,
textarea::placeholder { color: var(--paper-dim); }

/* Modals remain centered and intentionally plain. */
.modal,
.modal-content,
.dcs-modal,
.dcs-modal-panel,
.inv-modal-content,
.session-modal-content {
  color: var(--paper);
  background: var(--ink-deep);
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .58);
}


/* Feature-fix pass: stable inner-page navigation and reusable admin controls. */
#sidebar #nav-groups {
  gap: 0;
  align-items: stretch;
}
#sidebar .nav-section {
  position: relative;
  display: flex;
  align-items: stretch;
  border-left: 1px solid color-mix(in srgb,var(--cx-accent-deep) 12%,transparent);
}
#sidebar .nav-section:last-child { border-right: 1px solid color-mix(in srgb,var(--cx-accent-deep) 12%,transparent); }
#sidebar .nav-section > .nav-section-label {
  min-width: 96px;
  justify-content: center;
  padding-inline: clamp(13px, 1.45vw, 22px);
}
#sidebar .nav-section > .nav-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: auto;
  z-index: 1000;
  box-sizing: border-box;
  margin: 0;
}
#sidebar .nav-section:last-child > .nav-dropdown {
  left: auto;
  right: 0;
}

.cx-add-subpage-btn {
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 14px 0 0;
  padding: 7px 11px;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  background: color-mix(in srgb,var(--cx-accent-deep) 7%,transparent);
  color: var(--brass-light);
  font: 600 10px/1 var(--font-display);
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
}
.cx-add-subpage-btn:hover { background: color-mix(in srgb,var(--cx-accent-deep) 14%,transparent); }
.cx-subpage-link { margin-top: 14px; }
.cx-subpage-link.section { margin-top: 0; }
.npc-subpage-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.vote-option {
  width: 100%;
  color: inherit;
  background: transparent;
  text-align: left;
}
.vote-option:disabled { opacity: .5; cursor: not-allowed; }
.vote-avatar-fallback {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb,var(--cx-accent-deep) 38%,transparent);
  border-radius: 50%;
  background: color-mix(in srgb,var(--cx-accent-deep) 10%,transparent);
  color: var(--brass-light);
  font: 600 11px/1 var(--font-display);
}

#wiki-map-modal { position: fixed; inset: 0; z-index: 3000; }
#wiki-map-modal .cx-modal-backdrop { position: absolute; inset: 0; }
#wiki-map-modal .wiki-map-dialog {
  position: relative;
  z-index: 1;
  width: min(560px, calc(100vw - 32px));
  margin: 8vh auto 0;
}
#wiki-map-modal input[type="file"] { padding: 10px; }
