:root {
  color-scheme: dark;
  --page: #101713;
  --header: #18231d;
  --panel: #202d25;
  --panel-raised: #28382e;
  --line: #3b5143;
  --text: #f0f3e9;
  --muted: #a7b3a8;
  --green: #75c78b;
  --gold: #e4b64f;
  --red: #e16b60;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-width: 320px; height: 100%; margin: 0; overflow: hidden; background: var(--page); }
body, button { color: var(--text); font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button svg, a svg { display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
[hidden] { display: none !important; }

.game-app { display: grid; width: 100%; height: 100dvh; grid-template-rows: 64px minmax(0, 1fr); background: var(--page); user-select: none; }
.topbar { position: relative; z-index: 20; display: grid; grid-template-columns: 42px minmax(170px,1fr) minmax(500px,720px) minmax(98px,1fr); align-items: center; gap: 12px; padding: 0 18px; border-bottom: 1px solid var(--line); background: var(--header); }
.icon-button { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid var(--line); border-radius: 5px; color: #e0e8df; background: var(--panel); cursor: pointer; text-decoration: none; }
.icon-button:disabled { opacity: .4; cursor: default; }
.icon-button .play-icon, .icon-button.is-paused .pause-icon, .mute-line { display: none; }
.icon-button.is-paused .play-icon, .icon-button.is-muted .mute-line { display: block; }
.icon-button.is-muted .sound-wave { display: none; }
.brand { display: flex; min-width: 0; align-items: center; gap: 10px; }
.brand > span:last-child { display: grid; gap: 2px; }
.brand strong { font-size: 16px; }
.brand small, .metrics span, .shop-header span, .screen-content > p { color: var(--muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 9px; font-weight: 700; }
.brand-mark { position: relative; display: block; width: 32px; height: 32px; border: 2px solid var(--gold); border-radius: 50%; }
.brand-mark::before, .brand-mark::after { position: absolute; top: 14px; left: 4px; width: 21px; height: 2px; background: var(--gold); content: ""; }
.brand-mark::after { transform: rotate(90deg); }
.brand-mark i { position: absolute; inset: 9px; border: 2px solid #eef3df; transform: rotate(45deg); }
.metrics { display: grid; height: 100%; grid-template-columns: repeat(4,minmax(70px,1fr)) minmax(110px,1.3fr); border-right: 1px solid var(--line); border-left: 1px solid var(--line); }
.metrics > div { display: grid; min-width: 0; align-content: center; gap: 3px; padding: 0 14px; border-right: 1px solid var(--line); }
.metrics > div:last-child { border-right: 0; }
.metrics strong { font-family: "SFMono-Regular", Consolas, monospace; font-size: 17px; font-variant-numeric: tabular-nums; }
.base-bar { display: block; width: 88px; height: 11px; border: 1px solid #708477; background: #29372f; }
.base-bar i { display: block; width: 100%; height: 100%; background: var(--green); }
.actions { display: flex; justify-content: flex-end; gap: 8px; }

.workspace { display: grid; min-width: 0; min-height: 0; grid-template-columns: minmax(0,1fr) 310px; }
.battlefield { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #667953; isolation: isolate; }
#gameCanvas { display: block; width: 100%; height: 100%; }
.battle-message { position: absolute; top: 16px; left: 50%; z-index: 7; min-width: 190px; padding: 10px 16px; border: 1px solid #c89940; border-radius: 4px; color: #30230a; background: #f0c660; font-weight: 800; text-align: center; transform: translateX(-50%); }
.screen-layer { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(20,30,24,.66); }
.screen-layer.is-hidden { pointer-events: none; opacity: 0; transition: opacity 180ms ease; }
.screen-content { display: grid; width: min(430px,calc(100% - 32px)); justify-items: center; text-align: center; }
.screen-content > p { margin: 0 0 13px; color: #f0c660; }
.screen-content h1 { margin: 0; font-size: clamp(40px,7vh,66px); line-height: 1; }
.screen-content > span { margin: 14px 0 23px; color: #d7dfd4; font-size: 14px; }
.result { display: grid; width: min(290px,100%); margin-bottom: 20px; grid-template-columns: 1fr 1fr; border-top: 1px solid #78877d; border-bottom: 1px solid #78877d; }
.result div { display: grid; gap: 3px; padding: 12px; }
.result div + div { border-left: 1px solid #67766c; }
.result small { color: #b9c5bc; }
.result strong { font-family: "SFMono-Regular", Consolas, monospace; font-size: 20px; }
.primary-button { display: flex; height: 46px; align-items: center; gap: 9px; padding: 0 22px; border: 1px solid #af8230; border-radius: 5px; color: #241a08; background: var(--gold); font-weight: 800; cursor: pointer; }

.shop { display: grid; min-width: 0; min-height: 0; grid-template-rows: 62px minmax(0,1fr) 42px; border-left: 1px solid var(--line); background: #17221c; }
.shop-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.shop-header > div { display: grid; gap: 3px; }
.shop-header > div > span { color: #dce5dc; font-size: 12px; }
.shop-header strong { color: var(--muted); font-size: 10px; font-weight: 500; }
.shop-coins { display: flex; align-items: center; gap: 6px; color: var(--gold) !important; }
.shop-coins i { font-style: normal; }
.shop-coins b { font-family: "SFMono-Regular", Consolas, monospace; font-size: 15px; }
.unit-list { display: grid; align-content: start; overflow-y: auto; }
.unit-item { display: grid; min-height: 82px; grid-template-columns: 44px minmax(0,1fr) 26px 48px; align-items: center; gap: 9px; padding: 10px 12px; border: 0; border-bottom: 1px solid #304137; color: inherit; background: transparent; text-align: left; cursor: pointer; }
.unit-item:hover:not(:disabled) { background: var(--panel); }
.unit-item:disabled { opacity: .45; cursor: default; }
.unit-icon { position: relative; display: block; width: 42px; height: 42px; border: 1px solid #52675a; border-radius: 5px; background: var(--panel-raised); }
.unit-icon::before { position: absolute; top: 6px; left: 14px; width: 13px; height: 13px; border-radius: 50%; background: #d9ad86; content: ""; }
.unit-icon::after { position: absolute; bottom: 5px; left: 11px; width: 20px; height: 17px; background: #668ca3; content: ""; }
.female-icon::before { box-shadow: 8px 4px 0 -3px #744b35; }
.female-icon::after { background: #9a6aa5; }
.archer-icon::after { background: #6e8a48; }
.archer-icon i::before {
  position: absolute;
  z-index: 2;
  top: 20px;
  left: 8px;
  width: 22px;
  height: 17px;
  border: 2px solid #d7c58e;
  border-left: 0;
  border-radius: 0 50% 50% 0;
  content: "";
}
.crossbow-icon::after { background: #7c6a45; }
.crossbow-icon i::before,
.crossbow-icon i::after {
  position: absolute;
  z-index: 2;
  top: 24px;
  left: 7px;
  width: 28px;
  height: 2px;
  background: #d7c58e;
  content: "";
}
.crossbow-icon i::after { transform: rotate(90deg) scaleX(.55); }
.bed-crossbow-icon::before {
  top: 24px;
  left: 4px;
  width: 34px;
  height: 10px;
  border-radius: 2px;
  background: #6e573a;
}
.bed-crossbow-icon::after {
  bottom: 3px;
  left: 5px;
  width: 32px;
  height: 8px;
  border-radius: 50%;
  background: #353b34;
}
.bed-crossbow-icon i::before,
.bed-crossbow-icon i::after {
  position: absolute;
  z-index: 2;
  top: 8px;
  left: 4px;
  width: 34px;
  height: 17px;
  border: 3px solid #c39a61;
  border-top: 0;
  border-radius: 0 0 50% 50%;
  content: "";
}
.bed-crossbow-icon i::after {
  top: 16px;
  height: 2px;
  border: 0;
  background: #d9c496;
}
.cavalry-icon::after { bottom: 7px; left: 5px; width: 31px; height: 13px; border-radius: 8px 3px 3px 8px; background: #9b744d; }
.mountain-icon::after { background: #526b43; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.sailor-icon::before { border-radius: 50% 50% 20% 20%; box-shadow: 0 -4px 0 #d7e5ef; }
.sailor-icon::after { background: #477c9b; }
.heavy-icon::after { left: 7px; width: 28px; border-radius: 12px 12px 4px 4px; background: #596159; }
.ladder-icon i::before,
.ladder-icon i::after {
  position: absolute;
  z-index: 2;
  top: 8px;
  left: 8px;
  width: 3px;
  height: 28px;
  background: #c69458;
  content: "";
  transform: rotate(-12deg);
}
.ladder-icon i::after { left: 27px; }
.catapult-icon::before { top: 23px; left: 6px; width: 30px; height: 11px; border-radius: 2px; background: #80633f; }
.catapult-icon::after { bottom: 3px; left: 7px; width: 28px; height: 8px; border-radius: 50%; background: #383d35; }
.special-icon::before { background: #48564c; }
.special-icon::after { background: #354c3c; }
.tank-icon::before { top: 10px; left: 17px; width: 18px; height: 5px; border-radius: 1px; background: #3e5140; }
.tank-icon::after { bottom: 7px; left: 5px; width: 31px; height: 21px; border-radius: 3px; background: #62775f; }
.unit-copy { display: grid; min-width: 0; gap: 4px; }
.unit-copy strong { font-size: 13px; }
.unit-copy small { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.unit-count { color: #cbd8cd; font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; text-align: center; }
.buy-mark { display: grid; height: 28px; place-items: center; border: 1px solid #8d6c2e; border-radius: 4px; color: #f0c660; font-size: 10px; }
.shop-feedback { display: grid; margin: 0; place-items: center start; padding: 0 13px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.shop-feedback.is-error { color: #ef8b7f; }

@media (max-width: 920px) {
  .game-app { grid-template-rows: 104px minmax(0,1fr); }
  .topbar { grid-template-columns: 38px minmax(0,1fr) auto; grid-template-rows: 54px 50px; gap: 0 9px; padding: 0 12px; }
  .icon-button { width: 34px; height: 34px; }
  .brand-mark { width: 28px; height: 28px; }
  .brand strong { font-size: 14px; }
  .metrics { grid-area: 2/1/3/4; width: calc(100% + 24px); height: 50px; margin-left: -12px; grid-template-columns: repeat(4,minmax(52px,1fr)) minmax(82px,1.25fr); }
  .metrics > div { gap: 2px; padding: 0 7px; }
  .metrics strong { font-size: 14px; }
  .base-bar { width: min(70px,100%); }
  .workspace { grid-template-columns: minmax(0,1fr); grid-template-rows: minmax(280px,1fr) 188px; }
  .shop { grid-template-rows: 40px minmax(0,1fr) 30px; border-top: 1px solid var(--line); border-left: 0; }
  .shop-header { padding: 0 10px; }
  .shop-header strong { display: none; }
  .unit-list { display: flex; overflow-x: auto; overflow-y: hidden; }
  .unit-item { min-width: 170px; min-height: 116px; grid-template-columns: 42px minmax(0,1fr); grid-template-rows: 45px 28px; gap: 5px 8px; border-right: 1px solid #304137; border-bottom: 0; padding: 8px; }
  .unit-count { grid-area: 2/1; }
  .buy-mark { grid-area: 2/2; }
  .shop-feedback { padding: 0 10px; }
}

@media (max-width: 520px) {
  .brand-mark, .brand small { display: none; }
  .metrics span { font-size: 8px; }
  .metrics strong { font-size: 13px; }
  .workspace { grid-template-rows: minmax(240px,1fr) 178px; }
  .screen-content { transform: translateY(-10px); }
  .screen-content h1 { font-size: 40px; }
}
