/* Mobile menu toggle (☰ / ✕) – make it always readable */
#sidebarToggleBtn{
  width: 40px;
  height: 40px;
  border-radius: 12px;

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

  font-size: 18px;
  line-height: 1;

  color: var(--text);
  background: rgba(10, 14, 20, 0.72);
  border: 1px solid rgba(255,255,255,0.14);

  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  backdrop-filter: blur(8px);
}

#sidebarToggleBtn:hover{
  background: rgba(10, 14, 20, 0.85);
  border-color: rgba(255,255,255,0.22);
}

#sidebarToggleBtn:active{
  transform: translateY(1px);
}

#sidebarToggleBtn:focus-visible{
  outline: 2px solid rgba(255,255,255,0.45);
  outline-offset: 2px;
}
/* Header left group (button + title) */
.headerLeft{
  display:flex;
  gap:10px;
  align-items:flex-start;
}

/* Hidden by default on desktop */
.sidebarToggle{ display:none; }

/* Backdrop (off by default) */
.sidebarBackdrop{
  display:none;
}

/* Better viewport height on mobile browsers handled in main .app block */
:root{
  --bg:#0b0f14;
  --panel:#101824;
  --panel2:#0f1722;
  --text:#e8eef7;
  --muted:#9aa7b5;
  --border:rgba(255,255,255,.08);
  --accent:#ff4d4d;

  --epic:#b86bff;
  --rare:#5aa7ff;
  --uncommon:#33d17a;
  --common:#c9ced6;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background: radial-gradient(1200px 700px at 70% 0%, rgba(255,77,77,.10), transparent 60%) , var(--bg);
  color:var(--text);
}

.app{
  display:grid;
  grid-template-columns: 320px 1fr;
  height:100vh;
  height:100dvh; /* override on mobile for better viewport units */
}

.sidebar{
  border-right:1px solid var(--border);
  padding:18px;
  overflow:auto;
  background: linear-gradient(180deg, rgba(255,255,255,.03), transparent 30%);
}

.brand .title{ font-weight:800; font-size:20px; }
.brand .titleRow{ display:flex; align-items:center; justify-content:space-between; gap:8px; }
.brand .subtitle{ color:var(--muted); font-size:12px; margin-top:4px; }

.panel{
  margin-top:14px;
  padding:12px;
  background: rgba(16,24,36,.75);
  border:1px solid var(--border);
  border-radius:14px;
  backdrop-filter: blur(6px);
}

.panelTitle{ font-weight:700; margin-bottom:8px; }

.label{
  display:block;
  color:var(--muted);
  font-size:12px;
  margin:10px 0 6px;
}

select,input[type="number"]{
  width:100%;
  padding:10px 10px;
  background: var(--panel2);
  border:1px solid var(--border);
  color:var(--text);
  border-radius:10px;
  outline:none;
}

input[type="range"]{ width:100%; }

.check{
  display:flex;
  gap:10px;
  align-items:center;
  margin-top:10px;
  color:var(--text);
  font-size:13px;
}

button{
  width:100%;
  margin-top:10px;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid rgba(255,77,77,.35);
  background: rgba(255,77,77,.12);
  color: var(--text);
  cursor:pointer;
  font-weight:700;
}

button:disabled{
  opacity:.45;
  cursor:not-allowed;
}

button.ghost{
  border:1px solid var(--border);
  background: transparent;
  font-weight:600;
}

/* Small icon button for inline usage */
.iconBtn{
  width:auto;
  margin-top:0;
  padding:6px 10px;
  line-height:1;
}

.row2{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap:10px;
}

/* Inline row used to edit the custom multi-target scenario */
.multiTargetsRow{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-top:10px;
}

.hint{
  margin-top:8px;
  color:var(--muted);
  font-size:12px;
}

.main{
  padding:22px;
  overflow:auto;
}

.header{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:16px;
}

.h1{ font-size:26px; font-weight:900; }
.stats{ display:flex; gap:10px; }
.stat{
  min-width:110px;
  padding:10px;
  border-radius:14px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.03);
}
.stat .k{ font-size:22px; font-weight:900; }
.stat .v{ font-size:12px; color:var(--muted); }

.tableWrap{
  margin-top:18px;
  border:1px solid var(--border);
  border-radius:14px;
  /* Allow sticky headers inside .tableScroller to work correctly */
  overflow: visible;
  background: rgba(16,24,36,.55);
  padding: 10px;
}

table{
  width:100%;
  border-collapse:collapse;
  font-size:13px;
}

/* Horizontal scroll wrapper and hint for the results table */
.tableHint{
  display:none;
  font-size:12px;
  color:var(--muted);
  margin: 6px 4px 8px;
}

.tableScroller{
  overflow-x:auto;
  overflow-y:auto;           /* enable vertical scrolling inside the table */
  max-height: 60vh;          /* cap height so it scrolls on smaller screens */
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable both-edges;
  border-radius: 12px;
  position: relative; /* helps sticky layers behave predictably */
}

.tableScroller table{
  min-width: 900px;
}

.tableScroller th,
.tableScroller td{
  white-space: nowrap;
}

.tableScroller td:first-child{ /* weapon */
  white-space: normal;
  min-width: 140px;
}
.tableScroller td:nth-child(3){ /* attachments */
  white-space: normal;
  min-width: 180px;
}

@media (max-width: 600px){
  .tableHint{ display:block; }
}

/* Sticky first column inside horizontally scrollable table */
.tableScroller th:first-child,
.tableScroller td:first-child{
  position: sticky;
  left: 0;
  z-index: 3;                /* above other cells */
  background: var(--panel2);  /* opaque to avoid bleed */
  box-shadow: 8px 0 12px rgba(0,0,0,0.28);
}

/* Header cell should be above body sticky cells */
.tableScroller thead th:first-child{
  z-index: 5;
  background: rgba(12,16,22,.92); /* match thead background */
}

thead th{
  position:sticky;
  top:0;
  z-index:5;                 /* ensure header row stays above body cells */
  background: rgba(12,16,22,.92);
  border-bottom:1px solid var(--border);
  text-align:left;
  padding:10px;
  font-weight:800;
}

tbody td{
  padding:10px;
  border-bottom:1px solid rgba(255,255,255,.05);
  vertical-align:top;
}

.num{ text-align:right; font-variant-numeric: tabular-nums; }

/* Pre-patch delta arrows (table) – match graph colors */
.cellMain{
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.num .cellMain{
  justify-content: flex-end;
  width: 100%;
}

.deltaArrow{
  display:inline-block;
  width: 1.1em;           /* keep numbers aligned */
  text-align:center;
  font-size: 11px;
  line-height: 1;
  transform: translateY(-1px);
}

/* Note: delta.dir==='up' means improved (lower is better) */
.deltaUp{ color: var(--uncommon); }
.deltaDown{ color: var(--accent); }

.deltaArrow:focus-visible{
  outline: 2px solid rgba(255,255,255,0.35);
  outline-offset: 2px;
  border-radius: 6px;
}

.badge-epic{ color:var(--epic); font-weight:800; }
.badge-rare{ color:var(--rare); font-weight:800; }
.badge-uncommon{ color:var(--uncommon); font-weight:800; }
.badge-common{ color:var(--common); font-weight:800; }
.badge-legendary{ color: #ffd54a; font-weight:800; }

.variantLink{
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: rgba(255,255,255,.25);
  cursor:pointer;
}

.weaponLink{
  color: inherit; /* keep rarity color */
  text-decoration: underline;
  text-decoration-color: rgba(255,255,255,.25);
}
.weaponLink:hover{
  text-decoration-color: rgba(255,255,255,.45);
}

/* Chart styles */
.chartCard { margin-bottom: 14px; }
.chartHeader{
  display:flex; justify-content:space-between; align-items:baseline;
  padding: 6px 2px 10px 2px;
}
.chartTitle{ font-weight:600; }
.chartMeta{ opacity:.7; font-size:12px; }

.chartWrap{ position:relative; }
#ttkChart{
  width:100%;
  height:260px;           /* JS will override height to fit weapons */
  display:block;
  border-radius:12px;
}

#compareChart{
  width:100%;
  height:260px;           /* JS will override height to fit items */
  display:block;
  border-radius:12px;
}

.chartTooltip{
  position:absolute;
  pointer-events:none;
  z-index:10;
  padding:8px 10px;
  border-radius:10px;
  background: rgba(0,0,0,0.75);
  border: 1px solid rgba(255,255,255,0.12);
  color:#fff;
  font-size:12px;
  max-width: 360px;
  white-space:nowrap;
}

/* Modal overlay container (fixed, centered) */
.modal{
  position: fixed;
  inset: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 9999;
}

.modalBox{
  width:min(720px, 96vw);
  max-height:80vh;

  /* key change */
  overflow:hidden;

  /* keep content structured so only body scrolls */
  display:flex;
  flex-direction:column;

  background: var(--panel);
  border:1px solid var(--border);
  border-radius:16px;
  padding:14px;
}

/* the scrolling area */
.modalBody{
  margin-top:10px;
  color:var(--text);
  font-size:13px;
  white-space:pre-wrap;

  /* key change */
  overflow:auto;
  flex:1 1 auto;
  min-height:0; /* IMPORTANT: allows flex child to actually shrink and scroll */

  /* optional: prevents scrollbar overlaying text */
  padding-right:6px;
}
.hidden{ display:none; }
.modalTitle{ font-weight:900; font-size:16px; }

.sub{
  margin-top:2px;
  font-size:11px;
  color:var(--muted);
}

.subRow{
  display:flex;
  gap:12px;
  justify-content:space-between;
  align-items:flex-start;
}
.subRow .sub{
  white-space:nowrap;
}

.tierChecks{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:6px;
}

.tierPill{
  display:flex;
  align-items:center;
  gap:8px;
  padding:8px 10px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.03);
  font-size:13px;
}

th.sortable{
  cursor:pointer;
  user-select:none;
  padding-right: 20px; /* reserve space for arrow to avoid width shifts */
}

th.sortable:hover{
  background: rgba(255,255,255,.06);
}

.sortArrow{
  opacity:.65;
  font-size:11px;
  position:absolute;
  right:8px;
  top:50%;
  transform: translateY(-50%);
}

/* Compare chart controls */
.chartControls{
  display:flex;
  gap:10px;
  align-items:flex-end;
  flex-wrap:wrap;
}

.chartControlsLeft{
  margin-top: 8px;
  justify-content: flex-start;
  align-items: flex-start;
}

.chartCtl{
  display:flex;
  flex-direction:column;
  gap:4px;
  font-size:12px;
  opacity:.9;
}

.chartCtlInline{
  display:flex;
  align-items:center;
  gap:10px;
}
.chartCtlInline input[type="checkbox"]{
  transform: translateY(1px);
}

.chartCtl select{
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 10px;
  outline: none;
  width: 200px;
  box-sizing: border-box;
}

.chartCtl input{
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 10px;
  outline: none;
  width: 200px;
  box-sizing: border-box;
}

.chartScaleInput{
  width: 110px; /* small field on the right */
}

/* Table control: match chart controls spacing */
.tableWrap > .chartCtl{
  margin: 0 0 10px 0;
}

/* Compare chart header: left column (title+controls) and right small controls */
#compareCard .chartHeader{
  justify-content: space-between;
  align-items: baseline;
  flex-direction: row;
  gap: 8px;
}

/* Global chart controls row */
.chartGlobalControls{
  display:flex;
  justify-content:flex-start;
  align-items:flex-end;
  gap: 12px;
  margin: 0 0 10px 0;
}

/* Header row with toggle button */
.headerLeft{
  display:flex;
  gap:10px;
  align-items:flex-start;
}

/* Removed conflicting mobile drawer rules that used sidebar-collapsed */

/* ===== Mobile drawer sidebar (single source of truth) ===== */
@media (max-width: 900px){

  :root{ --drawer-w: min(340px, 92vw); }

  /* Don’t reserve a left column on mobile */
  .app{
    grid-template-columns: 1fr;
  }

  /* Make sure main fills the whole width */
  .main{
    padding: 14px;
    padding-top: 56px; /* space for the fixed ☰/✕ button */
    overflow: auto;
  }

  /* Show the toggle button on mobile */
  .sidebarToggle{
    display: inline-flex;
  }

  /* Keep the toggle button always clickable (even when sidebar is open) */
  #sidebarToggleBtn{
    position: fixed;
    top: 12px;
    left: 12px;                 /* ☰ position when closed */
    z-index: 2105;
    transition: left .18s ease;  /* slide with drawer */
  }

  body.sidebar-open #sidebarToggleBtn{
    left: min(calc(var(--drawer-w) + 12px), calc(100vw - 52px));
  }

  /* Sidebar becomes an off-canvas drawer */
  .sidebar{
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;

    width: var(--drawer-w);
    z-index: 2100;

    transform: translateX(-105%);
    transition: transform .18s ease;
    overflow: auto;

    border-right: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(255,255,255,.03), transparent 30%), var(--bg);
  }

  body.sidebar-open .sidebar{
    transform: translateX(0);
  }

  /* Backdrop only active when open */
  .sidebarBackdrop{
    display: block;
    position: fixed;
    inset: 0;
    z-index: 2090;
    background: rgba(0,0,0,.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
  }

  body.sidebar-open .sidebarBackdrop{
    opacity: 1;
    pointer-events: auto;
  }

  /* Prevent the page behind from scrolling when the drawer is open */
  body.sidebar-open{
    overflow: hidden;
  }
}
