:root {
  --bg: #f4f4f2;
  --panel: #ffffff;
  --text: #1c1c1c;
  --muted: #5c5c5c;
  --accent: #0b57d0;
  --border: #c9c9c4;
  --screen-bg: #000;
  --mono: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #2a2b2d;
    --panel: #323335;
    --text: #d4d5d7;
    --muted: #9b9ca1;
    --accent: #4aa6f0;
    --border: #1a1a1b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, sans-serif;
}

/* The top bar: the logo and the machine name on the left, the screen and run controls on the right. It stays at the top of the window
 * when the page scrolls (narrow windows; from 821 px the page does not scroll). */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { width: 36px; height: 36px; }
.brand #machine-title { font-style: italic; }

h1 { margin: 0; font-size: 18px; }
h2 { margin: 0 0 8px; font-size: 15px; }
h3 { margin: 0; font-size: 13px; color: var(--muted); }

.controls, .row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

button:focus-visible, .button:focus-within, select:focus-visible, canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  padding: 16px;
  align-items: start;
}

.screen-wrap { min-width: 0; position: relative; }
#selection {
  position: absolute;
  pointer-events: none;
  background: color-mix(in srgb, var(--accent) 35%, transparent);
  border: 1px solid var(--accent);
}
#selection[hidden] { display: none; }

.zoom { display: inline-flex; align-items: stretch; }
.zoom-label { min-width: 6.5ch; font-variant-numeric: tabular-nums; }

.screen-wrap { overflow: auto; }

/* The size is set by js/zoom.js; this is the size before it runs. It is the size of the picture: the border is outside it, so
 * 200% is 1120 device pixels of picture and every dot is two wide (js/display.js). */
canvas {
  box-sizing: content-box;
  display: block;
  margin: 0 auto;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--screen-bg);
  image-rendering: pixelated;
  border: 1px solid var(--border);
  border-radius: 4px;
}

canvas[hidden] { display: none; }
canvas.captured { outline: 2px solid var(--accent); }
canvas:fullscreen { border: 0; border-radius: 0; }  /* the browser fills the display; js/display.js draws 4:3 in the middle */

.hint, .status, .info { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.status { min-height: 1.4em; }
/* The Keyboard panel: whether the screen has the keys (a light), the paste layout and the status line of the page. */
.kbd-state { display: flex; align-items: flex-start; gap: 8px; margin: 0; font-size: 13px; }
.state-led { flex: none; margin-top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--led-off); box-shadow: inset 0 1px 1px rgb(0 0 0 / 0.35); }
.notes.captured .state-led { background: var(--led-on); box-shadow: 0 0 6px var(--led-glow); }
.notes .kbd-state + .hint { margin-top: 2px; padding-left: 17px; font-size: 12px; }
.paste-layout { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px; align-items: center; margin-top: 10px; font-size: 13px; color: var(--muted); }
.paste-layout select { width: 100%; min-width: 0; font-size: 12px; padding: 2px 24px 2px 6px; }
.notes .status { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); overflow-wrap: anywhere; }
.notes .status:empty { display: none; }
.status.error { color: #c5221f; }

.side { display: grid; gap: 16px; min-width: 0; }

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.disk .row + .row { margin-top: 6px; }
.disk.drop-target { outline: 2px dashed var(--accent); outline-offset: 4px; }
.report { margin-top: 6px; font-size: 13px; }
.report summary { cursor: pointer; color: var(--muted); }
.report pre { margin: 6px 0 0; max-height: 14em; overflow: auto; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.disk + .disk { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.info { font-family: var(--mono); font-size: 12px; margin-bottom: 6px; overflow-wrap: anywhere; }

/* The Disks title folds the panel to one line of drive lights and letters (app.js setupDisksFold). */
.fold, .fold:hover:not(:disabled), .fold:active:not(:disabled) {
  background: none; border: 0; box-shadow: none; padding: 0; color: var(--text); text-shadow: none; text-transform: none;
  letter-spacing: 0; font-size: inherit; font-weight: inherit;
}
.fold::after { content: " \25BE"; color: var(--muted); }
.fold[aria-expanded="false"]::after { content: " \25B8"; }
.fold:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.disks.folded { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.disks.folded h2 { margin: 0 6px 0 0; }
.disks.folded > :not(h2, .disk, .pending), .disks.folded .disk > :not(.drive), .disks.folded .actions, .disks.folded .drive-kind { display: none; }
/* Every drive of the folded line has the same box: D: follows the hidden slot row, whose `.slot + .disk` margin moved it down. */
.disks.folded .disk { margin: 0; padding: 0; border: 0; }
/* Under the folded line: a small Save for each drive with changes (app.js showPendingSaves). Only while folded. */
.disks .pending { display: none; }
.disks.folded .pending:not([hidden]) { display: flex; order: 1; flex: 1 0 100%; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.disks .pending button { padding: 2px 8px; font-size: 11px; }

/* The disks area: one compact row per drive (its light, name and buttons; Add and the notes fold away), the image below. */
.drive { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.drive h3 { color: var(--text); display: inline-flex; align-items: center; gap: 7px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.disk .info { margin: 4px 0 0; color: var(--muted); }
.info .image-name { color: var(--accent); font-weight: 700; }
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: " \25BE"; }
.menu > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu-body {
  position: absolute; z-index: 5; left: 0; top: calc(100% + 4px); min-width: 200px; display: grid; gap: 6px; padding: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 18px rgb(0 0 0 / 0.2);
}
.disk .button, .disk .actions button, .disk .menu-body button, .disk .menu > summary { padding: 3px 8px; }
.disk .menu-body select { font-size: 12px; padding: 3px 8px; }
.disk [data-dest] { flex: 1 1 7em; min-width: 0; font-size: 12.5px; }
.menu-body .button, .menu-body button, .menu-body select, .menu-body input[type="text"] { width: 100%; box-sizing: border-box; text-align: left; }
.menu-body [hidden] { display: none; }
.menu-body.opens-left { left: auto; right: 0; }            /* app.js placeMenu: no room to the right of the button */
/* the notes of a drive: shown while the pointer is on the "?" or it has the keyboard focus */
.tip-wrap { position: relative; }
.disk .actions .tip-button { padding: 3px 8px; font-weight: 700; }
.tip {
  display: none; position: absolute; z-index: 6; right: 0; top: calc(100% + 4px); width: min(300px, 80vw); padding: 4px 10px 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 18px rgb(0 0 0 / 0.2);
}
.tip-wrap:hover .tip, .tip-button:focus-visible + .tip { display: block; }
.tip .hint { margin: 6px 0 0; }
.tip [hidden] { display: none; }
.disk label.hint:not([hidden]) { display: block; margin-top: 6px; }
.make-new { margin: 12px 0 0; }
.slot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.slot[hidden] { display: none; }
.slot label { color: var(--muted); font-size: 13px; }
.slot + .disk { margin-top: 10px; }
.hint a { color: var(--accent); }

#debugger { font-family: var(--mono); font-size: 12px; }
#debugger pre { margin: 6px 0; white-space: pre; overflow-x: auto; }
#debugger input[type="text"] {
  font: inherit; width: 9ch; padding: 2px 4px;
  color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
}

@media (max-width: 820px) {
  main { grid-template-columns: minmax(0, 1fr); padding: 16px; }
}

/* A window wide enough for two columns: the page is the height of the window and does not scroll; the screen fits its column
 * (js/zoom.js) and the right column scrolls by itself only when its panels are taller than the window. */
@media (min-width: 821px) {
  body { height: 100vh; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
  main { min-height: 0; align-items: stretch; }
  .screen-wrap { min-height: 0; }
  .side { min-height: 0; overflow: auto; align-content: start; }
}

.pc .devices, .pc .tools { margin-bottom: 4px; }
.pc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.pc-head h2 { margin: 0; }
.pc-summary { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.pc-settings { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 10px; align-items: center; margin: 0 0 12px; }
.pc-settings[hidden] { display: none; }
.pc-settings label { display: contents; font-size: 13px; color: var(--muted); }
.pc-settings label[hidden] { display: none; }
.pc-settings select { width: 100%; min-width: 0; }
.pc .tools { display: flex; width: fit-content; margin-top: 4px; }

/* The download of a disk image: a box in the middle of the screen. */
.loading { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); min-width: min(360px, 80%); padding: 14px 18px;
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 28px rgb(0 0 0 / 0.45);
  text-align: center; font-size: 14px; z-index: 5; }
.loading[hidden] { display: none; }
.loading p { margin: 4px 0; overflow-wrap: anywhere; }
.loading progress { width: 100%; height: 12px; }
#loading-text { font-variant-numeric: tabular-nums; color: var(--muted); }

/* apple2_emu: the ROMs panel has the rows of the Disks panel. */
.rom + .rom { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.rom .button { padding: 3px 8px; }
.rom .info.warn { color: #b26a00; }
.disk .actions button.led { padding: 3px 8px; }
.loading.no-rom { max-width: 26em; }
.run-state { display: flex; align-items: center; gap: 8px; margin: -4px 0 10px; font-size: 13px; font-family: var(--mono); }
.state-led[data-on="true"] { background: var(--led-on); box-shadow: 0 0 6px var(--led-glow); }
.run-state .state-led[data-state="paused"] { background: #e0a020; box-shadow: 0 0 6px rgb(224 160 32 / 0.6); }
.tool-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.disks .pc-head h2 { margin: 0; }
/* The ROMs panel folds to its title and the two lights once both ROMs are there (app.js). */
.roms.folded { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.roms.folded h2 { margin: 0 6px 0 0; }
.roms.folded > .hint, .roms.folded .rom .info, .roms.folded .rom .actions { display: none; }
.roms.folded .rom { margin: 0; padding: 0; border: 0; }
.key-lights { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.key-light { display: inline-flex; align-items: center; gap: 6px; }
.key-light .state-led { margin-top: 0; }
#paddles { font-family: var(--mono); font-size: 12px; }
.paste-state { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; font-size: 13px; }
.paste-state button { padding: 2px 8px; font-size: 11px; }
.shortcuts { margin: 10px 0 0; padding-left: 18px; font-size: 12px; color: var(--muted); }
.shortcuts li + li { margin-top: 2px; }
.shortcuts [hidden] { display: none; }
kbd { font-family: var(--mono); font-size: 11px; padding: 0 4px; border: 1px solid var(--border); border-radius: 3px; background: var(--bg); }
.screen-wrap.drop-target canvas { outline: 3px dashed var(--accent); outline-offset: -3px; }
.key-light[hidden], .paste-state[hidden] { display: none; }
.tool-row > button { align-self: stretch; }
.rom select { font-size: 12px; padding: 3px 24px 3px 8px; max-width: 12em; }
.rom select[hidden] { display: none; }
