:root {
  --link: #0645ad;
  --visited: #0b0080;
  --redlink: #ba0000;
  --text: #202122;
  --muted: #54595d;
  --border: #a2a9b1;
  --soft-border: #c8ccd1;
  --bg: #ffffff;
  --sidebar-bg: #f8f9fa;
  --header-bg: #ffffff;
  --tab-bg: #eaecf0;
  --highlight: #eaf3ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: sans-serif;
  font-size: 14px;
  color: var(--text);
  background: #f6f6f6;
  line-height: 1.65;
  transition: background-color 1.2s ease, color 1.2s ease;
}

a { color: var(--link); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
a:visited { color: var(--visited); }
a.redlink, a.redlink:visited { color: var(--redlink); }

/* HEADER */
#site-header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--soft-border);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.logo { display: flex; align-items: center; gap: 12px; color: var(--text); }
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 48px; height: 48px;
  background: #fff;
  border: 2px solid #5a4a3a;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Linux Libertine', Georgia, serif;
  font-size: 30px;
  color: #5a4a3a;
  font-weight: bold;
}
.logo-text { line-height: 1.1; }
.logo-title {
  font-family: 'Linux Libertine', Georgia, serif;
  font-size: 24px;
  letter-spacing: 0.5px;
  color: #2a2a2a;
}
.logo-subtitle {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  margin-top: 2px;
}

.search { margin-left: auto; position: relative; }
.search input {
  width: 280px;
  padding: 6px 10px;
  border: 1px solid var(--soft-border);
  font-size: 13px;
  background: #fff;
  outline: none;
}
.search input:focus { border-color: #36c; }
#search-results {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--soft-border);
  border-top: none;
  display: none;
  z-index: 10;
  max-height: 360px;
  overflow-y: auto;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
#search-results.visible { display: block; }
#search-results a {
  display: block;
  padding: 7px 10px;
  border-bottom: 1px solid #f0f0f0;
  color: var(--link);
}
#search-results a:hover { background: var(--highlight); text-decoration: none; }

/* TABS */
#page-tabs {
  background: var(--bg);
  border-bottom: 1px solid var(--soft-border);
}
.page-tabs-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
}
.tab {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--link);
  border-right: 1px solid var(--soft-border);
}
.tab:first-child { border-left: 1px solid var(--soft-border); }
.tab-right { margin-left: auto; border-left: 1px solid var(--soft-border); }
.tab-active {
  background: var(--highlight);
  color: var(--text);
  font-weight: bold;
  cursor: default;
}
.tab-active:hover { text-decoration: none; }

/* LAYOUT */
#layout {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 200px 1fr;
  background: var(--bg);
  min-height: 70vh;
}

#sidebar {
  background: var(--sidebar-bg);
  padding: 20px 12px;
  border-right: 1px solid var(--soft-border);
  font-size: 12px;
}
.sidebar-section { margin-bottom: 18px; }
.sidebar-title {
  font-weight: bold;
  border-bottom: 1px solid var(--soft-border);
  padding-bottom: 4px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}
.sidebar-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.sidebar-list li { padding: 2px 0; }
.lang-list { font-style: italic; }

/* CONTENT */
#content {
  padding: 18px 28px 60px;
  font-family: sans-serif;
  background: var(--bg);
  min-width: 0;
}
.article-title {
  font-family: 'Linux Libertine', Georgia, serif;
  font-size: 28px;
  font-weight: normal;
  border-bottom: 1px solid var(--soft-border);
  padding-bottom: 6px;
  margin: 0 0 6px;
  line-height: 1.3;
}
.featured-banner {
  background: #fef6e7;
  border: 1px solid #d4a017;
  border-left: 4px solid #d4a017;
  padding: 8px 12px;
  margin: 0 0 14px;
  font-size: 13px;
  color: #5a4a18;
}
.featured-banner strong { color: #3a2e0e; }
.article-subtitle {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 16px;
}
.article-body p { margin: 0 0 12px; }
.article-body h2 {
  font-family: 'Linux Libertine', Georgia, serif;
  font-size: 22px;
  font-weight: normal;
  border-bottom: 1px solid var(--soft-border);
  padding-bottom: 4px;
  margin: 22px 0 10px;
}
.article-body h3 {
  font-size: 16px;
  margin: 18px 0 8px;
  font-weight: bold;
}
.article-body ul, .article-body ol { margin: 0 0 12px 22px; }
.article-body li { margin-bottom: 4px; }

/* INFOBOX */
.infobox {
  float: right;
  width: 22em;
  margin: 0 0 18px 18px;
  border: 1px solid var(--soft-border);
  background: #f8f9fa;
  font-size: 12px;
  padding: 0;
}
.infobox-title {
  font-weight: bold;
  text-align: center;
  font-size: 14px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--soft-border);
  background: #eaecf0;
}
.infobox-row {
  display: flex;
  padding: 5px 8px;
  border-bottom: 1px solid #eaecf0;
  line-height: 1.4;
}
.infobox-row:last-child { border-bottom: none; }
.infobox-key {
  width: 45%;
  font-weight: bold;
  padding-right: 6px;
  color: var(--muted);
}
.infobox-val { width: 55%; }

.infobox-thumb {
  background: transparent;
  border-color: #c8ccd1;
}
.infobox-image {
  margin: 0;
  padding: 6px;
  text-align: center;
  background: #f4ecd8;
  border-bottom: 1px solid var(--soft-border);
  position: relative;
  overflow: hidden;
}
.infobox-thumb .infobox-image { border-bottom: none; }
.infobox-image img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  border: 1px solid #d4c8a8;
  background: #f4ecd8;
  transition: filter 1.2s ease, opacity 1.2s ease;
}
.infobox-image figcaption {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 6px 4px 2px;
  font-style: italic;
  line-height: 1.45;
}

/* CITATION/SCAR FLAGS */
.cite-needed {
  color: var(--redlink);
  font-size: 0.78em;
  font-style: italic;
  margin-left: 3px;
  text-decoration: none;
  vertical-align: super;
}

/* REFERENCES + CATEGORIES */
.references-section {
  font-size: 12px;
  margin-top: 24px;
}
.references-section h2 {
  font-family: 'Linux Libertine', Georgia, serif;
  font-size: 18px;
  font-weight: normal;
  border-bottom: 1px solid var(--soft-border);
  padding-bottom: 4px;
}
.references-section ol { padding-left: 20px; }
.references-section li { margin-bottom: 4px; }
.categories-section {
  margin-top: 28px;
  padding: 6px 0;
  border-top: 1px solid var(--soft-border);
  font-size: 12px;
}
.cat-label { color: var(--muted); }
.cat { margin-left: 6px; }
.cat::after { content: " |"; color: var(--muted); margin-left: 4px; }
.cat:last-child::after { content: ""; }

/* CHANGES TABLE */
.changes-table { border-collapse: collapse; width: 100%; font-size: 13px; margin-top: 8px; }
.changes-table th, .changes-table td { padding: 6px 10px; text-align: left; }
.changes-table th { border-bottom: 2px solid var(--soft-border); font-size: 12px; color: var(--muted); }
.changes-table tr { border-bottom: 1px solid #eee; }
.delta-pos { color: #006400; }
.delta-neg { color: var(--redlink); }
.delta-zero { color: var(--muted); }

/* FOOTER */
#site-footer {
  background: #f6f6f6;
  border-top: 1px solid var(--soft-border);
  padding: 16px 0;
  margin-top: 24px;
  font-size: 12px;
  color: var(--muted);
}
.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}
.footer-inner p { margin: 6px 0; }

/* ============== DECAY LAYERS ============== */

/* Level 1: subtle. Letter-spacing drift on a few paragraphs. */
body.decay-1 .article-body p:nth-of-type(3n+1) {
  letter-spacing: 0.012em;
}
body.decay-1 .infobox { filter: contrast(0.96); }

/* Level 2: yellowing background. Slight title drift. Subtle paragraph fade. */
body.decay-2 {
  background: linear-gradient(to bottom, #ffffff 0%, #fbf7ee 100%);
}
body.decay-2 #content { background: linear-gradient(to bottom, #ffffff 0%, #fbf7ee 100%); }
body.decay-2 .article-title { letter-spacing: 0.02em; }
body.decay-2 .article-body p:nth-of-type(2n) { opacity: 0.95; }
body.decay-2 .article-body p:nth-of-type(4n+1)::after {
  content: " [verification needed]";
  color: var(--redlink);
  font-style: italic;
  font-size: 0.82em;
}

/* Level 3: visible decay. Strikethroughs. Infobox tilt. Sepia tint. */
body.decay-3 { background: #f6efde; }
body.decay-3 #content { background: #fbf6e7; }
body.decay-3 .article-body p:nth-of-type(3n+1) {
  text-decoration: line-through;
  text-decoration-color: rgba(186, 0, 0, 0.4);
  text-decoration-thickness: 1px;
}
body.decay-3 .infobox { transform: rotate(-0.6deg); transition: transform 1.5s; }
body.decay-3 .article-body p:nth-of-type(5n)::after {
  content: " [paragraph corrupted]";
  color: var(--redlink);
  font-style: italic;
  font-size: 0.82em;
}

/* Level 4: heavy decay. Sidebar items vanish. Font shifts. Footer breaks. */
body.decay-4 { background: #ede0c4; }
body.decay-4 #content { background: #f3e9d2; }
body.decay-4 #sidebar { background: #e8dcc0; }
body.decay-4 .sidebar-list li:nth-child(odd) {
  visibility: hidden;
  height: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
}
body.decay-4 .article-title { font-style: italic; color: #4a3a26; }
body.decay-4 .article-body p:nth-of-type(2n) {
  font-family: 'Times New Roman', Times, serif;
  color: #5a4a3a;
}
body.decay-4 #site-footer p:first-child::after {
  content: " [LICENCE FILE NOT FOUND]";
  color: var(--redlink);
  font-weight: bold;
}
body.decay-4 .infobox { transform: rotate(-1deg); }

/* Level 5: terminal. Layout failing. Sidebar gone. Title struck. */
body.decay-5 {
  background: #d8c596;
  color: #3a2a16;
}
body.decay-5 #content { background: #e0d0a4; filter: contrast(0.88); }
body.decay-5 .article-body { opacity: 0.78; }
body.decay-5 .article-title {
  text-decoration: line-through;
  text-decoration-color: rgba(0,0,0,0.4);
  color: #555;
}
body.decay-5 #sidebar { opacity: 0.32; filter: blur(0.4px); }
body.decay-5 .infobox {
  transform: rotate(-1.4deg) skew(-0.8deg);
  filter: blur(0.4px);
}
body.decay-5 #page-tabs { opacity: 0.5; }
body.decay-5 .article-body p:nth-of-type(3n+2)::before {
  content: "[ ";
}
body.decay-5 .article-body p:nth-of-type(3n+2)::after {
  content: " ] (recovered fragment)";
  font-style: italic;
  font-size: 0.85em;
  color: #6a5a36;
}

/* DECAY EFFECTS ON IMAGES */
body.decay-2 .infobox-image img { filter: contrast(0.95) saturate(0.92); }
body.decay-3 .infobox-image img { filter: sepia(0.45) blur(0.3px); }
body.decay-4 .infobox-image img {
  filter: sepia(0.75) blur(0.9px) contrast(0.7);
  opacity: 0.62;
}
body.decay-5 .infobox-image img {
  filter: sepia(1) blur(2.5px) contrast(0.5);
  opacity: 0.28;
}
body.decay-5 .infobox-image::after {
  content: "[image not recovered]";
  position: absolute;
  top: 50%;
  left: 6px;
  right: 6px;
  transform: translateY(-50%);
  text-align: center;
  font-size: 11px;
  color: var(--redlink);
  font-style: italic;
  font-family: 'Courier New', monospace;
  background: rgba(244, 236, 216, 0.88);
  padding: 6px 0;
  border-top: 1px dashed var(--redlink);
  border-bottom: 1px dashed var(--redlink);
}

/* TOMBSTONE — terminal state at 20+ clicks */
body.archive-lost {
  background: #1a1410;
  color: #c9b88a;
  transition: background-color 1.6s ease, color 1.6s ease;
}
body.archive-lost #site-header,
body.archive-lost #page-tabs,
body.archive-lost #sidebar,
body.archive-lost #site-footer {
  display: none;
}
body.archive-lost #layout {
  display: block;
  background: transparent;
  max-width: 720px;
  margin: 6vh auto;
  grid-template-columns: none;
}
body.archive-lost #content {
  background: transparent;
  padding: 0;
}
.tombstone {
  text-align: center;
  border: 1px solid #6b5634;
  background: #2a1f15;
  padding: 56px 44px 44px;
  font-family: 'Linux Libertine', Georgia, serif;
  box-shadow: 0 0 80px rgba(0,0,0,0.7), 0 0 60px rgba(201, 184, 138, 0.04) inset;
  animation: tombstone-appear 1.6s ease-out;
}
@keyframes tombstone-appear {
  0% { opacity: 0; transform: translateY(12px); }
  100% { opacity: 1; transform: translateY(0); }
}
.tombstone-seal {
  font-size: 48px;
  color: #6b5634;
  margin-bottom: 18px;
  line-height: 1;
}
.tombstone-title {
  font-size: 32px;
  letter-spacing: 0.22em;
  color: #d4c39a;
  margin: 0 0 6px;
  border: none;
  font-weight: normal;
  font-family: 'Linux Libertine', Georgia, serif;
}
.tombstone-subtitle {
  font-size: 11px;
  color: #8a7550;
  font-style: italic;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 36px;
}
.tombstone-body {
  text-align: left;
  font-size: 15px;
  line-height: 1.85;
  color: #c9b88a;
  margin: 0 auto 28px;
  max-width: 560px;
  font-family: 'Linux Libertine', Georgia, serif;
}
.tombstone-body p { margin: 0 0 16px; }
.tombstone-body em { color: #e0cea0; font-style: italic; }
.tombstone-body a.reload-link {
  color: #e8c878;
  text-decoration: underline;
}
.tombstone-body a.reload-link:hover { color: #f4d896; }
.tombstone-signature {
  font-size: 12px;
  font-style: italic;
  color: #8a7550;
  margin-top: 28px;
  border-top: 1px solid #4a3a1f;
  padding-top: 16px;
  font-family: 'Linux Libertine', Georgia, serif;
}

/* RESPONSIVE */
@media (max-width: 800px) {
  .header-inner { flex-wrap: wrap; }
  .search input { width: 100%; }
  .search { width: 100%; margin-left: 0; }
  #layout { grid-template-columns: 1fr; }
  #sidebar { border-right: none; border-bottom: 1px solid var(--soft-border); }
  .infobox { float: none; width: auto; margin: 0 0 18px; }
  .page-tabs-inner { overflow-x: auto; }
}
