/* ─────────────────────────────────────────────────────────────
   The IDE as a full-window app (laptop and desktop widths).
   Loaded after styles.css on /ide/ only. The phone layout (900px and narrower) is untouched.

   Regions, after VS Code 1.142.0's workbench (docs/reference/vscode.md, section 1):
     title bar · run bar
     activity bar (48px) │ side bar (resizable, hideable) │ editor over terminal panel
     status bar (22px)
   Colours still come from the tokens on .ide in styles.css, so a new theme (#4) is one block there.
   ───────────────────────────────────────────────────────────── */

/* Views switcher and side bar edge: desktop only */
.ide__activity,
.ide__sash { display: none; }

@media (min-width: 901px) {
  /* The page stops being a page: the IDE fills the window under the site nav, nothing scrolls. */
  html:has(body.page--ide-app) { overflow: hidden; }
  .page--ide-app .page-head--ide,
  .page--ide-app #site-footer,
  .page--ide-app .story-link { display: none; }
  .page--ide-app #main > .section { padding: 0; }

  .page--ide-app .ide {
    position: fixed;
    top: var(--ide-top, 72px);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    height: auto;
    max-height: none;
    border: 0;
    border-top: 1px solid var(--border-strong);
    border-radius: 0;
    box-shadow: none;
    /* One column as wide as the window: a long title (a sketch's path) shortens instead of widening every row */
    grid-template-columns: minmax(0, 1fr);
  }
  /* Full window still covers the site nav too */
  .page--ide-app .ide.is-full { top: 0; z-index: 55; border-top: 0; }

  /* Title bar: one compact row, no pretend window buttons */
  .page--ide-app .ide__bar { flex-wrap: nowrap; min-height: 35px; padding: 4px 10px 4px 14px; }
  .page--ide-app .ide__dots { display: none; }
  .page--ide-app .ide__conn { flex-wrap: nowrap; }

  /* Activity bar │ side bar │ edge │ work */
  .page--ide-app .ide__main { grid-template-columns: 48px auto auto minmax(0, 1fr); }
  .page--ide-app .ide__side { width: var(--side-w, 260px); border-right: 0; }
  .page--ide-app .ide.side-hidden .ide__side,
  .page--ide-app .ide.side-hidden .ide__sash { display: none; }
  .page--ide-app .ide__sidetabs { display: none; }

  .ide__activity {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding-top: 4px;
    background: rgba(0, 0, 0, 0.4);
    border-right: 1px solid var(--border);
  }
  .ide__act {
    position: relative;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
  }
  .ide__act svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
  .ide__act:hover,
  .ide__act:focus-visible { color: var(--text); outline: 0; }
  .ide__act[aria-selected="true"] { color: var(--accent); }
  .ide__act[aria-selected="true"]::before {
    content: "";
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: var(--accent);
    box-shadow: var(--glow);
  }
  .ide.side-hidden .ide__act[aria-selected="true"]::before { display: none; }

  /* The side bar's edge: a 4px hit area with a 1px line, like the terminal splitter */
  .ide__sash {
    display: block;
    position: relative;
    width: 4px;
    margin-left: -1px;
    cursor: col-resize;
    touch-action: none;
    z-index: 3;
  }
  .ide__sash::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 1px;
    width: 1px;
    background: var(--border);
  }
  .ide__sash:hover::before,
  .ide__sash:focus-visible::before,
  .ide__sash.is-dragging::before { left: 0; width: 4px; background: var(--accent); box-shadow: var(--glow); }
  .ide__sash:focus-visible { outline: 0; }
  html.ide-resizing-x { cursor: col-resize; user-select: none; }

  /* Status bar: 22px, 12px text */
  .page--ide-app .ide__statusbar { flex-wrap: nowrap; min-height: 22px; padding: 0 10px; font-size: 12px; line-height: 22px; white-space: nowrap; overflow: hidden; }
}

/* The story behind the IDE, as one quiet line on the empty editor (the card is phone-only now) */
.ide__story { font-size: 0.8rem; }
@media (max-width: 900px) {
  .ide__story { display: none; }
}

/* ── The command palette (site/js/commands.js), mounted inside .ide so it uses the IDE's colours ── */
.palette {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.35);
}
.palette[hidden] { display: none; }
.palette__box {
  position: absolute;
  top: calc(var(--ide-top, 72px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: min(620px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-2);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6), var(--glow);
  overflow: hidden;
  font-family: var(--font-mono);
}
.ide.is-full .palette__box { top: 8px; }
.palette__input {
  margin: 6px;
  padding: 7px 10px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: 0.9rem var(--font-mono);
  outline: 0;
}
.palette__list { list-style: none; margin: 0; padding: 0 0 6px; max-height: min(50vh, 440px); overflow: auto; overscroll-behavior: contain; }
.palette__item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 24px;
  padding: 3px 12px;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
}
.palette__item[aria-selected="true"] { background: var(--surface-hover); box-shadow: inset 2px 0 0 var(--accent); }
.palette__item.is-hint { color: var(--muted); cursor: default; }
.palette__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette__label mark { background: none; color: var(--accent); font-weight: 600; }
.palette__detail { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }
.palette__key {
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--muted);
  font: 0.72rem var(--font-mono);
  white-space: nowrap;
}

/* The title bar's search box (VS Code's command centre) */
.ide__command {
  display: flex;
  align-items: center;
  gap: 8px;
  width: clamp(200px, 32vw, 440px);
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--muted);
  font: 0.78rem var(--font-mono);
  cursor: pointer;
}
.ide__command:hover,
.ide__command:focus-visible { color: var(--text); border-color: var(--accent); outline: 0; }
.ide__command svg { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; }
.ide__command span { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ide__command kbd { font: 0.7rem var(--font-mono); opacity: 0.8; }
@media (max-width: 900px) {
  .ide__command { width: 100%; order: 5; }
}

/* The cursor position in the status bar opens Go to line */
.ide__sb-btn { padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }
.ide__sb-btn:hover,
.ide__sb-btn:focus-visible { color: var(--text); outline: 0; text-decoration: underline; }

/* ── The panel's tabs (Terminal, Plotter) and the Plotter (site/js/plotter.js) ── */
.ide__ptabs { display: flex; gap: 2px; margin-right: 6px; }
.ide__ptabs button {
  padding: 3px 8px;
  border: 0;
  border-bottom: 1px solid transparent;
  background: none;
  color: var(--muted);
  font: 0.72rem var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}
.ide__ptabs button:hover,
.ide__ptabs button:focus-visible { color: var(--text); outline: 0; }
.ide__ptabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); text-shadow: var(--glow); }

.ide__term { position: relative; }
.plot {
  position: absolute;
  top: var(--plot-top, 33px);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  background: #020504;
}
.plot[hidden] { display: none; }
.plot__legend { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 4px 12px 0; min-height: 22px; }
.plot__key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font: 0.75rem var(--font-mono);
  cursor: pointer;
}
.plot__key::before { content: ""; width: 12px; height: 3px; border-radius: 2px; background: var(--key); }
.plot__key[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; }
.plot__key[aria-pressed="false"]::before { opacity: 0.35; }
/* The canvas is absolutely placed in its area, so setting its pixel size can never change the layout */
.plot__area { position: relative; flex: 1; min-height: 0; }
.plot__canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.plot__empty {
  position: absolute;
  inset: 26px 16px auto;
  margin: 0;
  color: var(--muted);
  font: 0.78rem/1.6 var(--font-mono);
  pointer-events: none;
}
.plot__empty[hidden] { display: none; }
.plot__empty code { color: var(--accent); }
.plot.is-paused .plot__canvas { opacity: 0.6; }
.plot__win { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font: 0.72rem var(--font-mono); }
.plot__win[hidden] { display: none; }
.plot__win select {
  padding: 2px 4px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: #020504;
  color: var(--text);
  font: inherit;
}

/* Fresh start: a tick box beside Run */
.ide__fresh { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font: 0.75rem var(--font-mono); cursor: pointer; white-space: nowrap; }
.ide__fresh:hover { color: var(--text); }
.ide__fresh input { accent-color: var(--accent); margin: 0; }

/* Serial monitor controls in the title bar */
.ide__monitor { gap: 8px; flex-wrap: wrap; }
.ide__monitor strong { white-space: nowrap; }
.ide__mon-field { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font: 0.75rem var(--font-mono); white-space: nowrap; }
.ide__mon-field select { padding: 2px 4px; border: 1px solid var(--border-strong); border-radius: 4px; background: rgba(0, 0, 0, 0.3); color: var(--text); font: inherit; }
.ide__mon-field input { accent-color: var(--accent); margin: 0; }

/* Upload a compiled sketch: the dialog's tick box */
.ide-flash__check { display: flex; align-items: flex-start; gap: 8px; color: var(--muted); font-size: 0.85rem; line-height: 1.4; }
.ide-flash__check input { accent-color: var(--accent); margin-top: 3px; }

/* Title bar on narrower laptops: buttons stay on one line; the search box and folder name give way first */
@media (min-width: 901px) {
  .page--ide-app .ide__bar .btn,
  .page--ide-app .ide__bar .link-btn,
  .page--ide-app .ide__full { white-space: nowrap; }
  .page--ide-app .ide__command { width: auto; flex: 1 1 200px; min-width: 120px; max-width: 440px; }
  /* A sketch's path (~/sketches/Name/Name.ino) can be long: it shortens with an ellipsis instead of pushing the buttons out */
  .page--ide-app .ide__title { flex: 1 1 0; min-width: 0; max-width: 34ch; }
}
@media (min-width: 901px) and (max-width: 1180px) {
  .page--ide-app .ide__title { display: none; }
  .page--ide-app .ide__full-label { display: none; }
  .page--ide-app .ide__command kbd { display: none; }
}

/* Arduino sketches: the Sketch view in the side bar */
.ide__sk { overflow: auto; }
.ide__sk-row { display: flex; align-items: center; gap: 6px; }
.ide__sk-row select { flex: 1; min-width: 0; }
.ide__sk-actions { gap: 14px; font-size: 0.8rem; }
.ide__sk select { padding: 5px 6px; border: 1px solid var(--border-strong); border-radius: 4px; background: rgba(0, 0, 0, 0.3); color: var(--text); font: 0.8rem var(--font-mono); max-width: 100%; }
.ide__sk .icon-mini { width: 32px; height: 32px; background: transparent; border-color: var(--border-strong); }
.ide__sk-files { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.ide__sk-file { width: 100%; text-align: left; padding: 5px 8px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font: 0.8rem var(--font-mono); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ide__sk-file:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.ide__sk-file.is-current { color: var(--accent); background: rgba(255, 255, 255, 0.07); }
.ide__sk-head { margin: 6px 0 0; font: 600 0.7rem var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.ide__sk-field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; color: var(--muted); font: 0.75rem var(--font-mono); }
.ide__sk-field select { width: 100%; }
#ide-sk-opts { display: grid; gap: 10px; }
#ide-sk-opts:empty { display: none; }
#ide-sk-detect { justify-self: start; align-self: flex-start; }
.ide__sk-note { margin: 0; padding: 8px 10px; border-left: 2px solid var(--warn, #ffcb6b); background: rgba(255, 203, 107, 0.07); color: var(--text); font-size: 0.8rem; line-height: 1.45; }
.ide__sk-fqbn { margin: 0; font-size: 0.72rem; color: var(--muted); overflow-wrap: anywhere; }
.ide__sk-help { margin: 0; font-size: 0.78rem; line-height: 1.45; color: var(--muted); }
.ide.is-building #ide-sk-verify, .ide.is-building #ide-sk-upload { opacity: 0.6; pointer-events: none; }

/* Build output: links to a tab and line, warnings, and the size bars */
.ide .console__link { color: inherit; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.ide .console__link:hover { color: var(--accent); }
.ide .console__warn { color: #ffcb6b; }
.build-size { display: grid; gap: 4px; margin: 4px 0 6px; max-width: 560px; font: 0.75rem var(--font-mono); }
.build-size__row { display: grid; grid-template-columns: 7ch minmax(60px, 1fr) auto; align-items: center; gap: 10px; color: var(--muted); }
.build-size__bar { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.build-size__bar i { display: block; height: 100%; background: var(--accent); }
.build-size__row.is-warn .build-size__bar i { background: #ffcb6b; }
.build-size__row.is-over .build-size__bar i { background: #ff5f57; }
.build-size__num { white-space: nowrap; }
.build-size__warn { color: #ffcb6b; white-space: normal; }
@media (max-width: 600px) { .build-size__row { grid-template-columns: 7ch minmax(40px, 1fr); } .build-size__num { grid-column: 1 / -1; } }
