:root {
  --felt: #17633b;
  --felt-deep: #0d2f1d;
  --felt-lit: #228252;
  --wood: #6b3518;
  --wood-dark: #3a1b0c;
  --gold: #c9a15a;
  --ink: #f4ead6;
  --mute: #cbb89a;
  --room: #140e0b;
  --lamp: #f3d7a0;
  --maroon: #9d2c35;
  --safe-b: max(16px, env(safe-area-inset-bottom));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  background: var(--room);
  color: var(--ink);
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", "Times New Roman",
    serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  min-height: 100dvh;
}

button,
input {
  font: inherit;
}

#app,
.viewport {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}

.viewport {
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(243, 215, 160, 0.16), transparent 55%),
    radial-gradient(ellipse 90% 70% at 50% 70%, #2a1b12 0%, #140e0b 70%);
}

.scene {
  position: absolute;
  inset: 4vh 0 30vh;
  perspective: 1180px;
  perspective-origin: 50% 70%;
  transform-style: preserve-3d;
}

.world {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: end center;
  padding-bottom: 2vh;
  transform-style: preserve-3d;
  transform: rotateX(var(--look-x, 6deg)) rotateY(var(--look-y, 0deg));
  transition: transform 180ms ease-out;
}

.lamp {
  position: absolute;
  top: -2vh;
  left: 50%;
  width: 12vw;
  max-width: 88px;
  height: 10vh;
  transform: translateX(-50%);
  z-index: 3;
  pointer-events: none;
}

.lamp .cord {
  width: 2px;
  height: 3.4vh;
  margin: 0 auto;
  background: #2a2118;
}

.lamp .shade {
  height: 4.6vh;
  border-radius: 50% 50% 8% 8%;
  background: linear-gradient(180deg, #8a5a2b, #5a3514);
  box-shadow: 0 10px 30px rgba(243, 215, 160, 0.22);
}

.lamp .glow {
  position: absolute;
  left: 50%;
  top: 8vh;
  width: min(92vw, 720px);
  height: 58vh;
  transform: translateX(-50%);
  background: radial-gradient(
    ellipse at 50% 0%,
    rgba(243, 215, 160, 0.2),
    transparent 68%
  );
  pointer-events: none;
}

.table-root {
  position: relative;
  width: min(108vw, 860px);
  height: min(68vh, 560px);
  transform: rotateX(52deg) translateY(6vh) translateZ(-8px);
  transform-style: preserve-3d;
}

.table-slab {
  position: absolute;
  inset: 0;
  border-radius: 48% / 18%;
  background:
    radial-gradient(ellipse at 50% 38%, var(--felt-lit), var(--felt) 42%, var(--felt-deep));
  box-shadow:
    0 40px 50px rgba(0, 0, 0, 0.45),
    inset 0 0 0 14px #5a2a10,
    inset 0 0 0 18px var(--gold);
  transform-style: preserve-3d;
}

.table-edge {
  position: absolute;
  inset: auto 4% -16px 4%;
  height: 18px;
  border-radius: 0 0 48% 48%;
  background: linear-gradient(180deg, #5a2a10, var(--wood-dark));
  transform: translateZ(-10px);
}

.felt-grain {
  position: absolute;
  inset: 18px;
  border-radius: 46% / 16%;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.28);
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(255, 255, 255, 0.015) 3px
  );
  pointer-events: none;
}

.center-well {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 42%;
  height: 44%;
  transform: translate(-50%, -50%);
  transform-style: preserve-3d;
}

.stock-slot,
.pile-slot {
  position: absolute;
  top: 50%;
  width: 72px;
  height: 100px;
  transform-style: preserve-3d;
}

.stock-slot {
  left: 22%;
  transform: translate(-50%, -50%) rotateX(-24deg) translateZ(16px);
}

.pile-slot {
  left: 64%;
  transform: translate(-50%, -50%) rotateX(-24deg) translateZ(16px);
}

.landing-fan {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%) rotateX(-26deg) translateZ(22px);
  transform-style: preserve-3d;
}

.landing-fan .show-card {
  position: absolute;
  left: 0;
  top: 0;
  margin: -70px 0 0 -50px;
  filter: drop-shadow(0 18px 16px rgba(0, 0, 0, 0.35));
}

.stock-slot.is-live {
  cursor: pointer;
  filter: drop-shadow(0 0 12px rgba(243, 215, 160, 0.55));
}

.named-suit {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -118%) rotateX(-24deg);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(13, 47, 29, 0.72);
  border: 1px solid rgba(201, 161, 90, 0.45);
  color: #f4ead6;
  z-index: 4;
}

.named-suit.red {
  color: #c22f2f;
}

.named-suit svg {
  width: 28px;
  height: 28px;
}

.seat {
  position: absolute;
  transform-style: preserve-3d;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.seat-fan {
  position: relative;
  width: 84px;
  height: 54px;
  transform: rotateX(-52deg);
}

.seat-fan .mini {
  position: absolute;
  left: 50%;
  top: 0;
  margin-left: -18px;
}

.seat-name {
  transform: rotateX(-52deg);
  font-size: 13px;
  letter-spacing: 0.04em;
  background: rgba(20, 14, 11, 0.55);
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(201, 161, 90, 0.25);
  min-height: 28px;
}

.seat.turn .seat-name {
  border-color: var(--gold);
  color: var(--lamp);
}

.seat-count {
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

.hand-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 34vh;
  min-height: 250px;
  z-index: 6;
  pointer-events: none;
  padding-bottom: var(--safe-b);
}

.opp-row {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(34vh + 6px);
  display: flex;
  justify-content: center;
  gap: 8px;
  z-index: 7;
  pointer-events: none;
}

.opp-chip {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
  min-height: 32px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(20, 14, 11, 0.62);
  border: 1px solid rgba(201, 161, 90, 0.28);
  display: inline-flex;
  align-items: center;
}

.opp-chip.turn {
  border-color: var(--gold);
  color: var(--lamp);
}

.hand-stage {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hand-card {
  position: absolute;
  left: 50%;
  bottom: 20px;
  pointer-events: auto;
  touch-action: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: grab;
  transform-origin: 50% 100%;
  filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.35));
  transition: transform 280ms cubic-bezier(0.22, 1, 0.32, 1);
}

.hand-card:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
  border-radius: 10px;
}

.hand-card.is-played {
  cursor: default;
  pointer-events: none;
}

.hand-card:active {
  cursor: grabbing;
}

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
}

.hud > * {
  pointer-events: auto;
}

.top-bar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.brand {
  margin: 0;
  font-size: clamp(28px, 6vw, 42px);
  letter-spacing: -0.03em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}

.brand span {
  display: block;
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.72;
  font-family: ui-sans-serif, system-ui, sans-serif;
}

.turn-chip .hud-suit {
  width: 14px;
  height: 14px;
  margin-left: 6px;
}

.turn-chip .hud-suit.red {
  color: #e07070;
}

.room-chip,
.turn-chip {
  font-family: ui-sans-serif, system-ui, sans-serif;
  border: 1px solid rgba(201, 161, 90, 0.35);
  background: rgba(20, 14, 11, 0.55);
  backdrop-filter: blur(10px);
  color: var(--ink);
  border-radius: 999px;
  min-height: 48px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.12em;
}

.room-chip button {
  border: 0;
  background: transparent;
  color: var(--gold);
  min-height: 44px;
  padding: 0 4px;
  cursor: pointer;
}

.sheet {
  position: absolute;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  width: min(92vw, 420px);
  padding: 18px 18px 16px;
  border-radius: 22px;
  background: rgba(24, 16, 12, 0.78);
  border: 1px solid rgba(201, 161, 90, 0.28);
  backdrop-filter: blur(16px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

.sheet h2 {
  margin: 0 0 6px;
  font-size: 26px;
}

.sheet p {
  margin: 0 0 14px;
  opacity: 0.78;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

.row {
  display: flex;
  gap: 10px;
}

.row input {
  flex: 1;
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid rgba(244, 234, 214, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  padding: 0 14px;
}

.row input:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.btn {
  min-height: 48px;
  min-width: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  background: var(--gold);
  color: #2a1808;
  cursor: pointer;
  font-weight: 650;
  font-family: ui-sans-serif, system-ui, sans-serif;
}

.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid rgba(244, 234, 214, 0.22);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.lobby-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}

.lobby-list li {
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
}

.pass-btn,
.draw-hint {
  position: absolute;
  left: 50%;
  bottom: calc(38vh + 8px);
  transform: translateX(-50%);
  z-index: 9;
}

.suit-picker {
  position: absolute;
  left: 50%;
  bottom: calc(36vh + 12px);
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 10;
  padding: 10px;
  border-radius: 20px;
  background: rgba(24, 16, 12, 0.82);
  border: 1px solid rgba(201, 161, 90, 0.3);
}

.suit-picker button {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  border: 0;
  background: #f7f4ee;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.suit-picker button.red {
  color: #c22f2f;
}

.suit-picker button.black {
  color: #23262d;
}

.suit-picker svg {
  width: 30px;
  height: 30px;
}

.win-banner {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  text-align: center;
  font-size: clamp(32px, 8vw, 56px);
  text-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.toast {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(157, 44, 53, 0.92);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
}

.playing-card {
  position: relative;
  aspect-ratio: 5 / 7;
  border-radius: 0.9em;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.05),
    0 4px 10px rgba(0, 0, 0, 0.07);
  transform: translateZ(0);
}

.playing-card.face-down {
  color: #9d2c35;
}

.corner {
  position: absolute;
  top: 0.6em;
  left: 0.65em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2em;
}

.corner.flipped {
  top: auto;
  left: auto;
  right: 0.65em;
  bottom: 0.6em;
  transform: rotate(180deg);
}

.rank {
  font-weight: 650;
  font-size: 1.55em;
  line-height: 1;
  letter-spacing: -0.03em;
}

.suit-mini {
  width: 1.05em;
  height: 1.05em;
}

.ace-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.suit-ace {
  width: 4.6em;
  height: 4.6em;
}

.pip-field {
  position: absolute;
  left: 24%;
  right: 24%;
  top: 15%;
  bottom: 15%;
}

.pip {
  position: absolute;
  transform: translate(-50%, -50%);
}

.pip.flip {
  transform: translate(-50%, -50%) rotate(180deg);
}

.suit-pip {
  width: 2.1em;
  height: 2.1em;
  display: block;
}

.court {
  position: absolute;
  left: 24%;
  right: 24%;
  top: 16%;
  bottom: 16%;
  overflow: hidden;
  border-radius: 0.4em;
  border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
}

.court-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1em;
  background:
    radial-gradient(circle at 50% 40%, #fff, #f3eee4 70%),
    linear-gradient(180deg, color-mix(in srgb, currentColor 12%, #fff), #fff);
  box-shadow: inset 0 0 0 0.18em color-mix(in srgb, currentColor 28%, #fff);
}

.court-letter {
  font-size: 2.6em;
  font-weight: 700;
  line-height: 0.9;
}

.court-suit {
  width: 1.8em;
  height: 1.8em;
}

.back-inset {
  position: absolute;
  inset: 0.55em;
  border-radius: 0.5em;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.pile-card,
.stock-card {
  position: absolute;
  left: 50%;
  top: 50%;
  margin: -50px 0 0 -36px;
}

.conn {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 12px;
  opacity: 0.7;
}

@media (prefers-reduced-motion: reduce) {
  .hand-card,
  .world {
    transition: none;
  }
}

@media (max-width: 640px) {
  .table-root {
    width: 140vw;
    height: 52vh;
  }
  .stock-slot,
  .pile-slot {
    width: 58px;
    height: 82px;
  }
}
