:root {
  --pixel: "Press Start 2P", monospace;
  --text: "VT323", monospace;
  --mc-yellow: #ffff55;
  --mc-green: #80ff20;
  --shadow: 2px 2px 0 #3f3f3f;
  --bg-top: #3d6fd1;
  --bg-bottom: #f5a35c;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: #0b0716;
  color: #fff;
  font-family: var(--text);
  font-size: 22px;
  -webkit-font-smoothing: none;
  overscroll-behavior: none;
}

body.locked { overflow: hidden; height: 100%; touch-action: none; }

img { image-rendering: auto; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* ---------- Minecraft button ---------- */
.mc-btn {
  font-family: var(--text);
  font-size: 28px;
  color: #fff;
  text-shadow: var(--shadow);
  min-width: 260px;
  padding: 12px 28px;
  background: linear-gradient(#8f8f8f, #6f6f6f);
  border: 3px solid #000;
  box-shadow: inset 3px 3px 0 #b3b3b3, inset -3px -3px 0 #4a4a4a;
  image-rendering: pixelated;
}
.mc-btn:hover, .mc-btn:focus-visible { background: linear-gradient(#8a9fd8, #6b80be); outline: none; box-shadow: inset 3px 3px 0 #b6c4f0, inset -3px -3px 0 #3f4f86; }
.mc-btn:active { transform: translateY(2px); }

/* ---------- full-screen overlays ---------- */
.screen {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 72px;
  padding: 24px 16px;
  transition: opacity 0.6s;
}
.screen.hidden { opacity: 0; pointer-events: none; }

#title { background: rgba(10, 10, 20, 0.35); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }

.logo-wrap { position: relative; text-align: center; max-width: 100%; }
.logo {
  font-family: var(--pixel);
  line-height: 1.15;
  word-break: break-word;
  color: #c6c6c6;
  background: linear-gradient(#e6e6e6 0 40%, #9d9d9d 40% 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 0 #3a3a3a) drop-shadow(0 3px 0 #1e1e1e) drop-shadow(3px 0 0 #2a2a2a);
}
.edition {
  margin-top: 10px;
  font-family: var(--pixel);
  font-size: clamp(9px, 2.6vw, 14px);
  letter-spacing: 2px;
  color: #fff;
  text-shadow: var(--shadow);
}
.splash {
  position: absolute; right: 0; bottom: -22px;
  font-size: clamp(18px, 5vw, 28px);
  color: var(--mc-yellow);
  text-shadow: 2px 2px 0 #3f3f00;
  transform: rotate(-16deg);
  animation: splash 0.5s ease-in-out infinite alternate;
  white-space: nowrap;
}
@keyframes splash { to { transform: rotate(-16deg) scale(1.09); } }

.corner { position: absolute; bottom: calc(10px + env(safe-area-inset-bottom)); font-size: 20px; text-shadow: var(--shadow); opacity: 0.9; }
.corner.left { left: 12px; }
.corner.right { right: 12px; }

#generating { background-repeat: repeat; background-size: 64px; image-rendering: pixelated; gap: 18px; }
.gen-title { font-size: 34px; text-shadow: var(--shadow); }
.gen-seed { font-size: 24px; color: #a8a8a8; text-shadow: var(--shadow); }
.gen-bar { width: min(320px, 80vw); height: 14px; background: #3a3a3a; border: 2px solid #000; }
.gen-fill { height: 100%; width: 0; background: #80ff20; box-shadow: inset 0 -3px 0 #4cb012; transition: width 0.2s; }
.gen-status { font-size: 22px; color: #ddd; text-shadow: var(--shadow); min-height: 1em; }

/* ---------- 3D world ---------- */
#sky {
  position: fixed; inset: 0; z-index: 10;
  background: linear-gradient(#78a7ff 0%, #a9cdff 55%, #cfe2ff 100%);
}
#world { position: fixed; inset: 0; z-index: 11; width: 100%; height: 100%; display: block; touch-action: none; transition: opacity 1s; }

#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; display: none; }
#hud.on { display: block; }

#chat {
  position: absolute; top: calc(64px + env(safe-area-inset-top)); left: 10px; right: 10px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
}
.chat-line {
  font-size: 22px; padding: 1px 8px;
  background: rgba(0, 0, 0, 0.4);
  text-shadow: var(--shadow);
  max-width: 100%;
  transition: opacity 1s;
}
.chat-line.system { color: var(--mc-yellow); }
.chat-line.gone { opacity: 0; }

#joystick {
  position: absolute; left: 90px; top: calc(100% - 140px);
  width: 120px; height: 120px; margin: -60px 0 0 -60px;
  border: 3px solid rgba(255, 255, 255, 0.45);
  background: rgba(0, 0, 0, 0.18);
  display: flex; align-items: center; justify-content: center;
  opacity: 0.55; transition: opacity 0.2s;
}
#joystick.on { opacity: 1; }
#joystick .knob { width: 48px; height: 48px; background: rgba(255, 255, 255, 0.75); border: 3px solid rgba(0, 0, 0, 0.5); }
@media (pointer: fine) { #joystick { display: none; } }

.banner {
  position: absolute; left: 50%; bottom: calc(22% + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  pointer-events: auto;
  font-size: 32px; padding: 14px 30px;
  color: #fff; text-shadow: 2px 2px 0 #2b1d0e;
  background-size: 64px; image-rendering: pixelated;
  border: 4px solid #3b2a14;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.18), 0 6px 0 rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  display: none;
  animation: bob 1.2s ease-in-out infinite;
}
.banner.on { display: block; }
.banner::before, .banner::after {
  content: ""; position: absolute; top: -26px; width: 6px; height: 26px; background: #3b2a14;
}
.banner::before { left: 22px; }
.banner::after { right: 22px; }
@keyframes bob { 50% { transform: translateX(-50%) translateY(-6px); } }

#toast {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px;
  display: flex; align-items: center; gap: 12px;
  width: min(320px, calc(100vw - 24px));
  padding: 10px 14px;
  background: #212121;
  border: 3px solid #555;
  box-shadow: inset 0 0 0 2px #000;
  transform: translateX(calc(100% + 30px));
  transition: transform 0.45s cubic-bezier(.2, .9, .3, 1.2);
}
#toast.on { transform: none; }
.toast-icon { width: 40px; height: 40px; flex: none; background-size: cover; image-rendering: pixelated; }
.toast-head { color: var(--mc-yellow); font-size: 22px; text-shadow: var(--shadow); }
.toast-text { font-size: 22px; text-shadow: var(--shadow); }

#hint {
  position: absolute; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  font-size: 20px; padding: 4px 12px;
  background: rgba(0, 0, 0, 0.45);
  text-shadow: var(--shadow);
  white-space: nowrap;
  transition: opacity 0.8s;
}
#hint.gone { opacity: 0; }

#mute {
  position: fixed; z-index: 60;
  top: calc(10px + env(safe-area-inset-top)); left: 10px;
  width: 44px; height: 44px;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.4);
  display: none; align-items: center; justify-content: center;
  font-size: 22px;
}
#mute.on { display: flex; }
#mute svg { width: 24px; height: 24px; image-rendering: pixelated; }

/* ---------- tribute ---------- */
#bg {
  position: fixed; inset: 0; z-index: 0;
  background: linear-gradient(var(--bg-top), var(--bg-bottom));
}
#stars { position: fixed; inset: 0; z-index: 0; opacity: 0; pointer-events: none; }
#stars i { position: absolute; width: 3px; height: 3px; background: #fff; animation: twinkle 3s ease-in-out infinite alternate; }
@keyframes twinkle { from { opacity: 0.2; } to { opacity: 1; } }

#orbs { position: fixed; inset: 0; z-index: 1; pointer-events: none; overflow: hidden; }
#orbs i {
  position: absolute; bottom: -20px;
  width: 10px; height: 10px;
  background: #c8ff3c;
  box-shadow: 0 0 10px 3px rgba(160, 255, 60, 0.55), inset -3px -3px 0 #6fc21a;
  animation: rise linear infinite;
  opacity: 0;
}
@keyframes rise {
  0% { transform: translateY(0); opacity: 0; }
  10% { opacity: 0.9; }
  90% { opacity: 0.7; }
  100% { transform: translateY(-110vh); opacity: 0; }
}

#tribute { position: relative; z-index: 2; }

#reveal {
  min-height: 100vh; min-height: 100svh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  padding: 72px 16px 110px;
  text-align: center;
  position: relative;
}
#reveal > * { opacity: 0; transform: translateY(30px) scale(0.96); transition: opacity 0.9s, transform 0.9s cubic-bezier(.2, .8, .2, 1); }
#reveal.show > * { opacity: 1; transform: none; }
#reveal.show > :nth-child(2) { transition-delay: 0.25s; }
#reveal.show > :nth-child(3) { transition-delay: 0.45s; }
#reveal.show > :nth-child(4) { transition-delay: 0.7s; }
#reveal.show > :nth-child(5) { transition-delay: 1.3s; }

.frame {
  position: relative;
  padding: 14px;
  background-size: 48px; image-rendering: pixelated;
  border: 4px solid #3b2a14;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35), inset 0 0 0 3px rgba(0, 0, 0, 0.25);
}
.frame img { display: block; width: 100%; height: auto; border: 3px solid #2b1d0e; background: #222; }
.reveal-photo { width: min(78vw, 360px); }

.reveal-title {
  font-family: var(--pixel);
  font-weight: normal;
  font-size: clamp(20px, 6.5vw, 40px);
  line-height: 1.3;
  color: #fff;
  text-shadow: 3px 3px 0 #3f3f3f;
  margin-top: 10px;
}
.reveal-name {
  font-family: var(--pixel);
  font-size: clamp(26px, 10vw, 64px);
  line-height: 1.2;
  color: var(--mc-yellow);
  text-shadow: 4px 4px 0 #3f3f00;
  word-break: break-word;
}
.reveal-message {
  max-width: 520px;
  font-size: 26px; line-height: 1.15;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.45);
  text-shadow: var(--shadow);
}
.scroll-hint {
  position: absolute; bottom: calc(26px + env(safe-area-inset-bottom)); left: 50%;
  margin-left: -80px; width: 160px;
  font-size: 22px; text-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.scroll-hint .arrow {
  width: 18px; height: 18px;
  border-right: 6px solid #fff; border-bottom: 6px solid #fff;
  transform: rotate(45deg);
  animation: nudge 1.1s ease-in-out infinite;
  filter: drop-shadow(2px 2px 0 #3f3f3f);
}
@keyframes nudge { 50% { translate: 0 8px; } }

#gallery { position: relative; }
.painting {
  position: absolute;
  padding: 10px;
  background-size: 36px; image-rendering: pixelated;
  border: 4px solid #3b2a14;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.4), inset 0 0 0 3px rgba(0, 0, 0, 0.25);
  will-change: transform;
}
.painting img, .painting video { display: block; width: 100%; height: auto; border: 3px solid #2b1d0e; background: #222; }
.painting.is-video { cursor: pointer; }
.painting .float-idle { position: relative; }
.badge {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  font-size: 20px; padding: 2px 10px; white-space: nowrap;
  background: #100010e6; border: 2px solid #2a0a5e; box-shadow: inset 0 0 0 1px #5a2ab0;
  text-shadow: var(--shadow);
}

#viewer {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0, 0, 0, 0.92);
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  padding: 16px;
}
#viewer.on { display: flex; }
#viewer video { max-width: 100%; max-height: 78vh; border: 4px solid #3b2a14; background: #000; }

.enter { opacity: 0; transform: translateY(80px) scale(0.92); transition: opacity 1.1s ease, transform 1.3s cubic-bezier(.15, .85, .25, 1); }
.enter.in { opacity: 1; transform: none; }

.float-idle { animation: idle 5s ease-in-out infinite; }
.fade-in { opacity: 0; scale: 0.88; transition: opacity 1.2s ease, scale 1.4s cubic-bezier(.15, .85, .25, 1); }
.fade-in.in { opacity: 1; scale: 1; }
@keyframes idle { 50% { translate: 0 -10px; } }

.book {
  width: min(84vw, 420px);
  padding: 16px 20px 22px;
  background: #f3e9cf;
  color: #3a2a1a;
  border: 4px solid #6b4a24;
  box-shadow: inset 0 0 0 3px #e2d2ab, 0 10px 24px rgba(0, 0, 0, 0.3);
  text-align: left;
  font-size: 25px; line-height: 1.1;
  white-space: pre-line;
}
.book .page { text-align: right; font-size: 18px; color: #7a6a52; margin-bottom: 6px; }

#ending {
  min-height: 100vh;
  padding: 120px 20px 160px;
  display: flex; flex-direction: column; align-items: center; gap: 28px;
  text-align: center;
}
.poem { max-width: 540px; display: flex; flex-direction: column; gap: 22px; }
.poem p { font-size: 27px; line-height: 1.15; text-shadow: 2px 2px 0 #000; }
.poem p:nth-child(odd) { color: #5ff5d6; }
.poem p:nth-child(even) { color: #8cff6e; }
.final { max-width: 540px; font-size: 30px; line-height: 1.15; margin-top: 30px; text-shadow: var(--shadow); white-space: pre-line; }
.signature { font-size: 28px; color: var(--mc-yellow); text-shadow: 2px 2px 0 #3f3f00; }
#respawn { margin-top: 30px; }

#xpbar {
  position: fixed; z-index: 30;
  left: 50%; bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translate(-50%, 140%);
  width: min(88vw, 420px);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: transform 0.5s cubic-bezier(.2, .9, .3, 1.2);
  pointer-events: none;
}
#xpbar.on { transform: translate(-50%, 0); }
.xp-level {
  font-family: var(--pixel); font-size: 18px; color: var(--mc-green);
  text-shadow: 2px 0 0 #000, -2px 0 0 #000, 0 2px 0 #000, 0 -2px 0 #000;
}
.xp-level.pop { animation: pop 0.4s ease; }
@keyframes pop { 40% { transform: scale(1.5); } }
.xp-track {
  width: 100%; height: 12px;
  background: #2a2a2a; border: 2px solid #000;
  position: relative; overflow: hidden;
}
.xp-track::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 calc(5.55% - 2px), #000 calc(5.55% - 2px) 5.55%);
  opacity: 0.6;
}
.xp-fill { height: 100%; width: 0; background: #80ff20; box-shadow: inset 0 -3px 0 #4cb012, inset 0 2px 0 #c4ff8a; }

@media (prefers-reduced-motion: reduce) {
  .float-idle, .splash, .banner, #stars i { animation: none; }
}
