:root {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-hover: #e2e8f0;

  --border-light: #e2e8f0;
  --border-medium: #cbd5e1;
  --border-focus: #2563eb;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --accent-primary: #2563eb;
  --accent-primary-hover: #1d4ed8;
  --accent-primary-soft: #eff6ff;

  --accent-emerald: #059669;
  --accent-emerald-soft: #ecfdf5;

  --accent-rose: #e11d48;
  --accent-rose-soft: #fff1f2;

  --radius-lg: 12px;
  --radius-md: 8px;
  --radius-sm: 6px;

  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 48px;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 1. Minimalist White Header */
.top-header {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-light);
  padding: 12px 0;
  position: sticky;
  top: 0;
  z-index: 40;
}

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

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

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--text-primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
}

.brand-title h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-emerald-soft);
  color: var(--accent-emerald);
  border: 1px solid #a7f3d0;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.lang-switcher {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
}

.lang-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.lang-btn:hover {
  color: var(--text-primary);
}

.lang-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.14s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: var(--border-medium);
}

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

.btn-primary {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-primary-hover);
  border-color: var(--accent-primary-hover);
}

.btn-danger {
  background: var(--bg-card);
  border-color: #fecdd3;
  color: var(--accent-rose);
}

.btn-danger:hover:not(:disabled) {
  background: var(--accent-rose-soft);
  border-color: #fda4af;
}

.btn-emerald {
  background: var(--accent-emerald);
  border-color: var(--accent-emerald);
  color: #ffffff;
}

.btn-emerald:hover:not(:disabled) {
  background: #047857;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.btn.active {
  background: var(--accent-primary-soft);
  border-color: #93c5fd;
  color: var(--accent-primary);
  font-weight: 600;
}

/* 2. Streamlined Top Control Deck (Single Clean Card) */
.control-deck {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-top: 18px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.deck-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

/* Mode Segmented Switcher */
.mode-cards {
  display: inline-flex;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  gap: 4px;
  flex-wrap: wrap;
}

.mode-card {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.14s ease;
}

.mode-card:hover {
  color: var(--text-primary);
}

.mode-card.active {
  background: var(--bg-card);
  color: var(--accent-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.mode-card-desc {
  display: none;
}

/* Capture & Demo Bar */
.capture-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.capture-box.recording #btn-record-mic {
  background: var(--accent-rose);
  border-color: var(--accent-rose);
  color: #ffffff;
}

.tuner-strip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-subtle);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  font-size: 12px;
  color: var(--text-secondary);
}

.tuner-note {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-weight: 700;
  color: var(--accent-primary);
}

.demo-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.demo-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* 3. Main Score Card */
.score-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-top: 16px;
  box-shadow: var(--shadow-card);
}

.score-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 14px;
}

.tab-group {
  display: inline-flex;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  gap: 2px;
  flex-wrap: wrap;
}

.tab-group .btn {
  border: none;
  background: transparent;
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.tab-group .btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

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

/* Compact Inline Status Strip above Sheet Music */
.stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--text-secondary);
}

.stats-items {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.stat-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.stat-label {
  color: var(--text-muted);
}

.stat-value {
  font-weight: 600;
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, monospace;
}

/* Sheet Music Stage */
.score-stage {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px;
  min-height: 260px;
  overflow-x: auto;
}

.score-svg {
  width: 100%;
  height: auto;
  display: block;
}

.score-note-group {
  cursor: pointer;
}

.score-note-group:hover ellipse,
.score-note-group:hover text {
  fill: var(--accent-primary) !important;
}

.score-note-group.playing ellipse,
.score-note-group.playing text {
  fill: var(--accent-rose) !important;
}

.score-note-group.selected ellipse,
.score-note-group.selected text {
  fill: #d97706 !important;
}

/* Export Footer Bar */
.export-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}

.export-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* 4. Collapsible Advanced Settings & Piano Roll Drawer */
.advanced-drawer {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  margin-top: 14px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.advanced-drawer summary {
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-subtle);
}

.advanced-drawer summary:hover {
  color: var(--text-primary);
}

.advanced-body {
  padding: 18px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  align-items: end;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}

.form-input,
.form-select {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-primary);
  font-size: 12.5px;
  outline: none;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--border-focus);
}

input[type="range"] {
  accent-color: var(--accent-primary);
  width: 100%;
}

/* Light-Theme Canvases & Note Inspector */
.canvas-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.canvas-wrap {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.canvas-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  font-size: 11.5px;
  color: var(--text-secondary);
}

canvas {
  display: block;
  width: 100%;
}

.note-inspector {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--accent-primary-soft);
  border: 1px solid #bfdbfe;
  font-size: 12.5px;
  color: var(--text-primary);
}

.inspector-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* Event Table & ABC Code View */
.code-view-wrap {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 12px;
}

.events-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.events-table th,
.events-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
}

.events-table th {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 600;
}

.abc-textarea {
  width: 100%;
  min-height: 110px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
  margin-bottom: 12px;
}

/* Subtle Footer Security Note */
.security-strip {
  margin-top: 18px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
}

.security-strip-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.sec-pill {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 11px;
  color: var(--text-secondary);
}

.is-hidden {
  display: none !important;
}

@media print {
  body {
    background: #ffffff !important;
  }
  .top-header,
  .control-deck,
  .score-toolbar,
  .stats-bar,
  .export-bar,
  .advanced-drawer,
  .security-strip {
    display: none !important;
  }
  .score-card,
  .score-stage {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }
}
