@font-face {
  font-family: "Igoe Dialogue";
  src:
    url("assets/fonts/igoe-dialogue.woff") format("woff"),
    url("assets/fonts/igoe-dialogue.woff2") format("woff2"),
    url("assets/fonts/igoe-dialogue.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: dark;
  font-family: "Igoe Dialogue", "PxPlus IBM VGA8", "Perfect DOS VGA 437", "Courier New", monospace;
  letter-spacing: 0.04em;
  background: #05070a;
  color: #f5fff8;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, #13222a 0, #070b10 46%, #020304 100%);
}

body {
  display: grid;
  place-items: center;
}

button {
  font: inherit;
}

#game {
  box-sizing: content-box;
  position: relative;
  width: min(90vw, calc(90vh * 1.583333));
  aspect-ratio: 760 / 480;
  overflow: hidden;
  border: 3px solid #ff2bd6;
  border-radius: 0;
  background: #000;
  box-shadow: none;
}

#game::after {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  content: "";
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 4px,
      rgb(0 0 0 / 4%) 5px
    );
  mix-blend-mode: multiply;
}

#view {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.arrival-message {
  appearance: none;
  position: absolute;
  z-index: 6;
  top: 50%;
  left: 50%;
  width: max-content;
  max-width: 88%;
  margin: 0;
  padding: 12px 18px;
  border: 3px solid #ff2bd6;
  border-radius: 0;
  color: #f5fff8;
  background: #020304;
  box-shadow: none;
  font-size: clamp(17px, 3.2vw, 31px);
  letter-spacing: 0.16em;
  text-align: center;
  transform: translate(-50%, -50%);
  transition: opacity 500ms ease;
}

.arrival-message.faded {
  opacity: 0;
  pointer-events: none;
}

.retaliation-message {
  position: absolute;
  z-index: 19;
  top: 50%;
  left: 50%;
  width: max-content;
  max-width: 88%;
  margin: 0;
  padding: 12px 18px;
  border: 3px solid #fff238;
  border-radius: 0;
  color: #00d9ff;
  background: #020304;
  font-size: clamp(15px, 2.7vw, 27px);
  letter-spacing: 0.1em;
  line-height: 1.35;
  text-align: center;
  transform: translate(-50%, -50%);
}

.death-fade {
  position: absolute;
  z-index: 18;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: #020304;
  transition: opacity 950ms steps(10, end);
}

.death-fade.visible {
  opacity: 1;
}

.death-fade.restart-ready {
  pointer-events: auto;
  cursor: pointer;
}

#game.journey-locked {
  cursor: default;
}

.death-message {
  z-index: 20;
  white-space: normal;
  cursor: pointer;
}

.death-message:focus,
.death-message:focus-visible {
  outline: none;
  box-shadow: none;
}

#game.retaliation-impact {
  animation: retaliation-shake 420ms steps(2, end);
}

#game.death-impact {
  animation: death-shake 900ms steps(2, end);
}

.controls-hint {
  position: absolute;
  z-index: 6;
  top: 12px;
  left: 50%;
  margin: 0;
  padding: 8px 12px;
  color: #f5fff8;
  background: #020304;
  border: 3px solid #ff2bd6;
  border-radius: 0;
  font-size: clamp(10px, 1.7vw, 16px);
  letter-spacing: 0.12em;
  white-space: nowrap;
  transform: translateX(-50%);
  transition: opacity 500ms ease;
}

.controls-hint.faded {
  opacity: 0;
}

.hp-meter {
  position: absolute;
  z-index: 7;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  padding: 7px 10px;
  border: 3px solid #ff2bd6;
  border-radius: 0;
  color: #f5fff8;
  background: #020304;
  font-size: clamp(11px, 1.9vw, 18px);
  letter-spacing: 0.1em;
}

.hp-label {
  color: #f5fff8;
}

.hp-hearts {
  display: flex;
  gap: 3px;
  color: #ff2bd6;
  font-family: "Igoe Dialogue", "PxPlus IBM VGA8", "Perfect DOS VGA 437", monospace;
  font-size: 1.1em;
  letter-spacing: 0;
  line-height: 1;
}

.hp-heart.lost {
  color: #401034;
}

.debug-toggle {
  position: absolute;
  z-index: 10;
  top: 12px;
  right: 12px;
  padding: 7px 10px;
  border: 3px solid #ff2bd6;
  border-radius: 0;
  color: #ff2bd6;
  background: #020304;
  font-size: clamp(9px, 1.35vw, 13px);
  letter-spacing: 0.12em;
  cursor: pointer;
}

.debug-toggle:hover,
.debug-toggle:focus-visible {
  color: #05070a;
  background: #ff2bd6;
  outline: none;
}

.render-debug {
  position: absolute;
  z-index: 9;
  top: 52px;
  right: 12px;
  width: min(270px, calc(100% - 24px));
  max-height: calc(100% - 64px);
  overflow-y: auto;
  padding: 12px;
  border: 3px solid #ff2bd6;
  border-radius: 0;
  color: #f5fff8;
  background: #020304;
  font-size: clamp(10px, 1.5vw, 14px);
  letter-spacing: 0.1em;
}

.debug-title,
.debug-help {
  margin: 0;
}

.debug-title {
  margin-bottom: 11px;
  color: #00d9ff;
  letter-spacing: 0.16em;
}

.debug-section-title {
  margin-top: 16px;
}

.debug-help {
  margin-top: 9px;
  color: #f5fff8;
  font-size: 0.78em;
  text-align: right;
}

.debug-placement-status {
  min-height: 1.2em;
  margin: 5px 0 10px;
  color: #00d9ff;
  font-size: 0.78em;
  text-align: right;
}

.debug-field {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
}

.debug-field > span {
  display: flex;
  justify-content: space-between;
}

.debug-field select,
.debug-field input {
  width: 100%;
}

.debug-field select {
  padding: 6px 7px;
  border: 3px solid #ff2bd6;
  border-radius: 0;
  color: #f5fff8;
  background: #05070a;
  font: inherit;
  letter-spacing: 0.08em;
}

.debug-field input {
  accent-color: #00d9ff;
}

.dither-toggle {
  width: 100%;
  margin-top: 7px;
  padding: 7px 10px;
  border: 3px solid #ff2bd6;
  border-radius: 0;
  color: #f5fff8;
  background: #020304;
  font-size: inherit;
  letter-spacing: 0.1em;
  cursor: pointer;
}

.dither-toggle:hover,
.dither-toggle:focus-visible {
  border-color: #00d9ff;
  color: #05070a;
  background: #00d9ff;
  outline: none;
}

#spellPreviewToggle[aria-pressed="true"],
#partPlacementButton[aria-pressed="true"] {
  border-color: #00d9ff;
  color: #05070a;
  background: #00d9ff;
}

.encounter-prompt {
  position: absolute;
  z-index: 7;
  left: 50%;
  bottom: 11%;
  padding: 12px 20px;
  border: 3px solid #ff2bd6;
  border-radius: 0;
  color: #f5fff8;
  background: #05070a;
  font-size: 1.3rem;
  letter-spacing: 0.16em;
  transform: translateX(-50%);
  cursor: pointer;
  pointer-events: auto;
}

.encounter-prompt:hover,
.encounter-prompt:focus-visible,
.dialogue-action:hover,
.dialogue-action:focus-visible {
  color: #05070a;
  background: #f5fff8;
  outline: none;
}

.encounter-ui {
  position: absolute;
  z-index: 8;
  top: 5%;
  right: 4%;
  bottom: 5%;
  left: 4%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 12px;
  pointer-events: none;
}

.dialogue {
  position: relative;
  padding: clamp(7px, 1.25vw, 12px);
  border: 3px solid #ff2bd6;
  border-radius: 0;
  color: #f5fff8;
  background: #020304;
  pointer-events: auto;
}

.dialogue-text {
  min-height: 4.26em;
  margin: 0;
  font-size: clamp(18px, 3.1vw, 30px);
  letter-spacing: 0.055em;
  line-height: 1.42;
  text-wrap: pretty;
}

.dialogue-text::after {
  display: inline-block;
  width: 0.6em;
  margin-left: 0.18em;
  color: #ff2bd6;
  content: "■";
  animation: blink 700ms steps(1) infinite;
}

.dialogue.ready .dialogue-text::after {
  content: "►";
}

.dialogue-action {
  float: right;
  margin-top: 14px;
  padding: 9px 14px;
  border: 3px solid #ff2bd6;
  border-radius: 0;
  color: #f5fff8;
  background: transparent;
  font-size: 1.3rem;
  letter-spacing: 0.14em;
  cursor: pointer;
}

.part-menu {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: auto;
}

.part-menu.finale-choice-menu {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.part-action {
  min-height: 54px;
  padding: 9px 10px;
  border: 3px solid #ff2bd6;
  border-radius: 0;
  color: #f5fff8;
  background: #05070a;
  font-size: 1.2rem;
  letter-spacing: 0.12em;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.part-action:hover,
.part-action:focus-visible,
.part-action.menu-selected {
  color: #05070a;
  background: #fff238;
  outline: none;
}

.part-action:disabled {
  opacity: 0.35;
  cursor: wait;
}

.part-action.construct-attached:disabled {
  border-color: #00d9ff;
  color: #00d9ff;
  background: #05070a;
  opacity: 1;
  cursor: not-allowed;
}

.hidden {
  display: none !important;
}

.visually-hidden {
  position: fixed;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@keyframes blink {
  0%,
  52% {
    opacity: 1;
  }

  53%,
  100% {
    opacity: 0;
  }
}

@keyframes retaliation-shake {
  0%,
  100% { transform: translate(0, 0); }
  15% { transform: translate(-8px, 5px); }
  30% { transform: translate(9px, -6px); }
  45% { transform: translate(-7px, -4px); }
  60% { transform: translate(6px, 7px); }
  75% { transform: translate(-4px, 3px); }
}

@keyframes death-shake {
  0%,
  100% { transform: translate(0, 0); }
  10% { transform: translate(-15px, 9px); }
  20% { transform: translate(17px, -11px); }
  32% { transform: translate(-13px, -8px); }
  44% { transform: translate(15px, 12px); }
  58% { transform: translate(-10px, 7px); }
  72% { transform: translate(8px, -6px); }
  86% { transform: translate(-4px, 3px); }
}

@media (max-aspect-ratio: 3 / 4) {
  #game {
    width: 90vw;
  }

  .encounter-ui {
    right: 3%;
    left: 3%;
  }

  .part-menu,
  .part-menu.finale-choice-menu {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .dialogue-text::after {
    animation: none;
  }
}
