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

html, body { width: 100%; height: 100%; overflow: hidden; background: #000; }

#bg-canvas, #fg-canvas {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
}
#bg-canvas { z-index: 1; }
#fg-canvas { z-index: 2; background: transparent; }

/* ── Welcome ─────────────────────────────────────────────────────────────── */
#welcome {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column; align-items: center;
  overflow-y: auto;          /* scroll lives here, not inside the card */
  padding: 3rem 1.5rem;
  background: rgba(0,0,0,0.93); backdrop-filter: blur(8px);
  transition: opacity 0.8s ease;
}
#welcome.fade-out { opacity: 0; pointer-events: none; }

.welcome-inner {
  text-align: center; color: #d8e8ff;
  font-family: 'Segoe UI', system-ui, sans-serif;
  width: 100%; max-width: 480px; padding: 0;
  margin: auto;              /* centers vertically when content fits */
}
.welcome-inner h1 {
  font-size: clamp(2.4rem, 8vw, 4rem); font-weight: 200;
  letter-spacing: 0.28em; text-transform: uppercase; color: #90bcff;
  margin-bottom: 0.5rem;
}
.tagline { font-size: 1.05rem; color: #7888a8; margin-bottom: 2rem; font-weight: 300; }

.privacy-note {
  font-size: 0.83rem; color: #485868; margin-bottom: 2.4rem;
  line-height: 1.7; border: 1px solid #1a3050; border-radius: 8px;
  padding: 0.75rem 1rem;
}
#start-btn {
  background: transparent; border: 1px solid #3878b8; color: #78b0f8;
  font-size: 0.95rem; letter-spacing: 0.15em; text-transform: uppercase;
  padding: 0.75rem 2.2rem; border-radius: 4px; cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  font-family: inherit; margin-bottom: 1rem;
}
#start-btn:hover { background: #3878b820; border-color: #78b0f8; color: #b8d8ff; }
#start-btn:disabled { opacity: 0.5; cursor: default; }
.hint { font-size: 0.78rem; color: #283848; }

/* ── Debug overlay ──────────────────────────────────────────────────────── */
#debug-overlay {
  position: fixed; top: 1rem; right: 1rem; z-index: 300;
  background: rgba(0,0,0,0.78); border: 1px solid #182838;
  border-radius: 6px; padding: 0.7rem 0.9rem;
  font-family: 'Consolas','Menlo',monospace; font-size: 0.7rem;
  color: #507090; min-width: 200px;
}
#debug-overlay.hidden { display: none; }
.debug-title { color: #3878b8; margin-bottom: 0.5rem; font-size: 0.73rem; letter-spacing: 0.1em; }
.debug-hint  { color: #283848; font-size: 0.62rem; }
.debug-row   { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.22rem; }
.debug-row > span:first-child { width: 46px; color: #486880; }
.bar-wrap { flex: 1; height: 6px; background: #0d1820; border-radius: 3px; overflow: hidden; }
.bar      { height: 100%; width: 0%; background: #1860a0; border-radius: 3px; transition: width 0.05s linear; }
.onset-bar { background: #d05820; }
.sil-bar   { background: #186050; }
.val { width: 34px; text-align: right; color: #384858; }
.debug-fps { margin-top: 0.4rem; color: #2a4050; font-size: 0.66rem; }

/* ── Sound guide ──────────────────────────────────────────────────────── */
.sound-guide {
  text-align: left; border: 1px solid #1a3050; border-radius: 8px;
  padding: 0.8rem 1rem; margin-bottom: 2rem;
}
.sound-guide-title {
  color: #3878b8; font-size: 0.73rem; letter-spacing: 0.1em;
  text-transform: uppercase; margin-bottom: 0.55rem;
}
.sound-item {
  display: flex; gap: 0.5rem; align-items: baseline;
  font-size: 0.8rem; color: #486880; line-height: 1.55;
  margin-bottom: 0.2rem;
}
.si-icon { flex-shrink: 0; }
.sound-item strong { color: #90bcff; font-weight: 400; }

/* ── Mode tabs ───────────────────────────────────────────────────────── */
.mode-tabs {
  display: flex; gap: 0.5rem; margin-bottom: 1.4rem; justify-content: center;
}
.mode-tab {
  background: transparent; border: 1px solid #1a3050; color: #486880;
  font-family: inherit; font-size: 0.82rem; letter-spacing: 0.06em;
  padding: 0.4rem 1.2rem; border-radius: 4px; cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.mode-tab:hover  { border-color: #3878b8; color: #90bcff; }
.mode-tab.active { border-color: #3878b8; color: #78b0f8; background: #3878b810; }

/* ── Music panel (welcome screen) ────────────────────────────────────── */
#music-panel { width: 100%; margin-bottom: 1rem; }

#file-drop {
  border: 1px dashed #1a3050; border-radius: 6px;
  padding: 0.75rem 1rem; margin-bottom: 0.9rem;
  cursor: pointer; text-align: center; transition: border-color 0.2s, background 0.2s;
}
#file-drop:hover, #file-drop.drag-over {
  border-color: #3878b8; background: #3878b810;
}
.drop-label { font-size: 0.75rem; color: #486880; }

.ia-section { margin-bottom: 0.5rem; }
.ia-section-title {
  font-size: 0.65rem; color: #3878b8; letter-spacing: 0.1em;
  text-transform: uppercase; margin-bottom: 0.4rem;
}
.ia-form {
  display: flex; gap: 0.4rem; margin-bottom: 0.5rem;
}
.ia-form input {
  flex: 1; background: #050d14; border: 1px solid #1a3050;
  color: #90bcff; font-family: inherit; font-size: 0.78rem;
  padding: 0.35rem 0.6rem; border-radius: 4px; outline: none;
  transition: border-color 0.15s;
}
.ia-form input:focus { border-color: #3878b8; }
.ia-form button {
  background: transparent; border: 1px solid #1a3050; color: #486880;
  font-size: 0.78rem; padding: 0.35rem 0.6rem;
  border-radius: 4px; cursor: pointer; transition: border-color 0.15s, color 0.15s;
}
.ia-form button:hover { border-color: #3878b8; color: #78b0f8; }

#ia-results {
  max-height: 150px; overflow-y: auto; display: flex; flex-direction: column; gap: 1px;
}
#ia-results::-webkit-scrollbar { width: 4px; }
#ia-results::-webkit-scrollbar-track { background: transparent; }
#ia-results::-webkit-scrollbar-thumb { background: #1a3050; border-radius: 2px; }

.ia-item {
  display: flex; flex-direction: column; padding: 0.35rem 0.5rem;
  border-radius: 4px; cursor: pointer; transition: background 0.15s;
}
.ia-item:hover    { background: #0d2030; }
.ia-item.selected { background: #0d2035; border-left: 2px solid #3878b8; }
.ia-title { font-size: 0.75rem; color: #90bcff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ia-meta  { font-size: 0.65rem; color: #385060; }
.ia-msg   { font-size: 0.72rem; color: #385060; padding: 0.3rem 0.5rem; }
.ia-error { color: #804040; }

.music-status {
  font-size: 0.72rem; color: #3878b8; margin-top: 0.5rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-height: 1rem;
}

/* ── In-world music controls ─────────────────────────────────────────── */
#music-controls {
  display: none; align-items: center; gap: 0.5rem;
  background: rgba(0,0,0,0.6); border: 1px solid #1a3050;
  border-radius: 6px; padding: 0.45rem 0.65rem;
}
.music-track-info {
  flex: 1; font-size: 0.65rem; color: #486880;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 200px;
}
#music-toggle-btn {
  background: transparent; border: 1px solid #1a3050; color: #486880;
  font-size: 0.78rem; padding: 0.2rem 0.45rem;
  border-radius: 4px; cursor: pointer; flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
#music-toggle-btn:hover { border-color: #3878b8; color: #78b0f8; }
#music-stop-btn {
  background: transparent; border: 1px solid #3a1020; color: #804060;
  font-size: 0.78rem; padding: 0.2rem 0.45rem;
  border-radius: 4px; cursor: pointer; flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
#music-stop-btn:hover { border-color: #c04060; color: #f07090; }

/* ── Controls panel (sensitivity + reset) ────────────────────────────── */
#controls {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 100;
  display: none; flex-direction: column; gap: 0.5rem; align-items: stretch;
  font-family: 'Segoe UI', system-ui, sans-serif;
}
#controls.visible { display: flex; }

#sensitivity-wrap {
  background: rgba(0,0,0,0.6); border: 1px solid #1a3050;
  border-radius: 6px; padding: 0.55rem 0.75rem;
}
.sens-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 0.35rem;
}
.sens-title { font-size: 0.65rem; color: #486880; letter-spacing: 0.06em; text-transform: uppercase; }
#sens-val   { font-size: 0.72rem; color: #3878b8; font-variant-numeric: tabular-nums; }

.sens-row { display: flex; align-items: center; gap: 0.4rem; }
.sens-edge { font-size: 0.6rem; color: #283848; white-space: nowrap; }

#sens-slider {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 3px; background: #1a3050; border-radius: 2px; outline: none; cursor: pointer;
}
#sens-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 12px; height: 12px; border-radius: 50%;
  background: #3878b8; cursor: pointer;
  transition: background 0.15s;
}
#sens-slider::-webkit-slider-thumb:hover { background: #78b0f8; }
#sens-slider::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%; border: none;
  background: #3878b8; cursor: pointer;
}

#reset-btn, #home-btn {
  background: transparent; border: 1px solid #1a3050;
  font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 0.4rem 0.85rem; border-radius: 4px; cursor: pointer;
  font-family: inherit;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
#reset-btn { color: #2a5080; }
#reset-btn:hover { background: #1a305028; border-color: #3878b8; color: #78b0f8; }

#home-btn { color: #2a6050; border-color: #1a3828; }
#home-btn:hover { background: #1a302028; border-color: #38b888; color: #78f8d0; }
