/* 
  You're Getting Sleepy… — calming, quirky, surreal map UI
  Design goals: low-noise, soft contrast, gentle motion, playful glow
*/

:root{
  --bg: #0f1020;
  --panel: rgba(20, 22, 44, 0.86);
  --panel2: rgba(20, 22, 44, 0.72);
  --stroke: rgba(255,255,255,0.08);
  --text: rgba(255,255,255,0.92);
  --muted: rgba(255,255,255,0.62);

  --primary: #6b5cff;
  --secondary: #9fd3c7;
  --accent: #ffd166;

  --shadow: 0 10px 30px rgba(0,0,0,0.45);
  --radius: 14px;
}

*{box-sizing:border-box;}
html,body{height:100%; margin:0; background: radial-gradient(900px 500px at 20% 10%, rgba(107,92,255,0.20), transparent 60%),
                                        radial-gradient(900px 600px at 80% 30%, rgba(159,211,199,0.14), transparent 55%),
                                        radial-gradient(1200px 700px at 50% 100%, rgba(255,209,102,0.10), transparent 60%),
                                        var(--bg);
          color:var(--text);
          font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;}

#app{height:100%; display:flex; flex-direction:column;}

#topbar{
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 16px;
  border-bottom: 1px solid var(--stroke);
  backdrop-filter: blur(14px);
  background: rgba(10, 12, 30, 0.35);
  position: sticky; top:0; z-index: 20;
}
h1{margin:0; font-weight:700; letter-spacing:-0.02em; font-size:20px;}
.subtitle{margin-top:4px; color:var(--muted); font-family:"DM Sans", Inter, sans-serif;}

.top-actions{display:flex; gap:10px;}

button{
  cursor:pointer;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 999px;
  font-weight:600;
  transition: transform 120ms ease, background 120ms ease;
}
button:hover{background: rgba(255,255,255,0.07); transform: translateY(-1px);}
button:active{transform: translateY(0px);}

button.primary{
  background: linear-gradient(135deg, rgba(107,92,255,0.92), rgba(107,92,255,0.62));
  border-color: rgba(107,92,255,0.45);
}
button.ghost{background: rgba(255,255,255,0.03);}
button.mini{padding:6px 10px; font-weight:600; font-size:12px;}

#main{flex:1; display:flex; min-height:0;}
#leftPanel{
  width: 360px;
  max-width: 92vw;
  padding: 14px;
  display:flex;
  flex-direction:column;
  gap: 12px;
  border-right: 1px solid var(--stroke);
  background: rgba(12, 13, 28, 0.25);
  backdrop-filter: blur(16px);
  z-index: 10;
}

.panel{
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
}
.panel.foot{background: transparent; border:none; box-shadow:none; padding: 2px 2px 0;}
.panel-head{
  padding: 12px 12px 0;
}
.panel-head.row{display:flex; align-items:center; justify-content:space-between;}
.panel-head h2{
  margin:0; font-size: 13px; letter-spacing:0.02em; text-transform: uppercase; color: rgba(255,255,255,0.80);
}
.panel-body{padding: 12px; display:flex; flex-direction:column; gap:10px;}

.check{display:flex; gap:10px; align-items:center; user-select:none;}
.check input{width:18px; height:18px; accent-color: var(--primary);}

.legend-item{display:flex; gap:10px; align-items:center;}
.swatch{
  width:14px; height:14px; border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.16);
  box-shadow: 0 0 12px rgba(107,92,255,0.15);
}
.swatch[data-cat="Unregulated"]{background: rgba(159,211,199,0.65);}
.swatch[data-cat="Self-Regulated"]{background: rgba(107,92,255,0.70);}
.swatch[data-cat="Restricted"]{background: rgba(255,209,102,0.70);}
.swatch[data-cat="Regulated"]{background: rgba(255,120,146,0.72);}
.swatch[data-cat="Unknown"]{background: rgba(255,255,255,0.14);}

.hint{color: var(--muted); font-size: 12px; line-height:1.35;}

.timeline-controls{display:flex; gap:10px;}
.slider-wrap{display:flex; flex-direction:column; gap:8px;}
input[type="range"]{width:100%;}
.slider-meta{display:flex; align-items:center; justify-content:space-between;}
.pill{
  display:inline-flex; align-items:center; justify-content:center;
  padding: 6px 10px; border-radius:999px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--stroke);
  font-weight:700;
}
.muted{color:var(--muted);}
.small{font-size:12px;}

.event-card{
  border: 1px solid var(--stroke);
  background: var(--panel2);
  border-radius: 12px;
  padding: 12px;
  display:flex; flex-direction:column; gap:8px;
}
.event-title{font-weight:700;}
.event-desc{color: rgba(255,255,255,0.86); font-size: 13px; line-height:1.35;}
.event-source{font-size: 12px; overflow-wrap:anywhere;}

#viz{flex:1; position:relative; min-width:0;}
#svg{position:absolute; inset:0; width:100%; height:100%;}
#loading{
  position:absolute; inset:0;
  display:flex; flex-direction:column;
  align-items:center; justify-content:center;
  gap: 12px;
  background: rgba(10, 12, 30, 0.55);
  backdrop-filter: blur(6px);
  z-index: 30;
}
.spinner{
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: rgba(107,92,255,0.9);
  animation: spin 900ms linear infinite;
}
@keyframes spin {to{transform:rotate(360deg);}}

#tooltip{
  position:absolute;
  pointer-events:none;
  z-index: 25;
  max-width: 320px;
  background: rgba(10, 12, 30, 0.78);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 120ms ease, transform 120ms ease;
  font-size: 12.5px;
  line-height:1.3;
}
#tooltip.show{opacity:1; transform: translateY(0px);}
#tooltip .t-title{font-weight:700; margin-bottom:4px;}
#tooltip .t-row{color:var(--muted);}

.popup{
  position:absolute; z-index:26;
  min-width: 260px; max-width: 340px;
  background: rgba(10, 12, 30, 0.82);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 120ms ease, transform 120ms ease;
}
.popup.show{opacity:1; transform: translateY(0px);}
.popup h4{margin:0 0 6px; font-size:14px;}
.popup .p-meta{font-size:12px; color:var(--muted); margin-bottom:8px;}
.popup a{color: var(--secondary); text-decoration:none;}
.popup a:hover{text-decoration:underline;}

.country{
  stroke: rgba(255,255,255,0.12);
  stroke-width: 0.6px;
  vector-effect: non-scaling-stroke;
}
.country:hover{stroke: rgba(255,255,255,0.35);}

.school{
  filter: drop-shadow(0 0 10px rgba(159,211,199,0.25)) drop-shadow(0 0 18px rgba(107,92,255,0.18));
}
  50%{transform: scale(1.12); opacity:1;}
  100%{transform: scale(1); opacity:0.85;}
}

.event-marker{
  filter: drop-shadow(0 0 14px rgba(255,209,102,0.25));
}
  50%{transform: scale(1.35); opacity:1;}
  100%{transform: scale(1); opacity:0.75;}
}

/* Modals */
/*.modal{
  position: fixed; inset:0;
  display:flex; align-items:center; justify-content:center;
  background: rgba(0,0,0,0.55);
  z-index: 50;
  padding: 20px;
}
.modal[aria-hidden="true"]{display:none;}*/

/* --- HARDENED MODAL: always viewport-fixed, always above map/panels --- */
.modal{
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;

  width: 100vw !important;
  height: 100vh !important;

  display: flex;
  align-items: center;
  justify-content: center;

  background: rgba(0,0,0,0.55);
  z-index: 9999;            /* ensure above everything */
  padding: 20px;

  pointer-events: auto;
}

.modal[aria-hidden="true"]{
  display: none !important;
}

/* Prevent background page scroll when a modal is open */
body.modal-open{
  overflow: hidden;
}

/* May be unnecessary */
.modal{
  isolation: isolate;       /* creates a clean stacking context */
}

.modal-card{
  width: min(760px, 96vw);
  background: rgba(12, 13, 28, 0.92);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow:hidden;
}
.modal-head{display:flex; align-items:center; justify-content:space-between; padding: 14px 14px 0;}
.modal-head h3{margin:0;}
.modal-body{padding: 14px;}
.sources{margin:0; padding-left: 18px; color: rgba(255,255,255,0.86);}
.made-with{margin-top: 12px; color: var(--muted);}
.made-with a{color: var(--secondary);}

@media (max-width: 900px){
  #leftPanel{width: 320px;}
}
@media (max-width: 740px){
  #main{flex-direction:column;}
  #leftPanel{
    width: 100%;
    border-right:none;
    border-bottom: 1px solid var(--stroke);
    max-height: 52vh;
    overflow:auto;
  }
}


/* Popup hierarchy helpers (no layout changes, just typographic hierarchy) */
.popup .p-desc{font-size:13px; line-height:1.35; color: rgba(255,255,255,0.88); margin: 6px 0 10px;}
.popup .p-meta{font-size:12px; color: rgba(255,255,255,0.62); margin-bottom:6px;}
.popup .p-meta strong{color: rgba(255,255,255,0.82); font-weight:700;}
/*.popup.event{
  /* different background for timeline events, matching the square marker tint
  background: rgba(255,209,102,1);
  border-color: rgba(255,209,102,0.5);
 }*/

.popup.event{
  background: rgba(12, 13, 28, 1);            /* fully opaque, dark */
  border-color: rgba(255,209,102,0.28);
  box-shadow:
    0 10px 30px rgba(0,0,0,0.45),
    inset 0 0 0 999px rgba(255,209,102,0.18); /* tint overlay, but opaque overall */
}

/* Hide the panel toggle button on desktop/tablet by default */
#btnPanel{ display: none; }

/* Mobile behavior */
@media (max-width: 740px){
  #btnPanel{ display: inline-flex; }

  /* Make the left panel an overlay drawer on mobile */
  #leftPanel{
    position: fixed;
    left: 0;
    right: 0;
    top: 56px; /* header height; adjust slightly if needed */
    height: calc(100vh - 56px);

    z-index: 60;

    transform: translateY(-110%);
    opacity: 0;
    pointer-events: none;

    transition: transform 180ms ease, opacity 180ms ease;
    max-height: none;
  }

  body.panel-open #leftPanel{
    transform: translateY(0%);
    opacity: 1;
    pointer-events: auto;
  }

  /* Optional: dim background when panel is open (no layout change) */
  #viz::after{
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
    z-index: 55;
  }

  body.panel-open #viz::after{
    opacity: 1;
    pointer-events: auto; /* allows tapping the dimmed area to close */
  }
}
