/* Annotate — the house tokens (myjp.ca/login/ui.css, which are budget's on the
   M4), laid out as an editor: a bar, pages on the left, the stage, style and
   layers on the right. One accent for selection (the system blue); red is the
   default INK, not a UI colour. No backdrop-filter anywhere (IOS.md §24). */
:root {
  --bg: #f2f2f7; --panel: #ffffff; --panel-2: #f6f6f9; --line: rgba(60, 60, 67, .16);
  --ink: #000000; --ink-2: #3c3c43; --dim: #8a8a8e; --dim-2: #b0b0b6; --pill: #efeff0;
  --good: #1a9e4b; --bad: #e5322b; --link: #007aff; --accent: #007aff;
  --stage: #e4e4ea; --stage-dot: rgba(60, 60, 67, .10);
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.06);
  --shadow-float: 0 2px 6px rgba(0,0,0,.08), 0 10px 30px rgba(0,0,0,.10);
  --r-card: 20px; --r-mid: 13px; --r-tile: 10px;
  --font: -apple-system, BlinkMacSystemFont, system-ui, "SF Pro Text", "Helvetica Neue", sans-serif;
  --font-round: "SF Pro Rounded", ui-rounded, -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --bar-h: 52px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #000000; --panel: #1c1c1e; --panel-2: #2c2c2e; --line: rgba(84, 84, 88, .48);
  --ink: #ffffff; --ink-2: #d7d7db; --dim: #98989f; --dim-2: #6c6c70; --pill: #2c2c2e;
  --good: #30d158; --bad: #ff453a; --link: #0a84ff; --accent: #0a84ff;
  --stage: #0e0e10; --stage-dot: rgba(255, 255, 255, .06);
  --shadow: none; --shadow-float: 0 2px 10px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .001ms !important; transition-duration: .001ms !important; } }
button, input, select { font: inherit; color: inherit; }
button, a, label, input, select { touch-action: manipulation; }
.grow { flex: 1; }

/* ── buttons (budget's rule: filled ink pill default, .ghost the quiet one) ── */
button { background: var(--ink); color: var(--panel); border: 0; border-radius: 999px; padding: 10px 16px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; }
button:disabled { opacity: .4; cursor: default; }
button.ghost { background: var(--pill); color: var(--ink); }
button.tiny { padding: 6px 12px; font-size: 13px; }
button.danger { background: var(--bad); color: #fff; }
button.block { width: 100%; justify-content: center; padding: 12px 18px; font-size: 15px; }
button .spinner { display: none; }
button.busy .spinner { display: inline-block; }
button.busy .label { opacity: .6; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { background: transparent; color: var(--ink); padding: 0; width: 36px; height: 36px; justify-content: center; border-radius: 10px; flex: none; }
.icon-btn:hover:not(:disabled) { background: var(--pill); }
.icon-btn.small { width: 28px; height: 28px; border-radius: 8px; }
.icon-btn.on { background: var(--ink); color: var(--panel); }
[data-icon] { display: inline-flex; line-height: 0; }
[data-icon] svg { width: 18px; height: 18px; }
.icon-btn.small [data-icon] svg { width: 15px; height: 15px; }
a.btn { display: block; text-align: center; text-decoration: none; font-weight: 600; font-size: 15px; border-radius: 999px; padding: 12px 18px; background: var(--ink); color: var(--panel); }
.meta { color: var(--dim); font-size: 13px; line-height: 1.45; }

/* ── the door ── */
.gate { min-height: 100%; overflow: auto; display: flex; flex-direction: column; align-items: center; padding: 8vh 20px 40px; }
.wordmark { font-family: var(--font-round); font-weight: 700; font-size: clamp(2rem, 8vw, 2.5rem); letter-spacing: -0.01em; margin: 0 0 22px; color: var(--ink); text-decoration: none; }
.wordmark .dim-ca { color: var(--dim); }
.card { width: 100%; max-width: 440px; background: var(--panel); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 24px; }
.card p { color: var(--ink-2); font-size: 15px; line-height: 1.45; margin: 0 0 16px; }
.card p.meta { color: var(--dim); font-size: 13px; margin: 14px 0 0; }
.lockup { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.lockup h1 { margin: 0; font-size: 22px; }
.lockup.small { gap: 10px; margin: 0; }
.app-icon svg { width: 56px; height: 56px; }
.lockup.small .app-icon svg { width: 30px; height: 30px; }
.foot { color: var(--dim); font-size: 13px; margin-top: 18px; }
.foot a { color: var(--dim); }

/* ── the editor frame ── */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  height: var(--bar-h); flex: none; display: flex; align-items: center; gap: 4px;
  padding: 0 10px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.back { display: inline-flex; align-items: center; gap: 2px; color: var(--dim); text-decoration: none; font-weight: 600; padding: 6px 8px 6px 2px; border-radius: 8px; }
.back:hover { color: var(--ink); }
.project-name { border: 0; background: transparent; font-weight: 650; font-size: 15px; padding: 7px 9px; border-radius: 8px; min-width: 60px; width: 22ch; max-width: 34vw; text-overflow: ellipsis; }
.project-name:hover { background: var(--panel-2); }
.project-name:focus { outline: 2px solid var(--accent); background: var(--panel); }
.saved { color: var(--dim); font-size: 12px; white-space: nowrap; }
.saved.bad { color: var(--bad); font-weight: 600; }
button.primary { margin-left: 6px; padding: 8px 14px; }
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 172px 1fr 276px; }

.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 14px; font-size: 12px; font-weight: 650; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; }

/* pages */
.pages { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.page-list { list-style: none; margin: 0; padding: 2px 12px 16px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; }
.page-item { display: grid; grid-template-columns: 18px 1fr; gap: 6px; align-items: start; cursor: pointer; position: relative; }
.page-num { color: var(--dim); font-size: 11px; font-weight: 600; text-align: right; padding-top: 4px; font-variant-numeric: tabular-nums; }
.page-thumb { position: relative; border-radius: 8px; overflow: hidden; background: var(--stage); outline: 1px solid var(--line); display: grid; place-items: center; }
.page-thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.page-item.on .page-thumb { outline: 2.5px solid var(--accent); outline-offset: 1px; }
.page-name { grid-column: 2; font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: -2px; }
.page-more { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 7px; background: rgba(0,0,0,.55); color: #fff; padding: 0; justify-content: center; opacity: 0; }
.page-item:hover .page-more, .page-item.on .page-more { opacity: 1; }
.page-item.drop-before::before, .layer-row.drop-before::before { content: ''; position: absolute; left: 0; right: 0; top: -7px; height: 3px; border-radius: 2px; background: var(--accent); }
.page-item.drop-after::after, .layer-row.drop-after::after { content: ''; position: absolute; left: 0; right: 0; bottom: -7px; height: 3px; border-radius: 2px; background: var(--accent); }

/* stage */
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--stage); background-image: radial-gradient(var(--stage-dot) 1px, transparent 1px); background-size: 18px 18px; }
.canvas-host { position: absolute; inset: 0; touch-action: none; }
.canvas-host .canvas-container { touch-action: none; }
.dock {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; gap: 2px; padding: 5px; background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-float);
  max-width: calc(100% - 24px); overflow-x: auto; scrollbar-width: none;
}
.dock::-webkit-scrollbar { display: none; }
.dock .sep { width: 1px; background: var(--line); margin: 4px 3px; flex: none; }
.dock .icon-btn { width: 38px; height: 38px; }
.dock .icon-btn.on { background: var(--accent); color: #fff; }
.zoombar { position: absolute; right: 12px; bottom: 12px; z-index: 5; display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow-float); }
.zoom-pct { background: transparent; color: var(--ink); padding: 4px 6px; min-width: 54px; justify-content: center; font-variant-numeric: tabular-nums; font-size: 13px; border-radius: 8px; }
.zoom-pct:hover { background: var(--pill); }
.cropbar { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 6; display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px; background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-float); white-space: nowrap; max-width: calc(100% - 24px); overflow-x: auto; }
.crop-title { font-weight: 650; }
.drop-hint { position: absolute; inset: 10px; z-index: 7; border: 2.5px dashed var(--accent); border-radius: 16px; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 8%, transparent); pointer-events: none; }
.drop-hint div { background: var(--panel); padding: 14px 18px; border-radius: 14px; box-shadow: var(--shadow-float); display: flex; flex-direction: column; gap: 4px; text-align: center; }
.drop-hint span { color: var(--dim); font-size: 13px; }

/* segmented control */
.seg { display: inline-flex; background: var(--pill); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { background: transparent; color: var(--ink); padding: 5px 9px; border-radius: 7px; font-size: 13px; font-weight: 550; justify-content: center; }
.seg button.on { background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
:root[data-theme="dark"] .seg button.on { background: #636366; }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; }
.seg button [data-icon] svg { width: 16px; height: 16px; }
.seg.grow-ctl { flex: 1; }

/* side: inspector + layers */
.side { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.inspector { flex: none; max-height: 62%; overflow-y: auto; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.insp-title { display: flex; align-items: center; gap: 8px; padding: 12px 14px 4px; font-weight: 650; font-size: 14px; }
.insp-title .meta { font-weight: 400; margin-left: auto; font-size: 12px; }
.insp-title .link-btn { margin-left: auto; border: 0; background: none; padding: 2px 4px; color: var(--link); font: inherit; font-weight: 500; font-size: 13px; cursor: pointer; }
.row { display: flex; align-items: center; gap: 8px; padding: 6px 14px; }
.row > label, .field > label { width: 64px; flex: none; color: var(--dim); font-size: 12px; font-weight: 550; }
.row .grow-ctl { flex: 1; min-width: 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.sw { width: 22px; height: 22px; border-radius: 50%; padding: 0; border: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); cursor: pointer; flex: none; }
:root[data-theme="dark"] .sw { box-shadow: inset 0 0 0 1px rgba(255,255,255,.28); }
.sw.on { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.sw.custom { background: conic-gradient(#ff3b30, #ffcc00, #34c759, #00c7be, #007aff, #af52de, #ff3b30); position: relative; overflow: hidden; }
.sw.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; padding: 0; border: 0; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.num { width: 34px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 12px; }
select { background: var(--pill); border: 0; border-radius: 8px; padding: 6px 8px; font-size: 13px; }
.mini-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 4px; }
.mini-actions button { padding: 6px 10px; font-size: 12px; background: var(--pill); color: var(--ink); }
.mini-actions button.danger { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.hint { padding: 6px 14px 10px; color: var(--dim); font-size: 12px; line-height: 1.45; }
.kbd { display: inline-block; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: 11px; color: var(--ink-2); }

.layers { flex: 1; min-height: 120px; display: flex; flex-direction: column; }
.layer-list { overflow-y: auto; flex: 1; padding: 0 8px 14px; }
.layer-row { position: relative; display: flex; align-items: center; gap: 2px; height: 34px; padding: 0 4px; border-radius: 9px; cursor: pointer; }
.layer-row:hover { background: var(--panel-2); }
.layer-row.active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.layer-row .lname { flex: 1; min-width: 0; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 2px; }
.layer-row .lcount { color: var(--dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.layer-row .icon-btn.small { width: 26px; height: 26px; color: var(--dim); }
.layer-row .icon-btn.small.off { color: var(--dim-2); }
.layer-row .icon-btn.small.lockon { color: var(--ink); }
.layer-row.hidden-layer .lname { color: var(--dim); }
.layer-row input { flex: 1; min-width: 0; font-weight: 600; font-size: 13px; border: 0; outline: 2px solid var(--accent); border-radius: 6px; padding: 3px 5px; background: var(--panel); }
.obj-row { position: relative; display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 8px 0 34px; border-radius: 8px; cursor: pointer; font-size: 12.5px; color: var(--ink-2); }
.obj-row:hover { background: var(--panel-2); }
.obj-row.sel { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--ink); }
.obj-row .chip { width: 10px; height: 10px; border-radius: 3px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.obj-row .oname { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.obj-row [data-icon] svg { width: 14px; height: 14px; color: var(--dim); }
.obj-row.locked { opacity: .55; }
.layer-empty { padding: 2px 8px 6px 34px; color: var(--dim-2); font-size: 12px; }

/* sheets: projects, export */
.sheet-bg { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.32); display: flex; align-items: center; justify-content: center; padding: 20px; }
.sheet { width: 100%; max-width: 860px; max-height: calc(100dvh - 40px); overflow-y: auto; background: var(--bg); border-radius: var(--r-card); box-shadow: var(--shadow-float); padding: 18px 20px 20px; }
.sheet.narrow { max-width: 440px; background: var(--panel); }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 17px; }
.start-drop { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 30px 16px; border-radius: 16px; border: 2px dashed var(--dim-2); background: var(--panel); cursor: pointer; text-align: center; }
.start-drop:hover, .start-drop.over { border-color: var(--accent); }
.start-drop b { font-size: 17px; }
.start-drop span { color: var(--dim); }
.start-drop .big svg { width: 34px; height: 34px; color: var(--dim); }
.start-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; align-items: center; }
.start-row select { padding: 9px 10px; border-radius: 999px; }
.recent-head { font-size: 13px; color: var(--dim); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; margin: 18px 0 10px; }
.recent { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.proj { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; cursor: pointer; position: relative; }
.proj .pthumb { aspect-ratio: 4 / 3; background: var(--stage); display: grid; place-items: center; }
.proj .pthumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.proj .pmeta { padding: 8px 10px 10px; }
.proj .pname { font-weight: 650; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj .psub { color: var(--dim); font-size: 12px; }
.proj.current { outline: 2.5px solid var(--accent); }
.proj .page-more { opacity: 1; top: 6px; right: 6px; }
.recent-empty { grid-column: 1 / -1; color: var(--dim); font-size: 14px; padding: 6px 2px; }
.sheet-foot { margin-top: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { width: auto; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--ink-2); line-height: 1.4; margin-bottom: 12px; cursor: pointer; }
.check input { margin-top: 2px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
#exSummary { margin: 0 0 12px; }

/* menus, popups, toast */
.menu { position: fixed; z-index: 40; min-width: 200px; max-width: 280px; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow-float), 0 0 0 1px var(--line); padding: 5px; }
.menu button { display: flex; width: 100%; background: transparent; color: var(--ink); border-radius: 8px; padding: 7px 10px; font-weight: 500; font-size: 13.5px; justify-content: flex-start; }
.menu button:hover:not(:disabled) { background: var(--accent); color: #fff; }
.menu button .k { margin-left: auto; color: var(--dim); font-size: 12px; padding-left: 16px; }
.menu button:hover .k { color: rgba(255,255,255,.8); }
.menu button.danger { color: var(--bad); }
.menu button.danger:hover { background: var(--bad); color: #fff; }
.menu .msep { height: 1px; background: var(--line); margin: 4px 6px; }
.menu .mhead { color: var(--dim); font-size: 11.5px; padding: 6px 10px 2px; font-weight: 600; }
.popup-edit { position: fixed; z-index: 41; display: flex; gap: 6px; padding: 6px; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow-float); }
.popup-edit input { width: 120px; border: 0; background: var(--pill); border-radius: 8px; padding: 6px 8px; outline: none; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 12px; background: #1c1c1e; color: #fff; border-radius: 14px; padding: 10px 12px 10px 16px; box-shadow: var(--shadow-float); max-width: calc(100% - 32px); font-size: 14px; }
.toast button { background: rgba(255,255,255,.16); color: #fff; padding: 6px 12px; font-size: 13px; }

/* ── narrow screens: the panels become drawers over the stage ── */
.show-sm { display: none; }
@media (max-width: 820px) {
  .hide-sm { display: none !important; }
  .show-sm { display: inline-flex; }
  .workspace { grid-template-columns: 1fr; position: relative; }
  .pages, .side { position: absolute; top: 0; bottom: 0; z-index: 20; box-shadow: var(--shadow-float); }
  .pages { left: 0; width: 176px; transform: translateX(-105%); transition: transform .2s; }
  .side { right: 0; width: min(300px, 88vw); transform: translateX(105%); transition: transform .2s; }
  .workspace.pages-open .pages { transform: none; }
  .workspace.side-open .side { transform: none; }
  .dock { top: auto; bottom: calc(10px + env(safe-area-inset-bottom)); }
  .zoombar { bottom: auto; top: 10px; right: 10px; }
  .cropbar { bottom: calc(70px + env(safe-area-inset-bottom)); }
  .project-name { width: auto; flex: 1 1 60px; max-width: none; }
  .saved { display: none; }
}
@media (pointer: coarse) {
  .page-more { opacity: 1; }
}
