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

:root {
  --felt: #0b5d33;
  --felt-dark: #07401f;
  --card-w: 120px;
  --card-h: 170px;
}

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  color: #fff;
  min-height: 100vh;
  overflow: hidden;
}

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

h1 { font-size: 64px; letter-spacing: 12px; text-shadow: 0 4px 12px rgba(0,0,0,.5); }
h1 .sub { display: block; font-size: 14px; letter-spacing: 4px; font-weight: normal; opacity: .7; text-align: center; }
h1.small { font-size: 40px; letter-spacing: 8px; }

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

.roomList { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; max-width: 760px; }
.roomCard {
  background: rgba(0,0,0,.35);
  border-radius: 14px;
  padding: 22px 28px;
  width: 300px;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
  transition: transform .1s;
}
.roomCard:hover { transform: translateY(-3px); }
.roomCard h3 { font-size: 22px; color: #ffc93c; }
.roomCard p { opacity: .75; font-size: 14px; }

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

.roomHead { display: flex; align-items: center; gap: 20px; }
.roomHead h2 { font-size: 30px; letter-spacing: 3px; color: #ffc93c; }
button.big.small { font-size: 15px; padding: 8px 16px; }

.roomBody { display: flex; gap: 20px; align-items: stretch; flex-wrap: wrap; justify-content: center; }
.playersPanel { min-width: 300px; align-items: stretch; }
.playersPanel h3 { text-align: center; opacity: .8; font-weight: normal; letter-spacing: 2px; }
#playerList { display: flex; flex-direction: column; gap: 8px; min-height: 120px; }
.playerRow {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  background: rgba(255,255,255,.08); border-radius: 8px; padding: 8px 14px; font-size: 17px;
}
.playerRow .tag { font-size: 13px; opacity: .6; font-style: italic; }

.chatPanel { width: 420px; max-width: 90vw; align-items: stretch; gap: 10px; }
#chatLog {
  height: 260px; overflow-y: auto; background: rgba(0,0,0,.3); border-radius: 8px;
  padding: 10px; font-size: 15px; display: flex; flex-direction: column; gap: 4px;
}
.chatLine { word-wrap: break-word; }
.chatLine.sys { opacity: .55; font-style: italic; }
.chatLine b { color: #ffc93c; }
.chatRow { display: flex; gap: 8px; }
#chatInput { flex: 1; text-align: left; font-size: 15px; width: auto; }

#challengeModal, #rulesModal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.btnRow { display: flex; gap: 12px; }

/* ---------- rules ---------- */

.rulesPanel { max-width: 620px; max-height: 86vh; overflow-y: auto; align-items: stretch; }
.rulesPanel h2 { text-align: center; color: #ffc93c; letter-spacing: 2px; }
.rulesText { display: flex; flex-direction: column; gap: 10px; font-size: 16px; line-height: 1.45; }
.rulesText b { color: #ffc93c; }
.rulesText kbd {
  background: rgba(255,255,255,.15); border-radius: 4px; padding: 1px 7px;
  font-family: inherit; font-size: 14px; border: 1px solid rgba(255,255,255,.3);
}
button.mini {
  width: 30px; height: 30px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(255,255,255,.2); color: #fff; font-size: 17px; font-weight: bold;
}
button.mini:hover { background: rgba(255,255,255,.35); }

/* ---------- shared ---------- */

.panel {
  background: rgba(0,0,0,.35);
  border-radius: 16px;
  padding: 28px 36px;
  display: flex; flex-direction: column; gap: 14px; align-items: center;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}

input {
  font-size: 20px; padding: 10px 14px; border-radius: 8px; border: none; outline: none;
  text-align: center; width: 220px;
}

button.big {
  font-size: 20px; font-weight: bold; padding: 12px 28px; border: none; border-radius: 10px;
  background: #e8b021; color: #222; cursor: pointer; transition: transform .08s, background .15s;
}
button.big:hover { background: #ffc93c; transform: translateY(-2px); }
button.big:active { transform: translateY(1px) scale(.97); }
button.big:disabled { background: #777; color: #aaa; cursor: default; transform: none; }
button.big.alt { background: #555; color: #eee; }
button.big.alt:hover { background: #6a6a6a; }

.msg { color: #ffb3b3; min-height: 22px; font-size: 15px; }
.dim { opacity: .6; }

/* ---------- game board ---------- */

#game { justify-content: space-between; padding: 12px 0; gap: 8px; }

#topBar {
  display: flex; gap: 18px; align-items: center; font-size: 18px;
  background: rgba(0,0,0,.3); padding: 8px 22px; border-radius: 10px;
}
.pname { font-weight: bold; }
.count { opacity: .8; font-size: 15px; }
#roundLabel { color: #ffc93c; font-weight: bold; }

.cardRow { display: flex; gap: 16px; min-height: calc(var(--card-h) + 28px); align-items: flex-start; }

#centerRow { display: flex; gap: 48px; align-items: center; }

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

.card {
  width: var(--card-w); height: var(--card-h);
  border-radius: 11px;
  background: #fdfdf6;
  color: #111;
  position: relative;
  box-shadow: 0 3px 8px rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
}
.card .corner {
  position: absolute; top: 7px; left: 9px; font-size: 26px; font-weight: bold; line-height: 1;
  text-align: center;
}
.card .corner.br { top: auto; left: auto; bottom: 7px; right: 9px; transform: rotate(180deg); }
.card .pip { font-size: 58px; }
.card.red { color: #c0392b; }

.card.back {
  background: repeating-linear-gradient(45deg, #1d3f8f, #1d3f8f 7px, #2a55b8 7px, #2a55b8 14px);
  border: 5px solid #fdfdf6;
}

.pileSpot {
  width: var(--card-w); height: var(--card-h);
  border-radius: 11px;
  border: 2px dashed rgba(255,255,255,.35);
  position: relative;
  transition: border-color .12s, background .12s;
}
.badge {
  position: absolute; bottom: -26px; left: 50%; transform: translateX(-50%);
  font-size: 13px; opacity: .75; white-space: nowrap;
}

/* ---------- drag & drop feedback ---------- */

.grabbable { cursor: grab; touch-action: none; transition: transform .1s; }
.grabbable:hover { transform: translateY(-8px); box-shadow: 0 12px 20px rgba(0,0,0,.5); }

.dragGhost {
  position: fixed; z-index: 300; pointer-events: none;
  transform: rotate(4deg) scale(1.06);
  box-shadow: 0 18px 36px rgba(0,0,0,.6);
  opacity: .95;
}
.dragGhost.flyBack { transition: left .17s ease-in, top .17s ease-in; transform: none; }

/* opponent's card in flight */
.oppGhost {
  position: fixed; z-index: 250; pointer-events: none;
  transition: left .3s ease, top .3s ease;
  box-shadow: 0 14px 28px rgba(0,0,0,.55);
}

.dragSource { opacity: .35; }

.dragOver {
  outline: 5px solid #7CFC7C;
  outline-offset: -2px;
  filter: drop-shadow(0 0 14px #7CFC7C);
}
.pileSpot.dragOver { border-color: #7CFC7C; background: rgba(124,252,124,.12); }

.dragBad {
  outline: 5px solid #ff5f5f;
  outline-offset: -2px;
  filter: drop-shadow(0 0 12px #ff5f5f);
}

.shake { animation: shake .35s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}

/* a freshly landed card pops */
.card.pop { animation: pop .25s ease-out; }
@keyframes pop {
  0% { transform: scale(1.35) rotate(-3deg); box-shadow: 0 16px 30px rgba(0,0,0,.6); }
  100% { transform: scale(1) rotate(0); }
}

/* ---------- center piles / slap ---------- */

.centerPile { position: relative; }
.slapMode .centerPile { cursor: pointer; animation: pulse .5s infinite alternate; }
@keyframes pulse {
  from { filter: drop-shadow(0 0 4px #ffc93c); }
  to   { filter: drop-shadow(0 0 20px #ffc93c); }
}

#flash {
  position: fixed; inset: 0; pointer-events: none; z-index: 90;
  background: #fff; opacity: 0;
}
#flash.go { animation: flash .3s ease-out; }
@keyframes flash {
  0% { opacity: .55; }
  100% { opacity: 0; }
}

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

#controls { min-height: 64px; }
#spitBtn { background: #d43a3a; color: #fff; letter-spacing: 3px; }
#spitBtn:hover { background: #f04c4c; }
#spitBtn.waitingOther { background: #8a6; }

#banner {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.75); padding: 12px 30px; border-radius: 12px;
  font-size: 22px; font-weight: bold; color: #ffc93c; pointer-events: none;
  z-index: 50;
  animation: bannerIn .25s ease-out;
}
@keyframes bannerIn {
  from { transform: translateX(-50%) translateY(-16px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0); opacity: 1; }
}

#overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}

@media (max-width: 900px) {
  :root { --card-w: 84px; --card-h: 120px; }
  .card .pip { font-size: 38px; }
  .card .corner { font-size: 18px; }
  #centerRow { gap: 24px; }
  .cardRow { gap: 10px; }
}
