:root{
  --bg: #0b0e13;
  --paper: #0f141d;
  --ink: #e8eef7;
  --muted: rgba(232,238,247,.72);

  --stroke: rgba(232,238,247,.18);
  --stroke2: rgba(232,238,247,.10);

  --juvenile: #5ed3ff;
  --adult: #ffb86b;
  --other: #b18cff;

  --shadow: 0 12px 40px rgba(0,0,0,.42);
  --radius: 14px;

  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  background: radial-gradient(1200px 700px at 30% -10%, rgba(94,211,255,.14), transparent 55%),
              radial-gradient(900px 600px at 110% 10%, rgba(255,184,107,.10), transparent 60%),
              var(--bg);
  color:var(--ink);
  overflow:hidden;
}

a{color:inherit}
code{font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace}
.muted{color:var(--muted)}
.sr-only{position:absolute; left:-9999px; width:1px; height:1px; overflow:hidden}

.topbar{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  padding: calc(12px + var(--safe-top)) 12px 10px;
  gap:10px;
}

.topbar__title h1{
  margin:0;
  font-size: 16px;
  letter-spacing: .2px;
  line-height: 1.2;
}
.topbar__title p{
  margin:6px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.25;
  max-width: 62ch;
}

.topbar__actions{display:flex; gap:8px; align-items:center}
.iconbtn{
  width:38px; height:38px;
  border-radius: 12px;
  border:1px solid var(--stroke2);
  background: rgba(255,255,255,.04);
  color:var(--ink);
  display:grid;
  place-items:center;
  box-shadow: 0 8px 24px rgba(0,0,0,.26);
  cursor:pointer;
}
.iconbtn:active{transform: translateY(1px)}
.ghostbtn{
  border:1px solid var(--stroke2);
  background: transparent;
  color:var(--ink);
  border-radius: 10px;
  padding: 8px 10px;
  cursor:pointer;
}

.app{
  height: calc(100% - 64px);
  display:flex;
  gap:12px;
  padding: 0 12px calc(12px + var(--safe-bottom));
}

.mapwrap{
  position:relative;
  flex: 1 1 auto;
  min-width: 0;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--stroke2);
  border-radius: var(--radius);
  overflow:hidden;
  box-shadow: var(--shadow);
}

.viz{width:100%; height:100%}

/* Legend: mobile overlay drawer */
.legend{
  position:absolute;
  inset: 72px 12px 12px 12px;
  background: rgba(15,20,29,.92);
  border: 1px solid var(--stroke2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  display:block;
  transform: translateY(0);
  transition: transform .22s ease, opacity .22s ease;
  backdrop-filter: blur(10px);
}
.legend.is-collapsed{
  transform: translateY(calc(100% + 18px));
  opacity: 0;
  pointer-events:none;
}
.legend__header{display:flex; justify-content:space-between; align-items:center; gap:10px}
.legend h2{margin:0; font-size: 14px}
.legend h3{margin:14px 0 8px; font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing:.3px}
.legend__section{border-top: 1px solid var(--stroke2); margin-top: 10px; padding-top: 10px}
.legend__row{display:flex; gap:10px; align-items:flex-start; margin:10px 0}
.legend__label{font-size: 12px; font-weight: 700}
.legend__note{font-size: 12px; color:var(--muted); margin-top:4px}
.legend__bullets{margin: 8px 0 0; padding-left: 18px; color:var(--muted); font-size: 12px}
.legend__kvs{display:grid; gap:8px}
.kv{display:flex; align-items:center; gap:8px; font-size: 12px; color:var(--muted)}
.chip{width:10px; height:10px; border-radius: 4px; display:inline-block}
.legend__footer{margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--stroke2)}
.attrib{font-size: 11px; color: var(--muted); line-height: 1.3}

.swatch{width:34px; height:34px; border-radius: 12px; display:grid; place-items:center}
.swatch.hole{
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.92) 0 42%, rgba(0,0,0,.28) 46% 52%, transparent 55%),
    rgba(255,255,255,.04);
  border:1px solid var(--stroke2);
}

/* Tooltip (desktop) */
.tooltip{
  position:absolute;
  min-width: 220px;
  max-width: 320px;
  padding: 10px 10px;
  background: rgba(15,20,29,.95);
  border:1px solid var(--stroke2);
  border-radius: 12px;
  box-shadow: var(--shadow);
  pointer-events:none;
  opacity:0;
  transform: translateY(6px);
  transition: opacity .12s ease, transform .12s ease;
}
.tooltip.is-open{opacity:1; transform: translateY(0)}
.tip__title{font-weight:800; font-size: 13px}
.tip__sub{margin-top:4px; color:var(--muted); font-size: 12px}
.tip__grid{margin-top:8px; display:grid; grid-template-columns: 1fr 1fr; gap:6px}
.tip__k{color:var(--muted); font-size: 11px}
.tip__v{font-size: 12px; font-weight: 700}

/* Mobile bottom sheet */
.sheet{
  position:absolute;
  left:0; right:0; bottom:0;
  transform: translateY(110%);
  transition: transform .22s ease;
  background: rgba(15,20,29,.96);
  border-top: 1px solid var(--stroke2);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  padding-bottom: calc(10px + var(--safe-bottom));
}
.sheet.is-open{transform: translateY(0)}
.sheet__grab{
  width: 52px; height: 5px;
  border-radius: 10px;
  background: rgba(255,255,255,.18);
  margin: 10px auto 8px;
}
.sheet__content{padding: 0 14px 10px; position:relative}
.sheet__close{
  position:absolute;
  right: 10px; top: -2px;
  width: 36px; height: 36px;
  border-radius: 12px;
  border:1px solid var(--stroke2);
  background: rgba(255,255,255,.04);
  color:var(--ink);
  cursor:pointer;
}
.sheet__close:active{transform: translateY(1px)}

/* Loading */
.loading{
  position:absolute;
  inset:0;
  display:flex;
  gap:12px;
  align-items:center;
  justify-content:center;
  background: rgba(11,14,19,.72);
  backdrop-filter: blur(8px);
}
.spinner{
  width:20px; height:20px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.24);
  border-top-color: rgba(255,255,255,.85);
  animation: spin 1s linear infinite;
}
@keyframes spin{to{transform: rotate(360deg)}}
.loading__title{font-weight:800; font-size: 13px}
.loading__sub{color:var(--muted); font-size: 12px; margin-top:2px}

/* Modal */
.modal__backdrop{
  position:fixed;
  inset:0;
  display:grid;
  place-items:center;
  padding: 16px;
  background: rgba(0,0,0,.55);
  opacity:0;
  pointer-events:none;
  transition: opacity .18s ease;
}
.modal__backdrop.is-open{opacity:1; pointer-events:auto}
.modal{
  width:min(720px, 100%);
  max-height: min(82vh, 780px);
  overflow:auto;
  background: rgba(15,20,29,.98);
  border:1px solid var(--stroke2);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.modal__header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--stroke2);
}
.modal__header h2{margin:0; font-size: 14px}
.modal__body{padding: 12px; color: var(--muted); font-size: 13px; line-height: 1.45}

/* Desktop: legend becomes right panel */
@media (min-width: 980px){
  .topbar{padding: 16px 16px 12px}
  .topbar__title h1{font-size: 18px}
  .topbar__title p{font-size: 13px}
  .app{padding: 0 16px 16px; height: calc(100% - 80px)}
  .legend{
    position:relative;
    inset:auto;
    width: 340px;
    flex: 0 0 340px;
    transform:none !important;
    opacity: 1 !important;
    pointer-events:auto !important;
  }
}

/* SVG styling */
svg{width:100%; height:100%}
.state{
  fill: rgba(232,238,247,.06);
  stroke: rgba(232,238,247,.16);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.state.is-hover{
  fill: rgba(232,238,247,.10);
  stroke: rgba(232,238,247,.30);
}
.symbol-ring{filter: drop-shadow(0 10px 18px rgba(0,0,0,.40))}
.hole-symbol{filter: drop-shadow(0 10px 18px rgba(0,0,0,.34))}
