:root {
  --bg-0: #07101a;
  --bg-1: #0b1622;
  --panel: rgba(11, 19, 30, 0.88);
  --panel-border: rgba(149, 187, 226, 0.16);
  --text: #eaf4ff;
  --muted: #aac0d8;
  --accent: #66d7ff;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background: #080a0d;
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

.sidebar {
  position: relative;
  display: grid;
  grid-template-rows: 1fr;
  gap: 12px;
  padding: 10px;
  border: none;
  border-radius: 14px;
  background: #0f1318;
  box-shadow: none;
  min-height: 0;
}

.sidebar.sim-locked::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(9, 11, 14, 0.72);
  z-index: 3;
  pointer-events: none;
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: minmax(0, 1fr);
  gap: 8px;
  align-content: stretch;
  height: 100%;
  min-height: 0;
}

button {
  border: none;
  border-radius: 10px;
  background: #1a2027;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.tool-btn {
  width: 100%;
  min-height: 0;
  padding: 0;
  background-color: rgba(17, 27, 40, 0.9);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 72%;
  image-rendering: pixelated;
}

.tool-btn.active {
  background-color: rgba(102, 215, 255, 0.14);
}

.tool-btn[data-tool="wire"] {
  background-image: url("Assets/wire.png");
}

.tool-btn[data-tool="select"] {
  background-image: url("Assets/select.png");
}

.tool-btn[data-tool="and"] {
  background-image: url("Assets/and.png");
}

.tool-btn[data-tool="or"] {
  background-image: url("Assets/or.png");
}

.tool-btn[data-tool="not"] {
  background-image: url("Assets/not.png");
}

.tool-btn[data-tool="trigger"] {
  background-image: url("Assets/trigger.png");
}

.tool-btn[data-tool="light"] {
  background-image: url("Assets/light.png");
}

.tool-btn[data-tool="crossover"] {
  background-image: url("Assets/crossover.png");
}

.tool-btn[data-tool="random"] {
  background-image: url("Assets/random.png");
}

.tool-btn[data-tool="delay"] {
  background-image: url("Assets/delay.png");
}

.sim-controls {
  display: grid;
  gap: 8px;
  padding: 8px;
  border-radius: 10px;
  border: none;
  background: #0b0f14;
}

.run-btn {
  padding: 10px 0;
  font-weight: 700;
}

.mini-btn {
  padding: 8px 0;
  font-size: 0.85rem;
}

.run-btn.running {
  background: #234a33;
}

.slider-wrap {
  display: block;
}

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

.stage {
  position: relative;
  min-width: 0;
  border-radius: 14px;
  border: none;
  overflow: hidden;
  box-shadow: none;
  background: #090b0e;
}

.start-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  background: #090b0e;
}

.start-overlay.hidden {
  display: none;
}

.start-panel {
  display: grid;
  gap: 10px;
  width: min(220px, 70vw);
}

.start-btn {
  padding: 14px 16px;
  font-weight: 700;
  border-radius: 10px;
  background: #171c22;
}

.hotkey-help {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 1;
  display: grid;
  gap: 2px;
  text-align: right;
  color: rgba(200, 200, 200, 0.5);
  font-size: 11px;
  line-height: 1.25;
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}

.hotkey-help > :first-child {
  color: rgba(210, 210, 210, 0.5);
  font-weight: 700;
}

#simCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.stage.panning #simCanvas {
  cursor: grabbing;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(320px, 1fr);
  }

  .sidebar {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    align-items: start;
  }

  .tool-grid {
    grid-template-columns: repeat(10, minmax(0, 1fr));
    grid-auto-rows: 48px;
    height: auto;
  }

  .stage {
    min-height: 58vh;
  }
}

body.sw-shell-body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.sw-route-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid #2e3746;
  background: #11161d;
}

.sw-route-header[hidden] {
  display: none !important;
}

.sw-route-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sw-route-header__brand > a {
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.sw-route-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sw-route-header__actions > a,
.sw-route-header__actions > button {
  border: 1px solid #2e3746;
  border-radius: 8px;
  background: #161c25;
  color: var(--text);
  padding: 8px 10px;
  text-decoration: none;
}

.sw-route-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #2e3746;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  color: #c9d4e4;
  background: #161c25;
}

.sw-search-view {
  min-height: 0;
  overflow: auto;
  padding: 16px;
  background: #0f1319;
}

.sw-search-view[hidden] {
  display: none !important;
}

.sw-search-wrap {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  gap: 14px;
}

.sw-search-card {
  border: 1px solid #2e3746;
  border-radius: 10px;
  background: #161c25;
  padding: 16px;
}

.sw-search-card--hero {
  background: #161c25;
}

.sw-search-kicker {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.sw-search-card h1 {
  margin: 8px 0 8px;
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.05;
}

.sw-search-card p {
  margin: 0;
  color: var(--muted);
}

.sw-search-hero-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.sw-search-hero-actions a,
.sw-search-hero-actions button {
  border: 1px solid #2e3746;
  border-radius: 8px;
  background: #1a2230;
  color: var(--text);
  padding: 9px 12px;
  text-decoration: none;
  cursor: pointer;
}

.sw-search-toolbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}

.sw-search-tabs {
  display: inline-flex;
  gap: 6px;
  border: 1px solid #2e3746;
  border-radius: 8px;
  padding: 4px;
  background: #121822;
}

.sw-search-tabs button {
  padding: 8px 12px;
  border-radius: 6px;
  border: none;
  background: transparent;
}

.sw-search-tabs button.is-active {
  background: #263247;
}

.sw-search-toolbar input,
.sw-cloud-panel input,
.sw-cloud-panel textarea,
.sw-cloud-panel select {
  border: 1px solid #2e3746;
  border-radius: 8px;
  background: #0f141c;
  color: var(--text);
  padding: 9px 10px;
  font: inherit;
}

.sw-search-msg {
  min-height: 18px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.sw-search-msg[data-kind="error"] {
  color: #f0a6a6;
}

.sw-search-msg[data-kind="success"] {
  color: #9ed9aa;
}

.sw-search-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.sw-result-card {
  border: 1px solid #2e3746;
  border-radius: 10px;
  padding: 12px;
  background: #131923;
  display: grid;
  gap: 8px;
}

.sw-result-card a {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}

.sw-result-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.sw-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sw-chip {
  border: 1px solid #2e3746;
  border-radius: 999px;
  padding: 3px 8px;
  color: #bac6d8;
  font-size: 12px;
  background: #10151d;
}

body.sw-mode-search .app-shell,
body.sw-mode-search .sw-cloud-panel {
  display: none !important;
}

body.sw-mode-editor .sw-search-view {
  display: none !important;
}

body.sw-mode-editor {
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-rows: auto minmax(0, 1fr);
}

body.sw-mode-editor .sw-route-header {
  grid-column: 1 / -1;
}

body.sw-mode-editor .app-shell {
  grid-column: 1;
  grid-row: 2;
  grid-template-columns: 92px minmax(0, 1fr);
  min-height: 0;
}

.sw-cloud-panel {
  border-radius: 10px;
  background: #161c25;
  border: 1px solid #2e3746;
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  overflow: auto;
}

.sw-cloud-panel[hidden] {
  display: none !important;
}

body.sw-mode-editor .sw-cloud-panel {
  grid-column: 2;
  grid-row: 2;
  margin: 12px 12px 12px 0;
}

.sw-cloud-panel__head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 10px;
}

.sw-cloud-panel__head h2 {
  margin: 4px 0 0;
  font-size: 20px;
  line-height: 1.1;
}

.sw-cloud-panel__head a {
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}

.sw-cloud-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.sw-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.sw-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.sw-check input {
  width: auto;
  padding: 0;
}

.sw-panel-group {
  border-top: 1px solid #2e3746;
  padding-top: 10px;
  display: grid;
  gap: 8px;
}

.sw-panel-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.sw-panel-actions button,
.sw-panel-group button,
.sw-picker-row button {
  border: 1px solid #2e3746;
  border-radius: 8px;
  background: #1a2230;
  color: var(--text);
  padding: 9px 10px;
  cursor: pointer;
}

.sw-picker-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.sw-mini-list {
  display: grid;
  gap: 8px;
}

.sw-mini-item {
  border: 1px solid #2e3746;
  border-radius: 8px;
  padding: 10px;
  background: #131923;
  display: grid;
  gap: 6px;
}

.sw-mini-item a {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}

.sw-mini-item .sw-row button {
  padding: 6px 8px;
}

@media (max-width: 1200px) {
  body.sw-mode-editor {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  body.sw-mode-editor .app-shell {
    grid-column: 1;
    grid-row: 2;
  }

  body.sw-mode-editor .sw-cloud-panel {
    grid-column: 1;
    grid-row: 3;
    margin: 0 12px 12px;
  }
}

@media (max-width: 860px) {
  .sw-search-toolbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
}
