/* Layout: full-bleed low-res 3D view, PS1-menu panels floating over it. Single dark look. */
:root {
  color-scheme: dark;
  --ink: #f3ead6;
  --dim: #a3a9c9;
  --panel: rgba(9, 11, 26, 0.92);
  --edge: #2c3878;
  --edge-hi: #7489e0;
  --brand: #333A91;
  --yellow: #ffd23f;
  --vfd: #5cf2c8;
  --paper: #f1ede2;
  --paper-ink: #232016;
  --display: "Press Start 2P", "Courier New", monospace;
  --body: "VT323", "Courier New", monospace;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: #000;
  color: var(--ink);
  font-family: var(--body);
  font-size: 21px;
  line-height: 1.15;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
}

button {
  font: inherit;
  color: inherit;
}

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

.panel {
  background: var(--panel);
  border: 2px solid var(--edge);
  box-shadow: inset 0 0 0 2px #05060f, inset 0 0 0 3px var(--edge-hi), 4px 4px 0 rgba(0, 0, 0, 0.6);
}

.label {
  font-family: var(--display);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--dim);
  text-transform: uppercase;
}

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

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  z-index: 20;
  touch-action: pan-y;
  background: linear-gradient(rgba(4, 5, 14, 0.55), rgba(4, 5, 14, 0.82)), repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.25) 0 1px, transparent 1px 3px);
}

#loading {
  background: #05060d;
  z-index: 40;
}

#loading-msg {
  font-family: var(--display);
  font-size: 11px;
  color: var(--vfd);
  max-width: 34ch;
  text-align: center;
  line-height: 1.8;
}

#loading-msg::after {
  content: '_';
  animation: blink 1s steps(1) infinite;
}

/* title */
.title-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 28px;
  width: min(980px, 100%);
  align-items: center;
}

.eyebrow {
  font-family: var(--display);
  font-size: 10px;
  color: var(--yellow);
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow i {
  width: 18px;
  height: 18px;
  background: var(--brand);
  border: 2px solid var(--yellow);
  transform: rotate(-10deg);
  display: inline-block;
  box-shadow: 0 0 0 2px #000;
}

.logo {
  font-family: var(--display);
  font-size: clamp(40px, 8.2vw, 84px);
  line-height: 0.98;
  margin: 18px 0 14px;
  color: var(--yellow);
  text-shadow: 3px 0 #000, -3px 0 #000, 0 3px #000, 0 -3px #000, 7px 7px 0 var(--brand), 10px 10px 0 #000;
  letter-spacing: -0.02em;
}

.logo span {
  display: block;
  color: var(--ink);
}

.tagline {
  font-size: 23px;
  color: var(--ink);
  max-width: 36ch;
  margin: 0 0 22px;
}

.menu {
  display: grid;
  gap: 8px;
  justify-items: start;
  margin-bottom: 18px;
}

.menu button {
  background: none;
  border: 0;
  padding: 4px 0 4px 26px;
  font-family: var(--display);
  font-size: 14px;
  cursor: pointer;
  position: relative;
  color: var(--ink);
  text-align: left;
}

.menu button.primary {
  color: var(--yellow);
  font-size: 16px;
}

.menu button::before {
  content: '\25B6';
  position: absolute;
  left: 0;
  top: 0;
  color: var(--yellow);
  opacity: 0;
}

.menu button.selected::before {
  opacity: 1;
  animation: blink 0.9s steps(1) infinite;
}

.menu button.selected {
  color: var(--yellow);
}

.keys {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  color: var(--dim);
  font-size: 19px;
}

.keys b {
  font-family: var(--display);
  font-size: 9px;
  color: var(--ink);
  background: #1b2149;
  border: 1px solid var(--edge-hi);
  padding: 3px 5px 2px;
  margin-right: 4px;
  font-weight: normal;
}

.settings-line {
  font-family: var(--display);
  font-size: 8px;
  color: var(--dim);
  margin-top: 14px;
  line-height: 1.8;
}

.settings-line::before {
  content: none;
}

#best {
  color: var(--vfd);
  font-size: 19px;
  margin-top: 4px;
  min-height: 1em;
}

#best:empty {
  display: none;
}

.mission {
  padding: 18px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.mission canvas {
  width: 150px;
  height: 210px;
  box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--yellow);
}

.mission h3 {
  font-family: var(--display);
  font-size: 12px;
  line-height: 1.6;
  margin: 8px 0 4px;
  color: var(--yellow);
  text-wrap: balance;
}

.mission .plat {
  color: var(--vfd);
  font-size: 20px;
  margin-bottom: 10px;
}

.mission p {
  margin: 0 0 8px;
  font-size: 20px;
  color: var(--ink);
}

.mission p.fine {
  color: var(--dim);
  font-size: 18px;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.find {
  position: absolute;
  left: 14px;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  display: flex;
  gap: 10px;
  padding: 8px 12px 8px 8px;
  align-items: center;
  max-width: min(360px, 60vw);
}

.find canvas {
  width: 50px;
  height: 70px;
  flex: none;
  box-shadow: 0 0 0 1px #000, 0 0 0 2px var(--yellow);
}

.find .t {
  font-family: var(--display);
  font-size: 9px;
  line-height: 1.6;
  color: var(--yellow);
  margin-top: 4px;
}

.find .p {
  color: var(--vfd);
  font-size: 18px;
}

#clock {
  position: absolute;
  right: 14px;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  padding: 6px 14px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: #050807;
  border: 2px solid #1d2b27;
  box-shadow: inset 0 0 12px rgba(92, 242, 200, 0.15), 4px 4px 0 rgba(0, 0, 0, 0.6);
}

#clock-time {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

#clock .ampm {
  font-family: var(--display);
  font-size: 9px;
  color: var(--vfd);
  opacity: 0.85;
}

#clock-hm {
  font-size: 44px;
  line-height: 1;
  color: var(--vfd);
  text-shadow: 0 0 6px rgba(92, 242, 200, 0.8);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

#clock .closes {
  font-family: var(--display);
  font-size: 8px;
  color: var(--dim);
  white-space: nowrap;
}

#clock.urgent #clock-hm, #clock.urgent .ampm {
  color: #ff4a4a;
  text-shadow: 0 0 6px rgba(255, 60, 60, 0.9);
  animation: blink 1s steps(1) infinite;
}

.xhair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  transform: translate(-50%, -50%);
}

.xhair::before, .xhair::after {
  content: '';
  position: absolute;
  background: var(--ink);
  box-shadow: 0 0 0 1px #000;
}

.xhair::before {
  left: 6px;
  top: 0;
  width: 2px;
  height: 14px;
}

.xhair::after {
  top: 6px;
  left: 0;
  height: 2px;
  width: 14px;
}

.aim {
  position: absolute;
  left: 50%;
  top: calc(50% + 22px);
  transform: translateX(-50%);
  text-align: center;
  padding: 6px 10px 5px;
  max-width: 80vw;
}

.aim .a1 {
  font-family: var(--display);
  font-size: 10px;
  line-height: 1.5;
  color: var(--ink);
}

.aim .a2 {
  font-size: 18px;
  color: var(--yellow);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 78px);
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 14px 8px 8px;
  max-width: min(520px, 92vw);
}

.toast canvas {
  width: 50px;
  height: 70px;
  flex: none;
  box-shadow: 0 0 0 1px #000;
}

.toast .t1 {
  font-family: var(--display);
  font-size: 10px;
  line-height: 1.6;
}

.toast .t2 {
  font-size: 20px;
  color: var(--dim);
}

.toast.close {
  border-color: var(--yellow);
}

.toast.close .t2 {
  color: var(--yellow);
}

.pa {
  position: absolute;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 124px);
  transform: translateX(-50%);
  width: min(560px, 92vw);
  padding: 0;
  overflow: hidden;
}

.pa .tag {
  background: var(--brand);
  color: #fff;
  font-family: var(--display);
  font-size: 9px;
  padding: 6px 10px 5px;
  letter-spacing: 0.06em;
}

.pa .msg {
  padding: 8px 12px 10px;
  font-size: 21px;
}

.say {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 184px);
  transform: translateX(-50%);
  width: min(620px, 92vw);
  padding: 14px 16px 12px;
}

.say .who {
  position: absolute;
  top: -12px;
  left: 14px;
  background: #2e7d32;
  color: #fff;
  font-family: var(--display);
  font-size: 9px;
  padding: 5px 8px 4px;
  border: 2px solid #000;
}

.say p {
  margin: 4px 0 0;
  font-size: 22px;
}

.help {
  position: absolute;
  left: 14px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  padding: 8px 12px;
  transition: opacity 1.2s;
}

.help.fade {
  opacity: 0;
}

.clerk-label {
  position: absolute;
  left: 50%;
  top: calc(50% + 22px);
  transform: translateX(-50%);
  padding: 6px 10px 5px;
  font-family: var(--display);
  font-size: 10px;
  color: #8dff9d;
}

.drag-hint {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  padding: 8px 12px;
  font-size: 21px;
}

/* touch */
.touch-ui {
  display: none;
}

body.touch.playing .touch-ui {
  display: block;
}

#btn-grab, #btn-crouch, #btn-pause {
  touch-action: none;
  -webkit-touch-callout: none;
}

body.touch .help, body.touch .keys, body.touch .settings-line, body.touch .pause-hint, body.touch #drag-hint {
  display: none;
}

#btn-grab, #btn-pause {
  position: fixed;
  z-index: 15;
  pointer-events: auto;
  font-family: var(--display);
  background: var(--panel);
  border: 2px solid var(--edge-hi);
  color: var(--yellow);
}

#btn-grab {
  right: 22px;
  bottom: max(env(safe-area-inset-bottom, 0px), 30px);
  width: 84px;
  height: 84px;
  border-radius: 50%;
  font-size: 11px;
}

#btn-pause {
  right: 14px;
  top: calc(env(safe-area-inset-top, 0px) + 92px);
  padding: 8px 10px;
  font-size: 9px;
}

#btn-crouch {
  position: fixed;
  z-index: 15;
  pointer-events: auto;
  right: 118px;
  bottom: max(env(safe-area-inset-bottom, 0px), 40px);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  padding: 0;
  font-family: var(--display);
  font-size: 8px;
  background: var(--panel);
  border: 2px solid var(--edge-hi);
  color: var(--ink);
}

#btn-crouch.on {
  color: var(--yellow);
  border-color: var(--yellow);
}

.pause-hint {
  font-family: var(--display);
  font-size: 8px;
  color: var(--dim);
  margin: 12px 0 0;
}

.reveal {
  position: fixed;
  z-index: 25;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  transform: translateX(-50%);
  width: min(560px, 92vw);
  padding: 14px 16px;
  text-align: center;
  pointer-events: auto;
}

.reveal .r1 {
  font-family: var(--display);
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.08em;
}

.reveal .r2 {
  font-family: var(--display);
  font-size: 13px;
  line-height: 1.6;
  color: var(--yellow);
  margin: 8px 0 4px;
}

.reveal .r3 {
  font-size: 20px;
  margin-bottom: 12px;
}

#stick {
  position: fixed;
  z-index: 15;
  width: 110px;
  height: 110px;
  margin: -55px 0 0 -55px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

#stick-knob {
  position: absolute;
  left: 35px;
  top: 35px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 210, 63, 0.6);
}

/* pause + end */
.card {
  padding: 22px 24px;
  width: min(460px, 100%);
}

.card h2 {
  font-family: var(--display);
  font-size: 18px;
  margin: 0 0 12px;
  color: var(--yellow);
}

.card p {
  margin: 0 0 12px;
  font-size: 21px;
}

#pause .card {
  box-sizing: border-box;
  width: min(512px, 100%);
}

.pause-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.pause-head h2 {
  margin: 0;
}

#btn-mute {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 8px;
  color: var(--yellow);
}

#btn-mute svg {
  width: 24px;
  height: 24px;
}

#btn-mute .sound-off, #btn-mute.muted .sound-on {
  display: none;
}

#btn-mute.muted .sound-off {
  display: block;
}

.end-wrap {
  display: grid;
  gap: 18px;
  justify-items: center;
  width: min(480px, 100%);
}

.end-head {
  text-align: center;
}

.end-head h1 {
  font-family: var(--display);
  font-size: clamp(26px, 7vw, 44px);
  margin: 0 0 8px;
  color: var(--yellow);
  text-shadow: 4px 4px 0 var(--brand), 6px 6px 0 #000;
}

.end-head p {
  margin: 0;
  font-size: 22px;
}

.receipt {
  background: var(--paper);
  color: var(--paper-ink);
  width: min(360px, 100%);
  padding: 18px 18px 22px;
  font-size: 20px;
  line-height: 1.2;
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.6);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 8px), 95% 100%, 90% calc(100% - 8px), 85% 100%, 80% calc(100% - 8px), 75% 100%, 70% calc(100% - 8px), 65% 100%, 60% calc(100% - 8px), 55% 100%, 50% calc(100% - 8px), 45% 100%, 40% calc(100% - 8px), 35% 100%, 30% calc(100% - 8px), 25% 100%, 20% calc(100% - 8px), 15% 100%, 10% calc(100% - 8px), 5% 100%, 0 calc(100% - 8px));
}

.receipt .c {
  text-align: center;
}

.receipt-brand {
  display: block;
  width: 180px;
  max-width: 100%;
  height: auto;
  margin: 0 auto 12px;
}

.receipt hr {
  border: 0;
  border-top: 2px dashed #8d8775;
  margin: 10px 0;
}

.receipt .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-variant-numeric: tabular-nums;
}

.receipt .row span:last-child {
  text-align: right;
}

.receipt .item {
  font-weight: bold;
}

.receipt-barcode {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 10px auto 0;
  shape-rendering: crispEdges;
}

.lost-text {
  max-width: 40ch;
  text-align: center;
  font-size: 22px;
  color: var(--ink);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.btn {
  background: #1b2149;
  border: 2px solid var(--edge-hi);
  padding: 10px 14px 9px;
  font-family: var(--display);
  font-size: 11px;
  cursor: pointer;
  color: var(--ink);
  box-shadow: 3px 3px 0 #000;
}

.btn.primary {
  background: var(--brand);
  border-color: var(--yellow);
  color: #fff;
}

.btn:hover {
  filter: brightness(1.2);
}

.btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #000;
}

.btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.share-status {
  margin: 0;
  text-align: center;
  color: var(--ink);
  font-size: 20px;
}

.receipt-preview {
  width: min(560px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  box-sizing: border-box;
  padding: 20px;
  color: var(--ink);
}

.receipt-preview[open] {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.receipt-preview::backdrop {
  background: rgba(0, 0, 0, 0.82);
}

.receipt-preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex: none;
}

.receipt-preview-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 12px;
  line-height: 1.6;
  color: var(--yellow);
}

.receipt-preview-close {
  padding: 9px 10px;
  font-size: 10px;
}

.receipt-preview-content {
  min-height: 0;
  height: 60vh;
  height: 60dvh;
}

#receipt-preview-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.receipt-preview .btn-row, .receipt-preview .share-status {
  flex: none;
}

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

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

@media (max-width: 760px) {
  .title-wrap {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  .mission {
    grid-template-columns: 100px minmax(0, 1fr);
  }

  .mission canvas {
    width: 100px;
    height: 140px;
  }

  .find .t {
    font-size: 8px;
  }

  #clock-hm {
    font-size: 34px;
  }

  .pa {
    top: calc(env(safe-area-inset-top, 0px) + 120px);
  }

  .find {
    max-width: calc(100vw - 150px);
  }

  .say {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 236px);
  }

  .toast {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 128px);
  }

  .say p, .pa .msg {
    font-size: 19px;
  }
}

/* Reserve real space for both HUD columns, including long hunt titles. */
body.touch .hud-top {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  left: max(14px, env(safe-area-inset-left, 0px));
  right: max(14px, env(safe-area-inset-right, 0px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

body.touch .find {
  position: static;
  box-sizing: border-box;
  min-width: 0;
  max-width: 360px;
  padding: 8px;
  gap: 8px;
}

body.touch .find > div {
  min-width: 0;
  overflow-wrap: anywhere;
}

body.touch .find canvas {
  width: 42px;
  height: 59px;
}

body.touch .find .t {
  font-size: 8px;
}

body.touch .find .p {
  font-size: 16px;
}

body.touch .hud-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

body.touch #clock {
  position: relative;
  top: auto;
  right: auto;
  padding: 6px 8px 4px;
  gap: 5px;
}

body.touch #clock-hm {
  font-size: 34px;
}

body.touch #clock .ampm {
  font-size: 7px;
}

body.touch #clock .closes {
  font-size: 6px;
}

body.touch #btn-pause {
  position: static;
  margin-top: 20px;
  min-height: 44px;
}

body.touch .pa {
  position: static;
  grid-column: 1 / -1;
  justify-self: center;
  box-sizing: border-box;
  width: min(560px, 100%);
  transform: none;
}

body.touch .aim, body.touch .clerk-label {
  top: calc(50% + clamp(48px, 9vh, 80px));
  box-sizing: border-box;
  width: max-content;
  max-width: 80vw;
}

body.touch #btn-grab {
  right: calc(env(safe-area-inset-right, 0px) + 22px);
}

body.touch #btn-crouch {
  right: calc(env(safe-area-inset-right, 0px) + 118px);
}

@media (orientation: portrait) {
  body.touch #btn-crouch {
    right: calc(env(safe-area-inset-right, 0px) + 32px);
    bottom: calc(max(env(safe-area-inset-bottom, 0px), 30px) + 96px);
  }

  body.touch .logo {
    font-size: clamp(48px, 8.2vw, 84px);
  }
}

@media (orientation: landscape) {
  body.touch .overlay {
    padding-left: calc(env(safe-area-inset-left, 0px) + 24px);
    padding-right: calc(env(safe-area-inset-right, 0px) + 24px);
  }

  body.touch #title-screen {
    align-items: safe center;
  }

  body.touch .title-wrap {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }

  body.touch .logo {
    font-size: clamp(40px, 5vw, 84px);
  }

  body.touch .hud-status {
    flex-direction: row;
    gap: 12px;
    align-items: flex-start;
  }

  body.touch #btn-pause {
    margin-top: 0;
  }

  body.touch .aim, body.touch .clerk-label {
    max-width: max(180px, calc(100vw - 380px - 2 * env(safe-area-inset-right, 0px)));
  }
}
