:root{
  --bg: #f5f6fa;
  --panel-bg: #ffffff;
  --border: #e3e5ec;
  --text: #1b1e2b;
  --text-muted: #6b7080;
  --primary: #5b5bf6;
  --primary-dark: #4545d6;
  --primary-light: #eeeeff;
  --success: #17a673;
  --success-light: #e7f8f1;
  --danger: #e0445c;
  --danger-light: #fdeaee;
  --warn: #b8860b;
  --warn-light: #fff6e0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(20,20,50,0.06);
  --shadow-lg: 0 12px 40px rgba(20,20,50,0.18);
  font-size: 16px;
}

*{ box-sizing: border-box; }

/* Safety net: the [hidden] attribute must always win over any component's
   own display:flex/grid rule, otherwise toggling el.hidden in JS silently
   fails to actually hide the element. */
[hidden]{ display:none !important; }

body{
  margin:0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display:flex;
  flex-direction: column;
}

/* ===================== HEADER ===================== */
.app-header{
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}
.brand{ display:flex; align-items:center; gap:12px; }
.brand-mark{
  width:42px; height:42px; border-radius:10px;
  background: linear-gradient(135deg, var(--primary), #8b7bf7);
  color:#fff; display:flex; align-items:center; justify-content:center;
  font-size:20px; flex-shrink:0;
}
.brand-text h1{ margin:0; font-size:19px; font-weight:800; line-height:1.15; }
.brand-text h1 span{ font-weight:500; color: var(--text-muted); font-size: 15px; }
.tagline{ margin:2px 0 0; font-size:13px; color: var(--text-muted); }
.header-actions{ display:flex; align-items:center; gap:10px; }
.no-versions-note{
  display:inline-flex; align-items:center; gap:6px; color: var(--danger);
  font-size:12px; font-weight:600; max-width:340px; line-height:1.35;
}
.no-versions-note i{ flex-shrink:0; }

/* ===================== STEPS BAR ===================== */
.steps-bar{
  display:flex; align-items:center; justify-content:center;
  gap:10px; padding:12px 20px; background:#fbfbfe;
  border-bottom:1px solid var(--border); flex-wrap:wrap;
}
.step{ display:flex; align-items:center; gap:8px; opacity:0.45; transition:opacity .2s; }
.step.active{ opacity:1; }
.step.done{ opacity:0.85; }
.step-num{
  width:24px; height:24px; border-radius:50%; background:var(--border);
  color:#fff; display:flex; align-items:center; justify-content:center;
  font-size:12px; font-weight:700;
}
.step.active .step-num{ background: var(--primary); }
.step.done .step-num{ background: var(--success); }
.step-label{ font-size:13px; font-weight:600; color:var(--text); }
.step-sep{ width:26px; height:1px; background:var(--border); }

/* ===================== BADGES / BUTTONS ===================== */
.badge{ display:inline-flex; align-items:center; gap:6px; padding:6px 12px; border-radius:20px; font-size:12.5px; font-weight:600; }
.badge-muted{ background:#f0f1f7; color: var(--text-muted); }
.badge-success{ background: var(--success-light); color: var(--success); }

.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  border:none; border-radius: var(--radius-sm); padding:10px 16px;
  font-size:14px; font-weight:600; cursor:pointer; transition: all .15s ease;
  font-family: inherit;
}
.btn:disabled{ opacity:0.5; cursor:not-allowed; }
.btn-block{ width:100%; }
.btn-sm{ padding:8px 12px; font-size:13px; }
.btn-primary{ background: var(--primary); color:#fff; }
.btn-primary:hover:not(:disabled){ background: var(--primary-dark); }
.btn-secondary{ background:#f0f1f7; color: var(--text); }
.btn-secondary:hover:not(:disabled){ background:#e5e6f0; }
.btn-danger{ background: var(--danger-light); color: var(--danger); }
.btn-danger:hover:not(:disabled){ background:#fbdae0; }
.btn-ghost{ background:transparent; color: var(--text-muted); border:1px solid var(--border); }
.btn-ghost:hover{ background:#f4f4f8; }
.link-btn{
  background:none; border:none; color: var(--primary); font-weight:600;
  font-size:13px; cursor:pointer; padding:0; text-decoration:underline;
  font-family:inherit;
}
.icon-btn{
  width:32px; height:32px; border-radius:8px; border:1px solid var(--border);
  background:#fff; color:var(--text); cursor:pointer; display:flex; align-items:center; justify-content:center;
}
.icon-btn:hover{ background:#f4f4f8; }

/* ===================== LAYOUT ===================== */
.app-main{
  flex:1; display:flex; gap:0; align-items:stretch;
  max-width: 1500px; width:100%; margin:0 auto; padding: 20px 20px 40px;
  gap: 20px;
}

/* ===================== SIDEBAR ===================== */
.sidebar{
  width: 340px; flex-shrink:0; display:flex; flex-direction:column; gap:16px;
  max-height: calc(100vh - 160px); overflow-y:auto; padding-right:4px;
}
.panel{
  background: var(--panel-bg); border:1px solid var(--border); border-radius: var(--radius);
  padding:18px; box-shadow: var(--shadow);
}
.panel-title{
  margin:0 0 14px; font-size:15px; font-weight:700; display:flex; align-items:center; gap:8px;
}
.panel-title i{ color: var(--primary); }

/* ---- upload ---- */
.drop-zone{
  border:2px dashed #c9cbe0; border-radius: var(--radius); padding:28px 16px;
  text-align:center; cursor:pointer; transition: all .15s; background:#fafaff;
}
.drop-zone:hover, .drop-zone.dragover{ border-color: var(--primary); background: var(--primary-light); }
.drop-zone p{ margin:4px 0; font-size:13.5px; }
.drop-icon{ font-size:28px; color: var(--primary); margin-bottom:6px; }
.drop-hint{ color: var(--text-muted); font-size:12px; }
.sample-row{ margin-top:12px; font-size:12.5px; color:var(--text-muted); display:flex; flex-wrap:wrap; gap:8px; align-items:center; }

.meta-box{ margin-top:14px; background:#f8f9fc; border-radius: var(--radius-sm); padding:12px; }
.meta-row{ display:flex; justify-content:space-between; font-size:12.5px; padding:3px 0; }
.meta-row span{ color:var(--text-muted); }

.warning-note{
  margin-top:14px; font-size:12px; color:#8a6d00; background: var(--warn-light);
  border-radius: var(--radius-sm); padding:10px 12px; line-height:1.5;
}
.warning-note i{ margin-right:4px; }

/* ---- fields ---- */
.field{ margin-bottom:16px; }
.field:last-child{ margin-bottom:0; }
.field label{ display:block; font-size:13px; font-weight:600; margin-bottom:8px; }
.field-value{ font-weight:400; color: var(--primary); float:right; }
.field-inline{ display:flex; align-items:center; justify-content:space-between; margin-bottom:16px; }
.field-inline label{ margin-bottom:0; }
.tiny-hint{ font-size:11.5px; color: var(--text-muted); margin:6px 0 0; }
.tiny-hint-inline{ font-weight:400; font-size:11.5px; color:var(--text-muted); }

input[type="range"]{
  width:100%; accent-color: var(--primary); cursor:pointer;
}
input[type="color"]{
  width:100%; height:38px; border:1px solid var(--border); border-radius: var(--radius-sm);
  cursor:pointer; padding:2px;
}
input[type="number"]{
  width:100%; padding:8px 10px; border:1px solid var(--border); border-radius: var(--radius-sm);
  font-family:inherit; font-size:13px;
}

.segmented{ display:flex; background:#f0f1f7; border-radius: var(--radius-sm); padding:3px; }
.seg-btn{
  flex:1; border:none; background:transparent; padding:8px 10px; border-radius:6px;
  font-size:13px; font-weight:600; color:var(--text-muted); cursor:pointer; font-family:inherit;
}
.seg-btn.active{ background:#fff; color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

.switch{ position:relative; display:inline-block; width:42px; height:24px; flex-shrink:0; }
.switch input{ opacity:0; width:0; height:0; }
.switch-slider{
  position:absolute; cursor:pointer; inset:0; background:#ccc; border-radius:24px; transition:.2s;
}
.switch-slider::before{
  content:""; position:absolute; height:18px; width:18px; left:3px; bottom:3px;
  background:#fff; border-radius:50%; transition:.2s;
}
.switch input:checked + .switch-slider{ background: var(--primary); }
.switch input:checked + .switch-slider::before{ transform: translateX(18px); }

.status-text{ margin-top:10px; font-size:12.5px; text-align:center; color: var(--text-muted); }
.status-text.error{ color: var(--danger); }
.status-text.success{ color: var(--success); }

/* Disabled state while a trusted edit-permission check is in flight with
   the server (see setEditGateBusy() in js/app.js) — gives visible feedback
   during the brief round-trip and helps prevent duplicate submissions from
   rapid double-clicks. */
#fill-color-input:disabled,
#scale-slider:disabled,
#delete-shape-btn:disabled,
.move-btn:disabled{ opacity:.55; cursor:wait; }

/* ---- edit panel ---- */
.edit-counter-box{ background:#f8f9fc; border-radius: var(--radius-sm); padding:12px; margin-bottom:14px; }
.edit-counter-row{ display:flex; align-items:center; justify-content:space-between; font-size:13px; font-weight:600; margin-bottom:8px; }
.edit-dots{ display:flex; gap:6px; }
.edit-dots .dot{ flex:1; height:6px; border-radius:4px; background:#e3e5ec; }
.edit-dots .dot.used{ background: var(--primary); }
.edit-dots .dot.over{ background: var(--danger); }

.undo-redo-row{ display:flex; gap:8px; margin-bottom:14px; }
.undo-redo-row .btn{ flex:1; }

.hint-box{
  background:#f8f9fc; border:1px dashed var(--border); border-radius: var(--radius-sm);
  padding:12px; font-size:12.5px; color:var(--text-muted); margin-bottom:14px; line-height:1.5;
}

#selection-tools{ margin-bottom:6px; }
#selected-shape-name{ color: var(--primary); }

.move-pad{ display:flex; flex-direction:column; align-items:center; gap:4px; width:fit-content; margin:0 auto; }
.move-mid-row{ display:flex; gap:4px; align-items:center; }
.move-btn{
  width:34px; height:34px; border-radius:8px; border:1px solid var(--border);
  background:#fff; cursor:pointer; display:flex; align-items:center; justify-content:center; color: var(--text);
}
.move-btn:hover{ background: var(--primary-light); color: var(--primary); }
.move-center{ cursor: default; color:var(--text-muted); }
.move-center:hover{ background:#fff; color:var(--text-muted); }

.layers-field{ margin-top:6px; }
.layers-list{ list-style:none; margin:0; padding:0; max-height:180px; overflow-y:auto; border:1px solid var(--border); border-radius: var(--radius-sm); }
.layer-item{
  display:flex; align-items:center; gap:8px; padding:8px 10px; font-size:12.5px;
  cursor:pointer; border-bottom:1px solid var(--border);
}
.layer-item:last-child{ border-bottom:none; }
.layer-item:hover{ background:#f8f9fc; }
.layer-item.selected{ background: var(--primary-light); color: var(--primary-dark); font-weight:600; }
.layer-swatch{ width:14px; height:14px; border-radius:3px; border:1px solid rgba(0,0,0,0.15); flex-shrink:0; }
.layer-item.deleted{ opacity:0.35; text-decoration: line-through; }

.divider{ border:none; border-top:1px solid var(--border); margin:16px 0; }

.size-inputs{ display:flex; align-items:center; gap:10px; margin-bottom:10px; }
.size-input-group{ flex:1; }
.size-input-group label{ font-size:11px; color:var(--text-muted); margin-bottom:4px; }
.lock-icon{ color:var(--text-muted); margin-top:16px; }

/* ===================== WORKSPACE ===================== */
.workspace{
  flex:1; display:flex; flex-direction:column; min-width:0;
  background: var(--panel-bg); border:1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow:hidden;
}
.workspace-toolbar{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:12px 16px; border-bottom:1px solid var(--border); flex-wrap:wrap;
}
.view-tabs{ display:flex; gap:4px; background:#f0f1f7; border-radius: var(--radius-sm); padding:3px; }
.view-tab{
  border:none; background:transparent; padding:7px 14px; border-radius:6px; font-size:13px;
  font-weight:600; color:var(--text-muted); cursor:pointer; font-family:inherit;
}
.view-tab.active{ background:#fff; color: var(--primary); box-shadow:0 1px 3px rgba(0,0,0,0.08); }
.zoom-controls{ display:flex; align-items:center; gap:8px; font-size:13px; font-weight:600; color:var(--text-muted); }

#banner-area{ padding: 0 16px; }
.info-banner{
  display:flex; align-items:flex-start; gap:10px; padding:10px 14px; border-radius: var(--radius-sm);
  font-size:13px; margin-top:12px; line-height:1.5;
}
.info-banner.warn{ background: var(--warn-light); color:#8a6d00; }
.info-banner.error{ background: var(--danger-light); color: var(--danger); }
.info-banner.success{ background: var(--success-light); color: var(--success); }
.info-banner i{ margin-top:2px; }

.canvas-area{ flex:1; position:relative; padding:16px; min-height:480px; display:flex; }

.empty-state{
  margin:auto; text-align:center; color: var(--text-muted); padding:40px;
}
.empty-icon{ font-size:44px; color:#d6d8ea; margin-bottom:14px; }
.empty-state h3{ margin:0 0 6px; color: var(--text); font-size:17px; }

.compare-grid{
  display:grid; grid-template-columns:1fr 1fr; gap:16px; flex:1; width:100%;
}
.compare-grid.single{ grid-template-columns: 1fr; }
.preview-pane{
  display:flex; flex-direction:column; border:1px solid var(--border); border-radius: var(--radius-sm); overflow:hidden; min-height:400px;
}
.pane-label{
  padding:8px 12px; font-size:12.5px; font-weight:700; background:#f8f9fc; border-bottom:1px solid var(--border);
  display:flex; align-items:baseline; gap:8px;
}
.pane-label-sub{ font-weight:400; color:var(--text-muted); font-size:11px; }
.pane-scroll{ flex:1; overflow:auto; display:flex; align-items:center; justify-content:center; position:relative; }
.pane-zoom-wrap{ display:flex; align-items:center; justify-content:center; transition: transform .1s ease; padding:20px; }
.pane-zoom-wrap img{ max-width:100%; display:block; image-rendering:auto; }
#vector-container svg{ display:block; max-width:100%; height:auto; }

.checker-bg{
  background-image:
    linear-gradient(45deg, #e9e9ef 25%, transparent 25%),
    linear-gradient(-45deg, #e9e9ef 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e9e9ef 75%),
    linear-gradient(-45deg, transparent 75%, #e9e9ef 75%);
  background-size:20px 20px;
  background-position:0 0, 0 10px, 10px -10px, -10px 0px;
  background-color:#fbfbfd;
}

/* shape selection outline within svg */
.svg-shape-selected{ outline: 2px dashed var(--primary) !important; outline-offset:2px; }

/* ===================== FOOTER ===================== */
.app-footer{
  text-align:center; padding:16px; font-size:12px; color: var(--text-muted);
  border-top:1px solid var(--border); background: var(--panel-bg);
}

/* ===================== MODAL ===================== */
.modal-overlay{
  position:fixed; inset:0; background:rgba(20,20,40,0.5); display:flex; align-items:center; justify-content:center;
  z-index:1000; padding:20px;
}
.modal-box{
  background:#fff; border-radius:16px; max-width:420px; width:100%; padding:28px; position:relative;
  box-shadow: var(--shadow-lg); text-align:center;
}
.modal-close{
  position:absolute; top:14px; right:14px; border:none; background:#f0f1f7; width:30px; height:30px;
  border-radius:50%; cursor:pointer; color:var(--text-muted);
}
.modal-icon{
  width:56px; height:56px; border-radius:50%; background: var(--primary-light); color:var(--primary);
  display:flex; align-items:center; justify-content:center; font-size:24px; margin:0 auto 14px;
}
.modal-box h2{ margin:0 0 8px; font-size:19px; }
.modal-box p{ color:var(--text-muted); font-size:13.5px; line-height:1.6; margin:0 0 16px; }
.price-box{
  background:#f8f9fc; border-radius: var(--radius-sm); padding:14px; margin-bottom:18px;
}
.price{ font-size:32px; font-weight:800; color: var(--text); display:block; }
.price-note{ font-size:11.5px; color:var(--text-muted); }
#paypal-button-container{ margin-bottom:10px; min-height:45px; }
.paypal-sandbox-note{ text-align:center; margin-bottom:14px; }
.dev-entitlement-box{
  border:1px dashed #c9cbe0; border-radius: var(--radius-sm); padding:14px; margin-bottom:14px; background:#fafaff; text-align:left;
}
.dev-label{ font-size:12.5px; font-weight:700; color: var(--primary-dark); margin:0 0 4px; display:flex; align-items:center; gap:6px; }
.dev-entitlement-box .tiny-hint{ margin-bottom:10px; }

.start-new-confirm-actions{ display:flex; gap:10px; }
.start-new-confirm-actions .btn{ flex:1; }

/* ===================== TOAST ===================== */
.toast{
  position:fixed; bottom:24px; left:50%; transform:translateX(-50%);
  background:#1b1e2b; color:#fff; padding:12px 20px; border-radius:10px; font-size:13.5px;
  box-shadow: var(--shadow-lg); z-index:2000; display:flex; align-items:center; gap:8px;
}
.toast.error{ background: var(--danger); }
.toast.success{ background: var(--success); }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 980px){
  .app-main{ flex-direction:column; padding:14px; }
  .sidebar{ width:100%; max-height:none; overflow:visible; }
  .compare-grid{ grid-template-columns:1fr; }
  .steps-bar{ overflow-x:auto; justify-content:flex-start; }
}
@media (max-width: 600px){
  .app-header{ padding:12px 16px; }
  .brand-text h1{ font-size:16px; }
  .tagline{ display:none; }
  .header-actions{ width:100%; justify-content:space-between; }
}
