:root {
  --ink: #e6e0d4;
  --dim: #8d887c;
  --amber: #ffb000;
  --crt: #ffbf5a;
  --green: #3dff86;
  --red: #ff3b30;
  --panel: #2a2e32;
  --void: #0c0e10;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  max-width: 100%;
  background: var(--void);
  color: var(--ink);
  font-family: "Avenir Next Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

button, .knob, .track, .yoke { touch-action: none; }

.pit {
  height: 100dvh;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(128px, 24dvh) minmax(118px, 22dvh) minmax(0, 1fr);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  background:
    radial-gradient(120% 80% at 50% 0%, #1a1e22 0%, #0c0e10 55%);
}

.bezel {
  position: relative;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.035) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #4e555c, #2c3238 38%, #1b1f23);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), inset 0 -8px 16px rgba(0,0,0,.35);
}

.bezel::before, .bezel::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c5c8cc, #3a3e42 42%, #111 70%);
  box-shadow: 0 0 0 1px #000;
  z-index: 3;
}
.bezel::before { top: 5px; left: 5px; }
.bezel::after { top: 5px; right: 5px; }

.glass-wrap { overflow: hidden; }
.glass-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.hud {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 16px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  text-shadow: 0 2px 8px #000;
}
.hud b {
  display: block;
  font-family: "SF Mono", "Cascadia Mono", ui-monospace, monospace;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: 0.04em;
  line-height: 1;
}
.hud span {
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.18em;
}
.lamp {
  position: absolute;
  top: 46px;
  right: 16px;
  bottom: auto;
  left: auto;
  width: 12px;
  height: 12px;
  margin: 0;
  border-radius: 50%;
  background: #2a140f;
  box-shadow: inset 0 0 0 2px #1a0b08, 0 0 0 3px #111;
}
.lamp.on {
  background: var(--red);
  box-shadow: 0 0 12px var(--red), inset 0 0 4px #fff;
  animation: blink 0.35s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0.35; } }

.plate {
  position: absolute;
  left: 14px;
  bottom: 8px;
  font-size: 12px;
  letter-spacing: 0.22em;
  color: rgba(230, 224, 212, 0.72);
  text-shadow: 0 1px 2px #000;
}
.plate em { font-style: normal; color: var(--amber); letter-spacing: 0.14em; }

.radio {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid #000;
  border-bottom: 1px solid #000;
}
.comm { display: flex; flex-direction: column; align-items: center; justify-content: space-between; }
.tag {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  max-width: 100%;
}
.knob {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background:
    conic-gradient(from 210deg, #1a1c1e, #6a7178, #1a1c1e 70%, #111);
  box-shadow: inset 0 0 0 3px #0d0e10, 0 4px 0 #000;
  position: relative;
}
.knob::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 6px;
  width: 3px;
  height: 12px;
  margin-left: -1.5px;
  background: var(--amber);
  border-radius: 2px;
  transform-origin: center 17px;
}
.freq {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--amber);
  min-height: 14px;
}
.crt {
  background: #120d07;
  border-radius: 4px;
  box-shadow: inset 0 0 0 2px #070503, inset 0 0 24px rgba(255, 160, 40, 0.08);
  color: var(--crt);
  font-family: ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.35;
  padding: 6px 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  text-shadow: 0 0 6px rgba(255, 176, 60, 0.45);
}
.crt .gc { color: var(--crt); }
.crt .call { color: #fff; }
.crt .live { font-size: 14px; }
.crt .call.live { font-size: 15px; color: #fff; }
.crt div:not(.live) { opacity: 0.45; font-size: 11px; }
.crt .me { color: #fff6e4; }
.crt .bad { color: #ff7a55; }
.crt.off { color: transparent; text-shadow: none; }

.pedestal {
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.15fr) minmax(0, 0.72fr) minmax(0, 1.35fr);
  gap: 6px;
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
}
.lever-box, .yoke-box, .stack {
  min-height: 0;
  min-width: 0;
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.twins {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  justify-content: center;
  gap: 5px;
}
.gang {
  display: flex;
  gap: 3px;
  min-height: 0;
}
.track {
  position: relative;
  flex: 1;
  width: 28px;
  min-height: 0;
  border-radius: 8px;
  background: linear-gradient(#0c0d0e, #1a1d20);
  box-shadow: inset 0 0 0 2px #000, inset 0 8px 12px rgba(0,0,0,.6);
}
.tag.pair {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0 6px;
}
.handle {
  position: absolute;
  left: 4px;
  right: 4px;
  height: 22px;
  border-radius: 4px;
  background: linear-gradient(#d7dbe0, #6d747c 45%, #2c3136);
  box-shadow: 0 3px 0 #000;
}
.flaps { width: 54px; }
.flaps .notch {
  position: absolute;
  left: 0;
  right: 0;
  font-size: 9px;
  letter-spacing: 0.08em;
  color: #8b93a0;
  text-align: right;
  padding-right: 2px;
}
.flaps .notch:nth-child(1) { top: 0; }
.flaps .notch:nth-child(2) { top: 16.5%; }
.flaps .notch:nth-child(3) { top: 33%; }
.flaps .notch:nth-child(4) { top: 49.5%; }
.flaps .notch:nth-child(5) { top: 66%; }
.flaps .notch:nth-child(6) { top: 82.5%; }
.flaps .handle { height: 14px; width: 16px; left: 2px; right: auto; z-index: 1; }

.yoke {
  flex: 1;
  width: 100%;
  display: grid;
  place-items: center;
}
.wheel {
  width: min(112px, 100%);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, transparent 38%, #1a1d20 39%, #3a4046 48%, #111 62%, #2a2e32 64%, #0c0d0e 72%, transparent 73%);
  box-shadow: inset 0 0 0 8px #4a5158, 0 8px 0 #050607;
  position: relative;
}
.wheel::before, .wheel::after {
  content: "";
  position: absolute;
  background: #3a4046;
  border-radius: 4px;
}
.wheel::before { left: 18%; right: 18%; top: 46%; height: 8%; }
.wheel::after { top: 22%; bottom: 22%; left: 46%; width: 8%; }
.ap-disc {
  position: absolute;
  top: 38%;
  z-index: 2;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  font-size: 8px;
  letter-spacing: 0;
  color: #ffd2cc;
  background: #4a1814;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25), 0 2px 0 #000;
}
#ap { left: 7%; }
#ap2 { right: 7%; }
.ap-disc.on {
  background: #ff2d1f;
  color: #fff;
  box-shadow: 0 0 10px #ff2d1f, inset 0 1px 0 rgba(255,255,255,.4);
}

.stack {
  align-items: stretch;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr) minmax(0, 0.9fr) auto;
  gap: 4px;
}
#trim { grid-column: 1; grid-row: 1; }
#gear { grid-column: 2; grid-row: 1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; align-content: end; }
#gear .tag { grid-column: 1 / -1; text-align: center; }
#boards { grid-column: 3; grid-row: 1; }
#park { grid-column: 4; grid-row: 1; }
#lights { grid-column: 1; grid-row: 2; }
#beacon { grid-column: 2; grid-row: 2; }
#strobe { grid-column: 3; grid-row: 2; }
#brakes { grid-column: 4; grid-row: 2; }
#xpdr { grid-column: 1 / -1; grid-row: 3; }
.trim {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  background: #14181c;
  border: 1px solid #000;
  border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), 0 3px 0 #050607;
  touch-action: none;
}
.trim i {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, #d5dbe2 0 9deg, #2a3036 9deg 20deg);
  box-shadow: inset 0 0 0 7px #14181c, 0 2px 0 #000;
}
.stack > button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  min-height: 0;
}
.stack > button b {
  display: block;
  width: 14px;
  height: 22px;
  border-radius: 3px;
  background: linear-gradient(#8d949c, #343a40);
  border: 1px solid #000;
  transform: rotate(22deg);
  transform-origin: 50% 90%;
}
.stack > button.on b, #boards.on b, #park.hot b, #brakes.hot b {
  transform: rotate(-22deg);
}
#lights.on b { background: #f4f7ff; box-shadow: 0 0 8px #fff; }
#beacon.on b { background: #ff5a3c; box-shadow: 0 0 8px #ff5a3c; }
#strobe.on b { background: #e7f0ff; box-shadow: 0 0 8px #fff; }
#boards.on b { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
#park.hot b {
  width: 26px;
  height: 8px;
  margin-bottom: 4px;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}
#park b {
  width: 26px;
  height: 8px;
  margin-bottom: 10px;
  border-radius: 2px;
  transform: none;
  background: #c5ccd2;
  box-shadow: 0 8px 0 #3a4046, 0 14px 0 #22262a;
}
#brakes b {
  width: 70%;
  height: 12px;
  border-radius: 6px;
  transform: none;
  background: #3a4046;
}
#brakes.hot b { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
button {
  font: inherit;
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  background: #1a1e22;
  border: 1px solid #000;
  border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), 0 3px 0 #050607;
  padding: 4px;
}
button:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 1px 0 #050607; }
.gear { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px; align-items: end; }
.gear .tag, .boards .tag, .lights .tag { grid-column: 1 / -1; }
.gear i {
  height: 10px;
  border-radius: 50%;
  background: #1a120f;
  box-shadow: inset 0 0 0 1px #000;
}
.gear.down i { background: var(--green); box-shadow: 0 0 8px var(--green); }
.xpdr {
  display: grid;
  grid-template-columns: auto repeat(4, minmax(0, 1fr));
  gap: 3px;
  align-items: center;
  min-width: 0;
}
.xpdr .tag { letter-spacing: 0.12em; }
.xpdr button {
  font-family: ui-monospace, monospace;
  font-size: clamp(14px, 4.2vw, 18px);
  color: var(--amber);
  min-height: 36px;
  padding: 4px 0;
}
.pedal { letter-spacing: 0.06em; font-size: 12px; min-height: 36px; }
.pedal.hot { background: #3a2a16; color: var(--amber); }

#reset {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 5;
  letter-spacing: 0.16em;
  background: #3a1210;
  color: #ffd0c8;
  padding: 10px 14px;
}

body.shake .pit { animation: shake 0.18s linear; }
@keyframes shake {
  25% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
}
body.dead .glass-wrap { box-shadow: inset 0 0 80px rgba(180, 0, 0, 0.45); }
body.down .plate em { color: var(--green); }

@media (max-width: 560px) {
  .pedestal {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.05fr) minmax(0, 0.7fr);
    grid-template-rows: minmax(132px, 1.15fr) minmax(148px, 0.95fr);
  }
  .stack {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }
  .tag { letter-spacing: 0.04em; }
  .wheel { width: min(108px, 86%); }
  .hud b { font-size: 22px; }
  .ap-disc { width: 26px; height: 26px; font-size: 9px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .pit {
    grid-template-columns: 1.25fr 0.9fr;
    grid-template-rows: 1fr 168px;
  }
  .glass-wrap { grid-column: 1; grid-row: 1; }
  .radio { grid-column: 2; grid-row: 1; border: 0; }
  .pedestal {
    grid-column: 1 / 3;
    grid-row: 2;
    grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr) minmax(0, 0.7fr) minmax(0, 1.45fr);
    grid-template-rows: minmax(0, 1fr);
  }
  .stack {
    grid-column: auto;
    grid-row: auto;
    width: auto;
    min-height: 0;
    overflow: hidden;
    gap: 3px;
  }
  .xpdr button, .stack > button, .trim { min-height: 0; padding-top: 1px; padding-bottom: 1px; }
  .trim i { width: 26px; height: 26px; }
  .hud b { font-size: 22px; }
  .wheel { width: 78px; }
}
