/* Layout: one-screen markup desk. A top bar, a drawing stage with an iPad-style tool tray at the bottom,
   notes for Claude docked on the right (overlaid when narrow), sheets sliding over from the left. */
:root {
  --bg: #F3F1F5;
  --surface: #FFFFFF;
  --sunk: #E9E5ED;
  --ink: #1F1A24;
  --muted: #5E5866;
  --line: #DAD4E0;
  --accent: #C2255C;
  --accent-ink: #FFFFFF;
  --accent-soft: #FBE3EC;
  --danger: #B3261E;
  --scrim: rgba(25, 18, 30, .3);
  --shadow: 0 1px 2px rgba(25, 18, 30, .08), 0 8px 24px rgba(25, 18, 30, .12);
  --desk: #E2DEE7;
  --desk-grid: rgba(31, 26, 36, .05);
  --apple-bg: #000000;
  --apple-fg: #FFFFFF;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151217; --surface: #1E1A21; --sunk: #28232C; --ink: #EFEAF2; --muted: #A69DAE; --line: #352F3A;
    --accent: #F27CA6; --accent-ink: #2A0716; --accent-soft: #3A1626; --danger: #F2827A;
    --scrim: rgba(0, 0, 0, .5); --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .45);
    --desk: #0F0D11; --desk-grid: rgba(255, 255, 255, .035);
    --apple-bg: #FFFFFF; --apple-fg: #000000;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151217; --surface: #1E1A21; --sunk: #28232C; --ink: #EFEAF2; --muted: #A69DAE; --line: #352F3A;
  --accent: #F27CA6; --accent-ink: #2A0716; --accent-soft: #3A1626; --danger: #F2827A;
  --scrim: rgba(0, 0, 0, .5); --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .45);
  --desk: #0F0D11; --desk-grid: rgba(255, 255, 255, .035);
    --apple-bg: #FFFFFF; --apple-fg: #000000;
  color-scheme: dark;
}
html { height: 100%; box-sizing: border-box; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--bg); }
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
body { height: 100%; margin: 0; overflow: hidden; background: var(--bg); color: var(--ink); font: 14px/1.4 var(--font); -webkit-text-size-adjust: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; cursor: pointer; }
button:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

.app { height: 100%; display: flex; flex-direction: column; gap: 10px; padding-inline: 16px; padding-block: 0 16px;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* top bar */
.bar { display: flex; align-items: center; gap: 10px; padding-top: 10px; min-height: 54px; }
.meta { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.meta .num { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
.meta .title { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.meta .title.brand { font-size: 19px; letter-spacing: -.01em; }
.meta .dirty { font-size: 12px; color: var(--muted); white-space: nowrap; }
.actions { display: flex; gap: 6px; align-items: center; }
.btn { height: 44px; min-width: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.btn.icon { padding: 0; width: 44px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); min-width: 88px; }
/* Sign in with Apple: Apple's black style, white on dark backgrounds (--apple-* tokens). */
.btn.apple { background: var(--apple-bg); color: var(--apple-fg); border-color: var(--apple-bg); }
.btn.apple svg { fill: currentColor; stroke: none; width: 17px; height: 17px; margin-top: -2px; }
.btn svg, .tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.chip.waiting { border: 1px solid var(--ink); }
.chip.marked { background: var(--accent); color: var(--accent-ink); }
.chip.picked-up { background: var(--sunk); color: var(--muted); }

/* main area */
.main { flex: 1; min-height: 0; display: flex; gap: 12px; position: relative; }
.stage { flex: 1; min-width: 0; position: relative; overflow: hidden; border-radius: 14px; border: 1px solid var(--line);
  background-color: var(--desk);
  background-image: linear-gradient(var(--desk-grid) 1px, transparent 1px), linear-gradient(90deg, var(--desk-grid) 1px, transparent 1px);
  background-size: 24px 24px; touch-action: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; display: block; }
.stage.panning canvas { cursor: grab; }

/* tool tray */
.tray { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: 2px; padding: 5px; overflow-x: auto; scrollbar-width: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.tray::-webkit-scrollbar { display: none; }
.tool { flex: none; width: 42px; height: 42px; border-radius: 10px; border: 0; background: transparent; display: grid; place-items: center; color: var(--ink); }
.tool[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.tool .dot { width: 20px; height: 20px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.tool.swatch[aria-pressed="true"] { background: var(--sunk); }
.tool.swatch[aria-pressed="true"] .dot { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }
.tool.size[aria-pressed="true"] { background: var(--sunk); color: var(--ink); }
.tool.size i { display: block; border-radius: 50%; background: currentColor; }
.tray .sep { flex: none; width: 1px; height: 26px; background: var(--line); margin: 0 5px; }

.float { position: absolute; z-index: 2; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.hint { top: 12px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; max-width: calc(100% - 24px); }
.hint span { font-size: 13px; }
.hint .btn { height: 36px; }
.zoom { top: 12px; right: 12px; padding: 4px 8px; font-size: 12px; color: var(--muted); border-radius: 8px; }
.stage-msg { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; }
.stage-msg .card { position: static; max-width: 380px; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; padding: 22px; }
.stage-msg h2 { margin: 0; font-size: 18px; text-wrap: balance; }
.stage-msg p { margin: 0; color: var(--muted); text-wrap: pretty; -webkit-user-select: text; user-select: text; }

/* sheets drawer */
.scrim { position: absolute; inset: 0; background: var(--scrim); border-radius: 14px; z-index: 4; }
.drawer { position: absolute; z-index: 5; left: 0; top: 0; bottom: 0; width: min(340px, 100%); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  transform: translateX(calc(-100% - 24px)); transition: transform .22s ease; }
.drawer.open { transform: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-head .count { color: var(--muted); font-weight: 400; }
.sheet-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 4px; }
.sheet { width: 100%; display: grid; grid-template-columns: 72px 1fr; gap: 12px; align-items: center; text-align: left;
  padding: 8px; border-radius: 10px; border: 1px solid transparent; background: transparent; }
.sheet[aria-current="true"] { background: var(--accent-soft); border-color: var(--accent); }
.thumb { width: 72px; height: 54px; border-radius: 6px; background: var(--sunk); object-fit: cover; object-position: top left; border: 1px solid var(--line); }
.sheet-text { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.sheet-text .row { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; color: var(--muted); }
.sheet-text .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unsaved { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.empty { color: var(--muted); padding: 16px; margin: 0; }

/* notes */
.notes { width: 300px; flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.app:not(.notes-open) .notes { display: none; }
.notes-body { overflow-y: auto; flex: 1; min-height: 0; padding: 14px 16px; display: flex; flex-direction: column; gap: 16px; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 4px; }
.from-claude { background: var(--sunk); border-radius: 10px; padding: 10px 12px; }
.from-claude p { margin: 0; white-space: pre-wrap; -webkit-user-select: text; user-select: text; }
.notes textarea { width: 100%; min-height: 64px; resize: vertical; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
  font-size: 16px; line-height: 1.35; -webkit-user-select: text; user-select: text; }
.marks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.mark { display: grid; grid-template-columns: 36px 1fr; gap: 10px; align-items: start; }
.badge { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--c); color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center; }
.badge.zone { border-radius: 8px; }
.mark-body { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.mark-body label { font-size: 12px; color: var(--muted); }
.mark textarea { min-height: 44px; }
.summary { font-size: 12px; color: var(--muted); margin: 0; }
.tips { font-size: 12px; color: var(--muted); margin: 0; border-top: 1px solid var(--line); padding-top: 12px; }
.account-box { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.account { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.meter { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meter-bar { height: 6px; border-radius: 3px; background: var(--sunk); overflow: hidden; }
.meter-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; }
.meter.full .meter-bar i { background: var(--danger); }
.meter.full span { color: var(--danger); font-weight: 700; }
.account-actions { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; }
.account-actions .link, .account-actions .remove { padding: 4px 0; font-size: 13px; text-align: left; }
.legal-links { margin: 0; font-size: 12px; color: var(--muted); }
.legal-links a { color: var(--muted); }
.account span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link { border: 0; background: none; padding: 6px 0; font-weight: 700; color: var(--accent); }
.remove { align-self: flex-start; border: 0; background: none; color: var(--danger); font-weight: 700; padding: 6px 0; }

/* stabilization slider, scale hint and the PDF picker */
.steady-pop { bottom: 72px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 10px 14px; font-weight: 700; }
.steady-pop input[type="range"] { width: min(200px, 50vw); accent-color: var(--accent); }
.steady-pop output { min-width: 3.5ch; text-align: right; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint input, .hint select, .modal select { height: 40px; font-size: 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); padding: 0 8px; }
.hint input { width: 6.5em; }
.scale-box .summary { margin: 0 0 2px; }
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: var(--scrim); }
.modal-card { width: min(760px, 100%); max-height: calc(100% - 32px); display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.modal-body { padding: 14px 16px; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.modal-foot .summary { flex: 1; margin: 0; }
.modal .link { align-self: flex-start; }
.pdf-pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 10px; }
.pdf-page { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; border-radius: 10px; border: 2px solid transparent; background: var(--sunk); font-size: 12px; color: var(--muted); }
.pdf-page[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); font-weight: 700; }
.pdf-page canvas, .pdf-page .ph { display: block; width: 100%; height: auto; background: #fff; border-radius: 4px; box-shadow: 0 0 0 1px var(--line); }
.pdf-page .ph { aspect-ratio: 4 / 3; }
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 30;
  max-width: min(440px, calc(100% - 32px)); padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--bg); font-weight: 700; box-shadow: var(--shadow); }

@media (max-width: 1023px) {
  .notes { position: absolute; z-index: 5; right: 0; top: 0; bottom: 0; width: min(340px, 100%); box-shadow: var(--shadow); }
}
@media (max-width: 640px) {
  .btn .lbl { display: none; }
  .btn.primary { min-width: 64px; }
  .meta .dirty, .meta .chip { display: none; }
  .bar { gap: 6px; }
}
@media (prefers-reduced-motion: reduce) { .drawer { transition: none; } }
