/* ============================================================
   Partitio - Feuilles de styles & Design adaptatif
   ============================================================ */

:root {
  --bg-main: #0f172a;
  --bg-panel: #1e293b;
  --bg-card: #273549;
  --bg-input: #0f172a;
  --border-color: #334155;
  --border-focus: #3b82f6;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #10b981;
  --accent-hover: #059669;
  --warning: #f59e0b;
  --note-highlight: #ec4899;
  --note-highlight-glow: rgba(236, 72, 153, 0.45);
  --paper-bg: #ffffff;
  --paper-text: #0f172a;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── En-tête de l'application ─────────────────────────────── */
.app-header {
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  font-size: 1.6rem;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #60a5fa, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: none;
}

@media (min-width: 640px) {
  .brand-tagline {
    display: inline;
  }
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ── Disposition principale ───────────────────────────────── */
.app-container {
  max-width: 1360px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
}

/* ── Panneau de paramètres ────────────────────────────────── */
.panel {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  cursor: pointer;
  user-select: none;
}

.panel-title {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.panel-toggle-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
}

.panel-toggle-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-card);
}

.params-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  transition: all 0.2s ease;
}

.panel.collapsed .params-grid {
  display: none;
}

.param-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background-color: var(--bg-card);
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.param-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.random-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  font-size: 0.75rem;
  color: #a78bfa;
}

.random-checkbox-label input {
  accent-color: #a78bfa;
  cursor: pointer;
}

.param-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.select-input, .text-input, .range-input {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s ease;
}

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

.select-input:disabled, .text-input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.measures-val-badge {
  font-weight: 600;
  font-size: 0.85rem;
  min-width: 2rem;
  text-align: right;
  color: #38bdf8;
}

/* ── Barre de transport (Contrôles lecture & génération) ──── */
.transport-bar {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  position: sticky;
  top: 57px;
  z-index: 40;
  box-shadow: var(--shadow-md);
}

.transport-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.transport-tools {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Boutons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

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

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

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

.btn-accent:hover {
  background-color: var(--accent-hover);
}

.btn-accent.is-active {
  background-color: var(--warning);
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--border-color);
}

.btn-icon-only {
  padding: 0.5rem;
  font-size: 1rem;
}

/* Contrôles audio / MIDI */
.audio-output-select {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tempo-control {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tempo-slider {
  width: 80px;
  cursor: pointer;
}

.tempo-badge {
  font-weight: 600;
  color: #38bdf8;
  min-width: 45px;
}

.metronome-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
}

.metronome-toggle input {
  accent-color: var(--accent);
}

.live-hints-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  padding: 0.4rem 0.6rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.live-hints-label:hover {
  border-color: var(--accent);
}

.live-hints-label input {
  accent-color: #be185d;
  width: 1rem;
  height: 1rem;
}

.live-hints-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  user-select: none;
  transition: all var(--transition);
}

.live-hints-toggle:hover {
  border-color: #be185d;
  color: var(--text);
}

.live-hints-toggle input {
  accent-color: #be185d;
}

/* ── Barre basse permanente (Note la plus aiguë, Accord, Position) ── */
body.has-live-dock {
  padding-bottom: 5.5rem;
}

.live-playback-dock {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(860px, calc(100vw - 2rem));
  z-index: 1000;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid rgba(203, 213, 225, 0.9);
  border-radius: 9999px;
  padding: 0.45rem 0.85rem;
  box-shadow: 0 10px 30px -5px rgba(15, 23, 42, 0.18), 0 4px 12px -2px rgba(15, 23, 42, 0.08);
  animation: liveDockSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}

@keyframes liveDockSlideUp {
  from {
    opacity: 0;
    transform: translate(-50%, 20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.live-dock-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  width: 100%;
}

.live-hint-card {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  background: rgba(248, 250, 252, 0.9);
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  border: 1px solid #e2e8f0;
  transition: all var(--transition);
}

.live-hint-card:hover {
  background: #ffffff;
  border-color: #cbd5e1;
}

.live-hint-meta {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  white-space: nowrap;
}

.live-hint-badge {
  font-size: 1.15rem;
  font-weight: 800;
  color: #0f172a;
  padding: 0.2rem 0.65rem;
  border-radius: 9999px;
  text-align: center;
  min-width: 60px;
  white-space: nowrap;
  transition: all 0.1s ease;
}

.live-badge-note {
  color: #be185d;
  background: #fdf2f8;
  border: 1.5px solid #fbcfe8;
}

.live-badge-chord {
  color: #1d4ed8;
  background: #eff6ff;
  border: 1.5px solid #bfdbfe;
}

.live-badge-measure {
  color: #047857;
  background: #ecfdf5;
  border: 1.5px solid #a7f3d0;
}

@media (max-width: 680px) {
  .live-playback-dock {
    width: calc(100vw - 1rem);
    bottom: 0.5rem;
    border-radius: var(--radius-md);
    padding: 0.35rem 0.5rem;
  }
  .live-dock-inner {
    gap: 0.35rem;
  }
  .live-hint-card {
    padding: 0.3rem 0.45rem;
    gap: 0.35rem;
  }
  .live-hint-meta .live-hint-title {
    display: none;
  }
  .live-hint-badge {
    font-size: 0.95rem;
    min-width: 44px;
    padding: 0.1rem 0.4rem;
  }
}

/* ── Zone de partition (Papier blanc) ─────────────────────── */
.score-wrapper {
  background-color: var(--paper-bg);
  color: var(--paper-text);
  border-radius: var(--radius-md);
  padding: 1.5rem 1.25rem;
  box-shadow: var(--shadow-lg);
  min-height: 480px;
  position: relative;
  overflow-x: auto;
}

.score-meta-header {
  border-bottom: 2px solid #0f172a;
  padding-bottom: 0.5rem;
  margin-bottom: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.score-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.01em;
}

.score-details {
  font-size: 0.85rem;
  color: #475569;
  font-weight: 500;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ── Composant d'affichage de l'ambitus ────────────────────── */
.ambitus-card {
  margin-bottom: 1.25rem;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border: 1px solid #e2e8f0;
  padding: 0.85rem 1.1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.ambitus-panel {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.ambitus-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.ambitus-title-group {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.ambitus-icon {
  font-size: 1.15rem;
}

.ambitus-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #1e293b;
}

.ambitus-interval-badge {
  background: #e2e8f0;
  color: #334155;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 9999px;
  border: 1px solid #cbd5e1;
}

.ambitus-pills-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ambitus-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: #334155;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.ambitus-pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.ambitus-keyboard-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.2rem 0;
}

.ambitus-keyboard-svg {
  display: block;
  width: 100%;
  min-width: 620px;
  height: auto;
  max-height: 75px;
}

.key-white {
  transition: fill 0.2s ease, stroke 0.2s ease;
}

.key-black {
  transition: fill 0.2s ease, stroke 0.2s ease;
}

.key-active {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.08));
}

.ambitus-hands-breakdown {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: #475569;
  flex-wrap: wrap;
  padding-top: 0.45rem;
  border-top: 1px dashed #e2e8f0;
}

.hand-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.hand-indicator {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
  flex-shrink: 0;
}

.hand-bass strong {
  color: #0369a1;
}

.hand-treble strong {
  color: #be185d;
}

.hand-divider {
  color: #94a3b8;
}

.score-container {
  width: 100%;
}

.score-container .system {
  margin-bottom: 0.5rem;
  padding: 0.35rem 0;
  border-radius: var(--radius-sm);
  transition: background-color 0.2s ease;
}

.score-container .system svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible !important;
}

.score-container .system.is-current {
  background-color: rgba(59, 130, 246, 0.06);
}

/* Surlignage interactif de la note jouée */
.vf-note-clickable {
  cursor: pointer;
  transition: fill 0.08s ease, stroke 0.08s ease;
}

.vf-note-clickable:hover path,
.vf-note-clickable:hover polygon {
  fill: #2563eb !important;
}

/* Notes à très grand ambitus (lignes supplémentaires extrêmes) */
.vf-note-extreme path,
.vf-note-extreme polygon {
  filter: drop-shadow(0 0 2px rgba(59, 130, 246, 0.35));
}

/* Coloration active pendant la lecture */
.is-playing path,
.is-playing polygon,
.is-playing rect {
  fill: var(--note-highlight) !important;
  stroke: var(--note-highlight) !important;
  filter: drop-shadow(0 0 6px var(--note-highlight-glow));
}

/* ── Pied de page ─────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 1.25rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}

.app-footer a {
  color: #60a5fa;
  text-decoration: none;
}

/* ── Styles d'impression (A4) ─────────────────────────────── */
@media print {
  @page {
    size: A4 portrait;
    margin: 12mm 10mm 12mm 10mm;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .app-header,
  .panel,
  .transport-bar,
  .app-footer,
  .no-print {
    display: none !important;
  }

  .app-container {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .score-wrapper {
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    background: transparent !important;
  }

  .score-meta-header {
    border-bottom: 1.5pt solid #000 !important;
    margin-bottom: 1rem !important;
  }

  .score-title {
    font-size: 1.4rem !important;
    color: #000 !important;
  }

  .score-details {
    color: #222 !important;
    font-size: 0.85rem !important;
  }

  .ambitus-card {
    background: #ffffff !important;
    border: 1pt solid #94a3b8 !important;
    box-shadow: none !important;
    padding: 0.4rem 0.6rem !important;
    margin-bottom: 0.8rem !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .ambitus-keyboard-svg {
    min-width: 0 !important;
    max-height: 48px !important;
  }

  .ambitus-interval-badge {
    background: #ffffff !important;
    border: 1pt solid #64748b !important;
    color: #000000 !important;
  }

  .ambitus-pill {
    background: #ffffff !important;
    border: 1pt solid #94a3b8 !important;
    color: #000000 !important;
    box-shadow: none !important;
  }

  .score-container .system {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 0.5rem !important;
  }

  .is-playing path,
  .is-playing polygon {
    fill: #000000 !important;
    stroke: #000000 !important;
    filter: none !important;
  }
}

/* ── Adaptabilité Mobile (< 768px) ────────────────────────── */
@media (max-width: 768px) {
  .app-header {
    padding: 0.6rem 0.9rem;
  }

  .app-container {
    padding: 0.6rem;
    gap: 0.75rem;
  }

  .transport-bar {
    top: 50px;
    padding: 0.6rem 0.75rem;
    gap: 0.5rem;
  }

  .transport-main,
  .transport-tools {
    width: 100%;
    justify-content: space-between;
  }

  .score-wrapper {
    padding: 1rem 0.5rem;
    min-height: 360px;
  }

  .params-grid {
    grid-template-columns: 1fr;
  }
}
