:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1d2129;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --mark: #fff3bf;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

html[data-theme="dark"] {
  --bg: #14161c;
  --panel: #1c1f27;
  --ink: #e7e9ee;
  --muted: #9aa1af;
  --line: #2b2f3a;
  --accent: #7aa2ff;
  --accent-ink: #10131a;
  --mark: #4a3c00;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 "Georgia", "Times New Roman", serif;
}

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

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 3px solid var(--accent);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink);
  text-decoration: none;
}
.brand__logo {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  font: 700 1.3rem/1 system-ui, sans-serif;
}
.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand__text strong {
  font-size: 1.15rem;
  font-family: system-ui, sans-serif;
}
.brand__text small {
  color: var(--muted);
  font-style: italic;
  font-size: 0.72rem;
}

.search {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 520px;
  display: flex;
  gap: 0.4rem;
}
.search input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 0.95rem;
}
.search input:focus {
  outline: 2px solid var(--accent);
}
.search button,
.topbar__actions button,
.article__tools button,
.editor__tools button,
.primary {
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-family: system-ui, sans-serif;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.search button:hover,
.topbar__actions button:hover,
.article__tools button:hover,
.editor__tools button:hover {
  background: var(--mark);
  transform: translateY(-1px);
}
.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.primary:hover {
  filter: brightness(1.08);
}
.topbar__actions {
  display: flex;
  gap: 0.4rem;
}

.search__hints {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.search__hints li {
  padding: 0.45rem 0.6rem;
  border-radius: 7px;
  cursor: pointer;
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.search__hints li:hover {
  background: var(--mark);
  color: #1d2129;
}
.search__hints span {
  color: var(--muted);
  font-size: 0.76rem;
}

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 220px;
  gap: 1.25rem;
  max-width: 1240px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  box-shadow: var(--shadow);
}
.panel h3 {
  margin: 0 0 0.5rem;
  font: 700 0.78rem/1 system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.panel ul {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
}
.panel li {
  padding: 0.28rem 0;
  border-bottom: 1px dashed var(--line);
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
}
.panel li:last-child {
  border-bottom: none;
}
.panel time,
.muted {
  color: var(--muted);
  font-size: 0.75rem;
}

/* ---------- content ---------- */
.content {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.25rem 1.6rem 2rem;
  box-shadow: var(--shadow);
}
.content:focus {
  outline: none;
}

.crumbs {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.article__title {
  margin: 0;
  font-size: 2rem;
  line-height: 1.2;
  border-bottom: 2px solid var(--line);
  padding-bottom: 0.4rem;
}
.article__tagline {
  color: var(--muted);
  font-style: italic;
  margin-top: 0.5rem;
}
.article__tools {
  display: flex;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.article__body h2 {
  margin-top: 1.6rem;
  font-size: 1.4rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.2rem;
}
.article__body h3 {
  margin-top: 1.2rem;
  font-size: 1.12rem;
}
.article__body ul {
  padding-left: 1.4rem;
}
.article__body li {
  margin: 0.25rem 0;
}
.article__body code {
  background: var(--mark);
  color: #1d2129;
  padding: 0.05rem 0.3rem;
  border-radius: 5px;
  font-size: 0.9em;
}

.infobox {
  float: right;
  width: 250px;
  margin: 0 0 1rem 1.25rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem;
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
}
.infobox h4 {
  margin: 0 0 0.5rem;
  text-align: center;
  font-size: 1rem;
}
.infobox dl {
  margin: 0;
}
.infobox dt {
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 0.4rem;
}
.infobox dd {
  margin: 0;
}
.infobox__summary {
  border-top: 1px dashed var(--line);
  margin-bottom: 0;
  padding-top: 0.5rem;
  color: var(--muted);
  font-style: italic;
}

/* ---------- TOC ---------- */
.toc {
  position: sticky;
  top: 84px;
  align-self: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  box-shadow: var(--shadow);
}
.toc h3 {
  margin: 0 0 0.5rem;
  font: 700 0.78rem/1 system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.toc__list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: system-ui, sans-serif;
  font-size: 0.86rem;
}
.toc__list li {
  padding: 0.25rem 0;
}
.toc__l3 {
  padding-left: 0.9rem;
}

/* ---------- lists / editor ---------- */
.cardlist {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}
.cardlist li {
  margin-bottom: 0.6rem;
}
.cardlist a {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  transition: transform 0.12s, border-color 0.12s;
}
.cardlist a:hover {
  transform: translateX(4px);
  border-color: var(--accent);
  text-decoration: none;
}
.cardlist span {
  color: var(--muted);
  font-size: 0.86rem;
}

.hint {
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 0.88rem;
}
.hint code,
.article__body p code {
  background: var(--mark);
  color: #1d2129;
  padding: 0.05rem 0.3rem;
  border-radius: 5px;
}

#editor {
  width: 100%;
  min-height: 340px;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: 0.95rem/1.6 "JetBrains Mono", Menlo, Consolas, monospace;
  resize: vertical;
}
#editor:focus {
  outline: 2px solid var(--accent);
}
.editor__tools {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.75rem;
}
.history {
  font-family: system-ui, sans-serif;
  padding-left: 1.2rem;
}

/* ---------- footer / flash ---------- */
.footer {
  border-top: 1px solid var(--line);
  padding: 1.25rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-family: system-ui, sans-serif;
}

.flash {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: #10131a;
  color: #fff;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s;
  z-index: 60;
}
.flash--show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- responsive ---------- */
@media (max-width: 1020px) {
  .layout {
    grid-template-columns: 210px minmax(0, 1fr);
  }
  .toc {
    display: none;
  }
}
@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    order: 2;
  }
  .infobox {
    float: none;
    width: 100%;
    margin: 0 0 1rem;
  }
  .content {
    padding: 1rem;
  }
}

/* ---------- images / gallery / references ---------- */
.infobox__fig {
  margin: 0 0 0.6rem;
}
.infobox__fig img {
  display: block;
  width: 100%;
  border-radius: 8px;
  background: var(--bg-alt, #f5f2ea);
}
.infobox__fig figcaption {
  margin-top: 0.3rem;
  font-size: 0.72rem;
  font-style: italic;
  line-height: 1.35;
  text-align: center;
  color: var(--muted, #6b7280);
}
.fig {
  margin: 1rem 0;
}
.fig img {
  display: block;
  max-width: 100%;
  border: 1px solid var(--line, #e5e1d8);
  border-radius: 10px;
  background: var(--bg-alt, #f5f2ea);
}
.fig figcaption {
  margin-top: 0.4rem;
  font-size: 0.82rem;
  font-style: italic;
  text-align: center;
  color: var(--muted, #6b7280);
}
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.gallery__card {
  display: block;
  overflow: hidden;
  color: inherit;
  background: var(--bg-alt, #f5f2ea);
  border: 1px solid var(--line, #e5e1d8);
  border-radius: 10px;
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s;
}
.gallery__card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}
.gallery__card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}
.gallery__card span {
  display: block;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}
.refs {
  margin-top: 1.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line, #e5e1d8);
}
.refs h2 {
  font-size: 1.15rem;
}
.refs ol {
  padding-left: 1.4rem;
  font-size: 0.88rem;
  color: var(--muted, #6b7280);
}
.refs li {
  margin-bottom: 0.25rem;
}
