:root {
  --bg-app: #0f141d;
  --bg-bar: #161d2a;
  --bg-panel: #1b2434;
  --bg-card: #232f44;
  --border: #2e3c56;
  --text-main: #eef2f9;
  --text-muted: #95a3bd;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #f59e0b;
  --success: #10b981;
  --purple-warn: #9333ea;
  --blue-warn: #0284c7;
  --danger: #ef4444;
}

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

body {
  font-family: "Pretendard", "Malgun Gothic", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header & Transport */
.topbar {
  background: var(--bg-bar);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

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

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #b45309, #ea580c);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
}

.brand-title {
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.org-link {
  color: #fbbf24;
  text-decoration: none;
  font-weight: 800;
}
.org-link:hover {
  text-decoration: underline;
}

.pro-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.22);
  border: 1px solid #60a5fa;
  color: #93c5fd;
  font-weight: 800;
}

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

/* Limitations Banner */
.limit-banner {
  background: rgba(245, 158, 11, 0.11);
  border-bottom: 1px solid rgba(245, 158, 11, 0.35);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 11.5px;
  color: #fde68a;
}

.limit-banner code {
  background: rgba(15, 23, 42, 0.65);
  padding: 1px 5px;
  border-radius: 4px;
  color: #fff;
}

.limit-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.banner-close {
  background: transparent;
  border: none;
  color: #cbd5e1;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
}

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

.field-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-panel);
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.field-inline label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

select,
input[type="text"] {
  background: #111824;
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 12px;
  outline: none;
}

select:focus,
input[type="text"]:focus {
  border-color: var(--primary);
}

/* Transport Bar */
.transport-bar {
  background: #131a26;
  border-bottom: 1px solid var(--border);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.transport-controls,
.transpose-controls,
.export-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.playback-readout {
  font-size: 12px;
  color: #cbd5e1;
  background: #0b1018;
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 5px;
  min-width: 195px;
  font-variant-numeric: tabular-nums;
}

.tempo-box {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 2px;
}

.tempo-box input[type="range"] {
  width: 82px;
  accent-color: var(--accent);
}

#tempoLabel {
  color: var(--text-main);
  font-weight: 600;
  min-width: 56px;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text-main);
  background: var(--bg-card);
  user-select: none;
}

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

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

.btn-accent {
  background: var(--accent);
  color: #111827;
}
.btn-accent:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-success {
  background: var(--success);
  color: #06281e;
}
.btn-success:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-purple {
  background: var(--purple-warn);
  color: #fff;
}

.btn-warn-outline {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.5);
  color: #fcd34d;
}
.btn-warn-outline:hover {
  background: rgba(245, 158, 11, 0.25);
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
}
.btn-outline:hover:not(:disabled) {
  background: var(--bg-card);
  border-color: #4b5e82;
}

.btn-ghost {
  background: #1f2b3f;
  border-color: #30415f;
}
.btn-ghost:hover:not(:disabled) {
  background: #2a3a54;
}

.btn-ghost.active-mode {
  background: rgba(245, 158, 11, 0.24);
  border-color: var(--accent);
  color: #fde68a;
}

.btn-danger-ghost {
  background: rgba(239, 68, 68, 0.14);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.35);
}

.btn-xs {
  padding: 4px 8px;
  font-size: 11px;
}

.btn-icon {
  padding: 2px 8px;
  font-size: 14px;
  background: #1f293d;
  border: 1px solid var(--border);
}

/* Split Workspace */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
}

.workspace.drag-over {
  outline: 3px dashed var(--primary);
  outline-offset: -6px;
}

.pane {
  background: #121824;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.pane-header {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pane-title {
  font-size: 12.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.meta-badge {
  font-size: 11px;
  font-weight: 500;
  color: #cbd5e1;
  background: #0f1623;
  padding: 2px 7px;
  border-radius: 99px;
  border: 1px solid var(--border);
}

.issue-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 700;
}
.issue-pill.ok {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}
.issue-pill.warn {
  background: rgba(147, 51, 234, 0.25);
  color: #e9d5ff;
  border: 1px solid #a855f7;
}

.pane-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.seg-toggle {
  display: inline-flex;
  background: #0e1420;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.seg-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.zoom-text {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 38px;
  text-align: center;
}

.pane-viewport {
  flex: 1;
  overflow: auto;
  position: relative;
  padding: 16px;
  background: #171f2e;
}

.score-viewport {
  background: #e9eef5;
}

.image-canvas-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

#scannedImage {
  max-width: 100%;
  background: #fff;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  border-radius: 4px;
  transform-origin: top center;
  transition: width 0.12s ease;
}

.osmd-sheet {
  background: #ffffff;
  color: #000000;
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.15);
  min-height: 100%;
  padding: 12px 16px;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
}

.score-viewport .empty-state {
  color: #475569;
}

.empty-icon {
  font-size: 42px;
  margin-bottom: 10px;
}

.empty-state h3 {
  font-size: 15px;
  color: var(--text-main);
  margin-bottom: 6px;
}
.score-viewport .empty-state h3 {
  color: #1e293b;
}

.empty-state p {
  font-size: 12.5px;
  line-height: 1.55;
  margin-bottom: 14px;
}

.empty-actions {
  display: flex;
  gap: 8px;
}

/* Bottom Studio Dock */
.dock {
  height: 248px;
  background: var(--bg-bar);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.dock-tabs {
  display: flex;
  align-items: center;
  background: #111722;
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  gap: 4px;
}

.dock-tab {
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.dock-tab.active {
  color: #fff;
  border-bottom-color: var(--primary);
  background: rgba(59, 130, 246, 0.08);
}

.tab-count {
  background: #334155;
  color: #e2e8f0;
  padding: 1px 6px;
  border-radius: 99px;
  font-size: 10px;
  margin-left: 4px;
}
.tab-count.has-issue {
  background: var(--danger);
  color: #fff;
}

.dock-spacer {
  flex: 1;
}

.dock-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.dock-body {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 14px;
}
.dock-body.active {
  display: block;
}

.editor-empty {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12.5px;
}

/* Editor Grid */
.editor-grid {
  display: grid;
  grid-template-columns: 280px 305px 1fr;
  gap: 12px;
  height: 100%;
}

.editor-col {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 0;
  overflow: auto;
}

.col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 700;
  color: #cbd5e1;
}

.form-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-row label {
  width: 52px;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.form-row input {
  flex: 1;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.form-row-2 label {
  display: block;
  font-size: 10.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.form-row-2 select {
  width: 100%;
}

.form-row-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
}
.form-row-inline label {
  font-size: 11px;
  color: var(--text-muted);
}
.form-row-inline input {
  width: 115px;
}

.btn-row,
.btn-row-inline {
  display: flex;
  gap: 6px;
  align-items: center;
}

.measure-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  overflow-y: auto;
}

.m-pill {
  padding: 5px 9px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  background: #121926;
  border: 1px solid var(--border);
  color: var(--text-main);
  cursor: pointer;
}
.m-pill.active {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.24);
}
.m-pill.issue-purple {
  border-color: #a855f7;
  background: rgba(147, 51, 234, 0.28);
  color: #f3e8ff;
}
.m-pill.issue-blue {
  border-color: #38bdf8;
  background: rgba(2, 132, 199, 0.28);
  color: #e0f2fe;
}
.m-pill.issue-red {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.28);
  color: #fee2e2;
}
.m-pill.playing {
  outline: 2px solid var(--accent);
}

/* Note Cards */
.note-cards {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  align-items: stretch;
}

.note-card {
  min-width: 142px;
  background: #131b29;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.note-card.low-range-warn {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.note-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10.5px;
  color: var(--text-muted);
}

.violin-str-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
  font-weight: 700;
}
.violin-str-tag.out {
  background: rgba(239, 68, 68, 0.28);
  color: #fca5a5;
}

.note-del-btn {
  background: transparent;
  border: none;
  color: #f87171;
  cursor: pointer;
  font-size: 12px;
}

.pitch-stepper {
  display: flex;
  gap: 3px;
}
.pitch-stepper input {
  width: 68px;
  text-align: center;
  font-weight: 700;
}

.note-card select,
.note-card input {
  font-size: 11.5px;
  padding: 3px 5px;
}

/* Mixer Strips */
.mixer-strips {
  display: flex;
  gap: 12px;
  height: 100%;
  overflow-x: auto;
}

.mixer-channel {
  width: 220px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.mixer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  font-weight: 700;
}

.ms-btns {
  display: flex;
  gap: 4px;
}
.ms-btn {
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 800;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: #121824;
  color: var(--text-muted);
  cursor: pointer;
}
.ms-btn.mute-on {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.ms-btn.solo-on {
  background: var(--accent);
  color: #111827;
  border-color: var(--accent);
}

.vol-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}
.vol-row input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}

/* Issues & XML */
.issues-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.issue-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 12px;
  background: var(--bg-panel);
  border-left: 4px solid var(--purple-warn);
}
.issue-item.blue {
  border-left-color: var(--blue-warn);
}
.issue-item.red {
  border-left-color: var(--danger);
}

.xml-wrap {
  position: relative;
  height: 100%;
}
.copy-xml-btn {
  position: sticky;
  top: 0;
  float: right;
}
#xmlPreview {
  font-family: Consolas, "Courier New", monospace;
  font-size: 11.5px;
  color: #cbd5e1;
  white-space: pre-wrap;
  line-height: 1.45;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 13, 22, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 998;
  padding: 20px;
}

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 680px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  font-size: 15px;
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  font-size: 12.5px;
  line-height: 1.65;
  color: #dbe4f3;
}
.modal-lead {
  background: rgba(59, 130, 246, 0.12);
  border-left: 3px solid var(--primary);
  padding: 10px 12px;
  border-radius: 5px;
  margin-bottom: 14px;
}
.modal-body h4 {
  font-size: 13px;
  color: #fbbf24;
  margin: 12px 0 6px;
}
.modal-body ul {
  padding-left: 18px;
  margin-bottom: 10px;
}
.modal-body li {
  margin-bottom: 5px;
}
.modal-body code {
  background: #0f1623;
  padding: 1px 5px;
  border-radius: 4px;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

/* Loading & Toast */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 13, 22, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.loading-overlay[hidden],
.modal-backdrop[hidden],
.toast[hidden],
[hidden] {
  display: none !important;
}

.loading-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 26px 34px;
  text-align: center;
  max-width: 440px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(59, 130, 246, 0.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-card h3 {
  font-size: 15px;
  margin-bottom: 6px;
}
.loading-card p {
  font-size: 12px;
  color: var(--text-muted);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #475569;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 12.5px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
  z-index: 1000;
}

/* ==========================================================================
   Mobile & Tablet Responsiveness (@media queries)
   ========================================================================== */
@media (max-width: 960px) {
  body {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .brand-title {
    font-size: 13.5px;
  }

  .toolbar-group {
    width: 100%;
    justify-content: flex-start;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .field-inline {
    flex: 1 1 auto;
    min-width: 130px;
  }

  .transport-bar {
    padding: 8px 12px;
    gap: 8px;
    flex-direction: column;
    align-items: stretch;
  }

  .transport-controls,
  .transpose-controls,
  .export-controls {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
  }

  .playback-readout {
    width: 100%;
    min-width: 0;
  }

  /* Mobile Workspace Switcher & Stack */
  .workspace {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 0;
  }

  .pane {
    height: 420px;
    min-height: 350px;
  }

  .pane-viewport {
    height: calc(100% - 40px);
  }

  /* Bottom Dock on Mobile */
  .dock {
    height: auto;
    min-height: 380px;
  }

  .dock-tabs {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .dock-tab {
    flex-shrink: 0;
    padding: 8px 10px;
    font-size: 11.5px;
  }

  .editor-grid {
    display: flex;
    flex-direction: column;
    height: auto;
    gap: 12px;
  }

  .editor-col {
    width: 100%;
  }

  .measure-pills {
    max-height: 140px;
  }

  .note-cards {
    max-height: 220px;
  }

  /* Touch-friendly interactive targets */
  .btn {
    min-height: 34px;
    padding: 6px 10px;
  }

  .btn-xs {
    min-height: 28px;
  }

  .modal-card {
    width: 95%;
    max-height: 85vh;
    padding: 18px 16px;
  }
}

@media (max-width: 600px) {
  .pane {
    height: 350px;
    min-height: 300px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .brand {
    justify-content: space-between;
  }

  .brand-sub {
    display: none;
  }

  .tempo-box {
    width: 100%;
    justify-content: space-between;
    margin-left: 0;
  }

  .transpose-controls .ctrl-label {
    width: 100%;
    margin-bottom: 2px;
  }

  .toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
    text-align: center;
  }
}
