:root {
  --bg-gradient: linear-gradient(135deg, #1a1c2c 0%, #4a192c 100%);
  --card-bg: rgba(255, 255, 255, 0.1);
  --card-border: rgba(255, 255, 255, 0.2);
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;

  /* Rummikub Colors */
  --color-red: #ff4757;
  --color-black: #2f3542;
  --color-blue: #1e90ff;
  --color-orange: #ffa502;

  --primary-action: #2ed573;
  --danger-action: #ff4757;

  --font-main: "Outfit", sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none; /* Prevent selection for app-like feel */
}

body {
  background: var(--bg-gradient);
  color: var(--text-primary);
  font-family: var(--font-main);
  height: 100dvh; /* Use dynamic viewport height for mobile */
  /* overflow: hidden; Removed to allow scroll if needed, though we control it per screen */
}

.app-container {
  max-width: 500px;
  margin: 0 auto;
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1rem; /* Reduce padding for mobile */
  transition: opacity 0.3s ease, transform 0.3s ease;
  height: 100%;
  overflow-y: auto; /* Allow scrolling within the screen */
}

.hidden {
  display: none !important;
  opacity: 0;
  pointer-events: none;
}

/* --- Setup Screen --- */
.logo-header {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 3rem;
  margin-top: 2rem;
}

.tile {
  width: 40px;
  height: 50px;
  background: #f1f2f6;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.5rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  position: relative;
}

.tile::after {
  content: "";
  position: absolute;
  bottom: 5px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  opacity: 0.1;
  background: currentColor;
}

.tile-red {
  color: var(--color-red);
}
.tile-blue {
  color: var(--color-blue);
}
.tile-black {
  color: var(--color-black);
}
.tile-orange {
  color: var(--color-orange);
}

.card {
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

h2,
h3 {
  text-align: center;
  font-weight: 600;
}

.control-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.player-count-selector {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 4px;
}

.count-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 10px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.count-btn.active {
  background: var(--color-blue);
  color: white;
  box-shadow: 0 2px 8px rgba(30, 144, 255, 0.4);
}

.player-inputs {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.player-input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  padding: 12px;
  border-radius: 8px;
  color: white;
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.player-input:focus {
  border-color: var(--color-blue);
  background: rgba(255, 255, 255, 0.1);
}

.btn-primary {
  background: var(--primary-action);
  color: #1a1c2c;
  border: none;
  padding: 16px;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, filter 0.2s;
  width: 100%;
  margin-top: auto;
}

.btn-primary:active {
  transform: scale(0.98);
}

/* --- Game Screen --- */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  font-size: 1.2rem;
}

.round-indicator {
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.active-player-area {
  text-align: center;
  margin-bottom: 2rem;
}

.current-player-label {
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

#active-player-name {
  font-size: 2.5rem;
  font-weight: 800;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.timer-container {
  /* No flex: 1, make it sit at bottom of available space */
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 1rem;
  margin-top: auto; /* Push to bottom */
}

.timer-ring {
  position: relative;
  width: 280px;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-ring__circle {
  transition: stroke-dashoffset 0.1s linear, stroke 0.3s;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  stroke: var(--primary-action);
}

.timer-text {
  position: absolute;
  font-size: 5rem;
  font-weight: 300;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

.game-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem; /* Add separation from timer */
  flex: 0 0 auto; /* Don't shrink */
}

.btn-large {
  font-size: 1.8rem; /* Much bigger */
  padding: 30px; /* Much bigger */
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.main-action-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.btn-action-square {
  flex: 1;
  aspect-ratio: 1 / 1; /* Perfect square */
  max-height: 150px;
  font-size: 1.5rem;
  font-weight: 700;
  text-transform: uppercase;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.3;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.btn-action-square.btn-primary {
  background: var(--primary-action);
  color: #1a1c2c;
}

.btn-action-square.btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}

.btn-pause {
  padding: 12px;
  font-size: 1rem;
}

.secondary-controls {
  display: flex;
  gap: 1rem;
  height: 60px; /* Taller secondary buttons */
}

.btn-secondary,
.btn-danger {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.btn-danger {
  background: rgba(255, 71, 87, 0.2);
  color: var(--color-red);
}

.btn-warning {
    flex: 1;
    padding: 12px;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    background: rgba(255, 165, 2, 0.2);
    color: var(--color-orange);
}

.btn-neutral {
    flex: 1;
    padding: 12px;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.05); /* Very subtle grey */
    color: #a0a0a0;
    transition: all 0.2s;
}
.btn-neutral:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-secondary);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.9rem;
  margin-top: 10px;
}

.footer-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    padding-bottom: 20px; /* Add padding for bottom safe area */
    gap: 10px;
    flex-wrap: wrap; /* Allow wrap on very small screens */
}

.text-danger {
    color: var(--color-red);
    opacity: 0.8;
}

/* Animations included in JS logic usually, but here are some base ones */
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  10%,
  30%,
  50%,
  70%,
  90% {
    transform: translateX(-5px);
  }
  20%,
  40%,
  60%,
  80% {
    transform: translateX(5px);
  }
}

.urgent {
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

/* --- Scoring Screen --- */
.scoring-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 2rem 0;
  overflow-y: auto;
}

.score-player-card {
  background: rgba(255, 255, 255, 0.08);
  padding: 1.5rem; /* Bigger touch target */
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  border: 2px solid transparent; /* Prepare for border */
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.score-player-card:active {
    transform: scale(0.98);
}

.score-player-card.winner {
  background: rgba(46, 213, 115, 0.15);
  border-color: var(--primary-action);
  box-shadow: 0 0 20px rgba(46, 213, 115, 0.15);
}

.venceu-badge {
    display: none;
    font-weight: 800;
    color: var(--primary-action);
    text-transform: uppercase;
    font-size: 1.1rem;
}

.score-player-card.winner .venceu-badge {
    display: block;
}

.score-player-card.winner .select-text {
    display: none;
}

.select-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
}

.score-input {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  padding: 10px;
  width: 90px;
  border-radius: 8px;
  text-align: center;
  font-size: 1.2rem;
  font-weight: bold;
}

.score-input:focus {
    border-color: var(--color-blue);
    background: rgba(0,0,0,0.6);
}

.score-player-card.winner .select-text {
    display: none;
}

.select-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
}

.score-input:focus {
    border-color: var(--color-blue);
    background: rgba(0,0,0,0.6);
}

/* Custom Radio Button for "Venceu" */
.custom-radio {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    padding: 8px 12px;
    border-radius: 20px;
    background: rgba(255,255,255,0.1);
    transition: all 0.2s;
}

.custom-radio input {
    display: none; /* Hide default radio */
}

.custom-radio span.check-circle {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid white;
    display: inline-block;
    position: relative;
}

.custom-radio input:checked + span.check-circle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    background: white;
    border-radius: 50%;
}

.custom-radio:hover {
    background: rgba(255,255,255,0.2);
}

.score-player-card.winner .custom-radio {
    background: var(--primary-action);
    color: #1a1c2c;
}

.score-player-card.winner .custom-radio span.check-circle {
    border-color: #1a1c2c;
}

.score-player-card.winner .custom-radio input:checked + span.check-circle::after {
    background: #1a1c2c;
}

.btn-outlined {
    border: 1px solid rgba(255, 71, 87, 0.5);
    background: transparent;
    color: rgba(255, 71, 87, 0.8);
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    text-decoration: none;
    margin-top: 5px; 
    align-self: center; /* Center if in flex column */
}

.btn-outlined:hover {
    background: rgba(255, 71, 87, 0.1);
    color: var(--color-red);
    border-color: var(--color-red);
}

/* --- Modal --- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
    background: #2f3542;
    width: 90%;
    max-width: 400px;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.large-modal {
    max-width: 600px;
}

.rules-content {
    overflow-y: auto;
    text-align: left;
    line-height: 1.6;
}

.rules-content h4 {
    color: var(--color-blue);
    margin-top: 15px;
    margin-bottom: 5px;
}

.rules-content ul {
    margin-left: 20px;
    margin-bottom: 10px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}

.close-modal {
  background: none;
  border: none;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
}

.leaderboard-item {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.leaderboard-item:last-child {
  border: none;
}
.leaderboard-pos {
  font-weight: bold;
  width: 30px;
}
.leaderboard-score {
  font-weight: bold;
  color: var(--color-orange);
}

.winner-highlight {
    border-left: 4px solid var(--color-orange);
}

.shuffler-info {
    text-align: center;
    background: rgba(0,0,0,0.2);
    padding: 5px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-radius: 0 0 10px 10px;
    margin-bottom: 10px;
}

#shuffler-name {
    color: var(--color-orange);
    font-weight: bold;
}

.player-selection-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.full-width {
    width: 100%;
}

/* ===== TABLET STYLES ===== */
@media (min-width: 600px) {
    .app-container {
        max-width: 700px;
    }
    
    .screen {
        padding: 2rem;
    }
    
    #active-player-name {
        font-size: 3.5rem;
    }
    
    .timer-ring {
        width: 350px;
        height: 350px;
    }
    
    .timer-text {
        font-size: 6rem;
    }
    
    .btn-action-square {
        max-height: 180px;
        font-size: 1.8rem;
    }
    
    .footer-actions {
        gap: 1.5rem;
    }
    
    .modal-content {
        max-width: 500px;
        padding: 30px;
    }
    
    .large-modal {
        max-width: 700px;
    }
    
    .score-player-card {
        padding: 2rem;
    }
    
    .score-input {
        width: 120px;
        font-size: 1.4rem;
        padding: 12px;
    }
}

/* ===== LARGE TABLET / SMALL DESKTOP ===== */
@media (min-width: 900px) {
    .app-container {
        max-width: 800px;
    }
    
    .timer-ring {
        width: 400px;
        height: 400px;
    }
    
    .timer-text {
        font-size: 7rem;
    }
    
    .btn-action-square {
        max-height: 200px;
        font-size: 2rem;
    }
}
