:root {
  --bg: #07090f;
  --panel: rgba(12, 16, 28, 0.86);
  --line: rgba(190, 205, 235, 0.18);
  --text: #e6ebf5;
  --muted: #9aa6bd;
  --accent: #e9c85a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Segoe UI", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

#stage {
  position: fixed;
  inset: 0;
  touch-action: none;
}

#gl, #dbg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#dbg { pointer-events: none; }

#gl { opacity: 0; transition: opacity 1.4s ease-out; }
#gl.ready { opacity: 1; }

#ref {
  position: absolute;
  pointer-events: none;
  overflow: hidden;
}

#ref img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.5;
}

#hud {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  z-index: 3;
  opacity: 0.55;
  transition: opacity 0.3s;
}

#hud:hover, #hud:focus-within { opacity: 1; }
/* With a mouse: out of the way while it rests or is off the page (ui.js),
   back as soon as it moves — or when a button has keyboard focus. */
#hud.idle:not(:has(:focus-visible)) {
  opacity: 0;
  pointer-events: none;
  transition-duration: 0.8s;
}

button.icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

button.icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button.icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.icon[aria-pressed="true"] { color: var(--accent); border-color: rgba(233, 200, 90, 0.55); }
button.icon.busy svg { animation: busy 0.9s ease-in-out infinite alternate; }
@keyframes busy { to { opacity: 0.3; } }

#panel {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 52px);
  width: min(340px, calc(100vw - 24px));
  max-height: calc(100dvh - 90px);
  overflow: auto;
  padding: 16px 16px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 3;
}

#panel h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

#panel .sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
#panel .facts { margin: 10px 0 12px; color: #c7cfdf; font-size: 13px; }

.credit { margin: 6px 0 0; color: #6f7a90; font-size: 11px; }

#fallback {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

/* Touch screens: a hand taps twice (and again), then the hint fades away. */
#hint {
  position: fixed;
  left: 50%;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 64px);
  width: 56px;
  height: 56px;
  margin-left: -28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  pointer-events: none;
  z-index: 3;
  animation: hint-life 3.4s ease both;
}
#hint svg { width: 30px; height: 30px; overflow: visible; }
#hint .hand {
  fill: #0c101c;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linejoin: round;
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: hint-tap 1.2s ease-in-out 0.35s 2;
}
#hint .ripple {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  vector-effect: non-scaling-stroke;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
}
#hint .r1 { animation: hint-ripple 1.2s ease-out 0.47s 2; }
#hint .r2 { animation: hint-ripple 1.2s ease-out 0.77s 2; }

@keyframes hint-life {
  0% { opacity: 0; }
  9%, 85% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes hint-tap {
  0%, 22%, 47%, 100% { transform: none; }
  10%, 35% { transform: translateY(1px) scale(0.92); }
}
@keyframes hint-ripple {
  0% { opacity: 0.95; transform: scale(0.3); }
  50%, 100% { opacity: 0; transform: scale(1.6); }
}
@media (prefers-reduced-motion: reduce) {
  #hint .hand, #hint .ripple { animation: none; }
  #hint .r1 { opacity: 0.6; }
}
