/* Mattetornering. Overlay sizes are in game pixels: calc(var(--u) * n),
   where --u is one pixel of the 320x256 arcade screen. */

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: #000;
  color: #fff;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
}

[hidden] {
  display: none !important;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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

/* ---------- Cabinet ---------- */

.cabinet {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: calc(100svh - 76px);
  min-height: 300px;
  background: radial-gradient(ellipse at 50% 100%, #2a0a02 0%, #000 60%);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cabinet:fullscreen {
  height: 100vh;
}

.cabinet:-webkit-full-screen {
  height: 100vh;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}

.screen {
  --u: calc(var(--px, 1) * 1px);
  position: relative;
  width: 320px;
  height: 256px;
  font-family: "Press Start 2P", ui-monospace, monospace;
  font-size: calc(var(--u) * 8);
  line-height: 1.25;
  color: #fff;
  background: #000;
  box-shadow: 0 0 0 2px #1a1a1a, 0 0 60px rgba(255, 110, 30, 0.12);
}

.cabinet.is-playing .stage {
  touch-action: none;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  outline: none;
  transition: filter 300ms ease;
}

.screen.is-dim #game {
  filter: brightness(0.42) saturate(0.85);
}

/* ---------- Overlays ---------- */

.ov {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--u) * 6);
  padding: calc(var(--u) * 6) calc(var(--u) * 8);
  text-align: center;
  overflow: hidden auto;
  scrollbar-width: none;
}

.ov h2 {
  margin: 0;
  font-size: calc(var(--u) * 10);
  font-weight: 400;
  color: #ffe14a;
  text-shadow: calc(var(--u) * 1) calc(var(--u) * 1) 0 #a0300a;
}

.ov :focus-visible {
  outline: calc(var(--u) * 1) solid #9adfff;
  outline-offset: calc(var(--u) * 1);
}

.blink {
  animation: blink 1s steps(1) infinite;
}

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

.btn {
  padding: calc(var(--u) * 4) calc(var(--u) * 7);
  border: calc(var(--u) * 1) solid #8a8a9a;
  background: #000;
  color: #dcdce6;
  font-size: calc(var(--u) * 8);
  line-height: 1;
}

.btn:hover {
  border-color: #fff;
  color: #fff;
}

.btn.primary {
  border-color: #fff6a0;
  background: #ffe14a;
  color: #000;
  box-shadow: 0 calc(var(--u) * 2) 0 #b07a10;
}

.btn.primary:hover {
  background: #fff6a0;
}

.btn:active {
  transform: translateY(calc(var(--u) * 1));
}

.nav-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: calc(var(--u) * 6);
}

/* ---------- Title ---------- */

.ov-title {
  gap: calc(var(--u) * 7);
}

.logo-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--u) * 3);
  margin: 0;
  font-weight: 400;
  line-height: 1;
}

.logo-small {
  font-size: calc(var(--u) * 10);
  color: #9adfff;
  letter-spacing: calc(var(--u) * 6);
  margin-right: calc(var(--u) * -6);
  text-shadow: calc(var(--u) * 1) calc(var(--u) * 1) 0 #1a3a8a;
}

.logo-big {
  font-size: calc(var(--u) * 26);
  letter-spacing: calc(var(--u) * 1);
  background: linear-gradient(180deg, #fffbd0 0%, #fff6a0 22%, #ffcc33 22%, #ffcc33 48%, #ff8a20 48%, #ff8a20 70%, #e2401a 70%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 calc(var(--u) * 2) 0 #6a1600) drop-shadow(calc(var(--u) * 1) 0 0 #2a0800) drop-shadow(calc(var(--u) * -1) 0 0 #2a0800);
}

.tagline {
  margin: 0;
  color: #fff;
  font-size: calc(var(--u) * 8);
}

.legend {
  display: grid;
  gap: calc(var(--u) * 1);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: calc(var(--u) * 7);
}

.legend li {
  display: grid;
  grid-template-columns: calc(var(--u) * 30) calc(var(--u) * 84) calc(var(--u) * 70);
  align-items: center;
  gap: calc(var(--u) * 6);
  text-align: left;
}

.legend canvas {
  width: calc(var(--u) * 30);
  height: calc(var(--u) * 22);
}

.legend span {
  color: #dcdce6;
}

.legend b {
  font-weight: 400;
  color: #ffe14a;
  text-align: right;
}

.start {
  border: 0;
  background: none;
  padding: calc(var(--u) * 3) calc(var(--u) * 6);
  font-size: calc(var(--u) * 10);
  color: #5cf25c;
  text-shadow: calc(var(--u) * 1) calc(var(--u) * 1) 0 #0a4a0a;
}

.start:hover,
.start:focus-visible {
  animation: none;
  color: #b8ffb0;
}

.link {
  border: 0;
  background: none;
  padding: calc(var(--u) * 2);
  font-size: calc(var(--u) * 7);
  color: #ff7fd0;
  text-decoration: underline;
  text-underline-offset: calc(var(--u) * 2);
}

/* ---------- Highscores ---------- */

.ov-scores {
  gap: calc(var(--u) * 4);
  background: rgba(0, 0, 0, 0.55);
}

.rainbow {
  animation: rainbow 1.6s steps(1) infinite;
}

@keyframes rainbow {
  0% {
    color: #ff3b30;
  }
  16% {
    color: #ff9a2a;
  }
  33% {
    color: #ffe14a;
  }
  50% {
    color: #5cf25c;
  }
  66% {
    color: #3ab4ff;
  }
  83% {
    color: #ff7fd0;
  }
}

.tabs {
  display: flex;
  gap: calc(var(--u) * 4);
}

.tabs button {
  padding: calc(var(--u) * 2) calc(var(--u) * 5);
  border: calc(var(--u) * 1) solid #4a4a5a;
  background: #000;
  color: #8a8a9a;
  font-size: calc(var(--u) * 7);
  line-height: 1;
}

.tabs button[aria-selected="true"] {
  border-color: #9adfff;
  color: #9adfff;
}

.hs {
  border-collapse: collapse;
  font-size: calc(var(--u) * 7);
  line-height: 1;
}

.hs th {
  padding: 0 calc(var(--u) * 3) calc(var(--u) * 2);
  font-weight: 400;
  font-size: calc(var(--u) * 6);
  color: #8a8a9a;
  text-align: right;
}

.hs th:nth-child(3) {
  text-align: left;
}

.hs td {
  height: calc(var(--u) * 16);
  padding: 0 calc(var(--u) * 3);
  color: var(--c);
  text-align: right;
  white-space: nowrap;
  animation: row-in 400ms steps(4) both;
  animation-delay: var(--d);
}

.hs td.hs-name {
  text-align: left;
  min-width: calc(var(--u) * 84);
}

.hs td.hs-icon {
  padding: 0;
  width: calc(var(--u) * 30);
}

.hs td.hs-empty {
  color: #3a3a4a;
}

.hs canvas {
  display: block;
  width: calc(var(--u) * 30);
  height: calc(var(--u) * 18);
  margin-top: calc(var(--u) * -2);
}

.hs tr.is-new td {
  animation: row-in 400ms steps(4) both, new-row 0.5s steps(1) infinite;
  animation-delay: var(--d), 0s;
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateX(calc(var(--u) * -12));
  }
}

@keyframes new-row {
  50% {
    color: #fff;
    background: #3a1a6a;
  }
}

.hs-note {
  margin: 0;
  font-size: calc(var(--u) * 6);
  color: #8a8a9a;
}

/* ---------- Setup ---------- */

.ov-setup {
  background: rgba(0, 0, 0, 0.8);
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--u) * 5);
  width: 100%;
}

.group {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
  width: 100%;
}

.group legend {
  padding: 0;
  margin: 0 auto calc(var(--u) * 3);
  font-size: calc(var(--u) * 7);
  color: #ff7fd0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: calc(var(--u) * 3);
}

.chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--u) * 2);
  min-width: calc(var(--u) * 14);
  padding: calc(var(--u) * 3) calc(var(--u) * 4);
  border: calc(var(--u) * 1) solid #4a4a5a;
  background: #0c0c14;
  color: #b8b8c8;
  font-size: calc(var(--u) * 8);
  line-height: 1;
}

.chip b {
  font-weight: 400;
  font-size: calc(var(--u) * 10);
}

.chip small {
  font-size: calc(var(--u) * 5);
}

.chip:hover {
  border-color: #b8b8c8;
}

.chip[aria-pressed="true"] {
  border-color: #ffe14a;
  background: #3a2a00;
  color: #ffe14a;
}

.chip-level {
  width: calc(var(--u) * 56);
}

.chip-op {
  width: calc(var(--u) * 52);
}

.chip-table {
  min-width: calc(var(--u) * 18);
  padding: calc(var(--u) * 3) calc(var(--u) * 2);
}

.chip-all {
  padding: calc(var(--u) * 3) calc(var(--u) * 4);
}

.chip.shake {
  animation: shake 0.4s steps(6);
  border-color: #ff3b30;
}

@keyframes shake {
  25% {
    transform: translateX(calc(var(--u) * -2));
  }
  75% {
    transform: translateX(calc(var(--u) * 2));
  }
}

.hint {
  min-height: calc(var(--u) * 12);
  margin: calc(var(--u) * 3) auto 0;
  max-width: calc(var(--u) * 290);
  font-size: calc(var(--u) * 5);
  line-height: 1.5;
  color: #9adfff;
  text-transform: uppercase;
}

.hero {
  display: grid;
  grid-template-columns: calc(var(--u) * 90) 1fr;
  align-items: center;
  gap: calc(var(--u) * 8);
  width: 100%;
}

.hero-preview {
  display: grid;
  place-items: center;
  height: calc(var(--u) * 90);
  border: calc(var(--u) * 1) solid #2a2a3a;
  background: radial-gradient(circle at 50% 70%, #1a0f3a, #000 70%);
}

#preview {
  width: calc(var(--u) * 88);
  height: calc(var(--u) * 72);
}

.hero-controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: calc(var(--u) * 4);
  text-align: left;
}

.hero-controls .group legend,
.name-field {
  margin: 0 0 calc(var(--u) * 2);
  font-size: calc(var(--u) * 6);
  color: #ff7fd0;
}

.hero-controls .chips {
  justify-content: flex-start;
}

.hero-controls .chip {
  padding: calc(var(--u) * 3) calc(var(--u) * 4);
  font-size: calc(var(--u) * 7);
}

#name {
  width: 100%;
  margin: 0 0 calc(var(--u) * 2);
  padding: calc(var(--u) * 3) calc(var(--u) * 4);
  border: calc(var(--u) * 1) solid #ffe14a;
  border-radius: 0;
  background: #000;
  color: #fff;
  font-family: inherit;
  font-size: calc(var(--u) * 8);
  text-transform: uppercase;
  caret-color: #ffe14a;
  user-select: text;
  -webkit-user-select: text;
}

#name::placeholder {
  color: #4a4a5a;
}

#name:focus {
  outline: none;
  box-shadow: 0 0 0 calc(var(--u) * 1) #9adfff;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--u) * 3);
}

.swatch {
  width: calc(var(--u) * 13);
  height: calc(var(--u) * 11);
  padding: 0;
  border: calc(var(--u) * 1) solid #000;
  background: var(--sw);
  box-shadow: inset 0 calc(var(--u) * -2) 0 rgba(0, 0, 0, 0.3);
}

.swatch[aria-pressed="true"] {
  outline: calc(var(--u) * 1) solid #fff;
  outline-offset: calc(var(--u) * 1);
}

/* ---------- Pause and game over ---------- */

.ov-pause,
.ov-over {
  background: rgba(0, 0, 0, 0.72);
}

.ov-pause h2 {
  font-size: calc(var(--u) * 16);
}

.keys {
  margin: 0;
  font-size: calc(var(--u) * 6);
  line-height: 2;
  color: #9adfff;
}

.go {
  font-size: calc(var(--u) * 18) !important;
  color: #ff3b30 !important;
  text-shadow: calc(var(--u) * 2) calc(var(--u) * 2) 0 #5a0a00 !important;
}

.stats {
  display: grid;
  grid-template-columns: auto auto;
  gap: calc(var(--u) * 4) calc(var(--u) * 12);
  margin: 0;
  font-size: calc(var(--u) * 7);
}

.stats dt {
  color: #8a8a9a;
  text-align: right;
}

.stats dd {
  margin: 0;
  color: #ffe14a;
  text-align: left;
}

.rank {
  min-height: calc(var(--u) * 8);
  margin: 0;
  font-size: calc(var(--u) * 7);
  color: #5cf25c;
}

/* ---------- Touch controls ---------- */

.touch {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 12px max(12px, env(safe-area-inset-left)) 12px max(12px, env(safe-area-inset-right));
  pointer-events: none;
  font-family: "Press Start 2P", ui-monospace, monospace;
}

.touch button {
  pointer-events: auto;
  touch-action: none;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(30, 30, 46, 0.72);
  color: #fff;
}

.touch button.is-down {
  background: rgba(255, 225, 74, 0.85);
  color: #000;
}

.touch-dir {
  display: flex;
  gap: 10px;
}

.touch-dir button {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  font-size: 22px;
}

.touch-flap {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  font-size: 12px;
  border-color: rgba(255, 225, 74, 0.7) !important;
}

.touch-pause {
  align-self: flex-start;
  width: 44px;
  height: 36px;
  font-size: 12px;
  border-radius: 6px;
}

.cabinet.touch-beside .touch {
  top: 0;
  align-items: center;
}

.cabinet.touch-beside .touch-dir {
  flex-direction: column;
}

.cabinet.touch-beside .touch-pause {
  position: absolute;
  top: 12px;
  left: max(12px, env(safe-area-inset-left));
}

/* Portrait: the controls sit right under the screen */
.cabinet.touch-below .stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.cabinet.touch-below .touch {
  position: static;
  width: 100%;
  max-width: 560px;
  align-items: center;
  padding-top: 0;
  padding-bottom: 0;
}

.cabinet.touch-below .touch-pause {
  align-self: center;
}

@media (pointer: coarse) {
  .cabinet {
    height: 100svh;
  }
}

/* ---------- Bar under the screen ---------- */

.cab-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px 10px;
  font-family: "Press Start 2P", ui-monospace, monospace;
}

.bar-btn {
  padding: 6px 10px;
  border: 1px solid #2e2e3a;
  background: #0a0a10;
  color: #8a8a9a;
  font-size: 10px;
  line-height: 1;
}

.bar-btn:hover,
.bar-btn:focus-visible {
  color: #ffe14a;
  border-color: #ffe14a;
  outline: none;
}

.noscript {
  margin: 0;
  padding: 2rem;
  text-align: center;
}

/* ---------- About ---------- */

.about {
  padding: clamp(40px, 6vw, 80px) var(--ml-edge, 24px) clamp(56px, 8vw, 96px);
  background: #ffffff;
  color: #111111;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
}

.about h2 {
  margin: 0 0 1.4rem;
  font-size: 1rem;
  font-weight: 600;
}

.about__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2rem;
  max-width: 1300px;
}

.about h3 {
  margin: 0 0 0.4rem;
  font-family: "Newsreader", Georgia, serif;
  font-weight: 400;
  font-style: italic;
  font-size: 1.3rem;
}

.about p {
  margin: 0;
  color: #5b5b5b;
  font-size: 0.95rem;
  line-height: 1.55;
}

.about .about__note {
  margin-top: 2rem;
  font-family: "Newsreader", Georgia, serif;
  font-style: italic;
  font-size: 1.05rem;
}

@media (max-width: 900px) {
  .about__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .about__grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .cab-bar {
    gap: 4px;
  }
  .bar-btn {
    font-size: 8px;
    padding: 6px 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .blink,
  .rainbow,
  .hs td,
  .hs tr.is-new td {
    animation: none;
  }
}
