:root {
  --bg: #1f2937;
  --panel: #273449;
  --panel-2: #1b2432;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --danger: #ef4444;
  --green: #22c55e;
  --red-card: #dc2626;
  --black-card: #111827;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--panel-2);
  color: var(--text);
}
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button.ghost { background: transparent; border: 1px solid var(--muted); color: var(--muted); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input {
  font: inherit;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #374151;
  background: var(--panel-2);
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); }

/* Screens */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.panel {
  background: var(--panel);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.home-panel {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.home-header { display: flex; justify-content: space-between; align-items: center; }
.home-panel h1 { margin: 0; }
.home-panel label { font-size: 0.85rem; color: var(--muted); }
.lang-btn {
  background: transparent;
  border: 1px solid var(--muted);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}
.lang-btn:hover { color: var(--text); border-color: var(--text); }
.btn-icon { font-size: 1.05em; line-height: 1; }
.btn-label { margin-left: 6px; }
.tagline { margin: 0 0 8px; text-align: center; color: var(--muted); }
.home-actions { display: flex; flex-direction: column; gap: 8px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; }
.error { color: var(--danger); min-height: 18px; margin: 0; font-size: 0.9rem; }

/* Room layout */
#screen-room {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  gap: 12px;
  align-items: stretch;
  justify-content: flex-start;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}
.room-info { display: flex; align-items: baseline; gap: 10px; }
.room-code-label { color: var(--muted); font-size: 0.85rem; }
.room-code {
  font-family: ui-monospace, monospace;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.badge { padding: 4px 10px; border-radius: 999px; font-size: 0.8rem; }
.badge-lobby { background: #334155; }
.badge-playing { background: var(--green); color: #052e16; }

.room-layout {
  display: flex;
  gap: 12px;
  flex: 1;
  width: 100%;
  min-height: 0;
}
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
}

/* Lobby */
.hint { color: var(--muted); font-size: 0.9rem; margin: 4px 0 12px; }
.player-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.player {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--panel-2);
  border-radius: 8px;
}
.player.you { outline: 2px solid var(--accent); }
.player.disconnected { opacity: 0.5; }
.player-status { color: var(--muted); font-size: 0.85rem; }
.game-select-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 12px;
}
.game-select-row label { color: var(--muted); font-size: 0.85rem; }
.game-select-row select {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #374151;
  background: var(--panel-2);
  color: var(--text);
}
.lobby-actions { display: flex; gap: 8px; margin-top: 12px; }

/* Chat */
.chat-panel {
  width: 300px;
  min-height: 0;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 12px;
  padding: 12px;
  gap: 8px;
}
.chat-header { display: flex; justify-content: space-between; align-items: center; }
.chat-panel h2 { margin: 0; font-size: 1rem; }
.chat-controls { display: flex; gap: 4px; }
.font-btn {
  padding: 2px 9px;
  font-size: 0.9rem;
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
}
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 10px;
  font-size: var(--chat-font-size, 0.9rem);
}
.chat-msg { word-break: break-word; }
.chat-msg.system { color: var(--muted); font-style: italic; }
.chat-name { font-weight: 600; color: var(--accent); }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; }

/* Game */
.game-top {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
}
.stock { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stock-pile {
  width: 46px;
  height: 64px;
  border-radius: 8px;
  border: 2px solid #475569;
  background: repeating-linear-gradient(45deg, #334155, #334155 6px, #1e293b 6px, #1e293b 12px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}
.stock-count { font-size: 0.8rem; color: var(--muted); }
.discard { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.discard .card { cursor: default; }
.discard .card:hover { transform: none; }
.discard-suit { font-size: 0.8rem; color: var(--muted); }
.table {
  background: var(--panel);
  border-radius: 10px;
  padding: 10px;
  min-width: 120px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}
.table-cards { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.table-cards .card { cursor: default; width: 40px; height: 56px; }
.table-cards .card:hover { transform: none; }
.table-label { color: var(--muted); font-size: 0.8rem; }
.opponent {
  background: var(--panel);
  border-radius: 10px;
  padding: 10px;
  min-width: 120px;
}
.opponent.active { outline: 2px solid var(--green); }
.opp-name { font-weight: 600; }
.opp-count { color: var(--muted); font-size: 0.85rem; }
.opp-hand-full { line-height: 1; }
.opp-hand-compact {
  display: none;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  color: var(--muted);
}
.opp-hand-compact .card-back { width: 13px; height: 19px; margin: 0; }
.opp-books-compact { display: none; white-space: nowrap; color: #fbbf24; }
.opp-pairs { white-space: nowrap; color: #a78bfa; }
.opp-out { white-space: nowrap; color: var(--green); font-size: 0.8rem; }
.card-back {
  display: inline-block;
  width: 16px;
  height: 24px;
  background: var(--accent);
  border-radius: 3px;
  margin: 4px 2px 0 0;
}
.books { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.book {
  background: #fbbf24;
  color: #451a03;
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.8rem;
  font-weight: 700;
}
.book .suits { font-size: 0.7rem; margin-left: 2px; }

.turn-banner {
  text-align: center;
  font-size: 1.05rem;
  padding: 8px;
  background: var(--panel);
  border-radius: 8px;
  min-height: 20px;
}

.ask-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border-radius: 8px;
  padding: 10px;
}
.ask-label { color: var(--muted); }
.reveal-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: var(--panel);
  border-radius: 8px;
}
.reveal-area .card { cursor: default; }
.reveal-label { color: var(--muted); font-size: 0.9rem; }
.select-cards { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.select-card {
  width: 40px;
  height: 56px;
  padding: 0;
  border-radius: 6px;
  border: 2px solid #475569;
  cursor: pointer;
  background: repeating-linear-gradient(45deg, #2f3e57, #2f3e57 5px, #263449 5px, #263449 10px);
  transition: transform 0.1s ease;
}
.select-card:hover { transform: translateY(-4px); }
.suit-picker { display: inline-flex; gap: 4px; }
.suit-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 8px;
  font-size: 1.1rem;
  background: var(--panel-2);
  color: var(--text);
  border: 2px solid transparent;
}
.suit-btn:hover { border-color: var(--accent); }
.suit-btn.selected { border-color: var(--green); }
.suit-btn[data-suit="H"], .suit-btn[data-suit="D"] { color: var(--red-card); }

.my-hand {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  min-height: 90px;
  align-items: flex-end;
}
.my-label { text-align: center; color: var(--muted); }

.card {
  width: 52px;
  height: 74px;
  border-radius: 8px;
  background: #fff;
  color: var(--black-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 4px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  user-select: none;
  transition: transform 0.1s ease;
}
.card:hover { transform: translateY(-4px); }
.card.selected { transform: translateY(-10px); outline: 3px solid var(--green); }
.card.flash {
  outline: 3px solid #f59e0b;
  animation: flash-pulse 0.5s ease-in-out infinite alternate;
}
@keyframes flash-pulse {
  from { box-shadow: 0 0 4px #f59e0b; }
  to { box-shadow: 0 0 14px #f59e0b; }
}
.uno-card {
  width: 52px;
  height: 74px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.25);
  transition: transform 0.1s ease;
}
.uno-card:hover { transform: translateY(-4px); }
.uno-card.selected { transform: translateY(-10px); outline: 3px solid var(--green); }
.uno-R { background: #dc2626; }
.uno-Y { background: #facc15; color: #111827; }
.uno-G { background: #16a34a; }
.uno-B { background: #2563eb; }
.uno-wild {
  background: conic-gradient(#dc2626 0 25%, #facc15 0 50%, #16a34a 0 75%, #2563eb 0 100%);
  color: #fff;
  text-shadow: 0 0 3px #000;
}
.uno-value { font-size: 1.05rem; }
.discard .uno-card { cursor: default; }
.discard .uno-card:hover { transform: none; }
.color-picker { display: inline-flex; gap: 4px; }
.color-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.color-btn.selected { border-color: #fff; outline: 2px solid var(--green); }
.card.red { color: var(--red-card); }
.card .rank { font-size: 1.1rem; font-weight: 700; align-self: flex-start; }
.card .suit { font-size: 1.2rem; align-self: flex-end; }
.empty-hand { color: var(--muted); }

.game-actions { text-align: center; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  z-index: 100;
  max-width: 90vw;
}

/* Responsive */
@media (max-width: 720px) {
  .room-layout { flex-direction: column; }
  .chat-panel { width: 100%; height: 180px; }
  .card { width: 44px; height: 62px; }
  .card .rank { font-size: 1rem; }
  .card .suit { font-size: 1rem; }
  .uno-card { width: 44px; height: 62px; }
  .uno-value { font-size: 0.95rem; }

  .topbar-actions .btn-label { display: none; }
  .topbar-actions .ghost,
  .topbar-actions .lang-btn { padding: 8px 10px; }

  .game-top { flex-direction: column; align-items: stretch; }
  .opponent {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
    min-width: 0;
  }
  .opp-hand-full { display: none; }
  .opp-count { display: none; }
  .opponent .books { display: none; }
  .opp-hand-compact { display: inline-flex; }
  .opp-books-compact { display: inline; }
}
