/* style.css — the page is a stage for one object; everything else stays out of
   the way. The shell uses the generated image at its native 881x1785 geometry,
   so every hotspot can be placed as a percentage and stay aligned at any size. */

:root {
  --shell-w: 881;
  --shell-h: 1785;
  --ink: #20221f;
  --paper: #f3f0e7;
  --paper-deep: #e7e1d3;
  --lcd: #d9e8df;
  --rule: #c8c0ae;
  --orange: #d96029;
  --green: #2f7663;
  color-scheme: light dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font: 15px/1.5 "Avenir Next", Avenir, "Helvetica Neue", sans-serif;
  background:
    linear-gradient(rgba(65, 68, 61, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(65, 68, 61, .035) 1px, transparent 1px),
    #e9eaec;
  background-size: 24px 24px;
  color: var(--ink);
}

@media (prefers-color-scheme: dark) {
  html, body { background-color: #17181b; color: #d8d9dd; }
}

main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 18px 48px;
  gap: 24px;
}

[hidden] { display: none !important; }

#workspace {
  width: min(100%, 1120px);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(24px, 5vw, 64px);
}

#calculator-column {
  display: flex;
  flex: 0 1 392px;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#stage {
  width: min(392px, 86vw, calc((100vh - 118px) * 881 / 1785));
}

#shell {
  position: relative;
  width: 100%;
  aspect-ratio: 881 / 1785;
  background: url('../assets/fx-50fh-ii-generated-transparent.png?v=9206630d') center / 100% 100% no-repeat;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .28));
  touch-action: manipulation;
  user-select: none;
}

#lcd {
  position: absolute;
  display: block;
  border-radius: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Transparent hotspots sit over the source artwork. Keep them visually inert:
   the attached faceplate — including every key colour — must remain untouched. */
.key {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 34% / 40%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.key::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0;
  background: linear-gradient(rgba(255,255,255,.08), rgba(15,18,18,.24));
  box-shadow: inset 0 2px 4px rgba(0,0,0,.34), 0 1px 0 rgba(255,255,255,.16);
  transform: translateY(0) scale(1);
  transition: opacity 55ms ease-out, transform 75ms ease-out;
  pointer-events: none;
}

.key.down::after, .key:active::after {
  opacity: 1;
  transform: translateY(1px) scale(.975);
}

.key:focus-visible {
  outline: 2px solid #2f7fe0;
  outline-offset: 1px;
}

/* Mode strip — the machine shows the mode only inside its menu, so the page
   keeps a small, clickable reminder and a CMPLX cheat line. */
.mode-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 2px;
}
#mode-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 12px;
  border: 1px solid rgba(47, 118, 99, .32);
  border-radius: 999px;
  background: rgba(255, 255, 255, .72);
  color: #2b4f45;
  font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .08em;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}
#mode-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2f7663;
  box-shadow: 0 0 0 3px rgba(47, 118, 99, .16);
}
#mode-chip:hover { border-color: #2f7663; background: #eef6f0; transform: translateY(-1px); }
.mode-tip {
  color: #6f6d62;
  font: 600 10.5px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .02em;
}

/* Toast for keys the current mode refuses. */
.key-hint {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 60;
  max-width: min(92vw, 470px);
  padding: 11px 16px;
  border-radius: 12px;
  background: #1e2a25;
  color: #f7f4ea;
  font: 600 13px/1.45 "Avenir Next", Avenir, "Helvetica Neue", sans-serif;
  text-align: center;
  box-shadow: 0 18px 40px -18px rgba(20, 26, 23, .8);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 10px);
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms;
  pointer-events: none;
}
.key-hint.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

@keyframes key-attention {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(255, 190, 130, .35), 0 0 0 2px rgba(217, 96, 41, .35); }
  50% { box-shadow: inset 0 0 0 3px rgba(255, 200, 150, 1), 0 0 0 6px rgba(217, 96, 41, .55); }
}
.key.attention::after {
  opacity: 1;
  background: none;
  animation: key-attention 700ms ease-in-out 2;
}

#utility-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

#help-toggle, #studio-toggle {
  min-height: 36px;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 150ms ease, transform 150ms ease;
}
#help-toggle { padding: 7px 6px; opacity: .55; text-decoration: underline; }
#studio-toggle {
  padding: 7px 12px 6px;
  border: 1px solid rgba(47, 118, 99, .35);
  border-radius: 999px;
  background: rgba(217, 232, 223, .72);
  color: #255d50;
  font-weight: 700;
  letter-spacing: .02em;
}
#help-toggle:hover, #studio-toggle:hover { opacity: 1; transform: translateY(-1px); }

/* Program Studio — a warm, high-contrast workbench beside the machine. */
#studio {
  --st-ink: #1d2521;
  --st-muted: #6d6a5f;
  --st-line: #e0d8c6;
  --st-line-strong: #cdc3ac;
  --st-card: #fffdf8;
  --st-sunk: #f4efe3;
  --st-accent: #2f7663;
  --st-accent-soft: #e3efe8;
  --st-warn: #c0562f;
  --st-radius: 16px;

  position: relative;
  flex: 0 1 640px;
  width: min(100%, 640px);
  margin-top: 12px;
  padding: 28px 28px 24px;
  overflow: hidden;
  border: 1px solid var(--st-line-strong);
  border-radius: var(--st-radius);
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(47, 118, 99, .07), transparent 55%),
    linear-gradient(180deg, #fdfbf5, #f7f2e6 60%, #f4eee0);
  color: var(--st-ink);
  box-shadow:
    0 1px 0 #fff inset,
    0 2px 4px rgba(48, 42, 31, .06),
    0 26px 60px -32px rgba(42, 39, 31, .45);
  animation: studio-arrive 280ms cubic-bezier(.2,.8,.2,1) both;
}

#studio::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--st-accent), #7aa88f 55%, var(--orange));
}

@keyframes studio-arrive {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
#studio.studio-leave { animation: studio-leave 180ms cubic-bezier(.4,0,1,1) both; }
@keyframes studio-leave {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(6px) scale(.995); }
}

/* ---- header ---------------------------------------------------------------- */
.studio-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin: 2px 0 22px;
}
.studio-kicker {
  margin: 0 0 8px;
  color: var(--st-accent);
  font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .16em;
}
.studio-head h1 {
  margin: 0;
  color: var(--st-ink);
  font: 700 32px/1 "American Typewriter", Rockwell, Georgia, serif;
  letter-spacing: -.03em;
}
.studio-intro {
  margin: 10px 0 0;
  max-width: 34ch;
  color: var(--st-muted);
  font-size: 13px;
  line-height: 1.5;
}
.studio-head-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex: none;
}
.save-state {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--st-accent-soft);
  color: #2a5f50;
  font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.save-state::before {
  content: "";
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: #3f8b6f;
  box-shadow: 0 0 0 3px rgba(63, 139, 111, .16);
}
.studio-badge {
  padding: 4px 9px;
  border: 1px solid var(--st-line);
  border-radius: 999px;
  background: rgba(255, 253, 248, .7);
  color: var(--st-muted);
  font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---- segmented tabs -------------------------------------------------------- */
.studio-view-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0 0 18px;
  padding: 4px;
  border: 1px solid var(--st-line);
  border-radius: 12px;
  background: var(--st-sunk);
}
.studio-view-tabs button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--st-muted);
  font: 700 13px/1 "Avenir Next", Avenir, "Helvetica Neue", sans-serif;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
}
.studio-view-tabs button:hover { color: var(--st-ink); background: rgba(255, 253, 248, .7); }
.studio-view-tabs button[aria-selected="true"] {
  background: var(--st-card);
  color: var(--st-ink);
  box-shadow: 0 1px 2px rgba(38, 44, 40, .12), 0 6px 16px -12px rgba(38, 44, 40, .5);
}
.studio-view-tabs span {
  min-width: 20px;
  padding: 3px 6px;
  border-radius: 999px;
  background: var(--st-accent-soft);
  color: #2a5f50;
  font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.studio-view-tabs button[aria-selected="true"] span { background: var(--st-accent); color: #fff; }

/* ---- device toolbar -------------------------------------------------------- */
.studio-management {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  padding: 0 2px;
}
.studio-management > span {
  color: var(--st-muted);
  font: 800 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.studio-management > div { display: flex; flex-wrap: wrap; gap: 6px; }
.studio-management button,
.copy-tools button,
.studio-primary-actions button,
.pack-card button,
.program-card button,
.library-filters button {
  border: 1px solid var(--st-line-strong);
  border-radius: 9px;
  background: var(--st-card);
  color: #333c37;
  font: 700 12px/1 "Avenir Next", Avenir, "Helvetica Neue", sans-serif;
  cursor: pointer;
  transition: transform 110ms ease, box-shadow 130ms ease, border-color 130ms ease, background 130ms ease;
}
.studio-management button { min-height: 30px; padding: 0 11px; font-size: 11px; color: var(--st-muted); }
.studio-management button:hover,
.copy-tools button:hover,
.studio-primary-actions button:hover,
.pack-card button:hover,
.program-card button:hover {
  border-color: var(--st-accent);
  color: var(--st-accent);
  transform: translateY(-1px);
}
.studio-management button:focus-visible,
.copy-tools button:focus-visible,
.studio-primary-actions button:focus-visible,
.pack-card button:focus-visible,
.program-card button:focus-visible,
.studio-view-tabs button:focus-visible,
.program-slots button:focus-visible,
.library-filters button:focus-visible,
.library-controls input:focus-visible,
.library-controls select:focus-visible {
  outline: 2px solid var(--st-accent);
  outline-offset: 2px;
}
button:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ---- slot cards ------------------------------------------------------------ */
.program-slots {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 16px;
}
.program-slots button {
  position: relative;
  display: block;
  padding: 12px 12px 10px;
  border: 1px solid var(--st-line);
  border-radius: 12px;
  background: var(--st-card);
  text-align: left;
  cursor: pointer;
  transition: border-color 130ms ease, box-shadow 130ms ease, transform 130ms ease, background 130ms ease;
}
.program-slots button:hover { transform: translateY(-1px); border-color: var(--st-line-strong); }
.program-slots b {
  display: block;
  color: var(--st-ink);
  font: 800 15px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .02em;
}
.program-slots span {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  color: var(--st-muted);
  font: 400 10.5px/1.25 "Avenir Next", Avenir, sans-serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.program-slots button[aria-selected="true"] {
  border-color: var(--st-accent);
  background: var(--st-accent-soft);
  box-shadow: 0 0 0 1px var(--st-accent) inset;
}
.program-slots button[aria-selected="true"] b { color: #23584a; }
.program-slots button[aria-selected="true"] span { color: #3d6a5c; }

/* ---- editor ---------------------------------------------------------------- */
.studio-editor-card {
  padding: 16px;
  border: 1px solid var(--st-line);
  border-radius: 14px;
  background: var(--st-card);
  box-shadow: 0 1px 2px rgba(38, 44, 40, .05);
}
.editor-topline {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}
.editor-topline label,
.editor-label {
  display: block;
  color: var(--st-muted);
  font: 800 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.editor-topline label { display: flex; flex-direction: column; gap: 6px; }
.copy-tools { display: flex; gap: 6px; }
.copy-tools button { min-height: 32px; padding: 0 12px; font-size: 11.5px; }

#studio-mode,
.library-controls input,
.library-controls select {
  border: 1px solid var(--st-line-strong);
  border-radius: 9px;
  background: #fffefb;
  color: var(--st-ink);
  font: 700 12.5px/1 "Avenir Next", Avenir, sans-serif;
  transition: border-color 130ms ease, box-shadow 130ms ease;
}
#studio-mode { min-height: 32px; padding: 0 30px 0 10px; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #6d6a5f 50%), linear-gradient(135deg, #6d6a5f 50%, transparent 50%);
  background-position: calc(100% - 14px) 13px, calc(100% - 9px) 13px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.editor-label { margin: 16px 0 7px; }

#program-source {
  display: block;
  width: 100%;
  min-height: 232px;
  padding: 14px;
  resize: vertical;
  border: 1px solid var(--st-line);
  border-radius: 10px;
  background:
    repeating-linear-gradient(0deg, transparent 0, transparent 21px, rgba(64, 76, 68, .06) 21px, rgba(64, 76, 68, .06) 22px),
    #fbfaf4;
  color: #22302a;
  font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
  tab-size: 2;
  transition: border-color 130ms ease, box-shadow 130ms ease;
}
#program-source::placeholder { color: #a9a496; }
#program-source.invalid { border-color: var(--st-warn); box-shadow: 0 0 0 3px rgba(192, 86, 47, .1); }

.editor-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--st-muted);
  font: 600 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#program-feedback.error { color: var(--st-warn); }
#program-bytes {
  flex: none;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--st-sunk);
  color: #5c5a50;
  font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.byte-track { height: 6px; margin-top: 8px; overflow: hidden; border-radius: 6px; background: #e7e0d1; }
.byte-track i { display: block; width: 0; height: 100%; border-radius: 6px; background: var(--st-accent); transition: width 180ms ease, background 180ms ease; }
.byte-track i.warning { background: var(--st-warn); }

.studio-primary-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.studio-primary-actions button { min-height: 38px; padding: 0 14px; }
.studio-primary-actions .run-program {
  border-color: #24564a;
  background: linear-gradient(180deg, #357b67, #2b6a58);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .18) inset, 0 8px 18px -12px rgba(36, 86, 74, .8);
}
.studio-primary-actions .run-program:hover { color: #fff; background: linear-gradient(180deg, #3b8771, #2e705d); }
.studio-primary-actions .danger-link {
  margin-left: auto;
  border-color: transparent;
  background: transparent;
  color: #a4492a;
}
.studio-primary-actions .danger-link:hover { color: #8c3a1f; border-color: transparent; background: rgba(164, 73, 42, .08); }

/* ---- command shelf --------------------------------------------------------- */
.command-drawer {
  margin-top: 16px;
  padding: 14px 16px 16px;
  border: 1px solid var(--st-line);
  border-radius: 14px;
  background: rgba(255, 253, 248, .72);
}
.drawer-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.drawer-heading h2 {
  margin: 0;
  color: var(--st-ink);
  font: 700 14px/1.2 "American Typewriter", Rockwell, Georgia, serif;
  letter-spacing: -.01em;
}
.drawer-heading span {
  color: var(--st-muted);
  font: 700 9.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.command-group {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: start;
  gap: 10px;
  padding: 6px 0;
}
.command-group + .command-group { border-top: 1px dashed var(--st-line); }
.command-group > span {
  padding-top: 6px;
  color: var(--st-accent);
  font: 800 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.command-buttons { display: flex; flex-wrap: wrap; gap: 5px; }
.command-buttons button {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--st-line);
  border-radius: 7px;
  background: var(--st-card);
  color: #3a433d;
  font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}
.command-buttons button:hover { border-color: var(--st-accent); background: var(--st-accent-soft); color: #23584a; }

.studio-footnote {
  margin: 14px 2px 0;
  color: var(--st-muted);
  font-size: 11px;
  line-height: 1.55;
}
.studio-footnote b { color: #4c5a52; }

/* ---- library --------------------------------------------------------------- */
.program-library { animation: view-arrive 210ms cubic-bezier(.2,.8,.2,1) both; }
@keyframes view-arrive { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.library-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--st-line);
}
.library-eyebrow {
  margin: 0 0 8px;
  color: var(--orange);
  font: 800 9.5px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .14em;
}
.library-head h2 {
  margin: 0;
  font: 700 27px/1.05 "American Typewriter", Rockwell, Georgia, serif;
  letter-spacing: -.03em;
}
.library-head p:not(.library-eyebrow) {
  max-width: 46ch;
  margin: 9px 0 0;
  color: var(--st-muted);
  font-size: 12.5px;
  line-height: 1.5;
}
.library-pdf-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 7px 12px;
  border: 1px solid var(--st-line-strong);
  border-radius: 999px;
  background: var(--st-card);
  color: #34544a;
  font: 700 11px/1 "Avenir Next", Avenir, sans-serif;
  text-decoration: none;
  transition: border-color 130ms ease, background 130ms ease, transform 130ms ease;
}
.library-pdf-link::before { content: "↓"; font-size: 12px; }
.library-pdf-link:hover { border-color: var(--st-accent); background: var(--st-accent-soft); transform: translateY(-1px); }
.library-memory { text-align: right; color: #4d5f57; font: 800 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.library-memory > div { width: 150px; height: 7px; margin-top: 8px; margin-left: auto; overflow: hidden; border-radius: 6px; background: #e4ddce; }
.library-memory i { display: block; width: 0; height: 100%; background: var(--st-accent); transition: width 180ms ease-out, background 180ms ease-out; }
.library-memory i.warning { background: var(--orange); }

.library-controls {
  display: grid;
  grid-template-columns: 1fr 132px;
  gap: 10px;
  margin-top: 16px;
}
.library-controls label > span {
  display: block;
  margin-bottom: 6px;
  color: var(--st-muted);
  font: 800 9.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.library-controls input,
.library-controls select { width: 100%; min-height: 40px; padding: 0 12px; }
.library-controls input { background-image: none; }
.library-controls input::placeholder { color: #a8a294; }
.library-controls input:focus,
.library-controls select:focus { border-color: var(--st-accent); box-shadow: 0 0 0 3px rgba(47, 118, 99, .14); outline: none; }
.library-controls select { appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #6d6a5f 50%), linear-gradient(135deg, #6d6a5f 50%, transparent 50%);
  background-position: calc(100% - 16px) 18px, calc(100% - 11px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.library-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.library-filters button {
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: transparent;
  color: var(--st-muted);
  font-size: 11.5px;
}
.library-filters button:hover { border-color: var(--st-accent); color: var(--st-accent); }
.library-filters button[aria-pressed="true"] {
  border-color: #3b5149;
  background: #274f43;
  color: #fff;
  box-shadow: none;
}
.library-status {
  display: block;
  min-height: 20px;
  margin-top: 10px;
  color: #5b5a50;
  font: 600 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---- packs ----------------------------------------------------------------- */
.pack-shelf { margin-top: 22px; }
.program-packs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
  padding: 2px;
}
.pack-card {
  display: flex;
  flex-direction: column;
  padding: 14px;
  border: 1px solid var(--st-line);
  border-radius: 14px;
  background: var(--st-card);
  scroll-snap-align: start;
  box-shadow: 0 1px 2px rgba(38, 44, 40, .04);
  transition: border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}
.pack-card:hover { border-color: var(--st-line-strong); transform: translateY(-2px); box-shadow: 0 14px 30px -22px rgba(38, 44, 40, .55); }
.pack-card h3 { margin: 0; font: 700 15px/1.2 "American Typewriter", Rockwell, Georgia, serif; letter-spacing: -.01em; }
.pack-card p { min-height: 32px; margin: 7px 0 10px; color: var(--st-muted); font-size: 11px; line-height: 1.45; }
.pack-slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.pack-slots span {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 4px;
  border: 1px solid var(--st-line);
  border-radius: 6px;
  background: var(--st-sunk);
  text-align: center;
}
.pack-slots b {
  color: #6f6a5c;
  font: 800 8.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .06em;
}
.pack-slots i {
  color: #2a4f43;
  font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  font-style: normal;
}
.pack-card footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 12px; }
.pack-card footer span { color: #7a4b35; font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.pack-card button { min-height: 34px; padding: 0 12px; }
.pack-card button.confirming,
.program-card button.confirming { border-color: #7f321f; background: #a84c31; color: #fff; }

/* ---- program cards --------------------------------------------------------- */
.library-results-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
}
.library-results-heading h2 { margin: 0; font: 700 16px/1.2 "American Typewriter", Rockwell, Georgia, serif; }
.library-results-heading output {
  color: var(--st-muted);
  font: 800 9.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.program-library-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.program-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 15px 15px 14px 18px;
  overflow: hidden;
  border: 1px solid var(--st-line);
  border-radius: 14px;
  background: var(--st-card);
  box-shadow: 0 1px 2px rgba(38, 44, 40, .04);
  transition: border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}
.program-card:hover { border-color: var(--st-line-strong); transform: translateY(-2px); box-shadow: 0 16px 32px -24px rgba(38, 44, 40, .6); }
.program-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--card-accent, var(--st-accent)); }
.program-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.program-id {
  display: block;
  color: var(--card-accent, var(--st-accent));
  font: 900 9.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.program-card h3 { margin: 6px 0 0; font: 700 16px/1.15 "American Typewriter", Rockwell, Georgia, serif; letter-spacing: -.02em; }
.program-bytes { flex: none; padding: 5px 7px; border: 1px solid var(--st-line-strong); border-radius: 999px; color: #6c4939; font: 800 9.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.program-summary { min-height: 33px; margin: 10px 0 6px; color: #5f5d52; font-size: 12px; line-height: 1.5; }
.program-card details { margin-top: auto; border-top: 1px dashed var(--st-line); }
.program-card summary { padding: 10px 0 8px; color: #4e554f; font: 700 10.5px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; cursor: pointer; list-style: none; }
.program-card summary::-webkit-details-marker { display: none; }
.program-card summary::before { content: "▸ "; color: var(--card-accent, var(--st-accent)); }
.program-card details[open] summary::before { content: "▾ "; }
.program-details-content {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows 200ms ease-out, opacity 160ms ease-out;
}
.program-details-content > div { overflow: hidden; }
.program-card details[open] .program-details-content { grid-template-rows: 1fr; opacity: 1; }
.program-card dl { margin: 4px 0 10px; font-size: 10.5px; line-height: 1.5; }
.program-card dt { margin-top: 8px; color: var(--card-accent, #8a4e36); font-weight: 800; text-transform: uppercase; letter-spacing: .04em; font-size: 9px; }
.program-card dd { margin: 3px 0 0; color: #5f5d55; white-space: pre-wrap; }
.program-card pre {
  max-height: 150px;
  margin: 8px 0;
  padding: 10px;
  overflow: auto;
  border: 1px solid #d8ded7;
  border-radius: 8px;
  background: #f3f7f2;
  color: #27312c;
  font: 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}
.program-card button { width: 100%; min-height: 38px; margin-top: 4px; }
.program-card button:not(:disabled) { border-color: var(--st-accent); background: var(--st-accent-soft); color: #23584a; }
.program-card button:not(:disabled):hover { background: #d5e8dd; }
.library-empty { padding: 34px 12px; border: 1px dashed var(--st-line-strong); border-radius: 14px; text-align: center; color: var(--st-muted); font-size: 12px; }

#help {
  max-width: 620px;
  font-size: 14px;
  line-height: 1.65;
}
#help h1 { font-size: 18px; margin: 0 0 .4em; }
#help h2 { font-size: 15px; margin: 1.4em 0 .3em; }
#help table { border-collapse: collapse; margin: .4em 0 1em; }
#help td { padding: 1px 14px 1px 0; vertical-align: top; }
#help code {
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(128, 128, 128, .16);
  padding: 1px 5px;
  border-radius: 4px;
}
#help ul { padding-left: 1.1em; }
#help li { margin: .3em 0; }
#help .fine { opacity: .65; font-size: 13px; margin-top: 1.4em; }

@media (max-width: 820px) {
  #workspace { flex-direction: column; align-items: center; }
  #calculator-column { flex-basis: auto; width: 100%; }
  #studio { flex: none; margin-top: 0; width: 100%; max-width: 720px; }
}

@media (max-width: 520px) {
  main { padding-inline: 10px; }
  #studio { padding: 22px 16px 18px; border-radius: 14px; }
  .studio-head { gap: 10px; }
  .studio-head h1 { font-size: 25px; }
  .studio-intro { font-size: 12px; }
  .program-slots { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .studio-management { flex-direction: column; align-items: stretch; gap: 8px; }
  .studio-management > span { text-align: left; }
  .studio-management button { flex: 1; }
  .studio-head-meta { align-items: flex-end; }
  .studio-badge { display: none; }
  .studio-primary-actions .danger-link { margin-left: 0; }
  .command-group { grid-template-columns: 1fr; gap: 4px; }
  .command-group > span { padding-top: 0; }
  .library-head { grid-template-columns: 1fr; gap: 12px; align-items: start; }
  .library-memory { text-align: left; }
  .library-memory > div { margin-left: 0; width: 100%; }
  .library-controls { grid-template-columns: 1fr 104px; }
  .program-library-grid { grid-template-columns: 1fr; }
  .program-summary { min-height: 0; }
  .program-packs { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  #studio, #studio.studio-leave, #studio-editor-view, .program-library { animation: none; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .001ms !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
