/* Quantico (OFL) - vendored like three.js, because this runs on a client LAN
   with no guaranteed internet. Two weights; anything between maps to the
   nearer one. Glyphs outside latin (the ⟲⟳ buttons) fall back per-glyph. */
@font-face {
  font-family: 'Quantico';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../vendor/fonts/quantico/quantico-400.woff2') format('woff2');
}

@font-face {
  font-family: 'Quantico';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../vendor/fonts/quantico/quantico-700.woff2') format('woff2');
}

:root {
  --bg: #0e1116;
  --panel: #171c24;
  --border: #2a323d;
  --text: #e6ebf2;
  --muted: #8a97a8;
  --accent: #2a6fdb;
  --bar-height: 44px;
  --bottombar-height: 64px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 'Quantico', system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

/* Status bar --------------------------------------------------------------- */

#statusbar {
  height: var(--bar-height);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

#statusbar .brand { font-weight: 600; letter-spacing: 0.06em; }

/* The module menu and the bottom bar's period selector share the dark select. */
#statusbar .mode-menu,
#bottombar select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
#statusbar .spacer { flex: 1; }
#statusbar .field { color: var(--muted); }
#statusbar .field b { color: var(--text); font-weight: 500; }

#statusbar .demo-badge {
  padding: 2px 8px;
  border-radius: 3px;
  background: #7a4a00;
  color: #ffd08a;
  font-size: 12px;
  letter-spacing: 0.04em;
}

/* 3D viewport -------------------------------------------------------------- */

#viewport {
  position: absolute;
  inset: var(--bar-height) 0 var(--bottombar-height) 0;
}

#viewport canvas { display: block; }

/* CSS2D labels (floor number / short name) render into this overlay. */
#viewport .label {
  padding: 1px 5px;
  border-radius: 3px;
  /* background: rgba(14, 17, 22, 0.75); */
  text-shadow: 0 1px 4px #000;
  color: var(--text);
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

/* Designer toolbar + popup -------------------------------------------------- */

#designer-toolbar {
  position: absolute;
  top: calc(var(--bar-height) + 12px);
  left: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(23, 28, 36, 0.92);
}

#designer-toolbar[hidden] { display: none; }

#designer-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

#designer-toolbar .hint { color: var(--muted); font-size: 12px; }
#designer-toolbar .save-error { color: #ff8a8a; font-size: 12px; }

/* The "?" with the shortcut legend in a hover/focus tooltip. */
#designer-toolbar .help {
  position: relative;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--muted);
  font-size: 12px;
  cursor: help;
  user-select: none;
}

#designer-toolbar .help .tip {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  white-space: nowrap;
}

#designer-toolbar .help:hover .tip,
#designer-toolbar .help:focus-visible .tip { display: block; }

#designer-toolbar .bounds-input {
  width: 64px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

/* Unsaved-changes marker, amber like the simulation badge. */
.dirty-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffaa00;
}
.dirty-dot[hidden] { display: none; }

/* Buttons - first appearance in the app, so the base style lives here. */
.btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
}

.btn.danger {
  color: #ff8a8a;
  border-color: #5a2a2a;
}

/* The right-side column stacks the machine popup and the player card; the
   container is click-transparent so the floor stays interactive around them. */
#side-panels {
  position: absolute;
  top: calc(var(--bar-height) + 12px);
  right: 12px;
  width: 320px;
  max-height: calc(100% - var(--bar-height) - var(--bottombar-height) - 24px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

#side-panels > aside { pointer-events: auto; }

#popup,
#player-popup {
  position: relative; /* anchors each panel's absolute .close button */
  min-height: 0;      /* lets the flex column shrink panels to share the height */
  overflow-y: auto;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(23, 28, 36, 0.96);
  z-index: 999;
}

#popup[hidden],
#player-popup[hidden] { display: none; }

/* A player name that can be opened: styled as a link, works as a button. */
.player-link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}

.player-link:hover { text-decoration: underline; }
#popup h2, #player-popup h2 { margin: 0 0 2px; font-size: 16px; }
#popup .sub, #player-popup .sub { margin: 0 0 12px; color: var(--muted); font-size: 12px; }
#popup dl, #player-popup dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
#popup dt, #player-popup dt { color: var(--muted); }
#popup dd, #player-popup dd { margin: 0; text-align: right; }

/* Designer inspector form, sharing #popup's panel chrome. */
#popup .inspector-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  align-items: center;
}

#popup .inspector-grid label { color: var(--muted); }

#popup .inspector-grid input {
  width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

#popup .inspector-grid input:read-only { color: var(--muted); }

#popup .inspector-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

#popup .close,
#player-popup .close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}

/* Bottom status bar --------------------------------------------------------- */

#bottombar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--bottombar-height);
  display: flex;
  align-items: stretch;
  background: var(--panel);
  border-top: 1px solid var(--border);
  overflow: hidden;
}

/* Stat tile: title + value overlaid on a background sparkline canvas. */
#bottombar .widget {
  position: relative;
  width: 150px;
  flex: 0 0 auto;
  padding: 8px 12px;
  border-right: 6px solid var(--panel);
}

#bottombar .widget canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#bottombar .widget .title {
  position: relative; /* above the canvas */
  font-size: 11px;
  white-space: nowrap;
  text-shadow: 0 1px 3px #000
}

#bottombar .widget .value {
  position: relative;
  font-size: 16px;
  font-weight: 700;
  text-shadow: 0 1px 3px #000
}

#bottombar .period {
  display: flex;
  align-items: center;
  padding: 0 12px;
}

/* Ticker: a continuously scrolling track, paused on hover. */
#bottombar .ticker {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  overflow: hidden;
}

/* The track is positioned by JS (a conveyor, not a CSS marquee - see
   bottombar.js); spans separate themselves with a muted dot. */
#bottombar .ticker .track {
  display: flex;
  align-items: center;
  white-space: nowrap;
  padding-left: 12px;
  color: var(--muted);
  font-size: 12px;
  will-change: transform;
}

#bottombar .ticker .msg { flex: 0 0 auto; }

#bottombar .ticker .msg::after {
  content: '·';
  margin: 0 14px;
  color: var(--border);
}

#bottombar .ticker .msg b { color: var(--text); font-weight: 500; }

/* Boot error --------------------------------------------------------------- */

#boot-error {
  position: absolute;
  inset: var(--bar-height) 0 var(--bottombar-height) 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 40px;
  text-align: center;
}

#boot-error[hidden] { display: none; }
#boot-error h1 { margin: 0; font-size: 18px; color: #ff8a8a; }
#boot-error pre {
  margin: 0;
  max-width: 70ch;
  white-space: pre-wrap;
  color: var(--muted);
  font-size: 13px;
}
