/* Pixel-art handheld RPG styling: chunky borders, stepped corners, hard shadows, no smoothing. */
:root {
  --ink: #1a1423;
  --paper: #fff8e7;
  --paper-2: #f3e6c8;
  --line: #1a1423;
  --shade: #c9b48a;
  --accent: #e2562a;
  --accent-dark: #9c2f12;
  --gold: #ffd34d;
  --gold-dark: #c48a12;
  --red: #e2413c;
  --green: #3e9b4f;
  --blue: #3d4f9e;
  --page: #2b2340;
  --page-2: #241d36;
  --title: 'Press Start 2P', ui-monospace, monospace;
  --text: 'Pixelify Sans', ui-monospace, monospace;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font: 18px/1.35 var(--text);
  background-color: var(--page);
  background-image:
    linear-gradient(45deg, var(--page-2) 25%, transparent 25%, transparent 75%, var(--page-2) 75%),
    linear-gradient(45deg, var(--page-2) 25%, transparent 25%, transparent 75%, var(--page-2) 75%);
  background-position: 0 0, 8px 8px;
  background-size: 16px 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

h1,
h2 {
  margin: 0;
  font-weight: 400;
}

:focus-visible {
  outline: 3px dashed var(--gold);
  outline-offset: 2px;
}

/* Stepped 4px corners: the classic pixel window shape. */
.window,
.px-btn,
.menu-item,
.px-action,
.hud-tag,
.toast {
  clip-path: polygon(0 4px, 4px 4px, 4px 0, calc(100% - 4px) 0, calc(100% - 4px) 4px, 100% 4px, 100% calc(100% - 4px), calc(100% - 4px) calc(100% - 4px), calc(100% - 4px) 100%, 4px 100%, 4px calc(100% - 4px), 0 calc(100% - 4px));
}

/* The pixel world fills the window; the UI floats over it. */
.world {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.world.dim {
  filter: brightness(0.6) saturate(0.9);
}

body.playing {
  overflow: hidden;
}

.ui {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  pointer-events: none;
}

.ui-top,
.ui-bottom {
  pointer-events: auto;
}

.ui-bottom {
  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 580px;
  margin: 0 auto;
}

/* the rung clock: a pixel bar that drains in steps, going orange then flashing red */
.timer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  justify-self: center;
  width: min(100%, 360px);
  padding: 7px 10px;
  background: var(--paper);
  box-shadow: inset 0 0 0 3px var(--ink), inset 0 -6px 0 var(--shade);
  font: 9px/1 var(--title);
}

.timer[hidden] {
  display: none;
}

.timer b {
  min-width: 2ch;
  font-size: 12px;
  font-weight: 400;
  text-align: right;
}

.timer-bar {
  position: relative;
  height: 10px;
  background: #3a3358;
  box-shadow: 0 0 0 2px var(--ink);
}

.timer-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--left, 1) * 100%);
  background: repeating-linear-gradient(90deg, var(--gold) 0 10px, var(--gold-dark) 10px 12px);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45);
}

.timer.low .timer-bar i {
  background: repeating-linear-gradient(90deg, #ff9a3d 0 10px, var(--accent-dark) 10px 12px);
}

.timer.low b {
  color: var(--accent);
}

.timer.critical {
  animation: timer-flash 0.5s steps(1) infinite;
}

.timer.critical .timer-bar i {
  background: repeating-linear-gradient(90deg, var(--red) 0 10px, #8e1f22 10px 12px);
}

@keyframes timer-flash {
  50% {
    background: #ffd0cc;
  }
}

@media (prefers-reduced-motion: reduce) {
  .timer.critical {
    animation: none;
  }
}

.ui-top {
  display: grid;
  gap: 10px;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}

.result-page {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px 28px;
}

/* ---------- top strip ---------- */

.strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  padding: 0;
  border: 0;
  background: none;
  color: var(--gold);
  font: 18px/1 var(--title);
  text-shadow: 3px 3px 0 var(--accent-dark), 3px 0 0 var(--accent-dark), 0 3px 0 var(--accent-dark);
  cursor: pointer;
}

.strip-buttons {
  display: flex;
  gap: 6px;
}

.px-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  background: var(--paper);
  box-shadow: inset -3px -3px 0 var(--shade), inset 3px 3px 0 #fff;
  font: 12px/1 var(--title);
  cursor: pointer;
}

.px-btn:active {
  box-shadow: inset 3px 3px 0 var(--shade);
}

.px-icon {
  display: block;
  image-rendering: pixelated;
}

/* ---------- the game screen ---------- */

.hud {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: start;
  pointer-events: none;
}

.hud-tag {
  padding: 6px 8px;
  background: var(--paper);
  box-shadow: inset 0 -3px 0 var(--shade);
  font: 9px/1.3 var(--title);
}

.hud-tag.left {
  display: grid;
  gap: 4px;
}

.hud-tag.left b {
  color: var(--accent);
  font-size: 18px;
  font-weight: 400;
}

.hud-tag.center {
  justify-self: center;
  align-self: start;
  max-width: 100%;
  text-align: center;
}

.hearts {
  display: flex;
  gap: 3px;
  padding: 8px;
}

.hearts.hurt {
  animation: hurt 0.5s steps(4) both;
}

.title-card {
  position: absolute;
  inset: 20% 0 auto;
  text-align: center;
  pointer-events: none;
  animation: float 2.4s steps(2) infinite;
}

.title-card h1 {
  color: var(--gold);
  font: clamp(34px, 11vw, 48px) / 1 var(--title);
  text-shadow:
    4px 4px 0 var(--accent-dark),
    -2px -2px 0 var(--ink),
    2px -2px 0 var(--ink),
    -2px 2px 0 var(--ink),
    6px 6px 0 var(--ink);
}

.title-card p {
  display: inline-block;
  margin: 14px 0 0;
  padding: 6px 10px;
  background: var(--ink);
  color: #fff;
  font: 10px/1.4 var(--title);
}

/* ---------- windows & dialog ---------- */

.window {
  position: relative;
  padding: 16px 16px 14px;
  background: var(--paper);
  box-shadow:
    inset 0 0 0 4px var(--ink),
    inset 0 0 0 7px var(--paper),
    inset 0 0 0 9px var(--shade);
}

.window-title {
  margin: 4px 0 12px;
  font: 14px/1.4 var(--title);
}

.window-title.small {
  font-size: 11px;
}

.dialog {
  width: 100%;
  max-width: 580px;
  min-height: 180px;
  margin: 0 auto;
  padding: 18px 20px 16px;
}

.dialog-text {
  min-height: 72px;
  margin: 0 0 12px;
  font-size: 20px;
  line-height: 1.3;
}

.dialog-text b,
.answer label b {
  color: var(--accent-dark);
  font-weight: 700;
}

.dialog-arrow {
  position: absolute;
  right: 18px;
  bottom: 12px;
  font-size: 12px;
  animation: blink 0.8s steps(1) infinite;
}

.menu {
  display: grid;
  gap: 6px;
}

.menu.row {
  grid-template-columns: 1fr 1fr;
}

.menu.small {
  margin-top: 10px;
  justify-items: start;
}

.menu-item {
  position: relative;
  min-height: 44px;
  padding: 10px 14px 10px 30px;
  border: 0;
  background: var(--paper-2);
  box-shadow: inset -3px -3px 0 var(--shade);
  font: 11px/1.4 var(--title);
  text-align: left;
  cursor: pointer;
}

.menu.small .menu-item {
  min-height: 34px;
  padding: 8px 12px 8px 26px;
  font-size: 9px;
}

.menu-item::before {
  content: '▶';
  position: absolute;
  left: 12px;
  top: 50%;
  translate: 0 -50%;
  font-size: 10px;
  opacity: 0;
}

.menu-item:hover::before,
.menu-item:focus-visible::before,
.menu-item.primary::before {
  opacity: 1;
}

.menu-item.primary::before {
  animation: nudge 0.6s steps(2) infinite;
}

.menu-item.primary {
  background: var(--accent);
  box-shadow: inset -3px -3px 0 var(--accent-dark), inset 3px 3px 0 #ff8b5e;
  color: #fff;
}

.menu-item:active {
  translate: 0 2px;
}

.answer label {
  display: block;
  margin-bottom: 8px;
  font: 9px/1.6 var(--title);
}

.dialog-text:has(+ .suggest) {
  min-height: 0;
}

.suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: -4px 0 14px;
}

.suggest small {
  flex-basis: 100%;
  color: #9c8660;
  font: 14px/1 var(--text);
}

.suggest-btn {
  padding: 10px 14px 12px;
  border: 0;
  background: var(--gold);
  box-shadow: inset 0 0 0 2px var(--ink), inset 0 -4px 0 var(--gold-dark);
  color: var(--ink);
  font: 11px/1 var(--title);
  cursor: pointer;
  animation: pop-in 0.25s steps(3) both;
}

.suggest-btn:hover,
.suggest-btn:focus-visible {
  background: #fff3c4;
  outline: none;
}

.suggest-btn[data-first] {
  box-shadow: inset 0 0 0 2px var(--ink), inset 0 -4px 0 var(--gold-dark), 0 0 0 2px var(--accent);
}

@keyframes pop-in {
  from {
    transform: translateY(4px);
    opacity: 0;
  }
}

.answer label i {
  color: #8a6a3a;
  font-style: normal;
}

.answer-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 4px 4px 10px;
  background: #fff;
  box-shadow: inset 0 0 0 3px var(--ink);
}

.caret {
  color: var(--accent);
  font-size: 14px;
  animation: blink 0.8s steps(1) infinite;
}

.answer input {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  padding: 0;
  border: 0;
  background: transparent;
  font: 500 22px/1 var(--text);
  text-transform: uppercase;
}

.answer input::placeholder {
  color: #b9a988;
  text-transform: none;
}

.answer input:focus {
  outline: none;
}

.px-action {
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  background: var(--green);
  box-shadow: inset -3px -3px 0 #1f5e2b, inset 3px 3px 0 #6fc77d;
  color: #fff;
  font: 11px/1 var(--title);
  cursor: pointer;
}

.px-action:active {
  translate: 0 2px;
}

/* ---------- results ---------- */

.report-body {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: start;
}

#minimap {
  width: 80px;
  height: 300px;
  image-rendering: pixelated;
  box-shadow: 0 0 0 3px var(--ink);
}

.report-kicker {
  margin: 0;
  font: 9px/1.6 var(--title);
  color: #8a6a3a;
}

.big-score {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin: 10px 0 8px;
}

.big-score b {
  color: var(--accent);
  font: 56px/1 var(--title);
  font-weight: 400;
  text-shadow: 4px 4px 0 var(--gold);
}

.big-score span {
  padding-bottom: 4px;
  font: 12px/1 var(--title);
}

.rank {
  margin: 0 0 12px;
  font: 10px/1.6 var(--title);
}

.rank b {
  color: var(--blue);
  font-weight: 400;
}

.facts {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.facts li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 4px;
  border-bottom: 2px dotted var(--shade);
  font-size: 16px;
}

.facts b {
  text-align: right;
}

.facts.big li {
  font-size: 20px;
}

.report-line {
  margin: 14px 0;
  font-size: 19px;
}

.next {
  margin: 12px 0 0;
  font: 9px/1.6 var(--title);
  text-align: center;
}

.next b {
  color: var(--accent);
  font-weight: 400;
}

.gap-list,
.crack-list,
.tier-list,
.how {
  margin: 0;
  padding: 0;
  list-style: none;
}

.gap-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 10px;
  padding: 8px 0;
  border-bottom: 2px dotted var(--shade);
}

.gap-span {
  font-weight: 700;
}

.gap-count {
  grid-row: span 2;
  align-self: center;
  color: var(--red);
  font: 11px/1 var(--title);
}

.gap-list li.tight .gap-count {
  color: var(--green);
  font-size: 9px;
}

.gap-names {
  color: #7a6440;
  font-size: 15px;
}

.crack-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 2px dotted var(--shade);
}

.crack-list i {
  color: #7a6440;
  font-style: normal;
}

.crack-list b {
  color: var(--red);
  font: 9px/1 var(--title);
}

.tier-list li {
  display: grid;
  grid-template-columns: 52px 1fr;
  padding: 7px 0;
  border-bottom: 2px dotted var(--shade);
  color: #8a7a5a;
}

.tier-list li span:first-child {
  font: 9px/2 var(--title);
}

.tier-list li.mine {
  color: var(--ink);
  font-weight: 700;
}

.tier-list li.mine span:last-child::before {
  content: '▶ ';
  color: var(--accent);
}

/* ---------- modals ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(26 20 35 / 72%);
}

.modal {
  width: min(100%, 420px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 20px;
  animation: pop 0.18s steps(3) both;
}

.modal .close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
}

.how li {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
}

.how b {
  flex: none;
  color: var(--accent);
  font: 11px/1.8 var(--title);
}

.how em {
  color: var(--accent-dark);
  font-style: normal;
  font-weight: 700;
}

.note {
  margin: 10px 0 14px;
  color: #7a6440;
  font-size: 15px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  padding: 12px 16px;
  background: var(--ink);
  color: var(--gold);
  font: 10px/1.4 var(--title);
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.15s steps(2), transform 0.15s steps(2);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes blink {
  50% { opacity: 0; }
}

@keyframes nudge {
  50% { translate: 3px -50%; }
}

@keyframes float {
  50% { transform: translateY(-4px); }
}

@keyframes hurt {
  0%, 50% { transform: translateX(-4px); filter: brightness(1.6); }
  25%, 75% { transform: translateX(4px); }
}

@keyframes pop {
  from { transform: scale(0.9); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- end-of-climb banner, screen wipe, results entrance ---------- */

.banner {
  position: absolute;
  inset: 26% 0 auto;
  display: grid;
  place-items: center;
  pointer-events: none;
  animation: drop 0.5s steps(5) both;
}

.banner span {
  padding: 14px 22px;
  background: var(--ink);
  color: var(--gold);
  font: clamp(26px, 7vw, 44px) / 1 var(--title);
  text-shadow: 4px 4px 0 var(--accent-dark);
  box-shadow: 0 0 0 4px var(--paper), 0 0 0 8px var(--ink);
}

.banner.fell span {
  color: #ff8a80;
}

.banner.done span {
  color: var(--paper);
}

.wipe {
  position: fixed;
  inset: 0;
  z-index: 100;
  image-rendering: pixelated;
  pointer-events: none;
}

.result-page > .window {
  animation: slide-in 0.24s steps(4) both;
  animation-delay: calc(var(--i, 0) * 50ms + 30ms);
}

#curve {
  display: block;
  width: 100%;
  aspect-ratio: 160 / 72;
  image-rendering: pixelated;
  box-shadow: 0 0 0 3px var(--ink);
}

#curve[hidden] {
  display: none;
}

.curve-line {
  margin: 12px 0 0;
  font-size: 19px;
}

.curve-line b {
  color: var(--accent-dark);
}

.curve-line small {
  display: block;
  margin-top: 4px;
  color: #7a6440;
  font-size: 14px;
}

@keyframes drop {
  from { transform: translateY(-60px); opacity: 0; }
}

@keyframes slide-in {
  from { transform: translateY(24px); opacity: 0; }
}

.menu-item.dev {
  margin-top: 8px;
  width: 100%;
  background: #dfe4f5;
  box-shadow: inset -3px -3px 0 #9aa3c9;
}

/* ---------- your record: stats tiles, history chart, result badges ---------- */

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tile {
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 10px 4px;
  background: var(--paper-2);
  box-shadow: 0 0 0 2px var(--ink);
  text-align: center;
}

.tile b {
  font: 18px/1 var(--title);
}

.tile span {
  font: 7px/1.4 var(--title);
  color: #7a6440;
}

.tile.hot {
  background: var(--gold);
}

.tile.hot span {
  color: var(--accent-dark);
}

.sub {
  margin: 16px 0 8px;
  font: 9px/1.6 var(--title);
}

#history {
  display: block;
  width: 100%;
  aspect-ratio: 160 / 60;
  image-rendering: pixelated;
  box-shadow: 0 0 0 2px var(--ink);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin: 8px 0 0;
  font-size: 14px;
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: -6px;
  box-shadow: 0 0 0 2px var(--ink);
}

.legend .k-top { background: #ffd34d; }
.legend .k-fell { background: #ff8a80; }
.legend .k-done { background: #6db6f2; }

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -4px 0 12px;
}

.badges span {
  padding: 5px 7px;
  background: var(--accent);
  color: var(--paper);
  font: 8px/1 var(--title);
  box-shadow: 0 0 0 2px var(--ink);
  animation: badge 0.9s steps(2) 3;
}

@keyframes badge {
  50% { background: var(--gold); color: var(--ink); }
}

@media (prefers-reduced-motion: reduce) {
  .badges span { animation: none; }
}
