:root {
  --paper: #f3ead6;
  --paper-2: #e9dcc0;
  --ink: #2f2a22;
  --ink-soft: #6b604f;
  --line: #b9a888;
  --human: #2f5fa8;
  --human-bg: #dbe6f7;
  --orc: #a83a26;
  --orc-bg: #f6ddd3;
  --move: rgba(47, 95, 168, .28);
  --charge: rgba(222, 140, 20, .45);
  --attack: rgba(200, 40, 30, .38);
  --heal: rgba(40, 150, 70, .38);
  --curse: rgba(120, 50, 160, .38);
  --spawn: rgba(60, 140, 60, .3);
  --cell: 40px;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #d8cbb0; color: var(--ink); }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); padding: 6px 12px; }
button:hover:not(:disabled) { background: #fff8e8; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button.primary:hover:not(:disabled) { background: #4a4236; }
button.ghost { background: transparent; }
button.on { outline: 2px solid var(--ink); }
kbd { font-size: 11px; opacity: .7; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-left: 4px; }
.muted { color: var(--ink-soft); font-size: 13px; font-weight: normal; }
.hidden { display: none !important; }

#app { display: flex; flex-direction: column; height: 100vh; }
.top { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--paper); border-bottom: 1px solid var(--line); }
.title { font-weight: 700; font-size: 18px; letter-spacing: 2px; }
.title small { font-weight: normal; font-size: 11px; color: var(--ink-soft); letter-spacing: 0; }
.turn-info { flex: 1; text-align: center; font-size: 15px; }
.turn-info .who { font-weight: 700; padding: 2px 10px; border-radius: 99px; color: #fff; }
.turn-info .who.p1 { background: var(--human); }
.turn-info .who.p2 { background: var(--orc); }
.top-actions { display: flex; gap: 8px; }

.layout { flex: 1; display: flex; min-height: 0; }
.board-wrap { flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto; padding: 12px; }
.panel { width: 320px; flex-shrink: 0; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--paper-2); border-left: 1px solid var(--line); }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.card h3 { margin: 0 0 8px; font-size: 14px; }
.end { padding: 10px; font-size: 15px; }

/* ===== 棋盘 ===== */
.board {
  display: grid; position: relative;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  border: 2px solid var(--ink); background: var(--paper);
  box-shadow: 0 6px 24px rgba(60, 40, 10, .25);
  user-select: none;
}
.cell { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); position: relative; background-size: 100% 100%; }
.cell.t-F { background-color: #cfdcb0; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cg fill='%235d7d3a' opacity='.75'%3E%3Cpath d='M11 6l6 11h-12z'/%3E%3Cpath d='M28 15l6 11h-12z'/%3E%3Cpath d='M14 22l6 11h-12z'/%3E%3C/g%3E%3Cg stroke='%235d7d3a' stroke-width='1.6'%3E%3Cpath d='M11 17v3M28 26v3M14 33v3'/%3E%3C/g%3E%3C/svg%3E"); }
.cell.t-M { background-color: #d6cbb7; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M3 33L15 11l7 12 4-6 11 16z' fill='%23988a72' stroke='%235e5240' stroke-width='1.2'/%3E%3Cpath d='M15 11l-3 6 3-1 2 2z' fill='%23f3ead6'/%3E%3C/svg%3E"); }
.cell.t-W { background-color: #a9c7d8; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cg fill='none' stroke='%23567f99' stroke-width='1.5' opacity='.8'%3E%3Cpath d='M4 13q4-4 8 0t8 0 8 0 8 0'/%3E%3Cpath d='M4 27q4-4 8 0t8 0 8 0 8 0'/%3E%3C/g%3E%3C/svg%3E"); }
.cell.spawn-p1 { box-shadow: inset 0 0 0 2px rgba(47, 95, 168, .35); }
.cell.spawn-p2 { box-shadow: inset 0 0 0 2px rgba(168, 58, 38, .35); }
.cell::after { content: ''; position: absolute; inset: 0; pointer-events: none; }
.cell.hl-move::after { background: var(--move); }
.cell.hl-charge::after { background: var(--charge); }
.cell.hl-path::after { background: rgba(222, 140, 20, .18); }
.cell.hl-attack::after { background: var(--attack); }
.cell.hl-heal::after { background: var(--heal); }
.cell.hl-curse::after { background: var(--curse); }
.cell.hl-spawn::after { background: var(--spawn); }
.cell.hl-skill { cursor: crosshair; }
.cell.hl-area::after { background: rgba(200, 40, 30, .32); }
.cell.hl-move, .cell.hl-charge, .cell.hl-attack, .cell.hl-heal, .cell.hl-pull, .cell.hl-curse, .cell.hl-spawn { cursor: pointer; }
.cell.hover::before { content: ''; position: absolute; inset: 0; border: 2px solid var(--ink); z-index: 3; pointer-events: none; }

.base {
  pointer-events: none; z-index: 2; margin: 3px; border-radius: 8px; border: 3px double;
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700;
}
.base.p1 { border-color: var(--human); background: var(--human-bg); color: var(--human); }
.base.p2 { border-color: var(--orc); background: var(--orc-bg); color: var(--orc); }
.base .bname { font-size: calc(var(--cell) * .34); }
.base .bhp { font-size: calc(var(--cell) * .28); }

.unit {
  pointer-events: none; z-index: 2; margin: calc(var(--cell) * .08); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; position: relative;
  font-weight: 700; font-size: calc(var(--cell) * .42); border: 2px solid; transition: transform .12s;
}
.unit.p1 { background: var(--human-bg); color: var(--human); border-color: var(--human); }
.unit.p2 { background: var(--orc-bg); color: var(--orc); border-color: var(--orc); }
.unit.done { opacity: .55; }
.unit.sel { transform: scale(1.12); box-shadow: 0 0 0 3px #f2b233; }
.unit.cursed { box-shadow: 0 0 0 2px #7a3aa0; }
.unit .hpn { position: absolute; bottom: -6px; right: -6px; min-width: calc(var(--cell) * .4); height: calc(var(--cell) * .4); border-radius: 99px; display: flex; align-items: center; justify-content: center; font-size: calc(var(--cell) * .26); border: 1.5px solid var(--paper); padding: 0 2px; color: #fff; }
.unit.p1 .hpn { background: var(--human); }
.unit.p2 .hpn { background: var(--orc); }
.unit .hpn.low { background: #e0681c; }
.unit .tag.rage { left: auto; right: -7px; top: -7px; background: #b2471a; }
.cell.hl-pull::after { background: rgba(40, 150, 70, .3); outline: 2px dashed rgba(40, 120, 60, .8); outline-offset: -4px; }
.unit .hp { position: absolute; bottom: -5px; left: 50%; transform: translateX(-50%); display: flex; gap: 1px; }
.unit .hp i { width: calc(var(--cell) * .13); height: calc(var(--cell) * .13); border-radius: 50%; background: currentColor; border: 1px solid var(--paper); }
.unit .hp i.lost { background: var(--paper); border-color: currentColor; }
.unit .rider { position: absolute; top: -6px; right: -8px; width: calc(var(--cell) * .42); height: calc(var(--cell) * .42); border-radius: 50%; font-size: calc(var(--cell) * .24); display: flex; align-items: center; justify-content: center; border: 1.5px solid; background: inherit; }
.unit .rider.sel { box-shadow: 0 0 0 2px #f2b233; }
.unit .tag { position: absolute; top: -7px; left: -7px; font-size: 10px; background: #7a3aa0; color: #fff; border-radius: 6px; padding: 0 3px; }

.float { position: absolute; z-index: 5; pointer-events: none; font-weight: 800; font-size: 18px; text-shadow: 0 0 3px #fff, 0 0 3px #fff; animation: rise 1.1s ease-out forwards; display: flex; justify-content: center; }
.float.dmg { color: #c0241a; }
.float.heal { color: #1f8a3e; }
.float.curse { color: #7a3aa0; font-size: 14px; }
.float.skill { color: #8a5a14; font-size: 14px; }
@keyframes rise { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(-26px); opacity: 0; } }

/* ===== 面板 ===== */
.bases { display: flex; gap: 8px; }
.base-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; font-size: 14px; }
.base-row .dot { width: 10px; height: 10px; border-radius: 50%; }
.bar { flex: 1; height: 8px; border-radius: 4px; background: #ddd0b4; overflow: hidden; }
.bar > div { height: 100%; }
.shop { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.shop button { text-align: left; padding: 6px 8px; display: flex; gap: 8px; align-items: center; }
.shop .ico { width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; border: 2px solid; flex-shrink: 0; }
.shop .meta { font-size: 12px; color: var(--ink-soft); }
.shop button.on { background: #fff4d4; }
.ico.p1 { color: var(--human); background: var(--human-bg); }
.ico.p2 { color: var(--orc); background: var(--orc-bg); }
.sel-head { display: flex; align-items: center; gap: 10px; }
.sel-head .ico { width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; border: 2px solid; font-size: 17px; }
.sel-card ul, #selCard ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.6; }
.status { font-size: 12px; margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; }
.status span { background: var(--paper-2); border-radius: 6px; padding: 1px 6px; }
.preview { margin-top: 8px; font-size: 13px; background: #fff4d4; border-radius: 6px; padding: 6px 8px; }
.modes { display: flex; gap: 6px; margin-top: 8px; }
.log-card { flex: 1; min-height: 140px; display: flex; flex-direction: column; }
.log { flex: 1; overflow-y: auto; font-size: 12px; line-height: 1.6; max-height: 260px; }
.log .p1 { color: var(--human); }
.log .p2 { color: var(--orc); }
.log .sep { color: var(--ink-soft); margin-top: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; color: var(--ink-soft); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 3px; }

.overlay { position: fixed; inset: 0; background: rgba(40, 30, 15, .55); display: flex; align-items: center; justify-content: center; z-index: 50; }
.dialog { background: var(--paper); border-radius: 14px; padding: 24px 28px; max-width: 92vw; text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
.dialog h1 { margin: 0 0 8px; letter-spacing: 4px; }
.map-choice { display: flex; gap: 14px; margin-top: 18px; justify-content: center; flex-wrap: wrap; }
.map-choice button { padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.mini { display: grid; border: 1.5px solid var(--ink); }
.mini i { width: 9px; height: 9px; }
.dialog.rules { text-align: left; max-width: 760px; max-height: 86vh; overflow-y: auto; line-height: 1.65; font-size: 14px; position: relative; }
.dialog.rules h2 { margin: 16px 0 6px; font-size: 16px; }
.dialog.rules table { border-collapse: collapse; width: 100%; font-size: 13px; }
.dialog.rules td, .dialog.rules th { border: 1px solid var(--line); padding: 4px 8px; vertical-align: top; }
.dialog.rules .close { position: sticky; top: 0; float: right; }
.toast { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 8px 20px; border-radius: 99px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 60; font-size: 15px; }
.toast.show { opacity: 1; }

.unit .tag.shield { left: auto; right: -7px; top: auto; bottom: 12px; background: #c99a1a; }

/* ===== v0.4：菜单 / 设置 / 大厅 / 说明 ===== */
.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.menu { background: radial-gradient(circle at 50% 30%, #f6eedb, #d8cbb0 70%); }
.menu-card { text-align: center; }
.menu-title { font-size: 64px; font-weight: 800; letter-spacing: 14px; margin-left: 14px; }
.menu-title::before, .menu-title::after { content: '⚔'; font-size: 30px; vertical-align: middle; margin: 0 18px; color: var(--ink-soft); letter-spacing: 0; }
.menu-sub { color: var(--ink-soft); margin: 6px 0 30px; }
.menu-buttons { display: grid; grid-template-columns: repeat(2, 240px); gap: 14px; justify-content: center; }
button.big { padding: 16px 18px; text-align: left; display: flex; flex-direction: column; gap: 4px; border-radius: 12px; border-width: 2px; }
button.big b { font-size: 18px; }
button.big span { font-size: 13px; color: var(--ink-soft); }
button.big:hover { border-color: var(--ink); }
.menu-foot { margin-top: 26px; font-size: 12px; color: var(--ink-soft); }

.setup-card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 18px 24px 24px; width: min(720px, 100%); box-shadow: 0 8px 30px rgba(60, 40, 10, .2); }
.setup-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.setup-head h2 { margin: 0; font-size: 20px; }
.field { margin: 16px 0; }
.field > label { display: block; font-weight: 700; margin-bottom: 8px; font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); padding: 8px 16px; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: var(--paper); outline: 0; }
.match-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.match-row .vs { font-weight: 800; color: var(--ink-soft); }
.side-tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; color: #fff; margin-right: 6px; }
.side-tag.p1 { background: var(--human); }
.side-tag.p2 { background: var(--orc); }
.map-choice { justify-content: flex-start; margin-top: 0; }
.map-choice button.on { outline: 3px solid var(--ink); }
.setup-go { margin-top: 18px; padding: 10px 28px; font-size: 16px; }

.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 10px; }
.lobby-box { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.lobby-box h3 { margin: 0 0 4px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; font: inherit; font-size: 20px; letter-spacing: 4px; text-transform: uppercase; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fffaf0; min-width: 0; }

.top-left { display: flex; align-items: center; gap: 10px; }
#roomCard .code { font-size: 22px; font-weight: 800; letter-spacing: 4px; }
#roomCard .seats { font-size: 13px; margin-top: 6px; line-height: 1.8; }
.dot-on, .dot-off { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot-on { background: #2c9a4b; } .dot-off { background: #bbb; }
.win-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.cell.hl-last::before { content: ''; position: absolute; inset: 2px; border: 2px dashed #e2a21a; z-index: 3; pointer-events: none; }
.waiting { background: #fff4d4; border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-top: 8px; }

.dialog.guide { text-align: left; width: min(860px, 94vw); max-height: 90vh; overflow-y: auto; line-height: 1.7; font-size: 14px; position: relative; padding-top: 0; }
.guide-head { position: sticky; top: 0; background: var(--paper); display: flex; justify-content: space-between; align-items: center; padding: 16px 0 10px; border-bottom: 1px solid var(--line); z-index: 2; }
.guide-head h1 { margin: 0; font-size: 22px; letter-spacing: 3px; }
.guide-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 4px; }
.guide h2 { font-size: 17px; margin: 22px 0 8px; padding-left: 10px; border-left: 4px solid var(--ink); }
.guide table { border-collapse: collapse; width: 100%; font-size: 13px; }
.guide td, .guide th { border: 1px solid var(--line); padding: 5px 8px; vertical-align: top; }
.guide th { background: var(--paper-2); text-align: left; }
.guide .ico { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; border: 2px solid; }
.guide .ico.human { color: var(--human); background: var(--human-bg); }
.guide .ico.orc { color: var(--orc); background: var(--orc-bg); }
.steps { counter-reset: st; list-style: none; padding: 0; }
.steps li { counter-increment: st; position: relative; padding-left: 34px; margin: 8px 0; }
.steps li::before { content: counter(st); position: absolute; left: 0; top: 1px; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: var(--paper); text-align: center; line-height: 24px; font-size: 13px; }
.tip { background: #fff4d4; border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
@media (max-width: 640px) {
  .menu-title { font-size: 40px; letter-spacing: 6px; }
  .menu-buttons, .lobby-grid { grid-template-columns: 1fr; }
}

/* ===== v0.5：语言切换 / 范围图 ===== */
.menu { position: relative; }
.lang-btn { position: absolute; top: 16px; right: 20px; font-weight: 700; }
.fac-title { margin: 18px 0 6px; font-size: 16px; }
.unit-card { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 10px 0; background: #fffaf0; }
.unit-card-head { display: flex; align-items: center; gap: 10px; }
.unit-card-head b { font-size: 16px; }
.unit-card ul { margin: 8px 0 2px; padding-left: 18px; font-size: 13px; line-height: 1.6; }
.pats { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; align-items: flex-start; }
.pat { margin: 0; --pc: 15px; }
.pat figcaption { font-size: 12px; color: var(--ink-soft); margin-top: 4px; max-width: 170px; }
.pat-grid { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); width: max-content; }
.pat-grid i { width: var(--pc); height: var(--pc); background: var(--paper); display: flex; align-items: center; justify-content: center; font-style: normal; font-size: 10px; font-weight: 700; }
.pat-grid i.move, .pat-legend i.move { background: #9db7e0; }
.pat-grid i.atk, .pat-legend i.atk { background: #e58a7f; }
.pat-grid i.atk2, .pat-legend i.atk2 { background: #b8463a; }
.pat-grid i.charge, .pat-legend i.charge { background: #f0b85a; }
.pat-grid i.heal, .pat-legend i.heal { background: #8fd0a0; }
.pat-grid i.curse, .pat-legend i.curse { background: #b38ad0; }
.pat-grid i.me { color: #fff; border-radius: 50%; }
.pat-grid i.me.human { background: var(--human); }
.pat-grid i.me.orc { background: var(--orc); }
.pat-grid i.me.heal { box-shadow: 0 0 0 2px #5fbf7a inset; }
.pat-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-soft); margin: 6px 0; }
.pat-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: -2px; margin-right: 4px; }
html[lang="en"] .menu-title { letter-spacing: 1px; margin-left: 0; font-size: 54px; white-space: nowrap; }
html[lang="en"] .title { letter-spacing: 0; }
@media (max-width: 640px) { html[lang="en"] .menu-title { font-size: 32px; } }
html[lang="en"], html[lang="en"] button, html[lang="en"] input { font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, "Microsoft YaHei", sans-serif; }
html[lang="en"] .guide-head h1 { letter-spacing: 0; }
