/* ------------------------------------------------------------------ theme */
:root {
  --bg: #0b0f18;
  --bg-panel: #131a28;
  --bg-panel-2: #182233;
  --bg-input: #0d1320;
  --border: #24304a;
  --border-strong: #33415f;
  --text: #e6eefb;
  --text-dim: #9db0ca;
  --text-faint: #6d7f99;
  --accent: #4fc3f7;
  --accent-2: #ffd166;
  --good: #9ccc65;
  --warn: #ffb74d;
  --bad: #ff7043;
  --pink: #f06292;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--sans);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.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;
}

/* ----------------------------------------------------------------- header */
.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 9px 14px;
  background: linear-gradient(180deg, #182131, #121a27);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.brand-mark {
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
}

.mech-name-label {
  flex: 1 1 160px;
  min-width: 120px;
}

.mech-name {
  width: 100%;
  max-width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font: 600 13px var(--sans);
}

.mech-name:focus {
  outline: 2px solid rgba(79, 195, 247, 0.5);
  outline-offset: 1px;
}

.header-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ----------------------------------------------------------------- layout */
.app-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 268px minmax(320px, 1fr) 336px;
  gap: 1px;
  background: var(--border);
}

.panel {
  background: var(--bg-panel);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  /* grid items default to min-width:auto, which lets wide tables stretch the
     whole layout on narrow screens — opt out so panels can shrink instead. */
  min-width: 0;
}

.app-body > * {
  min-width: 0;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-title {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 700;
}

.hint {
  margin: 0;
  color: var(--text-faint);
  font-size: 11.5px;
  line-height: 1.5;
}

/* ----------------------------------------------------------------- canvas */
.canvas-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #0f1420;
}

#canvas {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

#canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.canvas-hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 20, 32, 0.92);
  border: 1px solid var(--border-strong);
  color: var(--accent-2);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  pointer-events: none;
  box-shadow: var(--shadow);
}

/* -------------------------------------------------------------- transport */
.transport {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--bg-panel-2);
  border-top: 1px solid var(--border);
}

.slider-field {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
}

.slider-field input[type="range"] {
  width: 128px;
  accent-color: var(--accent);
}

.slider-field output {
  font: 600 11.5px var(--mono);
  color: var(--text);
  min-width: 44px;
  text-align: right;
}

.status-bar {
  flex: 0 0 auto;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  background: #101725;
  font: 11.5px var(--mono);
  color: var(--text-dim);
  min-height: 30px;
}

.status-bar b {
  color: var(--text);
  font-weight: 650;
}

.status-ok {
  color: var(--good);
}

.status-warn {
  color: var(--warn);
}

.status-bad {
  color: var(--bad);
}

/* ---------------------------------------------------------------- buttons */
.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: #1b2537;
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  font: 600 12px var(--sans);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
}

.btn:hover {
  background: #223048;
  border-color: #40507a;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn-primary {
  background: #1d4f6b;
  border-color: #2c7ea6;
}

.btn-primary:hover {
  background: #23607f;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
  font-weight: 550;
}

.btn-ghost:hover {
  color: var(--text);
  background: #1a2334;
}

.btn.is-active {
  background: #1d4f6b;
  border-color: var(--accent);
  color: #fff;
}

.btn.is-danger {
  border-color: #6b2b1d;
  color: #ffb9a6;
}

.btn.is-danger:hover {
  background: #4a1f16;
}

.btn[disabled] {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn.is-playing {
  background: #6b3d1d;
  border-color: var(--warn);
}

/* ------------------------------------------------------------------ tools */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  justify-content: flex-start;
  text-align: left;
  padding: 7px 8px;
}

.tool-btn .tool-icon {
  font-size: 14px;
  width: 16px;
  text-align: center;
  flex: 0 0 auto;
}

.tool-btn .tool-key {
  margin-left: auto;
  font: 10px var(--mono);
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 3px;
}

/* ---------------------------------------------------------------- presets */
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preset-btn {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 9px;
  /* .btn sets white-space: nowrap; preset descriptions must wrap, otherwise
     they set a min-content width that overflows narrow layouts. */
  white-space: normal;
}

.preset-btn small {
  color: var(--text-faint);
  font-weight: 450;
  font-size: 11px;
  line-height: 1.35;
}

/* --------------------------------------------------------------- toggles */
.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.check {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.check input {
  accent-color: var(--accent);
}

/* ------------------------------------------------------------- kv / info */
.kv-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px dashed rgba(60, 76, 106, 0.55);
  padding-bottom: 3px;
}

.kv span:first-child {
  color: var(--text-faint);
}

.kv span:last-child {
  font-family: var(--mono);
  color: var(--text);
  text-align: right;
}

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font: 600 11px var(--sans);
  border: 1px solid transparent;
}

.badge-ok {
  background: rgba(156, 204, 101, 0.14);
  border-color: rgba(156, 204, 101, 0.5);
  color: var(--good);
}

.badge-warn {
  background: rgba(255, 183, 77, 0.14);
  border-color: rgba(255, 183, 77, 0.5);
  color: var(--warn);
}

.badge-bad {
  background: rgba(255, 112, 67, 0.14);
  border-color: rgba(255, 112, 67, 0.5);
  color: var(--bad);
}

/* ------------------------------------------------------------- inspector */
.inspector {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
}

.inspector h3 {
  margin: 0;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.field-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11.5px;
  color: var(--text-faint);
  min-width: 0;
}

.field.grow {
  flex: 1 1 120px;
}

.field input,
.field select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 7px;
  font: 12px var(--mono);
  width: 100%;
  min-width: 0;
}

.field input[type="range"] {
  padding: 0;
}

.field input:focus,
.field select:focus {
  outline: 2px solid rgba(79, 195, 247, 0.45);
  outline-offset: 0;
}

.field-row .field {
  flex: 0 1 auto;
}

.empty-note {
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.55;
}

.warn-note {
  color: var(--warn);
  font-size: 11.5px;
}

.bad-note {
  color: var(--bad);
  font-size: 11.5px;
}

/* --------------------------------------------------------------- readout */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
}

.tab {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-faint);
  border-radius: 6px;
  padding: 4px 9px;
  font: 600 11.5px var(--sans);
  cursor: pointer;
}

.tab.is-active {
  color: var(--text);
  background: #1c2739;
  border-color: var(--border-strong);
}

.readout {
  max-height: 268px;
  overflow: auto;
  min-width: 0;
  font: 11.5px var(--mono);
}

.readout table {
  width: 100%;
  border-collapse: collapse;
}

.readout th {
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  text-align: left;
  color: var(--text-faint);
  font-weight: 600;
  padding: 4px 5px;
  border-bottom: 1px solid var(--border);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.readout td {
  padding: 3px 5px;
  border-bottom: 1px solid rgba(36, 48, 74, 0.5);
  white-space: nowrap;
}

.readout tbody tr:hover {
  background: rgba(79, 195, 247, 0.07);
}

.readout tr.is-selected {
  background: rgba(255, 209, 102, 0.12);
}

.readout .num {
  text-align: right;
}

.readout .ok {
  color: var(--good);
}

.readout .bad {
  color: var(--bad);
}

.readout .clickable {
  cursor: pointer;
}

.readout .type-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
}

/* ------------------------------------------------------------ save / load */
.slot-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 160px;
  overflow: auto;
}

.slot {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 7px;
}

.slot-info {
  flex: 1 1 auto;
  min-width: 0;
}

.slot-name {
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-meta {
  color: var(--text-faint);
  font-size: 10.5px;
}

.slot .btn {
  padding: 3px 7px;
  font-size: 11px;
}

/* ----------------------------------------------------------------- toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #1b2537;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 22px;
  box-shadow: var(--shadow);
  z-index: 40;
  max-width: min(560px, 90vw);
  font-size: 12.5px;
}

.toast.is-error {
  border-color: var(--bad);
  color: #ffd9cf;
}

.toast.is-good {
  border-color: rgba(156, 204, 101, 0.6);
}

/* --------------------------------------------------------------- overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 15, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

/* `display: flex` above would otherwise beat the user agent's [hidden] rule. */
.overlay[hidden],
.toast[hidden],
.canvas-hint[hidden] {
  display: none;
}

.overlay-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  width: min(920px, 100%);
  max-height: min(84vh, 760px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.overlay-header h2 {
  margin: 0;
  font-size: 15px;
}

.overlay-body {
  padding: 14px 18px 22px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.overlay-body h3 {
  margin: 0 0 6px;
  font-size: 12.5px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.overlay-body ol,
.overlay-body ul {
  margin: 0;
  padding-left: 18px;
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.65;
}

.overlay-body b,
.overlay-body i {
  color: var(--text);
  font-style: normal;
  font-weight: 650;
}

table.keys {
  width: 100%;
  border-collapse: collapse;
  font: 11.5px var(--mono);
  color: var(--text-dim);
}

table.keys td {
  padding: 2px 6px 2px 0;
  vertical-align: top;
}

table.keys td:nth-child(odd) {
  color: var(--accent-2);
  white-space: nowrap;
}

/* ----------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .app-body {
    grid-template-columns: 232px minmax(280px, 1fr) 300px;
  }
}

@media (max-width: 560px) {
  .brand-text {
    display: none;
  }

  .app-header {
    gap: 8px;
  }

  .header-actions .btn {
    padding: 5px 8px;
    font-size: 11.5px;
  }

  .transport,
  .status-bar {
    padding: 7px 9px;
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-body {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: min-content;
  }

  .canvas-wrap {
    order: -1;
    height: 62vh;
    min-height: 380px;
  }

  .panel {
    max-height: none;
    overflow: visible;
  }

  .readout {
    max-height: 300px;
  }
}
