/* ── Tokens ──────────────────────────────────────────────────────────────── */
:root {
  --bg-primary:    #eadcc5;
  --bg-secondary:  #fbeed5;
  --bg-tertiary:   #dcd3c3;
  --text-header:   #6a5f55;
  --text-primary:  #4a3f35;
  --text-secondary:#6a5f55;
  --border:        #865809;
  --accent:        #6a5f55;
  --link:          #3c9d9f;
  --link-broken:   #b04a4a;
  --error:         #8b0000;

  --font-heading: 'Girassol', serif;
  --font-body:    'Nunito', sans-serif;

  --radius: 3px;
  --nav-h: 56px;
}

/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.75;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Nav ─────────────────────────────────────────────────────────────────── */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: var(--bg-tertiary);
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  gap: 1rem;
}

.site-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  color: var(--text-header);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: 0.03em;
}
.site-title:hover { color: var(--link); }

.nav-links {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
}
.nav-links a {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.nav-links a:hover,
.nav-links a[aria-current="page"] {
  color: var(--link);
  border-bottom-color: var(--link);
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
.page-content {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 2rem 4rem;
}

/* ── Typography ──────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  color: var(--text-header);
  line-height: 1.2;
  margin-top: 2rem;
  margin-bottom: 0.6rem;
}
h1 { font-size: 2.4rem; border-bottom: 2px solid var(--border); padding-bottom: 0.4rem; margin-top: 0; }
h2 { font-size: 1.7rem; border-bottom: 1px solid var(--border); padding-bottom: 0.25rem; }
h3 { font-size: 1.3rem; }
h4 { font-size: 1.1rem; }

p { margin-bottom: 1rem; }

a { color: var(--link); text-decoration: underline; }
a:hover { opacity: 0.8; }
a.wiki-link { color: var(--link); }
a[href^="#unresolved"] { color: var(--link-broken); text-decoration: underline dotted; }

strong { font-weight: 700; color: var(--text-primary); }
em { font-style: italic; }

ul, ol { padding-left: 1.5rem; margin-bottom: 1rem; }
li { margin-bottom: 0.25rem; }

blockquote {
  border-left: 4px solid var(--border);
  margin: 1.5rem 0;
  padding: 0.75rem 1.25rem;
  background: var(--bg-secondary);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
  font-style: italic;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
  opacity: 0.5;
}

/* ── Inline HTML from Chronicler ─────────────────────────────────────────── */
/* Let the raw HTML blocks render naturally — Chronicler's float layouts,
   infoboxes, and faction cards all pass through as-is. We just make sure
   floats are cleared and images are responsive. */
.content-article { overflow: hidden; } /* clears floats */
.content-article img { max-width: 100%; height: auto; }

/* ── Page tags ───────────────────────────────────────────────────────────── */
.page-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
}
.tag {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px 8px;
}

/* ── Index cards (used on section landing pages) ─────────────────────────── */
.index-page h1 { margin-bottom: 0.25rem; }
.index-subtitle { color: var(--text-secondary); margin-bottom: 2rem; font-size: 0.95rem; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 2.5rem;
}
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  text-decoration: none;
  color: var(--text-primary);
  display: block;
  transition: background 0.15s, border-color 0.15s;
}
.card:hover {
  background: var(--bg-tertiary);
  border-color: var(--link);
  color: var(--text-primary);
  text-decoration: none;
}
.card-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  color: var(--text-header);
  margin-bottom: 0.2rem;
}
.card-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ── Session list (linear, not grid) ────────────────────────────────────── */
.session-list { list-style: none; padding: 0; }
.session-list li {
  border-bottom: 1px solid var(--border);
  opacity: 0.85;
}
.session-list li:last-child { border-bottom: none; }
.session-list a {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.65rem 0.5rem;
  text-decoration: none;
  color: var(--text-primary);
  transition: background 0.12s;
  border-radius: var(--radius);
}
.session-list a:hover { background: var(--bg-secondary); color: var(--text-primary); }
.session-num {
  font-family: var(--font-heading);
  color: var(--text-header);
  min-width: 4ch;
  font-size: 1.05rem;
}
.session-summary {
  font-size: 0.88rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* ── Section group headers on index pages ────────────────────────────────── */
.group-heading {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  color: var(--text-header);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
  margin: 2rem 0 0.75rem;
}

/* ── Homepage hero ───────────────────────────────────────────────────────── */
.home-hero {
  text-align: center;
  padding: 3rem 1rem 2.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}
.home-hero h1 {
  border: none;
  font-size: 3rem;
  margin-bottom: 0.5rem;
}
.home-hero .tagline {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 1.05rem;
  margin-bottom: 2rem;
}
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.home-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-decoration: none;
  color: var(--text-header);
  font-family: var(--font-heading);
  font-size: 1.1rem;
  display: block;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
}
.home-card:hover {
  background: var(--bg-tertiary);
  border-color: var(--link);
  color: var(--link);
  text-decoration: none;
}
.home-card .card-count {
  display: block;
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.3rem;
  font-style: italic;
}

/* ── Syntax highlight (Chronicler HTML colors) ───────────────────────────── */
code, pre { font-family: 'Courier New', monospace; font-size: 0.88em; }
pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin-bottom: 1rem;
}
code { background: var(--bg-tertiary); padding: 1px 5px; border-radius: 2px; }
pre code { background: none; padding: 0; }

/* HTML tags */ .token.tag    { color: #b58900; }
/* attributes */ .token.attr-name { color: #268bd2; }
/* strings */ .token.string  { color: #2aa198; }

/* ── Infobox ─────────────────────────────────────────────────────────────── */
.infobox {
  float: right;
  clear: right;
  width: 260px;
  margin: 0 0 1.5rem 2rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.875rem;
}
.infobox-image {
  padding: 8px 8px 0;
}
.infobox-image img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius);
}
.infobox-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  color: var(--text-header);
  text-align: center;
  padding: 0.6rem 0.75rem 0.2rem;
}
.infobox-subtitle {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-style: italic;
  padding: 0 0.75rem 0.5rem;
}
.infobox-table {
  width: 100%;
  border-collapse: collapse;
  border-top: 1px solid var(--border);
}
.infobox-table tr + tr { border-top: 1px solid var(--border); }
.infobox-table th, .infobox-table td {
  padding: 4px 8px;
  text-align: left;
  vertical-align: top;
}
.infobox-table th {
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  width: 40%;
  background: var(--bg-tertiary);
}
.infobox-table td { color: var(--text-primary); }

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

/* ── Redactions ──────────────────────────────────────────────────────────── */
/* ||text|| is replaced at build time with x's — real content never in HTML  */
.redacted {
  display: inline;
  background: var(--text-primary);
  color: var(--text-primary);
  border-radius: 2px;
  padding: 0 2px;
  font-family: var(--font-body);
  letter-spacing: 0.01em;
  user-select: none;
  cursor: default;
}

/* ── Landing page ────────────────────────────────────────────────────────── */
.landing-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--nav-h) - 48px);
  padding: 2rem 1rem;
}
.landing-page h1 {
  border: none;
  font-size: 2.5rem;
  margin-bottom: 2.5rem;
}
.landing-grid {
  display: flex;
  gap: 2.5rem;
  align-items: flex-start;
  justify-content: center;
}
.landing-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  transition: transform 0.15s;
}
.landing-card:hover { transform: translateY(-3px); text-decoration: none; }
.landing-card-future { opacity: 0.5; }
.landing-card-img {
  width: 160px;
  height: 160px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-tertiary);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.landing-card:hover .landing-card-img {
  border-color: var(--link);
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}
.landing-card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.landing-card-img-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-size: 3.5rem;
  color: var(--border);
  width: 100%;
  height: 100%;
}
.landing-card-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  color: var(--text-header);
  text-align: center;
  max-width: 160px;
}

/* ── Nav back link ───────────────────────────────────────────────────────── */
.nav-back a {
  color: var(--text-secondary) !important;
  opacity: 0.7;
  font-size: 0.8rem !important;
}
.nav-back a:hover { opacity: 1; color: var(--link) !important; }

/* ── Submit button & modal ───────────────────────────────────────────────── */
.submit-btn {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: background 0.15s, border-color 0.15s;
  z-index: 200;
}
.submit-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--link);
  color: var(--link);
}
.submit-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.submit-modal[hidden] { display: none; }
.submit-dialog {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
.submit-dialog h3 {
  font-family: var(--font-heading);
  color: var(--text-header);
  margin: 0 0 0.25rem;
  font-size: 1.3rem;
}
.submit-page-ref {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}
.submit-dialog label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}
.submit-dialog input,
.submit-dialog textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.95rem;
  resize: vertical;
}
.submit-dialog input:focus,
.submit-dialog textarea:focus {
  outline: 2px solid var(--link);
  outline-offset: 1px;
}
.submit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.submit-actions button {
  padding: 0.45rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  cursor: pointer;
}
.submit-primary {
  background: var(--border) !important;
  color: var(--bg-primary) !important;
  font-weight: 600 !important;
}
.submit-actions button:hover { opacity: 0.85; }
.submit-status {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  min-height: 1.2em;
}

.district-grid-wrap {
  clear: both;
  margin-top: 1.5rem;
}

/* ── Infobox carousel ────────────────────────────────────────────────────── */
.carousel { position: relative; }
.carousel-slide { display: none; }
.carousel-slide.active { display: block; }
.carousel-slide img {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
}
.carousel-caption {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
  padding: 4px 8px;
  font-style: italic;
  margin: 0;
  border-top: 1px solid var(--border);
}
.carousel-btn {
  position: absolute;
  bottom: 28px; /* above caption */
  right: 6px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 1rem;
  line-height: 22px;
  text-align: center;
  cursor: pointer;
  color: var(--text-secondary);
  opacity: 0.8;
  padding: 0;
}
.carousel-btn:hover { opacity: 1; color: var(--link); }

/* ── Lock icon (CSS mask so it inherits color) ──────────────────────────── */
.lock-icon {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  background-color: currentColor;
  -webkit-mask-image: url('/assets/lock-icon.svg');
  mask-image: url('/assets/lock-icon.svg');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  vertical-align: -0.1em;
  margin-right: 0.3em;
}
.lock-icon-large {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
}

/* ── Sealed backlinks ────────────────────────────────────────────────────── */
.sealed-link {
  display: inline-flex;
  align-items: center;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border-radius: 2px;
  padding: 0 4px;
  cursor: default;
  user-select: none;
  opacity: 0.85;
}
.sealed-link .lock-icon { color: var(--border); margin-right: 0.25em; }

/* ── Sealed page itself ──────────────────────────────────────────────────── */
.sealed-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
}
.sealed-placeholder {
  text-align: center;
  color: var(--text-secondary);
}
.sealed-placeholder .lock-icon-large { color: var(--border); }
.sealed-message {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--text-header);
}

/* ── Sealed cards on index pages ─────────────────────────────────────────── */
.card.card-sealed {
  cursor: default;
  pointer-events: none;
  background: var(--bg-tertiary);
  opacity: 0.7;
}
.card.card-sealed .card-title {
  display: flex;
  align-items: center;
  gap: 0.4em;
  color: var(--text-secondary);
}
.card.card-sealed .lock-icon { color: var(--border); }

/* ── Admin lock button ───────────────────────────────────────────────────── */
.admin-lock-btn {
  position: fixed;
  bottom: 4.5rem;
  right: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
/* Use an inline SVG lock icon via content so no mask conflicts */
.admin-lock-btn::before {
  content: '';
  display: block;
  width: 20px;
  height: 20px;
  background-color: var(--text-secondary);
  -webkit-mask-image: url('/assets/lock-icon.svg');
  mask-image: url('/assets/lock-icon.svg');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  transition: background-color 0.15s;
}
.admin-lock-btn:hover { background: var(--bg-tertiary); border-color: var(--link); }
.admin-lock-btn:hover::before { background-color: var(--link); }
.admin-lock-btn.admin-lock-btn-unlocked { border-color: var(--link); background: var(--bg-secondary); }
.admin-lock-btn.admin-lock-btn-unlocked::before { background-color: var(--link); }

/* ── Revealed redaction ──────────────────────────────────────────────────── */
.revealed-redaction {
  background: var(--bg-secondary);
  border-radius: 2px;
  padding: 0 2px;
  color: var(--text-primary);
  font-style: italic;
}

/* ── Chronicler location / infobox box overrides ────────────────────────── */
/* Minimal intervention: let the Chronicler HTML use its natural sizing.
   Only prevent actual viewport overflow and re-theme colors.
   Do NOT constrain internal grid/flex — that causes cell wrapping. */

.content-article [style*="float: right"],
.content-article [style*="float:right"] {
  /* Prevent overflow but don't impose a smaller max-width than the source */
  max-width: 100% !important;
  box-sizing: border-box !important;
}
/* Prevent the inner 650px/800px divs from exceeding the page */
.content-article [style*="float: right"] > div,
.content-article [style*="float:right"] > div {
  max-width: 100% !important;
  box-sizing: border-box !important;
}
/* Prevent grid children from overflowing their cells */
.content-article [style*="float: right"] [style*="display: grid"] > *,
.content-article [style*="float:right"] [style*="display: grid"] > * {
  min-width: 0;
}

/* ── Color re-theming — site palette instead of Chronicler dark green ── */
.content-article [style*="color: #1b3022"] { color: var(--text-primary) !important; }
.content-article [style*="color: #8c7b50"] { color: var(--text-secondary) !important; }
.content-article [style*="background: #f4eee1"],
.content-article [style*="background:#f4eee1"],
.content-article [style*="background-color: #f4eee1"] {
  background: var(--bg-secondary) !important;
  border-color: var(--border) !important;
}
.content-article [style*="background: rgba(45, 74, 62"],
.content-article [style*="background:rgba(45, 74, 62"] {
  background: var(--bg-tertiary) !important;
  border-color: var(--border) !important;
}
.content-article [style*="border: 1px solid #2C1A14"] {
  border-color: var(--border) !important;
}

/* ── Mobile: remove float so box doesn't squeeze body text on narrow screens ── */
@media (max-width: 800px) {
  .content-article [style*="float: right"],
  .content-article [style*="float:right"] {
    float: none !important;
    margin: 0 0 1.5rem 0 !important;
  }
}

/* Give Chronicler table cells breathing room */
.content-article table td,
.content-article table th {
  padding: 4px 10px;
  vertical-align: top;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  background: var(--bg-tertiary);
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .site-nav { padding: 0 1rem; }
  .site-title { font-size: 1.15rem; }
  .nav-links { gap: 0.15rem 0.75rem; }
  .nav-links a { font-size: 0.78rem; }
  .page-content { padding: 1.5rem 1rem 3rem; }
  h1 { font-size: 1.8rem; }
  .home-hero h1 { font-size: 2rem; }
}
