/* ============================================================
   style.css — GeoGuessr Mathieu & Sébastien
   Conçu mobile-first, fonctionne aussi sur PC
   ============================================================ */

/* ----- Reset & base ----- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0f0f13;
  --surface:  #1a1a23;
  --surface2: #23232f;
  --accent:   #4f9ef8;
  --accent2:  #f86b4f;
  --text:     #e8e8f0;
  --muted:    #7a7a99;
  --green:    #4fcf7a;
  --red:      #f84f4f;
  --radius:   12px;
  --shadow:   0 4px 24px rgba(0,0,0,.5);
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

/* ----- Écran de sélection du joueur ----- */
#screen-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 24px;
  padding: 32px 20px;
}

#screen-player h1 {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.5px;
  text-align: center;
}

#screen-player p {
  color: var(--muted);
  text-align: center;
}

.player-btns {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-player {
  padding: 18px 36px;
  font-size: 1.2rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform .12s, opacity .12s;
  letter-spacing: 0.3px;
}
.btn-player:active { transform: scale(.96); opacity: .85; }

.btn-mathieu   { background: var(--accent);  color: #fff; }
.btn-sebastien { background: var(--accent2); color: #fff; }
.btn-mc        { background: #9b59b6;        color: #fff; }
.btn-solo      { background: var(--green);   color: #0f0f13; }

#test-mode-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  margin-top: 8px;
}
#test-mode-label input { cursor: pointer; accent-color: var(--accent); width: 16px; height: 16px; }

/* ----- Écran principal du jeu ----- */
#screen-game {
  display: none;
  flex-direction: column;
  height: 100dvh;
}

/* ----- Header scores ----- */
#header {
  background: var(--surface);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
}

.score-global {
  font-size: .85rem;
  color: var(--muted);
}
.score-global strong { color: var(--text); font-size: 1rem; }

.score-match {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  flex: 1;
}
.score-match .name-m { color: var(--accent); }
.score-match .name-s { color: var(--accent2); }

#turn-indicator {
  font-size: .8rem;
  background: var(--surface2);
  border-radius: 20px;
  padding: 4px 12px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: relative;
}
#turn-indicator:active { opacity: .7; }
#turn-indicator.my-turn  { color: var(--green); border: 1px solid var(--green); }
#turn-indicator.wait     { color: var(--muted); border: 1px solid var(--muted); }

/* Menu contextuel du header */
#header-menu {
  display: none;
  position: fixed;
  top: 52px;
  right: 8px;
  background: var(--surface2);
  border: 1px solid #333;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 9999;
  min-width: 140px;
}
#header-menu.open { display: block; }
#header-menu button {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: .95rem;
  text-align: left;
  cursor: pointer;
}
#header-menu button:hover { background: rgba(255,255,255,.06); }

/* ----- Zone principale ----- */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ----- Message d'attente / info ----- */
#msg-box {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px 24px;
  padding-bottom: calc(40px + env(safe-area-inset-bottom, 24px));
  text-align: center;
  gap: 20px;
}

#msg-box h2 { font-size: 1.4rem; }
#msg-box p  { color: var(--muted); line-height: 1.6; }

.btn-primary {
  padding: 14px 32px;
  font-size: 1rem;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity .12s;
}
.btn-primary:active { opacity: .8; }
.btn-primary:disabled { background: var(--surface2); color: var(--muted); cursor: default; }

/* ----- Panneau Street View (wrapper) ----- */
#sv-panel {
  display: none;
  flex: 1;
  position: relative;
  overflow: hidden;
  flex-direction: column;
}

/* === VUE STREET VIEW (fond, remplit tout le panneau) === */
#sv-view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

#streetview {
  flex: 1;
  width: 100%;
  background: #111;
  min-height: 0;
}

/* Bouton flottant "Placer mon point" — fixé au viewport sur mobile */
#sv-bar {
  position: fixed;
  bottom: 24px;
  right: 16px;
  z-index: 120;
  display: flex;
  pointer-events: none;
}

#btn-show-map {
  flex-shrink: 0;
  padding: 14px 22px;
  font-size: 1rem;
  pointer-events: all;
  box-shadow: 0 4px 20px rgba(0,0,0,.7);
  border-radius: 50px;
}

/* === BOTTOM SHEET CARTE (overlay 70%, monte depuis le bas) === */
#map-view {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 72%;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,.6);
  transform: translateY(105%);
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}

/* Handle visuel en haut du sheet */
#map-view::before {
  content: '';
  display: block;
  width: 40px; height: 4px;
  background: #555;
  border-radius: 2px;
  margin: 10px auto 6px;
  flex-shrink: 0;
}

/* Ouverture du sheet */
#sv-panel.map-active #map-view {
  transform: translateY(0);
}


#guess-map {
  flex: 1;
  width: 100%;
  min-height: 0;
}

/* Boutons carte : fixes au viewport, visibles uniquement quand la carte est ouverte */
#map-bar {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 12px;
  right: 12px;
  z-index: 1000;
  display: none; /* affiché via JS quand map-active */
  gap: 10px;
  align-items: center;
}

#btn-show-sv,
#btn-confirm-guess {
  box-shadow: 0 4px 16px rgba(0,0,0,.6);
}

#btn-show-sv {
  background: var(--surface2);
  border: 1px solid #444;
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
#btn-show-sv:active { opacity: .7; }

#btn-confirm-guess { flex: 1; }

/* ----- Résultat de manche ----- */
#result-panel {
  display: none;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  background: var(--surface);
}

#result-map {
  width: 100%;
  height: 240px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--surface2);
}

.result-scores {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.result-card {
  flex: 1;
  min-width: 130px;
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: center;
}
.result-card .player-name { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.result-card .dist        { font-size: 1.4rem; font-weight: 700; }
.result-card.winner-card  { border: 2px solid var(--green); }
.result-card.winner-card .dist { color: var(--green); }

.round-verdict {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
}
.round-verdict.win  { color: var(--green); }
.round-verdict.lose { color: var(--red); }
.round-verdict.tie  { color: var(--muted); }

/* ----- Overlay "Partie terminée" ----- */
#overlay-game-over {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.85);
  z-index: 200;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  text-align: center;
}
#overlay-game-over h2 { font-size: 2rem; }
#overlay-game-over p  { color: var(--muted); }


/* ----- Vignette rouge de fin de timer ----- */
#timer-vignette {
  display: none;
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 119;
  animation: timer-pulse 2s ease-in-out infinite;
}
#timer-vignette.active { display: block; }

@keyframes timer-pulse {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(248, 79, 79, 0); }
  50%       { box-shadow: inset 0 0 8vw 2vw rgba(248, 79, 79, 0.65); }
}

/* ----- Chrono Street View ----- */
#sv-timer {
  position: fixed;
  top: calc(56px + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  pointer-events: none;
  display: none;
  align-items: center;
  justify-content: center;
  /* Mobile : pill simple */
  background: rgba(0,0,0,.6);
  border-radius: 20px;
  border: 1.5px solid rgba(255,255,255,.2);
  padding: 6px 18px;
}

#timer-ring { display: none; } /* caché sur mobile */

#timer-text {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  white-space: nowrap;
}

#sv-timer.warning #timer-text { color: #f0c060; }
#sv-timer.warning { border-color: #f0c060; }
#sv-timer.expired #timer-text { color: var(--red); }
#sv-timer.expired { border-color: var(--red); }

/* PC : cercle dans le coin supérieur gauche de la SV */
@media (min-width: 768px) {
  #sv-timer {
    position: absolute;
    top: 16px;
    left: 16px;
    transform: none;
    background: none;
    border: none;
    padding: 0;
    width: 84px;
    height: 84px;
  }
  #timer-ring {
    display: block;
    position: absolute;
    inset: 0;
    width: 84px;
    height: 84px;
    transform: rotate(-90deg);
  }
  .ring-bg {
    fill: none;
    stroke: rgba(255,255,255,.15);
    stroke-width: 5;
  }
  .ring-fill {
    fill: none;
    stroke: #4f9ef8;
    stroke-width: 5;
    stroke-linecap: round;
    stroke-dasharray: 213.6;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1s linear, stroke .5s;
  }
  #sv-timer.warning .ring-fill { stroke: #f0c060; }
  #sv-timer.expired .ring-fill { stroke: var(--red); }
  #timer-text {
    position: absolute;
    font-size: .95rem;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}

/* ----- Boussole Street View ----- */
#sv-compass {
  position: fixed;
  bottom: 24px;
  left: 16px;
  width: 62px;
  height: 62px;
  z-index: 120;
  pointer-events: none;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,.8));
}
#sv-compass svg {
  width: 100%;
  height: 100%;
  transition: transform .1s linear;
}

/* ----- Masquer les éléments Google Maps en bas de l'écran ----- */
/* Barre "Données cartographiques / Conditions / Signaler" */
.gm-style-cc { display: none !important; }
/* Logo Google et lien associé */
.gm-style a[href^="https://maps.google"],
.gm-style a[href^="https://www.google"] { display: none !important; }
/* Icône clavier / accessibilité à gauche */
.gm-iv-address,
button.gm-iv-back-button { display: none !important; }

/* ----- Utilitaires ----- */
.hidden { display: none !important; }
.flex   { display: flex; }
.col    { flex-direction: column; }


/* ----- PC : Street View + carte côte à côte ----- */
@media (min-width: 768px) {
  #sv-panel { flex-direction: row; overflow: visible; }

  /* Reset du positionnement absolu mobile */
  #sv-view {
    position: relative;
    flex: 2;
    inset: auto;
  }
  #streetview { min-height: 400px; }

  /* Barre SV statique, bouton visible */
  #sv-bar {
    position: absolute;
    bottom: 16px;
    right: 16px;
    pointer-events: none;
  }
  #btn-show-map {
    display: inline-flex !important;
    pointer-events: all;
  }
  #sv-compass {
    position: absolute;
    bottom: 16px;
    left: 16px;
  }

  /* Reset du bottom sheet → carte classique à droite */
  #map-view {
    position: relative;
    bottom: auto; left: auto; right: auto;
    height: auto;
    flex: 1;
    min-width: 220px;
    max-width: 400px;
    transform: none !important;
    transition: none;
    border-radius: 0;
    box-shadow: none;
  }
  #map-view::before { display: none; }

  /* SV grande (2/3) + carte petite (1/3) par défaut */
  #sv-view  { flex: 2; order: 1; }
  #map-view { flex: 1; order: 2; }

  /* Interversion : carte grande (2/3) + SV petite (1/3) */
  #sv-panel.map-active #sv-view  { flex: 1; order: 2; }
  #sv-panel.map-active #map-view {
    flex: 2; order: 1;
    max-width: none;
    transform: none !important;
  }

  /* "Placer mon point" disparaît quand la carte est en grand */
  #sv-panel.map-active #btn-show-map { display: none !important; }

  /* "← Street View" visible dans la map-bar uniquement quand carte en grand */
  #btn-show-sv { display: none !important; }
  #sv-panel.map-active #btn-show-sv { display: inline-flex !important; }

  #map-bar {
    position: relative;
    bottom: auto; left: auto; right: auto;
    display: flex !important;
    padding: 10px 14px;
    background: var(--surface);
  }
  #btn-show-sv, #btn-confirm-guess { box-shadow: none; }

  #result-panel { flex-direction: row; align-items: flex-start; flex-wrap: wrap; }
  #result-map   { flex: 2; height: 300px; }
  .result-scores { flex: 1; min-width: 200px; flex-direction: column; align-items: stretch; }
}
