@font-face {
  font-family: "Pixelify Sans";
  src: url("/fonts/pixelify-sans-700.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("/fonts/atkinson-hyperlegible-400.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("/fonts/atkinson-hyperlegible-700.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --ink: #17172d;
  --panel: #21213a;
  --line: #575473;
  --cream: #fff4dd;
  --muted: #d1c7db;
  --gold: #ffd46e;
  --mint: #82f2c9;
  --coral: #ff898b;
  --display: "Pixelify Sans", monospace;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--cream);
  font: 1rem/1.4 var(--body);
}

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

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

:is(button, a, summary):focus-visible {
  outline: 3px solid var(--mint);
  outline-offset: 4px;
}

.cabinet {
  --gutter: clamp(0.6rem, 2vw, 1.5rem);
  position: fixed;
  inset: 0;
  isolation: isolate;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0.5rem;
  overflow: hidden;
  padding: max(0.6rem, env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    max(0.6rem, env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
}

.game-header {
  position: relative;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  pointer-events: none;
}

.game-header h1 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  color: var(--gold);
  font: 700 clamp(1.35rem, 3.5vw, 2rem)/1 var(--display);
  text-shadow: 2px 3px #1a172b;
}

.arcade-link {
  flex: 0 0 auto;
  padding: 0.48rem 0.7rem;
  border: 1px solid var(--line);
  color: var(--cream);
  background: rgba(23, 23, 45, 0.9);
  font-size: 0.875rem;
  font-weight: 700;
  text-decoration: none;
  pointer-events: auto;
}

.arcade-link:hover { border-color: var(--gold); }
.embedded .arcade-link { display: none; }

.robot-mark {
  position: relative;
  display: block;
  flex: 0 0 auto;
  width: 1.45rem;
  height: 1.2rem;
  border: 2px solid #192033;
  background: #7894a4;
  box-shadow: inset 0 -3px #527080;
}

.robot-mark::before {
  position: absolute;
  content: "";
  inset: -22% -26% auto;
  height: 34%;
  background: var(--gold);
  box-shadow: 0 2px #bd833f;
}

.robot-mark::after {
  position: absolute;
  content: "";
  inset: 36% 21% 28%;
  background: linear-gradient(90deg, var(--mint) 0 26%, #20263e 26% 74%, var(--mint) 74%);
}

.game-deck {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  align-items: start;
  gap: 0.5rem;
  min-height: 0;
}

.dashboard {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(7rem, 1fr) minmax(7rem, 1fr) minmax(20rem, 2.6fr);
  gap: 0.75rem;
  width: min(100%, 52rem);
  padding: 0.56rem 0.75rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  background: rgba(23, 23, 45, 0.94);
  box-shadow: 3px 4px 0 rgba(13, 12, 25, 0.42);
  pointer-events: none;
}

.meter-label,
.inventory dt {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.15;
}

.meter-label {
  display: flex;
  justify-content: space-between;
  gap: 0.25rem;
}

.meter-label b,
.inventory dd {
  font-variant-numeric: tabular-nums;
  color: var(--cream);
}

.meter-track {
  height: 0.56rem;
  margin-top: 0.36rem;
  overflow: hidden;
  background: #3a384f;
}

.meter-fill {
  width: 100%;
  height: 100%;
  background-image: repeating-linear-gradient(90deg, transparent 0 13px, #17172d55 13px 15px);
}

.energy .meter-fill { background-color: var(--mint); }
.suspicion .meter-fill { width: 0; background-color: var(--coral); }

.inventory {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
  margin: 0;
  padding-left: 0.75rem;
  border-left: 1px solid var(--line);
}

.inventory dt { white-space: nowrap; }

.inventory dd {
  margin: 0;
  font-weight: 700;
  line-height: 1.15;
}

#cash { color: var(--gold); }

.hat-adjust {
  position: relative;
  z-index: 4;
  grid-row: 2;
  justify-self: end;
  align-self: start;
  display: grid;
  justify-items: center;
  gap: 0.25rem;
  width: 3.2rem;
  padding: 0.4rem 0.2rem;
  border: 1px solid var(--line);
  background: rgba(23, 23, 45, 0.94);
  color: var(--cream);
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.1;
}

#hat-cover {
  width: 2.75rem;
  height: clamp(3.5rem, 15dvh, 7rem);
  margin: 0;
  writing-mode: vertical-lr;
  direction: ltr;
  accent-color: var(--gold);
  cursor: ns-resize;
  touch-action: none;
}

#hat-cover:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 2px;
}

#hat-state {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

#interact-hint:empty,
#notice:empty,
#scene-stats:empty { display: none; }

.stage,
#city,
.vignette,
.overlay { position: absolute; inset: 0; }

#city {
  display: block;
  width: 100%;
  height: 100%;
  background: #3c364d;
  touch-action: none;
}

#city:focus { outline: none; }

.stage::after {
  position: absolute;
  z-index: 2;
  inset: 0 0 auto;
  height: var(--hat-cover, 0%);
  background: radial-gradient(ellipse at 50% 12%, #201d2c, #101019 64%);
  box-shadow: inset 0 -4px rgba(105, 86, 112, 0.24);
  content: "";
  pointer-events: none;
}

.vignette {
  z-index: 1;
  background: radial-gradient(ellipse at 50% 47%, transparent 45%, rgba(16, 14, 31, 0.45) 100%);
  pointer-events: none;
}

body[data-scene="hospital"] .vignette {
  background: radial-gradient(ellipse at 50% 47%, transparent 44%, rgba(37, 109, 104, 0.5) 100%);
}

body[data-alert="chase"] .vignette,
body[data-alert="military"] .vignette {
  background: radial-gradient(ellipse at 50% 47%, transparent 50%, rgba(201, 46, 59, 0.5) 100%);
}

body[data-scan="true"] .vignette {
  box-shadow: inset 0 0 0 3px #ffd46ed9, inset 0 0 2.5rem #fec54c59;
}

.reticle {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: 1.125rem;
  height: 1.125rem;
  translate: -50% -50%;
  background:
    linear-gradient(var(--cream), var(--cream)) center top / 2px 4px no-repeat,
    linear-gradient(var(--cream), var(--cream)) center bottom / 2px 4px no-repeat,
    linear-gradient(var(--cream), var(--cream)) center left / 4px 2px no-repeat,
    linear-gradient(var(--cream), var(--cream)) center right / 4px 2px no-repeat;
  filter: drop-shadow(0 1px 1px var(--ink));
  pointer-events: none;
}

body[data-scene="hospital"] .reticle,
body:has(#scene-panel:not([hidden])) .reticle { visibility: hidden; }

.overlay {
  z-index: 8;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: clamp(0.8rem, 4vw, 2.25rem);
  background: rgba(18, 16, 37, 0.68);
  overscroll-behavior: contain;
}

.intro-overlay {
  background:
    radial-gradient(ellipse at center, #211c3ca6 0 35%, #151326e8 92%),
    linear-gradient(0deg, #472c5077, transparent);
}

.scene-card {
  width: min(100%, 30rem);
  max-height: 100%;
  overflow: auto;
  padding: clamp(1rem, 4vw, 1.9rem);
  border: 1px solid #79738c;
  border-top: 4px solid var(--gold);
  background: #202039ed;
  box-shadow: 6px 7px 0 #100d21a6;
}

.intro-card {
  width: min(100%, 33rem);
  margin-top: 1.25rem;
  text-align: center;
}

.scene-card h2 {
  margin: 0 0 0.65rem;
  color: var(--gold);
  font: 700 clamp(1.8rem, 4.5vw, 2.9rem)/0.95 var(--display);
}

.intro-card h2 {
  margin-bottom: 0.85rem;
  font-size: clamp(2.65rem, 8vw, 5rem);
  text-shadow: 3px 4px #8f593f, 6px 6px #151429;
}

.scene-card p { margin: 0 0 1rem; }

.intro-card > p:not(.look-help) {
  max-width: 27ch;
  margin-inline: auto;
}

.intro-mark {
  width: 3.1rem;
  height: 2.4rem;
  margin: 0.4rem auto 0.6rem;
  border-width: 4px;
}

.primary-button,
.scene-actions button,
.touch-actions button,
.direction-pad button {
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 2px 3px 0 #110f23;
  font-weight: 700;
}

.primary-button,
.scene-actions .primary-button {
  min-width: 10rem;
  border-color: #fff0a6;
  background: var(--gold);
  color: #261d29;
  font: 700 1.4rem/1 var(--display);
}

.primary-button:hover,
.scene-actions .primary-button:hover { background: #ffe5a5; }
.scene-actions button:hover { border-color: var(--gold); }

.scene-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.scene-actions button:disabled {
  opacity: 0.52;
  cursor: default;
}

.scene-stats {
  margin-bottom: 0.85rem;
  color: var(--mint);
}

.scene-card .look-help {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.touch-look { display: none; }

.dispatch {
  position: relative;
  z-index: 3;
  grid-row: 3;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.6rem;
  pointer-events: none;
}

.dispatch-update,
#interact-hint {
  width: fit-content;
  max-width: min(100%, 35rem);
  margin: 0;
  padding: 0.48rem 0.7rem;
  border: 1px solid var(--line);
  background: rgba(23, 23, 45, 0.92);
  font-size: 0.875rem;
}

.dispatch-update b { color: var(--mint); }
.dispatch-update p { margin: 0; }
#notice[data-tone="alert"] { color: var(--coral); }
#notice[data-tone="good"] { color: var(--mint); }

#interact-hint {
  flex-shrink: 0;
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 700;
}

.touch-controls { display: none; }

.control-guide {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.65rem;
  pointer-events: none;
}

#keyboard-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.65rem;
  margin: 0;
  padding: 0.42rem 0.6rem;
  border: 1px solid var(--line);
  background: rgba(23, 23, 45, 0.92);
  list-style: none;
  font-size: 0.875rem;
}

kbd {
  color: var(--gold);
  font: 700 0.8rem var(--body);
}

.control-guide details { pointer-events: auto; }

.control-guide summary {
  padding: 0.42rem 0.6rem;
  border: 1px solid var(--line);
  background: rgba(23, 23, 45, 0.92);
  font-size: 0.875rem;
  white-space: nowrap;
  cursor: pointer;
}

.control-guide details ul {
  position: absolute;
  right: 0;
  bottom: 2.4rem;
  width: min(100%, 27rem);
  max-height: 50dvh;
  overflow: auto;
  margin: 0;
  padding: 0.75rem 0.85rem 0.75rem 1.7rem;
  border: 1px solid var(--line);
  background: var(--ink);
}

.control-guide details li + li { margin-top: 0.5rem; }

body:has(#start-screen:not([hidden])) :is(.dashboard, .dispatch, .reticle, .game-header h1, .touch-controls, .control-guide),
body:has(#start-screen:not([hidden])) .hat-adjust,
body:has(#scene-panel:not([hidden])) :is(.hat-adjust, .touch-controls, .control-guide),
body[data-scene="hospital"] .hat-adjust {
  visibility: hidden;
}

@media (max-width: 670px) {
  .dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    padding: 0.4rem 0.55rem;
  }

  .inventory {
    grid-column: 1 / -1;
    padding: 0.32rem 0 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .dispatch {
    align-items: flex-start;
    flex-direction: column-reverse;
    gap: 0.28rem;
  }

  .dispatch-update,
  #interact-hint { padding: 0.32rem 0.5rem; }

  .dispatch-update:has(#notice:not(:empty)) b::after { color: var(--muted); content: " ·"; }
  .dispatch-update p { display: inline; padding-left: 0.22rem; }
}

@media (any-pointer: coarse) {
  .touch-look { display: block; }
  .keyboard-look, #keyboard-controls { display: none; }

  .control-guide { justify-content: flex-end; }

  .touch-controls {
    position: relative;
    z-index: 4;
    grid-row: 4;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.45rem;
    touch-action: none;
    user-select: none;
  }

  .direction-pad,
  .touch-actions {
    display: grid;
    align-items: end;
    gap: 0.25rem;
  }

  .direction-pad { grid-template-columns: repeat(3, 2.75rem); }

  .direction-pad button {
    padding: 0.25rem;
    font-size: 1.2rem;
    line-height: 1;
  }

  .direction-pad [data-move="up"] { grid-column: 2; }
  .direction-pad [data-move="left"] { grid-column: 1; grid-row: 2; }
  .direction-pad [data-move="down"] { grid-column: 2; grid-row: 2; }
  .direction-pad [data-move="right"] { grid-column: 3; grid-row: 2; }

  .touch-actions {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    width: min(100%, 12rem);
  }

  .touch-actions button {
    grid-column: span 2;
    padding: 0.3rem 0.22rem;
    font-size: 0.875rem;
  }

  .touch-actions .touch-interact,
  .touch-actions .touch-fire { grid-column: span 3; }

  .touch-actions .touch-interact { border-color: var(--gold); color: var(--gold); }
  .touch-actions .touch-fire { border-color: var(--coral); color: var(--coral); }
  .touch-controls button:is(:active, [data-held="true"]) { background: #55516e; }
}

@media (max-height: 440px) and (orientation: landscape) {
  .cabinet { gap: 0.25rem; }
  .game-deck { gap: 0.3rem; }
  .intro-mark { display: none; }
  .dispatch-update b::after { color: var(--muted); content: " ·"; }
  .dispatch-update p { display: inline; padding-left: 0.22rem; }
}
