:root {
  color-scheme: dark;
  --night: #0d151c;
  --panel: #17242d;
  --line: #31434e;
  --ink: #f5f2e8;
  --muted: #a8bac2;
  --acid: #d9f254;
  --orange: #ff8a35;
  --focus: #86d8ff;
  --z-screen: 30;
  --z-controls: 20;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 5%, rgba(217, 242, 84, 0.1), transparent 30rem),
    var(--night);
  font-family: "Avenir Next Condensed", "Franklin Gothic Condensed", "Arial Narrow", sans-serif;
}

button, a { font: inherit; }

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

.game-shell {
  width: min(100%, 1500px);
  height: 100svh;
  min-height: 100svh;
  margin: 0 auto;
  padding: 12px clamp(12px, 2vw, 32px) 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.topbar {
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: clamp(16px, 3vw, 44px);
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.wordmark {
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: baseline;
  gap: 7px;
  white-space: nowrap;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.wordmark strong {
  color: var(--acid);
  font-size: 1.5rem;
  letter-spacing: -0.025em;
  transform: skew(-6deg);
}

.stats {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: clamp(20px, 5vw, 72px);
}

.stat { min-width: 56px; }
.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.14em;
}
.stat strong {
  display: block;
  margin-top: 2px;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
}

.icon-button {
  min-height: 36px;
  padding: 0 13px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}
.icon-button:hover { background: var(--panel); }

/* The stage takes the FULL width it is given, unless the viewport is too short for a
   16:9 box that wide - then height decides. Whichever is smaller wins, so the canvas
   is always the biggest 16:9 rectangle that fits, with no black box around it. */
.stage {
  position: relative;
  width: min(100%, calc((100svh - 130px) * 16 / 9));
  margin-inline: auto;
  overflow: hidden;
  background: #6dcdf0;
  border: 1px solid #3a4d56;
  border-radius: 10px;
  box-shadow: 0 8px 0 #071014;
  isolation: isolate;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  max-height: calc(100svh - 130px);
  background: #70cff2;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: var(--z-screen);
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(360px, 1.1fr);
  align-items: center;
  visibility: hidden;
  opacity: 0;
  background: #111c24;
  transition: opacity 180ms ease-out, visibility 180ms;
}

.screen--visible { visibility: visible; opacity: 1; }

.screen__art {
  align-self: stretch;
  position: relative;
  overflow: hidden;
  background: var(--orange);
}

.sunburst {
  position: absolute;
  inset: -35%;
  opacity: 0.24;
  background: conic-gradient(from 8deg, #fff 0 8deg, transparent 8deg 25deg, #fff 25deg 33deg, transparent 33deg 50deg);
  animation: turn 24s linear infinite;
}

.screen__art img {
  position: absolute;
  z-index: 1;
  width: min(84%, 530px);
  left: 50%;
  bottom: -8%;
  transform: translateX(-50%) rotate(-2deg);
  filter: drop-shadow(18px 20px 0 rgba(22, 30, 34, 0.2));
}

.screen__copy { padding: clamp(28px, 6vw, 88px); }

.chapter {
  margin: 0 0 14px;
  color: var(--acid);
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.screen h1 {
  margin: 0;
  max-width: 8ch;
  font-size: clamp(3.1rem, 7vw, 6rem);
  line-height: 0.78;
  letter-spacing: -0.04em;
  text-wrap: balance;
  transform: skew(-4deg);
}

.screen h1 span {
  display: block;
  color: var(--orange);
  font-size: 0.48em;
  line-height: 1.05;
  letter-spacing: 0.03em;
}

.screen__copy > p:not(.chapter) {
  max-width: 42ch;
  margin: 24px 0;
  color: #d2dce0;
  font-size: clamp(1rem, 1.5vw, 1.25rem);
  line-height: 1.5;
}

.start-button {
  min-height: 54px;
  padding: 0 8px 0 22px;
  color: #121b20;
  background: var(--acid);
  border: 0;
  border-radius: 4px;
  box-shadow: 0 5px 0 #75851d;
  cursor: pointer;
  font-weight: 900;
  letter-spacing: 0.05em;
  transition: transform 120ms ease-out, box-shadow 120ms ease-out;
}
.start-button:hover { transform: translateY(-2px); box-shadow: 0 7px 0 #75851d; }
.start-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #75851d; }

kbd {
  display: inline-grid;
  min-width: 26px;
  min-height: 26px;
  place-items: center;
  margin-left: 12px;
  padding: 0 7px;
  color: inherit;
  background: rgba(0, 0, 0, 0.13);
  border-radius: 3px;
  font: 700 0.68rem/1 monospace;
}

.controls-copy {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
  margin-top: 28px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.controls-copy kbd { margin: 0 3px 0 0; background: var(--panel); }

.toast {
  position: absolute;
  z-index: var(--z-controls);
  top: 18px;
  left: 50%;
  padding: 8px 14px;
  color: #142027;
  background: var(--acid);
  border-radius: 3px;
  font-weight: 900;
  letter-spacing: 0.05em;
  transform: translate(-50%, -80px);
  transition: transform 180ms cubic-bezier(.22, 1, .36, 1);
}
.toast--visible { transform: translate(-50%, 0); }

/* Console deck: sits BELOW the screen (Game Boy style), filling the empty space.
   Hidden on desktop (keyboard). Shown on touch / small screens. */
.touch-controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.dpad { display: flex; gap: 14px; }
.touch-button {
  width: 66px;
  height: 66px;
  color: #fff;
  background: rgba(9, 18, 24, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 16px;
  font-weight: 900;
  font-size: 1.4rem;
  line-height: 1;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  box-shadow: 0 4px 0 #071014;
}
.touch-button:active { transform: translateY(3px); box-shadow: 0 1px 0 #071014; }
.touch-button--jump {
  width: 104px;
  height: 104px;
  color: #172027;
  background: rgba(217, 242, 84, 0.95);
  border: 0;
  border-radius: 50%;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  box-shadow: 0 5px 0 #75851d;
}
.touch-button--jump:active { transform: translateY(3px); box-shadow: 0 1px 0 #75851d; }

/* FIRE sits beside JUMP: smaller, roast-brown, so a thumb never confuses the two. */
.touch-button--fire {
  width: 84px;
  height: 84px;
  align-self: center;
  margin-right: 12px;
  color: #ffe9c9;
  background: rgba(122, 60, 28, 0.95);
  border: 0;
  border-radius: 50%;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  box-shadow: 0 5px 0 #40200f;
}
.touch-button--fire:active { transform: translateY(3px); box-shadow: 0 1px 0 #40200f; }

.footer-note {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

@keyframes turn { to { transform: rotate(1turn); } }

@media (pointer: coarse), (max-width: 760px) {
  .touch-controls {
    display: flex;
    flex: 1 1 auto;                          /* fill the empty space below the screen */
    min-height: 130px;
    margin-top: 8px;
    padding: clamp(16px, 5vw, 36px) clamp(20px, 7vw, 52px);
    background: linear-gradient(180deg, #1b2832, #0c1319);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.05), 0 8px 0 #071014;
  }
  .footer-note { display: none; }
  .game-shell { min-height: 100svh; justify-content: flex-start; padding: 8px; gap: 8px; }
  .topbar { min-height: 52px; padding-bottom: 8px; }
  .wordmark span, .stat:nth-child(2), .icon-button { display: none; }
  .wordmark strong { font-size: 1rem; }
  .stats { justify-content: flex-end; gap: 14px; }
  .stat { min-width: 38px; }
  .stat span { font-size: 0.52rem; }
  .stat strong { font-size: 0.88rem; }
  .screen { grid-template-columns: 1fr; }
  .screen__art { position: absolute; inset: 0 52% 0 0; opacity: 0.35; }
  .screen__copy { position: relative; z-index: 2; padding: 24px; }
  .screen h1 { font-size: clamp(3rem, 14vw, 5rem); }
  .controls-copy { display: none; }
}

@media (max-width: 520px) and (orientation: portrait) {
  .screen {
    position: fixed;
    inset: 60px 8px 8px;
    overflow-y: auto;
  }
  .screen__art { display: none; }
  .screen__copy { align-self: center; padding: 24px; }
  .screen__copy > p:not(.chapter) { margin: 16px 0; }
  .start-button { min-height: 48px; }
  .touch-button { width: 60px; height: 60px; }
  .touch-button--jump { width: 92px; height: 92px; }
  #game { min-height: 54vw; }
}

@media (max-height: 500px) {
  .screen {
    position: fixed;
    inset: 8px;
    min-height: 0;
  }
  .screen__copy { padding: 20px 34px; }
  .screen h1 { font-size: clamp(2.7rem, 9vh, 4rem); }
  .screen__copy > p:not(.chapter) { margin: 14px 0; }
  .controls-copy { margin-top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* On a real pointer (desktop/laptop) the on-screen D-pad + JUMP button are just
   clutter - the keyboard drives the game. Keep them for touch devices, where
   they are the only way to play. */
@media (hover: hover) and (pointer: fine) {
  .touch-controls { display: none !important; }
}
