:root {
  --bg: #030711;
  --panel: rgba(6, 15, 30, 0.66);
  --panel-strong: rgba(7, 18, 34, 0.82);
  --line: rgba(120, 176, 255, 0.18);
  --line-strong: rgba(148, 197, 255, 0.3);
  --text: #e7f2ff;
  --muted: #8193aa;
  --blue: #61a3ff;
  --cyan: #52e8ff;
  --violet: #9a5cff;
  --magenta: #f04dff;
  --orange: #ff9a3d;
  --green: #64ff77;
  --danger: #ff4d6d;
  --radius: 14px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
  --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 44%, rgba(28, 63, 119, 0.2), transparent 42%), var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

canvas#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  background: transparent;
}

.sim-app {
  position: relative;
  width: 100vw;
  height: 100vh;
  isolation: isolate;
}

.ui-shell {
  position: fixed;
  inset: 14px;
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr minmax(250px, 330px);
  grid-template-rows: 1fr;
  gap: 14px;
  z-index: 10;
  pointer-events: none;
  transition: opacity 260ms ease, transform 260ms ease, filter 260ms ease;
}

.ui-shell > * {
  pointer-events: auto;
}

.glass-panel {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(9, 21, 39, 0.74), rgba(4, 10, 21, 0.68));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(15px) saturate(120%);
}

.topbar {
  grid-column: 1 / 4;
  grid-row: 1;
  border-radius: var(--radius);
  display: grid;
  grid-template-columns: minmax(300px, 1fr) auto minmax(250px, 1fr);
  align-items: center;
  padding: 10px 14px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 50%;
  box-shadow: 0 0 24px rgba(125, 198, 255, 0.16);
}

h1,
h2,
h3,
p,
figure,
dl {
  margin: 0;
}

h1 {
  font-size: clamp(18px, 1.55vw, 27px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1.05;
  white-space: nowrap;
}

.brand-lockup p,
.hint,
.status-card p {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-top: 5px;
}

.tabs {
  display: flex;
  justify-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  background: rgba(4, 11, 22, 0.5);
  border-radius: 9px;
  overflow: hidden;
}

.tab,
.icon-button,
.primary-button,
.segmented-control button {
  color: var(--text);
  background: rgba(13, 31, 53, 0.58);
  border: 1px solid rgba(130, 190, 255, 0.16);
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.tab {
  padding: 11px 27px;
  color: #91a3bb;
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  border: 0;
  border-left: 1px solid rgba(130, 190, 255, 0.12);
}

.tab:first-child {
  border-left: 0;
}

.tab.active,
.segmented-control button.active {
  color: white;
  background: rgba(29, 66, 112, 0.72);
  box-shadow: inset 0 -2px 0 rgba(81, 179, 255, 0.7);
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.icon-button {
  width: 39px;
  height: 39px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 18px;
}

.primary-button {
  min-height: 38px;
  border-radius: 9px;
  padding: 0 16px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 11px;
}

.primary-button:hover,
.icon-button:hover,
.segmented-control button:hover,
.tab:hover {
  border-color: rgba(100, 210, 255, 0.5);
  background: rgba(30, 77, 127, 0.82);
}

.side-panel {
  grid-row: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(92, 147, 220, 0.4) transparent;
}

.left-panel {
  grid-column: 1;
}

.right-panel {
  grid-column: 3;
}

.card {
  border-radius: var(--radius);
  padding: 15px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 13px;
}

.section-heading h2,
.metric-card h3 {
  font-size: 13px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #eef6ff;
  font-weight: 700;
}

.section-heading span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

.slider-row,
.select-row,
.toggle-row {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) minmax(0, 110px) 58px;
  align-items: center;
  gap: 9px;
  min-height: 30px;
  color: #bfcee0;
  font-size: 12px;
}

.slider-row.wide {
  grid-template-columns: minmax(92px, 1fr) minmax(0, 1.25fr) 58px;
}

.slider-row span,
.select-row span,
.toggle-row span {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.slider-row output {
  color: #dbeaff;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 10px;
  min-width: 0;
  overflow: hidden;
  text-overflow: clip;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

input[type="color"] {
  width: 100%;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 31, 53, 0.58);
}

.color-row {
  grid-template-columns: minmax(96px, 1fr) minmax(120px, 1.4fr);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 14px currentColor;
}

.dot.inner { color: var(--violet); background: currentColor; }
.dot.shell { color: var(--blue); background: currentColor; }
.dot.mid { color: #4a5dff; background: currentColor; }
.dot.outer { color: var(--magenta); background: currentColor; }
.dot.boundary { color: var(--orange); background: currentColor; }
.dot.magneto { color: var(--cyan); background: currentColor; }

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin-top: 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
}

.segmented-control button {
  min-height: 34px;
  border: 0;
  border-left: 1px solid rgba(130, 190, 255, 0.12);
  color: #91a3bb;
  font-size: 11px;
}

.segmented-control button:first-child {
  border-left: 0;
}

.cross-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.cross-grid figure {
  position: relative;
  min-height: 82px;
  border: 1px solid rgba(130, 190, 255, 0.14);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(2, 8, 18, 0.5);
}

.cross-grid figcaption {
  position: absolute;
  left: 8px;
  top: 7px;
  color: #94a7bd;
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.mini-map,
.sparkline {
  width: 100%;
  height: 100%;
  display: block;
}

.status-card {
  min-height: 108px;
}

.live-dot {
  color: var(--green) !important;
}

.live-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  display: inline-block;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 16px var(--green);
}

.clock {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 31px;
  letter-spacing: 0.1em;
}

.select-row {
  grid-template-columns: minmax(90px, 1fr) minmax(130px, 1.4fr);
  margin-top: 12px;
}

select {
  width: 100%;
  color: var(--text);
  background: rgba(6, 18, 34, 0.82);
  border: 1px solid rgba(130, 190, 255, 0.2);
  border-radius: 8px;
  min-height: 34px;
  padding: 0 9px;
}

.color-ramp {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
  color: #91a3bb;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.color-ramp b {
  height: 9px;
  border-radius: 99px;
  background: linear-gradient(90deg, #266dff, #a24dff, #ff4dc7, #ff9f32, #ffe15c);
  box-shadow: 0 0 24px rgba(255, 87, 201, 0.22);
}

.diagnostics-card dl {
  display: grid;
  gap: 9px;
}

.diagnostics-card dl div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: #c4d0de;
  font-size: 12px;
}

.diagnostics-card dt {
  color: #8fa0b6;
}

.diagnostics-card dd {
  margin: 0;
  font-family: var(--font-mono);
  color: #edf6ff;
}

.toggle-row {
  grid-template-columns: 1fr auto;
  min-height: 32px;
}

.toggle-row input {
  width: 34px;
  height: 18px;
  accent-color: var(--blue);
}

.full-width {
  width: 100%;
  margin-top: 12px;
}

.link-button {
  display: grid;
  place-items: center;
  text-decoration: none;
}

.hint {
  margin-top: 10px;
  letter-spacing: 0.06em;
  text-transform: none;
  line-height: 1.45;
}

code {
  color: #d8edff;
  background: rgba(100, 180, 255, 0.1);
  padding: 1px 5px;
  border-radius: 5px;
}

.bottom-panel {
  grid-column: 2;
  grid-row: 3;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  min-height: 0;
}

.metric-card {
  border-radius: var(--radius);
  padding: 14px;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.metric-card h3 {
  font-size: 11px;
  color: #aab8c9;
}

.ratio-card {
  place-items: center;
}

.ratio-card h3 {
  justify-self: stretch;
}

.ratio-ring {
  position: relative;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at center, rgba(6, 12, 25, 0.95) 48%, transparent 50%), conic-gradient(from 18deg, var(--blue), var(--violet), var(--magenta), var(--orange), rgba(90, 116, 155, 0.25) 0);
  box-shadow: 0 0 40px rgba(148, 92, 255, 0.2);
}

.ratio-ring span {
  font-family: var(--font-mono);
  font-size: 28px;
}

.ratio-ring small {
  position: absolute;
  margin-top: 46px;
  color: #98a8ba;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 9px;
}

.show-ui-button,
.background-badge {
  position: fixed;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity 220ms ease, transform 220ms ease;
}

.show-ui-button {
  top: 18px;
  right: 18px;
  color: white;
  background: rgba(7, 18, 34, 0.78);
  border: 1px solid rgba(120, 180, 255, 0.3);
  border-radius: 999px;
  padding: 11px 17px;
  backdrop-filter: blur(14px);
  letter-spacing: 0.13em;
  text-transform: uppercase;
  font-size: 11px;
}

.background-badge {
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 8px);
  padding: 9px 15px;
  border-radius: 999px;
  color: #a9bdd6;
  background: rgba(5, 14, 26, 0.64);
  border: 1px solid rgba(120, 180, 255, 0.16);
  backdrop-filter: blur(14px);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

body.ui-hidden .ui-shell {
  opacity: 0;
  pointer-events: none;
  transform: scale(1.015);
  filter: blur(5px);
}

body.ui-hidden .show-ui-button,
body.ui-hidden .background-badge {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

body.ui-hidden:not(.background-mode) .background-badge {
  opacity: 0;
  pointer-events: none;
}

body.ui-hidden .background-badge {
  transform: translate(-50%, 0);
}

body.background-mode .show-ui-button {
  opacity: 0.18;
}

body.background-mode .ui-shell {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

body.background-mode .show-ui-button:hover {
  opacity: 1;
}

body.background-mode .background-badge {
  animation: fadeBadge 6s ease forwards;
}

@keyframes fadeBadge {
  0%, 68% { opacity: 1; }
  100% { opacity: 0; }
}

@media (max-width: 1180px) {
  .ui-shell {
    grid-template-columns: minmax(220px, 280px) 1fr minmax(220px, 280px);
    grid-template-rows: 1fr;
    gap: 10px;
    inset: 10px;
  }

  .side-panel {
    grid-row: 1;
  }
}

@media (max-width: 880px) {
  .ui-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    inset: 10px;
    overflow: hidden;
  }

  .side-panel {
    grid-column: 1;
    grid-row: 1;
    width: min(360px, calc(100vw - 20px));
    max-height: calc(100vh - 20px);
    justify-self: end;
    overflow: auto;
  }

  .card {
    padding: 13px;
  }

  .slider-row,
  .select-row,
  .toggle-row,
  .slider-row.wide {
    grid-template-columns: minmax(92px, 1fr) minmax(0, 1.2fr) 54px;
    gap: 8px;
  }
}
