/* Explore Code IDE layer (HOTBAR-36). Every rule is scoped to body.ide, which only ide.js sets,
   so with JS off the section pages look and read exactly as before.
   Look: Solar Design Studio / Energy Transition Simulator HUD: black ground, hairline edges, dim text,
   cyan accent, outline (never filled) buttons. */
body.ide {
  --ide-bg: #000; --ide-panel: #0b0e14; --ide-line: #2f343d; --ide-text: #fff; --ide-dim: #a6adbb;
  --ide-link: #66ccff; --ide-acc: #00ffff; --ide-sky: #9cdbff; --ide-warn: #ffd24a; --ide-ok: #00ff88; --ide-bad: #ff8a7a;
  --ide-rail: 264px; --ide-facts: 330px; --ide-bar: 56px;
  overflow-x: hidden;
}
body.ide [data-ide] { box-sizing: border-box; }
body.ide .ide-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  font: 12px/1.2 ui-monospace, Menlo, Consolas, monospace; color: var(--ide-dim); background: var(--ide-panel);
  border: 1px solid var(--ide-line); border-radius: 4px; padding: 6px 9px; min-height: 32px; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
body.ide .ide-btn:hover, body.ide .ide-btn:focus-visible { color: #fff; border-color: var(--ide-sky); }
body.ide .ide-btn.ide-flash { color: var(--ide-ok); border-color: var(--ide-ok); }
body.ide :focus-visible { outline: 2px solid var(--ide-acc); outline-offset: 2px; }
body.ide .ide-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; box-shadow: 0 0 6px currentColor; }
body.ide .ide-cap { margin: 14px 0 6px; font-size: 10px; letter-spacing: .14em; color: var(--ide-dim); text-transform: uppercase; }
body.ide .ide-role { display: inline-block; border: 1px solid; border-radius: 3px; padding: 0 6px; font-size: 11px; margin-right: 6px; }
body.ide .ide-aside { display: inline-block; color: var(--ide-warn); font-size: 11px; }
body.ide kbd { font: 11px ui-monospace, Menlo, monospace; border: 1px solid var(--ide-line); border-bottom-width: 2px; border-radius: 3px; padding: 0 5px; color: #fff; background: #05070b; }
body.ide .ide-hint { font-size: 11px; color: var(--ide-dim); }

/* ---- code: gutter + pre side by side; the pre scrolls sideways inside itself */
/* Flex, not grid: on iPhone Safari the grid let the gutter cover the first characters of every code line. The code
   paints above the gutter, never under it, and nothing indents or shifts the code text. */
body.ide .ide-codewrap { position: relative; display: flex; flex-wrap: wrap; align-items: stretch; margin: 10px 0 16px; width: 100%; min-width: 0; max-width: 100%; }
body.ide .ide-codewrap > pre { flex: 1 1 0; margin: 0; min-width: 0; border-left: 0; position: relative; z-index: 1; padding-left: 12px; text-indent: 0; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body.ide .ide-codewrap > pre > code { margin: 0; padding: 0; text-indent: 0; }
body.ide .ide-gutter {
  white-space: pre; text-align: right; user-select: none; color: #4c5a65; background: #05070b;
  border: 1px solid var(--ide-line); border-right: 1px solid #1c2c3a; padding: 12px 8px 12px 6px;
  font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; min-width: 3ch;
  flex: 0 0 auto; position: relative; z-index: 0; -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
body.ide .ide-head {
  grid-column: 1 / -1; flex: 0 0 100%; box-sizing: border-box; min-width: 0; max-width: 100%; display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  background: linear-gradient(90deg, #0b0e14, #05070b); border: 1px solid var(--ide-line); border-bottom: 0;
  padding: 5px 8px; font-size: 12px;
}
body.ide .ide-headkey { flex: 1 1 200px; min-width: 0; color: var(--ide-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.ide .ide-lineflash { position: absolute; left: 0; right: 0; background: rgba(0, 255, 255, .16); border-left: 2px solid var(--ide-acc); pointer-events: none; animation: ide-fade 2.2s ease-out forwards; }
@keyframes ide-fade { 0%, 60% { opacity: 1 } 100% { opacity: 0 } }

/* ---- sticky top bar: current file and its key */
body.ide #ide-top { cursor: pointer;
  position: sticky; top: var(--ide-hudh, 0px); z-index: 20; display: flex; align-items: center; gap: 8px; min-width: 0;
  background: rgba(0, 0, 0, .92); border-bottom: 1px solid var(--ide-line); padding: 6px 0; font-size: 12px;
  backdrop-filter: blur(4px);
}
body.ide #ide-top b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; color: #fff; }
body.ide .ide-topkey { flex: 1; min-width: 0; color: var(--ide-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.ide .ide-topn { color: var(--ide-acc); }

/* ---- the in-section compact card (phones/tablets) */
body.ide .ide-card { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12px; color: var(--ide-dim); margin: 2px 0 6px; }
body.ide .ide-hl { background: rgba(0, 255, 255, .12); outline: 1px solid var(--ide-acc); transition: background .3s; }

/* ---- Clarity mode: set aside unreached files and copies */
body.ide .ide-fold { display: none; }
body.ide.ide-clarity section.ide-asideable:not(.ide-open) > :not(h2):not(.ide-card):not(.ide-fold) { display: none; }
body.ide.ide-clarity section.ide-asideable { opacity: .7; border-left-style: dashed; }
body.ide.ide-clarity section.ide-asideable:not(.ide-open) .ide-fold {
  display: block; width: 100%; text-align: left; margin: 4px 0 10px; min-height: 44px;
  background: #05070b; color: var(--ide-warn); border: 1px dashed #4c5a65; border-radius: 4px; padding: 8px 10px; font: 12px ui-monospace, Menlo, monospace; cursor: pointer;
}
body.ide.ide-clarity .ide-files a.ide-dim { opacity: .4; text-decoration: line-through; }

/* ---- rails (desktop) */
body.ide .ide-panel {
  display: none; position: fixed; top: var(--ide-hudh, 0px); bottom: 0; z-index: 29; overflow-y: auto; overscroll-behavior: contain;
  background: var(--ide-panel); padding: 10px 14px 20px; font-size: 13px; scrollbar-width: thin; scrollbar-color: #2f343d transparent;
}
body.ide #ide-rail { left: 0; width: var(--ide-rail); border-right: 1px solid var(--ide-line); }
body.ide #ide-facts { right: 0; width: var(--ide-facts); border-left: 1px solid var(--ide-line); box-shadow: inset 3px 0 0 -1px var(--role, #2f343d); }
body.ide .ide-panel::before { content: ''; position: absolute; top: 6px; left: 6px; width: 10px; height: 10px; border-top: 1px solid var(--ide-acc); border-left: 1px solid var(--ide-acc); opacity: .7; }
body.ide.ide-hudmodes .ide-modes { display: none; }
body.ide .ide-modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 6px 0 10px; }
body.ide .ide-mode {
  font: 11px ui-monospace, Menlo, monospace; letter-spacing: .04em; color: var(--ide-dim); background: #05070b;
  border: 1px solid var(--ide-line); border-radius: 4px; min-height: 34px; padding: 4px 2px; cursor: pointer;
}
body.ide .ide-mode:hover { color: #fff; }
body.ide .ide-mode[aria-pressed="true"] { color: #000; background: var(--ide-acc); border-color: var(--ide-acc); box-shadow: 0 0 10px rgba(0, 255, 255, .45); }
body.ide .ide-level { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--ide-acc); letter-spacing: .08em; }
body.ide .ide-xp { flex: 1; height: 4px; background: #05070b; border: 1px solid var(--ide-line); border-radius: 2px; overflow: hidden; }
body.ide .ide-xp i { display: block; height: 100%; background: linear-gradient(90deg, #0066ff, var(--ide-acc)); }
body.ide .ide-files { list-style: none; margin: 0; padding: 0; counter-reset: f; }
body.ide .ide-files li { margin: 0; }
body.ide .ide-files a {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 4px; color: var(--ide-dim);
  text-decoration: none; border: 1px solid transparent; min-height: 32px;
}
body.ide .ide-files a:hover { color: #fff; background: #11161f; }
body.ide .ide-files a.ide-cur { color: #fff; border-color: var(--ide-line); background: #05070b; box-shadow: inset 2px 0 0 var(--ide-acc); }
body.ide .ide-files a.ide-seen .ide-fn::after { content: ' ·'; color: var(--ide-ok); }
body.ide .ide-fn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.ide .ide-ln { color: #4c5a65; font-size: 11px; }
body.ide .ide-secnav { display: flex; gap: 6px; flex-wrap: wrap; }
body.ide .ide-topic { display: block; margin-top: 8px; font-size: 12px; }
body.ide .ide-trail { display: flex; flex-wrap: wrap; gap: 4px; }
body.ide .ide-trail a, body.ide .ide-trail span { font-size: 11px; border: 1px solid var(--ide-line); border-radius: 3px; padding: 2px 6px; text-decoration: none; }
body.ide .ide-trail .ide-here { color: #000; background: var(--ide-acc); border-color: var(--ide-acc); }
body.ide .ide-ft { font-size: 15px; margin: 2px 0 6px; overflow-wrap: anywhere; }
body.ide .ide-syn { font-size: 12px; color: #dfe6f0; border-left: 2px solid var(--role, var(--ide-acc)); padding-left: 8px; margin: 8px 0; }
body.ide .ide-links { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ide-dim); }
body.ide .ide-links a { overflow-wrap: anywhere; }
body.ide .ide-more { color: #4c5a65; font-size: 11px; }
body.ide .ide-key { display: block; font-size: 11px; color: var(--ide-sky); background: #05070b; border: 1px solid var(--ide-line); padding: 6px; overflow-wrap: anywhere; }
body.ide .ide-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
body.ide .ide-miniwrap { position: relative; border: 1px solid var(--ide-line); }
body.ide #ide-mini { display: block; width: 100%; height: 200px; cursor: pointer; }
body.ide .ide-minivp { position: absolute; left: 0; right: 0; border: 1px solid var(--ide-acc); background: rgba(0, 255, 255, .07); pointer-events: none; }

/* ---- bottom bar (phones and tablets): 44px targets */
body.ide #ide-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 4px; padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); background: rgba(5, 7, 11, .96);
  border-top: 1px solid var(--ide-line); max-width: none; margin: 0; border-bottom: 0;
}
body.ide .ide-bb {
  display: flex; align-items: center; justify-content: center; min-height: 44px; min-width: 0; padding: 0 4px;
  font: 13px ui-monospace, Menlo, monospace; color: var(--ide-sky); background: var(--ide-panel); border: 1px solid var(--ide-line);
  border-radius: 6px; text-decoration: none; cursor: pointer;
}
body.ide .ide-bb:active { border-color: var(--ide-acc); color: #fff; }
body.ide .ide-bb.ide-off { opacity: .3; }
body.ide { padding-bottom: calc(var(--ide-bar) + env(safe-area-inset-bottom, 0px)); }
body.ide.ide-bump #ide-top { box-shadow: 0 2px 0 var(--ide-bad); }

/* ---- overlays: help + palette + map + toast */
body.ide #ide-ov { position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, .7); display: flex; align-items: flex-start; justify-content: center; padding: 10vh 12px 12px; }
body.ide .ide-box {
  position: relative; width: min(640px, 100%); max-height: 78vh; overflow: auto; background: var(--ide-panel);
  border: 1px solid var(--ide-line); border-radius: 6px; padding: 12px 14px; box-shadow: 0 0 0 1px #000, 0 0 30px rgba(0, 255, 255, .12);
}
body.ide .ide-box::before, body.ide .ide-box::after { content: ''; position: absolute; width: 12px; height: 12px; border-color: var(--ide-acc); border-style: solid; }
body.ide .ide-box::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
body.ide .ide-box::after { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }
body.ide .ide-keys td { border-bottom: 1px solid #1a1f27; padding: 6px 8px; }
body.ide .ide-pin { width: 100%; box-sizing: border-box; min-height: 44px; font-size: 16px; background: #05070b; border: 1px solid var(--ide-sky); border-radius: 4px; color: #fff; padding: 8px 10px; }
body.ide .ide-pres { list-style: none; margin: 8px 0 0; padding: 0; }
body.ide .ide-pres li { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 0 8px; padding: 7px 8px; border-radius: 4px; cursor: pointer; margin: 0; min-height: 30px; }
body.ide .ide-pres li.on { background: #11161f; box-shadow: inset 2px 0 0 var(--ide-acc); }
body.ide .ide-pk { font-size: 10px; color: var(--ide-dim); text-transform: uppercase; letter-spacing: .08em; padding-top: 2px; }
body.ide .ide-ptt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.ide .ide-ps { grid-column: 2; font-size: 11px; color: var(--ide-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.ide #ide-map { display: none; }
body.ide.ide-mapon #ide-map { display: flex; flex-direction: column; position: fixed; z-index: 50; top: var(--ide-hudh, 0px); bottom: 0; left: var(--ide-rail); right: var(--ide-facts); background: #000; border-left: 1px solid var(--ide-line); }
body.ide .ide-maphead { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--ide-line); font-size: 12px; }
body.ide .ide-maphead b { flex: 1; color: var(--ide-acc); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.ide #ide-map iframe { flex: 1; border: 0; width: 100%; background: #000; }
body.ide #ide-toast {
  position: fixed; left: 50%; bottom: calc(var(--ide-bar) + 14px); transform: translate(-50%, 10px); z-index: 90; opacity: 0; pointer-events: none;
  background: #05070b; color: #fff; border: 1px solid var(--ide-acc); border-radius: 4px; padding: 8px 12px; font-size: 12px; max-width: min(90vw, 560px);
  transition: opacity .2s, transform .2s;
}
body.ide #ide-toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---- wide: three panes, using the whole screen */
@media (min-width: 1200px) {
  body.ide { padding-bottom: 0; }
  body.ide .ide-panel { display: block; }
  body.ide #ide-bar { display: none; }
  body.ide #ide-toast { bottom: 18px; }
  body.ide > header, body.ide > nav, body.ide > main, body.ide > footer {
    max-width: none; margin-left: var(--ide-rail); margin-right: var(--ide-facts); padding-left: 28px; padding-right: 28px;
  }
  body.ide p { max-width: 1100px; }
  body.ide .ide-card { display: none; }
  body.ide main section.file { margin-left: -16px; }
}
@media (min-width: 1700px) { body.ide { --ide-rail: 300px; --ide-facts: 380px; } }

/* ---- narrow: single column, code first under the compact card */
@media (max-width: 1199.98px) {
  body.ide #ide-top b { max-width: 55%; }
}
@media (max-width: 759.98px) {
  body.ide > header, body.ide > nav, body.ide > main, body.ide > footer { padding-left: 12px; padding-right: 12px; }
  body.ide main section.file { display: flex; flex-direction: column; margin-left: -8px; padding-left: 8px; min-width: 0; }
  body.ide main section.file > * { order: 6; min-width: 0; max-width: 100%; }
  body.ide main section.file > h2 { order: 0; }
  body.ide main section.file > .ide-card { order: 1; }
  body.ide main section.file > .ide-fold { order: 2; }
  body.ide main section.file > .ide-codewrap { order: 3; }
  body.ide main section.file > p.syn { order: 4; }
  body.ide main section.file > p.k { order: 5; }
  body.ide .ide-gutter { font-size: 12px; padding-left: 3px; padding-right: 5px; }
  body.ide .ide-codewrap > pre { font-size: 12px; }
  body.ide .ide-codewrap > pre { max-height: 75vh; overflow: auto; }
  body.ide .ide-gutter { max-height: 75vh; overflow: hidden; }
  body.ide .ide-head .ide-btn { min-height: 40px; }
  body.ide #ide-top .ide-topkey { display: none; }
  body.ide dl.v { grid-template-columns: 1fr; }
  body.ide dl.v dt { margin-top: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  body.ide *, body.ide *::before, body.ide *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
