@font-face {
  font-family: systemMono;
  src: local("Menlo"), local("Consolas"), local("Courier New");
}

:root {
  --green: #8effc8;
  --green-2: #35f59c;
  --amber: #ffb24a;
  --red: #ff4c4c;
  --bg: #04110e;
  --panel: rgba(7, 24, 23, 0.70);
  --line: rgba(142, 255, 200, 0.78);
  --dim: rgba(142, 255, 200, 0.52);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(circle at 50% 15%, #15392f 0%, #061916 42%, #020605 100%);
  color: var(--green);
  font-family: systemMono, monospace;
  overflow: hidden;
  text-shadow: 0 0 8px rgba(142,255,200,.7);
}

.crt-noise,
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}
.crt-noise {
  opacity: .12;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 140 140' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
  mix-blend-mode: screen;
  animation: noiseMove .5s steps(2) infinite;
}
.scanlines {
  opacity: .26;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,.08) 0, rgba(255,255,255,.08) 1px, transparent 2px, transparent 5px);
}

.hud {
  width: 100vw;
  height: 100vh;
  padding: 22px 26px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transform: perspective(1100px) rotateX(.5deg);
  filter: drop-shadow(0 0 12px rgba(53,245,156,.28));
}

.topbar,
.controls,
.panel {
  border: 2px solid var(--line);
  background: var(--panel);
  box-shadow: inset 0 0 18px rgba(53,245,156,.14), 0 0 18px rgba(53,245,156,.14);
}

.topbar {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  letter-spacing: 2px;
  font-weight: 800;
  margin-bottom: 0;
  flex: 0 0 54px;
}
.brand { font-size: clamp(16px, 2vw, 28px); }
.status-strip { display: flex; align-items: center; gap: 12px; }
.clock { margin-left: 18px; }
.dot {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--green-2);
  box-shadow: 0 0 12px var(--green-2), 0 0 26px var(--green-2);
  animation: pulse 1.2s infinite;
}
.dot.idle { margin-left: auto; }

.grid {
  display: grid;
  grid-template-columns: minmax(260px, 23vw) 1fr minmax(300px, 25vw);
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
}
.left-column,
.right-column,
.center-column {
  display: grid;
  gap: 14px;
  min-height: 0;
}
.left-column { grid-template-rows: minmax(0, 1fr) minmax(0, 1fr) minmax(0, .52fr); }
.right-column { grid-template-rows: minmax(0, 1fr) minmax(0, 1.18fr); }
.center-column { grid-template-rows: minmax(0, 1fr) 168px; }
.panel { padding: 16px 18px; min-height: 0; overflow: hidden; }
.panel h2 {
  margin: 0 0 12px;
  font-size: clamp(17px, 1.8vw, 28px);
  letter-spacing: 4px;
}
p { margin: 7px 0; font-size: clamp(13px, 1.1vw, 22px); white-space: pre; }
b { color: #d7ffe9; }
.online { color: var(--green-2); }
.small p { font-size: 14px; }
.boot-log { font-size: clamp(11px, .9vw, 15px); line-height: 1.35; color: rgba(215,255,233,.85); }
.boot-log div { opacity: .88; }

.schematic-panel {
  padding: 12px;
  position: relative;
  background:
    linear-gradient(rgba(142,255,200,.06), rgba(142,255,200,.02)),
    radial-gradient(circle at 50% 45%, rgba(53,245,156,.06), transparent 65%),
    var(--panel);
}
.schematic-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.schematic-stage {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}
.schematic-image {
  display: block;
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 0 16px rgba(53,245,156,.30)) brightness(1.06) contrast(1.04);
}
.cyclotron-led-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.cyclotron-led {
  position: absolute;
  width: 4.8%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%) scale(.72);
  background: radial-gradient(circle at 35% 35%, #e8fff4 0%, #aaffd6 30%, #57ff9b 58%, rgba(87,255,155,.48) 70%, rgba(87,255,155,0) 100%);
  box-shadow:
    0 0 10px rgba(87,255,155,.45),
    0 0 22px rgba(87,255,155,.25);
  transition: opacity .18s linear, transform .18s linear, box-shadow .18s linear;
}
.cyclotron-led.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  box-shadow:
    0 0 12px rgba(232,255,244,.95),
    0 0 26px rgba(87,255,155,.9),
    0 0 42px rgba(87,255,155,.55);
  animation: cyclotronLedBlink .42s ease-in-out infinite;
}
.cyclotron-led.trail {
  opacity: .28;
  transform: translate(-50%, -50%) scale(.86);
}
.cyclotron-led.led-1 { left: 41.8%; top: 68.9%; }
.cyclotron-led.led-2 { left: 58.2%; top: 68.9%; }
.cyclotron-led.led-3 { left: 54.8%; top: 80.0%; }
.cyclotron-led.led-4 { left: 45.2%; top: 80.0%; }
body.shutdown .cyclotron-led,
body.shutdown .cyclotron-led.active,
body.shutdown .cyclotron-led.trail {
  opacity: 0 !important;
  animation: none;
}

.waveform-panel { padding: 8px 10px 10px; }
.mini-status {
  height: 30px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  font-weight: 800;
}
.mini-status span:nth-child(3) { margin-left: auto; margin-right: auto; }
#waveCanvas { width: 100%; height: 148px; border-top: 1px solid rgba(142,255,200,.45); }

.crt-cycle {
  margin: 4px 0 18px;
  display: grid;
  gap: 7px;
  max-width: 230px;
}
.crt-row {
  display: grid;
  grid-template-columns: 92px 24px;
  align-items: center;
  min-height: 28px;
  font-size: clamp(16px, 1.25vw, 23px);
  letter-spacing: 1px;
  color: rgba(142, 255, 200, .62);
}
.crt-row span {
  white-space: nowrap;
}
.crt-row.active {
  color: var(--green);
  text-shadow: 0 0 8px rgba(142,255,200,.85), 0 0 18px rgba(53,245,156,.45);
}
.crt-cursor {
  width: 18px;
  height: 22px;
  display: inline-block;
  opacity: 0;
  background: linear-gradient(to bottom, #d9fff0, var(--green-2));
  box-shadow: 0 0 8px var(--green-2), 0 0 22px rgba(53,245,156,.85);
}
.crt-row.active .crt-cursor {
  opacity: 1;
  animation: cursorBlink .42s steps(1) infinite;
}
body.shutdown .crt-row.active .crt-cursor {
  opacity: .18;
  animation: none;
}

.controls {
  height: 48px;
  margin-top: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 6px;
  flex: 0 0 48px;
  overflow-x: auto;
}
button {
  height: 34px;
  background: rgba(9, 31, 27, .9);
  border: 1px solid var(--line);
  color: var(--green);
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: 1px;
  padding: 0 12px;
  text-shadow: inherit;
}
button:hover { background: rgba(53,245,156,.16); }

body.overload { --green: #ff9b7a; --green-2: #ff4545; --line: rgba(255,105,78,.86); }
body.stream { --green: #8edcff; --green-2: #41bfff; --line: rgba(142,220,255,.82); }
body.shutdown { filter: brightness(.5); }

@keyframes pulse { 50% { opacity: .35; transform: scale(.72); } }
@keyframes rotate { to { transform: rotate(360deg); } }
@keyframes flow { to { stroke-dashoffset: -72; } }
@keyframes cycloPulse { 50% { fill: rgba(53,245,156,.55); filter: drop-shadow(0 0 10px var(--green-2)); } }
@keyframes cursorBlink { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
@keyframes cyclotronLedBlink { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.3); } }
@keyframes noiseMove { 0% { transform: translate(0,0); } 100% { transform: translate(3px,-2px); } }

@media (max-width: 1100px) {
  body { overflow: auto; }
  .hud { height: auto; min-height: 100vh; }
  .grid { grid-template-columns: 1fr; flex: 0 0 auto; }
  .center-column { grid-template-rows: minmax(420px, 68vh) 190px; }
  .left-column, .right-column { grid-template-rows: auto; }
  .controls { flex-wrap: wrap; height: auto; flex: 0 0 auto; }
}


/* --- Cyclotron LED overlay + calibration mode --- */
.schematic-stage {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

.cyclotron-led-overlay,
.calibration-points {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.cyclotron-led {
  position: absolute;
  width: 4.8%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%) scale(.72);
  background: radial-gradient(circle at 35% 35%, #e8fff4 0%, #aaffd6 30%, #57ff9b 58%, rgba(87,255,155,.48) 70%, rgba(87,255,155,0) 100%);
  box-shadow:
    0 0 10px rgba(87,255,155,.45),
    0 0 22px rgba(87,255,155,.25);
  transition: opacity .18s linear, transform .18s linear, box-shadow .18s linear, left .08s linear, top .08s linear;
}

.cyclotron-led.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  box-shadow:
    0 0 12px rgba(232,255,244,.95),
    0 0 26px rgba(87,255,155,.9),
    0 0 42px rgba(87,255,155,.55);
  animation: cyclotronLedBlink .42s ease-in-out infinite;
}

.cyclotron-led.trail {
  opacity: .28;
  transform: translate(-50%, -50%) scale(.86);
}

body.shutdown .cyclotron-led,
body.shutdown .cyclotron-led.active,
body.shutdown .cyclotron-led.trail {
  opacity: 0 !important;
  animation: none;
}

.calibration-points {
  display: none;
  z-index: 5;
  pointer-events: auto;
}

body.calibration .calibration-points {
  display: block;
}

body.calibration .cyclotron-led {
  opacity: .18;
}

.cal-point {
  position: absolute;
  width: 26px;
  height: 26px;
  transform: translate(-50%, -50%);
  border: 2px solid var(--green);
  border-radius: 50%;
  background: rgba(53,245,156,.12);
  box-shadow: 0 0 10px rgba(53,245,156,.65), 0 0 22px rgba(53,245,156,.28);
  cursor: grab;
  touch-action: none;
}

.cal-point:active {
  cursor: grabbing;
}

.cal-point::before,
.cal-point::after {
  content: "";
  position: absolute;
  background: var(--green);
  box-shadow: 0 0 8px rgba(142,255,200,.8);
}

.cal-point::before {
  left: 50%;
  top: -9px;
  width: 2px;
  height: 42px;
  transform: translateX(-50%);
}

.cal-point::after {
  top: 50%;
  left: -9px;
  width: 42px;
  height: 2px;
  transform: translateY(-50%);
}

.cal-point span {
  position: absolute;
  left: 30px;
  top: -3px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--green);
  background: rgba(2, 10, 8, .82);
  border: 1px solid rgba(142,255,200,.55);
  padding: 2px 6px;
  text-shadow: 0 0 8px rgba(142,255,200,.8);
}

.calibration-panel {
  position: absolute;
  left: 18px;
  bottom: 18px;
  display: none;
  max-width: calc(100% - 36px);
  padding: 10px 12px;
  border: 1px solid rgba(142,255,200,.72);
  background: rgba(2, 10, 8, .86);
  box-shadow: inset 0 0 12px rgba(53,245,156,.12), 0 0 16px rgba(53,245,156,.18);
  font-size: 13px;
  line-height: 1.45;
  z-index: 10;
}

.calibration-panel span {
  display: block;
}

body.calibration .calibration-panel {
  display: block;
}

@keyframes cyclotronLedBlink {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
}


/* Calibration labels are slightly smaller so they do not cover the schematic too much. */
.cal-point span {
  font-size: clamp(10px, .75vw, 12px) !important;
  padding: 1px 5px !important;
}


/* --- Compact calibration toolbar: does not cover the cyclotron LEDs --- */
.calibration-panel {
  left: 18px !important;
  right: auto !important;
  top: 18px !important;
  bottom: auto !important;
  width: auto !important;
  max-width: calc(100% - 36px) !important;
  padding: 6px 8px !important;
  display: none;
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(142,255,200,.72);
  background: rgba(2, 10, 8, .58) !important;
  box-shadow: inset 0 0 10px rgba(53,245,156,.10), 0 0 14px rgba(53,245,156,.16);
  font-size: clamp(10px, .72vw, 12px) !important;
  line-height: 1.1 !important;
  z-index: 10;
  backdrop-filter: blur(2px);
}

.calibration-panel b,
.calibration-panel span {
  display: inline !important;
  white-space: nowrap;
  margin: 0 !important;
}

body.calibration .calibration-panel {
  display: flex !important;
}


/* --- Feature pack: cinematic boot, stronger modes, idle saver, mobile/tablet --- */
.boot-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 40%, rgba(53,245,156,.16), transparent 42%),
    linear-gradient(rgba(3,12,10,.92), rgba(1,5,4,.98));
  color: var(--green);
  text-shadow: 0 0 10px rgba(142,255,200,.8);
  transition: opacity .7s ease, visibility .7s ease;
}

.boot-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-box {
  width: min(760px, calc(100vw - 44px));
  border: 2px solid var(--line);
  padding: 28px;
  background: rgba(2, 12, 10, .78);
  box-shadow: inset 0 0 24px rgba(53,245,156,.18), 0 0 38px rgba(53,245,156,.16);
}

.boot-title {
  font-size: clamp(22px, 3vw, 38px);
  font-weight: 900;
  letter-spacing: 3px;
  margin-bottom: 6px;
}

.boot-subtitle {
  font-size: clamp(12px, 1.3vw, 17px);
  color: rgba(142,255,200,.72);
  margin-bottom: 22px;
  letter-spacing: 2px;
}

.boot-lines {
  min-height: 235px;
  font-size: clamp(13px, 1.25vw, 18px);
  line-height: 1.55;
}

.boot-lines div {
  opacity: .92;
  animation: bootLineIn .18s ease-out;
}

.boot-lines b {
  color: var(--green-2);
}

.boot-progress {
  height: 14px;
  border: 1px solid rgba(142,255,200,.65);
  margin-top: 18px;
  background: rgba(142,255,200,.06);
  overflow: hidden;
}

.boot-progress i {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, rgba(53,245,156,.35), var(--green-2), rgba(215,255,233,.9));
  box-shadow: 0 0 18px rgba(53,245,156,.72);
  transition: width .22s linear;
}

.boot-final {
  margin-top: 12px;
  font-size: 13px;
  letter-spacing: 2px;
  opacity: .52;
}

.hud.booting .panel,
.hud.booting .topbar,
.hud.booting .controls {
  animation: panelWake .9s steps(2) infinite;
}

/* Stronger mode moods */
body.idle .schematic-panel {
  animation: idleBreath 5.5s ease-in-out infinite;
}

body.stream {
  --green: #8edcff;
  --green-2: #41bfff;
  --line: rgba(142,220,255,.82);
}

body.stream .schematic-panel,
body.stream .waveform-panel {
  box-shadow: inset 0 0 28px rgba(65,191,255,.22), 0 0 28px rgba(65,191,255,.18);
}

body.stream .cyclotron-led.active {
  animation-duration: .22s;
  box-shadow:
    0 0 14px rgba(232,250,255,.98),
    0 0 30px rgba(65,191,255,.95),
    0 0 56px rgba(65,191,255,.62);
}

body.stream .scanlines {
  opacity: .34;
}

body.overload {
  --green: #ff9b7a;
  --green-2: #ff4545;
  --line: rgba(255,105,78,.86);
  animation: overloadShake .16s steps(2) infinite;
}

body.overload .panel,
body.overload .topbar,
body.overload .controls {
  box-shadow: inset 0 0 24px rgba(255,69,69,.22), 0 0 30px rgba(255,69,69,.2);
}

body.overload .cyclotron-led.active {
  background: radial-gradient(circle at 35% 35%, #fff0e8 0%, #ffb199 28%, #ff4545 58%, rgba(255,69,69,.4) 72%, rgba(255,69,69,0) 100%);
  animation-duration: .18s;
}

body.overload::after {
  content: "WARNING // CONTAINMENT FIELD UNSTABLE";
  position: fixed;
  left: 50%;
  top: 92px;
  transform: translateX(-50%);
  z-index: 30;
  padding: 6px 14px;
  border: 1px solid rgba(255,155,122,.8);
  background: rgba(35, 5, 3, .72);
  color: #ffd2c2;
  font-family: systemMono, monospace;
  font-weight: 900;
  letter-spacing: 2px;
  text-shadow: 0 0 10px rgba(255,69,69,.9);
  animation: warningBlink .55s steps(1) infinite;
}

body.shutdown {
  filter: brightness(.5);
}

body.shutdown .schematic-image,
body.shutdown #waveCanvas {
  opacity: .28;
}

/* Real idle saver */
.idle-saver {
  position: fixed;
  inset: 0;
  z-index: 35;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  background:
    linear-gradient(transparent, rgba(53,245,156,.08), transparent),
    radial-gradient(circle at var(--idle-x, 40%) var(--idle-y, 40%), rgba(53,245,156,.11), transparent 26%);
  transition: opacity .9s ease, visibility .9s ease;
}

body.idle-saver-on .idle-saver {
  opacity: 1;
  visibility: visible;
}

body.idle-saver-on .hud {
  animation: saverDrift 12s ease-in-out infinite;
}

.idle-scan {
  position: absolute;
  left: 4vw;
  top: 16vh;
  padding: 8px 12px;
  border: 1px solid rgba(142,255,200,.42);
  background: rgba(2, 10, 8, .45);
  font-size: clamp(11px, 1vw, 15px);
  letter-spacing: 2px;
  animation: saverTextMove 18s linear infinite;
}

/* Tablet / mobile prop behavior */
body.prop-mode .controls {
  display: none;
}

body.prop-mode .hud {
  padding-bottom: 22px;
}

body.prop-mode {
  cursor: none;
}

@media (pointer: coarse) {
  button {
    min-height: 44px;
    padding: 0 14px;
  }

  .controls {
    height: auto;
    min-height: 58px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .cal-point {
    width: 34px;
    height: 34px;
  }
}

@media (max-width: 900px) {
  .hud {
    padding: 12px;
    gap: 10px;
    transform: none;
  }

  .topbar {
    height: auto;
    min-height: 52px;
    flex: 0 0 auto;
    gap: 8px;
    flex-wrap: wrap;
  }

  .brand {
    font-size: clamp(15px, 4.8vw, 24px);
  }

  .status-strip {
    font-size: 13px;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .center-column {
    grid-template-rows: minmax(420px, 64vh) 160px;
  }

  .left-column,
  .right-column {
    grid-template-rows: auto;
  }

  .panel {
    padding: 12px;
  }

  .controls {
    position: sticky;
    bottom: 0;
    z-index: 25;
    background: rgba(2, 12, 10, .92);
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  .center-column {
    grid-template-rows: minmax(470px, 70vh) 160px;
  }
}

@keyframes bootLineIn {
  from { opacity: 0; transform: translateX(-8px); }
}

@keyframes panelWake {
  50% { opacity: .82; filter: brightness(1.18); }
}

@keyframes idleBreath {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.10); }
}

@keyframes overloadShake {
  50% { transform: translate(.8px, -.6px); }
}

@keyframes warningBlink {
  50% { opacity: .28; }
}

@keyframes saverDrift {
  0%, 100% { transform: perspective(1100px) rotateX(.5deg) translate(0,0); }
  25% { transform: perspective(1100px) rotateX(.5deg) translate(5px,-3px); }
  50% { transform: perspective(1100px) rotateX(.5deg) translate(-4px,4px); }
  75% { transform: perspective(1100px) rotateX(.5deg) translate(3px,3px); }
}

@keyframes saverTextMove {
  0% { transform: translate(0,0); opacity: .2; }
  10%, 80% { opacity: .72; }
  100% { transform: translate(46vw, 58vh); opacity: .18; }
}


/* --- Audio button --- */
#audioToggleBtn.audio-on {
  background: rgba(53,245,156,.18);
  box-shadow: inset 0 0 12px rgba(53,245,156,.18), 0 0 14px rgba(53,245,156,.16);
}

body.overload #audioToggleBtn.audio-on {
  background: rgba(255,69,69,.18);
}


/* --- Mobile/public enhancement pack --- */

/* Landscape recommendation for mobile portrait */
.rotate-notice {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 40%, rgba(53,245,156,.18), transparent 45%),
    rgba(1, 6, 5, .92);
  color: var(--green);
  text-align: center;
  text-shadow: 0 0 10px rgba(142,255,200,.8);
}

.rotate-notice div {
  border: 2px solid var(--line);
  background: rgba(2, 12, 10, .82);
  box-shadow: inset 0 0 20px rgba(53,245,156,.15), 0 0 28px rgba(53,245,156,.18);
  padding: 22px;
  max-width: 420px;
}

.rotate-notice b {
  display: block;
  margin-bottom: 10px;
  font-size: clamp(20px, 6vw, 34px);
  letter-spacing: 3px;
}

.rotate-notice span {
  display: block;
  font-size: clamp(13px, 3.5vw, 18px);
  letter-spacing: 1px;
}

/* Keep it helpful, not blocking: after a tap the user can still use portrait mode. */
body.rotate-dismissed .rotate-notice {
  display: none !important;
}

/* Public and prop clean modes */
body.public-mode .controls,
body.public-mode .calibration-panel,
body.public-mode .calibration-points {
  display: none !important;
}

body.public-mode .hud {
  padding-bottom: 18px;
}

body.public-mode .boot-final {
  display: none;
}

/* Compact public view on portrait mobile: feature the pack instead of squeezing full dashboard */
@media (max-width: 760px) and (orientation: portrait) {
  body:not(.rotate-dismissed) .rotate-notice {
    display: grid;
  }

  body.public-mode .grid {
    display: block;
  }

  body.public-mode .left-column,
  body.public-mode .right-column,
  body.public-mode .waveform-panel {
    display: none;
  }

  body.public-mode .center-column {
    display: block;
  }

  body.public-mode .schematic-panel {
    height: calc(100vh - 96px);
    min-height: 540px;
  }

  body.public-mode .schematic-stage {
    width: 100%;
    height: 100%;
  }

  body.public-mode .schematic-image {
    height: 100%;
    width: auto;
    max-width: none;
  }

  body.public-mode .topbar {
    justify-content: center;
    text-align: center;
  }

  body.public-mode .status-strip {
    width: 100%;
    justify-content: center;
  }
}

/* Better landscape mobile / tablet fitting */
@media (max-height: 520px) and (orientation: landscape) {
  .hud {
    padding: 8px 10px;
    gap: 8px;
    transform: none;
  }

  .topbar {
    min-height: 42px;
    height: 42px;
    flex: 0 0 42px;
    padding: 0 10px;
  }

  .brand {
    font-size: clamp(14px, 2vw, 22px);
  }

  .grid {
    gap: 8px;
    grid-template-columns: minmax(190px, 22vw) 1fr minmax(220px, 24vw);
  }

  .left-column,
  .right-column,
  .center-column {
    gap: 8px;
  }

  .panel {
    padding: 8px 10px;
  }

  .panel h2 {
    font-size: clamp(14px, 1.5vw, 20px);
    margin-bottom: 7px;
    letter-spacing: 2px;
  }

  p {
    font-size: clamp(10px, 1vw, 14px);
    margin: 3px 0;
  }

  .center-column {
    grid-template-rows: minmax(0, 1fr) 112px;
  }

  #waveCanvas {
    height: 88px;
  }

  .mini-status {
    height: 22px;
    font-size: 11px;
  }

  .controls {
    min-height: 38px;
    height: 38px;
    flex: 0 0 38px;
  }

  button {
    height: 28px;
    min-height: 28px;
    font-size: 11px;
    padding: 0 8px;
  }

  .crt-row {
    min-height: 20px;
    font-size: clamp(12px, 1.2vw, 17px);
  }
}

/* Credits panel */
.credits-panel {
  position: fixed;
  right: 22px;
  bottom: 70px;
  z-index: 75;
  display: none;
  width: min(390px, calc(100vw - 44px));
  border: 1px solid rgba(142,255,200,.75);
  background: rgba(2, 12, 10, .86);
  box-shadow: inset 0 0 18px rgba(53,245,156,.12), 0 0 20px rgba(53,245,156,.18);
  padding: 14px 16px;
  color: var(--green);
  text-shadow: 0 0 8px rgba(142,255,200,.75);
}

.credits-panel b,
.credits-panel span {
  display: block;
}

.credits-panel b {
  margin-bottom: 8px;
  letter-spacing: 2px;
}

body.credits-on .credits-panel {
  display: block;
}

/* More organic cyclotron light behavior */
.cyclotron-led.trail {
  opacity: .34;
  transform: translate(-50%, -50%) scale(.9);
  filter: blur(.2px);
}

body.stream .cyclotron-led.trail {
  opacity: .46;
}

body.overload .cyclotron-led.trail {
  opacity: .18;
}

body.overload .cyclotron-led.active {
  animation: cyclotronLedOverload .18s steps(2) infinite;
}

@keyframes cyclotronLedOverload {
  0%, 100% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  50% { opacity: .35; transform: translate(-50%, -50%) scale(.82); }
}

/* Prevent hidden overlays from blocking public/mobile interactions */
.rotate-notice,
.credits-panel {
  pointer-events: auto;
}

.rotate-notice[aria-hidden="true"],
.credits-panel[aria-hidden="true"] {
  pointer-events: none;
}


/* --- Precise schematic overlay alignment fix --- */
/*
  The cyclotron LEDs must be positioned relative to the rendered image box, not the
  responsive panel box. JavaScript now sizes .schematic-stage to the exact fitted
  image dimensions; image and LED overlay fill that same stage.
*/
.schematic-stage {
  width: var(--schematic-stage-w, auto) !important;
  height: var(--schematic-stage-h, 100%) !important;
  max-width: 100% !important;
  max-height: 100% !important;
  aspect-ratio: var(--schematic-aspect, 1085 / 1450);
  flex: 0 0 auto;
}

.schematic-image {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: fill !important;
}

.cyclotron-led-overlay,
.calibration-points {
  width: 100% !important;
  height: 100% !important;
}

@media (max-width: 760px) and (orientation: portrait) {
  body.public-mode .schematic-stage {
    width: var(--schematic-stage-w, auto) !important;
    height: var(--schematic-stage-h, 100%) !important;
  }

  body.public-mode .schematic-image {
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .schematic-stage {
    width: var(--schematic-stage-w, auto) !important;
    height: var(--schematic-stage-h, 100%) !important;
  }
}

/* Credits function-key list formatting */
.credits-panel {
  max-height: min(78vh, 720px);
  overflow: auto;
}

.credits-panel hr {
  border: 0;
  border-top: 1px solid rgba(142,255,200,.35);
  margin: 10px 0;
}

.credits-panel span {
  line-height: 1.35;
}


/* --- Fire / random diagnostics / PKE / admin settings pack --- */
.fire-overlay {
  position: fixed;
  left: 50%;
  top: 82px;
  transform: translateX(-50%);
  z-index: 65;
  display: none;
  pointer-events: none;
}

.fire-overlay div {
  padding: 10px 18px;
  border: 2px solid rgba(142,220,255,.92);
  background: rgba(2, 18, 24, .78);
  color: #dff8ff;
  font-weight: 900;
  letter-spacing: 3px;
  text-shadow: 0 0 12px rgba(65,191,255,.95);
  box-shadow: inset 0 0 18px rgba(65,191,255,.18), 0 0 32px rgba(65,191,255,.25);
  animation: fireBannerPulse .42s steps(2) infinite;
}

body.firing .fire-overlay {
  display: block;
}

body.firing {
  --green: #8edcff;
  --green-2: #41bfff;
  --line: rgba(142,220,255,.92);
}

body.firing .schematic-panel,
body.firing .waveform-panel,
body.firing .topbar {
  box-shadow: inset 0 0 34px rgba(65,191,255,.28), 0 0 34px rgba(65,191,255,.24);
  filter: brightness(1.18) contrast(1.08);
}

body.firing .schematic-image {
  filter: drop-shadow(0 0 24px rgba(65,191,255,.48)) brightness(1.22) contrast(1.13);
}

body.firing .cyclotron-led.active {
  animation-duration: .12s;
  box-shadow:
    0 0 18px rgba(232,250,255,1),
    0 0 38px rgba(65,191,255,1),
    0 0 72px rgba(65,191,255,.72);
}

body.firing .scanlines {
  opacity: .42;
}

.pke-alert {
  position: fixed;
  right: 22px;
  top: 92px;
  z-index: 66;
  display: none;
  width: min(360px, calc(100vw - 44px));
  border: 2px solid rgba(255,178,74,.9);
  background: rgba(30, 17, 4, .84);
  color: #ffe4b2;
  padding: 12px 14px;
  box-shadow: inset 0 0 18px rgba(255,178,74,.16), 0 0 30px rgba(255,178,74,.25);
  text-shadow: 0 0 10px rgba(255,178,74,.8);
}

.pke-alert b,
.pke-alert span {
  display: block;
}

.pke-alert b {
  margin-bottom: 6px;
  letter-spacing: 2px;
}

body.pke-event .pke-alert {
  display: block;
  animation: pkePulse .32s steps(2) infinite;
}

body.pke-event .hud {
  animation: pkeScreenFlash .65s steps(2) 4;
}

.settings-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 85;
  display: none;
  width: min(520px, calc(100vw - 38px));
  max-height: min(82vh, 720px);
  overflow: auto;
  border: 2px solid var(--line);
  background: rgba(2, 12, 10, .94);
  box-shadow: inset 0 0 24px rgba(53,245,156,.14), 0 0 38px rgba(53,245,156,.22);
  color: var(--green);
  padding: 18px;
  text-shadow: 0 0 8px rgba(142,255,200,.75);
}

body.settings-on .settings-panel {
  display: block;
}

.settings-panel b {
  display: block;
  margin-bottom: 14px;
  font-size: 22px;
  letter-spacing: 3px;
}

.settings-panel label {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 12px;
  align-items: center;
  margin: 10px 0;
  font-size: 15px;
}

.settings-panel input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.settings-panel input,
.settings-panel select {
  accent-color: var(--green-2);
}

.settings-help {
  display: block;
  margin-top: 16px;
  opacity: .72;
  font-size: 13px;
}

body.no-crt-noise .crt-noise {
  display: none;
}

body.no-scanlines .scanlines {
  display: none;
}

#fireBtn {
  border-color: rgba(142,220,255,.9);
}

body.firing #fireBtn {
  background: rgba(65,191,255,.22);
  box-shadow: inset 0 0 12px rgba(65,191,255,.22), 0 0 18px rgba(65,191,255,.22);
}

@media (max-width: 760px) {
  .fire-overlay {
    top: 64px;
  }

  .fire-overlay div {
    font-size: 12px;
    padding: 7px 10px;
    letter-spacing: 2px;
  }

  .pke-alert {
    left: 16px;
    right: 16px;
    top: 76px;
    width: auto;
  }

  .settings-panel label {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

@keyframes fireBannerPulse {
  50% { opacity: .55; filter: brightness(1.25); }
}

@keyframes pkePulse {
  50% { opacity: .48; transform: translateX(1px); }
}

@keyframes pkeScreenFlash {
  50% { filter: brightness(1.45) hue-rotate(20deg); }
}
