/* ==========================================================================
   CRANIOMETER — optical-bench / precision-instrument theme
   ========================================================================== */

:root {
  --bg: #0b0d10;
  --bg-2: #0e1114;
  --panel: #12161b;
  --panel-2: #161b21;
  --rule: #1e262e;
  --rule-bright: #2a343d;
  --ink: #c8d2da;
  --ink-hi: #eef3f6;
  --dim: #6b7a87;
  --dim-2: #4a5760;

  --amber: #f2a03d;
  --amber-dim: #8a6329;
  --cyan: #3fd8e0;
  --cyan-dim: #276b70;
  --node: #8a9aa6;
  --node-hover: #eef3f6;
  --danger: #e0554a;
  --ok: #6bd08a;

  --font-display: "Oxanium", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --radius: 3px;
  --shadow-deep: 0 20px 60px -20px rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; }

/* Several elements below set an explicit `display` in their class rule
   (flex, for layout) which otherwise wins the cascade over the UA
   stylesheet's `[hidden] { display: none }` at equal specificity. Restore
   it explicitly so toggling the `hidden` DOM property always works. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-image:
    radial-gradient(ellipse 1200px 700px at 15% -10%, rgba(63, 216, 224, 0.05), transparent 60%),
    radial-gradient(ellipse 1000px 600px at 100% 110%, rgba(242, 160, 61, 0.045), transparent 60%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.012) 0px, rgba(255, 255, 255, 0.012) 1px, transparent 1px, transparent 32px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.012) 0px, rgba(255, 255, 255, 0.012) 1px, transparent 1px, transparent 32px);
  background-color: var(--bg);
}

::selection { background: var(--amber); color: #16110a; }

/* grain overlay */
.grain {
  position: fixed;
  inset: 0;
  z-index: 999;
  pointer-events: none;
  opacity: 0.035;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ==========================================================================
   Masthead
   ========================================================================== */

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  animation: reveal-down 0.5s ease both;
}

.masthead-left { display: flex; align-items: center; gap: 14px; }

.mark {
  color: var(--amber);
  display: flex;
  filter: drop-shadow(0 0 6px rgba(242, 160, 61, 0.35));
}

.masthead-titles h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.14em;
  margin: 0;
  color: var(--ink-hi);
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  color: var(--dim);
  text-transform: lowercase;
}

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

.status-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  padding: 6px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--dim);
  background: var(--panel);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dim-2);
  box-shadow: 0 0 0 3px transparent;
  transition: background 0.3s, box-shadow 0.3s;
}

.status-chip[data-state="connecting"] .status-dot { background: var(--amber); animation: pulse 1.2s ease-in-out infinite; }
.status-chip[data-state="ok"] .status-dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(107, 208, 138, 0.15); }
.status-chip[data-state="error"] .status-dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(224, 85, 74, 0.18); }
.status-chip[data-state="ok"] { color: var(--ink); }
.status-chip[data-state="error"] { color: var(--danger); }

.badge {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--dim);
  border: 1px solid var(--rule);
  padding: 6px 10px;
  border-radius: var(--radius);
}

/* ==========================================================================
   Layout
   ========================================================================== */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1px;
  background: var(--rule);
  min-height: 0;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Stage
   ========================================================================== */

.stage-wrap {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  animation: reveal-up 0.55s 0.05s ease both;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}

.stage-toolbar-group { display: flex; align-items: center; gap: 10px; }

.filename {
  font-size: 0.72rem;
  color: var(--dim);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  padding: 7px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--rule-bright);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s, transform 0.1s;
}

.btn:hover:not(:disabled) { border-color: var(--cyan); color: var(--ink-hi); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-ghost { background: transparent; }
.btn-solid { background: var(--panel-2); flex: 1; justify-content: center; }
.btn-icon { padding: 5px 9px; font-size: 0.9rem; line-height: 1; }
.btn-fit { padding: 5px 8px; font-size: 0.65rem; }

.btn kbd {
  font-size: 0.62rem;
  color: var(--dim);
  border: 1px solid var(--rule-bright);
  border-radius: 2px;
  padding: 0 4px;
  margin-left: 2px;
}

.face-select-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  color: var(--dim);
}

.face-select-wrap select {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--rule-bright);
  border-radius: var(--radius);
  padding: 4px 6px;
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.zoom-control input[type="range"] {
  width: 110px;
  accent-color: var(--cyan);
}

.canvas-frame {
  position: relative;
  flex: 1;
  min-height: 320px;
  overflow: hidden;
  background:
    radial-gradient(ellipse at center, rgba(63, 216, 224, 0.03), transparent 65%),
    var(--bg);
  cursor: crosshair;
}

.canvas-frame.panning { cursor: grabbing; }

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#loupe {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 10px 30px rgba(0, 0, 0, 0.55), 0 0 18px rgba(63, 216, 224, 0.25);
  z-index: 20;
}

.hover-readout {
  position: absolute;
  pointer-events: none;
  z-index: 21;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--ink-hi);
  background: rgba(10, 12, 15, 0.92);
  border: 1px solid var(--rule-bright);
  border-radius: var(--radius);
  padding: 4px 8px;
  transform: translate(14px, 14px);
  white-space: nowrap;
}

/* dropzone */
.dropzone {
  position: absolute;
  inset: 14px;
  border: 1.5px dashed var(--rule-bright);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--dim);
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.dropzone-inner { text-align: center; }
.dropzone-inner svg { color: var(--dim-2); margin-bottom: 10px; }
.dz-title { font-family: var(--font-display); font-size: 0.95rem; color: var(--ink); margin: 0 0 4px; letter-spacing: 0.02em; }
.dz-sub { font-size: 0.68rem; margin: 0; color: var(--dim); }

.canvas-frame.dragover .dropzone {
  border-color: var(--cyan);
  background: rgba(63, 216, 224, 0.045);
  color: var(--cyan);
}
.canvas-frame.dragover .dropzone-inner svg { color: var(--cyan); }

.canvas-frame.has-image .dropzone { display: none; }

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(11, 13, 16, 0.82);
  color: var(--dim);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--rule-bright);
  border-top-color: var(--amber);
  animation: spin 0.8s linear infinite;
}

.stage-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-top: 1px solid var(--rule);
  font-size: 0.65rem;
  color: var(--dim);
  letter-spacing: 0.03em;
}

.stage-hint { color: var(--dim-2); }

/* ==========================================================================
   Panel
   ========================================================================== */

.panel {
  background: var(--panel);
  padding: 20px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  animation: reveal-up 0.55s 0.12s ease both;
}

.panel-section { position: relative; }

.panel-heading {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 10px;
}

.panel-heading.small { font-size: 0.65rem; }

.panel-heading .tick {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--dim-2);
  border: 1px solid var(--rule-bright);
  border-radius: 2px;
  padding: 1px 4px;
}

.vector-row {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--panel-2);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.vector-row[data-active="1"][data-vector="a"] { border-color: var(--amber-dim); box-shadow: 0 0 0 1px rgba(242, 160, 61, 0.12) inset; }
.vector-row[data-active="1"][data-vector="b"] { border-color: var(--cyan-dim); box-shadow: 0 0 0 1px rgba(63, 216, 224, 0.12) inset; }

.vector-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.swatch-a { background: var(--amber); box-shadow: 0 0 8px rgba(242, 160, 61, 0.5); }
.swatch-b { background: var(--cyan); box-shadow: 0 0 8px rgba(63, 216, 224, 0.5); }

.vector-endpoints {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.66rem;
  letter-spacing: 0.02em;
  color: var(--dim);
}

.vector-endpoints .arrow { color: var(--dim-2); flex-shrink: 0; }

.pt {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}
.pt.empty { color: var(--dim-2); font-style: italic; }

.vector-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--ink-hi);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.vector-value .unit { font-size: 0.62rem; color: var(--dim); margin-left: 2px; font-weight: 400; }

.ratio-plate {
  position: relative;
  border: 1px solid var(--rule-bright);
  border-radius: 4px;
  padding: 16px;
  text-align: center;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.012) 0 2px, transparent 2px 10px),
    linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow:
    inset 0 1px 0 0 rgba(242, 160, 61, 0.18),
    inset 0 -1px 0 0 rgba(63, 216, 224, 0.18);
}

.ratio-label {
  font-family: var(--font-display);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  color: var(--dim);
  text-transform: uppercase;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ratio-sub { font-size: 0.6rem; letter-spacing: 0.04em; color: var(--dim-2); text-transform: none; }

.ratio-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 2.1rem;
  color: var(--ink-hi);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  transition: color 0.25s;
}

.ratio-value.flash { animation: value-pop 0.4s ease; }

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  font-size: 0.68rem;
  color: var(--dim);
}

.legend li { display: flex; align-items: center; gap: 6px; }

.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-eye { background: #6fd7ff; }
.dot-brow { background: #a78bfa; }
.dot-nose { background: #f2a03d; }
.dot-mouth { background: #ef6f8e; }
.dot-chin { background: #6bd08a; }
.dot-contour { background: #8a9aa6; }
.dot-fold { background: #d4b45a; }

.keymap dl { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.keymap dl > div { display: flex; justify-content: space-between; gap: 10px; font-size: 0.68rem; }
.keymap dt { color: var(--ink); flex-shrink: 0; }
.keymap dd { margin: 0; color: var(--dim); text-align: right; }
.keymap kbd {
  font-family: var(--font-mono);
  border: 1px solid var(--rule-bright);
  border-radius: 2px;
  padding: 0 5px;
  color: var(--ink);
}

/* tick-marked divider used between panel sections */
.panel-section + .panel-section::before {
  content: "";
  display: block;
  height: 1px;
  margin: -9px 0 18px;
  background: repeating-linear-gradient(90deg, var(--rule) 0 4px, transparent 4px 8px);
}

/* ==========================================================================
   Toasts
   ========================================================================== */

.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 340px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--rule-bright);
  background: var(--panel);
  box-shadow: var(--shadow-deep);
  font-size: 0.72rem;
  color: var(--ink);
  animation: toast-in 0.25s ease both;
}

.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--cyan); }

.toast-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--dim);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
}

/* ==========================================================================
   Animation
   ========================================================================== */

@keyframes reveal-down {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes reveal-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(242, 160, 61, 0.5); }
  50% { box-shadow: 0 0 0 4px rgba(242, 160, 61, 0); }
}
@keyframes value-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.06); color: var(--cyan); }
  100% { transform: scale(1); }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
