:root {
  color-scheme: dark;
  --ink: #120b18;
  --deep: #1f1228;
  --violet: #2a1c32;
  --plum: #493252;
  --stone: #6e5d6f;
  --gold: #f0c15b;
  --gold-2: #d6aa68;
  --gold-3: #b98a45;
  --gold-4: #7d5a2b;
  --vellum: #efe0b0;
  --paper: #f7e9b6;
  --cream: #fff8dc;
  --aqua: #6dd6c4;
  --aqua-2: #3c9a8e;
  --rose: #d85c7f;
  --crimson: #a64f58;
  --green: #87bc4c;
  --green-2: #4f7a35;
  --focus: #fff8dc;
  --pixel: "Press Start 2P", "Courier New", monospace;
  font-family: var(--pixel);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--paper);
  background-color: var(--ink);
  background-image:
    radial-gradient(ellipse at 50% 38%, rgba(240, 193, 91, 0.1), transparent 62%),
    linear-gradient(45deg, var(--deep) 25%, transparent 25%, transparent 75%, var(--deep) 75%),
    linear-gradient(45deg, var(--deep) 25%, transparent 25%, transparent 75%, var(--deep) 75%);
  background-position: 0 0, 0 0, 6px 6px;
  background-size: auto, 12px 12px, 12px 12px;
}

button {
  border: 0;
  border-radius: 0;
  color: var(--paper);
  background: var(--plum);
  font: inherit;
  font-size: 0.62rem;
  line-height: 1.4;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow:
    inset 0 -4px 0 rgba(18, 11, 24, 0.45),
    inset 0 3px 0 rgba(255, 248, 220, 0.14),
    0 0 0 3px var(--ink),
    0 5px 0 3px var(--ink);
  transition: transform 60ms steps(1), filter 60ms steps(1);
}

button:hover {
  filter: brightness(1.15);
}

button:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 -2px 0 rgba(18, 11, 24, 0.45),
    inset 0 3px 0 rgba(255, 248, 220, 0.14),
    0 0 0 3px var(--ink),
    0 2px 0 3px var(--ink);
}

button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 5px;
}

.shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px 14px 24px;
}

.cabinet {
  --side: 136px;
  position: relative;
  width: min(1140px, 100%);
  display: grid;
  gap: 14px;
  padding: 14px;
  background:
    linear-gradient(90deg, rgba(240, 193, 91, 0.08), transparent 18%, transparent 82%, rgba(240, 193, 91, 0.08)),
    var(--violet);
  box-shadow:
    inset 0 0 0 3px var(--plum),
    inset 0 0 0 6px var(--ink),
    0 0 0 4px var(--ink),
    0 0 0 8px var(--gold-4),
    0 0 0 12px var(--ink),
    0 18px 60px rgba(109, 214, 196, 0.08);
}

.marquee {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 20px 18px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 248, 220, 0.035) 0 4px, transparent 4px 8px),
    linear-gradient(180deg, #3a2440, var(--deep) 70%);
  box-shadow:
    inset 0 0 0 3px var(--gold-3),
    inset 0 0 0 6px var(--ink),
    inset 0 -14px 0 rgba(18, 11, 24, 0.35),
    0 0 0 3px var(--ink);
}

.marquee::before,
.marquee::after {
  content: "";
  position: absolute;
  top: 10px;
  width: 6px;
  height: 6px;
  background: var(--cream);
  animation: bulbs 1.6s steps(2) infinite;
}

.marquee::before {
  left: 10px;
}

.marquee::after {
  right: 10px;
  animation-delay: 0.8s;
}

@keyframes bulbs {
  50% {
    background: var(--gold-3);
  }
}

.kicker {
  margin: 0 0 12px;
  color: var(--aqua);
  font-size: clamp(0.5rem, 1.2vw, 0.62rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--gold);
  font-family: var(--pixel);
  font-size: clamp(1.05rem, 3.4vw, 2.1rem);
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow:
    0 -2px 0 var(--cream),
    3px 3px 0 var(--gold-4),
    6px 6px 0 var(--ink),
    0 0 18px rgba(240, 193, 91, 0.35);
  animation: marquee-glow 3.2s steps(4) infinite;
}

@keyframes marquee-glow {
  50% {
    text-shadow:
      0 -2px 0 var(--cream),
      3px 3px 0 var(--gold-4),
      6px 6px 0 var(--ink),
      0 0 26px rgba(240, 193, 91, 0.55);
  }
}

.status-strip {
  min-width: 220px;
  display: grid;
  gap: 8px;
  justify-items: end;
  font-size: 0.56rem;
  text-transform: uppercase;
  color: var(--cream);
}

.status-strip span {
  padding: 7px 10px 6px;
  background: var(--ink);
  box-shadow: inset 0 0 0 2px var(--plum), inset 0 2px 0 2px rgba(255, 248, 220, 0.06);
}

.status-strip span:first-child {
  color: var(--gold);
}

.status-strip span:last-child {
  color: var(--aqua);
}

.screen-wrap {
  position: relative;
  justify-self: center;
  width: min(100%, calc((100vh - 230px) * 16 / 9));
  min-width: 0;
  overflow: hidden;
  background: #050309;
  box-shadow:
    0 0 0 4px var(--ink),
    0 0 0 8px #3a2440,
    0 0 0 10px var(--gold-4),
    0 0 0 14px var(--ink),
    0 0 40px 14px rgba(109, 214, 196, 0.1);
  aspect-ratio: 16 / 9;
  margin: 14px 0;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(180deg, rgba(18, 11, 24, 0.16) 0 1px, transparent 1px 3px);
  box-shadow: inset 0 0 70px rgba(18, 11, 24, 0.55);
  opacity: 0.55;
}

.keys-button {
  position: absolute;
  z-index: 3;
  right: 12px;
  bottom: 12px;
  padding: 8px 10px 7px;
  color: var(--ink);
  background: var(--gold);
  font-size: 0.55rem;
  box-shadow:
    inset 0 -3px 0 var(--gold-3),
    inset 0 2px 0 var(--cream),
    0 0 0 2px var(--ink),
    0 3px 0 2px var(--ink);
}

.keys-button[aria-expanded="true"] {
  background: var(--aqua);
  box-shadow:
    inset 0 -3px 0 var(--aqua-2),
    inset 0 2px 0 var(--cream),
    0 0 0 2px var(--ink),
    0 3px 0 2px var(--ink);
}

.keys-guide {
  position: absolute;
  z-index: 4;
  right: 12px;
  bottom: 52px;
  width: min(400px, calc(100% - 24px));
  max-height: calc(100% - 66px);
  overflow: auto;
  padding: 16px;
  color: var(--paper);
  background:
    repeating-linear-gradient(180deg, rgba(255, 248, 220, 0.025) 0 2px, transparent 2px 4px),
    rgba(31, 18, 40, 0.97);
  box-shadow:
    inset 0 0 0 2px var(--gold-3),
    inset 0 0 0 4px var(--ink),
    0 0 0 3px var(--ink),
    6px 6px 0 3px rgba(18, 11, 24, 0.75);
}

.keys-guide[hidden] {
  display: none;
}

.keys-guide-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 2px dashed var(--plum);
}

.keys-guide-kicker {
  color: var(--aqua);
  font-size: 0.5rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.keys-guide h2 {
  margin: 8px 0 0;
  color: var(--gold);
  font-family: var(--pixel);
  font-size: 0.95rem;
  font-weight: 400;
  line-height: 1.2;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 var(--ink);
}

.keys-close {
  width: 32px;
  height: 30px;
  padding: 0;
  font-size: 0.8rem;
  line-height: 1;
}

.keys-list {
  display: grid;
  gap: 0;
  margin: 10px 0 0;
}

.keys-list > div {
  display: grid;
  grid-template-columns: 82px 1fr;
  align-items: center;
  gap: 10px;
  padding: 7px 2px;
  border-bottom: 2px solid var(--violet);
}

.keys-list > div:last-child {
  border-bottom: 0;
}

.keys-list dt {
  color: var(--gold-2);
  font-size: 0.5rem;
  text-transform: uppercase;
}

.keys-list dd {
  margin: 0;
  color: var(--cream);
  font-family: Monaco, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.8;
}

kbd {
  display: inline-block;
  min-width: 24px;
  margin: 1px 2px;
  padding: 3px 5px 2px;
  color: var(--ink);
  background: var(--vellum);
  font-family: Monaco, Consolas, monospace;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  box-shadow:
    inset 0 -3px 0 var(--gold-2),
    0 0 0 2px var(--ink);
}

.panel {
  justify-self: center;
  width: min(100%, calc((100vh - 230px) * 16 / 9));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  background:
    repeating-linear-gradient(90deg, rgba(18, 11, 24, 0.18) 0 2px, transparent 2px 10px),
    linear-gradient(180deg, #3a2440, var(--deep));
  box-shadow:
    inset 0 3px 0 rgba(255, 248, 220, 0.08),
    inset 0 0 0 3px var(--ink),
    0 0 0 3px var(--gold-4),
    0 0 0 6px var(--ink);
}

.hero-select,
.actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.select-button {
  min-width: 150px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 8px;
  color: var(--paper);
  background: var(--violet);
}

.select-button.active {
  color: var(--ink);
  background: var(--gold);
  box-shadow:
    inset 0 -4px 0 var(--gold-3),
    inset 0 3px 0 var(--cream),
    0 0 0 3px var(--ink),
    0 5px 0 3px var(--ink),
    0 0 18px 3px rgba(240, 193, 91, 0.25);
}

.portrait {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: inline-block;
  image-rendering: pixelated;
  box-shadow: 0 0 0 2px var(--ink), inset 0 0 0 2px rgba(18, 11, 24, 0.4);
  background-size: 100% 100%;
}

.portrait.aristotle {
  background:
    linear-gradient(135deg, transparent 0 58%, #a64f58 58% 70%, transparent 70%),
    linear-gradient(90deg, transparent 0 8px, #d7c48b 8px 24px, transparent 24px) 0 18px / 100% 8px no-repeat,
    linear-gradient(90deg, #4b6ca8 0 6px, #d7c48b 6px 10px, #f7d6ae 10px 22px, #d7c48b 22px 26px, #4b6ca8 26px),
    linear-gradient(#4b6ca8 0 4px, #d7c48b 4px 10px, #f7d6ae 10px 24px, #efe0b0 24px);
}

.portrait.aquinas {
  background:
    linear-gradient(90deg, transparent 0 14px, #f0c15b 14px 18px, transparent 18px) 0 25px / 100% 3px no-repeat,
    linear-gradient(90deg, #1d2030 0 9px, #f4f0ce 9px 23px, #1d2030 23px) 0 23px / 100% 9px no-repeat,
    linear-gradient(90deg, #3c9a8e 0 6px, #6a4b35 6px 9px, #f7d6ae 9px 23px, #6a4b35 23px 26px, #3c9a8e 26px),
    linear-gradient(#3c9a8e 0 4px, #f7d6ae 4px 7px, #6a4b35 7px 10px, #f7d6ae 10px 23px, #3c9a8e 23px);
}

.portrait.socrates {
  background:
    linear-gradient(90deg, transparent 0 9px, #b9b1a6 9px 23px, transparent 23px) 0 16px / 100% 9px no-repeat,
    linear-gradient(90deg, #5d4d74 0 7px, #b9b1a6 7px 9px, #f7d6ae 9px 23px, #b9b1a6 23px 25px, #5d4d74 25px),
    linear-gradient(#5d4d74 0 4px, #f7d6ae 4px 25px, #d6e0dc 25px);
}

.actions button {
  min-width: 92px;
  padding: 12px 14px 11px;
}

.actions .primary {
  color: var(--ink);
  background: var(--green);
  box-shadow:
    inset 0 -4px 0 var(--green-2),
    inset 0 3px 0 #b8c99a,
    0 0 0 3px var(--ink),
    0 5px 0 3px var(--ink);
}

#resetGame {
  background: var(--crimson);
  box-shadow:
    inset 0 -4px 0 #6f2e3f,
    inset 0 3px 0 rgba(255, 248, 220, 0.2),
    0 0 0 3px var(--ink),
    0 5px 0 3px var(--ink);
}

@media (max-width: 760px) {
  .shell {
    padding: 10px 8px 18px;
    place-items: start center;
  }

  .cabinet {
    padding: 10px;
    gap: 12px;
  }

  .marquee,
  .panel {
    align-items: stretch;
    flex-direction: column;
  }

  .marquee {
    padding: 14px 16px;
  }

  .status-strip {
    min-width: 0;
    justify-items: start;
    grid-auto-flow: column;
    justify-content: start;
  }

  .hero-select,
  .actions {
    flex-wrap: wrap;
  }

  .select-button {
    flex: 1 1 130px;
    min-width: 0;
  }

  .actions button {
    flex: 1 1 80px;
    min-width: 0;
  }

  .screen-wrap {
    margin: 8px 0;
  }

  .keys-button {
    right: 6px;
    bottom: 6px;
    padding: 5px 6px 4px;
    font-size: 0.45rem;
  }

  .keys-guide {
    right: 6px;
    bottom: 36px;
    width: calc(100% - 12px);
    max-height: calc(100% - 44px);
    padding: 10px;
  }

  .keys-list > div {
    grid-template-columns: 64px 1fr;
    padding: 5px 0;
  }

  .screen-wrap,
  .panel {
    width: 100%;
  }
}

.touch {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px 16px;
  background: var(--deep);
  box-shadow: inset 0 0 0 3px var(--ink), 0 0 0 3px var(--gold-4);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.touch-move {
  display: flex;
  align-items: center;
  gap: 14px;
}

.touch-pause {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 0.6rem;
  touch-action: manipulation;
}

.dpad {
  width: 120px;
  height: 60px;
  display: flex;
  touch-action: none;
  background: var(--violet);
  box-shadow:
    inset 0 -4px 0 rgba(18, 11, 24, 0.45),
    inset 0 3px 0 rgba(255, 248, 220, 0.14),
    0 0 0 3px var(--ink),
    0 5px 0 3px var(--ink);
}

.dpad span {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--paper);
  font-family: system-ui, sans-serif;
  font-size: 1.3rem;
}

.dpad span + span {
  box-shadow: inset 3px 0 0 var(--ink);
}

.dpad[data-dir="left"] [data-dir="left"],
.dpad[data-dir="right"] [data-dir="right"] {
  color: var(--gold);
  background: var(--plum);
}

.touch-act {
  width: var(--side);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px 8px;
}

.touch-act button {
  grid-column: span 2;
  height: 40px;
  padding: 0;
  color: var(--ink);
  font-size: 0.42rem;
  text-transform: uppercase;
  touch-action: none;
  background: var(--vellum);
}

.touch-act [data-touch="attack"],
.touch-act [data-touch="jump"] {
  grid-column: span 3;
  height: 58px;
  font-size: 0.56rem;
}

.touch-act [data-touch="jump"] {
  background: var(--gold);
}

.touch-act [data-touch="attack"] {
  background: var(--rose);
}

.touch-act [data-touch="block"] {
  background: var(--aqua);
}

.touch-act [data-touch="special"] {
  background: var(--green);
}

.touch-act button.held {
  transform: translateY(3px);
  filter: brightness(1.2);
}

@media (pointer: coarse) {
  .touch {
    display: flex;
  }

  .keys-button {
    display: none;
  }

  canvas {
    touch-action: manipulation;
  }
}

/* Portrait: controls sit between the screen and the hero panel. */
@media (pointer: coarse) and (orientation: portrait) {
  .touch {
    order: 1;
  }

  .panel {
    order: 2;
  }

  .kicker,
  .status-strip {
    display: none;
  }
}

/* Landscape: the screen fills the height, controls flank it, the hero panel sits below. */
@media (pointer: coarse) and (orientation: landscape) {
  .shell {
    min-height: 0;
    padding: 0;
    place-items: start stretch;
  }

  .cabinet {
    width: 100%;
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: 100vh auto;
    grid-template-rows: 100dvh auto;
    grid-template-areas:
      "move screen act"
      "panel panel panel";
    gap: 0 22px;
    padding: 0 max(10px, env(safe-area-inset-right)) 18px max(10px, env(safe-area-inset-left));
    box-shadow: none;
  }

  .marquee {
    display: none;
  }

  .touch {
    display: contents;
  }

  .touch-move {
    grid-area: move;
    flex-direction: column;
    place-self: center;
    gap: 28px;
  }

  .touch-act {
    grid-area: act;
    place-self: center;
  }

  .screen-wrap {
    grid-area: screen;
    align-self: center;
    width: min(calc(100vw - 2 * var(--side) - 64px), calc((100vh - 32px) * 16 / 9));
    width: min(calc(100vw - 2 * var(--side) - 64px), calc((100dvh - 32px) * 16 / 9));
    margin: 0;
  }

  .panel {
    grid-area: panel;
    width: 100%;
  }
}

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