/* Spike - layout and chrome. Tokens live in tokens.css. */

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--app);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
}

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

#topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  background: linear-gradient(180deg, var(--bar-top), var(--bar-bot));
  border-bottom: 1px solid var(--line-edge);
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand-tile {
  width: 24px; height: 24px; border-radius: 7px;
  background: linear-gradient(160deg, var(--accent), #19a68f);
  box-shadow: 0 0 10px var(--accent-glow);
  display: grid; place-items: center;
  color: #06110e; font-size: 13px; font-weight: 700;
}
.brand-word {
  font-size: 15px; font-weight: 600; letter-spacing: 0.04em;
}
.brand-word b { color: var(--accent); font-weight: 600; }
.badge {
  font-family: var(--font-mono); font-size: 10px;
  color: var(--text-dim);
  border: 1px solid var(--line-strong); border-radius: var(--r-chip);
  padding: 1px 5px;
}

.divider { width: 1px; height: 26px; background: #22262e; flex: 0 0 auto; }
.spacer  { flex: 1 1 auto; }

/* ---------------------------------------------------------------- buttons */

.btn {
  font-family: var(--font-ui); font-size: 12px; font-weight: 500;
  color: var(--text-mid);
  background: transparent;
  border: 1px solid transparent; border-radius: var(--r-btn);
  padding: 7px 11px;
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 90ms linear, color 90ms linear, border-color 90ms linear;
}
.btn:hover { background: #1a1e26; color: var(--text-high); }

.btn.solid  { background: var(--raised); border-color: var(--line-ctrl); }
.btn.solid:hover { border-color: var(--line-hover); }

.btn.accent {
  background: var(--accent-fill); border-color: var(--accent-line);
  color: var(--accent);
}
.btn.accent:hover { background: var(--accent-fill-2); border-color: var(--accent-line-2); }

/* section 42: the one button that brings the thing in */
.btn.gateway {
  background: rgba(126, 231, 135, 0.10); border-color: rgba(126, 231, 135, 0.34);
  color: var(--gateway);
}
.btn.gateway:hover { background: rgba(126, 231, 135, 0.18); }

.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-fill); color: var(--danger-hover); }

.btn[disabled] { opacity: 0.38; cursor: default; }
.btn[disabled]:hover { background: transparent; color: var(--text-mid); }

/* segmented control - section 26: alternatives, not on/off */
.seg {
  display: inline-flex; align-items: stretch; gap: 2px;
  background: #0e1116; border: 1px solid #1f242c;
  border-radius: 11px; padding: 3px;
}
.seg > button {
  font-family: var(--font-ui); font-size: 11px; font-weight: 500;
  color: var(--text-muted);
  background: transparent; border: 0; border-radius: 8px;
  padding: 5px 11px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
}
.seg > button:hover { color: var(--text-high); }
.seg > button.on {
  background: var(--accent-fill); color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}
.seg .glyph { font-family: var(--font-mono); font-size: 12px; }

/* ---------------------------------------------------------------- middle */

#middle { flex: 1 1 auto; display: flex; min-height: 0; }

#viewport-host {
  position: relative;
  flex: 1 1 auto; min-width: 0;
  background: radial-gradient(120% 95% at 50% 4%, #1a222b, #0e1218 48%, #090b0f);
  overflow: hidden;
  cursor: default;
}
#viewport-host canvas { display: block; position: absolute; inset: 0; z-index: 1; }

/* overlay host - ignores picks, its children take them (section 24) */
#viewport-overlay {
  position: absolute; inset: 0;
  z-index: 2;
  pointer-events: none;
  font-family: var(--font-mono);
}
#viewport-overlay > * { pointer-events: auto; }

.frosted {
  background: rgba(14, 17, 22, 0.72);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line-viewport);
  border-radius: var(--r-panel);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.55);
}
.frosted:hover { border-color: var(--line-hover); }

#hud-tl { position: absolute; left: 12px; top: 12px; padding: 8px 11px; }
#hud-tl .name { font-size: 11px; color: var(--text); display: flex; align-items: center; gap: 7px; }
#hud-tl .sub  { font-size: 10px; color: var(--text-dim); margin-top: 3px; }
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--accent);
  animation: pulse 1.9s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

#hud-tr {
  position: absolute; right: 12px; top: 12px; padding: 7px 11px;
  display: flex; align-items: center; gap: 10px; font-size: 10px;
}
#hud-tr .k { color: var(--text-dimmer); }
#hud-tr .v { color: var(--accent); }
#hud-tr .vline { width: 1px; height: 14px; background: #22262e; }

#xform-readout {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 54px; padding: 7px 14px;
  font-size: 12px; letter-spacing: 0.02em;
  color: var(--accent);
  border-color: var(--accent-line);
  box-shadow: 0 0 18px var(--accent-glow), 0 10px 34px rgba(0, 0, 0, 0.55);
}

#statusbar {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 12px; padding: 7px 13px;
  display: flex; align-items: center; gap: 11px;
  font-size: 10.5px; color: var(--text-mid);
}
#statusbar .sep { width: 1px; height: 13px; background: #22262e; }
#statusbar .swatch {
  width: 13px; height: 13px; border-radius: 4px;
  border: 1px solid var(--line-viewport);
}

/* second row for a mode's own controls (section 24) */
#mode-row {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: 10px;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px;
  background: rgba(14, 17, 22, 0.86);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line-viewport);
  border-radius: 11px;
}

#help-btn {
  position: absolute; left: 12px; bottom: 12px;
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  font-family: var(--font-ui); font-size: 14px; font-weight: 600;
  color: var(--text-mid); cursor: pointer;
}
#help-btn:hover { color: var(--text-high); }

#legend {
  position: absolute; left: 12px; bottom: 54px;
  width: 282px; padding: 4px 0;
  font-size: 10.5px;
}
#legend h4 {
  margin: 0; padding: 9px 12px 7px;
  font-family: var(--font-ui); font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--text-muted);
}
#legend .row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 3px 12px;
}
#legend .row .a { color: var(--text-mid); font-family: var(--font-ui); font-size: 11px; }
#legend .row .k {
  color: var(--text-dim);
  background: var(--inset); border: 1px solid var(--line-strong);
  border-radius: var(--r-chip); padding: 1px 5px; font-size: 9.5px;
  white-space: nowrap;
}
#legend .gap { height: 6px; }
#legend.hidden, #gizmo.hidden { display: none; }

#gizmo {
  position: absolute; right: 12px; bottom: 12px;
  width: 92px; height: 92px; border-radius: 50%;
  cursor: pointer;
}

/* ---------------------------------------------------------- right panel */

#panel {
  flex: 0 0 var(--panel-w); width: var(--panel-w);
  background: var(--panel);
  border-left: 1px solid var(--line-edge);
  display: flex; flex-direction: column; min-height: 0;
}

/* title bar, section 1: 28px, darker than the body, full bleed, X first */
.titlebar {
  height: var(--titlebar-h); flex: 0 0 auto;
  display: flex; align-items: center;
  padding: 0 3px;
  background: var(--titlebar);
  border-bottom: 1px solid var(--line-soft);
}
.titlebar .closebox {
  width: var(--closebox); height: var(--closebox);
  border-radius: var(--r-btn); border: 0; background: transparent;
  color: var(--text-mid); font-family: var(--font-ui); font-size: 12px;
  display: grid; place-items: center; cursor: pointer;
}
.titlebar .closebox:hover { color: var(--danger); background: var(--danger-fill); }
.titlebar .title {
  margin-left: 6px;
  font-size: 12px; font-weight: 700; color: var(--text);
}

#panel-body { flex: 1 1 auto; overflow-y: auto; min-height: 0; }

.section { padding: 14px 18px; border-bottom: 1px solid var(--line-soft); }
.section > h3 {
  margin: 0 0 10px;
  font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--text-muted);
}
.section .hint {
  margin: 8px 0 0; font-size: 10.5px; line-height: 1.5; color: var(--text-dim);
}

.row    { display: flex; align-items: center; gap: 6px; }
.row.wrap { flex-wrap: wrap; }
.grow   { flex: 1 1 auto; }
.stack  { display: flex; flex-direction: column; gap: 6px; }

.field-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-dim);
}
.mono { font-family: var(--font-mono); }
.readout {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-mid);
  background: var(--inset); border: 1px solid var(--line-strong);
  border-radius: var(--r-btn); padding: 4px 7px;
}

/* swatch grid */
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button {
  width: 26px; height: 26px; border-radius: var(--r-btn);
  border: 1px solid var(--line-viewport); cursor: pointer; padding: 0;
}
.swatches button.on { box-shadow: inset 0 0 0 1.5px var(--text-high), 0 0 8px var(--accent-glow); }

/* a typed millimetre field */
.mm-field {
  width: 78px;
  font-family: var(--font-mono); font-size: 11.5px;
  color: var(--text); text-align: right;
  background: var(--inset);
  border: 1px solid var(--line-strong); border-radius: var(--r-btn);
  padding: 5px 8px;
}
.mm-field:focus {
  outline: none;
  border-color: var(--accent-line-2);
  box-shadow: 0 0 8px var(--accent-glow);
}

input[type="color"] {
  width: 34px; height: 26px; padding: 0;
  background: var(--inset);
  border: 1px solid var(--line-strong); border-radius: var(--r-btn);
  cursor: pointer;
}

/* underline slider - Chiltons underline style: track is a hairline, not a pipe */
.uslider { display: flex; flex-direction: column; gap: 5px; }
.uslider .head { display: flex; justify-content: space-between; align-items: baseline; }
.uslider input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 14px; background: transparent; cursor: pointer; margin: 0;
}
.uslider input[type="range"]::-webkit-slider-runnable-track {
  height: 2px; background: var(--track); border-radius: 1px;
}
.uslider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 11px; height: 11px; margin-top: -4.5px;
  border-radius: 50%; border: 0;
  background: var(--accent); box-shadow: 0 0 8px var(--accent-glow);
}
.uslider input[type="range"]::-moz-range-track {
  height: 2px; background: var(--track); border-radius: 1px;
}
.uslider input[type="range"]::-moz-range-thumb {
  width: 11px; height: 11px; border: 0; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--accent-glow);
}

/* ---------------------------------------------------------------- toasts */
/* section 21: a refusal points at the control, it does not lecture */

#toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 70px; z-index: 40;
  display: flex; flex-direction: column; gap: 7px; align-items: center;
  pointer-events: none;
}
.toast {
  font-size: 11.5px; color: var(--text);
  background: var(--modal);
  border: 1px solid var(--line-ctrl); border-left-width: 3px;
  border-radius: var(--r-ctrl);
  padding: 8px 13px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  animation: rise 140ms ease-out;
}
.toast.warn { border-left-color: var(--warning); }
.toast.bad  { border-left-color: var(--danger); }
.toast.ok   { border-left-color: var(--accent); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ---------------------------------------------------------------- modal */

#modal-host {
  position: fixed; inset: 0; z-index: 50;
  display: none; place-items: center;
  background: rgba(6, 8, 11, 0.62);
}
#modal-host.open { display: grid; }
.modal {
  width: 380px;
  background: var(--modal);
  border: 1px solid var(--line-ctrl);
  border-radius: var(--r-modal);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.7);
  padding: 20px;
}
/* section 7: the border colour of a modal says what it costs */
.modal.destructive { border-color: rgba(255, 107, 120, 0.45); }
.modal h2 { margin: 0 0 8px; font-size: 15px; font-weight: 600; }
.modal p  { margin: 0 0 16px; font-size: 12px; line-height: 1.55; color: var(--text-dim); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; }

.hidden { display: none !important; }
