:root {
  --bg: #0a0d16;
  --bg-soft: #141a2b;
  --panel: #171e33;
  --line: #26304d;
  --text: #e8ecf7;
  --muted: #8f9ab8;
  --accent: #4ecdc4;
  --accent-2: #ff6b6b;
  --gold: #ffd166;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; }

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  padding: 11px 18px;
  background: var(--accent);
  color: #06231f;
  font-weight: 650;
  transition: filter .15s, transform .1s;
}
button:hover:not(:disabled) { filter: brightness(1.1); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--accent-2); color: #2a0808; }
button.small { padding: 7px 12px; font-size: 13px; }

input[type="text"], input[type="email"] {
  font: inherit;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0e1424;
  color: var(--text);
  width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

a { color: var(--accent); }

.screen { display: none; flex: 1; min-height: 0; }
.screen.active { display: flex; }

/* ---- logowanie ---- */

#login {
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  width: min(440px, 100%);
}
.card h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: -.5px; }
.card .sub { color: var(--muted); margin: 0 0 22px; font-size: 15px; line-height: 1.5; }
.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
  margin: 20px 0;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---- lobby ---- */

#lobby { flex-direction: column; overflow-y: auto; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  position: sticky; top: 0; z-index: 5;
}
.topbar .brand { font-weight: 800; font-size: 19px; letter-spacing: -.3px; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 14px; }
.badge {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  padding: 3px 8px; border-radius: 999px; background: rgba(78,205,196,.15); color: var(--accent);
}
.badge.admin { background: rgba(255,209,102,.16); color: var(--gold); }

.wrap { padding: 22px; max-width: 1180px; margin: 0 auto; width: 100%; }
.grid { display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid.two { grid-template-columns: 1.35fr 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.panel h2 { margin: 0 0 14px; font-size: 16px; text-transform: uppercase; letter-spacing: 1.1px; color: var(--muted); }

.game-list { display: flex; flex-direction: column; gap: 10px; }
.game-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #10182b;
}
.game-item.done { opacity: .55; }
.game-item.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.game-item .num {
  width: 30px; height: 30px; flex: none; border-radius: 8px;
  display: grid; place-items: center;
  background: #1d2740; color: var(--muted); font-weight: 700; font-size: 14px;
}
.game-item .info { flex: 1; min-width: 0; }
.game-item .info strong { display: block; font-size: 15px; }
.game-item .info span { color: var(--muted); font-size: 13px; }

.players { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 999px;
  background: #10182b; border: 1px solid var(--line); font-size: 14px;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.chip.admin .dot { background: var(--gold); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .7px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.me td { background: rgba(78,205,196,.08); }
.rank-1 { color: var(--gold); font-weight: 700; }

.controls { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 10px 0 0; }
.error { color: var(--accent-2); font-size: 14px; margin-top: 10px; min-height: 20px; }

/* ---- gra ---- */

#game { position: relative; background: #05070d; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  pointer-events: none;
  font-size: 14px;
  text-shadow: 0 2px 8px rgba(0,0,0,.9);
}
#hud .spacer { flex: 1; }
#hud .timer { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
#hud .title { font-weight: 700; }
#hud .role { color: var(--muted); }
#hud button { pointer-events: auto; }

#countdown {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: clamp(80px, 22vw, 220px); font-weight: 900; color: #fff;
  text-shadow: 0 8px 40px rgba(78,205,196,.6);
  pointer-events: none;
}

#helpbar {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 10px 16px 14px;
  background: linear-gradient(to top, rgba(5,7,13,.92), transparent);
  color: var(--muted); font-size: 13px; text-align: center;
  pointer-events: none;
}

/* sterowanie dotykowe */
#touch { position: absolute; inset: 0; pointer-events: none; display: none; }
#touch.on { display: block; }
#stick {
  position: absolute;
  left: calc(24px + env(safe-area-inset-left, 0px));
  bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  width: 132px; height: 132px; border-radius: 50%;
  background: rgba(255,255,255,.06); border: 2px solid rgba(255,255,255,.16);
  pointer-events: auto; touch-action: none;
}
#stick .knob {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px;
  margin: -28px 0 0 -28px; border-radius: 50%;
  background: rgba(78,205,196,.75); box-shadow: 0 4px 20px rgba(0,0,0,.5);
}
#actionBtn {
  position: absolute; right: 28px; bottom: 44px;
  width: 108px; height: 108px; border-radius: 50%;
  background: rgba(255,107,107,.8); color: #fff; font-weight: 800; font-size: 15px;
  pointer-events: auto; touch-action: none; display: none;
  border: 2px solid rgba(255,255,255,.25);
}
#actionBtn.on { display: block; }

/* drugi przycisk — tylko dla wylosowanych bohaterów w „Młotach" */
#skillBtn {
  position: absolute; right: 150px; bottom: 70px;
  width: 86px; height: 86px; border-radius: 50%;
  background: rgba(255,209,102,.85); color: #2a2110; font-weight: 800; font-size: 13px;
  pointer-events: auto; touch-action: none; display: none;
  border: 2px solid rgba(255,255,255,.25);
  padding: 0;
}
#skillBtn.on { display: block; }

/* przyciski kolosa („Młoty" na dotyku): młot pod kciukiem, tąpnięcie po skosie nad nim */
#hammerBtn {
  position: absolute;
  right: calc(26px + env(safe-area-inset-right, 0px));
  bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  width: 118px; height: 118px; border-radius: 50%;
  background: rgba(255,107,107,.85); color: #fff; font-weight: 800; font-size: 16px;
  pointer-events: auto; touch-action: none; display: none;
  border: 2px solid rgba(255,255,255,.25);
  padding: 0;
}
#hammerBtn.on { display: block; }
#slamBtn {
  position: absolute;
  right: calc(158px + env(safe-area-inset-right, 0px));
  bottom: calc(120px + env(safe-area-inset-bottom, 0px));
  width: 92px; height: 92px; border-radius: 50%;
  background: rgba(255,159,67,.85); color: #2a1808; font-weight: 800; font-size: 12px;
  pointer-events: auto; touch-action: none; display: none;
  border: 2px solid rgba(255,255,255,.25);
  padding: 0;
}
#slamBtn.on { display: block; }

/* Cooldown na przycisku jak w mobilnych MOB-ach: przyciemnienie + radialne wycieranie
   (conic-gradient zdejmowany przez --cd) + cyfra sekund pośrodku (z data-cd). */
.cd-btn { position: relative; overflow: hidden; user-select: none; -webkit-user-select: none; }
.cd-btn.oncd { filter: saturate(.45) brightness(.75); }
.cd-btn.oncd::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  background: conic-gradient(rgba(5,7,13,.6) calc(var(--cd, 0) * 1turn), transparent 0);
}
.cd-btn.oncd::after {
  content: attr(data-cd); position: absolute; inset: 0; pointer-events: none;
  display: grid; place-items: center;
  font-size: 30px; font-weight: 900; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.85);
}
/* ładowanie ciosu: rosnący czerwony pierścień mocy zamiast zaciemnienia */
.cd-btn.charging::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  background: conic-gradient(rgba(255,60,60,.8) calc(var(--charge, 0) * 1turn), rgba(5,7,13,.35) 0);
}
.cd-btn.ready-flash { animation: cdReady .35s ease-out; }
@keyframes cdReady {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,209,102,.85); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); box-shadow: 0 0 26px 6px rgba(255,209,102,0); }
}

/* ---- wymuszenie orientacji poziomej ---- */
#rotateOverlay { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  body.in-game #rotateOverlay {
    display: grid; place-items: center;
    position: fixed; inset: 0; z-index: 40;
    background: rgba(5,7,13,.96);
  }
}
.rotate-box { text-align: center; color: var(--text); font-size: 18px; font-weight: 700; }
.rotate-icon {
  font-size: 64px;
  animation: rotatePhone 1.6s ease-in-out infinite;
}
@keyframes rotatePhone {
  0%, 20% { transform: rotate(0); }
  60%, 100% { transform: rotate(90deg); }
}

/* ---- wybór zdolności kolosa przed bitwą ---- */
#prep {
  position: absolute; inset: 0; display: none; place-items: center;
  background: rgba(5,7,13,.9); padding: 18px; overflow: auto;
}
#prep.on { display: grid; }
.prep-card {
  width: min(920px, 100%);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px;
}
.prep-card h2 { margin: 0; font-size: 20px; }
.perk-grid {
  display: grid; gap: 12px; margin-top: 16px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}
.perk {
  text-align: left; padding: 14px; border-radius: 12px;
  border: 1px solid var(--line); background: #10182b; color: var(--text);
  cursor: default; transition: border-color .15s, background .15s;
}
.perk.pickable { cursor: pointer; }
.perk.pickable:hover { border-color: var(--accent); }
.perk.chosen { border-color: var(--gold); background: rgba(255,209,102,.12); }
.perk strong { display: block; font-size: 15px; margin-bottom: 6px; }
.perk .desc { display: block; color: var(--muted); font-size: 13px; line-height: 1.5; }
.perk .counter { display: block; margin-top: 8px; color: var(--accent); font-size: 12px; }
.prep-choices { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.prep-timer { margin-top: 12px; text-align: right; color: var(--muted); font-size: 14px; }
.prep-timer span { color: var(--gold); font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---- panel adminów ---- */
.admin-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.admin-row .email { flex: 1; font-size: 14px; word-break: break-all; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: #1d2740; color: var(--muted); }
.tag.domain { background: rgba(255,209,102,.15); color: var(--gold); }
.tag.granted { background: rgba(78,205,196,.15); color: var(--accent); }
.form-row { display: flex; gap: 10px; margin: 14px 0 4px; }
@media (max-width: 560px) { .form-row { flex-direction: column; } }
