:root {
  --bg: #0b2a1f; --felt: #0f3d2b; --felt2: #14523a; --line: #245c45;
  --ink: #f3f1e8; --muted: #9bb5a8; --acc: #f2c14e; --red: #e5484d;
  --card: #fbfaf5; --cardink: #1b1b1b; --ok: #4cc38a; --wood: #5a3a1c;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 8px) 12px calc(env(safe-area-inset-bottom) + 24px); }
button { font: inherit; color: var(--ink); background: var(--felt2); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 14px; min-height: 44px; cursor: pointer; }
button:active:not(:disabled) { transform: scale(.97); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--acc); color: #2a2100; border-color: var(--acc); font-weight: 700; }
button.warn { background: #7a2a2d; border-color: #a33a3e; }
button.ghost { background: transparent; }
button.small { min-height: 36px; padding: 6px 12px; border-radius: 10px; }
button.ic { min-height: 36px; min-width: 36px; padding: 4px 8px; border-radius: 18px; font-size: 16px; }
input[type=text] { width: 100%; font: inherit; color: var(--ink); background: #0a2219;
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 48px; }
input:focus { outline: 2px solid var(--acc); }
.muted { color: var(--muted); }
.center { text-align: center; padding-top: 10vh; }
.logo { font-size: 44px; font-weight: 800; letter-spacing: 2px; color: var(--acc); }
h2 { font-size: 18px; margin: 18px 0 8px; }

header { display: flex; align-items: center; gap: 6px; padding: 2px 0 6px; }
.brand { font-weight: 800; letter-spacing: 1px; color: var(--acc); font-size: 20px; margin-right: 4px; }
.nick { margin-left: auto; padding: 4px 12px; min-height: 36px; border-radius: 18px; max-width: 46vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); margin-left: 2px; }
.dot.on { background: var(--ok); } .dot.off { background: var(--red); }

.avatar { width: 44px; height: 44px; border-radius: 50%; background: #0a2219; border: 2px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center; font-size: 25px; flex: none; }
.avatar.sm { width: 34px; height: 34px; font-size: 19px; }
.avgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 10px 0; }
.avgrid button { font-size: 24px; padding: 6px 0; min-height: 48px; }
.avgrid button.on { border-color: var(--acc); background: #1b5e44; box-shadow: 0 0 0 2px var(--acc) inset; }

.tabs { display: flex; gap: 8px; margin: 6px 0 10px; }
.tabs button { flex: 1; } .tabs button.on { background: var(--felt2); border-color: var(--acc); }
.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; background: var(--felt); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { font-size: 13px; color: var(--muted); }
.row.invite { border-color: var(--acc); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.actions > * { flex: 1; }
.empty { text-align: center; padding: 22px 10px; color: var(--muted); }
.wins { font-size: 12px; color: var(--acc); font-weight: 700; }

/* ---------- stol ---------- */
.timerbox { margin: 0 0 4px; }
.timer { height: 7px; background: #0a2219; border-radius: 4px; overflow: hidden; }
.tfill { height: 100%; transform-origin: left; animation: shrink linear both; }
.tlabel { font-size: 13px; color: var(--muted); text-align: center; margin-top: 1px; }
@keyframes shrink {
  0% { transform: scaleX(1); background: var(--ok); }
  60% { background: var(--acc); }
  100% { transform: scaleX(0); background: var(--red); }
}
/* okragly stol: gracze siedza na elipsie (pozycje liczy app.js), na 5 osob stol jest bardziej owalny */
.ring { position: relative; width: 100%; aspect-ratio: 1 / 1.08; margin: 12px 0 4px; }
.ring.p4, .ring.p5 { aspect-ratio: 1 / 1.26; }
.ring.p4 .mid { top: 49%; }
.felt { position: absolute; inset: 9% 7%; border-radius: 50%; border: 9px solid var(--wood);
  background:
    radial-gradient(ellipse at 50% 18%, #ffe9a62a, transparent 55%),
    radial-gradient(ellipse at 50% 55%, #1f7a53, #0f3d2b 74%);
  box-shadow: inset 0 0 46px #000c, inset 0 0 0 2px #0a2a1c, 0 10px 26px #000b, 0 0 0 2px #3a2410,
    0 0 0 4px #7a5530; }
.ring.p5 .felt { border-radius: 46% / 40%; inset: 7% 8%; }
.spot { position: absolute; transform: translate(-50%, -50%); z-index: 2; }
.spot.mine { transform: translate(-50%, -64%); }
.mid { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); width: 50%; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
/* 2 osoby: przeciwnik naprzeciwko, wiec stol jest wyzszy */
.ring.p2 { aspect-ratio: 1 / 1.3; }
.ring.p2 .mid { width: 62%; top: 49%; }
.mid .lbl { font-size: 11px; color: var(--muted); }
.seat { width: 86px; text-align: center; padding: 2px; border-radius: 14px; }
.seat .avatar { box-shadow: 0 3px 8px #000a; }
.seat .sn { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px;
  text-shadow: 0 1px 3px #000, 0 0 6px #000; }
.spot.mine .seat { width: auto; min-width: 120px; }
.spot.mine .sn { max-width: 110px; }
.seat .off { color: #ff9b9e; font-size: 11px; text-shadow: 0 1px 3px #000; }
.seat.turn .avatar { border-color: var(--acc); box-shadow: 0 0 14px #f2c14e99; animation: pulse 1.1s ease-in-out infinite alternate; }
.seat.dead { opacity: .4; filter: grayscale(.8); }
.seat.shake { animation: shake .7s both; animation-delay: var(--d, 0ms); }
.seat.out { animation: outfade .9s both; animation-delay: var(--d, 0ms); }
.fan { display: flex; justify-content: center; margin-top: 3px; min-height: 52px; }
.fan .fc + .fc { margin-left: -13px; }
.fan.c2 .fc + .fc { margin-left: 3px; }
.fan.c3 .fc + .fc { margin-left: -7px; }

.center { text-align: center; }
.bidpanel { text-align: center; margin: 2px 0 0; min-height: 54px; }
.bidpanel .who { font-size: 13px; color: #c9ddd2; }
.bidpanel .bidtext { font-size: 18px; font-weight: 800; color: var(--acc); margin: 0 0 4px; text-shadow: 0 2px 6px #000a; line-height: 1.2; }
.bidpanel.enter .bidtext, .banner.enter { animation: pop .5s both; }
.chips { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; align-items: center; }
.chip { min-height: 36px; padding: 4px 12px; border-radius: 18px; background: #0a2219; font-weight: 700; }
.chip.static { display: inline-flex; align-items: center; border: 1px solid var(--line); min-height: 30px; padding: 2px 10px; }

/* ---------- karty ---------- */
.card { width: 52px; height: 74px; background: var(--card); color: var(--cardink); border-radius: 8px;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px #0008; font-style: normal; line-height: 1.05; }
.card b { font-size: 24px; } .card i { font-size: 20px; font-style: normal; }
.card.red { color: var(--red); }
.fc { position: relative; flex: none; perspective: 500px; }
.fc.sm { width: 36px; height: 52px; } .fc.md { width: 52px; height: 74px; } .fc.lg { width: 56px; height: 80px; }
.fc .card { width: 100%; height: 100%; }
.fc.sm .card b { font-size: 17px; } .fc.sm .card i { font-size: 14px; }
.fc.lg .card b { font-size: 28px; } .fc.lg .card i { font-size: 22px; }
.fi { position: absolute; inset: 0; transform-style: preserve-3d; }
.fc .face, .fc .cb { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 7px; }
.fc .cb { transform: rotateY(180deg); box-shadow: 0 2px 6px #0008; border: 2px solid #f3f1e8;
  background: repeating-linear-gradient(45deg, #2b6f9e, #2b6f9e 4px, #1f5a84 4px, #1f5a84 8px); }
.fc.down .fi { transform: rotateY(180deg); }
.fc.flip .fi { animation: flip .6s ease both; animation-delay: var(--d, 0ms); }
.fc.deal { animation: dealin .5s ease-out both; animation-delay: var(--d, 0ms); }
.fc.hl .face { animation: glow .9s ease-in-out infinite alternate both; animation-delay: var(--g, 0ms); }
.fc.dim .face { animation: dim .5s both; animation-delay: var(--g, 0ms); }
.hand { display: flex; gap: 6px; justify-content: center; margin: 0 0 3px; min-height: 74px; }
@keyframes flip { from { transform: rotateY(180deg); } to { transform: rotateY(0deg); } }
@keyframes dealin { from { opacity: 0; transform: translateY(-140px) scale(.4) rotate(-25deg); } to { opacity: 1; transform: none; } }
@keyframes glow {
  from { box-shadow: 0 0 0 0 #f2c14e00; transform: none; }
  to { box-shadow: 0 0 0 3px #f2c14e, 0 0 18px 5px #f2c14eaa; transform: translateY(-7px); }
}
@keyframes dim { to { opacity: .42; filter: grayscale(.6); } }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.1); } }
@keyframes pop { from { opacity: 0; transform: scale(.7); } 60% { transform: scale(1.08); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%,100% { transform: none; } 15% { transform: translateX(-7px); } 30% { transform: translateX(7px); }
  45% { transform: translateX(-5px); } 60% { transform: translateX(5px); } 80% { transform: translateX(-2px); } }
@keyframes outfade { to { opacity: .35; filter: grayscale(1); } }
@keyframes appear { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.appear { animation: appear .5s ease-out both; animation-delay: var(--d, 0ms); }

/* ---------- sprawdzam! ---------- */
.shout { position: fixed; inset: 0; z-index: 15; pointer-events: none; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; background: #000c; padding: 20px;
  animation: shout 1.5s both; animation-delay: var(--d, 0ms); }
.shout .who { font-size: 20px; color: #c9ddd2; }
.shout b { font-size: 52px; color: var(--acc); text-shadow: 0 4px 16px #000; letter-spacing: 1px; }
.shout .sub { margin-top: 10px; font-size: 17px; color: var(--ink); max-width: 320px; }
@keyframes shout {
  0% { opacity: 0; transform: scale(1.35); }
  14% { opacity: 1; transform: scale(1); }
  82% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}

/* ---------- ja / panel akcji ---------- */
.me { margin-top: 4px; }
.builder .chip { min-height: 30px; padding: 2px 10px; }
.mehead { display: flex; align-items: center; gap: 6px; justify-content: center; font-weight: 700; }
.verdict { text-align: center; margin: 6px 0; }
.verdict .big { font-size: 22px; font-weight: 800; margin: 6px 0; }
.banner { text-align: center; font-weight: 700; margin: 8px 0; }
.lost { color: #ff9b9e; } .won { color: var(--ok); }
.wait { text-align: center; padding: 14px; color: var(--muted); }
.builder .sel { margin: 4px 0; }
.builder .sel:empty { display: none; }
.builder .actions { margin: 6px 0; }
.builder button { min-height: 42px; }
.pv { text-align: center; font-weight: 600; font-size: 14px; min-height: 22px; margin: 2px 0 6px; }
.pv.err { color: #ff9b9e; } .pv.ok { color: var(--ok); font-size: 16px; }
.ranks { display: grid; grid-template-columns: repeat(var(--n, 6), 1fr); gap: 5px; margin: 6px 0; }
.rk { font-weight: 800; font-size: 18px; padding: 6px 0; min-height: 44px; background: var(--card); color: var(--cardink); border-color: #bdb8a2; }
/* panel akcji zawsze na wierzchu ekranu */
.dock { position: sticky; bottom: 0; z-index: 5; margin: 0 -12px; padding: 8px 12px calc(env(safe-area-inset-bottom) + 6px);
  background: linear-gradient(to top, var(--bg) 88%, transparent); }
/* 4-5 graczy: mniejsze karty i awatary */
.ring.p4 .seat, .ring.p5 .seat { width: 76px; }
.ring.p4 .avatar, .ring.p5 .avatar { width: 38px; height: 38px; font-size: 21px; }
.ring.p5 .fc.sm, .ring.p4 .fc.sm { width: 30px; height: 44px; }
.ring.p5 .fc.sm .card b, .ring.p4 .fc.sm .card b { font-size: 14px; }
.ring.p5 .fc.sm .card i, .ring.p4 .fc.sm .card i { font-size: 12px; }
.ring.p4 .fan, .ring.p5 .fan { min-height: 44px; }
.ring.p4 .fan .fc + .fc, .ring.p5 .fan .fc + .fc { margin-left: -14px; }
.ring.p4 .bidpanel .bidtext, .ring.p5 .bidpanel .bidtext { font-size: 16px; }
.ring .spot.mine .avatar { width: 34px; height: 34px; font-size: 19px; }

.modal { position: fixed; inset: 0; background: #000a; display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { width: 100%; max-width: 560px; background: var(--bg); border: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px); max-height: 92dvh; overflow: auto; }
.seg { display: flex; gap: 8px; margin: 10px 0 14px; } .seg button { flex: 1; } .seg button.on { border-color: var(--acc); background: var(--felt2); }
.err { color: #ff9b9e; }
.rules { text-align: left; }
.rules .rsec { margin: 12px 0; }
.rules h3 { font-size: 16px; color: var(--acc); margin: 0 0 4px; }
.rules p { margin: 4px 0; font-size: 15px; }
.rules ol { margin: 4px 0; padding-left: 22px; font-size: 15px; }
.rules .rex { background: #0a2219; border-left: 3px solid var(--acc); border-radius: 8px; padding: 6px 10px; margin: 6px 0; font-size: 14px; color: #dfe9e2; }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translate(-50%, 30px);
  background: #000d; color: #fff; padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: .25s; max-width: 90vw; text-align: center; z-index: 20; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.seg button { font-size: 14px; padding: 10px 6px; }
.modebox { background: rgba(0,0,0,.18); border-radius: 12px; padding: 10px 12px; margin: 0 0 12px; }
.modebox .seg { margin: 6px 0 0; }
.rdy { color: #7be08a; font-weight: 700; font-size: 13px; }
.row.tap { cursor: pointer; } .row.tap:active { background: rgba(255,255,255,.08); }
.row.invite { border: 1px solid var(--acc); }

/* ---------- efekty: konfetti po wygranej, czerwony blysk po przegranej ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
.confetti i { position: absolute; top: -16px; width: 8px; height: 14px; border-radius: 2px;
  animation: fall var(--t) cubic-bezier(.3,.6,.6,1) var(--d) both; }
@keyframes fall { from { transform: translate(0, 0) rotate(0); opacity: 1; }
  to { transform: translate(var(--x), 105vh) rotate(var(--r)); opacity: .9; } }
.flash { position: fixed; inset: 0; pointer-events: none; z-index: 29; animation: flash 1.4s ease-out both; }
.flash.bad { background: radial-gradient(ellipse at center, transparent 35%, #e5484d99); }
@keyframes flash { 0% { opacity: 0; } 12% { opacity: 1; } 100% { opacity: 0; } }
.verdict .big.won { animation: pop .6s both; animation-delay: var(--d, 0ms); text-shadow: 0 0 16px #4cc38a88; }
