:root {
  color-scheme: dark;
  --wi-bg: #030303;
  --wi-panel: rgba(10, 9, 9, 0.9);
  --wi-line: rgba(216, 208, 189, 0.18);
  --wi-red-line: rgba(143, 36, 24, 0.7);
  --wi-text: #ded7c8;
  --wi-muted: #968b78;
  --wi-red: #b44330;
  --wi-danger: #d96b5a;
  --wi-stage-offset: 91px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--wi-text);
  font-family: Georgia, "Times New Roman", serif;
  background:
    radial-gradient(ellipse at 50% 16%, rgba(75, 8, 6, 0.2), transparent 32%),
    radial-gradient(circle at 18% 72%, rgba(31, 38, 54, 0.16), transparent 24%),
    linear-gradient(180deg, #010101 0%, #050403 50%, #000 100%);
}

button,
input {
  font: inherit;
}

button,
a {
  color: var(--wi-text);
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--wi-red);
  outline-offset: 2px;
}

.wi-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  overflow: hidden;
  padding: 10px clamp(10px, 1.5vw, 22px) max(10px, env(safe-area-inset-bottom));
}

.wi-shell::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  content: "";
  pointer-events: none;
  opacity: 0.28;
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.014) 1px, transparent 1px),
    radial-gradient(circle at center, transparent 0 30%, rgba(0, 0, 0, 0.82) 100%);
  background-size: 42px 42px, 42px 42px, 100% 100%;
}

.wi-header {
  width: min(1500px, 100%);
  min-height: 46px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--wi-line);
  padding: 0 2px 8px;
}

.wi-header p,
.screen__eyebrow {
  margin: 0 0 2px;
  color: var(--wi-red);
  font-family: "Arial Narrow", Arial, Helvetica, sans-serif;
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.wi-header h1,
.screen h2 {
  margin: 0;
  color: var(--wi-text);
  font-size: clamp(1.35rem, 2.2vw, 2.15rem);
  line-height: 0.95;
  text-shadow: 0 2px 0 #000, 0 0 24px rgba(75, 8, 6, 0.38);
}

.wi-header a,
.stage-wrap a {
  color: var(--wi-muted);
  font-family: "Arial Narrow", Arial, Helvetica, sans-serif;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
}

.wi-header a:hover,
.stage-wrap a:hover {
  color: var(--wi-text);
}

.wi-layout {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.wi-shell:not(.is-playing) .status-grid {
  display: none;
}

.status-grid {
  width: min(920px, 100%);
  min-height: 44px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(92px, 1.35fr) repeat(4, minmax(72px, 1fr)) minmax(96px, 1.2fr) auto;
  border: 1px solid var(--wi-line);
  border-top-color: var(--wi-red-line);
  background: var(--wi-panel);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.34);
}

.status-grid > div:not(.hud-actions) {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 1px;
  padding: 5px 9px;
  border-right: 1px solid var(--wi-line);
}

.status-grid span {
  color: var(--wi-muted);
  font-family: "Arial Narrow", Arial, Helvetica, sans-serif;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-grid strong {
  overflow: hidden;
  color: var(--wi-text);
  font-family: "Arial Narrow", Arial, Helvetica, sans-serif;
  font-size: clamp(0.76rem, 1.2vw, 0.96rem);
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-grid__lives strong::before {
  margin-right: 5px;
  color: var(--wi-red);
  content: "\25B2";
  font-size: 0.68em;
}

.status-grid__energy meter {
  width: 100%;
  height: 7px;
  border: 1px solid rgba(216, 208, 189, 0.28);
  border-radius: 0;
  background: #171513;
}

.status-grid__energy meter::-webkit-meter-bar {
  border: 0;
  border-radius: 0;
  background: #171513;
}

.status-grid__energy meter::-webkit-meter-optimum-value {
  background: linear-gradient(90deg, #7b2b23, #d6c580);
}

.status-grid__energy meter::-moz-meter-bar {
  background: linear-gradient(90deg, #7b2b23, #d6c580);
}

.hud-actions {
  display: flex;
  align-items: stretch;
}

.hud-actions button {
  min-height: 0;
  border: 0;
  border-left: 1px solid var(--wi-line);
  padding: 5px 9px;
  color: var(--wi-muted);
  background: transparent;
  font-size: 0.66rem;
}

.playfield-zone {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}

.playfield-zone::before,
.playfield-zone::after {
  position: absolute;
  top: 12%;
  bottom: 12%;
  width: min(16vw, 220px);
  content: "";
  pointer-events: none;
  opacity: 0.34;
  border-top: 1px solid var(--wi-line);
  border-bottom: 1px solid var(--wi-line);
  background:
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(216, 208, 189, 0.045) 28px),
    linear-gradient(90deg, transparent, rgba(75, 8, 6, 0.2));
}

.playfield-zone::before {
  right: calc(50% + min(45vw, 480px));
  border-left: 1px solid var(--wi-line);
}

.playfield-zone::after {
  left: calc(50% + min(45vw, 480px));
  transform: scaleX(-1);
  border-left: 1px solid var(--wi-line);
}

.stage-wrap {
  position: relative;
  width: min(100%, calc(87.5dvh - var(--wi-stage-offset)));
  aspect-ratio: 7 / 8;
  overflow: hidden;
  border: 1px solid rgba(216, 208, 189, 0.28);
  border-top-color: var(--wi-red-line);
  background: #050506;
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.72), 0 0 32px rgba(75, 8, 6, 0.12);
}

.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

input[type="text"] {
  width: 100%;
  border: 1px solid var(--wi-line);
  border-radius: 2px;
  padding: 10px 12px;
  color: var(--wi-text);
  background: rgba(0, 0, 0, 0.66);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--wi-red);
}

input[type="checkbox"] {
  accent-color: var(--wi-red);
}

button {
  min-height: 38px;
  border: 1px solid var(--wi-line);
  border-radius: 2px;
  padding: 8px 13px;
  color: var(--wi-text);
  background: linear-gradient(180deg, rgba(75, 8, 6, 0.54), rgba(12, 2, 2, 0.88));
  font-family: "Arial Narrow", Arial, Helvetica, sans-serif;
  font-size: 0.74rem;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: rgba(216, 208, 189, 0.42);
  color: #fff7ea;
  background-color: rgba(96, 16, 11, 0.82);
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: clamp(8px, 1.5vh, 14px);
  overflow-y: auto;
  padding: clamp(16px, 4.5vmin, 34px);
  text-align: center;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.013) 0 1px, transparent 1px 4px),
    radial-gradient(circle at 50% 35%, rgba(75, 8, 6, 0.2), transparent 44%),
    rgba(3, 3, 3, 0.88);
  backdrop-filter: blur(2px);
}

.screen h2 {
  font-size: clamp(1.75rem, 6vmin, 3.5rem);
  text-transform: uppercase;
}

.screen p {
  max-width: 31rem;
  margin: 0;
  color: var(--wi-muted);
}

.screen--menu .menu-copy {
  font-size: clamp(0.78rem, 1.5vmin, 0.94rem);
  line-height: 1.35;
}

.score-legend {
  width: min(360px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--wi-line);
  border-top-color: var(--wi-red-line);
  background: rgba(0, 0, 0, 0.38);
}

.score-legend span {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 6px 9px;
  color: var(--wi-muted);
  font-family: "Arial Narrow", Arial, Helvetica, sans-serif;
  font-size: 0.68rem;
  text-transform: uppercase;
}

.score-legend__icon {
  width: 40px;
  height: 22px;
  flex: 0 0 40px;
}

.score-legend span:nth-child(odd) {
  border-right: 1px solid var(--wi-line);
}

.score-legend span:nth-child(-n + 2) {
  border-bottom: 1px solid var(--wi-line);
}

.score-legend b {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-legend strong {
  color: var(--wi-text);
}

.control-hint {
  font-family: "Arial Narrow", Arial, Helvetica, sans-serif;
  font-size: 0.64rem;
  letter-spacing: 0.04em;
  line-height: 1.35;
  text-transform: uppercase;
}

.menu-settings {
  width: min(360px, 100%);
  display: grid;
  grid-template-columns: auto minmax(80px, 1fr) auto minmax(80px, 1fr);
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--wi-line);
  color: var(--wi-muted);
  background: rgba(0, 0, 0, 0.34);
  font-family: "Arial Narrow", Arial, Helvetica, sans-serif;
  font-size: 0.68rem;
  text-transform: uppercase;
}

.menu-settings label {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.menu-settings label:nth-child(even) {
  display: grid;
  grid-template-columns: auto minmax(50px, 1fr);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
}

.name-form {
  width: min(320px, 100%);
  display: grid;
  gap: 10px;
  color: var(--wi-muted);
  text-align: left;
}

.name-form label {
  font-family: "Arial Narrow", Arial, Helvetica, sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.form-error {
  min-height: 1.2em;
  color: var(--wi-danger) !important;
}

.run-summary {
  display: grid;
  gap: 6px;
}

.run-summary strong {
  color: var(--wi-text);
  font-size: clamp(1.8rem, 12vw, 3.2rem);
}

.is-hidden {
  display: none !important;
}

.touch-controls {
  display: none;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.wi-shell.is-playing {
  --wi-stage-offset: 68px;
  grid-template-rows: minmax(0, 1fr) auto;
}

.wi-shell.is-playing .wi-header {
  display: none;
}

.wi-shell:fullscreen {
  width: 100%;
  height: 100dvh;
  max-width: none;
  background: var(--wi-bg);
}

.wi-shell:fullscreen .wi-header {
  display: none;
}

.wi-shell:fullscreen:not(.is-playing) {
  --wi-stage-offset: 21px;
  grid-template-rows: minmax(0, 1fr) auto;
}

.wi-shell.is-playing:fullscreen {
  --wi-stage-offset: 65px;
}

@media (max-width: 760px) {
  :root {
    --wi-stage-offset: 81px;
  }

  .wi-header {
    min-height: 40px;
  }

  .wi-header p {
    display: none;
  }

  .wi-header h1 {
    font-size: 1.25rem;
  }

  .status-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .status-grid > div:not(.hud-actions) {
    padding-inline: 5px;
  }

  .status-grid strong {
    font-size: 0.72rem;
  }

  .hud-actions {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 4;
    border: 1px solid var(--wi-line);
    background: rgba(3, 3, 3, 0.78);
  }

  .hud-actions button {
    min-height: 34px;
  }

  .playfield-zone::before,
  .playfield-zone::after {
    display: none;
  }
}

@media (pointer: coarse) {
  .wi-shell.is-playing {
    --wi-stage-offset: 116px;
  }

  .touch-controls {
    width: min(560px, 100%);
    margin: 0 auto;
    display: grid;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  :root {
    --wi-stage-offset: 61px;
  }

  .wi-shell {
    padding-block: 5px;
    gap: 4px;
  }

  .wi-header {
    min-height: 34px;
    padding-bottom: 4px;
  }

  .wi-header h1 {
    font-size: 1.1rem;
  }

  .wi-shell.is-playing {
    --wi-stage-offset: 49px;
  }

  .screen {
    gap: 5px;
    padding: 10px 18px;
  }

  .screen--menu .menu-copy,
  .control-hint {
    display: none;
  }

  .score-legend span,
  .menu-settings {
    padding-block: 4px;
  }

  .touch-controls button {
    min-height: 34px;
  }
}

@media (max-width: 420px) {
  .menu-settings {
    grid-template-columns: auto minmax(70px, 1fr);
  }

  .score-legend span {
    padding-inline: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
