:root {
  --bg: #0b0d12;
  --surface: #131722;
  --card: #1b2130;
  --line: #2e343e;
  --fg: #f3f4f6;
  --dim: #9ca3af;
  --accent: #e8851c;
  --accent-emu: #38bdf8;
  --accent-inst: #6ee42a;
  --accent-resc: #e8851c;
  --tab-accent: var(--accent-emu);
  --gold: #ffd740;
  --bad: #ef4444;
  --good: #6ee42a;
  --body: #181c26;
  --tray: #10141e;
  --knob: #131722;
  --btn: #1b2130;
  --label: #e5e7eb;
  --key-w: #dce0e8;
  --key-b: #1e2433;
  --lit: #6ee42a;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}
body[data-tab='emulator'] {
  --tab-accent: var(--accent-emu);
}
body[data-tab='install'] {
  --tab-accent: var(--accent-inst);
}
body[data-tab='rescue'] {
  --tab-accent: var(--accent-resc);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font:
    15px/1.55 system-ui,
    -apple-system,
    'Segoe UI',
    sans-serif;
  -webkit-font-smoothing: antialiased;
}
a {
  color: var(--tab-accent);
  text-decoration-color: color-mix(in srgb, var(--tab-accent) 45%, transparent);
  transition: color 180ms var(--ease);
}
a:hover {
  color: var(--fg);
}
.dim {
  color: var(--dim);
}
.small {
  font-size: 13px;
}
.mono,
pre,
code,
kbd {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
code {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12.5px;
  color: var(--fg);
}
kbd {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 12px;
}

header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.brand strong {
  letter-spacing: 0.08em;
  font-size: 15px;
  color: var(--fg);
}
#fwver {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--dim);
}
nav {
  display: flex;
  gap: 6px;
}
nav a {
  position: relative;
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  color: var(--dim);
  border: 1px solid transparent;
  font-weight: 500;
  transition:
    color 180ms var(--ease),
    background-color 180ms var(--ease),
    border-color 180ms var(--ease);
}
nav a::after {
  content: '';
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: transparent;
  transform: scaleX(0);
  transition:
    transform 200ms var(--ease),
    background-color 200ms var(--ease);
}
nav a:hover {
  color: var(--fg);
  background: var(--card);
  border-color: var(--line);
}
nav a.on {
  color: var(--fg);
  background: var(--card);
  border-color: var(--tab-accent);
}
nav a.on::after {
  background: var(--tab-accent);
  transform: scaleX(1);
}
nav a[data-tab='emulator'].on {
  border-color: var(--accent-emu);
}
nav a[data-tab='emulator'].on::after {
  background: var(--accent-emu);
}
nav a[data-tab='install'].on {
  border-color: var(--accent-inst);
}
nav a[data-tab='install'].on::after {
  background: var(--accent-inst);
}
nav a[data-tab='rescue'].on {
  border-color: var(--accent-resc);
}
nav a[data-tab='rescue'].on::after {
  background: var(--accent-resc);
}

.end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.source {
  font-size: 13px;
  color: var(--dim);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--bg);
  transition:
    color 180ms var(--ease),
    border-color 180ms var(--ease);
}
.source:hover {
  color: var(--fg);
  border-color: var(--tab-accent);
}
.badge {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  border-radius: 6px;
  padding: 3px 10px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.badge.ok {
  color: var(--good);
  border-color: color-mix(in srgb, var(--good) 55%, var(--line));
}
.badge.bad {
  color: #fff;
  background: color-mix(in srgb, var(--bad) 22%, var(--surface));
  border-color: var(--bad);
}

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 18px 16px;
}
footer {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px;
  border-top: 1px solid var(--line);
}
.tab {
  position: relative;
  animation: tabFadeIn 200ms var(--ease);
}
@keyframes tabFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
h1 {
  font-size: 21px;
  letter-spacing: 0.02em;
  margin: 6px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
h1::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 20px;
  border-radius: 2px;
  background: var(--tab-accent);
}
h2 {
  font-size: 15px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--fg);
  margin: 0 0 8px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px 18px;
  margin: 12px 0;
  transition:
    border-color 180ms var(--ease),
    background-color 180ms var(--ease);
}
.card:hover,
.card:focus-within {
  border-color: color-mix(in srgb, var(--tab-accent) 70%, var(--line));
}
.card ol,
.card ul {
  padding-left: 20px;
}
.card li {
  margin: 4px 0;
}

button,
select {
  font: inherit;
  font-size: 13.5px;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 6px 13px;
  cursor: pointer;
  transition:
    border-color 180ms var(--ease),
    background-color 180ms var(--ease),
    color 180ms var(--ease),
    transform 120ms var(--ease);
}
button:hover:not(:disabled),
select:hover:not(:disabled) {
  border-color: var(--tab-accent);
  background: color-mix(in srgb, var(--tab-accent) 10%, var(--card));
}
button:active:not(:disabled) {
  transform: translateY(1px);
}
button:focus-visible,
select:focus-visible,
input[type='file']:focus-visible {
  outline: 2px solid var(--tab-accent);
  outline-offset: 2px;
}
button.primary {
  background: color-mix(in srgb, var(--tab-accent) 18%, var(--surface));
  border: 1.5px solid var(--tab-accent);
  color: var(--fg);
  font-weight: 600;
}
button.primary:hover:not(:disabled) {
  background: var(--tab-accent);
  color: #0b0d12;
}
button:disabled {
  opacity: 0.38;
  cursor: default;
}
input[type='file'] {
  font-size: 13px;
  color: var(--dim);
  max-width: 100%;
  padding: 6px 8px;
  border-radius: 5px;
  border: 1px dashed var(--line);
  background: var(--surface);
  transition: border-color 180ms var(--ease);
}
input[type='file']:hover {
  border-color: var(--tab-accent);
}
progress {
  width: 100%;
  height: 8px;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  overflow: hidden;
}
progress::-webkit-progress-bar {
  background: var(--surface);
}
progress::-webkit-progress-value {
  background: var(--accent-inst);
  transition: width 150ms var(--ease);
}
progress::-moz-progress-bar {
  background: var(--accent-inst);
}
pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
}

.buildlog {
  max-width: 1040px;
  margin: 12px auto 0;
  padding: 12px 16px;
  border: 1px solid var(--bad);
  border-radius: 6px;
  background: color-mix(in srgb, var(--bad) 12%, var(--surface));
}
.buildlog-head {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: baseline;
}
.buildlog pre {
  margin: 8px 0 0;
  max-height: 40vh;
  overflow: auto;
}

/* ---- Drag-and-drop .MID overlay */
.drop-overlay {
  position: fixed;
  inset: 16px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(11, 13, 18, 0.88);
  border: 2px dashed var(--accent-emu);
  border-radius: 10px;
  color: var(--fg);
  pointer-events: none;
  animation: dropPulse 180ms var(--ease);
}
.drop-overlay[hidden] {
  display: none;
}
.drop-overlay strong {
  font-size: 18px;
  letter-spacing: 0.04em;
  color: var(--accent-emu);
}
@keyframes dropPulse {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ---- the device: controls are placed in a 1000 x 640 space (app.js) */
.device {
  position: relative;
  width: 100%;
  aspect-ratio: 1000 / 640;
  background: var(--body);
  border: 1.5px solid var(--line);
  border-radius: 3.4% / 5.4%;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  container-type: inline-size;
  transition: border-color 220ms var(--ease);
}
.device:focus-within {
  border-color: color-mix(in srgb, var(--accent-emu) 60%, var(--line));
}
.device > * {
  position: absolute;
}
.tray {
  background: var(--tray);
  border: 1px solid #242b3a;
  border-radius: 10px;
}
.bezel {
  background: #07090d;
  border: 1.5px solid var(--line);
  border-radius: 8%;
}
#screen {
  image-rendering: pixelated;
  background: #0b0d12;
  border-radius: 3px;
  z-index: 1;
}
.label {
  color: var(--dim);
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 1.55cqw;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
}
.knob {
  border-radius: 50%;
  background: var(--knob);
  box-shadow:
    0 0 0 0.45cqw var(--tray),
    inset 0 0 0 0.2cqw var(--line);
  cursor: ns-resize;
  touch-action: none;
  transform: rotate(var(--angle, 0deg));
  transition: box-shadow 150ms var(--ease);
}
.knob:hover {
  box-shadow:
    0 0 0 0.45cqw var(--tray),
    inset 0 0 0 0.25cqw var(--accent);
}
.knob::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 8%;
  width: 0.32cqw;
  height: 24%;
  margin-left: -0.16cqw;
  background: var(--accent);
  border-radius: 2px;
}
.btn {
  background: var(--btn);
  border-radius: 6px;
  box-shadow: inset 0 0 0 1.5px var(--line);
  color: var(--label);
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 1.35cqw;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
  transition:
    background-color 140ms var(--ease),
    box-shadow 140ms var(--ease),
    color 140ms var(--ease);
}
.btn:hover {
  box-shadow: inset 0 0 0 1.5px var(--accent-emu);
}
.btn.held {
  filter: brightness(1.35);
}
.btn.latched {
  box-shadow: inset 0 0 0 2px var(--accent);
}
.btn.lit {
  color: #0b0d12;
  background: var(--accent);
  box-shadow:
    inset 0 0 0 1.5px var(--gold),
    0 0 1.1cqw color-mix(in srgb, var(--accent) 70%, transparent);
}
.key {
  border-radius: 8px;
  background: var(--key-w);
  box-shadow: inset 0 -0.45cqw 0 rgba(11, 13, 18, 0.28);
  cursor: pointer;
  touch-action: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 0.8cqw;
  color: #4b5563;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 1.25cqw;
  font-weight: 600;
  line-height: 1.1;
  text-align: center;
  transition:
    background-color 90ms var(--ease),
    box-shadow 90ms var(--ease);
}
.key.black {
  background: var(--key-b);
  color: #9ca3af;
  box-shadow: inset 0 0 0 1px #364156;
}
.key.held {
  background: var(--accent-emu);
  color: #0b0d12;
}
.key.lit {
  background: var(--lit);
  color: #0b0d12;
  box-shadow: 0 0 1.2cqw color-mix(in srgb, var(--lit) 75%, transparent);
}
.key[data-backlight='1']:not(.lit),
.btn[data-backlight='1']:not(.lit) {
  box-shadow: 0 0 0.6cqw color-mix(in srgb, var(--accent) 30%, transparent);
}
.key[data-backlight='2']:not(.lit),
.btn[data-backlight='2']:not(.lit) {
  box-shadow: 0 0 1cqw color-mix(in srgb, var(--accent) 65%, transparent);
}
.key:focus-visible,
.btn:focus-visible,
.knob:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.poweron {
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 13, 18, 0.62);
  backdrop-filter: blur(2px);
  border-radius: inherit;
  z-index: 2;
}
.poweron button.primary {
  padding: 10px 24px;
  font-size: 15px;
  letter-spacing: 0.04em;
  border-color: var(--accent-inst);
  background: color-mix(in srgb, var(--accent-inst) 18%, var(--surface));
}
.poweron button.primary:hover {
  background: var(--accent-inst);
  color: #0b0d12;
}
.poweron[hidden] {
  display: none;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: 12px 0;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--dim);
}
#clock {
  margin-left: auto;
  font-size: 12px;
  color: var(--accent-emu);
}
.console {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  height: 140px;
  overflow: auto;
  margin: 0;
  color: var(--dim);
}
.console .err {
  color: var(--bad);
}
