/* Classic Crib — clean cribbage table. Green felt, warm brass accent. */
:root {
  --felt: #12331f;
  --felt2: #0d2618;
  --wood: #3a2415;
  --brass: #e0b64a;
  --brass-d: #b8902f;
  --ink: #f3ece0;
  --muted: #9fb0a2;
  --card-bg: #fbf7ee;
  --card-red: #c02b2b;
  --card-blk: #1c2530;
  --panel: #14231a;
  --line: rgba(224,182,74,0.22);
  --good: #2ed573;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 50% -10%, #1c4a2c 0%, var(--felt) 42%, var(--felt2) 100%);
  overflow: hidden;
  user-select: none;
}
.hidden { display: none !important; }
h1, h2, .title, .phase, .lobbylabel { font-family: 'Bitter', Georgia, serif; }

#stage { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- buttons ---------- */
.btn {
  font-family: 'Nunito', sans-serif; font-weight: 900; letter-spacing: .04em;
  border: none; border-radius: 12px; cursor: pointer;
  background: linear-gradient(180deg, var(--brass), var(--brass-d));
  color: #241a06; padding: 11px 20px; font-size: 15px;
  box-shadow: 0 3px 0 #7c5f1c, 0 6px 16px rgba(0,0,0,.35);
  transition: transform .08s, box-shadow .08s, opacity .15s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 #7c5f1c, 0 2px 8px rgba(0,0,0,.35); }
.btn.big { padding: 14px 28px; font-size: 17px; width: 100%; }
.btn.ghost {
  background: transparent; color: var(--brass); border: 2px solid var(--line);
  box-shadow: none; text-decoration: none; display: inline-block; text-align: center;
}
.btn.ghost:active { transform: translateY(2px); }
.btn:disabled { opacity: .4; cursor: default; pointer-events: none; }
.iconbtn {
  background: rgba(0,0,0,.25); border: 1px solid var(--line); color: var(--ink);
  width: 34px; height: 34px; border-radius: 9px; font-size: 16px; cursor: pointer; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.iconbtn.off { opacity: .38; }
.hint { color: var(--muted); font-size: 13px; font-weight: 700; }

/* ================= overlay panels ================= */
#overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, rgba(0,0,0,.35), rgba(0,0,0,.72)); z-index: 40; padding: 20px; }
.panel {
  width: min(400px, 94vw); background: linear-gradient(180deg, #1a2c20, #101c14);
  border: 1px solid var(--line); border-radius: 20px; padding: 30px 26px;
  text-align: center; box-shadow: 0 24px 70px rgba(0,0,0,.6); animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.title { font-size: 44px; line-height: .95; letter-spacing: .02em; color: var(--brass);
  text-shadow: 0 2px 0 rgba(0,0,0,.4); }
.tagline { color: var(--muted); margin-top: 8px; font-weight: 700; font-size: 14px; }
input {
  width: 100%; margin-top: 16px; padding: 13px 15px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(0,0,0,.28); color: var(--ink);
  font-family: 'Nunito'; font-weight: 800; font-size: 16px; text-align: center; outline: none;
}
input:focus { border-color: var(--brass); }
#createBtn { margin-top: 14px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted);
  font-size: 12px; font-weight: 800; margin: 18px 0 6px; text-transform: uppercase; letter-spacing: .1em; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.joinrow { display: flex; gap: 10px; }
.joinrow input { margin-top: 0; text-transform: uppercase; letter-spacing: .3em; }
.joinrow .btn { flex-shrink: 0; }
.error { color: #ff8b8b; margin-top: 12px; font-weight: 800; font-size: 14px; }

/* lobby */
.lobbylabel { font-size: 12px; letter-spacing: .2em; color: var(--muted); }
#codeBig { font-family: 'Bitter'; font-size: 52px; letter-spacing: .12em; color: var(--brass);
  margin: 4px 0 12px; text-shadow: 0 2px 0 rgba(0,0,0,.4); }
#copyBtn { font-size: 13px; padding: 8px 14px; }
#playerList { margin: 18px 0; display: flex; flex-direction: column; gap: 8px; }
.plrow { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,.22);
  border: 1px solid var(--line); border-radius: 11px; padding: 9px 13px; font-weight: 800; }
.plrow .dot2 { width: 13px; height: 13px; border-radius: 50%; flex-shrink: 0; }
.plrow .crown { margin-left: auto; font-size: 13px; color: var(--brass); }
.plrow.off { opacity: .45; }
#lobbyHint { margin-top: 8px; }

/* gameover */
#overEmoji { font-size: 58px; }
#overTitle { font-size: 30px; color: var(--brass); margin-top: 6px; }
#overStats { margin: 18px 0; display: flex; flex-direction: column; gap: 7px; }
.ovrow { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,.22);
  border: 1px solid var(--line); border-radius: 11px; padding: 9px 13px; font-weight: 800; }
.ovrow .osc { margin-left: auto; font-family: 'Bitter'; color: var(--brass); font-size: 18px; }
.ovrow.win { border-color: var(--brass); background: rgba(224,182,74,.12); }

/* ================= table ================= */
#table { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#topbar { display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  background: linear-gradient(180deg, rgba(0,0,0,.32), rgba(0,0,0,0)); }
@media (max-width: 430px) { #handInfo { display: none; } }
#phasePill { font-family: 'Bitter'; font-weight: 800; font-size: 14px; color: var(--brass);
  letter-spacing: .06em; text-transform: uppercase; }
#handInfo { color: var(--muted); font-size: 12.5px; font-weight: 700; }
#timerPill { margin-left: auto; font-weight: 900; font-family: 'Bitter'; font-size: 15px;
  background: rgba(0,0,0,.3); border: 1px solid var(--line); border-radius: 20px; padding: 4px 12px; }
#timerPill.urgent { color: #ff8b8b; border-color: #ff8b8b; }

/* ---- playfield: cribbage board + deck/cut/crib to its side ---- */
#playfield { display: flex; gap: 14px; padding: 8px 14px 6px; justify-content: center;
  align-items: stretch; flex-wrap: wrap; }
#cribbageBoard { flex: 1 1 460px; max-width: 660px; display: flex; flex-direction: column; gap: 5px; }
#pegBoard { width: 100%; }
#pegBoard svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 6px 14px rgba(0,0,0,.5)); }
.hole { fill: #2a1a0b; }
.hole.mark { fill: #241507; }
.hole.end { fill: #e0b64a; stroke: #8a6a1e; stroke-width: 0.7; }
.peg { stroke: #fff8e8; stroke-width: 1.3; filter: drop-shadow(0 1px 1px rgba(0,0,0,.5));
  transition: cx .55s cubic-bezier(.3,1.25,.5,1), cy .55s cubic-bezier(.3,1.25,.5,1); }
.pegback { stroke: rgba(255,248,232,.5); stroke-width: 1;
  transition: cx .5s ease, cy .5s ease, opacity .3s; }
.boardnum { fill: rgba(245,228,190,.55); font: 700 8.5px 'Bitter', serif; text-anchor: middle; }
.boardnum.lbl { fill: rgba(224,182,74,.85); font-size: 9px; font-weight: 800; }
.boardbrand { fill: rgba(245,228,190,.16); font: 700 11px 'Bitter', serif; text-anchor: middle; letter-spacing: 1px; }

#boardLegend { display: flex; flex-wrap: wrap; gap: 4px 8px; justify-content: center; }
.lg { display: flex; align-items: center; gap: 5px; font-weight: 800; font-size: 12px;
  background: rgba(0,0,0,.22); border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; }
.lg .pdot { width: 9px; height: 9px; border-radius: 50%; }
.lg .sc { font-family: 'Bitter'; color: var(--brass); }
.lg .deal { font-size: 9px; color: #241a06; background: var(--brass); border-radius: 3px; padding: 0 3px; font-weight: 900; }
.lg.turn { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass-d); }
.lg.dc { opacity: .5; }

/* ---- deck / cut / crib pile ---- */
#deckArea { display: flex; gap: 12px; align-items: flex-start; justify-content: center; }
.deckslot { display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 54px; }
.slotlabel { font-size: 10px; letter-spacing: .14em; color: var(--muted); font-weight: 800; white-space: nowrap; }
#cribSlot .slotlabel { display: flex; align-items: center; gap: 4px; }
#cribSlot .slotlabel .cdot { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.3); }
#cribSlot.mine .slotlabel { color: var(--brass); }
#cribSlot.mine { filter: drop-shadow(0 0 6px rgba(224,182,74,.35)); }
.deckstack { position: relative; width: 46px; height: 64px; }
.deckstack .card { position: absolute; top: 0; left: 0; --cw: 46px; }
.deckstack.empty::after { content: ''; position: absolute; inset: 0; border: 1px dashed var(--line);
  border-radius: 8px; }
.cardplace { width: 46px; height: 64px; }
#starterCard { --cw: 46px; }
#starterCard .card { --cw: 46px; }

/* felt — the pegging pile + count. top-aligned so it never overlaps the deck row */
#felt { flex: 1; position: relative; display: flex; flex-direction: column; align-items: center;
  justify-content: flex-start; gap: 12px; min-height: 0; padding: 14px 8px 8px; }
#feltMsg { font-family: 'Bitter'; font-weight: 700; font-size: clamp(14px, 3.6vw, 19px);
  color: var(--ink); text-align: center; min-height: 24px; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
#countPill { display: flex; flex-direction: column; align-items: center; line-height: 1;
  background: rgba(0,0,0,.34); border: 1px solid var(--line); border-radius: 14px; padding: 8px 20px; }
#countNum { font-family: 'Bitter'; font-weight: 800; font-size: 30px; color: var(--brass); }
#countPill small { font-size: 9px; letter-spacing: .16em; color: var(--muted); margin-top: 2px; }
.pile { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; max-width: 96vw; min-height: 4px; }

/* ================= cards ================= */
.card {
  position: relative; border-radius: 8px; background: var(--card-bg);
  box-shadow: 0 2px 5px rgba(0,0,0,.4); font-family: 'Bitter', Georgia, serif;
  display: flex; flex-direction: column; justify-content: space-between;
  width: var(--cw, 46px); height: calc(var(--cw, 46px) * 1.4);
  padding: 4px 5px; color: var(--card-blk); flex-shrink: 0;
}
.card .cr { font-weight: 800; font-size: calc(var(--cw, 46px) * 0.34); line-height: 1; }
.card .cs { align-self: flex-end; font-size: calc(var(--cw, 46px) * 0.42); line-height: 1; }
.card.red { color: var(--card-red); }
.card.mini { --cw: 26px; }
.card.back {
  background: repeating-linear-gradient(45deg, #7a2020, #7a2020 5px, #611818 5px, #611818 10px);
  border: 2px solid var(--card-bg); box-shadow: inset 0 0 0 1px #611818, 0 2px 5px rgba(0,0,0,.4);
}
.card.ghost { background: rgba(255,255,255,.06); border: 1px dashed var(--line); box-shadow: none; }
.cardplace { width: var(--cw, 60px); height: calc(var(--cw, 60px) * 1.4); }
#starterCard { --cw: 58px; }
#starterCard .card { --cw: 58px; }
.pile .card { --cw: 52px; animation: lay .22s ease; }
@keyframes lay { from { transform: translateY(-14px) rotate(-6deg); opacity: 0; } }
.pile .card .owner { position: absolute; top: -5px; left: 50%; transform: translateX(-50%);
  width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 0 1.5px var(--felt); }
/* the most recently played card, so you can see what just happened */
.pile .card.last { box-shadow: 0 0 0 2.5px var(--brass), 0 4px 10px rgba(0,0,0,.5); transform: translateY(-4px); }
.pile .card .pegpts { position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%);
  background: var(--brass); color: #241a06; font-family: 'Bitter'; font-weight: 800; font-size: 12px;
  border-radius: 10px; padding: 1px 7px; white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.4); animation: pop .18s ease; }
.pegnote { min-height: 18px; font-weight: 800; font-size: 13.5px; color: var(--brass); text-align: center; }
.pegnote .who { color: var(--ink); }

/* my hand */
#handArea { padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(0deg, rgba(0,0,0,.35), rgba(0,0,0,0)); }
.handlabel { text-align: center; font-size: 12.5px; font-weight: 800; color: var(--muted);
  min-height: 16px; margin-bottom: 4px; }
.handlabel b { color: var(--brass); }
.hand { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; min-height: 4px; }
.hand .card { --cw: clamp(48px, 13.5vw, 66px); cursor: grab; touch-action: none;
  transition: transform .14s, box-shadow .14s; }
.hand .card.sel { transform: translateY(-14px); box-shadow: 0 0 0 3px var(--brass), 0 8px 14px rgba(0,0,0,.45); }
.hand .card.playable { box-shadow: 0 0 0 2px var(--good), 0 2px 6px rgba(0,0,0,.4); }
.hand .card.dead { opacity: .4; }
.hand .card.dead .cr, .hand .card.dead .cs { filter: grayscale(1); }
.hand .card.dragging { transform: translateY(-18px) scale(1.06) rotate(2deg); cursor: grabbing;
  box-shadow: 0 0 0 2px var(--brass), 0 12px 22px rgba(0,0,0,.5); opacity: .95; z-index: 5;
  transition: box-shadow .12s; }

/* sort / reorder controls above the hand */
#handTools { display: flex; align-items: center; gap: 7px; justify-content: center; margin-bottom: 6px; }
#handTools .httitle { font-size: 11px; font-weight: 800; letter-spacing: .1em; color: var(--muted); text-transform: uppercase; }
.chipbtn { font-family: 'Nunito'; font-weight: 800; font-size: 12.5px; color: var(--ink);
  background: rgba(0,0,0,.28); border: 1px solid var(--line); border-radius: 20px;
  padding: 4px 12px; cursor: pointer; transition: background .12s, border-color .12s; }
.chipbtn:active { transform: translateY(1px); }
.chipbtn.on { background: rgba(224,182,74,.16); border-color: var(--brass); color: var(--brass); }
#handTools .hthint { font-size: 11px; font-weight: 700; color: var(--muted); margin-left: 2px; }
@media (max-width: 430px) { #handTools .hthint { display: none; } }
#handActions { display: flex; justify-content: center; gap: 10px; margin-top: 8px; min-height: 4px; }
#handActions .btn { width: auto; min-width: 180px; }
#waitHint { align-self: center; }

/* ================= the show reveal ================= */
#showPanel { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%);
  width: min(440px, 92vw); background: linear-gradient(180deg, #1c2f22, #12211a);
  border: 1px solid var(--brass-d); border-radius: 18px; padding: 18px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.6); z-index: 20; animation: pop .2s ease; }
#showTitle { font-family: 'Bitter'; font-weight: 800; font-size: 18px; margin-bottom: 12px; }
#showTitle .nm { color: var(--brass); }
.showrow { display: flex; gap: 5px; justify-content: center; margin-bottom: 12px; }
.showrow .card { --cw: 46px; }
.showrow .card.starter { box-shadow: 0 0 0 2px var(--brass), 0 2px 5px rgba(0,0,0,.4); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; min-height: 26px; }
.chip { background: rgba(224,182,74,.14); border: 1px solid var(--line); color: var(--ink);
  border-radius: 20px; padding: 4px 11px; font-weight: 800; font-size: 13px; animation: pop .18s ease; }
.chip b { color: var(--brass); }
.chip.zero { color: var(--muted); }
#showTotal { margin-top: 12px; font-family: 'Bitter'; font-weight: 800; font-size: 20px; }
#showTotal .big { color: var(--brass); font-size: 26px; }

/* ================= in-game menu ================= */
#gameMenu { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center;
  justify-content: center; background: rgba(0,0,0,.72); padding: 18px; }
.menuCard { width: min(460px, 94vw); max-height: 92vh; overflow-y: auto;
  background: linear-gradient(180deg, #1a2c20, #101c14); border: 1px solid var(--line);
  border-radius: 20px; padding: 24px; }
.menuTitle { color: var(--brass); font-size: 26px; text-align: center; margin-bottom: 12px; }
.menuHelp p { font-size: 14px; line-height: 1.5; margin-bottom: 10px; color: #d7e0d5; }
.legendLabel { font-size: 11px; letter-spacing: .14em; color: var(--brass); font-weight: 900;
  margin: 14px 0 8px; text-transform: uppercase; }
.legend { display: flex; flex-direction: column; gap: 7px; margin-bottom: 6px; }
.lrow { display: flex; align-items: center; gap: 11px; }
.lico { flex-shrink: 0; width: 30px; height: 30px; display: flex; align-items: center;
  justify-content: center; font-size: 17px; font-weight: 900; background: rgba(0,0,0,.28);
  border: 1px solid var(--line); border-radius: 8px; font-family: 'Bitter'; }
.ltxt { display: flex; flex-direction: column; }
.ltxt b { font-size: 13.5px; }
.ltxt small { font-size: 12px; color: var(--muted); }
#menuResume { margin-top: 14px; }
.menuHubBtn { margin-top: 10px; width: 100%; }

/* ================= game log ================= */
#logPanel { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center;
  justify-content: center; background: rgba(0,0,0,.72); padding: 18px; }
.logCard { width: min(440px, 94vw); max-height: 84vh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #1a2c20, #101c14); border: 1px solid var(--line);
  border-radius: 20px; padding: 18px 20px; }
.logHead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
#logList { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.logrow { font-size: 13.5px; font-weight: 700; color: #d7e0d5; padding: 5px 9px; border-radius: 8px;
  background: rgba(0,0,0,.18); line-height: 1.35; }
.logrow b { color: var(--brass); }
.logrow.score { background: rgba(224,182,74,.12); border: 1px solid var(--line); }
.logrow.hand { background: none; color: var(--brass); font-family: 'Bitter'; font-weight: 800;
  font-size: 12px; letter-spacing: .08em; text-transform: uppercase; margin-top: 8px; padding: 2px 4px; }
.logrow.win { background: rgba(224,182,74,.2); border: 1px solid var(--brass-d); color: var(--ink); }
#logList .logempty { color: var(--muted); font-weight: 700; text-align: center; padding: 20px; }

/* toasts */
#toasts { position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom));
  transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 30;
  align-items: center; pointer-events: none; width: max-content; max-width: 92vw; }
.toast { background: rgba(10,20,14,.94); border: 1px solid var(--line); color: var(--ink);
  border-radius: 12px; padding: 8px 15px; font-weight: 800; font-size: 14px;
  box-shadow: 0 6px 18px rgba(0,0,0,.4); animation: tin .25s ease; }
.toast b { color: var(--brass); }
.toast.big { font-size: 16px; border-color: var(--brass-d); }
@keyframes tin { from { transform: translateY(12px); opacity: 0; } }

@media (max-width: 480px) {
  #centerRow { gap: 14px; }
  #starterCard, #starterCard .card { --cw: 48px; }
}
