/* Crossing - the frame around the canvas. The field itself is all drawn. */

:root {
  --bg:      #070b16;
  --edge:    #1d2b4a;
  --ink:     #f2f6ff;
  --ink-dim: #8fa0c4;
  --accent:  #fbbf24;
  --good:    #8ee34a;
  color-scheme: dark;
}

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

html, body { height: 100%; }

body {
  display: block;
  overflow: hidden;
  background: radial-gradient(circle at 50% 30%, #16294a 0%, #0d1526 58%, var(--bg) 100%);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/*
 * The canvas fills the window. It is never stretched, because the backing store
 * is cut to the viewport's own aspect ratio in fitToViewport() rather than a
 * fixed one being scaled to fit.
 */
#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;          /* wins where supported; the line above is the fallback */
  overflow: hidden;
}

#screen {
  display: block;
  width: 100%;
  height: 100%;
  background: #0b1020;
  touch-action: none;
}

/* ---------------------------------------------------------------- tools */

#tools {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 4;
  display: flex;
  gap: 8px;
}

.pad {
  font: inherit;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: .08em;
  height: 38px;
  padding: 0 13px;
  color: var(--accent);
  background: rgba(7, 11, 22, .6);
  border: 2px solid var(--edge);
  border-radius: 7px;
  backdrop-filter: blur(3px);
  cursor: pointer;
  touch-action: manipulation;
}

.pad:hover { border-color: var(--accent); }

.pad:active {
  color: #071018;
  background: var(--accent);
  border-color: var(--accent);
  transform: translateY(1px);
}

.pad:focus-visible { outline: 2px solid var(--good); outline-offset: 2px; }

/* ---------------------------------------------------------------- the d-pad */

/*
 * Only up ever really matters, but back, left and right all have their moment -
 * stepping off a log before it leaves the field is the one that saves a life.
 * The layout is the same three by three as Stow's, so a player who has met one
 * of these games already knows where the buttons are.
 */
#pad {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 58px);
  gap: 4px;
}

#pad[hidden] { display: none; }

#pad button {
  font-size: 19px;
  line-height: 1;
  color: var(--ink);
  background: rgba(7, 11, 22, .62);
  border: 2px solid rgba(242, 246, 255, .3);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#pad button:active {
  color: #071018;
  background: var(--good);
  border-color: var(--good);
}

#pad_up    { grid-area: 1 / 2; }
#pad_left  { grid-area: 2 / 1; }
#pad_right { grid-area: 2 / 3; }
#pad_down  { grid-area: 3 / 2; }

@media (max-width: 520px) {
  #pad { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 50px); }
  #pad button { font-size: 16px; }
}

/* ---------------------------------------------------------------- build stamp */

#build_stamp {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 3;
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--ink-dim);
  opacity: .6;
  pointer-events: none;
}

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

#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(7, 11, 22, .95);
  border: 1px solid var(--accent);
  border-radius: 8px;
  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;
  padding: 7px 14px;
  color: #071018;
  background: var(--accent);
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}

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

@media (prefers-reduced-motion: reduce) {
  .pad:active { transform: none; }
}
