@font-face {
  font-family: 'Pixelify Sans';
  src: url('assets/fonts/PixelifySans.ttf') format('truetype');
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
}

.village-page {
  --pixel-ink: #19252a;
  --pixel-panel: #293a40;
  --pixel-edge: #849087;
  --pixel-light: #efdbad;
  --pixel-corners: polygon(4px 0, calc(100% - 4px) 0, calc(100% - 4px) 4px, 100% 4px, 100% calc(100% - 4px), calc(100% - 4px) calc(100% - 4px), calc(100% - 4px) 100%, 4px 100%, 4px calc(100% - 4px), 0 calc(100% - 4px), 0 4px, 4px 4px);
  background: #202f32;
  font-family: 'Pixelify Sans', ui-monospace, monospace;
}
.village-game { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh; height: 100dvh; overflow: hidden; }
.game-bar { position: relative; z-index: 3; border-bottom: 2px solid #576f66; background: var(--pixel-ink); color: #f0e6c9; }
.game-bar-inner { display: grid; grid-template-columns: auto minmax(0, 1fr) clamp(145px, 15vw, 200px) auto; align-items: center; gap: 5px clamp(12px, 2vw, 30px); max-width: 1580px; margin-inline: auto; padding: 6px clamp(12px, 2vw, 28px); }
.game-location { display: flex; align-items: center; gap: 9px; min-width: 0; }
.game-home { display: grid; flex: none; place-items: center; width: 34px; height: 34px; border: 1px solid #8d7381; background: #393143; box-shadow: inset 0 -2px #292331; }
.game-home:hover { border-color: #e4c17f; }
.game-home img { width: 100%; height: 100%; image-rendering: pixelated; }
.game-zone h1 { color: var(--pixel-light); font-size: clamp(1rem, 1.4vw, 1.25rem); line-height: 1.05; overflow-wrap: anywhere; }
.stage-number { margin-bottom: 2px; color: #c7a87b; font-size: .75rem; line-height: 1; }
.stage-objective { display: flex; align-items: center; justify-self: center; gap: 8px; min-width: 0; font-size: .85rem; line-height: 1.15; }
.stage-direction { display: grid; flex: none; place-items: center; width: 24px; height: 24px; border: 1px solid #665745; color: #f9c679; background: #282b2a; font: 700 .95rem/1 ui-monospace, monospace; }
.stage-direction:empty { display: none; }
#stage-foe { color: #e8d7ab; }
#stage-remaining { display: block; margin-top: 2px; color: #c5cec5; }
#stage-remaining:empty { display: none; }
.player-progress { display: grid; gap: 4px; min-width: 0; }
.progress-heading { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: baseline; gap: 5px; font-size: .82rem; line-height: 1; }
.progress-heading strong { color: #e9cb88; white-space: nowrap; }
#experience-value, #experience-gain { grid-area: 1 / 2; justify-self: end; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#experience-value { color: #dcc9eb; }
.progress-heading:has(#experience-gain:not(:empty)) #experience-value { visibility: hidden; }
#experience-gain { color: #dcabe5; font-size: .76rem; }
#experience-gain[data-level-up] { color: #f4d892; }
#experience-bar { display: block; appearance: none; width: 100%; height: 7px; border: 1px solid #776b84; border-radius: 0; background: #121c24; }
#experience-bar::-webkit-progress-bar { background: #121c24; }
#experience-bar::-webkit-progress-value { background: linear-gradient(#e1b1fa 0 1px, #ad78d5 1px 100%); }
#experience-bar::-moz-progress-bar { background: linear-gradient(#e1b1fa 0 1px, #ad78d5 1px 100%); }

.village-stage { --orb-size: clamp(52px, 14vw, 94px); --slot-size: clamp(40px, 10vw, 60px); --hud-height: calc(var(--orb-size) + 32px); position: relative; isolation: isolate; min-height: 0; overflow: hidden; }
#world { display: block; width: 100%; height: 100%; outline-offset: -4px; image-rendering: pixelated; cursor: crosshair; touch-action: manipulation; }
#world:focus-visible { outline: 2px solid #efdbad; }

.village-status, .village-defeat {
  border: 2px solid var(--pixel-edge);
  background: var(--pixel-ink);
  color: #f0e6c9;
  box-shadow: inset 0 2px #384c4e, inset 0 -3px #101d23;
  clip-path: var(--pixel-corners);
}
.village-tool-actions { display: flex; align-items: center; gap: 6px; }
.village-tool-actions button, .game-diagnostics button, .direction-pad button, .village-defeat button, .village-menu button, .village-menu select, .menu-actions a {
  color: #eee4c8;
  border: 2px solid var(--pixel-edge);
  border-radius: 0;
  background: var(--pixel-panel);
  box-shadow: inset 0 2px #425658, inset 0 -3px #19282c;
  font-weight: 600;
}
.village-tool-actions button { min-height: 34px; padding: 0 9px; font-size: .9rem; white-space: nowrap; }
.village-defeat button { min-height: 38px; padding: 0 13px; font-size: 1rem; }
.village-tool-actions button:hover:not(:disabled), .game-diagnostics button[aria-pressed="true"], .game-diagnostics button:hover:not(:disabled), .direction-pad button[data-pressed], .village-defeat button:hover, .village-menu button:hover, .menu-actions a:hover { border-color: #e4c17f; background: #525044; }
#menu-toggle { display: flex; align-items: center; gap: 5px; }
#menu-toggle kbd { min-width: 18px; padding: 0 3px; border: 1px solid #a28c6b; color: #f3d9a4; font: 600 .8em/1.25 'Pixelify Sans', monospace; box-shadow: 0 1px #15242a; }
#stats-badge { display: inline-grid; place-items: center; min-width: 1.35em; padding: 0 3px; color: #231b18; background: #e2b973; font-weight: 700; }
.game-diagnostics { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; min-width: 0; padding-top: 4px; border-top: 1px solid #384c4e; font-size: .78rem; line-height: 1.2; }
.game-diagnostics button { flex: none; padding: 3px 7px; border-width: 1px; }
#collision-readout { color: #c5cec5; font-variant-numeric: tabular-nums; }
.village-instructions { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px 12px; color: #c5cec5; font-size: .85rem; text-align: center; }
.village-instructions kbd { display: inline-block; padding: 1px 4px; border: 1px solid #6a7b78; background: #364a4c; color: #f0e6c9; box-shadow: inset 0 -2px #1c2a30; font-family: inherit; }

.combat-hud { position: absolute; z-index: 2; bottom: 0; left: 50%; transform: translateX(-50%); isolation: isolate; display: grid; grid-template-columns: var(--orb-size) auto var(--orb-size); align-items: end; gap: clamp(4px, 1.3vw, 16px); width: max-content; padding: 0 9px clamp(7px, 1.2vw, 12px); pointer-events: none; }
.combat-hud::before { content: ''; position: absolute; z-index: -1; inset: auto 0 0; height: 77%; border: 2px solid #9d8058; background: repeating-linear-gradient(90deg, transparent 0 17px, #e0bd7323 17px 19px, transparent 19px 36px), linear-gradient(#514033, #272827 27%, #111b22 79%, #352a26); box-shadow: inset 0 3px #deb47a, inset 0 6px #302727, inset 0 -5px #101719; clip-path: var(--pixel-corners); }
.vital { --level: 100%; --orb-cut: polygon(37% 0, 63% 0, 63% 4%, 75% 4%, 75% 9%, 85% 9%, 85% 15%, 91% 15%, 91% 25%, 96% 25%, 96% 37%, 100% 37%, 100% 63%, 96% 63%, 96% 75%, 91% 75%, 91% 85%, 85% 85%, 85% 91%, 75% 91%, 75% 96%, 63% 96%, 63% 100%, 37% 100%, 37% 96%, 25% 96%, 25% 91%, 15% 91%, 15% 85%, 9% 85%, 9% 75%, 4% 75%, 4% 63%, 0 63%, 0 37%, 4% 37%, 4% 25%, 9% 25%, 9% 15%, 15% 15%, 15% 9%, 25% 9%, 25% 4%, 37% 4%); position: relative; display: grid; gap: 4px; text-align: center; color: var(--vital-label); }
.vital-health { --vital-light: #ff987a; --vital-fill: #d13949; --vital-deep: #4e162b; --vital-label: #ffc9b9; }
.vital-mana { --vital-light: #a8dfff; --vital-fill: #3a80dc; --vital-deep: #17265c; --vital-label: #c4e8ff; }
.vital-orb { position: relative; isolation: isolate; display: grid; place-items: center; aspect-ratio: 1; clip-path: var(--orb-cut); background: linear-gradient(155deg, #edcc91 7%, #896747 29%, #b99863 52%, #3a3030 74%, #8a6a4d 94%); }
.vital-glass { position: absolute; z-index: -1; inset: clamp(4px, .7vw, 8px); isolation: isolate; clip-path: var(--orb-cut); background: radial-gradient(circle at 34% 25%, #36424b, #171e29 50%, #0c111a); box-shadow: inset 0 0 8px 3px #090e17; }
.vital-glass::before { content: ''; position: absolute; inset: 0; clip-path: inset(calc(100% - var(--level)) 0 0); background: radial-gradient(ellipse at 36% 25%, var(--vital-light), var(--vital-fill) 39%, var(--vital-deep) 90%); }
.vital-glass::after { content: ''; position: absolute; inset: 0; background: linear-gradient(#f2eeff38, #f2eeff05) 24% 20% / 26% 7% no-repeat, linear-gradient(#f2eeff55, #f2eeff20) 21% 33% / 8% 7% no-repeat; box-shadow: inset 0 -5px 10px #080e1bb8; }
.vital-orb > span { margin-top: 12%; color: #fff4e8; font-size: clamp(.76rem, 2.75vw, 1.35rem); font-variant-numeric: tabular-nums; font-weight: 700; text-shadow: 0 2px #101722, 1px 0 #101722, -1px 0 #101722; }
.vital-caption { font-size: clamp(.7rem, 2.25vw, .93rem); font-weight: 700; line-height: 1.15; text-shadow: 0 1px #0d131a; }
.vital-health[data-low] .vital-orb > span { color: #ffccac; }
.spellbar { position: relative; margin-bottom: 5px; padding: 5px; border: 2px solid #80684f; background: #141c25; box-shadow: inset 0 2px #c1985e, 0 3px #0a1217; pointer-events: auto; }
.spell-slots { display: grid; grid-template-columns: repeat(4, var(--slot-size)); gap: clamp(3px, .75vw, 9px); }
.spell-slot { --spell-accent: #e99168; position: relative; isolation: isolate; display: grid; place-items: center; aspect-ratio: 1; min-width: 0; padding: 0; touch-action: manipulation; border: 2px solid #79614d; color: #f8e4c8; text-align: center; background: radial-gradient(ellipse at 50% 55%, color-mix(in srgb, var(--spell-accent) 25%, #171a26), #1d222a 74%); box-shadow: inset 0 2px #fff2ce21, inset 0 -3px #0c141b; }
.spell-slot[data-spell="ward"] { --spell-accent: #a1c4fb; }
.spell-slot[data-spell="pulse"] { --spell-accent: #df9be6; }
.spell-slot[data-spell="turret"] { --spell-accent: #e6bd72; }
.spell-slot img { width: 85%; aspect-ratio: 1; object-fit: contain; image-rendering: pixelated; }
.spell-slot[data-spell="volley"] img { transform: rotate(-28deg) scale(1.15); }
.spell-slot:hover, .spell-slot:focus-visible { border-color: var(--spell-accent); z-index: 2; }
.spell-slot[data-state="mana"] img, .spell-slot[data-state="dead"] img { opacity: .43; }
.spell-key, .spell-cost { position: absolute; z-index: 1; color: #f9e6c5; text-shadow: 0 1px #080c12; }
.spell-key { top: 2px; left: 3px; display: grid; place-items: center; min-width: 1.15em; padding: 0 2px; border: 1px solid #85705b; background: #21252b; font: 700 clamp(.64rem, 1.65vw, .86rem)/1.1 'Pixelify Sans', monospace; }
.spell-cost { bottom: 3px; right: 4px; color: #cbe5ff; font-size: clamp(.67rem, 1.65vw, .85rem); line-height: 1; }
.spell-recharge { position: absolute; inset: 0; background: #090f1acf; transform: scaleY(var(--recharge, 0)); transform-origin: bottom; }
.spell-seconds { position: absolute; font-size: clamp(.93rem, 2vw, 1.3rem); line-height: 1; color: #fff1d5; text-shadow: 0 2px #0b1220; }
.spell-tooltip, .spell-notice { position: absolute; bottom: calc(100% + 10px); left: 50%; width: max-content; transform: translateX(-50%); z-index: 3; border: 1px solid #aa8c64; background: #17242a; box-shadow: 0 3px #0e161b; color: #f2dec2; font-size: .85rem; }
.spell-tooltip { display: none; max-width: 176px; padding: 7px 8px; text-align: left; line-height: 1.3; pointer-events: none; }
.spell-tooltip strong { display: block; color: var(--spell-accent); }
.spell-slot:focus-visible .spell-tooltip { display: block; }
@media (hover: hover) { .spell-slot:hover .spell-tooltip { display: block; } }
.spell-notice { padding: 6px 10px; bottom: calc(100% + 8px); pointer-events: none; }
.spellbar:has(.spell-slot:is(:hover, :focus-visible) .spell-tooltip) .spell-notice { bottom: calc(100% + 102px); }

.village-status { position: absolute; z-index: 3; top: 50%; left: 50%; width: max-content; max-width: calc(100% - 28px); transform: translate(-50%, -50%); padding: 10px 14px; text-align: center; }
.village-defeat { position: absolute; z-index: 3; top: 40%; left: 50%; width: min(332px, calc(100% - 28px)); transform: translate(-50%, -50%); padding: 16px 20px 19px; text-align: center; }
.village-defeat h2 { color: var(--pixel-light); font-size: 2rem; line-height: 1; }
.village-defeat p { margin: 9px 0 14px; }
.stage-result button { border-color: #be9b64; color: #ffedc8; background: #4e493b; }

.village-menu { width: min(412px, calc(100% - 28px)); max-height: calc(100dvh - 28px); padding: clamp(15px, 4vw, 25px); overflow: auto; border: 2px solid #b2956c; color: #f0e6c9; background: linear-gradient(155deg, #2e3d3e, #19252a 52%); box-shadow: inset 0 0 0 3px #101a21, inset 0 0 0 5px #78634c, 0 6px #111b23, 0 12px 35px #060b11a8; }
.village-menu::backdrop { background: radial-gradient(ellipse at center, #111b2561, #0a111bc4); }
.menu-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 11px; border-bottom: 2px solid #526565; box-shadow: 0 2px #0e1c22; }
.menu-header h2 { color: var(--pixel-light); font-size: clamp(1.8rem, 6vw, 2.5rem); line-height: 1; text-shadow: 0 2px #141a23; }
.village-menu .menu-key { width: 37px; height: 37px; padding: 0; color: #f3d59f; }
.menu-actions, .menu-settings, .menu-fields { display: grid; gap: 12px; }
.menu-actions, .menu-settings { margin-top: 17px; }
.menu-actions button, .menu-settings > button, .menu-actions a { min-height: 44px; padding: 7px 10px; }
.menu-actions a { display: grid; place-items: center; text-decoration: none; }
.menu-actions .menu-primary { border-color: #be9b64; color: #ffedc8; background: #4e493b; box-shadow: inset 0 2px #6c6149, inset 0 -3px #282b2a; }
.menu-settings fieldset { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 7px 12px 11px; border: 1px solid #60716e; background: #141f25a3; }
.menu-settings legend { padding: 0 6px; color: #e7c991; font-size: .95rem; }
.menu-setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 28px; }
.menu-setting output { color: #f9d898; font-variant-numeric: tabular-nums; }
.menu-settings select { min-height: 34px; padding: 0 5px; }
.menu-settings input { margin: 0; accent-color: #e1bf84; }
.menu-settings input[type="range"] { width: 100%; min-height: 29px; }
.menu-settings input[type="checkbox"] { width: 19px; height: 19px; }
.stats-instructions { margin-top: 15px; color: #e0d9c5; line-height: 1.4; }
.stats-points { margin: 15px 0 10px; color: #f1cc8b; font-size: 1.05rem; }
.stats-instructions:not([hidden]) + .stats-points { margin-top: 8px; }
.stats-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.stats-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid #60716e; background: #141f25; }
.stats-list strong { color: #eee1bf; font-size: 1.12rem; }
.stats-list strong span { margin-left: 4px; color: #efc78f; }
.stats-list p { margin-top: 2px; color: #c0ccbf; font-size: .88rem; }
.stats-list button { flex: 0 0 38px; min-height: 38px; color: #f3d59f; font-size: 1.3rem; }
.hero-stats button:disabled { border-color: #526565; color: #b4bdb7; background: #243235; box-shadow: none; cursor: default; }

.direction-pad { position: absolute; z-index: 2; display: none; grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(2, 44px); gap: 4px; right: 15px; bottom: var(--hud-height); touch-action: none; }
.direction-pad button { padding: 0; font-size: 1.25rem; }
.direction-pad button:first-child { grid-column: 2; }
.direction-pad button:nth-child(2) { grid-row: 2; grid-column: 1; }
.direction-pad button:nth-child(3) { grid-row: 2; grid-column: 2; }
.direction-pad button:nth-child(4) { grid-row: 2; grid-column: 3; }
.direction-pad .fire-control { grid-row: 1; grid-column: 3; font-size: .85rem; color: #f5d9fe; border-color: #b58bb9; }
@media (max-width: 760px) {
  .game-bar-inner { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; padding: 5px 10px 7px; }
  .stage-objective { grid-area: 2 / 1; justify-self: start; }
  .player-progress { grid-area: 2 / 2; justify-self: end; width: clamp(140px, 31vw, 166px); }
  .progress-heading { font-size: .75rem; }
  .village-tool-actions { grid-area: 1 / 2; justify-self: end; }
  .spellbar { margin-bottom: 2px; padding: 3px; }
}
@media (max-width: 390px) {
  .village-stage { --orb-size: clamp(43px, 15.5vw, 60px); --slot-size: clamp(38px, 10.8vw, 43px); }
  .game-bar-inner { gap: 6px 7px; padding-inline: 7px; }
  .game-location { gap: 6px; }
  .game-home { width: 29px; height: 29px; }
  .game-zone h1 { font-size: .9rem; }
  .stage-objective { gap: 5px; font-size: .78rem; }
  .stage-direction { width: 20px; height: 20px; }
  .progress-heading { font-size: .73rem; }
  #experience-gain { font-size: .68rem; }
  .combat-hud { padding-inline: 5px; }
  .village-tool-actions button { padding-inline: 6px; font-size: .8rem; }
  #menu-toggle kbd { display: none; }
}
@media (max-width: 310px) {
  .game-home { display: none; }
}
@media (max-height: 560px) and (min-width: 641px) {
  .village-stage { --orb-size: 66px; --slot-size: 48px; }
}
@media (any-pointer: coarse) {
  .direction-pad { display: grid; }
}
