/* Five Card Cribbage — table styled to match the reference board art */

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

:root {
  --gold: #d9b356;
  --gold-dim: rgba(217, 179, 86, 0.55);
  --gold-faint: rgba(217, 179, 86, 0.32);
  --felt-dark: #0c3a1d;
  --serif: 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
}

html, body {
  width: 100%; height: 100%;
  background: #0a0603;
  overflow: hidden;
  font-family: var(--serif);
  touch-action: none;
}

/* ---------- board scaling: fixed 1435x1080 design space ---------- */
#stage {
  position: absolute; left: 50%; top: 50%;
  width: 1435px; height: 1080px;
  transform-origin: center center;
}

/* ---------- wood frame + felt ---------- */
#board {
  position: absolute; inset: 10px;
  border-radius: 34px;
  background:
    repeating-linear-gradient(93deg, rgba(0,0,0,0.18) 0 3px, rgba(255,255,255,0.03) 3px 7px, rgba(0,0,0,0.10) 7px 13px),
    linear-gradient(180deg, #6b3f18 0%, #7d4c1e 18%, #5b3413 50%, #74461c 82%, #4e2c0f 100%);
  box-shadow: 0 0 60px rgba(0,0,0,0.9), inset 0 0 18px rgba(0,0,0,0.6);
  padding: 34px;
}
#felt {
  position: absolute; inset: 34px;
  border-radius: 18px;
  background:
    radial-gradient(ellipse at 52% 42%, #1d7c40 0%, #176333 45%, #104b25 75%, #0b3a1c 100%);
  box-shadow: inset 0 0 55px rgba(0,0,0,0.55), inset 0 0 6px rgba(0,0,0,0.8);
}
.corner {
  position: absolute; width: 46px; height: 46px; z-index: 5; pointer-events: none;
  border: 3px solid rgba(216, 178, 90, 0.75); filter: drop-shadow(0 0 2px rgba(0,0,0,.8));
}
.corner.tl { left: 22px; top: 22px; border-right: none; border-bottom: none; border-top-left-radius: 26px; }
.corner.tr { right: 22px; top: 22px; border-left: none; border-bottom: none; border-top-right-radius: 26px; }
.corner.bl { left: 22px; bottom: 22px; border-right: none; border-top: none; border-bottom-left-radius: 26px; }
.corner.br { right: 22px; bottom: 22px; border-left: none; border-top: none; border-bottom-right-radius: 26px; }

/* ---------- left sidebar ---------- */
#sidebar {
  position: absolute; left: 34px; top: 34px; bottom: 34px; width: 242px;
  background: linear-gradient(180deg, #0e4423 0%, #0b3a1d 100%);
  border-top-left-radius: 18px; border-bottom-left-radius: 18px;
  border-right: 10px solid transparent;
  border-image: linear-gradient(180deg, #6b3f18, #4e2c0f) 1;
  box-shadow: inset -14px 0 24px rgba(0,0,0,0.35);
  padding: 22px 18px;
  display: flex; flex-direction: column; align-items: stretch;
  z-index: 3;
}
.gold-heading {
  color: var(--gold); text-align: center; letter-spacing: 2.5px;
  font-size: 23px; font-variant: small-caps; text-transform: uppercase;
  padding: 10px 0; position: relative;
}
.gold-heading.ruled { border-top: 1px solid var(--gold-faint); border-bottom: 1px solid var(--gold-faint); }
#panel-me { margin-top: 30px; }

.player-panel {
  border-radius: 16px; padding: 14px 14px 10px;
  border: 1.5px solid rgba(217,179,86,0.5);
  box-shadow: 0 6px 14px rgba(0,0,0,0.45), inset 0 1px 2px rgba(255,255,255,0.18);
  margin-top: 14px; position: relative;
}
.player-panel.blue { background: linear-gradient(180deg, #16386b 0%, #0d2549 100%); }
.player-panel.red { background: linear-gradient(180deg, #8f1f14 0%, #5d130b 100%); }
.panel-top { display: flex; align-items: center; gap: 12px; }
.peg-ball { width: 44px; height: 58px; position: relative; flex: 0 0 auto; }
.peg-ball .ball {
  position: absolute; top: 0; left: 2px; width: 40px; height: 40px; border-radius: 50%;
}
.peg-ball .stem {
  position: absolute; top: 36px; left: 15px; width: 14px; height: 20px;
  border-radius: 4px 4px 7px 7px;
}
.blue .peg-ball .ball { background: radial-gradient(circle at 32% 28%, #9cc4ff 0%, #2f6fd8 38%, #123a7e 80%); }
.blue .peg-ball .stem { background: linear-gradient(180deg, #2f6fd8, #0e2c60); }
.red .peg-ball .ball { background: radial-gradient(circle at 32% 28%, #ffb09c 0%, #d84a2f 38%, #7e1912 80%); }
.red .peg-ball .stem { background: linear-gradient(180deg, #d84a2f, #5e0f0a); }
.panel-name { color: #fff; font-size: 24px; letter-spacing: 2px; font-variant: small-caps; white-space: nowrap; overflow: hidden; }
.panel-name.turn { animation: nameFlash 1.7s ease-in-out infinite; }
@keyframes nameFlash {
  0%, 100% { opacity: 1; text-shadow: none; }
  50% { opacity: 0.5; text-shadow: 0 0 12px rgba(255, 233, 168, 0.9); }
}
.panel-score { color: #fff; font-size: 58px; font-weight: bold; line-height: 1; text-shadow: 0 2px 6px rgba(0,0,0,0.6); }
.pegs-row {
  margin-top: 10px; border-radius: 9px; padding: 5px 12px;
  background: rgba(0,0,0,0.32); display: flex; align-items: center; gap: 10px;
}
.pegs-row .lbl { color: var(--gold); font-size: 15px; letter-spacing: 2px; }
.mini-peg { width: 17px; height: 17px; border-radius: 50%; }
.blue .mini-peg { background: radial-gradient(circle at 32% 28%, #9cc4ff, #1c4f9e 75%); }
.red .mini-peg { background: radial-gradient(circle at 32% 28%, #ffb09c, #9e2a1c 75%); }

.side-box {
  margin-top: 18px; border: 1.5px solid var(--gold-dim); border-radius: 12px;
  padding: 10px 12px 12px; text-align: center; background: rgba(0,0,0,0.12);
}
.side-box .title {
  color: var(--gold); font-size: 22px; letter-spacing: 2.5px; font-variant: small-caps;
  border-bottom: 1px solid var(--gold-faint); padding-bottom: 7px; margin-bottom: 9px;
}
.side-box .body { color: #f3e7c8; font-size: 21px; line-height: 1.25; min-height: 28px; }
#actionBox { cursor: default; }
#actionBox.pressable { cursor: pointer; animation: pulse 1.1s ease-in-out infinite; border-color: var(--gold); background: rgba(217,179,86,0.10); }
#actionBox.pressable .title { color: #ffe9a8; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217,179,86,0.0); }
  50% { box-shadow: 0 0 22px 4px rgba(217,179,86,0.55); }
}

/* big score popup under a player's panel */
.score-pop {
  position: absolute; left: 4px; right: 4px; text-align: center;
  font-size: 92px; font-weight: bold; color: #16386b; line-height: 1.02;
  text-shadow: 0 0 4px rgba(255,255,255,0.55), 0 0 18px rgba(93,114,192,0.95), 0 3px 8px rgba(0,0,0,0.8);
  background: rgba(5, 24, 12, 0.88); border-radius: 14px; padding: 4px 0 10px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.55);
  pointer-events: none; z-index: 40; opacity: 0;
}
.score-pop .why { display: block; font-size: 22px; letter-spacing: 2px; color: var(--gold); font-weight: normal; }
.score-pop.show { animation: popIn 0.45s ease-out forwards; }
@keyframes popIn { from { opacity: 0; transform: scale(0.3); } to { opacity: 1; transform: scale(1); } }
.score-pop.fly { transition: transform 0.7s ease-in, opacity 0.7s ease-in; }

/* ---------- main table zones ---------- */
.zone-label {
  position: absolute; color: var(--gold); font-size: 25px; letter-spacing: 3px;
  font-variant: small-caps; text-transform: uppercase; text-align: center; transform: translateX(-50%);
  z-index: 2; pointer-events: none; text-shadow: 0 2px 4px rgba(0,0,0,0.6);
}
.dashed-zone {
  position: absolute; border: 1.6px dashed var(--gold-faint); border-radius: 16px; z-index: 1;
}
#pegLine { position: absolute; pointer-events: none; opacity: 0.55; }
#lbl-hand { color: #c5301f; text-shadow: 0 0 3px rgba(255,255,255,0.35), 0 2px 4px rgba(0,0,0,0.6); }
#lbl-opphand { color: #16386b; text-shadow: 0 0 3px rgba(255,255,255,0.35), 0 2px 4px rgba(0,0,0,0.6); }

#cribEmblem { position: absolute; pointer-events: none; opacity: 0.5; }
#cribCount {
  position: absolute; color: var(--gold); font-size: 24px; letter-spacing: 3px;
  transform: translateX(-50%); text-align: center; font-variant: small-caps; z-index: 28;
  width: 260px; text-shadow: 0 0 4px rgba(240,237,226,0.75), 0 2px 6px rgba(0,0,0,0.7);
}

/* deck stack (static backs) */
.deck-back { position: absolute; z-index: 2; }
#deckHot { position: absolute; z-index: 30; border-radius: 12px; cursor: pointer; display: none; }
#deckHot.glow { display: block; animation: deckGlow 1.1s ease-in-out infinite; }
@keyframes deckGlow {
  0%, 100% { box-shadow: 0 0 0 3px rgba(217,179,86,0.25); }
  50% { box-shadow: 0 0 30px 8px rgba(255, 226, 140, 0.8); }
}

/* pegging running count */
#pegCount {
  position: absolute; color: #16386b; font-size: 46px; letter-spacing: 2px; z-index: 6;
  transform: translateX(-50%); text-align: center; text-shadow: 0 0 14px rgba(0,0,0,0.8);
  font-variant: small-caps; display: none;
}
#pegCount b { color: #16386b; font-size: 56px; text-shadow: 0 0 4px rgba(255,255,255,0.55), 0 0 16px rgba(93,114,192,0.9); }

/* center announcement (pegging scores, go, etc.) */
#announce {
  position: absolute; left: 50%; transform: translateX(-50%);
  color: #ffe9a8; font-size: 58px; letter-spacing: 3px; font-variant: small-caps;
  text-shadow: 0 0 20px rgba(255, 215, 120, 0.85), 0 3px 10px rgba(0,0,0,0.9);
  z-index: 45; pointer-events: none; opacity: 0; text-align: center; white-space: nowrap;
}
#announce .num {
  color: #16161c; font-weight: bold;
  text-shadow: 0 0 5px rgba(255,255,255,0.85), 0 0 16px rgba(255,255,255,0.45);
}
#announce.show { animation: annIn 0.4s ease-out forwards; }
@keyframes annIn { from { opacity: 0; transform: translateX(-50%) scale(0.5); } to { opacity: 1; transform: translateX(-50%) scale(1); } }

/* accumulating points shown big above the counting row */
#countAcc {
  position: absolute; left: 50%; transform: translateX(-50%);
  text-align: center; z-index: 44; pointer-events: none; display: none;
  color: #ffe9a8; font-variant: small-caps; letter-spacing: 2px; white-space: nowrap;
  text-shadow: 0 0 16px rgba(255, 215, 120, 0.8), 0 3px 8px rgba(0,0,0,0.85);
}
#countAcc .lbl { font-size: 26px; color: var(--gold); display: block; letter-spacing: 3px; }
#countAcc b {
  font-size: 84px; line-height: 1; display: block; color: #16386b;
  text-shadow: 0 0 4px rgba(255,255,255,0.55), 0 0 18px rgba(93,114,192,0.95), 0 3px 8px rgba(0,0,0,0.85);
}
#countAcc.bump b { animation: accBump 0.5s ease; }
@keyframes accBump { 0% { transform: scale(1.55); } 100% { transform: scale(1); } }

/* counting-phase helper text + claim flash */
#countHelp {
  position: absolute; left: 50%; transform: translateX(-50%); text-align: center;
  color: #e9dcb6; font-size: 23px; line-height: 1.35; z-index: 6; pointer-events: none; display: none;
  text-shadow: 0 2px 4px rgba(0,0,0,0.8); letter-spacing: 0.5px; width: 820px;
}
#countHelp b { color: #ffe9a8; }
.claim-flash {
  position: absolute; z-index: 46; pointer-events: none; text-align: center; white-space: nowrap;
  color: #6d1109; font-size: 44px; font-variant: small-caps; letter-spacing: 2px;
  text-shadow: 0 0 4px rgba(255,255,255,0.55), 0 0 14px rgba(255,120,100,0.55), 0 3px 8px rgba(0,0,0,0.9);
  transform: translate(-50%, -50%);
  animation: claimUp 2.6s ease-out forwards;
}
.claim-flash .pts {
  color: #16386b;
  text-shadow: 0 0 4px rgba(255,255,255,0.6), 0 0 16px rgba(93,114,192,0.95), 0 3px 8px rgba(0,0,0,0.9);
}
.claim-flash.bad { color: #ffb9a8; text-shadow: 0 0 14px rgba(255,120,80,0.8), 0 3px 8px rgba(0,0,0,0.9); font-size: 30px; }
@keyframes claimUp {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  75% { opacity: 1; transform: translate(-50%, -90%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(0.9); }
}

/* big action buttons on the felt */
.felt-btn {
  position: absolute; z-index: 35; transform: translateX(-50%);
  background: linear-gradient(180deg, #e8c977 0%, #c69a3e 55%, #a87d28 100%);
  color: #2a1c05; border: 2px solid #f4e2ad; border-radius: 14px;
  font-family: var(--serif); font-size: 30px; letter-spacing: 2px; font-variant: small-caps;
  padding: 12px 34px; cursor: pointer; display: none;
  box-shadow: 0 6px 16px rgba(0,0,0,0.6), inset 0 1px 2px rgba(255,255,255,0.6);
}
.felt-btn.show { display: block; animation: pulse 1.2s ease-in-out infinite; }
.felt-btn:active { transform: translateX(-50%) scale(0.96); }

/* ---------- cards ---------- */
.card {
  position: absolute; width: 126px; height: 192px; z-index: 10;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(.35,1.1,.45,1), opacity 0.4s;
  will-change: transform;
}
.card .inner {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transition: transform 0.5s ease; border-radius: 11px;
}
.card.down .inner { transform: rotateY(180deg); }
.card .face {
  position: absolute; inset: 0; border-radius: 11px; backface-visibility: hidden;
  -webkit-backface-visibility: hidden; overflow: hidden;
}
.card .front {
  background: #fff;
  border: 1px solid #b9b2a0;
  box-shadow: 0 5px 12px rgba(0,0,0,0.45);
}
.card .front img {
  width: 100%; height: 100%; display: block;
  pointer-events: none; user-select: none; -webkit-user-drag: none;
}
.card .back {
  transform: rotateY(180deg);
  border: 6px solid #f0ede2;
  box-shadow: 0 5px 12px rgba(0,0,0,0.45);
  background-color: #23346f;
}
.card.dragging { transition: none; z-index: 200 !important; }
.card.dragging .front, .card.dragging .back { box-shadow: 0 18px 34px rgba(0,0,0,0.6); }
.card.raised { filter: drop-shadow(0 0 12px rgba(255, 226, 140, 0.85)); }
.card.glowing { filter: drop-shadow(0 0 10px rgba(255, 226, 140, 0.75)); }
.card.dim .front { filter: brightness(0.75); }
.card.shake { animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { margin-left: 0; } 25% { margin-left: -9px; } 50% { margin-left: 9px; } 75% { margin-left: -5px; }
}
.card.starterGlow { filter: drop-shadow(0 0 14px rgba(140, 220, 255, 0.9)); }

.idx { position: absolute; text-align: center; line-height: 0.95; font-weight: bold; font-family: Georgia, serif; }
.idx .r { font-size: 34px; display: block; }
.idx .s { font-size: 26px; display: block; }
.idx.tl { top: 7px; left: 8px; }
.idx.br { bottom: 7px; right: 8px; transform: rotate(180deg); }
.red-c { color: #c0222c; }
.black-c { color: #1c1c24; }
.pip { position: absolute; font-size: 30px; transform: translate(-50%, -50%); font-family: Georgia, serif; }
.pip.flip { transform: translate(-50%, -50%) rotate(180deg); }
.court {
  position: absolute; inset: 26px 20px; border: 2px solid currentColor; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
}
.court::before { content: ''; position: absolute; inset: 4px; border: 1px solid currentColor; border-radius: 4px; opacity: 0.6; }
.court .big { font-size: 64px; font-weight: bold; font-family: Georgia, serif; line-height: 1; }
.court .suit { font-size: 44px; margin-top: 6px; }

/* ---------- overlays (lobby / winner) ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 100; display: none;
  align-items: center; justify-content: center;
  background: rgba(4, 12, 6, 0.72);
}
.overlay.show { display: flex; }
.panel {
  background: linear-gradient(180deg, #0f4a26 0%, #0a3519 100%);
  border: 2px solid var(--gold-dim); border-radius: 22px;
  padding: 44px 60px; text-align: center; max-width: 760px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}
.panel h1 { color: var(--gold); font-size: 52px; letter-spacing: 4px; font-variant: small-caps; margin-bottom: 6px; }
.panel .sub { color: #cfe3c9; font-size: 24px; margin-bottom: 30px; }
.big-btn {
  display: block; width: 440px; margin: 16px auto 0;
  background: linear-gradient(180deg, #e8c977 0%, #c69a3e 55%, #a87d28 100%);
  border: 2px solid #f4e2ad; border-radius: 16px; color: #2a1c05;
  font-family: var(--serif); font-size: 33px; letter-spacing: 2px; font-variant: small-caps;
  padding: 18px 20px; cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,0,0,0.5), inset 0 1px 2px rgba(255,255,255,0.6);
}
.big-btn.secondary { background: linear-gradient(180deg, #29663f, #17482a); color: #ffe9a8; border-color: var(--gold-dim); }
.big-btn:active { transform: scale(0.97); }
.panel input {
  display: block; width: 440px; margin: 18px auto 0; padding: 14px 18px;
  font-family: var(--serif); font-size: 30px; text-align: center; letter-spacing: 4px;
  border-radius: 12px; border: 2px solid var(--gold-dim); background: #0c2a15; color: #ffe9a8;
  text-transform: uppercase; outline: none;
}
.panel .note { color: #9fc0a0; font-size: 20px; margin-top: 22px; line-height: 1.4; }
.panel .code-show {
  color: #ffe9a8; font-size: 86px; letter-spacing: 18px; margin: 14px 0 4px; font-weight: bold;
  text-shadow: 0 0 24px rgba(255, 220, 130, 0.7);
}
.linkish { color: #9fc0a0; font-size: 20px; margin-top: 26px; cursor: pointer; text-decoration: underline; }

#winBanner {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%);
  z-index: 130; text-align: center; display: none; pointer-events: none;
}
#winBanner .who {
  color: #ffe9a8; font-size: 110px; letter-spacing: 6px; font-variant: small-caps; font-weight: bold;
  text-shadow: 0 0 34px rgba(255, 216, 120, 0.95), 0 6px 18px rgba(0,0,0,0.9);
}
#winBanner .wins { color: var(--gold); font-size: 56px; letter-spacing: 10px; font-variant: small-caps; }
#playAgain { position: absolute; left: 50%; top: 62%; z-index: 130; }
#fireworks { position: absolute; inset: 0; z-index: 120; pointer-events: none; display: none; }

/* toast for connection status */
#toast {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  background: rgba(0,0,0,0.75); color: #ffe9a8; font-size: 20px; font-family: var(--serif);
  padding: 8px 22px; border-radius: 10px; z-index: 140; display: none; letter-spacing: 1px;
}
