/* CNC Handwriting Studio - mobile-first. Theme comes from Bootstrap's data-bs-theme. */
:root {
  --cnc-accent: #0284c7; --cnc-accent-2: #0ea5e9; --cnc-warn: #f97316;
  --cnc-canvas-bg: #e2e8f0; --cnc-paper: #ffffff; --cnc-grid: rgba(100,116,139,.18); --cnc-grid-major: rgba(100,116,139,.38);
  --cnc-ruler: #f1f5f9; --cnc-ruler-text: #475569;
  --bar-h: 52px; --toolbar-h: 62px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
[data-bs-theme="dark"] {
  --cnc-canvas-bg: #0b1220; --cnc-paper: #1e293b; --cnc-grid: rgba(148,163,184,.16); --cnc-grid-major: rgba(148,163,184,.34);
  --cnc-ruler: #111a2c; --cnc-ruler-text: #94a3b8;
}
html { scroll-behavior: smooth; }
body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
main { flex: 1 0 auto; }
.skip-link { position: absolute; left: -999px; top: 0; z-index: 3000; background: var(--cnc-accent); color: #fff; padding: .5rem 1rem; }
.skip-link:focus { left: 0; }
:focus-visible { outline: 3px solid var(--cnc-accent-2); outline-offset: 2px; }
.btn, .form-control, .form-select { min-height: 40px; }
.btn-sm { min-height: 34px; }

/* ---- toasts ---- */
.toast-host { position: fixed; left: 50%; bottom: calc(var(--toolbar-h) + var(--safe-b) + 12px); transform: translateX(-50%); z-index: 3000; display: flex; flex-direction: column; gap: .5rem; width: min(92vw, 420px); pointer-events: none; }
.app-toast { pointer-events: auto; padding: .6rem .9rem; border-radius: .6rem; color: #fff; background: #334155; box-shadow: 0 6px 20px rgba(0,0,0,.3); font-size: .9rem; transition: opacity .3s; }
.app-toast.hide { opacity: 0; }
.app-toast-success { background: #15803d; } .app-toast-danger { background: #b91c1c; } .app-toast-warning { background: #b45309; } .app-toast-info { background: #0369a1; }

/* ---- navbar / footer ---- */
.brand-mark { display: inline-flex; width: 28px; height: 28px; border-radius: 7px; background: linear-gradient(135deg, var(--cnc-accent), #7c3aed); color: #fff; align-items: center; justify-content: center; margin-right: .5rem; font-size: 1rem; }
.site-footer { font-size: .85rem; }
#offlineBadge { position: fixed; top: calc(var(--safe-t) + 4px); right: 8px; z-index: 2500; }

/* ---- home ---- */
.hero { padding: 3rem 0 2rem; background: radial-gradient(1200px 400px at 80% -10%, rgba(14,165,233,.25), transparent), radial-gradient(900px 400px at 0% 0%, rgba(124,58,237,.18), transparent); }
.hero h1 { font-weight: 800; letter-spacing: -.02em; font-size: clamp(2rem, 6vw, 3.4rem); }
.feature-card { height: 100%; border-radius: 1rem; transition: transform .15s, box-shadow .15s; }
.feature-card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(2,132,199,.15); }
.feature-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; color: #fff; background: linear-gradient(135deg, var(--cnc-accent), var(--cnc-accent-2)); margin-bottom: .75rem; }
.demo-wrap { border-radius: 1rem; overflow: hidden; border: 1px solid var(--bs-border-color); background: var(--cnc-paper); }
.demo-canvas { width: 100%; height: 260px; display: block; touch-action: none; cursor: crosshair; background: var(--cnc-paper); }
.step-pill { display: inline-flex; align-items: center; gap: .4rem; padding: .25rem .7rem; border-radius: 99px; background: var(--bs-tertiary-bg); font-size: .85rem; }

/* ---- project cards ---- */
.project-card { border-radius: 1rem; overflow: hidden; height: 100%; }
.project-thumb { aspect-ratio: 4 / 3; width: 100%; object-fit: contain; background: var(--cnc-paper); border-bottom: 1px solid var(--bs-border-color); }
.project-thumb-empty { aspect-ratio: 4 / 3; display: grid; place-items: center; background: var(--bs-tertiary-bg); color: var(--bs-secondary-color); font-size: 2rem; }

/* ================= Studio shell ================= */
body.studio-page { height: 100vh; height: 100dvh; overflow: hidden; }
body.studio-page .site-footer, body.studio-page .navbar { display: none; }
/* the studio must be exactly viewport-high so the canvas fills it (main may shrink and clip) */
body.studio-page main { flex: 1 1 0; min-height: 0; overflow: hidden; }
.studio { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--cnc-canvas-bg); }
.studio-top { flex: 0 0 auto; display: flex; align-items: center; gap: .4rem; min-height: var(--bar-h); padding: calc(var(--safe-t) + 4px) calc(var(--safe-r) + 8px) 4px calc(var(--safe-l) + 8px); background: var(--bs-body-bg); border-bottom: 1px solid var(--bs-border-color); z-index: 20; }
.studio-top .proj-name { flex: 1 1 auto; min-width: 60px; font-weight: 600; border: 1px solid transparent; background: transparent; }
.studio-top .proj-name:hover, .studio-top .proj-name:focus { border-color: var(--bs-border-color); background: var(--bs-body-bg); }
.save-status { font-size: .75rem; color: var(--bs-secondary-color); white-space: nowrap; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; }
.save-status[data-state="saved"]::before { content: "\2713 "; color: #16a34a; }
.save-status[data-state="unsaved"]::before, .save-status[data-state="saving"]::before { content: "\25CF "; color: #f59e0b; }
.save-status[data-state="pending"]::before { content: "\25D0 "; color: #f59e0b; }
.save-status[data-state="local"]::before { content: "\25CB "; }
.save-status[data-state="conflict"]::before, .save-status[data-state="error"]::before { content: "! "; }
.save-status[data-state="conflict"], .save-status[data-state="error"] { color: #dc2626; }
.shape-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.shape-grid .tool-btn { min-height: 64px; border-color: var(--bs-border-color); }
#btnMulti.active { background: var(--cnc-accent); color: #fff; border-color: var(--cnc-accent); }
/* header: touch-size buttons that never wrap or shrink; only the project name gives way */
.studio-top > .btn, .studio-top .dropdown > .btn { flex: 0 0 auto; white-space: nowrap; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .3rem; }
.studio-top .dropdown { flex: 0 0 auto; }
.studio-top { gap: .25rem; }
@media (max-width: 374.98px) { .studio-top [data-action="preview"] > span { display: none; } }
@media (max-width: 359.98px) { .save-status { display: none; } }
/* very narrow phones: the save state shrinks to its icon so the header never overflows */
@media (max-width: 420px) { .save-status { font-size: 0; max-width: 1.4rem; } .save-status::before { font-size: 1rem; } .studio-top { gap: .25rem; } }
.studio-body { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.canvas-wrap { position: relative; flex: 1; min-width: 0; min-height: 0; }
#studioCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: var(--cnc-canvas-bg); touch-action: none; user-select: none; -webkit-user-select: none; }
.canvas-hud { position: absolute; left: 8px; bottom: 8px; display: flex; gap: .4rem; flex-wrap: wrap; pointer-events: none; }
.hud-chip { pointer-events: auto; background: rgba(15,23,42,.78); color: #fff; font-size: .72rem; padding: .2rem .55rem; border-radius: 99px; }
.zoom-ctl { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: .35rem; }
.zoom-ctl .btn { width: 40px; padding: 0; background: var(--bs-body-bg); }
.edit-bar { position: absolute; left: 8px; right: 60px; top: 8px; display: flex; gap: .35rem; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.edit-bar::-webkit-scrollbar { display: none; }
.edit-bar .btn { flex: 0 0 auto; background: var(--bs-body-bg); }
.poly-bar { position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%); display: flex; gap: .35rem; flex-wrap: wrap; justify-content: center; max-width: calc(100% - 16px); padding: .35rem; border-radius: .75rem; background: var(--bs-body-bg); box-shadow: 0 4px 16px rgba(0,0,0,.3); z-index: 25; }
.poly-bar .btn { min-height: 44px; }
.update-bar { position: fixed; left: 8px; right: 8px; bottom: calc(var(--safe-b) + 8px); z-index: 3100; display: flex; align-items: center; gap: .5rem; justify-content: space-between; padding: .6rem .8rem; border-radius: .75rem; background: #0369a1; color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.35); }
.conflict-bar { position: absolute; top: 0; left: 0; right: 0; z-index: 30; }

/* bottom toolbar (mobile) */
.toolbar { flex: 0 0 auto; display: flex; gap: .25rem; align-items: stretch; overflow-x: auto; scrollbar-width: none; min-height: var(--toolbar-h); padding: 6px calc(var(--safe-r) + 6px) calc(var(--safe-b) + 6px) calc(var(--safe-l) + 6px); background: var(--bs-body-bg); border-top: 1px solid var(--bs-border-color); z-index: 20; }
.toolbar::-webkit-scrollbar { display: none; }
.tool-btn { flex: 0 0 auto; min-width: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 4px 6px; border: 1px solid transparent; border-radius: .6rem; background: transparent; color: var(--bs-body-color); font-size: .66rem; line-height: 1.1; }
.tool-btn i { font-size: 1.25rem; }
.tool-btn:hover { background: var(--bs-tertiary-bg); }
.tool-btn.active { background: var(--cnc-accent); color: #fff; }
.tool-btn:disabled { opacity: .4; }
.toolbar-sep { flex: 0 0 1px; background: var(--bs-border-color); margin: 6px 3px; }

/* panels: bottom sheets */
.side { display: contents; }
/* panels on mobile, side panels on desktop */
.panel { position: fixed; left: 0; right: 0; bottom: 0; max-height: 78vh; max-height: 78dvh; z-index: 60; display: flex; flex-direction: column; background: var(--bs-body-bg); border-top-left-radius: 1.1rem; border-top-right-radius: 1.1rem; box-shadow: 0 -10px 30px rgba(0,0,0,.35); transform: translateY(105%); transition: transform .22s ease; padding-bottom: var(--safe-b); }
.panel.open { transform: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: .6rem 1rem; border-bottom: 1px solid var(--bs-border-color); font-weight: 600; }
.panel-head::before { content: ""; position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; border-radius: 2px; margin-left: -20px; background: var(--bs-border-color); }
.panel-body { overflow-y: auto; overscroll-behavior: contain; padding: .75rem 1rem 1rem; }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: none; }
.sheet-backdrop.show { display: block; }
.panel-section { border: 1px solid var(--bs-border-color); border-radius: .75rem; margin-bottom: .75rem; overflow: hidden; }
.panel-section > h3 { margin: 0; padding: .55rem .8rem; font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; background: var(--bs-tertiary-bg); cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.panel-section > h3::after { content: "\2212"; }
.panel-section.collapsed > h3::after { content: "+"; }
.panel-section.collapsed > .section-body { display: none; }
.section-body { padding: .75rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.form-label { font-size: .8rem; margin-bottom: .15rem; }
.opt-result { font-size: .8rem; color: var(--bs-secondary-color); margin-top: .5rem; }

/* preview overlay */
.overlay { position: fixed; inset: 0; z-index: 100; background: var(--bs-body-bg); display: flex; flex-direction: column; padding-top: var(--safe-t); }
.overlay-head { display: flex; align-items: center; justify-content: space-between; padding: .5rem .75rem; border-bottom: 1px solid var(--bs-border-color); }
.overlay-body { flex: 1; overflow: auto; }
body.overlay-open { overflow: hidden; }

/* settings: inline validation text is always shown with an icon-free plain message (never colour alone) */
.section-body .invalid-feedback { font-size: .78rem; }
.panel-section .form-control.is-invalid, .panel-section .form-select.is-invalid { border-width: 2px; }

/* ---- preview: full-screen on phones ---- */
.overlay-head { gap: .5rem; justify-content: flex-start; }
.overlay-title { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; gap: 2px; }
@media (max-width: 991.98px) {
  .overlay-body { overflow: hidden; display: flex; flex-direction: column; }
  #previewRoot { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
  .overlay .pv { flex: 1 1 0; min-height: 0; padding: 0; gap: 0; position: relative; display: flex; flex-direction: column; }
  .overlay .pv-bar { flex: 0 0 auto; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 4px 8px; }
  .overlay .pv-bar .btn-group { flex-wrap: nowrap; }
  .overlay .pv-bar .btn { min-height: 44px; white-space: nowrap; }
  .overlay .pv-stage { flex: 1 1 0; min-height: 0; height: auto; border: 0; border-radius: 0; }
  .overlay .pv-sim { flex: 0 0 auto; border-width: 1px 0 0; border-radius: 0; padding: .5rem .75rem calc(.5rem + var(--safe-b)); }
  .overlay .pv-sim-buttons .btn { min-width: 44px; min-height: 44px; }
  .overlay .pv-speed { min-height: 44px; }
  .overlay .pv-progress { margin: .25rem 0; }
  /* details: a drawer over the lower part of the screen, not a long scroll */
  .overlay .pv-info { position: absolute; left: 0; right: 0; bottom: 0; top: 30%; z-index: 6; overflow-y: auto; padding: .75rem 1rem calc(1rem + var(--safe-b)); background: var(--bs-body-bg); border-top: 1px solid var(--bs-border-color); border-radius: 1rem 1rem 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.35); transform: translateY(105%); visibility: hidden; transition: transform .22s ease, visibility 0s .22s; }
  .overlay .pv.pv-info-open .pv-info { transform: none; visibility: visible; transition: transform .22s ease; }
}

/* ---- preview panel ---- */
.pv { display: flex; flex-direction: column; gap: .5rem; padding: .5rem; }
.pv:fullscreen { background: var(--bs-body-bg); overflow: auto; }
.pv-fixed .pv { position: fixed; inset: 0; z-index: 200; background: var(--bs-body-bg); overflow: auto; }
.pv-bar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.pv-stage { position: relative; height: 52vh; min-height: 280px; border: 1px solid var(--bs-border-color); border-radius: .75rem; overflow: hidden; }
.pv:fullscreen .pv-stage { height: 70vh; }
.pv-canvas { width: 100%; height: 100%; display: block; }
.pv-loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; background: rgba(15,23,42,.55); color: #fff; }
.pv-sim { border: 1px solid var(--bs-border-color); border-radius: .75rem; padding: .5rem .75rem; }
.pv-sim-buttons { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.pv-speed { width: auto; margin-left: auto; min-height: 34px; padding-top: .15rem; padding-bottom: .15rem; }
.pv-progress { margin: .5rem 0 .25rem; }
.pv-readout { display: flex; flex-wrap: wrap; gap: .25rem .9rem; font-size: .8rem; font-variant-numeric: tabular-nums; }
.pv-cmd { flex: 1 1 100%; color: var(--bs-secondary-color); min-height: 1.2em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-stats { display: grid; grid-template-columns: auto 1fr; gap: .15rem .9rem; font-size: .88rem; margin-bottom: .75rem; }
.pv-stats dt { color: var(--bs-secondary-color); font-weight: 500; } .pv-stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* auth pages */
.auth-card { max-width: 460px; margin: 2rem auto; }
.gcode-pre { max-height: 50vh; overflow: auto; font-size: .78rem; }

/* ================= Desktop ================= */
@media (min-width: 992px) {
  .toolbar { flex-direction: column; overflow-y: auto; overflow-x: hidden; min-height: 0; width: 74px; padding: 8px 6px; border-top: 0; border-right: 1px solid var(--bs-border-color); }
  .toolbar-sep { flex: 0 0 1px; margin: 4px 6px; height: 1px; width: auto; }
  .studio-body { flex-direction: row; }
  .studio-body > .toolbar { order: -1; }
  .side { display: block; flex: 0 0 330px; width: 330px; overflow-y: auto; background: var(--bs-body-bg); border-left: 1px solid var(--bs-border-color); }
  .panel { position: static; transform: none; max-height: none; border-radius: 0; box-shadow: none; padding-bottom: 0; }
  .panel-head { display: none; }
  .sheet-backdrop { display: none !important; }
  .panel[data-sheet="shapes"] { display: none; }
  [data-open-sheet], .mobile-only { display: none !important; }
  .toast-host { bottom: 16px; }
  .pv { display: grid; grid-template-columns: minmax(0, 1fr) 340px; grid-template-areas: "bar info" "stage info" "sim info"; align-items: start; }
  .pv-bar { grid-area: bar; } .pv-stage { grid-area: stage; height: 62vh; } .pv-sim { grid-area: sim; } .pv-info { grid-area: info; }
}
@media (min-width: 992px) and (max-width: 1399px) { .side { flex-basis: 296px; width: 296px; } }
@media (max-width: 991.98px) { .desktop-only { display: none !important; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print { .navbar, .site-footer, .toolbar, .studio-top { display: none !important; } }

/* Phones: bottom navigation for general pages, 44px touch targets on list cards */
.bottom-nav { display: none; }
@media (max-width: 991.98px) {
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; background: var(--bs-body-bg); border-top: 1px solid var(--bs-border-color); padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { flex: 1; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: .75rem; text-decoration: none; color: var(--bs-secondary-color); }
  .bottom-nav a i { font-size: 1.25rem; line-height: 1; }
  .bottom-nav a[aria-current="page"], .bottom-nav a:active { color: var(--bs-primary); }
  body:has(.bottom-nav) .site-footer { margin-bottom: 64px; }
  .project-card .card-footer .btn, .card-footer .btn { min-height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; }
}

/* Phones: 44px minimum touch targets in the Studio panels and sheets */
@media (max-width: 991.98px) {
  .studio-shell .btn-sm, .studio-shell .zoom-ctl .btn, .studio-page .btn-sm, .studio-page .zoom-ctl .btn { min-height: 44px; min-width: 44px; }
  .studio-page .btn-close { width: 44px; height: 44px; background-size: 1rem; }
  .studio-page .form-control, .studio-page .form-select { min-height: 44px; }
  .studio-page .panel-head a, .studio-page .form-text a, .studio-page a.small { display: inline-block; padding: 12px 0; }
}

.pv-percent { margin-left: auto; font-size: .95rem; }
.overlay .pv-bar .btn-group { gap: 0; }

/* Drawing order panel */
.order-list { display: flex; flex-direction: column; gap: .35rem; }
.order-item { display: flex; align-items: center; gap: .35rem; border: 1px solid var(--bs-border-color); border-radius: .6rem; padding: .2rem; background: var(--bs-body-bg); }
.order-item.selected { border-color: var(--bs-primary); }
.order-item.active { background: rgba(245,158,11,.18); border-color: #f59e0b; }
.order-item.dragging { opacity: .6; }
.order-item.drop-before { box-shadow: 0 -3px 0 0 var(--bs-primary); }
.order-item.drop-after { box-shadow: 0 3px 0 0 var(--bs-primary); }
.order-handle { touch-action: none; cursor: grab; border: 0; background: transparent; color: var(--bs-secondary-color); min-width: 44px; min-height: 44px; font-size: 1.2rem; }
.order-label { flex: 1 1 auto; display: flex; align-items: center; gap: .5rem; text-align: left; border: 0; background: transparent; min-height: 44px; color: inherit; min-width: 0; }
.order-num { flex: 0 0 auto; min-width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--bs-tertiary-bg); display: inline-grid; place-items: center; font-size: .8rem; font-weight: 700; }
.order-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-sub { color: var(--bs-secondary-color); font-size: .78rem; white-space: nowrap; }
.order-move { min-width: 44px; min-height: 44px; }

.pv-objstatus { font-size: .9rem; margin-top: .35rem; }
.pv-chips { display: flex; gap: .3rem; overflow-x: auto; padding: .25rem 0; scrollbar-width: thin; }
.pv-chip { flex: 0 0 auto; min-width: 44px; min-height: 44px; border-radius: 50%; border: 1px solid var(--bs-border-color); background: var(--bs-body-bg); color: inherit; font-weight: 700; }
.pv-chip.active { background: #f59e0b; border-color: #f59e0b; color: #1f2937; }

/* ---- Laser engraver module ---- */
#settingsPanel:not(.is-laser) .laser-only { display: none !important; }
#settingsPanel.is-laser .cnc-only { display: none !important; }
.laser-slider { display: flex; align-items: center; gap: .6rem; }
.laser-range { flex: 1 1 auto; height: 2.5rem; margin: 0; }
.laser-range::-webkit-slider-thumb { width: 1.6rem; height: 1.6rem; margin-top: -.5rem; }
.laser-range::-moz-range-thumb { width: 1.6rem; height: 1.6rem; }
.laser-range { touch-action: pan-y; }   /* horizontal drags move the slider; vertical drags still scroll the panel */
.laser-num { flex: 0 0 5.5rem; min-height: 44px; font-size: 16px; }   /* 16px stops iOS Safari zooming the page when the field is focused */
.laser-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; margin: .25rem 0 .5rem; }
.laser-steps .btn { min-height: 44px; touch-action: manipulation; }
.pv-banner .btn, .pv-actions .btn { min-height: 44px; touch-action: manipulation; }
#laserMachineInfo { margin-bottom: .5rem; }
.pv-legend { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .4rem; }
.pv-key { display: inline-block; width: 1.4rem; height: 0; border-top: 3px solid; vertical-align: middle; }
.pv-key-on { border-color: #dc2626; } .pv-key-off { border-color: #94a3b8; border-top-style: dashed; height: 0; }
.pv-key-start, .pv-key-end { width: .7rem; height: .7rem; border: 0; border-radius: 50%; }
.pv-key-start { background: #16a34a; } .pv-key-end { background: #1e293b; }
.pv-verify { align-items: flex-start; gap: .5rem; padding-left: 1.75rem; }
.pv-verify .form-check-input { width: 1.4rem; height: 1.4rem; margin-left: -1.75rem; }
@media (max-width: 575.98px) { .laser-num { flex-basis: 4.8rem; } }

#refreshApp .spin { display: inline-block; animation: refresh-spin .8s linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #refreshApp .spin { animation: none; } }

/* ---- Text tool ---- */
.text-panel { max-height: calc(var(--vvh, 100dvh) * .6); bottom: var(--kb, 0px); }
.text-panel .text-body { flex: 1 1 auto; min-height: 0; }
.text-content { font-size: 16px; min-height: 3.2rem; resize: vertical; }   /* 16px stops iOS zooming in on focus */
.text-panel .form-control, .text-panel .form-select { font-size: 16px; min-height: 44px; }
.text-panel .btn { min-height: 44px; }
.text-foot { display: flex; gap: .5rem; padding: .6rem 1rem; border-top: 1px solid var(--bs-border-color); background: var(--bs-body-bg); }
.text-foot .btn { flex: 1; }
.text-panel[data-rtl="1"] .text-content { direction: rtl; text-align: right; }
@media (min-width: 992px) {
  .panel.text-panel { display: none; }
  .panel.text-panel.open { display: flex; position: sticky; top: 0; max-height: none; max-height: calc(100dvh - 120px); bottom: auto; }
  .text-foot { padding-bottom: .6rem; }
}

.scale-box .form-control, .scale-box .form-select { font-size: 16px; min-height: 40px; }
.scale-box .btn { min-height: 44px; }

/* ---- Shapes & designs library ---- */
.shape-panel .shape-search { font-size: 16px; min-height: 44px; }
.shape-chips { display: flex; gap: .4rem; overflow-x: auto; padding: .5rem 0; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.shape-chip { flex: 0 0 auto; min-height: 36px; padding: 0 .8rem; border: 1px solid var(--bs-border-color); border-radius: 999px; background: var(--bs-body-bg); color: inherit; font-size: .85rem; }
.shape-chip.active { background: var(--bs-primary); border-color: var(--bs-primary); color: #fff; }
.shl-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; }
.shape-card { position: relative; min-width: 0; }
.shape-open { display: flex; flex-direction: column; align-items: center; gap: .25rem; width: 100%; min-height: 44px; padding: .4rem .25rem; border: 1px solid var(--bs-border-color); border-radius: .5rem; background: var(--bs-body-bg); color: inherit; }
.shape-open:focus-visible, .shape-chip:focus-visible, .shape-star:focus-visible { outline: 3px solid var(--bs-primary); outline-offset: 1px; }
.shape-thumb { display: block; width: 100%; aspect-ratio: 1; max-width: 84px; }
.shape-name { font-size: .75rem; line-height: 1.15; text-align: center; overflow-wrap: anywhere; }
.shape-star { position: absolute; top: 2px; right: 2px; width: 32px; height: 32px; border: 0; background: transparent; font-size: 1.1rem; line-height: 1; color: var(--bs-secondary-color); }
.shape-star.on { color: #e0a800; }
.shape-empty { grid-column: 1 / -1; padding: 1rem 0; }
.shape-preview { width: 100%; height: 120px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--bs-border-color); border-radius: .5rem; padding: .25rem; }
.shape-form .form-control, .shape-form .form-select { font-size: 16px; min-height: 44px; }
.shape-panel .field-row > div { min-width: 0; }
@media (min-width: 576px) { .shl-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 992px) {
  .panel.shape-panel { display: none; }
  .panel.shape-panel.open { display: flex; position: sticky; top: 0; max-height: calc(100dvh - 120px); bottom: auto; }
  .shl-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: no-preference) { .shape-open { transition: border-color .12s; } }

/* ---- single-stroke font preview ---- */
.tx-fontpreview { border: 1px solid var(--bs-border-color); border-radius: .5rem; padding: .4rem; background: var(--bs-body-bg); }
.tx-fontpreview svg { display: block; width: 100%; max-height: 180px; }
