:root {
  --card-width: 105px;
  --card-height: 150px;
  --primary-color: #2e7d32;
  --accent-color: #ffd700;
  --header-bg: #1b5e20;
  --sidebar-width: 250px; /* New variable for sidebar */
}

/* ---- RESET & BASE ---- */
body {
  margin: 0;
  background: var(--primary-color);
  font-family: "Segoe UI", system-ui, sans-serif;
  overflow-x: hidden;
}

/* ---- HEADER & CONTROLS ---- */
.game-header {
  background: var(--header-bg);
  padding: 15px 40px; /* Slightly taller to look better with sidebar */
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  position: relative;
  z-index: 600; /* Ensure header stays above everything */
}

.brand {
  font-size: 24px;
  font-weight: 800;
  color: white;
  letter-spacing: 1px;
}

.brand span {
  color: var(--accent-color);
}

.menu-controls {
  display: flex;
  gap: 30px;
  align-items: center;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group label {
  font-size: 10px;
  text-transform: uppercase;
  color: #a5d6a7;
  font-weight: bold;
}

select {
  background: #2e7d32;
  color: white;
  border: 1px solid #4caf50;
  padding: 6px 12px;
  border-radius: 4px;
  outline: none;
}

.btn-primary {
  background: var(--accent-color);
  color: #1b5e20;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}

.btn-primary:hover {
  transform: translateY(-2px);
  background: #ffea00;
}

/* ---- LEADERBOARD SIDEBAR (NEW) ---- */
#leaderboard-panel {
  position: fixed;
  left: 0;
  top: 75px; /* Aligns just below the header */
  bottom: 0;
  width: var(--sidebar-width);
  background: rgba(0, 0, 0, 0.3); /* Dark glass effect */
  backdrop-filter: blur(8px);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  padding: 20px;
  box-sizing: border-box;
  overflow-y: auto;
  z-index: 500;
  color: white;
  transition: transform 0.3s ease;
}

/* Leaderboard Content Styles */
.lb-title {
  font-size: 1.1rem;
  margin-bottom: 15px;
  border-bottom: 2px solid var(--accent-color);
  padding-bottom: 5px;
  color: white;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.lb-table th {
  text-align: left;
  color: #a5d6a7;
  font-weight: normal;
  padding-bottom: 8px;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.lb-table td {
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #e8f5e9;
}

.lb-rank {
  color: var(--accent-color);
  font-weight: bold;
  width: 25px;
}

.lb-name {
  display: inline-block;
  max-width: 100px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  font-weight: 600;
}

.lb-score {
  text-align: right;
  font-variant-numeric: tabular-nums;
  opacity: 0.9;
}

.refresh-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e8f5e9;
  padding: 8px;
  width: 100%;
  border-radius: 4px;
  margin-bottom: 15px;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 0.8rem;
}

.refresh-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

/* ---- LAYOUT DEL TAVOLO (UPDATED) ---- */
#game-board {
  max-width: 1000px;
  /* Push the board to the right to make room for sidebar */
  margin: 0 auto 0 calc(var(--sidebar-width) + 20px);
  padding: 20px;
  transition: margin-left 0.3s ease;
}

.top-row {
  display: flex;
  gap: 15px;
  margin-bottom: 40px;
  align-items: flex-start;
}

.stats {
  color: white;
  font-size: 0.9em;
  font-weight: 500;
}
.stats .stat-item {
  display: inline-block;
  margin-left: 15px;
}

.spacer {
  flex-grow: 1;
}

#tableau {
  display: flex;
  gap: 15px;
  justify-content: space-between;
}

/* ---- CONTENITORI (PILES & COLUMNS) ---- */
.pile,
.column {
  width: var(--card-width);
  min-height: var(--card-height);
  border-radius: 8px;
  position: relative;
  background: rgba(0, 0, 0, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.1);
}

.column {
  background: transparent;
  border: none;
}

/* ---- CARD RENDERING ---- */
.card {
  width: var(--card-width);
  height: var(--card-height);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  box-sizing: border-box;
  transition: transform 0.1s;
}

.pile .card {
  position: absolute;
  top: 0;
  left: 0;
}

.column .card {
  position: relative;
  margin-bottom: -120px;
}

.column .card:last-child {
  margin-bottom: 0;
}

.card.face-down {
  background: linear-gradient(135deg, #1a237e 25%, transparent 25%) -10px 0,
    linear-gradient(225deg, #1a237e 25%, transparent 25%) -10px 0,
    linear-gradient(315deg, #1a237e 25%, transparent 25%),
    linear-gradient(45deg, #1a237e 25%, transparent 25%);
  background-size: 20px 20px;
  background-color: #3f51b5;
  border: 3px solid white;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.card.face-up {
  background: white;
  border: 1px solid #999;
  overflow: hidden;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---- TRASCINAMENTO (DRAGGING) ---- */
.card.dragging {
  position: fixed !important;
  z-index: 9999 !important;
  margin: 0 !important;
  pointer-events: none;
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5);
}

/* ---- RESPONSIVE ---- */

/* Breakpoint 1: Hide Sidebar on smaller screens (Tablets/Phones) */
@media (max-width: 1000px) {
  #leaderboard-panel {
    transform: translateX(-100%); /* Slide it off-screen */
  }
  
  #game-board {
    margin: 0 auto; /* Center the board normally */
  }
}

/* Breakpoint 2: Resize cards (Existing Logic) */
@media (max-width: 850px) {
  :root {
    --card-width: 70px;
    --card-height: 100px;
  }
  .column .card {
    margin-bottom: -80px;
  }
  
  .game-header {
    flex-direction: column;
    gap: 15px;
  }
}