:root {
  --ink: #100d18;
  --void: #25163a;
  --plum: #4b2864;
  --bone: #f2e6c9;
  --muted: #b7a9bb;
  --star: #63d9ff;
  --ember: #ff6b3d;
  --verdant: #74d36f;
  --thunder: #ffd34e;
  --danger: #ff4f70;
  --panel: rgba(16, 13, 24, 0.94);
  --pixel-border: 2px solid var(--bone);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 720px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #08060d;
  color: var(--bone);
  font-family: ui-monospace, "SFMono-Regular", "Microsoft YaHei", monospace;
}

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

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--thunder);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.stage {
  position: relative;
  width: var(--stage-width, 960px);
  height: var(--stage-height, 540px);
  overflow: hidden;
  border: 2px solid #3d3150;
  background: var(--ink);
  box-shadow: 0 0 0 2px #08060d, 0 18px 70px rgba(0, 0, 0, 0.68);
}

.game-mount,
.game-mount canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hud-layer,
.screen,
.loading-overlay {
  position: absolute;
  inset: 0;
}

.hud-layer {
  z-index: 8;
  pointer-events: none;
}

.player-hud {
  position: absolute;
  top: 10px;
  display: flex;
  width: 31%;
  min-width: 240px;
  gap: 8px;
  padding: 7px 9px;
  border: 2px solid rgba(242, 230, 201, 0.68);
  background: rgba(10, 8, 15, 0.88);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
}

.player-hud-left {
  left: 10px;
  border-left-color: var(--star);
}

.player-hud-right {
  right: 10px;
  border-right-color: var(--ember);
}

.pixel-portrait {
  flex: 0 0 36px;
  width: 36px;
  height: 44px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 36px 36px;
  image-rendering: pixelated;
}

.player-readout {
  min-width: 0;
  flex: 1;
}

.player-heading,
.boss-line,
.tutorial-step,
.settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.player-heading {
  min-width: 0;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 900;
}

.hp-track,
.boss-track {
  height: 7px;
  overflow: hidden;
  border: 1px solid rgba(242, 230, 201, 0.54);
  background: #09070e;
}

.hp-track span,
.boss-track span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--star);
  transition: width 100ms linear;
}

.player-hud-right .hp-track span {
  background: var(--ember);
}

.ability-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
  margin-top: 5px;
}

.ability-chip {
  min-width: 0;
  padding: 2px 3px;
  border: 1px solid rgba(242, 230, 201, 0.36);
  background: #17121f;
  overflow: hidden;
  color: var(--bone);
  font-size: 9px;
  font-weight: 900;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ability-chip.cooling {
  color: #7e7182;
}

.run-hud {
  position: absolute;
  top: 10px;
  left: 50%;
  width: 31%;
  transform: translateX(-50%);
  text-align: center;
  text-shadow: 2px 2px 0 #09070e;
}

.run-meta,
.seed-label {
  color: var(--muted);
  font-size: 9px;
}

.objective-text {
  margin: 3px 0;
  color: #fff8e8;
  font-size: 14px;
  font-weight: 900;
}

.boss-hud {
  position: absolute;
  left: 50%;
  bottom: 9px;
  width: 48%;
  padding: 7px 10px;
  transform: translateX(-50%);
  border: 2px solid var(--plum);
  background: rgba(10, 8, 15, 0.92);
}

.boss-line {
  margin-bottom: 4px;
  color: #e8d0ff;
  font-size: 11px;
  font-weight: 900;
}

.boss-track span {
  background: var(--danger);
}

.boss-hint {
  margin-top: 4px;
  color: var(--muted);
  font-size: 9px;
  text-align: center;
}

.dialogue-box {
  position: absolute;
  bottom: 10px;
  left: 10px;
  width: 31%;
  padding: 8px 10px;
  border-left: 3px solid var(--verdant);
  background: rgba(10, 8, 15, 0.9);
  color: var(--bone);
  font-size: 11px;
  line-height: 1.45;
}

.dialogue-speaker {
  display: block;
  margin-bottom: 3px;
  color: var(--verdant);
  font-size: 9px;
  font-weight: 900;
}

.tutorial-panel {
  position: absolute;
  top: 88px;
  right: 16px;
  bottom: auto;
  width: 330px;
  padding: 12px;
  border: 2px solid var(--thunder);
  background: var(--panel);
  pointer-events: auto;
}

.tutorial-step {
  color: var(--thunder);
  font-size: 12px;
  font-weight: 900;
}

.tutorial-panel p {
  margin: 8px 0 10px;
  color: var(--bone);
  font-size: 11px;
  line-height: 1.45;
}

.reward-panel {
  position: absolute;
  left: 50%;
  bottom: 14px;
  width: 72%;
  transform: translateX(-50%);
  border: 2px solid var(--thunder);
  background: rgba(10, 8, 15, 0.94);
  pointer-events: none;
}

.reward-heading {
  padding: 6px;
  border-bottom: 1px solid rgba(242, 230, 201, 0.38);
  color: var(--thunder);
  font-size: 11px;
  font-weight: 900;
  text-align: center;
}

.reward-choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.reward-choice {
  min-width: 0;
  min-height: 62px;
  padding: 7px 9px;
  border-right: 1px solid rgba(242, 230, 201, 0.28);
}

.reward-choice:last-child {
  border-right: 0;
}

.reward-choice strong {
  display: block;
  color: #fff8e8;
  font-size: 10px;
}

.reward-choice span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 8px;
  line-height: 1.35;
}

.reward-choice.active {
  background: rgba(255, 211, 78, 0.14);
  box-shadow: inset 0 0 0 2px var(--thunder);
}

.reward-foot {
  padding: 5px;
  border-top: 1px solid rgba(242, 230, 201, 0.28);
  color: var(--muted);
  font-size: 8px;
  text-align: center;
}

.training-exit-button {
  position: absolute;
  right: 14px;
  bottom: 12px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(242, 230, 201, 0.68);
  border-radius: 0;
  background: rgba(10, 8, 15, 0.9);
  color: var(--bone);
  font-size: 9px;
  font-weight: 900;
  pointer-events: auto;
}

.training-exit-button:hover {
  border-color: var(--thunder);
  color: var(--thunder);
}

.training-cheer {
  position: absolute;
  top: 35%;
  left: 50%;
  min-width: 178px;
  padding: 9px 15px;
  transform: translate(-50%, -50%);
  border-top: 2px solid var(--thunder);
  border-bottom: 2px solid var(--thunder);
  background: rgba(10, 8, 15, 0.9);
  color: var(--thunder);
  font-size: 18px;
  font-weight: 900;
  text-align: center;
  text-shadow: 2px 2px 0 #09070e;
  animation: training-cheer-pop 520ms steps(5, end);
}

.training-hud-active .ability-row {
  grid-template-columns: 1fr;
}

.training-hud-active .ability-chip {
  border-color: rgba(255, 211, 78, 0.46);
}

.screen {
  z-index: 12;
  background: var(--ink);
}

.menu-screen {
  overflow: hidden;
}

.menu-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}

.menu-copy {
  position: absolute;
  top: 12%;
  left: 8%;
  width: 46%;
  padding-left: 18px;
  border-left: 4px solid var(--star);
  text-shadow: 3px 3px 0 #09070e;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--thunder);
  font-size: 11px;
  font-weight: 900;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: #fff8e8;
  font-family: Impact, "Arial Black", "Microsoft YaHei", sans-serif;
  font-size: 70px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
  color: #fff8e8;
  font-family: "Arial Black", "Microsoft YaHei", sans-serif;
  font-size: 30px;
  letter-spacing: 0;
}

.subtitle {
  margin: 2px 0 18px;
  color: var(--star);
  font-size: 14px;
  font-weight: 900;
}

.menu-story {
  width: 90%;
  margin-bottom: 24px;
  color: var(--bone);
  font-size: 13px;
  line-height: 1.65;
}

.primary-actions,
.secondary-actions,
.screen-footer {
  display: flex;
  align-items: center;
  gap: 10px;
}

.secondary-actions {
  margin-top: 10px;
}

.menu-copy .primary-actions {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 0.8fr) minmax(0, 1fr);
}

.menu-copy .command-button {
  min-width: 0;
  padding-right: 8px;
  padding-left: 8px;
}

.command-button,
.text-button,
.danger-button,
.icon-button {
  border-radius: 0;
  background: transparent;
}

.command-button {
  min-height: 42px;
  padding: 0 15px;
  border: 2px solid var(--bone);
  background: #17121f;
  box-shadow: 4px 4px 0 #09070e;
  font-size: 12px;
  font-weight: 900;
}

.command-button:hover {
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 #09070e;
}

.command-button.primary {
  border-color: var(--thunder);
  background: var(--thunder);
  color: var(--ink);
}

.command-button:disabled {
  border-color: #625668;
  background: #28212d;
  color: #7f7282;
  cursor: not-allowed;
  box-shadow: none;
}

.text-button {
  padding: 4px 2px;
  border: 0;
  border-bottom: 1px solid currentColor;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
}

.text-button:hover {
  color: #fff8e8;
}

.continue-meta {
  position: absolute;
  right: 18px;
  bottom: 14px;
  color: #756978;
  font-size: 9px;
}

.training-select-screen,
.story-screen,
.select-screen,
.archive-screen,
.result-screen {
  padding: 38px 54px;
}

.story-screen {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  align-items: center;
  gap: 44px;
}

.story-illustration {
  height: 72%;
  border: 2px solid var(--plum);
  background: url("../assets/ui/title-art.png") center / cover;
  image-rendering: pixelated;
}

.story-copy h2 {
  font-size: 28px;
  line-height: 1.45;
}

.training-select-screen,
.select-screen,
.archive-screen,
.result-screen {
  background-color: var(--ink);
  background-image: linear-gradient(rgba(242, 230, 201, 0.035) 1px, transparent 1px), linear-gradient(90deg, rgba(242, 230, 201, 0.035) 1px, transparent 1px);
  background-size: 16px 16px;
}

.training-mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  max-width: 820px;
  margin: 28px auto 0;
}

.training-mode-button {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  align-items: center;
  min-width: 0;
  min-height: 190px;
  padding: 18px;
  border: 2px solid #5e5265;
  border-radius: 0;
  background: #17121f;
  box-shadow: 5px 5px 0 #09070e;
  color: var(--bone);
  text-align: left;
}

.training-mode-button:hover,
.training-mode-button:focus-visible {
  border-color: var(--thunder);
  transform: translate(1px, 1px);
  box-shadow: 4px 4px 0 #09070e;
}

.training-target-preview {
  width: 96px;
  height: 96px;
  background-position: 0 0;
  background-repeat: no-repeat;
  background-size: 192px 96px;
  image-rendering: pixelated;
  animation: training-target-preview 900ms steps(1, end) infinite;
}

.training-straw-preview {
  background-image: url("../assets/training/straw-dummy.png");
}

.training-bullseye-preview {
  background-image: url("../assets/training/moving-target.png");
}

.training-mode-copy,
.training-mode-copy strong,
.training-mode-copy span {
  display: block;
  min-width: 0;
}

.training-mode-copy strong {
  margin-bottom: 10px;
  color: var(--thunder);
  font-size: 17px;
}

.training-mode-copy span {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.7;
}

.training-select-footer {
  margin-top: 24px;
}

.screen-header {
  text-align: center;
}

.screen-header h2 {
  margin-bottom: 4px;
}

.screen-header p:last-child {
  color: var(--muted);
  font-size: 11px;
}

.select-columns {
  display: grid;
  grid-template-columns: 1fr 112px 1fr;
  align-items: center;
  gap: 20px;
  margin-top: 24px;
}

.slot-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
}

.wizard-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.wizard-card {
  position: relative;
  min-width: 0;
  min-height: 118px;
  padding: 11px;
  border: 2px solid #5e5265;
  background: #17121f;
  color: var(--bone);
  text-align: left;
}

.wizard-card.selected {
  border-color: var(--wizard-color);
  box-shadow: inset 0 -5px 0 var(--wizard-color);
}

.wizard-card.locked {
  filter: grayscale(1);
  opacity: 0.52;
}

.wizard-card .wizard-sprite {
  width: 48px;
  height: 60px;
  margin: 0 auto 5px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 48px 48px;
  image-rendering: pixelated;
}

.wizard-card strong,
.wizard-card span {
  display: block;
  overflow-wrap: anywhere;
  text-align: center;
}

.wizard-card strong {
  color: var(--wizard-color);
  font-size: 11px;
}

.wizard-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 8px;
}

.bond-sigil {
  display: grid;
  width: 104px;
  height: 104px;
  place-items: center;
  border: 2px solid var(--star);
  background: #17121f;
  box-shadow: inset 0 0 0 8px var(--ink), inset 0 0 0 10px var(--ember);
  transform: rotate(45deg);
}

.bond-sigil span {
  width: 78px;
  transform: rotate(-45deg);
  color: #fff8e8;
  font-size: 11px;
  font-weight: 900;
  text-align: center;
}

.run-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
  padding: 10px 0;
  border-top: 1px solid #514558;
  border-bottom: 1px solid #514558;
}

.run-options label {
  min-width: 0;
}

.run-options label > span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 8px;
  font-weight: 900;
}

.run-options select {
  width: 100%;
  height: 30px;
  padding: 0 7px;
  border: 1px solid #6a5b70;
  border-radius: 0;
  background: #17121f;
  color: var(--bone);
  font-size: 9px;
  font-weight: 900;
}

.run-options select:focus-visible {
  outline: 2px solid var(--thunder);
  outline-offset: 1px;
}

.screen-footer {
  justify-content: center;
  margin-top: 16px;
}

.archive-content {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-height: 72%;
  margin-top: 18px;
  padding-right: 8px;
  overflow-x: hidden;
  overflow-y: scroll;
  scrollbar-color: var(--thunder) #17121f;
  scrollbar-width: auto;
}

.archive-content::-webkit-scrollbar {
  width: 8px;
}

.archive-content::-webkit-scrollbar-track {
  background: #17121f;
}

.archive-content::-webkit-scrollbar-thumb {
  border: 2px solid #17121f;
  background: var(--thunder);
}

.archive-entry {
  min-height: 82px;
  padding: 10px;
  border: 1px solid #5e5265;
  background: #17121f;
}

.archive-entry strong {
  display: block;
  color: var(--entry-color, var(--bone));
  font-size: 10px;
}

.archive-entry span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 8px;
  line-height: 1.45;
}

.archive-entry.locked {
  color: #675b6a;
  filter: grayscale(1);
}

.archive-back {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
}

.archive-scroll-cue {
  position: absolute;
  top: 52%;
  right: 34px;
  color: var(--thunder);
  font-size: 16px;
  animation: archive-cue 1.2s steps(2, end) infinite;
}

.result-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.result-rune {
  margin-bottom: 8px;
  color: var(--thunder);
  font-size: 46px;
  animation: rune-pulse 1.6s steps(4) infinite;
}

.result-screen h2 {
  font-size: 38px;
}

.result-screen > p:not(.eyebrow) {
  max-width: 580px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.result-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
  margin: 12px 0;
  color: var(--bone);
  font-size: 10px;
}

.unlock-notice {
  margin: 6px 0 12px;
  padding: 7px 12px;
  border: 1px solid var(--verdant);
  color: var(--verdant);
  font-size: 10px;
}

.settings-panel {
  position: absolute;
  z-index: 30;
  top: 0;
  right: 0;
  width: 310px;
  height: 100%;
  padding: 24px;
  border-left: 3px solid var(--thunder);
  background: rgba(10, 8, 15, 0.98);
  box-shadow: -14px 0 40px rgba(0, 0, 0, 0.5);
}

.settings-heading h2 {
  margin: 0;
  font-size: 24px;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--bone);
  font-size: 22px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  border-bottom: 1px solid #44394a;
  font-size: 11px;
}

.toggle-row input {
  width: 34px;
  height: 18px;
  accent-color: var(--thunder);
}

.danger-button {
  width: 100%;
  min-height: 38px;
  margin-top: 28px;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 10px;
}

.loading-overlay {
  z-index: 50;
  display: grid;
  place-content: center;
  gap: 12px;
  background: var(--ink);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.loading-rune {
  width: 34px;
  height: 34px;
  margin: 0 auto;
  border: 3px solid var(--plum);
  border-top-color: var(--star);
  animation: pixel-spin 0.8s steps(8) infinite;
}

.keyboard-notice {
  display: none;
}

@keyframes pixel-spin {
  to { transform: rotate(360deg); }
}

@keyframes rune-pulse {
  50% { transform: scale(1.16); }
}

@keyframes archive-cue {
  50% { transform: translateY(5px); }
}

@keyframes training-target-preview {
  50%, 100% { background-position: -96px 0; }
}

@keyframes training-cheer-pop {
  0% { transform: translate(-50%, -50%) scale(0.78); }
  35% { transform: translate(-50%, -50%) scale(1.08); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

@media (max-width: 900px), (max-height: 560px) {
  h1 { font-size: 48px; }
  .menu-story { font-size: 11px; }
  .training-select-screen,
  .story-screen,
  .select-screen,
  .archive-screen,
  .result-screen { padding: 24px 34px; }
  .player-hud { min-width: 190px; padding: 5px; }
  .ability-chip { font-size: 8px; }
  .training-mode-grid { gap: 12px; margin-top: 16px; }
  .training-mode-button { grid-template-columns: 76px minmax(0, 1fr); min-height: 142px; padding: 12px; }
  .training-target-preview { width: 72px; height: 72px; background-size: 144px 72px; }
  .training-mode-copy strong { margin-bottom: 6px; font-size: 13px; }
  .training-mode-copy span { font-size: 9px; line-height: 1.45; }
}

@media (max-width: 900px), (max-height: 560px) {
  @keyframes training-target-preview {
    50%, 100% { background-position: -72px 0; }
  }
}

@media (max-width: 719px) {
  .keyboard-notice {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    background: var(--ink);
    color: var(--bone);
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }
}
