/* ---------------------------------------------------------------- */
/*  Reset & page shell                                               */
/* ---------------------------------------------------------------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #3b3c40;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system,
    "Segoe UI", sans-serif;
}

/* ---------------------------------------------------------------- */
/*  Canvas                                                           */
/* ---------------------------------------------------------------- */
#scene {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;       /* stop mobile scroll / pinch on the canvas */
  cursor: grab;
  outline: none;
}

#scene.pointing {
  cursor: pointer;
}

#scene.grabbing {
  cursor: grabbing;
}

/* ---------------------------------------------------------------- */
/*  Hint pill                                                        */
/* ---------------------------------------------------------------- */
#hint {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 9px;

  padding: 9px 18px;
  border-radius: 999px;

  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.045em;
  color: #d9dadd;

  background: rgba(30, 31, 34, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 6px 22px -10px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);

  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.9s ease, transform 0.9s ease;
}

#hint.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
}

#hint .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ef6a44;
  box-shadow: 0 0 0 3px rgba(239, 106, 68, 0.18);
  animation: pulse 2.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%      { transform: scale(0.7); opacity: 0.55; }
}

@media (max-width: 480px) {
  #hint {
    font-size: 11px;
    padding: 8px 14px;
    letter-spacing: 0.02em;
  }
}

/* Blender-style viewport overlays */
#vp-info {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  left: calc(env(safe-area-inset-left, 0px) + 14px);
  font-size: 11.5px;
  line-height: 1.45;
  white-space: pre;
  color: rgba(255, 255, 255, 0.78);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
#vp-info b { font-weight: 700; }

/* ---------------------------------------------------------------- */
/*  Crab Rave toggle + toast                                         */
/* ---------------------------------------------------------------- */
#rave-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 12px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px 7px 13px;
  border-radius: 999px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #e6e7ea;
  background: rgba(30, 31, 34, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 6px 22px -10px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.25s ease, color 0.25s ease;
}
#rave-btn:focus-visible {
  outline: 2px solid #ffd23d;
  outline-offset: 3px;
}
#rave-btn .ico {
  display: inline-block;
  font-size: 15px;
  line-height: 1;
}
#rave-btn .sw {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  transition: background-color 0.25s ease;
}
#rave-btn .sw::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
#rave-btn.on {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.5);
  animation: raveBeat 0.48s ease-out infinite; /* one pulse per beat at 125 BPM */
}
#rave-btn.on .sw {
  background: linear-gradient(90deg, #ff3d81, #ffd23d, #3dffb2, #3da5ff, #b03dff, #ff3d81);
  background-size: 200% 100%;
  animation: raveSlide 1.2s linear infinite;
}
#rave-btn.on .sw::after {
  transform: translateX(14px);
}
#rave-btn.on .ico {
  animation: raveBob 0.48s ease-in-out infinite;
}
@keyframes raveBeat {
  0%   { box-shadow: 0 0 0 0 rgba(255, 80, 160, 0.55); }
  100% { box-shadow: 0 0 0 11px rgba(255, 80, 160, 0); }
}
@keyframes raveSlide {
  to { background-position: -200% 0; }
}
@keyframes raveBob {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-2px) scale(1.12); }
}

#toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 62px);
  transform: translateX(-50%) translateY(-8px);
  z-index: 6;
  max-width: min(88vw, 420px);
  padding: 10px 16px;
  border-radius: 14px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  color: #fff;
  background: rgba(150, 40, 40, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 480px) {
  #rave-btn { font-size: 11.5px; padding: 6px 8px 6px 11px; gap: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  #rave-btn.on, #rave-btn.on .ico, #rave-btn.on .sw { animation: none; }
}

/* night toggle + vignette */
#night-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 56px);
  right: 12px;
  z-index: 5;
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 16px; line-height: 1;
  color: #fff;
  background: rgba(30, 31, 34, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  touch-action: manipulation;
}
#vig {
  position: fixed; inset: 0; z-index: 1;
  pointer-events: none; opacity: 0.2;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,0.7) 100%);
}

/* Android: backdrop-filter and animated box-shadows over a WebGL canvas force costly recomposites */
#vig { will-change: opacity; }
@media (hover: none) and (pointer: coarse) {
  #rave-btn, #night-btn, #hint {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(30, 31, 34, 0.82);
  }
  #rave-btn.on { animation: none; }
}

/* rave-lights toggle (sits under the night button) */
#light-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 98px);
  right: 12px;
  z-index: 5;
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 16px; line-height: 1;
  color: #fff;
  background: rgba(30, 31, 34, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.25s ease, filter 0.25s ease;
}
#light-btn.off { opacity: 0.5; filter: grayscale(1); }
@media (hover: none) and (pointer: coarse) {
  #light-btn { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(30, 31, 34, 0.82); }
}

/* ---------------- tool stack + settings sheet (responsive) ---------------- */
#tools {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 56px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  z-index: 5;
  display: flex; flex-direction: column; gap: 8px;
}
#tools > button { position: static; top: auto; right: auto; }
#rave-btn { right: calc(env(safe-area-inset-right, 0px) + 12px); }
#settings-btn {
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 16px; line-height: 1; color: #fff;
  background: rgba(30, 31, 34, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  cursor: pointer; touch-action: manipulation;
}
#settings-btn:focus-visible, #night-btn:focus-visible, #light-btn:focus-visible { outline: 2px solid #ffd23d; outline-offset: 3px; }
@media (hover: none) and (pointer: coarse) {
  #settings-btn { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(30, 31, 34, 0.82); }
}
@media (max-width: 520px) { #vp-info { display: none; } }

#settings {
  position: fixed; inset: 0; z-index: 8;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, 0); visibility: hidden; pointer-events: none;
  transition: background 0.25s ease, visibility 0s linear 0.28s;
}
#settings.open { background: rgba(0, 0, 0, 0.35); visibility: visible; pointer-events: auto; transition: background 0.25s ease; }
#settings .sheet {
  width: min(100%, 420px); max-height: min(88vh, 640px); overflow-y: auto;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  border-radius: 20px 20px 0 0; color: #e6e7ea;
  background: rgba(28, 29, 33, 0.97); border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 -10px 40px -12px rgba(0, 0, 0, 0.7);
  transform: translateY(24px); opacity: 0;
  transition: transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1), opacity 0.2s ease;
}
#settings.open .sheet { transform: none; opacity: 1; }
#settings header { display: flex; justify-content: space-between; align-items: center; font-size: 15px; font-weight: 800; margin-bottom: 6px; }
#settings button { font: inherit; touch-action: manipulation; cursor: pointer; }
#set-close { width: 30px; height: 30px; border-radius: 50%; border: 0; color: #cfd1d6; background: rgba(255, 255, 255, 0.08); }
#settings h3 { font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #9a9ca3; margin: 14px 0 7px; }
#settings .seg { display: flex; gap: 6px; }
#settings .seg button {
  flex: 1; padding: 10px 4px; border-radius: 10px; font-size: 12.5px; font-weight: 700;
  color: #cfd1d6; background: rgba(255, 255, 255, 0.07); border: 1px solid rgba(255, 255, 255, 0.1);
}
#settings .seg button[aria-pressed="true"] { color: #1b1c1f; background: #ffd23d; border-color: #ffd23d; }
#settings .note { font-size: 11.5px; color: #8d8f96; margin-top: 7px; min-height: 1.2em; }
#settings .row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0 2px; font-size: 14px; font-weight: 700; }
#settings .sw { width: 46px; height: 27px; border-radius: 999px; border: 0; position: relative; background: rgba(255, 255, 255, 0.2); transition: background-color 0.2s ease; }
#settings .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; transition: transform 0.2s ease; }
#settings .sw[aria-checked="true"] { background: #3dd68c; }
#settings .sw[aria-checked="true"]::after { transform: translateX(19px); }
#settings footer { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; font-size: 12px; color: #8d8f96; }
#set-reset { padding: 7px 14px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #cfd1d6; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.12); }
#settings button:focus-visible { outline: 2px solid #ffd23d; outline-offset: 2px; }

/* tablets / desktop: a popover beside the tool stack instead of a bottom sheet */
@media (min-width: 700px) and (min-height: 480px) {
  #settings { align-items: flex-start; justify-content: flex-end; padding: calc(env(safe-area-inset-top, 0px) + 56px) calc(env(safe-area-inset-right, 0px) + 58px) 0 0; }
  #settings.open { background: rgba(0, 0, 0, 0); }
  #settings .sheet { width: 340px; border-radius: 18px; box-shadow: 0 18px 50px -14px rgba(0, 0, 0, 0.7); }
}
/* landscape phones: keep the sheet to the right so the scene stays visible */
@media (orientation: landscape) and (max-height: 479px) {
  #settings { justify-content: flex-end; padding-right: calc(env(safe-area-inset-right, 0px) + 56px); }
  #settings .sheet { width: min(380px, 60vw); max-height: 94vh; border-radius: 16px 16px 0 0; }
}
@media (prefers-reduced-motion: reduce) { #settings, #settings .sheet { transition: none; } }

/* ================= Final polish ================= */
:root { --glass: rgba(24, 25, 29, 0.66); --glass-b: rgba(255, 255, 255, 0.16); --accent: #ffd23d; }
#rave-btn, #tools > button {
  background: var(--glass); border-color: var(--glass-b);
  transition: transform 0.15s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.25s ease, filter 0.25s ease;
}
@media (hover: hover) {
  #rave-btn:hover, #tools > button:hover { background: rgba(48, 50, 57, 0.82); border-color: rgba(255, 255, 255, 0.34); }
  #tools > button:hover { transform: scale(1.08); }
}
#rave-btn:active, #tools > button:active { transform: scale(0.94); }
#night-btn[aria-pressed="true"], #light-btn[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 210, 61, 0.18); }
#hint { max-width: calc(100vw - 24px); }
@media (max-width: 400px) { #hint { white-space: normal; text-align: center; line-height: 1.35; border-radius: 18px; } }
@media (hover: none) and (pointer: coarse) { #tools > button { width: 40px; height: 40px; } #tools { top: calc(env(safe-area-inset-top, 0px) + 58px); } }
@media (orientation: landscape) and (max-height: 420px) { #hint { display: none; } }

#loader {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; text-align: center;
  background: radial-gradient(ellipse at center, #4b4d53, #2b2c30); color: #e6e7ea;
  font-size: 13px; font-weight: 700; letter-spacing: 0.08em;
  transition: opacity 0.6s ease, visibility 0s linear 0.6s;
}
#loader.done { opacity: 0; visibility: hidden; pointer-events: none; }
#loader .crab { font-size: 46px; margin-bottom: 8px; animation: ldb 0.9s ease-in-out infinite; }
@keyframes ldb { 50% { transform: translateY(-9px) scale(1.1); } }
#nogl { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px; text-align: center; color: #fff; background: #2b2c30; font-weight: 700; line-height: 1.5; }
@media (prefers-reduced-motion: reduce) { #hint .dot, #loader .crab { animation: none; } }
