/*
 * Mini project styling.
 *
 * The tokens are the same ones the full platform ships in web/src/app/globals.css. Dark by
 * default for the same reason: this is read at night, and the status colours carry a safety
 * signal that a light theme washes out.
 *
 * No framework, no build step. The whole app is three script tags and this file.
 */

:root {
  --bg: #0b0f14;
  --bg-raised: #121820;
  --bg-inset: #0e141b;
  --border: #1f2a37;
  --border-strong: #2c3a4a;

  --text: #e6edf3;
  --text-muted: #8b98a5;
  --text-faint: #5c6b7a;

  --accent: #4f8ff7;
  --accent-dim: #1e3a5f;

  --good: #3fb950;
  --good-dim: #12351a;
  --caution: #d29922;
  --caution-dim: #3a2d0a;
  --critical: #f85149;
  --critical-dim: #45161a;
  --neutral: #6e7d8d;

  --beam-high: #5ad8f0;
  --beam-low: #7aa2c9;
  --beam-off: #4a5560;

  --radius: 10px;
  --radius-sm: 6px;
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ------------------------------------------------------------------ top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, var(--beam-high), #2b9fc4);
  flex-shrink: 0;
}

.brand-name { font-weight: 650; letter-spacing: -0.01em; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--text-muted); }

.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  border: 1px solid var(--border-strong);
  background: var(--bg-inset);
  color: var(--text-muted);
}
.chip-sim { border-color: var(--caution); color: var(--caution); background: var(--caution-dim); }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.btn {
  font: inherit; font-weight: 550;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-inset);
  color: var(--text);
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
.btn:hover { background: var(--border); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #06121f; }
.btn-primary:hover { background: #6ba3ff; }

/* ------------------------------------------------------------------- layout */

/*
 * Three columns at desk width: state, controls, and a tall console on the right. The console
 * needs the height — a log you can only see six lines of is not a log.
 */
.layout {
  display: grid;
  gap: 16px;
  padding: 20px;
  max-width: 1560px;
  margin: 0 auto;
  align-items: start;
  grid-template-columns: 360px 360px minmax(420px, 1fr);
  grid-template-areas:
    "beam      sensors   scenarios"
    "beam      sensors   serial"
    "events    events    serial"
    "selftest  selftest  serial";
}

.area-beam { grid-area: beam; }
.area-sensors { grid-area: sensors; }
.area-scenarios { grid-area: scenarios; }
.area-serial { grid-area: serial; align-self: stretch; }
.area-events { grid-area: events; }
.area-selftest { grid-area: selftest; }

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    grid-template-areas: none;
  }
  .area-beam, .area-sensors, .area-scenarios,
  .area-serial, .area-events, .area-selftest { grid-area: auto; }
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card-title { margin: 0 0 3px; font-size: 14px; font-weight: 650; }
.card-hint { margin: 0 0 16px; font-size: 12px; color: var(--text-faint); }

/* --------------------------------------------------------------- beam state */

.beam-card { grid-row: span 2; }

.lamp-wrap { display: grid; place-items: center; padding: 18px 0 10px; }

.lamp { position: relative; width: 190px; height: 140px; }

.lamp-body {
  position: absolute; left: 0; top: 20px;
  width: 100px; height: 100px;
  border-radius: 50% 8px 8px 50%;
  border: 2px solid var(--border-strong);
  background: var(--bg-inset);
  transition: background 200ms, border-color 200ms, box-shadow 200ms;
}

.lamp-beam {
  position: absolute; left: 92px; top: 40px;
  width: 0; height: 0;
  border-top: 30px solid transparent;
  border-bottom: 30px solid transparent;
  border-left: 96px solid transparent;
  transition: border-left-color 200ms, opacity 200ms, transform 200ms;
  transform-origin: left center;
  opacity: 0;
}

.mode-off .lamp-body { border-color: var(--beam-off); }
.mode-off .lamp-beam { opacity: 0; }

.mode-low .lamp-body {
  background: rgba(122, 162, 201, 0.26);
  border-color: var(--beam-low);
  box-shadow: 0 0 26px -6px var(--beam-low);
}
.mode-low .lamp-beam {
  border-left-color: rgba(122, 162, 201, 0.42);
  opacity: 1;
  transform: scaleX(0.62) rotate(7deg);
}

.mode-high .lamp-body {
  background: rgba(255, 214, 102, 0.34);
  border-color: var(--beam-high);
  box-shadow: 0 0 44px -4px var(--beam-high);
}
.mode-high .lamp-beam {
  border-left-color: rgba(255, 214, 102, 0.46);
  opacity: 1;
  transform: scaleX(1) rotate(0deg);
}

.beam-readout { text-align: center; }

.beam-mode {
  font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15;
}
.mode-off .beam-mode, .beam-mode.off { color: var(--beam-off); }
.beam-reason { font-size: 13px; color: var(--text-muted); margin-top: 4px; min-height: 20px; }

.dwell {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--caution);
  background: var(--caution-dim);
  border-radius: var(--radius-sm);
}
.dwell-head {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 12px; font-weight: 600; color: var(--caution);
}
.dwell-track {
  margin-top: 8px; height: 6px; border-radius: 3px;
  background: rgba(0, 0, 0, 0.35); overflow: hidden;
}
.dwell-fill {
  height: 100%; width: 0%; border-radius: 3px;
  background: var(--caution);
  transition: width 100ms linear;
}
.dwell-note { margin: 10px 0 0; font-size: 11.5px; color: var(--text-muted); }

.facts {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px; margin: 18px 0 0;
  border-top: 1px solid var(--border); padding-top: 14px;
}
.facts div { min-width: 0; }
.facts dt {
  font-size: 10px; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-faint);
}
.facts dd { margin: 3px 0 0; font-size: 14px; }

/* ----------------------------------------------------------------- controls */

.control { margin-bottom: 14px; }
.control label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px;
}
.unit {
  font-size: 10px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--text-faint);
}
.control input[type=range] {
  width: 100%; accent-color: var(--accent); background: transparent; margin: 0;
}
.control output { display: block; font-size: 12px; color: var(--text); margin-top: 3px; }

.toggles {
  display: grid; grid-template-columns: 1fr 1fr; gap: 7px;
  margin: 16px 0 4px; padding-top: 14px; border-top: 1px solid var(--border);
}
.toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-inset);
  font-size: 12px; cursor: pointer; -webkit-user-select: none; user-select: none;
}
.toggle:hover { border-color: var(--border-strong); }
.toggle input { accent-color: var(--accent); margin: 0; }
.toggle-danger input { accent-color: var(--critical); }
.toggle:has(input:checked) { border-color: var(--accent); color: var(--text); }
.toggle-danger:has(input:checked) {
  border-color: var(--critical); background: var(--critical-dim); color: var(--critical);
}

.override { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.override-label {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 7px;
}
.seg { display: flex; gap: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg-btn {
  flex: 1; font: inherit; font-size: 12px; font-weight: 550;
  padding: 8px 4px; border: 0; border-right: 1px solid var(--border-strong);
  background: var(--bg-inset); color: var(--text-muted); cursor: pointer;
}
.seg-btn:last-child { border-right: 0; }
.seg-btn:hover { background: var(--border); color: var(--text); }
.seg-btn.is-on { background: var(--accent-dim); color: var(--text); }

/* ---------------------------------------------------------------- scenarios */

.scenario-list { display: flex; flex-wrap: wrap; gap: 7px; }
.scenario {
  font: inherit; font-size: 12px; font-weight: 550;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--bg-inset);
  color: var(--text-muted); cursor: pointer;
}
.scenario:hover { background: var(--border); color: var(--text); }
.scenario.is-on { background: var(--accent-dim); border-color: var(--accent); color: var(--text); }
.scenario-blurb {
  margin: 14px 0 0; font-size: 12.5px; color: var(--text-muted);
  border-left: 2px solid var(--border-strong); padding-left: 12px; min-height: 40px;
}

/* ------------------------------------------------------------------- serial */

.serial {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--text-muted);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  min-height: 320px;
  height: 100%;
  max-height: 640px;
  overflow: auto;
  white-space: pre;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.serial::-webkit-scrollbar { width: 10px; height: 10px; }
.serial::-webkit-scrollbar-track { background: transparent; }
.serial::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 5px; border: 3px solid var(--bg-inset);
}
.serial .commit { color: var(--good); }
.serial .warn { color: var(--caution); }
.serial .crit { color: var(--critical); }

/* ------------------------------------------------------------------- events */

.events { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.events li {
  display: flex; align-items: baseline; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 12.5px;
}
.events li:last-child { border-bottom: 0; }
.events .ev-bar { width: 3px; align-self: stretch; border-radius: 2px; flex-shrink: 0; }
.events .ev-mode { font-weight: 650; min-width: 74px; }
.events .ev-reason { color: var(--text-muted); flex: 1; }
.events .ev-time { color: var(--text-faint); font-family: var(--font-mono); font-size: 11.5px; }
.events .empty { color: var(--text-faint); border: 0; }

/* ---------------------------------------------------------------- self test */

.selftest {
  margin-top: 14px; padding: 12px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  border: 1px solid var(--good); background: var(--good-dim); color: var(--good);
}
.selftest.fail { border-color: var(--critical); background: var(--critical-dim); color: var(--critical); }
.selftest-failures {
  list-style: none; margin: 10px 0 0; padding: 0;
  font-family: var(--font-mono); font-size: 11.5px; color: var(--critical);
}
.selftest-failures li { padding: 4px 0; }

/* -------------------------------------------------------------------- foot */

.foot {
  padding: 18px 20px 30px; text-align: center;
  font-size: 11.5px; color: var(--text-faint);
}

@media (prefers-reduced-motion: reduce) {
  .lamp-body, .lamp-beam, .dwell-fill { transition: none; }
}

/* ==========================================================================
   Splash
   ========================================================================== */

/*
 * A splash screen earns its place only if it is doing something. This one is: the beam
 * sweeps once, which is the single idea the whole project is about, and it is gone in under
 * two seconds. It is skippable on any key or click, because a splash you cannot dismiss is
 * an obstacle rather than an introduction.
 */

.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 45%, #12203a 0%, var(--bg) 62%);
  opacity: 1;
  transition: opacity 320ms ease;
}

.splash.is-leaving { opacity: 0; pointer-events: none; }

.splash-inner { text-align: center; padding: 24px; }

.splash-lamp {
  position: relative;
  width: 210px;
  height: 120px;
  margin: 0 auto 26px;
}

.splash-lamp-body {
  position: absolute;
  left: 0; top: 15px;
  width: 90px; height: 90px;
  border-radius: 50% 8px 8px 50%;
  border: 2px solid var(--beam-high);
  background: rgba(255, 214, 102, 0.28);
  box-shadow: 0 0 46px -6px var(--beam-high);
  animation: lamp-warm 1.6s ease-out both;
}

.splash-lamp-beam {
  position: absolute;
  left: 84px; top: 30px;
  width: 0; height: 0;
  border-top: 30px solid transparent;
  border-bottom: 30px solid transparent;
  border-left: 120px solid rgba(255, 214, 102, 0.42);
  transform-origin: left center;
  animation: beam-sweep 1.7s cubic-bezier(0.22, 0.9, 0.3, 1) both;
}

@keyframes lamp-warm {
  0%   { opacity: 0.25; box-shadow: none; }
  55%  { opacity: 1; }
  100% { opacity: 1; }
}

@keyframes beam-sweep {
  0%   { opacity: 0; transform: scaleX(0.05) rotate(-16deg); }
  45%  { opacity: 1; transform: scaleX(1.05) rotate(6deg); }
  100% { opacity: 1; transform: scaleX(1) rotate(0deg); }
}

.splash-title {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.splash-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.splash-bar {
  width: 180px;
  height: 3px;
  margin: 26px auto 0;
  border-radius: 2px;
  background: var(--bg-inset);
  overflow: hidden;
}

.splash-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: var(--beam-high);
  animation: splash-fill 1.5s ease-out both;
}

@keyframes splash-fill { to { width: 100%; } }

.splash-note {
  margin: 18px 0 0;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--caution);
}

/* ==========================================================================
   Login
   ========================================================================== */

.login {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
  background: radial-gradient(circle at 50% 30%, #101c31 0%, var(--bg) 60%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
}

.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }

.login-title { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -0.02em; }
.login-sub { margin: 4px 0 20px; font-size: 12.5px; color: var(--text-muted); }

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 11px 12px;
  color: var(--text);
  background: var(--bg-inset);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 120ms;
}

.field input::placeholder { color: var(--text-faint); }
.field input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(79, 143, 247, 0.22); }

.login-error {
  margin: 0 0 14px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: #ffb4b0;
  background: var(--critical-dim);
  border: 1px solid var(--critical);
  border-radius: var(--radius-sm);
}

.btn-block { width: 100%; padding: 12px; font-size: 14px; }

.login-demo {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.login-demo-head {
  margin: 0 0 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.login-demo-list { list-style: none; margin: 0; padding: 0; }

.login-demo-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.login-demo-list code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
}

.login-demo-fill {
  margin-left: auto;
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: 0;
  cursor: pointer;
  padding: 2px 4px;
}
.login-demo-fill:hover { text-decoration: underline; }

.login-honest {
  margin: 18px 0 0;
  padding: 11px 12px;
  font-size: 11.5px;
  line-height: 1.55;
  color: #f0d18a;
  background: var(--caution-dim);
  border: 1px solid var(--caution);
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Session block in the top bar
   ========================================================================== */

.session {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 12px;
  margin-left: 2px;
  border-left: 1px solid var(--border);
}

.session-name { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }

.btn-quiet {
  background: none;
  border-color: transparent;
  color: var(--text-muted);
  padding: 8px 10px;
}
.btn-quiet:hover { background: var(--bg-inset); color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  .splash, .splash-lamp-body, .splash-lamp-beam, .splash-bar span { animation: none; transition: none; }
  .splash-bar span { width: 100%; }
}

@media (max-width: 560px) {
  .session { border-left: 0; padding-left: 0; }
  .session-name { display: none; }
}
