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

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
}

body.is-dragging-tile {
  cursor: grabbing;
  user-select: none;
}

button {
  font: inherit;
}

.room {
  min-height: 100vh;
  display: grid;
  grid-template-rows: minmax(520px, 1fr) auto auto;
  gap: 8px;
  padding: 10px;
  background:
    radial-gradient(circle at 50% 42%, rgba(42, 126, 94, 0.35), transparent 55%),
    linear-gradient(135deg, rgba(32, 92, 72, 0.34), transparent 42%),
    #120e0b;
}

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

h1,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.35rem, 2.4vw, 2rem);
  letter-spacing: 0;
}

p,
.status,
.seat span {
  color: #d8cab6;
  font-size: 0.9rem;
}

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

.icon-button,
.text-button {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #f6efe2;
  border-radius: 8px;
  padding: 0 12px;
  cursor: pointer;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-weight: 800;
}

.text-button:disabled,
.pile:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.finish {
  border-color: rgba(220, 171, 71, 0.55);
  background: rgba(115, 78, 28, 0.48);
}

.table-wrap {
  position: relative;
  min-height: 520px;
  display: grid;
  place-items: center;
  overflow: visible;
}

.table {
  position: relative;
  width: min(100%, 1280px);
  height: 100%;
  min-height: 520px;
  border-radius: 22px;
  border: 12px solid #65422f;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.05), transparent),
    #206250;
  box-shadow:
    0 30px 75px rgba(0, 0, 0, 0.48),
    inset 0 0 48px rgba(0, 0, 0, 0.35);
  overflow: visible;
}

.felt-grain {
  position: absolute;
  inset: 0;
  opacity: 0.18;
  background-image:
    repeating-linear-gradient(45deg, transparent 0 12px, rgba(255, 255, 255, 0.08) 12px 13px),
    repeating-linear-gradient(-45deg, transparent 0 10px, rgba(0, 0, 0, 0.1) 10px 11px);
}

.messy-tiles {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 10px;
}

.messy-tiles i {
  position: absolute;
  left: calc(10% + (var(--i) * 7%) % 80%);
  top: calc(10% + (var(--i) * 13%) % 70%);
  width: 30px;
  height: 44px;
  border-radius: 5px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.55), transparent 22%),
    #eadfc8;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.24);
  rotate: calc((var(--i) - 19) * 9deg);
  transition: transform 700ms ease, opacity 500ms ease;
}

.dealt .messy-tiles i {
  transform: translate(calc((var(--i) - 20) * 8px), 135px) rotate(90deg);
  opacity: 0;
}

.deal-animation {
  position: absolute;
  inset: 0;
  z-index: 7;
  overflow: hidden;
  border-radius: 10px;
  pointer-events: none;
}

.deal-tile {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 46px;
  border-radius: 5px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.52), transparent 28%),
    repeating-linear-gradient(45deg, #eadfc8 0 7px, #d3c3a8 7px 10px);
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.28);
  opacity: 0;
  animation: deal-tile 1300ms cubic-bezier(0.2, 0.72, 0.18, 1) forwards;
  animation-delay: calc(var(--i) * 34ms);
}

@keyframes deal-tile {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.55) rotate(0deg);
  }

  15% {
    opacity: 0.95;
  }

  72% {
    opacity: 0.95;
  }

  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.9) rotate(var(--rot));
  }
}

.seat {
  position: absolute;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 136px;
  max-width: 168px;
  padding: 7px 9px;
  border-radius: 8px;
  background: rgba(19, 14, 11, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.13);
}

.seat > div:last-child {
  min-width: 0;
}

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

.seat.active {
  border-color: rgba(230, 188, 94, 0.85);
  box-shadow: 0 0 0 2px rgba(230, 188, 94, 0.15);
}

.seat-0 {
  bottom: 16px;
  left: 50%;
  translate: -50% 0;
}

.seat-1 {
  left: 16px;
  top: 46%;
  translate: 0 -50%;
}

.seat-2 {
  top: 14px;
  left: 50%;
  translate: -50% 0;
}

.seat-3 {
  right: 16px;
  top: 46%;
  translate: 0 -50%;
}

.avatar {
  width: 34px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #d5a447;
  color: #201711;
  font-weight: 900;
}

.pile,
.draw-cluster,
.table-open-area,
.player-discard {
  position: absolute;
  z-index: 2;
}

.pile {
  border: 0;
  background: transparent;
  color: inherit;
}

.draw-cluster {
  left: 50%;
  top: 38%;
  translate: -50% -50%;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 3;
}

.stock {
  position: static;
  width: 52px;
  height: 70px;
  border-radius: 7px;
  background:
    repeating-linear-gradient(180deg, #eadfc8 0 8px, #d3c3a8 8px 10px);
  box-shadow: 0 9px 16px rgba(0, 0, 0, 0.32);
}

.pile-count {
  display: grid;
  place-items: center;
  width: 34px;
  aspect-ratio: 1;
  margin: 18px auto 0;
  border-radius: 50%;
  background: rgba(36, 26, 18, 0.86);
  color: #f4dfb3;
  font-weight: 900;
}

.player-discard {
  width: 76px;
  min-height: 96px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  place-items: center;
  gap: 3px;
  border-radius: 8px;
  background: rgba(17, 42, 36, 0.45);
  border: 1px dashed rgba(255, 255, 255, 0.24);
  color: #ead6b9;
  font-weight: 800;
  padding: 5px;
}

.discard-0 {
  right: 18px;
  bottom: 18px;
  background: rgba(53, 24, 18, 0.52);
  border-color: rgba(255, 220, 172, 0.34);
  z-index: 6;
}

.discard-1 {
  left: 18px;
  bottom: 18px;
  translate: 0 0;
}

.discard-2 {
  left: 18px;
  top: 18px;
  translate: 0 0;
}

.discard-3 {
  right: 18px;
  top: 18px;
  translate: 0 0;
}

.discard-name,
.discard-count {
  font-size: 0.64rem;
  line-height: 1;
  opacity: 0.82;
  white-space: nowrap;
}

.discard-tile {
  display: grid;
  place-items: center;
  min-height: 64px;
}

.left-discard .tile,
.right-discard .tile,
.player-discard .tile {
  pointer-events: none;
}

.right-discard.ready {
  border-color: rgba(240, 201, 120, 0.82);
  box-shadow: 0 0 0 3px rgba(240, 201, 120, 0.13);
}

.indicator-card {
  display: grid;
  justify-items: center;
  gap: 4px;
  color: #ead6b9;
  font-weight: 700;
}

.indicator-card .tile {
  width: 42px;
  height: 56px;
  pointer-events: none;
}

.indicator-card .tile-number {
  margin-top: -10px;
  font-size: 1.42rem;
}

.indicator-card .tile-badge {
  bottom: 6px;
  width: 18px;
  font-size: 0.68rem;
}

.indicator-card small {
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #d8cab6;
  font-size: 0.68rem;
  white-space: nowrap;
}

.table-open-area {
  display: grid;
  max-height: 152px;
  pointer-events: none;
}

.table-open-0 {
  left: 50%;
  bottom: 70px;
  width: min(72%, 760px);
  translate: -50% 0;
}

.table-open-1 {
  left: 82px;
  top: 54%;
  width: min(31%, 390px);
  translate: 0 -50%;
}

.table-open-2 {
  left: 50%;
  top: 78px;
  width: min(72%, 760px);
  translate: -50% 0;
}

.table-open-3 {
  right: 82px;
  top: 54%;
  width: min(31%, 390px);
  translate: 0 -50%;
}

.table-open-rail {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  padding: 7px;
  border-radius: 6px;
  max-height: 174px;
  overflow-y: auto;
  overflow-x: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    rgba(6, 42, 48, 0.28);
  background-size: 28px 38px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    inset 0 0 24px rgba(0, 0, 0, 0.18);
}

.table-open-row {
  display: grid;
  flex: 0 0 max-content;
  grid-template-columns: repeat(var(--open-cols, 10), 30px);
  gap: 2px;
  align-items: center;
  overflow: visible;
}

.table-open-cell {
  width: 30px;
  height: 40px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.045);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.055);
}

.table-open-row.ghost {
  opacity: 0.42;
}

.table-open-area:not(.has-opened) {
  opacity: 0.62;
}

.table-open-area .tile {
  width: 30px;
  height: 40px;
  pointer-events: none;
}

.table-open-area .tile-number {
  margin-top: -7px;
  font-size: 0.92rem;
}

.table-open-area .tile-badge {
  bottom: 4px;
  width: 13px;
  font-size: 0.46rem;
  border-width: 1px;
}

.rack-zone {
  display: grid;
  grid-template-columns: minmax(58px, 82px) minmax(0, 1fr) minmax(118px, 150px);
  align-items: end;
  gap: 8px;
  width: min(100%, 1120px);
  margin: 0 auto;
}

.rack-shell {
  position: relative;
  display: block;
  min-width: 0;
  padding: 7px 10px 9px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, #b87922 0%, #c88723 49%, #9d5a17 50%, #714116 100%);
  box-shadow:
    inset 0 4px 0 rgba(255, 238, 171, 0.28),
    inset 0 -10px 18px rgba(74, 34, 8, 0.42),
    0 14px 34px rgba(0, 0, 0, 0.32);
  overflow: hidden;
}

.rack-control {
  display: grid;
  align-content: end;
  gap: 5px;
  min-width: 0;
}

.rack-meter {
  display: flex;
  gap: 6px;
  padding: 5px;
  border-radius: 8px;
  background: rgba(28, 25, 20, 0.76);
  color: #f7ead1;
  font-size: 0.78rem;
  font-weight: 900;
  pointer-events: none;
}

.rack-meter span {
  display: inline-flex;
  min-width: 74px;
  justify-content: center;
  border-radius: 6px;
  padding: 4px 6px;
  background: rgba(255, 255, 255, 0.08);
}

.rack-meter .ready {
  color: #24190c;
  background: #f0c978;
}

.rack-groove {
  display: grid;
  grid-template-columns: repeat(15, 48px);
  grid-template-rows: repeat(2, 66px);
  gap: 6px 4px;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 7px 8px 9px;
  border-radius: 5px;
  background:
    linear-gradient(180deg, rgba(255, 234, 165, 0.44), transparent 16px),
    repeating-linear-gradient(180deg, transparent 0 70px, rgba(80, 34, 8, 0.46) 70px 76px),
    #b9771d;
}

.rack-cell {
  min-width: 0;
  height: 64px;
}

.rack-slot {
  min-width: 0;
  height: 64px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
}

.tile {
  position: relative;
  display: grid;
  align-content: center;
  justify-items: center;
  min-width: 0;
  width: 48px;
  height: 64px;
  border: 0;
  border-radius: 5px;
  background:
    radial-gradient(circle at 50% 73%, rgba(255, 255, 255, 0.62) 0 18px, rgba(199, 188, 152, 0.42) 19px 21px, transparent 22px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.65), transparent 22%),
    linear-gradient(180deg, #eee9bf 0%, #d9d3a3 100%);
  color: #17120e;
  cursor: pointer;
  touch-action: none;
  box-shadow:
    inset -3px 0 0 rgba(0, 0, 0, 0.13),
    inset 1px 0 0 rgba(255, 255, 255, 0.55),
    0 2px 0 #a59b76,
    0 6px 10px rgba(0, 0, 0, 0.26);
}

.tile.dragging,
.left-discard.dragging,
.stock.dragging {
  opacity: 0.42;
}

.rack-groove.drag-over,
.discard-target.drag-over,
.opened-meld-row.drag-over {
  outline: 3px solid rgba(240, 201, 120, 0.82);
  outline-offset: 4px;
}

.opened-meld-row {
  border-radius: 5px;
  pointer-events: auto;
}

.tile-number {
  margin-top: -12px;
  font-size: 1.72rem;
  font-weight: 1000;
  line-height: 1;
  text-shadow:
    1px 1px 0 rgba(255, 255, 255, 0.28),
    2px 2px 0 rgba(0, 0, 0, 0.13);
}

.tile-badge {
  position: absolute;
  bottom: 7px;
  left: 50%;
  display: grid;
  place-items: center;
  width: 21px;
  aspect-ratio: 1;
  translate: -50% 0;
  border-radius: 50%;
  border: 2px solid rgba(171, 160, 118, 0.7);
  background: rgba(238, 231, 186, 0.72);
  color: currentColor;
  font-size: 0.78rem;
  line-height: 1;
}

.tile-red {
  color: #c41118;
}

.tile-blue {
  color: #008293;
}

.tile-black {
  color: #0c0b0a;
}

.tile-yellow {
  color: #da7f08;
}

.tile-joker {
  color: #623294;
}

.tile.selected {
  outline: 3px solid #f1c86f;
  translate: 0 -7px;
}

.tile-okey .tile-number,
.tile-okey .tile-badge {
  display: none;
}

.rack-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  justify-content: stretch;
}

.rack-actions .text-button,
.rack-control-left .text-button {
  min-height: 29px;
  padding: 0 6px;
  font-size: 0.68rem;
  font-weight: 900;
}

.status {
  min-height: 30px;
  font-size: 0.78rem;
}

@media (max-width: 900px) {
  .room {
    grid-template-rows: minmax(430px, 1fr) auto auto;
    padding: 8px;
  }

  .status {
    align-items: flex-start;
    flex-direction: column;
  }

  .table {
    width: 100%;
    min-height: 430px;
    border-width: 8px;
    border-radius: 16px;
  }

  .seat {
    min-width: 112px;
    max-width: 128px;
    padding: 6px;
  }

  .seat strong,
  .seat span {
    font-size: 0.74rem;
  }

  .player-discard {
    width: 62px;
    min-height: 82px;
    padding: 4px;
  }

  .discard-name {
    max-width: 56px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .discard-0 {
    right: 10px;
    bottom: 10px;
  }

  .discard-1 {
    left: 10px;
    bottom: 10px;
    translate: 0 0;
  }

  .discard-2 {
    top: 10px;
    left: 10px;
  }

  .discard-3 {
    right: 10px;
    top: 10px;
    translate: 0 0;
  }

  .draw-cluster {
    gap: 8px;
  }

  .stock {
    width: 46px;
    height: 62px;
  }

  .pile-count {
    width: 30px;
    margin-top: 16px;
  }

  .indicator-card .tile {
    width: 36px;
    height: 48px;
  }

  .indicator-card .tile-number {
    margin-top: -8px;
    font-size: 1.22rem;
  }

  .indicator-card .tile-badge {
    width: 15px;
    font-size: 0.58rem;
  }

  .table-open-0 {
    bottom: 70px;
    width: 62%;
  }

  .table-open-1 {
    left: 58px;
    top: 54%;
    width: 30%;
  }

  .table-open-2 {
    top: 62px;
    width: 62%;
  }

  .table-open-3 {
    right: 58px;
    top: 54%;
    width: 30%;
  }

  .table-open-rail {
    gap: 4px;
    padding: 5px;
    max-height: 130px;
  }

  .table-open-row {
    grid-template-columns: repeat(var(--open-cols, 10), 23px);
    gap: 2px;
  }

  .table-open-cell,
  .table-open-area .tile {
    width: 23px;
    height: 31px;
  }

  .table-open-area .tile-number {
    margin-top: -5px;
    font-size: 0.76rem;
  }

  .table-open-area .tile-badge {
    bottom: 4px;
    width: 11px;
    font-size: 0.42rem;
    border-width: 1px;
  }

  .rack-zone {
    grid-template-columns: 52px minmax(0, 1fr) 112px;
    gap: 5px;
  }

  .rack-shell {
    padding: 6px 7px 8px;
  }

  .rack-meter {
    gap: 4px;
    padding: 4px;
    font-size: 0.68rem;
  }

  .rack-meter span {
    min-width: 62px;
    padding: 3px 4px;
  }

  .rack-groove {
    grid-template-columns: repeat(15, 36px);
    grid-template-rows: repeat(2, 52px);
    gap: 5px 2px;
    padding: 6px;
  }

  .rack-cell,
  .rack-slot,
  .tile {
    height: 50px;
  }

  .tile {
    width: 36px;
  }

  .tile-number {
    margin-top: -9px;
    font-size: 1.34rem;
  }

  .tile-badge {
    bottom: 6px;
    width: 17px;
    font-size: 0.64rem;
  }

  .text-button {
    min-height: 31px;
    padding: 0 6px;
    font-size: 0.72rem;
  }

  .rack-actions .text-button,
  .rack-control-left .text-button {
    min-height: 25px;
    font-size: 0.58rem;
  }
}
