:root {
  --bg: #04030a;
  --panel: rgba(13, 12, 22, 0.88);
  --panel-strong: rgba(20, 16, 34, 0.96);
  --ink: #f5ecff;
  --muted: #a8a1c3;
  --line: rgba(255, 255, 255, 0.12);
  --magenta: #ff48c4;
  --red: #ff2d55;
  --orange: #ff8a00;
  --yellow: #ffe45e;
  --green: #72f36a;
  --cyan: #82f7ff;
  --blue: #2f7dd1;
  --purple: #6f38ff;
  --shadow: rgba(0, 0, 0, 0.48);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(111, 56, 255, 0.22), transparent 40%),
    radial-gradient(circle at 20% 20%, rgba(255, 72, 196, 0.18), transparent 30%),
    linear-gradient(180deg, #13061f 0%, var(--bg) 55%, #010103 100%);
  color: var(--ink);
  font-family: "SFMono-Regular", "IBM Plex Mono", "Menlo", "Consolas", monospace;
}

body {
  overflow: hidden;
}

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

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.02) 50%, transparent 50%),
    linear-gradient(90deg, rgba(255, 72, 196, 0.025), rgba(130, 247, 255, 0.02), rgba(255, 138, 0, 0.02));
  background-size: 100% 4px, 100% 100%;
  mix-blend-mode: screen;
  opacity: 0.45;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 18px;
  gap: 18px;
}

.panel {
  border: 2px solid var(--line);
  background: var(--panel);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.03),
    0 24px 50px var(--shadow);
  backdrop-filter: blur(12px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  gap: 16px;
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: clamp(1.4rem, 2vw, 2.2rem);
  letter-spacing: 0.12em;
}

.eyebrow {
  color: var(--yellow);
  text-transform: uppercase;
  letter-spacing: 0.24em;
  font-size: 0.74rem;
  margin-bottom: 6px;
}

.run-status {
  display: flex;
  align-items: center;
  gap: 16px;
}

.run-meta {
  color: var(--muted);
  font-size: 0.95rem;
  text-align: right;
  max-width: 32ch;
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  gap: 18px;
  flex: 1;
  min-height: 0;
}

.hud-panel {
  display: grid;
  grid-template-rows: repeat(4, min-content);
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

.stat-block {
  padding: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.015));
}

.stat-block h2 {
  margin: 0 0 10px;
  font-size: 0.9rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.stat-block.small {
  font-size: 0.87rem;
}

.meter-stack {
  display: grid;
  gap: 8px;
}

.meter-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.meter {
  height: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--magenta));
}

.meter-fill.stamina {
  background: linear-gradient(90deg, var(--cyan), var(--blue));
}

.meter-fill.boss {
  background: linear-gradient(90deg, var(--orange), var(--yellow));
}

.pip-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.pip,
.heal-pip {
  width: 16px;
  height: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
}

.pip.filled {
  background: linear-gradient(90deg, var(--red), #ff7b6c);
}

.heal-pip.filled {
  background: linear-gradient(90deg, var(--green), var(--yellow));
}

.tag-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tag {
  border: 1px solid var(--line);
  padding: 5px 8px;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: rgba(255, 255, 255, 0.04);
}

.mini-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.mini-list span {
  color: var(--ink);
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#game {
  width: min(100%, 1120px);
  max-height: calc(100vh - 150px);
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  background: linear-gradient(180deg, rgba(8, 5, 16, 0.35), rgba(0, 0, 0, 0.15));
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.06);
  touch-action: none;
}

.mobile-hud,
.touch-ui,
.rotate-prompt {
  display: none;
}

.overlay {
  position: absolute;
  inset: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.overlay.active {
  pointer-events: auto;
}

.modal {
  width: min(880px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 22px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  background: var(--panel-strong);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.03),
    0 24px 64px rgba(0, 0, 0, 0.55);
}

.modal h2,
.modal h3,
.modal p {
  margin-top: 0;
}

.modal .lead {
  color: var(--muted);
  max-width: 58ch;
}

.button-row,
.card-grid {
  display: grid;
  gap: 12px;
}

.button-row {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-top: 18px;
}

.card-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-top: 18px;
}

.pixel-button,
.ghost-button,
.card,
.upgrade-card {
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font: inherit;
  padding: 14px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.pixel-button:hover,
.ghost-button:hover,
.card:hover,
.upgrade-card:hover,
.pixel-button:focus-visible,
.ghost-button:focus-visible,
.card:focus-visible,
.upgrade-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.1);
}

.pixel-button {
  text-align: left;
}

.ghost-button {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
}

.card,
.upgrade-card {
  text-align: left;
}

.card h3,
.upgrade-card h3 {
  margin-bottom: 6px;
}

.card small,
.upgrade-card small {
  display: block;
  color: var(--muted);
  margin-bottom: 12px;
}

.accent {
  color: var(--yellow);
}

.status-note {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.84rem;
}

.combat-feed {
  position: absolute;
  right: 28px;
  bottom: 24px;
  display: grid;
  gap: 8px;
  pointer-events: none;
  max-width: 260px;
}

.feed-entry {
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(5, 4, 12, 0.82);
  color: var(--ink);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.feed-entry.crit {
  color: var(--yellow);
}

.feed-entry.hit {
  color: #ff9b86;
}

.feed-entry.system {
  color: var(--cyan);
}

.mobile-hud {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 3;
  pointer-events: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mobile-hud.visible {
  display: grid;
}

.mobile-panel {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(4, 3, 10, 0.76);
  padding: 8px 10px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.mobile-hud .mobile-panel:last-of-type {
  padding-right: 96px;
}

.touch-menu-button {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 72px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(4, 3, 10, 0.84);
  color: var(--ink);
  padding: 8px 12px;
  font: inherit;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  pointer-events: auto;
}

.mobile-title,
.mobile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mobile-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink);
  margin-bottom: 5px;
}

.mobile-row {
  color: var(--muted);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 5px;
}

.mobile-bar {
  height: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.mobile-bar + .mobile-bar {
  margin-top: 4px;
}

.mobile-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--magenta));
}

.mobile-fill.stamina {
  background: linear-gradient(90deg, var(--cyan), var(--blue));
}

.mobile-fill.boss {
  background: linear-gradient(90deg, var(--orange), var(--yellow));
}

.touch-ui {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.touch-ui.visible {
  display: block;
}

.touch-cluster {
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom));
}

.touch-left {
  left: max(12px, env(safe-area-inset-left));
}

.touch-right {
  right: max(12px, env(safe-area-inset-right));
}

.joystick-pad,
.touch-button {
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.joystick-pad {
  position: relative;
  width: 148px;
  height: 148px;
  border-radius: 999px;
  pointer-events: auto;
}

.joystick-ring,
.joystick-core,
.joystick-knob {
  position: absolute;
  border-radius: 999px;
}

.joystick-ring {
  inset: 0;
  border: 2px solid rgba(255, 255, 255, 0.16);
  background:
    radial-gradient(circle at center, rgba(130, 247, 255, 0.08), rgba(255, 255, 255, 0.04) 55%, rgba(0, 0, 0, 0.2) 100%);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.03),
    0 12px 26px rgba(0, 0, 0, 0.25);
}

.joystick-pad.active .joystick-ring {
  border-color: rgba(130, 247, 255, 0.32);
}

.joystick-core {
  inset: 42px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
}

.joystick-knob {
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin-left: -28px;
  margin-top: -28px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(180deg, rgba(130, 247, 255, 0.34), rgba(47, 125, 209, 0.28));
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.04),
    0 10px 18px rgba(0, 0, 0, 0.28);
  transform: translate(0, 0);
}

.touch-label {
  position: absolute;
  left: 50%;
  bottom: -18px;
  transform: translateX(-50%);
  font-size: 0.58rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.diamond-pad {
  position: relative;
  width: 176px;
  height: 176px;
}

.touch-button {
  position: absolute;
  width: 72px;
  height: 72px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background: rgba(12, 10, 21, 0.78);
  color: var(--ink);
  font: inherit;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  pointer-events: auto;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.03),
    0 12px 24px rgba(0, 0, 0, 0.25);
  transition: transform 90ms ease, border-color 90ms ease, background 90ms ease;
}

.touch-button span {
  pointer-events: none;
}

.touch-button-top {
  left: 52px;
  top: 0;
}

.touch-button-right {
  right: 0;
  top: 52px;
}

.touch-button-bottom {
  left: 52px;
  bottom: 0;
}

.touch-button-left {
  left: 0;
  top: 52px;
}

.touch-button[data-touch-action="parry"] {
  border-color: rgba(130, 247, 255, 0.28);
}

.touch-button[data-touch-action="dodge"] {
  border-color: rgba(255, 228, 94, 0.28);
}

.touch-button[data-touch-action="attack"] {
  border-color: rgba(255, 72, 196, 0.28);
}

.touch-button[data-touch-action="heal"] {
  border-color: rgba(114, 243, 106, 0.28);
}

.touch-button.active,
.touch-button:active {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.12);
}

.rotate-prompt {
  position: fixed;
  inset: 0;
  z-index: 12;
  align-items: center;
  justify-content: center;
  background: rgba(1, 1, 4, 0.8);
  padding:
    max(20px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
}

.rotate-prompt.visible {
  display: flex;
}

.rotate-card {
  max-width: 420px;
  padding: 20px;
  text-align: center;
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .main-layout {
    grid-template-columns: 1fr;
  }

  .hud-panel {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    grid-template-rows: none;
  }

  #game {
    max-height: none;
  }
}

@media (pointer: coarse) {
  body.mobile-ui {
    overflow: hidden;
    overscroll-behavior: none;
  }

  body.mobile-ui .app-shell {
    min-height: 100svh;
    padding: 8px;
    gap: 8px;
  }

  body.mobile-ui .topbar {
    padding: 10px 12px;
  }

  body.mobile-ui .brand h1 {
    font-size: 1rem;
  }

  body.mobile-ui .eyebrow {
    font-size: 0.6rem;
    margin-bottom: 3px;
  }

  body.mobile-ui .run-status {
    gap: 10px;
  }

  body.mobile-ui .run-meta {
    font-size: 0.74rem;
    max-width: 18ch;
  }

  body.mobile-ui .ghost-button {
    padding: 8px 10px;
    font-size: 0.76rem;
  }

  body.mobile-ui .main-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  body.mobile-ui .hud-panel {
    display: none;
  }

  body.mobile-ui .stage {
    padding: 0;
    min-height: 0;
  }

  body.mobile-ui #game {
    width: 100%;
    height: 100%;
    max-height: none;
    aspect-ratio: auto;
  }

  body.mobile-ui .overlay {
    inset: 0;
    padding: 10px;
  }

  body.mobile-ui .modal {
    width: min(100%, 720px);
    padding: 16px;
  }

  body.mobile-ui .combat-feed {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(104px, calc(env(safe-area-inset-bottom) + 92px));
    gap: 6px;
    max-width: 180px;
  }

  body.mobile-ui .feed-entry {
    font-size: 0.68rem;
    padding: 7px 8px;
  }

  body.mobile-run-fullscreen .app-shell {
    padding: 0;
    gap: 0;
  }

  body.mobile-run-fullscreen .topbar {
    display: none;
  }

  body.mobile-run-fullscreen .main-layout {
    display: block;
    height: 100svh;
  }

  body.mobile-run-fullscreen .stage {
    position: fixed;
    inset: 0;
    z-index: 2;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  body.mobile-run-fullscreen #game {
    width: 100vw;
    height: 100svh;
  }

  body.mobile-run-fullscreen .mobile-hud {
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
  }

  body.mobile-run-fullscreen .overlay {
    inset:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  body.mobile-run-fullscreen .combat-feed {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(108px, calc(env(safe-area-inset-bottom) + 96px));
  }
}

@media (pointer: coarse) and (orientation: landscape) {
  body.mobile-ui .main-layout {
    flex: 1;
  }

  body.mobile-ui .stage {
    height: 100%;
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  body.mobile-ui .mobile-hud,
  body.mobile-ui .touch-ui {
    display: none !important;
  }
}
