:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --card: #1e293b;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #f59e0b;
  --accent-2: #38bdf8;
  --ok: #22c55e;
  --radius: 16px;
}

* { box-sizing: border-box; }

/* atrybut hidden musi wygrywać z regułami display: (np. baner bingo) */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #1e293b, var(--bg));
  color: var(--text);
  min-height: 100dvh;
}

.screen { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }

/* ---------- EKRAN STARTOWY ---------- */
.logo { font-size: clamp(2rem, 6vw, 3.2rem); text-align: center; margin: 1.5rem 0 0.3rem; }
.tagline { text-align: center; color: var(--muted); margin: 0 0 2rem; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
@media (max-width: 640px) { .cards { grid-template-columns: 1fr; } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.card h2 { margin: 0; font-size: 1.2rem; }

label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); }

input, select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  color: var(--text);
  font-size: 1rem;
}
input:focus, select:focus { outline: 2px solid var(--accent-2); border-color: transparent; }
.code-input { text-transform: uppercase; letter-spacing: 0.4em; font-weight: 700; text-align: center; }

button {
  cursor: pointer;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 0.7rem 1rem;
  font-weight: 600;
  transition: transform .05s ease, filter .15s ease;
}
button:active { transform: scale(0.98); }
.primary { background: var(--accent); color: #1a1a1a; }
.primary:hover { filter: brightness(1.08); }
.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.ghost:hover { color: var(--text); }
.danger { background: transparent; color: #f87171; border-color: #f87171; }
.danger:hover { background: #f87171; color: #1a1a1a; }

.error { color: #f87171; text-align: center; margin-top: 1rem; }

/* wybór kategorii w formularzu nowej gry */
.cat-field { display: flex; flex-direction: column; gap: 0.5rem; }
.cat-legend { font-size: 0.85rem; color: var(--muted); }
.cat-legend small { opacity: 0.7; font-size: 0.75rem; }
.cat-list {
  display: flex; flex-wrap: wrap; gap: 0.45rem;
  max-height: 200px; overflow-y: auto;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.cat-chip {
  font-size: 0.82rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-weight: 600;
}
.cat-chip small { color: var(--muted); font-weight: 500; opacity: 0.7; }
.cat-chip.on {
  color: #1a1a1a;
  background: var(--accent);
  border-color: var(--accent);
}
.cat-chip.on small { color: #1a1a1a; opacity: 0.7; }

/* ---------- EKRAN GRY ---------- */
.game-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
}
.room-info { display: flex; flex-direction: column; }
.room-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.room-code {
  background: var(--bg-soft);
  border: 1px dashed var(--accent);
  color: var(--accent);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.25em;
  padding: 0.25rem 0.7rem;
}
.me-info { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; background: var(--muted); }

.game-body { display: grid; grid-template-columns: 1fr 320px; gap: 1.5rem; align-items: start; }

/* elementy mobilne (bottom sheet) – domyślnie schowane na desktopie */
.ranking-fab, .sheet-backdrop, .sheet-handle { display: none; }

/* plansza */
.board {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(var(--cols, 4), 1fr);
}
.cell {
  aspect-ratio: 1;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.4rem;
  cursor: pointer;
  text-align: center;
  user-select: none;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
  position: relative;
}
.cell:hover { border-color: var(--accent-2); }
.cell .icon { font-size: clamp(1.6rem, 6vw, 2.6rem); line-height: 1; }
.cell .label { font-size: 0.72rem; color: var(--muted); line-height: 1.1; }
.cell.fun {
  border-color: var(--accent);
  border-style: dashed;
  background: linear-gradient(160deg, rgba(245,158,11,.16), rgba(245,158,11,.04));
}
.cell.fun .label { color: #fcd34d; }
.cell.marked {
  background: linear-gradient(160deg, rgba(34,197,94,.25), rgba(34,197,94,.08));
  border-color: var(--ok);
}
.cell.fun.marked { border-style: solid; }
.cell.marked .label { color: var(--text); }
.cell.marked::after {
  content: "✓";
  position: absolute;
  top: 4px; right: 7px;
  color: var(--ok);
  font-weight: 900;
  font-size: 1rem;
}

/* ranking */
.ranking-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  position: sticky;
  top: 1rem;
}
.ranking-wrap h2 { margin: 0 0 0.8rem; font-size: 1.1rem; display: flex; align-items: center; gap: 0.5rem; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(34,197,94,.7); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.6);} 70%{ box-shadow: 0 0 0 8px rgba(34,197,94,0);} 100%{ box-shadow: 0 0 0 0 rgba(34,197,94,0);} }

.admin-bar {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0.9rem; padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.admin-tag { font-size: 0.72rem; color: var(--accent); font-weight: 700; }
button.small { font-size: 0.78rem; padding: 0.4rem 0.6rem; }

.filter-row { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.9rem; }
.filter-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  display: inline-flex; align-items: center; gap: 0.35rem;
}
.chip .cdot { width: 9px; height: 9px; border-radius: 50%; }
.chip.on { color: var(--text); border-color: var(--accent-2); background: var(--bg-soft); }
.chip.off { opacity: 0.45; text-decoration: line-through; }

.ranking { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.rank-item {
  display: flex; align-items: center; gap: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
}
.rank-item.me { border-color: var(--accent); }
.rank-pos { font-weight: 800; color: var(--muted); width: 1.4rem; text-align: center; }
.rank-name { flex: 1; font-weight: 600; display: flex; align-items: center; gap: 0.45rem; }
.rank-score { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.85rem; }
.rank-bingo { color: var(--accent); font-weight: 800; font-size: 0.8rem; }
.crown { font-size: 0.8rem; }
.kick-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-weight: 800;
  padding: 0.1rem 0.4rem;
  border-radius: 8px;
  line-height: 1;
}
.kick-btn:hover { color: #f87171; border-color: #f87171; }
.empty { color: var(--muted); font-size: 0.85rem; }

/* baner bingo */
.bingo-banner {
  position: fixed;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(2rem, 12vw, 6rem);
  font-weight: 900;
  background: rgba(15,23,42,.85);
  z-index: 50;
  animation: pop .5s ease;
}
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ============ MOBILE (telefon) ============ */
@media (max-width: 860px) {
  .screen { padding: 0.7rem; }

  /* nagłówek zawsze widoczny u góry */
  .game-header {
    position: sticky;
    top: 0;
    z-index: 30;
    gap: 0.6rem;
    margin: -0.7rem -0.7rem 0.8rem;
    padding: 0.7rem;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
  }
  .room-code { font-size: 1.2rem; letter-spacing: 0.2em; }
  .me-info { font-size: 0.9rem; }

  /* plansza na całą szerokość */
  .game-body { grid-template-columns: 1fr; gap: 0; }
  .board { gap: 0.4rem; }
  .cell { border-radius: 12px; gap: 0.2rem; }
  .cell .label { font-size: 0.68rem; }

  /* ranking jako wysuwany panel od dołu (bottom sheet) */
  .ranking-wrap {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    top: auto;
    max-height: 80vh;
    overflow-y: auto;
    border-radius: 20px 20px 0 0;
    border: 1px solid var(--line);
    border-bottom: none;
    transform: translateY(110%);
    transition: transform 0.25s ease;
    z-index: 40;
    box-shadow: 0 -10px 30px rgba(0,0,0,.4);
    padding-bottom: calc(1.1rem + env(safe-area-inset-bottom));
  }
  #game.sheet-open .ranking-wrap { transform: none; }

  .sheet-handle {
    display: block;
    width: 44px; height: 4px;
    border-radius: 999px;
    background: var(--line);
    margin: 0 auto 0.8rem;
  }

  .sheet-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 39;
  }
  #game.sheet-open .sheet-backdrop { opacity: 1; pointer-events: auto; }

  /* pływający przycisk otwierający ranking */
  .ranking-fab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    position: fixed;
    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom));
    z-index: 41;
    background: var(--accent);
    color: #1a1a1a;
    font-weight: 700;
    border-radius: 999px;
    padding: 0.7rem 1.1rem;
    box-shadow: 0 6px 18px rgba(0,0,0,.4);
  }
  #game.sheet-open .ranking-fab { display: none; }

  /* ekran startowy: więcej oddechu i wygodniejsze elementy na telefonie */
  #home.screen { padding: 1rem; }
  .logo { margin-top: 0.6rem; font-size: clamp(1.7rem, 8vw, 2.4rem); }
  .tagline { margin-bottom: 1.1rem; font-size: 0.9rem; }
  .cards { gap: 0.9rem; }
  .card { padding: 1.1rem; gap: 0.8rem; }
  .card h2 { font-size: 1.1rem; }
  input, select { padding: 0.8rem; }
  .primary { padding: 0.85rem 1rem; font-size: 1.05rem; }
  .cat-chip { padding: 0.5rem 0.8rem; }
  .cat-list { max-height: 40vh; }
}
