:root {
  --bg: #1a5e1a;
  --bg-dark: #0d3d0d;
  --accent: #e94560;
  --text: #e0e0e0;
  --text-dim: #a0a0b0;
  --card-white: #ffffff;
  --card-border: #999;
  --highlight: #ffeb3b;
  --valid: #4caf50;
  --red-suit: #ff4444;
  --black-suit: #e0e0e0;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0d3d0d;
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: 100%;
  height: 100dvh;
  position: relative;
}

.screen {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 3vw, 20px);
}

.hidden {
  display: none !important;
}

/* ── Lobby ─────────────────────────────────────────── */

#lobby {
  gap: clamp(12px, 3vh, 20px);
  background: #0d3d0d;
}

#lobby h1 {
  font-size: clamp(2rem, 6vw, 3rem);
  color: #ffffff;
  font-weight: 800;
  letter-spacing: -1px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#lobbyHeader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 4px;
}

.lobby-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 2vh, 14px);
  width: min(320px, 90vw);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.form-group.deck-back-row {
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.deck-back-row {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.deck-back-content {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.deck-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: clamp(0.7rem, 2vw, 0.8rem);
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

input[type="text"] {
  padding: clamp(10px, 2vh, 14px) clamp(12px, 2.5vw, 16px);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
  color: #ffffff;
  font-size: clamp(0.95rem, 2.5vw, 1.05rem);
  font-weight: 500;
  transition: border-color 0.2s, background 0.2s;
}

input[type="text"]:focus {
  outline: none;
  border-color: rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.12);
}

input[type="text"]::placeholder {
  color: rgba(255,255,255,0.3);
}

input[type="file"] {
  display: none;
}

.deck-preview {
  width: clamp(72px, 18vw, 96px);
  aspect-ratio: 2.5 / 3.5;
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  transition: border-color 0.2s;
}

.deck-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.deck-controls {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: center;
}

.deck-controls label {
  font-size: clamp(0.7rem, 2vw, 0.8rem);
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.deck-controls label:hover {
  color: rgba(255,255,255,0.8);
}

button {
  padding: clamp(10px, 2.5vh, 14px) clamp(20px, 5vw, 32px);
  border: none;
  border-radius: 10px;
  background: #ffffff;
  color: #0d3d0d;
  font-size: clamp(0.9rem, 2.5vw, 1rem);
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

button:hover {
  background: #f0f0f0;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

button:active {
  transform: scale(0.98);
}

.room-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(320px, 90vw);
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  flex: 1;
}

.error {
  color: #ff6b6b;
  font-size: clamp(0.75rem, 2vw, 0.85rem);
  min-height: 20px;
  text-align: center;
}

/* ── Game Screen ───────────────────────────────────── */

#gameScreen {
  padding: 0;
  background: #0d3d0d;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

#topBar {
  width: 100%;
  height: 36px;
  min-height: 36px;
  max-height: 45px;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(8px, 2vw, 16px);
  flex-shrink: 0;
  z-index: 10;
}

#topBar #roomName {
  font-size: clamp(0.75rem, 2vw, 0.9rem);
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80%;
}

#topBar button {
  padding: 2px 8px;
  font-size: clamp(0.8rem, 2vw, 1rem);
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: 8px;
  flex-shrink: 0;
  transition: background 0.3s;
}

.status-dot.connected {
  background: #4caf50;
  box-shadow: 0 0 4px #4caf50;
}

.status-dot.disconnected {
  background: #f44336;
  box-shadow: 0 0 4px #f44336;
}

#gameContainer {
  flex: 1;
  width: 100%;
  height: 0;
  position: relative;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}

.countdown-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  pointer-events: none;
}

.countdown-overlay {
  font-size: 80px;
  font-weight: bold;
  color: #fff;
}

/* ── Toast ─────────────────────────────────────────── */

.toast {
  position: fixed;
  top: clamp(40px, 8vh, 60px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  z-index: 200;
  font-size: clamp(0.75rem, 2vw, 0.9rem);
  transition: opacity 0.3s;
  white-space: nowrap;
}

/* ── End Game / Scores ─────────────────────────────── */

#endGame {
  padding: clamp(16px, 4vh, 32px) clamp(12px, 3vw, 24px);
  background: #0d3d0d;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  overflow-y: auto;
}

#endGame > h1 {
  font-size: clamp(1.2rem, 3.5vw, 1.6rem);
  margin: 0;
  color: #ffffff;
}

#scores {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.score-row.winner {
  background: rgba(255, 215, 0, 0.15);
  border: 1px solid rgba(255, 215, 0, 0.3);
}

.score-row.finished-first {
  background: rgba(255, 140, 0, 0.12);
  border: 1px solid rgba(255, 140, 0, 0.25);
}

.score-player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.deck-logo {
  width: 32px;
  height: 44px;
  border-radius: 4px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.score-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.player-name {
  font-weight: bold;
  font-size: clamp(0.85rem, 2.2vw, 1rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-details {
  font-size: clamp(0.7rem, 1.8vw, 0.8rem);
  color: var(--text-dim);
}

.score-value {
  font-weight: bold;
  font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  flex-shrink: 0;
  margin-left: 12px;
}

#scores button {
  margin-top: 12px;
  width: 100%;
}

/* ── Modal ─────────────────────────────────────────── */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: #0d3d0d;
  border-radius: 12px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 200px;
}

.modal-content h2 {
  font-size: 1.2rem;
  margin: 0;
  text-align: center;
  color: #ffffff;
}
