/* Ultra Elliot
   Responsive shell around a fixed 16:9 stage.
   Future Nintendo Switch Port Preparation: the stage is locked to 16:9 so the
   same layout maps 1:1 onto Switch OLED handheld (1280x720) and TV (1920x1080).
   Nothing here is Nintendo-proprietary; it is standard CSS. */

:root {
  --bg: #0d0f0d;
  --panel: #171a17;
  --text: #f2f4ef;
  --muted: #a8afa5;
  --border: #30362f;
  --accent: #79d58d;

  --gap: 12px;
  --chrome: 210px; /* vertical space the page chrome needs beside the stage */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  /* no horizontal scrolling, ever */
  overflow-x: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  display: flex;
  justify-content: center;
  padding: 14px;
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}

.app {
  width: min(1280px, 100%);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ---------- header ---------- */

.topbar {
  display: flex;
  gap: var(--gap);
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brandtext {
  min-width: 0;
}

.brandmark {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: cover;
  flex: none;
}

h1 {
  margin: 0 0 3px;
  font-size: clamp(17px, 2.4vw, 24px);
  line-height: 1.1;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: clamp(11px, 1.3vw, 14px);
  line-height: 1.35;
}

.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 10px;
  background: var(--panel);
  font-size: clamp(11px, 1.2vw, 14px);
  white-space: nowrap;
}

.pill[hidden] {
  display: none;
}

#padStat {
  border-color: #3a7847;
  color: var(--accent);
}

/* ---------- the 16:9 stage ---------- */

.game-shell {
  background: #000;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  /* preserve aspect ratio, never crop, never overflow the viewport */
  aspect-ratio: 16 / 9;
  width: 100%;
  max-height: calc(100dvh - var(--chrome));
  margin-inline: auto;
  /* when max-height binds, keep 16:9 by shrinking width to match */
  max-width: calc((100dvh - var(--chrome)) * 16 / 9);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  background: #000;
  touch-action: none;
}

/* ---------- footer ---------- */

.bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
}

.help {
  font-size: clamp(11px, 1.2vw, 14px);
  color: var(--muted);
  flex: 1 1 260px;
  min-width: 0;
}

.actions {
  display: flex;
  gap: 8px;
}

button {
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  min-height: 42px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

button:hover {
  border-color: #596357;
}

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

.restart {
  background: #21472a;
  border-color: #3a7847;
}

/* ---------- touch controls ---------- */

.touch {
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--gap);
}

.touch-pad {
  display: grid;
  grid-template-columns: repeat(3, 60px);
  gap: 7px;
}

.touch-actions {
  display: flex;
  gap: 7px;
  align-items: flex-end;
}

.touch button {
  padding: 0;
  min-width: 60px;
  min-height: 52px;
  font-size: 15px;
  background: rgba(23, 26, 23, 0.92);
}

.touch button:active {
  border-color: var(--accent);
  background: #21472a;
}

/* Offer touch controls to touch devices. The media query catches most
   of them; body.has-touch is set from navigator.maxTouchPoints for
   hybrids and browsers that report pointer:fine with a touchscreen. */
@media (pointer: coarse) {
  .touch {
    display: flex;
  }
}

body.has-touch .touch {
  display: flex;
}

.mobile-note {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

/* ---------- small screens ---------- */

@media (max-width: 700px) {
  :root {
    --chrome: 300px;
  }

  body {
    padding: 8px;
  }

  .brandmark {
    width: 40px;
    height: 40px;
  }

  .actions {
    width: 100%;
  }

  .actions button {
    flex: 1;
  }

  .subtitle {
    display: none;
  }
}

/* ---------- landscape phones: give the stage the room it needs ---------- */

@media (orientation: landscape) and (max-height: 560px) {
  :root {
    --gap: 6px;
    --chrome: 76px;
  }

  body {
    padding: 6px;
  }

  .brandmark,
  .subtitle,
  .help,
  .mobile-note {
    display: none;
  }

  .topbar {
    flex-wrap: nowrap;
    align-items: center;
  }

  .bottom {
    margin: 0;
  }

  h1 {
    font-size: 15px;
  }

  .pill {
    padding: 4px 8px;
    font-size: 11px;
  }

  button {
    min-height: 34px;
    font-size: 12px;
  }

  .touch {
    /* overlay the pads on the stage instead of stacking below it */
    position: fixed;
    inset: auto 10px 10px 10px;
    pointer-events: none;
    z-index: 5;
  }

  .touch-pad,
  .touch-actions {
    pointer-events: auto;
  }

  .touch-pad {
    grid-template-columns: repeat(3, 48px);
  }

  .touch button {
    min-width: 48px;
    min-height: 42px;
    font-size: 13px;
    opacity: 0.82;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* quality selector sits with the action buttons */
.quality {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.quality select {
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  min-height: 42px;
  padding: 0 8px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.quality select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 700px) {
  .quality {
    flex: 1;
  }

  .quality select {
    flex: 1;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .quality span {
    display: none;
  }

  .quality select {
    min-height: 34px;
    font-size: 12px;
  }
}

/* developer credit */
.credits {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  padding: 4px 0 2px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.credits strong {
  color: var(--text);
}

@media (orientation: landscape) and (max-height: 560px) {
  .credits {
    display: none;
  }
}

.credits p {
  margin: 2px 0;
}

.credits a {
  color: var(--accent);
  text-decoration: none;
}

.credits a:hover {
  text-decoration: underline;
}

.credit-links {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
