:root {
  --bg: #050608;
  --bg-soft: #0b0d11;
  --panel: rgba(14, 16, 22, 0.88);
  --panel-strong: rgba(18, 21, 28, 0.96);
  --panel-muted: rgba(22, 26, 35, 0.86);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #f4f5f7;
  --muted: rgba(244, 245, 247, 0.68);
  --muted-soft: rgba(244, 245, 247, 0.44);
  --accent: #8abfff;
  --accent-strong: #9fd6ff;
  --danger: #cf342f;
  --danger-soft: rgba(207, 52, 47, 0.28);
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: "Manrope", "Inter", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 680px at 15% 0%, rgba(98, 124, 166, 0.18), transparent 60%),
    radial-gradient(1000px 640px at 100% 0%, rgba(255, 255, 255, 0.05), transparent 62%),
    linear-gradient(180deg, #090a0f 0%, #040507 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.012), rgba(255, 255, 255, 0.012)),
    repeating-linear-gradient(90deg, transparent 0 119px, rgba(255, 255, 255, 0.012) 119px 120px);
  opacity: 0.3;
  mix-blend-mode: screen;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

.sim-app {
  width: min(1180px, calc(100% - 28px));
  margin: clamp(14px, 3vw, 24px) auto 18px;
}

.sim-shell {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.012)),
    linear-gradient(180deg, rgba(11, 13, 18, 0.98), rgba(8, 10, 14, 0.96));
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sim-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top left, rgba(138, 191, 255, 0.08), transparent 36%);
  pointer-events: none;
}

.sim-topbar {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  min-height: 76px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(24, 27, 35, 0.9), rgba(14, 16, 22, 0.92));
}

.sim-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.78rem;
  text-decoration: none;
}

.sim-brand__mark {
  width: 30px;
  height: 30px;
  stroke: #67a9ff;
  fill: none;
  stroke-width: 2.25;
  stroke-linejoin: round;
}

.sim-brand__wordmark {
  font-size: clamp(1.7rem, 2vw, 2.25rem);
  font-weight: 800;
  letter-spacing: -0.05em;
}

.sim-tabs {
  display: flex;
  justify-content: center;
  gap: 0.15rem;
  min-width: 0;
}

.sim-tab {
  position: relative;
  min-width: 0;
  padding: 0.9rem 1.45rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: color 0.2s ease;
}

.sim-tab:hover,
.sim-tab:focus-visible {
  color: var(--text);
  outline: none;
}

.sim-tab.is-active {
  color: var(--accent);
}

.sim-tab.is-active::after {
  content: "";
  position: absolute;
  left: 0.85rem;
  right: 0.85rem;
  bottom: -1px;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(138, 191, 255, 0.5), var(--accent-strong), rgba(138, 191, 255, 0.4));
}

.sim-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.icon-btn,
.transport-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line-strong);
  color: var(--text);
  outline: none;
}

.icon-btn svg,
.transport-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn svg circle {
  fill: currentColor;
  stroke: none;
}

.sim-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  grid-template-rows: minmax(440px, 1fr) auto;
  grid-template-areas:
    "stage side"
    "scenario controls";
}

.stage-panel,
.path-panel,
.scenario-panel,
.transport-panel {
  background: linear-gradient(180deg, rgba(12, 14, 19, 0.88), rgba(8, 10, 14, 0.92));
}

.stage-panel {
  grid-area: stage;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.stage-panel__surface {
  position: relative;
  min-height: 100%;
  background:
    radial-gradient(circle at 25% 15%, rgba(255, 255, 255, 0.06), transparent 32%),
    linear-gradient(180deg, rgba(15, 17, 22, 0.5), rgba(10, 12, 16, 0.85));
}

#stormCanvas,
#pathCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.stage-panel__surface,
.path-panel__map {
  overflow: hidden;
}

.stage-panel__vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at center, transparent 38%, rgba(0, 0, 0, 0.3) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.22), transparent 22%, transparent 72%, rgba(0, 0, 0, 0.36));
}

.path-panel {
  grid-area: side;
  padding: 20px 22px 18px;
  border-bottom: 1px solid var(--line);
}

.path-panel__title {
  margin: 0 0 14px;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.path-panel__map {
  height: 278px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(40, 44, 56, 0.5), rgba(28, 31, 39, 0.75)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent);
}

.sim-toggle {
  display: flex;
  align-items: center;
  gap: 0.72rem;
  margin-top: 16px;
  color: var(--text);
  cursor: pointer;
}

.sim-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.sim-toggle__box {
  position: relative;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.sim-toggle__label {
  font-size: 0.9rem;
  font-weight: 600;
}

.sim-toggle input:checked + .sim-toggle__box {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
}

.sim-toggle input:checked + .sim-toggle__box::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.06));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.sim-toggle input:focus-visible + .sim-toggle__box {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.scenario-panel {
  grid-area: scenario;
  padding: 16px 18px 18px;
  border-right: 1px solid var(--line);
}

.panel-label {
  margin-bottom: 12px;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0.01));
  overflow: hidden;
}

.scenario-item {
  min-width: 0;
  padding: 12px 18px;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.scenario-item:nth-child(3n) {
  border-right: 0;
}

.scenario-item:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.scenario-item__label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.scenario-item__value {
  display: block;
  font-family: "Inter", sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.transport-panel {
  grid-area: controls;
  display: grid;
  align-content: center;
  gap: 14px;
  padding: 16px 18px 18px;
}

.transport-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  min-height: 84px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
}

.transport-btn {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}

.transport-btn:hover,
.transport-btn:focus-visible {
  color: var(--text);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.06);
  transform: translateY(-1px);
  outline: none;
}

.transport-btn--primary {
  width: 62px;
  height: 62px;
}

.transport-btn svg.icon-play {
  display: none;
}

body.is-paused .transport-btn svg.icon-play {
  display: block;
  fill: currentColor;
  stroke: none;
}

body.is-paused .transport-btn svg.icon-pause {
  display: none;
}

.transport-readout {
  display: grid;
  gap: 2px;
  justify-items: center;
  text-align: center;
}

.transport-readout span {
  color: var(--muted-soft);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.transport-readout strong {
  font-size: 0.96rem;
  font-weight: 700;
}

.sim-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 14px 4px 0;
  color: var(--muted-soft);
  font-size: 0.86rem;
}

.sim-footer a {
  text-decoration: none;
}

.sim-footer a:hover {
  color: var(--text);
}

@media (max-width: 980px) {
  .sim-topbar {
    grid-template-columns: 1fr;
    justify-items: center;
    padding: 18px 16px 14px;
  }

  .sim-brand {
    justify-self: start;
  }

  .sim-tabs {
    flex-wrap: wrap;
  }

  .sim-actions {
    justify-self: end;
    margin-top: -48px;
  }

  .sim-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "stage"
      "side"
      "scenario"
      "controls";
  }

  .stage-panel,
  .scenario-panel {
    border-right: 0;
  }

  .path-panel,
  .scenario-panel {
    border-bottom: 1px solid var(--line);
  }

  .transport-panel {
    padding-top: 18px;
  }
}

@media (max-width: 700px) {
  .sim-app {
    width: min(100%, calc(100% - 12px));
    margin-top: 6px;
  }

  .sim-shell {
    border-radius: 22px;
  }

  .sim-topbar {
    padding: 16px 14px 12px;
  }

  .sim-brand__wordmark {
    font-size: 1.9rem;
  }

  .sim-tab {
    padding: 0.8rem 0.85rem;
    font-size: 0.86rem;
  }

  .path-panel,
  .scenario-panel,
  .transport-panel {
    padding-left: 14px;
    padding-right: 14px;
  }

  .stage-panel__surface {
    min-height: 320px;
  }

  .path-panel__map {
    height: 240px;
  }

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

  .scenario-item:nth-child(3n) {
    border-right: 1px solid rgba(255, 255, 255, 0.05);
  }

  .scenario-item:nth-child(2n) {
    border-right: 0;
  }

  .scenario-item:nth-last-child(-n + 2) {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  }

  .scenario-item:last-child {
    border-bottom: 0;
  }

  .sim-footer {
    flex-direction: column;
    gap: 0.3rem;
    padding: 12px 4px 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto;
  }

  .transport-btn,
  .sim-tab,
  .icon-btn,
  .sim-toggle__box {
    transition: none;
  }
}
