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

:root {
  --bg-deep: #080e1c;
  --bg-panel: #0f172a;
  --bg-card: #162036;
  --border-slate: #334155;
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --cerulean: #38bdf8;
  --cerulean-btn: #0369a1;
  --emerald-btn: #15803d;
  --amber-btn: #b45309;
  --rose-btn: #be185d;
  --slate-btn: #334155;
}

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 50% 0%, #13213c 0%, var(--bg-deep) 72%);
  color: var(--text-main);
  font-family: "DejaVu Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.app-shell {
  max-width: 1004px;
  margin: 0 auto;
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: nowrap;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border-slate);
  border-radius: 10px;
  padding: 7px 12px;
}

.brand-block {
  min-width: 0;
}

.brand-block h1 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.2;
  color: #e0f2fe;
  letter-spacing: 0.01em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.77rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

button, select {
  font-family: inherit;
}

.btn-pill, .btn-ctrl, .btn-mini {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  color: #ffffff;
  background: var(--slate-btn);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 5px 9px;
  cursor: pointer;
  transition: filter 0.14s ease, transform 0.08s ease;
}

.btn-pill:hover:not(:disabled),
.btn-ctrl:hover:not(:disabled),
.btn-mini:hover:not(:disabled) {
  filter: brightness(1.14);
}

.btn-ctrl:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-cerulean { background: var(--cerulean-btn); }
.btn-emerald { background: var(--emerald-btn); }
.btn-amber { background: var(--amber-btn); }
.btn-rose { background: var(--rose-btn); }
.btn-slate { background: var(--slate-btn); }

.hub-link {
  color: #7dd3fc;
  font-size: 0.77rem;
  font-weight: 600;
  text-decoration: underline;
  padding: 4px 6px;
  white-space: nowrap;
}

.action-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid var(--border-slate);
  border-radius: 9px;
  padding: 5px 9px;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.disc-select {
  background: #0b1324;
  color: #ffffff;
  border: 1px solid #475569;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.77rem;
  font-weight: 600;
}

.collapsible-bar {
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid #0284c7;
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 0.78rem;
}

.bar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.bar-controls {
  display: flex;
  gap: 5px;
}

.lb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 6px;
}

.lb-item {
  background: #0b1324;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 5px 8px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.74rem;
}

.stage-wrap {
  position: relative;
  background: #091122;
  border: 1px solid var(--border-slate);
  border-radius: 11px;
  overflow: hidden;
}

#hanoiCanvas {
  display: block;
  width: 100%;
  height: 332px;
  touch-action: none;
  cursor: grab;
}

#hanoiCanvas:active {
  cursor: grabbing;
}

.hud-pill {
  position: absolute;
  right: 10px;
  top: 8px;
  background: rgba(8, 14, 28, 0.92);
  border: 1px solid #475569;
  color: #e0f2fe;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  pointer-events: none;
}

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

.metric-card {
  background: rgba(22, 32, 54, 0.92);
  border: 1px solid var(--border-slate);
  border-radius: 8px;
  padding: 6px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-label {
  font-size: 0.69rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.metric-value {
  font-size: 0.85rem;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-footer {
  font-size: 0.73rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.footer-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.app-footer a, .modal-note a {
  color: #7dd3fc;
  text-decoration: underline;
}

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

.cli-details {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border-slate);
  border-radius: 7px;
  padding: 4px 9px;
}

.cli-details summary {
  cursor: pointer;
  color: #bae6fd;
  font-weight: 600;
}

.cli-pre {
  margin: 6px 0 2px;
  padding: 7px;
  background: #060b16;
  border-radius: 6px;
  overflow-x: auto;
  line-height: 1.35;
}

.cli-pre code {
  background: transparent;
  border: 0;
  padding: 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 18, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-dialog {
  max-width: 460px;
  width: 100%;
  background: #0f172a;
  border: 1px solid #38bdf8;
  border-radius: 11px;
  padding: 14px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.modal-head h2 {
  margin: 0;
  font-size: 0.96rem;
  color: #e0f2fe;
}

.modal-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.auth-active {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #162036;
  border: 1px solid #334155;
  padding: 6px 9px;
  border-radius: 7px;
  margin-bottom: 8px;
  font-size: 0.8rem;
}

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

.auth-row input {
  flex: 1;
  background: #080e1c;
  color: #f8fafc;
  border: 1px solid #475569;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.79rem;
}

.auth-status {
  margin: 7px 0 0;
  font-size: 0.77rem;
  color: #7dd3fc;
}

@media (max-width: 760px) {
  .app-shell {
    padding: 5px 6px 8px;
    gap: 5px;
  }
  .top-header {
    flex-wrap: wrap;
    padding: 5px 7px;
    gap: 4px;
  }
  .brand-block h1 {
    font-size: 0.88rem;
  }
  .subtitle {
    font-size: 0.67rem;
    white-space: normal;
  }
  .header-actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 4px;
  }
  .btn-pill, .btn-ctrl, .disc-select {
    font-size: 0.65rem;
    padding: 3px 5px;
  }
  .hub-link {
    font-size: 0.66rem;
  }
  .action-strip {
    padding: 4px 5px;
    gap: 4px;
  }
  #hanoiCanvas {
    height: 204px;
  }
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }
  .metric-value {
    font-size: 0.76rem;
  }
}
