:root {
  color-scheme: dark;
  --bg: #08110d;
  --panel: rgba(9, 21, 16, 0.82);
  --panel-strong: rgba(13, 34, 25, 0.95);
  --line: rgba(226, 207, 160, 0.22);
  --gold: #e8c56f;
  --gold-bright: #ffe7a3;
  --jade: #5fe0b6;
  --red: #f45d62;
  --ink: #111515;
  --cream: #fff7e8;
  --muted: #9eb3a7;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.42);
  --card-w: clamp(46px, 5vw, 72px);
  --card-h: calc(var(--card-w) * 1.42);
  --selected-card-lift: calc(var(--card-h) / 3);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(232, 197, 111, 0.12), transparent 32%),
    radial-gradient(circle at 82% 20%, rgba(95, 224, 182, 0.11), transparent 36%),
    linear-gradient(135deg, #07110d 0%, #0f241a 48%, #050806 100%);
  color: var(--cream);
}

button {
  border: 0;
  cursor: pointer;
  font: inherit;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  filter: grayscale(0.35);
}

.hidden {
  display: none !important;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  padding: 18px;
  isolation: isolate;
}

.app-shell::before {
  position: fixed;
  inset: 0;
  z-index: -3;
  content: "";
  background:
    linear-gradient(rgba(4, 12, 9, 0.48), rgba(4, 12, 9, 0.86)),
    url("assets/table-bg.svg") center / cover no-repeat;
  opacity: 0.78;
}

.app-shell::after {
  position: fixed;
  inset: 0;
  z-index: -2;
  content: "";
  background-image:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at center, #000 0 55%, transparent 82%);
}

.particle-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}

.particle {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 227, 157, 0.58);
  box-shadow: 0 0 16px rgba(255, 227, 157, 0.8);
  animation: floatParticle var(--duration, 9s) linear infinite;
}

.topbar,
.game-layout,
.board,
.info-panel,
.status-block,
.phase-card,
.result-card {
  backdrop-filter: blur(18px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto 16px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(9, 24, 18, 0.84), rgba(15, 36, 28, 0.68));
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(24px, 3vw, 42px);
  line-height: 1.05;
}

h2 {
  margin-bottom: 10px;
  color: var(--gold-bright);
  font-size: 16px;
}

.topbar-actions,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ghost-button,
.primary-button,
.secondary-button,
.danger-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  color: var(--cream);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, background 160ms ease;
}

.ghost-button,
.secondary-button {
  background: rgba(255,255,255,0.08);
}

.primary-button {
  background: linear-gradient(135deg, #e5b24f, #936219);
  box-shadow: 0 8px 22px rgba(232, 197, 111, 0.24);
}

.danger-button {
  background: linear-gradient(135deg, #f45d62, #8f1e28);
  box-shadow: 0 8px 22px rgba(244, 93, 98, 0.24);
}

.ghost-button:hover:not(:disabled),
.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled),
.danger-button:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: rgba(255, 231, 163, 0.55);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.34);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
}

.info-panel {
  display: grid;
  align-content: start;
  gap: 12px;
}

.status-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 14px;
}

.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
}

.status-grid div {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255,255,255,0.045);
}

dt {
  color: var(--muted);
  font-size: 12px;
}

dd {
  margin: 3px 0 0;
  color: var(--cream);
  font-weight: 700;
}

.hint-text {
  min-height: 46px;
  color: #dce8df;
  line-height: 1.45;
}

.log-block {
  max-height: calc(100vh - 392px);
  min-height: 180px;
  overflow: hidden;
}

.log-list {
  display: flex;
  flex-direction: column-reverse;
  gap: 7px;
  max-height: calc(100vh - 464px);
  min-height: 120px;
  overflow: auto;
  padding: 0 4px 0 18px;
  margin: 0;
  color: #d4e5da;
  font-size: 13px;
  line-height: 1.45;
}

.board {
  position: relative;
  display: grid;
  grid-template-rows: minmax(116px, 0.7fr) minmax(220px, 1.4fr) minmax(168px, 0.95fr);
  grid-template-columns: minmax(116px, 0.68fr) minmax(260px, 1.55fr) minmax(116px, 0.68fr);
  min-height: calc(100vh - 114px);
  border: 1px solid rgba(232, 197, 111, 0.22);
  border-radius: 8px;
  overflow: hidden;
  background:
    radial-gradient(circle at center, rgba(36, 91, 62, 0.66), rgba(13, 38, 28, 0.82) 48%, rgba(5, 12, 9, 0.92)),
    linear-gradient(135deg, rgba(232, 197, 111, 0.06), rgba(95, 224, 182, 0.05));
  box-shadow: var(--shadow);
}

.board::before {
  position: absolute;
  inset: 9%;
  content: "";
  border: 1px solid rgba(255, 231, 163, 0.18);
  border-radius: 50%;
  box-shadow: inset 0 0 80px rgba(0,0,0,0.45), 0 0 80px rgba(232,197,111,0.08);
}

.seat {
  position: relative;
  z-index: 1;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  padding: 12px;
}

.seat-top {
  grid-area: 1 / 2 / 2 / 3;
}

.seat-left {
  grid-area: 2 / 1 / 3 / 2;
}

.seat-right {
  grid-area: 2 / 3 / 3 / 4;
}

.seat-bottom {
  grid-area: 3 / 2 / 4 / 3;
  z-index: 4;
}

.player-card {
  width: min(100%, 250px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 10px;
  background: rgba(3, 11, 8, 0.42);
  box-shadow: 0 16px 38px rgba(0,0,0,0.24);
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.seat-bottom .player-card {
  position: relative;
  z-index: 4;
  width: min(100%, 680px);
}

.seat-left .player-card,
.seat-right .player-card {
  width: min(100%, 156px);
}

.current-player .player-card {
  border-color: rgba(255, 231, 163, 0.85);
  box-shadow: 0 0 0 1px rgba(255, 231, 163, 0.24), 0 18px 42px rgba(0,0,0,0.35);
  transform: translateY(-2px);
}

.human-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.human-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.human-actions .primary-button,
.human-actions .secondary-button {
  min-width: 64px;
  min-height: 36px;
}

.player-meta {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.avatar {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  border: 2px solid rgba(255,231,163,0.5);
  border-radius: 50%;
  overflow: hidden;
  background:
    linear-gradient(rgba(0,0,0,0.1), rgba(0,0,0,0.42)),
    var(--avatar, linear-gradient(135deg, #285941, #d4a84d));
  background-size: cover;
  background-position: center;
  color: var(--gold-bright);
  font-weight: 900;
}

.avatar.revealed {
  animation: revealBadge 520ms ease both;
}

.player-name {
  margin: 0;
  font-weight: 800;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  color: var(--muted);
  font-size: 12px;
}

.role-badge.landlord {
  background: rgba(232, 197, 111, 0.18);
  color: var(--gold-bright);
}

.role-badge.farmer {
  background: rgba(95, 224, 182, 0.16);
  color: #c6ffef;
}

.player-stats {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.mini-hand,
.human-hand {
  display: flex;
  justify-content: center;
  width: 100%;
}

.mini-hand {
  min-height: 54px;
  margin-top: 8px;
}

.seat-left .mini-hand,
.seat-right .mini-hand {
  align-items: center;
  flex-direction: column;
  min-height: 206px;
  overflow: visible;
}

.mini-hand .card {
  width: 32px;
  height: 46px;
  margin-left: -18px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.32);
}

.seat-left .mini-hand .card,
.seat-right .mini-hand .card {
  width: 34px;
  height: 48px;
  margin-top: -30px;
  margin-left: 0;
}

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

.seat-left .mini-hand .card:first-child,
.seat-right .mini-hand .card:first-child {
  margin-top: 0;
}

.human-hand {
  position: relative;
  z-index: 6;
  align-items: flex-end;
  min-height: calc(var(--card-h) * 1.42);
  padding: calc(var(--card-h) * 0.36) 12px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  pointer-events: auto;
  scrollbar-width: none;
}

.human-hand::-webkit-scrollbar {
  display: none;
}

.human-hand .card {
  flex: 0 0 var(--card-w);
  margin-left: calc(var(--card-w) * -0.34);
  pointer-events: auto;
}

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

.center-table {
  position: relative;
  z-index: 1;
  grid-area: 2 / 2 / 3 / 3;
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 18px;
}

.table-glow {
  position: absolute;
  width: min(72%, 520px);
  aspect-ratio: 1 / 0.58;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 231, 163, 0.2), rgba(95, 224, 182, 0.12) 45%, transparent 72%);
  filter: blur(4px);
  animation: tableBreath 4.8s ease-in-out infinite;
}

.center-table.explode {
  animation: explodePulse 780ms ease both;
}

.deck-pile {
  position: absolute;
  left: 18px;
  bottom: 18px;
  width: 58px;
  height: 82px;
}

.deck-card {
  position: absolute;
  width: 54px;
  height: 78px;
}

.deck-card.offset {
  transform: translate(6px, -5px) rotate(6deg);
}

.table-state {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 14px;
  width: min(100%, 560px);
  padding: 18px;
  border: 1px solid rgba(255,231,163,0.16);
  border-radius: 8px;
  background: rgba(2, 10, 7, 0.36);
}

.table-state p {
  margin-bottom: 0;
  color: #dce8df;
}

.table-cards,
.phase-cards {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  min-height: calc(var(--card-h) + 20px);
  gap: 8px;
  flex-wrap: wrap;
}

.card {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--card-w);
  height: var(--card-h);
  padding: 7px;
  border: 1px solid rgba(20, 18, 14, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.98), rgba(247, 236, 210, 0.98)),
    repeating-linear-gradient(45deg, transparent 0 6px, rgba(232,197,111,0.1) 6px 7px);
  color: #191815;
  box-shadow: 0 8px 20px rgba(0,0,0,0.32);
  overflow: hidden;
  user-select: none;
  transform-origin: center bottom;
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease;
}

.card.red {
  color: #bc1f2f;
}

.card.black {
  color: #141516;
}

.card.selectable:hover {
  transform: translateY(-8px);
  box-shadow: 0 14px 28px rgba(0,0,0,0.42), 0 0 0 1px rgba(255,231,163,0.3);
}

.card.selected {
  transform: translateY(calc(var(--selected-card-lift) * -1));
  box-shadow: 0 18px 34px rgba(0,0,0,0.44), 0 0 24px rgba(255,231,163,0.42);
}

.card.playable {
  outline: 2px solid rgba(95, 224, 182, 0.75);
  outline-offset: -4px;
}

.card.entering {
  animation: dealIn 420ms cubic-bezier(.2,.82,.28,1.1) both;
  animation-delay: var(--delay, 0ms);
}

.human-hand .card.selected {
  animation: none;
  transform: translateY(calc(var(--selected-card-lift) * -1));
}

.card.played {
  animation: playIn 360ms cubic-bezier(.2,.88,.22,1.12) both;
}

.card .corner {
  position: absolute;
  top: 7px;
  left: 7px;
  display: grid;
  line-height: 1;
  font-size: clamp(12px, 1.5vw, 17px);
  font-weight: 900;
}

.card .suit-center {
  place-self: center;
  font-size: clamp(23px, 2.6vw, 34px);
}

.card .corner.bottom {
  top: auto;
  right: 7px;
  bottom: 7px;
  left: auto;
  transform: rotate(180deg);
}

.card-back {
  border-color: rgba(255, 231, 163, 0.22);
  background:
    radial-gradient(circle at center, rgba(255,231,163,0.3), transparent 28%),
    repeating-linear-gradient(135deg, rgba(255,255,255,0.12) 0 4px, transparent 4px 10px),
    linear-gradient(135deg, #86232b, #1b4734);
}

.card-back::after {
  position: absolute;
  inset: 8px;
  content: "";
  border: 1px solid rgba(255,231,163,0.35);
  border-radius: 6px;
}

.phase-panel,
.result-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0,0,0,0.62);
}

.phase-card,
.result-card {
  width: min(640px, 100%);
  border: 1px solid rgba(255,231,163,0.28);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 28px 90px rgba(0,0,0,0.62);
  padding: 22px;
  animation: modalIn 240ms ease both;
}

.phase-card p,
.result-card p {
  color: #dce8df;
  line-height: 1.55;
}

.phase-cards {
  justify-content: flex-start;
  margin: 16px 0;
}

.phase-cards .card {
  cursor: pointer;
}

.finish-order {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.finish-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
}

@keyframes floatParticle {
  from {
    transform: translateY(105vh) translateX(0);
    opacity: 0;
  }
  12% {
    opacity: 0.8;
  }
  to {
    transform: translateY(-12vh) translateX(var(--drift, 30px));
    opacity: 0;
  }
}

@keyframes tableBreath {
  0%,
  100% {
    transform: scale(0.96);
    opacity: 0.72;
  }
  50% {
    transform: scale(1.06);
    opacity: 1;
  }
}

@keyframes dealIn {
  from {
    transform: translateY(-90px) rotate(-12deg) scale(0.82);
    opacity: 0;
  }
  to {
    transform: translateY(0) rotate(0) scale(1);
    opacity: 1;
  }
}

@keyframes playIn {
  from {
    transform: translateY(42px) scale(0.88);
    opacity: 0.45;
  }
  70% {
    transform: translateY(-8px) scale(1.03);
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes revealBadge {
  0% {
    transform: rotateY(0);
  }
  50% {
    transform: rotateY(90deg);
  }
  100% {
    transform: rotateY(0);
  }
}

@keyframes explodePulse {
  0% {
    filter: brightness(1);
  }
  45% {
    filter: brightness(1.65) saturate(1.4);
    box-shadow: inset 0 0 120px rgba(244, 93, 98, 0.45);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes modalIn {
  from {
    transform: translateY(18px) scale(0.98);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@media (max-width: 1040px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .info-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .log-block {
    grid-column: 1 / -1;
    max-height: 190px;
  }

  .log-list {
    max-height: 126px;
  }

  .board {
    min-height: 760px;
  }
}

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

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

  .info-panel {
    grid-template-columns: 1fr;
  }

  .board {
    grid-template-rows: 116px minmax(250px, 1fr) 188px;
    grid-template-columns: 84px minmax(0, 1fr) 84px;
    min-height: 700px;
  }

  .seat {
    padding: 8px;
  }

  .player-card {
    padding: 8px;
  }

  .seat-left .player-meta,
  .seat-right .player-meta {
    flex-direction: column;
    text-align: center;
  }

  .human-header-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .human-actions {
    justify-content: flex-start;
    margin-left: 0;
  }

  .seat-left .player-name,
  .seat-right .player-name,
  .seat-left .role-badge,
  .seat-right .role-badge {
    display: none;
  }

  .mini-hand .card {
    width: 25px;
    height: 36px;
    margin-left: -16px;
  }

  .deck-pile {
    display: none;
  }
}
