/* ======== RESET & BASE ======== */
:root {
  --bg-dark: #1a1a1a;       /* Body background */
  --bg-darker: #111111;     /* Header, Footer, Active Row */
  --bg-card: #2c2c2c;       /* Cards, Inputs, List Items */
  --bg-popup: #222222;      /* Popup background */
  
  --text-main: #e0e0e0;     /* Primary text */
  --text-muted: #bdc3c7;    /* Secondary text */
  --text-inverse: #111111;  /* Text on bright backgrounds */

  --primary: #a8e063;       /* Main buttons */
  --primary-hover: #8cc34a;
  
  --danger: #c0392b;        /* Delete, Lose, Death */
  --danger-hover: #a93226;
  --error: #e74c3c;         /* Input error */

  --warning: #f1c40f;       /* Potential, Bonus, Highlight */
  --success: #27ae60;       /* Multipliers, Safe tiles */

  --border: #333333;        /* Separators */
  --border-light: #555555;  /* Input borders */
  
  --tile-bg: #646464;       /* Inactive tiles */
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html, body {
  height: 100%;
}
body {
  font-family: 'Orbitron', sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
input, button {
  touch-action: manipulation;
  font-family: 'Orbitron', sans-serif;
}
button, input[type="button"], input[type="submit"], input[type="reset"] {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ======== UTILITIES ======== */
.btn {
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  font-family: 'Orbitron', sans-serif;
  transition: background-color 0.2s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--primary);
  color: var(--text-inverse);
  font-weight: bold;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-danger {
  background-color: var(--danger);
  color: white;
}
.btn-danger:hover {
  background-color: var(--danger-hover);
}

.input-text {
  background-color: var(--bg-card);
  border: 1px solid transparent;
  border-radius: 0.5rem;
  color: var(--text-main);
  padding: 0.75rem 1rem;
  font-family: 'Orbitron', sans-serif;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
.input-text:focus {
  border-color: var(--primary);
}
.input-text.error {
  border-color: var(--error);
}

/* ======== HEADER ======== */
header {
  background-color: var(--bg-darker);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 10;
}
header > div {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  position: relative;
}
header > div > img {
  height: 2.2rem;
  width: 2.2rem;
  vertical-align: middle;
}
header h1 {
  font-size: 1.5rem;
  font-weight: normal;
}
#back-link {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 0.2em 0.6em;
  font-size: 2rem;
  color: var(--text-main);
  cursor: pointer;
  z-index: 2;
  line-height: 1;
  text-decoration: none;
}
#header-status {
  margin-top: 0.5rem;
  font-size: 1rem;
  min-height: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
#status-text {
  font-weight: bold;
}
#status-multiplier {
  color: var(--success);
}
#status-potential {
  color: var(--warning);
}

/* ======== CONTENEUR PRINCIPAL ======== */
#game-container {
  flex: 1;
  display: flex;
  flex-direction: column-reverse;
  overflow-y: auto;
  padding: 1.5rem;
  padding-top: calc(2rem + env(safe-area-inset-top, 0px));
  padding-bottom: 15rem;
  min-height: 0;
  scroll-behavior: smooth;
}

/* ======== GRILLE DE JEU ======== */
.row {
  display: flex;
  align-items: center;
  margin-bottom: 0.75rem;
}
.multiplier-label {
  width: 4.5rem;
  font-size: 1rem;
  text-align: right;
  margin-right: 0.75rem;
  color: var(--text-main);
  flex-shrink: 0;
}.tour-par-tour-multiplier-label {
  width: 1.5rem;
}
.tiles {
  display: flex;
  flex: 1;
  gap: 0.63rem;
  justify-content: center;
}
.tile {
  flex: 0 0 calc((100% / 5) - 0.5rem);
  max-width: calc((100% / 5) - 0.5rem);
  aspect-ratio: 1 / 1;
  position: relative;
  background-color: var(--tile-bg);
  border-radius: 0.4rem;
  cursor: default;
  user-select: none;
  overflow: hidden;
}
.tile-content {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  color: var(--text-main);
}

/* --- États des tuiles --- */
.tile.inactive {
  opacity: 0.4;
}
.tile.clickable {
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.tile.safe {
  background-color: var(--success);
}
.tile.skull-visible {
  background-color: var(--tile-bg);
}
.tile.skull-visible .tile-content {
  color: #ecf0f1; /* Keep specific color for icon contrast if needed, or use var(--text-main) */
}
.tile.death {
  background-color: var(--danger);
}

/* --- États des rangées --- */
.row.active .tiles {
  outline: 2px solid var(--success);
  background-color: var(--bg-darker);
  border-radius: 0.4rem;
}
.row.active.death-row .tiles {
  outline: 2px solid var(--danger);
  border-radius: 0.4rem;
}
.row.active.bonus-row .tiles {
  position: relative;
  border-radius: 0.5rem;
  outline: none;
  z-index: 1;
}
.row.active.bonus-row .tiles::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 0.5rem;
  z-index: 2;
  pointer-events: none;
  border: 2px solid transparent;
  background: linear-gradient(90deg, var(--warning), #e91e63, #9b59b6, #3498db, var(--success), var(--warning));
  background-size: 200% 100%;
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: borderCycle 4s linear infinite;
}

/* ======== BARRE DU BAS (FIXE) ======== */
#bottom-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background-color: var(--bg-darker);
  border-top: 1px solid var(--border);
  padding: 4rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 100;
}
.number-input-container {
  position: relative;
  width: 100%;
  max-width: 16rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 3rem;
}
#bet-input {
  width: 100%;
  padding: 0.6rem 0;
  text-align: center;
  font-size: 1.25rem;
  border: 1px solid var(--border-light);
  border-radius: 0.3rem;
  background-color: var(--bg-card);
  color: var(--text-main);
  z-index: 1;
  margin: 0;
}
.number-input-container button {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  height: 2rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 0.3rem;
  color: var(--text-main);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  z-index: 0;
}
.number-input-container .btn-up {
  top: -2.1rem;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}
.number-input-container .btn-down {
  bottom: -2.1rem;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.btn-row {
  display: flex;
  gap: 0.75rem;
  width: 100%;
  max-width: 16rem; /* Increased to allow side-by-side */
}

#continue-btn {
  color: var(--text-inverse);
}

#start-btn, #cashout-btn, #replay-btn, #continue-btn {
  width: 100%;
  /* max-width removed to let flex handle it */
  padding: 0.8rem 0;
  font-size: 1.5rem;
  font-weight: bold;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background-color 0.2s;
  flex: 1; /* Take remaining space */
}
#start-btn, #cashout-btn, #replay-btn {
  background-color: var(--primary);
  color: var(--text-inverse);
}
.big-btn:hover {
  background-color: var(--primary-hover);
}
#cashout-btn {
  display: none; /* Caché par défaut */
}
#cashout-btn:disabled {
  background-color: #888 !important;
  color: #222 !important;
  cursor: not-allowed !important;
  opacity: 0.7;
}
#cashout-btn svg {
  vertical-align: middle;
  margin-right: 0.5em;
}
.shuffle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.8rem;
  background-color: var(--text-main);
  color: var(--text-inverse);
  width: auto;
  flex: 0 0 auto; /* Don't grow */
  border-radius: 0.5rem;
  font-size: 1.5rem;
  border: none;
  cursor: pointer;
}
.shuffle-btn:hover,
.shuffle-btn:active,
.shuffle-btn:focus {
  background: var(--text-main) !important;
  color: var(--text-inverse) !important;
  box-shadow: none;
  outline: none;
  border: none;
  cursor: pointer;
}

/* ======== POPUP FIN DE PARTIE ======== */
#end-popup {
  display: none; /* Géré par JavaScript */
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.75);
  align-items: center;
  justify-content: center;
}
#end-popup > div {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  background: var(--bg-popup);
  padding: 2rem;
  border-radius: 0.5rem;
  max-width: 90vw;
  min-width: 260px;

  position: relative;
  box-shadow: 0 4px 32px #000;
}
#close-popup-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.7rem;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}
#end-popup-content {
  font-size: 1.25rem;
  text-align: center;
  color: var(--text-main);
}
#next-player-btn {
  display: none; /* Géré par JavaScript */
  margin: 2rem auto 0 auto;
  display: block;
  background: var(--success);
  color: var(--text-main);
  font-size: 1.1rem;
  font-weight: bold;
  padding: 0.7em 1.5em;
  border: none;
  border-radius: 0.5em;
  cursor: pointer;
}

/* ======== ICÔNES BONUS ======== */
.bonus-icon {
  opacity: 1;
  transition: opacity 0.2s;
  width: 40%;
  max-width: 2.5em;
  height: auto;
  display: inline-block;
  vertical-align: middle;
}
.bonus-popup-icon {
  height: 1.5em;
  vertical-align: middle;
  margin-right: 0.4em;
  margin-top: -0.3rem;
  width: auto;
  display: inline-block;
}

/* ======== ANIMATIONS ======== */
@keyframes borderCycle {
  0%   { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

#header-title {
    font-size: 1.5rem;
    font-weight: normal;
    margin: 0;
    text-align: center;
}

#choose-game-main-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 0rem;
}

#choose-game-main {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 320px;
  margin: 2rem auto 0 auto;
  align-items: center;
}

.game-choice-container {
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-card);
  padding: 0.75rem 1rem;
  border-radius: 0.4rem;
  font-size: 1rem;
}

.game-choice-container:hover {
  background-color: #353535; /* Keep a slightly lighter shade for hover, or define a var */
}

.game-choice-container img {
  width: 2.2rem;
  height: 2.2rem;

  margin-right: 1rem;
}

.game-choice-container h3 {
  flex: 1;
  font-size: 1.1rem;
  font-weight: bold;

  margin: 0;
  letter-spacing: 0.03em;
  text-align: left;
}

.game-choice-play-btn {

    background: var(--primary);
    color: var(--text-inverse);
    border: none;
    border-radius: 0.5rem;
    width: 2.5rem;
    height: 2rem;
    font-size: 1.3rem;
    padding: 0px 0px 2px 0px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;



}

/* ======== LEADERBOARD ======== */
#leaderboard-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  z-index: 2;
  color: var(--text-main);
  display: block;
  padding: 0.2em 0.6em;
}
#leaderboard-btn img {
  width: 1.8rem;
  height: 1.8rem;
  display: block;
}

#leaderboard-popup {
  display: none;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.75);
  align-items: center;
  justify-content: center;
}
#leaderboard-popup > div {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  background: var(--bg-popup);
  padding: 2rem;
  border-radius: 0.5rem;
  max-width: 90vw;
  min-width: 260px;
  position: relative;
  box-shadow: 0 4px 32px #000;
  max-height: 80vh;
  overflow-y: auto;
}
#leaderboard-popup h2 {
  text-align: center;
  margin-bottom: 0.5rem;
  font-size: 1.5rem;
  color: var(--text-main);
}
#close-leaderboard-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.7rem;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}
#leaderboard-list {
  list-style: none;
  padding: 0;
  width: 100%;
}
#leaderboard-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 1.1rem;
}
#leaderboard-list li:last-child {
  border-bottom: none;
}
#leaderboard-list li span:last-child {
  color: var(--warning);
  font-weight: bold;
  font-size: 1.4rem;
}

.leaderboard-score {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}
.leaderboard-icon {
  width: 1.4rem;
  height: auto;
  vertical-align: middle;
  margin-bottom: 0.2rem;
}

#reset-leaderboard-btn {
  background-color: #ecf0f1;
  color: #1a1a1a;
  border: none;
  font-weight: bold;
  padding: 0.8rem;
  border-radius: 0.5rem;
  width: 100%;
  margin-top: 1rem;
  font-size: 1.1rem;
  cursor: pointer;
}
#reset-leaderboard-btn:hover {
  background-color: #bdc3c7;
}
