:root {
  --bg-page: #080e1c;
  --bg-card: #0f172a;
  --bg-elevated: #1e293b;
  --border-subtle: #334155;
  --border-bright: #38bdf8;
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --accent-blue: #0369a1;
  --accent-coral: #c2410c;
  --accent-emerald: #15803d;
  --sky-glow: #7dd3fc;
}

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

body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: "DejaVu Sans", system-ui, -apple-system, sans-serif;
  line-height: 1.38;
  -webkit-font-smoothing: antialiased;
}

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

.app-shell {
  max-width: 1004px;
  margin: 0 auto;
  padding: 8px 12px 14px;
}

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

.top-header h1 {
  margin: 0 0 2px;
  font-size: 1.18rem;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: -0.01em;
}

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

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

button {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  color: #f8fafc;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 4px 7px;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

button:hover {
  border-color: var(--sky-glow);
  background: #26354d;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--sky-glow);
  outline-offset: 2px;
}

button.mode-btn.active {
  background: var(--accent-coral);
  border-color: #fb923c;
  color: #ffffff;
}

button.corpus-btn.active,
button.ckpt-btn.active,
button.preset-btn.active,
button.sub-btn.active,
button.apply-btn {
  background: var(--accent-blue);
  border-color: var(--sky-glow);
  color: #ffffff;
}

button.hint-btn {
  background: var(--accent-emerald);
  border-color: #4ade80;
  color: #ffffff;
}

.studio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 294px;
  gap: 10px;
  align-items: start;
}

.stage-card,
.sidebar-card {
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 8px;
}

.canvas-wrap {
  position: relative;
  isolation: isolate;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #1e293b;
  background: #080e1c;
}

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

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

.hud-left {
  left: 8px;
}

.hud-right {
  right: 8px;
}

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

.metric-card {
  min-width: 0;
  background: #111c33;
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 5px 7px;
}

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

.metric-value {
  display: block;
  font-size: 0.77rem;
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-group {
  background: #111c33;
  border: 1px solid #26354d;
  border-radius: 8px;
  padding: 7px;
}

.control-group.hidden {
  display: none;
}

.control-group h2 {
  margin: 0 0 5px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--sky-glow);
}

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

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

.btn-grid-2.corpus-grid {
  margin-top: 0;
  margin-bottom: 5px;
}

.btn-grid-3 button,
.btn-grid-2 button {
  padding: 4px 4px;
  font-size: 0.69rem;
  text-align: center;
  white-space: nowrap;
}

.prompt-input-row {
  display: flex;
  gap: 5px;
  margin-top: 6px;
}

#promptInput {
  flex: 1;
  min-width: 0;
  background: #080e1c;
  color: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 0.73rem;
  font-family: inherit;
}

.vocab-hint {
  margin: 4px 0 0;
  font-size: 0.66rem;
  color: var(--text-muted);
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.70rem;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.slider-row input[type="range"] {
  width: 100%;
  accent-color: #38bdf8;
  margin: 0;
}

.chal-title {
  margin: 0 0 3px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #f8fafc;
}

.chal-desc {
  margin: 0 0 6px;
  font-size: 0.69rem;
  color: var(--text-muted);
}

.chal-status {
  margin: 6px 0 0;
  font-size: 0.69rem;
  font-weight: 600;
  color: #7dd3fc;
}

.chal-status.solved {
  color: #4ade80;
}

.controls-note {
  margin: 0;
  font-size: 0.67rem;
  color: var(--text-muted);
}

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

.bottom-footer {
  margin-top: 9px;
  padding-top: 7px;
  border-top: 1px solid #1e293b;
  font-size: 0.71rem;
  color: var(--text-muted);
}

.bottom-footer p {
  margin: 0;
}

.bottom-footer a {
  color: #7dd3fc;
  text-decoration: underline;
}

@media (max-width: 760px) {
  .app-shell {
    padding: 5px 7px 10px;
  }

  .top-header h1 {
    font-size: 0.95rem;
  }

  .lede {
    font-size: 0.68rem;
    line-height: 1.25;
  }

  .action-strip {
    gap: 3px;
    margin-bottom: 5px;
  }

  .action-strip button {
    font-size: 0.64rem;
    padding: 3px 5px;
  }

  .studio-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .stage-card {
    padding: 5px;
  }

  .hud-pill {
    font-size: 0.58rem;
    padding: 1px 6px;
    bottom: 4px;
  }

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

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
