:root {
  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-infobox: #f8f9fa;
  --bg-infobox-header: #b8d4e3;
  --bg-disambig: #fff8dc;
  --text: #202122;
  --text-secondary: #54595d;
  --link: #0645ad;
  --link-visited: #6b4ba1;
  --border: #a2a9b1;
  --border-light: #c8ccd1;
  --border-section: #a2a9b1;
  --toc-bg: #f8f9fa;
  --table-header: #eaecf0;
  --table-alt: #f8f9fa;
  --serif: 'Linux Libertine', 'Georgia', 'Times New Roman', serif;
  --sans: 'Noto Sans', 'Helvetica Neue', Arial, sans-serif;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.dark-mode {
  --bg: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-infobox: #1a1a2e;
  --bg-infobox-header: #2a4a6b;
  --bg-disambig: #2d2a1a;
  --text: #e0e0e0;
  --text-secondary: #a0a0a0;
  --link: #6daaff;
  --link-visited: #b494d6;
  --border: #404060;
  --border-light: #353555;
  --border-section: #404060;
  --toc-bg: #16213e;
  --table-header: #252545;
  --table-alt: #1e1e38;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

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

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
a:visited { color: var(--link-visited); }

.wiki-article h2 {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 400;
  border-bottom: 1px solid var(--border-section);
  padding-bottom: 0.25rem;
  margin: 1.5rem 0 0.75rem;
}

.wiki-article h3 {
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 700;
  margin: 1rem 0 0.5rem;
}

.wiki-article p {
  margin-bottom: 0.75rem;
}

.wiki-table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.75rem 0;
  font-size: 0.875rem;
}

.wiki-table th {
  background: var(--table-header);
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  text-align: left;
  font-weight: 700;
}

.wiki-table td {
  border: 1px solid var(--border-light);
  padding: 0.4rem 0.75rem;
}

.wiki-table tr:nth-child(even) td {
  background: var(--table-alt);
}

.infobox {
  float: right;
  width: 280px;
  margin: 0 0 1rem 1.5rem;
  border: 1px solid var(--border);
  background: var(--bg-infobox);
  font-size: 0.85rem;
}

.infobox-header {
  background: var(--bg-infobox-header);
  padding: 0.5rem;
  text-align: center;
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 700;
}

.infobox-row {
  display: flex;
  border-top: 1px solid var(--border-light);
}

.infobox-label {
  width: 40%;
  padding: 0.35rem 0.5rem;
  font-weight: 700;
  background: var(--table-alt);
}

.infobox-value {
  width: 60%;
  padding: 0.35rem 0.5rem;
}

.disambig-box {
  background: var(--bg-disambig);
  border: 1px solid #e0d8b0;
  border-left: 4px solid #c8b040;
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  font-style: italic;
}

.toc-box {
  background: var(--toc-bg);
  border: 1px solid var(--border-light);
  padding: 0.75rem 1rem;
  display: inline-block;
  min-width: 200px;
}

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  z-index: 9999;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

.reference-item {
  cursor: pointer;
  transition: background 0.2s;
  padding: 0.15rem 0.25rem;
  border-radius: 3px;
}

.reference-item:hover {
  background: var(--table-alt);
}

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

@media print {
  .no-print { display: none !important; }
  body { background: white; color: black; }
}

.puzzle-logo {
  display: inline-block;
  position: relative;
  width: 50px;
  height: 50px;
}

.search-autocomplete {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: none;
  z-index: 100;
  box-shadow: var(--shadow);
}

.search-autocomplete-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.search-autocomplete-item:hover {
  background: var(--table-alt);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.fade-in {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}