/*
 * Wiki — "the codex" — restyled to match the game's sci-fi HUD aesthetic.
 * Loaded only by the wiki layout. Reuses the game's space background and footer
 * partials; this file owns the typography, palette, and component styling.
 */

:root {
  --codex-ink: #1f2937;            /* gray-800 — light mode body */
  --codex-ink-bright: #0f172a;     /* slate-900 */
  --codex-ink-mute: #475569;       /* slate-600 */
  --codex-ink-faint: #94a3b8;      /* slate-400 */
  --codex-rule: rgba(15, 75, 145, 0.28);
  --codex-rule-soft: rgba(15, 75, 145, 0.12);
  --codex-accent: #0f4b91;         /* light sky */
  --codex-accent-hover: #1d4ed8;
  --codex-accent-glow: rgba(15, 75, 145, 0.18);
  --codex-warn: #b91c1c;
  --codex-panel-bg: rgba(255, 255, 255, 0.75);
  --codex-input-bg: rgba(255, 255, 255, 0.7);
  --codex-display: 'Orbitron', sans-serif;
  --codex-body: ui-sans-serif, system-ui, -apple-system, 'Helvetica Neue', sans-serif;
  --codex-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
}

.dark {
  --codex-ink: #e2e8f0;            /* slate-200 — body prose */
  --codex-ink-bright: #f1f5f9;     /* slate-100 — pulled back from chalk-white */
  --codex-ink-mute: #94a3b8;       /* slate-400 */
  --codex-ink-faint: #64748b;      /* slate-500 */
  --codex-rule: rgba(56, 189, 248, 0.3);
  --codex-rule-soft: rgba(56, 189, 248, 0.12);
  --codex-accent: #38bdf8;         /* sky-400 */
  --codex-accent-hover: #7dd3fc;   /* sky-300 */
  --codex-accent-glow: rgba(56, 189, 248, 0.35);
  --codex-warn: #f87171;
  --codex-panel-bg: rgba(3, 7, 18, 0.78);
  --codex-input-bg: rgba(15, 23, 42, 0.6);
}

/* ── Page wrapper ──────────────────────────────────────────── */

.codex-page {
  color: var(--codex-ink);
  font-family: var(--codex-body);
  background-color: #1e293b;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Prevent rogue wide imported content (large MediaWiki tables, fixed-width
     spans, etc.) from forcing the page to scroll horizontally — wide tables
     should scroll inside their own container instead. */
  overflow-x: hidden;
}


/* ── Article body panel (elevated glass surface for prose) ── */

.codex-content-panel {
  background-color: var(--codex-panel-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 0.75rem;
  padding: 2.25rem 2.5rem 2.75rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 12px 30px rgba(0, 0, 0, 0.25);
  /* Hard cap so wide imported content can't push the panel past the viewport.
     `min-width: 0` is needed so the panel can shrink below its content size
     when the cumulative inline-styled content (e.g. fixed-width tables) would
     otherwise force the panel wider. */
  max-width: 100%;
  min-width: 0;
}

.dark .codex-content-panel {
  border-color: rgba(71, 85, 105, 0.55);
}

@media (min-width: 1024px) {
  .codex-content-panel {
    padding: 2.75rem 3.5rem 3rem;
  }
}

/* ── Top-bar panel (game-style glass card with HUD brackets) ── */

.codex-topbar {
  background-color: var(--codex-panel-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-top: 0;
  border-radius: 0 0 0.75rem 0.75rem;
  position: relative;
}

.dark .codex-topbar {
  border-color: rgba(71, 85, 105, 0.55);
}

/* ── Wordmark + actions ───────────────────────────────────── */

.codex-mark {
  font-family: var(--codex-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--codex-accent);
  text-decoration: none;
  text-shadow: 0 0 10px var(--codex-accent-glow);
  transition: color 200ms ease, text-shadow 200ms ease;
}

.codex-mark:hover {
  color: var(--codex-accent-hover);
  text-shadow: 0 0 14px var(--codex-accent-glow);
}

.codex-mark > .glyph {
  display: inline-block;
  margin-right: 0.55em;
  font-weight: 400;
  opacity: 0.85;
}

.codex-action {
  font-family: var(--codex-display);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--codex-ink-mute);
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  transition: color 200ms ease, text-shadow 200ms ease;
  text-decoration: none;
}

.codex-action:hover {
  color: var(--codex-accent);
  text-shadow: 0 0 8px var(--codex-accent-glow);
}

.codex-action.danger:hover {
  color: var(--codex-warn);
  text-shadow: 0 0 8px rgba(248, 113, 113, 0.4);
}

form.button_to {
  display: contents;
}

/* ── Breadcrumbs ────────────────────────────────────────────── */

.codex-crumbs {
  font-family: var(--codex-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  color: var(--codex-ink-faint);
}

.codex-crumbs a {
  color: var(--codex-ink-mute);
  transition: color 150ms ease;
  text-decoration: none;
}

.codex-crumbs a:hover {
  color: var(--codex-accent-hover);
}

.codex-crumbs .sep {
  margin: 0 0.5em;
  color: var(--codex-ink-faint);
}

/* ── Article title block ───────────────────────────────────── */

.codex-title {
  font-family: var(--codex-display);
  font-weight: 700;
  font-size: clamp(1.1rem, 4.8vw, 2.25rem);
  line-height: 1.15;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--codex-ink-bright);
  margin-top: 0.7rem;
  text-shadow: 0 0 14px var(--codex-accent-glow);
  /* Imported titles like "APOLLO CLASS FIGHTER" are long; allow wrap on
     narrow viewports so they don't clip past the panel edge. */
  overflow-wrap: break-word;
  word-wrap: break-word;
  hyphens: auto;
}

.codex-title .index-glyph {
  color: var(--codex-accent);
  margin-right: 0.45rem;
  font-weight: 500;
  opacity: 0.9;
}

.codex-attribution {
  margin-top: 1rem;
  font-family: var(--codex-body);
  font-size: 13px;
  color: var(--codex-ink-mute);
  letter-spacing: 0.01em;
}

.codex-divider {
  border: 0;
  border-top: 1px solid var(--codex-accent);
  width: 4rem;
  margin: 1.6rem 0 0;
  opacity: 0.55;
  box-shadow: 0 0 8px var(--codex-accent-glow);
}

/* ── Prose (rendered article body) ─────────────────────────── */

.codex-prose {
  font-family: var(--codex-body);
  font-size: 17px;
  line-height: 1.75;
  color: var(--codex-ink);
  margin-top: 2.75rem;
}

.codex-prose > * + *,
.codex-prose .trix-content > * + * {
  margin-top: 1.1em;
}

.codex-prose p,
.codex-prose ul,
.codex-prose ol,
.codex-prose dl,
.codex-prose blockquote,
.codex-prose pre,
.codex-prose figure,
.codex-prose table {
  margin-top: 0;
  margin-bottom: 1.1em;
}

.codex-prose p:last-child,
.codex-prose ul:last-child,
.codex-prose ol:last-child {
  margin-bottom: 0;
}

/* Auto clearfix so floated thumbs don't escape the article. */
.codex-prose::after {
  content: "";
  display: block;
  clear: both;
}

.codex-prose h1,
.codex-prose h2,
.codex-prose h3 {
  font-family: var(--codex-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--codex-ink-bright);
}

.codex-prose h1 {
  font-size: 1.4em;
  margin-top: 2.4em;
  text-shadow: 0 0 10px var(--codex-accent-glow);
}

.codex-prose h2 {
  font-size: 1.05em;
  margin-top: 2em;
  padding-bottom: 0.45em;
  border-bottom: 1px solid var(--codex-rule);
}

.codex-prose h3 {
  font-size: 0.92em;
  margin-top: 1.6em;
  color: var(--codex-accent);
}

.codex-prose a {
  color: var(--codex-accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: rgba(56, 189, 248, 0.4);
  transition: color 150ms ease, text-decoration-color 150ms ease;
}

.codex-prose a:hover {
  color: var(--codex-accent-hover);
  text-decoration-color: var(--codex-accent-hover);
}

.codex-prose strong {
  color: var(--codex-ink-bright);
  font-weight: 600;
}

.codex-prose em {
  font-style: italic;
}

.codex-prose blockquote {
  font-style: italic;
  color: var(--codex-ink-mute);
  border-left: 2px solid var(--codex-accent);
  padding-left: 1.25em;
  margin-left: 0;
  background-color: var(--codex-input-bg);
  padding-top: 0.5em;
  padding-bottom: 0.5em;
  padding-right: 1em;
}

.codex-prose ul,
.codex-prose ol {
  padding-left: 1.6em;
}

.codex-prose ul > li {
  list-style: none;
  position: relative;
}

.codex-prose ul > li::before {
  content: "▸";
  position: absolute;
  left: -1.1em;
  top: 0.05em;
  color: var(--codex-accent);
  font-size: 0.85em;
}

.codex-prose ol > li {
  list-style: decimal;
}

.codex-prose ol > li::marker {
  color: var(--codex-accent);
  font-family: var(--codex-mono);
}

.codex-prose li + li {
  margin-top: 0.4em;
}

.codex-prose pre {
  font-family: var(--codex-mono);
  font-size: 13px;
  line-height: 1.55;
  background-color: var(--codex-input-bg);
  border: 1px solid var(--codex-rule);
  border-radius: 4px;
  padding: 1em 1.2em;
  overflow-x: auto;
  color: var(--codex-ink);
}

.codex-prose code {
  font-family: var(--codex-mono);
  font-size: 0.88em;
  background-color: var(--codex-input-bg);
  border: 1px solid var(--codex-rule-soft);
  border-radius: 3px;
  padding: 0.1em 0.4em;
  color: var(--codex-accent-hover);
}

.codex-prose pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.codex-prose hr {
  border: 0;
  text-align: center;
  margin: 2.5em 0;
  height: 1em;
}

.codex-prose hr::before {
  content: "◆ ◆ ◆";
  color: var(--codex-ink-faint);
  font-size: 0.7em;
  letter-spacing: 0.6em;
}

.codex-prose img {
  max-width: 100%;
  max-height: 240px;
  height: auto;
  width: auto;
  border-radius: 4px;
  border: 1px solid var(--codex-rule-soft);
}

/* Tables — make them horizontally scrollable when they would otherwise
   overflow the article column. Wrapping each <table> in a .table-scroll
   container is done at render time (see wiki_pages_helper#render_wiki_body). */
.codex-prose .table-scroll {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.5rem 0;
  /* visual hint that there is more content to scroll on small screens */
  scrollbar-color: var(--codex-rule) transparent;
}

.codex-prose table {
  border-collapse: collapse;
  margin: 0;
  /* keep tables from being forced full-width when they appear standalone */
  max-width: 100%;
}

.codex-prose .table-scroll > table {
  margin: 0;
}

.codex-prose td,
.codex-prose th {
  padding: 0.6rem 0.85rem;
  vertical-align: top;
  border: 1px solid var(--codex-rule-soft);
  /* drop legacy invalid `vertical-align: text-top` etc. — our rule wins by specificity */
}

.codex-prose th {
  font-family: var(--codex-display);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 0.8rem;
  color: var(--codex-ink-bright);
  background-color: var(--codex-input-bg);
  text-align: center;
}

/* Cells holding plain numeric/text data inside the inherited MediaWiki
   `<p>` wrappers — kill the paragraph spacing so cells don't look like
   they have an extra blank line. */
.codex-prose td > p,
.codex-prose th > p {
  margin: 0;
}

/* Legacy MediaWiki ".infoboxcell" — used in the floated nested-table
   info-box on ship and similar pages. Right-align the value column. */
.codex-prose td.infoboxcell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Empty captions left over from MediaWiki — collapse. */
.codex-prose table caption:empty {
  display: none;
}

/* The nested floated info-box on ship pages: outer table is the wrapper,
   inner table is the content. We give the wrapper width/float behaviour
   but normalize border/padding so it reads as a card.

   `max-width: 100% !important` is critical: the imported HTML carries
   inline `style="width:300px"` which would otherwise overflow narrow
   viewports. !important overrides the inline style. */
.codex-prose table[style*="float:right"],
.codex-prose table[style*="float: right"] {
  float: right;
  clear: right;
  width: 18rem;
  max-width: 100% !important;
  margin: 0 0 1.5rem 1.5rem;
  border: 1px solid var(--codex-rule);
  border-radius: 6px;
  background-color: var(--codex-input-bg);
}

/* Inner table (the content of the info-box) must not double-up the border. */
.codex-prose table[style*="float:right"] table,
.codex-prose table[style*="float: right"] table {
  width: 100%;
  margin: 0;
  border: 0;
}

.codex-prose table[style*="float:right"] td,
.codex-prose table[style*="float:right"] th,
.codex-prose table[style*="float: right"] td,
.codex-prose table[style*="float: right"] th {
  border-color: transparent;
  border-bottom: 1px solid var(--codex-rule-soft);
  padding: 0.45rem 0.75rem;
  font-size: 0.9rem;
  line-height: 1.4;
}

.codex-prose table[style*="float:right"] th[colspan],
.codex-prose table[style*="float: right"] th[colspan] {
  background-color: transparent;
  font-family: var(--codex-display);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  color: var(--codex-accent);
  text-transform: uppercase;
  border-bottom: 1px solid var(--codex-rule);
  padding-top: 0.9rem;
}

/* Legacy ship-page Statistics: three side-by-side floated divs ("Cost",
   "Specifications", "Rapid Fire"). On any narrow screen they need to stack. */
.codex-prose div[style*="float:left"],
.codex-prose div[style*="float: left"] {
  box-sizing: border-box;
  width: calc(33.333% - 1rem);
  min-width: 14rem;
  margin: 0 0.5rem 1rem;
  text-align: left !important;
}

.codex-prose dl {
  margin: 0.5rem 0;
}

.codex-prose dt {
  margin-top: 0.25rem;
}

.codex-prose dd {
  margin-left: 1.5rem;
}

.codex-prose figure.attachment {
  display: inline-block;
  margin: 0.25rem 0;
  max-width: 100%;
}

.codex-prose figure.attachment img {
  display: block;
}

.codex-prose figure.attachment .attachment__caption {
  display: none;
}

/* Sized thumbnails — icons whose original MediaWiki <img> had explicit
   width/height attributes. The .wiki-thumb wrapper carries those dimensions
   as inline style so the icon renders at its intended size, not at its
   stored variant size. */
.codex-prose .wiki-thumb {
  display: inline-block;
  vertical-align: middle;
}

/* MediaWiki .thumb.tleft / .thumb.tright / .floatleft / .floatright become
   floated thumbs on import so prose wraps around them like the original wiki. */
.codex-prose .wiki-thumb-left {
  float: left;
  margin: 0.25rem 1.25rem 0.5rem 0;
}

.codex-prose .wiki-thumb-right {
  float: right;
  margin: 0.25rem 0 0.5rem 1.25rem;
}

.codex-prose .wiki-thumb figure.attachment {
  margin: 0;
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.codex-prose .wiki-thumb figure.attachment img {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: contain;
  border: none;
  border-radius: 0;
}

/* ── Responsive cleanup for the imported MediaWiki content ─────
   Below 768px (tablets and narrower), undo MediaWiki layout patterns:
   - floated image thumbs become full-width centered blocks
   - the nested-table info-box drops its float and goes full-width
   - the three-column Statistics floats stack vertically
   - generic prose floats clear so paragraphs don't collapse into 80px columns */

@media (max-width: 767px) {
  /* Image thumbs — the imported HTML carries inline `style="width:300px;height:300px"`
     so we need !important to override. Below the breakpoint they become inline,
     full-width images sized by their natural aspect ratio. */
  .codex-prose .wiki-thumb,
  .codex-prose .wiki-thumb-left,
  .codex-prose .wiki-thumb-right {
    float: none !important;
    display: block !important;
    width: 100% !important;
    max-width: 22rem !important;
    height: auto !important;
    margin: 1rem auto !important;
  }

  .codex-prose .wiki-thumb figure.attachment {
    margin: 0 auto;
  }

  .codex-prose .wiki-thumb figure.attachment img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 22rem;
    margin: 0 auto;
  }

  /* Tiny inline icons (e.g. note bulb, sigil glyphs) keep their inline flow
     and a sensible size cap. */
  .codex-prose .wiki-thumb[style*="width:18px"],
  .codex-prose .wiki-thumb[style*="width:25px"],
  .codex-prose .wiki-thumb[style*="width:32px"],
  .codex-prose .wiki-thumb[style*="width:40px"],
  .codex-prose .wiki-thumb[style*="width:50px"] {
    display: inline-block !important;
    width: auto !important;
    max-width: 3rem !important;
    margin: 0 0.25rem !important;
  }

  /* Nested-table info-box (ship pages): float was sized 300px; release it. */
  .codex-prose table[style*="float:right"],
  .codex-prose table[style*="float: right"],
  .codex-prose table[style*="float:left"],
  .codex-prose table[style*="float: left"] {
    float: none !important;
    width: 100% !important;
    margin: 0 0 1.5rem 0 !important;
  }

  /* Floated stat-block divs (ship pages: three side-by-side "Cost",
     "Specifications", "Rapid Fire"). */
  .codex-prose div[style*="float:left"],
  .codex-prose div[style*="float: left"],
  .codex-prose div[style*="float:right"],
  .codex-prose div[style*="float: right"] {
    float: none !important;
    width: 100% !important;
    margin: 0 0 1rem 0 !important;
    text-align: left !important;
  }

  /* Tighten the article panel padding so we get more content width. */
  .codex-content-panel {
    padding: 1.4rem 1.1rem 1.6rem;
  }

  .codex-prose {
    font-size: 16px;
  }

  /* Tables — force horizontal scroll on wide data tables (no inline float).
     We use `display:block; overflow-x:auto` so the table can be wider than
     the viewport and the user can swipe horizontally. The :not() guard keeps
     this OFF the floated info-box tables, which the migration cleanup has
     already converted into semantic <aside class="codex-infobox"> markup. */
  .codex-prose table:not([style*="float"]) {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Section headings — give them a little breathing room on mobile. */
  .codex-prose h2 {
    margin-top: 1.6em;
  }

  .codex-prose h3 {
    margin-top: 1.4em;
  }
}

/* ── Tablet/small-desktop tweaks for the floated info-box ──────
   Above 768px the float still applies but we cap its width so the prose
   column gets enough room and the info-box doesn't span half the page. */
@media (min-width: 768px) {
  .codex-prose table[style*="float:right"],
  .codex-prose table[style*="float: right"] {
    width: 18rem;
  }
}

/* ── Codex infobox (cleaned-up replacement for legacy MediaWiki nested-table
   info-boxes on ship/building/tech pages) ──────────────────── */

.codex-prose .codex-infobox {
  float: right;
  clear: right;
  width: 18rem;
  max-width: 100%;
  margin: 0 0 1.5rem 1.5rem;
  border: 1px solid var(--codex-rule);
  border-radius: 6px;
  background-color: var(--codex-input-bg);
  padding: 0.6rem 0.85rem 0.85rem;
  font-size: 0.92rem;
  line-height: 1.45;
}

.codex-prose .codex-infobox__figure {
  margin: -0.6rem -0.85rem 0.6rem;
  text-align: center;
  background-color: rgba(0, 0, 0, 0.25);
  border-bottom: 1px solid var(--codex-rule-soft);
  border-radius: 6px 6px 0 0;
  overflow: hidden;
}

.codex-prose .codex-infobox__figure figure.attachment {
  display: block;
  margin: 0;
}

.codex-prose .codex-infobox__figure figure.attachment img,
.codex-prose .codex-infobox__figure img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 14rem;
  object-fit: contain;
  border: 0;
  border-radius: 0;
}

/* The wiki-thumb wrapper inside the figure carries an inline width/height
   from the source HTML — neutralize so the image fills the figure naturally. */
.codex-prose .codex-infobox__figure .wiki-thumb {
  display: block !important;
  float: none !important;
  width: 100% !important;
  height: auto !important;
  margin: 0 !important;
  max-width: 100% !important;
}

.codex-prose .codex-infobox__title {
  font-family: var(--codex-display);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--codex-accent);
  text-align: center;
  padding: 0.25rem 0 0.55rem;
  border-bottom: 1px solid var(--codex-rule-soft);
  margin-bottom: 0.4rem;
}

.codex-prose .codex-infobox__heading {
  font-family: var(--codex-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--codex-accent);
  margin: 0.85rem 0 0.3rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--codex-rule-soft);
}

.codex-prose .codex-infobox__heading:first-child,
.codex-prose .codex-infobox__title + .codex-infobox__heading {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.codex-prose .codex-infobox__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 0;
  border-bottom: 1px dotted var(--codex-rule-soft);
}

.codex-prose .codex-infobox__row:last-child {
  border-bottom: 0;
}

.codex-prose .codex-infobox__label {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--codex-ink-mute);
  word-break: break-word;
}

.codex-prose .codex-infobox__label > p,
.codex-prose .codex-infobox__value > p {
  margin: 0;
  display: inline;
}

.codex-prose .codex-infobox__value {
  flex: 0 0 auto;
  text-align: right;
  color: var(--codex-ink-bright);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 767px) {
  .codex-prose .codex-infobox {
    float: none;
    width: 100%;
    margin: 1rem 0 1.5rem;
  }
}

/* Cleaned-up replacement for legacy MediaWiki "main page" layout tables —
   `<table style="width:100%">` used as a multi-column visual grid. The
   transform converts each cell to a `.codex-grid__cell` and lets CSS Grid
   handle responsiveness: 3-up on wide screens, naturally stacks on narrow
   ones via `auto-fit minmax`. */
.codex-prose .codex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1.5rem 2rem;
  margin: 1.5rem 0;
  align-items: start;
}

.codex-prose .codex-grid__cell {
  min-width: 0;
}

.codex-prose .codex-grid__cell--span {
  grid-column: 1 / -1;
}

.codex-prose .codex-grid__cell > dl {
  margin: 0;
}

/* Cleaned-up replacement for the broken spatial requirements tech-tree.
   Renders as a simple, scannable list of "Requires X level Y" items. */
.codex-prose .codex-requirements-list {
  list-style: none;
  padding: 0.5rem 0.75rem;
  margin: 1.25rem 0;
  border: 1px solid var(--codex-rule-soft);
  border-radius: 4px;
  background-color: var(--codex-input-bg);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: 0.4rem 1rem;
}

.codex-prose .codex-requirements-list > li {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  font-size: 0.95rem;
  color: var(--codex-ink-mute);
}

.codex-prose .codex-requirements-list > li::before {
  content: "▸";
  color: var(--codex-accent);
  margin-right: 0.4em;
  font-size: 0.85em;
}

.codex-prose .codex-requirements-list > li strong,
.codex-prose .codex-requirements-list > li b {
  color: var(--codex-ink-bright);
  font-weight: 500;
}

/* ── Index list (page directory) ───────────────────────────── */

.codex-index {
  margin-top: 2.5rem;
}

.codex-index-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 1.5rem;
  padding: 1rem 0.25rem;
  border-bottom: 1px solid var(--codex-rule-soft);
  text-decoration: none;
  transition: border-color 200ms ease, background-color 200ms ease, padding-left 200ms ease;
}

.codex-index-row:hover {
  border-bottom-color: var(--codex-accent);
  background-color: var(--codex-input-bg);
  padding-left: 0.75rem;
}

.codex-index-row .title {
  font-family: var(--codex-display);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--codex-ink-bright);
  transition: color 200ms ease;
}

.codex-index-row:hover .title {
  color: var(--codex-accent);
}

.codex-index-row .path {
  font-family: var(--codex-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--codex-ink-faint);
}

.codex-empty {
  margin-top: 4rem;
  padding: 3rem 2rem;
  border: 1px dashed var(--codex-rule);
  text-align: center;
  font-family: var(--codex-body);
  color: var(--codex-ink-mute);
  background-color: var(--codex-input-bg);
  border-radius: 6px;
}

/* ── Forms ─────────────────────────────────────────────────── */

.codex-field {
  display: block;
  margin-top: 1.75rem;
}

.codex-field-label {
  display: block;
  font-family: var(--codex-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--codex-ink-mute);
  margin-bottom: 0.6rem;
}

.codex-field-help {
  font-family: var(--codex-body);
  font-size: 12px;
  color: var(--codex-ink-faint);
  margin-top: 0.4rem;
}

.codex-input {
  width: 100%;
  background-color: var(--codex-input-bg);
  border: 1px solid var(--codex-rule);
  border-radius: 4px;
  padding: 0.65rem 0.9rem;
  font-family: var(--codex-body);
  font-size: 1.05rem;
  color: var(--codex-ink-bright);
  outline: none;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}

.codex-input:focus {
  border-color: var(--codex-accent);
  box-shadow: 0 0 0 1px var(--codex-accent), 0 0 14px var(--codex-accent-glow);
}

.codex-input.path-input {
  font-family: var(--codex-mono);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

/* Wiki source-mode editor — raw HTML in a textarea. */
.codex-input.wiki-source {
  font-family: var(--codex-mono);
  font-size: 0.85rem;
  line-height: 1.55;
  letter-spacing: 0.005em;
  resize: vertical;
  min-height: 480px;
  white-space: pre-wrap;
  word-break: break-word;
}

.wiki-source-toolbar {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-top: 0.6rem;
}

.wiki-source-status {
  font-family: var(--codex-mono);
  font-size: 0.8rem;
  color: var(--codex-ink-faint);
  letter-spacing: 0.02em;
}

/* ── Search bar (in the wiki layout, below the topbar) ──── */

.codex-search {
  position: relative;
  display: block;
  width: 100%;
}

@media (min-width: 640px) {
  .codex-search {
    max-width: 22rem;
    margin-left: auto;
  }
}

/* Inline variant — used when the search lives inside a fixed-width slot
   (e.g. the topbar middle column on >= md). Lets the slot control width. */
.codex-search.codex-search--inline {
  max-width: none;
  margin-left: 0;
}

.codex-search__icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0.95rem;
  height: 0.95rem;
  color: var(--codex-ink-faint);
  pointer-events: none;
  transition: color 200ms ease;
}

.codex-search:focus-within .codex-search__icon {
  color: var(--codex-accent);
}

.codex-search__input {
  width: 100%;
  background-color: var(--codex-input-bg);
  border: 1px solid var(--codex-rule);
  border-radius: 6px;
  padding: 0.55rem 0.9rem 0.55rem 2.4rem;
  font-family: var(--codex-mono);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  color: var(--codex-ink-bright);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}

.codex-search__input::placeholder {
  color: var(--codex-ink-faint);
  font-family: var(--codex-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.codex-search__input:hover {
  border-color: rgba(56, 189, 248, 0.45);
}

.codex-search__input:focus {
  border-color: var(--codex-accent);
  box-shadow: 0 0 0 1px var(--codex-accent), 0 0 14px var(--codex-accent-glow);
}

.codex-search__input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  height: 0.85rem;
  width: 0.85rem;
  margin-left: 0.4rem;
  background-color: var(--codex-ink-faint);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M6 6l8 8M14 6L6 14' stroke='black' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
          mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M6 6l8 8M14 6L6 14' stroke='black' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  cursor: pointer;
  transition: background-color 200ms ease;
}

.codex-search__input::-webkit-search-cancel-button:hover {
  background-color: var(--codex-accent);
}

.codex-form-errors {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-left: 2px solid var(--codex-warn);
  background-color: rgba(248, 113, 113, 0.1);
  font-family: var(--codex-body);
  font-size: 13px;
  color: var(--codex-ink);
  border-radius: 0 4px 4px 0;
}

.codex-form-errors .label {
  font-family: var(--codex-display);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 10px;
  color: var(--codex-warn);
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.codex-form-actions {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--codex-rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.codex-btn {
  font-family: var(--codex-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 0.7rem 1.5rem;
  border: 1px solid var(--codex-accent);
  color: white;
  background-color: var(--codex-accent);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 200ms ease, box-shadow 200ms ease, transform 100ms ease;
}

.codex-btn:hover {
  background-color: var(--codex-accent-hover);
  box-shadow: 0 0 18px var(--codex-accent-glow);
}

.codex-btn:active {
  transform: translateY(1px);
}

.dark .codex-btn {
  color: #0c1424;
}

/* ── Beta notice banner (golden alert) ─────────────────────── */

.codex-beta-banner {
  background-color: #fbbf24;          /* amber-400 — solid gold */
  color: #1c1917;                     /* stone-900 — high contrast on gold */
  border: 1px solid #b45309;          /* amber-700 — definition against dark bg */
  border-radius: 0.75rem;
  padding: 0.75rem 1.125rem;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}

.codex-beta-banner__chip {
  flex: 0 0 auto;
  font-family: var(--codex-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 0.25rem 0.625rem;
  background-color: #1c1917;
  color: #fbbf24;
  border-radius: 0.375rem;
}

.codex-beta-banner__body {
  margin: 0;
  font-size: 17px;
  line-height: 1.45;
}

@media (max-width: 640px) {
  .codex-beta-banner {
    align-items: flex-start;
    gap: 0.625rem;
  }
  .codex-beta-banner__chip {
    margin-top: 0.125rem;
  }
}

/* ── Comments ──────────────────────────────────────────────── */

.codex-comments {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--codex-rule-soft);
}

.codex-comments__heading {
  font-family: var(--codex-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--codex-ink-mute);
  margin: 0 0 1.25rem;
}

.codex-comments-list {
  list-style: none;
  padding: 0;
  margin: 0 0 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.codex-comments-empty {
  font-family: var(--codex-body);
  font-size: 14px;
  color: var(--codex-ink-faint);
  font-style: italic;
  margin: 0 0 2rem;
}

.codex-comments-error {
  font-family: var(--codex-body);
  font-size: 14px;
  color: var(--codex-warn);
  background-color: rgba(248, 113, 113, 0.08);
  border: 1px solid var(--codex-warn);
  border-radius: 4px;
  padding: 0.65rem 0.9rem;
  margin: 0 0 1rem;
}

.codex-comment {
  background-color: var(--codex-panel-bg);
  border: 1px solid var(--codex-rule-soft);
  border-radius: 6px;
  padding: 1rem 1.15rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.codex-comment__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.5rem;
}

.codex-comment__avatar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}

.codex-comment__author {
  font-family: var(--codex-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--codex-ink-bright);
}

.codex-comment__time {
  font-family: var(--codex-body);
  font-size: 12px;
  color: var(--codex-ink-faint);
}

.codex-comment__stale {
  font-family: var(--codex-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--codex-ink-faint);
  border: 1px solid var(--codex-rule-soft);
  border-radius: 3px;
  padding: 0.15rem 0.45rem;
}

.codex-comment__delete-form {
  margin-left: auto;
}

.codex-comment__body {
  font-size: 15px;
  line-height: 1.6;
}

.codex-comment__body > *:first-child {
  margin-top: 0;
}

.codex-comment__body > *:last-child {
  margin-bottom: 0;
}

.codex-comment-form-area {
  margin-top: 1rem;
}

.codex-comments-cta {
  font-family: var(--codex-body);
  font-size: 14px;
  color: var(--codex-ink-mute);
  background-color: var(--codex-input-bg);
  border: 1px dashed var(--codex-rule);
  border-radius: 6px;
  padding: 0.85rem 1.1rem;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.codex-comment-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.codex-comment-form__label {
  font-family: var(--codex-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--codex-ink-mute);
}

.codex-comment-form__label strong {
  color: var(--codex-ink-bright);
  font-weight: 700;
}

.codex-comment-form__textarea {
  width: 100%;
  background-color: var(--codex-input-bg);
  border: 1px solid var(--codex-rule);
  border-radius: 4px;
  padding: 0.65rem 0.9rem;
  font-family: var(--codex-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--codex-ink-bright);
  outline: none;
  resize: vertical;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}

.codex-comment-form__textarea:focus {
  border-color: var(--codex-accent);
  box-shadow: 0 0 0 1px var(--codex-accent), 0 0 14px var(--codex-accent-glow);
}

.codex-comment-form__submit {
  align-self: flex-start;
  font-family: var(--codex-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--codex-ink-bright);
  background-color: var(--codex-accent);
  border: 0;
  border-radius: 4px;
  padding: 0.55rem 1.1rem;
  cursor: pointer;
  transition: background-color 200ms ease, box-shadow 200ms ease;
}

.codex-comment-form__submit:hover {
  background-color: var(--codex-accent-hover);
  box-shadow: 0 0 14px var(--codex-accent-glow);
}

.codex-comment-form__submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.dark .codex-comment-form__submit {
  color: #0c1424;
}

