:root {
  --ink: #1e1833;
  --muted: #766f8f;
  --paper: #fffaf2;
  --panel: rgba(255, 255, 255, 0.84);
  --line: rgba(40, 31, 68, 0.14);
  --shadow: 0 24px 70px rgba(34, 25, 71, 0.18);
  --red: #ff4d68;
  --yellow: #ffd257;
  --green: #38d891;
  --blue: #55a7ff;
  --wild: #332846;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 12%, rgba(255, 210, 87, 0.42), transparent 28rem),
    radial-gradient(circle at 88% 18%, rgba(85, 167, 255, 0.36), transparent 26rem),
    linear-gradient(135deg, #fff7db 0%, #f7f2ff 48%, #eafdff 100%);
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 10px 24px rgba(30, 24, 51, 0.12);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 30px rgba(30, 24, 51, 0.16);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  transform: none;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 18px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  outline: none;
}

input:focus {
  border-color: rgba(85, 167, 255, 0.72);
  box-shadow: 0 0 0 4px rgba(85, 167, 255, 0.18);
}

.hidden {
  display: none !important;
}

.bubble-field {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.bubble-field span {
  position: absolute;
  display: block;
  width: 9rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.66);
  box-shadow: inset 0 0 34px rgba(255, 255, 255, 0.66), 0 24px 60px rgba(85, 167, 255, 0.12);
  animation: float 14s ease-in-out infinite;
}

.bubble-field span:nth-child(1) {
  left: 7%;
  top: 15%;
}

.bubble-field span:nth-child(2) {
  width: 6rem;
  left: 72%;
  top: 8%;
  animation-delay: -4s;
}

.bubble-field span:nth-child(3) {
  width: 12rem;
  left: 82%;
  top: 66%;
  animation-delay: -8s;
}

.bubble-field span:nth-child(4) {
  width: 5rem;
  left: 14%;
  top: 77%;
  animation-delay: -2s;
}

.bubble-field span:nth-child(5) {
  width: 7rem;
  left: 46%;
  top: 56%;
  animation-delay: -6s;
}

@keyframes float {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(0, -22px, 0) scale(1.04);
  }
}

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  padding: clamp(16px, 2vw, 26px);
}

.join-view {
  min-height: calc(100vh - 52px);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 24px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 18px;
  width: min(520px, 100%);
}

.logo-bubble {
  display: grid;
  place-items: center;
  width: 92px;
  aspect-ratio: 1;
  border-radius: 50%;
  color: #fff;
  font-size: 1.55rem;
  font-weight: 900;
  background:
    radial-gradient(circle at 32% 22%, rgba(255, 255, 255, 0.7), transparent 18%),
    conic-gradient(from 18deg, var(--red), var(--yellow), var(--green), var(--blue), var(--red));
  box-shadow: 0 24px 48px rgba(30, 24, 51, 0.2);
}

.brand-lockup h1 {
  margin: 0;
  font-size: clamp(3rem, 10vw, 5.8rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.brand-lockup p {
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.join-panel {
  width: min(520px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 32px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.join-panel label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.join-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary {
  color: #fff;
  background: linear-gradient(135deg, #ff4d68, #ff8a4b);
}

.game-view {
  min-height: calc(100vh - 52px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 16px;
}

.top-bar,
.hand-panel,
.players-panel,
.chat-panel,
.table-panel {
  border: 1px solid rgba(255, 255, 255, 0.7);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.top-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 28px;
}

.room-pill,
.turn-pill,
.status-dot {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  font-weight: 900;
}

.room-pill span {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
}

.turn-pill {
  justify-self: center;
  min-width: min(360px, 100%);
  color: #fff;
  background: #2f2947;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.top-actions button,
.table-actions button,
.chat-form button {
  padding: 0 16px;
  font-weight: 900;
}

.table-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(190px, 240px) minmax(0, 1fr) minmax(220px, 280px);
  gap: 16px;
}

.players-panel,
.chat-panel,
.table-panel,
.hand-panel {
  border-radius: 32px;
}

.players-panel,
.chat-panel {
  min-height: 0;
  padding: 16px;
}

.panel-title,
.eyebrow {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 950;
  text-transform: uppercase;
}

.players-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.player-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.64);
  border: 1px solid var(--line);
}

.player-row.is-turn {
  border-color: rgba(85, 167, 255, 0.68);
  box-shadow: 0 0 0 4px rgba(85, 167, 255, 0.14);
}

.player-avatar {
  display: grid;
  place-items: center;
  width: 38px;
  aspect-ratio: 1;
  border-radius: 50%;
  color: #fff;
  font-weight: 950;
  background: linear-gradient(135deg, var(--blue), var(--green));
}

.player-name {
  min-width: 0;
}

.player-name strong,
.player-name span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-name span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.card-count {
  min-width: 34px;
  min-height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  font-weight: 950;
}

.table-panel {
  min-width: 0;
  min-height: 420px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 14px;
  padding: clamp(14px, 2vw, 22px);
}

.table-center {
  position: relative;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 4vw, 54px);
  border-radius: 36px;
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.26)),
    linear-gradient(135deg, rgba(56, 216, 145, 0.24), rgba(85, 167, 255, 0.2));
  overflow: hidden;
}

.table-center::before,
.table-center::after {
  content: "";
  position: absolute;
  width: 220px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 28px solid rgba(255, 255, 255, 0.22);
}

.table-center::before {
  left: -70px;
  top: -70px;
}

.table-center::after {
  right: -80px;
  bottom: -80px;
}

.draw-stack,
.discard-slot {
  position: relative;
  z-index: 1;
}

.draw-stack {
  width: clamp(90px, 13vw, 126px);
  aspect-ratio: 0.68;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #fff;
  font-size: clamp(1.4rem, 4vw, 2.3rem);
  font-weight: 950;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.55), transparent 18%),
    conic-gradient(from 20deg, var(--red), var(--yellow), var(--green), var(--blue), var(--red));
  box-shadow: 0 24px 42px rgba(30, 24, 51, 0.22);
}

.draw-stack::before,
.draw-stack::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(-8px, 7px) rotate(-5deg);
}

.draw-stack::after {
  transform: translate(8px, -7px) rotate(5deg);
}

.discard-slot {
  min-width: clamp(90px, 13vw, 126px);
  min-height: calc(clamp(90px, 13vw, 126px) / 0.68);
  display: grid;
  place-items: center;
}

.color-orbit {
  position: absolute;
  z-index: 2;
  right: clamp(14px, 3vw, 34px);
  top: clamp(14px, 3vw, 34px);
  width: 28px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--wild);
  border: 4px solid rgba(255, 255, 255, 0.74);
  box-shadow: 0 10px 22px rgba(30, 24, 51, 0.16);
}

.move-line {
  min-height: 22px;
  color: var(--muted);
  font-weight: 850;
  text-align: center;
}

.table-actions {
  min-height: 48px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.hand-panel {
  min-height: 206px;
  padding: 14px;
}

.hand-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.hand-head strong {
  display: block;
  font-size: 1.1rem;
}

.status-dot {
  min-height: 36px;
  font-size: 0.82rem;
}

.hand {
  min-height: 148px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  overflow-x: auto;
  padding: 10px 6px 14px;
  scroll-snap-type: x proximity;
}

.card {
  flex: 0 0 clamp(74px, 10vw, 112px);
  aspect-ratio: 0.68;
  position: relative;
  display: grid;
  place-items: center;
  padding: 10px;
  border: 4px solid rgba(255, 255, 255, 0.86);
  border-radius: 18px;
  color: #fff;
  font-weight: 950;
  box-shadow: 0 18px 30px rgba(30, 24, 51, 0.18);
  scroll-snap-align: center;
  user-select: none;
}

.hand .card {
  cursor: pointer;
}

.hand .card.playable {
  transform: translateY(-8px);
  box-shadow: 0 24px 40px rgba(30, 24, 51, 0.22), 0 0 0 4px rgba(255, 255, 255, 0.78);
}

.hand .card:not(.playable) {
  filter: saturate(0.75);
  opacity: 0.82;
}

.card::before {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  transform: rotate(-18deg);
}

.card-label {
  position: relative;
  z-index: 1;
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: center;
  font-size: clamp(1rem, 3vw, 1.55rem);
  line-height: 1;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.card-corner {
  position: absolute;
  left: 8px;
  top: 7px;
  z-index: 1;
  font-size: 0.78rem;
}

.card.red,
.color-red {
  background: var(--red);
}

.card.yellow,
.color-yellow {
  background: var(--yellow);
  color: #3c2b11;
}

.card.green,
.color-green {
  background: var(--green);
}

.card.blue,
.color-blue {
  background: var(--blue);
}

.card.wild,
.color-wild {
  background:
    radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.35), transparent 18%),
    conic-gradient(from 18deg, var(--red), var(--yellow), var(--green), var(--blue), var(--red));
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.chat-log {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-line {
  padding: 9px 11px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid var(--line);
}

.chat-line strong {
  display: block;
  font-size: 0.78rem;
}

.chat-line span {
  display: block;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.chat-form input {
  min-height: 42px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 20;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 999px;
  color: #fff;
  background: #2f2947;
  box-shadow: var(--shadow);
  transform: translate(-50%, 140%);
  transition: transform 180ms ease;
  font-weight: 850;
}

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

.color-dialog {
  border: 0;
  border-radius: 30px;
  padding: 18px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.color-dialog::backdrop {
  background: rgba(30, 24, 51, 0.36);
}

.color-dialog h2 {
  margin: 0 0 14px;
}

.color-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(90px, 1fr));
  gap: 10px;
}

.color-choices button {
  min-height: 72px;
  color: #fff;
  font-weight: 950;
}

.color-choices button.color-yellow {
  color: #3c2b11;
}

@media (max-width: 980px) {
  .game-view {
    grid-template-rows: auto auto auto;
  }

  .top-bar,
  .table-layout {
    grid-template-columns: 1fr;
  }

  .turn-pill,
  .top-actions {
    justify-self: stretch;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .players-panel {
    order: 2;
  }

  .table-panel {
    min-height: 370px;
    order: 1;
  }

  .chat-panel {
    min-height: 240px;
    order: 3;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 10px;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .logo-bubble {
    width: 70px;
    font-size: 1.2rem;
  }

  .join-panel,
  .top-bar,
  .players-panel,
  .chat-panel,
  .table-panel,
  .hand-panel {
    border-radius: 24px;
  }

  .join-actions,
  .chat-form {
    grid-template-columns: 1fr;
  }

  .table-center {
    min-height: 250px;
    gap: 16px;
  }

  .hand {
    min-height: 132px;
  }

  .card {
    flex-basis: 72px;
  }
}
