/* ============================================
   Pyramid Card Game — Mobile-First Styles
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');

/* --- Reset & Base --- */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #0f0e17;
  --bg-card: #1a1932;
  --bg-surface: #16213e;
  --border: #2a2a4a;
  --text-primary: #eee;
  --text-muted: #777;
  --accent: #3498db;
  --accent-hover: #2980b9;
  --success: #2ecc71;
  --success-hover: #27ae60;
  --danger: #e74c3c;
  --red: #e74c3c;
  --green: #2ecc71;
  --yellow: #f1c40f;
  --violet: #9b59b6;
  --blue: #3498db;
}

body {
  font-family: 'Inter', 'Segoe UI', sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 18%, rgba(31, 77, 151, 0.28) 0%, rgba(9, 18, 44, 0.16) 34%, transparent 62%),
    linear-gradient(145deg, #030713 0%, #071226 48%, #030713 100%);
  color: var(--text-primary);
  padding: 0.75rem;
  overflow-x: hidden;
}

#status {
  font-size: 0.75rem;
  color: var(--danger);
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  letter-spacing: 0.02em;
}

/* ============================================
   HOME SCREEN
   ============================================ */
#home-screen {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.05rem;
  width: min(100%, 520px);
  padding: 1rem 0;
  animation: fadeIn 0.4s ease;
  isolation: isolate;
}
.home-pyramid-logo {
  width: min(420px, 76vw);
  max-height: 34dvh;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 22px 34px rgba(0, 0, 0, 0.42));
  margin-bottom: -0.15rem;
}
#home-screen::before {
  content: "";
  position: absolute;
  top: 6%;
  left: 50%;
  width: min(380px, 72vw);
  aspect-ratio: 1;
  border: 2px solid rgba(77, 116, 190, 0.18);
  border-radius: 50%;
  transform: translateX(-50%);
  z-index: -1;
}
#home-screen h1 {
  color: #f4f6fb;
  font-size: clamp(3.2rem, 13vw, 5.25rem);
  font-weight: 800;
  line-height: 0.9;
  text-align: center;
  letter-spacing: 0;
  text-shadow: 0 6px 20px rgba(0, 0, 0, 0.38);
}
.subtitle {
  color: #aeb7c8;
  font-size: clamp(1.05rem, 3.2vw, 1.35rem);
  font-weight: 600;
  margin-top: -0.15rem;
}
.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
  width: min(100%, 410px);
  margin-top: 1.15rem;
}
#home-screen .btn-large {
  width: 100%;
  min-height: 68px;
  border-radius: 16px;
  font-size: clamp(1.25rem, 4vw, 1.65rem);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.16), 0 14px 28px rgba(0,0,0,0.26);
}
#home-screen .btn-green {
  background: linear-gradient(135deg, #82d976, #5fcf72);
}
#home-screen .btn:not(.btn-green) {
  background: linear-gradient(135deg, #78b8f3, #5393dd);
}
#home-screen .btn:hover {
  transform: translateY(-1px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.2), 0 18px 34px rgba(0,0,0,0.3);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.65rem 2rem;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  min-height: 44px;
}
.btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}
.btn:active { transform: translateY(0); }
.btn:disabled {
  background: #333;
  color: #666;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn-green { background: var(--success); }
.btn-green:hover { background: var(--success-hover); box-shadow: 0 4px 12px rgba(46, 204, 113, 0.3); }
.btn-green:disabled { background: #333; color: #666; }
.btn-red { background: var(--danger); font-size: 0.85rem; padding: 0.5rem 1.2rem; }
.btn-red:hover { background: #c0392b; box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3); }
.btn-large { font-size: 1.1rem; padding: 0.85rem 2rem; }
.btn-small { font-size: 0.8rem; padding: 0.4rem 1rem; border-radius: 8px; }
.btn-back {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.4rem 1rem;
}
.btn-back:hover { background: rgba(255,255,255,0.05); border-color: var(--text-muted); box-shadow: none; }

/* ============================================
   CREATE / JOIN SCREENS
   ============================================ */
#create-screen, #join-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  animation: fadeIn 0.4s ease;
}
#create-screen h2, #join-screen h2 {
  font-weight: 600;
  font-size: 1.4rem;
  background: linear-gradient(135deg, var(--accent), var(--success));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
#create-name-section, #join-code-section, #join-name-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}
#create-name-section label, #join-code-section label, #join-name-section label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

input[type="text"] {
  font-family: inherit;
  font-size: 1.1rem;
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  width: 260px;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

#join-code-input {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  width: 200px;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2rem;
}

/* ============================================
   LOBBY
   ============================================ */
#lobby {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  animation: fadeIn 0.4s ease;
}
#lobby h2 {
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--text-primary);
}

.room-id-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 1rem 2rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.room-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}
.room-code {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.room-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.copy-feedback {
  color: var(--success);
  font-size: 0.8rem;
  font-weight: 600;
}

.lobby-players {
  width: 280px;
}
.lobby-players h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
  text-align: center;
}

#player-list {
  list-style: none;
  width: 100%;
}
#player-list li {
  padding: 0.6rem 1rem;
  margin: 0.35rem 0;
  background: var(--bg-surface);
  border-radius: 10px;
  font-size: 1rem;
  text-align: center;
  border: 1px solid var(--border);
  animation: slideIn 0.3s ease;
}
#player-list li.you {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(52, 152, 219, 0.08);
}
#player-list li.disconnected {
  opacity: 0.5;
  border-color: var(--danger);
}

.hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

/* --- AI Controls (Solo Mode) --- */
.ai-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 260px;
  margin: 0.5rem 0;
}

.ai-difficulty-select {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  width: 100%;
  padding: 0.75rem 2.5rem 0.75rem 1.25rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='%23777'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 12px;
}
.ai-difficulty-select:hover {
  border-color: var(--text-muted);
}
.ai-difficulty-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}
.ai-difficulty-select option {
  background: var(--bg-surface);
  color: var(--text-primary);
  padding: 0.5rem;
}

/* ============================================
   GAME SCREEN
   ============================================ */
#game-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 600px;
  gap: 0.6rem;
  animation: fadeIn 0.4s ease;
  padding-bottom: 1rem;
}

#game-header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}
#round-info { color: var(--text-muted); }
#room-tag { color: var(--text-muted); font-size: 0.75rem; }
#my-chips { color: var(--danger); }

#scoreboard {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  width: 100%;
}
.scoreboard-player {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  transition: border-color 0.3s, opacity 0.3s;
}
.scoreboard-player.active-turn {
  border-color: var(--success);
  background: rgba(46, 204, 113, 0.05);
}
.scoreboard-player.dropped { opacity: 0.4; }
.scoreboard-player.offline { opacity: 0.35; border-style: dashed; }
.scoreboard-player .name { font-weight: 600; }
.scoreboard-player .rank-small { color: var(--text-muted); font-size: 0.7rem; font-weight: 700; }
.scoreboard-player .cards { color: var(--accent); }
.scoreboard-player .chips { color: var(--danger); }
.chip-delta { color: var(--text-muted); font-size: 0.85em; }

#turn-info {
  font-size: 1rem;
  font-weight: 600;
  padding: 0.5rem 1.2rem;
  border-radius: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  transition: all 0.3s ease;
}
#turn-info.your-turn {
  border-color: var(--success);
  color: var(--success);
  background: rgba(46, 204, 113, 0.08);
  animation: pulse 2s ease-in-out infinite;
}

/* ============================================
   PYRAMID
   ============================================ */
#pyramid-container {
  width: 100%;
  overflow-x: auto;
  padding: 0.5rem 0;
}
#pyramid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: fit-content;
}
.pyramid-tier {
  display: flex;
  gap: 3px;
  justify-content: center;
}

.pyramid-slot {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: all 0.2s ease;
  user-select: none;
  overflow: hidden;
}

.pyramid-slot.empty {
  border: 2px dashed rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.02);
}

.pyramid-slot.valid {
  border: 2px solid var(--success);
  background: rgba(46, 204, 113, 0.12);
  cursor: pointer;
  animation: slotPulse 1.5s ease-in-out infinite;
}
.pyramid-slot.valid:hover {
  background: rgba(46, 204, 113, 0.25);
  transform: scale(1.1);
}

.pyramid-slot.filled {
  /* border: 1px solid rgba(255,255,255,0.15); */
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  background: transparent;
}
.pyramid-slot.filled.post-loss {
  opacity: 0.45;
}

.slot-emoji {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

#instruction {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  min-height: 1.2rem;
  font-style: italic;
}

#hand-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
#hand-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
#hand-count {
  font-weight: 700;
  color: var(--accent);
}
#hand {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  width: 100%;
  padding: 0.2rem 0;
}

.card {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  border: 2px solid rgba(255,255,255,0.15);
  cursor: default;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  user-select: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  overflow: hidden;
  background: transparent;
}
.card.selectable { cursor: pointer; }
.card.selectable:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}
.card.selected {
  transform: translateY(-8px) scale(1.05);
  border-color: #fff;
  box-shadow: 0 0 16px rgba(255,255,255,0.4), 0 6px 20px rgba(0,0,0,0.3);
}

.card-emoji {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

#action-buttons {
  display: flex;
  gap: 0.75rem;
}

/* ============================================
   HOW TO PLAY BUTTON (home screen)
   ============================================ */
.btn-how-to-play {
  font-family: inherit;
  font-size: clamp(1.05rem, 3.5vw, 1.35rem);
  font-weight: 800;
  color: #f2f4fa;
  background: rgba(4, 12, 28, 0.2);
  border: 2px solid rgba(118, 141, 178, 0.52);
  border-radius: 16px;
  width: min(100%, 410px);
  min-height: 68px;
  padding: 0.75rem 1.6rem;
  cursor: pointer;
  transition: border-color 0.25s ease, background 0.25s ease, transform 0.1s ease;
  letter-spacing: 0;
  margin-top: 0.35rem;
}
.btn-how-to-play:hover {
  color: var(--text-primary);
  border-color: rgba(155, 181, 222, 0.78);
  background: rgba(86, 123, 183, 0.08);
  transform: translateY(-1px);
}
.powered-by {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas:
    "line-left label line-right"
    ". logo .";
  align-items: center;
  gap: 0.55rem 1rem;
  width: min(100%, 410px);
  margin-top: 1.25rem;
  color: #6f7d97;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}
.powered-by::before,
.powered-by::after {
  content: "";
  height: 2px;
  background: rgba(98, 118, 153, 0.45);
}
.powered-by::before {
  grid-area: line-left;
}
.powered-by::after {
  grid-area: line-right;
}
.powered-by span {
  grid-area: label;
  white-space: nowrap;
}
.powered-by img {
  grid-area: logo;
  width: 78px;
  max-width: 22vw;
  height: auto;
  display: block;
  justify-self: center;
  opacity: 0.9;
}

/* ============================================
   INSTRUCTIONS SCREEN
   ============================================ */
#instructions-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.35s ease;
  width: 100%;
  max-width: 420px;
}

.instructions-container {
  position: relative;
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.8rem 1.4rem 1.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.instructions-close {
  position: absolute;
  top: 0.75rem;
  right: 0.9rem;
  font-size: 1.1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  transition: color 0.2s, transform 0.2s;
  z-index: 5;
}
.instructions-close:hover {
  color: var(--text-primary);
  transform: scale(1.15);
}

/* --- Slides Wrapper --- */
.instructions-slides {
  width: 100%;
  position: relative;
  min-height: 340px;
}

.instructions-slide {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  animation: slideFadeIn 0.35s ease;
  width: 100%;
}
.instructions-slide.active {
  display: flex;
}

@keyframes slideFadeIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* --- Slide Header --- */
.slide-icon {
  font-size: 2.4rem;
  line-height: 1;
  margin-bottom: -0.2rem;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.3));
}

.slide-title {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  margin-bottom: 0.2rem;
}

/* --- Info Tiles --- */
.slide-tiles {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: 100%;
}

.info-tile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  transition: background 0.2s, border-color 0.2s;
}
.info-tile:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
}

.tile-emoji {
  font-size: 1.5rem;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.2));
}

.tile-text {
  font-size: 0.88rem;
  color: var(--text-primary);
  line-height: 1.4;
}
.tile-text strong {
  color: #fff;
  font-weight: 700;
}

/* --- Step Tiles --- */
.tile-step-num {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

/* --- Mini Pyramid Diagram --- */
.slide-diagram {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.3rem;
}

.mini-pyramid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.mini-row {
  display: flex;
  gap: 3px;
}

.mini-slot {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15);
  overflow: hidden;
}
.mini-slot.placed[data-color="green"] {
  background: transparent;
}
.mini-slot.placed[data-color="red"] {
  background: transparent;
}
.mini-emoji {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}

.diagram-caption {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

/* --- Slide Note --- */
.slide-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 0.4rem 0.6rem;
  background: rgba(52, 152, 219, 0.06);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

/* --- Got it! Button --- */
.instructions-done {
  margin-top: 0.5rem;
  width: 100%;
}

/* --- Navigation --- */
.instructions-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.2rem;
}

.instructions-arrow {
  font-size: 1.6rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1;
  padding: 0;
}
.instructions-arrow:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(52, 152, 219, 0.1);
  color: var(--accent);
}
.instructions-arrow:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

.instructions-dots {
  display: flex;
  gap: 8px;
  align-items: center;
}
.instructions-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: all 0.25s ease;
}
.instructions-dots .dot.active {
  background: var(--accent);
  width: 22px;
  border-radius: 4px;
  box-shadow: 0 0 8px rgba(52, 152, 219, 0.4);
}
.instructions-dots .dot:hover:not(.active) {
  background: rgba(255, 255, 255, 0.3);
}

/* ============================================
   OVERLAY
   ============================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.3s ease;
}
.overlay.hidden { display: none; }

.overlay-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  max-width: 360px;
  width: 90%;
  text-align: center;
  animation: fadeIn 0.4s ease;
}
.overlay-content h2 {
  font-size: 1.4rem;
  margin-bottom: 1.2rem;
  background: linear-gradient(135deg, var(--accent), var(--success));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.scores-table {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.score-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  font-size: 0.95rem;
}
.score-row .rank {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 800;
  width: 32px;
  text-align: center;
}
.score-row .name { flex: 1; text-align: left; font-weight: 600; }
.score-row .chips { color: var(--danger); font-weight: 700; }
.overlay-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
}
.overlay-actions .btn {
  flex: 1 1 0;
  min-width: 0;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

.overlay-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  font-style: italic;
}

/* ============================================
   RECONNECTING BANNER
   ============================================ */
.reconnecting-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(231, 76, 60, 0.95);
  color: #fff;
  text-align: center;
  padding: 0.6rem;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  backdrop-filter: blur(4px);
}
.reconnecting-banner.hidden { display: none; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============================================
   LOBBY SETTINGS (Time Escalation toggle)
   ============================================ */
.lobby-setting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  width: 260px;
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.toggle-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  cursor: pointer;
  user-select: none;
}

.toggle-label.disabled {
  cursor: default;
  opacity: 0.7;
}

.toggle-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  transition: background 0.3s ease;
  cursor: pointer;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--text-primary);
  border-radius: 50%;
  transition: transform 0.3s ease;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--success);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-switch input:disabled + .toggle-slider {
  cursor: not-allowed;
  opacity: 0.5;
}

.setting-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
}

.setting-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  user-select: none;
}

.rounds-select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: border-color 0.25s ease, background 0.25s ease;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%239ba5b4' d='M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.rounds-select:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
}

.rounds-select:focus:not(:disabled) {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.rounds-select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.rounds-select option {
  background: var(--bg-surface);
  color: var(--text-primary);
  padding: 0.5rem;
}

.lobby-setting.disabled {
  opacity: 0.7;
}

/* ============================================
   TURN TIMER BAR
   ============================================ */
.turn-timer-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

.turn-timer-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.1s linear;
  background: var(--success);
}

.turn-timer-fill.timer-warn {
  background: var(--yellow);
}

.turn-timer-fill.timer-danger {
  background: var(--danger);
  animation: timerUrgent 0.5s ease-in-out infinite;
}

.turn-timer-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.turn-timer-info .timer-seconds {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.turn-timer-info .timer-seconds.timer-text-danger {
  color: var(--danger);
}

.turn-timer-info .timer-max-label {
  font-size: 0.65rem;
  opacity: 0.7;
}

.turn-timer-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.timeout-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(231, 76, 60, 0.95);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  z-index: 150;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 1.7s forwards;
  pointer-events: none;
  text-align: center;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
  50%      { box-shadow: 0 0 0 6px rgba(46, 204, 113, 0.15); }
}

@keyframes slotPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
  50%      { box-shadow: 0 0 0 4px rgba(46, 204, 113, 0.25); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes timerUrgent {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to   { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 420px) {
  body { padding: 0.4rem; }
  #home-screen {
    width: min(100%, 360px);
    gap: 0.85rem;
  }
  #home-screen::before {
    top: 7%;
    width: min(300px, 76vw);
  }
  .home-pyramid-logo {
    width: min(320px, 84vw);
    max-height: 27dvh;
  }
  .home-buttons,
  .btn-how-to-play,
  .powered-by {
    width: min(100%, 320px);
  }
  #home-screen .btn-large,
  .btn-how-to-play {
    min-height: 58px;
    border-radius: 14px;
  }
  .pyramid-slot {
    width: 34px;
    height: 34px;
    border-radius: 6px;
  }
  .pyramid-tier { gap: 2px; }
  #pyramid { gap: 2px; }
  .card {
    width: 48px;
    height: 48px;
    border-radius: 8px;
  }
  #hand { gap: 4px; }
  .btn { padding: 0.5rem 1.2rem; font-size: 0.9rem; }
  .scoreboard-player { font-size: 0.7rem; padding: 0.3rem 0.5rem; }
  #home-screen h1 { font-size: 2.2rem; }
  .powered-by img { width: 68px; }
  .room-code { font-size: 1.8rem; }
  #join-code-input { font-size: 1.4rem; }
  .instructions-container { padding: 1.4rem 1rem 1rem; }
  .instructions-slides { min-height: 310px; }
  .slide-icon { font-size: 2rem; }
  .slide-title { font-size: 1.1rem; }
  .tile-text { font-size: 0.82rem; }
  .info-tile { padding: 0.55rem 0.7rem; gap: 0.6rem; }
  .tile-emoji { font-size: 1.3rem; width: 30px; }
  .lobby-setting { width: 100%; }
  .turn-timer-bar { height: 6px; }
}

@media (max-height: 800px) {
  #home-screen {
    gap: 0.72rem;
    padding: 0.5rem 0;
  }
  #home-screen::before {
    top: 5%;
    width: min(350px, 64vw);
  }
  .home-pyramid-logo {
    width: min(430px, 76vw);
    max-height: 30dvh;
  }
  #home-screen h1 {
    font-size: clamp(3rem, 11vw, 4.4rem);
  }
  .subtitle {
    font-size: clamp(0.95rem, 2.7vw, 1.1rem);
  }
  .home-buttons {
    gap: 0.7rem;
    margin-top: 0.6rem;
  }
  #home-screen .btn-large,
  .btn-how-to-play {
    min-height: 58px;
    border-radius: 14px;
    font-size: clamp(1.05rem, 3.2vw, 1.3rem);
  }
  .btn-how-to-play {
    margin-top: 0.15rem;
  }
  .powered-by {
    gap: 0.35rem 0.8rem;
    margin-top: 0.65rem;
    font-size: 0.72rem;
  }
  .powered-by img {
    width: 58px;
  }
}
