/* Project Stargem browser player. Layouts:
 *  - desktop (no touch): the screen fills the frame; keyboard help only on
 *    the start overlay
 *  - touch, portrait:    screen across the full width on top, below it two
 *                        columns: D-pad + SELECT left, A/B + START right
 *  - touch, landscape:   screen across the full height, the same two
 *                        columns left and right of it */

:root {
  --bg: #000;
  --ink: #d1f8ef;
  --ink-dim: #7d8c92;
  --pad-face: #2b3438;
  --pad-edge: #161c1f;
  --btn-face: #cc1250;
  --btn-edge: #84072e;
  --btn-ink: #ffe3ea;
  --pad-size: min(40vw, 26vh, 200px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: grid;
  height: 100%;
  width: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "screen";
}

#screen-area {
  grid-area: screen;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#screen-frame {
  position: relative;
  line-height: 0;
}

#screen {
  display: block;
  width: 160px;
  height: 144px;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#start-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8em;
  padding: 1em;
  border: 0;
  background: rgba(0, 0, 0, 0.78);
  color: var(--ink);
  font: inherit;
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
}

#start-overlay[hidden] { display: none; }

.start-title {
  font-size: clamp(15px, 4.5vmin, 30px);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.start-hint {
  font-size: clamp(13px, 3.4vmin, 20px);
  font-weight: 600;
  padding: 0.5em 1.6em;
  border-radius: 999px;
  background: var(--btn-face);
  color: var(--btn-ink);
}

.start-keys {
  font-size: clamp(10px, 2.2vmin, 13px);
  color: var(--ink-dim);
}

body.touch .start-keys { display: none; }

/* With cover art (cover.png in the build) the start screen shows it full
 * size; the logo is in the picture, so the title text steps aside and the
 * prompt moves down onto a dark strip. */
body.has-cover #start-overlay {
  justify-content: flex-end;
  gap: 0.5em;
  padding-bottom: 5%;
  background: #000 url("cover.png") center / cover no-repeat;
  image-rendering: pixelated;
}

body.has-cover .start-title { display: none; }

body.has-cover .start-hint {
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}

body.has-cover .start-keys {
  padding: 0.35em 1em;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.8);
  color: var(--ink);
  white-space: nowrap;
}

/* Too narrow for the key line on one row: leave it out. */
@media (max-width: 559px) {
  .start-keys { display: none; }
}

/* On-screen controls exist only on touch devices (body.touch is set by the
 * player for a coarse pointer, a first touch, or ?touch=1). */
body:not(.touch) .pad-col { display: none; }

.pad-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 3vh, 28px);
  min-width: 0;
  min-height: 0;
}

#left { grid-area: left; }
#right { grid-area: right; }

/* Portrait: the screen takes the full width, the controls the rest. */
body.touch #app {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "screen screen"
    "left   right";
}

body.touch #screen-area {
  width: 100%;
  aspect-ratio: 160 / 144;
  max-height: 62vh;
}

#dpad {
  position: relative;
  flex: none;
  width: var(--pad-size);
  height: var(--pad-size);
}

/* The cross is one shape: two overlapping bars under a single drop shadow,
 * so no seams show where the arms meet. The arms above it are invisible
 * and only light up while pressed. */
#dpad .cross {
  position: absolute;
  inset: 0;
  filter: drop-shadow(0 4px 0 var(--pad-edge));
}

#dpad .cross::before,
#dpad .cross::after {
  content: "";
  position: absolute;
  background: var(--pad-face);
  border-radius: 8px;
}

#dpad .cross::before { left: 33%; top: 0; width: 34%; height: 100%; }
#dpad .cross::after { left: 0; top: 33%; width: 100%; height: 34%; }

#dpad .arm {
  position: absolute;
  width: 34%;
  height: 34%;
}

#dpad .arm.is-pressed {
  filter: none;
  transform: none;
  background: rgba(255, 255, 255, 0.16);
}

#dpad .up { left: 33%; top: 0; border-radius: 8px 8px 0 0; }
#dpad .down { left: 33%; bottom: 0; border-radius: 0 0 8px 8px; }
#dpad .left { left: 0; top: 33%; border-radius: 8px 0 0 8px; }
#dpad .right { right: 0; top: 33%; border-radius: 0 8px 8px 0; }

#ab {
  position: relative;
  flex: none;
  width: var(--pad-size);
  height: var(--pad-size);
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.btn.round {
  position: absolute;
  width: 42%;
  height: 42%;
  border-radius: 50%;
  background: var(--btn-face);
  box-shadow: inset 0 -5px 0 var(--btn-edge);
  color: var(--btn-ink);
  font-size: calc(var(--pad-size) * 0.14);
}

/* The classic diagonal: B low left, A high right. */
#ab [data-key="b"] { left: 2%; bottom: 12%; }
#ab [data-key="a"] { right: 2%; top: 12%; }

.btn.pill {
  flex: none;
  min-width: 88px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--pad-face);
  box-shadow: inset 0 -3px 0 var(--pad-edge);
  color: var(--ink-dim);
  font-size: 12px;
  letter-spacing: 0.12em;
}

.is-pressed {
  filter: brightness(1.5);
  box-shadow: none !important;
  transform: translateY(2px);
}

/* SELECT and START sit toward the middle, close together, like on the
 * handheld: each at the inner edge of its column. */
#select { align-self: flex-end; margin-right: 6px; }
#start { align-self: flex-start; margin-left: 6px; }

@media (orientation: landscape) {
  body.touch {
    --pad-size: min(42vh, 21vw, 190px);
  }

  /* Landscape: the screen takes the full height, a column on each side. */
  body.touch #app {
    grid-template-columns:
      minmax(0, 1fr) min(calc(100vh * 160 / 144), 62vw) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "left screen right";
  }

  body.touch #screen-area {
    width: auto;
    height: 100%;
    max-height: none;
    aspect-ratio: auto;
  }
}
