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

html, body {
  width: 100%; height: 100%;
  background: #0a0a0a;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Screen overlays ────────────────────────────────────── */
.screen-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 12, 0.97);
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease;
}

.screen-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.screen-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}

/* ─── Tutorial screen ────────────────────────────────────── */
.screen-title {
  font-size: clamp(24px, 6vw, 38px);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #fff;
}

.instructions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.gesture {
  display: flex;
  align-items: center;
  gap: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 8px 12px;
  text-align: left;
}

.gesture-icon-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  transform: rotate(26deg);
}

.gesture-icon {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: opacity 0.2s ease;
}

.gesture-icon--v2 { opacity: 0; }
.gesture-icon-wrap.lit .gesture-icon--v1 { opacity: 0; }
.gesture-icon-wrap.lit .gesture-icon--v2 { opacity: 1; }

.gesture-text strong {
  display: block;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}

.gesture-text p {
  color: rgba(255, 255, 255, 0.45);
  font-size: 13px;
}

/* ─── Status area (queue / countdown) ───────────────────── */
#status-area {
  width: 100%;
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.status-connecting {
  color: rgba(255, 255, 255, 0.3);
  font-size: 14px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.status-countdown {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.countdown-label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.45);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.countdown-number {
  font-size: clamp(56px, 18vw, 96px);
  font-weight: 800;
  color: #fff;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  animation: pulse-number 1s ease-in-out;
}

@keyframes pulse-number {
  0%   { transform: scale(1.3); opacity: 0.5; }
  100% { transform: scale(1);   opacity: 1; }
}

.status-queue {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.queue-number {
  font-size: clamp(56px, 18vw, 96px);
  font-weight: 800;
  color: rgba(255, 200, 80, 0.9);
  line-height: 1;
}

.queue-label {
  font-size: 15px;
  color: rgba(255, 255, 255, 0.5);
}

/* ─── Thank-you screen ───────────────────────────────────── */
.thankyou-icon {
  font-size: 52px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}

.thankyou-msg {
  font-size: 17px;
  color: rgba(255, 255, 255, 0.6);
  line-height: 1.6;
}

.qr-hint {
  font-size: 40px;
  opacity: 0.4;
  margin-top: 8px;
}

/* ─── Stage ─────────────────────────────────────────────── */
#stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

/* ─── Session timer bar ──────────────────────────────────── */
#session-timer-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.08);
  z-index: 700;
  pointer-events: none;
}

#session-timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #7dd3fc, #a78bfa, #f472b6);
  transition: width 1s linear;
}

/* ─── Layer images ───────────────────────────────────────── */
.layer-img {
  position: absolute;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  draggable: false;
  will-change: transform, filter, opacity;
  transform-origin: center center;
  transition: filter 0.35s ease-out;
}

/* Tap animation */
@keyframes anim-tap {
  0%   { transform: scale(1);    filter: brightness(1);   }
  35%  { transform: scale(1.13); filter: brightness(2.2); }
  100% { transform: scale(1);    filter: brightness(1);   }
}
.anim-tap {
  animation: anim-tap 240ms cubic-bezier(.22,.61,.36,1) forwards;
}

/* Slide */
.anim-slide {
  filter: brightness(1.5) drop-shadow(0 0 14px var(--accent, #fff)) saturate(1.6) !important;
  transition: filter 0.06s ease-in !important;
}

/* Hold */
@keyframes anim-hold {
  0%, 100% { filter: brightness(1)   drop-shadow(0 0  0px var(--accent, #fff)); }
  50%       { filter: brightness(1.5) drop-shadow(0 0 22px var(--accent, #fff)); }
}
.anim-hold {
  animation: anim-hold 1.3s ease-in-out infinite;
}

/* ─── FX canvas ──────────────────────────────────────────── */
#fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 500;
}

/* ─── Loader ─────────────────────────────────────────────── */
#loader {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a0a;
  z-index: 900;
  transition: opacity 0.5s ease;
}
#loader.hidden { opacity: 0; pointer-events: none; }
.loader-text {
  color: rgba(255,255,255,0.35);
  font-size: 14px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* ─── Settings button ────────────────────────────────────── */
#settings-btn {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.65);
  color: rgba(255,255,255,0.7);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  z-index: 850;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#settings-btn:hover,
#settings-btn:focus-visible { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.35); }
#settings-btn { display: none; }

/* ─── Settings panel ─────────────────────────────────────── */
#settings-panel {
  position: fixed;
  bottom: calc(max(20px, env(safe-area-inset-bottom, 20px)) + 54px);
  right: 20px;
  background: rgba(12,12,12,0.96);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: 20px;
  min-width: 290px;
  z-index: 860;
  color: #fff;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
#settings-panel.hidden { display: none; }

#settings-panel h2 {
  margin-bottom: 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
}

#settings-panel label {
  display: block;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  margin-bottom: 5px;
}

#td-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(255,255,255,0.45);
  margin-bottom: 12px;
}

.led {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transition: background 0.3s, box-shadow 0.3s;
}
.led.disconnected { background: #444; }
.led.connecting   { background: #ffcc00; box-shadow: 0 0 6px #ffcc00; animation: led-blink 0.8s ease infinite; }
.led.connected    { background: #44ff88; box-shadow: 0 0 7px #44ff88; }
.led.error        { background: #ff4444; box-shadow: 0 0 6px #ff4444; }

@keyframes led-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

#settings-panel button {
  display: block;
  width: 100%;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.07);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  margin-bottom: 0;
}
#settings-panel button:hover { background: rgba(255,255,255,0.14); }
#settings-panel .sep { height: 1px; background: rgba(255,255,255,0.08); margin: 10px 0; }
#settings-close { color: rgba(255,255,255,0.4); border-color: transparent; background: transparent; }
#settings-close:hover { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1); }

/* Error / detail line */
#td-detail {
  display: none;
  font-size: 11px;
  color: #ff8080;
  font-family: "SF Mono", "Fira Code", monospace;
  margin-bottom: 8px;
  padding: 5px 8px;
  background: rgba(255,60,60,0.08);
  border-radius: 6px;
  border: 1px solid rgba(255,60,60,0.2);
  word-break: break-all;
  line-height: 1.4;
}

.td-count {
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  margin-bottom: 2px;
}

/* Copy row with <code> element */
.copy-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  align-items: center;
}
#td-relay-url {
  flex: 1;
  display: block;
  padding: 8px 10px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  color: #7dd3fc;
  font-size: 13px;
  font-family: "SF Mono", "Fira Code", monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.5;
  min-width: 0;
  cursor: text;
  user-select: all;
  -webkit-user-select: all;
}
#settings-panel .copy-row button {
  flex-shrink: 0;
  width: auto;
  padding: 8px 12px;
  font-size: 12px;
}

.tip {
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  line-height: 1.5;
  margin: 0;
}
.tip strong { color: rgba(255,255,255,0.6); font-weight: 600; }
.tip em     { color: rgba(255,255,255,0.5); font-style: normal; }

/* ─── Overlay logo (tutorial + thank-you screens) ───────── */
.overlay-logo {
  width: 55vw;
  max-width: 260px;
  max-height: 15vh;
  object-fit: contain;
  opacity: 0.9;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.overlay-logo--bottom {
  margin-top: 4px;
  opacity: 0.75;
}

/* ─── Stage logo (below piano layers) ───────────────────── */
#luna-logo {
  position: absolute;
  bottom: max(8vh, env(safe-area-inset-bottom, 8vh));
  left: 50%;
  transform: translateX(-50%);
  width: 55vw;
  max-width: 280px;
  max-height: 16vh;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 0;
  opacity: 0.88;
  transition: opacity 0.5s ease;
}
#luna-logo.idle-hidden { opacity: 0; }

/* ─── Bilingual countdown label ──────────────────────────── */
.countdown-label--en {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.3);
  margin-top: -2px;
}

/* ─── Bilingual queue label ──────────────────────────────── */
.queue-label--en {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.3);
  margin-top: -2px;
}

/* ─── Thank-you screen redesign ──────────────────────────── */
#screen-thankyou .screen-inner {
  gap: 16px;
}

.thankyou-logo {
  width: 60vw;
  max-width: 240px;
  max-height: 18vh;
}

.thankyou-divider {
  width: 40%;
  height: 1px;
  background: rgba(255, 255, 255, 0.12);
}

.screen-title--en {
  font-size: clamp(18px, 4.5vw, 28px);
  font-weight: 600;
  color: rgba(255, 255, 255, 0.5);
}

.thankyou-msg--en {
  color: rgba(255, 255, 255, 0.35);
  font-size: 14px;
}

/* ─── Idle hint (active stage, no gesture for 10s) ──────── */
#idle-hint {
  position: absolute;
  bottom: max(8vh, env(safe-area-inset-bottom, 8vh));
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
#idle-hint.hidden { display: none; }

.idle-text-bg {
  font-size: clamp(22px, 5.5vw, 34px);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #fff;
  animation: idle-zoom-in 1.6s cubic-bezier(.22,.61,.36,1) forwards;
}

.idle-text-en {
  font-size: clamp(13px, 3vw, 18px);
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 0.08em;
}

@keyframes idle-zoom-in {
  0%   { transform: scale(0.35); opacity: 0; }
  18%  { transform: scale(1);    opacity: 1; }
  72%  { transform: scale(1);    opacity: 1; }
  100% { transform: scale(1.08); opacity: 0; }
}
