/* ===== fidgly — enhanced visual layer =====
   Load after styles.css. Adds to, doesn't replace.
   ================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500&display=swap');

/* ── Typography ────────────────────────────────────────────── */
*, *::before, *::after {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Deep space background ─────────────────────────────────── */
html {
  background:
    radial-gradient(ellipse at 50% 0%, #0d0d1f 0%, #06060f 55%, #000005 100%)
    fixed;
  overscroll-behavior: none;
}
body {
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
canvas {
  -webkit-touch-callout: none;
}
@media (max-width: 768px) {
  html, body { height: 100dvh; }
}

/* ── OLED grain overlay — desktop only ────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9000;
  opacity: 0.032;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}
@media (max-width: 768px) {
  body::before { display: none; }
}

/* ── HUD labels ─────────────────────────────────────────────── */
.world-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  color: rgba(255, 255, 255, 0.7);
}
.world-mood {
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  color: rgba(255, 255, 255, 0.12);
}

/* ── HUD buttons ────────────────────────────────────────────── */
.hud-btn {
  background: rgba(8, 8, 20, 0.72);
  border: 0.5px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.42);
  width: 32px;
  height: 32px;
  font-size: 13px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}
.hud-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.22);
  color: rgba(255, 255, 255, 0.88);
}
.hud-btn.active {
  color: var(--theme);
  border-color: rgba(255, 255, 255, 0.18);
}
.hud-btn-bg {
  border-radius: 10px !important;
  width: auto !important;
  padding: 0 10px !important;
  font-size: 9px !important;
  letter-spacing: 0.06em;
}
@media (max-width: 768px) {
  .hud-btn {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(4, 4, 14, 0.94);
  }
}

/* ── Theme picker ───────────────────────────────────────────── */
.theme-picker {
  background: rgba(8, 8, 20, 0.72);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  border-radius: 30px;
  padding: 8px 12px;
  gap: 8px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
@media (max-width: 768px) {
  .theme-picker {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(4, 4, 14, 0.96);
  }
}
.theme-dot {
  width: 11px;
  height: 11px;
  opacity: 0.32;
  border: 1.5px solid transparent;
  transition: opacity 0.18s, transform 0.18s, border-color 0.18s;
}
.theme-dot:hover { opacity: 0.78; transform: scale(1.38); }
.theme-dot.active {
  opacity: 1;
  transform: scale(1.5);
  border-color: rgba(255, 255, 255, 0.78);
}

/* ── Controls panel ─────────────────────────────────────────── */
#controls-panel {
  background: rgba(8, 8, 20, 0.88);
  border: 0.5px solid rgba(255, 255, 255, 0.09);
  border-radius: 40px;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}
#controls-panel label {
  color: rgba(255, 255, 255, 0.28);
  font-weight: 300;
  letter-spacing: 0.07em;
  font-size: 10px;
}
@media (max-width: 768px) {
  #controls-panel {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(4, 4, 14, 0.97);
  }
}

/* ── Ctrl button ────────────────────────────────────────────── */
.ctrl-btn {
  background: rgba(255, 255, 255, 0.055);
  border: 0.5px solid rgba(255, 255, 255, 0.13);
  color: rgba(255, 255, 255, 0.6);
  border-radius: 20px;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.07em;
  padding: 4px 12px;
  transition: background 0.18s, border-color 0.18s, color 0.18s;
}
.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.26);
  color: #fff;
}
.ctrl-btn.active {
  background: rgba(255, 255, 255, 0.13);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}

/* ── Divider ────────────────────────────────────────────────── */
.ctrl-divider { background: rgba(255, 255, 255, 0.07); }

/* ── Sliders ────────────────────────────────────────────────── */
input[type="range"] {
  height: 2px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 0 7px rgba(255, 255, 255, 0.26);
}
input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 0 7px rgba(255, 255, 255, 0.26);
  border: none;
}
@media (pointer: coarse) {
  input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; }
}

/* ── Speed readout ──────────────────────────────────────────── */
#speed-val { color: rgba(255, 255, 255, 0.28); font-weight: 300; }

/* ── Time counter ───────────────────────────────────────────── */
#time-counter {
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.15);
}

/* ── Share toast ────────────────────────────────────────────── */
#share-toast {
  background: rgba(8, 8, 20, 0.92);
  border: 0.5px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  font-weight: 300;
  letter-spacing: 0.06em;
  border-radius: 24px;
}

/* ── Custom cursor ──────────────────────────────────────────── */
#cursor { width: 8px; height: 8px; border-width: 1px; }

/* ── Extra world buttons (export / clear / undo) ─────────────  */
.extra-btn {
  background: rgba(8, 8, 20, 0.88);
  border: 0.5px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.5);
  border-radius: 20px;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.07em;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: background 0.18s, border-color 0.18s, color 0.18s;
}
.extra-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.24);
  color: #fff;
}
@media (max-width: 768px) {
  .extra-btn {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(4, 4, 14, 0.96);
  }
}

/* ── Draw / drag hints ──────────────────────────────────────── */
#draw-hint .hint-text,
#drag-hint .hint-text {
  font-weight: 300;
  letter-spacing: 0.22em;
  color: rgba(255, 255, 255, 0.2);
}

/* ── Breathe world text & picker ────────────────────────────── */
#breathe-text   { font-weight: 300; letter-spacing: 0.22em; }
#breathe-phase  { font-weight: 300; letter-spacing: 0.14em; }
#breathe-pattern-picker {
  background: rgba(8, 8, 20, 0.85);
  border: 0.5px solid rgba(255, 255, 255, 0.09);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.pattern-btn { font-weight: 300; letter-spacing: 0.08em; }
@media (max-width: 768px) {
  #breathe-pattern-picker {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(4, 4, 14, 0.97);
  }
}

/* ── Sand world controls ────────────────────────────────────── */
#sand-controls {
  background: rgba(8, 8, 20, 0.9) !important;
  border: 0.5px solid rgba(255, 255, 255, 0.09) !important;
  backdrop-filter: blur(20px) !important;
  -webkit-backdrop-filter: blur(20px) !important;
}
.sand-mode-btn { font-weight: 300; letter-spacing: 0.09em; }
@media (max-width: 768px) {
  #sand-controls {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(4, 4, 14, 0.97) !important;
  }
}

/* ── Kids back button ───────────────────────────────────────── */
#k-back {
  background: rgba(255,255,255,0.2) !important;
  border: 2px solid rgba(255,255,255,0.4) !important;
  border-radius: 20px !important;
  color: white !important;
  font-weight: 600 !important;
  padding: 8px 16px !important;
  font-size: 13px !important;
  min-height: 44px !important;
  width: auto !important;
  height: auto !important;
  transition: all 0.18s ease !important;
}
#k-back:active {
  background: rgba(255, 255, 255, 0.35) !important;
  border-color: rgba(255,255,255,0.7) !important;
}

/* ── Star-tooltip (constellation world) ────────────────────── */
#star-tooltip {
  background: rgba(8, 8, 20, 0.85);
  border: 0.5px solid rgba(255, 255, 255, 0.1);
  font-weight: 300;
  letter-spacing: 0.05em;
}

/* ── Session-complete modal (breathe) ───────────────────────── */
#session-complete h2 { font-weight: 300; letter-spacing: 0.14em; }
#session-complete p  { font-weight: 300; }
#session-complete button {
  background: rgba(255, 255, 255, 0.06);
  border: 0.5px solid rgba(255, 255, 255, 0.15);
  font-weight: 300;
  letter-spacing: 0.1em;
}

/* ── Radar hint text ────────────────────────────────────────── */
canvas + script,
.hint-text { font-weight: 300; }

/* ══════════════════════════════════════════════════════════
   GEAR PANEL SYSTEM — replaces old HUD
   ══════════════════════════════════════════════════════════ */

/* Default --theme for worlds that don't load styles.css */
:root { --theme: #4a9eff; }

/* Hide all old HUD chrome */
#hud, #controls-panel, #time-counter, #share-toast, #cursor { display: none !important; }

/* Pre-hide world extras until migrated into gear panel */
#extra-btns, #sand-controls, #breathe-pattern-picker { display: none; }

/* World name — top left, ultra-subtle */
#world-name {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 400;
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.16em;
  color: rgba(255,255,255,0.25);
  text-transform: lowercase;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  transition: opacity 0.6s ease;
}

/* Home button — top right */
#home-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 400;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 18px;
  color: rgba(255,255,255,0.5);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 14px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 0.2s, border-color 0.2s, color 0.2s, opacity 0.6s ease;
}
#home-btn:hover {
  background: rgba(255,255,255,0.16);
  border-color: rgba(255,255,255,0.28);
  color: rgba(255,255,255,0.9);
}
@media (max-width: 768px) {
  #home-btn {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(4,4,14,0.9);
  }
}

/* Gear button — bottom right */
#gear-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 600;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(8,8,20,0.82);
  border: 1px solid rgba(255,255,255,0.13);
  color: rgba(255,255,255,0.4);
  font-size: 18px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s, color 0.2s, border-color 0.2s, opacity 0.6s ease;
}
#gear-btn:hover {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.85);
  border-color: rgba(255,255,255,0.25);
}
#gear-btn.open {
  color: var(--theme, #4a9eff);
  border-color: var(--theme, #4a9eff);
  background: rgba(8,8,20,0.95);
}
@media (max-width: 768px) {
  #gear-btn {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(4,4,14,0.95);
  }
}

/* Gear overlay */
#gear-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 499;
}
#gear-overlay.open { display: block; }

/* Gear panel */
#gear-panel {
  position: fixed;
  bottom: 72px;
  right: 16px;
  z-index: 500;
  width: 260px;
  background: rgba(8,8,18,0.97);
  border: 0.5px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 16px 48px rgba(0,0,0,0.65);
  padding: 16px 16px 12px;
  transform: translateY(14px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
  max-height: calc(100dvh - 96px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
#gear-panel.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: all;
}
@media (max-width: 768px) {
  #gear-panel {
    width: calc(100vw - 20px);
    max-width: 320px;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(4,4,14,0.99);
  }
}

/* Gear labels and dividers */
.gear-label {
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.2);
  margin-bottom: 8px;
  display: block;
}
.gear-divider {
  height: 1px;
  background: rgba(255,255,255,0.07);
  margin: 10px 0;
}

/* Theme dots in gear panel */
#gear-theme-dots {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
#gear-theme-dots .theme-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  cursor: pointer;
}

/* Speed presets */
.gear-speed-presets {
  display: flex;
  gap: 6px;
  margin-bottom: 7px;
}
.gear-speed-btn {
  background: rgba(255,255,255,0.05);
  border: 0.5px solid rgba(255,255,255,0.1);
  border-radius: 11px;
  color: rgba(255,255,255,0.4);
  font-size: 10px;
  padding: 3px 8px;
  cursor: pointer;
  flex: 1;
  min-height: 28px;
  transition: background 0.15s, color 0.15s;
}
.gear-speed-btn:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.8); }

/* Slider rows */
.gear-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.gear-row-label {
  font-size: 10px;
  font-weight: 300;
  color: rgba(255,255,255,0.32);
  min-width: 46px;
  letter-spacing: 0.04em;
}
.gear-row input[type="range"] { flex: 1; }
.gear-speed-val {
  font-size: 10px;
  color: rgba(255,255,255,0.25);
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* BG pills */
#gear-bg-pills {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.gear-bg-pill {
  background: rgba(255,255,255,0.05);
  border: 0.5px solid rgba(255,255,255,0.1);
  border-radius: 11px;
  color: rgba(255,255,255,0.4);
  font-size: 10px;
  padding: 4px 10px;
  cursor: pointer;
  min-height: 28px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.gear-bg-pill:hover, .gear-bg-pill.active {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.26);
  color: rgba(255,255,255,0.9);
}

/* Toggle rows */
.gear-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}
.gear-toggle-label {
  font-size: 10px;
  font-weight: 300;
  color: rgba(255,255,255,0.42);
  letter-spacing: 0.04em;
}
.gear-toggle {
  width: 32px;
  height: 18px;
  background: rgba(255,255,255,0.1);
  border-radius: 9px;
  position: relative;
  cursor: pointer;
  border: 0.5px solid rgba(255,255,255,0.12);
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}
.gear-toggle.on { background: var(--theme, #4a9eff); border-color: transparent; }
.gear-toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: rgba(255,255,255,0.8);
  transition: transform 0.2s;
}
.gear-toggle.on::after { transform: translateX(14px); background: white; }

/* Footer: timer + share */
#gear-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2px;
}
#gear-timer {
  font-size: 10px;
  font-weight: 300;
  color: rgba(255,255,255,0.18);
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}
#gear-share {
  font-size: 10px;
  color: rgba(255,255,255,0.28);
  background: rgba(255,255,255,0.05);
  border: 0.5px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  padding: 3px 9px;
  cursor: pointer;
  min-height: 26px;
  transition: background 0.15s, color 0.15s;
}
#gear-share:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.7); }

/* World extras — world-specific controls migrated in */
#gear-world-extras { }

/* Reset visual styles of elements migrated into gear panel */
#gear-panel #extra-btns,
#gear-panel #sand-controls,
#gear-panel #breathe-pattern-picker {
  position: static !important;
  transform: none !important;
  background: none !important;
  border: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  opacity: 1 !important;
  display: flex !important;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

/* Idle state: fade chrome */
body.idle #world-name,
body.idle #home-btn { opacity: 0; pointer-events: none; }
body.idle #gear-btn:not(.open) { opacity: 0; pointer-events: none; }

/* Kids worlds: bigger gear button */
body.kids-world #gear-btn { width: 52px; height: 52px; font-size: 22px; }
body.kids-world #gear-panel { width: 280px; }
@media (max-width: 768px) {
  body.kids-world #gear-panel { width: calc(100vw - 20px); max-width: 320px; }
}
