:root {
  --bg: #10141c;
  --bg-alt: #171d2b;
  --text: #eef1f7;
  --text-dim: #9aa4b8;
  --accent: #4f8cff;
  --accent-hover: #6da0ff;
  --border: #2a3144;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden; /* pas de scroll, PC comme mobile */
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

input,
textarea {
  user-select: text;
  -webkit-user-select: text;
}

.app {
  height: 100dvh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.view {
  width: 100%;
  max-width: 26rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.view--hidden {
  display: none;
}

.logo {
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 700;
  margin: 0 0 0.5rem;
  letter-spacing: 0.02em;
}

.view-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}

.menu-btn {
  padding: 0.9rem 1.25rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.menu-btn:hover {
  border-color: var(--accent);
  background: #1b2333;
}

.menu-btn:active {
  transform: scale(0.98);
}

.menu-btn--secondary {
  color: var(--text-dim);
  font-weight: 500;
}

.back-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0.5rem;
}

.back-btn:hover {
  color: var(--text);
}

.account-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.account-form label {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.account-form input {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  color: var(--text);
}

.account-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.account-status {
  min-height: 1.2rem;
  font-size: 0.9rem;
  color: var(--text-dim);
  margin: 0;
}

.account-logged-in {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

/* ---------- Multijoueur : création / lobby ---------- */

.player-count-choice {
  display: flex;
  gap: 0.5rem;
}

.player-count-btn {
  flex: 1;
  padding: 0.6rem;
}

.player-count-btn--selected {
  border-color: var(--accent);
  background: #1b2333;
  color: var(--accent);
}

.lobby-code {
  font-size: 1.1rem;
  margin: 0;
}

.lobby-code strong {
  color: var(--accent);
  letter-spacing: 0.15em;
}

.lobby-players {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.lobby-players li {
  padding: 0.6rem 1rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  text-align: center;
}

.lobby-players__empty {
  color: var(--text-dim);
  font-style: italic;
}

.code-display {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.code-digit {
  width: 3rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  width: 100%;
}

.keypad-btn {
  padding: 0.9rem;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  cursor: pointer;
}

.keypad-btn:hover {
  border-color: var(--accent);
}

.keypad-btn:active {
  transform: scale(0.96);
}

.keypad-btn--action {
  color: var(--text-dim);
}

/* ---------- Plateau animé (V2) ---------- */

.skyjo-animation-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  perspective: 600px;
}

.card-ghost {
  position: absolute;
  transform-style: preserve-3d;
}

.card-ghost .card {
  width: 100%;
  height: 100%;
}

.grid {
  perspective: 600px;
}

.grid .card {
  transform-style: preserve-3d;
}

.fullscreen-btn {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.3rem;
  line-height: 1;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  color: var(--text);
  cursor: pointer;
}

.fullscreen-btn:hover {
  border-color: var(--accent);
}

.game-menu {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 10;
}

.game-menu-btn {
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.3rem;
  line-height: 1;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  color: var(--text);
  cursor: pointer;
}

.game-menu-btn:hover {
  border-color: var(--accent);
}

.game-menu-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  display: none;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 11rem;
  padding: 0.5rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}

.game-menu-dropdown--open {
  display: flex;
}

.game-menu-item {
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-size: 0.95rem;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
}

.game-menu-item:hover {
  background: #232b3d;
}

/* PC : layout un peu plus large, menu non étiré sur toute la hauteur */
@media (min-width: 768px) {
  .view:not(.view--game) {
    max-width: 22rem;
  }
}

/* ---------- Plateau de jeu ---------- */

.view--game {
  max-width: none;
  width: 100%;
  height: 100%;
  justify-content: space-between;
  gap: 0.5rem;
}

.board {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.board-opponents { order: 1; }
.board-center { order: 2; }
.board-self { order: 3; }

.board-opponents,
.board-self {
  display: flex;
  justify-content: center;
  min-height: 0;
}

.board-opponents {
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* Grilles adverses plus compactes dès qu'il y a plus d'un adversaire (3-4 joueurs), pour ne jamais
   provoquer de scroll même sur petit écran mobile. */
.board-opponents--multi .player-panel {
  padding: 0.3rem;
  gap: 0.2rem;
}

.board-opponents--multi .player-name {
  font-size: 0.7rem;
}

.board-opponents--multi .grid {
  grid-template-columns: repeat(4, minmax(1.3rem, 1.7rem));
  grid-template-rows: repeat(3, minmax(1.7rem, 2.2rem));
  gap: 0.15rem;
}

.board-opponents--multi .card {
  font-size: 0.75rem;
}

.player-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem;
  border-radius: 0.75rem;
  border: 1px solid transparent;
}

.player-panel--active {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.08);
}

.player-name {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(2.4rem, 3.4rem));
  grid-template-rows: repeat(3, minmax(3.2rem, 4.4rem));
  grid-auto-flow: column;
  gap: 0.3rem;
}

.card {
  border-radius: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  color: #10141c;
  user-select: none;
}

.card--facedown {
  background: #2a3144;
  border: 1px solid var(--border);
}

.card--removed {
  background: transparent;
  border: 1px dashed var(--border);
}

.card--faceup {
  background: #cfd8e3;
}

.card--neg { background: #7fb3ff; }
.card--zero { background: #8fe3d8; }
.card--low { background: #9fe08a; }
.card--mid { background: #f5d76e; }
.card--high { background: #f28b82; }

.card--clickable {
  cursor: pointer;
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.board-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  width: 11rem;
  height: 4.5rem;
  flex-shrink: 0;
  align-self: center;
}

.pile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.pile .card,
.pile .pile-label {
  width: 3rem;
  height: 4.2rem;
}

.pile-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 0.4rem;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  font-size: 0.7rem;
  text-align: center;
}

.pile--draw .pile-label {
  background: #2a3144;
  color: var(--text);
  border-style: solid;
}

.pile-count {
  font-size: 0.6rem;
  color: var(--text-dim);
}

.pile--clickable {
  cursor: pointer;
}

.pile--clickable .pile-label,
.pile--clickable .card {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.pending-card {
  width: 3rem;
  height: 4.2rem;
}

.pending-card .card {
  width: 3rem;
  height: 4.2rem;
}

/* V2 seulement : la carte piochée reste visuellement "tenue en main" (soulevée, ombre) tant que le
   joueur n'a pas décidé de la poser ou de la défausser. Valeurs synchronisées avec HOLD_LIFT_PX /
   HOLD_SCALE dans skyjo-board.js pour que le fantôme d'animation se fonde dans cet état sans à-coup. */
.board-animated .pending-card .card {
  transform: translateY(-6px) scale(1.03);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.35);
}

.board-status {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  text-align: center;
}

.game-status-text {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.game-status-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

@media (min-width: 768px) {
  .board {
    flex-direction: row;
    align-items: stretch;
  }

  .board-self { order: 1; }
  .board-center { order: 2; }
  .board-opponents { order: 3; }

  .board-self,
  .board-opponents {
    flex: 1;
    align-items: center;
  }
}
