/* mobile.css - phone dock + bottom sheets (load AFTER responsive.css) */
.dock{display:none}
#sheetBack{display:none}

@keyframes sheetUp{from{transform:translateY(24px);opacity:0}to{transform:none;opacity:1}}

@media(max-width:600px){
  /* canvas gets the whole screen above the dock */
  body .app{grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr);grid-template-areas:"stage";box-sizing:border-box;padding-bottom:calc(76px + env(safe-area-inset-bottom,0px));background:var(--stage)}
  body .stage{grid-area:stage}
  body .left,body .right{display:none}

  /* ---------- floating dock ---------- */
  .dock{display:flex;align-items:stretch;gap:2px;position:fixed;left:8px;right:8px;bottom:calc(8px + env(safe-area-inset-bottom,0px));height:60px;padding:4px 6px;background:var(--cream);border:2px solid var(--ink);border-radius:20px;box-shadow:var(--shadow),0 8px 20px rgba(0,0,0,.18);z-index:9990}
  .dk{flex:1 1 0;min-width:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;border:0;border-radius:14px;background:transparent;padding:0;font-size:10px;font-weight:600;line-height:1;transition:background .15s,transform .1s}
  .dk svg{width:24px;height:24px;fill:var(--ink);stroke:none;flex:none}
  .dk.stk svg{fill:none;stroke:var(--ink);stroke-width:2.2;stroke-linejoin:round;stroke-linecap:round}
  .dk:active{transform:scale(.92)}
  .dk.on{background:var(--lime)}
  .dk:disabled{opacity:.3}
  .dk-sep{flex:none;width:2px;margin:10px 3px;background:var(--lime-deep);opacity:.5;border-radius:2px}

  #sheetBack{display:block;position:fixed;inset:0;z-index:9980;background:rgba(0,0,0,.28);opacity:0;pointer-events:none;transition:opacity .2s}
  body.sheet-on #sheetBack{opacity:1;pointer-events:auto}

  /* ---------- tool lists (Brush, Select, Shapes, Mirror, Themes) become bottom sheets ---------- */
  body .fly-panel.open{
    position:fixed;left:8px!important;right:8px;top:auto!important;bottom:calc(76px + env(safe-area-inset-bottom,0px));
    width:auto;max-height:min(58dvh,calc(100dvh - 160px));overflow-y:auto;
    grid-template-columns:repeat(auto-fill,minmax(56px,1fr));gap:10px;padding:26px 12px 12px;
    border-radius:20px;
    background:linear-gradient(var(--ink),var(--ink)) no-repeat center 9px/44px 4px var(--cream);
    box-shadow:var(--shadow),0 -6px 24px rgba(0,0,0,.2);
    animation:sheetUp .22s ease-out
  }
  body .fly-panel.two.open{grid-template-columns:repeat(2,1fr)}
  body .fly-panel.list.open{grid-template-columns:1fr;gap:2px}
  body .fly-panel.open::before{content:attr(data-title);grid-column:1/-1;font-weight:700;font-size:15px;padding:0 4px 4px}
  body .fly-panel.open .tool{width:100%;height:52px}
  body .fly-panel.open .tool svg{width:26px;height:26px}
  body .fly-panel.open .bs-item{min-height:48px}
  body .fly-panel.open .bs-pv{width:120px}

  /* ---------- Color and More sheets (use the right bar) ---------- */
  body.sheet-color .right,body.sheet-more .right{
    display:flex;flex-direction:column;align-items:stretch;justify-content:flex-start;
    position:fixed;left:8px;right:8px;bottom:calc(76px + env(safe-area-inset-bottom,0px));z-index:9998;
    max-height:min(66dvh,calc(100dvh - 160px));overflow-x:hidden;overflow-y:auto;
    padding:26px 14px 14px;gap:10px;
    border:2px solid var(--ink);border-radius:20px;
    background:linear-gradient(var(--ink),var(--ink)) no-repeat center 9px/44px 4px var(--lime-soft);
    box-shadow:var(--shadow),0 -6px 24px rgba(0,0,0,.2);
    animation:sheetUp .22s ease-out;-webkit-mask-image:none;mask-image:none
  }
  body.sheet-color .right::before{content:"Color"}
  body.sheet-more .right::before{content:"More"}
  body.sheet-on .right::before{font-weight:700;font-size:15px}
  body.sheet-color .right .grp-more{display:none}
  body.sheet-more .right .grp-color{display:none}

  body .right .rule{width:100%;height:0;margin:2px 0;border-left:0;border-top:2px dashed var(--lime-deep)}
  body .right .slots{width:100%;flex:none;flex-direction:row;gap:8px}
  body .right .slots .slot{flex:1;width:auto;min-width:0;height:46px;font-size:12px;padding:0 6px}
  body .right .slot.rb{width:100%;min-height:46px}
  body .right .palette{width:100%;grid-template-columns:repeat(6,1fr);grid-template-rows:none;gap:10px;justify-items:center}
  body .right .sw{width:40px;height:40px}
  body .right .sw.none::after{top:-3px;height:46px}
  body .right .sw.sel{transform:scale(1.12)}
}

/* ---------- stage 2: contextual tool settings bar ---------- */
.ctx{display:none}
@media(max-width:600px){
  .ctx{display:flex;flex-wrap:wrap;align-items:center;gap:8px 10px;position:fixed;left:8px;right:8px;bottom:calc(76px + env(safe-area-inset-bottom,0px));z-index:9985;padding:8px 10px;background:var(--cream);border:2px solid var(--ink);border-radius:18px;box-shadow:var(--shadow),0 6px 16px rgba(0,0,0,.16);animation:sheetUp .18s ease-out}
  body:not(.ctx-on) .ctx{display:none}
  .ctx [hidden]{display:none!important}
  body.ctx-on .app{padding-bottom:calc(84px + var(--ctxh,0px) + env(safe-area-inset-bottom,0px))}

  .cx-btn{display:flex;align-items:center;gap:6px;min-height:44px;padding:0 12px;border:2px solid var(--ink);border-radius:12px;background:#fff;font-size:13px;font-weight:600;box-shadow:0 2px 0 var(--ink)}
  .cx-btn:active{transform:translateY(2px);box-shadow:none}
  .cx-btn.on{background:var(--lime)}
  .cx-chip{display:block;width:22px;height:22px;border-radius:50%;border:2px solid var(--ink)}
  .cx-rng{flex:1 1 150px;display:flex;align-items:center;gap:8px;min-height:44px;font-size:12px;font-weight:600}
  .cx-rng input{flex:1;min-width:0;height:32px;accent-color:var(--lime-deep)}
  .cx-rng b{min-width:34px;text-align:right}
  .cx-dot{display:block;flex:none;border-radius:50%;background:var(--ink)}
  .cx-dotw{width:26px;height:26px;display:grid;place-items:center;flex:none}
}

/* ---------- stage 3: Color + More sheets ---------- */
.mx,.mx-only{display:none}
@media(max-width:600px){
  body .right .mx-only{display:flex}
  body .right .mx{display:block}

  /* old buttons replaced by the tiles in More */
  body .right .fly-btn,body .right #aiBtn,body .right #muteBtn,body .right #tlBtn,body .right #fsBtn{display:none!important}

  /* color sheet */
  body .right .slots .slot:not(.on){opacity:.7}
  body .right .slots .slot.on{box-shadow:0 2px 0 var(--ink),0 0 0 3px var(--lime-deep)}
  body .right .sw.sel{box-shadow:0 0 0 3px var(--cream),0 0 0 6px var(--ink)}
  body .right .sw.sel::before{content:"✓";position:absolute;inset:0;display:grid;place-items:center;font-size:20px;font-weight:700;color:#fff;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}
  body .right .sw:not(.sel){opacity:.92}

  /* more sheet */
  .mx-h{font-weight:700;font-size:13px;margin:12px 2px 6px;opacity:.8}
  .mx-h:first-child{margin-top:0}
  .mx-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
  .mx-b{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;min-height:60px;padding:6px 4px;border:2px solid var(--ink);border-radius:14px;background:#fff;font-size:12px;font-weight:600;line-height:1.15;text-align:center;box-shadow:0 2px 0 var(--ink);transition:transform .1s,background .15s}
  .mx-b:active{transform:translateY(2px);box-shadow:none}
  .mx-b.on{background:var(--lime);box-shadow:0 2px 0 var(--ink),0 0 0 3px var(--lime-deep)}
  .mx-b.danger:active{background:#ffd9cf}
  .mx-i{font-style:normal;font-size:20px;line-height:1;display:block}
  .mx-dot{display:block;width:22px;height:22px;border-radius:50%;border:2px solid var(--ink)}
}

/* ---------- stage 4: collapsible side panels + polish ---------- */
.pn-t{display:none}
@media(min-width:601px){
  .app{transition:grid-template-columns .22s ease}
  body.no-left .app{grid-template-columns:0 minmax(0,1fr) 140px}
  body.no-right .app{grid-template-columns:132px minmax(0,1fr) 0}
  body.no-left.no-right .app{grid-template-columns:0 minmax(0,1fr) 0}
  body.no-left .left,body.no-right .right{visibility:hidden;overflow:hidden;padding-left:0;padding-right:0;border-width:0}

  .pn-t{display:grid;place-items:center;position:absolute;top:50%;transform:translateY(-50%);z-index:8;width:22px;height:56px;padding:0;border:2px solid var(--ink);background:var(--cream);box-shadow:var(--shadow);font-size:12px;font-weight:700;transition:background .15s}
  .pn-t:hover{background:var(--lime)}
  .pn-l{left:0;border-left:0;border-radius:0 12px 12px 0}
  .pn-r{right:0;border-right:0;border-radius:12px 0 0 12px}

  /* polish */
  .tool,.act,.slot{transition:background .15s,transform .1s,box-shadow .15s}
  .tool:hover:not(:disabled),.act:hover{transform:translateY(-1px)}
  .tool.on{transform:none}
  .tool.on::before{content:"";position:absolute;left:-9px;top:25%;height:50%;width:4px;border-radius:4px;background:var(--ink)}
  .slot:hover:not(:disabled){background:#f1f9d6}
  .slot.on:hover{background:var(--lime)}
}
@media(min-width:601px) and (max-width:820px){
  body.no-left .app{grid-template-columns:0 minmax(0,1fr) 120px}
  body.no-right .app{grid-template-columns:84px minmax(0,1fr) 0}
  body.no-left.no-right .app{grid-template-columns:0 minmax(0,1fr) 0}
}
@media(max-width:600px){.pn-t{display:none!important}}

/* ---------- phone fixes: top bar, zoom pill, compact settings bar ---------- */
@media(max-width:600px){
  .topbar{padding:0 8px;gap:4px;overflow:hidden}
  .brand img{height:50px}
  .menus{margin-left:0;gap:3px;min-width:0}
  .nbtn{padding:4px 8px;font-size:12px}
  .nbtn .caret,.nbtn svg{display:none}
  .topbar .save{padding:7px 10px}
  .topbar .save .caret{display:none}
  .topbar .icon-label{display:none}

  /* zoom pill floats on the canvas, top right */
  .topbar .pill{position:fixed;top:62px;right:8px;margin:0;z-index:45;gap:2px;padding:2px;box-shadow:var(--shadow),0 4px 10px rgba(0,0,0,.15)}
  .topbar .pill .ibtn{width:34px;height:34px}
  .topbar .pill .zoomval{min-width:44px;min-height:34px;font-size:13px}

  /* settings bar: row 1 = type + colours, row 2 = size + opacity */
  .ctx{gap:6px 8px;padding:6px 8px}
  .ctx [data-r="type"]{order:1}
  .ctx [data-r="fill"]{order:2}
  .ctx [data-r="out"]{order:3}
  .ctx [data-do]{order:1;flex:1 1 40%}
  .ctx .cx-rng{order:4;flex:1 1 135px;min-height:36px}
  .cx-btn{min-height:40px;padding:0 10px}
}