html, body { 
  height: 100%; 
  margin: 0; 
  color: var(--text);
}
#wrap { position: relative; width: 100%; height: 100%; overflow: hidden; }
canvas { width: 100%; height: 100%; display:block; touch-action:none; }

.hud { position:absolute; left:12px; top:12px; display:flex; gap:10px; flex-wrap:wrap; pointer-events:none; }
.pill {
  pointer-events:auto;
  background: rgba(20,24,36,.85);
  border: 1px solid rgba(120,140,255,.18);
  border-radius: 999px;
  padding: 8px 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
  display:flex; gap:10px; align-items:center;
}
.pill button {
  background: rgba(255,255,255,.06);
  color:#e8ecff;
  border: 1px solid rgba(120,140,255,.18);
  border-radius: 10px;
  padding: 6px 10px;
  cursor:pointer;
}
.pill button:hover { background: rgba(255,255,255,.10); }

#panel {
  position:absolute; right:12px; bottom:12px; width:min(440px, calc(100% - 24px));
  background: rgba(20,24,36,.85);
  border: 1px solid rgba(120,140,255,.18);
  border-radius: 18px;
  padding: 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
}
#panel h3 { margin: 0 0 6px 0; font-size: 16px; }
#panel .muted { color: rgba(232,236,255,.72); font-size: 13px; line-height: 1.35; }
#panel .row { margin-top:10px; display:flex; gap:10px; flex-wrap:wrap; align-items:center;}
#panel .row button { background: rgba(255,255,255,.06); border:1px solid rgba(120,140,255,.18); color:#e8ecff; border-radius:12px; padding:8px 10px; cursor:pointer; }
#panel .row button:hover { background: rgba(255,255,255,.10); }

.hint { position:absolute; left:12px; bottom:12px; color: rgba(232,236,255,.55); font-size: 12px; user-select:none; }

/* Active bonuses panel (top-right) */
#activePanel{
  position:absolute; right:12px; top:12px; width:min(360px, calc(100% - 24px));
  background: rgba(20,24,36,.85);
  border: 1px solid rgba(120,140,255,.18);
  border-radius: 18px;
  padding: 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
  max-height: min(46vh, 520px);
  overflow:auto;
}
#activePanel h3{ margin:0 0 6px 0; font-size: 16px; }
#activePanel .muted{ color: rgba(232,236,255,.72); font-size: 13px; line-height: 1.35; }
#activePanel ul{ margin: 8px 0 0 0; padding-left: 18px; }
#activePanel li{ margin: 4px 0; }

/* Toggle button + backdrop for mobile active bonuses drawer */
#activeToggle{
  position:absolute;
  right: 12px;
  top: 12px;
  z-index: 60;
  pointer-events: auto;
  background: rgba(20,24,36,.85);
  border: 1px solid rgba(120,140,255,.18);
  border-radius: 999px;
  padding: 8px 12px;
  color: #e8ecff;
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
  display:none; /* shown on mobile via media query */
  align-items:center;
  gap:8px;
  font-size: 13px;
  line-height: 1;
}
#activeToggle:active{ transform: translateY(1px); }

#activeBackdrop{
  position:absolute;
  inset:0;
  background: rgba(0,0,0,.45);
  opacity:0;
  pointer-events:none;
  transition: opacity 180ms ease;
  z-index: 55;
}
#activeBackdrop.is-on{ opacity:1; pointer-events:auto; }

@media (max-width: 768px){
  /* On mobile: turn the panel into a slide-out drawer */
  #activeToggle{ display:flex; }

  #activePanel{
    top: 0;
    right: 0;
    bottom: 0;
    width: min(86vw, 360px);
    max-height: none;
    height: 100%;
    border-radius: 18px 0 0 18px;
    transform: translate3d(110%, 0, 0);
    transition: transform 220ms cubic-bezier(.2,.8,.2,1);
    z-index: 56;
    overflow: auto;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom)) 12px;
  }
  body.active-open #activePanel{ transform: translate3d(0,0,0); }
}

/* Desktop panel title */
#panel > #ptitle{ margin: 0 0 6px 0; font-size: 16px; }

/* Tooltip near cursor on node hover */
#tooltip{
  position:absolute;
  z-index: 50;
  max-width: 280px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(20,24,36,.92);
  border: 1px solid rgba(120,140,255,.18);
  box-shadow: 0 10px 28px rgba(0,0,0,.45);
  backdrop-filter: blur(8px);
  color:#e8ecff;
  font-size: 12.5px;
  line-height: 1.3;
  pointer-events:none;
  display:none;
  transform: translate3d(0,0,0);
}
#tooltip .t-title{ font-weight: 650; font-size: 13px; margin-bottom: 4px; }
#tooltip .t-desc{
  color: rgba(232,236,255,.78);
  white-space: pre-line;
}

#pdesc{
  white-space: pre-line;
}

/* ---- Mobile bottom sheet ---- */
#sheetBackdrop{
  position:absolute; inset:0;
  background: rgba(0,0,0,.45);
  opacity:0; pointer-events:none;
  transition: opacity 180ms ease;
}

/* Default panel styles (desktop) stay as-is, we only enhance mobile UX below */
.bottom-sheet .sheet-header{ display:none; }
.bottom-sheet .sheet-content{ }

@media (max-width: 768px){

  /* Hide desktop title inside panel on mobile to avoid duplicates */
  #panel.bottom-sheet > #ptitle{ display:none; }

  html, body { height:100%; overflow:hidden; }

  /* Backdrop becomes active when sheet is expanded */
  #sheetBackdrop.is-on{ opacity:1; pointer-events:auto; }

  /* Convert the info panel into a draggable bottom sheet */
  #panel.bottom-sheet{
    position:absolute;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    margin: 0;
    border-radius: 18px 18px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding: 0;
    box-sizing: border-box;

    /* Sheet geometry */
    height: calc(85vh + env(safe-area-inset-bottom));
    max-height: calc(100vh - 8px);
    transform: translate3d(0, var(--sheetY, 0px), 0);
    transition: transform 220ms cubic-bezier(.2,.8,.2,1);
    will-change: transform;
    touch-action: none; /* sheet handles its own gestures */
    display:flex;
    flex-direction: column;
  }

  #panel.bottom-sheet.is-dragging{ transition:none; }

  #panel.bottom-sheet .sheet-header{
    display:flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 14px 8px 14px;
    border-bottom: 1px solid rgba(120,140,255,.12);
    user-select:none;
    -webkit-user-select:none;
  }

  #panel.bottom-sheet .sheet-handle{
    width: 44px;
    height: 5px;
    border-radius: 999px;
    background: rgba(232,236,255,.35);
    margin: 2px auto 0 auto;
  }

  #panel.bottom-sheet .sheet-titlebar h3{
    margin: 0;
    font-size: 16px;
    line-height: 1.2;
  }

  #panel.bottom-sheet .sheet-content{
    padding: 10px 14px calc(14px + env(safe-area-inset-bottom)) 14px;
    overflow:auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y; /* allow scroll inside content */
  }

  /* Keep HUD readable above */
  .hud{ top: 10px; left: 10px; right: 10px; }
}

/* ===== Site header (logo + main nav) ===== */
.siteHeader{
  display:flex;
  gap:14px;
  align-items:center;
  justify-content:space-between;
  padding:12px 14px;


  background:linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.012));
  box-shadow:var(--shadow);
}

.brand{
  display:flex;
  align-items:center;
  gap:10px;
  text-decoration:none;
  color:var(--text);
  min-width:180px;
}

.brandLogo{
  width:34px;
  height:34px;
  display:block;
  object-fit:contain;
  border-radius:10px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(0,0,0,.25);
}

.brandText{
  font-weight:800;
  letter-spacing:.02em;
}

.siteNav{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  justify-content:flex-end;
}

.siteNav a{
  text-decoration:none;
  color:var(--muted);
  padding:8px 10px;
  border-radius:10px;
  border:1px solid transparent;
  background:rgba(0,0,0,.10);
  transition:all .15s ease;
}

.siteNav a:hover{
  color:var(--text);
  border-color:rgba(122,162,255,.25);
  background:rgba(122,162,255,.06);
}

.siteNav a.is-active{
  color:#fff;
  border-color:rgba(122,162,255,.45);
  background:rgba(122,162,255,.12);
  box-shadow: 0 0 0 2px rgba(122,162,255,.10) inset;
}

@media (max-width: 720px){
  .siteHeader{
    flex-direction:column;
    align-items:flex-start;
  }
  .brand{min-width:0}
  .siteNav{justify-content:flex-start}
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#app {
  flex: 1;
}

/* ===== Mobile burger menu ===== */

.burgerBtn{
  display:none;
  width:44px;
  height:44px;
  border-radius:12px;
  border:1px solid rgba(122,162,255,.25);
  background:rgba(0,0,0,.18);
  color:var(--text);
  cursor:pointer;
  box-shadow: 0 8px 18px rgba(0,0,0,.25);
  align-items:center;
  justify-content:center;
}

.burgerBtn:hover{
  border-color:rgba(122,162,255,.45);
  background:rgba(122,162,255,.08);
}

.burgerIcon{
  display:block;
  width:18px;
  height:2px;
  background:currentColor;
  position:relative;
  border-radius:2px;
}
.burgerIcon::before,
.burgerIcon::after{
  content:"";
  position:absolute;
  left:0;
  width:18px;
  height:2px;
  background:currentColor;
  border-radius:2px;
}
.burgerIcon::before{ top:-6px; }
.burgerIcon::after{ top:6px; }

.navOverlay{
  position:fixed;
  inset:0;
  z-index:9999;
  background:rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
}

.navOverlay[hidden]{ display:none; }

.navPanel{
  position:absolute;
  inset:0;
  padding:18px 16px 22px;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(122,162,255,.15), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(115,246,208,.10), transparent 55%),
    var(--bg);
  overflow:auto;
}

.navClose{
  position:sticky;
  top:0;
  margin-left:auto;
  display:flex;
  align-items:center;
  justify-content:center;
  width:44px;
  height:44px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(0,0,0,.20);
  color:var(--text);
  cursor:pointer;
}

.navClose:hover{
  border-color:rgba(122,162,255,.45);
  background:rgba(122,162,255,.08);
}

.navMobile{
  margin-top:10px;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.navMobile a{
  text-decoration:none;
  color:var(--text);
  padding:14px 14px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(0,0,0,.18);
}

.navMobile a:hover{
  border-color:rgba(122,162,255,.35);
  background:rgba(122,162,255,.08);
}

.navMobile a.is-active{
  border-color:rgba(122,162,255,.55);
  background:rgba(122,162,255,.14);
  box-shadow: 0 0 0 2px rgba(122,162,255,.10) inset;
}

/* На мобилках прячем обычное меню и показываем бургер */
@media (max-width:720px){
  .siteHeader{
    flex-direction:row;         /* возвращаем в линию */
    align-items:center;
  }
  .siteNav{ display:none; }
  .burgerBtn{ display:inline-flex; }
}

/* Чтобы не скроллилась страница под меню */
body.nav-open{ overflow:hidden; }