:root {
  color-scheme: dark;
  --bg: #07090f;
  --panel: #111622;
  --border: rgba(255, 255, 255, 0.12);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #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 30% 15%, #172038 0%, #07090f 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: rgba(17, 22, 34, 0.92);
  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, #38bdf8, #f97316);
  color: #fff;
}

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

.tab-switcher {
  display: flex;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.05);
  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.82rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

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

[hidden] {
  display: none !important;
}

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

.stage-card,
.card-block,
.info-card,
.guide-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;
}

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

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

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

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

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

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

.dual-canvas-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sub-stage {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

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

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

.large-square {
  max-width: 440px;
  margin: 0 auto;
}

.table-square {
  width: min(92vw, 560px, 64dvh);
  margin: 0 auto;
}

.rect-box {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 62dvh;
  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;
}

.hud-pill {
  position: absolute;
  left: 12px;
  top: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 700;
  color: #fde68a;
  pointer-events: none;
}

.hud-pill.static {
  position: static;
  pointer-events: auto;
}

.tag-pill {
  font-size: 0.76rem;
  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;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.action-row.spread {
  justify-content: space-between;
}

.submode-tabs {
  display: flex;
  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: #0284c7; border-color: #38bdf8; }
.btn-accent { background: #ea580c; border-color: #fb923c; }
.btn-secondary { background: rgba(255, 255, 255, 0.07); }
.btn-secondary.active { background: rgba(56, 189, 248, 0.25); border-color: #38bdf8; color: #e0f2fe; }
.btn.playing { background: rgba(16, 185, 129, 0.28); border-color: #10b981; color: #a7f3d0; }

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

.quick-chords {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.quick-chord-btn {
  min-height: 36px;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid rgba(253, 224, 71, 0.35);
  background: rgba(253, 224, 71, 0.08);
  color: #fef08a;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.quick-chord-btn:hover {
  background: rgba(253, 224, 71, 0.22);
}

.quick-chord-btn.active {
  background: #fde047;
  border-color: #ffffff;
  color: #090d16;
  box-shadow: 0 0 14px rgba(253, 224, 71, 0.45);
}

.note-pill {
  min-width: 42px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1.5px solid var(--pill-color, #38bdf8);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.note-pill.dim { opacity: 0.35; border-color: rgba(148, 163, 184, 0.4); }
.note-pill.selected {
  background: rgba(253, 224, 71, 0.25);
  border-color: #fde047;
  color: #fef08a;
  box-shadow: 0 0 12px rgba(253, 224, 71, 0.35);
}
.note-pill.active {
  opacity: 1;
  background: var(--pill-color, #38bdf8);
  color: #090d16;
  transform: scale(1.06);
}

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

.card-block h2 { font-size: 0.92rem; color: #cbd5e1; }

.preset-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  max-height: 360px;
  overflow-y: auto;
  touch-action: pan-y;
}

.preset-btn,
.preset-chip,
.route-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.preset-btn span { font-size: 0.7rem; color: var(--muted); }
.preset-btn.active,
.preset-chip.active,
.route-chip.active {
  background: rgba(56, 189, 248, 0.22);
  border-color: #38bdf8;
}

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

.slider-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.82rem;
  color: var(--muted);
}

.slider-bar strong { color: #f8fafc; min-width: 38px; }
.slider-bar input[type="range"] { flex: 1; accent-color: #38bdf8; }

.single-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.table-toolbar,
.table-sliders {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
}

.table-sliders .slider-bar { flex: 1; min-width: 180px; }

.guide-panel { overflow-y: auto; touch-action: pan-y; }
.guide-container { max-width: 960px; margin: 0 auto; width: 100%; }
.guide-card h2 { color: #7dd3fc; font-size: 1.12rem; }
.guide-card p, .guide-card li { font-size: 0.9rem; line-height: 1.65; color: #cbd5e1; }
.guide-card ul { margin-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.guide-card code {
  background: rgba(56, 189, 248, 0.15);
  color: #7dd3fc;
  padding: 1px 6px;
  border-radius: 5px;
}

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

@media (max-width: 600px) {
  .dual-canvas-row { grid-template-columns: 1fr; }
  .preset-list { grid-template-columns: 1fr; }
}
