/* Living World: shared materials and motion for every page.
   Values come from brand/tokens.json (world section); check-tokens.mjs keeps them in sync. */
:root {
  --sky-day-top: #6fb7ff;
  --sky-day-bottom: #cfe8ff;
  --sky-dusk-top: #3b2a5c;
  --sky-dusk-bottom: #f28a5b;
  --sky-night-top: #050913;
  --sky-night-bottom: #13203a;
  --grass: #5fa83a;
  --dirt: #8a5a32;
  --stone: #7d828c;
  --lava: #f2701d;
  --diamond: #4fd8e0;
  --emerald: #2fbf71;
  --torch: #ffcf6b;
  --gravel: #9a9a92;
  --gravel-dark: #6f6f69;
  --lava-dark: #8a3a14;
  --void: #3a4256;
  --void-dark: #2a3142;
  --cloud: #e8eef6;
  --cloud-rain: #7f8796;
  --cloud-storm: #3a3f4d;
  --led-green: #4ade80;
  --led-amber: #f59e0b;
  --t-fast: 160ms;
  --t-base: 280ms;
  --t-slow: 400ms;
  --ease-snap: cubic-bezier(.2,.9,.2,1.2);
  --ease-out: cubic-bezier(.16,1,.3,1);
  --pixel: 4px;
}

/* The living sky sits behind everything. Pages keep their own backgrounds transparent over it. */
.sky {
  position: fixed; inset: 0; z-index: -1;
  width: 100vw; height: 100vh;
  pointer-events: none;
  image-rendering: pixelated;
  background: linear-gradient(var(--sky-night-top), var(--sky-night-bottom));
}
:root[data-theme="light"] .sky { background: linear-gradient(var(--sky-day-top), var(--sky-day-bottom)); }
/* html keeps the theme colour (dark-mode extensions read it); the sky paints above it, behind the body. */
html.has-sky { background: var(--bg); }
html.has-sky body { background: transparent; }

/* Text over the sky always sits on a scrim. */
.scrim {
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  backdrop-filter: blur(10px) saturate(1.2);
}

/* Canvas overlays used by build-in, mine-out and XP. */
.voxel-layer {
  position: fixed; left: 0; top: 0; z-index: 60;
  pointer-events: none;
  image-rendering: pixelated;
}

/* Torch: a warm pixel light that follows a fine pointer. */
.torch {
  position: fixed; left: 0; top: 0; z-index: 1;
  width: 360px; height: 360px; margin: -180px 0 0 -180px;
  pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--torch) 14%, transparent), transparent);
  mix-blend-mode: screen;
  opacity: 0; transition: opacity var(--t-base) var(--ease-out);
  will-change: transform;
}
:root[data-theme="light"] .torch { mix-blend-mode: soft-light; }
.torch.on { opacity: 1; }

/* Mine-out crack stages: pixel cracks drawn as a stepped mask over the element. */
.crack-1, .crack-2, .crack-3 { position: relative; }
.crack-1::after, .crack-2::after, .crack-3::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background:
    linear-gradient(45deg, transparent 46%, rgba(0,0,0,.45) 46% 54%, transparent 54%) 30% 40% / 24px 24px no-repeat,
    linear-gradient(-45deg, transparent 46%, rgba(0,0,0,.45) 46% 54%, transparent 54%) 62% 58% / 20px 20px no-repeat;
  image-rendering: pixelated;
}
.crack-2::after { background-size: 40px 40px, 36px 36px; }
.crack-3::after {
  background:
    linear-gradient(45deg, transparent 46%, rgba(0,0,0,.5) 46% 54%, transparent 54%) 30% 40% / 56px 56px no-repeat,
    linear-gradient(-45deg, transparent 46%, rgba(0,0,0,.5) 46% 54%, transparent 54%) 62% 58% / 52px 52px no-repeat,
    linear-gradient(10deg, transparent 47%, rgba(0,0,0,.4) 47% 53%, transparent 53%) 80% 20% / 40px 40px no-repeat;
}

/* Build-in: the element waits under the voxels, then settles. */
.building { opacity: 0; transform: translateY(6px) scale(.985); }
.built { opacity: 1; transform: none; transition: opacity var(--t-base) var(--ease-out), transform var(--t-slow) var(--ease-snap); }

/* Chunk load: the new view appears as square chunks growing in a 64px grid, in blocky steps. */
@property --chunk { syntax: '<percentage>'; inherits: false; initial-value: 0%; }
@keyframes btw-chunk { from { --chunk: 0%; } to { --chunk: 101%; } }
@keyframes btw-hold { from { opacity: 1; } to { opacity: 1; } }
/* Page-to-page (every page opts in, so site <-> panel moves transition too) and panel view swaps (.chunk-in). */
@view-transition { navigation: auto; }
@media (prefers-reduced-motion: reduce) { @view-transition { navigation: none; } }
html:not(.vt-theme)::view-transition-old(root) { animation: btw-hold var(--t-slow) linear both; }
html:not(.vt-theme)::view-transition-new(root),
.chunk-in {
  animation: btw-chunk var(--t-slow) steps(6, end) both;
  --edge-a: calc(50% - var(--chunk) / 2);
  --edge-b: calc(50% + var(--chunk) / 2);
  -webkit-mask-image:
    linear-gradient(to right, transparent var(--edge-a), #000 var(--edge-a) var(--edge-b), transparent var(--edge-b)),
    linear-gradient(to bottom, transparent var(--edge-a), #000 var(--edge-a) var(--edge-b), transparent var(--edge-b));
  mask-image:
    linear-gradient(to right, transparent var(--edge-a), #000 var(--edge-a) var(--edge-b), transparent var(--edge-b)),
    linear-gradient(to bottom, transparent var(--edge-a), #000 var(--edge-a) var(--edge-b), transparent var(--edge-b));
  -webkit-mask-size: 64px 64px; mask-size: 64px 64px;
  -webkit-mask-composite: source-in; mask-composite: intersect;
}

/* Redstone wire between connected things. */
.redstone { position: fixed; inset: 0; z-index: 2; pointer-events: none; overflow: visible; }
.redstone path { fill: none; stroke: var(--red); stroke-width: 3; stroke-linejoin: miter; shape-rendering: crispEdges; opacity: .75; }
.redstone .pulse { stroke: var(--torch); stroke-dasharray: 6 60; animation: redstone 1.2s linear infinite; }
@keyframes redstone { to { stroke-dashoffset: -66; } }

/* Speaker toggle in footers. */
.sound-toggle { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 6px 8px; border-radius: var(--radius-sm, 8px); }
.sound-toggle:hover { color: var(--text); }
.sound-toggle:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .torch, .redstone .pulse { display: none; }
  .building { opacity: 1; transform: none; }
  html:not(.vt-theme)::view-transition-new(root), .chunk-in { -webkit-mask-image: none; mask-image: none; animation: none; }
}
