/* CHAPTER MECHANICS (js/chapters/) — overlays for Ch3 market cycles and Ch4 Dev boss.
   Dark AAA style like the market HUD: dark glass, Michroma / Oswald / Archivo Black. */

.chx-host { position: relative; }

.chx-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  overflow: hidden;
}

.chx-layer > * {
  position: absolute;
  left: calc(var(--c) * var(--cell));
  top: calc(var(--r) * var(--cell));
  width: calc(var(--w, 1) * var(--cell));
  height: calc(var(--h, 1) * var(--cell));
  display: block;
}

/* ---------- page tint behind the stage ---------- */

.chx-bg {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  transition: background 1.2s ease, opacity 1.2s ease;
}

body.chx-bull .chx-bg { background: radial-gradient(ellipse at 50% 110%, rgba(47, 224, 122, 0.22), transparent 65%); }
body.chx-bear .chx-bg { background: radial-gradient(ellipse at 50% 110%, rgba(255, 59, 74, 0.3), transparent 65%), rgba(40, 0, 6, 0.35); }
.chx-bg4 { background: radial-gradient(ellipse at 50% 40%, rgba(120, 50, 220, 0.18), transparent 70%); }

/* ---------- mechanic HUD panel ---------- */

.chx-hud {
  position: fixed;
  z-index: 15;
  width: 220px;
  padding: 10px 12px 12px;
  font-family: "Michroma", "Eurostile", Arial, sans-serif;
  color: #e9f3ee;
  background: linear-gradient(90deg, rgba(8, 12, 16, 0.86), rgba(8, 12, 16, 0.6));
  border-left: 3px solid var(--pump, #2fe07a);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  user-select: none;
  -webkit-user-select: none;
  animation: chx-hud-in 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  transition: border-color 0.6s ease;
}

.chx-hud[hidden] { display: none; }
.chx-hud.bear, .chx-hud4 { border-left-color: var(--dump, #ff3b4a); }
.chx-hud4.enraged { animation: chx-hud-in 0.6s both, chx-rage 1.2s ease-in-out infinite; }
@keyframes chx-hud-in { from { transform: translateY(-12px); opacity: 0; } }
@keyframes chx-rage { 50% { box-shadow: 0 0 28px rgba(255, 59, 74, 0.45); } }

.chx-hud-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 10px;
  letter-spacing: 0.16em;
  margin-bottom: 6px;
}

.chx-hud-kick { color: var(--gold, #ffd21a); }
.chx-hud-state { font-family: "Oswald", sans-serif; font-weight: 700; font-size: 12px; letter-spacing: 0.06em; }
.chx-hud-state.up { color: var(--pump, #2fe07a); }
.chx-hud-state.down { color: var(--dump, #ff3b4a); }

.chx-phase { display: flex; justify-content: space-between; align-items: baseline; }
.chx-phase-name { font-family: "Archivo Black", "Arial Black", sans-serif; font-weight: 400; font-size: 18px; color: var(--pump, #2fe07a); }
.chx-hud.bear .chx-phase-name { color: var(--dump, #ff3b4a); }
.chx-phase-time { font-family: "Oswald", sans-serif; font-weight: 700; font-size: 18px; }

.chx-meter, .chx-hp {
  position: relative;
  height: 8px;
  margin: 6px 0 4px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.chx-meter i, .chx-hp i {
  position: absolute;
  inset: 0;
  transform-origin: left;
  background: var(--pump, #2fe07a);
  transition: transform 0.25s linear;
}

.chx-hud.bear .chx-meter i { background: var(--dump, #ff3b4a); }
.chx-note { font-family: "Oswald", sans-serif; font-size: 12px; letter-spacing: 0.04em; color: #9fb3a8; }

.chx-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  border: 0;
  cursor: pointer;
  font-family: "Archivo Black", "Arial Black", sans-serif;
  font-size: 14px;
  letter-spacing: 0.04em;
  color: #04150b;
  background: var(--pump, #2fe07a);
  box-shadow: 0 0 18px rgba(47, 224, 122, 0.45);
  animation: chx-pulse 1s ease-in-out infinite;
}

.chx-btn small { font-family: "Oswald", sans-serif; font-size: 11px; opacity: 0.75; margin-left: 4px; }
.chx-btn[hidden] { display: none; }
.chx-btn:hover { filter: brightness(1.12); }
@keyframes chx-pulse { 50% { box-shadow: 0 0 30px rgba(47, 224, 122, 0.8); } }

/* phones / narrow windows: one compact line (under the market strip on phones) */
.chx-hud.strip { display: flex; align-items: center; height: 32px; padding: 3px 8px; animation: none; }
.chx-hud.strip .chx-hud-head, .chx-hud.strip .chx-note, .chx-hud.strip .chx-boss-name { display: none; }
.chx-hud.strip .chx-hud-body { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.chx-hud.strip .chx-phase { flex: none; gap: 6px; }
.chx-hud.strip .chx-phase-name, .chx-hud.strip .chx-phase-time { font-size: 13px; }
.chx-hud.strip .chx-meter { flex: 1; margin: 0; height: 6px; }
.chx-hud.strip .chx-btn { flex: none; width: auto; margin: 0; padding: 4px 8px; font-size: 11px; }
.chx-hud.strip .chx-btn small { display: none; }
.chx-hud.strip .chx-boss { flex: 1; gap: 8px; }
.chx-hud.strip .chx-dev { width: 26px; height: 26px; }
.chx-hud.strip .chx-hp { margin: 0; height: 16px; }

@media (max-width: 979px) {
  body.chx-on.market-on .stage { padding-top: max(136px, calc(env(safe-area-inset-top) + 128px)); }
}

/* ---------- Ch3: candles + covers ---------- */

.chx-layer .chx-candle {
  background: url("../images/arcade/candle-green.webp") center / 160% no-repeat;
  animation: chx-candle 0.65s cubic-bezier(0.3, 0.7, 0.4, 1) both;
  filter: drop-shadow(0 0 6px rgba(47, 224, 122, 0.9));
}

@keyframes chx-candle {
  0% { transform: translateY(-260%) scale(0.6); opacity: 0; }
  60% { transform: translateY(0) scale(1.3); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}

.chx-layer .chx-redwave {
  background: linear-gradient(180deg, transparent, rgba(255, 59, 74, 0.85) 40%, rgba(255, 59, 74, 0.2));
  animation: chx-wave 0.7s ease-in both;
  mix-blend-mode: screen;
}

@keyframes chx-wave {
  from { transform: translateY(-100%); opacity: 1; }
  to { transform: translateY(100%); opacity: 0; }
}

/* A covered tile: raised like a closed tile, with a red candle body on it. */
.chx-layer .chx-cov {
  background:
    linear-gradient(90deg, transparent 44%, #5a0d14 44% 56%, transparent 56%) center / 100% 100% no-repeat,
    linear-gradient(180deg, transparent 22%, #ff3b4a 22% 78%, transparent 78%) center / 50% 100% no-repeat,
    #3a0a10;
  box-shadow: inset 2px 2px 0 rgba(255, 140, 150, 0.45), inset -2px -2px 0 rgba(0, 0, 0, 0.55);
  animation: chx-cov-in 0.35s ease-out both;
}

.chx-layer .chx-cov.gone { animation: chx-cov-out 0.4s ease-in both; }
@keyframes chx-cov-in { from { transform: translateY(-40%); opacity: 0; } }
@keyframes chx-cov-out { to { transform: scale(0.4); opacity: 0; } }

/* ---------- Ch4: the Dev ---------- */

.chx-boss { display: flex; gap: 10px; align-items: center; }
.chx-dev { width: 64px; height: 64px; flex: none; filter: drop-shadow(0 0 10px rgba(153, 69, 255, 0.6)); }
.chx-boss-info { flex: 1; min-width: 0; }
.chx-boss-name { font-family: "Archivo Black", "Arial Black", sans-serif; font-size: 15px; }
.chx-boss-name small { display: block; font-family: "Oswald", sans-serif; font-size: 10px; letter-spacing: 0.08em; color: #9fb3a8; }
.chx-hp { height: 14px; }
.chx-hp i { background: linear-gradient(90deg, #ff3b4a, #ff7a3b); }
.chx-hp span { position: absolute; inset: 0; display: grid; place-items: center; font-family: "Oswald", sans-serif; font-weight: 700; font-size: 10px; text-shadow: 0 1px 0 #000; }
.chx-hud.strip .chx-dev { width: 40px; height: 40px; }
.chx-hud.strip .chx-boss-name small { display: none; }

.chx-layer .chx-blanket {
  /* the rug body of the sprite (x 26–229, y 100–237 of 256) stretched over the whole 4×4 */
  background: url("../images/arcade/rug.webp") 49% 84% / 126% 187% no-repeat, #5b21b6;
  border-radius: 3px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), inset 0 0 0 2px rgba(153, 69, 255, 0.8);
  animation: chx-blanket-in 0.5s cubic-bezier(0.4, 1.6, 0.5, 1) both;
}

.chx-layer .chx-blanket.gone { animation: chx-blanket-out 0.45s ease-in both; }
@keyframes chx-blanket-in { from { transform: translateY(-120%) rotate(-14deg) scale(1.3); opacity: 0; } }
@keyframes chx-blanket-out { to { transform: translate(40%, -60%) rotate(18deg); opacity: 0; } }

/* ---------- intro card ---------- */

.chx-card {
  position: fixed;
  inset: 0;
  z-index: 46;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.55);
  animation: chx-fade 0.3s ease both;
}

.chx-card.out { animation: chx-fade 0.3s ease reverse both; pointer-events: none; }
@keyframes chx-fade { from { opacity: 0; } }

.chx-card-box {
  position: relative;
  width: min(520px, 100%);
  padding: 26px 26px 22px 120px;
  color: #e9f3ee;
  background: linear-gradient(90deg, rgba(8, 12, 16, 0.95), rgba(14, 18, 24, 0.88));
  border-left: 4px solid var(--gold, #ffd21a);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  animation: chx-card-in 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

@keyframes chx-card-in { from { transform: translateY(24px) scale(0.96); opacity: 0; } }

.chx-card-art { position: absolute; left: 14px; top: 20px; width: 92px; height: 92px; }
.chx-card-kick { font-family: "Michroma", Arial, sans-serif; font-size: 11px; letter-spacing: 0.2em; color: var(--gold, #ffd21a); }
.chx-card-head { margin-top: 8px; font-family: "Archivo Black", "Arial Black", sans-serif; font-size: 22px; line-height: 1.15; }
.chx-card-sub { margin-top: 10px; font-family: "Oswald", sans-serif; font-size: 15px; line-height: 1.35; color: #b9c8c0; }
.chx-card-sub b { color: var(--pump, #2fe07a); }

.chx-card-ok {
  margin-top: 16px;
  padding: 8px 22px;
  border: 0;
  cursor: pointer;
  font-family: "Archivo Black", "Arial Black", sans-serif;
  font-size: 14px;
  color: #111;
  background: var(--gold, #ffd21a);
}

@media (max-width: 560px) {
  .chx-card-box { padding: 92px 18px 18px; }
  .chx-card-art { left: 50%; top: 10px; width: 76px; height: 76px; transform: translateX(-50%); }
  .chx-card-head { font-size: 19px; }
}

/* ---------- callouts ---------- */

.chx-callout {
  position: fixed;
  left: 50%;
  top: 30%;
  z-index: 26;
  transform: translateX(-50%);
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  animation: chx-call 2.4s ease forwards;
}

.chx-callout b { display: block; font-family: "Archivo Black", "Arial Black", sans-serif; font-weight: 400; font-size: clamp(28px, 6vw, 60px); text-shadow: 0 3px 0 #000, 0 0 24px currentColor; }
.chx-callout span { display: inline-block; margin-top: 6px; padding: 4px 12px; font-family: "Michroma", Arial, sans-serif; font-size: clamp(10px, 1.6vw, 13px); letter-spacing: 0.18em; color: #fff; background: rgba(0, 0, 0, 0.6); }
.chx-callout.up { color: var(--pump, #2fe07a); }
.chx-callout.down { color: var(--dump, #ff3b4a); }
.chx-callout.gold { color: var(--gold, #ffd21a); }

@keyframes chx-call {
  0% { opacity: 0; transform: translateX(-50%) scale(1.6); }
  10% { opacity: 1; transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-20px); }
}

/* ---------- Ch4 win cutscene ---------- */

.chx-cut {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(60, 18, 110, 0.75), rgba(0, 0, 0, 0.92));
  animation: chx-fade 0.4s ease both;
  overflow: hidden;
}

.chx-cut.out { animation: chx-fade 0.5s ease reverse both; }
.chx-boom { position: absolute; left: 50%; top: 45%; width: 0; height: 0; }
.chx-boom img { position: absolute; left: 0; top: 0; width: 12vmin; height: 12vmin; }
.chx-dazed { width: min(42vmin, 300px); animation: chx-dazed 0.9s ease-in-out infinite alternate; filter: drop-shadow(0 0 30px rgba(153, 69, 255, 0.8)); }
@keyframes chx-dazed { from { transform: rotate(-5deg); } to { transform: rotate(5deg) translateY(-6px); } }
.chx-cut-title { font-family: "Archivo Black", "Arial Black", sans-serif; font-size: clamp(26px, 6vw, 64px); color: var(--gold, #ffd21a); text-align: center; text-shadow: 0 4px 0 #000, 0 0 30px rgba(255, 200, 0, 0.5); padding: 0 16px; animation: chx-call-in 0.6s 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
.chx-cut-sub { font-family: "Michroma", Arial, sans-serif; font-size: clamp(10px, 1.8vw, 14px); letter-spacing: 0.18em; color: #e9f3ee; text-align: center; padding: 0 16px; animation: chx-fade 0.6s 0.9s both; }
@keyframes chx-call-in { from { transform: scale(2); opacity: 0; } }
