/* ROHLAN FORGE - tablet / touch layer. Loaded LAST. Everything here is under  html.is-touch  (set by js/touch.js on a touch screen),
   so the mouse + keyboard look does not change at all. Rule of thumb: every button, slider and handle is at least ~40 px, nothing needs hover. */

html.is-touch{--ctl:42px}
/* ---------- the page itself: no zoom, no scroll, no text-selection loupe, no grey tap flash ---------- */
html.is-touch,html.is-touch body{overscroll-behavior:none;-webkit-text-size-adjust:100%;touch-action:manipulation;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none;-webkit-user-select:none;user-select:none;height:100%}
@supports (height:100dvh){html.is-touch,html.is-touch body{height:100dvh}}
html.is-touch input,html.is-touch textarea,html.is-touch select{-webkit-user-select:text;user-select:text;touch-action:manipulation}
html.is-touch body{position:fixed;left:0;top:0;right:0;bottom:0;width:100%;overflow:hidden}
html.is-touch #stage canvas{touch-action:none}
html.is-touch button,html.is-touch .btn,html.is-touch .card,html.is-touch .it{touch-action:manipulation}
/* hover-only looks must not stay "stuck" after a tap */
@media (hover:none){
  .btn:hover,.mini:hover,.card:hover,#rail button:hover,#etool button:hover,#ctx li:hover{background:inherit;border-color:inherit;transform:none}
  .btn.on:hover,.mini.on:hover,#rail button.active:hover{background:var(--ink);color:#fff}
  #etool button.on:hover{background:var(--ink)}
  #ctx li:active{background:#ececec}
}

/* ---------- top bar: wraps into 2 rows instead of hiding Undo / Save / Panel behind a sideways scroll ---------- */
html.is-touch #top{height:auto;min-height:56px;flex-wrap:wrap;row-gap:6px;column-gap:6px;padding:6px 10px;overflow:visible;white-space:normal;align-content:center}
html.is-touch #top .grow{flex:1 1 8px;min-width:0}
html.is-touch #top .btn{height:42px;min-width:42px;padding:0 12px;border-radius:11px}
html.is-touch #top .btn .ico{width:19px;height:19px}
html.is-touch #top .btn svg{width:19px;height:19px}
html.is-touch #snap-size{display:inline-block!important;height:42px;font-size:16px;border-radius:11px;padding:0 8px}
html.is-touch .seg2{height:42px}
html.is-touch .seg2 button{height:36px;padding:0 16px!important;font-size:11.5px}
html.is-touch #top .sep{display:block!important;height:26px}
html.is-touch #top .logo{font-size:12px!important;letter-spacing:.2em!important}
html.is-touch #savebadge{height:34px}
@media (max-width:1320px){html.is-touch #top .logo .wm{display:none}}
html.is-touch #stage{top:var(--topH,56px)}
html.is-touch #panel{top:var(--topH,56px)}
html.is-touch #rail{top:calc(var(--topH,56px) + 12px);max-height:calc(100% - var(--topH,56px) - 24px);overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch;scrollbar-width:none}
html.is-touch #rail::-webkit-scrollbar{display:none}
html.is-touch #rail button{width:64px;padding:11px 0 9px;font-size:10.5px}
html.is-touch #rail button .ico{width:23px;height:23px}
html.is-touch #hint{max-width:min(560px,calc(100vw - 140px));font-size:12.5px;padding:9px 14px}

/* ---------- side panel ---------- */
html.is-touch #panel{width:min(380px,100vw)}
html.is-touch body.panel-open #rail,html.is-touch body.pinned #rail{right:392px}
html.is-touch body.pinned #stage{right:380px}
html.is-touch .phead{height:60px}
html.is-touch .phead button{width:42px;height:42px;border-radius:11px}
html.is-touch #pbody{-webkit-overflow-scrolling:touch;overscroll-behavior:contain;padding-bottom:40px}
html.is-touch .tabs button{padding:12px 0;font-size:11px}
html.is-touch .seg button{padding:12px 0;font-size:12px}
html.is-touch .mini{padding:11px 14px;font-size:12px;border-radius:10px}
html.is-touch .row{min-height:44px}
html.is-touch .row input[type=number],html.is-touch .row input[type=text],html.is-touch .xyz input,html.is-touch .row select,html.is-touch select,html.is-touch input[type=text],html.is-touch input[type=number]{height:42px;font-size:16px;border-radius:9px}
html.is-touch .row input[type=color],html.is-touch .crow input[type=color]{height:42px;width:56px}
html.is-touch .list .it{padding:13px 12px}
html.is-touch .list .it i,html.is-touch .list .it .ic{padding:8px 11px;font-size:14px}
html.is-touch .dot{width:32px;height:32px}
html.is-touch .sw button{height:48px}
html.is-touch .tog{padding:11px 12px}
html.is-touch .tog button{width:54px;height:30px;border-radius:15px}
html.is-touch .tog button::after{width:24px;height:24px;top:3px;left:3px}
html.is-touch .tog button.on::after{left:27px}
html.is-touch .card{padding:13px 4px 11px}

/* ---------- sliders: a thumb a finger can grab ---------- */
html.is-touch input[type=range]{-webkit-appearance:none;appearance:none;height:36px;background:transparent;margin:0;cursor:pointer}
html.is-touch input[type=range]::-webkit-slider-runnable-track{height:6px;border-radius:3px;background:#d6d6d6}
html.is-touch input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:28px;height:28px;margin-top:-11px;border-radius:50%;background:#111;border:3px solid #fff;box-shadow:0 1px 5px rgba(0,0,0,.45)}
html.is-touch input[type=range]::-moz-range-track{height:6px;border-radius:3px;background:#d6d6d6}
html.is-touch input[type=range]::-moz-range-thumb{width:22px;height:22px;border-radius:50%;background:#111;border:3px solid #fff;box-shadow:0 1px 5px rgba(0,0,0,.45)}

/* ---------- bottom edit toolbar: wraps into rows instead of a hidden sideways scroll ---------- */
html.is-touch #etool{flex-wrap:wrap;justify-content:flex-start;overflow:visible;max-width:calc(100vw - 100px);row-gap:4px}
html.is-touch #etool button{min-width:58px;padding:8px 8px 6px}
html.is-touch #etool button .ico{width:24px;height:24px}
html.is-touch #etool button .lb{font-size:10.5px}
@media (max-width:1180px){html.is-touch #etool .esep{display:none}}

/* ---------- right-click menu (long-press) ---------- */
html.is-touch #ctx ul{min-width:240px;max-height:calc(100vh - 16px);overflow-y:auto}
html.is-touch #ctx li{padding:13px 14px;font-size:14px;min-height:46px}
html.is-touch #ctx li.head{padding:9px 14px 4px;font-size:11px;min-height:0}
html.is-touch #ctx li.sep{min-height:0}
html.is-touch #ctx li em{font-size:11px}
html.is-touch #ctx li.has:hover>ul{display:none}
html.is-touch #ctx li.has.open>ul{display:block}
html.is-touch #ctx li>ul{max-height:calc(100vh - 24px);overflow-y:auto}
html.is-touch #ctx li.has em{display:none}

/* ---------- sketch / extrude / pipe / bend bars and cards ---------- */
html.is-touch #sk-bar .sk-row{padding:7px}
html.is-touch #sk-bar button,html.is-touch #sk-card button,html.is-touch #pipe-card button{min-height:42px}
html.is-touch #sk-bar .sk-tools button{min-width:44px;height:44px;padding:0 9px}
html.is-touch #sk-bar .sk-tools .lb{font-size:11.5px}
html.is-touch #sk-bar input,html.is-touch #sk-card input,html.is-touch #sk-dim input,html.is-touch #pipe-card input,html.is-touch #sk-bar select,html.is-touch #sk-card select{height:40px;font-size:16px}
html.is-touch #sk-card{max-height:calc(100% - 24px);overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch}
html.is-touch #pipe-card{max-height:calc(100% - 24px);overflow-y:auto;overscroll-behavior:contain}
html.is-touch #sk-msg{font-size:12.5px}
html.is-touch #fb-card,html.is-touch .fbcard{max-height:calc(100% - 24px);overflow-y:auto;overscroll-behavior:contain}

/* ---------- timeline ---------- */
html.is-touch .tl-bar button,html.is-touch .tl-bar .btn,html.is-touch .tl-bar .mini{min-height:40px;min-width:40px}
html.is-touch .tl-bar input[type=number],html.is-touch .tl-bar select{height:40px;font-size:16px}
html.is-touch #tl{touch-action:manipulation}

/* ---------- view cube / mini navigator stay clear of the finger-sized toolbar ---------- */
@media (max-width:1180px){html.is-touch #mini{bottom:150px}}

/* ---------- key pad (left edge) ---------- */
.kpad{display:none;position:fixed;right:96px;top:calc(var(--topH,56px) + 140px);z-index:60;flex-direction:column;gap:6px;align-items:flex-end;-webkit-user-select:none;user-select:none}
body.panel-open .kpad,body.pinned .kpad{right:488px}
html.is-touch .kpad{display:flex}
.kp-tog{width:48px;height:48px;border-radius:14px;border:1px solid var(--line);background:var(--glass);box-shadow:0 6px 20px rgba(0,0,0,.18);display:flex;align-items:center;justify-content:center;color:#333;padding:0;cursor:pointer;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px)}
.kpad.open .kp-tog{background:var(--ink);color:#fff;border-color:var(--ink)}
.kpad.mods .kp-tog{outline:3px solid #ff8a00;outline-offset:1px}
.kp-body{display:none;flex-direction:column;gap:5px;padding:6px;border-radius:14px;background:var(--glass);border:1px solid var(--line);box-shadow:0 10px 30px rgba(0,0,0,.22);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px)}
.kpad.open .kp-body{display:flex}
.kp-r{display:flex;gap:5px}
.kp-body button{min-width:46px;height:42px;padding:0 9px;border-radius:10px;border:1px solid var(--line);background:#fff;font:700 12px/1 Montserrat,system-ui,sans-serif;color:#333;cursor:pointer;flex:1 1 auto;touch-action:manipulation}
.kp-body button:active{background:#e8e8e8}
.kp-body button.red{color:#c0392b;border-color:#f3c6c0;background:#fff5f4}
.kp-body button.on{background:var(--ink);color:#fff;border-color:var(--ink)}
@media (max-height:640px){.kpad{top:calc(var(--topH,56px) + 8px)}.kp-body button{height:38px}}

/* ---------- shortcut dialog: touch help on top ---------- */
.tk-help{margin:6px 0 12px;padding:10px 14px 4px;border-radius:12px;background:#fff7ec;border:1px solid #f6d9ad}
.tk-help h4{margin:4px 0 8px;font-size:11px;font-weight:800;color:#a35a00;text-transform:uppercase;letter-spacing:.06em}
.tk-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:2px 16px}
.tk-grid p{margin:0 0 8px;font-size:12px;font-weight:600;color:#444;line-height:1.4}
.tk-grid b{color:#111}
@media (max-width:760px){.tk-grid{grid-template-columns:1fr}}
html.is-touch .khead button{width:42px;height:42px;font-size:22px}
html.is-touch .kcol kbd{font-size:12px}

/* ---------- update popup ---------- */
html.is-touch #upd-box button{min-height:46px;font-size:15px}

/* ---------- sketch bar: the drawing tools scroll sideways in their own row, the action buttons (Pipe / Extrude / Bend / Finish) always stay visible below them ---------- */
@media (max-width:1280px){
  html.is-touch #sk-bar{left:12px;right:12px;transform:none;max-width:none;align-items:stretch}
  html.is-touch #sk-bar .sk-row{max-width:100%;overflow:visible}
  html.is-touch #sk-bar .sk-sec.sk-draw{flex-wrap:wrap;row-gap:6px;width:100%}
  html.is-touch #sk-bar .sk-draw > .sk-title{flex:0 0 auto}
  html.is-touch #sk-bar .sk-draw > .sk-sepv{display:none}
  html.is-touch #sk-bar .sk-tools{flex:1 1 0;min-width:0;flex-wrap:nowrap;overflow-x:auto;overflow-y:hidden;scrollbar-width:none;-webkit-overflow-scrolling:touch;overscroll-behavior-x:contain;touch-action:pan-x;
    -webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 26px),transparent);mask-image:linear-gradient(90deg,#000 calc(100% - 26px),transparent)}
  html.is-touch #sk-bar .sk-tools::-webkit-scrollbar{display:none}
  html.is-touch #sk-bar .sk-draw > button{flex:0 0 auto}
  html.is-touch #sk-bar .sk-draw > .sk-fin{margin-left:auto}
  html.is-touch #sk-bar .sk-draw > button.sk-ext{padding:0 12px}
}

/* ---------- object list, checkboxes, small icon buttons ---------- */
html.is-touch input[type=checkbox],html.is-touch input[type=radio]{width:24px;height:24px;accent-color:#111}
html.is-touch .orow{min-height:52px;gap:10px}
html.is-touch .orow input[type=checkbox]{width:24px;height:24px}
html.is-touch .orow button,html.is-touch .orow .ic,html.is-touch .list .it button{min-width:42px;min-height:42px;display:inline-flex;align-items:center;justify-content:center}
html.is-touch .tabs button{min-height:42px}
html.is-touch #sk-card .sk-nudge button,html.is-touch #pipe-card .sk-nudge button,html.is-touch #sk-card .sk-seg button,html.is-touch #sk-card .sk-xr button,html.is-touch #pipe-card .sk-seg button,html.is-touch #pipe-card .sk-xr button{height:42px!important;font-size:12px}
html.is-touch #sk-bar .sk-opts input{height:40px;width:64px;font-size:16px}
html.is-touch #sk-bar .sk-opts button{height:40px;padding:0 12px;font-size:12px}
html.is-touch .sk-chip button{height:40px!important;min-width:40px!important}
html.is-touch #pipe-card input[type=checkbox]{width:24px;height:24px}
html.is-touch #sk-nav button{min-width:42px;min-height:42px}

/* ---------- timeline: finger-sized rows, keys and buttons (no hover needed) ---------- */
html.is-touch .tn,html.is-touch .tr{height:40px}
html.is-touch .tn.grp,html.is-touch .tn.cut,html.is-touch .tr.grprow,html.is-touch .tr.cutrow{height:46px}
html.is-touch .tn .x{opacity:.75;width:36px;height:36px;font-size:19px}
html.is-touch .tn .car{width:30px;height:30px}
html.is-touch .tn .car svg{width:16px;height:16px}
html.is-touch .tn .ic svg{width:18px;height:18px}
html.is-touch .kf{width:16px;height:16px;margin:-8px 0 0 -8px}
html.is-touch .kf.grp{width:15px;height:15px;margin:-7.5px 0 0 -7.5px}
html.is-touch .kf::before,html.is-touch .cutf::before{content:'';position:absolute;left:-14px;right:-14px;top:-14px;bottom:-14px}
html.is-touch .cutf{height:30px;top:7px}
@media (max-height:820px){html.is-touch{--tlh:236px}}

/* ---------- extrude / pipe / bend cards: every field and button finger-sized ---------- */
html.is-touch #sk-card select,html.is-touch #sk-card input[type=number],html.is-touch #sk-card input[type=text],html.is-touch #sk-card button,html.is-touch #pipe-card button,html.is-touch #pipe-card select{min-height:42px}
html.is-touch #sk-card [id^="x-"]{min-height:42px}

/* ---------- more room for the model: slimmer top bar, shorter timeline ---------- */
html.is-touch #top{min-height:50px;row-gap:4px;column-gap:4px;padding:5px 8px}
html.is-touch #top .btn{height:38px;min-width:38px;padding:0 9px;border-radius:10px}
html.is-touch #snap-size{height:38px}
html.is-touch .seg2{height:38px}
html.is-touch .seg2 button{height:32px;padding:0 12px!important}
html.is-touch #top .sep{margin:0 1px}
html.is-touch #stage,html.is-touch #panel{top:var(--topH,50px)}
@media (max-height:820px){html.is-touch{--tlh:190px}}
@media (max-width:1320px){html.is-touch #top .seg2 button{font-size:10.5px}}
@media (min-width:1100px) and (max-width:1320px){
  html.is-touch #top{column-gap:3px;padding:5px 6px}
  html.is-touch #top .btn{min-width:36px;padding:0 6px}
  html.is-touch .seg2 button{padding:0 9px!important}
  html.is-touch #top .sep{display:none!important}
  html.is-touch #top .logo{margin-right:2px}
}

/* ---------- "..." menu in the top bar ---------- */
#more-pop{position:fixed;right:8px;top:calc(var(--topH,50px) + 4px);z-index:90;display:flex;flex-direction:column;gap:4px;padding:6px;min-width:190px;background:var(--glass,#fff);border:1px solid var(--line,#e5e5e5);border-radius:14px;box-shadow:0 14px 40px rgba(0,0,0,.25);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px)}
#more-pop[hidden]{display:none}
html.is-touch #more-pop .btn{width:100%;height:46px;justify-content:flex-start;gap:12px;padding:0 14px;font-size:14px;font-weight:600}
html.is-touch #more-pop .btn svg{width:20px;height:20px}

@media (max-width:1100px){html.is-touch #top .sep{display:none!important}}
