:root {
  color-scheme: dark;
  --bg: #070b14;
  --panel: #111827;
  --border: rgba(255, 255, 255, 0.12);
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --accent: #10b981;
  --warn: #f59e0b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  min-height: 100dvh;
  background: radial-gradient(circle at 30% 15%, #172554 0%, #070b14 70%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  touch-action: pan-y;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 1360px;
  margin: 0 auto;
  padding:
    max(10px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  gap: 10px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(17, 24, 39, 0.9);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
}

.title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  color: #fff;
}

.title-group h1 {
  font-size: 1.08rem;
  font-weight: 800;
}

.status-pill {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.16);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

.status-pill.unoccupied {
  background: rgba(245, 158, 11, 0.18);
  border-color: rgba(245, 158, 11, 0.45);
  color: #fcd34d;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, background-color 0.15s ease;
}

.btn:active { transform: scale(0.97); }
.btn-primary { background: #0284c7; border-color: #38bdf8; }
.btn-secondary { background: rgba(255, 255, 255, 0.08); }
.btn-secondary.active { background: rgba(56, 189, 248, 0.24); border-color: #38bdf8; color: #e0f2fe; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 1fr);
  gap: 12px;
  flex: 1;
  align-items: start;
}

.stage-card {
  background: rgba(17, 24, 39, 0.88);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
}

.canvas-box {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 76dvh;
  background: #030712;
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  touch-action: none;
}

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

#shellCanvas:active { cursor: grabbing; }

.hud-overlay {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
}

#formulaHud {
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fde68a;
  font-variant-numeric: tabular-nums;
}

.drag-hint {
  font-size: 0.76rem;
  color: var(--muted);
  background: rgba(15, 23, 42, 0.72);
  padding: 3px 9px;
  border-radius: 999px;
}

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

.card-block,
.info-card {
  background: rgba(17, 24, 39, 0.9);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-block h2 {
  font-size: 0.94rem;
  color: #e2e8f0;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.preset-btn {
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: #cbd5e1;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.preset-btn.active {
  background: rgba(56, 189, 248, 0.24);
  border-color: #38bdf8;
  color: #fff;
}

.preset-btn.warn.active {
  background: rgba(245, 158, 11, 0.24);
  border-color: #f59e0b;
  color: #fef3c7;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.slider-group:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.84rem;
  color: #cbd5e1;
}

.slider-label strong {
  color: #7dd3fc;
  font-variant-numeric: tabular-nums;
}

.slider-group small {
  font-size: 0.74rem;
  color: var(--muted);
}

input[type="range"] {
  width: 100%;
  accent-color: #38bdf8;
  min-height: 26px;
  cursor: pointer;
}

.info-card h3 {
  font-size: 0.96rem;
  color: #7dd3fc;
}

.info-card p {
  font-size: 0.82rem;
  line-height: 1.5;
  color: #cbd5e1;
}

.citation {
  color: var(--muted) !important;
  font-size: 0.76rem !important;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 6px;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}
