:root {
  color-scheme: dark;
  --ink: #f7ecd2;
  --muted: #aaa0b8;
  --night: #100c1c;
  --panel: #1d172b;
  --panel-2: #29203a;
  --line: #49385d;
  --gold: #ffd166;
  --amber: #ed9b45;
  --red: #ef5d60;
  --green: #7bd389;
  --blue: #67c5e8;
  --shadow: #090611;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--night);
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -10%, #35224c 0, transparent 42%),
    linear-gradient(180deg, #171022 0, var(--night) 65%);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, "Noto Sans TC", monospace;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

button,
summary {
  font: inherit;
}

button {
  min-height: 44px;
  border: 2px solid var(--line);
  color: var(--ink);
  background: var(--panel-2);
  box-shadow: 0 4px 0 var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
}

button:active {
  translate: 0 2px;
  box-shadow: 0 2px 0 var(--shadow);
}

button:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

main {
  width: min(100%, 42rem);
  margin: 0 auto;
  padding: max(0.7rem, env(safe-area-inset-top)) 0.7rem max(1.2rem, env(safe-area-inset-bottom));
}

.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.55rem;
}

.eyebrow {
  margin: 0 0 0.05rem;
  color: var(--amber);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.22em;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 7vw, 2rem);
  line-height: 1;
  letter-spacing: 0.08em;
  text-shadow: 3px 3px 0 #6a315b;
}

.icon-button {
  width: 46px;
  padding: 0;
  color: var(--gold);
  font-size: 1.3rem;
}

.icon-button[aria-pressed="true"] {
  color: var(--muted);
  background: #17131f;
}

.hud {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.45rem 0.7rem;
  padding: 0.55rem;
  border: 2px solid var(--line);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: 0 5px 0 var(--shadow);
}

.floor-badge {
  grid-row: span 2;
  display: grid;
  min-width: 4.1rem;
  place-content: center;
  border: 2px solid #8a6442;
  color: var(--gold);
  background: #2b1d27;
  text-align: center;
}

.floor-badge > span {
  color: var(--muted);
  font-size: 0.65rem;
}

.floor-badge strong {
  font-size: 1.15rem;
}

.health-line {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.2rem;
  font-size: 0.72rem;
}

.health-track {
  height: 12px;
  overflow: hidden;
  border: 2px solid #0b0711;
  background: #34233a;
}

.health-bar {
  width: 100%;
  height: 100%;
  background: var(--green);
  transition: width 140ms steps(5), background 140ms linear;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.75rem;
  color: var(--muted);
  font-size: 0.7rem;
}

.stats b {
  color: var(--ink);
}

.quest {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 58px;
  margin: 0.65rem 0 0.45rem;
  padding: 0.45rem 0.6rem;
  border-left: 4px solid var(--blue);
  background: #171321;
}

.quest-icon {
  flex: 0 0 auto;
  color: var(--blue);
  font-size: 1.65rem;
  line-height: 1;
  text-shadow: 0 0 12px currentColor;
}

.quest strong {
  display: block;
  color: var(--blue);
  font-size: 0.78rem;
}

.quest p {
  margin: 0.08rem 0 0;
  color: var(--muted);
  font-size: 0.68rem;
}

.quest[data-complete="true"] {
  border-color: var(--gold);
}

.quest[data-complete="true"] .quest-icon,
.quest[data-complete="true"] strong {
  color: var(--gold);
}

.stage-shell {
  position: relative;
  width: 100%;
  overflow: hidden;
  aspect-ratio: 15 / 11;
  border: 3px solid #6d4c72;
  background: #050308;
  box-shadow:
    0 0 0 2px #171020,
    0 7px 0 var(--shadow),
    0 0 28px rgb(103 197 232 / 8%);
  touch-action: none;
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.action-row {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 0.7rem;
  margin-top: 0.8rem;
}

.potion-button {
  align-self: center;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.35rem;
  min-width: 8.7rem;
  padding: 0.65rem 0.7rem;
  border-color: #91404e;
  color: #ffbac1;
  background: #3a1d2b;
  text-align: left;
}

.potion-button > span:first-child {
  color: var(--red);
  font-size: 1.25rem;
}

.potion-button b {
  display: grid;
  min-width: 1.55rem;
  min-height: 1.55rem;
  place-content: center;
  border-radius: 50%;
  color: var(--ink);
  background: #8d3347;
}

.potion-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dpad {
  display: grid;
  grid-template-areas:
    ". up ."
    "left down right";
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(2, 48px);
  gap: 4px;
}

.dpad button {
  width: 48px;
  min-height: 48px;
  padding: 0;
  border-color: #635278;
  font-size: 1rem;
  user-select: none;
  -webkit-user-select: none;
}

#t-up { grid-area: up; }
#t-left { grid-area: left; }
#t-down { grid-area: down; }
#t-right { grid-area: right; }

.event-log {
  display: grid;
  gap: 0.18rem;
  min-height: 3.4rem;
  margin: 0.65rem 0;
  padding: 0.5rem 0.65rem;
  border: 1px solid #302541;
  color: var(--muted);
  background: rgb(9 6 17 / 62%);
  font-size: 0.68rem;
  list-style: none;
}

.event-log li::before {
  content: "› ";
}

.event-log [data-tone="loot"],
.event-log [data-tone="relic"] {
  color: var(--gold);
}

.event-log [data-tone="kill"],
.event-log [data-tone="level"] {
  color: var(--green);
}

.event-log [data-tone="strike"],
.event-log [data-tone="locked"] {
  color: #ff9295;
}

.event-log [data-tone="heal"] {
  color: #ffbac1;
}

.utility-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.utility-row > button {
  flex: 0 0 auto;
  padding: 0.55rem 0.7rem;
  color: var(--muted);
  background: #17131f;
}

details {
  flex: 1;
  border: 1px solid #302541;
  color: var(--muted);
  background: #17131f;
  font-size: 0.7rem;
}

summary {
  min-height: 42px;
  padding: 0.68rem;
  color: var(--ink);
  cursor: pointer;
}

details p {
  margin: 0;
  padding: 0 0.7rem 0.7rem;
}

.credits {
  margin-top: 0.5rem;
  opacity: 0.76;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  background: rgb(5 3 8 / 86%);
  transition: opacity 160ms linear;
}

.overlay[data-show="true"] {
  opacity: 1;
  pointer-events: auto;
}

.overlay-card {
  width: min(100%, 21rem);
  padding: 1rem;
  border: 3px double var(--gold);
  background: #1c1426;
  box-shadow: 8px 8px 0 #08050e;
  text-align: center;
}

.overlay-mark {
  display: block;
  color: var(--gold);
  font-size: 2.3rem;
  animation: pulse 900ms steps(2) infinite;
}

.overlay h2 {
  margin: 0.25rem 0;
  color: var(--gold);
  font-size: 1.25rem;
}

.overlay p {
  margin: 0 0 0.8rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.primary-action {
  width: 100%;
  border-color: #b77c37;
  color: #201409;
  background: var(--gold);
  font-weight: 900;
}

@keyframes pulse {
  50% { scale: 1.12; }
}

@media (min-width: 38rem) {
  main {
    padding-inline: 1.2rem;
  }

  .hud {
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
  }

  .floor-badge {
    grid-row: auto;
  }

  .stats {
    display: grid;
    min-width: 7rem;
  }

  .action-row {
    align-items: center;
  }

  .dpad {
    grid-template-columns: repeat(3, 54px);
    grid-template-rows: repeat(2, 54px);
  }

  .dpad button {
    width: 54px;
    min-height: 54px;
  }
}

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