:root {
  --bg: #17061a;
  --bg-2: #0f0410;
  --text: #f6f3eb;
  --muted: #d6cfbf;
  --panel: rgba(12, 4, 22, 0.78);
  --line: rgba(243, 229, 184, 0.25);
  --gold: #e3be63;
  --treasure: #f0cb6d;
  --trap: #d76a57;
  --blank: #53385e;
  --accent: #2a0d2f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Chakra Petch", sans-serif;
  color: var(--text);
  background-image: url("./images/background.png"),
    radial-gradient(circle at 85% 15%, rgba(250, 190, 94, 0.2), transparent 35%),
    radial-gradient(circle at 20% 80%, rgba(12, 4, 22, 0.25), transparent 35%),
    linear-gradient(140deg, var(--bg) 0%, var(--bg-2) 60%, #07120d 100%);
  background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
  background-position: center center, 85% 15%, 20% 80%, 0 0;
  background-size: cover, 35% 35%, 35% 35%, auto;
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  filter: blur(55px);
  opacity: 0.5;
  pointer-events: none;
}

.orb-1 {
  width: 280px;
  height: 280px;
  top: 2rem;
  left: -5rem;
  background: #f1c768;
  animation: driftA 12s ease-in-out infinite alternate;
}

.orb-2 {
  width: 320px;
  height: 320px;
  bottom: -7rem;
  right: -6rem;
  background: #2f1a33;
  animation: driftB 14s ease-in-out infinite alternate;
}

@keyframes driftA {
  from {
    transform: translate(0, 0) scale(1);
  }
  to {
    transform: translate(35px, 20px) scale(1.1);
  }
}

@keyframes driftB {
  from {
    transform: translate(0, 0) scale(1);
  }
  to {
    transform: translate(-25px, -30px) scale(1.08);
  }
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.2rem;
  display: grid;
  gap: 1rem;
}

/* Nowy wyśrodkowany, wolny nagłówek bez okienka backgroundu */
.app-header-centered {
  text-align: center;
  padding: 2rem 1rem 1rem 1rem;
  animation: fadeInUp 0.5s ease;
}

.app-header-centered h1 {
  margin: 0.3rem 0;
  font-family: "Bree Serif", serif;
  font-size: clamp(2rem, 6vw, 3.2rem);
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.eyebrow {
  margin: 0;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
}

h1,
h2,
h3 {
  font-family: "Bree Serif", serif;
}

h1 {
  margin: 0.3rem 0;
  font-size: clamp(1.5rem, 5vw, 2.4rem);
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(2px);
  border-radius: 16px;
  padding: 1rem;
  animation: fadeInUp 0.5s ease;
}

.panel.warning {
  border-color: rgba(224, 116, 89, 0.7);
}

.panel.info {
  border-color: rgba(123, 197, 157, 0.7);
}

.panel-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* Węższe, wyśrodkowane okienko menu głównego */
.join-panel-reimagined {
  max-width: 420px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.8rem;
  border-color: var(--line);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

/* Dopasowanie szerokości panelu lobby do szerokości menu głównego */
#lobbyPanel {
  max-width: 420px;
  margin: 0 auto;
  width: 100%;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

/* Segmenty ułożone jeden pod drugim */
.join-segment {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.join-segment label {
  font-weight: 600;
  color: var(--gold);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Układ input + przycisk akcji w jednej linii wewnątrz segmentu */
.input-with-action {
  display: flex;
  gap: 0.5rem;
}

.input-with-action input {
  flex: 1;
}

.full-width {
  width: 100%;
  justify-content: center;
  text-align: center;
}

.target-center {
  align-items: center;
  margin-top: 0.5rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.95rem;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid rgba(239, 227, 188, 0.35);
  background: rgba(12, 4, 22, 0.85);
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
}

.button-row {
  margin-top: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.btn {
  border: 1px solid rgba(223, 208, 165, 0.45);
  background: rgba(14, 3, 30, 0.95);
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background: linear-gradient(160deg, #d3a95f, #af7f35);
  border-color: rgba(255, 238, 170, 0.55);
  color: #201206;
  font-weight: 700;
}

.btn.ghost {
  background: rgba(10, 4, 20, 0.95);
}

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

.badge {
  border: 1px solid rgba(230, 214, 166, 0.45);
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  font-weight: 700;
  background: rgba(12, 4, 22, 0.95);
}

.muted {
  color: var(--muted);
}

.players-list {
  display: grid;
  gap: 0.55rem;
}

.player-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem;
  border: 1px solid rgba(231, 220, 186, 0.2);
  border-radius: 10px;
  background: rgba(12, 4, 22, 0.55);
}

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

.tag {
  font-size: 0.78rem;
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
  border: 1px solid rgba(228, 218, 185, 0.3);
}

.tag.raiders {
  color: #ffe3a3;
}

.tag.amazons {
  color: #ffbeaa;
}

.tag.pending {
  color: #d8d8d8;
}

.status-text {
  margin-bottom: 0.8rem;
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
  gap: 0.65rem;
}

.stat-card {
  border: 1px solid rgba(232, 220, 180, 0.25);
  border-radius: 12px;
  padding: 0.55rem 0.7rem;
  background: rgba(12, 4, 22, 0.52);
}

.stat-card h3 {
  margin: 0;
  font-size: 0.84rem;
  color: var(--muted);
}

.stat-card p {
  margin: 0.2rem 0 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.stat-card.treasure {
  border-color: rgba(240, 203, 109, 0.45);
}

.stat-card.trap {
  border-color: rgba(215, 106, 87, 0.45);
}

.winner-banner {
  margin-top: 0.9rem;
  border: 1px solid rgba(243, 229, 184, 0.55);
  border-radius: 12px;
  padding: 0.7rem;
  background: linear-gradient(130deg, rgba(215, 165, 83, 0.22), rgba(53, 18, 69, 0.15));
  font-size: 1.06rem;
  font-weight: 700;
}

.table-players {
  margin-top: 0.95rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.player-panel {
  border: 1px solid rgba(233, 223, 185, 0.25);
  border-radius: 12px;
  background: rgba(56, 31, 68, 0.342);
  padding: 0.7rem;
  width: 100%;
}

.player-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
}

.player-panel h3 {
  margin: 0;
  font-size: 1rem;
}

.player-name.raiders,
.tag.raiders {
  color: #f7c553;
}

.player-name.amazons,
.tag.amazons {
  color: #dd2828;
}

.player-name.pending,
.tag.pending {
  color: #f6f3eb;
}

.player-name {
  font-family: "Bree Serif", serif;
}

.player-report {
  margin-top: 0.45rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.player-report span {
  border: 1px solid rgba(243, 229, 184, 0.18);
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  background: rgba(12, 4, 22, 0.45);
}

.player-cards {
  margin-top: 0.6rem;
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 0.45rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding-top: 30px;
  padding-bottom: 0.35rem;
}

.card {
  height: 150px;
  width: fit-content;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 0;
  background: transparent;
  font-size: 0.86rem;
  font-weight: 600;
  overflow: visible;
  position: relative;
}

.card.back {
  background: transparent;
}

.player-key {
  width: 28px;
  height: 28px;
  vertical-align: middle;
  margin-left: 0.45rem;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

.key-fly {
  position: fixed;
  width: 48px;
  height: 48px;
  z-index: 9999;
  pointer-events: none;
  transition: transform 1500ms cubic-bezier(.2,.9,.2,1), opacity 1500ms ease;
  transform-origin: center;
  opacity: 0.0;
  will-change: transform, opacity;
}

.card.key-card {
  display: grid;
  place-items: center;
  background: transparent;
  margin-left: 2rem;
}

.card-key-img {
  width: auto;
  height: 150px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.22);
}

.card.treasure {
  border-color: rgba(240, 203, 109, 0.6);
  color: var(--treasure);
}

.card.trap {
  border-color: rgba(215, 106, 87, 0.6);
  color: #ffc1b4;
}

.card.empty {
  border-color: rgba(136, 165, 143, 0.6);
  color: #c8dfcf;
}

.card-image {
  width: auto;
  height: 150px;
  max-width: none;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  pointer-events: none;
  user-select: none;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.22);
}

.card-inner {
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 700ms cubic-bezier(.2,.9,.2,1);
  display: grid;
}

.card-face {
  grid-area: 1 / 1 / 2 / 2;
  backface-visibility: hidden;
  display: grid;
  place-items: center;
}

.card-face.back {
  transform: rotateY(180deg);
}

.card.is-revealed {
  z-index: 6;
}

.card.is-revealed .card-inner {
  transform: rotateY(180deg) translateY(-15px);
}

.card.is-revealed .card-image,
.card.is-revealed .card-face img {
  box-shadow: 0 12px 24px rgba(0,0,0,0.32);
}

.card-face img {
  width: auto;
  height: 150px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}

button.card {
  appearance: none;
  font: inherit;
  cursor: pointer;
  border: 0;
  padding: 0;
}

.card-button:hover {
  transform: translateY(-2px);
}

.card.revealed-lifted {
  z-index: 2;
}

.card.revealed-animate {
  animation: cardSlideUp 0.35s ease-out;
}

@keyframes cardSlideUp {
  0% { transform: translateY(0); }
  70% { transform: translateY(-10px); }
  100% { transform: translateY(-8px); }
}

.player-actions {
  margin-top: 0.6rem;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: 360px;
  background: rgba(12, 4, 22, 0.95);
  border: 1px solid rgba(234, 222, 185, 0.45);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  z-index: 20;
}

.round-modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 4, 22, 0.72);
  display: grid;
  place-items: center;
  z-index: 35;
  padding: 1rem;
}

.round-modal-card {
  width: fit-content;
  max-width: calc(100% - 2rem);
  border: 1px solid rgba(243, 229, 184, 0.35);
  background: linear-gradient(160deg, rgba(12, 4, 22, 0.98), rgba(8, 3, 16, 0.98));
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.4);
}

.round-modal-card h2 {
  margin: 0 0 0.5rem;
}

.round-modal-card p {
  margin: 0;
  color: var(--muted);
}

.round-modal-visual {
  margin-top: 1rem;
  display: grid;
  gap: 0.6rem;
  overflow: auto;
}

.role-modal-visual {
  margin-top: 1rem;
}

.round-summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.round-summary-strip-inline {
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.3rem;
}

.round-summary-card {
  width: auto;
  height: 150px;
  border-radius: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.round-summary-thumb {
  height: 150px !important;
  border-radius: 10px;
}

.round-summary-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.round-summary-empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.2rem 0;
}

.round-summary-line {
  color: var(--muted);
}

.role-modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 4, 22, 0.72);
  display: grid;
  place-items: center;
  z-index: 30;
  padding: 1rem;
}

.role-modal-card {
  width: fit-content;
  max-width: calc(100% - 2rem);
  border: 1px solid rgba(243, 229, 184, 0.35);
  background: linear-gradient(160deg, rgba(12, 4, 22, 0.98), rgba(8, 3, 16, 0.98));
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.4);
}

.role-modal-card h2 {
  margin: 0 0 0.5rem;
}

.role-modal-card p {
  margin: 0;
  color: var(--muted);
}

body.game-mode .app-shell {
  max-width: none;
  width: 100%;
  padding: 0;
  gap: 0;
}

body.game-mode .app-header-centered,
body.game-mode #joinPanel,
body.game-mode #lobbyPanel,
body.game-mode #configWarning,
body.game-mode #connectionInfo {
  display: none !important;
}

body.game-mode #gamePanel {
  width: 100%;
  min-height: 100vh;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  padding: 1rem;
}

body.game-mode .table-players {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 0.7rem;
  }

  .panel {
    padding: 0.75rem;
  }

  .card {
    min-height: 72px;
  }

  .player-panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .table-players {
    grid-template-columns: 1fr;
  }

  body.game-mode #gamePanel {
    padding: 0.75rem;
  }
}

.instruction-btn {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 99998;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(243, 229, 184, 0.45);
  background: rgba(12, 4, 22, 0.9);
  color: var(--gold);
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
}

.instruction-modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(12, 4, 22, 0.82);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.instruction-card {
  max-width: 680px;
  width: 100%;
  border: 1px solid rgba(243, 229, 184, 0.35);
  background: linear-gradient(160deg, rgba(12, 4, 22, 0.98), rgba(8, 3, 16, 0.98));
  border-radius: 16px;
  padding: 1.2rem;
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.4);
}

.instr-img-row {
  display: flex;
  gap: 1rem;
  margin: 1rem 0;
}

.instr-img-row img {
  width: 80px;
  height: 120px;
  object-fit: cover;
  border-radius: 10px;
  box-shadow: 0 6px 12px rgba(0,0,0,0.25);
}

.instr-img-row div {
  text-align: center;
  font-size: 0.9rem;
}