/* Matchy Matchy — styles */
:root {
  --bg: #0f0c1d;
  --bg-2: #1a1530;
  --card: #221a3a;
  --card-2: #2a2148;
  --text: #f5f1ff;
  --muted: #9a90b8;
  --accent: #ff7a3d; /* orange */
  --accent-2: #b14dff; /* violet */
  --accent-3: #4dffaf; /* vert fluo */
  --p1: #4dd1ff; /* cyan */
  --p2: #ff5cb1; /* rose */
  --danger: #ff4f6d;
  --success: #4dffaf;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(ellipse at top, #2a1f4a 0%, var(--bg) 60%);
  color: var(--text);
  font-family: "Nunito", system-ui, -apple-system, Segoe UI, sans-serif;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1,
h2,
h3 {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  margin: 0;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

/* ---------- Lobby ---------- */
.lobby .hero {
  text-align: center;
  margin: 32px 0 28px;
}
.title {
  font-size: clamp(44px, 9vw, 72px);
  line-height: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: -1px;
}
.title span {
  background: linear-gradient(135deg, var(--accent-3), var(--p1));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 17px;
}
.tagline strong {
  color: var(--accent-3);
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.card.centered {
  text-align: center;
}
.card.centered h2 {
  font-size: 26px;
  margin-bottom: 8px;
}
.card.centered p {
  color: var(--muted);
  margin: 8px 0;
}

.field {
  display: block;
  margin-bottom: 14px;
}
.field span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
  font-weight: 700;
}
.field input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--bg-2);
  border: 2px solid transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  text-transform: none;
  outline: none;
  transition: border-color 0.2s, transform 0.2s;
}
.field input:focus {
  border-color: var(--accent-2);
}
.field input.shake {
  animation: shake 0.4s;
  border-color: var(--danger);
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.btn {
  display: block;
  width: 100%;
  padding: 16px 20px;
  border-radius: 12px;
  border: none;
  font-family: "Fredoka", sans-serif;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: transform 0.15s, box-shadow 0.2s, filter 0.2s;
  margin-top: 8px;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 8px 22px rgba(177, 77, 255, 0.35);
}
.btn-primary:hover {
  filter: brightness(1.1);
}
.btn-secondary {
  background: var(--card-2);
  color: var(--text);
  border: 2px solid rgba(255, 255, 255, 0.08);
}
.btn-secondary:hover {
  border-color: var(--accent-3);
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.separator {
  text-align: center;
  margin: 18px 0 14px;
  position: relative;
  color: var(--muted);
  font-size: 13px;
}
.separator::before,
.separator::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
}
.separator::before { left: 0; }
.separator::after { right: 0; }

.footnote {
  text-align: center;
  margin-top: 24px;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Game ---------- */
.game-container {
  padding: 12px 12px 80px;
  max-width: 800px;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  align-items: center;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.player.right {
  justify-content: flex-end;
}
.player .name {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}
.player .score {
  font-family: "Fredoka", sans-serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--accent-3);
  min-width: 30px;
  text-align: center;
}
.player.is-me .name::after {
  content: " (toi)";
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
}
.player.has-voted .dot {
  box-shadow: 0 0 0 4px rgba(77, 255, 175, 0.3);
}
.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: box-shadow 0.3s;
}
.dot-1 { background: var(--p1); }
.dot-2 { background: var(--p2); }

.middle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.round-indicator {
  font-family: "Fredoka", sans-serif;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

/* Screen */
.screen {
  animation: fadein 0.3s;
}
@keyframes fadein {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Waiting */
.room-code {
  font-family: "Fredoka", sans-serif;
  font-size: 52px;
  font-weight: 700;
  letter-spacing: 8px;
  background: linear-gradient(135deg, var(--accent-3), var(--p1));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 18px 0;
  user-select: all;
}
.hint {
  color: var(--muted);
  font-size: 13px;
  margin-top: 10px;
}
.share-link {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-2);
  border: 2px solid var(--accent-2);
  color: var(--text);
  font-family: monospace;
  font-size: 13px;
  text-align: center;
  user-select: all;
  -webkit-user-select: all;
}

/* Theme bar */
.theme-bar {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: var(--radius);
  padding: 14px 18px;
  text-align: center;
  margin-bottom: 14px;
  box-shadow: 0 8px 22px rgba(255, 122, 61, 0.25);
}
.theme-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 700;
}
.theme-text {
  font-size: clamp(22px, 5vw, 32px);
  margin-top: 2px;
  color: #fff;
}

/* Grille */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 3px solid transparent;
  background-color: #000;
  background-size: cover;
  background-position: center;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s, border-color 0.2s, opacity 0.3s, filter 0.3s;
}
.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 60%, rgba(0, 0, 0, 0.5));
  pointer-events: none;
}
.tile:hover {
  transform: scale(1.04);
  border-color: var(--accent-3);
  z-index: 2;
}
.tile.selected {
  border-color: var(--p1);
  box-shadow: 0 0 0 4px rgba(77, 209, 255, 0.3), 0 6px 16px rgba(0, 0, 0, 0.5);
  transform: scale(1.04);
}
.tile.selected .tile-icon::before {
  content: "✓";
  position: absolute;
  top: 6px;
  right: 8px;
  background: var(--p1);
  color: #000;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.tile.dimmed {
  opacity: 0.5;
  filter: grayscale(0.4);
}
.tile.faded {
  opacity: 0.25;
  filter: grayscale(0.7);
}

/* Révélation */
.tile.match {
  border-color: var(--success);
  box-shadow: 0 0 0 6px rgba(77, 255, 175, 0.4), 0 0 30px rgba(77, 255, 175, 0.6);
  animation: pop 0.5s ease-out;
}
.tile.vote-1 {
  border-color: var(--p1);
  box-shadow: 0 0 0 4px rgba(77, 209, 255, 0.4);
}
.tile.vote-2 {
  border-color: var(--p2);
  box-shadow: 0 0 0 4px rgba(255, 92, 177, 0.4);
}
.tile-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
  z-index: 3;
  pointer-events: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}
.tile-label {
  position: absolute;
  bottom: 6px;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 3;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1.04); }
}

.status-line {
  text-align: center;
  font-family: "Fredoka", sans-serif;
  font-size: 18px;
  color: var(--muted);
  padding: 12px;
  border-radius: 12px;
  background: var(--card);
  margin-bottom: 10px;
}
.status-line.match {
  color: var(--success);
  background: rgba(77, 255, 175, 0.12);
  font-size: 22px;
}
.status-line.miss {
  color: var(--danger);
  background: rgba(255, 79, 109, 0.12);
}

/* Flash quand match */
body.flash-match::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(circle, rgba(77, 255, 175, 0.3), transparent 70%);
  pointer-events: none;
  z-index: 999;
  animation: flash 0.6s ease-out;
}
@keyframes flash {
  0% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 0; }
}

/* End screen */
.final-scores {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  margin: 24px 0;
}
.final-score {
  background: var(--bg-2);
  border-radius: 12px;
  padding: 18px 12px;
  border: 2px solid transparent;
}
.final-score.me {
  border-color: var(--accent-3);
}
.fs-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fs-pts {
  font-family: "Fredoka", sans-serif;
  font-size: 44px;
  font-weight: 700;
  color: var(--accent-3);
  line-height: 1;
}
.fs-pts small {
  font-size: 14px;
  color: var(--muted);
}
.vs {
  color: var(--muted);
  font-size: 22px;
  font-family: "Fredoka", sans-serif;
}

.history {
  margin-top: 18px;
  text-align: left;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
}
.hist-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 10px;
  margin-bottom: 6px;
  background: var(--bg-2);
  border-left: 4px solid var(--danger);
}
.hist-row.match {
  border-left-color: var(--success);
}
.hist-index {
  font-family: "Fredoka", sans-serif;
  font-size: 12px;
  color: var(--muted);
}
.hist-theme {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hist-imgs {
  display: flex;
  align-items: center;
  gap: 4px;
}
.hist-imgs img {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
}
.hist-eq {
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  padding: 0 4px;
}
.hist-empty {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  color: var(--muted);
}

.end-buttons {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.end-buttons .btn {
  flex: 1;
  margin-top: 0;
  min-width: 160px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card-2);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 700;
  box-shadow: var(--shadow);
  border: 1px solid var(--accent);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 1000;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Mobile tweaks */
@media (max-width: 480px) {
  .container {
    padding: 16px 12px 60px;
  }
  .grid {
    gap: 6px;
  }
  .tile {
    border-width: 2px;
    border-radius: 10px;
  }
  .tile-icon {
    font-size: 36px;
  }
  .tile-label {
    font-size: 11px;
  }
  .player .name {
    max-width: 80px;
    font-size: 13px;
  }
  .player .score {
    font-size: 22px;
  }
  .room-code {
    font-size: 40px;
    letter-spacing: 6px;
  }
}
