/* ==========================================================================
   Tokens
   ========================================================================== */
:root {
  --bg-void: #0c0b09;
  --bg-surface: #17140f;
  --bg-raised: #211c15;
  --bg-raised-2: #2b241a;
  --line: #3a3226;
  --text: #f3eee4;
  --text-muted: #a89d89;
  --text-faint: #6f6656;
  --amber: #e8a33d;
  --amber-strong: #ffbf5c;
  --red: #c1443b;
  --green: #6fae6a;

  --font: -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-num: "Helvetica Neue", Arial, sans-serif;

  --radius: 10px;
  --radius-sm: 6px;

  --shell-max: 1600px;
}

@media (prefers-color-scheme: light) {
  /* L'application est pensée pour une salle sombre : on garde le thème
     sombre même si le système est en mode clair, pour la lisibilité. */
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg-void);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  font-family: inherit;
  color: inherit;
}

a {
  color: var(--amber);
}

::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}
::-webkit-scrollbar-track {
  background: var(--bg-surface);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-raised-2);
  border-radius: 8px;
  border: 3px solid var(--bg-surface);
}

:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  border-radius: var(--radius-sm);
  padding: 0.6em 1em;
  font-size: 1rem;
}
button:hover {
  border-color: var(--amber);
}
button.primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #1a1204;
  font-weight: 700;
}
button.primary:hover {
  background: var(--amber-strong);
}
button.ghost {
  background: transparent;
  border-color: transparent;
}
button.ghost:hover {
  border-color: var(--line);
}
button.danger {
  border-color: var(--red);
  color: var(--red);
  background: transparent;
}
button.danger:hover {
  background: var(--red);
  color: var(--text);
}
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

input[type="text"],
input[type="number"],
textarea,
select {
  background: var(--bg-void);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.55em 0.75em;
  width: 100%;
}
textarea {
  resize: vertical;
  min-height: 5em;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Shell / Topbar
   ========================================================================== */
.app-shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.brand .dot {
  width: 0.5em;
  height: 0.5em;
  border-radius: 50%;
  background: var(--amber);
  display: inline-block;
}

.topbar-search {
  flex: 1;
  max-width: 420px;
}

.topbar-nav {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

main.view {
  flex: 1;
  width: 100%;
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 1.5rem;
}

/* ==========================================================================
   Bibliothèque
   ========================================================================== */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}

.song-card {
  text-align: left;
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.song-card:hover {
  border-color: var(--amber);
}
.song-card .title {
  font-size: 1.25rem;
  font-weight: 700;
}
.song-card .artist {
  color: var(--text-muted);
}
.song-card .meta {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.6rem;
  font-variant-numeric: tabular-nums;
}

.chip {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.15em 0.75em;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.chip.accent {
  border-color: var(--amber);
  color: var(--amber-strong);
}

.empty-state {
  color: var(--text-muted);
  padding: 3rem 1rem;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  margin-top: 1.25rem;
}

/* ==========================================================================
   Écran de répétition
   ========================================================================== */
.song-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.song-header h1 {
  font-size: clamp(1.4rem, 2.5vw, 2rem);
  margin: 0;
}
.song-header .artist {
  color: var(--text-muted);
  font-size: 1.1rem;
}
.song-header-meta {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.layout-song {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1.25rem;
  align-items: start;
}

.side-rail {
  position: sticky;
  top: 5.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}
.panel-title {
  font-size: 0.8rem;
  color: var(--text-faint);
  margin: 0 0 0.6rem;
  font-weight: 700;
}

.section-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.section-pill {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.55em 0.7em;
  display: flex;
  align-items: center;
  gap: 0.6em;
  color: var(--text-muted);
}
.section-pill .marker {
  width: 6px;
  align-self: stretch;
  border-radius: 3px;
  background: var(--line);
}
.section-pill:hover {
  border-color: var(--line);
  color: var(--text);
}
.section-pill.active {
  background: var(--bg-raised);
  color: var(--text);
  border-color: var(--amber);
  font-weight: 700;
}
.section-pill.active .marker {
  background: var(--amber);
}

/* Module tempo */
.tempo-module {
  text-align: center;
}
.bpm-value {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 3.4rem;
  font-weight: 800;
  line-height: 1;
  margin: 0.2rem 0;
  transition: transform 60ms ease-out;
}
.bpm-value.pulse {
  transform: scale(1.08);
  color: var(--amber-strong);
}
.bpm-label {
  color: var(--text-faint);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}
.bpm-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.6rem 0;
}
.bpm-controls button {
  font-size: 1.3rem;
  width: 2.6em;
  height: 2.6em;
  border-radius: 999px;
  line-height: 1;
}
.beat-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--line);
  display: inline-block;
  margin: 0 3px;
  transition: background 40ms, transform 40ms;
}
.beat-dot.on {
  background: var(--amber);
  transform: scale(1.3);
}
.beat-row {
  margin: 0.5rem 0 0.75rem;
}
.tempo-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.tempo-actions button {
  flex: 1;
}
#metronomeToggle.playing {
  background: var(--amber);
  border-color: var(--amber);
  color: #1a1204;
  font-weight: 700;
}

/* Zone paroles */
.lyrics-stage {
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 12rem);
  min-height: 420px;
}

.scroll-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.scroll-toolbar .spacer {
  flex: 1;
}
.scroll-toolbar label {
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.scroll-toolbar input[type="range"] {
  width: 120px;
}

.lyrics-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.75rem 60vh;
  scroll-behavior: smooth;
}

.section-block {
  margin-bottom: 2.25rem;
  padding-left: 1rem;
  border-left: 3px solid var(--line);
}
.section-block.current {
  border-left-color: var(--amber);
}
.section-block .section-label {
  color: var(--amber-strong);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 0.4rem;
  font-size: 1.05rem;
}
.section-block .chords-line {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color: var(--green);
  white-space: pre-wrap;
  margin-bottom: 0.4rem;
  font-size: 1rem;
}
.section-block .lyrics-text {
  white-space: pre-wrap;
  font-size: clamp(1.15rem, 1.6vw, 1.5rem);
  max-width: 62ch;
}
.section-block .no-lyrics {
  color: var(--text-faint);
  font-style: italic;
}

/* ==========================================================================
   Mode Live (plein écran)
   ========================================================================== */
body.live-mode .topbar,
body.live-mode [data-hide-live] {
  display: none !important;
}

body.controls-hidden .side-rail,
body.controls-hidden .scroll-toolbar {
  display: none !important;
}
body.controls-hidden .layout-song {
  grid-template-columns: 1fr;
}
body.live-mode main.view {
  padding: 0;
  max-width: none;
}
body.live-mode .layout-song {
  grid-template-columns: 260px 1fr;
  gap: 0;
  height: 100vh;
}
body.live-mode .side-rail {
  position: static;
  height: 100vh;
  border-right: 1px solid var(--line);
  border-radius: 0;
  overflow-y: auto;
}
body.live-mode .panel {
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-top: none;
}
body.live-mode .lyrics-stage {
  height: 100vh;
  border: none;
  border-radius: 0;
}
body.live-mode .song-header {
  padding: 0.9rem 1.75rem 0;
  margin-bottom: 0;
}
body.live-mode .section-block .lyrics-text {
  font-size: clamp(1.8rem, 3vw, 3rem);
}
body.live-mode .section-block .chords-line {
  font-size: 1.3rem;
}
body.live-mode .bpm-value {
  font-size: 4.2rem;
}
body.live-mode .lyrics-scroll {
  padding-top: 2rem;
}

.live-hint {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  z-index: 30;
  pointer-events: none;
}

/* ==========================================================================
   Admin
   ========================================================================== */
.admin-toolbar {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.admin-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.admin-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
}
.admin-row .info {
  flex: 1;
}
.admin-row .info .title {
  font-weight: 700;
}
.admin-row .info .sub {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.admin-row .actions {
  display: flex;
  gap: 0.5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.form-field label {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.form-field.span-2 {
  grid-column: span 2;
}

.sections-editor {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.section-editor-row {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem;
  background: var(--bg-surface);
}
.section-editor-row .row-top {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.6rem;
}
.section-editor-row .row-top input[type="text"] {
  flex: 1;
}
.section-editor-row .row-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.reorder-btns {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.reorder-btns button {
  padding: 0.1em 0.5em;
  font-size: 0.8rem;
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  margin: 1.5rem 0;
}

.io-row {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 900px) {
  .layout-song {
    grid-template-columns: 1fr;
  }
  .side-rail {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .side-rail .panel {
    flex: 1;
    min-width: 220px;
  }
  .lyrics-stage {
    height: 60vh;
  }
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }
  .form-field.span-2 {
    grid-column: span 2;
  }
  body.live-mode .layout-song {
    grid-template-columns: 1fr;
  }
  body.live-mode .side-rail {
    height: auto;
  }
}

@media (max-width: 560px) {
  .topbar {
    flex-wrap: wrap;
  }
  .topbar-search {
    order: 3;
    max-width: none;
    width: 100%;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .form-field.span-2 {
    grid-column: span 1;
  }
  .section-editor-row .row-fields {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
