:root {
  --bg: #10131c;
  --bg-panel: #171b28;
  --bg-elevated: #1f2436;
  --border: #2a3044;
  --text: #e8e9f0;
  --text-dim: #8b90a5;
  --accent: #d98b4b;
  --accent-2: #6fc3a7;
  --danger: #d96b6b;
  --white-key: #f4f2ea;
  --black-key: #1a1c22;
  --radius: 16px;
  --grad-1: #7b5cf0;
  --grad-2: #c04fce;
  --grad-3: #e0679b;
  --sidebar-w: 84px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  height: 100%;
  overflow-x: hidden;
}

#app { min-height: 100vh; display: flex; }

/* ---- Sidebar façon Simply Piano ---- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, #241a45 0%, #3a1f52 55%, #4a2154 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}
.sidebar-logo { font-size: 1.6rem; margin-bottom: 18px; }
.side-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.62);
  width: 100%;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 0.65rem;
  border-left: 3px solid transparent;
  transition: all .15s ease;
}
.side-icon { font-size: 1.3rem; }
.side-btn:hover { color: #fff; background: rgba(255,255,255,0.06); }
.side-btn.active {
  color: #fff;
  background: rgba(255,255,255,0.12);
  border-left-color: #ffd27a;
}

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { font-size: 1.1rem; font-weight: 700; display: flex; gap: 10px; align-items: center; letter-spacing: 0.01em; }
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: linear-gradient(135deg, var(--grad-1), var(--grad-3));
  box-shadow: 0 0 10px var(--grad-2);
}

.topbar-right { margin-left: auto; }

.badge {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.badge-off { color: var(--text-dim); }
.badge-on { color: var(--accent-2); border-color: var(--accent-2); }

main { flex: 1; padding: 24px 24px 60px; max-width: 1240px; margin: 0 auto; width: 100%; }

h1 { font-size: 1.5rem; margin: 4px 0 4px; }
.hint { color: var(--text-dim); margin: 0 0 18px; }

.view { display: none; }
.view.active { display: block; }

.level-group { margin-bottom: 30px; }
.level-title {
  font-size: 0.95rem;
  color: var(--grad-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
  font-weight: 700;
}

.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: all .15s ease;
}
.filter-btn:hover { color: var(--text); border-color: var(--grad-2); }
.filter-btn.active {
  background: linear-gradient(135deg, var(--grad-1), var(--grad-3));
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

/* Cartes de leçons : dégradé violet façon Simply Piano */
.card {
  position: relative;
  background: linear-gradient(150deg, var(--grad-1) 0%, var(--grad-2) 55%, var(--grad-3) 100%);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 130px;
  overflow: hidden;
  color: #fff;
}
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 85% 15%, rgba(255,255,255,0.25), transparent 55%);
  pointer-events: none;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(123,92,240,0.35); }
.card h3 { margin: 0; font-size: 1.02rem; font-weight: 700; }
.card p { margin: 0; color: rgba(255,255,255,0.82); font-size: 0.82rem; line-height: 1.4; }
.card .stars { color: #ffd27a; font-size: 0.95rem; letter-spacing: 2px; }
.card .card-badge {
  align-self: flex-start;
  font-size: 0.66rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.18);
  color: #fff;
  backdrop-filter: blur(2px);
}

/* La bibliothèque garde des cartes sobres pour se distinguer visuellement du parcours */
#song-grid .card {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
}
#song-grid .card::after { display: none; }
#song-grid .card p { color: var(--text-dim); }
#song-grid .card .card-badge { background: var(--bg-elevated); color: var(--text-dim); }
#song-grid .card:hover { border-color: var(--grad-3); box-shadow: none; transform: translateY(-2px); }

#stats-panel .card {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: default;
  align-items: center;
  text-align: center;
  justify-content: center;
}
#stats-panel .card::after { display: none; }
#stats-panel .card h3 { font-size: 1.8rem; background: linear-gradient(135deg, var(--grad-1), var(--grad-3)); -webkit-background-clip: text; background-clip: text; color: transparent; }
#stats-panel .card p { color: var(--text-dim); }

.play-header {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.play-title-wrap { display: flex; align-items: center; gap: 10px; flex: 1 1 240px; min-width: 0; }
.play-header h2 { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.play-controls { flex: 2 1 480px; }

.progress-ring { position: relative; width: 34px; height: 34px; flex-shrink: 0; }
.progress-ring svg { width: 34px; height: 34px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--bg-elevated); stroke-width: 4; }
.ring-fg {
  fill: none;
  stroke: url(#none);
  stroke: var(--accent-2);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 107;
  stroke-dashoffset: 107;
  transition: stroke-dashoffset .25s ease;
}
.ring-check {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent-2); font-weight: 800; font-size: 1rem;
}

.btn-ghost, .btn-primary {
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
}
.btn-ghost { background: var(--bg-elevated); color: var(--text); }
.btn-primary { background: linear-gradient(135deg, var(--grad-1), var(--grad-3)); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }

.play-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.switch-label, .tempo-label {
  font-size: 0.82rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.feedback-banner {
  text-align: center;
  padding: 8px;
  border-radius: 10px;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 0.9rem;
}
.feedback-banner.ok { background: rgba(111,195,167,0.15); color: var(--accent-2); }
.feedback-banner.done { background: rgba(123,92,240,0.18); color: #cbb8ff; }
.hidden { display: none; }

.staff-panel {
  width: 100%;
  background: linear-gradient(180deg, #1d1636 0%, #241a3f 100%);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 4px 0;
}
#staff { width: 100%; height: 130px; display: block; }

#falling-notes {
  width: 100%;
  height: 220px;
  background: linear-gradient(180deg, #0c0e16 0%, #141826 100%);
  display: block;
}

#keyboard-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: 0 0 var(--radius) var(--radius);
  background: #05060a;
}
#keyboard { display: block; height: 140px; touch-action: none; }

#detected-note-panel {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-dim);
  text-align: center;
}
#detected-note-panel .sep { margin: 0 10px; opacity: 0.4; }
#detected-note-panel strong { color: var(--text); }

.library-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.library-header h1 { margin-bottom: 2px; }

.card-badge-custom { background: linear-gradient(135deg, var(--grad-1), var(--grad-3)); color: #fff; }
.card-delete {
  position: absolute;
  top: 10px; right: 10px;
  background: rgba(0,0,0,0.35);
  border: none;
  color: #fff;
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
}
.card-delete:hover { background: rgba(217,107,107,0.85); }

#song-grid .card { padding-bottom: 44px; }
.card-demo-btn {
  position: absolute;
  bottom: 12px; left: 18px; right: 18px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  transition: all .15s ease;
}
.card-demo-btn:hover { background: linear-gradient(135deg, var(--grad-1), var(--grad-3)); border-color: transparent; color: #fff; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8,9,14,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
}
.modal h2 { margin: 0 0 14px; font-size: 1.2rem; }

.modal-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.modal-tab-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
}
.modal-tab-btn.active {
  background: linear-gradient(135deg, var(--grad-1), var(--grad-3));
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}
.modal-tab { display: none; }
.modal-tab.active { display: block; }

.field-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 12px 0 6px;
}
.field-label code {
  background: var(--bg-elevated);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--accent-2);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 0.88rem;
  font-family: inherit;
}
textarea { resize: vertical; font-family: 'Courier New', monospace; }

.code-sample {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 0.78rem;
  color: var(--text-dim);
  overflow-x: auto;
  margin: 8px 0 14px;
}

.search-row { display: flex; gap: 8px; margin-bottom: 14px; }
.search-row input { flex: 1; }

.suggested-titles { margin-bottom: 16px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.suggest-chip {
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  color: var(--text-dim);
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.76rem;
  transition: all .15s ease;
}
.suggest-chip:hover {
  color: #fff;
  border-style: solid;
  border-color: transparent;
  background: linear-gradient(135deg, var(--grad-1), var(--grad-3));
}

.online-results { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.online-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.online-result span { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online-result button {
  background: linear-gradient(135deg, var(--grad-1), var(--grad-3));
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.online-result button:disabled { opacity: 0.6; cursor: default; }

.import-error {
  color: var(--danger);
  font-size: 0.82rem;
  margin-top: 8px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

@media (max-width: 820px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0; top: auto;
    width: 100%;
    height: 64px;
    flex-direction: row;
    justify-content: space-around;
    padding: 4px 0;
  }
  .sidebar-logo { display: none; }
  .side-btn { border-left: none; border-top: 3px solid transparent; }
  .side-btn.active { border-top-color: #ffd27a; }
  .main-col { padding-bottom: 64px; }
  main { padding: 16px 14px 40px; }
  .play-controls { width: 100%; justify-content: space-between; }
  #falling-notes { height: 180px; }
  #staff { height: 100px; }
  #keyboard { height: 110px; }
}
