/* ============================================================
   DB Lyrics Studio — Design System & Layout Aegisub Style
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

:root {
  /* DARK THEME (Default) */
  --bg-base: #121212;
  --bg-panel: #1A1A1A;
  --bg-hover: #2A2A2A;
  --bg-overlay: rgba(26, 26, 26, 0.85);
  --border: #333333;

  --text-main: #FFFFFF;
  --text-muted: rgba(255, 255, 255, 0.5);
  --text-inverse: #121212;

  --accent: #C8862A;
  --accent-hover: #E0962F;
  --accent-transparent: rgba(200, 134, 42, 0.2);

  --success: #27AE60;
  --danger: #E74C3C;
  --danger-transparent: rgba(231, 76, 60, 0.15);

  --font-main: 'Poppins', sans-serif;
  --font-mono: 'Consolas', 'Monaco', monospace;

  --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  --radius: 8px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  --header-height: 50px;
  --timeline-height: 250px;

  --bg-preview: #000000;
  --text-preview: #FFFFFF;
  --bg-timeline: #000000;
  --waveform-played: rgba(200, 134, 42, 0.85);
  --waveform-unplayed: rgba(255, 255, 255, 0.4);
  --waveform-center: rgba(255, 255, 255, 0.1);
}

[data-theme="light"] {
  --bg-base: #F7F4EF;
  --bg-panel: #FFFFFF;
  --bg-hover: #EAE5DE;
  --bg-overlay: rgba(255, 255, 255, 0.85);
  --border: #D1CCC5;

  --text-main: #1A1A1A;
  --text-muted: rgba(26, 26, 26, 0.5);
  --text-inverse: #FFFFFF;

  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);

  --bg-preview: #F7F4EF;
  --text-preview: #1A1A1A;
  --bg-timeline: #EAE5DE;
  --waveform-played: rgba(200, 134, 42, 0.85);
  --waveform-unplayed: rgba(26, 26, 26, 0.25);
  --waveform-center: rgba(26, 26, 26, 0.15);
}

[data-theme="light"] .time-ruler {
  background: rgba(0, 0, 0, 0.05);
}

/* ============================================================
   RESET & BASICS
   ============================================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-main);
  background: var(--bg-base);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
  /* Empêche la sélection globale */
}

a,
button {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================
   LAYOUT (DASHBOARD)
   ============================================================ */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* HEADER */
.app-header {
  height: var(--header-height);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem;
  z-index: 100;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.app-title {
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: 0.5px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  color: var(--text-main);
  font-size: 1.3rem;
  transition: var(--transition);
}

.icon-btn:hover {
  background: var(--bg-hover);
}

.icon-btn.active {
  color: var(--accent);
}

/* SIDE MENU */
.side-menu {
  position: fixed;
  top: 0;
  left: -300px;
  width: 300px;
  height: 100vh;
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  z-index: 1000;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.side-menu.open {
  transform: translateX(300px);
}

.menu-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.menu-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: var(--header-height);
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
}

.menu-title {
  font-weight: 600;
}

.menu-content {
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  overflow-y: auto;
}

.menu-group h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
  letter-spacing: 1px;
}

.menu-btn {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  text-align: left;
  font-weight: 500;
  transition: var(--transition);
}

.menu-btn i {
  font-size: 1.2rem;
  color: var(--accent);
}

.menu-btn:hover {
  background: var(--bg-hover);
}

/* MAIN AREA */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height));
  position: relative;
  min-height: 0;
}

/* PANELS */
.main-columns {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr 1.5fr;
  /* 3 colonnes */
  grid-template-rows: minmax(0, 1fr);
  gap: 1px;
  /* Borders via background */
  background: var(--border);
  overflow: hidden;
  min-height: 0;
}

.panel {
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 0;
}

.panel-header {
  height: 40px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  font-size: 0.9rem;
}

.panel-header h3 {
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}

.panel-body {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* PLAYER OVERLAY */
.player-overlay {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.divider {
  width: 1px;
  height: 24px;
  background: var(--border);
}

.play-btn {
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.8rem;
}

.play-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.mode-select {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.toggle-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  transition: var(--transition);
}

.toggle-btn.active {
  background: var(--danger-transparent);
  border-color: var(--danger);
  color: var(--danger);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4);
  }

  70% {
    box-shadow: 0 0 0 6px rgba(231, 76, 60, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0);
  }
}

.player-hints {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.8rem;
  align-items: center;
}

kbd {
  background: var(--border);
  color: var(--text-main);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
}

/* ============================================================
   PANEL 1: BLOC NOTE
   ============================================================ */
.blocnote-body {
  position: relative;
  overflow: auto;
  padding: 1rem;
}

/* On superpose le highlight et le textarea pour voir la ligne active colorée */
.blocnote-highlights,
#blocnote-textarea {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  font-family: var(--font-main);
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  padding-left: 3.5rem;
}

.blocnote-highlights {
  color: transparent;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

#blocnote-textarea {
  background: transparent;
  color: var(--text-main);
  border: none;
  resize: none;
  outline: none;
  z-index: 2;
  user-select: text;
  overflow-y: auto;
}

.note-line {
  position: relative;
  min-height: 1.6em;
}

.note-line::before {
  content: attr(data-line);
  position: absolute;
  left: -3rem;
  width: 2.5rem;
  text-align: right;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  user-select: none;
  visibility: visible;
}

.note-hl-active {
  background: var(--accent-transparent);
  border-radius: 4px;
  border-left: 3px solid var(--accent);
}

/* ============================================================
   PANEL 2: PAROLES (Tap View)
   ============================================================ */
.tap-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-preview);
  color: var(--text-preview);
}

.tap-countdown {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 8rem;
  font-weight: 700;
  color: var(--accent);
  opacity: 0;
  z-index: 10;
  transition: opacity 0.2s, transform 0.2s;
}

.tap-countdown.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.2);
}

.tap-lyrics-scroll {
  height: 100%;
  width: 100%;
  padding: 20vh 2rem;
  overflow-y: auto;
  position: relative;
  mask-image: linear-gradient(to bottom, transparent, black 15%, black 85%, transparent);
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 15%, black 85%, transparent);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  margin-top: 30vh;
  font-style: italic;
}

.tap-lyric-line {
  font-size: 1.2rem;
  font-weight: 600;
  padding: 0.6rem 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: center;
  transform-origin: center;
  opacity: 0.3;
  transform: scale(0.9);
  cursor: pointer;
}

.tap-lyric-line:hover {
  opacity: 0.8;
}

.tap-lyric-line.state-active {
  font-size: 2rem;
  opacity: 1;
  transform: scale(1);
  color: var(--text-preview);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.tap-lyric-line.state-past {
  opacity: 0.15;
  transform: translateY(-10px) scale(0.85);
}

.tap-lyric-line.state-future {
  opacity: 0.3;
  transform: translateY(10px) scale(0.9);
}

/* ============================================================
   PANEL 3: SOUS-TITRES (Tableau)
   ============================================================ */
.badge {
  background: var(--accent);
  color: #fff;
  padding: 0.1rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.subs-body {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.table-container {
  flex: 1;
  overflow-y: auto;
}

#subs-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

#subs-table th {
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  padding: 0.6rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

#subs-table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  cursor: pointer;
}

#subs-table tr.selected {
  background: var(--accent-transparent);
  border-left: 2px solid var(--accent);
}

#subs-table input {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.2rem;
  border-radius: 4px;
}

#subs-table input:focus {
  border-color: var(--accent);
  outline: none;
  background: var(--bg-base);
}

.sub-delete-btn {
  color: var(--danger);
  opacity: 0;
  transition: opacity 0.2s;
}

#subs-table tr:hover .sub-delete-btn {
  opacity: 1;
}

/* ============================================================
   BOTTOM PANEL: TIMELINE
   ============================================================ */
.panel-bottom {
  display: flex;
  flex-direction: column;
  height: auto;
  /* Let it grow based on contents, or flex: 0 0 300px */
  flex: 0 0 300px;
  border-top: 1px solid var(--border);
}

.timeline-header {
  height: 36px;
  background: var(--bg-panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
}

.timeline-info {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
}

.timeline-tools {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.timeline-tools input[type="range"] {
  width: 80px;
  accent-color: var(--accent);
}

.timeline-body {
  flex: 1;
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--bg-timeline);
}

.timeline-scroll-area {
  position: relative;
  height: 100%;
  min-width: 100%;
}

#waveform-canvas {
  position: absolute;
  top: 25px;
  left: 0;
  height: calc(100% - 25px);
  width: 100%;
  cursor: default;
}

.time-ruler {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 25px;
  background: rgba(0, 0, 0, 0.15);
  border-bottom: 1px solid var(--border);
  pointer-events: auto;
  cursor: ew-resize;
  z-index: 25;
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #E74C3C;
  pointer-events: none;
  z-index: 30;
}

.playhead::after {
  content: '';
  position: absolute;
  top: 0;
  left: -5px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid #E74C3C;
  background: none;
  border-radius: 0;
}

.timeline-events {
  position: absolute;
  top: 25px;
  left: 0;
  width: 100%;
  height: calc(100% - 25px);
  pointer-events: none;
  z-index: 20;
}

/* Markers for LRC */
.tl-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  pointer-events: auto;
  cursor: pointer;
}

.tl-marker-label {
  position: absolute;
  top: 5px;
  left: 4px;
  font-size: 0.7rem;
  background: var(--accent);
  color: #fff;
  padding: 1px 4px;
  border-radius: 4px;
}

/* Regions for SRT */
.tl-region {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent-transparent);
  border-left: 2px solid var(--accent);
  border-right: 2px solid var(--accent);
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}

.tl-region-label {
  font-size: 0.75rem;
  color: #fff;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* Drop Overlays */
.drop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--accent);
  border: 2px dashed var(--accent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 100;
}

.drag-over .drop-overlay {
  opacity: 1;
  pointer-events: none;
}

/* let drop event pass to parent */

/* ============================================================
   TOASTS
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--bg-panel);
  color: var(--text-main);
  padding: 1rem 1.5rem;
  border-radius: 8px;
  font-weight: 500;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  animation: slideIn 0.3s ease forwards;
}

.toast.success i {
  color: #10b981;
}

.toast.error i {
  color: #ef4444;
}

.toast.info i {
  color: #3b82f6;
}

.toast.removing {
  animation: slideOut 0.3s ease forwards;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }

  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* ============================================================
   MODALS
   ============================================================ */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.modal.show {
  display: flex;
  opacity: 1;
}

.modal-content {
  background: var(--bg-panel);
  color: var(--text-main);
  padding: 2rem;
  border-radius: 8px;
  width: 600px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-close:hover {
  color: var(--text-main);
}

.help-scroll-area {
  overflow-y: auto;
  padding-right: 1rem;
  margin-top: 1rem;
}

.help-scroll-area h3 {
  color: var(--accent);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
}

.help-scroll-area h3:first-child {
  margin-top: 0;
}

.help-scroll-area p,
.help-scroll-area ul {
  margin-bottom: 1rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.help-scroll-area li {
  margin-bottom: 0.5rem;
  margin-left: 1.5rem;
  list-style-type: disc;
}

.help-scroll-area kbd {
  background: var(--bg-base);
  border: 1px solid var(--border);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--text-main);
}

.help-scroll-area strong {
  color: var(--text-main);
}