:root {
  color-scheme: dark;
  --bg: #050811;
  --panel: rgba(15, 23, 42, 0.9);
  --border: rgba(255, 255, 255, 0.12);
  --text: #f8fafc;
  --muted: #94a3b8;
  --yang: #fbbf24;
  --yin: #60a5fa;
}

* {
  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 40% 15%, #161e35 0%, #050811 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: 1340px;
  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, #38bdf8);
  color: #050811;
}

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

.dim-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.dim-btn {
  min-height: 38px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.dim-btn.active {
  background: rgba(251, 191, 36, 0.22);
  border-color: #fbbf24;
  color: #fef08a;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 13px;
  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; }

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

.stage-card,
.card-block,
.info-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.05rem;
  color: #fde68a;
}

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

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

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

#cubeCanvas:active { cursor: grabbing; }

.hud-hint {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-size: 0.75rem;
  color: var(--muted);
  background: rgba(5, 8, 17, 0.78);
  padding: 3px 9px;
  border-radius: 999px;
  pointer-events: none;
}

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

.hex-header {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(3, 6, 14, 0.65);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.hex-symbol {
  width: 58px;
  height: 64px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px 0;
  flex-shrink: 0;
}

.hex-line {
  height: 6px;
  width: 100%;
  display: flex;
  justify-content: space-between;
}

.hex-line.yang {
  background: var(--yang);
  border-radius: 2px;
}

.hex-line.yin span {
  width: 42%;
  height: 100%;
  background: var(--yin);
  border-radius: 2px;
}

.hex-line.dim {
  opacity: 0.2;
}

.hex-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hex-meta h2 {
  font-size: 1.15rem;
  color: #fde68a;
}

.hex-meta span {
  font-size: 0.82rem;
  color: #cbd5e1;
}

.hex-meta code {
  font-size: 0.78rem;
  color: #7dd3fc;
}

.yao-title {
  font-size: 0.82rem;
  color: var(--muted);
}

.yao-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.yao-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.yao-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.yao-btn .yao-state.yang { color: var(--yang); }
.yao-btn .yao-state.yin { color: var(--yin); }

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

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

.info-card code {
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
  padding: 1px 5px;
  border-radius: 4px;
}

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