:root {
  --paper: #f4ede0;
  --card: #fbf7ef;
  --ink: #231f1a;
  --muted: #7a6f60;
  --line: #d8ccb6;
  --red: #a8322a;
  --red-soft: #f3dcd6;
  --gold: #b08528;
  --green: #3d6b45;
  --blue: #2f5878;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 2px 8px rgba(60, 40, 20, .06);
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", serif;
  --sans: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.5 var(--sans); }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 6px; padding: 6px 12px; }
button:hover:not(:disabled) { border-color: var(--ink); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--red); border-color: var(--red); color: #fff; }
button.primary:hover:not(:disabled) { background: #8c2820; }
button.chip { padding: 3px 10px; border-radius: 999px; font-size: 13px; }
button.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
input { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
h1, h2, h3 { font-family: var(--serif); margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ── 首页 / 大厅 ── */
.home { max-width: 460px; margin: 10vh auto; padding: 0 16px; }
.home h1 { font-size: 44px; letter-spacing: .15em; }
.home .sub { color: var(--muted); margin: 4px 0 28px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; box-shadow: var(--shadow); }
.home .panel + .panel { margin-top: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1; min-width: 0; }
.lobby-players { list-style: none; padding: 0; margin: 12px 0; }
.lobby-players li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.share { font-family: ui-monospace, Menlo, monospace; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; word-break: break-all; flex: 1; }
.rules { margin-top: 14px; }
.rules summary { cursor: pointer; font-weight: 600; }
.rules ol { padding-left: 20px; margin: 8px 0 0; }

/* ── 游戏主界面 ── */
.top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; }
.top h1 { font-size: 20px; letter-spacing: .1em; }
.sky { background: var(--ink); color: var(--paper); border-radius: 6px; padding: 4px 10px; }
.sky b { font-family: var(--serif); margin-right: 6px; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; padding: 16px; max-width: 1400px; margin: 0 auto; }
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.section-title { font-family: var(--serif); font-size: 15px; margin: 0 0 8px; display: flex; justify-content: space-between; align-items: baseline; }

.nations { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.nation { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; position: relative; box-shadow: var(--shadow); }
.nation.picked { outline: 2px solid var(--red); }
.nation.dead { opacity: .45; filter: grayscale(1); }
.nation .head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.seal { width: 34px; height: 34px; border-radius: 6px; background: var(--red); color: #fff; font: 700 20px/34px var(--serif); text-align: center; flex: none; }
.seal.sm { width: 22px; height: 22px; font-size: 13px; line-height: 22px; border-radius: 4px; display: inline-block; }
.nation .heg { color: var(--gold); font-weight: 600; }
.stat { display: grid; grid-template-columns: 30px 1fr 16px; align-items: center; gap: 6px; font-size: 12px; }
.pips { display: flex; gap: 2px; }
.pip { flex: 1; height: 7px; border-radius: 2px; background: #e8dfcf; }
.pip.on.econ { background: var(--gold); }
.pip.on.gov { background: var(--blue); }
.pip.on.mil { background: var(--red); }
.stat b { text-align: right; }
.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: #ffe8a8; } to { background: transparent; } }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 999px; border: 1px solid currentColor; }
.badge.zhou { color: var(--gold); }
.badge.dead { color: var(--red); }
.adj { font-size: 11px; color: var(--muted); margin-top: 4px; }

.action { border: 2px solid var(--red); }
.action.idle { border-color: var(--line); }
.action h2 { font-size: 17px; margin-bottom: 6px; }
.action .hint { color: var(--muted); margin-bottom: 10px; }
.editor { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 10px 0; }
.editor .row { margin: 6px 0; }
.editor .lbl { width: 56px; color: var(--muted); font-size: 12px; }
.plan { list-style: none; padding: 0; margin: 8px 0; }
.plan li { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; background: var(--red-soft); border-radius: 6px; margin-bottom: 4px; }
.versus { display: flex; align-items: center; justify-content: center; gap: 16px; font-family: var(--serif); font-size: 20px; margin: 6px 0 12px; }
.versus .dice { font-family: var(--sans); font-size: 13px; color: var(--muted); display: block; text-align: center; }

.cards { display: flex; gap: 8px; flex-wrap: wrap; }
.card { width: 132px; min-height: 104px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px; box-shadow: var(--shadow); text-align: left; display: flex; flex-direction: column; gap: 4px; }
.card .name { font-family: var(--serif); font-weight: 700; font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.card .speed { font: 700 12px/20px var(--sans); width: 20px; height: 20px; text-align: center; border-radius: 50%; background: var(--ink); color: var(--paper); }
.card .text { font-size: 12px; color: var(--muted); }
.card.reaction { background: #eef2f4; }
.card.war { border-color: #d6aaa4; }
.card.selectable:hover { border-color: var(--ink); transform: translateY(-2px); }
.card.selected { outline: 2px solid var(--red); }
.card.used { opacity: .35; }

.hero { width: 180px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; box-shadow: var(--shadow); }
.hero .name { font-family: var(--serif); font-size: 16px; font-weight: 700; display: flex; justify-content: space-between; }
.hero .score { color: var(--red); }
.hero .cond { font-size: 12px; margin: 4px 0; }
.hero .state { font-size: 12px; }
.hero.revealed { border-color: var(--gold); background: #fbf3dc; }
.hero.failed { opacity: .5; }
.hero.pick { cursor: pointer; }
.hero.pick:hover { border-color: var(--ink); }

.players { list-style: none; padding: 0; margin: 0; }
.players li { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.players li:last-child { border-bottom: 0; }
.players .who { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.players .name { font-weight: 600; }
.players .meta { font-size: 12px; color: var(--muted); }
.players .heroes { font-size: 12px; margin-top: 2px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #b9ae9b; margin-left: 4px; }
.dot.on { background: var(--green); }
.tag { font-size: 11px; padding: 0 6px; border-radius: 4px; background: var(--ink); color: var(--paper); margin-left: 4px; }
.tag.wait { background: var(--gold); }
.diku { color: var(--green); letter-spacing: 1px; }

.queue { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.queue li { padding: 3px 0; display: flex; gap: 6px; }
.queue li.done { color: var(--muted); }
.queue .sp { font-weight: 700; width: 18px; text-align: center; }

.die { display: inline-block; width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--line); text-align: center; font-size: 11px; line-height: 16px; margin: 1px; background: #fff; }
.die.hit { background: var(--red); color: #fff; border-color: var(--red); }

.log { max-height: 340px; overflow: auto; font-size: 12.5px; }
.log p { margin: 0 0 5px; }
.log p.private { color: var(--blue); }
.log p.big { font-weight: 600; }

.scores { width: 100%; border-collapse: collapse; }
.scores td, .scores th { padding: 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 8px; z-index: 20; max-width: 90vw; }

/* ── 地图 ── */
.mapwrap { overflow-x: auto; }
.map { position: relative; min-width: 660px; aspect-ratio: 16 / 9.5; background: radial-gradient(ellipse at 60% 40%, #efe5d1 0%, #e6d8bd 100%); border: 1px solid var(--line); border-radius: 12px; }
.map svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.edge { fill: none; stroke: #a8977a; stroke-width: 3; stroke-dasharray: 2 5; stroke-linecap: round; }
.edge.dead { stroke: #cbbfa9; }
.edge.focus { stroke: var(--ink); stroke-dasharray: none; stroke-width: 3; }
.edge.war { stroke: var(--red); stroke-dasharray: none; stroke-width: 5; }
.mnation { position: absolute; transform: translate(-50%, -50%); width: 150px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; box-shadow: var(--shadow); }
.mnation.dead { opacity: .5; filter: grayscale(1); }
.mnation.picked { outline: 3px solid var(--red); }
.mnation.atwar { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft), var(--shadow); }
.mnation.pickable { cursor: pointer; }
.mnation.pickable:hover { border-color: var(--ink); }
.mhead { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.mhead .seal { width: 28px; height: 28px; font-size: 17px; line-height: 28px; }
.mhead .heg { color: var(--gold); font-weight: 600; flex: 1; font-size: 13px; }
.mstat { display: grid; grid-template-columns: 14px 1fr 12px; gap: 5px; align-items: center; font-size: 11px; }
.mstat b { text-align: right; }
.legend { position: absolute; left: 10px; bottom: 8px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.legend .pip { width: 14px; flex: none; }
/* 宽屏用地图，窄屏用卡片网格 */
.nations { display: none; }
@media (max-width: 700px) {
  .mapwrap { display: none; }
  .nations { display: grid; }
}

.hero.keeping { outline: 3px solid var(--green); background: #eef5ec; }
.hero.discarding { outline: 3px solid var(--red); background: var(--red-soft); text-decoration: line-through; }
.logpanel .log { max-height: 190px; }
.logpanel .log p.old { color: var(--muted); font-weight: 400; }
