:root{
  --bg:#0b0f14; --panel:#111823; --panel2:#0f1620; --txt:#e8eef8; --muted:#9bb0c9;
  --accent:#67d1ff; --danger:#ff5c7a; --ok:#7dff9b; --radius:14px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}
*{box-sizing:border-box}
html,body{height:100%; margin:0; background:var(--bg); color:var(--txt);
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif}
a{color:var(--accent); text-decoration:none}
#app{height:100%; display:grid; grid-template-rows:auto 1fr; gap:10px; padding:10px}
#top{
  background:linear-gradient(180deg,var(--panel),var(--panel2));
  border:1px solid rgba(255,255,255,.07);
  border-radius:var(--radius);
  padding:10px;
  display:flex; flex-wrap:wrap; align-items:center;
  gap:10px 12px;
}
.group{display:flex; align-items:center; gap:8px; padding:6px 8px;
  background:rgba(255,255,255,.03); border:1px solid rgba(255,255,255,.06); border-radius:12px}
label{font-size:12px; color:var(--muted); font-weight:900; letter-spacing:.25px}
select,input[type="range"],input[type="text"]{accent-color:var(--accent)}
select{
  background:rgba(255,255,255,.04); color:var(--txt);
  border:1px solid rgba(255,255,255,.10);
  border-radius:12px;
  padding:8px 10px;
  font-weight:900;
  cursor:pointer;
}
input[type="file"]{color:var(--muted); font-weight:800}
.btn{
  appearance:none; border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.04);
  color:var(--txt);
  padding:8px 10px;
  border-radius:12px;
  cursor:pointer;
  font-weight:900;
  letter-spacing:.2px;
  transition:transform .06s ease, background .15s ease, border-color .15s ease;
  user-select:none;
}
.btn:hover{background:rgba(255,255,255,.07); border-color:rgba(255,255,255,.16)}
.btn:active{transform:translateY(1px)}
.btn.primary{border-color:rgba(103,209,255,.35); box-shadow:0 0 0 2px rgba(103,209,255,.10) inset}
.btn.danger{border-color:rgba(255,92,122,.35); box-shadow:0 0 0 2px rgba(255,92,122,.10) inset}
.pill{
  padding:6px 10px; border-radius:999px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.03);
  color:var(--muted);
  font-size:12px;
  white-space:nowrap;
}
#main{
  min-height:0;
  display:grid;
  grid-template-columns: 340px 1fr;
  gap:10px;
}
#sidebar{
  min-height:0;
  background:linear-gradient(180deg,var(--panel),var(--panel2));
  border:1px solid rgba(255,255,255,.07);
  border-radius:var(--radius);
  overflow:hidden;
  box-shadow:var(--shadow);
  display:flex;
  flex-direction:column;
}
#sideTabs{
  display:flex;
  gap:6px;
  padding:10px;
  border-bottom:1px solid rgba(255,255,255,.06);
  flex-wrap:wrap;
  align-content:flex-start;
  position:sticky;
  top:0;
  background:linear-gradient(180deg,var(--panel),var(--panel2));
  z-index:5;
}
#sideTabs::-webkit-scrollbar{height:8px}
#sideTabs::-webkit-scrollbar-thumb{background:rgba(255,255,255,.15); border-radius:999px}

.tab{
  flex:1 0 46%;
  min-width:110px;
  padding:10px 10px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.03);
  color:var(--muted);
  font-weight:950;
  cursor:pointer;
}
.tab.active{
  background:rgba(103,209,255,.10);
  border-color:rgba(103,209,255,.25);
  color:var(--txt);
}
#sideContent{min-height:0; overflow:auto; padding:10px}
.card{
  background:rgba(255,255,255,.03);
  border:1px solid rgba(255,255,255,.07);
  border-radius:14px;
  padding:12px;
  margin-bottom:10px;
}
.card h3{margin:0 0 8px 0; font-size:13px; color:var(--txt); letter-spacing:.2px}
.small{font-size:12px; color:var(--muted); line-height:1.35}
.grid{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap:10px;
}
.sticker{
  position:relative;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.04);
  padding:10px;
  cursor:pointer;
  transition:transform .08s ease, background .15s ease, border-color .15s ease;
}
.sticker:hover{transform:translateY(-1px); background:rgba(255,255,255,.06); border-color:rgba(103,209,255,.22)}
.sticker img{width:100%; height:70px; object-fit:contain; display:block; filter:drop-shadow(0 10px 18px rgba(0,0,0,.35))}
.sticker .name{margin-top:8px; font-size:11px; color:var(--muted); font-weight:900; text-align:center}
.row{display:flex; gap:10px; flex-wrap:wrap; align-items:center}
.field{display:flex; flex-direction:column; gap:6px}
.field input[type="range"]{width:200px}
.kbd{
  display:inline-block; padding:1px 6px; border-radius:8px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.06);
  font-weight:950; font-size:11px; color:var(--txt);
  margin:0 2px;
}
#stage{
  position:relative;
  background:linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.01));
  border:1px solid rgba(255,255,255,.07);
  border-radius:var(--radius);
  overflow:hidden;
  min-height:0;
  box-shadow:var(--shadow);
}
canvas{width:100%; height:100%; display:block}
#c{touch-action:none; cursor:crosshair}
#overlay{position:absolute; inset:0; pointer-events:none}
#toast{
  position:absolute; top:12px; right:12px;
  background:rgba(10,14,20,.72);
  border:1px solid rgba(255,255,255,.10);
  border-radius:12px;
  padding:10px 12px;
  font-size:12px;
  color:var(--txt);
  max-width:460px;
  display:none;
  backdrop-filter: blur(10px);
}
#toast.ok{border-color:rgba(125,255,155,.25)}
#toast.bad{border-color:rgba(255,92,122,.25)}
#toast .small{color:var(--muted); margin-top:4px}
.badge{
  display:inline-flex; align-items:center; gap:6px;
  font-size:12px; color:var(--muted); font-weight:900;
}
.dot{width:8px; height:8px; border-radius:999px; background:rgba(125,255,155,.85)}
.dot.off{background:rgba(255,92,122,.85)}
#adBar{
  margin-top:10px;
  background:rgba(255,255,255,.02);
  border-top:1px solid rgba(255,255,255,.06);
  padding:10px;
  border-radius:0 0 var(--radius) var(--radius);
}
#adsenseSlot{
  min-height:90px;
  display:flex;
  align-items:center;
  justify-content:center;
  border:1px dashed rgba(255,255,255,.12);
  border-radius:14px;
  color:rgba(255,255,255,.35);
  font-weight:950;
}
@media (max-width: 980px){
  #main{grid-template-columns:1fr}
  #sidebar{order:2}
  #stage{order:1; min-height:60vh}
}



/* Meme text overlay */
.memeText{
  position:absolute;
  left:50%;
  transform:translateX(-50%);
  width:96%;
  text-align:center;
  font-weight:900;
  letter-spacing:.5px;
  text-transform:uppercase;
  pointer-events:none;
  user-select:none;
  line-height:1.05;
  padding:10px 8px;
  mix-blend-mode:normal;
}
.memeText.top{ top:10px; }
.memeText.bottom{ bottom:10px; }

.presetList{
  display:flex;
  flex-direction:column;
  gap:8px;
  margin-top:10px;
}
.presetItem{
  display:flex;
  gap:8px;
  align-items:center;
  justify-content:space-between;
  padding:10px;
  border-radius:12px;
  background:rgba(255,255,255,.04);
  border:1px solid rgba(255,255,255,.06);
}
.presetItem .name{ font-weight:700; }
.presetItem .mini{ color:var(--muted); font-size:12px; }
.presetItem .actions{ display:flex; gap:8px; }



/* Share modal */
.modal{
  position:fixed; inset:0; background:rgba(0,0,0,.55);
  display:flex; align-items:center; justify-content:center;
  padding:16px; z-index:50;
}
.modalCard{
  width:min(760px, 100%);
  background:linear-gradient(180deg, var(--panel), var(--panel2));
  border:1px solid rgba(255,255,255,.06);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:14px;
}
.modalHeader{
  display:flex; align-items:flex-start; justify-content:space-between; gap:12px;
  margin-bottom:12px;
}
.modalTitle{ font-weight:800; font-size:18px; }
.shareGrid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:10px;
}
@media (max-width:640px){
  .shareGrid{ grid-template-columns:1fr; }
}


/* --- Brand / menu button --- */
#btnMenu.btn.icon{
  width:42px; height:42px; padding:0;
  display:inline-flex; align-items:center; justify-content:center;
  font-size:18px;
}
.brand{display:flex; align-items:center; padding:0 6px;}
.brandMark{
  font-weight:900; letter-spacing:.5px;
  padding:6px 10px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.08);
  background:rgba(255,255,255,.04);
}

/* Drawer scrim */
#drawerScrim{
  position:fixed; inset:0;
  background:rgba(0,0,0,.55);
  display:none;
  z-index:40;
}

/* Close button in sidebar (shown on mobile) */
#btnCloseSidebar.btn.close{
  display:none;
  position:sticky; top:0;
  margin:6px 6px 0 auto;
  width:42px; height:42px; padding:0;
  z-index:3;
}

@media (max-width: 860px){
  #app{padding:6px; gap:6px;}
  #top{
    position:sticky; top:0; z-index:45;
    padding:8px;
  }
  /* Make top bar compact */
  #top .group{padding:0; background:transparent; border:0;}
  #top label{display:none;}
  #caps{display:none;}

  /* Hide heavy/secondary actions on mobile (available from Share modal + sidebar) */
  #btnDemo{display:none;}
  #exportMorphZip{display:none;}
  #shareOpen{display:none;}

  /* Fullscreen canvas, sidebar becomes drawer */
  #main{display:block;}
  #stage{min-height:72vh;}
  #sidebar{
    position:fixed;
    top:0; left:0;
    height:100%;
    width:min(92vw, 380px);
    transform:translateX(-105%);
    transition:transform .18s ease;
    z-index:50;
    border-radius:0;
    box-shadow: 0 30px 80px rgba(0,0,0,.65);
    overflow:auto;
  }
  body.drawerOpen #sidebar{ transform:translateX(0); }
  body.drawerOpen #drawerScrim{ display:block; }

  #btnCloseSidebar.btn.close{ display:inline-flex; align-items:center; justify-content:center; }

  /* Tabs wrap nicely */
  #sideTabs{flex-wrap:wrap;}
  #sideTabs .tab{flex:1 1 auto; min-width:32%;}

  /* Canvas padding */
  #stage{border-radius:var(--radius);}
}
