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

:root {
  --orange: #F5893A;
  --orange-dark: #E07820;
  --bg: #EFEFEF;
  --white: #FFFFFF;
  --border: #E8E8E8;
  --text: #1A1A1A;
  --muted: #6B6B6B;
  --font: 'Inter', sans-serif;
}

body { font-family: var(--font); background: var(--bg); color: var(--text); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

/* ── HEADER ── */
.header { display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 60px; background: var(--white); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.logo { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; flex-shrink: 0; }
.title-input { font-family: var(--font); font-size: 15px; font-weight: 500; border: none; outline: none; background: transparent; color: var(--text); flex: 1; min-width: 0; }
.title-input:hover, .title-input:focus { background: #F5F5F5; border-radius: 6px; padding: 4px 8px; }
.mode-toggle { display: flex; background: #F0F0F0; border-radius: 8px; padding: 3px; flex-shrink: 0; }
.mode-btn { font-family: var(--font); font-size: 13px; font-weight: 500; padding: 6px 14px; border: none; border-radius: 6px; cursor: pointer; background: transparent; color: var(--muted); transition: all 0.15s; }
.mode-btn.active { background: var(--white); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.saved-status { font-size: 13px; color: var(--muted); flex-shrink: 0; }
.export-btn { font-family: var(--font); font-size: 14px; font-weight: 600; padding: 8px 20px; background: var(--orange); color: white; border: none; border-radius: 8px; cursor: pointer; transition: background 0.15s; }
.export-btn:hover { background: var(--orange-dark); }

/* ── LAYOUT ── */
.layout { display: flex; flex: 1; overflow: hidden; }

/* ── SIDEBAR ── */
.sidebar { width: 300px; background: var(--white); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; transition: width 0.2s; overflow: hidden; }
.sidebar.collapsed { width: 0; border-right: none; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 12px; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.collapse-btn { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; }
.tracks-list { overflow-y: auto; padding: 4px 12px; }
.track-item { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; transition: background 0.1s; }
.track-item:hover { background: #F8F8F8; }
.track-item.active { border-color: var(--orange); background: #FFF5EE; }
.track-icon { width: 34px; height: 34px; border-radius: 7px; background: #F0F0F0; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.track-info { flex: 1; min-width: 0; }
.track-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.track-btns { display: flex; gap: 4px; }
.track-btn { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border); background: var(--white); cursor: pointer; font-size: 13px; display: flex; align-items: center; justify-content: center; transition: all 0.1s; }
.track-btn:hover { background: #F0F0F0; }
.track-btn.on { background: #FFE8D9; border-color: var(--orange); }

.add-part-btn { font-family: var(--font); margin: 12px; padding: 10px; background: var(--orange); color: white; border: none; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background 0.15s; flex-shrink: 0; }
.add-part-btn:hover { background: var(--orange-dark); }
.add-part-btn:disabled { background: #ccc; cursor: not-allowed; }

/* ── ADD PART PANEL ── */
.add-part-panel { display: none; flex-direction: column; flex: 1; overflow-y: auto; padding: 20px; gap: 16px; }
.add-part-panel.visible { display: flex; }

.panel-title { font-size: 16px; font-weight: 700; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.field input[type="text"],
.field select {
  font-family: var(--font);
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: var(--white);
  color: var(--text);
  width: 100%;
}
.field input[type="text"]:focus,
.field select:focus { border-color: var(--orange); }

.mode-options { display: flex; flex-direction: column; gap: 8px; }

.mode-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 14px;
  font-weight: 500;
}
.mode-option.selected { border-color: var(--orange); background: #FFF5EE; }

.mode-radio {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.mode-option.selected .mode-radio { border-color: var(--orange); background: var(--orange); }
.mode-option.selected .mode-radio::after { content: ''; width: 8px; height: 8px; border-radius: 50%; background: white; }

.recording-state { display: none; flex-direction: column; align-items: center; gap: 12px; padding: 16px; background: #FFF5EE; border-radius: 10px; border: 2px solid var(--orange); }
.recording-state.visible { display: flex; }
.record-dot { width: 14px; height: 14px; border-radius: 50%; background: #E53E3E; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
.record-countdown { font-size: 28px; font-weight: 700; color: var(--orange); }
.record-label { font-size: 12px; color: var(--muted); }
.stop-btn { font-family: var(--font); padding: 8px 20px; background: #E53E3E; color: white; border: none; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; }

.panel-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.create-btn { font-family: var(--font); padding: 12px; background: var(--orange); color: white; border: none; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background 0.15s; }
.create-btn:hover { background: var(--orange-dark); }
.create-btn:disabled { background: #ccc; cursor: not-allowed; }
.cancel-btn { font-family: var(--font); padding: 8px; background: none; border: none; font-size: 13px; color: var(--muted); cursor: pointer; text-align: center; }
.cancel-btn:hover { color: var(--text); }

/* ── MAIN ── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.play-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--orange);
  color: white;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.play-btn:hover { background: var(--orange-dark); }
.play-btn:disabled { background: #ccc; cursor: not-allowed; }

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

.info-item { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.info-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.info-value { font-size: 13px; font-weight: 600; }

.tempo-input {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  width: 46px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  text-align: center;
  outline: none;
}
.tempo-input:focus { border-color: var(--orange); }

.metronome-pill {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  background: #E0E0E0;
  color: var(--muted);
  transition: all 0.15s;
  letter-spacing: 0.04em;
}
.metronome-pill.on { background: var(--orange); color: white; }

.speed-select {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  outline: none;
  background: var(--white);
  cursor: pointer;
}
.speed-select:focus { border-color: var(--orange); }

/* ── OSMD cursor → orange playhead ── */
.osmd-cursor-line-following, .osmd-cursor {
  background-color: rgba(245, 137, 58, 0.15) !important;
  border-left: 3px solid #F5893A !important;
  z-index: 5 !important;
  opacity: 1 !important;
}

/* ── EDIT TOOLBAR ── */
.edit-toolbar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.edit-toolbar.visible { display: flex; }

.edit-group { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.edit-label { font-size: 13px; color: var(--muted); font-weight: 500; }

.edit-dropdown { position: relative; }

.edit-dropdown-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s;
  white-space: nowrap;
}
.edit-dropdown-btn:hover, .edit-dropdown-btn.open { border-color: var(--orange); }

.edit-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
  min-width: 180px;
  z-index: 50;
  overflow: hidden;
  max-height: 300px;
  overflow-y: auto;
}
.edit-dropdown-menu.open { display: block; }

.edit-dropdown-item { padding: 9px 14px; font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.edit-dropdown-item:hover { background: #F5F5F5; }
.edit-dropdown-item.active { color: var(--orange); font-weight: 600; background: #FEF0E4; }

.edit-dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

.edit-dropdown-group-label {
  padding: 6px 14px 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── SCORE AREA ── */
.score-area { flex: 1; overflow-y: auto; padding: 24px; }
.score-card { background: var(--white); border-radius: 12px; box-shadow: 0 1px 6px rgba(0,0,0,0.08); padding: 32px; min-height: 360px; position: relative; }

.upload-prompt { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; height: 300px; color: var(--muted); }
.upload-prompt-icon { font-size: 48px; }
.upload-prompt p { font-size: 15px; font-weight: 500; color: var(--text); }
.upload-prompt span { font-size: 13px; }
.upload-file-btn { font-family: var(--font); padding: 10px 24px; background: var(--orange); color: white; border: none; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; margin-top: 4px; }

.loading-overlay { display: none; position: absolute; inset: 0; background: rgba(255,255,255,0.88); border-radius: 12px; flex-direction: column; align-items: center; justify-content: center; gap: 16px; z-index: 10; }
.loading-overlay.visible { display: flex; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--orange); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-size: 15px; font-weight: 600; }
.loading-sub { font-size: 13px; color: var(--muted); }
#osmd-container { position: relative; transition: opacity 0.5s ease-out; }

#osmd-container { width: 100%; }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1A1A1A;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: all 0.25s;
  pointer-events: none;
  z-index: 2000;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── EXPORT MODAL ── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: 18px;
  padding: 32px;
  width: 560px;
  max-width: calc(100vw - 48px);
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
  position: relative;
}

.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.modal-title { font-size: 22px; font-weight: 700; }
.modal-close { width: 32px; height: 32px; border-radius: 50%; border: none; background: #F0F0F0; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--muted); line-height: 1; }
.modal-close:hover { background: #E0E0E0; }

.format-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 28px; }

.format-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 8px 14px;
  border: 2px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--white);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.format-card:hover { border-color: var(--orange); }
.format-card.selected { background: #FEF0E4; border-color: transparent; }

.format-icon { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; }

.export-row { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.export-row-label { font-size: 15px; font-weight: 600; min-width: 90px; }

.custom-select-wrap { position: relative; flex: 1; }

.custom-select-btn {
  font-family: var(--font);
  font-size: 14px;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  outline: none;
}
.custom-select-btn:focus, .custom-select-btn.open { border-color: var(--orange); }

.custom-select-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
  z-index: 10;
  overflow: hidden;
}
.custom-select-dropdown.open { display: block; }

.custom-select-option { padding: 10px 14px; font-size: 14px; cursor: pointer; }
.custom-select-option:hover { background: #F5F5F5; }
.custom-select-option.selected { background: #FEF0E4; color: var(--orange); font-weight: 600; }

.export-checkbox-row { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; font-size: 15px; font-weight: 600; }
.export-checkbox-row input { width: 18px; height: 18px; accent-color: var(--orange); cursor: pointer; }
.info-icon { color: var(--muted); font-size: 16px; cursor: help; }

.download-btn {
  font-family: var(--font);
  width: 100%;
  padding: 15px;
  background: var(--orange);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.download-btn:hover { background: var(--orange-dark); }
.download-btn:disabled { background: #ccc; cursor: not-allowed; }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D0D0D0; border-radius: 3px; }
