:root {
  --bg: #0f1420;
  --panel: #182032;
  --border: #2a3550;
  --text: #e6e9f0;
  --muted: #8b95ab;
  --accent: #5fd0f0;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

header, main {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

h1 { margin: 0.5em 0 0; font-size: 1.6rem; }
h2 { font-size: 1.05rem; color: var(--muted); margin: 1em 0 0.5em; }
.sub { color: var(--muted); margin: 0.25em 0 0; }
a { color: var(--accent); text-underline-offset: 3px; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.site-nav { display: flex; align-items: center; gap: 24px; min-height: 52px; font-size: .9rem; }
.site-brand { color: var(--text); font-size: 1.25rem; font-weight: 750; line-height: 1.15; text-decoration: none; }
.site-brand span { display: block; }
.site-brand span + span { color: var(--muted); font-size: .85em; font-weight: 600; }
.story-link { padding-block: 12px; white-space: nowrap; }
.story-link[aria-current="page"] { color: var(--text); text-decoration-thickness: 2px; }
.reddit-link { display: flex; align-items: center; justify-content: center; gap: 8px; margin-left: auto; min-height: 44px; padding: 8px 12px; border: 1px solid #ff450066; border-radius: 8px; background: #ff450010; color: var(--text); text-decoration: none; white-space: nowrap; }
.reddit-link:hover { background: #ff450025; }
.reddit-link img { display: block; flex: 0 0 24px; }
.mapper-intro { margin-top: 20px; }
@media (max-width: 620px) {
  .site-nav { gap: 16px; }
  .site-brand { font-size: 1.1rem; }
  .reddit-link { width: 44px; padding: 8px; border-color: transparent; background: transparent; }
  .reddit-name { display: none; }
}

.story-shell { max-width: 800px; }
.story { padding-top: 8px; padding-bottom: 48px; }
.story-kicker { color: var(--muted); font-size: .85rem; margin: 0 0 12px; }
.story h1 { margin: 0 0 24px; font-size: clamp(2rem, 6vw, 2.8rem); line-height: 1.15; text-wrap: balance; }
.story h2 { color: var(--text); font-size: 1.3rem; margin-top: 32px; }
.story p { line-height: 1.75; }
.story .story-lead { font-size: 1.15rem; }
.story figure { margin: 32px 0; }
.story img { display: block; width: 100%; height: auto; border-radius: var(--radius); }
.story figcaption { color: var(--muted); font-size: .85rem; margin-top: 10px; }
.story-back { display: inline-block; margin-top: 16px; font-weight: 600; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.drop {
  position: relative;
  display: block;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
}
.drop.dragover { border-color: var(--accent); }
.drop:focus-within { outline: 2px solid var(--accent); outline-offset: 4px; }
.drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.status { color: var(--muted); min-height: 1.5em; margin: 0.75em 0 0; }

canvas { max-width: 100%; max-height: 480px; width: auto; height: auto; display: block; }

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 120px));
  gap: 16px 12px;
  padding-bottom: 8px;
}

/* Bottom-first DOM order; each higher disc overlaps the one below by 5%. */
.tube {
  --disc-height: 24px;
  display: flex;
  flex-direction: column-reverse;
  gap: 0;
  list-style: none;
  margin: 0;
  padding: 6px 4px 4px;
}
.slot {
  flex: 0 0 var(--disc-height);
  height: var(--disc-height);
  border-radius: 50% / 30%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: inset 0 -4px 0 #0005, 0 2px 2px #0004;
}
.slot + .slot { margin-bottom: calc(var(--disc-height) * -0.05); }
.slot.physical-disc { border: 0; border-radius: 0; box-shadow: none; }
.slot.empty { border-style: dashed; background: transparent; box-shadow: none; opacity: .4; }

pre {
  background: #0b0f18;
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-size: 0.85rem;
}

button {
  background: var(--accent);
  color: #0b0f18;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
}

.stack { margin: 0; min-width: 0; }
.palette-head, .palette-color {
  display: grid;
  grid-template-columns: 28px 42px minmax(0, 160px) 36px 36px;
  align-items: center;
  gap: 6px;
}
.palette-head { margin-top: 20px; color: var(--muted); font-size: 11px; text-align: center; }
.palette-head span:nth-child(3) { text-align: left; }
.palette-color { min-height: 44px; margin: 4px 0; }
.palette-color strong { font-size: 12px; }
.palette-color .palette-swatch {
  width: 42px; height: 30px; padding: 0;
  border: 0; border-radius: 0; box-shadow: none;
}
.palette-swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.palette-color .stripe-option { display: flex; justify-content: center; align-items: center; height: 44px; cursor: pointer; }
.stripe-option input { width: 18px; height: 18px; margin: 0; }
.palette-name { width: 100%; min-width: 0; font-size: 16px; }
input { font: inherit; max-width: 100%; }
input:not([type="checkbox"]):not([type="file"]):not([type="color"]) { padding: 6px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; }

#palette-link { width: 100%; margin-top: 12px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; align-items: center; }
.import-label { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.import-label input { max-width: 210px; }
.warning { color: #ffd080; }
summary { cursor: pointer; }
code { overflow-wrap: anywhere; }

#physical-output { scroll-margin-top: 16px; }
/* This region receives programmatic focus after upload, not keyboard input. */
#physical-output:focus { outline: none; }
#color-dialog {
  width: min(360px, calc(100% - 32px)); max-height: calc(100% - 32px);
  overflow-y: auto; padding: 20px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--panel); color: var(--text);
}
#color-dialog::backdrop { background: #000a; }
#color-dialog h2 { margin-top: 0; }
.color-preview { width: 96px; height: 52px; margin: 20px auto; border: 0; border-radius: 0; box-shadow: none; }
.hex-label { display: flex; align-items: center; gap: 12px; }
#disc-hex { width: 9ch; min-width: 0; }
.color-channel { display: grid; grid-template-columns: 1fr auto; margin-top: 16px; }
.color-channel input { grid-column: 1 / -1; width: 100%; margin: 8px 0; height: 28px; border-radius: 8px; }
#color-dialog .actions { margin-top: 12px; }

.color-preview { position: relative; display: block; cursor: pointer; }
#disc-native-color {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer;
}
.color-preview:focus-within { outline: 2px solid var(--accent); outline-offset: 4px; }
.picker-hint { color: var(--muted); font-size: .85rem; text-align: center; }
.mapping-legend { display: grid; grid-template-columns: repeat(2, max-content); gap: 8px 28px; max-width: 100%; margin: 16px 0; }
.mapping-item { display: grid; grid-template-columns: 18px 7ch 22px; align-items: center; gap: 3px; white-space: nowrap; font: 12px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; }
.mapping-label { text-align: center; font-variant-numeric: tabular-nums; }
.mapping-source, .mapping-target { display: inline-block; width: 18px; height: 14px; border: 1px solid var(--muted); }
.mapping-target { width: 22px; border: 0; border-radius: 0; }

.drawer > summary { font-size: 1rem; font-weight: 600; }
.drawer-content { padding-top: 16px; }
.drawer-content > section + section { margin-top: 24px; }

/* Keep the phone-sized workflow cards together on wider screens. */
body:has(.mapper-layout) .site-header,
.mapper-layout { max-width: 1232px; }
.mapper-layout {
  display: grid;
  grid-template-columns: minmax(0, 384px);
  gap: 16px;
  align-items: start;
  justify-content: center;
}
.mapper-layout > *, .mapper-drawers { min-width: 0; }
.mapper-layout > .panel, .mapper-drawers .panel { margin-bottom: 0; }
.mapper-drawers { display: grid; gap: 16px; }
.mapper-layout [hidden] { display: none; }
/* A disc keeps its proportions even when its stack column changes width. */
.mapper-layout .grid { grid-template-columns: repeat(var(--cols, 4), minmax(0, 72px)); }
.mapper-layout .slot { height: auto; flex: 0 0 auto; aspect-ratio: 3 / 1; }
.mapper-layout .slot + .slot { margin-bottom: -1px; }
@media (min-width: 832px) {
  .mapper-layout { grid-template-columns: repeat(2, minmax(0, 384px)); }
  .mapper-drawers { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}
@media (min-width: 1232px) {
  .mapper-layout { grid-template-columns: repeat(3, minmax(0, 384px)); }
  .mapper-drawers { grid-column: auto; grid-template-columns: minmax(0, 1fr); }
}

/* Source link shares the compact header actions with Reddit. */
.reddit-link { margin-left: 0; }
.github-link { display: flex; align-items: center; justify-content: center; gap: 8px; margin-left: auto; min-height: 44px; padding: 8px 12px; border-radius: 8px; color: #111; background: #f5f5f5; text-decoration: none; white-space: nowrap; }
.github-link:hover { background: #ddd; }
.github-link img { display: block; }
@media (max-width: 620px) {
  .site-nav { gap: 10px; }
  .github-link { width: 44px; flex-shrink: 0; padding: 10px; }
  .github-name { display: none; }
}

