/* Mobile-first, single-screen layout, canvas fills viewport */
:root{
  --bg:#071021;
  --panel: rgba(0,0,0,0.35);
  --accent: #f5c85a;
  --muted: #cbd5e1;
  --control-size: 52px; /* slightly bigger touch targets for portrait */
  --compact-height: 72px;
}
/* Prevent pull-to-refresh and overscroll gestures on root; allow scroll inside specific containers (e.g. modal has overflow:auto) */
html,body{
  height:100%;
  margin:0;
  background:var(--bg);
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
  overflow:hidden;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}
/* Allow text selection and usual behaviors inside form controls */
input, textarea, select { -webkit-user-select: text; -moz-user-select: text; user-select: text; }

/* small footer for attribution */
#app-footer{
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 8px;
  color: #94a3b8;
  font-size: 12px;
  text-align: center;
  z-index: 70;
  pointer-events: auto;
  background: rgba(255,255,255,0.012);
  padding: 6px 10px;
  border-radius: 10px;
}
#app-footer a{ color: var(--accent); text-decoration: none; }
#app-footer a:hover{ text-decoration: underline; }
canvas#canvas{
  width:100vw;
  height:100vh;
  display:block;
  touch-action: none;
  background: radial-gradient(ellipse at 20% 10%, rgba(255,255,255,0.03), transparent 5%),
              radial-gradient(ellipse at 80% 90%, rgba(255,255,255,0.02), transparent 10%),
              var(--bg);
}

/* Top header: elegant white centered label */
#top-header{
  position: fixed;
  top: 40px;
  left: 12px;
  right: 12px;
  z-index: 60;
  text-align: center;
  font-weight: 600;
  color: #ffffff;
  font-family: "Segoe UI", Inter, Roboto, Arial, sans-serif;
  font-size: 18px;
  letter-spacing: 0.8px;
  padding: 4px 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  text-shadow: 0 1px 0 rgba(0,0,0,0.45);
  opacity: 0.98;
}
@media (min-width:600px){
  #top-header{
    font-size:20px;
    top:40px;
    left:18px;
    right:18px;
    padding:4px 0;
    letter-spacing:0.9px;
  }
}
@media (min-width:900px){
  #top-header{
    left:18px;
    right:18px;
    top:36px;
    pointer-events:none;
    background: transparent;
    box-shadow: none;
    color: #ffffff;
    font-size:16px;
    padding:4px 0;
    text-align:center;
    letter-spacing:0.9px;
  }
}

/* Loading overlay */
#loading{
  position:fixed;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  background: linear-gradient(180deg, rgba(7,16,33,0.9), rgba(7,16,33,0.95));
  z-index:40;
  pointer-events:auto;
}
.loading-card{
  width:84%;
  max-width:420px;
  background: rgba(255,255,255,0.02);
  border-radius:12px;
  padding:18px;
  display:flex;
  flex-direction:column;
  gap:10px;
  align-items:center;
  box-shadow: 0 12px 36px rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
}
.logo{ display:block; }
#loading-text{ color:#cbd5e1; font-size:14px; }
#loading-sub{ color:#94a3b8; font-size:12px; }
#loading-bar{
  width:100%;
  height:10px;
  background: rgba(255,255,255,0.04);
  border-radius:8px;
  overflow:hidden;
}
#loading-progress{
  height:100%;
  background: linear-gradient(90deg,#f5c85a,#ffb86b);
  width:0%;
  transition:width 180ms linear;
  box-shadow:0 4px 10px rgba(245,200,90,0.12) inset;
}

/* UI overlay adapted for portrait mobile: compact bottom bar and stacked panels */
#ui{
  position:fixed;
  left:0;
  right:0;
  bottom:48px; /* separado del pie para evitar solapamiento */
  display:flex;
  gap:10px;
  align-items:flex-end;
  justify-content:center;
  pointer-events:none; /* allow canvas gestures except controls */
  padding:0 12px;
  box-sizing:border-box;
  z-index:30;
}

/* Controls: centered bottom bar with larger touch targets */
#controls{
  pointer-events:auto;
  display:flex;
  gap:10px;
  align-items:center;
  background:var(--panel);
  padding:10px;
  border-radius:14px;
  box-shadow: 0 12px 36px rgba(2,6,23,0.6);
  backdrop-filter: blur(6px);
  height: var(--compact-height);
  max-width: calc(100% - 36px);
  width: min(980px, calc(100% - 36px));
  justify-content: center;
}
#controls button{
  width:var(--control-size);
  height:var(--control-size);
  min-width:var(--control-size);
  min-height:var(--control-size);
  border-radius:12px;
  border:0;
  background:#0f1724;
  color:var(--muted);
  font-size:20px;
  display:flex;
  align-items:center;
  justify-content:center;
  box-shadow:inset 0 -2px 0 rgba(0,0,0,0.4);
  touch-action: manipulation;
}
#controls button:active{ transform:translateY(1px); }
#controls .range input[type="range"]{
  width:110px;
  -webkit-appearance:none;
  background:transparent;
}
#controls input[type="range"]::-webkit-slider-runnable-track{ height:4px; background:#203040; border-radius:4px;}
#controls input[type="range"]::-webkit-slider-thumb{ -webkit-appearance:none; width:16px;height:16px;border-radius:10px;background:var(--accent); margin-top:-6px; box-shadow:0 1px 2px rgba(0,0,0,0.6);}

/* Search & clear placed compactly inside controls */
#controls input[type="search"]{
  color: var(--muted);
  background: transparent;
  outline: none;
  width:140px;
  height:40px;
  border-radius:10px;
  padding:6px 10px;
  border: 1px solid rgba(255,255,255,0.02);
}
#controls input[type="search"]::placeholder{
  color: #94a3b8;
  opacity: 1;
}
#controls > button, #controls > .range, #controls input[type="search"], #controls > div {
  margin: 0 4px;
}

/* Legend and info: stacked above controls on small screens */
#legend{
  pointer-events:auto;
  position: fixed;
  left:12px;
  right:12px;
  bottom: calc(var(--compact-height) + 26px);
  margin:0 auto;
  padding:8px 10px;
  background:linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  color:var(--muted);
  font-size:12px;
  border-radius:10px;
  display:flex;
  gap:8px;
  align-items:center;
  min-width:90px;
  justify-content:center;
  max-width:420px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  z-index:29;
}
.legend-item{ display:flex; gap:6px; align-items:center; }
.legend-dot{ width:12px; height:12px; border-radius:50%; box-shadow:0 1px 2px rgba(0,0,0,0.6); }

/* Info panel shown when tapping objects: floats above legend and controls */
#info{
  pointer-events:auto;
  position: fixed;
  left:12px;
  right:12px;
  bottom: calc(var(--compact-height) + 86px);
  margin:0 auto;
  padding:12px;
  background: linear-gradient(180deg, rgba(3,6,12,0.7), rgba(3,6,12,0.55));
  color: #f8f7f3;
  font-size:13px;
  border-radius:12px;
  max-width:420px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.6);
  display:none;
  flex-direction:column;
  gap:8px;
  z-index:31;
}
#info.visible{ display:flex; }
#info .title{ font-weight:600; color:var(--accent); font-size:15px; }
#info .desc{ color:var(--muted); font-size:13px; line-height:1.25; }
#info .close{
  align-self:flex-end;
  background:transparent;
  border:0;
  color:var(--muted);
  font-size:18px;
  padding:6px;
}

/* Ensure enough spacing on taller / tablet viewports */
@media (min-width:600px) {
  :root { --control-size: 46px; --compact-height: 64px; }
  #ui{ bottom:56px; } /* mantener separación mayor en pantallas más anchas */
  #legend{ left:18px; right:auto; bottom:18px; top:auto; position: fixed; width: auto; max-width: 220px; }
  #info{ left:18px; right:auto; bottom: 18px; max-width: 320px; }
}

/* Desktop / wide screens keep a top-left compact UI but still portrait-friendly */
@media (min-width:900px){
  #ui{
    left:18px;
    top:18px;
    right:auto;
    bottom:auto;
    justify-content:flex-start;
    align-items:center;
    pointer-events:none;
  }
  #controls{ max-width:380px; height:var(--control-size); padding:6px; border-radius:10px; }
  #legend{ position: static; margin-left:8px; bottom:auto; left:auto; right:auto; }
  #info{ position: static; margin-left:8px; max-width:220px; bottom:auto; left:auto; right:auto; display:none; }
}