/* ===== RESET & ROOT ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

:root {
  --bg:         #09090E;
  --surface:    #11111C;
  --surface-el: #191926;
  --border:     rgba(255, 255, 255, 0.06);
  --border-hi:  rgba(255, 255, 255, 0.12);
  --text:       #EEEEFF;
  --text-sec:   #6666A0;
  --accent:     #5C6EFF;
  --danger:     #FF3D6E;

  --piece-I: #00D8FF;
  --piece-J: #5C6EFF;
  --piece-L: #FF7A35;
  --piece-O: #FFCD00;
  --piece-S: #00E676;
  --piece-T: #CB61FF;
  --piece-Z: #FF3D6E;
  --piece-G: #2E2E4A;
}

body {
  font-family: 'Space Grotesk', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== TOPBAR ===== */
.topbar {
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
}

.topbar__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  margin-left: auto;
}

/* ===== LOGO ===== */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.logo__grid {
  display: grid;
  grid-template-columns: repeat(3, 8px);
  grid-template-rows: repeat(3, 8px);
  gap: 2px;
}

.logo__grid i {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  font-style: normal;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.btn:hover {
  opacity: 0.85;
}

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

.btn--accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn--outline {
  background: transparent;
  border-color: var(--border-hi);
  color: var(--text);
}

.btn--danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn--sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* ===== CARD ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
}

.card h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}

/* ===== FIELD ===== */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field > label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-sec);
  text-transform: uppercase;
}

.field input,
.field select {
  background: var(--surface-el);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.field input:focus,
.field select:focus {
  border-color: var(--border-hi);
}

.field input::placeholder {
  color: var(--text-sec);
}

.field ul {
  list-style: none;
  color: var(--danger);
  font-size: 12px;
  margin-top: 2px;
}

/* ===== TAGS ===== */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: var(--surface-el);
  color: var(--text-sec);
}

.tag--accent {
  background: rgba(92, 110, 255, 0.15);
  color: var(--accent);
}

.tag--ready {
  background: rgba(0, 230, 118, 0.15);
  color: #00E676;
}

/* ===== SR-ONLY ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ===== TETRIS GRID ===== */
.tetris-grid {
  display: grid;
  grid-template-columns: repeat(10, var(--cell-size, 30px));
  grid-template-rows: repeat(20, var(--cell-size, 30px));
  background: #08080F;
  border: 2px solid rgba(255, 255, 255, 0.07);
}

.tetris-grid .cell {
  width: var(--cell-size, 30px);
  height: var(--cell-size, 30px);
  box-sizing: border-box;
}

.tetris-grid .cell.empty {
  background: rgba(255, 255, 255, 0.012);
  border-right: 1px solid rgba(255, 255, 255, 0.025);
  border-bottom: 1px solid rgba(255, 255, 255, 0.025);
}

.tetris-grid .cell.filled {
  box-shadow: inset 3px 3px 0 rgba(255, 255, 255, 0.30),
              inset -2px -2px 0 rgba(0, 0, 0, 0.25);
}

.tetris-grid .cell.ghost {
  border: 1px solid;
}

.tetris-grid .cell.garbage {
  background: var(--piece-G);
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.05),
              inset -1px -1px 0 rgba(0, 0, 0, 0.30);
}

/* ===== MINI GRID ===== */
.mini-grid {
  --cell-size: 7px;
  display: grid;
  grid-template-columns: repeat(10, 7px);
  grid-template-rows: repeat(20, 7px);
  background: #08080F;
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.mini-grid--eliminated {
  filter: grayscale(1);
  opacity: 0.35;
}

/* ===== NEXT PIECE PREVIEW ===== */
.next-piece-preview {
  --cell-size: 18px;
  display: grid;
  grid-template-columns: repeat(4, 18px);
  grid-template-rows: repeat(4, 18px);
}

/* ===== GAME SCREEN ===== */
.topbar__room {
  margin-left: 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sec);
}

.game-layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 32px;
  padding: 24px;
  min-height: calc(100vh - 52px);
}

.game-sidebar {
  width: 160px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.game-sidebar--right {
  width: fit-content;
}

.game-board {
  /* La grille fait 300×600px (10×20 × 30px) */
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-sec);
  text-transform: uppercase;
}

.sidebar-divider {
  border: none;
  border-top: 1px solid var(--border);
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-sec);
  text-transform: uppercase;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-value--accent { color: var(--accent); }

.controls-table {
  border-collapse: collapse;
  font-size: 11px;
  color: var(--text-sec);
  width: 100%;
}

.controls-table td { padding: 3px 0; }

kbd {
  display: inline-block;
  background: var(--surface-el);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: monospace;
  font-size: 10px;
  color: var(--text);
}

.opponent-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: fit-content;
}

.opponent-name {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-sec);
}

.mini-grid {
  position: relative;
}

.eliminated-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-sec);
}

/* ===== RESULTS SCREEN ===== */
.results-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 52px);
  gap: 32px;
}

.results-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.results-trophy { font-size: 48px; }

.results-title {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: -0.05em;
}

.results-subtitle {
  font-size: 13px;
  color: var(--text-sec);
}

.results-leaderboard {
  width: 560px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.result-row--winner {
  background: rgba(92, 110, 255, 0.14);
  border-color: rgba(92, 110, 255, 0.40);
}

.result-row--me {
  border-color: var(--border-hi);
}

.result-medal {
  font-size: 20px;
  width: 28px;
  text-align: center;
}

.result-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.result-name {
  flex: 1;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-stats {
  display: flex;
  gap: 24px;
}

.result-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.result-stat .stat-value {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.results-actions {
  display: flex;
  gap: 12px;
}

/* ===== HOME PAGE ===== */
.home-content {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 52px);
  padding: 40px 24px;
}

.home-cards {
  display: flex;
  align-items: stretch;
  gap: 0;
}

.or-divider {
  display: flex;
  align-items: center;
  padding: 0 24px;
  color: var(--text-sec);
  font-size: 12px;
  font-weight: 600;
}

.player-selector {
  display: flex;
  gap: 8px;
}

.player-selector button {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
}

.player-selector button.active {
  background: var(--accent);
  border-color: var(--accent);
}

.home-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
  color: var(--text-sec);
  font-size: 12px;
}

.piece-colors {
  display: flex;
  gap: 4px;
}

.piece-colors span {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: block;
}

/* ===== LOBBY PAGE ===== */
.lobby-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 52px);
  gap: 24px;
  padding: 40px 24px;
}

.lobby-badge {
  display: flex;
}

.lobby-title {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.lobby-url {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-el);
  border-radius: 6px;
  padding: 6px 14px;
}

.lobby-url code {
  font-family: monospace;
  color: var(--text-sec);
  font-size: 13px;
}

.players-grid {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.player-card {
  width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.player-card--empty {
  opacity: 0.3;
}

.player-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}

.player-name {
  font-size: 14px;
  font-weight: 600;
}

.player-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

.player-slot-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px dashed var(--border-hi);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--text-sec);
}

.player-slot-label {
  font-size: 12px;
  color: var(--text-sec);
}

.lobby-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-sec);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #00E676;
  flex-shrink: 0;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.85); }
}

.lobby-actions {
  display: flex;
  gap: 12px;
}

/* ===== DEBUG PANEL ===== */
.debug-panel {
  margin-top: 16px;
  padding: 12px;
  border: 1px dashed var(--danger);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.debug-panel__title {
  font-size: 10px;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--danger);
}

.debug-panel__group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.debug-panel__label {
  font-size: 10px;
  color: var(--text-sec);
  letter-spacing: 0.08em;
}

.debug-btn {
  width: 100%;
  padding: 6px 10px;
  font-size: 11px;
  font-family: inherit;
  background: var(--surface-el);
  color: var(--text);
  border: 1px solid var(--border-hi);
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 0.1s;
}

.debug-btn:hover {
  background: rgba(255, 61, 110, 0.15);
  border-color: var(--danger);
}

.debug-btn--secondary:hover {
  background: var(--surface-el);
  border-color: var(--border-hi);
  color: var(--text-sec);
}

.lobby-hint {
  font-size: 12px;
  color: var(--text-sec);
}

.recent-room-link {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: var(--surface-el);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
  min-width: 140px;
}

.recent-room-link:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.recent-room-name {
  font-size: 13px;
  font-weight: 700;
}

.recent-room-meta {
  font-size: 11px;
  color: var(--text-sec);
  margin-top: 2px;
}
