@font-face {
  font-family: "Norwester";
  src: url("assets/norwester.woff") format("woff");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --page: #080808;
  --ink: #f2f1dc;
  --line: rgba(239, 237, 199, 0.24);
  --line-soft: rgba(239, 237, 199, 0.1);
  --line-strong: rgba(239, 237, 199, 0.54);
  --toggle-bg: rgba(8, 8, 8, 0.8);
  --accent: #f1ec91;
  --danger: #fc383d;
  --grain-opacity: 0.055;
  --grain-blend: screen;
}

:root[data-theme="light"] {
  color-scheme: light;
  --page: #fafaf8;
  --ink: #171714;
  --line: rgba(25, 25, 22, 0.3);
  --line-soft: rgba(25, 25, 22, 0.12);
  --line-strong: rgba(25, 25, 22, 0.6);
  --toggle-bg: rgba(250, 250, 248, 0.9);
  --accent: #7c7021;
  --danger: #c82730;
  --grain-opacity: 0.045;
  --grain-blend: multiply;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 280px;
  min-height: 100%;
  background: var(--page);
}

body {
  min-width: 280px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: "Gill Sans MT", "Gill Sans", "Malgun Gothic", Arial, sans-serif;
  transition: background-color 260ms ease-out, color 260ms ease-out;
}

body::after {
  position: fixed;
  inset: -64px;
  z-index: 10;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cfilter id='grain'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23grain)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  mix-blend-mode: var(--grain-blend);
  opacity: var(--grain-opacity);
  animation: grain-refresh 0.8s ease-out infinite;
  content: "";
}

@keyframes grain-refresh {
  0%, 100% { transform: translate(0, 0); }
  12.5% { transform: translate(-28px, 17px); }
  25% { transform: translate(31px, -20px); }
  37.5% { transform: translate(-12px, -33px); }
  50% { transform: translate(23px, 29px); }
  62.5% { transform: translate(-37px, -14px); }
  75% { transform: translate(11px, 38px); }
  87.5% { transform: translate(38px, -29px); }
}

button {
  font: inherit;
}

.combat[hidden] { display: none; }
.combat { position: fixed; inset: 0; z-index: 6; display: flex; flex-direction: column; background: #101010; color: #f2f1dc; padding: clamp(12px, 2vw, 24px); gap: 10px; }
.combat__bar { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.combat__status { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.combat__attack-controls { display: flex; flex-wrap: wrap; gap: 4px; }
.combat__exit, .combat__pad button, .combat__attack-controls button { border: 1px solid #827e59; background: #171717; color: #f2f1dc; padding: 8px 12px; cursor: pointer; }
.combat__attack-controls button { font-size: 12px; }
.combat__attack-controls [data-attack-type][aria-pressed="true"] { border-color: #ede792; background: #47432a; color: #fffce0; }
.combat__exit { flex: none; }
.combat__exit:focus-visible, .combat__pad button:focus-visible, .combat__attack-controls button:focus-visible { outline: 2px solid #fc383d; }
.combat__viewport { flex: 1; min-height: 0; min-width: 0; display: flex; overflow: hidden; }
.combat__canvas { display: block; flex: 1; width: 100%; height: 100%; min-width: 0; min-height: 0; background: #191919; touch-action: none; }
.combat__canvas:focus-visible { outline: 2px solid #fc383d; outline-offset: 2px; }
@media (pointer: fine) { .combat__canvas { cursor: none; } }
.combat__controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.combat__pad { display: flex; gap: 4px; }
.combat__pad button { min-width: 42px; min-height: 42px; touch-action: none; }
.title-row h1 { font-size: clamp(17px, 2.3vw, 28px); text-align: center; }
.settings[hidden] { display: none; }
.settings { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(0,0,0,.82); color: #eeeccc; }
.settings__panel { position: relative; width: min(100%, 520px); max-height: min(88vh, 720px); overflow: auto; padding: clamp(20px, 4vw, 32px); border: 1px solid #777454; background: #151514; box-shadow: 0 0 0 5px #0b0b0b, 0 22px 65px rgba(0,0,0,.65); }
.settings__panel::before { position: absolute; top: 0; left: 0; width: 76px; height: 3px; background: #e9df85; content: ''; }
.settings__heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-bottom: 18px; border-bottom: 1px solid #4d4c3c; }
.settings__heading h2 { margin: 0; color: #f4f1d6; font-size: 21px; font-weight: 700; letter-spacing: .1em; }
.settings button, .combat__settings { border: 1px solid #4b4a3c; background: #1d1d1b; color: #e8e6ce; padding: 10px 13px; cursor: pointer; transition: color 160ms ease-out, background-color 160ms ease-out, border-color 160ms ease-out; }
.settings button:hover { border-color: #b0a976; color: #fffdea; }
.settings button[aria-pressed="true"] { border-color: #d1c779; background: #373629; color: #fffbd1; }
.settings button:focus-visible, .combat__settings:focus-visible { outline: 2px solid #fc383d; outline-offset: 2px; }
.settings .settings-close { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; font-size: 23px; line-height: 1; }
.settings__section { padding: 20px 0; border-bottom: 1px solid #32322c; }
.settings__section h3 { margin: 0 0 11px; color: #a9a78e; font-size: 12px; font-weight: 600; letter-spacing: .08em; }
.settings select { width: 100%; padding: 12px; margin-bottom: 10px; background: #23231e; color: #f5eebd; border: 1px solid #777454; font: inherit; }
.settings select:focus-visible { outline: 2px solid #fc383d; }
.equipment-preview[hidden] { display: none; }
.equipment-preview { min-height: 84px; display: flex; align-items: center; justify-content: center; padding: 12px; margin: 0 0 12px; background: #1e1e1a; border: 1px solid #32322c; }
.equipment-preview__sprite { display: block; max-width: 100%; max-height: 124px; object-fit: contain; image-rendering: pixelated; }
.settings .combat__attack-controls, .settings__modes, .settings__actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin: 0; }
.settings .combat__attack-controls button { display: flex; align-items: center; gap: 10px; min-height: 46px; text-align: left; font-size: 13px; }
.settings__key { display: grid; flex: 0 0 24px; height: 24px; place-items: center; border: 1px solid #5d5b48; color: #bcb99c; font-size: 11px; }
.settings [aria-pressed="true"] .settings__key { border-color: #d1c779; color: #fff2a5; }
.settings__modes button, .settings__actions button { min-height: 42px; font-size: 13px; text-align: left; }
.settings__footer { display: flex; justify-content: flex-end; padding-top: 18px; }
.settings__footer:has(> [hidden]) { display: none; }
.settings .combat__exit { color: #e7a6a3; border-color: #694747; }
.settings-open + .settings-open { margin-left: 8px; }
.combat__bar { position: absolute; left: 24px; top: 24px; z-index: 3; }
.combat__viewport { position: relative; }
.touch-controls { display: none; position: absolute; inset: 0; pointer-events: none; }
.combat__revive { position: absolute; top: calc(70% + 28px); left: 50%; transform: translateX(-50%); min-width: 120px; min-height: 44px; border: 1px solid #9b805f; background: #1b1715; color: #eee2c6; cursor: pointer; transition: background-color 160ms ease-out, border-color 160ms ease-out; }
.combat__revive[hidden] { display: none; }
.combat__revive:hover { background: #35211e; border-color: #da7f6f; }
.combat__revive:focus-visible { outline: 2px solid #f2cc79; outline-offset: 4px; }
@media (any-pointer: coarse) { .touch-controls[data-mode="manual"] { display: block; } }
.joystick { position: absolute; bottom: 7%; width: clamp(92px, 20vw, 140px); aspect-ratio: 1; border: 1px solid rgba(240,235,170,.65); border-radius: 50%; background: rgba(20,20,18,.52); touch-action: none; pointer-events: auto; }
.joystick--move { left: 5%; } .joystick--aim { right: 5%; }
.joystick { bottom: max(24px,env(safe-area-inset-bottom)); width: clamp(96px,18vmin,132px); }
.joystick--move { left: max(24px,env(safe-area-inset-left)); }
.joystick--aim { right: max(24px,env(safe-area-inset-right)); }
.touch-cooldown { position: absolute; left: 0; right: 0; top: -15px; height: 5px; background: #322c28; border: 1px solid #9a8e67; pointer-events: none; }
.touch-cooldown__fill { height: 100%; background: #f0d586; transform-origin: left; transition: transform 70ms ease-out; }
.touch-run { display: none; position: absolute; right: calc(max(24px,env(safe-area-inset-right)) + clamp(96px,18vmin,132px)); bottom: calc(max(24px,env(safe-area-inset-bottom)) + clamp(96px,18vmin,132px) - 15px); min-width: 64px; min-height: 44px; border: 1px solid #a69d70; background: #22211c; color: #eee8bc; touch-action: manipulation; }
.touch-run[aria-pressed="true"] { background: #5a4924; border-color: #f0d586; }
.touch-run:focus-visible { outline: 2px solid #f0d586; }
@media (any-pointer:coarse) { .touch-run { display: block; } }
.combat[data-input="touch"] .touch-run, .combat[data-input="touch"] .touch-controls[data-mode="manual"] { display:block; }
.joystick span { position: absolute; width: 34%; height: 34%; left: 33%; top: 33%; border: 1px solid #f0eaaa; border-radius: 50%; background: rgba(235,230,160,.34); }

.perimeter {
  position: fixed;
  inset: clamp(14px, 2.5vw, 34px);
  z-index: 1;
  border: 1px solid var(--line-soft);
  pointer-events: none;
}

.perimeter__corner {
  position: absolute;
  width: 30px;
  height: 30px;
  border-color: var(--line-strong);
  border-style: solid;
}

.perimeter__corner--tl { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.perimeter__corner--tr { top: -1px; right: -1px; border-width: 2px 2px 0 0; }
.perimeter__corner--bl { bottom: -1px; left: -1px; border-width: 0 0 2px 2px; }
.perimeter__corner--br { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }

.topbar {
  position: absolute;
  top: clamp(27px, 4vw, 51px);
  right: clamp(28px, 4vw, 54px);
  left: clamp(28px, 4vw, 54px);
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 18px;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar__emblem {
  position: relative;
  display: block;
  width: 34px;
  flex: 0 0 34px;
  aspect-ratio: 180 / 200;
  overflow: hidden;
  background: #000;
}

.topbar__name {
  font-family: "Norwester", "Arial Narrow", sans-serif;
  font-size: clamp(16px, 1.8vw, 21px);
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.035em;
  white-space: nowrap;
}

.topbar__line {
  flex: 1;
  min-width: 0;
  height: 1px;
  background: var(--line);
}

.theme-toggle {
  display: grid;
  width: 43px;
  height: 43px;
  flex: 0 0 43px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--toggle-bg);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 180ms ease-out, color 180ms ease-out, background-color 180ms ease-out;
}

.theme-toggle:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.theme-toggle:focus-visible,
.logo-button:focus-visible,
.placeholder-button:focus-visible {
  outline: 3px solid var(--danger);
  outline-offset: 4px;
}

.theme-toggle svg {
  width: 19px;
  height: 19px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.theme-toggle__moon,
:root[data-theme="light"] .theme-toggle__sun {
  display: none;
}

:root[data-theme="light"] .theme-toggle__moon {
  display: block;
}

.stage {
  position: relative;
  z-index: 2;
  display: grid;
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  place-items: center;
  padding: 96px 28px 108px;
}

.title-block {
  position: relative;
  width: min(520px, 100%);
  text-align: center;
}

.plate {
  width: min(360px, 100%);
  margin-inline: auto;
  padding: 8px;
  border: 1px solid var(--line-strong);
  background: #090909;
  box-shadow: 0 18px 80px rgba(0, 0, 0, 0.3);
}

:root[data-theme="light"] .plate {
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.14);
}

.plate__cap {
  display: flex;
  height: 14px;
  align-items: center;
  gap: 9px;
  padding: 0 3px;
}

.plate__cap-stripes {
  width: 76px;
  height: 6px;
  background: repeating-linear-gradient(125deg, #e8e291 0 6px, transparent 6px 11px);
  opacity: 0.8;
}

.plate__cap-line {
  flex: 1;
  height: 1px;
  background: rgba(239, 237, 199, 0.32);
}

.plate__lights {
  display: flex;
  gap: 4px;
}

.plate__lights i {
  display: block;
  width: 5px;
  height: 5px;
  background: #6c694c;
  transition: background-color 180ms ease-out, box-shadow 180ms ease-out;
}

.plate__lights i:first-child { background: #f44443; }

.plate:has(.logo-button:hover) .plate__lights i,
.plate:has(.logo-button:focus-visible) .plate__lights i,
.plate:has(.logo-button.is-active) .plate__lights i {
  background: #f1ec91;
  box-shadow: 0 0 8px rgba(241, 236, 145, 0.8);
}

.logo-button {
  position: relative;
  display: grid;
  width: 100%;
  place-items: center;
  padding: clamp(6px, 1.6vw, 17px) clamp(9px, 2.1vw, 22px);
  border: 1px solid rgba(239, 237, 199, 0.24);
  border-radius: 0;
  background: #000;
  cursor: pointer;
  transition: border-color 180ms ease-out, box-shadow 180ms ease-out;
}

.logo-button:hover,
.logo-button:focus-visible,
.logo-button.is-active {
  border-color: #f1ec91;
  box-shadow: inset 0 0 34px rgba(241, 236, 145, 0.14), 0 0 20px rgba(241, 236, 145, 0.13);
}

.logo-button.is-active {
  border-color: #ff4545;
  box-shadow: inset 0 0 38px rgba(255, 58, 62, 0.25), 0 0 24px rgba(255, 58, 62, 0.25);
}

.logo-button__image-window {
  position: relative;
  display: block;
  width: min(180px, 80%);
  aspect-ratio: 180 / 200;
  overflow: hidden;
}

.topbar__emblem img,
.logo-button__image-window img {
  position: absolute;
  top: -23.5%;
  left: 0;
  display: block;
  width: 342.2222%;
  max-width: none;
  height: auto;
  user-select: none;
}

.plate__foot {
  display: flex;
  height: 8px;
  align-items: end;
  gap: 4px;
  padding: 0 3px;
}

.plate__foot span { height: 2px; background: rgba(239, 237, 199, 0.4); }
.plate__foot span:first-child { width: 16px; background: #f44443; }
.plate__foot span:nth-child(2) { width: 28px; }
.plate__foot span:last-child { flex: 1; opacity: 0.35; }

.title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 32px);
  margin-top: clamp(26px, 4vw, 38px);
}

.title-row__line {
  width: min(17%, 108px);
  height: 1px;
  background: var(--line-strong);
}

h1 {
  margin: 0;
  font-family: "Gill Sans MT", "Gill Sans", "Malgun Gothic", Arial, sans-serif;
  font-size: clamp(23px, 3.4vw, 39px);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 0.06em;
}

.placeholder-button {
  position: relative;
  min-width: 152px;
  min-height: 46px;
  margin-top: 25px;
  padding: 10px 30px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--toggle-bg);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: border-color 180ms ease-out, color 180ms ease-out, background-color 180ms ease-out;
}

.placeholder-button::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 4px;
  background: var(--danger);
  content: "";
}

.placeholder-button:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.placeholder-button.is-active {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.bottom-rail {
  position: absolute;
  right: clamp(44px, 5vw, 70px);
  bottom: clamp(28px, 4vw, 49px);
  left: clamp(44px, 5vw, 70px);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.bottom-rail__stripes {
  width: 72px;
  height: 6px;
  background: repeating-linear-gradient(125deg, var(--line-strong) 0 5px, transparent 5px 10px);
}

.bottom-rail__line { flex: 1; height: 1px; background: var(--line); }
.bottom-rail__end { width: 20px; height: 4px; background: var(--danger); }

@media (max-width: 600px) {
  .combat__controls { flex-wrap: wrap; justify-content: center; }
  .combat__controls > span { flex: 1 0 100%; text-align: center; }
  .perimeter { inset: 12px; }
  .perimeter__corner { width: 20px; height: 20px; }
  .topbar { top: 27px; right: 27px; left: 27px; gap: 8px; }
  .topbar__brand { gap: 7px; }
  .topbar__emblem { width: 29px; flex-basis: 29px; }
  .topbar__name { font-size: 15px; letter-spacing: 0.015em; }
  .theme-toggle { width: 40px; height: 40px; flex-basis: 40px; }
  .stage { padding: 90px 24px 100px; }
  .plate { padding: 6px; }
  .plate__cap-stripes { width: 46px; }
  .title-row { gap: 12px; }
  .title-row__line { width: 9%; }
  h1 { font-size: clamp(20px, 6vw, 28px); letter-spacing: 0.035em; }
  .bottom-rail { right: 30px; bottom: 29px; left: 30px; }
}

@media (max-width: 360px) {
  .topbar__emblem { width: 25px; flex-basis: 25px; }
  .topbar__name { font-size: 12px; letter-spacing: 0; }
}

@media (max-height: 520px) and (min-width: 601px) {
  .stage { padding: 78px 24px 65px; }
  .title-block { width: min(500px, 66vw); }
  .title-row { margin-top: 15px; }
  h1 { font-size: 24px; }
  .placeholder-button { margin-top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  body::after {
    animation: none !important;
  }
}

.combat[data-input="mouse"] .touch-controls, .combat[data-input="mouse"] .touch-run { display:none !important; }

.connection-status{position:fixed;bottom:36px;left:0;width:100%;text-align:center;color:#e0ce91;z-index:15;pointer-events:none}
.announcement{position:fixed;top:76px;left:50%;transform:translateX(-50%);max-width:min(600px,90vw);padding:12px 22px;background:#171713ed;border:1px solid #b7aa6d;color:#f5efd0;z-index:100;white-space:pre-wrap;overflow-wrap:anywhere}
.settings__section input{display:block;box-sizing:border-box;max-width:100%;width:100%;background:#171714;color:#eee8d0;border:1px solid #817c54;padding:8px;margin:6px 0 12px}
.settings__section label{display:block;margin-top:10px}.settings__panel{max-height:88dvh;overflow-y:auto}
[hidden]{display:none!important}
