:root {
  --paper: #fffdf7;
  --panel: #fffdf7;
  --sand: #e8dcba;
  --ink: #302c23;
  --ink-soft: #756c58;
  --line: #ddd2b7;
  --red: #b23a30;
  --blue: #2f5285;
  --gold: #a97a2e;
  --green: #4f7c4a;
  --bw: 836px;
  --bh: 460px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  background-color: #e2dfd3;
  background-image:
    linear-gradient(rgba(90, 80, 55, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(90, 80, 55, .035) 1px, transparent 1px);
  background-size: 28px 28px;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, select { font-family: inherit; }
button { cursor: pointer; }

/* ---------- A4 横式纸张 ---------- */
.desk { min-height: 100vh; display: grid; place-items: center; padding: 18px; }
.sheet-wrap { width: 1220px; height: 863px; }
.sheet {
  width: 1220px; height: 863px;
  transform-origin: top left;
  display: flex; flex-direction: column;
  padding: 18px 30px 14px;
  background: var(--paper);
  background-image: linear-gradient(90deg, rgba(169, 122, 46, .04) 0 1px, transparent 1px 38px);
  border: 1px solid #d9cdb0;
  border-radius: 3px;
  box-shadow: 0 20px 55px rgba(60, 50, 30, .22), 0 2px 6px rgba(60, 50, 30, .1);
}
.sheet::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--blue) 0 42%, #c9b78d 42% 58%, var(--red) 58% 100%);
  opacity: .55;
}
.sheet { position: relative; }

.sheet-head { height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 6px;
  display: grid; place-items: center; font-size: 23px; color: #fbf3dd;
  background: linear-gradient(145deg, #4c5b3f, #2f3a29);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.2);
}
.brand-text h1 {
  margin: 0; font-size: 20px; letter-spacing: 3px; font-weight: 700;
  font-family: "Songti SC", "Noto Serif CJK SC", "SimSun", serif;
}
.brand-text h1 em { color: var(--gold); font-style: normal; }
.brand-text p { margin: 2px 0 0; font-size: 10.5px; color: var(--ink-soft); letter-spacing: 2px; }
.head-center { text-align: center; display: flex; flex-direction: column; gap: 3px; }
.doc-label { font-size: 12px; letter-spacing: 5px; color: #8a774e; font-family: "Songti SC", "SimSun", serif; }
.doc-sub { font-size: 10px; letter-spacing: 2px; color: #a99c7f; }
.top-actions { display: flex; gap: 7px; }
.ghost {
  border: 1px solid var(--line); background: #fffdf7; color: var(--ink);
  padding: 7px 12px; border-radius: 5px; font-size: 12px; transition: .15s;
}
.ghost:hover { border-color: var(--gold); color: var(--gold); }
.head-rule { height: 5px; border-top: 1.5px solid var(--gold); border-bottom: 1px solid var(--line); margin: 2px 0 13px; }

.sheet-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 292px; gap: 20px; min-height: 0; }

/* ---------- 左侧：地图 ---------- */
.map-area { display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.map-head { height: 32px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.strip { display: flex; align-items: center; gap: 7px; font-size: 11.5px; white-space: nowrap; }
.strip.blue b { color: var(--blue); }
.strip.red b { color: var(--red); }
.strip b { letter-spacing: .5px; }
.strip-info { color: var(--ink-soft); font-size: 10.5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.blue { background: var(--blue); }
.dot.red { background: var(--red); }
.map-title { font-size: 12px; letter-spacing: 3px; color: #6c5327; font-family: "Songti SC", "SimSun", serif; white-space: nowrap; }
.map-title small { font-size: 10px; letter-spacing: 1px; color: #a99c7f; font-family: inherit; margin-left: 6px; }

.board-viewport {
  flex: 1; min-height: 0;
  display: flex; justify-content: center; align-items: center;
  padding: 8px 0 10px; overflow-x: auto; overflow-y: hidden;
}
.board-frame {
  position: relative; flex: none; width: var(--bw); height: var(--bh);
  border-radius: 4px; border: 1px solid #c9b78d;
  box-shadow: 0 4px 14px rgba(70, 58, 32, .16), inset 0 0 0 3px rgba(255,255,255,.35);
  overflow: hidden;
}
.board {
  position: absolute; top: 0; left: 0; width: var(--bw); height: var(--bh);
  background:
    radial-gradient(ellipse at 50% 50%, rgba(255,255,255,.28), transparent 72%),
    repeating-linear-gradient(0deg, rgba(140,120,75,.028) 0 2px, transparent 2px 4px),
    var(--sand);
  user-select: none;
}
#lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cells, .pieces, .markers { position: absolute; inset: 0; }
.cells { z-index: 2; }
.pieces, .markers { pointer-events: none; }
.pieces { z-index: 3; }
.markers { z-index: 4; }
.cell {
  position: absolute; width: 54px; height: 54px; border-radius: 50%;
  cursor: pointer; background: transparent; transition: background .12s;
}
.cell:hover { background: rgba(169, 122, 46, .13); }
.cell.is-target { background: rgba(79, 124, 74, .18); }
.cell.is-attack { background: rgba(178, 58, 48, .17); }

.mk-move {
  position: absolute; width: 13px; height: 13px; border-radius: 50%;
  background: rgba(63, 112, 61, .78); border: 2px solid rgba(255,255,255,.85);
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.mk-attack {
  position: absolute; width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid rgba(178, 58, 48, .85); background: rgba(178,58,48,.1);
  box-shadow: 0 0 0 2px rgba(255,255,255,.6) inset;
}
.mk-hint {
  position: absolute; width: 46px; height: 46px; border-radius: 50%;
  border: 3px dashed var(--gold); background: rgba(169,122,46,.12);
  animation: pulse 1.1s infinite alternate;
}
@keyframes pulse { from { opacity: .5; } to { opacity: 1; } }

.piece {
  position: absolute; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; text-align: center;
  font-weight: 700; font-size: 13.5px; letter-spacing: 1px;
  border: 2px solid rgba(255,255,255,.55);
  box-shadow: 0 3px 6px rgba(50, 40, 20, .32), inset 0 1px 2px rgba(255,255,255,.35);
  transition: left .22s ease, top .22s ease, transform .16s ease, opacity .16s ease, box-shadow .16s;
  animation: pop .22s ease-out;
}
@keyframes pop { from { transform: scale(.55); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.piece.red { background: radial-gradient(circle at 32% 28%, #cf5a4a, #8f251e 78%); color: #fff4e6; }
.piece.blue { background: radial-gradient(circle at 32% 28%, #5379ae, #223a63 78%); color: #eaf2ff; }
.piece.back {
  background: repeating-linear-gradient(45deg, #46536a 0 7px, #37425a 7px 14px);
  color: #e2e9f6; border-color: #72809a; font-size: 17px; letter-spacing: 0;
}
.piece.back .txt { text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.piece.flag { box-shadow: 0 0 0 2px var(--gold), 0 3px 6px rgba(50,40,20,.35); }
.piece.known::before {
  content: ''; position: absolute; top: 1px; right: 2px;
  width: 8px; height: 8px; border-radius: 50%;
  background: #f0c04a; border: 1px solid #fff;
}
.piece.selected { transform: translateY(-4px) scale(1.09); box-shadow: 0 0 0 3px #e6b04a, 0 6px 12px rgba(50,40,20,.35); }
.piece .txt { line-height: 1; }

.rank-strip {
  display: flex; align-items: center; gap: 12px; min-height: 44px;
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 5px;
  background: #faf6ea;
}
.rank-title { font-size: 10.5px; letter-spacing: 2px; color: #8a774e; flex: none; border-right: 1px solid var(--line); padding-right: 12px; }
.rank-list { display: flex; align-items: center; gap: 5px; flex-wrap: nowrap; font-size: 11px; white-space: nowrap; }
.rank-list span { background: #fff; border: 1px solid #e2d6b9; border-radius: 3px; padding: 3px 6px; }
.rank-list span i { font-style: normal; color: #a99c7f; font-size: 9px; margin-left: 3px; }
.rank-list em { color: #b6a680; font-style: normal; }
.rank-list .rank-extra { margin-left: 8px; padding: 3px 8px; border-radius: 3px; background: #efe3c5; color: #6c5327; font-size: 10.5px; font-weight: 600; }

.map-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 26px; }
.legend { display: flex; align-items: center; gap: 12px; font-size: 10.5px; color: var(--ink-soft); white-space: nowrap; }
.legend span { display: flex; align-items: center; gap: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.lg-move { background: #4f7c4a; }
.lg-attack { border: 2px solid var(--red); background: rgba(178,58,48,.15); }
.lg-back { background: #46536a; }
.lg-camp { border-radius: 2px !important; background: linear-gradient(90deg, #9a8556 0 33%, #eee0bb 33% 66%, #6b5836 66%); }
.swipe-tip { display: none; color: var(--red); font-weight: 700; }
.board-foot { font-size: 11px; color: #6c5327; text-align: right; flex: 1; }

/* ---------- 右侧：控制台 ---------- */
.side { display: flex; flex-direction: column; gap: 9px; min-height: 0; }
.side::-webkit-scrollbar, .log::-webkit-scrollbar { width: 6px; }
.side::-webkit-scrollbar-thumb, .log::-webkit-scrollbar-thumb { background: #d8ccae; border-radius: 3px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 10px 12px; box-shadow: 0 1px 3px rgba(90,75,45,.04);
}
.panel h2 {
  margin: 0 0 8px; font-size: 12px; letter-spacing: 1.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: flex-start;
}
.panel h2::before { content: ''; width: 3px; height: 12px; background: var(--gold); margin-right: 7px; border-radius: 2px; }
.panel h2 .mini { margin-left: auto; }
.mini { border: none; background: none; color: var(--ink-soft); font-size: 10.5px; padding: 2px 4px; }
.mini:hover { color: var(--gold); }
.panel h3 { margin: 0 0 6px; font-size: 10.5px; color: var(--ink-soft); font-weight: 600; letter-spacing: .5px; }
.hint { margin: 8px 0 0; font-size: 10.5px; line-height: 1.65; color: var(--ink-soft); }

.phase-line { display: flex; align-items: center; gap: 9px; }
.phase-tag { background: var(--gold); color: #fff; border-radius: 4px; font-size: 10.5px; padding: 3px 8px; letter-spacing: 2px; font-weight: 700; }
.phase-tag.play { background: var(--green); }
.phase-tag.over { background: #6c6555; }
.turn-text { font-size: 12.5px; font-weight: 700; }
.phase-desc { margin-top: 6px; font-size: 10.5px; color: var(--ink-soft); line-height: 1.6; }

.btn-row { display: flex; gap: 6px; }
.btn-row button, .style-btn {
  flex: 1; padding: 7px 5px; border-radius: 5px; font-size: 11.5px;
  border: 1px solid var(--line); background: #fffdf7; color: var(--ink); transition: .14s;
}
.btn-row button:hover, .style-btn:hover { border-color: var(--gold); color: var(--gold); }
.style-btn.active { background: #f0e3c3; border-color: var(--gold); color: #6c4c13; font-weight: 700; }
.primary {
  width: 100%; margin-top: 9px; padding: 9px; border: none; border-radius: 5px;
  background: linear-gradient(135deg, #4d6440, #33452c); color: #f8f3df;
  font-size: 13px; font-weight: 700; letter-spacing: 6px; transition: .15s;
  box-shadow: 0 2px 6px rgba(50,70,40,.2);
}
.primary:hover { filter: brightness(1.12); }
.level-label { display: flex; align-items: center; justify-content: space-between; font-size: 11.5px; color: var(--ink-soft); }
.level-label select { border: 1px solid var(--line); border-radius: 5px; padding: 5px 7px; background: #fffdf7; color: var(--ink); font-size: 11.5px; outline: none; }

.log-panel { flex: 1; display: flex; flex-direction: column; min-height: 120px; }
.log { flex: 1; min-height: 0; overflow-y: auto; font-size: 11px; line-height: 1.6; }
.log-line { padding: 4px 6px; border-bottom: 1px dashed #eee6d2; display: flex; gap: 6px; }
.log-line:last-child { border-bottom: none; }
.log-no { color: #b0a488; flex: 0 0 20px; font-variant-numeric: tabular-nums; }
.log-line.red { color: #8d3229; }
.log-line.blue { color: #2b4b7c; }
.log-line.big { background: #f7efd8; font-weight: 700; border-radius: 4px; }
.log-line.info { color: var(--ink-soft); }
.log-empty { color: #aa9f87; padding: 10px 5px; text-align: center; }

.intel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 3px; align-content: flex-start; min-height: 20px; max-height: 62px; overflow-y: auto; }
.chip { font-size: 10px; padding: 2px 5px; border-radius: 3px; background: #eee6d0; color: #5d5340; white-space: nowrap; }
.chip.blue { background: #dde6f5; color: #2b4b7c; }
.chip.red { background: #f6dedb; color: #8d3229; }
.muted { color: #aa9f87; font-size: 10.5px; }

.sheet-foot {
  height: 34px; margin-top: 10px; border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10px; color: #9b8f74; letter-spacing: 1px;
}

/* ---------- 弹窗 ---------- */
.modal-layer {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(38, 33, 22, .48); backdrop-filter: blur(3px); padding: 20px;
}
.modal-layer[hidden] { display: none; }
.modal-card {
  position: relative; width: min(600px, 100%); max-height: 86vh; overflow-y: auto;
  background: var(--panel); border: 1px solid #e0d3b3; border-radius: 10px;
  padding: 24px 30px 26px; box-shadow: 0 20px 60px rgba(30,25,12,.35);
  animation: rise .2s ease-out;
}
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-close { position: absolute; top: 10px; right: 14px; border: none; background: none; font-size: 24px; line-height: 1; color: #9b8f74; }
.modal-close:hover { color: var(--red); }
.modal-card h2 { margin: 0 0 12px; font-size: 20px; letter-spacing: 3px; font-family: "Songti SC", "Noto Serif CJK SC", "SimSun", serif; }
.modal-card h3 { margin: 16px 0 6px; font-size: 12.5px; color: #6c5327; letter-spacing: 1px; }
.modal-card p, .modal-card li { font-size: 12px; line-height: 1.8; color: #4d4637; }
.modal-card ul { padding-left: 20px; margin: 5px 0; }
.modal-card table { width: 100%; border-collapse: collapse; font-size: 11.5px; margin-top: 7px; }
.modal-card th, .modal-card td { border: 1px solid var(--line); padding: 5px 7px; text-align: left; }
.modal-card th { background: #f4ecd7; font-weight: 600; }
.result-banner { text-align: center; padding: 6px 0 16px; font-size: 26px; font-weight: 700; letter-spacing: 6px; font-family: "Songti SC", "Noto Serif CJK SC", serif; }
.result-banner.win { color: var(--red); }
.result-banner.lose { color: var(--blue); }
.result-banner.draw { color: #6c6555; }
.result-stats { display: flex; justify-content: center; gap: 28px; margin: 4px 0 18px; font-size: 11.5px; color: var(--ink-soft); }
.result-stats b { display: block; font-size: 18px; color: var(--ink); text-align: center; }

/* ---------- 窄屏：退回文档流，棋盘可横向滑动 ---------- */
@media (max-width: 900px) {
  .desk { display: block; padding: 10px; }
  .sheet-wrap { width: 100% !important; height: auto !important; }
  .sheet { width: 100%; height: auto; transform: none !important; padding: 12px 14px 10px; }
  .sheet-head { height: auto; flex-wrap: wrap; gap: 8px; }
  .head-center { display: none; }
  .brand-text p { display: none; }
  .ghost { padding: 6px 9px; font-size: 11px; }
  .sheet-body { grid-template-columns: 1fr; gap: 14px; }
  .map-head { height: auto; flex-wrap: wrap; }
  .map-title { order: -1; width: 100%; }
  .board-viewport { flex: none; justify-content: flex-start; padding: 6px 0; }
  .board-frame { margin: 0; }
  .rank-strip { overflow-x: auto; }
  .map-foot { flex-direction: column; align-items: flex-start; gap: 6px; }
  .board-foot { text-align: left; }
  .legend { flex-wrap: wrap; white-space: normal; }
  .swipe-tip { display: inline-flex; }
  .side { max-height: none; }
  .log-panel { min-height: 180px; }
  .log { max-height: 220px; }
  .sheet-foot { height: auto; flex-wrap: wrap; gap: 5px; padding-top: 8px; }
}
