:root { --cast-atlas: url("./portrait-atlas.webp"); }
* { box-sizing: border-box; }
:root {
  color-scheme: dark;
  --ink: #10141f;
  --gold: #f9d289;
  --cream: #f6e9d3;
  --line: #33374b;
  --muted: #a2a7bc;
  --sans: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  --serif: "Songti SC", "Noto Serif CJK SC", "SimSun", serif;
}
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  background: radial-gradient(ellipse at 56% 4%, #22243b 0%, #131827 46%, #0e121b 90%);
  color: var(--cream);
  font: 14px/1.6 var(--sans);
}
button { font: inherit; cursor: pointer; color: inherit; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 2px solid #ffda99; outline-offset: 4px; }
.shell { width: min(1080px, calc(100% - 72px)); margin: 0 auto; padding: clamp(20px, 5vh, 58px) 0 26px; }
.top { display: flex; justify-content: space-between; align-items: center; margin: 0 0 17px; }
.identity { display: flex; align-items: center; gap: 13px; color: #d9d3cf; font-size: 13px; letter-spacing: .18em; }
.sigil {
  width: 24px; height: 24px; border: 1px solid #635847; position: relative;
  transform: rotate(45deg) scale(.75); margin-inline: 3px;
}
.sigil::before, .sigil::after { content: ""; position: absolute; background: var(--gold); inset: 10px 4px; transform: rotate(-45deg); }
.sigil::after { transform: rotate(45deg); }
.sound, .restart { border: 0; background: transparent; color: var(--muted); padding: 6px 4px; font-size: 12px; letter-spacing: .06em; }
.sound { border: 1px solid #3b3e50; padding: 5px 12px; border-radius: 5px; background: #191d2b; display: flex; align-items: center; gap: 7px; }
.sound:hover, .restart:hover { color: var(--gold); }
.sound-icon { color: var(--gold); font-size: 15px; }
.game {
  position: relative; isolation: isolate; background: #202540; border: 1px solid #57546a; border-radius: 9px;
  box-shadow: 0 20px 70px #070912a0, 0 0 0 5px #11162399; overflow: hidden;
}
#world { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.game-border { position: absolute; inset: 0; pointer-events: none; z-index: 3; border-radius: inherit; box-shadow: inset 0 0 0 1px #b9a6ca22, inset 0 0 48px #080d1980; }
.title-screen {
  position: absolute; inset: 0; display: flex; align-items: center;
  background: linear-gradient(90deg,#101827f2 0%,#111927d4 24%,#151d3185 42%,transparent 67%);
}
.title-content { margin-left: 8.7%; padding-bottom: 1%; }
.title-star { font: 28px/1 var(--serif); color: var(--gold); margin-bottom: 15px; text-shadow: 0 0 21px #ffc3728c; }
h1 {
  font: 700 clamp(36px, 6.85vw, 88px)/1.04 var(--serif);
  letter-spacing: .025em; color: #fff0d6; margin: 0 0 29px; text-shadow: 0 3px 14px #121221b0;
}
h1 span { color: var(--gold); }
.primary { background: #f0c986; color: #2b2430; border: 1px solid #ffe2a8; box-shadow: inset 0 -3px #be8c50, 0 5px 16px #090b17a8; border-radius: 4px; font-weight: 700; padding: 10px 16px; }
.start { min-width: 150px; text-align: left; letter-spacing: .1em; }
.start span { margin-left: 15px; }
.primary:hover { background: #ffe0aa; }
.chapter, .mini, .note {
  position: absolute; z-index: 2; border: 1px solid #77748c85; border-radius: 4px; color: #f5e5ce;
  background: #151a2beb; box-shadow: 0 2px 12px #080d1860;
}
.chapter { font-size: 12px; letter-spacing: .12em; top: 15px; left: 15px; padding: 5px 10px; }
.chapter span:first-child { color: var(--gold); }
.mini { top: 15px; right: 15px; padding: 3px; }
#map { display: block; width: 112px; height: 64px; image-rendering: pixelated; }
.note { bottom: 15px; left: 50%; transform: translateX(-50%); width: max-content; max-width: 90%; padding: 5px 11px; font-size: 13px; pointer-events: none; }
.control-bar { display: flex; align-items: center; position: relative; min-height: 51px; gap: 18px; }
.progress { display: flex; gap: 6px; align-items: center; }
.progress span { width: 23px; height: 3px; background: #393e56; border-radius: 2px; }
.progress .done { background: #a68e70; }
.progress .here { background: var(--gold); box-shadow: 0 0 8px #ffcf8465; }
.keys { display: flex; gap: 18px; color: var(--muted); font-size: 11px; }
kbd { font: 11px ui-monospace, monospace; color: #eae5e8; padding: 2px 5px; background: #212639; border: 1px solid #393e53; border-radius: 3px; }
.restart { margin-left: auto; }
.touch-controls { display: none; justify-content: space-between; align-items: center; }
.dpad { display: grid; grid-template-columns: repeat(3, 44px); gap: 5px; }
.dpad button, .touch-action { touch-action: none; user-select: none; height: 44px; border: 1px solid #525971; background: #222941; border-radius: 6px; font-size: 18px; }
.dpad button:active, .touch-action:active { background: #4b4d63; }
.up { grid-column: 2; }
.left { grid-column: 1; grid-row: 2; }
.down { grid-column: 2; grid-row: 2; }
.right { grid-column: 3; grid-row: 2; }
.touch-action { font-size: 14px; min-width: 63px; color: var(--gold); }
.dialog {
  color: var(--cream); padding: clamp(21px, 4vw, 36px); background: #1e2234; border: 1px solid #8c765e;
  border-radius: 7px; box-shadow: inset 0 0 0 4px #28283b, 0 18px 70px #0a0c16bb;
  width: min(480px, calc(100% - 40px)); max-height: calc(100% - 38px); overflow: auto;
}
.dialog::backdrop { background: #0b1022b2; }
.dialog p { margin: 0 0 18px; line-height: 1.9; font-size: 16px; overflow-wrap: anywhere; }
.quote p { font-family: var(--serif); font-size: clamp(16px, 3.6vw, 21px); }
.letter { background: #f7e9cf; color: #3c2c31; border-color: #86664e; box-shadow: inset 0 0 0 5px #dfc498, 0 18px 70px #0a0c16bb; }
.letter-star { color: #975a2f; font-size: 24px; }
.letter h2 { margin: 3px 0 11px; font: 700 27px var(--serif); }
.light-button { border: 1px solid #887557; border-radius: 4px; padding: 6px 12px; background: transparent; color: #f4d399; }
.light-button:hover { background: #a0834730; }
.letter .light-button { color: #623d2c; }
.letter .light-button:focus-visible { outline-color: #8c6330; }
@media (pointer: coarse), (max-width: 650px) {
  .shell { width: calc(100% - 32px); }
  .touch-controls { display: flex; }
}
@media (pointer: coarse) {
  .keys { display: none; }
}
@media (max-width: 550px) {
  .title-star { font-size: 19px; margin-bottom: 6px; }
  h1 { margin-bottom: 11px; font-size: clamp(26px, 7.3vw, 40px); }
  .start { min-width: 0; padding: 5px 9px; font-size: 12px; }
  .start span { margin-left: 6px; }
  .top { margin-bottom: 12px; }
  .chapter { top: 7px; left: 7px; padding: 2px 5px; font-size: 10px; }
  .mini { top: 7px; right: 7px; padding: 2px; }
  #map { width: 61px; height: auto; }
  .note { bottom: 6px; font-size: 11px; padding: 2px 6px; }
  .keys { gap: 5px; }
  .keys kbd { padding: 2px; font-size: 10px; }
  .control-bar { gap: 8px; }
  .progress span { width: 12px; }
}

.title-content h1 { font: 500 clamp(62px, 10.7vw, 136px)/.9 Georgia, serif; letter-spacing: -.066em; margin: 0; }
.subtitle { color: #f5d3a1; letter-spacing: .45em; margin: 18px 0 26px; font: 700 clamp(15px,2.1vw,23px) var(--serif); }
.game .note { font-size: 14px; padding: 5px 13px; }
.board-dialog {
  width: min(720px, calc(100% - 28px));
  max-height: calc(100% - 24px);
  background: #23243a;
  color: #f5e6cc;
  border: 1px solid #b39777;
  border-radius: 12px;
  padding: 19px 22px;
  box-shadow: inset 0 0 0 4px #181b2f, 0 25px 100px #040610c9;
}
.board-dialog::backdrop { background: #0b1020d3; }
.board-head {display:flex; justify-content:space-between; align-items:flex-start; gap:12px; margin-bottom:12px;}
.board-head h2 { margin:0; color:#ffe6b0; font:700 33px/1.15 var(--serif); }
.board-head p { margin:4px 0 0; color:#bdb6bd; font-size:13px; }
.icon-button {
  width:35px; height:35px; background:#34374d; border:1px solid #53566d; border-radius:50%; font:21px/1 var(--sans);
}
.board-layout { display:grid; grid-template-columns:minmax(0, 1.58fr) minmax(190px, 1fr); gap:20px; align-items:start; }
.board-meta { display:flex; gap:14px; align-items:center; margin-bottom:7px; font-size:12px; color:#e6dcd3; }
.board-meta > span { display:flex; align-items:center; gap:5px; }
.legend {width:10px; height:10px; border-radius:50%; display:inline-block;}
.player-legend {background:#ffd084;}
.echo-legend {background:#adc0ff;}
.tempo {margin-left:auto; color:#ffe2a4;}
.tempo b {font-size:17px; font-variant-numeric:tabular-nums; line-height:1;}
.chess-grid {
  display:grid; width:100%; gap:2px;
  grid-template-columns:repeat(var(--cols), minmax(0,1fr));
  background:#101223; padding:5px; border:1px solid #5b566b; border-radius:7px;
}
.square { aspect-ratio:1; border:1px solid #343953; border-radius:3px; background:#333951; position:relative; overflow:hidden; }
.square:nth-child(odd) { background:#343b54; }
.square.wall {
  border-color:#787089; background:
    repeating-linear-gradient(0deg, #453f55 0 1px, transparent 1px 6px),
    repeating-linear-gradient(90deg, #56516a 0 1px, #5c566e 1px 8px);
  box-shadow:inset 0 2px #7f7586, inset -3px -3px #454258;
}
.square.goal-player { --goal:#f4bb74; --goal-bg:#ad754a32; }
.square.goal-echo { --goal:#afbcff; --goal-bg:#8fa4fc32; }
.square.goal-player, .square.goal-echo { background:var(--goal-bg); }
.square.goal-player::before, .square.goal-echo::before {
  content:""; position:absolute; inset:20%; transform:rotate(45deg);
  border:2px dashed var(--goal); border-radius:18%; opacity:.85;
}
.square.preview-player::after, .square.preview-echo::after {
  content:""; position:absolute; inset:28%; border:2px dotted var(--token); border-radius:50%; z-index:2;
}
.square.preview-player, .pawn.player { --token:#fbd084; --token-dark:#a47151; }
.square.preview-echo, .pawn.echo { --token:#b9c8ff; --token-dark:#6c71a3; }
.pawn {
  position:absolute; inset:15%; z-index:1; display:grid; place-items:center; border-radius:50%;
  border:2px solid var(--token); background:var(--token-dark);
  box-shadow:inset 0 0 0 2px #292c435e,0 2px 6px #171625bd;
  color:var(--token); font:700 clamp(10px, 2.1vw, 20px)/1 Georgia,serif;
}
.board-message { margin:6px 0 0; min-height:22px; font-size:12px; color:#f5cf93; }
.board-hand { padding-top:14px; display:flex; flex-direction:column; gap:9px; }
.cards {display:grid; gap:5px;}
.card {
  display:grid; grid-template-columns:31px 1fr auto auto; align-items:center; gap:8px; padding:5px 8px;
  min-height:47px; text-align:left; border:1px solid #555b75; border-radius:6px; background:#30364f;
}
.card[aria-pressed="true"] { background:#504456; border-color:#f0c389; box-shadow:0 0 14px #daa25a22; }
.card:disabled { opacity:.55; cursor:default; }
.card-art { color:#edc998; font:700 20px/1 Georgia,serif; letter-spacing:-.14em; }
.card strong, .card small {display:block; line-height:1.45;}
.card strong { font-size:13px; }
.card small { font-size:10px; color:#c8c0c4; }
.card kbd {font-size:9px; padding-inline:4px;}
.quantity {color:#ffdfa2; font-size:11px; white-space:nowrap;}
.board-arrows {display:grid; grid-template-columns:repeat(4,1fr); gap:5px;}
.board-arrows button,.board-tools button {min-height:36px; padding:3px; border:1px solid #535b78; background:#31374e; border-radius:5px;}
.board-arrows button {font:20px var(--sans);}
.board-arrows button:hover:not(:disabled),.board-tools button:hover:not(:disabled) {background:#4e4b62; color:#ffe0a9;}
.board-arrows button:disabled,.board-tools button:disabled {opacity:.4; cursor:default;}
.board-tools {display:flex; gap:5px;}
.board-tools button { flex:1; color:#ded1c4; font-size:12px; min-height:33px; }
.board-done { align-self:stretch; text-align:center; }
@media (max-width:570px) {
  .title-content h1 { font-size:clamp(40px,12vw,62px); }
  .subtitle {margin:7px 0 12px;}
  .game .note {font-size:11px; padding:2px 6px; }
  .board-dialog {padding:12px 14px;}
  .board-head {margin-bottom:5px;}
  .board-head h2 {font-size:23px;}
  .board-head p {font-size:11px;}
  .board-layout {display:block;}
  .board-play {max-width:min(100%,33vh,330px); margin:auto;}
  .board-meta {font-size:10px; margin-bottom:4px; gap:8px;}
  .board-message {min-height:17px; font-size:11px; margin-top:3px;}
  .board-hand {padding-top:5px; gap:5px;}
  .cards {grid-template-columns:repeat(3,minmax(0,1fr)); gap:4px;}
  .card {min-height:43px; grid-template-columns:22px minmax(0,1fr); gap:2px 4px; padding:4px; }
  .card-art {font-size:12px; letter-spacing:-.12em; text-align:center; white-space:nowrap;}
  .card strong {font-size:11px;}
  .card small {font-size:8px; white-space:nowrap;}
  .card kbd {display:none;}
  .card .quantity {grid-column:2; font-size:9px;}
  .board-arrows button {min-height:42px;}
  .board-done {padding:6px 9px;}
}
.board-arrows button.suggested { color:#ffe0a9; border-color:#ffca86; }
.chess-grid.won .goal-player, .chess-grid.won .goal-echo { box-shadow:inset 0 0 14px var(--goal); }

.title-content h1 { margin-bottom: clamp(19px,4vw,42px); }
.cast-caption { display:block; font-size:10px; color:#cbc0c1; margin:2px 0 0 14px; letter-spacing:.08em; }
.story-dialog { width:min(505px,calc(100% - 34px)); }
.story-layout { display:grid; grid-template-columns:78px 1fr; gap:15px; align-items:start; }
.story-portrait { display:grid; place-items:center; width:78px; height:85px; border:1px solid #6a596e; background:radial-gradient(ellipse at 50% 42%,#4d3b54,#29293d 75%); border-radius:5px; }
.story-portrait canvas { width:70px; height:75px; image-rendering:pixelated; }
.story-layout h2 { margin:1px 0 4px; color:#f0c88f; font:700 18px var(--serif); }
.story-layout p { margin:0 0 13px; color:#fff0df; font:16px/1.7 var(--sans); }
.story-dialog > button {display:block; margin:8px 0 0 auto;}
.letter .signature { text-align:right; font:700 24px/1.2 var(--serif); color:#6a4037; margin:22px 0 14px; }
.side-grid { display:grid; grid-template-columns:repeat(var(--cols),minmax(0,1fr)); gap:2px; background:#161a2a; padding:4px; border:1px solid #655d75; border-radius:6px; }
.side-cell {
  min-width:0; aspect-ratio:1; padding:0; position:relative; display:grid; place-items:center; overflow:hidden;
  border:1px solid #4d526c; border-radius:4px; background:#343b54; color:#e2d0ba; font:700 clamp(12px,2.6vw,23px)/1 var(--sans);
}
.side-cell:hover:not(:disabled) { background:#4e5170; }
.side-cell:focus-visible { outline-offset:-3px; z-index:1; }
.side-cell.flood { color:#547d9c; background:repeating-linear-gradient(168deg,#34485e 0 5px,#2b3d55 5px 9px); border-color:#405c75; }
.side-cell.awning { background:#52445c; border-color:#8e6e76; color:#ffd99b; }
.side-cell.occupied { color:#ffdd96; background:#6e574f; box-shadow:inset 0 0 12px #f0bd7266; }
.side-cell.suggested {border-color:#ffdb8e; box-shadow:inset 0 0 0 2px #ffdb8e; }
#sideMeter { font-size:11px; }
@media(max-width:570px) {
  .cast-caption { font-size:8px; }
  .story-layout {grid-template-columns:55px 1fr; gap:9px;}
  .story-portrait {width:55px;height:62px;}
  .story-portrait canvas {width:53px;height:57px;}
  .story-layout p {font-size:14px;}
  .side-dialog .board-play {max-width:min(100%, 46vh);}
  #sideMeter,#sideLegend {font-size:10px;}
}

.sky-dialog {
  width:min(680px,calc(100% - 28px)); max-height:calc(100% - 24px);
  padding:19px 22px 14px; color:#f5e6cc; background:#23243a;
  border:1px solid #b39777; border-radius:11px;
  box-shadow:inset 0 0 0 4px #181b2f,0 26px 85px #040610cd;
}
.sky-dialog::backdrop {background:#0b1020d2;}
.sky-view {position:relative; overflow:hidden; border:1px solid #625f7d; border-radius:5px; background:#161d36;}
#skyCanvas {display:block;width:100%;height:auto;image-rendering:pixelated;}
#skyChoices {position:absolute;inset:0;pointer-events:none;}
.sky-choice {
  position:absolute; width:clamp(30px,7vw,48px); height:clamp(30px,7vw,48px); transform:translate(-50%,-50%);
  pointer-events:auto; background:transparent; border:1px solid transparent; border-radius:50%;
}
.sky-choice:hover,.sky-choice:focus-visible {border-color:#cebad3; background:#9fa4ff1e;}
.sky-footer {display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:10px;}
.sky-footer p {margin:0;color:#e7cfa8;font-size:13px;}
.sky-footer button {flex-shrink:0;}
@media(max-width:550px) {
  .sky-dialog {padding:12px 14px;}
  .sky-footer p {font-size:11px;}
  .sky-footer button {font-size:12px;padding:5px 6px;}
}

.story-dialog {width:min(610px,calc(100% - 34px));}
.story-layout {grid-template-columns:113px 1fr;align-items:center;gap:17px;}
.story-portrait {
  width:113px;height:113px;overflow:hidden;border:1px solid #a88684;border-radius:6px;
  background:#382239;box-shadow:0 3px 10px #19162799;
}
.portrait-art {width:100%;height:100%;background-image:var(--cast-atlas);background-size:200% 200%;background-repeat:no-repeat;}
.portrait-art[data-portrait="ji"] {background-position:0 0;}
.portrait-art[data-portrait="ye"] {background-position:100% 0;}
.portrait-art[data-portrait="liang"] {background-position:0 100%;}
.portrait-art[data-portrait="qin"] {background-position:100% 100%;}
.story-layout h2 {margin:0 0 6px;}
.story-layout p {margin:0;}
@media(max-width:570px) {
  .story-layout {grid-template-columns:81px 1fr;gap:12px;}
  .story-portrait {width:81px;height:81px;}
}

.portrait-art {image-rendering:pixelated;}