/* ============================================================
   /s640/: long-form project notes (Veikk S640 firmware).
   Generated page, see the comment in index.html. Uses the tokens,
   fonts, status rail and switch of /style.css (data-tab="projects",
   osu! purple). Same grammar as the main page: hairline rules, mono
   labels, numbered section heads. No glass. Motion only under
   [data-motion="on"], which follows the main site's Animations switch.
   ============================================================ */

/* ---- views: html[data-view] is set before paint; no JS = long version ---- */
html:not([data-view="short"]) .view-short,
html[data-view="short"] .view-long { display: none !important; }

/* ============================================================
   DISCLAIMER GATE (same layout idea as 404.html: words left, Vivlos right)
   ============================================================ */
.gate { display: none; }

html.gated .doc-canvas { display: none; }

html.gated .gate {
  min-height: 100vh;
  max-width: 980px;
  margin: 0 auto;
  padding: 40px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 40px;
}

.gate-text {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 560px;
}

.gate-kicker,
.gate-note,
.doc-kicker {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
}

.gate-note { color: var(--text-dim); }

.gate h1 {
  font-size: clamp(2.4rem, 7vw, 4rem);
  font-weight: 900;
  line-height: 1;
  color: var(--text-bright);
  margin-bottom: 6px;
}

.gate p {
  font-size: 1.02rem;
  line-height: 1.6;
  color: var(--text-secondary);
}
.gate p strong { color: var(--text-bright); }

.gate .gate-warned {
  font-weight: 900;
  color: var(--text-bright);
  padding-left: 14px;
  border-left: 2px solid var(--accent);
}

.gate-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
  margin-top: 10px;
}

.gate-accept {
  font: inherit;
  font-weight: 700;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--bg-canvas);
  cursor: pointer;
}
.gate-accept:hover { background: var(--text-bright); }

.gate-leave {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.gate-art {
  height: min(70vh, 460px);
  width: auto;
}

/* ============================================================
   PAGE
   ============================================================ */
.doc-canvas {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 24px 96px;
  display: grid;
  grid-template-columns: 196px minmax(0, 1fr);
  column-gap: 52px;
  row-gap: 28px;
}

.top-status-bar { grid-column: 1 / -1; }
.top-status-bar .status-home { text-decoration: none; }

/* ---- header ---- */
.doc-head {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 24px;
  border-bottom: 1px solid var(--border-hairline);
}

.doc-head-text {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0 28px;
}

.doc-head h1 {
  max-width: 780px;
  font-size: 2.1rem;
  font-weight: 900;
  line-height: 1.12;
  color: var(--text-bright);
}

.doc-meta {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
}

.doc-art {
  align-self: end;
  height: 230px;
  width: auto;
  margin-bottom: -1px; /* sits on the rule */
}

/* key numbers: a row of label/value pairs split by hairlines */
.doc-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, auto));
  justify-content: start;
  margin-top: 14px;
  border-top: 1px solid var(--border-hairline);
}

.doc-stats > div {
  padding: 12px 28px 0 0;
  margin-right: 28px;
  border-right: 1px solid var(--border-hairline);
}
.doc-stats > div:last-child { border-right: none; margin-right: 0; }

.doc-stats dt {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-dim);
}

.doc-stats dd {
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--text-bright);
  line-height: 1.3;
}

.doc-stats dd span {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--accent);
}

.doc-noscript {
  grid-column: 1 / -1;
  padding: 2px 0 2px 16px;
  border-left: 2px solid var(--accent);
  color: var(--text-secondary);
}
.doc-noscript p { display: inline; }

/* ---- contents rail ---- */
.doc-toc {
  position: sticky;
  top: 20px;
  align-self: start;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.doc-toc summary {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  list-style: none;
  padding-bottom: 10px;
}
.doc-toc summary::-webkit-details-marker { display: none; }

.doc-toc ol {
  list-style: none;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border-hairline);
}

.doc-toc a {
  display: grid;
  grid-template-columns: 24px 1fr;
  padding: 5px 0 5px 12px;
  margin-left: -1px;
  border-left: 1px solid transparent;
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--text-secondary);
  text-decoration: none;
}
.toc-num {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1.95;
  color: var(--text-dim);
}
.doc-toc a:hover { color: var(--text-bright); }
.doc-toc a.is-current {
  color: var(--text-bright);
  border-left-color: var(--accent);
}
.doc-toc a.is-current .toc-num { color: var(--accent); }

/* ---- body text ---- */
.doc-body { min-width: 0; }

.doc-body article {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.doc-body article > p,
.doc-body li { line-height: 1.65; }

.doc-body article > p,
.doc-body article > ul,
.doc-body article > ol { max-width: 74ch; }

.doc-body ul,
.doc-body ol {
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.doc-body li::marker { color: var(--text-dim); }
.doc-body li > p { display: inline; }
.doc-body li .code-wrap,
.doc-body li pre { margin-top: 10px; }

.doc-body strong { color: var(--text-bright); }

.doc-body hr { display: none; }

/* section heads: number + title, like the numbered tabs on the main page */
.doc-body h2 {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-top: 44px;
  padding-top: 28px;
  border-top: 1px solid var(--border-hairline);
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1.2;
  color: var(--text-bright);
  scroll-margin-top: 16px;
}
.doc-body article > h2:first-child { margin-top: 8px; border-top: none; padding-top: 0; }

.h-num {
  flex: none;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.doc-body h3 {
  margin-top: 20px;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-bright);
  scroll-margin-top: 16px;
}

.doc-body blockquote {
  max-width: 74ch;
  padding: 2px 0 2px 16px;
  border-left: 2px solid var(--accent);
  color: var(--text-main);
}

/* ---- code ---- */
/* Maple Mono's contextual alternates draw 0x as 0×; this page is full of hex */
.doc-body code,
.doc-body pre {
  font-variant-ligatures: none;
  font-feature-settings: "calt" 0, "liga" 0;
}

.doc-body code {
  padding: 1px 4px;
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  overflow-wrap: anywhere;
}

.doc-body pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  font-size: 0.78rem;
  line-height: 1.55;
}
.doc-body pre code {
  padding: 0;
  background: none;
  font-size: inherit;
  overflow-wrap: normal;
  white-space: pre;
}

/* short blocks (commands) get a copy button and wrap, so the whole command is visible;
   the long listings keep their columns and scroll sideways */
.code-wrap { position: relative; }
.code-wrap pre { padding-right: 68px; }
.code-wrap pre,
.code-wrap pre code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 8px;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xs);
  background: var(--bg-surface-elevated);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-secondary);
  cursor: pointer;
}
.copy-btn:hover { color: var(--text-bright); border-color: var(--accent); }

/* ---- tables ---- */
.table-wrap {
  overflow-x: auto;
  border-bottom: 1px solid var(--border-hairline);
}

.doc-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.doc-body th {
  padding: 8px 14px 8px 0;
  text-align: left;
  vertical-align: bottom;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-dim);
  white-space: nowrap;
}

.doc-body td {
  padding: 8px 14px 8px 0;
  vertical-align: baseline;
  border-top: 1px solid var(--border-hairline);
  line-height: 1.5;
}

.doc-body td:first-child { color: var(--text-bright); }

/* ---- images ---- */
.doc-body img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
}

/* ---- collapsible listings ---- */
.doc-body details {
  border-top: 1px solid var(--border-hairline);
  padding-top: 10px;
}
.doc-body details > summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
  padding-bottom: 10px;
}
.doc-body details > summary:hover,
.doc-body details[open] > summary { color: var(--text-bright); }

/* ---- short version extras ---- */
.short-more {
  margin-top: 24px;
  padding: 14px 0 0;
  border-top: 1px solid var(--border-hairline);
  color: var(--text-secondary);
}

/* ---- footer ---- */
.doc-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 56px;
  padding-top: 14px;
  border-top: 1px solid var(--border-hairline);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* ---- motion (only when the visitor allows it on the main site) ---- */
[data-motion="on"] .doc-toc a,
[data-motion="on"] .copy-btn,
[data-motion="on"] .gate-accept { transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease; }

/* ============================================================
   NARROW SCREENS
   ============================================================ */
@media (max-width: 900px) {
  .doc-canvas {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 22px;
  }
  .doc-art { height: 170px; }
  .doc-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 12px; }
  .doc-stats > div:nth-child(2) { border-right: none; margin-right: 0; }
  .doc-toc {
    position: static;
    max-height: none;
    border-bottom: 1px solid var(--border-hairline);
    padding-bottom: 16px;
  }
  .doc-toc summary { cursor: pointer; color: var(--accent); }
}

@media (max-width: 640px) {
  .doc-canvas { padding: 8px 16px 64px; }
  .doc-head { grid-template-columns: minmax(0, 1fr); }
  .doc-art { display: none; }
  .doc-head h1 { font-size: 1.55rem; }
  .doc-stats dd { font-size: 1.05rem; }
  .doc-body h2 { font-size: 1.3rem; gap: 10px; }
  .doc-body pre { font-size: 0.72rem; }
  .doc-body table { font-size: 0.82rem; }

  html.gated .gate {
    grid-template-columns: minmax(0, 1fr);
    align-content: center;
    padding: 32px 16px;
    gap: 8px;
  }
  .gate-art { order: -1; height: 200px; justify-self: end; }
}
