/* CEMENT PROTOCOL — commercial + Bucket Dash
   Mobile: cinema trailer, landscape play, controls BELOW stage */

.cp-body {
  --cp-amber: #ffb84d;
  --cp-hot: #ff5a1f;
  --cp-cyan: #5ee7ff;
  --cp-dim: #9aa8bc;
  --cp-panel: #0a0806;
  background:
    radial-gradient(ellipse 70% 45% at 20% 10%, rgba(255, 90, 31, 0.18), transparent 55%),
    radial-gradient(ellipse 50% 40% at 90% 80%, rgba(255, 184, 77, 0.1), transparent 50%),
    #0a0604;
  color: #f4ebe0;
  min-height: 100dvh;
}

.cp-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem 1rem calc(2.5rem + env(safe-area-inset-bottom, 0px));
}

.cp-kicker {
  font-family: var(--mono, ui-monospace, Consolas, monospace);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  color: var(--cp-hot);
  text-transform: uppercase;
  margin: 0.5rem 0 0.25rem;
}

.cp-wrap h1 {
  font-size: clamp(1.6rem, 5vw, 2.5rem);
  margin: 0 0 0.35rem;
  letter-spacing: 0.06em;
  text-shadow: 0 0 22px rgba(255, 90, 31, 0.45);
}

.cp-lede {
  color: var(--cp-dim);
  font-size: 0.95rem;
  line-height: 1.45;
  margin: 0 0 1rem;
  max-width: 44rem;
}

.cp-playfield {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
}

.cp-stage {
  position: relative;
  background: #000;
  border: 1px solid rgba(255, 90, 31, 0.45);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(255, 90, 31, 0.15), 0 0 60px rgba(255, 184, 77, 0.08);
  aspect-ratio: 16 / 9;
  width: 100%;
  max-height: min(70dvh, 620px);
}

.cp-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

.cp-trailer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #050302;
  z-index: 4;
}

.cp-trailer[hidden] { display: none !important; }

.cp-skip-pill {
  position: absolute;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  z-index: 5;
  font-family: var(--mono, ui-monospace, Consolas, monospace);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ffb84d;
  background: rgba(10, 6, 4, 0.85);
  border: 1px solid rgba(255, 184, 77, 0.55);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  cursor: pointer;
  min-height: 44px;
}

.cp-skip-pill[hidden] { display: none !important; }
.cp-skip-pill:hover { background: rgba(255, 90, 31, 0.35); }

.cp-hud {
  position: absolute;
  inset: 0 auto auto 0;
  right: 0;
  pointer-events: none;
  font-family: var(--mono, ui-monospace, Consolas, monospace);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: rgba(255, 184, 77, 0.95);
  text-shadow: 0 1px 3px #000;
  padding: 0.55rem 0.7rem;
  display: flex;
  justify-content: space-between;
  z-index: 2;
}

.cp-hud #cp-hud-mid { color: rgba(255, 90, 31, 0.95); }
.cp-hud #cp-hud-right { color: rgba(94, 231, 255, 0.95); }

/* Floating beam / critical alert — high-vis placard (readable over fire) */
.cp-alert {
  position: absolute;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  z-index: 6;
  pointer-events: none;
  min-width: min(86%, 400px);
  max-width: 94%;
  padding: 0.65rem 1rem 0.75rem;
  text-align: center;
  box-sizing: border-box;
  /* Solid high-vis yellow — no alpha, works over fire graphics */
  background: #ffb84d;
  border: 3px solid #1a0c04;
  border-radius: 8px;
  box-shadow:
    0 0 0 2px #ffb84d,
    0 0 0 4px #1a0c04,
    0 8px 22px rgba(0, 0, 0, 0.75);
  animation: cp-alert-pulse 0.95s ease-in-out infinite;
}

.cp-alert[hidden] { display: none !important; }

.cp-alert-stamp {
  margin: 0 0 0.15rem;
  font-family: var(--mono, ui-monospace, Consolas, monospace);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #5a1a08;
}

.cp-alert-title {
  margin: 0;
  font-family: var(--mono, ui-monospace, Consolas, monospace);
  font-weight: 900;
  font-size: clamp(1.25rem, 4vw, 1.85rem);
  letter-spacing: 0.04em;
  line-height: 1.1;
  color: #120806;
  text-shadow: none;
}

.cp-alert-tip {
  margin: 0.3rem 0 0;
  font-family: var(--mono, ui-monospace, Consolas, monospace);
  font-size: clamp(0.72rem, 2.1vw, 0.88rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #2a1408;
}

.cp-alert.is-ride {
  background: #7ee8ff;
  border-color: #062028;
  box-shadow:
    0 0 0 2px #7ee8ff,
    0 0 0 4px #062028,
    0 8px 22px rgba(0, 0, 0, 0.7);
  animation: none;
}

.cp-alert.is-ride .cp-alert-stamp { color: #063040; }
.cp-alert.is-ride .cp-alert-title { color: #041820; }
.cp-alert.is-ride .cp-alert-tip { color: #0a3040; }

.cp-alert.is-critical {
  background: #ff6a45;
  border-color: #2a0804;
  box-shadow:
    0 0 0 2px #ff6a45,
    0 0 0 4px #2a0804,
    0 8px 22px rgba(0, 0, 0, 0.75);
}

.cp-alert.is-critical .cp-alert-stamp,
.cp-alert.is-critical .cp-alert-title,
.cp-alert.is-critical .cp-alert-tip { color: #140604; }

@keyframes cp-alert-pulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.035); }
}

@media (orientation: landscape) and (max-height: 480px) {
  .cp-alert {
    top: 10%;
    padding: 0.4rem 0.8rem 0.5rem;
    min-width: min(72%, 340px);
  }
  .cp-alert-title { font-size: clamp(1.05rem, 3.4vw, 1.45rem); }
  .cp-alert-tip { font-size: 0.68rem; margin-top: 0.18rem; }
  .cp-alert-stamp { font-size: 0.58rem; }
}

/* Controls sit UNDER the stage — never overlay the canvas */
.cp-touch {
  display: none;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(12, 8, 4, 0.95), rgba(6, 4, 2, 0.98));
  border: 1px solid rgba(255, 184, 77, 0.28);
  border-top: none;
  border-radius: 0 0 6px 6px;
  box-sizing: border-box;
  z-index: 3;
}

.cp-touch:not([hidden]) {
  display: flex;
}

.cp-touch-move,
.cp-touch-actions {
  display: flex;
  gap: 0.5rem;
}

.cp-touch button {
  min-width: 76px;
  min-height: 56px;
  border-radius: 10px;
  border: 2px solid rgba(255, 184, 77, 0.55);
  background: rgba(20, 12, 6, 0.9);
  color: var(--cp-amber);
  font-family: var(--mono, ui-monospace, Consolas, monospace);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  font-weight: 700;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cp-btn-duck {
  min-width: 100px !important;
  border-color: rgba(94, 231, 255, 0.55) !important;
  color: #5ee7ff !important;
}

.cp-touch button:active {
  background: rgba(255, 90, 31, 0.4);
  transform: scale(0.97);
}

/* Lives at <body> level — never clipped by the stage */
.cp-overlay {
  position: fixed;
  inset: 0;
  z-index: 160;
  display: flex;
  align-items: stretch;
  justify-content: center;
  overflow: hidden;
  background: rgba(6, 4, 2, 0.88);
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  backdrop-filter: blur(3px);
}

.cp-overlay[hidden] { display: none !important; }

/* Hide during trailer / play — menu & results only */
body.cp-mode-trailer .cp-overlay,
body.cp-mode-play .cp-overlay {
  display: none !important;
}

.cp-card {
  display: flex;
  flex-direction: column;
  max-width: 520px;
  width: 100%;
  max-height: min(92dvh, 720px);
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #1a120a 0%, #0c0906 100%);
  border: 2px solid rgba(255, 184, 77, 0.5);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 0 40px rgba(255, 90, 31, 0.2);
  text-align: center;
}

.cp-card-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1.35rem 1.35rem 0.85rem;
}

.cp-card-art {
  display: block;
  width: 100%;
  height: auto;
  max-height: 34vh;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(255, 184, 77, 0.35);
  margin: 0 0 0.9rem;
}

.cp-kit {
  text-align: left;
  margin: 0.35rem 0 0.85rem;
  padding: 0.75rem 0.85rem;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 184, 77, 0.22);
  border-radius: 6px;
}

.cp-kit h3 {
  margin: 0.35rem 0 0.45rem;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  color: var(--cp-amber);
  font-family: var(--mono, ui-monospace, Consolas, monospace);
}

.cp-kit h3:first-child { margin-top: 0; }

.cp-kit ul {
  margin: 0 0 0.55rem;
  padding: 0 0 0 0.15rem;
  list-style: none;
}

.cp-kit li {
  margin: 0 0 0.4rem;
  color: var(--cp-dim);
  font-size: 0.92rem;
  line-height: 1.4;
}

.cp-kit-tag {
  display: inline-block;
  min-width: 7.5rem;
  margin-right: 0.35rem;
  padding: 0.12rem 0.4rem;
  border-radius: 3px;
  font-family: var(--mono, ui-monospace, Consolas, monospace);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.cp-kit-mix { background: rgba(94, 231, 255, 0.2); color: #5ee7ff; }
.cp-kit-vest { background: rgba(255, 184, 77, 0.22); color: #ffb84d; }
.cp-kit-clear { background: rgba(255, 90, 31, 0.22); color: #ff8a55; }
.cp-kit-boots { background: rgba(180, 140, 255, 0.22); color: #c4a8ff; }

.cp-kit-note {
  margin: 0.35rem 0 0 !important;
  font-size: 0.85rem !important;
  color: rgba(255, 184, 77, 0.85) !important;
}

.cp-card-stamp {
  font-family: var(--mono, ui-monospace, Consolas, monospace);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  color: var(--cp-hot);
  margin: 0 0 0.55rem;
}

.cp-card h2 {
  margin: 0 0 0.65rem;
  font-size: clamp(1.35rem, 5.5vw, 1.65rem);
  letter-spacing: 0.06em;
  color: #fff5e8;
  text-shadow: 0 0 16px rgba(255, 90, 31, 0.5);
}

.cp-card p {
  margin: 0 0 0.85rem;
  color: var(--cp-dim);
  font-size: clamp(1.05rem, 4vw, 1.15rem);
  line-height: 1.5;
  white-space: pre-line;
}

.cp-card-extra {
  font-family: var(--mono, ui-monospace, Consolas, monospace);
  font-size: 0.9rem;
  color: var(--cp-amber) !important;
}

/* Buttons always visible under the scroll area */
.cp-card-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: center;
  margin: 0;
  padding: 0.85rem 1rem calc(0.95rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(255, 184, 77, 0.28);
  background: rgba(8, 5, 3, 0.96);
}

.cp-card-actions .btn {
  margin: 0;
  min-height: 52px;
  font-size: 1rem;
  padding: 0.75rem 1.15rem;
  flex: 1 1 auto;
  max-width: 100%;
}

/* Phones: instruction sheet fills the screen; buttons stay pinned */
@media (max-width: 900px) {
  .cp-overlay:not([hidden]) {
    padding: 0;
  }
  .cp-card {
    max-width: none;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: none;
    border-top: 2px solid rgba(255, 184, 77, 0.45);
  }
  .cp-card-scroll {
    padding: 1.75rem 1.35rem 1.1rem;
  }
  .cp-card h2 { font-size: 1.65rem; }
  .cp-card p { font-size: 1.18rem; line-height: 1.55; }
  .cp-card-stamp { font-size: 0.85rem; }
  .cp-card-extra { font-size: 1rem; }
  .cp-card-actions {
    gap: 0.7rem;
    padding: 1rem 1.1rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  }
  .cp-card-actions .btn {
    min-height: 58px;
    font-size: 1.08rem;
    width: 100%;
    flex: 1 1 100%;
  }
}

.cp-help {
  font-size: 0.8rem;
  color: var(--cp-dim);
  margin: 0.75rem 0 0;
  font-family: var(--mono, ui-monospace, Consolas, monospace);
}

.cp-help kbd {
  display: inline-block;
  padding: 0.05rem 0.35rem;
  border: 1px solid rgba(255, 184, 77, 0.35);
  border-radius: 3px;
  background: rgba(20, 12, 6, 0.8);
  font-size: 0.72rem;
}

.cp-foot {
  margin: 1.25rem 0 0;
  font-size: 0.85rem;
  color: var(--cp-dim);
}

.cp-foot a { color: var(--cp-amber); }

/* ===== Rotate gate (game requires landscape on phones) ===== */
.cp-rotate {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(5, 3, 2, 0.96);
  text-align: center;
}

.cp-rotate[hidden] { display: none !important; }

.cp-rotate-inner {
  max-width: 22rem;
}

.cp-rotate-icon {
  font-size: 2.8rem;
  margin: 0 0 0.75rem;
}

.cp-rotate h2 {
  margin: 0 0 0.5rem;
  letter-spacing: 0.08em;
  color: var(--cp-amber);
  font-size: 1.35rem;
}

.cp-rotate p {
  margin: 0;
  color: var(--cp-dim);
  font-size: 1rem;
  line-height: 1.45;
}

/* ===== CINEMA: commercial fills the screen ===== */
body.cp-mode-trailer {
  overflow: hidden;
}

body.cp-mode-trailer .cp-chrome,
body.cp-mode-trailer .site-header,
body.cp-mode-trailer .scanlines {
  display: none !important;
}

body.cp-mode-trailer .cp-wrap {
  max-width: none;
  padding: 0;
  margin: 0;
}

body.cp-mode-trailer .cp-playfield {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: #000;
}

body.cp-mode-trailer .cp-stage {
  position: absolute;
  inset: 0;
  max-height: none;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

body.cp-mode-trailer .cp-trailer {
  object-fit: contain;
  width: 100%;
  height: 100%;
  background: #000;
}

body.cp-mode-trailer .cp-touch {
  display: none !important;
}

body.cp-mode-trailer .cp-skip-pill {
  bottom: max(1rem, env(safe-area-inset-bottom));
  right: max(1rem, env(safe-area-inset-right));
  font-size: 0.85rem;
  min-height: 48px;
  padding: 0.65rem 1.2rem;
  z-index: 130;
}

/* ===== PLAY: landscape shell, controls under stage ===== */
body.cp-mode-play .cp-chrome,
body.cp-mode-play .site-header {
  display: none !important;
}

body.cp-mode-play {
  overflow: hidden;
  background: #050302;
}

body.cp-mode-play .cp-wrap {
  max-width: none;
  margin: 0;
  padding: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

body.cp-mode-play .cp-playfield {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

body.cp-mode-play .cp-stage {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  aspect-ratio: auto;
  height: auto;
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-top: none;
  /* Letterbox 16:9 canvas — never stretch */
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

body.cp-mode-play .cp-stage canvas {
  width: auto !important;
  height: auto !important;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  image-rendering: auto;
}

body.cp-mode-play .cp-touch:not([hidden]) {
  display: flex;
  flex: 0 0 auto;
  margin-top: 0;
  border-radius: 0;
  min-height: calc(72px + env(safe-area-inset-bottom, 0px));
  padding: 0.55rem 0.75rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
}

body.cp-mode-play .cp-touch button {
  min-width: 88px;
  min-height: 60px;
  font-size: 0.8rem;
}

body.cp-mode-play .cp-btn-duck {
  min-width: 110px !important;
}

body.cp-mode-play .cp-hud {
  font-size: 0.85rem;
  padding: 0.65rem 0.85rem;
}

/* Portrait while playing → rotate gate (controls stay hidden until landscape) */
@media (orientation: portrait) {
  body.cp-mode-play .cp-playfield {
    visibility: hidden;
    pointer-events: none;
  }
  body.cp-mode-play #cp-rotate:not([hidden]) {
    display: flex !important;
  }
}

@media (orientation: landscape) {
  body.cp-mode-play #cp-rotate {
    display: none !important;
  }
  body.cp-mode-play .cp-playfield {
    visibility: visible;
    pointer-events: auto;
  }

  /* Side rails on wide landscape: stage center, pads in the margins feel */
  body.cp-mode-play .cp-touch {
    justify-content: space-between;
    gap: 1rem;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }
}

/* Menu: readable on phones (zoom allowed via viewport) */
@media (max-width: 640px) {
  .cp-wrap {
    padding-left: max(0.85rem, env(safe-area-inset-left));
    padding-right: max(0.85rem, env(safe-area-inset-right));
  }
  .cp-wrap h1 { font-size: 1.55rem; }
  .cp-lede { font-size: 1rem; }
  .cp-card p { font-size: 1.05rem; }
  .cp-card-stamp { font-size: 0.75rem; }
  .cp-help { font-size: 0.78rem; line-height: 1.45; }
}

@media (pointer: coarse) {
  .cp-help kbd { display: none; }
}
