:root {
  font-family: "Microsoft YaHei", Arial, sans-serif;
  color: #f7f0df;
  background: #17261f;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: url('1.png') center center / cover no-repeat fixed,
    linear-gradient(135deg, #14251d 0%, #213a2d 42%, #4a3322 100%);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, rgba(20, 37, 29, .55), rgba(74, 51, 34, .55));
  z-index: -1;
}
body.game-page {
  background: url('2.png') center center / cover no-repeat fixed,
    linear-gradient(135deg, #14251d 0%, #213a2d 42%, #4a3322 100%);
}
body.game-page::before {
  background: linear-gradient(135deg, rgba(20, 37, 29, .40), rgba(74, 51, 34, .40));
}
button, input { font: inherit; }
button {
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 7px;
  background: linear-gradient(#2f8f67, #1f6f50);
  color: #fff8df;
  padding: 9px 13px;
  cursor: pointer;
  box-shadow: 0 3px 0 #104631, 0 8px 18px rgba(0,0,0,.22);
}
button.secondary { background: linear-gradient(#6b7668, #475347); box-shadow: 0 3px 0 #2d352e, 0 8px 18px rgba(0,0,0,.2); }
button:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.35); }
button[hidden] { display: none; }
input {
  border: 1px solid rgba(255,255,255,.26);
  border-radius: 7px;
  padding: 10px 11px;
  background: rgba(255,255,255,.9);
  color: #17261f;
}
.home { max-width: 720px; min-height: 100vh; margin: 0 auto; padding: 60px 20px; }
.hero { padding: 40px 0 28px; text-shadow: 0 3px 16px rgba(0,0,0,.35); text-align: center; }
.hero h1 { font-size: 64px; margin: 0; color: #fff4cf; }
.hero p { margin: 0; font-size: 18px; color: #dfe9d3; }
.home-grid { display: grid; grid-template-columns: 1fr; gap: 20px; max-width: 520px; margin: 0 auto; }
.panel {
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 14px;
  padding: 36px 32px;
  display: grid;
  gap: 20px;
  background: linear-gradient(180deg, rgba(255,255,255,.16), rgba(255,255,255,.08));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 16px 36px rgba(0,0,0,.24);
  backdrop-filter: blur(8px);
}
.panel h2 { margin: 0; font-size: 26px; color: #ffe6a0; text-align: center; }
.panel label { display: grid; gap: 8px; color: #ecf4df; font-size: 18px; }
.panel input { font-size: 18px; padding: 14px 16px; border-radius: 10px; }
.panel button { font-size: 20px; padding: 14px 20px; border-radius: 10px; }
.game {
  max-width: 1180px;
  height: 100vh;
  margin: 0 auto;
  padding: 10px 14px 70px;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,.02) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,.015) 1px, transparent 1px),
    linear-gradient(135deg, rgba(43, 86, 58, .28), rgba(93, 64, 38, .32));
  background-size: 34px 34px, 34px 34px, auto;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 0 48px rgba(0,0,0,.34);
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
  background: rgba(20, 32, 25, .62);
}
.topbar h1 { margin: 0; font-size: 20px; line-height: 1.1; color: #ffe6a0; }
.topbar h1 span { color: #dbe8cf; font-size: 13px; font-weight: 500; margin-left: 8px; }
.topbar p { margin: 0; font-size: 13px; color: #dbe8cf; text-align: right; }
.actions {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(1180px, 100%);
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid rgba(255,255,255,.16);
  background: linear-gradient(180deg, rgba(29, 45, 35, .95), rgba(16, 28, 22, .98));
  box-shadow: 0 -12px 26px rgba(0,0,0,.22);
}
.players, .ecosystems { display: flex; flex-wrap: wrap; gap: 6px; margin: 7px 0 0; }
.badge {
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 4px 9px;
  background: rgba(255,255,255,.13);
  color: #f5f2df;
  font-size: 12px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18);
}
.player-badge { background: rgba(255, 230, 160, .16); }
.ecosystem-badge { background: rgba(107, 177, 124, .18); }
.player-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: 68px;
  gap: 6px;
  margin-top: 8px;
}

.player-card {
  min-width: 0;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 8px;
  background: rgba(255, 230, 160, .12);
  padding: 6px;
  display: grid;
  align-content: center;
  gap: 3px;
}

.player-card strong,
.player-card span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-card strong {
  color: #fff4cf;
  font-size: 12px;
}

.player-card span {
  color: #dbe8cf;
  font-size: 11px;
}

.current-player {
  border-color: rgba(255, 214, 90, .75);
  box-shadow: inset 0 0 0 1px rgba(255, 214, 90, .26), 0 0 14px rgba(255, 214, 90, .12);
}

.empty-player {
  opacity: .45;
  background: rgba(255,255,255,.06);
}
.board { min-height: 0; margin-top: 9px; overflow: hidden; }
.hand { margin-top: 9px; padding: 9px; border-radius: 8px; background: rgba(18, 30, 23, .42); border: 1px solid rgba(255,255,255,.1); }
.hand h2 { margin: 0 0 7px; font-size: 15px; color: #ffe6a0; }
.board-scroll {
  height: 100%;
  overflow: auto;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.13);
  background:
    linear-gradient(90deg, rgba(82, 48, 27, .26), rgba(47, 91, 61, .22)),
    rgba(16, 29, 22, .38);
  box-shadow: inset 0 0 22px rgba(0,0,0,.18);
}
.groups { display: grid; gap: 10px; }
.group {
  min-height: 82px;
  border: 1px dashed rgba(255, 230, 160, .46);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: rgba(255, 249, 219, .08);
}
.group:empty::after { content: "放置组合"; color: rgba(255, 244, 207, .46); font-size: 13px; align-self: center; }
.tiles { display: flex; flex-wrap: wrap; gap: 6px; min-height: 86px; max-height: 188px; overflow: auto; }
.tile {
  width: 62px;
  height: 84px;
  border-radius: 6px;
  border: 2px solid var(--tile-color);
  background:
    linear-gradient(135deg, rgba(255,255,255,.95), rgba(246, 240, 218, .96));
  color: #20302a;
  box-shadow: 0 2px 0 rgba(0,0,0,.22), 0 7px 14px rgba(0,0,0,.22);
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 6px;
  cursor: pointer;
  user-select: none;
  position: relative;
  overflow: hidden;
}
.tile::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 4px;
  border: 1px solid color-mix(in srgb, var(--tile-color), white 60%);
  pointer-events: none;
}
.tile.selected { outline: 3px solid #ffd65a; transform: translateY(-3px); }
.tile .eco { font-size: 10px; color: #4d6057; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; position: relative; }
.tile .name { align-self: center; text-align: center; font-weight: 800; line-height: 1.12; position: relative; }
.tile .num { font-size: 18px; font-weight: 900; text-align: right; color: var(--tile-color); position: relative; }
.tile.number-mode .name { font-size: 28px; }
.message { color: #ffd0c6; min-height: 20px; margin: 5px 0; font-size: 13px; }
@media (max-width: 720px) {
  .game { padding-inline: 8px; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 4px; }
  .topbar p { text-align: left; }
  .tile { width: 54px; height: 76px; }
  .home-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 44px; }
  .panel { padding: 28px 20px; }
  .panel h2 { font-size: 22px; }
  .panel input { font-size: 16px; }
  .panel button { font-size: 18px; }
}

.canvas-board {
  height: 560px;
  min-height: 0;
  margin-top: 9px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.13);
  background:
    linear-gradient(90deg, rgba(82, 48, 27, .26), rgba(47, 91, 61, .22)),
    rgba(16, 29, 22, .38);
  box-shadow: inset 0 0 22px rgba(0,0,0,.18);
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: none;
}

@media (max-width: 720px) {
  .canvas-board { height: 460px; }
}

.split-game {
  max-width: 1280px;
  padding: 12px;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: 1fr;
  gap: 12px;
}

.side-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 10px;
}

.side-section {
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
  background: rgba(20, 32, 25, .62);
  padding: 10px;
  min-width: 0;
}

.side-section h1,
.side-section h2,
.side-section p {
  margin: 0 0 7px;
}

.side-section h1 {
  font-size: 21px;
  color: #ffe6a0;
}

.side-section h2 {
  font-size: 15px;
  color: #ffe6a0;
}

.hand-panel {
  overflow: hidden;
}

.hand-tiles {
  height: 100%;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  align-content: start;
  gap: 6px;
}

.hand-tile {
  width: 100%;
  aspect-ratio: 1;
  padding: 5px;
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: center;
  border: 4px solid var(--tile-color);
  border-radius: 7px;
  background: #f8f1d8;
  color: #20302a;
  box-shadow: 0 2px 0 rgba(0,0,0,.22), 0 7px 14px rgba(0,0,0,.18);
}

.hand-tile span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
}

.hand-tile b {
  color: var(--tile-color);
  font-size: 13px;
  font-weight: 900;
}

.side-actions {
  position: static;
  transform: none;
  width: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  background: rgba(20, 32, 25, .72);
  box-shadow: none;
  padding: 10px;
}

.table-board {
  height: min(88vh, 840px);
  margin-top: 0;
}

.chain-board {
  height: min(88vh, 840px);
  margin-top: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.chain-header {
  padding: 6px 14px;
  border-radius: 8px;
  background: rgba(255, 230, 160, .12);
  border: 1px solid rgba(255, 214, 90, .28);
  color: #ffe6a0;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

#chainCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: none;
  border-radius: 8px;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 220, 150, .08), transparent 60%),
    radial-gradient(ellipse at 80% 80%, rgba(120, 200, 140, .10), transparent 60%),
    linear-gradient(135deg, rgba(30, 60, 42, .55), rgba(50, 35, 22, .55));
}

.score-line {
  margin: 4px 0;
  font-size: 14px;
  color: #ecf4df;
}

.score-line b {
  color: #ffd65a;
  font-size: 16px;
  margin-left: 4px;
}

.countdown-line b {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.countdown-line b.countdown-warn {
  color: #ff8844;
  animation: countdownPulse 1s infinite;
}

.countdown-line b.countdown-over {
  color: #d95a3f;
  font-size: 20px;
}

@keyframes countdownPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

.rule-list {
  margin: 6px 0 0 18px;
  padding: 0;
  color: #dbe8cf;
  font-size: 12.5px;
  line-height: 1.7;
}

.rule-list li b {
  color: #ffd65a;
}

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

.item-btn {
  font-size: 12px;
  padding: 8px 4px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 1px solid rgba(255, 214, 90, .3);
  border-radius: 7px;
  background: linear-gradient(180deg, rgba(255, 214, 90, .15), rgba(255, 214, 90, .06));
  color: #ffe6a0;
  cursor: pointer;
}

.item-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, rgba(255, 214, 90, .25), rgba(255, 214, 90, .12));
  border-color: rgba(255, 214, 90, .55);
}

.item-btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

.item-count {
  font-size: 14px;
  font-weight: 900;
  color: #ffd65a;
}

@media (max-width: 900px) {
  .split-game {
    height: auto;
    min-height: 100vh;
    overflow: auto;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .side-panel {
    grid-template-rows: auto auto 260px auto;
  }

  .table-board {
    height: 112vw;
    max-height: 840px;
  }

  .chain-board {
    height: 80vh;
    max-height: 760px;
  }
}
