:root {
  --felt: #1a5c38;
  --bg: #0d2318;
  --gold: #e8c34a;
  --ink: #1c2430;
  --card-w: 62px;
  --card-h: 88px;

  /* Original, simple flat colors for card faces — no copied card artwork. */
  --c-red: #d64545;
  --c-yellow: #d6b845;
  --c-green: #3fa15e;
  --c-blue: #3f7fd6;
  --c-black: #2b2b32;
}

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

html, body {
  min-height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: radial-gradient(ellipse at 50% 30%, var(--felt) 0%, var(--bg) 90%);
  color: #eef3ee;
  overflow-x: hidden;
}

.hidden { display: none !important; }
.view { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; }

/* ------------------------------ home / lobby ------------------------------ */

.home-card {
  background: rgba(10, 26, 18, 0.75);
  border: 1px solid rgba(232, 195, 74, 0.25);
  border-radius: 16px;
  padding: 40px 48px;
  display: flex; flex-direction: column; gap: 14px;
  align-items: center; min-width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

.logo { font-size: 2rem; letter-spacing: 1px; font-weight: 800; color: #fff; text-align: center; }
.logo span { color: var(--gold); }
.logo.small { font-size: 1rem; }

.tagline { color: #9fbfae; font-size: .85rem; text-align: center; }

input {
  background: #0b1f14; color: #fff; border: 1px solid #2e5941;
  border-radius: 8px; padding: 12px 14px; font-size: 1rem; width: 100%;
  text-align: center; outline: none;
}
input:focus { border-color: var(--gold); }
#code-input { text-transform: uppercase; letter-spacing: 6px; font-weight: 700; }

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

.btn {
  background: #274c38; color: #fff; border: 1px solid #3c7154;
  padding: 12px 22px; border-radius: 8px; font-size: 1rem; cursor: pointer;
  width: 100%; transition: transform .08s, background .15s;
}
.btn:hover:not(:disabled) { background: #336249; transform: translateY(-1px); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.primary { background: var(--gold); border-color: #b8952c; color: var(--ink); font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: #f2d269; }
.btn.subtle { background: transparent; border-color: #33503f; color: #8fae9c; }
.btn.tiny { width: auto; padding: 5px 14px; font-size: .8rem; }

.status { color: #9fbfae; font-size: .85rem; min-height: 1.2em; text-align: center; }

.room-code {
  background: #0b1f14; border: 1px dashed var(--gold); color: var(--gold);
  padding: 4px 14px; border-radius: 8px; letter-spacing: 6px; font-weight: 800;
}
.room-code.small { font-size: .8rem; padding: 2px 10px; letter-spacing: 3px; }

.menu-link { color: #8fae9c; font-size: .8rem; text-decoration: none; margin-top: 4px; }
.menu-link:hover { color: var(--gold); }

.lobby-list { list-style: none; width: 100%; }
.lobby-list li {
  padding: 9px 14px; border-bottom: 1px solid #234534;
  display: flex; justify-content: space-between; font-size: 1rem;
}
.lobby-list .host-tag { color: var(--gold); font-size: .8rem; }

/* ------------------------------ game layout ------------------------------ */

/* Fixed-height flex column that never scrolls (see fitGame in client.js,
   which shrinks the card size until the board fits any viewport). */
#view-game {
  justify-content: space-between;
  height: 100dvh; overflow: hidden; gap: 4px;
  /* Keep clear of notches / rounded corners on modern phones. */
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.top-bar { width: 100%; display: flex; justify-content: flex-end; align-items: center; color: #9fbfae; font-size: .9rem; position: relative; flex-shrink: 0; }
#round-label {
  position: absolute; left: 50%; top: 2px; transform: translateX(-50%);
  color: #cfe8da; font-size: .85rem; white-space: nowrap;
}
.top-right { display: flex; gap: 8px; align-items: center; }

.opponents { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 4px; min-height: 96px; }

.seat {
  background: #16302257; border: 2px solid transparent; border-radius: 12px;
  padding: 8px 12px; text-align: center; min-width: 100px; position: relative;
  transition: border-color .2s, box-shadow .2s, opacity .2s;
}
.seat.turn { border-color: var(--gold); box-shadow: 0 0 18px rgba(232,195,74,.45); animation: pulse 1.6s infinite; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 10px rgba(232,195,74,.35); }
  50% { box-shadow: 0 0 22px rgba(232,195,74,.65); }
}
.seat.finished { opacity: .55; }
.seat.eliminated { opacity: .4; filter: grayscale(.6); }
.seat.gone { opacity: .3; filter: grayscale(1); }
.seat .seat-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.seat .seat-count { font-size: .85rem; color: #bcd8c8; }
.seat .badges { display: flex; gap: 4px; justify-content: center; margin-top: 3px; flex-wrap: wrap; }
.badge { font-size: .62rem; padding: 1px 7px; border-radius: 9px; font-weight: 700; letter-spacing: .3px; }
.badge.uno { background: var(--gold); color: var(--ink); animation: pulse 1s infinite; }
.badge.finished { background: #2c5340; color: #cfe8da; }
.badge.eliminated { background: #6b2a2a; color: #f0c9c9; }
.badge.offline { background: var(--c-red); color: #fff; }
.badge.host { background: #3a6d54; color: #dff0e6; }

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

.table-zone { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.table-row { display: flex; align-items: center; gap: 28px; }
.deck-pile { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pile-count { font-size: .8rem; color: #9fbfae; }
.discard-area { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.color-indicator { width: 100%; text-align: center; font-size: .78rem; text-transform: uppercase; letter-spacing: 2px; }
.pending-draw { color: var(--c-red); font-weight: 800; font-size: 1.05rem; min-height: 1.3em; }
.direction-label { color: #9fbfae; font-size: .85rem; }

.turn-banner { text-align: center; font-size: 1.05rem; font-weight: 700; min-height: 1.5em; color: var(--gold); }
.turn-banner.waiting { color: #9fbfae; font-weight: 400; }
.turn-timer { text-align: center; font-size: .9rem; color: #9fbfae; min-height: 1.2em; }
.turn-timer.urgent { color: var(--c-red); font-weight: 800; animation: pulse 1s infinite; }

/* ------------------------------ cards ------------------------------ */
/* Card faces/backs are the real "soft squish" UNO SVG deck (public/cards/)
   for every card type it covers — the <img> IS the card. No Mercy's extra
   specialty cards without matching art (see cardSvgSrc in client.js) fall
   back to the original flat-color + glyph/label rendering below. */

.card {
  width: var(--card-w); height: var(--card-h);
  border-radius: 10px; border: 2px solid rgba(255,255,255,.25);
  color: #fff; position: relative; flex-shrink: 0;
  box-shadow: 0 3px 8px rgba(0,0,0,.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 800; user-select: none; text-align: center; padding: 4px;
}
.card img { width: 100%; height: 100%; display: block; border-radius: 10px; }
.card.color-red { background: var(--c-red); }
.card.color-yellow { background: var(--c-yellow); color: #241d05; }
.card.color-green { background: var(--c-green); }
.card.color-blue { background: var(--c-blue); }
.card.color-black { background: var(--c-black); background-image: linear-gradient(135deg, #d64545 0 25%, #d6b845 25% 50%, #3fa15e 50% 75%, #3f7fd6 75% 100%); }
.card .card-value { font-size: 1.3rem; line-height: 1.1; }
.card .card-label { font-size: .62rem; line-height: 1.15; margin-top: 2px; opacity: .92; }
.card.back {
  background: url('cards/card-back.svg') center / cover no-repeat;
  border: none;
}
.card.mini { width: 30px; height: 42px; border-radius: 5px; }
.card.mini .card-value { font-size: .65rem; }
.card.mini .card-label { display: none; }
.card.empty { background: rgba(255,255,255,.06); border: 1px dashed rgba(255,255,255,.25); box-shadow: none; }

.hand .card { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.hand .card:hover { transform: translateY(-8px); }
.hand .card.selected { transform: translateY(-16px); box-shadow: 0 0 0 3px var(--gold), 0 10px 18px rgba(0,0,0,.5); }

/* ------------------------------ color picker / swap picker ------------------------------ */

.color-picker, .swap-picker {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: rgba(10,26,18,.85); border: 1px solid rgba(232,195,74,.3);
  border-radius: 12px; padding: 16px 20px;
}
.color-choices { display: flex; gap: 10px; }
.color-btn {
  width: 56px; height: 56px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4);
  cursor: pointer; font-size: .7rem; font-weight: 800; color: #fff;
}
.color-btn.red { background: var(--c-red); }
.color-btn.yellow { background: var(--c-yellow); color: #241d05; }
.color-btn.green { background: var(--c-green); }
.color-btn.blue { background: var(--c-blue); }
.color-btn:hover { transform: scale(1.08); }

.swap-choices { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.swap-choices .btn { width: auto; }

/* ------------------------------ hand zone ------------------------------ */

.hand-zone { width: 100%; display: flex; flex-direction: column; gap: 8px; align-items: center; padding-bottom: 4px; flex-shrink: 0; }
/* Wrap instead of horizontal-scroll — no scrollbars in-game (fitGame shrinks
   the cards so even a big Mercy-Rule hand fits). */
.hand { display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-end; padding: 14px 10px 4px; max-width: 100%; gap: 4px; }
.opponents { flex-shrink: 0; }
.actions { display: flex; gap: 12px; }
.actions .btn { width: 140px; }

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

.overlay { position: fixed; inset: 0; background: rgba(4, 12, 8, 0.82); display: flex; align-items: center; justify-content: center; z-index: 50; }
.panel {
  background: #12271b; border: 1px solid rgba(232,195,74,.3); border-radius: 16px;
  padding: 30px 36px; display: flex; flex-direction: column; gap: 14px;
  align-items: center; max-width: 92vw; max-height: 88vh; overflow-y: auto;
}
.rankings { list-style: none; width: 100%; min-width: 280px; }
.rankings li { display: flex; justify-content: space-between; gap: 20px; padding: 8px 12px; border-bottom: 1px solid #234534; font-size: 1.05rem; }
.rankings li:first-child { background: rgba(232,195,74,.12); border-radius: 8px; }
.rankings .tag-elim { color: #f0c9c9; font-size: .8rem; }

/* ------------------------------ rulebook ------------------------------ */

.rules-btn {
  position: fixed; top: 14px; left: 14px; z-index: 96;
  background: #16302298; border: 1px solid #3c7154; color: #cfe8da;
  padding: 7px 14px; border-radius: 20px; font-size: .85rem; cursor: pointer;
  backdrop-filter: blur(4px);
}
.rules-btn:hover { background: #234534; }
.rules-panel { max-width: 560px; text-align: left; }
.rules-panel h2 { text-align: center; }
.rules-body { max-height: 50vh; overflow-y: auto; font-size: .92rem; line-height: 1.6; color: #eef3ee; }
.rules-body ul { list-style: disc; padding-left: 1.3em; display: flex; flex-direction: column; gap: 8px; }
.rules-body strong { color: var(--gold); }

/* ------------------------------ log & toast ------------------------------ */

.log {
  position: fixed; left: 10px; bottom: 10px; width: 230px; max-height: 26vh;
  overflow-y: auto; font-size: .74rem; color: #9fbfae;
  background: rgba(8,20,13,.6); border-radius: 8px; padding: 8px 10px;
  pointer-events: none;
}
.log div { padding: 1px 0; }
.log div:last-child { color: #e6f2ea; }

#toast-holder { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center; }
.toast {
  background: #26483573; backdrop-filter: blur(6px); border: 1px solid #3c7154; color: #fff;
  padding: 10px 22px; border-radius: 24px; font-size: .95rem; animation: toastin .25s ease-out;
  box-shadow: 0 6px 20px rgba(0,0,0,.45);
}
.toast.error { background: #5a2626d9; border-color: #a04545; }
@keyframes toastin { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }

/* Touch devices: no hover-lift (sticks after a tap; tap already selects). */
@media (hover: none) {
  .hand .card:hover { transform: none; }
  .color-btn:hover { transform: none; }
}

@media (max-width: 640px) {
  /* Card size is driven by fitGame (JS) in-game. */
  .home-card { padding: 28px 20px; min-width: 0; width: min(360px, calc(100vw - 24px)); }
  .log { display: none; }
  .seat { min-width: 78px; padding: 5px 7px; }

  /* Slim the top bar so the fixed Rules button and the right-hand controls
     never collide; the centered status label is dropped on phones. */
  #round-label { display: none; }
  .rules-btn { top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); padding: 6px 11px; font-size: .78rem; }
  .top-bar { font-size: .8rem; }
  .top-right { gap: 5px; }
  .top-right .menu-link.tiny { font-size: 0; }
  .top-right .menu-link.tiny::after { content: '←'; font-size: 1.1rem; line-height: 1; }
  .room-code.small { letter-spacing: 2px; padding: 2px 7px; }
  .btn.tiny { padding: 4px 9px; }

  /* Action buttons stretch for big tap targets; color picker fits width. */
  .actions { width: 100%; padding: 0 10px; gap: 10px; }
  .actions .btn { width: auto; flex: 1; }
  .color-btn { width: 50px; height: 50px; }

  /* Overlays hug the screen with a small margin. */
  .panel, .rules-panel { max-width: calc(100vw - 20px); padding: 22px 18px; }
}

/* Short viewports (landscape phones): compact the vertical chrome. */
@media (max-height: 500px) {
  #view-game { padding: 4px 10px; }
  .opponents { margin-top: 2px; min-height: 0; gap: 6px; }
  .table-zone { min-height: 0; gap: 4px; }
  .turn-banner { font-size: .9rem; min-height: 1.1em; }
  .turn-timer { font-size: .78rem; min-height: 1em; }
  .direction-label, .color-indicator { font-size: .72rem; }
  .color-btn { width: 42px; height: 42px; }
}
