:root {
  --color-red: #ff5555;
  --color-yellow: #ffaa00;
  --color-green: #55aa55;
  --color-blue: #5555ff;
  --color-wild: #2b2b2b;

  --bg: #14261d;
  --panel-bg: #1d3226;
  --ink: #f4f4f2;
  --ink-dim: #b9c4bd;
  --accent: #ffaa00;

  color-scheme: dark;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

h1, h2, h3 {
  margin: 0 0 0.5em;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.screen[hidden] {
  display: none;
}

.panel {
  background: var(--panel-bg);
  border-radius: 16px;
  padding: 2rem;
  width: min(420px, 100%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.logo {
  text-align: center;
  font-size: 2.5rem;
  letter-spacing: 0.1em;
  color: var(--accent);
  text-shadow: 2px 2px 0 var(--color-red);
}

.field {
  display: block;
  margin-bottom: 1rem;
}

.field span {
  display: block;
  font-size: 0.85rem;
  color: var(--ink-dim);
  margin-bottom: 0.25rem;
}

.field input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid #3a5443;
  background: #0f1d15;
  color: var(--ink);
  font-size: 1rem;
}

.field input:focus {
  outline: 2px solid var(--accent);
}

.btn {
  width: 100%;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  border: none;
  background: #33513f;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 600;
  transition: transform 0.05s ease, background 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: #3d6049;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #1a1a1a;
}

.btn-primary:hover:not(:disabled) {
  background: #ffbb33;
}

.btn-small {
  width: auto;
  padding: 0.5rem 1rem;
}

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

.btn-uno {
  width: auto;
  padding: 0.85rem 1.75rem;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--ink-dim);
  margin: 1rem 0;
  font-size: 0.8rem;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid #3a5443;
}

.divider span {
  padding: 0 0.75rem;
}

.error-text {
  color: var(--color-red);
  font-size: 0.9rem;
  margin-top: 1rem;
  text-align: center;
}

/* Lobby */

.room-code {
  text-align: center;
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--accent);
  background: #0f1d15;
  border-radius: 12px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
}

.hint {
  color: var(--ink-dim);
  font-size: 0.85rem;
  text-align: center;
  margin: 0.5rem 0 1rem;
}

.lobby-players {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
}

.lobby-players li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  background: #0f1d15;
  border-radius: 8px;
  margin-bottom: 0.4rem;
  gap: 0.5rem;
}

.lobby-players .player-name {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-players .player-tags {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.bot-badge {
  font-size: 0.7rem;
  color: var(--ink-dim);
  border: 1px solid #3a5443;
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  white-space: nowrap;
}

.remove-bot-btn {
  border: none;
  background: transparent;
  color: var(--color-red);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem 0.3rem;
}

.add-bot-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.add-bot-row select {
  flex: 1;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid #3a5443;
  background: #0f1d15;
  color: var(--ink);
  font-size: 0.9rem;
}

.add-bot-row .btn-small {
  flex-shrink: 0;
}

.timer-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
  cursor: pointer;
}

.timer-toggle input {
  width: 18px;
  height: 18px;
}

.lobby-players .host-tag {
  font-size: 0.75rem;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
}

/* Game board */

#screen-game {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  padding: 0.75rem;
  justify-content: space-between;
  align-items: stretch;
}

#screen-game:not([hidden]) {
  display: flex;
}

.opponents {
  position: relative;
  height: 150px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto 0.5rem;
}

.opponent {
  background: var(--panel-bg);
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
  text-align: center;
  min-width: 90px;
  position: absolute;
  border: 2px solid transparent;
  transform: translateX(-50%);
}

/* Seats are hand-placed per opponent count (max 3, since the game caps at 4
   players) rather than computed via trig -- simpler and gives a deliberate
   "around the table" feel. Recomputed fresh every render off state.players,
   so the layout reflows automatically when a player is removed mid-game. */
.opponent[data-seat="1-0"] { left: 50%; top: 30px; }

.opponent[data-seat="2-0"] { left: 22%; top: 40px; }
.opponent[data-seat="2-1"] { left: 78%; top: 40px; }

.opponent[data-seat="3-0"] { left: 10%; top: 60px; }
.opponent[data-seat="3-1"] { left: 50%; top: 0; }
.opponent[data-seat="3-2"] { left: 90%; top: 60px; }

.opponent.is-turn {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(255, 170, 0, 0.5);
}

.opponent .opponent-name {
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
}

.opponent .card-count {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
}

.uno-flag {
  font-size: 0.65rem;
  color: var(--color-red);
  font-weight: 800;
}

.catch-btn {
  margin-top: 0.35rem;
  font-size: 0.95rem;
  padding: 0.5rem 1rem;
  background: var(--color-red);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.my-seat {
  position: relative;
  display: flex;
  justify-content: center;
}

.emoji-bar {
  display: flex;
  gap: 0.5rem;
}

.emoji-btn {
  border: none;
  background: var(--panel-bg);
  border-radius: 999px;
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.emoji-btn:hover {
  background: #3d6049;
}

/* Reaction emojis render into this full-screen layer (not inside the small
   seat badges) so they have room to travel visibly across the table. */
.reaction-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 15;
  overflow: hidden;
}

.reaction-pop {
  position: fixed;
  font-size: 3.4rem;
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
  animation: reaction-travel 2s ease-out forwards;
}

@keyframes reaction-travel {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.25); }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px))) scale(1);
  }
}

@media (max-width: 480px) {
  .reaction-pop {
    font-size: 2.4rem;
  }
}

.table {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.5rem;
  padding: 1rem;
  flex-wrap: wrap;
}

.pile-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

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

.center-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.direction {
  font-size: 1.8rem;
  color: var(--ink-dim);
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: transparent;
}

.color-swatch.color-red { background: var(--color-red); }
.color-swatch.color-yellow { background: var(--color-yellow); }
.color-swatch.color-green { background: var(--color-green); }
.color-swatch.color-blue { background: var(--color-blue); }

.turn-banner {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  min-height: 1.6em;
  color: var(--accent);
}

.turn-timer {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink-dim);
}

.turn-timer.urgent {
  color: var(--color-red);
}

.pending-draw-banner {
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-red);
  background: rgba(255, 85, 85, 0.12);
  border: 1px solid var(--color-red);
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  margin: 0 auto 0.4rem;
  width: fit-content;
}

.hand-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.hand-controls {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}

.hand {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.5rem;
  max-width: 100%;
  scrollbar-width: thin;
}

/* Cards */

.card {
  width: 64px;
  height: 96px;
  border-radius: 8px;
  background: white;
  color: #111;
  border: 1px solid #00000030;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  flex-shrink: 0;
  position: relative;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  user-select: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.card.playable {
  cursor: pointer;
  transform: translateY(-8px);
}

.card.dimmed {
  opacity: 0.35;
  filter: grayscale(60%);
}

.card.selected-wild {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  transform: translateY(-8px);
}

.card.playable:hover {
  transform: translateY(-14px);
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.4);
}

.card.color-red { background: var(--color-red); color: white; }
.card.color-yellow { background: var(--color-yellow); color: #3a2600; }
.card.color-green { background: var(--color-green); color: white; }
.card.color-blue { background: var(--color-blue); color: white; }
.card.color-wild {
  background: linear-gradient(135deg, var(--color-red) 25%, var(--color-yellow) 25% 50%, var(--color-green) 50% 75%, var(--color-blue) 75%);
  color: white;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.card-back {
  width: 64px;
  height: 96px;
  border-radius: 8px;
  background: repeating-linear-gradient(45deg, var(--color-wild), var(--color-wild) 6px, #1a1a1a 6px, #1a1a1a 12px);
  border: 2px solid var(--color-red);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.card-back.disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.discard-pile .card {
  transform: none;
}

.discard-pile .card:hover {
  transform: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* Overlays */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 1rem;
}

.overlay[hidden] {
  display: none;
}

.overlay-panel {
  background: var(--panel-bg);
  border-radius: 16px;
  padding: 2rem;
  width: min(400px, 100%);
  text-align: center;
}

.color-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}

.color-choice {
  height: 64px;
  border-radius: 10px;
  border: none;
}

.color-choice[data-color="red"] { background: var(--color-red); }
.color-choice[data-color="yellow"] { background: var(--color-yellow); }
.color-choice[data-color="green"] { background: var(--color-green); }
.color-choice[data-color="blue"] { background: var(--color-blue); }

.score-breakdown {
  text-align: left;
  margin: 1rem 0;
  font-size: 0.9rem;
  color: var(--ink-dim);
}

.score-breakdown div {
  display: flex;
  justify-content: space-between;
  padding: 0.2rem 0;
}

.awards-list {
  text-align: left;
  margin: 0 0 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #3a5443;
}

.awards-list .award-row {
  padding: 0.3rem 0;
  font-size: 0.85rem;
}

.awards-list .award-label {
  color: var(--accent);
  font-weight: 700;
}

.awards-list .award-detail {
  color: var(--ink-dim);
}

/* Toast */

.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-red);
  color: white;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

@media (max-width: 480px) {
  .card, .card-back {
    width: 52px;
    height: 78px;
    font-size: 1.3rem;
  }
  .panel {
    padding: 1.5rem;
  }
  .opponent {
    min-width: 72px;
    padding: 0.4rem 0.5rem;
  }
  .opponent[data-seat="3-0"] { left: 2%; }
  .opponent[data-seat="3-2"] { left: 98%; }
}
