:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #151617;
  color: #f4f0e8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  background:
    linear-gradient(115deg, rgba(120, 28, 38, 0.32), transparent 36%),
    linear-gradient(250deg, rgba(221, 170, 76, 0.16), transparent 34%),
    radial-gradient(circle at 50% 15%, rgba(42, 124, 78, 0.45), transparent 28rem),
    linear-gradient(135deg, #151617 0%, #24201b 46%, #101816 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.13;
  background:
    linear-gradient(60deg, transparent 0 44%, rgba(255, 255, 255, 0.5) 44% 45%, transparent 45% 100%),
    linear-gradient(120deg, transparent 0 47%, rgba(255, 255, 255, 0.38) 47% 48%, transparent 48% 100%);
  background-size: 8rem 11rem;
}

button,
input {
  font: inherit;
}

button {
  min-height: 3rem;
  border: 0;
  border-radius: 8px;
  padding: 0 1rem;
  background: #e6bd58;
  color: #1e1b16;
  font-weight: 800;
  cursor: pointer;
}

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

input {
  width: 100%;
  min-height: 3rem;
  border: 1px solid rgba(244, 240, 232, 0.22);
  border-radius: 8px;
  padding: 0 0.9rem;
  background: rgba(255, 255, 255, 0.08);
  color: #f4f0e8;
}

label {
  display: grid;
  gap: 0.45rem;
  color: #c9c2b4;
  font-size: 0.92rem;
}

.app {
  position: relative;
  z-index: 1;
  width: min(100%, 920px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  align-items: center;
}

.panel,
.game {
  border: 1px solid rgba(244, 240, 232, 0.14);
  border-radius: 8px;
  background: rgba(20, 22, 21, 0.72);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

.join-panel {
  display: grid;
  gap: 1.2rem;
  padding: clamp(1rem, 4vw, 2rem);
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: #79c69c;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.5rem, 11vw, 5.5rem);
  line-height: 0.92;
}

h2 {
  margin-bottom: 0;
  font-size: 2rem;
}

h3 {
  margin-bottom: 0.35rem;
  font-size: clamp(1.4rem, 5vw, 2.4rem);
  line-height: 1.05;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
}

.status {
  min-height: 1.4rem;
  margin-bottom: 0;
  color: #c9c2b4;
}

.hidden {
  display: none !important;
}

[hidden] {
  display: none !important;
}

.game {
  align-self: stretch;
  display: grid;
  grid-template-rows: auto auto auto minmax(17rem, 1fr) auto auto;
  gap: 1rem;
  padding: 1rem;
}

.game:not([data-phase="lobby"]) .topbar {
  display: none;
}

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

.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #f4f0e8;
}

.room-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(8rem, 1fr)) minmax(0, 1.2fr);
  align-items: end;
  gap: 0.75rem;
  border: 1px solid rgba(244, 240, 232, 0.14);
  border-radius: 8px;
  padding: 0.85rem;
  background: rgba(255, 255, 255, 0.06);
}

.option-summary {
  margin-bottom: 0;
  color: #d6d0c6;
  font-size: 0.9rem;
}

.table {
  min-height: 17rem;
  border-radius: 8px;
  display: grid;
  grid-template-areas:
    "deck reveal message"
    "hand hand hand";
  grid-template-columns: minmax(5.5rem, 8rem) minmax(7rem, 10rem) minmax(0, 1fr);
  align-items: center;
  gap: clamp(0.7rem, 3vw, 1.5rem);
  padding: clamp(0.8rem, 3vw, 1.5rem);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(#1d6844, #155235);
  background-size: 26px 26px, auto;
}

.deck {
  grid-area: deck;
  display: grid;
  gap: 0.55rem;
  justify-items: center;
}

.card {
  aspect-ratio: 2.5 / 3.5;
  width: 100%;
  max-width: 10rem;
  border-radius: 8px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(0, 0, 0, 0.24);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.22);
  user-select: none;
}

.card-back {
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.14) 25%, transparent 25% 50%, rgba(255, 255, 255, 0.14) 50% 75%, transparent 75%),
    #bf3f39;
  background-size: 1rem 1rem;
  color: #fff7ed;
  font-size: 1.4rem;
  font-weight: 900;
}

.deck-status {
  min-height: 1.4rem;
  margin: 0;
  border-radius: 999px;
  padding: 0.32rem 0.65rem;
  background: rgba(14, 20, 17, 0.52);
  color: #fff2c4;
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.reveal-card {
  grid-area: reveal;
  background: #fff9ed;
  color: #171818;
  grid-template-rows: 1fr 1fr;
  transform-style: preserve-3d;
}

.reveal-card.red-card {
  color: #b82d33;
}

.rank {
  align-self: end;
  font-size: clamp(2rem, 9vw, 4rem);
  font-weight: 900;
}

.suit {
  align-self: start;
  font-size: clamp(2rem, 9vw, 4rem);
  line-height: 0.9;
}

.message {
  grid-area: message;
  min-width: 0;
}

.message p {
  color: #d6d0c6;
}

#lastResult {
  min-height: 1.5rem;
  margin-bottom: 0;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
}

#lastResult:empty {
  padding: 0;
}

.result-correct {
  background: rgba(55, 166, 98, 0.22);
  color: #baf3cd !important;
}

.result-wrong {
  background: rgba(200, 72, 79, 0.23);
  color: #ffd1d5 !important;
}

.result-neutral {
  background: rgba(230, 189, 88, 0.16);
  color: #ffe4a3 !important;
}

.own-hand {
  grid-area: hand;
  width: 100%;
  min-width: 0;
  border-top: 1px solid rgba(244, 240, 232, 0.16);
  padding-top: 0.8rem;
}

.own-cards {
  display: flex;
  gap: 0.5rem;
  min-height: 4.25rem;
  overflow-x: auto;
  padding-bottom: 0.1rem;
}

.mini-card {
  width: 3.1rem;
  min-width: 3.1rem;
  aspect-ratio: 2.5 / 3.5;
  border-radius: 6px;
  display: grid;
  grid-template-rows: 1fr 1fr;
  place-items: center;
  background: #fff9ed;
  color: #171818;
  border: 1px solid rgba(0, 0, 0, 0.22);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
  font-weight: 900;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.mini-card.red-card {
  color: #b82d33;
}

.mini-card.affected-card {
  border-color: #e6bd58;
  box-shadow:
    0 0 0 2px rgba(230, 189, 88, 0.32),
    0 12px 24px rgba(0, 0, 0, 0.26);
  transform: translateY(-0.12rem);
}

.mini-card.card-jump {
  animation: card-jump 520ms ease-out;
}

.mini-rank {
  align-self: end;
  font-size: 1.25rem;
}

.mini-suit {
  align-self: start;
  font-size: 1.35rem;
  line-height: 0.9;
}

.empty-hand {
  align-self: center;
  margin: 0;
  color: #d6d0c6;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(3, minmax(8rem, auto));
  gap: 0.75rem;
}

.answer-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.75rem;
}

.give-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.75rem;
}

.busdriver-ride-controls {
  margin-top: 0.85rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(2, minmax(7rem, auto));
  align-items: center;
  gap: 0.75rem;
}

.busdriver-status {
  margin: 0;
  color: #f4f0e8;
  font-weight: 800;
}

.give-label {
  align-self: center;
  margin: 0;
  color: #f4f0e8;
  font-weight: 800;
}

.red {
  background: #c8484f;
  color: #fff9ed;
}

.black {
  background: #171818;
  color: #fff9ed;
  border: 1px solid rgba(244, 240, 232, 0.18);
}

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

.player {
  border: 1px solid rgba(244, 240, 232, 0.12);
  border-radius: 8px;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.07);
}

.player.active {
  border-color: #e6bd58;
  background: rgba(230, 189, 88, 0.14);
}

.player-name {
  overflow-wrap: anywhere;
  font-weight: 800;
}

.player-meta {
  margin: 0.15rem 0 0;
  color: #c9c2b4;
  font-size: 0.9rem;
}

.finish-panel {
  display: grid;
  gap: 0.85rem;
  border: 1px solid rgba(230, 189, 88, 0.28);
  border-radius: 8px;
  padding: 1rem;
  background: rgba(18, 20, 19, 0.72);
}

.leaderboard {
  display: grid;
  gap: 0.5rem;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.75rem;
  border: 1px solid rgba(244, 240, 232, 0.12);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  background: rgba(255, 255, 255, 0.06);
}

.leaderboard-place {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e6bd58;
  color: #1e1b16;
  font-weight: 900;
}

.leaderboard-row span:not(.leaderboard-place) {
  color: #d6d0c6;
  font-size: 0.9rem;
}

.flip-in {
  animation: flip-card 360ms ease-out;
}

.draw-pulse {
  animation: draw-card 320ms ease-out;
}

@keyframes flip-card {
  0% {
    opacity: 0.2;
    transform: translateY(-0.8rem) rotateY(88deg) scale(0.94);
  }

  100% {
    opacity: 1;
    transform: translateY(0) rotateY(0) scale(1);
  }
}

@keyframes draw-card {
  0% {
    transform: translateY(0) rotate(0);
  }

  45% {
    transform: translateY(-0.35rem) rotate(-2deg);
  }

  100% {
    transform: translateY(0) rotate(0);
  }
}

@keyframes card-jump {
  0% {
    transform: translateY(0) scale(1);
  }

  34% {
    transform: translateY(-0.55rem) scale(1.05);
  }

  64% {
    transform: translateY(0.08rem) scale(0.99);
  }

  100% {
    transform: translateY(-0.12rem) scale(1);
  }
}

.sip-popup {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 10;
  width: min(calc(100% - 2rem), 24rem);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  border: 1px solid rgba(230, 189, 88, 0.5);
  border-radius: 8px;
  padding: 1rem;
  background: rgba(25, 25, 24, 0.96);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.45);
}

.sip-popup h3 {
  margin-bottom: 0.25rem;
  font-size: 1.35rem;
}

.sip-popup p:last-child {
  margin-bottom: 0;
}

@media (max-width: 700px) {
  .app {
    align-items: stretch;
  }

  .split,
  .room-options,
  .controls,
  .answer-controls,
  .give-controls,
  .busdriver-ride-controls {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .table {
    grid-template-areas:
      "reveal deck"
      "message message"
      "hand hand";
    grid-template-columns: minmax(7rem, 1fr) minmax(5.75rem, 0.82fr);
    align-items: start;
    justify-items: center;
    text-align: center;
  }

  .card {
    max-width: 9.25rem;
  }

  .deck .card {
    max-width: 7.5rem;
  }

  .message {
    width: 100%;
  }

  .sip-popup {
    left: 1rem;
    right: 1rem;
    grid-template-columns: 1fr;
  }

  .leaderboard-row {
    grid-template-columns: 2rem minmax(0, 1fr);
  }
}
