/* =========================================================
   Le Foreur Maritime
   Theme clair par defaut, theme sombre en bascule.
   Toutes les couleurs passent par des variables.
   ========================================================= */

/* --- Theme clair, palette d'origine du jeu --- */
:root {
  --ciel-1: #87CEEB;
  --ciel-2: #4682B4;
  --mer-1: #87CEEB;
  --mer-2: #1E90FF;
  --mer-3: #006994;

  --cadre-1: #D4A574;
  --cadre-2: #8B6F47;
  --cadre-bord: #8B6F47;

  --panneau: rgba(255, 255, 255, 0.95);
  --panneau-plein: #FFFFFF;
  --panneau-doux: #F5F5F5;
  --bordure: rgba(0, 0, 0, 0.12);

  --texte: #2C1810;
  --texte-doux: #5F6775;
  --titre: #2C1810;

  --accent: #0099cc;
  --accent-texte: #FFFFFF;
  --succes: #059669;
  --alerte: #DC2626;

  --fond-grille: #001F3F;
  --terre-1: #8B7355;
  --terre-2: #654321;
  --roche-1: #708090;
  --roche-2: #2F4F4F;
  --or-1: #FFD700;
  --or-2: #FFA500;
  --diamant-1: #E0FFFF;
  --diamant-2: #00CED1;
  --vide-1: #1A4D6D;
  --vide-2: #0A2540;
  --joueur-1: #FF6B6B;
  --joueur-2: #C92A2A;

  --ombre: 0 4px 14px rgba(0, 0, 0, 0.2);
  --rayon: 12px;
  --cadre-epaisseur: clamp(6px, 2vw, 15px);
  --police: "Outfit", "Segoe UI", system-ui, sans-serif;
  --police-mono: "JetBrains Mono", "SFMono-Regular", monospace;
}

/* --- Theme sombre, aligne sur les jetons de hednai.com --- */
[data-theme="sombre"] {
  --ciel-1: #0F172A;
  --ciel-2: #16233C;
  --mer-1: #16283F;
  --mer-2: #0E2136;
  --mer-3: #071626;

  --cadre-1: #3A4A61;
  --cadre-2: #1E293B;
  --cadre-bord: #334155;

  --panneau: rgba(30, 41, 59, 0.96);
  --panneau-plein: #1E293B;
  --panneau-doux: #16202F;
  --bordure: #334155;

  --texte: #F1F5F9;
  --texte-doux: #94A3B8;
  --titre: #F1F5F9;

  --accent: #00B0E6;
  --accent-texte: #04283A;
  --succes: #34D399;
  --alerte: #F87171;

  --fond-grille: #030C17;
  --terre-1: #6B5A44;
  --terre-2: #3F2F1D;
  --roche-1: #4B5563;
  --roche-2: #1F2937;
  --or-1: #F5C842;
  --or-2: #D98F14;
  --diamant-1: #9BE8EF;
  --diamant-2: #0FA5B4;
  --vide-1: #0E2B45;
  --vide-2: #061726;
  --joueur-1: #FF7A7A;
  --joueur-2: #B02525;

  --ombre: 0 4px 18px rgba(0, 0, 0, 0.55);
}

/* =========================================================
   Base
   ========================================================= */

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--police);
  color: var(--texte);
  background: linear-gradient(180deg, var(--ciel-1) 0%, var(--ciel-2) 100%);
  /* Empeche le rebond elastique et le tirer pour rafraichir pendant une partie */
  overscroll-behavior: none;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
  stroke: none;
}

/* =========================================================
   Structure generale : trois rangees qui remplissent l'ecran
   ========================================================= */

#app {
  height: 100dvh;
  max-width: 980px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

/* --- Barre superieure --- */

#barreHaut {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: linear-gradient(180deg, var(--cadre-1) 0%, var(--cadre-2) 100%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  z-index: 2;
}

.marque {
  margin: 0;
  font-size: clamp(0.95rem, 3.6vw, 1.35rem);
  font-weight: 600;
  color: var(--titre);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-theme="sombre"] .marque {
  color: #F1F5F9;
}

.outils {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.bouton-icone {
  width: 36px;
  height: 36px;
  padding: 8px;
  border-radius: 50%;
  background: var(--panneau);
  color: var(--texte);
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.bouton-icone:hover {
  transform: scale(1.06);
}

.bouton-icone--texte {
  font-family: var(--police-mono);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0;
}

/* Bascule des pictogrammes selon l'etat du bouton */
.bouton-icone[data-etat="actif"] .icone-coupe,
.bouton-icone[data-etat="coupe"] .icone-ondes {
  display: none;
}

.icone-ondes,
.icone-coupe {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.bouton-icone[data-etat="clair"] .icone-soleil,
.bouton-icone[data-etat="sombre"] .icone-lune {
  display: none;
}

.icone-soleil path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* --- Scene --- */

#scene {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: linear-gradient(180deg, var(--mer-1) 0%, var(--mer-2) 45%, var(--mer-3) 100%);
  border-left: var(--cadre-epaisseur) solid var(--cadre-bord);
  border-right: var(--cadre-epaisseur) solid var(--cadre-bord);
  overflow: hidden;
}

#bateau {
  width: 96px;
  height: 48px;
  margin: 0 auto;
  flex-shrink: 0;
  animation: flotter 3s ease-in-out infinite;
}

@keyframes flotter {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

/* Sur les ecrans courts le bateau cede sa place au plateau */
@media (max-height: 700px) {
  #bateau {
    display: none;
  }
}

#scoreBar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  flex-shrink: 0;
}

.pastille {
  background: var(--panneau);
  border-radius: 10px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.pastille__libelle {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--texte-doux);
}

.pastille__valeur {
  font-family: var(--police-mono);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--texte);
}

.pastille--accent .pastille__valeur {
  color: var(--accent);
}

#ligneOxygene {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  font-size: 0.68rem;
  color: #FFFFFF;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.oxygene__libelle {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.oxygene__palier {
  flex-shrink: 0;
  font-weight: 600;
}

#jaugeOxygene {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

#barreOxygene {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.25s ease, background-color 0.25s ease;
}

/* La jauge vire au rouge quand la reserve devient critique */
#jaugeOxygene[data-critique="1"] #barreOxygene {
  background: var(--alerte);
}

#plateauConteneur {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* =========================================================
   Plateau et tuiles
   ========================================================= */

#zoneJeu {
  display: grid;
  grid-template-columns: repeat(var(--colonnes, 15), var(--tuile, 32px));
  gap: var(--ecart, 2px);
  padding: var(--pad-plateau, 8px);
  background: var(--fond-grille);
  border-radius: var(--rayon);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.55);
  /* Le balayage est gere en JavaScript, le navigateur ne doit pas intercepter */
  touch-action: none;
  user-select: none;
}

.tuile {
  position: relative;
  width: var(--tuile, 32px);
  height: var(--tuile, 32px);
  border-radius: 4px;
  transition: background 0.18s ease;
}

.tuile::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
}

.terre {
  background: linear-gradient(135deg, var(--terre-1) 0%, var(--terre-2) 100%);
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.3);
}

.terre::after {
  border-radius: 4px;
  background-image:
    radial-gradient(circle at 28% 30%, rgba(0, 0, 0, 0.22) 11%, transparent 12%),
    radial-gradient(circle at 72% 66%, rgba(255, 255, 255, 0.14) 9%, transparent 10%);
}

.roche {
  background: linear-gradient(135deg, var(--roche-1) 0%, var(--roche-2) 100%);
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
}

.roche::after {
  width: 58%;
  height: 58%;
  background: rgba(0, 0, 0, 0.32);
  border-radius: 44% 56% 48% 52% / 52% 44% 56% 48%;
}

.or {
  background: linear-gradient(135deg, var(--or-1) 0%, var(--or-2) 100%);
  animation: eclat 2s ease-in-out infinite;
}

.or::after {
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 0 0 2px rgba(140, 90, 0, 0.45);
}

@keyframes eclat {

  0%,
  100% {
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.55);
  }

  50% {
    box-shadow: 0 0 16px rgba(255, 215, 0, 0.9);
  }
}

.diamant {
  background: linear-gradient(135deg, var(--diamant-1) 0%, var(--diamant-2) 100%);
  animation: scintiller 1.6s ease-in-out infinite;
}

.diamant::after {
  width: 42%;
  height: 42%;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 3px;
  transform: rotate(45deg);
}

@keyframes scintiller {

  0%,
  100% {
    box-shadow: 0 0 12px rgba(0, 206, 209, 0.7);
  }

  50% {
    box-shadow: 0 0 22px rgba(0, 206, 209, 1);
  }
}

.vide {
  background: linear-gradient(135deg, var(--vide-1) 0%, var(--vide-2) 100%);
}

.joueur {
  background: radial-gradient(circle, var(--joueur-1) 0%, var(--joueur-2) 100%);
  box-shadow: 0 0 14px rgba(255, 107, 107, 0.75);
  animation: battement 1.1s ease-in-out infinite;
  z-index: 1;
}

/* Le foret pointe vers le bas, sens de progression du foreur */
.joueur::after {
  width: 0;
  height: 0;
  background: none;
  border-left: calc(var(--tuile, 32px) * 0.2) solid transparent;
  border-right: calc(var(--tuile, 32px) * 0.2) solid transparent;
  border-top: calc(var(--tuile, 32px) * 0.32) solid rgba(255, 255, 255, 0.92);
}

@keyframes battement {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.08);
  }
}

.tuile--change {
  animation: apparition 0.18s ease-out;
}

@keyframes apparition {
  from {
    transform: scale(0.85);
  }

  to {
    transform: scale(1);
  }
}

/* Secousse de la scene lors d'un sonar ou d'un choc */
.scene--secousse-faible {
  animation: secousse 0.18s ease-in-out;
}

.scene--secousse-forte {
  animation: secousse 0.3s ease-in-out;
}

@keyframes secousse {

  0%,
  100% {
    transform: translate(0, 0);
  }

  25% {
    transform: translate(-3px, 2px);
  }

  50% {
    transform: translate(3px, -2px);
  }

  75% {
    transform: translate(-2px, -1px);
  }
}

/* =========================================================
   Commandes
   ========================================================= */

#barreBas {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--panneau);
  border-top: 1px solid var(--bordure);
  box-shadow: 0 -3px 10px rgba(0, 0, 0, 0.18);
}

.pave,
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.actions {
  flex-direction: column;
  gap: 4px;
}

.bouton-rond {
  width: 54px;
  height: 54px;
  padding: 14px;
  border-radius: 50%;
  background: var(--panneau-doux);
  border: 1px solid var(--bordure);
  color: var(--texte);
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, background-color 0.15s ease;
}

.bouton-rond:active:not(:disabled) {
  transform: scale(0.93);
}

.bouton-rond--principal {
  width: 66px;
  height: 66px;
  padding: 16px;
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-texte);
}

.bouton-rond--sonar {
  border: 2px solid var(--accent);
  color: var(--accent);
}

.bouton-rond--sonar svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.bouton-rond:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.bouton-texte {
  font-size: 0.7rem;
  color: var(--texte-doux);
  text-decoration: underline;
  padding: 2px 4px;
}

/* =========================================================
   Ecrans superposes
   ========================================================= */

.ecran {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  overflow-y: auto;
}

body[data-ecran="accueil"] #ecranAccueil,
body[data-ecran="fin"] #panneauFinJeu {
  display: grid;
}

.carte {
  width: 100%;
  max-width: 420px;
  background: var(--panneau-plein);
  color: var(--texte);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--ombre);
  animation: entree 0.28s ease-out;
  margin: auto;
}

@keyframes entree {
  from {
    transform: translateY(-16px) scale(0.96);
    opacity: 0;
  }

  to {
    transform: none;
    opacity: 1;
  }
}

.carte__titre {
  margin: 0 0 6px;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--titre);
}

.carte__soustitre {
  margin: 18px 0 8px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--texte-doux);
}

.carte__texte {
  margin: 0 0 14px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--texte-doux);
}

.carte__aide {
  margin: 14px 0 0;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--texte-doux);
}

.record {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  margin-bottom: 14px;
  border-radius: 10px;
  background: var(--panneau-doux);
  font-size: 0.85rem;
  color: var(--texte-doux);
}

.record strong {
  font-family: var(--police-mono);
  font-size: 1.1rem;
  color: var(--accent);
}

.bouton-primaire {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-texte);
  font-size: 1rem;
  font-weight: 600;
  transition: filter 0.15s ease, transform 0.12s ease;
}

.bouton-primaire:hover {
  filter: brightness(1.08);
}

.bouton-primaire:active {
  transform: scale(0.98);
}

.bouton-secondaire {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--bordure);
  color: var(--texte-doux);
  font-size: 0.9rem;
}

.legende {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.legende li {
  display: flex;
  align-items: center;
  gap: 12px;
}

.legende .tuile {
  --tuile: 28px;
  flex-shrink: 0;
  animation: none;
}

.legende strong {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
}

.legende em {
  display: block;
  font-style: normal;
  font-size: 0.76rem;
  color: var(--texte-doux);
}

.badge {
  display: inline-block;
  margin: 0 0 10px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-texte);
  font-size: 0.75rem;
  font-weight: 600;
}

.bilan {
  margin: 0 0 18px;
  display: grid;
  gap: 8px;
}

.bilan div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--panneau-doux);
}

.bilan dt {
  font-size: 0.8rem;
  color: var(--texte-doux);
}

.bilan dd {
  margin: 0;
  font-family: var(--police-mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--texte);
}

.signature {
  margin: 18px 0 0;
  font-size: 0.72rem;
  text-align: center;
  color: var(--texte-doux);
}

.signature a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.signature a:hover {
  text-decoration: underline;
}

/* =========================================================
   Bannière d'installation
   ========================================================= */

#pwaBanner {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom));
  width: min(94vw, 420px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--panneau-plein);
  border: 1px solid var(--bordure);
  box-shadow: var(--ombre);
  font-size: 0.8rem;
  cursor: pointer;
  z-index: 1100;
}

#pwaBanner[hidden] {
  display: none;
}

.pwa__icone {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-texte);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.8rem;
}

.pwa__texte {
  flex: 1;
}

.pwa__fermer {
  width: 24px;
  height: 24px;
  padding: 4px;
  color: var(--texte-doux);
  flex-shrink: 0;
}

.pwa__fermer svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* =========================================================
   Adaptations grands ecrans et paysage
   ========================================================= */

@media (min-width: 780px) {
  #app {
    padding: 12px 0;
  }

  #barreHaut {
    border-radius: 14px 14px 0 0;
  }

  #barreBas {
    border-radius: 0 0 14px 14px;
    justify-content: center;
    gap: 32px;
  }

  .bouton-rond {
    width: 50px;
    height: 50px;
  }

  .bouton-rond--principal {
    width: 58px;
    height: 58px;
  }

  .pastille__libelle {
    font-size: 0.72rem;
  }

  .pastille__valeur {
    font-size: 1.05rem;
  }
}

/* En paysage sur telephone, les commandes passent a droite du plateau */
@media (max-height: 520px) and (orientation: landscape) {
  #app {
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr) auto;
  }

  #barreHaut {
    grid-column: 1 / -1;
  }

  #barreBas {
    flex-direction: column;
    justify-content: center;
    padding-right: calc(14px + env(safe-area-inset-right));
    border-top: none;
    border-left: 1px solid var(--bordure);
  }

  .pave {
    flex-wrap: wrap;
    justify-content: center;
    max-width: 130px;
  }

  .bouton-texte {
    display: none;
  }
}

/* Respect du reglage systeme de reduction des animations */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}