:root {
  --bg-1: #4e0e0e;
  --bg-2: #7c1515;
  --bg-3: #2b0707;
  --gold-1: #f4d89f;
  --gold-2: #d6a44a;
  --gold-3: #8e5f20;
  --panel: rgba(60, 10, 10, 0.65);
  --panel-border: rgba(239, 191, 103, 0.38);
  --text-main: #f9f2de;
  --text-muted: rgba(249, 242, 222, 0.8);
  --text-soft: rgba(249, 242, 222, 0.62);
  --danger: #d02828;
  --success: #5fd687;
  --font-title: "Ma Shan Zheng", cursive;
  --font-body: "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-body);
  color: var(--text-main);
  background:
    radial-gradient(1100px 600px at 50% -15%, #b84f32 0%, transparent 60%),
    radial-gradient(900px 500px at 0% 100%, rgba(255, 159, 99, 0.25) 0%, transparent 60%),
    radial-gradient(850px 450px at 100% 100%, rgba(255, 224, 138, 0.22) 0%, transparent 62%),
    linear-gradient(165deg, var(--bg-3), var(--bg-1) 48%, var(--bg-2));
  overflow-x: hidden;
  position: relative;
}

.bg-glow {
  position: fixed;
  width: 320px;
  height: 320px;
  border-radius: 999px;
  filter: blur(70px);
  opacity: 0.45;
  pointer-events: none;
  z-index: 0;
}

.bg-glow-left {
  left: -110px;
  top: 80px;
  background: rgba(253, 196, 74, 0.42);
}

.bg-glow-right {
  right: -120px;
  top: 140px;
  background: rgba(255, 123, 80, 0.36);
}

.table-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.16;
  background-image:
    radial-gradient(circle at 2px 2px, rgba(255, 216, 158, 0.16) 1.2px, transparent 0),
    radial-gradient(circle at 6px 6px, rgba(0, 0, 0, 0.2) 1.1px, transparent 0);
  background-size: 8px 8px;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1220px;
  margin: 0 auto;
  padding: 20px 16px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.royal-frame {
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(7px);
  box-shadow:
    inset 0 0 0 1px rgba(255, 235, 192, 0.14),
    0 12px 30px rgba(0, 0, 0, 0.35);
}

.top-panel {
  padding: 14px 16px 12px;
  background:
    linear-gradient(180deg, rgba(255, 214, 138, 0.07), transparent 42%),
    var(--panel);
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h1 {
  margin: 0;
  font-family: var(--font-title);
  font-size: clamp(1.8rem, 3.5vw, 2.7rem);
  color: var(--gold-1);
  letter-spacing: 0.03em;
  text-shadow:
    0 2px 0 rgba(111, 64, 17, 0.85),
    0 8px 16px rgba(0, 0, 0, 0.42);
}

h2,
h3 {
  margin: 0;
  font-weight: 800;
}

.mode-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 700;
  color: #2f1307;
  border: 1px solid rgba(255, 236, 193, 0.7);
  background: linear-gradient(160deg, #ffe29f, #efb85f);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.26);
}

.meta-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
  color: var(--text-soft);
  font-size: 0.92rem;
}

.meta-row.compact {
  align-items: baseline;
}

.meta-row.compact strong {
  font-size: 1.06rem;
  color: #fff6de;
}

.meta-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.meta-card {
  border: 1px solid rgba(245, 196, 97, 0.28);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 246, 220, 0.08), rgba(255, 246, 220, 0.02));
  padding: 8px 10px;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.meta-label {
  font-size: 0.8rem;
  color: var(--text-soft);
}

.meta-row strong {
  color: var(--text-main);
  font-weight: 800;
  word-break: break-all;
}

.notice-row {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(251, 204, 114, 0.2);
  background: rgba(255, 245, 216, 0.05);
  min-height: 38px;
  align-items: center;
}

.board {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) 190px;
  gap: 12px;
}

.ai-panel {
  padding: 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-height: 280px;
}

.avatar-frame {
  width: 88px;
  height: 88px;
  border-radius: 999px;
  border: 2px solid rgba(255, 230, 175, 0.55);
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 227, 164, 0.5), rgba(157, 73, 24, 0.2) 68%),
    rgba(72, 19, 19, 0.72);
  box-shadow:
    inset 0 0 22px rgba(255, 210, 132, 0.2),
    0 8px 16px rgba(0, 0, 0, 0.3);
  display: grid;
  place-items: center;
  position: relative;
}

.avatar {
  font-size: 1.9rem;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.5));
}

.role-tag {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 222, 153, 0.62);
  border-radius: 999px;
  background: linear-gradient(180deg, #ffdf95, #d89234);
  color: #3d1d0d;
  padding: 1px 10px;
  font-size: 0.75rem;
  font-weight: 700;
}

.ai-info {
  display: grid;
  gap: 5px;
}

.ai-panel p {
  margin: 0;
  color: var(--text-muted);
}

.back-stack {
  width: 100%;
  min-height: 130px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(28px, 1fr));
  gap: 7px;
  align-content: start;
}

.back-card {
  height: 45px;
  border-radius: 7px;
  border: 1px solid rgba(255, 225, 170, 0.22);
  background:
    linear-gradient(145deg, #8a1720 0%, #5d0f15 48%, #3f080d 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 0 0 3px rgba(255, 204, 120, 0.06);
  position: relative;
}

.back-card::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 4px;
  border: 1px dashed rgba(255, 216, 147, 0.4);
}

.center-area {
  padding: 12px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.play-zone {
  position: relative;
  min-height: 240px;
  border-radius: 16px;
  overflow: hidden;
  background:
    radial-gradient(circle at center, rgba(31, 108, 69, 0.9) 0%, rgba(12, 63, 40, 0.94) 52%, rgba(7, 38, 24, 0.98) 100%);
  border: 1px solid rgba(255, 218, 139, 0.25);
}

.table-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(78vw, 560px);
  aspect-ratio: 2.45/1;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  border: 2px solid rgba(255, 215, 130, 0.5);
  box-shadow:
    inset 0 0 26px rgba(255, 204, 97, 0.2),
    0 0 24px rgba(255, 180, 80, 0.16);
}

.play-content {
  position: relative;
  z-index: 1;
  padding: 14px;
}

.play-zone h2 {
  margin-bottom: 4px;
  color: #ffe8bb;
  font-size: 1.08rem;
}

.play-owner {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.table-cards {
  min-height: 100px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: flex-start;
  align-content: center;
  justify-content: center;
  padding: 10px;
}

.history-zone {
  border-top: 1px solid rgba(255, 229, 179, 0.2);
  padding-top: 8px;
}

.history-zone h3 {
  margin-bottom: 6px;
  color: #ffe7b8;
  font-size: 1rem;
}

#history-list {
  margin: 0;
  padding-left: 18px;
  max-height: 150px;
  overflow: auto;
  color: var(--text-muted);
  font-size: 0.88rem;
}

#history-list li {
  margin-bottom: 4px;
}

.player-area {
  padding: 14px 12px 12px;
  position: relative;
  overflow: hidden;
}

.player-area::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(255, 208, 107, 0.06), transparent 35%),
    linear-gradient(90deg, transparent, rgba(255, 245, 213, 0.03) 50%, transparent);
  pointer-events: none;
}

.landlord-crown {
  position: absolute;
  top: 9px;
  left: 12px;
  z-index: 2;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.82rem;
  font-weight: 800;
  color: #3d1b08;
  border: 1px solid rgba(255, 234, 192, 0.68);
  background: linear-gradient(180deg, #ffe9b4, #e2a64d);
}

.player-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding-left: 62px;
}

.player-title-row p {
  margin: 0;
  color: var(--text-muted);
}

.player-hand {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  min-height: 126px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 6px 10px;
}

.player-card,
.table-card {
  width: 58px;
  height: 86px;
  border-radius: 11px;
  border: 2px solid transparent;
  background:
    linear-gradient(165deg, #fffdf8 0%, #f5ead6 100%);
  box-shadow:
    0 7px 16px rgba(0, 0, 0, 0.36),
    inset 0 0 0 1px rgba(255, 255, 255, 0.72);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 7px 5px;
  position: relative;
}

.player-card {
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.player-card:hover {
  transform: translateY(-7px);
  z-index: 3;
}

.player-card.disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

.player-card.selected {
  border-color: #ffbf47;
  box-shadow:
    0 0 0 2px rgba(255, 191, 71, 0.45),
    0 12px 24px rgba(0, 0, 0, 0.4);
  transform: translateY(-16px);
  z-index: 4;
}

.table-card {
  width: 56px;
  height: 82px;
  cursor: default;
}

.card-rank {
  font-weight: 800;
  font-size: 1.12rem;
  line-height: 1;
  align-self: flex-start;
}

.card-suit {
  font-size: 1.18rem;
  line-height: 1;
  margin-bottom: 2px;
}

.card-joker {
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.red {
  color: var(--danger);
}

.black {
  color: #121212;
}

.action-bar {
  padding: 12px;
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
}

.action-btn {
  appearance: none;
  border: 1px solid rgba(255, 233, 190, 0.28);
  border-radius: 14px;
  min-width: 130px;
  padding: 10px 22px;
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--text-main);
  background:
    linear-gradient(180deg, rgba(255, 248, 221, 0.08), rgba(255, 248, 221, 0.02));
  cursor: pointer;
  transition: transform 0.16s ease, filter 0.16s ease, opacity 0.15s ease;
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.25);
}

.action-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

.action-btn.primary {
  color: #3d1b08;
  border: 1px solid rgba(255, 233, 188, 0.85);
  background: linear-gradient(160deg, #ffe6ad 0%, #f5be5c 60%, #cf8d39 100%);
}

.action-btn.ghost {
  background: linear-gradient(180deg, rgba(255, 217, 164, 0.2), rgba(80, 19, 19, 0.2));
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  background: rgba(60, 12, 12, 0.92);
  color: #fff8e8;
  border: 1px solid rgba(255, 228, 173, 0.28);
  border-radius: 10px;
  padding: 9px 14px;
  z-index: 50;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

.result-modal {
  position: fixed;
  inset: 0;
  background: rgba(26, 3, 3, 0.76);
  display: grid;
  place-items: center;
  z-index: 90;
}

.hidden {
  display: none;
}

.modal-card {
  width: min(92vw, 420px);
  border-radius: 16px;
  border: 1px solid rgba(255, 223, 167, 0.36);
  background: linear-gradient(180deg, #6c1717 0%, #3c0b0b 100%);
  padding: 20px 18px;
  text-align: center;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.5);
}

.modal-card h2 {
  margin-bottom: 8px;
  color: #ffe0a2;
}

.modal-card p {
  margin: 0 0 14px;
  color: var(--text-muted);
}

@media (max-width: 980px) {
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .board {
    grid-template-columns: 1fr;
  }

  .ai-panel {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    min-height: auto;
    padding: 10px 12px;
  }

  .avatar-frame {
    width: 66px;
    height: 66px;
  }

  .avatar {
    font-size: 1.6rem;
  }

  .back-stack {
    flex: 1;
    min-height: auto;
    max-width: 62%;
  }

  .center-area {
    order: -1;
  }

  .player-card,
  .table-card {
    width: 52px;
    height: 76px;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 12px 10px 18px;
  }

  h1 {
    font-size: 1.8rem;
  }

  .mode-chip {
    padding: 3px 10px;
    font-size: 0.78rem;
  }

  .meta-row {
    font-size: 0.88rem;
  }

  .landlord-crown {
    top: 8px;
    left: 10px;
    font-size: 0.75rem;
  }

  .player-hand {
    min-height: 112px;
    padding: 6px 2px 10px;
  }

  .player-card,
  .table-card {
    width: 50px;
    height: 72px;
    padding: 6px 2px;
  }

  .card-rank {
    font-size: 0.96rem;
  }

  .card-suit {
    font-size: 1rem;
  }

  .action-btn {
    width: 100%;
  }

  .action-bar {
    flex-direction: column;
  }
}
