:root {
  --ink: #f5e8c8;
  --muted: #a99cb2;
  --night: #070612;
  --panel: #100d22;
  --panel-light: #191233;
  --purple: #3b285f;
  --acid: #9acb54;
  --ember: #d77843;
  --touch-size: clamp(34px, 8.7dvh, 42px);
  --touch-small: clamp(27px, 6.7dvh, 32px);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: var(--night);
}

body {
  min-width: 320px;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  overscroll-behavior: none;
  color: var(--ink);
  background:
    linear-gradient(rgba(7, 6, 18, 0.78), rgba(7, 6, 18, 0.96)),
    repeating-linear-gradient(
      90deg,
      transparent 0 31px,
      rgba(109, 72, 184, 0.08) 31px 32px
    ),
    var(--night);
  font-family: "Courier New", Courier, monospace;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.game-page {
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 52px) 0 24px;
}

.game-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  width: min(960px, 100%);
  margin: 0 auto 16px;
  gap: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--acid);
  font-size: clamp(9px, 1.3vw, 12px);
  font-weight: 700;
  letter-spacing: 0.18em;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(28px, 5vw, 52px);
  line-height: 0.84;
  letter-spacing: -0.08em;
  text-shadow: 4px 4px 0 var(--purple);
}

.game-subtitle {
  margin: 10px 0 0;
  color: var(--ember);
  font-size: clamp(9px, 1.5vw, 13px);
  font-weight: 700;
  letter-spacing: 0.28em;
}

.world-counter {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
}

.world-counter strong {
  color: var(--ember);
}

.header-tools {
  display: flex;
  align-items: end;
  flex-direction: column;
  gap: 8px;
}

.header-tools a {
  color: var(--acid);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-decoration: none;
}

.header-tools a:hover,
.header-tools a:focus-visible {
  color: var(--ink);
}

.game-stage {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: clamp(8px, 1.4vw, 14px);
  border: 2px solid var(--purple);
  background: var(--panel);
  box-shadow:
    8px 8px 0 #030208,
    inset 0 0 0 2px var(--panel-light);
}

.play-surface {
  position: relative;
  width: 100%;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  background:
    radial-gradient(circle at center, #191233 0, #09071a 68%),
    #09071a;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.canvas-shell {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: auto;
  overflow: hidden;
  border: 2px solid #05040c;
  background: #09071a;
}

.canvas-shell::after {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  content: "";
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 5px,
    rgba(3, 2, 8, 0.055) 5px 6px
  );
  mix-blend-mode: multiply;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
}

canvas:focus-visible {
  box-shadow: inset 0 0 0 2px var(--acid);
}

.platform-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 12;
  display: flex;
  gap: 6px;
}

.platform-button {
  min-height: 30px;
  padding: 6px 8px;
  border: 1px solid rgba(154, 203, 84, 0.72);
  color: var(--ink);
  background: rgba(16, 13, 34, 0.82);
  box-shadow: 2px 2px 0 rgba(3, 2, 8, 0.84);
  font: 700 8px/1 "Courier New", monospace;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.platform-button:hover,
.platform-button:focus-visible,
.platform-button[aria-pressed="true"] {
  color: #090711;
  background: var(--acid);
  outline: none;
}

.touch-controls {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  pointer-events: none;
}

.touch-controls[data-enabled="true"] {
  display: block;
}

.touch-controls button {
  pointer-events: auto;
}

.touch-menu-toggle {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 2;
  display: grid;
  width: var(--touch-small);
  height: var(--touch-small);
  place-items: center;
  padding: 0;
  border: 1px solid rgba(154, 203, 84, 0.78);
  border-radius: 6px;
  color: var(--ink);
  background: rgba(16, 13, 34, 0.7);
  font: 800 16px/1 "Courier New", monospace;
  touch-action: none;
}

.touch-menu-toggle[aria-expanded="true"] {
  color: #090711;
  background: var(--acid);
}

.touch-button {
  display: grid;
  width: var(--touch-size);
  height: var(--touch-size);
  place-items: center;
  padding: 0;
  border: 2px solid rgba(245, 232, 200, 0.72);
  border-radius: 9px;
  color: var(--ink);
  background: rgba(16, 13, 34, 0.46);
  box-shadow:
    0 3px 0 rgba(3, 2, 8, 0.8),
    inset 0 0 0 1px rgba(109, 72, 184, 0.48);
  font: 800 clamp(10px, 2.8dvh, 14px)/1 "Courier New", monospace;
  text-shadow: 1px 1px 0 #070612;
  touch-action: none;
  opacity: 0.7;
  transition:
    opacity 120ms ease,
    transform 80ms ease,
    background-color 120ms ease;
}

.touch-button.is-active,
.touch-button:active {
  border-color: var(--acid);
  color: #090711;
  background: rgba(154, 203, 84, 0.92);
  box-shadow:
    0 1px 0 rgba(3, 2, 8, 0.8),
    inset 0 0 0 1px rgba(245, 232, 200, 0.54);
  text-shadow: none;
  transform: translateY(2px);
  opacity: 1;
}

.touch-dpad {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: max(10px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: repeat(3, var(--touch-size));
  grid-template-rows: repeat(2, var(--touch-size));
  gap: 2px;
}

.touch-dpad-up {
  grid-column: 2;
  grid-row: 1;
}

.touch-dpad-left {
  grid-column: 1;
  grid-row: 2;
}

.touch-dpad-down {
  grid-column: 2;
  grid-row: 2;
}

.touch-dpad-right {
  grid-column: 3;
  grid-row: 2;
}

.touch-actions {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, var(--touch-size));
  grid-template-rows: repeat(2, var(--touch-size));
  gap: 5px;
}

.touch-button--action {
  border-radius: 50%;
  font-size: clamp(7px, 2dvh, 10px);
}

.touch-action-interact {
  grid-column: 1;
  grid-row: 1;
  border-color: rgba(215, 120, 67, 0.88);
}

.touch-action-magic {
  grid-column: 2;
  grid-row: 1;
  border-color: rgba(160, 109, 225, 0.92);
}

.touch-action-melee {
  grid-column: 1;
  grid-row: 2;
  border-color: rgba(245, 232, 200, 0.88);
}

.touch-action-jump {
  grid-column: 2;
  grid-row: 2;
  border-color: rgba(154, 203, 84, 0.94);
}

.touch-utility {
  position: absolute;
  top: calc(max(8px, env(safe-area-inset-top)) + var(--touch-small) + 5px);
  right: max(8px, env(safe-area-inset-right));
  display: none;
  grid-template-columns: repeat(2, var(--touch-small));
  max-width: calc(var(--touch-small) * 2 + 5px);
  gap: 4px;
  padding: 5px;
  border: 1px solid rgba(154, 203, 84, 0.38);
  border-radius: 7px;
  background: rgba(7, 6, 18, 0.58);
}

.touch-controls[data-tools="open"] .touch-utility {
  display: grid;
}

.touch-controls[data-tools="open"] .touch-dpad,
.touch-controls[data-tools="open"] .touch-actions {
  opacity: 0.12;
  pointer-events: none;
}

.touch-button--utility {
  width: var(--touch-small);
  height: var(--touch-small);
  border-width: 1px;
  border-radius: 5px;
  font-size: clamp(6px, 1.7dvh, 8px);
}

.touch-button--vision {
  color: var(--acid);
}

.touch-dpad,
.touch-actions {
  transition: opacity 120ms ease;
}

.play-surface[data-touch-context="dialogue"] .touch-dpad,
.play-surface[data-touch-context="dialogue"] .touch-action-magic,
.play-surface[data-touch-context="dialogue"] .touch-action-melee,
.play-surface[data-touch-context="dialogue"] .touch-action-jump,
.play-surface[data-touch-context="inventory"] .touch-dpad,
.play-surface[data-touch-context="inventory"] .touch-actions,
.play-surface[data-touch-context="zone-map"] .touch-dpad,
.play-surface[data-touch-context="zone-map"] .touch-actions,
.play-surface[data-touch-context="pause"] .touch-dpad,
.play-surface[data-touch-context="pause"] .touch-actions {
  opacity: 0;
  pointer-events: none;
}

.play-surface[data-touch-context="shop"] .touch-action-magic,
.play-surface[data-touch-context="shop"] .touch-action-melee,
.play-surface[data-touch-context="shop"] .touch-action-jump,
.play-surface[data-touch-context="world-map"] .touch-action-magic,
.play-surface[data-touch-context="world-map"] .touch-action-melee,
.play-surface[data-touch-context="world-map"] .touch-action-jump {
  opacity: 0;
  pointer-events: none;
}

.play-surface[data-touch-context="dialogue"] .touch-action-interact,
.play-surface[data-touch-context="shop"] .touch-action-interact,
.play-surface[data-touch-context="world-map"] .touch-action-interact {
  opacity: 0.9;
}

.play-surface[data-touch-context="world-map"] .touch-dpad,
.play-surface[data-touch-context="world-map"] .touch-actions {
  transform: scale(0.78);
}

.play-surface[data-touch-context="world-map"] .touch-dpad {
  transform-origin: left bottom;
}

.play-surface[data-touch-context="world-map"] .touch-actions {
  transform-origin: right bottom;
}

.play-surface[data-touch-context="world-map"]
  .touch-controls[data-tools="closed"]
  .touch-utility {
  display: grid;
  grid-template-columns: var(--touch-small);
  max-width: var(--touch-small);
  padding: 0;
  border: 0;
  background: transparent;
}

.play-surface[data-touch-context="world-map"]
  .touch-controls[data-tools="closed"]
  .touch-utility
  .touch-button:not(.touch-button--vision) {
  display: none;
}

.play-surface[data-touch-context="world-map"] .touch-button--vision {
  border-color: rgba(154, 203, 84, 0.86);
  background: rgba(16, 13, 34, 0.64);
  opacity: 0.86;
}

.orientation-lock {
  display: none;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  padding: 9px 2px 0;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.1em;
}

.status-bar b {
  font: inherit;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  background: var(--acid);
  box-shadow: 0 0 8px rgba(154, 203, 84, 0.8);
}

.status-meta {
  display: flex;
  gap: 14px;
}

#input-mode {
  color: var(--acid);
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(960px, 100%);
  margin: 18px auto 0;
  gap: 8px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.09em;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.control-row > span:first-child {
  color: var(--acid);
  font-weight: 700;
}

kbd {
  min-width: 22px;
  margin-left: 3px;
  padding: 4px 6px;
  border: 1px solid #564178;
  border-bottom-width: 3px;
  color: var(--ink);
  background: #18122b;
  font: inherit;
  text-align: center;
}

.control-note {
  margin-top: 4px;
  color: var(--ember);
  font-weight: 700;
}

#play-surface:fullscreen,
#play-surface:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  aspect-ratio: auto;
  background: #030208;
}

#play-surface:fullscreen .canvas-shell,
#play-surface:-webkit-full-screen .canvas-shell,
.is-fullscreen #play-surface .canvas-shell {
  width: min(100vw, calc(100vh * 16 / 9));
  width: min(100vw, calc(100svh * 16 / 9));
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  height: min(100svh, calc(100vw * 9 / 16));
  height: min(100dvh, calc(100vw * 9 / 16));
}

.is-fullscreen #touch-toggle,
#play-surface:fullscreen #touch-toggle,
#play-surface:-webkit-full-screen #touch-toggle {
  display: none;
}

@media (max-width: 560px) {
  .game-page {
    width: calc(100% - 16px);
    padding-top: 16px;
  }

  .game-header {
    align-items: center;
  }

  .header-tools {
    align-items: end;
  }

  .world-counter {
    font-size: 9px;
  }

  .game-stage {
    padding: 6px;
    box-shadow: 4px 4px 0 #030208;
  }

  .control-row {
    row-gap: 9px;
  }

  .platform-button {
    padding-inline: 6px;
    font-size: 7px;
  }
}

@media (pointer: coarse) {
  .platform-actions {
    display: none;
  }

  .touch-controls[data-enabled="true"] {
    display: block;
  }

  canvas {
    cursor: default;
  }
}

@media (pointer: coarse) and (orientation: landscape) {
  #play-surface:fullscreen .canvas-shell,
  #play-surface:-webkit-full-screen .canvas-shell,
  .is-fullscreen #play-surface .canvas-shell {
    width: 100%;
    height: 100%;
  }
}

@media (orientation: portrait) and (pointer: coarse) {
  .orientation-lock {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 10px;
    padding:
      max(24px, env(safe-area-inset-top))
      max(24px, env(safe-area-inset-right))
      max(24px, env(safe-area-inset-bottom))
      max(24px, env(safe-area-inset-left));
    color: var(--ink);
    background:
      radial-gradient(circle, #23164b 0, #070612 72%);
    font-size: 13px;
    letter-spacing: 0.12em;
    text-align: center;
    pointer-events: auto;
  }

  .orientation-lock span:last-child {
    color: var(--muted);
    font-size: 9px;
  }

  .rotate-glyph {
    color: var(--acid);
    font-size: 48px;
    line-height: 1;
  }
}

@media
  (max-height: 600px)
  and (orientation: landscape)
  and (pointer: coarse) {
  body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    overflow: hidden;
  }

  .game-page {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    min-height: 0;
    padding: 0;
  }

  .game-header,
  .controls,
  .status-bar {
    display: none;
  }

  .game-stage {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .play-surface {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    aspect-ratio: auto;
  }

  .canvas-shell {
    width: 100%;
    height: 100%;
  }

  .platform-actions {
    top: max(7px, env(safe-area-inset-top));
    right: max(7px, env(safe-area-inset-right));
  }

  .platform-button {
    min-height: 27px;
    background: rgba(16, 13, 34, 0.62);
  }
}

@media (prefers-reduced-motion: reduce) {
  .status-dot {
    box-shadow: none;
  }

  .touch-button {
    transition: none;
  }
}
