:root {
  --bg: #0f0f14;
  --bg2: #16161e;
  --surface: #1c1c27;
  --surface2: #252533;
  --surface3: #2e2e3f;
  --border: #363649;
  --text: #e4e4ef;
  --text2: #9d9db5;
  --text3: #6b6b85;
  --accent: #7c6aef;
  --accent2: #9b8afb;
  --accent-bg: rgba(124, 106, 239, 0.12);
  --green: #5ccba0;
  --green-bg: rgba(92, 203, 160, 0.12);
  --red: #ef6b7a;
  --red-bg: rgba(239, 107, 122, 0.12);
  --yellow: #e8c468;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 0;
  min-height: calc(100vh - 72px);
}

.panel-left {
  padding: 20px 24px 80px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

.panel-right {
  background: var(--bg2);
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 72px);
}

/* ── Hero ── */
.hero { padding: 16px 0 12px; }

.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent2);
  font-size: 18px;
  font-weight: 700;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.card-header.sub { margin-top: 16px; margin-bottom: 10px; }
.card-header h2 { font-size: 14px; font-weight: 600; }

.step-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: var(--accent-bg);
  color: var(--accent2);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.step-badge.small { width: 18px; height: 18px; font-size: 10px; }

/* ── URL Input ── */
.url-row {
  display: flex;
  align-items: center;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  transition: border-color var(--transition);
}

.url-row:focus-within { border-color: var(--accent); }
.input-icon { color: var(--text3); display: flex; flex-shrink: 0; }

.url-row input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  padding: 10px 8px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
}

.url-row input::placeholder { color: var(--text3); }

.btn-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}

.btn-inline:hover { filter: brightness(1.15); }
.btn-inline:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Loading ── */
.loading-card { text-align: center; padding: 32px 16px; }
.loading-content { display: flex; flex-direction: column; align-items: center; gap: 12px; }

.pulse-ring {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-bg); position: relative;
  animation: pulse 2s ease-in-out infinite;
}

.pulse-ring::after {
  content: ""; position: absolute; inset: 10px;
  border-radius: 50%; background: var(--accent);
  animation: pulse-inner 2s ease-in-out infinite;
}

@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); opacity: 0.7; } }
@keyframes pulse-inner { 0%,100% { transform: scale(1); } 50% { transform: scale(0.85); } }

#loading-text { font-size: 13px; font-weight: 500; }
.loading-sub { font-size: 11px; color: var(--text3); }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 84px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500; z-index: 100;
  opacity: 0; transition: all 0.3s ease; pointer-events: none;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239,107,122,0.2); }
.toast.success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(92,203,160,0.2); }

/* ── Now Playing ── */
.now-playing { margin-bottom: 12px; }

.now-playing-key {
  display: flex; align-items: center; gap: 10px; margin-bottom: 4px;
}

.now-label { font-size: 11px; color: var(--text3); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }

.now-value {
  font-size: 28px; font-weight: 700; color: var(--green);
  transition: color 0.3s ease;
}

.now-value.shifted { color: var(--accent2); }

.key-meta-row {
  display: flex; align-items: center; gap: 12px;
  font-size: 12px; color: var(--text3);
}

.key-meta-row strong { color: var(--text2); }
.confidence-text { font-size: 11px; }

/* ── Shift Row (compact) ── */
.shift-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px;
}

.shift-row select, .shift-row input[type="number"] {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: 10px 12px;
  font-size: 14px; font-family: inherit; outline: none;
  transition: border-color var(--transition);
}

.shift-row select { width: 120px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='5' viewBox='0 0 8 5' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l3 3 3-3' stroke='%236b6b85' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; padding-right: 24px;
}

.shift-row input[type="number"] { width: 64px; }
.shift-row select:focus, .shift-row input:focus { border-color: var(--accent); }

.semitone-badge {
  padding: 3px 8px; background: var(--accent-bg); color: var(--accent2);
  border-radius: 12px; font-size: 11px; font-weight: 600; white-space: nowrap;
}

.btn-accent-sm {
  padding: 10px 18px; background: var(--green); color: var(--bg);
  border: none; border-radius: 8px; font-size: 14px; font-weight: 600;
  font-family: inherit; cursor: pointer; white-space: nowrap;
  transition: all var(--transition);
}

.btn-accent-sm:hover { filter: brightness(1.1); }
.btn-accent-sm:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Add to Preset ── */
.add-to-preset {
  display: flex; align-items: center; gap: 6px;
}

.add-to-preset select {
  flex: 1; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text2); padding: 6px 8px;
  font-size: 12px; font-family: inherit; outline: none;
}

/* ── Buttons ── */
.btn-sm {
  padding: 8px 14px; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text2); font-size: 13px; font-weight: 500;
  font-family: inherit; cursor: pointer; transition: all var(--transition); white-space: nowrap;
}

.btn-sm:hover { background: var(--surface3); color: var(--text); }
.btn-sm.green { background: var(--green-bg); color: var(--green); border-color: rgba(92,203,160,0.2); }
.btn-sm.green:hover { filter: brightness(1.2); }

.btn-icon {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; background: none; border: none;
  color: var(--text2); cursor: pointer; border-radius: 6px;
  transition: all var(--transition);
}

.btn-icon:hover { color: var(--text); background: var(--surface2); }
.btn-icon.active { color: var(--accent2); }

/* ── Preset Panel ── */
.preset-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}

.preset-header h2 { font-size: 14px; font-weight: 600; }

.new-folder-row {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 10px;
}

.new-folder-row input {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); padding: 6px 10px;
  font-size: 12px; font-family: inherit; outline: none;
}

.new-folder-row input:focus { border-color: var(--accent); }

.preset-list { display: flex; flex-direction: column; gap: 8px; }

.preset-folder {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden;
}

.folder-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; cursor: pointer;
  transition: background var(--transition);
}

.folder-header:hover { background: var(--surface2); }

.folder-chevron {
  color: var(--text3); transition: transform 0.2s; flex-shrink: 0;
}

.folder-chevron.open { transform: rotate(90deg); }

.folder-name {
  flex: 1; font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.folder-count {
  font-size: 11px; color: var(--text3); margin-right: 4px;
}

.folder-actions {
  display: flex; gap: 2px; opacity: 0; transition: opacity var(--transition);
}

.folder-header:hover .folder-actions { opacity: 1; }

.folder-actions button {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; background: none; border: none;
  color: var(--text3); cursor: pointer; border-radius: 6px; font-size: 14px;
}

.folder-actions button:hover { color: var(--text); background: var(--surface3); }
.folder-actions button.del:hover { color: var(--red); }

.folder-songs { display: none; }
.folder-songs.open { display: block; }

.song-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px 10px 32px; font-size: 13px;
  cursor: pointer; transition: background var(--transition);
}

.song-item:hover { background: var(--surface2); }
.song-item.playing { background: var(--accent-bg); }

.song-item .song-title {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.song-item .song-key {
  font-size: 10px; color: var(--green); font-weight: 600;
  background: var(--green-bg); padding: 1px 6px; border-radius: 4px;
  flex-shrink: 0;
}

.song-item .song-remove {
  display: flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; background: none; border: none;
  color: var(--text3); cursor: pointer; border-radius: 3px;
  opacity: 0; transition: all var(--transition); font-size: 11px;
}

.song-item:hover .song-remove { opacity: 1; }
.song-item .song-remove:hover { color: var(--red); background: var(--red-bg); }

.preset-empty {
  text-align: center; padding: 32px 16px; color: var(--text3); font-size: 12px;
}

/* ── Bottom Player Bar ── */
.player-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg2); border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; height: 72px; z-index: 50;
}

.player-info {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 140px; max-width: 200px;
}

.player-title {
  font-size: 12px; font-weight: 500; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

.player-key-badge {
  font-size: 10px; color: var(--green); font-weight: 600;
}

.player-bar audio {
  flex: 1; height: 32px; min-width: 0;
  filter: invert(1) hue-rotate(180deg) brightness(0.8) contrast(0.9);
  opacity: 0.85;
}

.player-controls {
  display: flex; align-items: center; gap: 2px; flex-shrink: 0;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
  animation: fadeIn 0.15s ease;
  display: none;
}

.modal-overlay.open {
  display: flex;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; min-width: 300px; max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.modal-msg {
  font-size: 14px; margin-bottom: 16px; line-height: 1.6;
}

.modal-input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); padding: 8px 12px;
  font-size: 14px; font-family: inherit; outline: none; margin-bottom: 16px;
}

.modal-input:focus { border-color: var(--accent); }

.modal-btns {
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .panel-right {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: none;
    padding-bottom: 80px;
  }

  .panel-left {
    max-width: none;
    padding: 12px 12px 16px;
  }
}
