/* ============================================================
   Zynthian Documentation — Dark Synth Theme
   Graphite ground · warm ink · the display's blue as the accent
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.72;
  background: #0f1013;
  color: #cfcbc2;
}

/* --- Header --- */
#site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(180deg, #101114, #191a1e);
  color: #a9a49a;
  padding: 0.55rem 1.5rem;
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(228,222,208,0.14);
  box-shadow: none;
}
#site-header a { color: #a9a49a; text-decoration: none; }
#site-header a:hover { color: #cfeaff; }
/* the mark inherits the header's colour, so the hover carries it too */
#site-header a { display: inline-flex; align-items: center; gap: 0.55rem; vertical-align: -0.35em; }
.brand-mark { flex: 0 0 auto; }

/* --- Layout --- */
#layout { display: flex; min-height: calc(100vh - 42px); }

/* --- Sidebar --- */
#sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #101114;
  border-right: 1px solid rgba(228,222,208,0.3);
  padding: 0.75rem 0 1.5rem;
  overflow-y: auto;
  position: sticky;
  top: 42px;
  height: calc(100vh - 42px);
}
#sidebar .track { margin-bottom: 0.25rem; }
.track-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: calc(100% - 2rem);
  margin: 0.85rem 1rem 0.35rem;
  padding: 0 0 0.3rem;
  background: none;
  border: none;
  border-bottom: 1px solid rgba(228,222,208,0.2);
  cursor: pointer;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: #8fbde0;
  text-align: left;
}
.track-header:hover { color: #cfeaff; }
.track-arrow {
  font-size: 0.65rem;
  transition: transform 0.18s ease;
  flex-shrink: 0;
  margin-left: 0.3rem;
}
.track-header[aria-expanded="false"] .track-arrow { transform: rotate(-90deg); }
#sidebar ul { list-style: none; margin: 0; padding: 0; }
#sidebar .track-list { margin-bottom: 0.5rem; }
.sb-donate {
  display: block;
  margin: 1.75rem 1rem 0.75rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid rgba(228,222,208,0.3);
  border-radius: 4px;
  text-align: center;
  text-decoration: none;
  color: #a9a49a;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  transition: color 0.18s ease, border-color 0.18s ease;
}
.sb-donate:hover { color: #cfeaff; border-color: rgba(228,222,208,0.55); }
#sidebar li a {
  display: block;
  padding: 0.28rem 1rem;
  text-decoration: none;
  color: #a9a49a;
  font-size: 0.875rem;
  transition: background 0.12s, color 0.12s;
}
#sidebar li a:hover { background: rgba(228,222,208,0.08); color: #cfeaff; }
#sidebar li a[aria-current="page"] {
  background: rgba(79,131,176,0.18);
  color: #cfeaff;
  font-weight: 600;
  border-left: 2px solid #cfeaff;
  padding-left: calc(1rem - 2px);
}

/* --- Search --- */
#nav-search {
  display: block;
  width: calc(100% - 2rem);
  margin: 0.7rem 1rem 0.8rem;
  padding: 0.32rem 0.6rem;
  border: 1px solid rgba(228,222,208,0.28);
  border-radius: 2px;
  font-size: 0.85rem;
  background: rgba(255,255,255,0.03);
  color: #8fbde0;
}
#nav-search::placeholder { color: rgba(169,164,154,0.35); }
#nav-search:focus { outline: 1px solid #8fbde0; border-color: #8fbde0; background: rgba(255,255,255,0.05); }
#search-results ul { list-style: none; margin: 0; padding: 0; }
#search-no-results { padding: 0.4rem 1rem; color: #7d786d; font-size: 0.85rem; margin: 0; }
.search-result a { display: block; padding: 0.5rem 1rem; text-decoration: none; border-bottom: 1px solid rgba(228,222,208,0.1); }
.search-result a:hover, .result-focused a { background: rgba(228,222,208,0.08); }
.result-focused a { outline: 1px solid #8fbde0; outline-offset: -1px; }
.result-title { display: block; font-weight: 600; font-size: 0.88rem; color: #cfeaff; }
.result-heading { display: block; font-size: 0.75rem; color: #8fbde0; margin-top: 0.1rem; }
.result-excerpt { display: block; font-size: 0.78rem; color: #8a8579; margin-top: 0.12rem; line-height: 1.4; }
mark { background: rgba(228,222,208,0.25); color: inherit; padding: 0 2px; border-radius: 1px; }

/* --- Main --- */
main {
  flex: 1;
  padding: 2rem 2.5rem;
  background: #131316;
}

/* --- Article --- */
article {
  max-width: 820px;
  margin: 0 auto;
  padding: 2.5rem 2.75rem;
  background: #17181b;
  border: 1px solid rgba(228,222,208,0.18);
  border-radius: 3px;
  box-shadow: 0 6px 32px rgba(0,0,0,0.4);
}

/* --- Headings --- */
h1, h2, h3, h4 { color: #efece4; line-height: 1.3; font-weight: 600; }

h1 {
  font-size: 2rem;
  margin-top: 0;
  margin-bottom: 1.4rem;
}
h1::after {
  content: '';
  display: block;
  margin-top: 0.45rem;
  height: 2px;
  background: linear-gradient(to right, #8fbde0 0%, #8fbde0 40%, transparent 100%);
}

h2 {
  font-size: 1.35rem;
  margin-top: 2rem;
  margin-bottom: 0.65rem;
}
h2::after {
  content: '';
  display: block;
  margin-top: 0.25rem;
  height: 1px;
  background: linear-gradient(to right, rgba(228,222,208,0.6) 0%, rgba(228,222,208,0.1) 50%, transparent 100%);
}

h3 { font-size: 1.05rem; color: #dcd8ce; margin-top: 1.6rem; margin-bottom: 0.45rem; }
h4 { font-size: 0.95rem; color: #b6b1a6; margin-top: 1.1rem; }

p { margin: 0 0 0.9rem; color: #c2beb4; }

a { color: #8fbde0; text-decoration: underline; text-decoration-color: rgba(228,222,208,0.3); }
a:hover { color: #cfeaff; text-decoration-color: rgba(207,234,255,0.6); }

/* --- HR --- */
hr {
  border: none;
  height: 1px;
  background: linear-gradient(to right, transparent 0%, rgba(228,222,208,0.4) 15%, rgba(228,222,208,0.4) 85%, transparent 100%);
  margin: 1.75rem 0;
}

/* --- Code --- */
pre, code { font-family: 'Fira Code', 'Cascadia Code', 'Consolas', 'Courier New', monospace; }
pre {
  background: #0a0d13;
  color: #d6d2c8;
  border-left: 2px solid #4f83b0;
  border-radius: 0 2px 2px 0;
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
  font-size: 0.84rem;
  line-height: 1.6;
  margin: 1.1rem 0;
}
code {
  background: rgba(79,131,176,0.16);
  color: #cfeaff;
  padding: 0.1em 0.32em;
  border-radius: 2px;
  font-size: 0.86em;
}
pre code { background: none; padding: 0; color: inherit; font-size: inherit; }

/* --- Tables --- */
table { border-collapse: collapse; width: 100%; margin: 1.1rem 0; font-size: 0.9rem; }
th {
  background: #0e1723;
  color: #8fbde0;
  text-align: left;
  font-weight: 600;
  letter-spacing: 0.04em;
  font-size: 0.85rem;
}
th, td { padding: 0.42rem 0.8rem; border: 1px solid rgba(228,222,208,0.2); }
td { color: #c2beb4; }
tr:nth-child(even) td { background: rgba(228,222,208,0.03); }
tr:hover td { background: rgba(228,222,208,0.07); }

/* --- Images --- */
img {
  max-width: 100%;
  border: 1px solid rgba(228,222,208,0.3);
  border-radius: 2px;
  box-shadow: 2px 4px 10px rgba(0,0,0,0.4);
  display: block;
  margin: 0.75rem 0;
}

/* --- Blockquote --- */
blockquote {
  border-left: 2px solid #4f83b0;
  margin: 1.1rem 0;
  padding: 0.5rem 1rem;
  background: rgba(228,222,208,0.06);
  color: #a9a49a;
  font-style: italic;
}

/* --- Lists --- */
ul, ol { padding-left: 1.5rem; margin: 0.4rem 0 0.9rem; }
li { margin-bottom: 0.2rem; color: #c2beb4; }

/* --- Mermaid --- */
.mermaid { margin: 1.4rem 0; }

/* --- Responsive --- */
@media (max-width: 900px) {
  #layout { flex-direction: column; }
  #sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1px solid rgba(228,222,208,0.3); }
  #toc-column { display: none !important; }
  main { padding: 1rem; }
  article { padding: 1.25rem 1rem; }
}

/* --- Copy buttons --- */
.pre-wrap { position: relative; }
.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(228,222,208,0.08);
  color: #8fbde0;
  border: 1px solid rgba(228,222,208,0.25);
  border-radius: 2px;
  padding: 0.16rem 0.5rem;
  font-size: 0.7rem;
  font-family: inherit;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  line-height: 1.6;
}
.copy-btn:hover { background: rgba(228,222,208,0.18); color: #cfeaff; }
.copy-btn.copied { background: rgba(228,222,208,0.2); color: #cfeaff; }

/* --- Anchor links --- */
.anchor-link {
  margin-left: 0.5em;
  color: rgba(228,222,208,0.35);
  text-decoration: none;
  font-size: 0.8em;
  font-weight: 400;
  vertical-align: middle;
}
.anchor-link:hover, .anchor-link.anchor-copied { color: #8fbde0; }

/* --- TOC column (wide screens) --- */
#toc-column {
  width: 220px;
  flex-shrink: 0;
  padding: 1.5rem 0.75rem 1.5rem 0;
  display: none;
}
@media (min-width: 1280px) {
  #toc-column { display: block; }
}

/* --- TOC box --- */
#toc {
  background: #101114;
  border: 1px solid rgba(228,222,208,0.22);
  border-radius: 3px;
  padding: 0.6rem 0.8rem;
  font-size: 0.8rem;
  overflow-y: auto;
}
/* Sticky when in column */
#toc-column #toc {
  position: sticky;
  top: 58px;
  max-height: calc(100vh - 80px);
}
/* Fixed floating when toggled on narrow screens */
#toc.toc-floating {
  position: fixed;
  right: 1.5rem;
  top: 80px;
  width: 210px;
  max-height: calc(100vh - 120px);
  z-index: 10;
  display: none;
}
#toc.toc-floating.toc-visible { display: block; }
.toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.toc-header-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.62rem;
  color: #8fbde0;
}
.toc-collapse-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #8fbde0;
  font-size: 0.75rem;
  padding: 0 0.1rem;
  line-height: 1;
  transition: transform 0.18s ease;
}
.toc-collapse-btn:hover { color: #cfeaff; }
#toc.toc-body-collapsed .toc-collapse-btn { transform: rotate(-90deg); }
#toc.toc-body-collapsed ul { display: none; }
#toc ul { list-style: none; margin: 0; padding: 0; }
#toc li a {
  display: block;
  color: #8a8579;
  text-decoration: none;
  padding: 0.18rem 0;
  line-height: 1.4;
  transition: color 0.1s;
}
#toc li a:hover, #toc li a.toc-active { color: #8fbde0; }
#toc li.toc-h3 a { padding-left: 0.8rem; font-size: 0.75rem; }

/* Floating toggle button (narrow screens only) */
#toc-toggle {
  display: none;
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  width: 40px; height: 40px;
  background: #101114;
  border: 1px solid #8fbde0;
  border-radius: 50%;
  color: #8fbde0;
  font-size: 1.1rem;
  cursor: pointer;
  z-index: 11;
  align-items: center;
  justify-content: center;
}
@media (max-width: 1279px) {
  #toc-toggle { display: flex; }
}
