:root {
  color-scheme: dark;
  --bg: #080c16;
  --panel: rgba(17, 24, 39, 0.9);
  --border: rgba(255, 255, 255, 0.12);
  --text: #f8fafc;
  --muted: #94a3b8;
  --gold: #fbbf24;
  --sky: #38bdf8;
}

* {
  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 35% 15%, #172036 0%, #080c16 75%);
  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: 1320px;
  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: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  background: linear-gradient(135deg, #fbbf24, #f97316);
  color: #080c16;
}

.brand h1 {
  font-size: 1.06rem;
  font-weight: 800;
}

.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.84rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease;
}

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

.stage-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.stage-header strong {
  font-size: 1.06rem;
  color: #fde68a;
}

.tag {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.16);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #7dd3fc;
}

.dual-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 1fr);
  gap: 14px;
  align-items: start;
}

.canvas-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.panel-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.square-box {
  width: min(100%, 540px);
  aspect-ratio: 1;
  background: #04070e;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin: 0 auto;
  touch-action: none;
}

.gnomon-box {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #04070e;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  touch-action: none;
}

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

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

.controls-card,
.info-card {
  background: rgba(4, 7, 14, 0.65);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.84rem;
  color: #cbd5e1;
}

.slider-row strong {
  color: #fde68a;
}

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

.metrics-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric {
  background: rgba(17, 24, 39, 0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric span {
  font-size: 0.74rem;
  color: var(--muted);
}

.metric strong {
  font-size: 0.9rem;
  color: #7dd3fc;
}

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

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

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