/* 紅白機風：黑底、白框選單視窗、紅白機調色盤。只有一種畫面色調，不做深淺色切換。 */
:root {
  --bg: #000000; --fg: #FCFCFC; --dim: #BCBCBC; --mute: #7C7C7C; --line: #3C3C3C;
  --blue: #0000BC; --sky: #3CBCFC; --gold: #F8B800; --red: #F83800; --deep-red: #A81000; --green: #58D854;
  --cell: 64px;
  --f-ui: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --f-num: "DotGothic16", "Noto Sans TC", monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--f-ui); font-weight: 700; }
body { padding: 18px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, select:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.win { border: 4px solid var(--fg); border-radius: 6px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.win h2 { margin: 0; font-size: 15px; color: var(--dim); }
.num { font-family: var(--f-num); font-weight: 400; }
.dim { color: var(--dim); font-weight: 500; }
.small { font-size: 13px; }
p { margin: 0; line-height: 1.6; }

.top { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.top h1 { margin: 0; font-size: 28px; font-weight: 900; letter-spacing: .1em; }
.lamps { display: flex; align-items: center; gap: 7px; margin-left: auto; }
.lamp { width: 15px; height: 22px; border: 2px solid var(--fg); border-radius: 8px 8px 2px 2px; }

.btn { appearance: none; min-height: 48px; padding: 0 16px; border: 4px solid var(--fg); border-radius: 6px; background: var(--bg); font-size: 17px; }
.btn.primary { background: var(--blue); }
.btn.go { background: var(--deep-red); font-size: 22px; font-weight: 900; letter-spacing: .3em; }
.btn.on { border-color: var(--gold); background: var(--blue); }
.btn:disabled { border-color: var(--mute); color: var(--mute); cursor: default; background: var(--bg); }
.link { appearance: none; border: 0; background: none; padding: 0; color: var(--gold); font-size: 15px; text-decoration: underline; }

/* 地圖 */
.board { position: relative; width: calc(var(--cell) * 12); height: calc(var(--cell) * 10); border: 4px solid var(--fg); border-radius: 6px; box-sizing: content-box; overflow: hidden; flex: none; }
.tiles { display: grid; grid-template-columns: repeat(12, var(--cell)); }
.tile { width: var(--cell); height: var(--cell); box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.t-plain { background: #58D854; }
.t-grass { background: radial-gradient(#58D854 22%, transparent 23%) 0 0/25% 25%, #00A800; }
.t-forest { background: radial-gradient(circle at 50% 40%, #00A800 0 32%, transparent 33%) 0 0/50% 50%, #005800; }
.t-mountain { background: linear-gradient(135deg, transparent 46%, #503000 46% 56%, transparent 56%) 0 0/50% 50%, #AC7C00; }
.t-river { background: repeating-linear-gradient(0deg, #3CBCFC 0 12.5%, #0078F8 12.5% 17%); }
.t-bridge { background: repeating-linear-gradient(90deg, #AC7C00 0 15%, #503000 15% 20%); }
.t-village { background: linear-gradient(#F83800,#F83800) 50% 28%/72% 28% no-repeat, linear-gradient(#FCE0A8,#FCE0A8) 50% 76%/56% 40% no-repeat, #58D854; }
.t-fort { background: repeating-linear-gradient(45deg, #881400 0 8%, #58D854 8% 22%); }
.t-treasure { background: linear-gradient(#F8B800,#F8B800) center/46% 34% no-repeat, linear-gradient(#881400,#881400) center/58% 46% no-repeat, #58D854; }
.deploy { position: absolute; background: rgba(0,120,248,.28); box-shadow: inset 0 0 0 2px #3CBCFC; cursor: pointer; }
.unit { position: absolute; width: var(--cell); height: var(--cell); display: flex; align-items: flex-end; justify-content: center; transition: left .25s linear, top .25s linear; }
.unit img { position: relative; height: var(--cell); max-width: 160%; image-rendering: pixelated; flex: none; }
.unit.flip img { transform: scaleX(-1); }
/* 敵我底座：我軍藍、敵軍紅，像當年戰略遊戲的部隊格；畫在人物腳下 */
.unit::before { content: ""; position: absolute; inset: 2px; border: 2px solid; border-radius: 4px; }
.unit.ours::before { background: rgba(0,88,248,.5); border-color: #3CBCFC; }
.unit.enemy::before { background: rgba(168,16,0,.55); border-color: #F83800; }
.unit .tag { position: absolute; left: 50%; top: -2px; transform: translateX(-50%); padding: 0 4px; font-size: 11px; line-height: 1.4; white-space: nowrap; border-radius: 2px; }
.unit.ours .tag { background: #0058F8; }
.unit.enemy .tag { background: var(--deep-red); }
.unit .hp { position: absolute; left: 10%; right: 10%; bottom: -1px; height: 6px; background: #000; border: 1px solid; }
.unit.ours .hp { border-color: #3CBCFC; }
.unit.enemy .hp { border-color: #F83800; }
.unit .hp i { display: block; height: 100%; }
.unit.out { opacity: 0; transition: opacity .4s; }
.unit.hitflash img { filter: brightness(3); }
.unit.confused::after { content: "？"; position: absolute; right: 0; top: 0; color: var(--gold); font-size: 14px; }
.cursor { position: absolute; width: var(--cell); height: var(--cell); outline: 4px solid var(--gold); outline-offset: -2px; pointer-events: none; }
.fx-fire { position: absolute; width: var(--cell); height: var(--cell); pointer-events: none; background: radial-gradient(circle at 50% 70%, #FCE0A8 0 12%, #F8B800 13% 30%, #F83800 31% 52%, rgba(168,16,0,.55) 53% 70%, transparent 71%); animation: fade 1s forwards; }
.fx-rock { position: absolute; width: var(--cell); height: var(--cell); pointer-events: none; background: radial-gradient(circle, #AC7C00 0 25%, #503000 26% 38%, transparent 40%); animation: fade .9s forwards; }
.fx-heal { position: absolute; width: var(--cell); height: var(--cell); pointer-events: none; background: radial-gradient(circle, rgba(88,216,84,.7) 0 40%, transparent 60%); animation: fade .9s forwards; }
.pop { position: absolute; font-family: var(--f-num); font-size: 22px; pointer-events: none; text-shadow: 2px 0 #000, -2px 0 #000, 0 2px #000, 0 -2px #000; animation: rise .9s forwards; }
@keyframes fade { to { opacity: 0; } }
@keyframes rise { to { transform: translateY(-24px); opacity: 0; } }
.rain { position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(105deg, transparent 0 14px, rgba(60,188,252,.35) 14px 16px); }

/* 版面 */
.row { display: flex; gap: 20px; align-items: flex-start; }
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.menu { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.menu button { appearance: none; width: 100%; display: flex; align-items: center; gap: 10px; padding: 6px 8px; border: 0; border-radius: 3px; background: none; text-align: left; font-size: 18px; }
.menu button[aria-current="true"] { background: var(--blue); }
.menu button:disabled { color: var(--mute); cursor: default; }
.menu .state { margin-left: auto; font-size: 14px; color: var(--gold); }
dl.kv { margin: 0; display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 6px 12px; font-size: 15px; font-weight: 500; }
dl.kv dt { color: var(--dim); }
dl.kv dd { margin: 0; }
.forecast { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.forecast i { width: 13px; height: 13px; border-radius: 2px; }
.plan { appearance: none; text-align: left; padding: 10px 12px; border: 3px solid var(--mute); border-radius: 4px; background: var(--bg); display: flex; flex-direction: column; gap: 4px; }
.plan[aria-pressed="true"] { border-color: var(--gold); background: var(--blue); }
.plan b { font-size: 18px; font-weight: 900; }
.badge { font-size: 12px; padding: 0 5px; background: var(--gold); color: #000; border-radius: 2px; margin-left: 8px; }
.roster li { display: grid; grid-template-columns: 18px 38px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 3px; cursor: pointer; }
.roster li[aria-selected="true"] { background: var(--blue); }
.roster img { height: 32px; image-rendering: pixelated; }
.roster .face { width: 38px; height: 34px; display: grid; place-items: end center; overflow: hidden; }
.mini { appearance: none; border: 2px solid var(--mute); border-radius: 3px; background: none; padding: 0 6px; font-size: 13px; }
select { appearance: none; background: var(--bg); border: 2px solid var(--fg); border-radius: 3px; padding: 4px 8px; font-size: 14px; max-width: 100%; }
.rule { display: flex; flex-direction: column; gap: 4px; padding: 6px 8px; border: 2px solid var(--line); border-radius: 3px; min-width: 0; }
.rule select { width: 100%; min-width: 0; }
.msgbox { border: 4px solid var(--fg); border-radius: 6px; padding: 10px 16px; font-size: 18px; line-height: 1.6; min-height: 80px; }
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 500; max-height: 300px; overflow: auto; }
.bars li { display: grid; grid-template-columns: 52px minmax(0, 1fr) 84px; gap: 8px; align-items: center; font-size: 15px; }
.bar { height: 10px; background: var(--line); }
.bar i { display: block; height: 100%; }
.ctrls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 1.1fr 1.4fr; gap: 8px; }
.ctrls .btn { font-size: 16px; padding: 0 6px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal .win { background: var(--bg); width: min(980px, 100%); max-height: 100%; overflow: auto; }
.levels { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 24px; }
.levels li { display: grid; grid-template-columns: 40px 76px 1fr; gap: 10px; align-items: center; }
.levels img { height: 32px; image-rendering: pixelated; }

@media (max-width: 1100px) {
  .row { flex-direction: column; align-items: stretch; }
  .row > .col { width: auto !important; min-width: 0 !important; max-width: 100%; }
  .ctrls { grid-template-columns: repeat(3, minmax(0, 1fr)) 1fr 1.2fr; }
}
@media (max-width: 800px) {
  body { padding-left: 0; padding-right: 0; }
  .app > *:not(.row) { margin: 0 12px; }
  .row > .col:not(.boardwrap) { margin: 0 12px; }
  .boardwrap .msgbox, .boardwrap > p { margin: 0 12px; }
  .top h1 { font-size: 20px; }
  .levels { grid-template-columns: 1fr; }
  .board { border-width: 0; border-radius: 0; }
  /* 手機格子太小，戰場上只留敵我底座，不放名牌 */
  .board.fight .unit .tag { display: none; }
  .board.fight .unit::before { inset: 1px; border-width: 3px; }
}
