:root {
  color-scheme: light;
  font-family: "Poppins", "Segoe UI", Tahoma, sans-serif;
  background: linear-gradient(180deg, #cbe8ff, #f3f8ff 45%, #ffffff 100%);
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: rgba(255, 255, 255, 0.95);
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #38bdf8;
  --text: #07253a;
  --muted: rgba(7, 37, 58, 0.55);
  --border: rgba(15, 23, 42, 0.12);
  --shadow: 0 28px 60px rgba(15, 32, 52, 0.16);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: clamp(1rem, 3vw, 2.5rem);
  color: var(--text);
}

button {
  border: none;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  padding: 0.75rem 1.8rem;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.45);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.primary {
  background: linear-gradient(135deg, var(--primary), #60a5fa);
  color: #fff;
  box-shadow: 0 18px 38px rgba(37, 99, 235, 0.26);
}

.primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 22px 46px rgba(37, 99, 235, 0.32);
}

.ghost {
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.12);
}

.ghost:hover:not(:disabled) {
  transform: translateY(-1px);
  background: rgba(37, 99, 235, 0.12);
}

.ghost--small {
  padding: 0.45rem 1.1rem;
  font-size: 0.85rem;
}

.app {
  width: min(1100px, 100%);
  display: flex;
  flex-direction: column;
  gap: clamp(1rem, 2vw, 1.8rem);
}

.app__header {
  display: grid;
  gap: 0.4rem;
  text-align: center;
}

.app__tagline {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.view {
  display: none;
}

.view--active {
  display: block;
}

.hidden {
  display: none !important;
}

.card {
  position: relative;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(241, 247, 255, 0.82));
  border-radius: 28px;
  padding: clamp(1.3rem, 3vw, 2rem);
  box-shadow: 0 28px 60px rgba(15, 32, 52, 0.16);
  border: 1px solid rgba(148, 163, 184, 0.18);
  backdrop-filter: blur(14px);
}

.auth {
  margin: 0 auto;
  width: min(480px, 100%);
  display: grid;
  gap: 1.2rem;
}

.auth h2 {
  margin: 0;
  text-align: center;
}

.input-group {
  display: grid;
  gap: 0.4rem;
  color: var(--muted);
}

.input-group input {
  padding: 0.8rem 1rem;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.15);
  background: rgba(255, 255, 255, 0.95);
  font: inherit;
  color: var(--text);
}

.input-group input:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.25);
  border-color: transparent;
}

.skins {
  border: none;
  padding: 0;
  display: grid;
  gap: 0.65rem;
}

.skins__options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.6rem;
}

.skins__notice {
  grid-column: 1 / -1;
  margin: 0;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  text-align: center;
  color: var(--muted);
  background: rgba(37, 99, 235, 0.08);
  border-radius: 14px;
}

.skin-option {
  border-radius: 18px;
  border: 2px solid transparent;
  padding: 0.8rem;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(96, 165, 250, 0.12));
  display: grid;
  gap: 0.35rem;
  cursor: pointer;
  transition: border 120ms ease, transform 120ms ease;
}

.skin-option__preview {
  width: 60px;
  height: 60px;
  border-radius: 18px;
  justify-self: center;
  background: rgba(37, 99, 235, 0.1);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.skin-option input {
  display: none;
}

.skin-option__preview[data-has-image="true"] {
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.35), 0 12px 18px rgba(15, 32, 52, 0.15);
}

.skin-option.is-selected {
  border-color: var(--primary);
  transform: translateY(-2px);
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.22), rgba(14, 165, 233, 0.18));
}

.layout {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.panel {
  display: grid;
  gap: 1rem;
  position: relative;
  overflow: hidden;
}

.panel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, rgba(37, 99, 235, 0.12), transparent 60%);
  pointer-events: none;
}

.panel h2 {
  position: relative;
  margin-bottom: 0.2rem;
  padding-bottom: 0.2rem;
}

.panel h2::after {
  content: "";
  position: absolute;
  bottom: -0.15rem;
  left: 0;
  width: 52px;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.7), rgba(14, 165, 233, 0.65));
}

.panel__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.8rem;
}

.list li {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(231, 241, 255, 0.88));
  border-radius: 20px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  padding: 0.85rem 1.15rem 0.85rem 1.3rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 20px 40px rgba(15, 32, 52, 0.12);
}

.list li.placeholder {
  justify-content: center;
  color: var(--muted);
  font-weight: 500;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(245, 249, 255, 0.9));
}

.list--compact li {
  padding: 0.55rem 0.8rem;
  font-size: 0.92rem;
}

.list--players li {
  align-items: flex-start;
  flex-direction: column;
  gap: 0.25rem;
}

.list--players li:first-child {
  border-color: rgba(37, 99, 235, 0.28);
}

.list--players li div {
  color: var(--muted);
  font-size: 0.92rem;
}

.list li strong {
  font-size: 1.05rem;
}

.list li[data-rank] {
  padding-left: 3.4rem;
}

.list li[data-rank]::before {
  content: attr(data-rank);
  position: absolute;
  left: 1.15rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.25);
}

.list li span {
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.list li[data-rank="1"]::before {
  background: linear-gradient(135deg, #facc15, #f97316);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.65);
}

.list li[data-rank="2"]::before {
  background: linear-gradient(135deg, #cbd5f5, #94a3b8);
  color: #0f172a;
}

.list li[data-rank="3"]::before {
  background: linear-gradient(135deg, #fcd34d, #fb7185);
  color: #1f2937;
}

.list li::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.08), transparent 60%);
  opacity: 0;
  transition: opacity 160ms ease;
  pointer-events: none;
}

.list li:hover::after {
  opacity: 1;
}

.player-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.18), rgba(125, 211, 252, 0.2));
  color: var(--primary);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.22);
}

.lobby {
  display: grid;
  gap: 1.5rem;
}

.lobby__header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 20px;
  padding: 1.1rem 1.3rem;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.16);
}

.lobby__actions {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.lobby__body {
  display: grid;
  gap: 1.5rem;
  background: rgba(255, 255, 255, 0.68);
  border-radius: 22px;
  padding: 1.1rem 1.3rem;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.16);
}

.countdown {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.15), rgba(59, 130, 246, 0.12));
  border-radius: 18px;
  padding: 0.7rem 1.4rem;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.countdown span {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.7rem;
  color: var(--primary);
}

.countdown strong {
  font-size: 2.4rem;
  color: var(--primary);
}

.game-ui {
  display: grid;
  gap: 1.5rem;
}

.game-ui__bar {
  display: flex;
  gap: clamp(1rem, 5vw, 2.5rem);
  justify-content: center;
  flex-wrap: wrap;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(231, 241, 255, 0.85));
  border-radius: 26px;
  padding: 1.05rem 1.6rem;
  box-shadow: 0 24px 40px rgba(15, 32, 52, 0.14);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.game-ui__bar > div {
  display: grid;
  gap: 0.25rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.58);
  border-radius: 16px;
  padding: 0.4rem 0.85rem;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.22);
}

.game-ui__bar .label {
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.game-ui__bar strong {
  font-size: 1.35rem;
}

.game-board {
  position: relative;
  background: linear-gradient(180deg, #f6efe2 0%, #f3e4cc 100%);
  border-radius: 32px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  box-shadow: 0 40px 68px rgba(116, 85, 45, 0.18);
  overflow: hidden;
  padding: clamp(1.5rem, 4vw, 2.6rem);
  min-height: 420px;
}

.cotton {
  position: relative;
  width: min(360px, 78vw);
  margin: 0 auto;
  height: min(460px, 68vh);
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
  gap: clamp(0.35rem, 1vh, 0.6rem);
  padding-bottom: clamp(2.2rem, 4vh, 3.1rem);
}

.cotton::before {
  content: "";
  position: absolute;
  top: clamp(0.6rem, 2vh, 1rem);
  bottom: clamp(2.8rem, 6vh, 3.4rem);
  left: 50%;
  transform: translateX(-50%);
  width: clamp(8px, 1vw, 12px);
  background: linear-gradient(180deg, #c8a776 0%, #a16a38 100%);
  border-radius: 999px;
  z-index: 0;
  opacity: 0.75;
  pointer-events: none;
}

.cotton--hit-left {
  animation: cottonHitLeft 160ms ease;
}

.cotton--hit-right {
  animation: cottonHitRight 160ms ease;
}

.cotton-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(88px, 1fr));
  gap: clamp(1rem, 3vw, 2.2rem);
  align-items: center;
  justify-items: center;
  min-height: clamp(48px, 8vh, 64px);
  transition: transform 140ms ease, opacity 160ms ease;
  --row-offset: 0px;
  opacity: var(--row-opacity, 1);
  transform: translateY(var(--row-offset));
  position: relative;
  z-index: 1;
}

.cotton-row--active {
  --row-offset: 6px;
  filter: drop-shadow(0 14px 20px rgba(15, 32, 52, 0.18));
}

.cotton-cell {
  display: grid;
  place-items: center;
  width: clamp(88px, 14vw, 110px);
  aspect-ratio: 1;
  pointer-events: none;
}

.cotton-cell--left {
  justify-self: end;
}

.cotton-cell--right {
  justify-self: start;
}

.cotton-cell img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 160ms ease, opacity 160ms ease, filter 160ms ease;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.cotton-cell--empty img {
  opacity: 0.35;
  filter: saturate(0.2);
  transform: scale(0.82);
}

.cotton-row--active .cotton-cell--full img {
  transform: scale(1.08);
  filter: drop-shadow(0 16px 28px rgba(15, 23, 42, 0.16));
}

.player {
  position: absolute;
  bottom: clamp(1.4rem, 4vh, 2.1rem);
  left: 50%;
  --player-offset: -210%;
  transform: translateX(var(--player-offset));
  width: clamp(96px, 16vw, 116px);
  height: clamp(96px, 16vw, 118px);
  transition: transform 160ms ease;
  pointer-events: none;
  --player-accent: #2563eb;
  --player-shadow: rgba(37, 99, 235, 0.28);
  z-index: 2;
}

.player::after {
  content: "";
  position: absolute;
  bottom: clamp(-0.9rem, -1.8vh, -0.7rem);
  left: 50%;
  transform: translateX(-50%);
  width: clamp(110px, 22vw, 140px);
  height: clamp(28px, 5vw, 38px);
  background: radial-gradient(circle at center, var(--player-shadow) 0%, transparent 70%);
  opacity: 0.8;
  filter: blur(2px);
  z-index: 0;
}

.player--right {
  --player-offset: 98%;
}

.player__body {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  background-image: url("postac1.png");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  --player-direction: 1;
  --player-swing: 0px;
  transform: scaleX(var(--player-direction)) translateY(var(--player-swing));
  transition: transform 140ms ease;
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.55), 0 18px 28px var(--player-shadow);
  border-radius: 20px;
}

.player--right .player__body {
  --player-direction: -1;
}

.player--swing .player__body {
  background-image: url("postac1-uderzenie.png");
  --player-swing: -4px;
}

.controls-hint {
  position: absolute;
  bottom: 0.8rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 24px rgba(15, 32, 52, 0.14);
  pointer-events: none;
}

@keyframes cottonHitLeft {
  0% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(-8px);
  }
  100% {
    transform: translateX(0);
  }
}

@keyframes cottonHitRight {
  0% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(8px);
  }
  100% {
    transform: translateX(0);
  }
}

.gauge {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(260px, 70vw);
  height: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.65), rgba(226, 232, 240, 0.4));
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.1), 0 8px 18px rgba(15, 23, 42, 0.22);
  transition: opacity 160ms ease;
}

.gauge__label {
  position: absolute;
  top: 1rem;
  right: clamp(1rem, 4vw, 2rem);
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.1), rgba(14, 165, 233, 0.12));
  color: var(--primary);
  padding: 0.32rem 0.75rem;
  border-radius: 12px;
  font-size: 0.78rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.gauge.hidden,
.gauge__label.hidden,
#opponentBlock.hidden-block {
  display: none !important;
}

#gaugeFill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #22c55e, #38bdf8, #2563eb);
  transition: width 60ms ease;
}

.result {
  display: grid;
  gap: 1.4rem;
  text-align: center;
}

.result > h2 {
  margin-bottom: -0.3rem;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  -webkit-background-clip: text;
  color: transparent;
}

.result__scores,
.result__leaderboard {
  display: grid;
  gap: 0.7rem;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 22px;
  padding: 1rem 1.2rem;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.15);
}

.result__actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translate(-50%, -20px);
  padding: 0.6rem 1.2rem;
  background: rgba(37, 99, 235, 0.9);
  color: #fff;
  border-radius: 999px;
  box-shadow: 0 18px 36px rgba(15, 32, 52, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 50;
}

.toast--show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 860px) {
  body {
    padding: clamp(0.8rem, 5vw, 1.2rem);
  }
  .layout {
    grid-template-columns: 1fr;
  }
  .lobby__header {
    flex-direction: column;
    align-items: stretch;
  }
  .lobby__actions {
    justify-content: space-between;
  }
}

@media (max-width: 640px) {
  .card {
    border-radius: 20px;
  }
  .cotton {
    width: min(260px, 88vw);
    gap: 0.4rem;
  }
  .cotton-cell {
    width: clamp(70px, 22vw, 86px);
  }
  .player {
    width: clamp(82px, 28vw, 96px);
    height: clamp(82px, 28vw, 96px);
    --player-offset: -185%;
  }
  .player--right {
    --player-offset: 72%;
  }
}
