:root {
  color-scheme: dark;
  --bg: #06070b;
  --panel: #0d1018;
  --line: #273040;
  --line-strong: #3f4d63;
  --ink: #f5f7fb;
  --ink-2: #cfd7e6;
  --muted: #8290a6;
  --muted-2: #526074;
  --amber: #f8c14d;
  --amber-bright: #ffe08a;
  --amber-dim: #9a6c18;
  --cyan: #62e5ff;
  --cyan-dim: rgba(98, 229, 255, 0.35);
  --emerald: #45e0a7;
  --rose: #ff6b91;
  --violet: #a78bfa;
  --display: "VT323", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --body: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-family: var(--body);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
}

.crt-scanlines,
.crt-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
}

.crt-scanlines {
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0, 0, 0, 0.17) 3px,
    transparent 4px
  );
  mix-blend-mode: multiply;
  opacity: 0.48;
}

.crt-vignette {
  background: radial-gradient(ellipse at center, transparent 58%, rgba(0, 0, 0, 0.58) 100%);
}

.glow-amber {
  color: var(--amber-bright);
  text-shadow: 0 0 6px rgba(248, 193, 77, 0.55), 0 0 18px rgba(248, 193, 77, 0.18);
}

@keyframes crt-flicker {
  0%,
  96%,
  100% { opacity: 1; }
  97% { opacity: 0.96; }
  99% { opacity: 0.98; }
}

@keyframes blink {
  0%,
  60%,
  100% { opacity: 1; }
  70% { opacity: 0.3; }
}

.app {
  width: 100vw;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0));
  background:
    radial-gradient(circle at 50% 12%, rgba(98, 229, 255, 0.08), transparent 34%),
    radial-gradient(circle at 13% 82%, rgba(167, 139, 250, 0.06), transparent 30%),
    linear-gradient(90deg, rgba(248, 193, 77, 0.026) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(0deg, rgba(98, 229, 255, 0.022) 1px, transparent 1px) 0 0 / 48px 48px,
    var(--bg);
  overflow: hidden;
  animation: crt-flicker 6s infinite;
}

.topbar {
  height: 32px;
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--muted);
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.wordmark {
  font-family: var(--display);
  font-size: 18px;
  letter-spacing: 0.06em;
}

.sep { color: var(--muted-2); }
.breadcrumb { color: var(--ink-2); }
.spacer { flex: 1; }

.topbar .dot {
  color: var(--emerald);
  text-shadow: 0 0 6px rgba(69, 224, 167, 0.55);
  animation: blink 1.8s infinite;
  font-size: 10px;
}

.topbar .state { color: var(--cyan); }
.topbar .clock {
  color: var(--amber-bright);
  min-width: 9ch;
  text-align: right;
}

.infobar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  flex-shrink: 0;
  font-family: var(--display);
  letter-spacing: 0.05em;
}

.infobar .cell {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  border: 1px solid rgba(98, 229, 255, 0.22);
  background: linear-gradient(180deg, rgba(98, 229, 255, 0.05), rgba(0, 0, 0, 0.38));
  padding: 5px 8px;
}

.infobar .cell span {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  line-height: 1;
  margin-bottom: 2px;
  text-transform: uppercase;
}

.infobar .cell b {
  color: var(--amber-bright);
  font-size: 16px;
  font-weight: 400;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-line {
  min-height: 18px;
  flex-shrink: 0;
  margin: 0;
  padding: 0 4px;
  color: var(--cyan);
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 0.05em;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-line.is-good { color: var(--emerald); }
.status-line.is-bad { color: var(--rose); }

.screen {
  position: relative;
  min-height: 0;
  flex: 1;
  border: 1px solid rgba(98, 229, 255, 0.28);
  background:
    radial-gradient(ellipse at center, rgba(98, 229, 255, 0.055), transparent 68%),
    linear-gradient(180deg, rgba(8, 10, 16, 0.64), rgba(0, 0, 0, 0.86)),
    #030408;
  box-shadow:
    inset 0 0 72px rgba(0, 0, 0, 0.74),
    inset 0 0 110px rgba(98, 229, 255, 0.04),
    0 12px 28px -12px rgba(0, 0, 0, 0.72),
    0 0 0 1px rgba(248, 193, 77, 0.06);
  overflow: hidden;
}

#vortexCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  flex-shrink: 0;
}

.control-row {
  min-width: 0;
  height: 36px;
  display: grid;
  grid-template-columns: auto minmax(42px, 1fr) minmax(4ch, auto);
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.4);
  padding: 4px 8px;
  font-family: var(--display);
  font-size: 13px;
  letter-spacing: 0.05em;
}

.control-row span {
  color: var(--muted);
  text-transform: uppercase;
}

.control-row input[type="range"] {
  width: 100%;
  min-width: 0;
  accent-color: var(--cyan);
}

.control-row b {
  color: var(--amber-bright);
  font-size: 14px;
  font-weight: 400;
  line-height: 1;
  text-align: right;
  white-space: nowrap;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.25fr;
  gap: 4px;
  flex-shrink: 0;
}

.act {
  min-height: 44px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  background: rgba(0, 0, 0, 0.42);
  color: var(--amber);
  font-family: var(--display);
  font-size: 17px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 120ms, border-color 120ms, background 120ms, text-shadow 120ms;
  -webkit-tap-highlight-color: transparent;
}

.act:hover,
.act:active {
  color: var(--amber-bright);
  border-color: var(--amber);
  text-shadow: 0 0 6px rgba(248, 193, 77, 0.4);
}

.act.toggle {
  color: var(--cyan);
  border-color: rgba(98, 229, 255, 0.55);
}

.act.kick {
  color: var(--violet);
  border-color: rgba(167, 139, 250, 0.55);
}

.act.reset {
  color: #101016;
  background: var(--amber);
  border-color: var(--amber);
}

.act.reset:hover,
.act.reset:active {
  color: #101016;
  background: var(--amber-bright);
  text-shadow: none;
}

@media (max-width: 900px) {
  .control-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .control-row:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow: auto;
    overscroll-behavior: auto;
  }

  .app {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .screen {
    flex: none;
    height: 1160px;
  }
}

@media (max-width: 760px) {
  .control-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-row:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 540px) {
  .app {
    gap: 6px;
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom, 0));
  }

  .topbar {
    font-size: 13px;
    gap: 4px;
  }

  .topbar .breadcrumb,
  .topbar .sep {
    display: none;
  }

  .infobar .cell {
    padding: 5px 6px;
  }

  .infobar .cell b {
    font-size: 14px;
  }

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

  .control-row {
    height: 32px;
    gap: 6px;
    padding: 3px 6px;
    font-size: 12px;
  }

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

  .act {
    min-height: 38px;
    font-size: 15px;
  }

  .act.reset {
    grid-column: 1 / -1;
  }
}

@media (max-height: 520px) and (min-width: 861px) {
  .infobar .cell span { font-size: 9px; }
  .infobar .cell b { font-size: 14px; }
  .control-row { height: 30px; font-size: 12px; }
  .act { min-height: 34px; font-size: 14px; }
}

@media (min-width: 1000px) {
  .app {
    max-width: 1440px;
    margin: 0 auto;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0));
    gap: 8px;
  }

  .topbar {
    height: 36px;
    font-size: 15px;
  }

  .wordmark { font-size: 20px; }
  .status-line { min-height: 22px; font-size: 16px; }
  .control-row { height: 38px; font-size: 14px; }
  .mode-pill { min-height: 36px; font-size: 17px; }
  .act { min-height: 48px; font-size: 18px; }
}
