:root {
  --red: #d92b2b;
  --yellow: #e6b315;
  --green: #1f9d4d;
  --blue: #1f6fd0;
  --felt: #0b2f24;
  --ink: #f4f1e8;
  --panel: #14211f;
  --muted: #9db3ac;
  --card-w: 78px;
  --card-h: 116px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 50% -10%, #164436 0%, transparent 60%),
    radial-gradient(900px 600px at 50% 110%, #061b15 0%, transparent 65%),
    #07120f;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ------------------------------------------------------------- screens */

.screen {
  width: min(1080px, 100vw);
  height: 100%;
  max-height: 100dvh;
  padding: 18px clamp(12px, 3vw, 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.logo {
  margin: 0;
  font-size: clamp(38px, 8vw, 68px);
  letter-spacing: -2px;
  font-weight: 900;
  line-height: 0.9;
  color: #fff;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}

.logo span {
  display: block;
  font-size: 0.34em;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 10px;
  font-weight: 700;
}

.logo.small { font-size: clamp(24px, 4vw, 34px); letter-spacing: -1px; }
.logo.small span { display: inline; font-size: 1em; letter-spacing: 0.12em; color: #fff; margin: 0; }

.panel {
  width: min(420px, 100%);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }

input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus { border-color: #48d18e; box-shadow: 0 0 0 3px rgba(72, 209, 142, 0.18); }

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(180deg, #2fbf7a, #19965c);
  border-color: rgba(255, 255, 255, 0.22);
  color: #04120c;
  box-shadow: 0 8px 22px rgba(31, 157, 77, 0.35);
}

.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #39d08a, #1aa466); }

.btn.uno {
  background: linear-gradient(180deg, #ffd34d, #e8a20c);
  color: #2a1a00;
  font-size: 18px;
  letter-spacing: 0.06em;
  animation: pulse 0.8s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 211, 77, 0.5); }
  to { transform: scale(1.05); box-shadow: 0 0 0 12px rgba(255, 211, 77, 0); }
}

.or { text-align: center; font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.or span { position: relative; padding: 0 10px; }

.joinRow { display: flex; gap: 10px; }
.joinRow input { text-transform: uppercase; letter-spacing: 0.35em; text-align: center; font-weight: 700; }

/* ------------------------------------------------------------- room browser */

.rooms { display: flex; flex-direction: column; gap: 7px; }

.roomsHead {
  margin: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.roomsHead em { font-style: normal; text-transform: none; letter-spacing: 0; }

.roomList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 26vh;
  overflow-y: auto;
}

.roomRow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  font-size: 14px;
}

.roomRow strong { letter-spacing: 0.22em; font-size: 15px; }

.roomRow.empty { background: none; padding: 2px; color: var(--muted); font-size: 13px; }

.roomMeta {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn.tiny { padding: 6px 12px; font-size: 13px; border-radius: 9px; }

.hint { margin: 0; font-size: 13px; color: var(--muted); text-align: center; }
.share { margin: 0; text-align: center; color: var(--muted); font-size: 13px; }
.share strong { color: #fff; letter-spacing: 0.35em; font-size: 18px; }

.linkBtn {
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  padding: 6px;
}

.linkBtn:hover { color: var(--ink); }

/* ------------------------------------------------------------- lobby list */

.playerList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.playerRow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  font-size: 15px;
}

.playerRow em { margin-left: auto; font-style: normal; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: #48d18e; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: #555; }
.dot.on { background: #48d18e; box-shadow: 0 0 8px #48d18e; }

/* ------------------------------------------------------------- table */

#home { overflow-y: auto; justify-content: safe center; }

#table { justify-content: flex-start; gap: 10px; padding-top: 14px; }

.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tag {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  font-weight: 700;
}

.tag.turn { color: var(--ink); }
.tag.turn.mine { background: #1f9d4d; color: #04120c; }

.colorTag { display: inline-flex; align-items: center; gap: 7px; }
.colorTag i { width: 12px; height: 12px; border-radius: 3px; background: var(--muted); }
.colorTag[data-color="red"] i { background: var(--red); }
.colorTag[data-color="yellow"] i { background: var(--yellow); }
.colorTag[data-color="green"] i { background: var(--green); }
.colorTag[data-color="blue"] i { background: var(--blue); }

#leaveGame { margin-left: auto; }

.opponents {
  width: 100%;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 52px;
}

.opponent {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid transparent;
  min-width: 86px;
}

.opponent.active { border-color: #48d18e; box-shadow: 0 0 18px rgba(72, 209, 142, 0.28); }
.opponent.close { background: rgba(217, 43, 43, 0.22); }
.opponent.winner { border-color: #ffd34d; box-shadow: 0 0 20px rgba(255, 211, 77, 0.35); }

.oppName { font-size: 14px; font-weight: 700; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.oppCount { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

.tableArea {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 0;
}

.piles { display: flex; align-items: center; gap: clamp(18px, 5vw, 56px); }

.pile { position: relative; width: var(--card-w); height: var(--card-h); }

.pile.deck {
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
}

.deckBack {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: linear-gradient(150deg, #1b1b2b, #0d0d16);
  border: 3px solid #f4f1e8;
  display: grid;
  place-items: center;
  box-shadow: 3px 3px 0 #000, 6px 6px 0 rgba(244, 241, 232, 0.25);
}

.deckBack b {
  font-size: 15px;
  letter-spacing: 0.06em;
  color: #ffd34d;
  transform: rotate(-18deg);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
}

.pile.deck em {
  position: absolute;
  right: -10px;
  bottom: -10px;
  font-style: normal;
  font-size: 11px;
  font-weight: 700;
  background: #14211f;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--muted);
}

.pile.center { display: grid; place-items: center; }

.actions { display: flex; gap: 10px; min-height: 44px; align-items: center; }

/* ------------------------------------------------------------- cards */

.card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 10px;
  border: 3px solid #f4f1e8;
  background: var(--red);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  user-select: none;
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
  overflow: hidden;
}

.card.red { background: var(--red); }
.card.yellow { background: var(--yellow); }
.card.green { background: var(--green); }
.card.blue { background: var(--blue); }
.card.wild {
  background:
    conic-gradient(from 45deg, var(--red) 0 25%, var(--yellow) 0 50%, var(--green) 0 75%, var(--blue) 0);
}

.card .oval {
  width: 74%;
  height: 66%;
  border-radius: 50%;
  background: #f7f4ea;
  transform: rotate(-22deg);
  display: grid;
  place-items: center;
  color: var(--red);
  font-weight: 900;
  font-size: 30px;
  letter-spacing: -1px;
}

.card.red .oval { color: var(--red); }
.card.yellow .oval { color: #b8890a; }
.card.green .oval { color: var(--green); }
.card.blue .oval { color: var(--blue); }
.card.wild .oval { color: #111; font-size: 17px; }

.card .corner {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 12px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}


.card.small { width: 52px; height: 78px; }
.card.small .oval { font-size: 20px; }

.hand {
  width: 100%;
  min-height: calc(var(--card-h) + 18px);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(2px, 1vw, 10px);
  flex-wrap: nowrap;
  padding-bottom: 8px;
}

#hand .card { cursor: default; }

#hand .card.playable { cursor: pointer; box-shadow: 0 10px 22px rgba(255, 211, 77, 0.35), 0 0 0 2px #ffd34d; }
#hand .card.playable:hover { transform: translateY(-16px) scale(1.04); }
#hand .card.dim { filter: brightness(0.62) saturate(0.8); }
#hand .card.justDrawn { box-shadow: 0 0 0 3px #48d18e, 0 10px 22px rgba(72, 209, 142, 0.4); }

/* ------------------------------------------------------------- log */

.log {
  list-style: none;
  margin: 0;
  padding: 0;
  width: min(560px, 100%);
  height: 52px;
  overflow: hidden;
  display: flex;
  flex-direction: column-reverse;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  gap: 2px;
}

.log li:first-child { color: var(--ink); }

/* ------------------------------------------------------------- overlays */

.picker, .banner {
  position: fixed;
  inset: 0;
  background: rgba(3, 10, 8, 0.82);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 20;
}

.picker p { margin: 0; font-size: 13px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }

.swatches { display: flex; gap: 14px; }

.swatch {
  width: 74px;
  height: 74px;
  border-radius: 16px;
  border: 3px solid #f4f1e8;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.swatch:hover { transform: translateY(-6px) scale(1.04); }
.swatch.red { background: var(--red); }
.swatch.yellow { background: var(--yellow); }
.swatch.green { background: var(--green); }
.swatch.blue { background: var(--blue); }

.banner h2 { margin: 0; font-size: clamp(28px, 6vw, 46px); }
.banner p { margin: 0; color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  background: #2b1512;
  border: 1px solid rgba(255, 120, 100, 0.4);
  color: #ffd9d3;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 30;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------- small screens */

@media (max-width: 640px) {
  :root { --card-w: 58px; --card-h: 88px; }
  .card .oval { font-size: 22px; }
  .card .corner { font-size: 10px; }
  .swatch { width: 58px; height: 58px; }
  .roomList { max-height: 18vh; }
  #table { padding: 8px; gap: 6px; }
  .log { height: 40px; }
}
