:root {
  --bg: #16181d;
  --fg: #eef0e8;
  --dim: #9aa0a6;
  --accent: #e66e1e;
  --ok: #3ccf6e;
  --danger: #ff4d3d;
  --glass: rgba(14, 16, 20, 0.55);
  --stick-opacity: 0.6;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

#game {
  position: fixed;
  inset: 0;
}

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

button {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

/* ---- loading ------------------------------------------------------------------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg);
  transition: opacity 0.4s;
}
#loading.done {
  opacity: 0;
  pointer-events: none;
}
#loading .logo {
  width: 84px;
  height: 84px;
}
#loading .title {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.04em;
}
#loading .bar {
  width: min(320px, 70vw);
  height: 6px;
  border-radius: 3px;
  background: #2a2e36;
  overflow: hidden;
}
#load-bar {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.15s;
}
#load-text {
  color: var(--dim);
  font-size: 13px;
  min-height: 1.3em;
  text-align: center;
}
#load-error {
  text-align: center;
  max-width: 80vw;
}
#load-error p {
  color: #ffb3a8;
}
#load-error button,
.menu button,
.menu select {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid #3a3f48;
  background: #23262d;
  margin: 4px;
}

/* ---- turn the phone ---------------------------------------------------------------- */
#rotate {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
#rotate .phone {
  width: 44px;
  height: 76px;
  border: 4px solid var(--fg);
  border-radius: 9px;
  animation: turn 2s ease-in-out infinite;
}
@keyframes turn {
  0%, 30% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}

/* ---- on-screen controls ------------------------------------------------------------ */
#touch {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}
#touch .zone {
  position: absolute;
  bottom: 0;
  height: 62%;
  pointer-events: auto;
  touch-action: none;
}
#touch .zone.left { left: 0; width: 50%; }
#touch .zone.right { right: 0; width: 50%; }

.stick {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(238, 240, 232, 0.55);
  background: rgba(14, 16, 20, 0.35);
  opacity: var(--stick-opacity);
  box-sizing: border-box;
  pointer-events: none;
}
.stick.active {
  opacity: calc(var(--stick-opacity) + 0.25);
}
.stick .cross-v,
.stick .cross-h {
  position: absolute;
  background: rgba(238, 240, 232, 0.18);
}
.stick .cross-v { left: 50%; top: 8%; bottom: 8%; width: 1px; }
.stick .cross-h { top: 50%; left: 8%; right: 8%; height: 1px; }
.stick .notch {
  position: absolute;
  left: -10px;
  right: -10px;
  height: 0;
  border-top: 3px solid var(--accent);
  opacity: 0.9;
}
.stick .notch::after {
  content: attr(data-label);
  position: absolute;
  right: -2px;
  top: -18px;
  font-size: 10px;
  color: var(--accent);
}
.stick .knob {
  position: absolute;
  width: 38%;
  height: 38%;
  margin: -19% 0 0 -19%;
  border-radius: 50%;
  background: rgba(238, 240, 232, 0.85);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.stick .label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -18px;
  text-align: center;
  font-size: 10px;
  color: rgba(238, 240, 232, 0.7);
  letter-spacing: 0.06em;
}

/* top row of buttons */
#touch .row {
  position: absolute;
  top: calc(6px + var(--safe-t));
  display: flex;
  gap: 6px;
  pointer-events: none;
}
#touch .row.l { left: calc(8px + var(--safe-l)); }
/* the right group stops short of the corner: OG Arcade's chat button lives there */
#touch .row.r { right: calc(64px + var(--safe-r)); }
.tbtn {
  pointer-events: auto;
  touch-action: none;
  min-width: 46px;
  height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid rgba(238, 240, 232, 0.25);
  background: var(--glass);
  color: var(--fg);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.tbtn.on {
  border-color: var(--accent);
  color: #fff;
  background: rgba(230, 110, 30, 0.35);
}
.tbtn.held {
  background: rgba(230, 110, 30, 0.6);
}
.tbtn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* arm: slide to arm */
.arm {
  pointer-events: auto;
  touch-action: none;
  position: relative;
  width: 128px;
  height: 40px;
  border-radius: 20px;
  border: 1px solid rgba(238, 240, 232, 0.3);
  background: var(--glass);
  overflow: hidden;
}
.arm .fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: rgba(255, 77, 61, 0.45);
}
.arm .text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 30px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--dim);
}
.arm .thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--fg);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5);
}
.arm.armed {
  border-color: var(--danger);
  background: rgba(255, 77, 61, 0.35);
}
.arm.armed .text {
  color: #fff;
  padding-left: 0;
  padding-right: 30px;
}

#toast {
  position: absolute;
  top: 54px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(14, 16, 20, 0.8);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
}

#fps {
  position: absolute;
  left: 50%;
  bottom: calc(4px + var(--safe-b));
  transform: translateX(-50%);
  font: 11px ui-monospace, monospace;
  color: rgba(238, 240, 232, 0.6);
  pointer-events: none;
}

/* ---- menus (pause, mode, settings) ---------------------------------------------------- */
.menu {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(10, 11, 14, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: pan-y;
}
.menu .panel {
  width: min(560px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background: #1c1f25;
  border: 1px solid #30343c;
  border-radius: 14px;
  padding: 14px 16px;
  box-sizing: border-box;
}
.menu h2 {
  margin: 0 0 10px;
  font-size: 18px;
}
.menu h3 {
  margin: 14px 0 6px;
  font-size: 13px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.menu .grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.menu .grid button {
  margin: 0;
}
.menu button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}
.menu button.sel {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.menu button:disabled {
  opacity: 0.4;
}
.menu .opt {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}
.menu .opt label {
  flex: 0 0 130px;
  color: var(--dim);
}
.menu .opt input[type="range"] {
  flex: 1;
  height: 32px;
  accent-color: var(--accent);
}
.menu .opt output {
  flex: 0 0 48px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.menu .opt input[type="checkbox"] {
  width: 26px;
  height: 26px;
  accent-color: var(--accent);
}
.menu .seg {
  display: flex;
  flex-wrap: wrap;
}
.menu .note {
  color: var(--dim);
  font-size: 12px;
  margin: 4px 0;
}

/* ---- setting hints: tap (i) to open the explanation under the setting ------------------ */
.menu button.info {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  min-height: 0;
  margin: 0 0 0 4px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid #8a8f98;
  background: transparent;
  color: #c9ccd2;
  font: italic 700 15px Georgia, serif;
  line-height: 1;
}
.menu button.info.on {
  border-color: var(--accent);
  color: var(--accent);
}
.menu h3 .info {
  vertical-align: middle;
  width: 24px;
  height: 24px;
  font-size: 13px;
  text-transform: none;
}
.menu .hint {
  background: #262a32;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 2px 0 8px;
  font-size: 13px;
  line-height: 1.4;
  color: #e3e5ea;
}
.menu .hint p {
  margin: 0 0 4px;
}
.menu .hint b {
  color: var(--dim);
  font-weight: 700;
}
.menu .hint .beg b {
  color: #8cdc8c;
}

/* fullscreen button (plain browsers only; OG Arcade keeps this corner for its chat button) */
.fs-btn {
  position: fixed;
  top: calc(6px + var(--safe-t));
  right: calc(10px + var(--safe-r));
  z-index: 40;
  width: 44px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(238, 240, 232, 0.25);
  background: var(--glass);
  color: var(--fg);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
.fs-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
