/* ==========================================================================
   THAT MESH E — HIGH-GLOSS TACTILE NEUMORPHISM (LIGHT & DARK)
   ========================================================================== */

:root[data-theme="dark"] {
  --bg: #151922;
  --surface: #181d27;
  --surface-hi: #1f2533;
  --surface-lo: #12151d;
  --shadow-dark: rgba(6, 8, 12, 0.82);
  --shadow-light: rgba(44, 53, 74, 0.42);
  --specular: linear-gradient(145deg, rgba(255, 255, 255, 0.065) 0%, rgba(255, 255, 255, 0) 55%);
  --rim: rgba(255, 255, 255, 0.06);
  --text: #eef2f8;
  --muted: #8b96ab;
  --rf: #38bdf8;
  --ac: #34d399;
  --focus: #f472b6;
  --warn: #fbbf24;
}

:root[data-theme="light"] {
  --bg: #e3e8f0;
  --surface: #e6ebf3;
  --surface-hi: #f2f5fb;
  --surface-lo: #d5dce7;
  --shadow-dark: rgba(163, 174, 194, 0.72);
  --shadow-light: rgba(255, 255, 255, 0.92);
  --specular: linear-gradient(145deg, rgba(255, 255, 255, 0.78) 0%, rgba(255, 255, 255, 0) 60%);
  --rim: rgba(255, 255, 255, 0.65);
  --text: #1b2434;
  --muted: #647187;
  --rf: #0284c7;
  --ac: #059669;
  --focus: #db2777;
  --warn: #d97706;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  transition: background 0.25s ease, color 0.25s ease;
  overflow-x: hidden;
}

.shell {
  max-width: 1260px;
  margin: 0 auto;
  padding: 20px 16px 36px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Extruded Glossy Neumorphic Surface */
.neu-panel {
  background: var(--specular), var(--surface);
  border-radius: 28px;
  border: 1px solid var(--rim);
  box-shadow:
    10px 10px 22px var(--shadow-dark),
    -8px -8px 20px var(--shadow-light);
  transition: background 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

/* Recessed Neumorphic Well */
.neu-inset {
  background: var(--surface-lo);
  border-radius: 22px;
  border: 1px solid var(--rim);
  box-shadow:
    inset 6px 6px 14px var(--shadow-dark),
    inset -5px -5px 12px var(--shadow-light);
  transition: background 0.25s ease, box-shadow 0.25s ease;
}

/* Capsule Neumorphic Interactive Pill */
.neu-pill {
  background: var(--specular), var(--surface);
  border-radius: 9999px;
  border: 1px solid var(--rim);
  padding: 10px 18px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow:
    5px 5px 12px var(--shadow-dark),
    -4px -4px 10px var(--shadow-light);
  transition: transform 0.12s ease, box-shadow 0.16s ease, color 0.2s ease;
}

.neu-pill:hover {
  transform: translateY(-1px);
}

.neu-pill:active,
.neu-pill.active {
  background: var(--surface-lo);
  box-shadow:
    inset 4px 4px 9px var(--shadow-dark),
    inset -3px -3px 8px var(--shadow-light);
  color: var(--rf);
  transform: translateY(0);
}

.neu-pill.sm {
  padding: 8px 14px;
  font-size: 0.78rem;
}

.icon-pill {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 1.05rem;
}

/* Top Bar */
.topbar {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-well {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--surface-lo);
  box-shadow:
    inset 3px 3px 7px var(--shadow-dark),
    inset -3px -3px 7px var(--shadow-light);
}

.logo {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  object-fit: cover;
}

.brand h1 {
  font-size: 1.22rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.mode-switch {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-chip {
  border-radius: 9999px;
  padding: 9px 16px;
  font-size: 0.8rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ac);
  box-shadow: 0 0 10px var(--ac);
}

/* Metrics Strip */
.metrics-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.metric {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.m-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.m-val {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.m-val small {
  font-size: 0.88rem;
  font-weight: 700;
  opacity: 0.8;
}

.accent-rf {
  color: var(--rf);
}

.accent-ac {
  color: var(--ac);
}

/* Main Workspace */
.workspace-grid {
  display: grid;
  grid-template-columns: 1.65fr 1fr;
  gap: 18px;
}

.radar-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.radar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.toolbar-hint {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.canvas-well {
  position: relative;
  width: 100%;
  height: 430px;
  overflow: hidden;
  touch-action: none;
}

#mesh-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#mesh-canvas:active {
  cursor: grabbing;
}

.legend-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--muted);
}

.legend-bar span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.swatch.rf {
  background: var(--rf);
  box-shadow: 0 0 8px var(--rf);
}

.swatch.ac {
  background: var(--ac);
  box-shadow: 0 0 8px var(--ac);
}

.swatch.focus {
  background: var(--focus);
  box-shadow: 0 0 8px var(--focus);
}

/* Side Column */
.side-col {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.wave-card,
.events-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-title {
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.scope-well {
  height: 150px;
  overflow: hidden;
}

#scope-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.events-well {
  height: 230px;
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ev-row {
  padding: 9px 12px;
  border-radius: 14px;
  background: var(--surface);
  font-size: 0.78rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.ev-tag {
  font-weight: 800;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 9999px;
}

.ev-tag.rf {
  color: var(--rf);
}

.ev-tag.ac {
  color: var(--ac);
}

/* Nodes Grid */
.nodes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.node-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.node-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.node-title {
  font-weight: 800;
  font-size: 0.96rem;
}

.node-badge {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 9999px;
  color: var(--ac);
  background: var(--surface-lo);
  box-shadow:
    inset 2px 2px 5px var(--shadow-dark),
    inset -2px -2px 5px var(--shadow-light);
}

.node-bars {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 700;
}

.bar-row header {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
}

.meter {
  height: 8px;
  border-radius: 9999px;
  background: var(--bg);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.12s ease;
}

.meter-fill.rf {
  background: var(--rf);
}

.meter-fill.ac {
  background: var(--ac);
}

.empty-box {
  grid-column: 1 / -1;
  padding: 28px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.footer {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  padding-top: 6px;
}

@media (max-width: 960px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
  .metrics-strip {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 540px) {
  .metrics-strip {
    grid-template-columns: 1fr;
  }
  .canvas-well {
    height: 340px;
  }
}