html, body, #game { touch-action: none; }
html, body { margin: 0; height: 100%; overflow: hidden; }
html { background: #0a0a14; }
body {
  --cq-left: var(--cq-sal, env(safe-area-inset-left, 0px));
  --cq-right: var(--cq-sar, env(safe-area-inset-right, 0px));
  --cq-top: var(--cq-sat, env(safe-area-inset-top, 0px));
  --cq-bottom: var(--cq-sab, env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #1a1f33, #10131f 45%, #0a0a14);
}
[hidden] { display: none !important; }
#game, #cq-ctl-root, #cq-pause-layer, #rotate-gate {
  position: fixed;
  top: var(--cq-vv-top, 0px);
  left: var(--cq-vv-left, 0px);
  width: var(--cq-vv-width, 100vw);
  height: var(--cq-vv-height, 100dvh);
}
canvas { image-rendering: pixelated; }
#cq-safe-area {
  position: absolute;
  visibility: hidden;
  pointer-events: none;
  padding: var(--cq-top) var(--cq-right) var(--cq-bottom) var(--cq-left);
}
#cq-ctl-root { z-index: 40; pointer-events: none; }
#cq-ctl-root button { pointer-events: auto; }
.cq-rail {
  display: flex;
  position: absolute;
  bottom: calc(var(--cq-bottom) + 8px);
  gap: 8px;
}
#rail-left { left: calc(var(--cq-left) + 8px); }
.cq-stack-left #rail-left { flex-direction: column-reverse; gap: 29px; }
#rail-right {
  right: calc(var(--cq-right) + 8px);
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.cq-compact-right #rail-right {
  display: grid;
  grid-template-columns: 52px 72px;
  column-gap: 12px;
  justify-items: center;
  align-items: end;
}
.cq-compact-right #cq-mack,
.cq-compact-right #cq-jump { grid-column: 2; }
.cq-compact-right #cq-mack { grid-row: 1; }
#cq-bone-ctl {
  position: absolute;
  bottom: calc(var(--cq-bottom) + 8px);
  right: calc(var(--cq-right) + 4px);
}
.cq-btn {
  --size: 64px;
  --ring: #1b2030;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  width: var(--size);
  height: var(--size);
  flex: 0 0 var(--size);
  border-radius: 50%;
  border: 0;
  padding: 0;
  opacity: .82;
  cursor: pointer;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 32% 26%, var(--hi), var(--base) 42%, var(--dk));
  box-shadow: 0 0 0 4px var(--ring), 0 6px 0 #0009, inset 0 3px 5px #ffffff80, inset 0 -6px 10px #0005;
}
.cq-btn::before {
  content: "";
  position: absolute;
  inset: 15%;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 26%, var(--hi), var(--base) 50%, var(--dk) 115%);
  box-shadow: inset 0 3px 5px #fff8, inset 0 -4px 8px #0005, 0 2px 4px #0006;
}
.cq-btn svg, #cq-pause svg { position: relative; width: 26px; height: 26px; fill: #141008; }
.cq-label {
  position: absolute;
  z-index: 1;
  bottom: calc(100% + 6px);
  font: 900 11px/1.15 Arial, sans-serif;
  letter-spacing: .06em;
  color: #f5e9c8;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
  text-align: center;
  white-space: nowrap;
}
.cq-label.inside {
  position: relative;
  bottom: auto;
  font-size: 12px;
  color: #141008;
  text-shadow: none;
}
.cq-btn.held, .cq-btn:active { opacity: 1; filter: brightness(1.2); }
.cq-btn:focus-visible, #cq-pause:focus-visible, #cq-pause-layer button:focus-visible {
  outline: 3px solid #fff4ac;
  outline-offset: 0;
}
.cq-btn.go   { --hi: #c8f7c0; --base: #7fe27a; --dk: #3f9a44; }
.cq-btn.back { --hi: #d3ecff; --base: #9ad4ff; --dk: #4f83b8; }
.cq-btn.mack { --hi: #ffd3ec; --base: #ff9ad4; --dk: #c05a92; }
.cq-btn.jump { --size: 72px; --hi: #fff0a8; --base: #ffd94a; --dk: #c08a12; }
.cq-btn.cq-jump-locked { --hi: #d8d7d4; --base: #aeaaa3; --dk: #676361; }
.cq-btn.ral  { --size: 52px; --hi: #ffe0bd; --base: #f0a45a; --dk: #b56a2a; }
.cq-btn.bone { --size: 80px; --hi: #f0d9b8; --base: #c98f4a; --dk: #8a5c26; }
#cq-bone .cq-label {
  font-size: 12px;
  line-height: 1.1;
  border-radius: 4px;
  padding: 2px 5px;
  background: #0a0a14dc;
}
#cq-mack.glow, #cq-bone.urgent {
  --ring: #fff1a0;
  animation: cq-brighten .55s ease-in-out infinite alternate;
}
@keyframes cq-brighten { from { filter: brightness(1); } to { filter: brightness(1.25); } }
#cq-pause {
  box-sizing: border-box;
  position: absolute;
  top: calc(var(--cq-top) + 8px);
  right: calc(var(--cq-right) + 8px);
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  background: #f5e9c8d9;
  border: 2px solid #fff0a8;
  border-radius: 10px;
  cursor: pointer;
}
#cq-pause-layer {
  z-index: 70;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  padding: var(--cq-menu-top, 8px) var(--cq-menu-right, 8px) var(--cq-menu-bottom, 8px) var(--cq-menu-left, 8px);
  background: #080a12bd;
  font: 16px/1.35 Arial, sans-serif;
  color: #f5e9c8;
}
#cq-pause-layer section {
  box-sizing: border-box;
  width: min(100%, 440px);
  max-height: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 2px solid #b98a32;
  border-radius: 12px;
  padding: 14px;
  background: #14192a;
  box-shadow: 0 12px 28px #0008;
}
#cq-pause-layer h1, #rotate-gate h1 { margin: 0; font: 900 23px/1.15 Arial, sans-serif; color: #ffd94a; }
#cq-pause-layer header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#cq-pause-layer button {
  min-height: 44px;
  border: 1px solid #a39367;
  border-radius: 7px;
  padding: 6px 12px;
  background: #232c40;
  color: #f5e9c8;
  font: 700 15px/1.15 Arial, sans-serif;
  cursor: pointer;
}
#cq-pause-layer button:hover { border-color: #ffe088; }
#cq-pause-layer .primary { background: #ffd94a; color: #141008; }
.cq-menu-actions { display: grid; gap: 8px; margin-top: 12px; }
.cq-short-menu .cq-menu-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#cq-pause-layer #cq-controls-panel { width: min(100%, 560px); }
#cq-controls-panel dl { display: grid; gap: 0 16px; margin: 8px 0 0; font-size: 13px; }
.cq-short-menu #cq-controls-panel dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#cq-controls-panel dl div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  column-gap: 6px;
  padding: 4px 0;
  border-bottom: 1px solid #ddd4a928;
}
#cq-controls-panel dt { grid-row: span 2; font-weight: bold; }
#cq-controls-panel dd { margin: 0; }
#cq-controls-panel dd:last-child { color: #9ad4ff; }
#cq-controls-panel p { margin: 9px 0 0; font-size: 13px; }
#rotate-gate {
  z-index: 80;
  display: flex;
  box-sizing: border-box;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: max(16px, var(--cq-top)) max(16px, var(--cq-right)) max(16px, var(--cq-bottom)) max(16px, var(--cq-left));
  gap: 12px;
  background: #0a0a14;
  color: #f5e9c8;
  font: 15px/1.35 Arial, sans-serif;
}
#rotate-gate p { margin: 0; }
#cq-layout-debug {
  z-index: 90;
  position: fixed;
  top: 2px;
  left: 2px;
  max-width: 95vw;
  padding: 4px;
  margin: 0;
  pointer-events: none;
  background: #000d;
  color: #fff;
  font: 11px monospace;
}
.cq-paused #cq-ctl-root *, .cq-reduced-motion #cq-ctl-root * { animation-play-state: paused; }
@media (prefers-reduced-motion: reduce) {
  body:not(.cq-allow-motion) #cq-ctl-root * { animation: none; }
}
