/* ── Design tokens ─────────────────────────────────────────────── */
:root {
  --bg:           #f0e8d4;
  --bg2:          #e4d8be;
  --card:         rgba(255, 252, 242, 0.92);
  --line:         #c0a870;
  --text:         #2a1f0e;
  --muted:        #6b5535;
  --link:         #8b4513;
  --link-hover:   #5a2d0c;
  --gold:         #c9a227;
  --gold-dark:    #9a7a10;
  --header-bg:    #1a120a;
  --header-text:  #e8d8b0;
  --shadow:       0 4px 24px rgba(60, 40, 10, 0.18);
  --shadow-lg:    0 8px 40px rgba(60, 40, 10, 0.24);
  --radius:       8px;
  --radius-lg:    14px;

  /* Effect colours (MediaWiki) */
  --green:        #1a6e1a;
  --green-bg:     #d4edda;
  --red:          #9e0000;
  --red-bg:       #fde8e8;
}

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

/* ── Base ───────────────────────────────────────────────────────── */
html { font-size: 16px; scroll-behavior: smooth; }

body {
  color: var(--text);
  font-family: "Georgia", "Noto Serif SC", "Source Han Serif SC", serif;
  line-height: 1.7;
  background-color: var(--bg);
  background-image:
    url("data:image/svg+xml,%3Csvg width='200' height='200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at top, #f7eedb 0%, var(--bg) 60%);
}

a { color: var(--link); }
a:hover { color: var(--link-hover); }

/* ── Header / nav ───────────────────────────────────────────────── */
.site-header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
  border-bottom: 1px solid var(--gold-dark);
}

.site-header::before {
  content: "⚜";
  color: var(--gold);
  font-size: 22px;
  flex-shrink: 0;
}

.home-link {
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--gold);
  font-family: "Georgia", serif;
  font-weight: bold;
  white-space: nowrap;
}
.home-link:hover { color: #e8c85a; }

.header-title {
  flex: 1;
  font-size: 15px;
  color: rgba(232, 216, 176, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Header search */
.header-search-wrap {
  position: relative;
  flex: 1;
  max-width: 320px;
  margin: 0 12px;
}
.header-search {
  display: flex;
}
.header-search-input {
  flex: 1;
  padding: 4px 10px;
  font-size: 13px;
  font-family: inherit;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(201,162,39,0.3);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  color: var(--header-text);
  outline: none;
}
.header-search-input::placeholder { color: rgba(232,216,176,0.4); }
.header-search-input:focus { border-color: var(--gold); background: rgba(255,255,255,0.12); }
.header-search button {
  padding: 4px 10px;
  background: rgba(255,255,255,0.06);
  color: var(--gold);
  border: 1px solid rgba(201,162,39,0.3);
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
  font-size: 13px;
}
.header-search button:hover { background: rgba(201,162,39,0.15); }

/* ── Autocomplete dropdown ───────────────────────────────────────── */
.search-wrap {
  position: relative;
  max-width: 600px;
  margin: 0 auto 20px;
}

.suggest-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
  margin: 0;
  padding: 4px 0;
}
.suggest-list--header {
  top: calc(100% + 2px);
  min-width: 320px;
}

.suggest-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.1s;
}
.suggest-list li:hover,
.suggest-list li.active {
  background: rgba(192, 168, 112, 0.2);
}
.sug-title {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}
.sug-en {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.suggest-list mark {
  background: rgba(201, 162, 39, 0.3);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Search result list with snippets ────────────────────────────── */
.result-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-item a {
  display: block;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  background: var(--card);
  border: 1px solid rgba(192, 168, 112, 0.28);
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.result-item a:hover {
  border-color: var(--gold);
  box-shadow: var(--shadow-lg);
}
.result-title {
  font-size: 16px;
  font-weight: bold;
  color: var(--text);
  margin-bottom: 2px;
}
.result-en {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.result-snippet {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  border-top: 1px solid rgba(192,168,112,0.2);
  padding-top: 6px;
  margin-top: 4px;
}
.result-snippet mark {
  background: rgba(201, 162, 39, 0.25);
  color: var(--text);
  border-radius: 2px;
  padding: 0 2px;
}

.header-source-links {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.header-source-links a {
  font-size: 12px;
  color: rgba(232, 216, 176, 0.65);
  text-decoration: none;
  padding: 2px 8px;
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 999px;
  transition: color 0.15s, border-color 0.15s;
}
.header-source-links a:hover {
  color: var(--gold);
  border-color: var(--gold);
}

/* ── Hero (index page) ──────────────────────────────────────────── */
.hero {
  padding: 48px 28px 36px;
  text-align: center;
  background: linear-gradient(180deg, rgba(26,18,10,0.06) 0%, transparent 100%);
  border-bottom: 1px solid rgba(192, 168, 112, 0.3);
}

.hero h1 {
  font-size: clamp(28px, 5vw, 48px);
  color: var(--text);
  margin-bottom: 10px;
  text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}

.hero .tagline {
  color: var(--muted);
  font-size: 15px;
  max-width: 560px;
  margin: 0 auto;
}

/* ── Page layout (article) ──────────────────────────────────────── */
.page-layout {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px;
}

.page-title-bar {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--gold);
}
.page-title-bar h1 {
  font-size: clamp(22px, 4vw, 36px);
  color: var(--text);
}

/* Single-pane full-width */
.pane-single {
  max-width: 960px;
}

/* ── Pane card ──────────────────────────────────────────────────── */
.pane {
  background: var(--card);
  border: 1px solid rgba(192, 168, 112, 0.35);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.pane-head {
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(192, 168, 112, 0.3);
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.pane-head h2 {
  font-size: 16px;
  font-variant: small-caps;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.pane-head p {
  font-size: 13px;
  color: var(--muted);
}

/* ── Wiki body content ──────────────────────────────────────────── */
.wiki-body {
  overflow-wrap: anywhere;
  font-size: 14.5px;
  line-height: 1.75;
}

.wiki-body h2 {
  font-size: 1.3em;
  margin: 1.4em 0 0.5em;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}
.wiki-body h3 {
  font-size: 1.1em;
  margin: 1.2em 0 0.4em;
  color: var(--text);
}
.wiki-body h4 {
  font-size: 1em;
  margin: 1em 0 0.3em;
  color: var(--muted);
}

.wiki-body p { margin-bottom: 0.8em; }
.wiki-body ul, .wiki-body ol {
  margin: 0.4em 0 0.8em 1.6em;
}
.wiki-body li { margin-bottom: 0.25em; }
.wiki-body dl { margin: 0.5em 0 0.8em 1em; }
.wiki-body dt { font-weight: bold; }
.wiki-body dd { margin-left: 1.4em; }
.wiki-body hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1em 0;
}

/* Images */
.wiki-body img { height: auto; max-width: 100%; vertical-align: middle; }

/* ── Tables ─────────────────────────────────────────────────────── */
.wiki-body table {
  border-collapse: collapse;
  max-width: 100%;
  margin: 0.8em 0;
  font-size: 13.5px;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.wiki-body table th {
  background: rgba(26, 18, 10, 0.78);
  color: var(--gold);
  padding: 7px 11px;
  text-align: left;
  font-size: 12.5px;
  letter-spacing: 0.04em;
}
.wiki-body table td {
  padding: 6px 11px;
  border-top: 1px solid rgba(192, 168, 112, 0.2);
  vertical-align: middle;
}
.wiki-body table tr:nth-child(even) td {
  background: rgba(192, 168, 112, 0.07);
}

/* ── Infobox / country box ──────────────────────────────────────── */
.wiki-body .countryboxfix,
.wiki-body table[style*="float:right"],
.wiki-body table[style*="float: right"] {
  float: right;
  margin: 0 0 16px 20px;
  clear: right;
  font-size: 13px !important;
  width: min(320px, 100%) !important;
  border: 1px solid rgba(192, 168, 112, 0.4) !important;
  border-radius: var(--radius) !important;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: rgba(255, 252, 242, 0.97) !important;
}
.wiki-body .countryboxfix th[colspan],
.wiki-body table[style*="float:right"] th[colspan],
.wiki-body table[style*="float: right"] th[colspan] {
  background: var(--header-bg) !important;
  color: var(--gold) !important;
  padding: 8px 12px !important;
}

/* Idea/bonus boxes */
.wiki-body table.a-r td, .wiki-body table.at-c td {
  text-align: center;
}

/* ── Navboxes ───────────────────────────────────────────────────── */
.wiki-body .navbox,
.wiki-body .navbox-inner,
.wiki-body table[class*="navbox"] {
  background: rgba(240, 232, 212, 0.6) !important;
  border: 1px solid var(--line) !important;
  font-size: 13px;
}

/* ── EU4 coloured bg helpers ────────────────────────────────────── */
.wiki-body .bg-黑, [class^="bg-"] { background: #3a3028 !important; color: #f0e8d4 !important; }
.wiki-body .bg-水 { background: #c5dde8 !important; color: var(--text) !important; }
.wiki-body .bg-绿 { background: #c5e8c5 !important; color: var(--text) !important; }
.wiki-body .bg-红 { background: #e8c5c5 !important; color: var(--text) !important; }

/* ── roundy helpers ─────────────────────────────────────────────── */
.wiki-body .roundy-6, .wiki-body .roundy { border-radius: var(--radius) !important; }
.wiki-body .roundytop-6 { border-radius: var(--radius) var(--radius) 0 0 !important; }
.wiki-body .roundybottom-6 { border-radius: 0 0 var(--radius) var(--radius) !important; }

/* ── Effect colours ─────────────────────────────────────────────── */
.wiki-body .effect-green  { color: var(--green) !important; font-weight: bold; }
.wiki-body .effect-red    { color: var(--red)   !important; font-weight: bold; }
.wiki-body .effect-background-green {
  background: var(--green-bg) !important;
  border-radius: 3px;
  padding: 1px 4px;
}
.wiki-body .effect-background-red {
  background: var(--red-bg) !important;
  border-radius: 3px;
  padding: 1px 4px;
}

/* ── Alert / ambox ──────────────────────────────────────────────── */
.wiki-body .ambox2020,
.wiki-body .alert-warning {
  border-left: 4px solid var(--gold) !important;
  background: rgba(201, 162, 39, 0.1) !important;
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 10px 14px !important;
  font-size: 13px;
  color: var(--muted);
  margin: 0.6em 0;
}

/* ── Hidden MW cruft ─────────────────────────────────────────────── */
.wiki-body .mw-editsection,
.wiki-body .reference,
.wiki-body .error,
.wiki-body .mw-empty-elt { display: none !important; }

/* ── ruby text (pronunciation) ───────────────────────────────────── */
.wiki-body ruby rt { font-size: 70%; color: var(--muted); }

/* ── Achievements table ──────────────────────────────────────────── */

/* Let the pane expand to full page width when it contains the achievements table */
.pane-single:has(table.mildtable) {
  max-width: none;
}

.wiki-body table.mildtable {
  table-layout: fixed !important;
  width: 100% !important;
  font-size: 13px;
}

.wiki-body table.mildtable th,
.wiki-body table.mildtable td {
  width: auto !important;
  padding: 8px 10px;
  vertical-align: top;
  overflow: hidden;
}

/* Achievement name col: fixed width so icon never squishes */
.wiki-body table.mildtable td:nth-child(1),
.wiki-body table.mildtable th:nth-child(1) {
  width: 190px !important;
}

/* The flex wrapper inside the name cell */
.wiki-body table.mildtable td:nth-child(1) > div {
  display: flex !important;
  align-items: flex-start !important;
  gap: 8px;
  flex-wrap: nowrap;
}

/* Achievement icon — always 64×64, never shrink */
.wiki-body table.mildtable td:nth-child(1) > div > a {
  flex: 0 0 64px;
  display: block;
}
.wiki-body table.mildtable td:nth-child(1) > div > a img {
  width: 64px !important;
  height: 64px !important;
  display: block;
  border-radius: 4px;
}

/* Text block next to icon */
.wiki-body table.mildtable td:nth-child(1) > div > div {
  flex: 1 1 0;
  min-width: 0;
  overflow-wrap: break-word;
}

/* Start conditions col */
.wiki-body table.mildtable td:nth-child(2),
.wiki-body table.mildtable th:nth-child(2) {
  width: 150px !important;
}

/* Requirements col */
.wiki-body table.mildtable td:nth-child(3),
.wiki-body table.mildtable th:nth-child(3) {
  width: 190px !important;
}

/* Notes col: takes all remaining space */
.wiki-body table.mildtable td:nth-child(4),
.wiki-body table.mildtable th:nth-child(4) {
  width: auto !important;
  min-width: 260px;
}

/* DLC / version / difficulty cols */
.wiki-body table.mildtable td:nth-child(n+5),
.wiki-body table.mildtable th:nth-child(n+5) {
  width: 52px !important;
  text-align: center;
  white-space: nowrap;
}

/* ── Sortable table headers ───────────────────────────────────────── */
.wiki-body table.sortable th:not(.unsortable) {
  cursor: pointer;
  user-select: none;
}
.wiki-body table.sortable th:not(.unsortable):hover {
  background: rgba(201, 162, 39, 0.22) !important;
}
.wiki-body table.sortable th:not(.unsortable)::after {
  content: " ⇅";
  opacity: 0.35;
  font-size: 10px;
}
.wiki-body table.sortable th[data-sort-dir="asc"]::after {
  content: " ↑";
  opacity: 0.9;
}
.wiki-body table.sortable th[data-sort-dir="desc"]::after {
  content: " ↓";
  opacity: 0.9;
}

/* ── Homepage nav ────────────────────────────────────────────────── */
.homepage-nav {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin: 16px 0;
}

.nav-section {
  border: 1px solid rgba(192, 168, 112, 0.35);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--card);
}

.nav-section-title {
  background: #103D8F;
  color: #fff;
  font-size: 15px;
  font-weight: bold;
  font-variant: small-caps;
  padding: 8px 12px;
}

.nav-section-links {
  list-style: none;
  padding: 10px 12px;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.nav-section-links li a {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  font-size: 13.5px;
  color: var(--link);
  padding: 3px 0;
  white-space: nowrap;
}
.nav-section-links li a:hover { color: var(--link-hover); }
.nav-section-links li a img {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

/* ── Empty state ─────────────────────────────────────────────────── */
.empty-state {
  padding: 20px;
  border-radius: var(--radius-lg);
  background: rgba(192, 168, 112, 0.15);
  border: 1px dashed var(--line);
  color: var(--muted);
  font-style: italic;
  text-align: center;
}

/* ── Index page ──────────────────────────────────────────────────── */
.index-wrap { padding: 28px 24px; max-width: 1400px; margin: 0 auto; }

.search-bar {
  display: flex;
}
.search-bar input {
  flex: 1;
  padding: 10px 16px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid var(--line);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  background: var(--card);
  color: var(--text);
  outline: none;
}
.search-bar input:focus { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(201,162,39,0.2); }
.search-bar button {
  padding: 10px 16px;
  background: var(--header-bg);
  color: var(--gold);
  border: 1px solid var(--line);
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
  font-size: 16px;
}

.page-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.page-list li { display: contents; }
.page-list li[hidden] { display: none; }

.page-list a {
  display: block;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--card);
  border: 1px solid rgba(192, 168, 112, 0.28);
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
}
.page-list a:hover {
  border-color: var(--gold);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.page-list strong {
  display: block;
  font-size: 14.5px;
  color: var(--text);
}
.page-list span {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.results-count {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .page-grid { grid-template-columns: 1fr; }
  .wiki-body .countryboxfix,
  .wiki-body table[style*="float:right"],
  .wiki-body table[style*="float: right"] {
    float: none;
    margin: 0 auto 16px;
    width: 100% !important;
  }
}

@media (max-width: 600px) {
  .site-header { height: 44px; padding: 0 14px; }
  .header-title { display: none; }
  .page-layout { padding: 16px; }
}
