:root {
  --bg-deep: #0a0e12;
  --bg-panel: rgba(22, 30, 40, 0.92);
  --felt: #1a5c42;
  --felt-dark: #0f3d2c;
  --accent: #f0b429;
  --accent-glow: rgba(240, 180, 41, 0.35);
  --primary: #3d8bfd;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --danger: #ff6b6b;
  --success: #4ade80;
  --radius: 14px;
  --font: 'Outfit', system-ui, sans-serif;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

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

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-deep);
  overflow-x: hidden;
}

.app-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(61, 139, 253, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(240, 180, 41, 0.08), transparent),
    var(--bg-deep);
  z-index: -1;
}

.screen {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
  padding: 1rem;
  max-width: 960px;
  margin: 0 auto;
}

.screen--active {
  display: flex;
}

.hero {
  text-align: center;
  padding: 2rem 0 1.5rem;
}

.hero__title {
  font-size: clamp(2.5rem, 8vw, 3.5rem);
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fff 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero__sub {
  color: var(--text-muted);
  margin: 0.5rem 0 0;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field__label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input, select {
  font: inherit;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
}

input:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.lobby-actions .btn {
  width: 100%;
}

/* Popup (dialog) */
.modal {
  border: none;
  padding: 0;
  max-width: calc(100vw - 2rem);
  background: transparent;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.modal__card {
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  min-width: min(100%, 320px);
}

.modal__title {
  margin: 0 0 0.35rem;
  font-size: 1.2rem;
}

.modal__hint {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.modal__actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.modal__actions .btn {
  flex: 1;
}

.modal__actions .btn--ghost {
  width: auto;
}

.btn {
  font: inherit;
  font-weight: 600;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  width: 100%;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: linear-gradient(135deg, var(--primary), #2563eb);
  color: #fff;
}

.btn--accent {
  background: linear-gradient(135deg, var(--accent), #d97706);
  color: #1a1200;
  box-shadow: 0 0 24px var(--accent-glow);
}

.btn--secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.btn--next {
  background: linear-gradient(135deg, #4ade80 0%, #16a34a 100%);
  color: #052e16;
  font-weight: 700;
  box-shadow: 0 0 22px rgba(74, 222, 128, 0.38);
}

.btn--next:hover:not(:disabled) {
  box-shadow: 0 0 28px rgba(74, 222, 128, 0.5);
}

.btn--waiting-anim {
  opacity: 0.55;
  cursor: wait;
}

#btn-spawn-bots {
  margin-bottom: 0;
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  width: auto;
}

.btn--sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.btn--lg {
  padding: 1rem 1.5rem;
  font-size: 1.1rem;
}

.error-msg {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0.75rem 0 0;
}

/* Pokój — układ pod telefon (stół między nagłówkiem a przyciskami) */
#screen-room.screen--active {
  padding: 0.4rem 0.85rem 0.6rem;
  min-height: 100dvh;
  max-height: 100dvh;
  /* Pionowy pasek przewijania, gdy zawartość (np. przycisk „Rozpocznij mecz")
     nie mieści się na ekranie — wcześniej była ucinana i nieosiągalna. */
  overflow-x: hidden;
  overflow-y: auto;
}

#screen-room .room-bar {
  flex-shrink: 0;
}

#screen-room .scoreboard {
  flex-shrink: 0;
  margin-bottom: 0.35rem;
  max-height: 4.5rem;
  overflow-y: auto;
}

#screen-room .game-stage {
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

#screen-room .room-actions {
  flex-shrink: 0;
  padding: 0.25rem 0 0.2rem;
}

.room-actions__stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: stretch;
}

.room-actions__stack > [hidden] {
  display: none !important;
}

/* Przyciski akcji pod filcem — jednolity rozmiar i odstęp */
.room-actions__stack--in-game {
  margin-top: 15px;
}

.room-actions__stack--in-game > .btn {
  padding: 1rem 1.5rem;
  font-size: 1.1rem;
  min-height: 3.25rem;
}

.player-seat__play-zone--war-pulsing .playing-card {
  animation: war-card-pulse 1.35s ease-in-out infinite;
}

.player-seat__play-zone--war-pulsing {
  animation: war-zone-pulse 1.35s ease-in-out infinite;
}

@keyframes war-zone-pulse {
  0%, 100% {
    box-shadow: inset 0 0 0 0 rgba(240, 180, 41, 0);
    background: rgba(240, 180, 41, 0.06);
  }
  50% {
    box-shadow: inset 0 0 12px 2px rgba(240, 180, 41, 0.35);
    background: rgba(240, 180, 41, 0.14);
  }
}

#screen-room .game-announce {
  flex-shrink: 0;
  width: 100%;
  margin: 0;
  padding: 0.7rem 0.9rem;
  text-align: center;
  border-radius: 12px;
  border: 2px solid rgba(96, 165, 250, 0.45);
  background: rgba(10, 22, 38, 0.92);
  box-shadow:
    0 4px 22px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.game-announce__title {
  margin: 0 0 0.25rem;
  font-size: clamp(1.2rem, 4.8vw, 1.55rem);
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
}

.game-announce__text {
  margin: 0;
  font-size: clamp(0.95rem, 3.6vw, 1.12rem);
  font-weight: 600;
  line-height: 1.4;
  color: #8ecfff;
}

.game-announce--event .game-announce__text {
  font-size: clamp(1.02rem, 3.9vw, 1.2rem);
  font-weight: 700;
  color: #ffe08a;
}

.game-announce--error .game-announce__text {
  color: #ff9f9f;
}

.game-announce--match {
  border-color: rgba(240, 180, 41, 0.65);
  background: linear-gradient(
    135deg,
    rgba(240, 180, 41, 0.18) 0%,
    rgba(10, 22, 38, 0.95) 100%
  );
}

.game-announce--match .game-announce__text {
  color: var(--text);
  font-weight: 500;
}

.game-announce--hint .game-announce__text {
  color: #9eb8d4;
  font-weight: 500;
  font-size: clamp(0.88rem, 3.2vw, 1rem);
}

.room-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "code  leave"
    "phase phase";
  align-items: center;
  column-gap: 0.5rem;
  row-gap: 0.1rem;
  padding: 0.5rem 0;
}

/* „rozpuszczamy” wrapper, by kod+kopiuj i Wyjdź trafiły w jeden rząd siatki */
.room-bar__info {
  display: contents;
}

.room-bar__code-row {
  grid-area: code;
}

.room-bar__phase {
  grid-area: phase;
}

.room-bar__btn--leave {
  grid-area: leave;
  align-self: center;
}

.room-bar__code-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.room-bar__code {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.15em;
}

.room-bar__btn {
  font: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.38rem 0.7rem;
  border-radius: 9px;
  border: 1.5px solid transparent;
  cursor: pointer;
  width: auto;
  flex-shrink: 0;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.room-bar__btn:active {
  transform: scale(0.96);
}

.room-bar__btn--copy {
  border-color: rgba(96, 165, 250, 0.55);
  background: linear-gradient(160deg, rgba(37, 99, 235, 0.35), rgba(30, 58, 95, 0.5));
  color: #bfdbfe;
  box-shadow: 0 0 14px rgba(59, 130, 246, 0.25);
}

.room-bar__btn--leave {
  border-color: rgba(248, 113, 113, 0.45);
  background: linear-gradient(160deg, rgba(127, 29, 29, 0.35), rgba(40, 20, 24, 0.55));
  color: #fecaca;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.18);
}

.room-bar__btn--flash-ok {
  border-color: var(--success);
  box-shadow: 0 0 16px rgba(74, 222, 128, 0.45);
}

.room-bar__btn--flash-err {
  border-color: var(--danger);
  box-shadow: 0 0 14px rgba(255, 107, 107, 0.4);
}

.score-chip--pending {
  border-style: dashed;
  opacity: 0.85;
}

.score-chip__actions {
  display: inline-flex;
  gap: 0.25rem;
  margin-left: 0.35rem;
}

.score-chip__actions button {
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.room-bar__phase {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.scoreboard {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.score-chip {
  box-sizing: border-box;
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  text-align: left;
}

.score-chip--me {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.table-wrap {
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0;
  overflow: visible;
}

.table-felt {
  position: relative;
  width: min(100%, calc(100dvh - 14rem), calc(100vw - 1rem));
  aspect-ratio: 1 / 1;
  max-height: 100%;
  margin: 0 auto;
  border-radius: 16px;
  overflow: visible;
  background:
    radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  box-shadow:
    inset 0 0 50px rgba(0, 0, 0, 0.35),
    0 6px 24px rgba(0, 0, 0, 0.4);
  border: 3px solid rgba(255, 255, 255, 0.08);
}

.table-center {
  position: absolute;
  inset: 38% 38%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.pot-badge {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 0.5rem;
}

.player-seats {
  position: absolute;
  inset: 10% 9%;
  pointer-events: none;
}

.player-seat {
  position: absolute;
  transform: translate(-50%, -50%);
  transition: transform 0.3s ease;
  width: 0;
  height: 0;
}

.player-seat__inner {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.player-seat__toward-center,
.player-seat__toward-edge {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: min(42vw, 140px);
}

.player-seat__toward-center {
  transform: translate(
    calc(var(--dir-x, 0) * min(2.4vw, 12px)),
    calc(var(--dir-y, 0) * min(2.4vw, 12px))
  );
}

.player-seat__toward-edge {
  transform: translate(
    calc(var(--dir-x, 0) * min(-3vw, -14px)),
    calc(var(--dir-y, 0) * min(-3vw, -14px))
  );
}

.player-seat__inner--top .player-seat__toward-edge { order: 1; }
.player-seat__inner--top .player-seat__toward-center { order: 2; }

.player-seat__inner--bottom .player-seat__toward-center { order: 1; }
.player-seat__inner--bottom .player-seat__toward-edge { order: 2; }

.player-seat__inner--left {
  flex-direction: row;
  align-items: center;
}
.player-seat__inner--left .player-seat__toward-edge { order: 1; }
.player-seat__inner--left .player-seat__toward-center { order: 2; }

.player-seat__inner--right {
  flex-direction: row;
  align-items: center;
}
.player-seat__inner--right .player-seat__toward-center { order: 1; }
.player-seat__inner--right .player-seat__toward-edge { order: 2; }

.player-seat__inner--left .player-seat__toward-center,
.player-seat__inner--right .player-seat__toward-center {
  flex-direction: row;
  align-items: flex-end;
  gap: 0.3rem;
}

/* Boczne miejsca: etykieta + bank + licznik w kolumnie — długa nazwa nie wypycha licznika poza ekran */
.player-seat__inner--left .player-seat__toward-edge,
.player-seat__inner--right .player-seat__toward-edge {
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  max-width: min(30vw, 96px);
  transform: translate(
    calc(var(--dir-x, 0) * min(-2vw, -10px)),
    calc(var(--dir-y, 0) * min(-2vw, -10px))
  );
}

.player-seat__inner--left .player-seat__edge-label,
.player-seat__inner--right .player-seat__edge-label {
  max-width: min(28vw, 92px);
}

.player-seat__zone-wrap {
  z-index: 2;
}

.player-seat__zone-wrap:has(.player-seat__hand-review) {
  max-width: min(228px, 54vw);
}

.player-seat__edge-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: min(44vw, 120px);
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(240, 180, 41, 0.45);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.player-seat__bank {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 0.35rem;
  z-index: 1;
  overflow: visible;
}

.player-seat__war-stash {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  min-width: 46px;
  min-height: 48px;
  padding: 0.15rem 0.25rem;
  border-radius: 6px;
  background: rgba(28, 48, 78, 0.82);
  border: 2px solid rgba(130, 175, 230, 0.55);
  box-shadow: inset 0 0 10px rgba(80, 130, 200, 0.2);
  overflow: visible;
}

.player-seat__war-stash--empty {
  min-height: 40px;
  opacity: 0.5;
  border-style: dashed;
  border-color: rgba(130, 175, 230, 0.28);
  background: rgba(20, 35, 55, 0.45);
}

.war-stash-placeholder {
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: rgba(180, 205, 240, 0.55);
  text-transform: uppercase;
}

.war-stash-label {
  font-size: 0.52rem;
  font-weight: 600;
  color: rgba(180, 210, 255, 0.85);
  line-height: 1;
}

.player-seat__play-zone .playing-card--landed-war {
  position: relative;
  flex-shrink: 0;
}

.player-seat__play-zone--flash {
  animation: play-zone-flash 0.5s ease-out;
}

@keyframes play-zone-flash {
  0% {
    box-shadow: 0 0 0 0 rgba(240, 180, 41, 0.8);
    background: rgba(240, 180, 41, 0.2);
  }
  100% {
    box-shadow: none;
    background: rgba(0, 0, 0, 0.18);
  }
}

.player-seat__play-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-height: clamp(58px, 15vw, 88px);
  min-width: clamp(40px, 11vw, 60px);
  padding: 0.2rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  overflow: visible;
}

.player-seat__play-zone--war-pending {
  background: rgba(240, 180, 41, 0.08);
}

.play-zone-war-tag {
  position: relative;
  z-index: 4;
  flex-shrink: 0;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent-glow);
  line-height: 1;
  opacity: 1;
  visibility: visible;
  pointer-events: none;
}

.player-seat__play-zone--war-pulsing .play-zone-war-tag {
  animation: none;
  opacity: 1;
}

.player-seat--war-pending .player-seat__name {
  color: var(--accent);
  animation: war-name-pulse 1.5s ease-in-out infinite;
}

.player-seat__play-empty {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.35);
}

.player-seat__hand-review {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.3rem;
  width: min(220px, 52vw);
  min-height: 88px;
  padding: 0.4rem 0.45rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.18);
  overflow: visible;
}

.player-seat__hand-review--count-only {
  justify-content: center;
  align-items: center;
  min-height: clamp(88px, 20vw, 112px);
  padding: 0.5rem 0.6rem;
}

.hand-review__empty-center {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: clamp(72px, 16vw, 96px);
  text-align: center;
}

.hand-review__score-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  width: 100%;
  text-align: center;
}

.hand-review__count-line {
  font-size: clamp(1.35rem, 5.8vw, 1.95rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.92);
  line-height: 1.1;
}

.hand-review__points-line {
  font-size: clamp(0.8rem, 3vw, 0.95rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.2;
}

.hand-review__count-only {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: clamp(72px, 16vw, 96px);
}

.hand-review__aces-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
  align-items: flex-end;
  padding-top: 0.15rem;
  overflow: visible;
}

.hand-review__aces-row .playing-card {
  flex-shrink: 0;
}

.hand-review__grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  justify-content: center;
  align-content: flex-start;
  overflow: visible;
}

.hand-review__chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.06rem;
  padding: 0.18rem 0.38rem;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.94);
  color: #1a1a1a;
  font-weight: 700;
  line-height: 1.15;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.hand-review__chip--red {
  color: #c41e3a;
}

.hand-review__chip--ace {
  background: linear-gradient(145deg, #fff8e6 0%, #ffe08a 100%);
  outline: 1.5px solid var(--accent);
  outline-offset: 0;
}

.hand-review__chip-rank {
  font-size: 0.82rem;
}

.hand-review__chip-suit {
  font-size: 0.78rem;
}

.hand-review__aces {
  width: 100%;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 0.15rem;
}

#btn-award-points {
  margin-bottom: 0.5rem;
}

.player-seat__edge-label .player-seat__name {
  margin-top: 0;
  max-width: min(40vw, 110px);
  font-size: clamp(0.68rem, 3.2vw, 0.84rem);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.96);
}

.player-seat__inner--left .player-seat__edge-label .player-seat__name,
.player-seat__inner--right .player-seat__edge-label .player-seat__name {
  max-width: 100%;
}

.player-seat__name {
  font-size: clamp(0.62rem, 2.8vw, 0.72rem);
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
  max-width: min(38vw, 88px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  line-height: 1.15;
  margin-top: 0.1rem;
}

.player-seat__count {
  font-size: clamp(0.58rem, 2.5vw, 0.68rem);
  color: rgba(255, 255, 255, 0.75);
  text-align: center;
}

.player-seat--war .player-seat__name {
  color: var(--accent);
}

.player-seat--eliminated {
  opacity: 0.35;
}

.room-actions {
  padding: 0;
}

.player-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.player-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.player-list__actions {
  display: flex;
  gap: 0.35rem;
}

.player-list__actions button {
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
}

.approve-btn {
  background: rgba(74, 222, 128, 0.2);
  color: var(--success);
}

.reject-btn {
  background: rgba(255, 107, 107, 0.2);
  color: var(--danger);
}

.fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  overflow: hidden;
}

@media (min-width: 640px) {
  .screen { padding: 1.5rem 2rem; }
}

/* ===== Prośba o obrót telefonu (orientacja pozioma) ===== */
.rotate-notice {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  background:
    radial-gradient(ellipse 80% 60% at 50% 30%, rgba(61, 139, 253, 0.18), transparent),
    var(--bg-deep);
}

.rotate-notice__card {
  max-width: 340px;
}

.rotate-notice__icon {
  color: var(--accent);
  display: inline-flex;
  transform-origin: 50% 50%;
  animation: rotate-hint 2.4s ease-in-out infinite;
}

.rotate-notice__title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 1rem 0 0.5rem;
}

.rotate-notice__text {
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

@keyframes rotate-hint {
  0%, 40% { transform: rotate(0deg); }
  70%, 100% { transform: rotate(-90deg); }
}

/* Pokaż prośbę o obrót tylko na telefonach (dotyk) w pionie, podczas gry */
@media (hover: none) and (pointer: coarse) and (orientation: portrait) {
  body.in-room .rotate-notice {
    display: flex;
  }
}

/* Lobby na komórce — bez górnego marginesu, kompaktowy nagłówek */
@media (hover: none) and (pointer: coarse) {
  #screen-lobby.screen--active {
    padding-top: 0;
    justify-content: center;
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  #screen-lobby.screen--active {
    padding-top: 0;
    justify-content: center;
  }

  #screen-lobby .hero {
    padding: 0.4rem 0 0.6rem;
  }

  #screen-lobby .hero__title {
    font-size: clamp(1.6rem, 8vh, 2.6rem);
  }
}

/* ===== Układ poziomy (telefon na boku): szeroki stół + wąski panel ===== */
@media (orientation: landscape) and (max-height: 600px) {
  #screen-room.screen--active {
    display: grid;
    /* Stół zajmuje większość szerokości, panel z przyciskami jest wąski */
    grid-template-columns: minmax(0, 1fr) clamp(7rem, 22vw, 10.5rem);
    /* Wiersz z punktacją jest elastyczny i przewijany, dzięki czemu komunikat
       i przyciski akcji (np. „Rozpocznij mecz") są ZAWSZE widoczne na dole,
       nawet przy 8 graczach — wcześniej długa lista pigułek spychała przyciski
       poza ekran i były nieosiągalne. */
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "bar    bar"
      "table  score"
      "table  announce"
      "table  actions";
    column-gap: 0.45rem;
    row-gap: 0.25rem;
    height: 100dvh;
    max-height: 100dvh;
    max-width: 100%;
    margin: 0;
    /* Niewielki margines wokół filcu, by nie dotykał krawędzi ekranu telefonu. */
    padding: 0.5rem 0.85rem;
    overflow: hidden;
  }

  #screen-room .room-bar {
    grid-area: bar;
    padding: 0.1rem 0;
  }

  /* Stół i komunikat są wewnątrz .game-stage — rozpuszczamy go w siatce */
  #screen-room .game-stage {
    display: contents;
  }

  #screen-room .table-wrap {
    grid-area: table;
    min-height: 0;
    min-width: 0;
    height: 100%;
    width: 100%;
    padding: 0;
    align-items: stretch;
  }

  /* Boczna kolumna: punktacja (przewijana) + komunikat + przycisk akcji */
  #screen-room .scoreboard {
    grid-area: score;
    align-self: stretch;
    min-height: 0;
    margin: 0;
    overflow-y: auto;
    align-content: flex-start;
    gap: 0.25rem;
  }

  #screen-room .score-chip {
    padding: 0.2rem 0.5rem;
    font-size: 0.72rem;
  }

  #screen-room #game-announce {
    grid-area: announce;
    align-self: center;
    padding: 0.45rem 0.55rem;
  }

  #screen-room .game-announce__title {
    font-size: 0.95rem;
  }

  #screen-room .game-announce__text {
    font-size: 0.82rem;
  }

  #screen-room .room-actions {
    grid-area: actions;
    align-self: end;
    padding: 0;
  }

  #screen-room .room-actions__stack--in-game {
    margin-top: 0;
  }

  /* Kompaktowe przyciski w wąskim panelu (także w lobby: „Rozpocznij mecz",
     „Dodaj graczy") — by zmieściły się w pionie i nie wypychały się poza ekran. */
  #screen-room .room-actions__stack > .btn {
    padding: 0.5rem 0.6rem;
    font-size: 0.9rem;
    min-height: 2.4rem;
  }

  /* Stół wypełnia całą dostępną przestrzeń (szeroka elipsa) — wykorzystuje
     pełną szerokość ekranu i rozsuwa miejsca graczy, by karty się nie zlewały. */
  .table-felt {
    width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    aspect-ratio: auto;
  }

  /* Krąg miejsc: mały margines, bo gracze z góry/dołu mają teraz układ poziomy
     (niski), a z boków pionowy. Margines poziomy nieco większy, by talia i
     „Wojna” graczy bocznych nie wychodziły poza filc/ekran. */
  #screen-room .player-seats {
    inset: 13% 8%;
  }

  /* Boczni gracze: bez dodatkowego „wypychania na zewnątrz”, by „Wojna” i talia
     zostały na filcu. */
  #screen-room .player-seat__inner--left .player-seat__toward-edge,
  #screen-room .player-seat__inner--right .player-seat__toward-edge {
    transform: none;
  }

  /* Górny i dolny gracz w poziomie: układ POZIOMY (jak boczni) — niski pasek
     zamiast wysokiego stosu, dzięki czemu nazwa, talia, „Wojna” i karta
     mieszczą się przy krawędzi, a pola kart nie zachodzą na środku. */
  #screen-room .player-seat__inner--top,
  #screen-room .player-seat__inner--bottom {
    flex-direction: row;
    align-items: center;
    gap: 0.3rem;
  }

  #screen-room .player-seat__inner--top .player-seat__toward-center,
  #screen-room .player-seat__inner--bottom .player-seat__toward-center,
  #screen-room .player-seat__inner--top .player-seat__toward-edge,
  #screen-room .player-seat__inner--bottom .player-seat__toward-edge {
    transform: none;
  }

  #screen-room .player-seat__inner--top .player-seat__toward-edge,
  #screen-room .player-seat__inner--bottom .player-seat__toward-edge {
    flex-direction: row;
    align-items: center;
    gap: 0.3rem;
    max-width: none;
  }

  /* Nazwa gracza góra/dół nie rozpycha paska */
  #screen-room .player-seat__inner--top .player-seat__edge-label,
  #screen-room .player-seat__inner--bottom .player-seat__edge-label {
    max-width: min(28vw, 110px);
  }

  /* Mniejsze karty na komórce — całość mieści się na filcu */
  #screen-room .playing-card--lg {
    --card-w: clamp(30px, 7.2vh, 44px);
    --card-h: clamp(42px, 10vh, 60px);
  }

  #screen-room .playing-card--sm {
    --card-w: 24px;
    --card-h: 35px;
  }

  #screen-room .player-seat__play-zone {
    min-height: clamp(44px, 11vh, 64px);
    min-width: clamp(32px, 8vh, 48px);
    padding: 0.12rem;
    gap: 0.1rem;
  }

  #screen-room .player-seat__war-stash {
    min-width: 34px;
    min-height: 36px;
    padding: 0.1rem 0.2rem;
  }

  #screen-room .player-seat__war-stash--empty {
    min-height: 30px;
  }

  #screen-room .player-seat__bank {
    gap: 0.25rem;
  }

  #screen-room .player-seat__name {
    font-size: clamp(0.58rem, 1.7vh, 0.7rem);
  }

  #screen-room .player-seat__count {
    font-size: clamp(0.54rem, 1.5vh, 0.64rem);
  }

  /* Stany końcowe tury (przegląd kart przed punktacją) — mniejsze pola i czcionki,
     by nie zachodziły na siebie ani nie wychodziły poza filc. */
  #screen-room .player-seat__zone-wrap:has(.player-seat__hand-review) {
    max-width: min(132px, 30vw);
  }

  #screen-room .player-seat__hand-review {
    width: min(128px, 30vw);
    min-height: clamp(46px, 12vh, 70px);
    padding: 0.25rem 0.3rem;
    gap: 0.18rem;
  }

  #screen-room .player-seat__hand-review--count-only {
    min-height: clamp(46px, 12vh, 72px);
    padding: 0.3rem 0.35rem;
  }

  #screen-room .hand-review__empty-center,
  #screen-room .hand-review__count-only {
    min-height: clamp(40px, 10vh, 64px);
  }

  #screen-room .hand-review__count-line {
    font-size: clamp(0.8rem, 3vh, 1.2rem);
  }

  #screen-room .hand-review__points-line {
    font-size: clamp(0.6rem, 1.9vh, 0.8rem);
  }

  #screen-room .hand-review__aces-row {
    gap: 0.2rem;
  }

  #screen-room .hand-review__grid {
    gap: 0.2rem;
  }

  #screen-room .hand-review__chip {
    padding: 0.12rem 0.28rem;
  }

  #screen-room .hand-review__chip-rank {
    font-size: 0.7rem;
  }

  #screen-room .hand-review__chip-suit {
    font-size: 0.64rem;
  }

  #screen-room .hand-review__aces {
    font-size: 0.6rem;
  }
}
