:root { --scale: 3; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: #cfcfcf;
  font-family: "Courier New", ui-monospace, monospace;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px;
}

#frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* ---- the desk: speakers + CRT monitor ------------------------------------
   The 320x200 buffer is displayed at 4:3 (as VGA mode 13h was on a real
   monitor). Everything scales with the window and keeps its shape. */
#desk {
  --monw: min(70vw, calc(70vh * 4 / 3));
  display: flex;
  align-items: flex-end;
  gap: calc(var(--monw) * 0.025);
}
#monitor {
  width: var(--monw);
  background: linear-gradient(160deg, #ddd7c9, #beb8aa 60%, #a49e90);
  border-radius: 1.6% / 2.2%;
  padding: 2.6% 2.6% 0;
  box-shadow:
    inset 0 2px 3px rgba(255,255,255,.55),
    inset 0 -4px 8px rgba(0,0,0,.28),
    inset 3px 0 5px rgba(255,255,255,.18),
    inset -3px 0 6px rgba(0,0,0,.15),
    0 22px 60px rgba(0,0,0,.75);
}
/* inner bezel ring around the glass */
#crt {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 2.5% / 3.5%;
  overflow: hidden;
  border: 3px solid #8f897c;
  border-bottom-color: #c6c0b2;
  border-right-color: #b0aa9c;
  box-shadow:
    inset 0 0 0 2px #14140f,
    inset 0 4px 10px rgba(0,0,0,.85),
    inset 0 0 26px 7px rgba(0,0,0,.9);
}
#screen {
  display: block;
  position: absolute;
  inset: 1.5% 1.5%;
  width: 97%;
  height: 97%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  transform-origin: 50% 50%;
  /* the front-panel dials: size via transform, picture via filter */
  transform: scale(var(--hsize,1), var(--vsize,1));
  filter: brightness(var(--crtb,1)) contrast(var(--crtc,1));
  transition: transform .18s ease-in, opacity .14s ease-in .08s;
}
/* scanlines + curvature vignette + glass glare; never intercepts input */
#crtfx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  transition: opacity .3s ease;
  background:
    radial-gradient(ellipse 90% 78% at 30% 22%, rgba(255,255,255,.05), transparent 55%),
    repeating-linear-gradient(to bottom, rgba(0,0,0,.16) 0px, rgba(0,0,0,.16) 1px, transparent 1px, transparent 3px),
    radial-gradient(ellipse 120% 105% at 50% 50%, transparent 62%, rgba(0,0,0,.38) 100%);
}
#monitorbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5% 2% 1.7%;
}
.mcontrols {
  display: flex;
  align-items: center;
  gap: calc(var(--monw) * 0.012);
}
/* front-panel controls: labelled dials (scroll to turn) + degauss button */
.mctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.mctl .glyph {
  font-size: clamp(6px, 0.65vw, 9px);
  line-height: 1;
  color: #6a6458;
  text-shadow: 0 1px 0 rgba(255,255,255,.4);
}
.dial {
  position: relative;
  width: calc(var(--monw) * 0.022);
  height: calc(var(--monw) * 0.022);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #d5cfc1, #8f897b 75%);
  box-shadow: inset 0 -1px 2px rgba(0,0,0,.4), 0 1px 1px rgba(0,0,0,.3);
  cursor: ns-resize;
}
/* the indicator line, rotated to the dial's position */
.dial::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 5%;
  width: 9%;
  min-width: 2px;
  height: 45%;
  border-radius: 1px;
  background: #3c382f;
  transform-origin: 50% 100%;
  transform: translateX(-50%) rotate(var(--rot, 0deg));
}
.dgbtn {
  width: calc(var(--monw) * 0.024);
  height: calc(var(--monw) * 0.017);
  margin-top: calc(var(--monw) * 0.003);
  border-radius: 3px;
  background: linear-gradient(#cbc5b7, #90897b);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.6), inset 0 -1px 2px rgba(0,0,0,.4), 0 1px 1px rgba(0,0,0,.3);
  cursor: pointer;
}
.dgbtn:active {
  background: linear-gradient(#b1ab9d, #857e70);
  box-shadow: inset 0 1px 3px rgba(0,0,0,.5);
}
/* the degauss THUNK: the picture shudders and the colours shimmer */
#screen.degauss { animation: degauss 1.1s ease-out; }
@keyframes degauss {
  0%   { transform: scale(var(--hsize,1), var(--vsize,1)) rotate(0.9deg) scale(1.02);  filter: brightness(var(--crtb,1)) contrast(var(--crtc,1)) hue-rotate(25deg) saturate(1.8); }
  25%  { transform: scale(var(--hsize,1), var(--vsize,1)) rotate(-0.7deg) scale(1.012); filter: brightness(var(--crtb,1)) contrast(var(--crtc,1)) hue-rotate(-18deg) saturate(1.5); }
  50%  { transform: scale(var(--hsize,1), var(--vsize,1)) rotate(0.4deg);  filter: brightness(var(--crtb,1)) contrast(var(--crtc,1)) hue-rotate(10deg); }
  75%  { transform: scale(var(--hsize,1), var(--vsize,1)) rotate(-0.2deg); filter: brightness(var(--crtb,1)) contrast(var(--crtc,1)) hue-rotate(-5deg); }
  100% { transform: scale(var(--hsize,1), var(--vsize,1));                 filter: brightness(var(--crtb,1)) contrast(var(--crtc,1)); }
}
.mcontrols .pwr {
  width: calc(var(--monw) * 0.034);
  height: calc(var(--monw) * 0.018);
  margin-left: calc(var(--monw) * 0.015);
  border-radius: 2px;
  background: linear-gradient(#cbc5b7, #90897b);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.6), inset 0 -1px 2px rgba(0,0,0,.4), 0 1px 1px rgba(0,0,0,.3);
}
#monitorbar .brand {
  font-size: clamp(8px, 1.2vw, 13px);
  font-weight: bold;
  letter-spacing: .28em;
  color: #6a6458;
  text-shadow: 0 1px 0 rgba(255,255,255,.4);
}
#powerled {
  width: clamp(6px, .8vw, 10px);
  height: clamp(6px, .8vw, 10px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #9dff9d, #18b418 60%, #0a660a);
  box-shadow: 0 0 6px 1px rgba(40,220,40,.8);
}

/* the power controls really work (easter egg) */
.mcontrols .pwr, #powerled,
.speaker .spknob, .speaker .spled { cursor: pointer; }
.speaker .spknob.dial { cursor: ns-resize; }
.mcontrols { align-items: flex-start; }
.mcontrols .pwr, #powerled { margin-top: calc(var(--monw) * 0.004); }

/* monitor switched off: the picture collapses like a dying tube */
body.monitor-off #screen { transform: scaleY(.004) scaleX(.72); opacity: 0; }
body.monitor-off #crtfx  { opacity: 0; }
body.monitor-off #powerled {
  background: radial-gradient(circle at 35% 35%, #4a544a, #232a20 60%, #101408);
  box-shadow: inset 0 1px 1px rgba(0,0,0,.5);
}

/* beige desktop speakers — always on the desk; the sound state shows on
   the power LED (green = on, dark = off) */
.speaker {
  width: calc(var(--monw) * 0.16);
  height: calc(var(--monw) * 0.38);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--monw) * 0.015) calc(var(--monw) * 0.012);
  background: linear-gradient(160deg, #ddd7c9, #b4ae9f 70%, #a09a8c);
  border-radius: 5px;
  box-shadow:
    inset 0 2px 3px rgba(255,255,255,.55),
    inset 0 -3px 6px rgba(0,0,0,.28),
    0 16px 40px rgba(0,0,0,.7);
}
/* sound off = amp off: the LED goes dark */
body:not(.sound-on) .spled {
  background: radial-gradient(circle at 35% 35%, #4a544a, #232a20 60%, #101408);
  box-shadow: inset 0 1px 1px rgba(0,0,0,.5);
}
/* big squarish grey fabric grille covering most of the front, with the
   drivers showing faintly through the cloth */
.speaker .grillepad {
  width: 94%;
  flex: 1;
  margin: 3% 0;
  border-radius: 7px;
  background:
    radial-gradient(circle at 50% 70%, rgba(0,0,0,.30) 0 27%, transparent 36%),
    radial-gradient(circle at 50% 16%, rgba(0,0,0,.22) 0 9%, transparent 14%),
    repeating-linear-gradient(0deg, rgba(0,0,0,.13) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0,0,0,.13) 0 1px, transparent 1px 3px),
    #96918a;
  box-shadow:
    inset 0 2px 6px rgba(0,0,0,.45),
    inset 0 -1px 2px rgba(255,255,255,.15),
    inset 0 0 0 2px rgba(0,0,0,.22);
}
/* control row on one speaker only */
.speaker .spctl {
  display: flex;
  align-items: center;
  gap: calc(var(--monw) * 0.012);
  min-height: calc(var(--monw) * 0.02);
}
.speaker .spknob {
  width: calc(var(--monw) * 0.02);
  height: calc(var(--monw) * 0.02);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #d5cfc1, #8f897b 75%);
  box-shadow: inset 0 -1px 2px rgba(0,0,0,.4), 0 1px 1px rgba(0,0,0,.3);
}
.speaker .spled {
  width: calc(var(--monw) * 0.008);
  height: calc(var(--monw) * 0.008);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #9dff9d, #18b418 60%, #0a660a);
  box-shadow: 0 0 4px 1px rgba(40,220,40,.8);
}
.speaker .spbrand { min-height: calc(var(--monw) * 0.02); display: flex; align-items: center; }
.speaker .spbrand {
  font-size: clamp(6px, 0.7vw, 10px);
  font-weight: bold;
  letter-spacing: .3em;
  color: #6a6458;
  text-shadow: 0 1px 0 rgba(255,255,255,.4);
}

#hint {
  font-size: 13px;
  color: #7a7a86;
  letter-spacing: .3px;
  text-align: center;
}

#gamesplayed {
  font-size: 12px;
  color: #55555f;
  letter-spacing: .3px;
  text-align: center;
  min-height: 1em;
}

#soundctl {
  position: fixed;
  top: 10px;
  right: 12px;
  display: flex;
  gap: 6px;
  z-index: 5;         /* above the CRT's positioned layers, below #overlay */
}
#soundctl select, #soundctl button {
  padding: 6px 9px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1;
  color: #a8a8b4;
  background: #16161c;
  border: 1px solid #33333d;
  border-radius: 6px;
  cursor: pointer;
  transition: color .12s ease, background .12s ease, border-color .12s ease;
}
/* each button lights up on its own */
#soundctl > button:hover, #soundwrap > button:hover {
  color: #fff;
  background: #242433;
  border-color: #5a5a72;
}
#mute { font-size: 16px; }

/* ---- About / Rules overlay ---- */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
#overlay[hidden] { display: none; }
#panel {
  width: min(92vw, 620px);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  background: #0a0a14;
  border: 2px solid #33334d;
  box-shadow: 0 24px 60px rgba(0,0,0,.7);
}
#panelbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #16162a;
  border-bottom: 1px solid #33334d;
  color: #ffd23f;
  font-weight: bold;
  letter-spacing: .5px;
}
#panelclose {
  padding: 4px 14px;
  font-family: inherit;
  color: #eee;
  background: #23232b;
  border: 1px solid #3a3a44;
  border-radius: 4px;
  cursor: pointer;
}
#panelbody {
  overflow-y: auto;
  padding: 14px 18px;
  font-size: 14px;
  line-height: 1.55;
  color: #c8c8d0;
}
#panelbody h2 {
  margin: 14px 0 6px;
  font-size: 14px;
  color: #ffd23f;
  letter-spacing: .5px;
  text-transform: uppercase;
}
#panelbody h2:first-child { margin-top: 0; }
#panelbody p { margin: 6px 0; }
#panelbody pre { margin: 6px 0; color: #eee; }
#panelbody .dim { color: #8890a8; }
#panelbody .tiny { font-size: 12px; }
#panelbody .dead { text-decoration: underline dotted; color: #7aa0d0; }
#panelbody .exhibit {
  margin: 10px 0;
  padding: 10px 12px;
  background: #10101e;
  border: 1px solid #2a2a44;
  border-radius: 4px;
}
#panelbody .exhibit h3 { margin: 0 0 4px; font-size: 14px; }
#panelbody .exhibit a { color: #ffd23f; text-decoration: none; }
#panelbody .exhibit a:hover { text-decoration: underline; }
#panelbody .exhibit p { margin: 0; color: #9aa; font-size: 13px; }

#soundwrap { position: relative; }
#soundmenu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 262px;
  padding: 12px 14px;
  background: #10101e;
  border: 1px solid #33334d;
  border-radius: 6px;
  box-shadow: 0 12px 32px rgba(0,0,0,.6);
  z-index: 20;
}
#soundmenu[hidden] { display: none; }
#soundmenu .srow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: #c8c8d0;
  white-space: nowrap;
}
#soundmenu select {
  padding: 4px 6px;
  font-family: inherit;
  font-size: 13px;
  color: #cfcfcf;
  background: #16161c;
  border: 1px solid #33333d;
  border-radius: 4px;
}
#soundmenu input[type="checkbox"] { accent-color: #ffd23f; }
#soundmenu .srow.sleft { justify-content: flex-start; }
#soundmenu .shead {
  margin-top: 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #8890a8;
  border-bottom: 1px solid #26263a;
  padding-bottom: 3px;
}
#soundmenu .sval { display: flex; align-items: center; gap: 5px; color: #8890a8; font-size: 12px; }
#soundmenu input[type="number"] {
  width: 62px;
  padding: 4px 6px;
  font-family: inherit;
  font-size: 13px;
  color: #cfcfcf;
  background: #16161c;
  border: 1px solid #33333d;
  border-radius: 4px;
}

#volume {
  -webkit-appearance: none;
  appearance: none;
  width: 110px;
  height: 4px;
  margin: auto 0;
  background: #33333d;
  border-radius: 2px;
  cursor: pointer;
}
#volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #cfcfcf;
  border: 1px solid #33333d;
}
#volume::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #cfcfcf;
  border: 1px solid #33333d;
}



/* keyboardless devices see the error screen; hide the key hints */
@media (pointer: coarse) and (hover: none) {
  #hint { display: none; }
}

#panelbody .storylink { color: #ffd23f; text-decoration: none; }
#panelbody .storylink:hover { text-decoration: underline; }

/* the 1995 gameplay shot inside the About story */
#panelbody img.aboutshot {
  display: block;
  width: 100%;
  max-width: 440px;
  margin: 14px auto;
  image-rendering: pixelated;
  border: 2px solid #333;
  border-radius: 3px;
}

/* the Highscores panel: compact list, click a row for the game's details */
#scoresList .hsrow {
  display: grid;
  grid-template-columns: 2.4em 1fr 7em 5.5em 4.5em;
  gap: 8px;
  align-items: baseline;
  padding: 6px 10px;
  border-bottom: 1px solid #1c1c2c;
  cursor: pointer;
  font-size: 14px;
}
#scoresList .hsrow:hover { background: #16162a; }
#scoresList .hsrow.open  { background: #1a1a30; }
#scoresList .hshead {
  cursor: default;
  color: #8890a8;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
#scoresList .hshead:hover { background: none; }
#scoresList .hsrank  { color: #8890a8; text-align: right; }
#scoresList .hsdate  { color: #8890a8; font-size: 12px; }
#scoresList .hsacc   { color: #9aa; text-align: right; }
#scoresList .hsscore { color: #ffd23f; font-weight: bold; text-align: right; }
#scoresList .hsdetails {
  padding: 6px 12px 10px calc(2.4em + 18px);
  background: #101020;
  border-bottom: 1px solid #1c1c2c;
}
#scoresList .hsdetails p { margin: 3px 0; }
