:root {
  color-scheme: dark;
  --bg: #07090f;
  --panel: #111622;
  --border: rgba(255, 255, 255, 0.11);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #f97316;
}

* {
  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% 20%, #171e30 0%, #07090f 75%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  touch-action: pan-y;
}

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

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 1280px;
  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, 22, 34, 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, #f97316, #ec4899);
  color: #fff;
}

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

.tab-switcher {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 4px;
}

.tab-btn {
  min-height: 38px;
  padding: 0 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.tab-btn.active {
  background: rgba(249, 115, 22, 0.25);
  color: #fff;
}

.top-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.top-controls[hidden],
.workspace[hidden] {
  display: none;
}

select#rootSelect {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b0f19;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  color-scheme: dark;
}

select#rootSelect option {
  background: #0b0f19;
  color: var(--text);
}

.bpm-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #0b0f19;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  min-height: 44px;
  font-size: 0.84rem;
  color: var(--muted);
}

.bpm-inline strong {
  color: #fdba74;
  min-width: 28px;
}

.bpm-inline input[type="range"] {
  width: 110px;
  accent-color: #f97316;
}

.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: #ea580c; border-color: #fb923c; }
.btn-secondary { background: rgba(255, 255, 255, 0.07); }
.btn-secondary.active { background: rgba(249, 115, 22, 0.25); border-color: #fb923c; color: #ffedd5; }

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

.stage-card {
  background: rgba(17, 22, 34, 0.88);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.country-banner {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
}

.flag {
  font-size: 2rem;
  line-height: 1;
}

.country-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.country-meta strong {
  font-size: 0.96rem;
  color: #f8fafc;
}

.country-meta span {
  font-size: 0.8rem;
  color: #38bdf8;
  font-weight: 600;
}

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

.canvas-box {
  width: min(100%, 490px);
  aspect-ratio: 1;
  position: relative;
  touch-action: none;
}

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

.note-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: 100%;
}

.note-pill {
  min-width: 42px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1.5px solid var(--pill-color, #fb923c);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, background-color 0.15s ease, color 0.15s ease;
}

.note-pill.dim {
  opacity: 0.35;
  border-color: rgba(148, 163, 184, 0.4);
}

.note-pill.active {
  opacity: 1;
  background: var(--pill-color, #fb923c);
  color: #090d16;
  transform: scale(1.07);
  box-shadow: 0 0 16px var(--pill-glow, rgba(251, 146, 60, 0.45));
}

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

.card-block,
.info-card {
  background: rgba(17, 22, 34, 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.92rem;
  color: #cbd5e1;
}

.scale-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  max-height: 420px;
  overflow-y: auto;
  touch-action: pan-y;
}

.scale-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-height: 50px;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.scale-btn strong {
  font-size: 0.82rem;
}

.scale-btn span {
  font-size: 0.71rem;
  color: var(--muted);
}

.scale-btn.active {
  background: rgba(249, 115, 22, 0.18);
  border-color: var(--btn-accent, #fb923c);
}

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

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

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

@media (max-width: 480px) {
  .scale-list {
    grid-template-columns: 1fr;
  }
}
