* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --paper: #f5efe0;
  --ink: #2b2620;
  --ink-soft: #6b6154;
  --line: #c9bda4;
  --red: #b5322a;
  --red-dark: #8c241e;
  --gold: #c8971f;
  --green: #4a6b4a;
  --blue: #3a5a7a;
  --panel: #fbf7ec;
}
body {
  font-family: "Noto Serif SC", "Songti SC", "SimSun", serif;
  background: #ece4d2;
  color: var(--ink);
  min-height: 100vh;
  padding: 12px;
}
#app { max-width: 1320px; margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px 12px; border-bottom: 2px solid var(--line); margin-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 10px; }
.seal { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; background: var(--red); color: #fff; font-size: 18px; border-radius: 4px; transform: rotate(-4deg); }
.brand h1 { font-size: 24px; letter-spacing: 4px; }
.brand .sub { color: var(--ink-soft); font-size: 13px; letter-spacing: 1px; margin-left: 6px; }
.top-actions button { margin-left: 8px; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 4px; padding: 6px 14px; color: var(--ink); cursor: pointer; font-family: inherit; }
.ghost:hover { background: var(--paper); }

.legend { display: flex; flex-wrap: wrap; gap: 18px; font-size: 12px; color: var(--ink-soft); padding: 6px 14px 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 14px; height: 14px; border-radius: 3px; flex: none; }
.lg-own { background: #e0e9f2; border-left: 4px solid #3a5a7a; }
.lg-token { background: #b5322a; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #b5322a; }
.lg-active { background: #c8971f; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 2px var(--gold); }
.lg-tap { background: transparent; border: 1.5px dashed var(--gold); }
.legend-tap { display: none; }

.layout { display: grid; grid-template-columns: minmax(560px, 1fr) 320px; gap: 18px; align-items: start; }
.board-wrap { position: relative; width: 100%; max-width: 780px; aspect-ratio: 1; margin: 0 auto; background: var(--paper); border: 2px solid var(--line); box-shadow: inset 0 0 40px rgba(120,100,60,.12); }
.board { position: absolute; inset: 0; display: grid; }
.board-center { position: absolute; left: 26%; top: 26%; width: 48%; height: 48%; background: #efe6d0; border: 2px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; z-index: 5; }
.dynasty-title { font-size: 18px; letter-spacing: 6px; color: var(--red-dark); border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.dice { display: flex; flex-direction: column; gap: 4px; width: 48px; height: 48px; background: #fff; border: 2px solid var(--ink); border-radius: 8px; padding: 5px; justify-content: space-between; }
.pip-row { display: flex; justify-content: space-between; }
.pip-row i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink); opacity: 0; }
.pip-row i.center { margin: 0 auto; }
.dice.show-1 .pip-row:nth-child(2) i.center { opacity: 1; }
.dice.show-2 .pip-row:nth-child(1) i:last-child, .dice.show-2 .pip-row:nth-child(3) i:first-child { opacity: 1; }
.dice.show-3 .pip-row:nth-child(1) i:last-child, .dice.show-3 .pip-row:nth-child(2) i.center, .dice.show-3 .pip-row:nth-child(3) i:first-child { opacity: 1; }
.dice.show-4 .pip-row:nth-child(1) i, .dice.show-4 .pip-row:nth-child(3) i { opacity: 1; }
.dice.show-5 .pip-row:nth-child(1) i, .dice.show-5 .pip-row:nth-child(2) i.center, .dice.show-5 .pip-row:nth-child(3) i { opacity: 1; }
.dice.show-6 .pip-row i { opacity: 1; }
.roll-btn { background: var(--red); color: #fff; border: none; border-radius: 4px; padding: 9px 26px; font-size: 16px; letter-spacing: 3px; cursor: pointer; font-family: inherit; }
.roll-btn:disabled { background: #aaa; cursor: not-allowed; }
.round-info, .turn-info { font-size: 13px; color: var(--ink-soft); }

/* 格子：领地归属用底色 + 左侧色条表达，与棋子完全区分 */
.cell {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 4px 4px 20px;
  position: relative;
  overflow: hidden;
  transition: background .2s;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.cell.owned { border-left: 4px solid var(--owner-color); padding-left: 6px; }
.cell .zone-bar { position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.cell .cell-name { font-weight: 600; font-size: 12px; line-height: 1.2; padding-left: 2px; }
.cell .cell-meta { font-size: 10px; color: var(--ink-soft); padding-left: 2px; }
.cell .cell-meta.rent { color: var(--red-dark); font-weight: 600; }
.cell .owner-tag {
  position: absolute; right: 2px; top: 4px;
  width: 15px; height: 15px; border-radius: 3px;
  color: #fff; font-size: 10px; line-height: 15px; text-align: center;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.cell .heroes { font-size: 10px; color: var(--green); padding-left: 2px; white-space: nowrap; overflow: hidden; }
.cell.start { background: #e8dcc2; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.cell.event { background: #eee6f0; }
.cell.chance { background: #eef0d8; }
/* 当前行动位置：外圈金色描边，独立于归属底色 */
.cell.active-pos { outline: 3px solid var(--gold); outline-offset: -3px; z-index: 4; }
.cell.active-pos::before {
  content: '当前'; position: absolute; top: 2px; left: 50%; transform: translateX(-50%);
  font-size: 8px; color: #fff; background: var(--gold); padding: 0 4px; border-radius: 2px; z-index: 6;
}

/* 棋子：带名字首字，当前行动者金色呼吸光晕 */
.token {
  position: absolute;
  width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35);
  color: #fff; font-size: 10px; line-height: 13px; text-align: center;
  z-index: 5;
}
.token-active {
  box-shadow: 0 0 0 2px var(--gold), 0 0 8px var(--gold);
  animation: pulse 1.3s ease-in-out infinite;
  z-index: 7;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--gold), 0 0 5px var(--gold); }
  50% { box-shadow: 0 0 0 3px var(--gold), 0 0 12px var(--gold); }
}

.side { display: flex; flex-direction: column; gap: 14px; }
.panel { background: var(--panel); border: 2px solid var(--line); padding: 12px; }
.panel h2 { font-size: 15px; letter-spacing: 3px; color: var(--red-dark); border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 10px; }
.player-card { padding: 8px; border: 1px solid var(--line); margin-bottom: 8px; border-left: 5px solid var(--pcolor); background: #fff; }
.player-card.active { box-shadow: 0 0 0 2px var(--gold); }
.player-card .pname { font-weight: 600; margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; }
.player-card .pstats { font-size: 12px; color: var(--ink-soft); display: flex; gap: 10px; flex-wrap: wrap; }
.player-card.bankrupt { opacity: .45; filter: grayscale(1); }
.hero-tags { margin-top: 5px; font-size: 11px; color: var(--green); }
.chip { display: inline-block; width: 17px; height: 17px; line-height: 17px; border-radius: 50%; color: #fff; font-size: 10px; text-align: center; margin-right: 5px; vertical-align: 1px; }
.log { font-size: 12px; line-height: 1.7; max-height: 280px; overflow-y: auto; }
.log div { padding: 3px 0; border-bottom: 1px dashed var(--line); }
.log .hi { color: var(--red); }

.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  background: var(--red-dark); color: #fff; padding: 9px 22px; border-radius: 4px;
  font-size: 14px; z-index: 60; box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.toast.hidden { display: none; }

.modal { position: fixed; inset: 0; background: rgba(40,30,20,.5); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-card { background: var(--panel); border: 3px double var(--gold); padding: 22px; width: min(460px, 92vw); max-height: 84vh; overflow-y: auto; }
.modal-card h2 { font-size: 19px; color: var(--red-dark); margin-bottom: 12px; letter-spacing: 2px; }
.modal-card p { line-height: 1.8; margin-bottom: 10px; font-size: 14px; }
.modal-card ul { padding-left: 20px; line-height: 1.9; font-size: 13px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; justify-content: flex-end; }
.modal-actions button { background: var(--red); color: #fff; border: none; padding: 8px 18px; border-radius: 4px; cursor: pointer; font-family: inherit; font-size: 14px; }
.modal-actions button.alt { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.modal-actions button:disabled { opacity: .4; cursor: not-allowed; }
.hero-option { border: 1px solid var(--line); padding: 10px; margin: 8px 0; background: #fff; cursor: pointer; }
.hero-option:hover { border-color: var(--gold); background: #fffdf5; }
.hero-option h4 { font-size: 14px; margin-bottom: 4px; }
.hero-option .desc { font-size: 12px; color: var(--ink-soft); }
.badge { display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 3px; color: #fff; margin-left: 6px; }
.badge.wen { background: var(--blue); }
.badge.wu { background: var(--red); }

/* ============ 平板与桌面窄屏 ============ */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .board-wrap { max-width: min(94vw, 700px); }
  .side { display: grid; grid-template-columns: 1fr 1fr; }
}

/* ============ 手机竖屏：信息分层 + 触控优化 ============ */
@media (max-width: 600px) {
  body { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .topbar { padding: 6px 4px 10px; }
  .brand { gap: 7px; }
  .seal { width: 28px; height: 28px; font-size: 15px; }
  .brand h1 { font-size: 19px; letter-spacing: 2px; }
  .brand .sub { display: none; }
  .top-actions button { margin-left: 5px; padding: 8px 12px; min-height: 40px; }
  .legend { gap: 8px 12px; font-size: 11px; padding: 4px 2px 8px; line-height: 1.5; }
  .legend span:not(.legend-tap) { display: none; }
  .legend-tap { display: inline-flex; }

  .layout { grid-template-columns: 1fr; gap: 12px; }
  .board-wrap { max-width: 100%; border-width: 1px; }
  .board-center { left: 30%; top: 30%; width: 40%; height: 40%; gap: 4px; padding: 4px; border-width: 1px; }
  .dynasty-title { font-size: 12px; letter-spacing: 2px; padding-bottom: 2px; }
  .dice { width: 32px; height: 32px; border-width: 1px; padding: 3px; border-radius: 5px; }
  .pip-row i { width: 5px; height: 5px; }
  .roll-btn { padding: 8px 14px; font-size: 14px; letter-spacing: 2px; min-height: 44px; }
  .round-info, .turn-info { font-size: 11px; line-height: 1.3; }

  /* 手机上格子精简：地名 + 归属 + 棋子，详情点开看 */
  .cell { padding: 2px 1px 15px; }
  .cell.owned { padding-left: 4px; border-left-width: 3px; }
  .cell .cell-name { font-size: 10px; line-height: 1.15; word-break: break-all; }
  .cell .cell-meta, .cell .heroes { display: none; }
  .cell .owner-tag { width: 12px; height: 12px; font-size: 8px; line-height: 12px; right: 1px; top: 2px; }
  .token { width: 14px; height: 14px; font-size: 9px; line-height: 10px; border-width: 1.5px; }
  .cell.active-pos::before { font-size: 7px; padding: 0 2px; }

  .side { grid-template-columns: 1fr; gap: 10px; }
  .panel { padding: 10px; border-width: 1px; }
  .panel h2 { font-size: 14px; }
  .player-card { padding: 7px; }
  .log { max-height: 200px; }

  .toast { top: 12px; padding: 8px 16px; font-size: 13px; max-width: 90vw; }
  .modal-card { padding: 16px; width: 94vw; max-height: 88vh; }
  .modal-card h2 { font-size: 17px; }
  .modal-card p { font-size: 13px; line-height: 1.7; }
  .modal-card ul { font-size: 12px; }
  .modal-actions { justify-content: stretch; }
  .modal-actions button { flex: 1; min-height: 44px; }
  .hero-option { padding: 12px; min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .token-active { animation: none; }
}
