:root {
  --bg: #1b1714;
  --bg-2: #2a221c;
  --ink: #efe6d8;
  --ink-dim: #b5a894;
  --accent: #f29a2e;      /* COMX orange keys */
  --wood-1: #6b3f22;
  --wood-2: #4a2a16;
  --wood-3: #82502c;
  --plastic: #1d1d1f;
  --screen-off: #20261f;
  --phosphor: #33e033;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background:
    radial-gradient(ellipse 90% 60% at 50% 0%, #3a2e24 0%, transparent 70%),
    linear-gradient(180deg, var(--bg) 0%, #120f0d 100%);
  background-color: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

header { text-align: center; margin-bottom: 20px; }
h1 {
  font-family: VT323, monospace;
  font-weight: 400;
  font-size: clamp(2.4rem, 7vw, 3.6rem);
  letter-spacing: 0.04em;
  margin: 0;
  color: var(--phosphor);
  text-shadow: 0 0 12px rgba(51, 224, 51, 0.45);
}
h1 span { color: var(--accent); text-shadow: 0 0 12px rgba(242, 154, 46, 0.4); }
.sub { margin: 4px 0 0; color: var(--ink-dim); }
.credit { margin: 2px 0 0; font: 400 1.15rem VT323, monospace; letter-spacing: 0.04em; color: var(--accent); }

/* ------------------------------------------------------------ television */
.tv {
  position: relative;
  width: min(100%, 1040px);
  margin: 104px auto 0;
}

.antenna { position: absolute; left: 50%; top: -44px; width: 0; height: 0; }
.antenna::before {
  content: ""; position: absolute; left: -26px; top: 34px; width: 52px; height: 16px;
  background: #2b2b2b; border-radius: 26px 26px 0 0;
}
.antenna i {
  position: absolute; bottom: -38px; left: -2px; width: 4px; height: 92px;
  background: linear-gradient(90deg, #888, #ddd, #777);
  transform-origin: bottom center; border-radius: 2px;
}
.antenna i:first-child { transform: rotate(-32deg); }
.antenna i:last-child { transform: rotate(28deg); }
.antenna i::after {
  content: ""; position: absolute; top: -5px; left: -3px; width: 10px; height: 10px; border-radius: 50%; background: #ccc;
}

.cabinet {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 17%;
  gap: 4%;
  padding: 3.4%;
  border-radius: 26px;
  background:
    repeating-linear-gradient(92deg, rgba(0,0,0,0.0) 0 7px, rgba(0,0,0,0.10) 7px 9px, rgba(255,255,255,0.03) 9px 13px),
    repeating-linear-gradient(88deg, transparent 0 31px, rgba(0,0,0,0.12) 31px 33px),
    linear-gradient(180deg, var(--wood-3), var(--wood-1) 40%, var(--wood-2));
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,0.15),
    inset 0 -6px 12px rgba(0,0,0,0.45),
    0 30px 60px rgba(0,0,0,0.6),
    0 6px 0 #2a170b;
}

.bezel {
  padding: 5.5%;
  border-radius: 20px;
  background: linear-gradient(145deg, #3a3a3c, #161618);
  box-shadow: inset 0 3px 8px rgba(0,0,0,0.8), 0 1px 0 rgba(255,255,255,0.12);
}

.screen {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 9% / 12%;
  overflow: hidden;
  background: var(--screen-off);
  box-shadow: inset 0 0 40px rgba(0,0,0,0.9);
  transition: background-color 0.2s;
}

#display {
  position: absolute;
  /* COMX picture sits inside the overscan border, like on a real set */
  left: 4.5%; top: 4%;
  width: 91%; height: 92%;
  filter: saturate(1.15) contrast(1.05);
  opacity: 0;
  transform: scaleY(0.004);
  transition: opacity 0.25s, transform 0.45s cubic-bezier(.2,.9,.3,1.2);
}
.screen.on #display { opacity: 1; transform: none; }

.scanlines {
  position: absolute; inset: 0; pointer-events: none;
  /* faint phosphor glow; the real scanlines are drawn on the canvas */
  background: radial-gradient(ellipse at center, rgba(120,255,120,0.04), transparent 70%);
}
.glass {
  position: absolute; inset: 0; pointer-events: none;
  border-radius: inherit;
  background:
    radial-gradient(ellipse 70% 50% at 30% 18%, rgba(255,255,255,0.13), transparent 60%),
    radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.55) 100%);
  box-shadow: inset 0 0 18px rgba(0,0,0,0.8);
}

.poweron {
  position: absolute; inset: 0; margin: auto;
  width: max-content; height: max-content;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 14px 26px;
  font: 400 1.6rem VT323, monospace;
  color: var(--phosphor);
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(51,224,51,0.5);
  border-radius: 10px;
  cursor: pointer;
  text-shadow: 0 0 8px rgba(51,224,51,0.6);
}
.poweron small { font-size: 1.05rem; color: var(--ink-dim); text-shadow: none; }
.pw-icon { font-size: 2.2rem; line-height: 1; }
.poweron:hover { background: rgba(0,0,0,0.75); }
.screen.on .poweron { display: none; }

.panel {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10% 6%;
  border-radius: 14px;
  background: linear-gradient(180deg, #2c2c2e, #18181a);
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.7), 0 1px 0 rgba(255,255,255,0.1);
}
.brand {
  font: 600 0.7rem Inter, sans-serif; letter-spacing: 0.25em; color: #c9b38a;
  margin-bottom: 12%;
  text-align: center;
}
.knob {
  position: relative;
  width: 64%; aspect-ratio: 1;
  border-radius: 50%;
  border: 0; padding: 0;
  cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #6a6a6e, #232325 70%);
  box-shadow: 0 4px 8px rgba(0,0,0,0.6), inset 0 1px 1px rgba(255,255,255,0.3);
  transition: transform 0.3s;
}
.knob.small { width: 46%; }
.knob i {
  position: absolute; left: 50%; top: 8%; width: 8%; height: 34%; margin-left: -4%;
  background: #e8dcc4; border-radius: 3px;
}
.knob:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.knob-label { font-size: 0.6rem; letter-spacing: 0.2em; color: var(--ink-dim); margin-bottom: 8%; }
.grille {
  flex: 1; width: 80%; min-height: 40px;
  background: repeating-linear-gradient(180deg, #0c0c0d 0 3px, #2b2b2e 3px 6px);
  border-radius: 6px;
}
.tv-led {
  width: 8px; height: 8px; border-radius: 50%; margin-top: 8px;
  background: #3a1010;
}
.tv-led.on { background: #ff3b30; box-shadow: 0 0 8px #ff3b30; }

/* touch joystick on the TV: only on touch screens */
.touchpad { display: none; }
.stick {
  position: relative;
  width: 100%; max-width: 150px; aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #3a3a3d, #121214 72%);
  box-shadow: inset 0 3px 8px rgba(0,0,0,0.8), 0 1px 0 rgba(255,255,255,0.12);
  touch-action: none;
  cursor: pointer;
}
.stick .arrow {
  position: absolute; width: 0; height: 0;
  border: 7px solid transparent;
  opacity: 0.7;
}
.stick .arrow.up { top: 6%; left: 50%; margin-left: -7px; border-bottom: 10px solid #e8dcc4; border-top: 0; }
.stick .arrow.down { bottom: 6%; left: 50%; margin-left: -7px; border-top: 10px solid #e8dcc4; border-bottom: 0; }
.stick .arrow.left { left: 6%; top: 50%; margin-top: -7px; border-right: 10px solid #e8dcc4; border-left: 0; }
.stick .arrow.right { right: 6%; top: 50%; margin-top: -7px; border-left: 10px solid #e8dcc4; border-right: 0; }
.stick-top {
  position: absolute; left: 28%; top: 28%; width: 44%; height: 44%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #5a5a5e, #0e0e10 70%);
  box-shadow: 0 6px 10px rgba(0,0,0,0.7), inset 0 1px 1px rgba(255,255,255,0.25);
  transition: transform 0.06s;
  pointer-events: none;
}
.stick[data-dir="up"] .stick-top { transform: translateY(-26%); }
.stick[data-dir="down"] .stick-top { transform: translateY(26%); }
.stick[data-dir="left"] .stick-top { transform: translateX(-26%); }
.stick[data-dir="right"] .stick-top { transform: translateX(26%); }
.stick[data-dir] .arrow { opacity: 0.35; }
.pad-buttons {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  width: 100%; max-width: 170px;
}
.pad-key {
  min-height: 40px;
  border: 0; border-radius: 6px;
  font: 600 0.8rem Inter, sans-serif; color: #2a1606;
  background: linear-gradient(#ffb04a, var(--accent));
  box-shadow: 0 3px 0 #a85d12, 0 4px 6px rgba(0,0,0,0.5);
  touch-action: none;
  user-select: none; -webkit-user-select: none;
}
.pad-key.wide { grid-column: 1 / -1; }
.pad-key.down { transform: translateY(2px); box-shadow: 0 1px 0 #a85d12; }

html.touch .cabinet { grid-template-columns: 1fr 25%; }
html.touch .grille { display: none; }
html.touch .touchpad { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; margin-top: 6px; }

.feet { display: flex; justify-content: space-between; padding: 0 12%; }
.feet i { width: 70px; height: 14px; background: linear-gradient(#2a170b, #120a05); border-radius: 0 0 8px 8px; }

.cable {
  width: 6px; height: 40px; margin: 0 auto;
  background: linear-gradient(90deg, #111, #444, #111);
  border-radius: 3px;
}

/* ------------------------------------------------------------ computer */
.computer { width: min(100%, 900px); margin: 0 auto; }
.photo {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 24px 50px rgba(0,0,0,0.6);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.photo img { display: block; width: 100%; height: auto; }
.hotspots { position: absolute; inset: 0; }
.hotspot {
  position: absolute;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.08s, box-shadow 0.08s;
}
@media (hover: hover) { .hotspot:hover { box-shadow: 0 0 0 2px rgba(242,154,46,0.65); } }
.hotspot.down { background: rgba(0,0,0,0.35); box-shadow: inset 0 3px 6px rgba(0,0,0,0.6); }
.hotspot.latched { box-shadow: 0 0 0 2px var(--phosphor), 0 0 10px rgba(51,224,51,0.6); }
.hotspot.joy { border-radius: 50%; }
@media (hover: hover) { .hotspot.joy:hover { box-shadow: 0 0 0 2px rgba(242,154,46,0.5); } }
.joy-dir {
  position: absolute; width: 33%; height: 33%;
  border-radius: 50%;
}
.joy-dir.down { background: rgba(242,154,46,0.35); }

.power-led {
  position: absolute; border-radius: 50%;
  pointer-events: none;
  transition: background 0.2s, box-shadow 0.2s;
}
.power-led.on { background: rgba(255,40,30,0.85); box-shadow: 0 0 12px 4px rgba(255,40,30,0.7); }

/* ------------------------------------------------------------ controls */
.controls {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid #3a3027;
  border-radius: 14px;
}
.controls label, .controls button, .controls select {
  font: 600 0.95rem Inter, sans-serif;
  color: var(--ink);
}
.controls .picker {
  flex: 1 1 320px;
  display: flex; flex-direction: column; gap: 4px;
}
.controls .picker span {
  font: 400 1.3rem VT323, monospace; letter-spacing: 0.04em; color: var(--accent);
}
.controls select {
  width: 100%;
  min-height: 46px;
  font-size: 16px; /* 16px keeps iOS from zooming in on focus */
  border: 2px solid var(--accent) !important;
  background: #1a1410 !important;
}
.controls select, .controls button, .controls .file {
  background: var(--bg-2);
  border: 1px solid #4a3d31;
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 46px;
  cursor: pointer;
}
.controls button, .controls .file { align-self: flex-end; display: inline-flex; align-items: center; }
.controls button:hover, .controls .file:hover, .controls select:hover { border-color: var(--accent); }
.controls .file input { display: none; }
.record {
  flex-basis: 100%;
  margin: 2px 0 0;
  font-size: 0.9rem; color: var(--ink-dim);
}
.record b { color: var(--phosphor); font-family: VT323, monospace; font-size: 1.3rem; }
.record-item { white-space: nowrap; margin-right: 14px; }
.newrecord {
  width: min(100%, 1040px);
  margin: 12px auto 0;
  padding: 12px 14px;
  border: 2px solid var(--phosphor);
  border-radius: 12px;
  background: rgba(51,224,51,0.08);
  box-shadow: 0 0 20px rgba(51,224,51,0.25);
}
.newrecord[hidden] { display: none; }
.newrecord p { margin: 0 0 8px; }
.newrecord-row { display: flex; gap: 8px; }
.newrecord input {
  flex: 1; min-width: 0; min-height: 44px;
  font: 16px Inter, sans-serif; color: var(--ink);
  background: #111; border: 1px solid #4a3d31; border-radius: 8px; padding: 6px 10px;
}
.newrecord button {
  min-height: 44px; padding: 0 18px;
  font: 600 1rem Inter, sans-serif; color: #062006;
  background: var(--phosphor); border: 0; border-radius: 8px; cursor: pointer;
}
.shift-indicator {
  position: absolute; left: 2%; top: 3%;
  font: 1.2rem VT323, monospace; color: #111; background: var(--accent);
  padding: 2px 8px; border-radius: 4px;
  pointer-events: none;
}

.howto {
  max-width: 720px; margin: 32px auto 0;
  background: rgba(255,255,255,0.03);
  border: 1px solid #3a3027;
  border-radius: 14px;
  padding: 18px 22px;
}
.howto h2 { font: 400 1.8rem VT323, monospace; margin: 0 0 6px; color: var(--accent); }
.howto ol { padding-left: 20px; margin: 0 0 8px; }
.howto li { margin: 4px 0; }
.howto p { margin: 0; color: var(--ink-dim); }
kbd {
  font: 0.8rem Inter, sans-serif;
  background: #111; color: var(--ink);
  border: 1px solid #555; border-bottom-width: 3px;
  border-radius: 4px; padding: 0 5px;
}

footer { max-width: 720px; margin: 28px auto 0; font-size: 0.8rem; color: #8c806f; text-align: center; }
footer a { color: var(--ink-dim); }

/* tablet: use the full width */
@media (max-width: 1100px) {
  main { padding: 16px 12px 40px; }
  .tv, .computer, .controls { width: 100%; }
}

/* touch phones and portrait tablets: joystick row under the screen */
@media (max-width: 1100px) {
  html.touch .cabinet { grid-template-columns: 1fr; gap: 10px; }
  html.touch .panel { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; padding: 8px; gap: 14px; }
  html.touch .knob { width: 44px; } html.touch .knob.small { width: 36px; }
  html.touch .knob-label, html.touch .brand { display: none; }
  html.touch .tv-led { margin: 0; }
  html.touch .touchpad { order: 2; flex-basis: 100%; flex-direction: row; justify-content: space-evenly; align-items: center; margin: 0; }
  html.touch .stick { width: 40%; max-width: 190px; }
  html.touch .pad-buttons { width: 48%; max-width: 260px; gap: 8px; }
  html.touch .pad-key { min-height: 50px; font-size: 1rem; }
}

/* phone: TV and keyboard run edge to edge */
@media (max-width: 700px) {
  main { padding: 12px 0 32px; }
  header, .howto, footer { margin-left: 12px; margin-right: 12px; }
  header { margin-bottom: 12px; }
  .sub { font-size: 0.85rem; }
  .controls { border-radius: 0; border-left: 0; border-right: 0; gap: 8px; padding: 10px 12px; }
  .controls .picker { flex-basis: 100%; }
  .controls button, .controls .file { flex: 1 1 0; justify-content: center; padding: 8px 6px; font-size: 0.85rem; }
  .tv { margin-top: 12px; }
  .antenna, .feet { display: none; }
  .cabinet { grid-template-columns: 1fr; gap: 8px; padding: 10px; border-radius: 0; }
  .bezel { padding: 6px; border-radius: 12px; }
  .panel { flex-direction: row; justify-content: center; padding: 6px; gap: 14px; }
  .knob { width: 40px; } .knob.small { width: 32px; }
  .knob-label, .brand, .grille { display: none; }
  .tv-led { margin: 0; }
  .cable { height: 14px; }
  .photo { border-radius: 0; }
  .howto { padding: 14px 16px; }
}

.howto p + p { margin-top: 8px; }

/* ------------------------------------------------------------ fullscreen */
.fs-exit { display: none; }
body.fs-open { overflow: hidden; }
.tv.fs {
  position: fixed; inset: 0; z-index: 100;
  width: 100%; max-width: none; margin: 0;
  display: flex; align-items: center; justify-content: center;
  background: #000;
}
.tv.fs .antenna, .tv.fs .feet { display: none; }
.tv.fs .cabinet {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  width: 100%; height: 100%;
  padding: 0; border-radius: 0;
  background: none; box-shadow: none;
}
.tv.fs .bezel { padding: 0; background: none; box-shadow: none; }
.tv.fs .screen { width: min(100vw, calc(100vh * 4 / 3)); border-radius: 3% / 4%; }
.tv.fs .panel { display: none; }
.tv.fs .fs-exit {
  display: block;
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 44px; height: 44px;
  font-size: 1.2rem; color: var(--ink);
  background: rgba(40,40,40,0.7); border: 1px solid #555; border-radius: 50%;
  cursor: pointer;
}

/* touch: keep the joystick and buttons next to the picture */
html.touch .tv.fs .panel {
  display: flex; flex: none;
  padding: 0; background: none; box-shadow: none;
}
html.touch .tv.fs .knob, html.touch .tv.fs .tv-led,
html.touch .tv.fs .brand, html.touch .tv.fs .knob-label { display: none; }
html.touch .tv.fs .touchpad { display: flex; margin: 0; }
@media (orientation: landscape) {
  html.touch .tv.fs .cabinet { flex-direction: row; }
  html.touch .tv.fs .screen { width: min(calc(100vw - 250px), calc(100vh * 4 / 3)); }
  html.touch .tv.fs .panel { width: 210px; }
  html.touch .tv.fs .touchpad { flex-direction: column; gap: 18px; }
  html.touch .tv.fs .stick { width: 170px; max-width: none; }
  html.touch .tv.fs .pad-buttons { width: 190px; max-width: none; }
}
@media (orientation: portrait) {
  html.touch .tv.fs .cabinet { flex-direction: column; gap: 14px; }
  html.touch .tv.fs .screen { width: min(100vw, calc((100vh - 230px) * 4 / 3)); }
  html.touch .tv.fs .panel { width: 100%; }
  html.touch .tv.fs .touchpad { flex-direction: row; justify-content: space-evenly; }
  html.touch .tv.fs .stick { width: 40%; max-width: 190px; }
}
