:root {
  --bg: #1a1a2e;
  --bg-light: #16213e;
  --surface: #0f3460;
  --primary: #e94560;
  --primary-hover: #c73a52;
  --accent: #f5c518;
  --text: #eee;
  --text-dim: #999;
  --success: #4caf50;
  --danger: #e94560;
  --card-bg: #e8e0d4;
  --card-text: #1a1a2e;
  --radius: 12px;
  --transition: 0.3s ease;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100dvh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.screen {
  display: none;
  height: 100dvh;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* --- Home --- */
.home-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 24px;
  text-align: center;
}

.title {
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-dim);
  margin-bottom: 40px;
  font-size: 1rem;
}

.home-form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

input[type="text"] {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.1rem;
  border: 2px solid var(--surface);
  border-radius: var(--radius);
  background: var(--bg-light);
  color: var(--text);
  outline: none;
  text-align: center;
}

input[type="text"]:focus {
  border-color: var(--primary);
}

.btn {
  padding: 14px 24px;
  font-size: 1.1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), transform 0.1s;
  min-height: 48px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
}

.btn-small {
  padding: 8px 16px;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 8px 0;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--surface);
}

.join-code {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.hidden { display: none !important; }

/* --- Lobby --- */
.lobby-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px;
  flex: 1;
}

.lobby-container h2 {
  font-size: 1.8rem;
  margin-bottom: 16px;
}

.game-code-box {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-light);
  padding: 12px 20px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 4px;
}

#player-list {
  list-style: none;
  width: 100%;
  max-width: 320px;
  margin-bottom: 24px;
}

#player-list li {
  padding: 12px 16px;
  background: var(--bg-light);
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

#player-list li .you-badge {
  font-size: 0.75rem;
  background: var(--primary);
  padding: 2px 8px;
  border-radius: 4px;
}

.status-text {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 8px;
}

/* --- Game Screen --- */
#screen-game {
  padding: 0;
}

.status-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-light);
  border-bottom: 1px solid var(--surface);
  flex-shrink: 0;
}

.btn-quit {
  padding: 6px 14px;
  font-size: 0.8rem;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--text-dim);
  min-height: auto;
}

.status-item {
  text-align: center;
}

.status-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.status-value {
  font-size: 1.3rem;
  font-weight: 700;
}

.status-sub {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.lives { color: var(--danger); }
.stars { color: var(--accent); }

/* Opponents */
.opponents {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 12px 16px;
  flex-shrink: 0;
}

.opponent {
  text-align: center;
  padding: 8px 16px;
  background: var(--bg-light);
  border-radius: 8px;
  min-width: 80px;
}

.opponent-name {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.opponent-cards {
  font-size: 1.3rem;
  font-weight: 700;
}

.opponent.disconnected {
  opacity: 0.4;
}

/* Pile */
.pile-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.pile-card {
  width: 100px;
  height: 140px;
  background: var(--card-bg);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: transform var(--transition);
}

.pile-card.empty {
  background: var(--surface);
  border: 2px dashed var(--text-dim);
  box-shadow: none;
}

#pile-number {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--card-text);
}

.pile-card.empty #pile-number {
  color: var(--text-dim);
  font-size: 2rem;
}

.pile-count {
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* Star area */
.star-area {
  padding: 8px 16px;
  text-align: center;
  flex-shrink: 0;
}

.btn-star {
  background: var(--bg-light);
  color: var(--accent);
  border: 2px solid var(--accent);
  padding: 10px 24px;
  font-size: 1rem;
}

.btn-star:disabled {
  opacity: 0.3;
  cursor: default;
}

.btn-star.proposed {
  background: var(--accent);
  color: var(--bg);
}

.star-status {
  font-size: 0.85rem;
  color: var(--accent);
  margin-top: 4px;
}

/* Hand */
.hand {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  flex-shrink: 0;
  flex-wrap: wrap;
  min-height: 120px;
}

.card {
  width: 64px;
  height: 90px;
  background: var(--card-bg);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--card-text);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  -webkit-tap-highlight-color: transparent;
}

.card:active {
  transform: scale(0.93);
}

.card.lowest {
  box-shadow: 0 0 0 3px var(--primary);
}

/* Overlay */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay-content {
  text-align: center;
  padding: 32px;
  max-width: 320px;
}

.overlay-content h2 {
  font-size: 1.8rem;
  margin-bottom: 12px;
}

.overlay-content p {
  color: var(--text-dim);
  font-size: 1rem;
}

/* Game Over */
.gameover-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 24px;
  text-align: center;
}

.gameover-container h1 {
  font-size: 2.5rem;
  margin-bottom: 16px;
}

.gameover-container p {
  color: var(--text-dim);
  font-size: 1.1rem;
  margin-bottom: 32px;
}

/* --- Animations --- */
@keyframes cardFlyIn {
  from {
    transform: translateY(80px) scale(0.5);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes errorFlash {
  0%, 100% { background: var(--bg); }
  50% { background: rgba(233, 69, 96, 0.15); }
}

@keyframes levelUp {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

.card-fly-in {
  animation: cardFlyIn 0.4s ease-out;
}

.error-flash {
  animation: errorFlash 0.5s ease 2;
}

.level-up-anim {
  animation: levelUp 0.5s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

.fade-in { animation: fadeIn 0.3s ease; }
.slide-up { animation: slideUp 0.3s ease; }
