:root {
  color-scheme: dark;
  --bg: #111318;
  --surface: #1a1d24;
  --surface-2: #252934;
  --ink: #f7f2e8;
  --muted: #aeb4c1;
  --line: rgba(255, 255, 255, 0.12);
  --red: #e53935;
  --yellow: #f5c84b;
  --green: #2abf72;
  --blue: #2877e4;
  --wild: #20242c;
  --accent: #ffb000;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at top left, rgba(42, 191, 114, 0.16), transparent 28rem),
    linear-gradient(135deg, #111318 0%, #16191f 48%, #231519 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, opacity 160ms ease;
}

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

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

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #0d0f13;
  color: var(--ink);
  outline: none;
  text-transform: none;
}

input:focus {
  border-color: var(--accent);
}

.hidden {
  display: none !important;
}

.shell {
  min-height: 100dvh;
}

.entry-view {
  min-height: 100dvh;
  display: grid;
  align-content: center;
  gap: 28px;
  padding: max(22px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.brand-block h1 {
  max-width: 780px;
  margin: 0;
  font-size: clamp(2.4rem, 9vw, 6.2rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

.subcopy {
  max-width: 560px;
  margin: 18px 0 0;
  font-size: 1.05rem;
  line-height: 1.5;
}

.join-panel {
  width: min(100%, 520px);
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(26, 29, 36, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

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

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.primary {
  border-color: rgba(255, 176, 0, 0.55);
  background: linear-gradient(180deg, #ffc043 0%, #eb8f21 100%);
  color: #17120a;
  font-weight: 900;
}

.ghost {
  background: rgba(255, 255, 255, 0.06);
}

.compact {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.86rem;
  font-weight: 800;
}

.wide {
  width: 100%;
}

.topbar,
.game-top {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
}

.room-code {
  min-height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 2rem;
  font-weight: 950;
  letter-spacing: 0.16em;
}

.lobby-view {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.lobby-main {
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 14px;
}

.lobby-main h2 {
  margin: 0;
  font-size: 2rem;
}

.lobby-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 10px;
}

.invite-box,
.settings-box {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.invite-box p,
.settings-box p {
  margin: 0;
  font-size: 0.86rem;
}

.invite-box input {
  color: var(--muted);
  text-transform: none;
}

.settings-box {
  grid-template-columns: minmax(0, 1.1fr) minmax(130px, 0.55fr);
  align-items: end;
}

.settings-box h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.settings-box input:disabled {
  opacity: 0.7;
}

.rule-badges {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rule-badges span {
  padding: 5px 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
}

.invite-actions {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: 8px;
}

.player-tile {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.player-tile > div,
.seat > div {
  min-width: 0;
  overflow: hidden;
}

.avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: hsl(var(--avatar-hue) 82% 47%);
  color: #fff;
  font-weight: 950;
  box-shadow: inset 0 -8px 16px rgba(0, 0, 0, 0.24);
}

.player-name {
  max-width: 100%;
  overflow: hidden;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.kick-button {
  min-height: 30px;
  margin-top: 6px;
  padding: 0 9px;
  border-color: rgba(229, 57, 53, 0.45);
  background: rgba(229, 57, 53, 0.14);
  color: #ffd7d7;
  font-size: 0.75rem;
  font-weight: 900;
}

.lobby-footer {
  padding: 12px max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.game-view {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(180px, 1fr) auto auto auto;
  background:
    linear-gradient(90deg, rgba(229, 57, 53, 0.09), transparent 30%, rgba(40, 119, 228, 0.11)),
    #111318;
}

.room-chip,
.turn-chip {
  max-width: 100%;
  min-width: 0;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.turn-chip {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-chip strong,
.turn-chip strong {
  color: var(--ink);
}

.table {
  position: relative;
  min-height: 236px;
  margin: 0 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(42, 191, 114, 0.22), rgba(40, 119, 228, 0.18)),
    #16221f;
}

.players-ring {
  position: absolute;
  inset: 8px;
  pointer-events: none;
}

.seat {
  position: absolute;
  width: 154px;
  min-height: 54px;
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 8px;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 8px;
  background: rgba(8, 10, 13, 0.58);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.seat.turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 176, 0, 0.16);
}

.seat .avatar {
  width: 36px;
  height: 36px;
  font-size: 0.83rem;
}

.seat .cards-left {
  color: var(--muted);
  font-size: 0.75rem;
}

.seat .kick-button {
  position: absolute;
  top: 4px;
  right: 4px;
  min-height: 22px;
  margin-top: 0;
  padding: 0 6px;
  font-size: 0.66rem;
}

.seat.disconnected {
  opacity: 0.55;
}

.center-stack {
  position: absolute;
  inset: 50%;
  width: min(58vw, 320px);
  height: 164px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: center;
  gap: 10px;
  transform: translate(-50%, -50%);
}

.draw-pile,
.uno-card {
  width: 86px;
  height: 126px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.26);
}

.draw-pile {
  background: linear-gradient(135deg, #1d2028, #e53935 48%, #f5c84b 49%, #2877e4 76%, #2abf72);
  color: #fff;
  font-weight: 950;
}

.draw-pile.draw-needed {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 176, 0, 0.22), 0 16px 34px rgba(0, 0, 0, 0.38);
  animation: drawPulse 1100ms ease-in-out infinite;
}

.draw-pile small {
  align-self: end;
  margin-bottom: 8px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
}

.discard-slot {
  min-width: 86px;
  min-height: 126px;
}

.color-status {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 850;
}

.color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid rgba(255, 255, 255, 0.72);
}

.action-row {
  display: grid;
  grid-template-columns: 0.9fr 1.15fr 1fr 1fr;
  gap: 8px;
  padding: 10px;
}

.action-row.finished {
  grid-template-columns: 1fr 1fr;
}

.action-row.draw-needed #drawBtn {
  border-color: var(--accent);
  background: linear-gradient(180deg, #ffd064 0%, #ee9d28 100%);
  color: #1a1204;
  font-weight: 950;
  box-shadow: 0 0 0 4px rgba(255, 176, 0, 0.18);
  animation: drawPulse 1100ms ease-in-out infinite;
}

.uno-button {
  border-color: rgba(245, 200, 75, 0.6);
  color: var(--yellow);
  font-weight: 950;
}

.uno-button.armed {
  background: var(--yellow);
  color: #1b1300;
}

.hand-zone {
  min-height: 154px;
  overflow: hidden;
}

.hand {
  display: flex;
  gap: 8px;
  min-height: 154px;
  padding: 2px 12px 14px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
}

.hand .uno-card {
  flex: 0 0 86px;
  scroll-snap-align: center;
  transform-origin: bottom center;
}

.hand.compact {
  gap: 0;
  padding-left: 34px;
  padding-right: 18px;
}

.hand.compact .uno-card {
  margin-left: -32px;
}

.hand.compact .uno-card:first-child {
  margin-left: 0;
}

.hand .uno-card.playable {
  border-color: #fff;
  transform: translateY(-8px);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.13), 0 16px 26px rgba(0, 0, 0, 0.34);
}

.hand .uno-card.selected {
  border-color: var(--accent);
  transform: translateY(-18px) rotate(-1deg);
  box-shadow: 0 0 0 4px rgba(255, 176, 0, 0.24), 0 20px 32px rgba(0, 0, 0, 0.42);
}

.hand .uno-card.locked {
  filter: grayscale(0.45) brightness(0.74);
}

.hand .uno-card.blocked {
  opacity: 0.52;
}

.uno-card {
  position: relative;
  overflow: hidden;
  padding: 7px;
  color: #fff;
  font-weight: 950;
  text-transform: uppercase;
}

.uno-card::before {
  content: "";
  position: absolute;
  inset: 10px 7px;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 50%;
  transform: rotate(-24deg);
}

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

.uno-card .value {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 2.18rem;
  text-align: center;
  line-height: 0.9;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.discard-slot .uno-card {
  animation: discardPop 280ms ease-out;
}

.card-flight {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  animation: cardFly 560ms cubic-bezier(0.22, 0.9, 0.25, 1) forwards;
}

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

.uno-card.yellow {
  background: var(--yellow);
  color: #211600;
}

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

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

.uno-card.wild {
  background:
    linear-gradient(135deg, var(--red) 0 25%, var(--yellow) 25% 50%, var(--green) 50% 75%, var(--blue) 75%),
    var(--wild);
}

.action-feed {
  min-height: 44px;
  margin: 0 10px max(8px, env(safe-area-inset-bottom));
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.action-feed[class*="event-"] {
  display: grid;
  gap: 3px;
  color: var(--ink);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
}

.feed-label {
  font-size: 0.72rem;
  font-weight: 950;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.feed-message {
  font-size: 0.98rem;
  font-weight: 900;
  line-height: 1.25;
}

.action-feed.event-penalty {
  border-color: rgba(229, 57, 53, 0.68);
  background: linear-gradient(180deg, rgba(229, 57, 53, 0.28), rgba(229, 57, 53, 0.12));
}

.action-feed.event-penalty .feed-label {
  color: #ffb4b4;
}

.action-feed.event-draw {
  border-color: rgba(255, 176, 0, 0.7);
  background: linear-gradient(180deg, rgba(255, 176, 0, 0.25), rgba(255, 176, 0, 0.1));
}

.action-feed.event-draw .feed-label {
  color: var(--accent);
}

.action-feed.event-action {
  border-color: rgba(40, 119, 228, 0.65);
  background: linear-gradient(180deg, rgba(40, 119, 228, 0.24), rgba(40, 119, 228, 0.1));
}

.action-feed.event-action .feed-label {
  color: #9dc4ff;
}

.action-feed.event-win {
  border-color: rgba(42, 191, 114, 0.68);
  background: linear-gradient(180deg, rgba(42, 191, 114, 0.24), rgba(42, 191, 114, 0.1));
}

.action-feed.event-win .feed-label {
  color: #97f0bf;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.58);
}

.modal-panel {
  width: min(100%, 360px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-panel h2 {
  margin: 0 0 14px;
}

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

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

.modal-head h2 {
  margin: 0;
}

.help-panel {
  width: min(100%, 560px);
}

.help-list {
  margin: 16px 0 0;
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.55;
}

.help-list li + li {
  margin-top: 8px;
}

.result-panel {
  display: grid;
  gap: 12px;
  text-align: center;
}

.result-panel h2 {
  margin: 0;
  font-size: 1.9rem;
  line-height: 1.05;
}

.result-message {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.result-panel.winner {
  border-color: rgba(42, 191, 114, 0.65);
  background:
    linear-gradient(180deg, rgba(42, 191, 114, 0.16), rgba(26, 29, 36, 0.96)),
    var(--surface);
}

.result-panel.loser {
  border-color: rgba(255, 176, 0, 0.55);
  background:
    linear-gradient(180deg, rgba(255, 176, 0, 0.13), rgba(26, 29, 36, 0.96)),
    var(--surface);
}

.color-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.color-choice {
  min-height: 72px;
  border-color: rgba(255, 255, 255, 0.38);
  color: #fff;
  font-weight: 950;
}

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

.color-choice.yellow {
  background: var(--yellow);
  color: #211600;
}

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

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

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 30;
  width: min(92vw, 460px);
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #f7f2e8;
  color: #15171d;
  font-weight: 800;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

@keyframes drawPulse {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  50% {
    transform: translateY(-2px) scale(1.03);
  }
}

@keyframes discardPop {
  0% {
    opacity: 0.35;
    transform: translateY(-10px) scale(0.92) rotate(-4deg);
  }

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

@keyframes cardFly {
  0% {
    opacity: 0.96;
    transform: translate(0, 0) scale(1) rotate(0deg);
  }

  70% {
    opacity: 0.96;
  }

  100% {
    opacity: 0;
    transform: translate(var(--fly-x), var(--fly-y)) scale(0.72) rotate(10deg);
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .game-view {
    grid-template-rows: 52px minmax(172px, 1fr) 52px 138px auto;
  }

  .game-top {
    min-height: 52px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .table {
    min-height: 164px;
  }

  .center-stack {
    height: 132px;
  }

  .draw-pile,
  .uno-card {
    width: 76px;
    height: 112px;
  }

  .hand .uno-card {
    flex-basis: 76px;
  }

  .hand-zone,
  .hand {
    min-height: 132px;
  }

  .seat {
    width: 132px;
    min-height: 42px;
    grid-template-columns: 28px 1fr;
    gap: 6px;
    padding: 5px;
  }

  .seat .avatar {
    width: 28px;
    height: 28px;
    font-size: 0.72rem;
  }

  .seat .cards-left {
    font-size: 0.7rem;
  }

  .seat .player-name {
    font-size: 0.8rem;
  }

  .seat .kick-button {
    min-height: 18px;
    padding: 0 5px;
    font-size: 0.6rem;
  }
}

@media (max-width: 520px) {
  .game-top {
    gap: 8px;
  }

  .room-chip,
  .turn-chip,
  .compact {
    min-height: 36px;
    padding-inline: 9px;
    font-size: 0.76rem;
  }

  .action-row {
    grid-template-columns: 0.82fr 1.18fr 0.9fr 0.9fr;
    gap: 6px;
    padding: 8px 10px;
  }

  .action-row button {
    min-height: 42px;
    padding-inline: 6px;
    font-size: 0.84rem;
  }

  .table {
    min-height: 220px;
  }
}

@media (max-width: 380px) {
  .topbar,
  .game-top {
    justify-content: center;
  }

  .topbar > *,
  .game-top > * {
    flex: 1 1 auto;
  }

  .room-code {
    font-size: 1.55rem;
  }

  .room-chip,
  .turn-chip,
  .compact,
  .ghost {
    font-size: 0.72rem;
  }

  .invite-actions,
  .settings-box,
  .entry-actions,
  .action-row,
  .action-row.finished {
    grid-template-columns: 1fr;
  }

  .rule-badges {
    gap: 6px;
  }

  .seat {
    width: 118px;
  }

  .seat .player-name {
    font-size: 0.74rem;
  }

  .modal {
    padding: 10px;
  }
}

@media (min-width: 760px) {
  .entry-view {
    grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
    align-items: center;
    padding: 40px;
  }

  .join-panel {
    justify-self: end;
  }

  .lobby-main {
    max-width: 1040px;
    width: 100%;
    justify-self: center;
    padding: 34px;
  }

  .lobby-footer {
    max-width: 1040px;
    width: 100%;
    justify-self: center;
  }

  .table {
    margin: 0 22px;
  }

  .action-row {
    max-width: 640px;
    width: 100%;
    justify-self: center;
  }

  .hand {
    justify-content: center;
  }
}
