:root {
  --bg-deep: #080e1c;
  --bg-panel: #111827;
  --bg-card: #1e293b;
  --border-slate: #334155;
  --text-bright: #f8fafc;
  --text-muted: #cbd5e1;
  --accent-sky: #38bdf8;
  --accent-ice: #7dd3fc;
  --btn-blue: #0369a1;
  --btn-amber: #c2410c;
  --btn-emerald: #15803d;
  --btn-slate: #1e293b;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-deep);
  color: var(--text-bright);
  font-family: "DejaVu Sans", system-ui, -apple-system, sans-serif;
  line-height: 1.35;
}

.app-shell {
  max-width: 1008px;
  margin: 0 auto;
  padding: 6px 10px 8px;
}

.top-header {
  margin-bottom: 6px;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.title-row h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  color: var(--text-bright);
}

.badge-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: #0c4a6e;
  color: #e0f2fe;
  border: 1px solid #0284c7;
}

.lede {
  margin: 3px 0 5px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

kbd, code {
  font-family: "DejaVu Sans Mono", monospace;
  font-size: 0.73rem;
  padding: 1px 4px;
  border-radius: 4px;
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #475569;
}

.action-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

.action-strip button {
  padding: 4px 7px;
  font-size: 0.73rem;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border-slate);
  color: #ffffff;
  transition: filter 0.12s ease;
}

.action-strip button:hover,
.chip-btn:hover {
  filter: brightness(1.12);
}

.action-strip button:focus-visible,
.chip-btn:focus-visible {
  outline: 2px solid var(--accent-sky);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--btn-blue);
  border-color: #38bdf8 !important;
}

.btn-accent {
  background: var(--btn-amber);
  border-color: #fb923c !important;
}

.btn-emerald {
  background: var(--btn-emerald);
  border-color: #4ade80 !important;
}

.btn-secondary {
  background: var(--btn-slate);
  border-color: #475569 !important;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 298px;
  gap: 8px;
  align-items: start;
  isolation: isolate;
}

.stage-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.canvas-frame {
  position: relative;
  width: 100%;
  background: #0b1120;
  border: 1px solid var(--border-slate);
  border-radius: 9px;
  overflow: hidden;
  isolation: isolate;
}

#opticsCanvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  cursor: pointer;
}

.hud-pill {
  position: absolute;
  bottom: 6px;
  padding: 2px 8px;
  font-size: 0.71rem;
  font-weight: 700;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  border: 1px solid #475569;
  pointer-events: none;
  z-index: 2;
}

.hud-left {
  left: 8px;
  max-width: 48%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-right {
  right: 8px;
  border-color: #0284c7;
  color: #e0f2fe;
}

.metrics-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.metric-card {
  min-width: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-slate);
  border-radius: 7px;
  padding: 4px 7px;
}

.metric-label {
  display: block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #94a3b8;
}

.metric-value {
  display: block;
  font-size: 0.76rem;
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.control-sidebar {
  min-width: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-slate);
  border-radius: 9px;
  padding: 7px 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.panel-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.panel-heading {
  margin: 0;
  font-size: 0.74rem;
  color: var(--accent-ice);
  letter-spacing: 0.01em;
}

.btn-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.btn-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

.btn-grid-5 {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.color-row {
  margin-top: 3px;
}

.editor-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin-top: 3px;
}

.chip-btn {
  padding: 4px 5px;
  font-size: 0.71rem;
  font-weight: 700;
  border-radius: 6px;
  border: 1px solid #475569;
  background: var(--bg-card);
  color: var(--text-bright);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-btn.active {
  background: var(--btn-blue);
  border-color: var(--accent-sky);
  color: #ffffff;
}

.chip-btn.solved {
  border-color: #4ade80;
}

.chip-btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.helper-note {
  margin: 1px 0 0;
  font-size: 0.71rem;
  color: var(--text-muted);
}

.rules-list {
  margin: 0;
  padding-left: 15px;
  font-size: 0.69rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.status-toast {
  margin: 2px 0 0;
  padding: 4px 6px;
  border-radius: 6px;
  background: #0f172a;
  border: 1px solid #334155;
  font-size: 0.70rem;
  color: #e0f2fe;
}

.site-footer {
  margin-top: 6px;
  padding-top: 4px;
  border-top: 1px solid #1e293b;
  font-size: 0.70rem;
  color: var(--text-muted);
}

.site-footer a {
  color: var(--accent-ice);
  text-decoration: underline;
}

@media (max-width: 760px) {
  .app-shell {
    padding: 4px 6px 8px;
  }
  .title-row h1 {
    font-size: 0.94rem;
  }
  .badge-pill {
    display: none;
  }
  .lede {
    font-size: 0.68rem;
    margin: 2px 0 4px;
  }
  .action-strip {
    gap: 3px;
  }
  .action-strip button {
    padding: 3px 5px;
    font-size: 0.64rem;
  }
  .workspace-grid {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .metrics-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
