/* Nanonauts: Overdrive - layout and chrome.
   The canvas itself draws the game; everything here is the frame around it. */

:root {
  --bg:        #07060f;
  --panel:     #120f24;
  --panel-2:   #191434;
  --edge:      #2c2350;
  --ink:       #f4eefb;
  --ink-dim:   #a294bd;
  --accent:    #ffcf4a;
  --accent-2:  #4ff0ff;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  display: block;
  overflow: hidden;                 /* the page must never scroll during play */
  background: #07060f;
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------------------------------------------------------------- stage */

/*
 * The game fills the window edge to edge. It does not letterbox, and it does
 * not stretch: the canvas backing store is cut to the viewport's own aspect
 * ratio in fitToViewport(), so this 100%/100% is always a 1:1 match.
 */
#stage {
  position: relative;
  width: 100vw;
  /* Order matters. 100vh on iOS is the height with the browser bars *hidden*,
     so while they are showing it overflows and the bottom of the game is cut
     off. Declare it first as the fallback and let 100dvh - the height actually
     visible right now - win wherever it is supported. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#screen {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  background: #0e1230;
  touch-action: none;
}

/* ---------------------------------------------------------------- panel */

#panel {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 20;
  flex-direction: column;
  gap: 20px;
  padding: max(22px, env(safe-area-inset-top)) 22px 22px;
  overflow-y: auto;
  background: linear-gradient(160deg, rgba(25,20,52,.97), rgba(10,8,20,.98));
  backdrop-filter: blur(6px);
}

#panel.open { display: flex; }

#panel > * { width: min(100%, 460px); margin-inline: auto; }

#panel_close {
  display: block;
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 44px;
  height: 40px;
  font-size: 20px;
  z-index: 21;
}

#panel header { border-bottom: 1px solid var(--edge); padding-bottom: 14px; }

.wordmark {
  display: block;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .16em;
  color: var(--ink);
}

.sub {
  display: block;
  font-size: 13px;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--accent);
}

#panel h2 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 10px;
}

#panel label {
  display: block;
  font-size: 12px;
  color: var(--ink-dim);
  margin-bottom: 6px;
}

#player_name {
  width: 100%;
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  background: #0a0818;
  border: 1px solid var(--edge);
  border-radius: 3px;
}

#player_name:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }

.keys { display: grid; grid-template-columns: auto 1fr; gap: 9px 12px; align-items: center; }
.keys dt { display: flex; gap: 4px; flex-wrap: wrap; }
.keys dd { font-size: 13px; color: var(--ink-dim); }

kbd {
  display: inline-block;
  min-width: 26px;
  padding: 3px 6px;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  color: var(--accent-2);
  background: #0a0818;
  border: 1px solid var(--edge);
  border-bottom-width: 2px;
  border-radius: 3px;
}

.tips { list-style: none; display: flex; flex-direction: column; gap: 9px; }
.tips li { font-size: 13px; color: var(--ink-dim); padding-left: 13px; position: relative; }
.tips li::before { content: "\203A"; position: absolute; left: 0; color: var(--accent); }
.tips em { color: var(--ink); font-style: normal; font-weight: 600; }

#panel footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--edge);
  font-size: 12px;
  color: var(--ink-dim);
}

#panel footer a { color: var(--accent); }

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

#touch, #touch_top { display: none; }

.pad {
  font: inherit;
  font-weight: 700;
  letter-spacing: .1em;
  color: var(--accent-2);
  background: #0a0818;
  border: 2px solid var(--edge);
  border-radius: 4px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .55);
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.pad:active {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 3px 0 rgba(0, 0, 0, .55);
  transform: translateY(2px);
}

.noscript {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg); color: var(--ink); font-size: 18px;
}

/* ---------------------------------------------------------------- touch layer */

#touch_fly, #rotate_hint { display: none; }

/* Utility buttons are useful with a mouse too, so they show at every size. */
#touch_top {
  display: flex;
  gap: 8px;
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 4;
}

#touch_top .small {
  width: 46px;
  height: 38px;
  font-size: 15px;
  background: rgba(10, 8, 24, .55);
  backdrop-filter: blur(3px);
}

/*
 * JUMP.
 *
 * A circle, because the control is one binary action rather than a direction -
 * the character never moves along the ground, so there is nothing to point at.
 * Translucent so it never hides the track it sits over, and on the right, where
 * a thumb rests when the other hand is holding the phone.
 */
#btn_jump {
  display: none;
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 5;

  width: clamp(96px, 19vh, 148px);
  aspect-ratio: 1;
  border-radius: 50%;

  font-size: clamp(13px, 2.2vh, 17px);
  letter-spacing: .14em;
  color: rgba(79, 240, 255, .9);
  background: rgba(12, 10, 28, .34);
  border: 2px solid rgba(79, 240, 255, .45);
  box-shadow: inset 0 0 26px rgba(79, 240, 255, .10),
              0 6px 22px rgba(0, 0, 0, .45);
  backdrop-filter: blur(2px);
  transition: background .12s ease, transform .08s ease;
}

#btn_jump:active {
  background: rgba(79, 240, 255, .26);
  border-color: rgba(255, 207, 74, .9);
  color: #fff;
  transform: scale(.94);
}

/*
 * Overdrive sits directly above the jump circle, on the same side as the thumb
 * that will reach for it, offset by exactly the circle's height.
 */
#touch_actions {
  display: none;
  flex-direction: column;
  gap: 10px;
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(max(20px, env(safe-area-inset-bottom)) + clamp(96px, 19vh, 148px) + 14px);
  z-index: 4;
}

#touch_actions .pad {
  width: clamp(96px, 19vh, 148px);
  height: 52px;
  font-size: 12px;
  letter-spacing: .08em;
  border-radius: 8px;
  background: rgba(10, 8, 24, .5);
  backdrop-filter: blur(3px);
  transition: opacity .18s ease, color .18s ease, border-color .18s ease;
}

/*
 * A control you cannot use should not look like one you can. Overdrive stays
 * dimmed and inert until the meter is full, then lights and pulses - so the
 * meter filling and the button arming are the same event to the player.
 */
.pad:disabled {
  opacity: .3;
  pointer-events: none;
  color: var(--ink-dim);
  border-color: var(--edge);
}

#btn_over:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
  animation: odready 1.5s ease-in-out infinite;
}

@keyframes odready {
  0%, 100% { box-shadow: inset 0 -4px 0 rgba(0,0,0,.55), 0 0 0 rgba(255,207,74,0); }
  50%      { box-shadow: inset 0 -4px 0 rgba(0,0,0,.55), 0 0 20px rgba(255,207,74,.45); }
}

/* Touch devices get the on-screen controls; a keyboard does not need them. */
@media (pointer: coarse) {
  #touch_fly { display: block; position: absolute; inset: 0; z-index: 2; touch-action: none; }
  #btn_jump { display: block; }
  #touch_actions { display: flex; }
}

/* Portrait stops play outright. A 16:9 runner in a tall window is not a layout
   problem to solve - it is the wrong shape, so pause and ask for a rotation. */
@media (orientation: portrait) and (pointer: coarse) {
  #rotate_hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    position: fixed;
    inset: 0;
    z-index: 30;
    padding: 32px;
    text-align: center;
    background: rgba(7, 6, 15, .96);
    color: var(--ink-dim);
    font-size: 14px;
    line-height: 1.55;
  }
  #rotate_hint strong { color: var(--ink); font-size: 19px; }
  #rotate_hint .rot {
    font-size: 58px;
    color: var(--accent-2);
    animation: tilt 2.4s ease-in-out infinite;
  }
  #rotate_hint .a2hs {
    margin-top: 10px;
    padding: 12px 16px;
    max-width: 320px;
    font-size: 12.5px;
    color: var(--ink-dim);
    background: rgba(255, 255, 255, .04);
    border: 1px solid var(--edge);
    border-radius: 6px;
  }
  #rotate_hint .a2hs b { color: var(--accent); font-weight: 600; }

  /* Which build am I actually running? The portrait screen is where you are
     already stopped and looking, so it is where the answer belongs. */
  #rotate_hint .build {
    margin-top: 4px;
    font-size: 11px;
    letter-spacing: .1em;
    color: var(--muted, #718486);
    opacity: .75;
  }

  /* nothing behind the overlay should be reachable */
  #btn_jump, #touch_actions, #touch_fly, #touch_top { display: none !important; }
}

@keyframes tilt {
  0%, 100% { transform: rotate(0deg); }
  50%      { transform: rotate(-90deg); }
}

@media (prefers-reduced-motion: reduce) {
  .pad:active, #btn_jump:active { transform: none; }
  #btn_over:not(:disabled) { animation: none; }
  #rotate_hint .rot { animation: none; }
}


/* ---------------------------------------------------------------- update notice */

/*
 * Added to the home screen the game is a standalone app, and a standalone app
 * that silently serves last week's build is worse than one that asks. Mirrors
 * the version.json convention the Angular apps use.
 */
#update_banner {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 14px 11px 18px;
  background: rgba(10, 8, 24, .94);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--ink);
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .55);
}

#update_banner[hidden] { display: none; }

#update_reload {
  font: inherit;
  font-weight: 700;
  letter-spacing: .06em;
  padding: 7px 14px;
  color: #12101f;
  background: var(--accent);
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}
