:root {
  --bg: #03050b;
  --panel: rgba(8, 14, 28, 0.78);
  --panel-strong: rgba(10, 18, 36, 0.94);
  --line: rgba(113, 223, 255, 0.18);
  --text: #eaf8ff;
  --muted: #83a0b2;
  --cyan: #48e7ff;
  --amber: #ffb13d;
  --hot: #ff5f2e;
  --green: #7dffb8;
  --shadow: 0 18px 70px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  background:
    radial-gradient(circle at 50% 20%, rgba(48, 126, 255, 0.12), transparent 32%),
    radial-gradient(circle at 72% 55%, rgba(255, 132, 34, 0.10), transparent 40%),
    linear-gradient(180deg, #02030a, #050915 55%, #03050b);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 580px;
  overflow: hidden;
}

.stage-wrap { position: absolute; inset: 0; }
#crogenticStage { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }

.stage-wrap::after {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(3, 5, 11, 0.84), transparent 20%, transparent 80%, rgba(3, 5, 11, 0.84)),
    linear-gradient(180deg, rgba(3, 5, 11, 0.55), transparent 18%, transparent 82%, rgba(3, 5, 11, 0.68));
}

.brand-badge {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 13px;
  border: 1px solid rgba(72, 231, 255, 0.22);
  background: rgba(4, 9, 19, 0.54);
  backdrop-filter: blur(12px);
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 5;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #031019;
  font-weight: 900;
  background: linear-gradient(135deg, var(--cyan), var(--amber));
}
.brand-badge strong { display: block; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
.brand-badge span { display: block; color: var(--muted); font-size: 11px; margin-top: -2px; }

.panel {
  position: absolute;
  top: 74px;
  bottom: 62px;
  width: min(352px, calc(100vw - 24px));
  z-index: 8;
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(9, 18, 36, 0.86), rgba(5, 8, 18, 0.72));
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  scrollbar-width: thin;
}
.panel-left { left: 16px; }
.panel-right { right: 16px; }

.panel-header h1 { margin: 0; font-size: 28px; letter-spacing: -0.05em; }
.panel-header p { margin: 6px 0 18px; color: var(--muted); line-height: 1.35; }

.field-label, .section-title {
  display: block;
  margin: 14px 0 8px;
  color: #bcefff;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
}

textarea, input[type="text"] {
  width: 100%;
  border: 1px solid rgba(72, 231, 255, 0.17);
  border-radius: 16px;
  color: var(--text);
  outline: none;
  background: rgba(0, 0, 0, 0.24);
  padding: 12px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}
textarea:focus, input[type="text"]:focus { border-color: rgba(72, 231, 255, 0.52); }

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin: 12px 0;
}
.button-grid.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.button-grid.compact button { padding-inline: 6px; }

.control {
  border: 1px solid rgba(123, 203, 255, 0.18);
  border-radius: 14px;
  color: #dff8ff;
  background: rgba(255, 255, 255, 0.055);
  padding: 11px 10px;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}
.control:hover { transform: translateY(-1px); border-color: rgba(72, 231, 255, 0.45); }
.control.active { background: rgba(72, 231, 255, 0.17); border-color: rgba(72, 231, 255, 0.62); }
.control.primary { background: linear-gradient(135deg, rgba(72, 231, 255, 0.28), rgba(255, 177, 61, 0.24)); border-color: rgba(72, 231, 255, 0.5); }
.control.hot { background: linear-gradient(135deg, rgba(255, 95, 46, 0.26), rgba(255, 177, 61, 0.2)); border-color: rgba(255, 177, 61, 0.4); }

.slider-row {
  display: grid;
  grid-template-columns: 70px 1fr 50px;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 13px;
}
input[type="range"] { accent-color: var(--cyan); width: 100%; }
output { color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }

.glyph-buttons {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 7px;
}
.glyph-buttons button {
  min-height: 34px;
  border: 1px solid rgba(72, 231, 255, 0.16);
  border-radius: 11px;
  color: #e8fbff;
  background: rgba(255, 255, 255, 0.045);
  cursor: pointer;
}
.glyph-buttons button:hover { background: rgba(72, 231, 255, 0.12); }

.readout-card {
  border: 1px solid rgba(72, 231, 255, 0.14);
  border-radius: 20px;
  padding: 14px;
  background: rgba(0, 0, 0, 0.18);
  margin-bottom: 14px;
}
.readout-card .section-title { margin-top: 0; }
.readout-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}
.readout-grid div {
  padding: 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.045);
}
dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
dd { margin: 3px 0 0; font-size: 18px; font-weight: 850; font-variant-numeric: tabular-nums; }

.ai-console {
  min-height: 132px;
  max-height: 248px;
  overflow: auto;
  color: #c8f7ff;
  line-height: 1.45;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}
.fine-print { color: var(--muted); font-size: 12px; line-height: 1.35; }

.bottom-dock {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 9;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  border: 1px solid rgba(72, 231, 255, 0.16);
  border-radius: 999px;
  background: rgba(4, 8, 18, 0.65);
  backdrop-filter: blur(16px);
  color: #b8ecf6;
  box-shadow: var(--shadow);
  font-size: 12px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%) translateY(14px);
  opacity: 0;
  pointer-events: none;
  z-index: 12;
  padding: 10px 14px;
  border-radius: 999px;
  color: #eaffff;
  background: rgba(4, 8, 18, 0.88);
  border: 1px solid rgba(72, 231, 255, 0.26);
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 980px) {
  .brand-badge { top: 10px; }
  .panel {
    width: calc(50vw - 18px);
    top: auto;
    bottom: 62px;
    max-height: 38dvh;
    border-radius: 18px;
    padding: 12px;
  }
  .panel-left { left: 10px; }
  .panel-right { right: 10px; }
  .panel-header h1 { font-size: 22px; }
  .button-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .glyph-buttons { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .app-shell { min-height: 640px; }
  .brand-badge { left: 12px; right: 12px; transform: none; justify-content: center; }
  .panel {
    top: auto;
    bottom: 60px;
    width: calc(50vw - 14px);
    max-height: 34dvh;
  }
  .panel-left { left: 8px; }
  .panel-right { right: 8px; }
  .bottom-dock { left: 8px; right: 8px; font-size: 11px; }
  .readout-grid { grid-template-columns: 1fr; }
  dd { font-size: 15px; }
}
