:root {
  --bg: #0c0c0f;
  --surface: #141419;
  --surface2: #1e1e25;
  --hair: #282831;
  --text: #e0e0e6;
  --dim: #80808e;
  --accent: #6ee1aa;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

#screen {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
}

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

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg);
  color: var(--dim);
  font-size: 14px;
  z-index: 10;
  transition: opacity 180ms ease;
}

#loading.hidden {
  opacity: 0;
  pointer-events: none;
}

#loading.error {
  color: #ff8fa3;
  white-space: pre-wrap;
  padding: 24px;
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 2px solid var(--hair);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

#touch {
  display: none;
  flex: 0 0 auto;
  padding: 8px 14px 10px;
  background: var(--bg);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

@media (pointer: coarse) {
  #touch {
    display: block;
  }
}

/* ?touch=1 forces the pad for testing on a desktop browser. */
html.force-touch #touch {
  display: block;
}

.touch-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.touch-row.main {
  margin-top: 8px;
}

.touch-spacer {
  flex: 1;
}

.shoulder button {
  min-width: 58px;
  height: 34px;
  border-radius: 10px;
}

.shoulder.right {
  display: flex;
  justify-content: flex-end;
}

#touch button {
  appearance: none;
  border: 1px solid var(--hair);
  background: var(--surface2);
  color: var(--text);
  font: 600 13px/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.04em;
  touch-action: none;
  transition: background 60ms ease, transform 60ms ease;
}

#touch button.on {
  background: color-mix(in srgb, var(--accent) 55%, var(--surface2));
  border-color: var(--accent);
  color: #0b0b0d;
  transform: scale(0.97);
}

.dpad {
  position: relative;
  width: 132px;
  height: 132px;
  flex: 0 0 132px;
}

.dpad button {
  position: absolute;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  font-size: 12px;
}

.dpad .up {
  left: 44px;
  top: 0;
}
.dpad .down {
  left: 44px;
  top: 88px;
}
.dpad .left {
  left: 0;
  top: 44px;
}
.dpad .right {
  left: 88px;
  top: 44px;
}

.middle {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-bottom: 6px;
}

.middle .small {
  min-width: 76px;
  height: 30px;
  border-radius: 15px;
  font-size: 10px;
  color: var(--dim);
}

.ab {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.ab button {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 18px;
}

.ab .b {
  margin-top: 26px;
}

@media (max-width: 420px) {
  .dpad {
    width: 120px;
    height: 120px;
    flex-basis: 120px;
  }
  .dpad button {
    width: 40px;
    height: 40px;
  }
  .dpad .up {
    left: 40px;
  }
  .dpad .down {
    left: 40px;
    top: 80px;
  }
  .dpad .left {
    top: 40px;
  }
  .dpad .right {
    left: 80px;
    top: 40px;
  }
  .ab button {
    width: 50px;
    height: 50px;
  }
}
