/* SmallOLED Web Flasher — "Paper Docs" direction.
   Light, warm-paper dev-docs layout: sticky left rail (brand + TOC + links),
   main content column to the right. Warm neutrals + one forest-green accent.
   Geist Sans for UI, Geist Mono for technical content, a single pixel mark
   as the only nod to the OLED pixel-clock aesthetic. */

:root {
  --paper:      #f4f0e7;
  --paper-2:    #efe9db;
  --card:       #fcfaf4;
  --card-2:     #f6f1e6;
  --inset:      #eee7d6;

  --ink:        #24221c;
  --ink-soft:   #3a382f;
  --mute:       #6c675b;
  --dim:        #8a8472;
  --faint:      #a39c89;

  --line:       #e4ddcc;
  --line-soft:  #ece6d7;
  --line-2:     #d4cbb5;

  --green:      #1f8a5b;
  --green-d:    #176c47;
  --green-l:    #2ba169;
  --green-soft: rgba(31, 138, 91, 0.12);
  --green-line: rgba(31, 138, 91, 0.32);

  --ok:    #1f8a5b;
  --warn:  #b8740d;
  --err:   #c0392b;

  /* CRT readout — the one retro screen, reused for specs + serial monitor */
  --crt-bg:  #131e18;
  --crt-fg:  #84f3ad;
  --crt-dim: #4d8a67;
  --crt-line:#0c140f;

  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --pixel: "Press Start 2P", monospace;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --rail-width: 224px;
  --rail-gap:   72px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

/* faint green wash at the top, like the device's AP screen tint */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 520px;
  pointer-events: none;
  background: radial-gradient(900px 300px at 38% -60px, rgba(31, 138, 91, 0.07), transparent 70%);
  z-index: 0;
}

/* ────────── shell + layout ────────── */

.shell {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding: 40px 56px 80px;
}
.layout {
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  gap: var(--rail-gap);
  align-items: start;
}

/* ────────── left rail ────────── */

.rail {
  position: sticky;
  top: 40px;
  align-self: start;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding-right: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}
.rail::-webkit-scrollbar { width: 6px; }
.rail::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 999px; }

.rail-inner { display: flex; flex-direction: column; gap: 28px; }

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--green);
  display: grid;
  place-items: center;
  flex: none;
  box-shadow: 0 0 0 4px var(--green-soft);
}
/* 2×2 pixel cluster — the OLED nod */
.brand-mark::after {
  content: "";
  width: 14px;
  height: 14px;
  background:
    linear-gradient(#fff 0 0) 0 0 / 6px 6px no-repeat,
    linear-gradient(#fff 0 0) 8px 8px / 6px 6px no-repeat,
    linear-gradient(rgba(255,255,255,.55) 0 0) 8px 0 / 6px 6px no-repeat,
    linear-gradient(rgba(255,255,255,.55) 0 0) 0 8px / 6px 6px no-repeat;
}
.brand-text { min-width: 0; }
.brand-name { font-weight: 600; color: var(--ink); letter-spacing: -0.01em; font-size: 15px; line-height: 1.15; }
.brand-sub { color: var(--dim); font-family: var(--mono); font-size: 11.5px; line-height: 1.4; }

.rail-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 10px;
}

.toc { display: flex; flex-direction: column; gap: 2px; }
.toc-item {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin-left: -10px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--mute);
  text-decoration: none;
  border: 0;
  position: relative;
  transition: background 120ms ease, color 120ms ease;
}
.toc-item .toc-num { font-family: var(--mono); font-size: 11px; color: var(--faint); letter-spacing: 0.04em; }
.toc-item:hover { background: var(--paper-2); color: var(--ink); }
.toc-item:hover .toc-num { color: var(--mute); }
.toc-item.is-active { color: var(--ink); background: var(--paper-2); }
.toc-item.is-active::before {
  content: "";
  position: absolute;
  left: -1px; top: 8px; bottom: 8px;
  width: 2px; border-radius: 2px;
  background: var(--green);
}
.toc-item.is-active .toc-num { color: var(--green); }

.rail-links { display: flex; flex-direction: column; gap: 4px; }
.rail-links a {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--mute);
  padding: 5px 0;
  border-bottom: 0;
  transition: color 120ms ease;
}
.rail-links a:hover { color: var(--green-d); }

.rail-foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
}
.rail-foot .rail-version span { color: var(--mute); }

/* ────────── main column ────────── */

.main { min-width: 0; }

.hero { margin-bottom: 36px; padding-top: 4px; }
.hero h1 {
  margin: 0 0 14px;
  font-size: 46px;
  line-height: 1.06;
  letter-spacing: -0.03em;
  color: var(--ink);
  font-weight: 600;
  text-wrap: balance;
  max-width: 17ch;
}
.hero h1 .accent { color: var(--green); }
.hero p {
  margin: 0;
  max-width: 62ch;
  color: var(--mute);
  font-size: 16.5px;
  text-wrap: pretty;
}

/* ────────── browser support callout ────────── */

.browser-callout {
  display: none;
  margin: 28px 0 0;
  padding: 14px 16px;
  border: 1px solid var(--line-2);
  background: var(--card);
  border-radius: var(--r-md);
  color: var(--mute);
  font-size: 14px;
  gap: 12px;
  align-items: flex-start;
  max-width: 640px;
}
.browser-callout.show { display: flex; }
.browser-callout strong { color: var(--ink); font-weight: 600; display: block; margin-bottom: 2px; }
.browser-callout .pulse {
  flex: none; width: 8px; height: 8px; margin-top: 7px;
  border-radius: 999px; background: var(--warn);
  box-shadow: 0 0 0 4px rgba(184, 116, 13, 0.14);
}

/* ────────── panels ────────── */

.panel { border-top: 1px solid var(--line); padding: 38px 0; }
.panel:last-of-type { padding-bottom: 12px; }

.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.panel-head .num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--mute);
  padding: 3px 8px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  letter-spacing: 0.04em;
}
.panel-head h2 {
  margin: 0;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--ink);
  scroll-margin-top: 36px;
}

.lede { margin: 0 0 18px; max-width: 68ch; color: var(--mute); font-size: 15px; text-wrap: pretty; }
.lede strong { color: var(--ink-soft); font-weight: 600; }

/* ────────── checklist ────────── */

.checklist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.checklist li {
  position: relative;
  padding-left: 24px;
  max-width: 72ch;
  font-size: 14.5px;
  color: var(--mute);
  text-wrap: pretty;
}
.checklist li::before {
  content: "";
  position: absolute;
  left: 4px; top: 7px;
  width: 8px; height: 8px;
  background: var(--green);
  /* tiny pixel tick */
  clip-path: polygon(0 40%, 38% 40%, 38% 0, 62% 0, 62% 40%, 100% 40%, 100% 64%, 62% 64%, 62% 100%, 38% 100%, 38% 64%, 0 64%);
  opacity: .0;
}
.checklist li::after {
  content: "";
  position: absolute;
  left: 6px; top: 9px;
  width: 6px; height: 6px;
  border-radius: 2px;
  background: var(--green);
}
.checklist li strong { color: var(--ink); font-weight: 600; margin-right: 4px; }

/* ────────── form: board select ────────── */

.field-label {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 8px;
}
.select-wrap { position: relative; max-width: 560px; margin-bottom: 18px; }
.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px; top: 50%;
  width: 8px; height: 8px;
  border-right: 1.5px solid var(--mute);
  border-bottom: 1.5px solid var(--mute);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  background: #ffffff;
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  padding: 12px 36px 12px 14px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(80, 65, 35, 0.06);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
select:hover { border-color: var(--line-2); }
select:focus { outline: none; border-color: var(--green-line); box-shadow: 0 0 0 3px var(--green-soft); }

/* board note under the picker */
.board-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  max-width: 560px;
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--mute);
  font-family: var(--mono);
  line-height: 1.5;
}
.board-note .bn-dot { flex: none; width: 7px; height: 7px; margin-top: 6px; border-radius: 2px; background: var(--green); }
.board-note strong { color: var(--ink); font-weight: 500; }

/* ────────── specs as CRT readout ────────── */

.specs {
  margin: 0 0 20px;
  max-width: 560px;
  padding: 15px 17px;
  background: var(--crt-bg);
  border: 1px solid var(--crt-line);
  border-radius: var(--r-md);
  display: flex;
  flex-direction: column;
  gap: 7px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 24px rgba(0,0,0,.55), inset 0 0 3px rgba(132,243,173,.4);
  font-family: var(--mono);
}
.specs::after {
  content: "";
  position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.14) 0 1px, transparent 1px 3px);
  pointer-events: none;
}
.spec-row { display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: baseline; font-size: 13px; position: relative; z-index: 1; }
.spec-row dt { color: var(--crt-dim); font-size: 12px; letter-spacing: 0.04em; text-transform: lowercase; }
.spec-row dd { margin: 0; color: var(--crt-fg); word-break: break-word; text-shadow: 0 0 6px rgba(132,243,173,.35); }

.status-line { margin: 0 0 14px; font-family: var(--mono); font-size: 12.5px; color: var(--dim); min-height: 1em; max-width: 560px; }
.status-line.error { color: var(--err); }
.status-line.warn  { color: var(--warn); }
.status-line.ok    { color: var(--ok); }
.status-line:empty { display: none; }

/* ────────── install row ────────── */

.install-row { display: flex; flex-direction: column; gap: 12px; }
#install-slot {
  --esp-tools-button-color: var(--green);
  --esp-tools-button-text-color: #ffffff;
  display: flex;
  align-items: center;
  min-height: 44px;
}
#install-slot esp-web-install-button { display: inline-block; }
esp-web-install-button::part(button) { font-family: var(--sans) !important; font-weight: 600 !important; }
/* Avoid a flash of raw slot text before the custom element upgrades. */
esp-web-install-button:not(:defined) { visibility: hidden; }
esp-web-install-button:not(:defined) .unsupported { display: none; }

.hint { color: var(--dim); font-size: 13px; margin: 0; text-wrap: pretty; max-width: 68ch; }
.hint code, .lede code, .checklist code, .step-list code, .path-body code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--ink-soft);
}
.unsupported { color: var(--err); font-size: 13px; font-family: var(--mono); }

/* ────────── after-flash + paths ────────── */

.path { margin: 0 0 4px; }
.path-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.path-head h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--ink); letter-spacing: -0.005em; }
.path-tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--green-d); background: var(--green-soft); border: 1px solid var(--green-line); border-radius: 999px;
}
.path-tag-muted { color: var(--dim); background: var(--paper-2); border-color: var(--line); }
.path-pulse {
  width: 6px; height: 6px; border-radius: 999px; background: var(--green);
  box-shadow: 0 0 0 0 var(--green-line); animation: path-pulse 1.8s ease-out infinite;
}
@keyframes path-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(31, 138, 91, 0.4); }
  100% { box-shadow: 0 0 0 8px rgba(31, 138, 91, 0); }
}
@media (prefers-reduced-motion: reduce) { .path-pulse { animation: none; } }

.path-body { margin: 0 0 14px; max-width: 68ch; color: var(--mute); font-size: 14.5px; text-wrap: pretty; }
.path-body strong { color: var(--ink); font-weight: 600; }
.path-body a { color: var(--green-d); }

/* ────────── credentials block (AP setup) ────────── */

.creds {
  margin: 0 0 22px;
  max-width: 560px;
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  overflow: hidden;
}
.creds-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--card-2);
}
.creds-dot { width: 8px; height: 8px; border-radius: 2px; background: var(--green); box-shadow: 0 0 8px var(--green-line); }
.creds-title { font-family: var(--mono); font-size: 11.5px; color: var(--dim); letter-spacing: 0.04em; text-transform: lowercase; }
.creds-row {
  display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: baseline;
  padding: 11px 16px; font-family: var(--mono); font-size: 14px;
  border-bottom: 1px dashed var(--line);
}
.creds-row:last-of-type { border-bottom: 0; }
.creds-key { color: var(--dim); font-size: 11.5px; letter-spacing: 0.04em; text-transform: lowercase; }
.creds-val { color: var(--ink); word-break: break-all; }
.creds-val .dim { color: var(--faint); }
.creds-val a { color: var(--green-d); border-bottom: 1px dotted var(--green-line); }
.creds-val a:hover { border-bottom-color: var(--green-d); }
.creds-note { margin: 0; padding: 8px 16px 12px; font-family: var(--mono); font-size: 11px; color: var(--faint); background: var(--card-2); border-top: 1px solid var(--line); }

/* ────────── step list ────────── */

.step-list { counter-reset: step; list-style: none; padding: 0; margin: 0 0 18px; display: flex; flex-direction: column; gap: 12px; }
.step-list li {
  counter-increment: step;
  position: relative;
  padding-left: 36px;
  min-height: 24px;
  max-width: 72ch;
  font-size: 14.5px;
  color: var(--mute);
  text-wrap: pretty;
}
.step-list li::before {
  content: counter(step);
  position: absolute; left: 0; top: 0;
  font-family: var(--mono); font-size: 11px; color: var(--green-d);
  background: var(--green-soft); border: 1px solid var(--green-line); border-radius: 6px;
  width: 24px; height: 24px; display: inline-grid; place-items: center;
}
.step-list li strong { color: var(--ink); font-weight: 600; }
.step-list li a { color: var(--green-d); }

/* ────────── OS picker (Python section) ────────── */

.os-tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 9px; margin: 0 0 18px; }
.os-tab {
  font-family: var(--mono); font-size: 12.5px;
  padding: 7px 16px; border-radius: 6px; border: 0; background: transparent;
  color: var(--mute); cursor: pointer; transition: background 120ms ease, color 120ms ease;
}
.os-tab:hover { color: var(--ink); }
.os-tab.is-active { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(80,65,35,.08); }

.os-panel { display: none; }
.os-panel.is-active { display: block; }

/* ────────── command / code block (terminal) ────────── */

.cmd {
  position: relative;
  max-width: 640px;
  margin: 0 0 16px;
  background: var(--crt-bg);
  border: 1px solid var(--crt-line);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: inset 0 0 22px rgba(0,0,0,.5);
}
.cmd-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 13px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  background: rgba(255,255,255,.02);
}
.cmd-dot { width: 9px; height: 9px; border-radius: 999px; background: #2c4636; }
.cmd-dot:nth-child(2) { background: #355640; }
.cmd-dot:nth-child(3) { background: #3e6649; }
.cmd-title { margin-left: auto; padding-right: 56px; font-family: var(--mono); font-size: 11px; color: var(--crt-dim); letter-spacing: 0.04em; }
.cmd pre {
  margin: 0;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  color: var(--crt-fg);
  white-space: pre-wrap;
  word-break: break-word;
  text-shadow: 0 0 6px rgba(132,243,173,.25);
}
.cmd pre .pr { color: var(--crt-dim); user-select: none; }
.cmd pre .cm { color: #5f9c77; }
.cmd-copy {
  position: absolute; top: 7px; right: 11px;
  font-family: var(--mono); font-size: 10.5px;
  color: var(--crt-dim);
  background: rgba(132,243,173,.06);
  border: 1px solid rgba(132,243,173,.16);
  border-radius: 5px; padding: 4px 9px; cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
}
.cmd-copy:hover { color: var(--crt-fg); background: rgba(132,243,173,.12); }
.cmd-copy.copied { color: var(--crt-fg); }

.note {
  display: flex; gap: 10px; align-items: flex-start;
  max-width: 640px; margin: 0 0 18px;
  padding: 12px 14px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-left: 2px solid var(--green);
  border-radius: var(--r-sm);
  font-size: 13.5px; color: var(--mute); text-wrap: pretty;
}
.note strong { color: var(--ink); font-weight: 600; }
.note .note-k { flex: none; font-family: var(--mono); font-size: 11px; color: var(--green-d); margin-top: 2px; letter-spacing: 0.04em; }

/* ────────── links ────────── */

a { color: var(--green-d); text-decoration: none; border-bottom: 1px solid var(--line-2); transition: border-color 120ms ease, color 120ms ease; }
a:hover { border-color: var(--green); color: var(--green); }

/* ────────── serial monitor ────────── */

.monitor-row { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.btn-monitor {
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 9px 18px; border-radius: var(--r-md);
  border: 1px solid var(--green-d); background: var(--green); color: #fff;
  cursor: pointer; transition: filter 120ms ease, opacity 120ms ease;
}
.btn-monitor:hover:not(:disabled) { filter: brightness(1.05); }
.btn-monitor:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-monitor.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line-2); }
.btn-monitor.btn-ghost:hover:not(:disabled) { background: var(--card-2); }

.monitor-output {
  margin: 0 0 12px;
  padding: 14px 16px;
  background: var(--crt-bg);
  border: 1px solid var(--crt-line);
  border-radius: var(--r-md);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--crt-fg);
  white-space: pre-wrap;
  word-break: break-all;
  height: 320px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--crt-dim) transparent;
  box-shadow: inset 0 0 24px rgba(0,0,0,.5);
  text-shadow: 0 0 6px rgba(132,243,173,.2);
}
.monitor-output::-webkit-scrollbar { width: 6px; }
.monitor-output::-webkit-scrollbar-thumb { background: var(--crt-dim); border-radius: 999px; }
.monitor-output:empty::before { content: "Waiting for connection…"; color: var(--crt-dim); }

/* ────────── footer ────────── */

.footer {
  margin-top: 44px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  color: var(--dim); font-family: var(--mono); font-size: 11.5px; flex-wrap: wrap;
}
.footer a { color: var(--mute); border-bottom: 0; }
.footer a:hover { color: var(--green-d); }

/* ────────── responsive ────────── */

@media (max-width: 980px) {
  :root { --rail-gap: 48px; --rail-width: 200px; }
  .shell { padding: 32px 36px 64px; }
  .hero h1 { font-size: 38px; }
}
@media (max-width: 820px) {
  .shell { padding: 24px 22px 48px; }
  .layout { grid-template-columns: 1fr; gap: 28px; }
  .rail {
    position: static; max-height: none; overflow: visible;
    padding-right: 0; padding-bottom: 18px; border-bottom: 1px solid var(--line);
  }
  .rail-inner { display: grid; grid-template-columns: 1fr auto; gap: 16px 24px; align-items: center; }
  .toc, .rail-foot { display: none; }
  .rail-links { flex-direction: row; gap: 16px; grid-column: 1 / -1; }
  .rail-links .rail-label { display: none; }
  .hero h1 { font-size: 31px; }
}
@media (max-width: 480px) {
  .spec-row, .creds-row { grid-template-columns: 82px 1fr; gap: 12px; }
  .hero h1 { font-size: 26px; }
}
