:root {
  --ink: #3b2a21;
  --paper: #e7cfaa;
  --paper-soft: #f4e0bc;
  --accent: #945f36;
  --accent-dark: #5b321b;
  --accent-ok: #2d7c4d;
  --accent-bad: #8f2f2f;
  --panel: #f8e7c8;
  --line: #6d4b32;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 20%, #f0dab8 0%, #d8b886 50%, #b08554 100%);
  overflow: hidden;
}

.page {
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 6px;
}

.panel {
  width: min(560px, 100%);
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 8px 8px 0 #6f4f36;
}
.init-panel {
  max-height: calc(100vh - 20px);
}

.title {
  margin: 0 0 20px;
  text-align: center;
  font-size: clamp(36px, 6vw, 52px);
  line-height: 1;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #6d3f1e;
  text-shadow: 2px 2px 0 #f7ecd7;
}

.field {
  display: block;
  margin-bottom: 16px;
}

.label-text {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

input {
  width: 100%;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 12px;
  font-size: 18px;
  background: #f8ecd4;
  color: var(--ink);
  outline: none;
}

input:focus {
  border-color: var(--accent);
}

.hint {
  display: block;
  margin-top: 6px;
  min-height: 20px;
  font-weight: 700;
}

.hint.ok {
  color: var(--accent-ok);
}

.hint.bad {
  color: var(--accent-bad);
}

.start-btn {
  width: 100%;
  margin-top: 10px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 14px 12px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1px;
  cursor: pointer;
  color: #fff7eb;
  background: var(--accent);
  box-shadow: 0 5px 0 #4f3223;
}

.start-btn:active:enabled {
  transform: translateY(2px);
  box-shadow: 0 3px 0 #4f3223;
}

.start-btn:disabled {
  cursor: not-allowed;
  background: #9b8468;
  box-shadow: none;
  opacity: 0.75;
}

.hidden {
  display: none !important;
}

.game-shell {
  width: min(calc(100vw - 24px), 1680px);
  height: calc(100vh - 16px);
  border: 4px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 8px 8px 0 #6f4f36;
  display: grid;
  grid-template-columns: 20% 60% 20%;
  grid-template-rows: 50% 50%;
  gap: 8px;
  padding: 8px;
  position: relative;
}

.player-zone {
  border: 3px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  padding: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.top-left {
  grid-column: 1;
  grid-row: 1;
}
.top-right {
  grid-column: 3;
  grid-row: 1;
}
.bottom-left {
  grid-column: 1;
  grid-row: 2;
}
.bottom-right {
  grid-column: 3;
  grid-row: 2;
}

.center-zone {
  grid-column: 2;
  grid-row: 1 / span 2;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: #f1dbb6;
  padding: 8px 8px 10px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  overflow: hidden;
}

.status-panels {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: stretch;
  height: 108px;
  min-height: 108px;
}

.public-status-panel,
.public-log-panel {
  border: 3px solid var(--line);
  border-radius: 12px;
  background: #f9ebd1;
  padding: 4px 6px;
  display: grid;
  gap: 3px;
  min-height: 108px;
  height: 108px;
  overflow: hidden;
}

.status-item {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.status-long {
  overflow: hidden;
  text-overflow: ellipsis;
}

.public-log-panel {
  grid-template-rows: auto 1fr;
}

.log-header {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  line-height: 1.1;
}

.action-log-list {
  border: 2px solid #8a6647;
  border-radius: 8px;
  background: #fff3df;
  padding: 3px 5px;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: none;
  min-height: 0;
  height: 100%;
  font-size: 10px;
  font-weight: 700;
}

.log-body {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  overflow: hidden;
}

.action-log-list::-webkit-scrollbar {
  width: 8px;
}
.action-log-list::-webkit-scrollbar-thumb {
  background: #b0835a;
  border-radius: 999px;
}
.action-log-list::-webkit-scrollbar-track {
  background: #f3dec1;
}

.log-entry {
  margin: 2px 0;
  white-space: normal;
  word-break: break-word;
}

.log-nav {
  display: grid;
  grid-template-rows: repeat(4, auto);
  gap: 3px;
  align-items: center;
  justify-content: center;
  align-content: center;
  min-width: 38px;
}

.log-arrow-btn {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #7e6a56;
  color: #fff7eb;
  font-weight: 900;
  cursor: pointer;
}

.log-arrow-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.log-page-input {
  width: 36px;
  height: 22px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 2px 4px;
  background: #fff3df;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
}

.log-total-text {
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

.center-content {
  display: grid;
  grid-template-columns: 1fr 150px 140px;
  gap: 8px;
  min-height: 0;
}

.market-panel {
  border: 3px solid var(--line);
  border-radius: 12px;
  background: var(--paper-soft);
  padding: 8px;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
}

.nobles-panel {
  border: 3px solid var(--line);
  border-radius: 12px;
  background: var(--paper-soft);
  padding: 8px;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
}

.section-title {
  margin: 0;
  text-align: center;
  font-size: 15px;
}

.market-rows {
  display: grid;
  grid-template-rows: repeat(3, minmax(146px, 1fr));
  gap: 4px;
  min-height: 0;
}

.market-row,
.nobles-row {
  display: flex;
  gap: 6px;
  align-items: center;
  overflow: hidden;
}

.market-row {
  min-height: 146px;
}

.nobles-column {
  display: grid;
  grid-template-rows: repeat(5, 1fr);
  gap: 4px;
  overflow: hidden;
  justify-items: center;
  align-content: start;
  padding-bottom: 2px;
}

.deck-slot {
  width: 98px;
  height: 142px;
  border: 2px dashed #8b6645;
  border-radius: 8px;
  overflow: hidden;
  background: #e4cfad;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.deck-slot img,
.card-face img,
.noble-face img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #f7edd7;
}

.card-face,
.noble-face {
  width: 98px;
  height: 142px;
  border: 2px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  background: #f7edd7;
  flex: 0 0 auto;
}

.nobles-column .noble-face {
  width: 84px;
  height: 84px;
}

.noble-slot {
  width: 84px;
  height: 84px;
  border: 2px dashed #8b6645;
  border-radius: 8px;
  background: rgba(255, 246, 232, 0.45);
}

.card-face.disabled,
.noble-face.disabled {
  cursor: default;
  opacity: 0.7;
}

.card-new {
  animation: cardPop 240ms ease-out;
}

.card-ghost {
  animation: cardFly 280ms ease-out forwards;
}

@keyframes cardPop {
  from {
    transform: scale(0.92);
    opacity: 0.35;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes cardFly {
  to {
    transform: translateY(-6px) scale(0.82);
    opacity: 0;
  }
}

.bank-sidebar {
  border: 3px solid var(--line);
  border-radius: 12px;
  background: var(--paper-soft);
  padding: 6px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  gap: 8px;
}

.bank-chip-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  justify-content: flex-start;
  overflow: hidden auto;
}

.chip-button {
  width: 112px;
  min-height: 48px;
  border: 2px solid #7d7d7d;
  border-radius: 999px;
  background: #f3ebda;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
}

.chip-button img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 50%;
}

.chip-image-white,
.chip-image-green,
.chip-image-gold {
  transform: rotate(180deg);
}

.chip-image-blue,
.chip-image-red {
  transform: rotate(-40deg);
}

.chip-image-black {
  transform: rotate(180deg);
}

.chip-button.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px #c69d6f inset;
}

.chip-button.selected-twice {
  box-shadow: 0 0 0 2px #c69d6f inset, 0 0 0 4px #2f6fb4 inset;
}

.chip-button.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.bank-chip-divider {
  width: 90%;
  border-top: 2px dashed #876445;
  margin: 0;
}

.bank-gold-slot {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 2px;
}

.chip-count {
  font-weight: 800;
  font-size: 16px;
}

.chip-control-panel {
  border-top: 2px solid #8a6647;
  padding-top: 6px;
  display: grid;
  gap: 6px;
}

.chip-selection-preview {
  min-height: 18px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.chip-control-buttons {
  display: flex;
  gap: 5px;
}

.stylish-btn {
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #d6a676;
  color: #fff8ee;
  font-weight: 800;
  padding: 6px 8px;
  cursor: pointer;
  flex: 1;
  font-size: 12px;
}

.stylish-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.stylish-btn.ghost {
  background: #7e6a56;
}

.player-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.turn-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid var(--line);
  background: #fff3dc;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 900;
}

.player-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: #ebc491;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.player-id {
  font-weight: 800;
  font-size: 13px;
}

.mini-chip-row {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.mini-chip-row > div {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.mini-chip-row img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  border-radius: 50%;
  border: 1px solid #888;
}

.mini-chip {
  width: 30px;
  height: 20px;
  border-radius: 999px;
  border: 2px solid #8b8b8b;
  background: #ddd;
  position: relative;
}

.mini-chip-count {
  font-size: 11px;
  font-weight: 800;
}

.zone-subtitle {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
}

.player-card-tray {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-rows: 32% 68%;
  gap: 4px;
}

.tray-top {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.tray-half {
  border: 2px dashed #9a7758;
  border-radius: 8px;
  padding: 2px;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.tray-watermark {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 900;
  color: #8b6a4f;
  opacity: 0.62;
  z-index: 1;
  pointer-events: none;
  white-space: nowrap;
}

.tray-cards {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  gap: 4px;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
}

.purchased-zone {
  border: 2px dashed #9a7758;
  border-radius: 8px;
  padding: 2px;
  min-height: 0;
  overflow: hidden;
}

.purchased-grid {
  width: 100%;
  height: 100%;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  overflow: hidden auto;
}

.reserved-card,
.noble-card {
  width: 44px;
  height: 56px;
}

.purchased-card {
  width: 42px;
  height: 28px;
  flex: 0 0 auto;
}

.total-chip-line {
  position: relative;
}

.discard-inline-panel {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 126px;
  z-index: 12;
  border: 2px solid #a06e47;
  border-radius: 8px;
  padding: 4px;
  background: #fde3be;
  display: grid;
  gap: 4px;
  box-shadow: 0 3px 0 #6b4a33;
}

.discard-inline-panel .chip-control-buttons {
  flex-wrap: wrap;
}

.context-menu {
  position: absolute;
  z-index: 30;
  min-width: 116px;
  border: 3px solid var(--line);
  border-radius: 10px;
  background: #fbedd3;
  padding: 6px;
  display: grid;
  gap: 5px;
  box-shadow: 4px 4px 0 #5e4430;
}

.menu-btn {
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 5px 6px;
  background: #cf9a67;
  color: #fff8ef;
  font-weight: 800;
  cursor: pointer;
}

.menu-btn:disabled {
  background: #9f8f7f;
  cursor: not-allowed;
}

.game-over-panel {
  position: absolute;
  inset: 0;
  background: rgba(45, 26, 14, 0.45);
  display: grid;
  place-content: center;
  gap: 12px;
  text-align: center;
  z-index: 40;
}

.game-over-panel h2,
.game-over-panel p {
  margin: 0;
  color: #fff5e6;
}

.hover-info {
  position: absolute;
  z-index: 50;
  min-width: 130px;
  max-width: 180px;
  border: 3px solid var(--line);
  border-radius: 10px;
  background: #fff1d9;
  color: #4d321f;
  padding: 8px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.4;
  box-shadow: 4px 4px 0 #5e4430;
  pointer-events: none;
  white-space: pre-line;
}

@media (max-width: 1200px) {
  .game-shell {
    grid-template-columns: 22% 56% 22%;
  }
  .status-panels {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 980px) {
  .page {
    padding: 4px;
  }
  .game-shell {
    height: calc(100vh - 8px);
    gap: 4px;
    padding: 4px;
    border-radius: 12px;
  }
  .status-panels {
    grid-template-columns: 1fr;
  }
  .center-content {
    grid-template-columns: 1fr 120px 120px;
  }
  .deck-slot,
  .card-face,
  .noble-face {
    width: 78px;
    height: 110px;
  }
  .nobles-column .noble-face,
  .noble-slot {
    width: 72px;
    height: 72px;
  }
}

.chip-fallback-white {
  background: #f9f9f9;
}
.chip-fallback-blue {
  background: #3d6bc7;
}
.chip-fallback-green {
  background: #2f9b5a;
}
.chip-fallback-red {
  background: #bf3e3e;
}
.chip-fallback-black {
  background: #2f2f2f;
}
.chip-fallback-gold {
  background: #d8ba45;
}

