:root {
  --table: #0d7a45;
  --table-dark: #075832;
  --table-light: #14945b;
  --card: #fffdf7;
  --ink: #17211b;
  --muted: rgba(255, 255, 255, 0.78);
  --line: rgba(255, 255, 255, 0.2);
  --gold: #ffd05a;
  --red: #d3222a;
  --shadow: rgba(0, 0, 0, 0.22);
  --app-height: 100vh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #fff;
  background: radial-gradient(circle at center, var(--table-light), var(--table-dark));
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 16px;
  font-weight: 700;
  color: #16331f;
  background: #fff5cf;
  box-shadow: 0 3px 0 #c99e2d;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

button:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #c99e2d;
}

button:disabled {
  color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.16);
  box-shadow: none;
  cursor: not-allowed;
}

input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  padding: 10px 12px;
  color: #fff;
  background: rgba(0, 0, 0, 0.22);
  outline: none;
}

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

.game-shell {
  min-height: 100vh;
  min-height: 100dvh;
  min-height: var(--app-height);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: max(12px, var(--safe-top)) max(12px, var(--safe-right)) max(12px, var(--safe-bottom)) max(12px, var(--safe-left));
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.game-header h1 {
  margin: 0;
  font-size: clamp(24px, 5vw, 40px);
  letter-spacing: 0;
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.header-actions button {
  padding: 9px 12px;
  font-size: 14px;
}

.status-pill,
.turn-banner {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  color: #fff;
  background: rgba(0, 0, 0, 0.18);
}

.table {
  width: min(1180px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

.top-zone {
  min-height: 86px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.bottom-cards,
.play-area,
.ai-panel,
.human-zone,
.controls {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.15);
  box-shadow: 0 12px 28px var(--shadow);
}

.bottom-cards {
  min-width: min(360px, 92vw);
  padding: 10px;
  text-align: center;
}

.zone-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

.middle-zone {
  min-height: 250px;
  display: grid;
  grid-template-columns: minmax(110px, 160px) 1fr minmax(110px, 160px);
  gap: 12px;
  align-items: stretch;
}

.ai-panel {
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}

.ai-panel.active,
.human-zone.active {
  outline: 3px solid var(--gold);
}

.player-name {
  min-height: 24px;
  font-weight: 800;
}

.player-note {
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
}

.landlord-badge {
  display: inline-flex;
  min-width: 0;
  margin-left: 4px;
  color: var(--gold);
}

.landlord-badge:not(:empty)::before {
  content: "地主";
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 12px;
}

.card-back-stack {
  width: 76px;
  height: 106px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  color: #fff;
  font-size: 28px;
  font-weight: 900;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.22) 25%, transparent 25%) 0 0 / 18px 18px,
    linear-gradient(225deg, rgba(255,255,255,0.2) 25%, transparent 25%) 0 0 / 18px 18px,
    #b71e35;
}

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

.last-play {
  display: flex;
  min-height: 118px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.round-log {
  min-height: 30px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.human-zone {
  padding: 10px;
}

.human-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
}

.hand-scroll {
  overflow-x: auto;
  padding: 18px 4px 6px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.cards-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  min-height: 78px;
}

.cards-row.hand {
  justify-content: flex-start;
  min-width: max-content;
}

.cards-row.small {
  min-height: 60px;
}

.card {
  width: 54px;
  height: 74px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d7d2c3;
  border-radius: 8px;
  color: var(--ink);
  background: var(--card);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.22);
  font-size: 18px;
  font-weight: 800;
  user-select: none;
  transition: transform 0.16s ease, outline-color 0.16s ease, background 0.16s ease;
}

.card.small {
  width: 44px;
  height: 58px;
  font-size: 14px;
}

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

.card.black {
  color: #111;
}

.card.hidden-card {
  color: transparent;
  border-color: rgba(255, 255, 255, 0.42);
  background:
    repeating-linear-gradient(45deg, #9d1731, #9d1731 8px, #c92c49 8px, #c92c49 16px);
}

.card.selectable {
  cursor: pointer;
  min-width: 54px;
}

.card.selected {
  transform: translateY(-16px);
  outline: 3px solid var(--gold);
  background: #fff9df;
}

.controls {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 10px;
}

.button-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.message {
  min-height: 28px;
  margin-top: 10px;
  text-align: center;
  color: #fff6c9;
  font-weight: 700;
}

.effect-layer {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  font-size: clamp(44px, 12vw, 96px);
  font-weight: 900;
  color: #fff6c9;
  text-shadow: 0 6px 0 #9d1731, 0 16px 40px rgba(0, 0, 0, 0.45);
  opacity: 0;
}

.effect-layer.active {
  animation: bombPop 900ms ease both;
}

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

.modal-backdrop.hidden,
.side-panel.hidden {
  display: none;
}

.modal {
  width: min(420px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 24px;
  color: #fff;
  background: linear-gradient(180deg, rgba(21, 116, 72, 0.98), rgba(8, 70, 42, 0.98));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
  animation: modalIn 220ms ease both;
}

.modal h2,
.side-panel h2 {
  margin: 0 0 12px;
}

.modal-actions,
.leaderboard-tools,
.name-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-actions {
  margin-top: 18px;
}

.side-panel {
  position: fixed;
  right: 12px;
  top: 12px;
  bottom: 12px;
  z-index: 25;
  width: min(560px, calc(100vw - 24px));
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 16px;
  background: rgba(7, 66, 39, 0.98);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
}

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

.name-row {
  align-items: center;
  margin: 12px 0;
}

.name-row label {
  color: var(--muted);
}

.name-row input {
  flex: 1 1 180px;
}

.leaderboard-content {
  margin-top: 12px;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 8px;
  font-size: 14px;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 9px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
  text-align: left;
}

.leaderboard-table th {
  color: #fff6c9;
  background: rgba(0, 0, 0, 0.18);
}

.empty-state {
  padding: 20px;
  border: 1px dashed rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.play-flash {
  animation: playFlash 360ms ease;
}

.deal-animate .card {
  animation: dealIn 380ms ease both;
}

.deal-animate .card:nth-child(2n) {
  animation-delay: 40ms;
}

.deal-animate .card:nth-child(3n) {
  animation-delay: 80ms;
}

.last-play-animate {
  animation: playIn 220ms ease both;
}

@keyframes dealIn {
  from {
    opacity: 0;
    transform: translateY(-34px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

@keyframes playFlash {
  0% {
    box-shadow: 0 12px 28px var(--shadow);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(255, 208, 90, 0.55), 0 12px 28px var(--shadow);
  }
  100% {
    box-shadow: 0 12px 28px var(--shadow);
  }
}

@keyframes bombPop {
  0% {
    opacity: 0;
    transform: scale(0.45) rotate(-8deg);
  }
  25% {
    opacity: 1;
    transform: scale(1.14) rotate(2deg);
  }
  70% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.35);
  }
}

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

@media (max-width: 760px) {
  html,
  body {
    overflow-x: hidden;
  }

  .game-shell {
    min-height: 100dvh;
    min-height: var(--app-height);
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 6px;
    padding: max(8px, var(--safe-top)) max(8px, var(--safe-right)) max(8px, var(--safe-bottom)) max(8px, var(--safe-left));
  }

  .game-header {
    align-items: center;
    flex-direction: row;
    gap: 8px;
  }

  .brand {
    flex: 1 1 auto;
    min-width: 0;
    gap: 6px;
  }

  .game-header h1 {
    font-size: 22px;
    line-height: 1.1;
    white-space: nowrap;
  }

  .header-actions {
    width: auto;
    flex: 0 0 auto;
    justify-content: flex-end;
    gap: 5px;
  }

  .header-actions button {
    min-width: 0;
    padding: 8px 9px;
    font-size: 12px;
  }

  .status-pill {
    padding: 5px 8px;
    font-size: 13px;
    white-space: nowrap;
  }

  .table {
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 6px;
  }

  .top-zone {
    min-height: 54px;
  }

  .bottom-cards {
    min-width: 0;
    width: min(270px, 84vw);
    padding: 6px 8px;
  }

  .zone-title {
    margin-bottom: 4px;
    font-size: 12px;
  }

  .middle-zone {
    min-height: 0;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto minmax(138px, 1fr);
    grid-template-areas:
      "leftAI rightAI"
      "playArea playArea";
    gap: 6px;
  }

  .ai-panel.left {
    grid-area: leftAI;
  }

  .ai-panel.right {
    grid-area: rightAI;
  }

  .play-area {
    grid-area: playArea;
  }

  .ai-panel {
    min-height: 76px;
    padding: 6px 8px;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    justify-items: start;
    gap: 2px 8px;
    text-align: left;
  }

  .card-back-stack {
    grid-row: 1 / span 2;
    grid-column: 2;
    width: 44px;
    height: 58px;
    font-size: 18px;
    border-radius: 7px;
  }

  .play-area {
    min-height: 138px;
    padding: 8px;
    grid-template-rows: auto minmax(80px, 1fr) auto;
    gap: 6px;
  }

  .turn-banner {
    padding: 6px 8px;
    font-size: 13px;
  }

  .last-play {
    min-height: 78px;
  }

  .round-log {
    max-height: 42px;
    overflow: hidden;
    font-size: 12px;
    line-height: 1.45;
  }

  .human-zone {
    padding: 7px 8px;
  }

  .human-meta {
    margin-bottom: 4px;
    font-size: 12px;
  }

  .hand-scroll {
    margin: 0 -4px;
    padding: 18px 4px 4px;
  }

  .card {
    width: clamp(40px, 11.2vw, 48px);
    min-width: clamp(40px, 11.2vw, 48px);
    height: clamp(56px, 15.6vw, 66px);
    font-size: clamp(14px, 4vw, 16px);
    border-radius: 7px;
  }

  .card.selectable {
    min-width: clamp(40px, 11.2vw, 48px);
  }

  .card.small {
    width: 34px;
    min-width: 34px;
    height: 46px;
    font-size: 12px;
  }

  .cards-row {
    min-height: 54px;
    gap: 4px;
  }

  .cards-row.hand {
    min-height: clamp(72px, 20vw, 88px);
    padding-right: 8px;
  }

  button {
    min-height: 42px;
    min-width: 72px;
    padding: 10px 12px;
    font-size: 14px;
  }

  .controls {
    padding: 7px 8px calc(7px + var(--safe-bottom));
  }

  .button-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .button-row button {
    width: 100%;
    min-width: 0;
    padding: 10px 4px;
    white-space: nowrap;
  }

  .message {
    min-height: 22px;
    margin-top: 6px;
    font-size: 13px;
    line-height: 1.35;
  }

  .modal-backdrop {
    padding: max(12px, var(--safe-top)) max(12px, var(--safe-right)) max(12px, var(--safe-bottom)) max(12px, var(--safe-left));
  }

  .modal {
    padding: 18px;
  }

  .side-panel {
    inset: max(8px, var(--safe-top)) max(8px, var(--safe-right)) max(8px, var(--safe-bottom)) max(8px, var(--safe-left));
    width: auto;
    padding: 12px;
  }

  .name-row,
  .leaderboard-tools {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .name-row label {
    grid-column: 1 / -1;
  }

  .leaderboard-table {
    min-width: 520px;
  }

  .leaderboard-content {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 460px) {
  .game-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand,
  .header-actions {
    width: 100%;
  }

  .header-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .header-actions button {
    width: 100%;
  }

  .player-name,
  .player-note,
  .round-log {
    font-size: 12px;
  }

  .turn-banner {
    padding: 6px 8px;
    font-size: 13px;
  }
}

@media (max-height: 720px) and (max-width: 760px) {
  .game-shell {
    gap: 5px;
  }

  .top-zone {
    min-height: 46px;
  }

  .bottom-cards {
    padding: 4px 6px;
  }

  .card.small {
    width: 30px;
    min-width: 30px;
    height: 40px;
    font-size: 11px;
  }

  .middle-zone {
    grid-template-rows: auto minmax(112px, 1fr);
  }

  .ai-panel {
    min-height: 62px;
  }

  .card-back-stack {
    width: 36px;
    height: 48px;
    font-size: 16px;
  }

  .play-area {
    min-height: 112px;
  }

  .last-play {
    min-height: 58px;
  }

  .round-log {
    display: none;
  }

  .hand-scroll {
    padding-top: 14px;
  }

  .cards-row.hand {
    min-height: 66px;
  }

  .card {
    width: 38px;
    min-width: 38px;
    height: 52px;
    font-size: 13px;
  }

  .card.selectable {
    min-width: 38px;
  }

  .card.selected {
    transform: translateY(-12px);
  }

  button {
    min-height: 38px;
    padding-top: 8px;
    padding-bottom: 8px;
  }
}
