:root{
  --bg:#0b0e14;
  --panel:#0f1420;
  --panel2:#111a2b;
  --text:#e9eefc;
  --muted:#9fb0d0;
  --line:rgba(255,255,255,0.08);
  --accent:#66a6ff;
  --accent2:#8a6bff;
  --danger:#ff4d4d;

  --radius:14px;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
}

*{ box-sizing:border-box; }
html,body{ height:100%; margin:0; font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial; background:var(--bg); color:var(--text); }

.topbar{
  position:sticky; top:0; z-index:50;
  display:flex; align-items:center; justify-content:space-between;
  padding:10px 12px;
  background: linear-gradient(180deg, rgba(16,22,34,0.95), rgba(11,14,20,0.85));
  border-bottom:1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand{
  text-decoration:none;
  color:var(--text);
  font-weight:700;
  letter-spacing:0.2px;
  padding:8px 10px;
  border-radius:999px;
  border:1px solid var(--line);
  background:rgba(255,255,255,0.03);
}

.topbarRight{ display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; }

.btn{
  appearance:none; border:1px solid var(--line);
  background:rgba(255,255,255,0.03);
  color:var(--text);
  padding:10px 12px;
  border-radius:12px;
  font-weight:600;
  cursor:pointer;
}
.btn:hover{ border-color: rgba(255,255,255,0.18); }
.btn:active{ transform: translateY(1px); }

.btn.primary{
  border-color: rgba(102,166,255,0.45);
  background: rgba(102,166,255,0.12);
}
.btn.ghost{ background:transparent; }
.btn.full{ width:100%; }
.btn.small{ padding:8px 10px; border-radius:10px; font-size:13px; }
.btn.danger{ border-color: rgba(255,77,77,0.4); background: rgba(255,77,77,0.1); }

.app{
  display:grid;
  grid-template-columns: 1fr minmax(320px, 420px);
  gap:12px;
  height: calc(100vh - 54px);
  padding:12px;
}

.viewer{
  min-width:0;
  display:flex;
  flex-direction:column;
  border-radius: var(--radius);
  overflow:hidden;
  border:1px solid var(--line);
  background: radial-gradient(1200px 500px at 40% 10%, rgba(102,166,255,0.10), transparent 60%),
              radial-gradient(900px 500px at 70% 90%, rgba(138,107,255,0.10), transparent 60%),
              rgba(255,255,255,0.02);
  box-shadow: var(--shadow);
}

.viewerStage{
  position:relative;
  flex:1;
  min-height:200px;
}

.glCanvas, .maskCanvas{
  position:absolute; inset:0;
  width:100%;
  height:100%;
  display:block;
}

.maskCanvas{
  pointer-events:none;
  mix-blend-mode: screen;
  opacity:0.55;
}

.hud{
  position:absolute; left:10px; top:10px;
  display:flex; flex-direction:column; gap:8px;
  pointer-events:none;
}
.hudRow{ display:flex; gap:8px; flex-wrap:wrap; }
.pill{
  font-size:13px;
  padding:6px 10px;
  border-radius:999px;
  border:1px solid var(--line);
  background:rgba(0,0,0,0.25);
  color:var(--text);
}

.bottomBar{
  display:flex; justify-content:space-between; align-items:center;
  gap:12px;
  padding:10px;
  border-top:1px solid var(--line);
  background: rgba(0,0,0,0.18);
  backdrop-filter: blur(8px);
}

.bottomLeft{ display:flex; gap:8px; flex-wrap:wrap; }
.seg{
  border:1px solid var(--line);
  background:rgba(255,255,255,0.03);
  color:var(--text);
  padding:10px 12px;
  border-radius:999px;
  cursor:pointer;
  font-weight:700;
}
.seg.active{
  border-color: rgba(102,166,255,0.45);
  background: rgba(102,166,255,0.12);
}

.bottomRight{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.mini{
  display:flex; align-items:center; gap:8px;
  padding:8px 10px;
  border-radius:999px;
  border:1px solid var(--line);
  background:rgba(255,255,255,0.02);
  font-size:13px;
  color:var(--muted);
}
.mini select{
  background:transparent; color:var(--text);
  border:1px solid var(--line);
  border-radius:10px;
  padding:6px 8px;
}

.panel{
  min-width:0;
  display:flex;
  flex-direction:column;
  border-radius: var(--radius);
  border:1px solid var(--line);
  background: linear-gradient(180deg, rgba(15,20,32,0.90), rgba(15,20,32,0.75));
  box-shadow: var(--shadow);
  overflow:hidden;
  transition: transform 200ms ease, opacity 200ms ease;
}

.panel.closed{
  transform: translateX(12px);
  opacity:0;
  pointer-events:none;
}

.panelHeader{
  display:flex; align-items:center; justify-content:space-between;
  padding:12px;
  border-bottom:1px solid var(--line);
  background: rgba(0,0,0,0.18);
}

.panelTitle{ font-weight:900; letter-spacing:0.2px; }

.iconBtn{
  border:1px solid var(--line);
  background:rgba(255,255,255,0.03);
  color:var(--text);
  width:40px; height:36px;
  border-radius:12px;
  cursor:pointer;
}

.panelBody{
  padding:10px;
  overflow:auto; /* internal scrolling */
}

.group{
  border:1px solid var(--line);
  border-radius: 14px;
  margin:10px 0;
  background: rgba(255,255,255,0.02);
  overflow:hidden;
}

.groupSummary{
  cursor:pointer;
  padding:12px;
  display:flex; align-items:center; justify-content:space-between;
  gap:10px;
  background: rgba(255,255,255,0.02);
  border-bottom:1px solid rgba(255,255,255,0.04);
}

.groupTitle{
  font-weight:900;
}
.hint{
  color:var(--muted);
  font-size:12px;
  font-weight:700;
}

.groupBody{ padding:12px; display:flex; flex-direction:column; gap:12px; }

.slider{
  display:grid;
  grid-template-columns: 1fr 1fr auto;
  gap:10px;
  align-items:center;
}
.slider label{ font-weight:800; color:var(--text); font-size:13px; }
.slider input[type="range"]{ width:100%; }
.val{
  min-width:54px;
  text-align:right;
  color:var(--muted);
  font-weight:900;
  font-variant-numeric: tabular-nums;
}

.row{ display:flex; gap:10px; align-items:center; }
.kv{
  flex:1;
  border:1px solid var(--line);
  border-radius:12px;
  padding:10px;
  background: rgba(0,0,0,0.18);
}
.k{ font-size:12px; color:var(--muted); font-weight:800; }
.v{ font-size:13px; font-weight:900; margin-top:6px; }

.infoBox{
  border:1px solid rgba(102,166,255,0.25);
  background: rgba(102,166,255,0.08);
  border-radius:14px;
  padding:10px;
}
.infoTitle{ font-weight:900; }
.infoText{ color:var(--muted); font-weight:700; font-size:13px; margin-top:6px; line-height:1.4; }

.tabs{
  display:flex; gap:6px; flex-wrap:wrap;
}
.tab{
  border:1px solid var(--line);
  background: rgba(255,255,255,0.02);
  color:var(--text);
  font-weight:900;
  padding:8px 10px;
  border-radius:999px;
  cursor:pointer;
  font-size:13px;
}
.tab.active{
  border-color: rgba(102,166,255,0.45);
  background: rgba(102,166,255,0.12);
}

.curveTop{
  display:flex;
  justify-content:space-between;
  gap:10px;
  flex-wrap:wrap;
}
.curveTabs{ display:flex; gap:8px; flex-wrap:wrap; }
.cTab{
  border:1px solid var(--line);
  background: rgba(255,255,255,0.02);
  color:var(--text);
  font-weight:900;
  padding:8px 10px;
  border-radius:999px;
  cursor:pointer;
  font-size:13px;
}
.cTab.active{
  border-color: rgba(138,107,255,0.45);
  background: rgba(138,107,255,0.12);
}

.curveWrap{
  border:1px solid var(--line);
  border-radius:14px;
  overflow:hidden;
  background: rgba(0,0,0,0.25);
}
#curveCanvas{
  width:100%;
  height:auto;
  display:block;
}

.note{
  color: var(--muted);
  font-size:13px;
  font-weight:700;
  line-height:1.4;
}

.helpList{
  margin:0;
  padding-left:18px;
  color:var(--muted);
  font-weight:700;
  line-height:1.6;
}

/* Tablet / narrow layouts */
@media (max-width: 980px){
  .app{ grid-template-columns: 1fr; }
  .panel{
    position:fixed;
    top:56px;
    right:12px;
    bottom:12px;
    width:min(420px, calc(100vw - 24px));
    z-index:100;
  }
}
/* ---------- Modern Scrollbar (Right Panel) ---------- */
.panelBody{
  scrollbar-width: thin;                 /* Firefox */
  scrollbar-color: rgba(255,255,255,0.18) rgba(255,255,255,0.04);
}

/* Chromium/Edge/Safari */
.panelBody::-webkit-scrollbar{
  width: 10px;
}
.panelBody::-webkit-scrollbar-track{
  background: rgba(255,255,255,0.03);
  border-radius: 999px;
  margin: 10px;                          /* creates "floating" track */
}
.panelBody::-webkit-scrollbar-thumb{
  background: linear-gradient(
    180deg,
    rgba(102,166,255,0.20),
    rgba(255,255,255,0.14)
  );
  border: 2px solid rgba(0,0,0,0.20);    /* makes it look refined */
  border-radius: 999px;
}
.panelBody::-webkit-scrollbar-thumb:hover{
  background: linear-gradient(
    180deg,
    rgba(102,166,255,0.28),
    rgba(255,255,255,0.18)
  );
}

/* Optional: reduce scroll bar visual weight further on mobile */
@media (max-width: 980px){
  .panelBody::-webkit-scrollbar{ width: 8px; }
  .panelBody::-webkit-scrollbar-track{ margin: 8px; }
}
/* ---------- On-canvas Quick Controls ---------- */
.quickControls{
  position:absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display:flex;
  align-items:center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 28px rgba(0,0,0,0.35);
  z-index: 20;
  max-width: calc(100% - 24px);
  overflow: hidden;
}

.qcGroup{
  display:flex;
  align-items:center;
  gap: 8px;
}

.qcBtn{
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  height: 36px;
  min-width: 44px;            /* touch-friendly */
  padding: 0 10px;
  border-radius: 999px;
  font-weight: 900;
  cursor: pointer;
}

.qcBtn:hover{ border-color: rgba(255,255,255,0.18); }
.qcBtn:active{ transform: translateY(1px); }

.qcSlider{
  width: 160px;
  height: 36px;
}

.qcDivider{
  width: 1px;
  height: 28px;
  background: rgba(255,255,255,0.12);
}

/* Make sliders shorter on smaller screens */
@media (max-width: 560px){
  .qcSlider{ width: 120px; }
  .qcBtn{ min-width: 40px; }
}
