:root {
  --page: #ffffff;
  --ink: #202122;
  --muted: #54595d;
  --subtle: #72777d;
  --blue: #36c;
  --blue-hover: #447ff5;
  --line: #a2a9b1;
  --line-soft: #eaecf0;
  --panel: #f8f9fa;
  --panel-2: #f2f2f2;
  --notice: #f8f9fa;
  --success: #14866d;
  --danger: #b32424;
  --warning: #fff8e5;
  --content-max: 1180px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page);
  font-size: 16px;
  line-height: 1.6;
}
body.text-small { font-size: 14px; }
body.text-large { font-size: 18px; }
body.theme-dark {
  --page: #101418;
  --ink: #eaecf0;
  --muted: #c8ccd1;
  --subtle: #a2a9b1;
  --blue: #8cb4ff;
  --blue-hover: #a8c7ff;
  --line: #54595d;
  --line-soft: #34383d;
  --panel: #171d22;
  --panel-2: #20272e;
  --notice: #171d22;
  --warning: #2d2510;
  color-scheme: dark;
}
body.width-wide { --content-max: 1420px; }

img { max-width: 100%; display: block; }
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-hover); text-decoration: underline; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

/* Top Wikipedia-like bar */
.wiki-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: minmax(230px, 320px) minmax(280px, 680px) auto;
  align-items: center;
  gap: 1rem;
  min-height: 58px;
  padding: 0.5rem max(1.4rem, calc((100vw - var(--content-max) - 470px) / 2));
  border-bottom: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--page) 94%, transparent);
  backdrop-filter: blur(10px);
}
.wiki-brand {
  display: flex;
  align-items: center;
  gap: 0.72rem;
  color: var(--ink);
  min-width: 0;
}
.wiki-brand:hover { text-decoration: none; color: var(--ink); }
.wiki-logo {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 1.5rem;
  background: var(--panel);
  color: var(--ink);
}
.wiki-brand strong {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.28rem;
  line-height: 1;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.wiki-brand small {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 0.1rem;
}
.wiki-search {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
  min-width: 0;
}
.wiki-search input,
.wiki-search button {
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--page);
  color: var(--ink);
  padding: 0.35rem 0.65rem;
  border-radius: 0;
}
.wiki-search input { border-right: 0; }
.wiki-search button { background: var(--panel); font-weight: 600; }
.wiki-search button:hover { background: var(--panel-2); }
.wiki-usernav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.8rem;
  white-space: nowrap;
  font-size: 0.92rem;
}
.wiki-usernav a.active { color: var(--ink); font-weight: 700; }
.icon-button, .nav-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  min-width: 32px;
  min-height: 32px;
  border-radius: 2px;
  padding: 0 0.45rem;
}
.icon-button:hover, .nav-button:hover { background: var(--panel); }

/* Shell */
.wiki-layout {
  width: min(calc(100% - 2.2rem), calc(var(--content-max) + 470px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 205px minmax(0, var(--content-max)) 210px;
  gap: 1.65rem;
  align-items: start;
}
.wiki-sidebar,
.appearance-panel {
  position: sticky;
  top: 74px;
  max-height: calc(100vh - 88px);
  overflow: auto;
  padding-top: 1rem;
  font-size: 0.9rem;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border-bottom: 1px solid var(--line-soft);
  padding: 0 0 0.55rem;
  margin-bottom: 0.55rem;
  color: var(--ink);
}
.sidebar-head button {
  border: 0;
  border-radius: 2px;
  background: var(--panel);
  color: var(--ink);
  padding: 0.18rem 0.45rem;
  font-size: 0.78rem;
}
.sidebar-nav,
.toc-list {
  display: grid;
  gap: 0.08rem;
}
.sidebar-nav a,
.toc-list a {
  display: block;
  padding: 0.24rem 0 0.24rem 0.25rem;
  border-left: 2px solid transparent;
  color: var(--blue);
  line-height: 1.35;
}
.sidebar-nav a.active,
.toc-list a:hover {
  border-left-color: var(--ink);
  color: var(--ink);
  text-decoration: none;
}
.appearance-group {
  border-bottom: 1px solid var(--line-soft);
  padding: 0.3rem 0 0.9rem;
  margin-bottom: 0.75rem;
}
.appearance-group p {
  margin: 0 0 0.42rem;
  color: var(--muted);
}
.appearance-group label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.25rem 0;
  color: var(--ink);
  font-weight: 400;
}
.appearance-group input { width: auto; }

.wiki-main {
  min-width: 0;
  padding: 1.35rem 0 2.5rem;
}
.wiki-page-header {
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.8rem;
}
.title-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}
h1, h2, h3 {
  margin: 0;
  line-height: 1.25;
  font-weight: 500;
  color: var(--ink);
}
h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 3.3vw, 2.75rem);
  letter-spacing: -0.02em;
}
h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.38rem, 2.2vw, 1.85rem);
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.1rem;
  margin-bottom: 0.55rem;
}
h3 { font-size: 1.1rem; font-weight: 700; }
.language-pill {
  color: var(--blue);
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
  margin-bottom: 0.35rem;
}
.page-tabs {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-top: 0.45rem;
}
.tabs-left,
.tabs-right {
  display: flex;
  align-items: center;
  gap: 0.05rem;
  min-width: 0;
}
.page-tabs a,
.page-tabs button {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0.35rem 0.55rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--blue);
  font-size: 0.92rem;
}
.page-tabs a.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
  text-decoration: none;
}

/* Article */
.wiki-article {
  position: relative;
  color: var(--ink);
  font-size: 1rem;
}
.wiki-source-line {
  margin: 0.35rem 0 0.8rem;
  font-size: 0.93rem;
  color: var(--ink);
}
.protected-note {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  width: min(760px, 100%);
  margin: 1rem auto 0.65rem;
  border: 1px solid var(--line);
  background: var(--notice);
  color: var(--ink);
  padding: 0.55rem 1rem;
  line-height: 1.45;
}
.protected-note p { margin: 0; }
.lock-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: var(--subtle);
  font-size: 1.65rem;
}
.official-name {
  margin: 1rem 0 0.35rem;
  color: var(--muted);
  font-size: 0.98rem;
}
.lead,
.wiki-lead {
  margin: 0.35rem 0 1rem;
  font-size: 1.02rem;
  line-height: 1.75;
  color: var(--ink);
}
.wiki-article p { margin-top: 0; }
.article-content { display: block; }
.article-section {
  scroll-margin-top: 78px;
  clear: none;
  margin-top: 1.35rem;
}
.article-section h2 { margin-top: 1.25rem; }
.article-section h3 {
  font-family: sans-serif;
  font-size: 1.02rem;
  font-weight: 800;
  margin: 1.1rem 0 0.35rem;
  padding-top: 0.15rem;
  border-bottom: 1px solid var(--line-soft);
}
.article-section .period {
  margin: 0.35rem 0 0.65rem;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.92rem;
}
.article-section p {
  margin: 0 0 1rem;
  line-height: 1.75;
  text-align: left;
}

/* Infobox Wikipedia-like */
.wiki-infobox {
  float: right;
  clear: right;
  width: min(520px, 54vw);
  margin: 0.4rem 0 1rem 1.45rem;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--ink);
}
.wiki-infobox h2 {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  font-size: 1.34rem;
  font-weight: 800;
  text-align: center;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  padding: 0.45rem 0.6rem;
  margin: 0;
}
.flag-coa-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.72rem;
  padding: 0.78rem;
  border-bottom: 1px solid var(--line-soft);
  align-items: stretch;
}
.flag-coa-grid figure,
.media-item {
  margin: 0;
}
.flag-coa-grid figure {
  display: grid;
  grid-template-rows: 230px auto;
  min-width: 0;
}
.infobox-cover,
.mini-symbol,
.infobox-map,
.leader-card {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  background: #fff;
  color: var(--muted);
  text-align: center;
  padding: 0.45rem;
}
.infobox-cover,
.mini-symbol {
  width: 100%;
  min-height: 230px;
  height: 230px;
}
body.theme-dark .infobox-cover,
body.theme-dark .mini-symbol,
body.theme-dark .infobox-map,
body.theme-dark .leader-card { background: #111820; }
.infobox-cover img,
.mini-symbol img,
.infobox-map img,
.leader-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.flag-coa-grid figcaption {
  text-align: center;
  color: var(--blue);
  margin-top: 0.42rem;
  font-size: 0.9rem;
}
.infobox-map {
  min-height: 230px;
  margin: 0.78rem;
}
.leader-card {
  min-height: 205px;
  margin: 0.78rem;
  font-weight: 700;
}
.wiki-infobox dl {
  display: grid;
  grid-template-columns: 38% 62%;
  margin: 0;
  border-top: 1px solid var(--line);
}
.wiki-infobox dt,
.wiki-infobox dd {
  margin: 0;
  padding: 0.42rem 0.5rem;
  border-bottom: 1px solid var(--line-soft);
}
.wiki-infobox dt {
  font-weight: 800;
  background: var(--panel-2);
}
.wiki-infobox dd { overflow-wrap: anywhere; }

/* Home */
.home-article {
  min-height: 70vh;
}
.welcome-box {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel) 0%, var(--page) 100%);
  padding: 1rem 1.1rem;
  margin: 1rem 0;
}
.welcome-box h2 {
  border: 0;
  padding: 0;
  margin: 0 0 0.4rem;
}
.welcome-box p { margin: 0; color: var(--ink); }
.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin: 1rem 0 1.35rem;
}
.stat-card.compact {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0.85rem 1rem;
}
.stat-card.compact span {
  display: block;
  font-size: 1.65rem;
  font-weight: 800;
  line-height: 1;
}
.stat-card.compact small { color: var(--muted); font-weight: 700; }
.wiki-toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.8rem;
  border-top: 1px solid var(--line-soft);
  padding-top: 1rem;
}
.wiki-toolbar h2 { margin-bottom: 0.1rem; }
.filters {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 240px) minmax(180px, 270px);
  gap: 0.5rem;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--page);
  color: var(--ink);
  padding: 0.44rem 0.55rem;
  border-radius: 2px;
  outline: none;
}
textarea { min-height: 6rem; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}
.wiki-country-list {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
  margin-top: 0.6rem;
}
.country-card {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 0.9rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink);
}
.country-card:hover { text-decoration: none; background: color-mix(in srgb, var(--panel) 65%, transparent); }
.card-image {
  display: grid;
  place-items: center;
  width: 128px;
  height: 82px;
  border: 1px solid var(--line-soft);
  background: var(--panel);
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 1.45rem;
}
.card-image img { width: 100%; height: 100%; object-fit: contain; }
.card-body { min-width: 0; }
.card-body h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}
.card-body p { margin: 0.25rem 0; color: var(--ink); line-height: 1.55; }
.card-meta { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-bottom: 0.15rem; }
.pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-soft);
  background: var(--panel);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1;
  padding: 0.25rem 0.45rem;
  border-radius: 999px;
}
.empty-state { padding: 2rem 0; color: var(--muted); }
.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.76rem;
}

/* Gallery */
.gallery-section { clear: both; margin-top: 2rem; }
.media-gallery {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.media-item {
  border: 1px solid var(--line);
  background: var(--panel);
}
.media-item img { width: 100%; height: 165px; object-fit: cover; }
.media-item figcaption { padding: 0.55rem; color: var(--muted); font-size: 0.88rem; }

/* Buttons and admin */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0.4rem 0.8rem;
  font-weight: 700;
  border-radius: 2px;
}
.button:hover { background: var(--panel-2); text-decoration: none; }
.button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.button.ghost { background: var(--page); }
.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button.small { min-height: 31px; padding: 0.25rem 0.58rem; font-size: 0.9rem; }
.notice {
  border: 1px solid var(--line);
  background: var(--notice);
  padding: 0.8rem;
  margin: 1rem 0;
}
.notice.warning { background: var(--warning); }
.auth-card,
.editor-card,
.admin-list-card {
  border: 1px solid var(--line);
  background: var(--page);
  padding: 1rem;
}
.auth-card { max-width: 560px; margin: 1rem 0; }
.stack-form,
.editor-form,
.section-list,
.section-row { display: grid; gap: 0.75rem; }
label {
  display: grid;
  gap: 0.25rem;
  color: var(--ink);
  font-weight: 700;
  font-size: 0.9rem;
}
.form-message { min-height: 1.3rem; color: var(--muted); font-weight: 700; }
.admin-header,
.editor-topline,
.editor-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}
.admin-grid {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 1rem;
}
.admin-country-list {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.6rem;
  max-height: 70vh;
  overflow: auto;
}
.country-list-item {
  border: 1px solid var(--line-soft);
  background: var(--panel);
  color: var(--ink);
  padding: 0.55rem;
  text-align: left;
}
.country-list-item strong { display: block; }
.country-list-item small { color: var(--muted); }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.bulk-editor-card {
  border-left: 4px solid var(--blue);
}
.bulk-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 0.75rem;
}
.bulk-head h3 { margin-top: 0.15rem; }
.inline-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  font-weight: 700;
}
.inline-check input { width: auto; }
.bulk-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin-top: 0.7rem;
}
.bulk-preview {
  margin-top: 0.75rem;
  border: 1px solid var(--line-soft);
  background: var(--page);
  padding: 0.75rem;
}
.bulk-preview dl {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 0.35rem 0.75rem;
  margin: 0.55rem 0 0;
}
.bulk-preview dt { color: var(--muted); font-weight: 800; }
.bulk-preview dd { margin: 0; }
.bulk-editor-card,
.media-uploader,
.section-editor,
.section-row {
  border: 1px solid var(--line-soft);
  background: var(--panel);
  padding: 0.8rem;
  margin-top: 0.75rem;
}

.media-help {
  color: var(--muted);
  margin: -0.25rem 0 0.75rem;
}
.media-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}
.media-field {
  border: 1px solid var(--line-soft);
  background: var(--page);
  padding: 0.75rem;
  display: grid;
  gap: 0.65rem;
}
.clipboard-zone {
  border: 1px dashed var(--line);
  background: var(--panel-2);
  min-height: 150px;
  padding: 0.75rem;
  display: grid;
  gap: 0.4rem;
  place-items: center;
  text-align: center;
  outline: none;
}
.clipboard-zone:focus,
.clipboard-zone:hover {
  border-color: var(--blue);
  background: color-mix(in srgb, var(--blue) 7%, var(--page));
}
.clipboard-zone span,
.clipboard-zone small {
  color: var(--muted);
}
.media-preview {
  width: 100%;
  max-height: 130px;
  object-fit: contain;
  border: 1px solid var(--line-soft);
  background: var(--page);
}
.paste-image-btn {
  width: fit-content;
}
.section-row-top {
  display: grid;
  grid-template-columns: 80px 1fr 150px auto;
  gap: 0.55rem;
  align-items: end;
}
.section-row textarea { min-height: 150px; }
.remove-section {
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line));
  background: color-mix(in srgb, var(--danger) 10%, var(--page));
  color: var(--danger);
  padding: 0.48rem 0.65rem;
  font-weight: 900;
}

.wiki-footer {
  width: min(calc(100% - 2.2rem), calc(var(--content-max) + 470px));
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  padding: 1.2rem 0 2rem;
  font-size: 0.88rem;
}

@media (max-width: 1180px) {
  .wiki-topbar { grid-template-columns: 240px minmax(0, 1fr) auto; padding-inline: 1rem; }
  .wiki-layout { grid-template-columns: 180px minmax(0, 1fr); }
  .appearance-panel { display: none; }
  .form-grid.four, .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 880px) {
  .wiki-topbar {
    position: static;
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }
  .wiki-usernav { justify-content: flex-start; flex-wrap: wrap; }
  .wiki-layout { width: min(100% - 1rem, 760px); grid-template-columns: 1fr; gap: 0; }
  .wiki-sidebar { display: none; }
  .wiki-main { padding-top: 0.8rem; }
  .title-row, .page-tabs, .tabs-right { align-items: flex-start; flex-direction: column; }
  .page-tabs { gap: 0.35rem; }
  .tabs-left, .tabs-right { flex-wrap: wrap; flex-direction: row; }
  .wiki-infobox { float: none; width: 100%; margin: 1rem 0; }
  .filters { grid-template-columns: 1fr; }
  .stat-strip { grid-template-columns: 1fr; }
  .country-card { grid-template-columns: 88px 1fr; }
  .card-image { width: 88px; height: 62px; }
  .protected-note { grid-template-columns: 1fr; }
  .lock-icon { display: none; }
  .media-gallery { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
  .form-grid, .form-grid.four, .media-grid, .section-row-top, .bulk-preview dl { grid-template-columns: 1fr; }
  .bulk-head { flex-direction: column; }
  .wiki-footer { width: min(100% - 1rem, 760px); flex-direction: column; }
}
.bulk-editor-card { border-left: 4px solid var(--blue); }

@media (max-width: 560px) {
  .flag-coa-grid {
    grid-template-columns: 1fr;
  }
  .flag-coa-grid figure {
    grid-template-rows: 210px auto;
  }
  .infobox-cover,
  .mini-symbol {
    min-height: 210px;
    height: 210px;
  }
}
