:root {
  color-scheme: dark;
  --font-ui: "Aptos", "Segoe UI", "Trebuchet MS", sans-serif;
  --font-display: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --bg-1: #041226;
  --bg-2: #0b2746;
  --bg-3: #10385a;
  --panel: rgba(7, 18, 37, 0.58);
  --panel-strong: rgba(9, 23, 46, 0.8);
  --panel-border: rgba(163, 222, 255, 0.18);
  --text-main: #eff8ff;
  --text-soft: #bad1e7;
  --text-muted: #8aa1ba;
  --primary: #6be2ff;
  --primary-strong: #1eb8de;
  --accent: #ffb453;
  --accent-strong: #ff8d48;
  --success: #83f7bb;
  --danger: #ff7b8b;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.33);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

.app-shell[data-theme="light"] {
  color-scheme: light;
  --bg-1: #eef6ff;
  --bg-2: #d7ebff;
  --bg-3: #bfdcff;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-strong: rgba(255, 255, 255, 0.82);
  --panel-border: rgba(48, 108, 165, 0.18);
  --text-main: #10233d;
  --text-soft: #274666;
  --text-muted: #54708e;
  --primary: #0089b8;
  --primary-strong: #006c93;
  --accent: #f49532;
  --accent-strong: #df6f22;
  --success: #1e9a63;
  --danger: #df4762;
  --shadow: 0 20px 54px rgba(44, 83, 123, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-ui);
  color: var(--text-main);
  background:
    radial-gradient(circle at 12% 14%, rgba(101, 205, 255, 0.18), transparent 28%),
    radial-gradient(circle at 88% 18%, rgba(255, 180, 83, 0.14), transparent 22%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2) 48%, var(--bg-3));
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  padding: 28px;
  isolation: isolate;
}

.ambient {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

.ambient-orb {
  filter: blur(42px);
  opacity: 0.8;
}

.ambient-one {
  inset: auto auto 12% 8%;
  width: 320px;
  height: 320px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(86, 194, 255, 0.32), transparent 68%);
  animation: drift 16s ease-in-out infinite;
}

.ambient-two {
  inset: 12% 10% auto auto;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 169, 91, 0.26), transparent 70%);
  animation: drift 20s ease-in-out infinite reverse;
}

.ambient-grid {
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.35), transparent 82%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
}

.brand-block h1,
.section-heading h2,
.graph-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-block h1 {
  font-size: clamp(2.1rem, 2.7vw, 3.6rem);
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  font-size: 0.74rem;
  color: var(--primary);
}

.subtitle,
.stage-caption,
.canvas-footer,
.toggle-card small,
.mini-label,
.stat-label,
.graph-accent {
  color: var(--text-soft);
}

.subtitle {
  max-width: 720px;
  margin: 10px 0 0;
  line-height: 1.55;
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.glass-panel {
  position: relative;
  background: linear-gradient(160deg, var(--panel), var(--panel-strong));
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  border-radius: var(--radius-xl);
}

.panel {
  padding: 22px;
}

.controls-panel {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.panel-section {
  padding: 18px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.section-heading {
  margin-bottom: 18px;
}

.section-heading.compact {
  margin-bottom: 16px;
}

.control-group + .control-group {
  margin-top: 18px;
}

.control-header,
.control-row,
.graph-head,
.canvas-footer,
.badge-row,
.mini-stats,
.button-grid,
.toggle-grid,
.stat-grid,
.graph-grid {
  display: grid;
  gap: 12px;
}

.control-header {
  grid-template-columns: 1fr auto;
  align-items: center;
  margin-bottom: 10px;
}

.control-header label,
.stacked-label,
.graph-head h3 {
  font-weight: 600;
}

.control-row {
  grid-template-columns: minmax(0, 1fr) 96px;
  align-items: center;
}

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

.number-input,
.select-input,
.ghost-button,
.action-button {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.number-input,
.select-input {
  width: 100%;
  padding: 10px 12px;
}

.stacked-label {
  display: block;
  margin: 12px 0 8px;
}

.value-pill,
.status-badge {
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(107, 226, 255, 0.13);
  border: 1px solid rgba(107, 226, 255, 0.2);
  color: var(--text-main);
  font-size: 0.92rem;
}

.toggle-grid {
  margin-top: 16px;
}

.toggle-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.toggle-card span {
  display: grid;
  gap: 4px;
}

.toggle-card input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.button-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 18px;
}

.ghost-button,
.action-button {
  padding: 11px 16px;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.ghost-button:hover,
.action-button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.3);
}

.action-button.primary {
  background: linear-gradient(135deg, rgba(44, 199, 255, 0.92), rgba(25, 130, 179, 0.92));
  color: #051422;
  font-weight: 700;
}

.action-button.accent {
  background: linear-gradient(135deg, rgba(255, 186, 103, 0.92), rgba(243, 129, 70, 0.92));
  color: #341103;
  font-weight: 700;
}

.mini-stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mini-stat,
.stat-card,
.graph-card {
  padding: 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.mini-stat strong,
.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.02rem;
}

.feedback-banner {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  line-height: 1.5;
}

.feedback-banner.neutral {
  background: rgba(107, 226, 255, 0.12);
  color: var(--text-main);
}

.feedback-banner.success {
  background: rgba(131, 247, 187, 0.14);
  color: var(--success);
}

.feedback-banner.danger {
  background: rgba(255, 123, 139, 0.14);
  color: var(--danger);
}

.equation-card {
  display: grid;
  gap: 12px;
  line-height: 1.6;
  color: var(--text-soft);
}

.equation-line {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.equation-line code {
  display: block;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.98rem;
  color: var(--text-main);
}

.simulation-column {
  display: grid;
  gap: 22px;
}

.simulation-card {
  padding: 18px;
}

.stage-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.badge-row {
  grid-auto-flow: column;
  width: max-content;
}

.status-badge.secondary {
  background: rgba(255, 180, 83, 0.12);
  border-color: rgba(255, 180, 83, 0.2);
}

.canvas-wrap {
  position: relative;
  min-height: 480px;
  border-radius: 24px;
  overflow: hidden;
  background:
    linear-gradient(to bottom, rgba(117, 210, 255, 0.08), rgba(5, 17, 34, 0.08)),
    rgba(2, 10, 22, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#simulationCanvas,
#graphXCanvas,
#graphYCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

#simulationCanvas {
  min-height: 480px;
}

.canvas-footer {
  grid-auto-flow: column;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 0.93rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
}

.data-panel,
.graphs-panel {
  padding: 18px;
}

.stat-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat-card {
  min-height: 102px;
}

.graph-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.graph-card {
  display: grid;
  gap: 14px;
}

.graph-head {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.graph-accent {
  font-size: 0.88rem;
}

.graph-accent.cyan {
  color: var(--primary);
}

.graph-accent.amber {
  color: var(--accent);
}

#graphXCanvas,
#graphYCanvas {
  min-height: 220px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.15);
}

@keyframes drift {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(16px, -14px, 0) scale(1.06);
  }
}

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

  .controls-panel {
    order: 2;
  }

  .simulation-column {
    order: 1;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding: 18px;
  }

  .topbar,
  .stage-head,
  .canvas-footer {
    grid-auto-flow: row;
    display: grid;
  }

  .button-grid,
  .mini-stats,
  .graph-grid {
    grid-template-columns: 1fr;
  }

  .control-row {
    grid-template-columns: 1fr;
  }

  .number-input {
    max-width: none;
  }

  .canvas-wrap,
  #simulationCanvas {
    min-height: 360px;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }

  .brand-block,
  .simulation-column,
  .controls-panel {
    min-width: 0;
  }

  .topbar-actions {
    width: 100%;
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding:
      16px
      max(16px, env(safe-area-inset-right))
      16px
      max(16px, env(safe-area-inset-left));
  }

  .glass-panel {
    border-radius: 24px;
  }

  .controls-panel,
  .simulation-card,
  .data-panel,
  .graphs-panel {
    padding: 16px;
  }

  .panel-section {
    padding: 15px;
  }

  .brand-block h1 {
    font-size: clamp(1.95rem, 9vw, 2.8rem);
  }

  .subtitle {
    font-size: 0.98rem;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-actions .ghost-button {
    width: 100%;
    min-height: 46px;
  }

  .control-header {
    grid-template-columns: 1fr;
    align-items: flex-start;
    gap: 8px;
  }

  .value-pill {
    width: max-content;
  }

  .toggle-card {
    align-items: flex-start;
  }

  .toggle-card input {
    margin-top: 6px;
  }

  .button-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .button-grid .action-button {
    min-height: 48px;
  }

  .mini-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-card {
    min-height: 96px;
  }

  .badge-row {
    grid-auto-flow: row;
    width: 100%;
    justify-items: start;
  }

  .canvas-wrap,
  #simulationCanvas {
    min-height: clamp(300px, 68vw, 420px);
  }

  #graphXCanvas,
  #graphYCanvas {
    min-height: 190px;
  }

  .canvas-footer span {
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding:
      12px
      max(12px, env(safe-area-inset-right))
      12px
      max(12px, env(safe-area-inset-left));
  }

  .brand-block h1 {
    font-size: clamp(1.75rem, 10vw, 2.35rem);
  }

  .eyebrow {
    font-size: 0.68rem;
    letter-spacing: 0.18em;
  }

  .topbar-actions,
  .button-grid,
  .mini-stats,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .graph-head {
    grid-template-columns: 1fr;
  }

  .canvas-wrap,
  #simulationCanvas {
    min-height: clamp(250px, 74vw, 340px);
    border-radius: 20px;
  }

  #graphXCanvas,
  #graphYCanvas {
    min-height: 170px;
  }

  .canvas-footer {
    font-size: 0.88rem;
  }

  .number-input,
  .select-input,
  .ghost-button,
  .action-button {
    min-height: 46px;
  }
}
