:root{
  --sidebar-width: 280px;
  --accent: #85adfa;
  --accent-text: #2a5adf;
  --page-bg: #eef0f4;
  --card-bg: #ffffff;
  --control-bg: #f2f3f6;
  --control-bg-active: #e6e9f0;
  --border: rgba(0,0,0,.08);
  --text: #1c1c1e;
  --text-secondary: #6e6e73;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
*{
  -webkit-tap-highlight-color: transparent;
}
body{
  margin:0;
  font-family:var(--font);
  height:100vh;
  background:#dde0e6;
  color:var(--text);
}
.heading{
  font-size:1.1em;
  font-weight:700;
  letter-spacing:-.01em;
  margin:0;
  display:flex;
  align-items:baseline;
  gap:6px;
}

.heading span{
  font-size:0.55em;
  font-weight:600;
  color:var(--text-secondary);
}

/* SIDEBAR */
.sidebar{
  position:fixed;
  top:0;
  left:0;
  bottom:0;
  width:var(--sidebar-width);
  display:flex;
  flex-direction:column;
  font-size:0.85em;
  background:var(--page-bg);
  border-right:1px solid var(--border);
  z-index:5;
}
.sidebar-header{
  flex:0 0 auto;
  padding:14px 16px 12px;
  border-bottom:1px solid var(--border);
}
.sidebar-footer{
  flex:0 0 auto;
  padding:10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top:1px solid var(--border);
  background:var(--page-bg);
}

/* RIGHT SIDEBAR — hidden unless the RIGHT_SIDEPANEL config flag in app.js
   turns on body.has-right-sidebar (see the CONFIG section at the top of
   app.js). Mirrors the left .sidebar's width so the canvas stays centered
   between two equal-width columns when both are shown. */
.sidebar-right{
  display:none;
  position:fixed;
  top:0;
  right:0;
  bottom:0;
  width:var(--sidebar-width);
  background:var(--accent);
  z-index:5;
}
body.has-right-sidebar .sidebar-right{
  display:block;
}

/* SETTINGS (scrollable middle section of the sidebar) */
.settings{
  flex:1 1 auto;
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
  padding:14px;
  display:flex;
  flex-direction:column;
  gap:16px;
}
.settings-group-title{
  font-size:.66rem;
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:.06em;
  color:var(--text-secondary);
  margin:0 0 6px 4px;
}

/* grouped "list" card — rows separated by hairlines, iOS Settings style */
.settings-card{
  background:var(--card-bg);
  border-radius:12px;
  box-shadow:0 1px 2px rgba(0,0,0,.06);
  overflow:hidden;
}
.settings-card label{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  min-height:34px;
  padding:6px 12px;
  margin:0;
  border-bottom:1px solid var(--border);
}
.settings-card label:last-child{
  border-bottom:none;
}
.row-label{
  font-size:.82rem;
  color:var(--text);
  flex:1 1 auto;
}

.settings input,
.settings select{
  font-family:var(--font);
  font-size:.82rem; /* matches .row-label; iOS will auto-zoom on focus below 16px, accepted for the space savings */
  color:var(--text);
  background:var(--control-bg);
  border:1px solid transparent;
  border-radius:7px;
  padding:3px 8px;
  box-sizing:border-box;
  text-align:right;
  transition:background-color .15s, border-color .15s;
}
.settings input{
  width:66px;
  flex:0 0 auto;
}
.settings select{
  width:auto;
  max-width:104px;
  text-align:left;
  flex:0 1 auto;
}
.settings input:focus,
.settings select:focus{
  outline:none;
  background:#fff;
  border-color:var(--accent);
  box-shadow:0 0 0 3px rgba(133,173,250,.35);
}
.settings button{
  font-family:var(--font);
  font-size:.8rem;
  font-weight:600;
  color:var(--text);
  background:var(--control-bg);
  border:1px solid transparent;
  border-radius:999px;
  padding:4px 12px;
  min-height:26px;
  box-sizing:border-box;
  cursor:pointer;
  transition:background-color .15s, transform .05s;
}
.settings button:hover{
  background:var(--control-bg-active);
}
.settings button:active{
  transform:scale(.96);
}
.settings button:focus-visible,
.settings input:focus-visible,
.settings select:focus-visible{
  outline:2px solid var(--accent);
  outline-offset:2px;
}

/* iOS-STYLE TOGGLE SWITCH */
.switch{
  position:relative;
  display:inline-block;
  flex:0 0 auto;
  width:38px;
  height:22px;
}
.switch input{
  opacity:0;
  width:0;
  height:0;
}
.switch .slider{
  position:absolute;
  inset:0;
  background:#d9dae0;
  border-radius:34px;
  cursor:pointer;
  transition:background-color .2s;
}
.switch .slider::before{
  content:"";
  position:absolute;
  left:3px;
  top:3px;
  width:16px;
  height:16px;
  background:#fff;
  border-radius:50%;
  box-shadow:0 1px 3px rgba(0,0,0,.25);
  transition:transform .2s;
}
.switch input:checked + .slider{
  background:var(--accent);
}
.switch input:checked + .slider::before{
  transform:translateX(16px);
}
.switch input:focus-visible + .slider{
  outline:2px solid var(--accent);
  outline-offset:2px;
}

/* ORIENTATION BUTTONS (portrait / landscape) */
.orientation-toggle{
  display:flex;
  gap:6px;
  flex:0 0 auto;
}
/* extra ".settings" prefix bumps specificity above the generic ".settings
   button" pill styling so width/radius/padding actually win */
.settings .orientation-btn{
  display:flex;
  align-items:center;
  justify-content:center;
  width:32px;
  height:28px;
  padding:0;
  border-radius:8px;
  background:var(--control-bg);
}
.settings .orientation-btn.active{
  background:var(--accent);
}
.orientation-icon{
  width:16px;
  height:16px;
  display:block;
  pointer-events:none;
}
.settings .orientation-btn.active .orientation-icon{
  filter:brightness(0) invert(1);
}

/* IMPORT / EXPORT BUTTON ROW */
.button-row{
  display:flex;
  gap:8px;
  flex:1 1 auto;
}
.button-row button{
  flex:1 1 0;
}

#exportPdf{
  width:100%;
  font-family:var(--font);
  font-size:.88rem;
  font-weight:700;
  color:#fff;
  background:var(--accent-text);
  border:0;
  border-radius:10px;
  padding:9px 8px;
  box-sizing:border-box;
  cursor:pointer;
  box-shadow:0 2px 8px rgba(42,90,223,.35);
  transition:background-color .15s, transform .05s;
}
#exportPdf:hover{
  background:#2450cc;
}
#exportPdf:active{
  transform:scale(.98);
}
#exportPdf:focus-visible{
  outline:2px solid var(--accent);
  outline-offset:2px;
}


/* CANVAS */
.canvas{
  position:fixed;
  top:0;
  left:var(--sidebar-width);
  right:0;
  bottom:0;
  display:flex;
  justify-content:center;
  align-items:center;
}
/* Leaves room for the right sidebar when it's visible, so the page preview
   stays centered between both columns instead of sliding under it. */
body.has-right-sidebar .canvas{
  right:var(--sidebar-width);
}
.page{
  position:relative;
  background:#fff;
  height:90%;
  box-shadow:0 0 20px rgba(0,0,0,.2);
}

/* HISTORY (UNDO / REDO) */
.history-controls{
  position:absolute;
  left:20px;
  bottom:20px;
  display:flex;
  gap:10px;
  z-index:6;
}
.history-btn{
  width:44px;
  height:44px;
  padding:0;
  border:0;
  border-radius:50%;
  background:var(--accent);
  color:#fff;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  box-shadow:0 2px 8px rgba(0,0,0,.18);
  transition:filter .15s, transform .05s, opacity .15s;
}
.history-btn svg{
  display:block;
  pointer-events:none;
}
.history-btn:hover:not(:disabled){
  filter:brightness(.92);
}
.history-btn:active:not(:disabled){
  transform:scale(.94);
}
.history-btn:disabled{
  opacity:.4;
  cursor:default;
}
.history-btn:focus-visible{
  outline:2px solid var(--accent-text);
  outline-offset:2px;
}

/* PAGE SVG — every panel, connector, label, and preview element now lives
   inside this one SVG, filling #page exactly (viewBox set in js/app.js
   render() to match #page's pixel size 1:1). */
.page-svg{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
}

/* PANELS — native polygons; hit-testing is the browser's own SVG shape
   hit-test against the true (possibly angled) geometry, no bounding-box
   approximation involved. */
.panel{
  fill:#fafafa;
  stroke:#000;
  stroke-width:1;
  vector-effect:non-scaling-stroke;
  touch-action:manipulation;
}
.panel.split-hover{
  stroke:red;
  cursor:pointer;
}
.panel.merge-hover{
  stroke:#1e6bff;
}
.split-line{
  pointer-events:none;
  stroke:red;
  stroke-width:1;
  stroke-dasharray:4 3;
  display:none;
}
.merge-box{
  fill:none;
  stroke:none;
  pointer-events:none;
  display:none;
}

/* MERGE CONNECTORS — 3 sections along their length: dragging the middle
   moves both the start and end point of the split together (unchanged
   resize behavior, generalized to translate an already-angled cut intact);
   dragging start/end tilts just that one endpoint. Always faintly visible
   (unlike the old single-strip connector, which was invisible until
   hover), and brightens on hover. Each section's polygon points are
   recomputed directly from the two panels' live corners (js/app.js
   createUniqueConnector/repaint), so the connector visually *is* the true
   gap shape and hit-tests as it natively — no separate stale hit-box.
   Clicking any of the 3 sections still merges, via event bubbling to the
   parent <g class="connector">'s onclick. */
.connector{
  cursor:pointer;
  touch-action:none;
}
.connector-start{ fill:rgba(133,173,250,.35); pointer-events:auto; }
.connector-mid  { fill:rgba(0,120,255,.15);  pointer-events:auto; }
.connector-end  { fill:rgba(42,90,223,.35);  pointer-events:auto; }
.connector-start:hover{ fill:rgba(133,173,250,.75); }
.connector-mid:hover  { fill:rgba(0,120,255,.6); }
.connector-end:hover  { fill:rgba(42,90,223,.75); }

/* LABELS */
.label{
  font-family:var(--font);
  font-size:10px;
  fill:var(--text);
  pointer-events:none;
  text-anchor:middle;
}

/* DEBUG_NAMES label (js/app.js CONFIG) — each panel's own dotted id,
   drawn at its centroid. Bold + a fixed dark color (not var(--text), so
   it stays legible against DEBUG_COLOR's own light backgrounds and
   against dark-mode text alike) and dominant-baseline so it centers
   vertically on its anchor point, not just horizontally. */
.debug-label{
  font-family:var(--font);
  font-size:11px;
  font-weight:700;
  fill:#c0392b;
  pointer-events:none;
  text-anchor:middle;
  dominant-baseline:middle;
}

/* CURSOR DOT */
.cursor-dot{
  position:fixed;
  width:12px;
  height:12px;
  border-radius:50%;
  background:red;
  pointer-events:none;
  transform:translate(-50%,-6px);
  display:none;
}

/* MOBILE / NARROW VIEWPORTS — stack the sidebar above the canvas instead of
   squeezing both into a split-screen layout */
@media (max-width: 700px){
  body{
    height:auto;
    overflow-y:auto;
  }
  .sidebar{
    position:static;
    width:100%;
    max-height:none;
    border-right:0;
    border-bottom:1px solid var(--border);
  }
  .settings{
    max-height:50vh;
  }
  .canvas{
    position:static;
    left:0;
    right:0 !important;
    height:70vh;
    padding:24px 12px;
    box-sizing:border-box;
  }
  .sidebar-right{
    position:static;
    width:100%;
    height:40px;
  }
}

/* PRINT (native browser print of the editor view, fallback to the PDF export flow) */
@media print{
  @page{
    margin:0;
  }
  body{
    background:#fff;
  }
  .sidebar,
  .sidebar-right,
  .label,
  .debug-label,
  .cursor-dot,
  .connector,
  .merge-box,
  .split-line,
  .history-controls{
    display:none !important;
  }
  /* .page-svg itself stays visible — panels are drawn directly as SVG
     polygons now, so there's no separate border layer to reconcile. */
  .canvas{
    position:static;
    inset:auto;
    display:block;
    width:var(--page-w) !important;
    height:var(--page-h) !important;
  }
  .page{
    width:var(--page-w) !important;
    height:var(--page-h) !important;
    box-shadow:none;
  }
}
