:root {
  --ink: #2b2140;
  --paper: #fff8ec;
  --bg: #ffd23f;
  --bg2: #ff9f43;
  --card: #fffdf8;
  --muted: #7a6d8a;
  --accent: #6c5ce7;
  --ok: #2ec26a;
  --danger: #ff5a5f;
  --shadow: 0 4px 0 var(--ink);
  --r: 18px;
  --top: 52px;
  font-family: 'Fredoka', 'Segoe UI', system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,.35) 0 8%, transparent 9%),
    radial-gradient(circle at 85% 80%, rgba(255,255,255,.25) 0 6%, transparent 7%),
    repeating-linear-gradient(45deg, transparent 0 22px, rgba(255,255,255,.12) 22px 44px),
    linear-gradient(160deg, var(--bg), var(--bg2));
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- horní lišta ---------- */
.topbar {
  height: var(--top); display: flex; align-items: center; gap: 10px;
  padding: 0 12px; padding-top: env(safe-area-inset-top);
  background: var(--ink); color: #fff;
  position: sticky; top: 0; z-index: 20;
}
.logo { font-size: 28px; text-decoration: none; }
.topbar-title { font-weight: 600; font-size: 18px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; font-size: 24px; padding: 4px 8px; }
.conn { background: var(--danger); padding: 2px 10px; border-radius: 99px; font-size: 13px; animation: pulse 1s infinite; }

/* ---------- obrazovky ---------- */
.screen { min-height: calc(100dvh - var(--top)); padding: 16px; }
.screen.center { display: grid; place-items: center; }
.spinner { font-size: 64px; animation: spin 1.2s linear infinite; }

.card {
  background: var(--card); border: 3px solid var(--ink); border-radius: var(--r);
  box-shadow: 0 6px 0 var(--ink); padding: 20px;
}
.card.narrow { width: min(440px, 100%); }
.card h1, .card h2 { margin: 0 0 10px; line-height: 1.15; }
.card h1 { font-size: 28px; }
.muted { color: var(--muted); }
.big-emoji { font-size: 56px; text-align: center; }
.err { color: var(--danger); min-height: 1.2em; margin: 6px 0; font-weight: 500; }

.btn {
  display: inline-block; text-decoration: none; text-align: center;
  background: var(--accent); color: #fff; border: 3px solid var(--ink); border-radius: 14px;
  padding: 10px 18px; font-weight: 600; font-size: 17px;
  box-shadow: var(--shadow); transition: transform .08s, box-shadow .08s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.big { width: 100%; font-size: 21px; padding: 14px; background: var(--ok); }
.btn.ghost { background: #fff; color: var(--ink); }
.btn.small { font-size: 15px; padding: 7px 12px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.row-btns .btn { flex: 1; }

.lbl { display: block; font-weight: 600; margin: 14px 0 6px; }
input, select {
  font: inherit; font-size: 19px; width: 100%; padding: 10px 14px;
  border: 3px solid var(--ink); border-radius: 12px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 3px solid var(--accent); outline-offset: 1px; }

.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.av {
  font-size: 30px; aspect-ratio: 1; border-radius: 12px; border: 2px solid transparent;
  background: #f4ecdf; transition: transform .1s;
}
.av.taken { opacity: .45; }
.av.on { border: 3px solid var(--ink); background: #fff; transform: scale(1.12) rotate(-6deg); box-shadow: 0 3px 0 var(--ink); opacity: 1; }

/* ---------- čekárna ---------- */
.lobby { display: grid; gap: 16px; max-width: 980px; margin: 0 auto; grid-template-columns: 1fr; }
@media (min-width: 760px) { .lobby { grid-template-columns: 1fr 1fr; align-items: start; } }
.invite { text-align: center; }
.invite img { width: min(300px, 80%); aspect-ratio: 1; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 6px; image-rendering: pixelated; }
.code-line { font-size: 20px; margin-top: 8px; }
.code-line b { font-size: 30px; letter-spacing: 4px; background: var(--bg); padding: 0 10px; border-radius: 8px; border: 2px solid var(--ink); }
.link-line code { display: inline-block; margin-top: 8px; font-size: 14px; word-break: break-all; color: var(--muted); }
.pill { background: var(--ink); color: #fff; padding: 1px 12px; border-radius: 99px; font-size: 18px; vertical-align: middle; }
.countdown { font-size: 18px; font-weight: 500; background: #fff4c7; border: 2px dashed var(--ink); border-radius: 12px; padding: 8px 12px; margin-bottom: 12px; }
.plist { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; max-height: 50vh; overflow-y: auto; }
.plist li { display: flex; align-items: center; gap: 10px; background: #fff; border: 2px solid var(--ink); border-radius: 14px; padding: 6px 10px; }
.plist li.pop { animation: popin .45s cubic-bezier(.3,1.6,.5,1); }
.plist li.empty { justify-content: center; color: var(--muted); border-style: dashed; padding: 16px; }
.pav { font-size: 30px; }
.pn { font-weight: 600; font-size: 18px; flex: 1; }
.tag { font-size: 12px; background: #eee3ff; border-radius: 99px; padding: 2px 8px; }
.kick { background: none; border: 0; font-size: 18px; color: var(--muted); }
.host-controls { display: grid; gap: 8px; }

/* ---------- hra ---------- */
body[data-screen="game"] .screen { padding: 0; }
.game {
  height: calc(100dvh - var(--top));
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "chips" "board" "controls";
}
.chips { grid-area: chips; display: flex; gap: 6px; overflow-x: auto; padding: 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 6px;
  background: var(--cl); border: 3px solid var(--cd); border-radius: 14px; padding: 4px 10px 4px 6px;
  min-width: 110px; max-width: 220px; transition: transform .2s;
}
.chip.active { background: var(--c); box-shadow: 0 4px 0 var(--ink); border-color: var(--ink); transform: translateY(-2px); animation: wobble 1.6s ease-in-out infinite; }
.chip.done { opacity: .85; }
.chip-av { grid-row: span 2; font-size: 26px; align-self: center; }
.chip-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-prog { font-size: 12px; letter-spacing: 1px; }

.board-wrap { grid-area: board; position: relative; min-height: 0; padding: 4px; }
#board { width: 100%; height: 100%; display: block; overflow: visible; user-select: none; touch-action: manipulation; }

.controls {
  grid-area: controls; background: var(--card); border-top: 3px solid var(--ink);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); display: grid; gap: 6px;
  --c: #ccc; --cd: #888;
}
.controls.mine { background: linear-gradient(0deg, var(--card) 60%, color-mix(in srgb, var(--c) 35%, var(--card))); }
.turn { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 19px; }
.turn-av { font-size: 28px; }
.controls.mine .turn-txt { color: var(--cd); animation: pulse 1.2s infinite; }
.timer { height: 8px; background: #eee3d3; border-radius: 99px; overflow: hidden; border: 2px solid var(--ink); }
.tbar { height: 100%; width: 0; background: var(--c); transition: width .25s linear; }
.tbar.low { background: var(--danger); }
.dice-row { display: flex; align-items: center; gap: 14px; }
.dice { width: 78px; height: 78px; border: 0; background: none; padding: 0; flex: 0 0 auto; transition: transform .1s; }
.dice svg { width: 100%; height: 100%; display: block; }
.dice:disabled { cursor: default; }
.dice.ready { animation: diceReady 1s ease-in-out infinite; }
.dice.pressed { transform: scale(.9); }
.dice.rolling { animation: diceRoll .56s linear; }
.dice.landed { animation: diceLand .35s cubic-bezier(.3,1.8,.5,1); }
.hint { font-size: 17px; font-weight: 500; flex: 1; }
.reacts { display: flex; gap: 2px; justify-content: space-between; }
.reacts button { background: none; border: 0; font-size: 24px; padding: 2px 4px; border-radius: 10px; transition: transform .1s; }
.reacts button:active, .reacts button.sent { transform: scale(1.4); }

@media (min-aspect-ratio: 5/4) and (min-width: 700px) {
  .game {
    grid-template-columns: 240px 1fr 280px;
    grid-template-rows: 1fr;
    grid-template-areas: "chips board controls";
  }
  .chips { flex-direction: column; overflow-y: auto; padding: 12px; }
  .chip { max-width: none; }
  .controls { border-top: 0; border-left: 3px solid var(--ink); align-content: center; padding: 16px; gap: 14px; }
  .dice-row { flex-direction: column; text-align: center; }
  .dice { width: 120px; height: 120px; }
  .reacts { flex-wrap: wrap; justify-content: center; }
}

/* ---------- plocha (SVG) ---------- */
.b-road-outline { fill: none; stroke: var(--ink); stroke-linejoin: round; }
.b-road { fill: none; stroke: var(--paper); stroke-linejoin: round; }
.b-home-lane { fill: none; stroke-linecap: round; }
.b-center { fill: #fff3b0; stroke: var(--ink); stroke-width: 3; }
.b-center-txt { text-anchor: middle; }
.b-field { fill: #fff; stroke: var(--ink); stroke-width: 3; }
.b-start-txt { text-anchor: middle; fill: #fff; font-weight: 700; paint-order: stroke; stroke: var(--ink); stroke-width: 3px; pointer-events: none; }
.b-arrow { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.b-yard { stroke: var(--ink); stroke-width: 3; stroke-dasharray: 8 5; }
.b-yardspot { stroke: var(--ink); stroke-width: 2; opacity: .55; }
.b-label { pointer-events: none; }
.b-label text { text-anchor: middle; }
.b-label-name { font-weight: 600; fill: var(--ink); paint-order: stroke; stroke-width: 4px; stroke-linejoin: round; }
.b-target { fill: rgba(255,255,255,.35); stroke-width: 3; stroke-dasharray: 6 5; animation: dash 1s linear infinite; cursor: pointer; }
.b-target.cap { fill: rgba(255,90,95,.35); }

.pawn { cursor: default; }
.pawn-body { transform-box: fill-box; transform-origin: 50% 100%; }
.pawn-base, .pawn-head { stroke-width: 2.2; }
.pawn-shadow { fill: rgba(0,0,0,.22); }
.pawn-shine { fill: rgba(255,255,255,.6); }
.pawn-ring { fill: none; stroke: #fff; stroke-width: 3; opacity: 0; }
.eyes-closed { fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; display: none; }
.mouth { fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; }
.mouth.scream { fill: var(--ink); stroke: none; display: none; }
.zzz { display: none; fill: var(--ink); font-weight: 700; }
.pawn.sleep .eyes-open { display: none; }
.pawn.sleep .eyes-closed { display: inline; }
.pawn.sleep .zzz { display: inline; animation: zzz 2.4s ease-in-out infinite; }
.pawn.sleep .mouth.smile { d: path('M-1.5 -6.5 q1.5 1 3 0'); }
.pawn.happy .pawn-body { animation: happy 2.2s ease-in-out infinite; }
.pawn.scared .mouth.smile { display: none; }
.pawn.scared .mouth.scream { display: inline; }
.pawn.scared .eyes-open ellipse { transform: scale(1.25); transform-box: fill-box; transform-origin: center; }
.pawn.scared .pawn-body { animation: shake .12s linear infinite; }
.pawn.can { cursor: pointer; }
.pawn.can .pawn-ring { opacity: 1; animation: ring 1s ease-in-out infinite; }
.pawn.can .pawn-body { animation: canBounce .7s ease-in-out infinite; }
.pawn-body.hop { animation: hop .18s ease-out; }
.pawn-body.bighop { animation: bighop .42s ease-out; }
.pawn-body.spin { animation: flyspin 1s ease-in-out; }

.burst-in { animation: burst 1.25s cubic-bezier(.2,1.6,.4,1) forwards; transform-box: fill-box; transform-origin: center; }
.burst-txt { text-anchor: middle; font-weight: 700; font-family: 'Fredoka', sans-serif; }
.bdie-in { animation: popin .35s cubic-bezier(.3,1.8,.5,1); transform-box: fill-box; transform-origin: center; }
.bdie { transition: opacity .5s; }
.bdie.fade { opacity: 0; }

/* bublina s hláškou */
.bubble {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  max-width: min(92%, 520px); background: #fff; border: 3px solid var(--ink); border-radius: 20px;
  padding: 10px 16px; font-size: 18px; font-weight: 600; text-align: center;
  box-shadow: 0 5px 0 var(--ink); pointer-events: none; z-index: 5;
}
.bubble::after {
  content: ''; position: absolute; bottom: -14px; left: 50%; width: 22px; height: 22px; background: #fff;
  border-right: 3px solid var(--ink); border-bottom: 3px solid var(--ink); transform: translateX(-50%) rotate(45deg) scale(.7);
}
.bubble.show { animation: bubbleIn .4s cubic-bezier(.3,1.7,.5,1); }

.overlay { position: fixed; inset: 0; background: rgba(43,33,64,.55); display: grid; place-items: center; padding: 16px; z-index: 30; }
.over-card { text-align: center; animation: popin .5s cubic-bezier(.3,1.6,.5,1); }
.trophy { font-size: 70px; animation: wobble 1.5s ease-in-out infinite; }
.podium { list-style: none; padding: 0; display: grid; gap: 6px; text-align: left; }
.podium li { display: flex; align-items: center; gap: 10px; border: 3px solid var(--ink); border-left: 12px solid var(--c); border-radius: 12px; padding: 6px 10px; background: #fff; }
.podium .pnote { margin-left: auto; font-size: 14px; color: var(--muted); }
.podium .medal { font-size: 26px; min-width: 34px; text-align: center; }
.over-card .btn { margin-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 140%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 14px; font-weight: 500;
  transition: transform .25s, opacity .25s; z-index: 50; max-width: 90vw; text-align: center;
  opacity: 0; visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
.floater { position: fixed; z-index: 40; pointer-events: none; display: grid; justify-items: center; animation: floatUp 2.6s ease-out forwards; transform: translate(-50%, -50%); }
.floater .fe { font-size: 44px; }
.floater .fn { font-size: 12px; font-weight: 600; background: #fff; border: 2px solid var(--ink); border-radius: 99px; padding: 0 8px; white-space: nowrap; }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

/* ---------- animace ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .55; } }
@keyframes popin { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes wobble { 0%, 100% { transform: translateY(-2px) rotate(0); } 25% { transform: translateY(-2px) rotate(-2deg); } 75% { transform: translateY(-2px) rotate(2deg); } }
@keyframes dash { to { stroke-dashoffset: -22; } }
@keyframes hop { 50% { transform: translateY(-10px) scale(1.05, .95); } }
@keyframes bighop { 0% { transform: scale(.6); } 50% { transform: translateY(-30px) scale(1.15); } 100% { transform: none; } }
@keyframes flyspin { 0% { transform: none; } 50% { transform: translateY(-40px) rotate(400deg) scale(1.4); } 100% { transform: rotate(720deg); } }
@keyframes canBounce { 50% { transform: translateY(-6px); } }
@keyframes ring { 50% { stroke-width: 6; } }
@keyframes happy { 0%, 80%, 100% { transform: none; } 85% { transform: translateY(-5px) rotate(-8deg); } 92% { transform: translateY(-5px) rotate(8deg); } }
@keyframes shake { 0% { transform: translateX(-1.5px); } 50% { transform: translateX(1.5px); } 100% { transform: translateX(-1.5px); } }
@keyframes zzz { 0% { opacity: 0; transform: translate(0, 0); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(6px, -10px); } }
@keyframes burst { 0% { transform: scale(0) rotate(-30deg); } 25% { transform: scale(1.2) rotate(5deg); } 70% { transform: scale(1) rotate(0); opacity: 1; } 100% { transform: scale(1.3); opacity: 0; } }
@keyframes diceReady { 0%, 100% { transform: rotate(-6deg) scale(1); } 50% { transform: rotate(6deg) scale(1.08); } }
@keyframes diceRoll { 0% { transform: rotate(0) scale(1); } 25% { transform: rotate(-120deg) scale(1.15) translateY(-8px); } 50% { transform: rotate(-260deg) scale(.95); } 75% { transform: rotate(-330deg) scale(1.1) translateY(-4px); } 100% { transform: rotate(-360deg) scale(1); } }
@keyframes diceLand { 0% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes bubbleIn { from { transform: translateX(-50%) scale(.4); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); } 15% { opacity: 1; transform: translate(-50%, -70%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -260%) scale(1); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
