:root {
  color-scheme: light;
  --bg: #f7f2ec;
  --ink: #1d1b16;
  --muted: #6d6256;
  --accent: #d77b47;
  --accent-dark: #a2572d;
  --panel: #ffffff;
  --shadow: 0 24px 60px rgba(29, 27, 22, 0.12);
  --radius: 24px;
}

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

body {
  font-family: "Work Sans", sans-serif;
  background: radial-gradient(circle at top left, #fff6e9 0%, #f7f2ec 40%, #efe6db 100%);
  color: var(--ink);
  min-height: 100vh;
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.08;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140' viewBox='0 0 140 140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.35'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
  z-index: -1;
}

.dashboard {
  padding: 48px 6vw 64px;
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.hero {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-size: 0.7rem;
  color: var(--accent-dark);
  font-weight: 600;
}

.title-row {
  --h1-size: clamp(2.6rem, 4vw, 4rem);
  display: flex;
  align-items: flex-end;
  gap: 18px;
  margin-top: 8px;
}

.hero h1 {
  font-family: "Playfair Display", serif;
  font-size: var(--h1-size);
  line-height: 1;
}

.player-btn {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  /* le bas du bouton est calé sur la ligne de base du titre (line-height:1
     descend un peu sous la baseline, on remonte donc légèrement). */
  transform: translateY(calc(var(--h1-size) * 0.05 - 1px));
  transition: background 0.2s ease, transform 0.1s ease;
}

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

.player-btn:active {
  transform: translateY(calc(var(--h1-size) * 0.05 - 1px)) scale(0.94);
}

.player-btn .player-icon-play {
  margin-left: 3px;
}

.player-btn .player-icon-pause {
  display: none;
}

.player-btn.is-playing .player-icon-play {
  display: none;
}

.player-btn.is-playing .player-icon-pause {
  display: inline;
}

.subtext {
  color: var(--muted);
  margin-top: 12px;
  max-width: 420px;
}

.status {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(215, 123, 71, 0.12);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--accent-dark);
}

.hero-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-end;
}

.timezone-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

#timezone-toggle {
  width: 54px;
  height: 28px;
  border: none;
  background: rgba(109, 98, 86, 0.25);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s ease;
}

#timezone-toggle .toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 6px 16px rgba(29, 27, 22, 0.18);
  transition: transform 0.2s ease;
}

#timezone-toggle[aria-pressed="true"] {
  background: rgba(31, 138, 76, 0.35);
}

#timezone-toggle[aria-pressed="true"] .toggle-knob {
  transform: translateX(26px);
}

.pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(215, 123, 71, 0.7);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(215, 123, 71, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(215, 123, 71, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(215, 123, 71, 0);
  }
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.card {
  background: var(--panel);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  overflow: hidden;
}

.card.highlight {
  background: linear-gradient(130deg, #ffe9d6 0%, #fff6ed 50%, #ffffff 100%);
}

.card h2 {
  font-size: 1.05rem;
  color: var(--muted);
  font-weight: 500;
}

.value {
  font-size: clamp(2rem, 3vw, 3.4rem);
  font-weight: 600;
  line-height: 1;
}

.value-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.trend-arrow {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--muted);
  line-height: 1;
  display: inline-block;
}

.trend-arrow.up {
  color: #1f8a4c;
}

.trend-arrow.down {
  color: #ff1e1e;
}

.trend {
  color: var(--accent-dark);
  font-weight: 500;
}

.caption {
  color: var(--muted);
  font-size: 0.9rem;
}

.badge {
  position: absolute;
  top: 21px;
  right: 18px;
  background: #d92d20;
  color: #fff;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.panel {
  background: var(--panel);
  padding: 28px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.panel-header h2 {
  font-size: 1.4rem;
}

.panel-header p {
  color: var(--muted);
  margin-top: 4px;
}

.losses-decades {
  margin: 0 0 20px;
  padding: 16px 18px 18px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.72) 0%, rgba(247, 242, 236, 0.9) 100%);
  border: 1px solid rgba(29, 27, 22, 0.08);
}

.losses-decades[hidden] {
  display: none;
}

.losses-decades-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 14px;
  font-weight: 600;
}

.losses-decades-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 10px;
}

.losses-decade {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.losses-decade-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  white-space: nowrap;
}

.losses-decade-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(29, 27, 22, 0.08);
  overflow: hidden;
}

.losses-decade-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  transition: width 0.35s ease, background 0.35s ease;
}

.losses-decade-value {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #c0392b;
  text-align: center;
}

.losses-decade.is-empty .losses-decade-value {
  color: var(--muted);
  font-weight: 500;
}

@media (max-width: 900px) {
  .losses-decades-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px 10px;
  }
}

.table-wrap {
  overflow-x: auto;
}

.losses-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.losses-table thead th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 12px 12px;
  border-bottom: 1px solid rgba(29, 27, 22, 0.1);
  white-space: nowrap;
}

.losses-table tbody td {
  padding: 12px;
  border-bottom: 1px solid rgba(29, 27, 22, 0.06);
  color: var(--ink);
}

.losses-table tbody tr.losses-row--two-spins td {
  background: rgba(29, 27, 22, 0.05);
}

.losses-table tbody tr.losses-row--three-spins td {
  background: rgba(29, 27, 22, 0.09);
}

.losses-table tbody tr:last-child td {
  border-bottom: none;
}

.losses-table .col-rank {
  width: 1%;
  white-space: nowrap;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.losses-table .col-song {
  font-weight: 500;
}

.losses-song-btn {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 500;
  color: inherit;
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(215, 123, 71, 0.35);
  text-underline-offset: 3px;
}

.losses-song-btn:hover {
  color: var(--accent-dark);
  text-decoration-color: var(--accent);
}

body.modal-open {
  overflow: hidden;
}

.broadcast-modal[hidden] {
  display: none;
}

.broadcast-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.broadcast-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(29, 27, 22, 0.45);
  backdrop-filter: blur(4px);
}

.broadcast-modal-panel {
  position: relative;
  width: min(100%, 980px);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--panel);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 24px 24px 20px;
}

.broadcast-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(29, 27, 22, 0.1);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.broadcast-modal-close:hover {
  color: var(--ink);
  border-color: rgba(29, 27, 22, 0.2);
}

.broadcast-modal-title {
  font-family: "Playfair Display", serif;
  font-size: 1.35rem;
  line-height: 1.25;
  padding-right: 44px;
}

.broadcast-modal-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.broadcast-modal-body {
  margin-top: 20px;
}

.broadcast-grid-loading,
.broadcast-grid-error,
.broadcast-grid-meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.broadcast-grid-wrap {
  overflow-x: auto;
}

.broadcast-grid {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 720px;
}

.broadcast-grid th,
.broadcast-grid td {
  border: 1px solid rgba(29, 27, 22, 0.08);
  text-align: center;
  padding: 0;
}

.broadcast-grid thead th {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 2px;
  background: rgba(247, 242, 236, 0.9);
}

.broadcast-grid-hour {
  width: 34px;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--muted);
  background: rgba(247, 242, 236, 0.65);
}

.broadcast-grid td {
  height: 22px;
  background: #fff;
  font-size: 0.62rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #fff;
  vertical-align: middle;
}

.broadcast-grid td.is-broadcast {
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(162, 87, 45, 0.35);
}

.broadcast-grid td.is-broadcast-zero {
  background: rgba(215, 123, 71, 0.45);
  color: rgba(255, 255, 255, 0.9);
}

.broadcast-grid-meta {
  margin-top: 12px;
}

.losses-table .col-num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.losses-table .col-loss {
  color: #c0392b;
  font-weight: 600;
}

.losses-empty {
  text-align: center !important;
  color: var(--muted);
  padding: 24px 12px !important;
}

#refresh-button {
  border: none;
  background: var(--accent-dark);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 10px 20px rgba(162, 87, 45, 0.25);
}

#refresh-button:hover {
  transform: translateY(-2px);
}

.chart-wrap {
  position: relative;
  height: 320px;
}

.chart-wrap--streams {
  height: 220px;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  color: var(--accent-dark);
  border: 1.5px solid rgba(162, 87, 45, 0.25);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 12px rgba(162, 87, 45, 0.1);
}

.btn-back:hover {
  background: rgba(215, 123, 71, 0.08);
  box-shadow: 0 6px 18px rgba(162, 87, 45, 0.18);
}

.settings-loading {
  color: var(--muted);
  font-size: 0.95rem;
  padding: 8px 0;
}

.settings-error {
  color: #c0392b;
  font-size: 0.95rem;
  padding: 8px 0;
}

.stream-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stream-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 20px;
  padding: 16px 0;
  border-bottom: 1px solid rgba(29, 27, 22, 0.07);
}

.stream-row:last-child {
  border-bottom: none;
}

.stream-mount {
  font-family: "Courier New", monospace;
  font-size: 0.88rem;
  color: var(--muted);
  word-break: break-all;
}

.stream-name-input {
  border: 1.5px solid rgba(109, 98, 86, 0.25);
  border-radius: 10px;
  padding: 10px 14px;
  font-family: "Work Sans", sans-serif;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--bg);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  width: 100%;
}

.stream-name-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(215, 123, 71, 0.15);
}

.stream-name-input::placeholder {
  color: rgba(109, 98, 86, 0.5);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 24px;
}

.btn-save {
  border: none;
  background: var(--accent-dark);
  color: #fff;
  padding: 12px 28px;
  border-radius: 999px;
  font-family: "Work Sans", sans-serif;
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 10px 20px rgba(162, 87, 45, 0.25);
}

.btn-save:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(162, 87, 45, 0.3);
}

.save-status {
  font-size: 0.9rem;
  font-weight: 500;
}

.save-status.success {
  color: #1f8a4c;
}

.save-status.error {
  color: #c0392b;
}

@media (max-width: 600px) {
  .stream-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

@media (max-width: 768px) {
  .dashboard {
    padding: 32px 5vw 48px;
  }

  .hero {
    align-items: flex-start;
  }

  .hero-controls {
    align-items: flex-start;
  }

  .timezone-switch {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .panel {
    padding: 24px;
  }
}
