:root {
  --bg: #0d1117;
  --surround: #000000;   /* dark grey around the picture in full screen */
  --panel: #161b22;
  --ink: #e6edf3;
  --muted: #8b949e;
  --line: #30363d;
  --accent: #2ea043;
}

* { box-sizing: border-box; }

/* The page gradient is sized to the body's box.  Without these it tiles below
   the content -- the light centre of the gradient repeats and shows as a
   paler band under the screen -- so pin it: no repeat, a solid colour behind
   it, and a body at least as tall as the viewport. */
html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: radial-gradient(circle at 20% 10%, #1f2937 0%, var(--bg) 45%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--ink);
  font-family: Consolas, "Liberation Mono", Menlo, monospace;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
}

.toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.toolbar h1 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

button, .fileLabel {
  background: #21262d;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

button:hover, .fileLabel:hover { border-color: var(--accent); }

.toggleLabel {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #21262d;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

.toggleLabel:hover {
  border-color: var(--accent);
}

.toggleLabel input {
  margin: 0;
}

.fileLabel input { display: none; }

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.screenWrap {
  margin-top: 12px;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

#screen {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
}

.status {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}

.status.hidden {
  display: none;
}

.status div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.debugWrap {
  margin-top: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}

.debugWrap.hidden {
  display: none;
}

.debugHeader {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.debugControls {
  display: flex;
  gap: 8px;
}

.debugControls button {
  padding: 4px 8px;
  font-size: 0.8rem;
}

.debugLog {
  margin: 0;
  padding: 8px;
  background: #0b0f14;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 90px;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
}


/* --- Full screen ---
   NB each rule is written out per prefix rather than as a selector list:
   a list containing a selector the browser does not know is discarded
   whole, which would drop the letterbox in Firefox (no :-webkit-full-screen)
   and in Safari before 16.4 (no :fullscreen).
   -----------------------------------------------------------
   The original MAVIS display was ~4:3, so the picture is letterboxed to that
   ratio and centred, with the dark grey surround filling whatever is left.
   The canvas is 640x500 (1.28:1); presenting it at 4:3 matches the real
   display, whose pixels were not square. */
.screenWrap:fullscreen {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--surround);
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screenWrap:-webkit-full-screen {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--surround);
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screenWrap:fullscreen #screen {
  width: min(100vw, calc(100vh * 4 / 3));
  height: min(100vh, calc(100vw * 3 / 4));
  max-width: none;
  image-rendering: pixelated;
  background: #000;
}

.screenWrap:-webkit-full-screen #screen {
  width: min(100vw, calc(100vh * 4 / 3));
  height: min(100vh, calc(100vw * 3 / 4));
  max-width: none;
  image-rendering: pixelated;
  background: #000;
}

/* ============================================================
   Ferranti / MAVIS-inspired virtual keyboard
   ============================================================ */
.vkb {
  margin-top: 12px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.vkb.hidden {
  display: none;
}

.vkb-chassis {
  position: relative;
  background: linear-gradient(180deg, #c8b8a0 0%, #b5a48c 40%, #9e8d78 100%);
  border: 2px solid #6b5d4d;
  border-radius: 6px;
  padding: 20px 12px 14px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.35),
    0 4px 12px rgba(0,0,0,0.45);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

.vkb-badge {
  position: absolute;
  top: 4px;
  right: 10px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #5c4033;
  background: #d4c4a8;
  border: 1px solid #8b7355;
  border-radius: 2px;
  padding: 1px 6px;
  font-family: "Times New Roman", Times, serif;
}

.vkb-main {
  flex: 1 1 280px;
  min-width: 0;
  max-width: 520px;
}

.vkb-row {
  display: flex;
  justify-content: center;
  gap: 3px;
  margin-bottom: 4px;
}

.vkb-space-row {
  margin-top: 6px;
}

/* Main cluster keys — sans-serif, larger labels like the photo */
.vkb-key {
  flex: 1 1 0;
  min-width: 0;
  max-width: 42px;
  height: 38px;
  padding: 0 1px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0;
  color: #e8e0d4;
  background: linear-gradient(180deg, #5a524a 0%, #3e3832 55%, #2c2824 100%);
  border: 1px solid #1a1816;
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.12),
    0 2px 0 #1a1816,
    0 3px 4px rgba(0,0,0,0.35);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.04s, box-shadow 0.04s;
  line-height: 1.1;
}

.vkb-key:active,
.vkb-key.pressed {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 3px rgba(0,0,0,0.5),
    0 0 0 #1a1816;
  background: linear-gradient(180deg, #3e3832 0%, #2c2824 100%);
}

.vkb-mod {
  font-size: 0.62rem;
  max-width: 52px;
  color: #c8c0b4;
}

.vkb-wideish {
  max-width: 72px;
  flex: 1.6 1 0;
  font-size: 0.58rem;
}

/* Darker space bar, wider than other keys */
.vkb-space {
  max-width: 320px;
  flex: 6 1 0;
  height: 42px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #c8c0b4;
  background: linear-gradient(180deg, #2a2622 0%, #1a1814 55%, #0e0c0a 100%);
  border-color: #0a0806;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.06),
    0 2px 0 #0a0806,
    0 3px 4px rgba(0,0,0,0.45);
}

.vkb-space:active,
.vkb-space.pressed {
  background: linear-gradient(180deg, #1a1814 0%, #0e0c0a 100%);
  box-shadow:
    inset 0 1px 3px rgba(0,0,0,0.6),
    0 0 0 #0a0806;
}

/* Right-hand 3x4 GRAPH ALPHA / cursor cluster — smaller labels OK */
.vkb-side {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-top: 2px;
  flex: 0 0 auto;
}

.vkb-side-row {
  display: flex;
  gap: 3px;
}

.vkb-graph,
.vkb-cursor {
  width: 44px;
  max-width: 44px;
  height: 40px;
  flex: 0 0 44px;
  font-size: 0.52rem;
  font-weight: 700;
  line-height: 1.15;
  padding: 2px 1px;
}

.vkb-blue {
  background: linear-gradient(180deg, #5a8ec8 0%, #2a5888 100%);
  color: #e8f0ff;
  border-color: #1a4060;
}
.vkb-green {
  background: linear-gradient(180deg, #4a9860 0%, #2a6840 100%);
  color: #e8ffe8;
  border-color: #1a5030;
}
.vkb-yellow {
  background: linear-gradient(180deg, #d0a838 0%, #887018 100%);
  color: #fff8e0;
  border-color: #6a5010;
}
.vkb-red {
  background: linear-gradient(180deg, #c04848 0%, #782828 100%);
  color: #ffe8e8;
  border-color: #5a1818;
}
.vkb-magenta {
  background: linear-gradient(180deg, #9850a8 0%, #603070 100%);
  color: #f8e8ff;
  border-color: #402050;
}
.vkb-cyan {
  background: linear-gradient(180deg, #40a8b8 0%, #206878 100%);
  color: #e0f8ff;
  border-color: #104858;
}
.vkb-white {
  background: linear-gradient(180deg, #e8e0d4 0%, #c8c0b4 55%, #a8a094 100%);
  color: #2c2824;
  border-color: #6b5d4d;
}

.vkb-cursor {
  background: linear-gradient(180deg, #e8e0d4 0%, #c8c0b4 55%, #a8a094 100%);
  color: #2c2824;
  border-color: #6b5d4d;
}

@media (max-width: 560px) {
  .vkb-chassis {
    padding: 18px 6px 12px;
    gap: 8px;
  }
  .vkb-key {
    height: 36px;
    font-size: 0.88rem;
    max-width: 34px;
  }
  .vkb-mod {
    font-size: 0.55rem;
    max-width: 44px;
  }
  .vkb-wideish {
    max-width: 58px;
    font-size: 0.5rem;
  }
  .vkb-graph,
  .vkb-cursor {
    width: 38px;
    max-width: 38px;
    height: 36px;
    flex-basis: 38px;
    font-size: 0.48rem;
  }
  .vkb-space {
    max-width: 260px;
    height: 40px;
    font-size: 0.8rem;
  }
  .vkb-badge {
    font-size: 0.55rem;
  }
}

@media (max-width: 400px) {
  .vkb-side {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 6px;
  }
}
