/* ============================================================
   ETCRAFT — Minecraft mechanic: redstone lever, page-wide
   redstone dust + lamps, flying bat, advancement toasts.
   Mechanic ported from the reference sample; the art is the
   real Minecraft texture pack it uses.
   ============================================================ */

/* ---------- Advancement toasts ---------- */
#advStack {
  position: fixed;
  top: 5.6rem;
  left: 50%;
  z-index: 9999;
  display: flex;
  width: max-content;
  max-width: calc(100vw - 32px);
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
  pointer-events: none;
}
.mc-adv {
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 380px;
  max-width: 480px;
  max-height: 260px;
  margin-top: 12px;
  overflow: hidden;
  padding: 18px 28px 18px 20px;
  border: 1px solid rgba(255, 215, 90, 0.32);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(26, 22, 38, 0.98), rgba(12, 10, 18, 0.98));
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.62), inset 0 0 0 1px rgba(255, 215, 90, 0.1),
    inset 2px 2px 0 rgba(255, 255, 255, 0.06);
  opacity: 0;
  transform: translateY(-26px);
  transition: transform 0.45s cubic-bezier(0.34, 1.45, 0.64, 1), opacity 0.3s,
    max-height 0.34s ease-in, padding 0.34s ease-in, border-width 0.34s ease-in,
    margin-top 0.34s ease-in;
}
.mc-adv.in {
  opacity: 1;
  transform: translateY(0);
}
/* Viền sáng chạy ngang trên đỉnh: "có phần thưởng" là khoảnh khắc phải được
   đánh dấu, còn chiếc thẻ thì vẫn đứng nguyên chỗ cũ. */
.mc-adv::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255, 215, 90, 0.9), transparent);
  transform: scaleX(0);
  transform-origin: 50% 0;
  pointer-events: none;
}
/* Ánh kim quét một lần qua mặt thẻ. Chỉ dùng transform nên không tốn repaint. */
.mc-adv::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    transparent 18%,
    rgba(255, 215, 90, 0.2) 42%,
    rgba(255, 255, 255, 0.14) 50%,
    transparent 74%
  );
  transform: translateX(-120%);
  pointer-events: none;
}
.mc-adv.in::before {
  animation: advRule 620ms cubic-bezier(0.22, 0.61, 0.36, 1) 140ms forwards;
}
.mc-adv.in::after {
  animation: advSheen 900ms cubic-bezier(0.22, 0.61, 0.36, 1) 300ms both;
}
@keyframes advRule {
  to {
    transform: scaleX(1);
  }
}
@keyframes advSheen {
  from {
    transform: translateX(-120%);
  }
  to {
    transform: translateX(120%);
  }
}
/* Chiết lui: mờ dần rồi mới co lại, để hai chiếc phía dưới trôi lên mượt thay
   vì bị giật lên khi chiếc trên cùng biến mất khỏi layout. */
.mc-adv.out {
  opacity: 0;
  transform: translateY(-26px);
  max-height: 0;
  margin-top: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-top-width: 0;
  border-bottom-width: 0;
  transition: transform 0.3s ease-in, opacity 0.22s, margin-top 0.3s 0.26s ease-in,
    max-height 0.3s 0.26s ease-in, padding 0.3s 0.26s ease-in, border-width 0.3s 0.26s ease-in;
}
.mc-adv-ico {
  flex: none;
  width: 58px;
  height: 58px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
  /* Hai animation trên hai property độc lập (scale/rotate và translate) để
     chiếc nhảy vào rồi thở, thay vì phải viết chồng lên nhau trong `transform`. */
  animation: advIconPop 440ms cubic-bezier(0.34, 1.56, 0.64, 1) both,
    advIconBob 2.6s ease-in-out 0.9s infinite;
}
@keyframes advIconPop {
  0% {
    scale: 0.28;
    rotate: -16deg;
    opacity: 0;
  }
  70% {
    scale: 1.14;
    rotate: 4deg;
    opacity: 1;
  }
  100% {
    scale: 1;
    rotate: 0deg;
  }
}
@keyframes advIconBob {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -3px;
  }
}
.mc-adv-eyebrow {
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #ffcf3f;
  animation: advRise 380ms cubic-bezier(0.22, 0.61, 0.36, 1) 80ms both;
}
.mc-adv-title {
  font-size: 19px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: #fff;
  animation: advRise 380ms cubic-bezier(0.22, 0.61, 0.36, 1) 150ms both;
}
.mc-adv-desc {
  margin-top: 5px;
  font-size: 12.5px;
  font-style: italic;
  line-height: 1.3;
  color: var(--muted);
  animation: advRise 380ms cubic-bezier(0.22, 0.61, 0.36, 1) 230ms both;
}
/* Chữ đi lên theo từng dòng thay vì cả khối cùng lúc — chiếc toast đọc được
   như một thông báo vừa mở, không phải một tấm ảnh dán vào. */
@keyframes advRise {
  from {
    opacity: 0;
    translate: 0 7px;
  }
  to {
    opacity: 1;
    translate: 0 0;
  }
}
@media (max-width: 520px) {
  #advStack {
    max-width: calc(100vw - 20px);
  }
  .mc-adv {
    min-width: 0;
    gap: 12px;
    padding: 14px 18px 14px 14px;
  }
  .mc-adv-ico {
    width: 44px;
    height: 44px;
  }
}

/* ---------- Redstone lever (two real textures, swapped by state) ---------- */
.rs-lever {
  position: absolute;
  right: clamp(0.9rem, 3vw, 2.4rem);
  /* keep it above the fold even when the banner is taller than the screen;
     the banner starts under the 64px fixed header, so that offset is included */
  bottom: max(clamp(1rem, 4vh, 2.6rem), calc(100% - 100vh + 9rem));
  z-index: 60;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.6));
  transition: filter 0.15s;
}
.rs-lever--docked {
  position: fixed;
  right: 1.1rem;
  bottom: 1.2rem;
  z-index: 9990;
}
.rs-lever[data-state="off"] .lever-on,
.rs-lever[data-state="on"] .lever-off {
  display: none;
}
.lever-img {
  display: block;
  width: auto;
  height: 88px;
  transform-origin: bottom center;
}
/* idle wiggle to draw the eye toward the lever (stops once used) */
@keyframes leverWiggle {
  0%,
  82%,
  100% {
    transform: rotate(0);
  }
  88% {
    transform: rotate(-8deg);
  }
  94% {
    transform: rotate(5deg);
  }
}
.rs-lever:not(.used) .lever-img {
  animation: leverWiggle 3.6s ease-in-out infinite;
}
/* Hai texture cần gạt chỉ khác nhau mỗi tí một, nên cú gạt nếu đổi ảnh trần sẽ
   trông như nhảy hình. Một nhịp quay quá đà ngắn biến nó thành thao tác vật lý.
   `rotate` là property riêng nên không đụng transform-origin của ảnh Wiggle. */
@keyframes leverThrow {
  0% {
    rotate: -10deg;
  }
  55% {
    rotate: 6deg;
  }
  100% {
    rotate: 0deg;
  }
}
.rs-lever.thrown .lever-img,
.rs-lever-cover.thrown {
  animation: leverThrow 300ms cubic-bezier(0.3, 1.5, 0.5, 1);
}
/* page-absolute copy of the lever, painted above the wire so the dust looks
   like it grows out of the lever instead of out of thin air */
.rs-lever-cover {
  position: absolute;
  top: 0;
  left: 0;
  display: none;
  z-index: 52;
  pointer-events: none;
  transform-origin: bottom center;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.6));
}

/* ---------- Redstone overlay + lamps ---------- */
/* absolute + a translateY(scrollY) nudge rather than `fixed`: the explosion
   shakes the page by transforming <body>, and a transform on <body> turns it
   into the containing block for fixed descendants — the dust would snap to the
   top of the document for the half second of the shake. */
#rsOverlay {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 49;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s;
}
/* will-change chỉ khi mạch đang sáng: một lớp phủ to bằng viewport được
   thăng hạng thường trực thì tốn bộ nhớ ngay cả lúc nó đang mờ bằng 0. */
#rsOverlay.active {
  will-change: opacity, transform;
  animation: rsPulse 2.8s ease-in-out infinite;
}
@keyframes rsPulse {
  0%,
  100% {
    opacity: 0.88;
  }
  50% {
    opacity: 1;
  }
}
.rs-lamp-abs {
  position: absolute;
  z-index: 50;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: auto;
  cursor: pointer;
  transition: transform 0.09s ease-out;
}
/* The glow is painted once and only its opacity breathes: an animated
   `filter` re-rasterises every lamp on every frame, which is what made the
   whole page shimmer while the circuit was live. */
.rs-lamp-abs.lit {
  filter: drop-shadow(0 0 16px rgba(255, 140, 20, 0.8)) drop-shadow(0 0 6px rgba(255, 210, 80, 0.6));
  animation: lampIgnite 340ms ease-out, rsLampGlow 2.8s ease-in-out var(--gd, 0.34s) infinite;
}
@keyframes lampIgnite {
  0% {
    scale: 0.8;
    opacity: 0.55;
  }
  55% {
    scale: 1.16;
    opacity: 1;
  }
  100% {
    scale: 1;
  }
}
@keyframes rsLampGlow {
  0%,
  100% {
    opacity: 0.84;
  }
  50% {
    opacity: 1;
  }
}
/* Đèn đứt bóng: một cái giật rồi sập, để cú bấm cuối có hậu quả nhìn thấy được
   chứ không chỉ đổi ảnh và mất màu. */
.rs-lamp-abs.burnt {
  animation: lampBurnt 340ms ease-out;
}
@keyframes lampBurnt {
  0% {
    rotate: 0deg;
  }
  18% {
    rotate: -8deg;
  }
  42% {
    rotate: 7deg;
  }
  68% {
    rotate: -4deg;
  }
  100% {
    rotate: 0deg;
  }
}

/* ---------- Explosion screen shake ---------- */
@keyframes rsShake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  15% {
    transform: translate(-7px, 4px);
  }
  30% {
    transform: translate(6px, -5px);
  }
  45% {
    transform: translate(-5px, -4px);
  }
  60% {
    transform: translate(5px, 5px);
  }
  75% {
    transform: translate(-4px, 3px);
  }
  90% {
    transform: translate(3px, -3px);
  }
}
body.rs-shake {
  animation: rsShake 0.5s ease-in-out;
}

/* ---------- Flying bat (real MC animation) ---------- */
.site-bat {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9997;
  width: 54px;
  height: auto;
  cursor: pointer;
  pointer-events: auto;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
  will-change: transform;
}

/* ---------- Gutter models ---------- */
/* Absolute in the document (not fixed) so they read as furniture of the page:
   they scroll with their section instead of hovering over the text. */
.mc-model {
  position: absolute;
  z-index: 48;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  animation: mcFloat 5.4s ease-in-out infinite;
}
.mc-model img {
  display: block;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
  transition: opacity 0.18s ease-out, transform 0.18s ease-out;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
}
/* Phản hồi khi rê vào: khối nhấc lên một tí. Viết trước .pop để cú chạm vẫn là
   thứ thắng thế — hai rule cùng độ đặc hiệu, nguồn sau quyết định. */
.mc-model:hover img {
  transform: translateY(-4px) scale(1.06);
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.55));
}
.mc-model.pop img {
  transform: scale(1.16);
}
/* The halo is painted once and only its opacity breathes: animating `filter`
   re-rasterises the block every frame and made the whole column shimmer. */
.mc-model--glow::before,
.mc-model--egg::before {
  content: "";
  position: absolute;
  /* inset thay vì left/top + translate(-50%,-50%): giữ nguyên -70% mỗi cạnh
     cho cùng một vị trí nhưng giải phóng `scale`, để quầng sáng co giãn đúng
     tâm thay vì bị dịch đi khi nhân ma trận transform. */
  inset: -70%;
  border-radius: 50%;
  pointer-events: none;
  animation: mcHaloBreathe 4.6s ease-in-out infinite;
  animation-delay: var(--hd, 0s);
}
.mc-model--glow::before {
  background: radial-gradient(circle, rgb(var(--brand-rgb) / 0.3) 0%, rgb(var(--brand-rgb) / 0.1) 34%, transparent 68%);
}
.mc-model--egg::before {
  background: radial-gradient(circle, rgb(var(--accent-rgb) / 0.22) 0%, transparent 62%);
}
.mc-model--glow img {
  filter: drop-shadow(0 0 12px rgb(var(--brand-rgb) / 0.5)) drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
}
.mc-model--egg img {
  filter: drop-shadow(0 0 8px rgb(var(--accent-rgb) / 0.4)) drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
}
.mc-model--shelf {
  animation-duration: 6.6s;
}
.mc-model--egg {
  animation-duration: 4.6s;
}
.mc-model--egg.gone img {
  opacity: 0;
  transform: scale(0.4) rotate(22deg);
  transition-duration: 0.13s;
  transition-timing-function: cubic-bezier(0.5, 0, 0.75, 0.35);
}
/*Hiện về: nhảy vào có dội một nhịp, kèm vòng sóng tím lan ra — chất dịch
  chuyển của enderman, chứ không phải một khối bỗng hiện lên chỗ trống. */
.mc-model--egg.arrive img {
  animation: mcEggArrive 360ms cubic-bezier(0.22, 1.2, 0.36, 1);
}
.mc-model--egg::after {
  content: "";
  position: absolute;
  inset: 6%;
  border: 2px solid rgb(var(--accent-rgb) / 0.55);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}
.mc-model--egg.arrive::after {
  animation: mcEggRing 520ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
@keyframes mcEggArrive {
  0% {
    scale: 0.45;
    opacity: 0;
  }
  60% {
    opacity: 1;
  }
  100% {
    scale: 1;
  }
}
@keyframes mcEggRing {
  0% {
    opacity: 0.85;
    scale: 0.4;
  }
  100% {
    opacity: 0;
    scale: 1.9;
  }
}
/* Lơ lửng thành đường số 8 nhỏ thay vì lên-xuống thẳng: hai trục chạm nhau ở
   các mốc khác nhau nên năm khối lề trang không còn gật gù cùng một nhịp. */
@keyframes mcFloat {
  0% {
    transform: translateY(0) rotate(0deg);
  }
  30% {
    transform: translateY(-9px) rotate(1.3deg);
  }
  50% {
    transform: translateY(-6px) rotate(0deg);
  }
  70% {
    transform: translateY(-9px) rotate(-1.3deg);
  }
  100% {
    transform: translateY(0) rotate(0deg);
  }
}
@keyframes mcHaloBreathe {
  0%,
  100% {
    opacity: 0.45;
    scale: 0.9;
  }
  50% {
    opacity: 1;
    scale: 1.06;
  }
}
.mc-model--shelf .book {
  position: absolute;
  top: -30%;
  left: 50%;
  margin-left: -25%;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.45));
  animation: mcBookDrift 13s ease-in-out infinite alternate;
}
/* One keyframe set carries both the side-to-side patrol and the float, because
   two animations writing `transform` on the same element would fight. */
@keyframes mcBookDrift {
  0% {
    transform: translate(-20px, 0) rotate(-3deg);
  }
  20% {
    transform: translate(-8px, -7px) rotate(2deg);
  }
  45% {
    transform: translate(9px, 2px) rotate(-2deg);
  }
  70% {
    transform: translate(20px, -6px) rotate(3deg);
  }
  100% {
    transform: translate(6px, 3px) rotate(-1deg);
  }
}
/* Cuốn sách nghiêng theo hướng bay: tự nó lật nhẹ chứ không trượt như một tấm
   sticker trên kính. */
.mc-model--shelf .book {
  transform-origin: 50% 50%;
}
/* Ngoài màn hình thì nghỉ: năm kệ hàng + quầng sáng + đèn đá đỏ đang chạy
   animation vô hạn, và trình duyệt vẫn composite chúng dù chẳng ai nhìn thấy. */
.mc-model.idle,
.mc-model.idle img,
.mc-model.idle .book,
.mc-model.idle::before,
.rs-lamp-abs.idle,
/* Dải tin ở đầu Trang chủ chạy 55 giây một vòng, vô hạn: cuộn xuống dưới là nó
   vẫn composite nguyên dải chữ dài gấp đôi màn hình dù đã khuất hẳn. */
.ticker-track.idle {
  /* !important: các rule khai báo animation (`.mc-model--shelf .book`…) ngang hoặc cao hơn
     độ ưu tiên này và đứng sau nó, nên kiểu khai báo trần chỉ đặt lại play-state về running. */
  animation-play-state: paused !important;
}
/* No gutter below the width the models were placed for. */
@media (max-width: 1359px) {
  .mc-model {
    display: none !important;
  }
}

/* ---------- Redstone mode dressing ---------- */
html[data-redstone="on"] body::before {
  background: radial-gradient(120% 80% at 12% -10%, rgb(var(--brand-rgb) / 0.14) 0%, transparent 58%),
    radial-gradient(90% 70% at 92% 4%, rgb(var(--sky-rgb) / 0.1) 0%, transparent 55%),
    linear-gradient(180deg, rgb(var(--brand-rgb) / 0.06) 0%, transparent 26%, var(--ink) 86%);
}
/* Redstone is a wide-screen flourish only: the wire routes through the outer
   margins, so it needs room outside the content column. */
@media (max-width: 900px) {
  .rs-lever,
  .rs-lever-cover,
  #rsOverlay,
  .rs-lamp-abs {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mc-adv,
  .mc-adv.in {
    transform: none;
    transition: opacity 0.2s linear;
  }
  /* toast vẫn xuất hiện, chỉ bỏ hết chuyển động: không quét ánh kim, không kẻ
     viền sáng, chữ không bay lên. */
  .mc-adv.in::before,
  .mc-adv.in::after {
    animation: none;
  }
  .mc-adv-ico,
  .mc-adv-eyebrow,
  .mc-adv-title,
  .mc-adv-desc {
    animation: none;
  }
  .rs-lever:not(.used) .lever-img,
  .rs-lever.thrown .lever-img,
  .rs-lever-cover.thrown,
  .rs-lamp-abs.lit,
  .rs-lamp-abs.burnt,
  #rsOverlay.active,
  .mc-model,
  .mc-model--glow::before,
  .mc-model--egg::before,
  .mc-model--shelf .book,
  .mc-model--egg.arrive img,
  .mc-model--egg.arrive::after,
  body.rs-shake {
    animation: none;
  }
  .mc-model,
  .mc-model img {
    transition: none;
  }
  .mc-model:hover img {
    transform: none;
  }
}
