:root {
  --bg: #f4f4f2;
  --fg: #18181a;
  --dim: #6b6b70;
  --card: #ffffff;
  --line: #dcdcd8;
  --accent: #e8851c;
  --bad: #c0392b;
  --good: #2e8b57;
  --body: #3a3d42;
  --tray: #26282c;
  --knob: #1f2124;
  --btn: #2e3135;
  --label: #e8e8ea;
  --key-w: #d9dadc;
  --key-b: #c9cacd;
  --lit: #ffb347;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --fg: #ececee;
    --dim: #8d8d94;
    --card: #1c1c1f;
    --line: #2e2e33;
  }
}
* {
  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;
}
a {
  color: inherit;
}
.dim {
  color: var(--dim);
}
.small {
  font-size: 13px;
}
.mono,
pre,
code,
kbd {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
kbd {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 12px;
}

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand strong {
  letter-spacing: 0.04em;
}
nav {
  display: flex;
  gap: 4px;
}
nav a {
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--dim);
}
nav a.on {
  color: var(--fg);
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--line);
}
.end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.source {
  font-size: 14px;
  color: var(--dim);
  text-decoration: none;
}
.source:hover {
  color: var(--fg);
}
.badge {
  font-size: 13px;
  border-radius: 999px;
  padding: 3px 12px;
}
.badge.ok {
  color: var(--good);
}
.badge.bad {
  color: #fff;
  background: var(--bad);
  border-color: var(--bad);
}

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px;
}
footer {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px;
}
h1 {
  font-size: 22px;
  margin: 8px 0 12px;
}
h2 {
  font-size: 16px;
  margin: 0 0 8px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  margin: 12px 0;
}
.card ol,
.card ul {
  padding-left: 20px;
}
button,
select {
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1206;
  font-weight: 600;
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
input[type='file'] {
  font-size: 13px;
  max-width: 100%;
}
progress {
  width: 100%;
  height: 6px;
}
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: 10px;
  background: color-mix(in srgb, var(--bad) 10%, var(--card));
}
.buildlog-head {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: baseline;
}
.buildlog pre {
  margin: 8px 0 0;
  max-height: 40vh;
  overflow: auto;
}

/* ---- 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-radius: 4.4% / 6.9%;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  container-type: inline-size;
}
.device > * {
  position: absolute;
}
.tray {
  background: var(--tray);
  border-radius: 14px;
}
.bezel {
  background: #111214;
  border-radius: 11%;
}
#screen {
  image-rendering: pixelated;
  background: #000;
  z-index: 1;
}
.label {
  color: var(--label);
  font-size: 1.7cqw;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
}
.knob {
  border-radius: 50%;
  background: var(--knob);
  box-shadow:
    0 0 0 0.5cqw var(--tray),
    inset 0 0 0 0.2cqw #44474c;
  cursor: ns-resize;
  touch-action: none;
}
.knob::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 8%;
  width: 0.3cqw;
  height: 22%;
  margin-left: -0.15cqw;
  background: var(--label);
  border-radius: 2px;
}
.knob {
  transform: rotate(var(--angle, 0deg));
}
.btn {
  background: var(--btn);
  border-radius: 9px;
  box-shadow: inset 0 0 0 1.5px #4a4d52;
  color: var(--label);
  font-size: 1.4cqw;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
}
.btn.held {
  filter: brightness(1.5);
}
.btn.latched {
  box-shadow: inset 0 0 0 2px var(--accent);
}
.btn.lit {
  color: #1a1206;
  background: var(--lit);
  box-shadow: 0 0 1.4cqw var(--lit);
}
.key {
  border-radius: 999px;
  background: var(--key-w);
  cursor: pointer;
  touch-action: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 0.8cqw;
  color: #55575c;
  font-size: 1.3cqw;
  font-weight: 600;
  line-height: 1.1;
  text-align: center;
}
.key.black {
  background: var(--key-b);
}
.key.held {
  filter: brightness(0.8);
}
.key.lit {
  background: var(--lit);
  box-shadow: 0 0 1.4cqw var(--lit);
}
.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(0, 0, 0, 0.45);
  border-radius: inherit;
  z-index: 2;
}
.poweron[hidden] {
  display: none;
}

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