@font-face {
  font-family: "Press Start 2P";
  src: url("assets/fonts/PressStart2P.woff2") format("woff2");
  font-display: swap;
}

:root,
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f0ede6;
  --fg: #1a1a14;
  --accent: #1a7a5e;
  --accent-lt: rgba(26, 122, 94, 0.12);
  --muted: #8a8878;
  --border: rgba(26, 122, 94, 0.2);
  --navy: var(--bg);
  --navy-2: #e5e0d6;
  --ink: var(--fg);
  --cream: var(--fg);
  --paper: #fffaf0;
  --gold: var(--accent);
  --orange: #db7148;
  --mint: var(--accent);
  --blue: #599b84;
  --shadow: rgba(26, 26, 20, 0.22);
  --guide-bg: rgba(240, 237, 230, 0.92);
  --console-bg: #e9ddba;
  --console-edge: #9b7e58;
  --console-label: #796c56;
  --console-copy: #716752;
  --console-action-copy: #675d4c;
  --dialog-card: #f6e4af;
  --dialog-card-shadow: #bda867;
  --game-chip: #cfe8d8;
  --dialog-muted: #766d5e;
  --on-accent: #fffaf0;
  --overlay: rgba(26, 26, 20, 0.68);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --fg: #e8e8d0;
  --accent: #58c4a0;
  --accent-lt: rgba(88, 196, 160, 0.15);
  --muted: #858572;
  --border: rgba(88, 196, 160, 0.2);
  --navy: var(--bg);
  --navy-2: #181813;
  --ink: var(--fg);
  --cream: var(--fg);
  --paper: #171712;
  --gold: var(--accent);
  --mint: var(--accent);
  --blue: #6dbda3;
  --shadow: rgba(0, 0, 0, 0.45);
  --guide-bg: rgba(13, 13, 13, 0.92);
  --console-bg: #25251f;
  --console-edge: #090909;
  --console-label: #aaa993;
  --console-copy: #c4c4aa;
  --console-action-copy: #c4c4aa;
  --dialog-card: #24241e;
  --dialog-card-shadow: #0a0a08;
  --game-chip: rgba(88, 196, 160, 0.15);
  --dialog-muted: #aaa993;
  --on-accent: #fffaf0;
  --overlay: rgba(0, 0, 0, 0.78);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--navy);
  transition: background 0.15s, color 0.15s;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--fg);
  font-family: "Press Start 2P", monospace;
  background: var(--bg);
  transition: background 0.15s, color 0.15s;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image: radial-gradient(circle, var(--muted) 1px, transparent 1px);
  background-size: 20px 20px;
}

button,
a {
  font: inherit;
}

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

.sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  display: none;
}

.sky span {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--cream);
  box-shadow: 8px 0 var(--cream), 4px -4px var(--cream), 4px 4px var(--cream);
  opacity: 0.55;
  animation: twinkle 3s steps(2, end) infinite;
}

.sky span:nth-child(1) { left: 8%; top: 18%; }
.sky span:nth-child(2) { left: 88%; top: 13%; animation-delay: 0.4s; }
.sky span:nth-child(3) { left: 4%; top: 72%; animation-delay: 1.1s; }
.sky span:nth-child(4) { left: 91%; top: 67%; animation-delay: 1.7s; }
.sky span:nth-child(5) { left: 72%; top: 89%; animation-delay: 2.2s; }

@keyframes twinkle {
  50% { opacity: 0.12; transform: scale(0.7); }
}

.topbar {
  position: relative;
  z-index: 2;
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 24px 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.theme-btn {
  padding: 8px 10px;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  cursor: pointer;
  font-size: 7px;
}

.theme-btn:hover,
.theme-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.brand,
.back-link {
  color: var(--fg);
  text-decoration: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 10px;
  letter-spacing: 0.08em;
}

.brand-ball {
  width: 22px;
  height: 22px;
  position: relative;
  border: 3px solid var(--fg);
  border-radius: 50%;
  background: linear-gradient(var(--orange) 0 43%, var(--ink) 43% 57%, var(--on-accent) 57%);
}

.brand-ball::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--on-accent);
}

.back-link {
  padding: 8px 0;
  color: var(--muted);
  font-size: 7px;
  transition: color 120ms ease, translate 120ms ease;
}

.back-link:hover,
.back-link:focus-visible {
  color: var(--accent);
  translate: -3px 0;
}

.game-layout {
  position: relative;
  z-index: 2;
  width: min(1120px, calc(100% - 40px));
  min-height: calc(100vh - 80px);
  margin: 0 auto;
  padding: 22px 0 50px;
  display: grid;
  grid-template-columns: minmax(480px, 700px) minmax(270px, 330px);
  align-items: center;
  justify-content: center;
  gap: clamp(30px, 5vw, 70px);
}

.game-console {
  padding: 16px 18px 18px;
  border: 4px solid var(--fg);
  border-radius: 24px 24px 38px 24px;
  color: var(--ink);
  background: var(--console-bg);
  box-shadow:
    0 10px 0 var(--console-edge),
    0 14px 0 var(--fg),
    18px 26px 45px rgba(26, 26, 20, 0.2);
}

.console-topline {
  min-height: 24px;
  padding: 0 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--console-label);
  font-size: 6px;
  letter-spacing: 0.12em;
}

.console-lights {
  display: flex;
  gap: 5px;
}

.console-lights i {
  width: 7px;
  height: 7px;
  border: 1px solid #695f50;
  border-radius: 50%;
  background: var(--orange);
}

.console-lights i:nth-child(2) { background: var(--gold); }
.console-lights i:nth-child(3) { background: var(--mint); }

.screen-bezel {
  padding: clamp(10px, 2vw, 18px);
  border: 4px solid #31352f;
  border-radius: 14px 14px 24px 14px;
  background: #626a60;
  box-shadow: inset 0 0 0 4px #252a24;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  background: #151a16;
  box-shadow: 0 0 0 3px #151a16;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

canvas:focus-visible {
  box-shadow: inset 0 0 0 2px var(--gold);
}

.loading-card {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--cream);
  background: var(--navy);
  font-size: 8px;
}

.loading-card.is-hidden {
  display: none;
}

.nearby-prompt {
  position: absolute;
  left: 50%;
  bottom: 10px;
  translate: -50% 0;
  min-width: max-content;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--on-accent);
  color: var(--on-accent);
  background: rgba(26, 26, 20, 0.92);
  box-shadow: 3px 3px 0 var(--shadow);
  font-size: 6px;
  animation: prompt-bob 900ms steps(2, end) infinite;
}

.nearby-prompt[hidden] {
  display: none;
}

@keyframes prompt-bob {
  50% { translate: -50% -2px; }
}

kbd {
  padding: 4px 5px;
  border: 1px solid currentColor;
  border-bottom-width: 3px;
  border-radius: 3px;
  font: inherit;
  font-size: 0.85em;
  background: rgba(255, 255, 255, 0.1);
}

.console-bottom {
  min-height: 104px;
  padding: 16px 12px 2px;
  display: grid;
  grid-template-columns: 108px 1fr 90px;
  align-items: center;
  gap: 16px;
}

.dpad {
  width: 92px;
  height: 92px;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
}

.dpad button,
.dpad-center {
  border: 0;
  color: #a5aa9e;
  background: #30362f;
  box-shadow: inset -3px -3px #171b16, inset 3px 3px #50594e;
}

.dpad button {
  cursor: pointer;
  font-size: 11px;
}

.dpad button:active {
  color: var(--gold);
  box-shadow: inset 2px 2px #171b16;
}

.dpad-up { grid-area: 1 / 2; border-radius: 5px 5px 0 0 !important; }
.dpad-left { grid-area: 2 / 1; border-radius: 5px 0 0 5px !important; }
.dpad-center { grid-area: 2 / 2; }
.dpad-right { grid-area: 2 / 3; border-radius: 0 5px 5px 0 !important; }
.dpad-down { grid-area: 3 / 2; border-radius: 0 0 5px 5px !important; }

.game-status {
  margin: 0;
  color: var(--console-copy);
  font-size: 6px;
  line-height: 1.9;
  text-align: center;
}

.action-button {
  justify-self: end;
  border: 0;
  color: var(--console-action-copy);
  background: transparent;
  cursor: pointer;
  font-size: 5px;
  text-transform: uppercase;
}

.action-button span {
  width: 54px;
  height: 54px;
  margin: 0 auto 8px;
  display: grid;
  place-items: center;
  border: 3px solid #913d31;
  border-radius: 50%;
  color: var(--on-accent);
  background: var(--orange);
  box-shadow: 0 5px 0 #913d31;
  font-size: 14px;
}

.action-button:active span {
  translate: 0 4px;
  box-shadow: 0 1px 0 #913d31;
}

.guide-card {
  position: relative;
  padding: 30px 28px;
  border: 3px solid var(--accent);
  color: var(--fg);
  background: var(--guide-bg);
  box-shadow: 8px 8px 0 var(--accent-lt);
}

.guide-card::before,
.guide-card::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--gold);
}

.guide-card::before { left: 8px; top: 8px; }
.guide-card::after { right: 8px; bottom: 8px; }

.guide-kicker,
.quest-label,
.dialog-eyebrow {
  margin: 0 0 14px;
  color: var(--gold);
  font-size: 6px;
  letter-spacing: 0.12em;
}

.guide-card h1 {
  margin: 0;
  font-size: clamp(16px, 2.2vw, 24px);
  line-height: 1.55;
}

.guide-copy {
  margin: 18px 0 24px;
  color: var(--fg);
  opacity: 0.78;
  font: 14px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.quest-card {
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border: 2px solid var(--border);
  background: var(--accent-lt);
}

.quest-icon {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--on-accent);
  background: var(--gold);
  font-size: 11px;
}

.quest-label {
  display: block;
  margin: 1px 0 7px;
  font-size: 5px;
}

.quest-card p {
  margin: 0;
  color: var(--fg);
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.room-legend {
  margin: 24px 0;
  padding: 0;
  display: grid;
  gap: 16px;
  list-style: none;
}

.room-legend li {
  display: flex;
  align-items: center;
  gap: 13px;
}

.room-legend > li > span {
  width: 34px;
  color: var(--mint);
  font-size: 20px;
  text-align: center;
}

.room-legend strong,
.room-legend small {
  display: block;
}

.room-legend strong {
  margin-bottom: 5px;
  font-size: 7px;
  font-weight: normal;
}

.room-legend small {
  color: var(--muted);
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.keyboard-help {
  padding-top: 18px;
  border-top: 1px dashed var(--border);
  color: var(--muted);
  font: 11px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.keyboard-help p {
  margin: 5px 0;
}

.dialog-box {
  width: min(650px, calc(100% - 28px));
  max-height: min(720px, calc(100vh - 30px));
  padding: 0;
  overflow: visible;
  border: 0;
  color: var(--ink);
  background: transparent;
}

.dialog-box::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(4px);
}

.dialog-inner {
  max-height: min(720px, calc(100vh - 30px));
  overflow-y: auto;
  padding: 25px;
  border: 5px solid var(--ink);
  outline: 4px solid var(--paper);
  background: var(--paper);
  box-shadow: 12px 12px 0 var(--gold);
}

.dialog-heading {
  padding-bottom: 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 3px solid var(--ink);
}

.dialog-eyebrow {
  margin-bottom: 9px;
  color: #ae563d;
}

.dialog-heading h2 {
  margin: 0;
  font-size: clamp(14px, 3vw, 22px);
  line-height: 1.5;
}

.dialog-close {
  width: 38px;
  height: 38px;
  border: 3px solid var(--ink);
  color: var(--ink);
  background: var(--gold);
  cursor: pointer;
  font-size: 18px;
}

.dialog-content {
  padding: 22px 0 10px;
  font: 14px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.dialog-content > p:first-child {
  margin-top: 0;
}

.dialog-content a {
  color: #9c4435;
  font-weight: 700;
}

.menu-grid,
.project-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.menu-button,
.project-card,
.soft-card {
  padding: 16px;
  border: 2px solid var(--ink);
  color: var(--ink);
  background: var(--dialog-card);
  box-shadow: 4px 4px 0 var(--dialog-card-shadow);
}

.menu-button {
  min-height: 82px;
  cursor: pointer;
  text-align: left;
  font-size: 8px;
  line-height: 1.7;
}

.menu-button small {
  display: block;
  margin-top: 7px;
  font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.menu-button:hover,
.menu-button:focus-visible {
  translate: -2px -2px;
  box-shadow: 6px 6px 0 var(--orange);
}

.project-card h3 {
  margin: 0 0 6px;
  font: 700 14px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.project-card .tech {
  color: #9c4435;
  font-size: 10px;
  font-weight: 700;
}

.project-card p {
  min-height: 68px;
  font-size: 12px;
}

.scenic-view {
  margin: 0;
  overflow: hidden;
  border: 2px solid var(--ink);
  background: var(--dialog-card);
  box-shadow: 4px 4px 0 var(--dialog-card-shadow);
}

.scenic-view img {
  width: 100%;
  max-height: min(52vh, 390px);
  display: block;
  object-fit: cover;
  object-position: center;
}

.scenic-view figcaption {
  padding: 14px 16px;
  border-top: 2px solid var(--ink);
  font-size: 12px;
}

.mirror-reflection {
  margin: 0;
  padding: 16px;
  border: 2px solid var(--ink);
  background: var(--dialog-card);
  box-shadow: 4px 4px 0 var(--dialog-card-shadow);
  text-align: center;
}

.mirror-glass {
  width: min(230px, 75%);
  aspect-ratio: 4 / 3;
  margin: 0 auto 16px;
  display: grid;
  place-items: end center;
  overflow: hidden;
  border: 6px solid var(--gold);
  outline: 2px solid var(--ink);
  background:
    linear-gradient(135deg, rgb(255 255 255 / 55%) 0 12%, transparent 12% 22%, rgb(255 255 255 / 22%) 22% 29%, transparent 29%),
    #b9d8d6;
  box-shadow: inset 0 0 0 4px rgb(255 255 255 / 28%);
}

.mirror-glass img {
  width: 128px;
  max-width: 70%;
  height: auto;
  display: block;
  image-rendering: pixelated;
  transform: scaleX(-1);
  transform-origin: center bottom;
}

.mirror-reflection figcaption {
  font-size: 12px;
}

.game-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0;
  list-style: none;
}

.game-list li {
  border: 2px solid var(--ink);
  background: var(--game-chip);
  font-size: 11px;
}

.game-list a,
.game-list span {
  min-height: 100%;
  padding: 10px 12px;
  display: block;
}

.game-list a {
  text-decoration: none;
}

.game-list a:hover,
.game-list a:focus-visible {
  background: var(--accent-lt);
}

.game-list small {
  margin-top: 5px;
  display: block;
  color: var(--dialog-muted);
  font-size: 9px;
}

.dialog-footer {
  min-height: 35px;
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px dashed #988d76;
  color: var(--dialog-muted);
  font-size: 6px;
}

.dialog-back {
  border: 0;
  color: #9c4435;
  background: transparent;
  cursor: pointer;
  font-size: 7px;
}

.room-link {
  width: fit-content;
  padding: 12px 15px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 2px solid var(--accent);
  color: var(--accent);
  background: var(--accent-lt);
  box-shadow: 4px 4px 0 var(--accent-lt);
  font-size: 7px;
  text-decoration: none;
}

.room-link:hover,
.room-link:focus-visible {
  translate: -2px -2px;
  box-shadow: 6px 6px 0 var(--accent-lt);
  text-decoration: none;
}

@media (min-width: 861px) {
  .game-console {
    width: min(100%, calc(100vh - 260px));
    min-width: 420px;
    justify-self: end;
  }
}

@media (min-width: 861px) and (max-height: 820px) {
  .game-layout {
    padding-top: 12px;
    padding-bottom: 28px;
  }

  .console-bottom {
    min-height: 90px;
    padding-top: 12px;
  }

  .dpad {
    width: 78px;
    height: 78px;
  }

  .action-button span {
    width: 48px;
    height: 48px;
  }
}

@media (max-width: 860px) {
  .game-layout {
    grid-template-columns: minmax(0, 620px);
    align-items: start;
  }

  .guide-card {
    order: -1;
  }

  .guide-card h1,
  .guide-copy,
  .room-legend {
    display: none;
  }

  .guide-card {
    padding: 16px 18px;
  }

  .quest-card {
    margin-top: 8px;
  }
}

@media (max-width: 560px) {
  .topbar,
  .game-layout {
    width: min(100% - 20px, 520px);
  }

  .topbar {
    padding-top: 14px;
  }

  .brand { font-size: 8px; }
  .back-link { font-size: 6px; }
  .topbar-actions { gap: 10px; }
  .theme-btn { padding: 7px 8px; font-size: 6px; }

  .game-layout {
    gap: 18px;
    padding-top: 10px;
  }

  .game-console {
    padding: 10px;
    border-radius: 16px 16px 26px 16px;
  }

  .screen-bezel { padding: 10px; }

  .console-bottom {
    min-height: 90px;
    grid-template-columns: 84px 1fr 65px;
    gap: 8px;
    padding: 13px 5px 0;
  }

  .dpad {
    width: 76px;
    height: 76px;
  }

  .action-button span {
    width: 46px;
    height: 46px;
  }

  .game-status { font-size: 5px; }

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

  .dialog-inner {
    padding: 18px;
    box-shadow: 7px 7px 0 var(--gold);
  }
}

@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;
  }
}
