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

:root {
  --bg-deep: #07130b;
  --bg-mid: #123124;
  --panel: rgba(8, 20, 16, 0.92);
  --panel-soft: rgba(14, 34, 27, 0.86);
  --accent: #5fe3a8;
  --accent-strong: #7ef0b6;
  --accent-warm: #f4c96b;
  --text-main: #f7f3e8;
  --text-muted: #b7d8c7;
  --border: rgba(95, 227, 168, 0.38);
  --border-strong: rgba(127, 240, 182, 0.65);
  --shadow: rgba(0, 0, 0, 0.36);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at top, #163d2e 0%, var(--bg-mid) 42%, var(--bg-deep) 100%);
  font-family: 'Segoe UI', Arial, sans-serif;
  user-select: none;
  color: var(--text-main);
}

/* ── Calques superposés ── */
#bg-layer, #game-layer, #ui-overlay, #counters-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}

/* COUCHE 1 — fond */
#bg-layer { z-index: 1; }
#bg-canvas { width: 100%; height: 100%; display: block; }

/* COUCHE 3 — Three.js */
#game-layer { z-index: 3; }
#three-canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  background: transparent;
}

/* Compteurs par case */
#counters-layer {
  z-index: 5;
  pointer-events: none;
}

.cell-counter {
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(6, 18, 14, 0.9);
  border: 1.5px solid rgba(100, 215, 153, 0.6);
  color: #f7fce9;
  font-size: 13px;
  font-weight: bold;
  font-family: 'Segoe UI', Arial, sans-serif;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  box-shadow: 0 2px 8px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.08);
  transform: translateX(-50%);
  pointer-events: none;
  transition: opacity 0.2s;
}

.store-counter {
  width: 36px;
  height: 36px;
  font-size: 15px;
  border-color: rgba(242, 201, 109, 0.9);
  background: rgba(8, 24, 18, 0.92);
  box-shadow: 0 2px 10px rgba(0,0,0,0.7), 0 0 0 1px rgba(242, 201, 109, 0.16);
}

/* COUCHE 4 — UI */
#ui-overlay {
  z-index: 6;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding: 16px 18px 18px;
  gap: 10px;
}

#score-panel {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(12px, 2.4vw, 24px);
  pointer-events: auto;
  width: min(92vw, 800px);
  margin-bottom: 6px;
}

.score-box {
  flex: 1 1 0;
  max-width: 180px;
  background: linear-gradient(135deg, rgba(13, 29, 22, 0.95), rgba(24, 49, 37, 0.88));
  border: 1px solid rgba(100, 215, 153, 0.35);
  border-radius: 16px;
  padding: 8px 14px;
  text-align: center;
  min-width: 110px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.32), inset 0 1px 0 rgba(255,255,255,0.06);
}
.player-label {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.score-val {
  display: block;
  font-size: 30px;
  font-weight: bold;
  color: var(--accent-strong);
  line-height: 1.1;
  text-shadow: 0 0 12px rgba(242, 201, 109, 0.25);
}

#turn-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, rgba(10, 22, 17, 0.96), rgba(17, 36, 28, 0.9));
  border: 1px solid rgba(242, 201, 109, 0.45);
  border-radius: 999px;
  padding: 7px 18px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.28);
  min-width: 168px;
}
#turn-dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow: 0 0 8px var(--accent-strong), 0 0 16px rgba(242, 201, 109, 0.3);
  transition: background 0.4s, box-shadow 0.4s;
}
#turn-dot.p2 {
  background: #7bc3ff;
  box-shadow: 0 0 8px #7bc3ff, 0 0 16px rgba(123,195,255,0.35);
}
#turn-text {
  font-size: 13px;
  color: #f3e1b4;
  letter-spacing: 0.06em;
}

#msg-bar {
  text-align: center;
  background: rgba(10, 24, 18, 0.86);
  border: 1px solid rgba(100, 215, 153, 0.26);
  border-radius: 12px;
  color: #dcefd9;
  font-size: 13px;
  padding: 8px 18px;
  letter-spacing: 0.04em;
  align-self: center;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
}

#btn-row {
  display: flex;
  justify-content: center;
  gap: 14px;
  pointer-events: auto;
  flex-wrap: wrap;
  width: 100%;
  max-width: 760px;
  margin-top: 4px;
  margin-bottom: 54px;
}

#mode-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  pointer-events: auto;
  margin-top: 8px;
  flex-wrap: wrap;
  width: 100%;
  max-width: 760px;
}

.mode-btn {
  background: rgba(10, 24, 18, 0.9);
  border: 1px solid rgba(100, 215, 153, 0.38);
  border-radius: 10px;
  color: #ccefd7;
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 11px;
  padding: 7px 14px;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: background 0.22s, border-color 0.22s, box-shadow 0.22s, transform 0.1s;
  box-shadow: 0 3px 12px rgba(0,0,0,0.34);
}
.mode-btn.active {
  background: rgba(24, 60, 40, 0.85);
  border-color: rgba(242, 201, 109, 0.9);
  color: #f3e1b4;
  box-shadow: 0 4px 18px rgba(100, 215, 153, 0.18);
}

button {
  background: rgba(10, 24, 18, 0.9);
  border: 1px solid rgba(100, 215, 153, 0.38);
  border-radius: 10px;
  color: #ccefd7;
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 13px;
  padding: 9px 26px;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: background 0.22s, border-color 0.22s, box-shadow 0.22s, transform 0.1s;
  box-shadow: 0 3px 12px rgba(0,0,0,0.34);
}
button:hover {
  background: rgba(24, 60, 40, 0.9);
  border-color: rgba(242, 201, 109, 0.9);
  color: #f3e1b4;
  box-shadow: 0 4px 18px rgba(100, 215, 153, 0.16);
}
button:active { transform: scale(0.96); }

#win-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.78);
  padding: 20px;
}
#win-box {
  width: min(90vw, 480px);
  background: linear-gradient(145deg, rgba(10, 24, 18, 0.96), rgba(18, 38, 29, 0.95));
  border: 2px solid rgba(100, 215, 153, 0.55);
  border-radius: 18px;
  padding: 42px 64px;
  text-align: center;
  box-shadow: 0 8px 48px rgba(0,0,0,0.7), 0 0 0 1px rgba(242, 201, 109, 0.08);
}
#win-box h2 {
  color: #f3e1b4;
  font-size: 34px;
  margin-bottom: 12px;
  text-shadow: 0 0 20px rgba(242, 201, 109, 0.28);
}
#win-box p  { color: #a5c2b1; font-size: 16px; margin-bottom: 26px; }
#win-box button { font-size: 15px; padding: 11px 34px; }

@keyframes pulse-ring {
  0%   { opacity: 0.9; transform: scale(1); }
  50%  { opacity: 0.5; transform: scale(1.06); }
  100% { opacity: 0.9; transform: scale(1); }
}
.selected-ring { animation: pulse-ring 0.9s ease-in-out infinite; }

@media (max-width: 600px) {
  .score-box { min-width: 92px; padding: 6px 10px; }
  .score-val { font-size: 22px; }
  #msg-bar { font-size: 11px; }
  .cell-counter { width: 24px; height: 24px; font-size: 11px; }
  .store-counter { width: 30px; height: 30px; font-size: 13px; }
  #turn-indicator { min-width: 130px; padding: 7px 12px; }
  #score-panel { gap: 8px; }
}

/* ══════════════════════════════════════════
   BANDEAU BIENVENU DÉFILANT
══════════════════════════════════════════ */
#welcome-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  height: 34px;
  background: linear-gradient(90deg,
    rgba(7, 19, 15, 0.98) 0%,
    rgba(24, 57, 44, 0.98) 50%,
    rgba(7, 19, 15, 0.98) 100%);
  border-top: 1.5px solid rgba(95, 227, 168, 0.42);
  overflow: hidden;
  display: flex;
  align-items: center;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.6);
  pointer-events: none;
}

#welcome-track {
  display: flex;
  white-space: nowrap;
  animation: bannerScroll 32s linear infinite;
}

.welcome-msg {
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--accent-warm);
  letter-spacing: 0.03em;
  padding-right: 60px;
  text-shadow: 0 0 14px rgba(244,201,107,0.18);
}

@keyframes bannerScroll {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* ══════════════════════════════════════════
   BOUTON MUSIQUE FLOTTANT
══════════════════════════════════════════ */
#music-btn {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px 7px 10px;
  background: rgba(10,5,0,0.88);
  border: 1.5px solid rgba(210,155,50,0.6);
  border-radius: 20px;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  box-shadow: 0 2px 14px rgba(0,0,0,0.55);
}
#music-btn:hover {
  background: rgba(40,20,0,0.95);
  border-color: rgba(245,200,80,0.85);
  transform: scale(1.05);
}
#music-btn:active { transform: scale(0.97); }

#music-icon {
  font-size: 15px;
  line-height: 1;
}
#music-label {
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: #f5d49a;
  letter-spacing: 0.04em;
}
#music-btn.playing {
  border-color: rgba(100,255,120,0.75);
  background: rgba(0,30,10,0.92);
}
#music-btn.playing #music-label {
  color: #80ffaa;
}

#music-volume {
  position: fixed;
  top: 48px;
  right: 14px;
  z-index: 300;
  width: 118px;
  height: 6px;
  cursor: pointer;
  accent-color: #f5d49a;
  opacity: 0.95;
}

#music-file-btn {
  position: fixed;
  top: 76px;
  right: 14px;
  z-index: 300;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(210,155,50,0.6);
  background: rgba(10,5,0,0.88);
  color: #f5d49a;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.45);
}

#music-file-btn:hover {
  background: rgba(40,20,0,0.95);
  border-color: rgba(245,200,80,0.85);
}

/* ══════════════════════════════════════════
   BOUTON LISTE PLAYLIST
══════════════════════════════════════════ */
#music-playlist-btn {
  position: fixed;
  top: 100px;
  right: 14px;
  z-index: 300;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(210,155,50,0.6);
  background: rgba(10,5,0,0.88);
  color: #f5d49a;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.45);
}
#music-playlist-btn:hover {
  background: rgba(40,20,0,0.95);
  border-color: rgba(245,200,80,0.85);
}

#music-stop-btn {
  position: fixed;
  top: 124px;
  right: 14px;
  z-index: 300;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(210,155,50,0.6);
  background: rgba(10,5,0,0.88);
  color: #f5d49a;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.45);
}
#music-stop-btn:hover {
  background: rgba(40,20,0,0.95);
  border-color: rgba(245,200,80,0.85);
}

/* ══════════════════════════════════════════
   PANNEAU PLAYLIST
══════════════════════════════════════════ */
#playlist-panel {
  display: none;
  flex-direction: column;
  position: fixed;
  top: 130px;
  right: 14px;
  z-index: 400;
  width: 240px;
  max-height: 320px;
  background: rgba(10,5,0,0.96);
  border: 1.5px solid rgba(210,155,50,0.6);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.7);
  overflow: hidden;
}

#playlist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(210,155,50,0.3);
  flex-shrink: 0;
}

#playlist-title {
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: #f5d49a;
  letter-spacing: 0.05em;
}

#playlist-controls {
  display: flex;
  gap: 4px;
}
#playlist-controls button {
  background: rgba(40,20,0,0.7);
  border: 1px solid rgba(210,155,50,0.4);
  border-radius: 6px;
  color: #f5d49a;
  font-size: 11px;
  padding: 3px 7px;
  cursor: pointer;
}
#playlist-controls button:hover { background: rgba(80,40,0,0.9); }

#songo-playlist-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
  flex: 1;
}
#songo-playlist-list::-webkit-scrollbar { width: 4px; }
#songo-playlist-list::-webkit-scrollbar-track { background: transparent; }
#songo-playlist-list::-webkit-scrollbar-thumb { background: rgba(210,155,50,0.4); border-radius: 2px; }

.pl-item {
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 12px;
  color: #e0c080;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
}
.pl-item:hover { background: rgba(80,40,0,0.6); }
.pl-item.pl-active {
  color: #80ffaa;
  background: rgba(0,40,15,0.5);
  font-weight: 600;
}
.pl-empty {
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 11px;
  color: rgba(200,150,60,0.6);
  padding: 12px 14px;
  text-align: center;
  font-style: italic;
}
