/* Brandlift Canvas. Floating panels on a grey board, in the spirit of Figma. */
:root {
  --board: #f5f5f5;
  --dots: #d4d4d4;
  --panel: #ffffff;
  --ink: #1e1e1e;
  --muted: #6f6f6f;
  --faint: #a3a3a3;
  --line: #e8e8e8;
  --hover: #f2f2f2;
  --pressed: #e9e9e9;
  --brand: #f5d013;
  --brand-ink: #0a0a0a;
  --select: #0d99ff;
  --select-soft: rgba(13, 153, 255, 0.1);
  --guide: #f24822;
  --danger: #d92d20;
  --shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--board);
  color: var(--ink);
  font: 13px/1.4 var(--ui);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* --- the board ------------------------------------------------------------------------------------------------- */
#viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background-color: var(--board);
  background-image: radial-gradient(circle, var(--dots) 1px, transparent 1.3px);
  outline: none;
}
#viewport.hand { cursor: grab; }
#viewport.panning { cursor: grabbing; }
#viewport.crosshair { cursor: crosshair; }
#viewport.texting { cursor: text; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#frames, #objects { position: absolute; left: 0; top: 0; }

.obj { position: absolute; left: 0; top: 0; }
.obj.rect, .obj.ellipse, .obj.note, .obj.frame, .obj.image { overflow: visible; }
.obj.ellipse { border-radius: 50%; }
.obj.note { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 4px 10px rgba(0, 0, 0, 0.06); }
.obj.frame { box-shadow: 0 0 0 calc(1px / var(--z, 1)) rgba(0, 0, 0, 0.06); }
.obj.image img { display: block; width: 100%; height: 100%; object-fit: fill; pointer-events: none; -webkit-user-drag: none; border-radius: inherit; }
.obj.image.pending img { opacity: 0.55; }
.obj.image.pending::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: calc(28px / var(--z, 1));
  height: calc(28px / var(--z, 1));
  border-radius: 50%;
  border: calc(3px / var(--z, 1)) solid rgba(255, 255, 255, 0.9);
  border-top-color: var(--select);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.obj.line, .obj.pen { pointer-events: none; }
.obj svg { position: absolute; left: 0; top: 0; overflow: visible; }
.obj .hit { stroke: transparent; fill: none; pointer-events: stroke; stroke-width: calc(14px / var(--z, 1)); stroke-linecap: round; }

.frame-label {
  position: absolute;
  left: 0;
  bottom: 100%;
  padding-bottom: calc(4px / var(--z, 1));
  font: 500 calc(11px / var(--z, 1)) / 1.2 var(--ui);
  color: var(--muted);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
}
.frame-label.on { color: var(--select); }
.frame-label[contenteditable] { max-width: none; overflow: visible; color: var(--ink); outline: none; cursor: text; user-select: text; -webkit-user-select: text; }

.txt {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline: none;
  min-width: 1px;
  line-height: 1.3;
}
.txt[contenteditable] { user-select: text; -webkit-user-select: text; cursor: text; caret-color: var(--ink); }
.obj.text .txt { padding: 0; }
.obj.text.auto .txt { white-space: pre; }
.obj.rect .txt, .obj.ellipse .txt {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 12px;
  text-align: center;
}
.obj.ellipse .txt { padding: 14% 16%; }
.obj.note .txt { position: absolute; inset: 0; padding: 16px 18px; overflow: hidden; }
.f-sans { font-family: var(--ui); }
.f-serif { font-family: "New York", "Iowan Old Style", ui-serif, Georgia, "Times New Roman", serif; }
.f-mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace; }

#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
#overlay .h { pointer-events: all; }
#overlay .h-hit { fill: transparent; stroke: none; }
@media (pointer: fine) { #overlay .h-hit { display: none; } }
#overlay [data-handle="nw"], #overlay [data-handle="se"] { cursor: nwse-resize; }
#overlay [data-handle="ne"], #overlay [data-handle="sw"] { cursor: nesw-resize; }
#overlay [data-handle="n"], #overlay [data-handle="s"] { cursor: ns-resize; }
#overlay [data-handle="e"], #overlay [data-handle="w"] { cursor: ew-resize; }
#overlay [data-handle^="p"] { cursor: crosshair; }
#overlay .size-tag rect { fill: var(--select); }
#overlay .size-tag text { fill: #fff; font: 500 11px var(--ui); }

#empty-hint {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  margin: 0;
  color: var(--faint);
  font-size: 14px;
  text-align: center;
  pointer-events: none;
  max-width: 80vw;
}

/* --- panels ---------------------------------------------------------------------------------------------------- */
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  flex: none;
}
.icon-btn.small { width: 24px; height: 24px; border-radius: 6px; }
.icon-btn.small svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { background: var(--pressed); }
.icon-btn:disabled { color: var(--faint); background: transparent; cursor: default; }
.text-btn { border: 0; background: transparent; padding: 6px 8px; border-radius: 8px; color: var(--ink); }
.text-btn:hover { background: var(--hover); }
.primary-btn { border: 0; border-radius: 8px; background: var(--brand-ink); color: #fff; padding: 9px 14px; font-weight: 600; }
.primary-btn:hover { background: #2b2b2b; }
.primary-btn:disabled { opacity: 0.5; }
.danger-btn { border: 0; border-radius: 8px; background: var(--danger); color: #fff; padding: 9px 14px; font-weight: 600; }
:focus-visible { outline: 2px solid var(--select); outline-offset: 1px; }

#side {
  position: fixed;
  left: 8px;
  top: 8px;
  bottom: 8px;
  width: 240px;
  display: flex;
  flex-direction: column;
  z-index: 3;
  overflow: hidden;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 6px 14px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 14px; }
.brand img { border-radius: 5px; }
.side-section { padding: 4px 8px 8px; border-top: 1px solid var(--line); min-height: 0; }
.side-section:first-of-type { border-top: 0; }
.side-section.grow { flex: 1; overflow-y: auto; }
.side-section:not(.grow) { max-height: 40%; overflow-y: auto; flex: none; }
.side-title { display: flex; align-items: center; justify-content: space-between; padding: 8px 6px 4px; font-weight: 600; font-size: 12px; }
.side-foot { border-top: 1px solid var(--line); padding: 6px 8px; }
.side-foot .text-btn { color: var(--muted); font-size: 12px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 4px 0 8px;
  border-radius: 7px;
  cursor: default;
  white-space: nowrap;
}
.list li:hover { background: var(--hover); }
.list li.on { background: var(--select-soft); }
.list li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.list li .i { color: var(--muted); display: grid; place-items: center; }
.list li .i svg { width: 16px; height: 16px; }
.list li .meta { color: var(--faint); font-size: 11px; }
.list li .icon-btn { opacity: 0; }
.list li:hover .icon-btn, .list li.on .icon-btn { opacity: 1; }
.list li input { flex: 1; min-width: 0; border: 1px solid var(--select); border-radius: 5px; padding: 3px 5px; outline: none; }
.list .more-row { color: var(--faint); font-size: 12px; }
#board-list li { cursor: pointer; }

#side-open {
  position: fixed;
  left: 8px;
  top: 8px;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 0 10px;
  border: 0;
  z-index: 3;
  max-width: calc(100vw - 16px);
  font-weight: 600;
}
#side-open .i { display: grid; }
#side-open-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.side-shown #side-open { display: none; }
body:not(.side-shown) #side { display: none; }

#props {
  position: fixed;
  right: 8px;
  top: 8px;
  width: 248px;
  max-height: calc(100% - 80px);
  overflow-y: auto;
  z-index: 3;
  padding-bottom: 6px;
}
.props-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 4px 14px; font-weight: 600; }
.props-head .actions { display: flex; gap: 2px; }
.props-toggle { display: none; }
.group { padding: 8px 14px 10px; border-top: 1px solid var(--line); }
.group:first-of-type { border-top: 0; }
.group-title { font-weight: 600; font-size: 12px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.row { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.row:first-child { margin-top: 0; }
.field {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  height: 28px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--hover);
  border: 1px solid transparent;
}
.field:focus-within { border-color: var(--select); background: #fff; }
.field .lab { color: var(--faint); font-size: 11px; width: 10px; flex: none; }
.field input, .field select { border: 0; background: transparent; outline: none; width: 100%; min-width: 0; padding: 0; height: 100%; }
.field select { appearance: none; -webkit-appearance: none; cursor: pointer; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  border: 0;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
  position: relative;
}
.swatch.on { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1), 0 0 0 2px #fff, 0 0 0 3.5px var(--select); }
.swatch.none { background: linear-gradient(135deg, #fff 45%, var(--danger) 45%, var(--danger) 55%, #fff 55%); }
.swatch.custom { background: conic-gradient(#f24822, #ffcd29, #14ae5c, #0d99ff, #9747ff, #f24822); overflow: hidden; }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.seg { display: flex; background: var(--hover); border-radius: 7px; padding: 2px; gap: 2px; flex: 1; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 5px; height: 24px; padding: 0 6px; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.seg button svg { width: 16px; height: 16px; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08); }
.icon-row { display: flex; gap: 2px; justify-content: space-between; }
.icon-row .icon-btn svg { width: 18px; height: 18px; }
input[type="range"] { flex: 1; accent-color: var(--ink); }
.value { width: 40px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.wide-btn { width: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; height: 30px; border: 0; border-radius: 7px; background: var(--hover); }
.wide-btn:hover { background: var(--pressed); }
.wide-btn.danger { color: var(--danger); }

#toolbar {
  position: fixed;
  left: 50%;
  bottom: calc(12px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  z-index: 4;
}
.tool {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  padding: 0;
}
.tool:hover { background: var(--hover); }
.tool.on { background: var(--brand); color: var(--brand-ink); }
.tool.group { width: 52px; grid-template-columns: 1fr 12px; padding-left: 6px; }
.tool.group .more { display: grid; place-items: center; height: 100%; width: 14px; border-radius: 0 9px 9px 0; }
.tool.group .more:hover { background: rgba(0, 0, 0, 0.06); }
#toolbar .sep, #zoombar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; flex: none; }

#zoombar {
  position: fixed;
  right: 8px;
  bottom: calc(12px + var(--safe-b));
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  z-index: 3;
}
#zoom-level { min-width: 58px; font-variant-numeric: tabular-nums; }
#status { width: 28px; height: 28px; display: grid; place-items: center; }
#status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #14ae5c; transition: background 0.2s; }
#status.saving::before, #status.pending::before { background: var(--faint); }
#status.offline::before { background: #f59e0b; }
#status.error::before { background: var(--danger); }
#status.offline, #status.error { width: auto; padding: 0 8px 0 10px; grid-auto-flow: column; gap: 6px; font-size: 12px; color: var(--muted); }

.menu {
  position: fixed;
  z-index: 10;
  min-width: 190px;
  padding: 6px;
  background: #1e1e1e;
  color: #fff;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
}
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 7px 10px;
  border-radius: 6px;
  text-align: left;
  white-space: nowrap;
}
.menu button svg { width: 16px; height: 16px; }
.menu button:hover, .menu button:focus-visible { background: var(--select); outline: none; }
.menu button .key { margin-left: auto; padding-left: 18px; opacity: 0.55; font-size: 12px; }
.menu button.danger:hover { background: var(--danger); }
.menu hr { border: 0; border-top: 1px solid rgba(255, 255, 255, 0.12); margin: 5px 4px; }
.menu .menu-note { padding: 6px 10px; opacity: 0.6; font-size: 12px; }

#toasts { position: fixed; left: 50%; bottom: calc(76px + var(--safe-b)); transform: translateX(-50%); display: grid; gap: 8px; z-index: 11; justify-items: center; pointer-events: none; }
.toast { background: #1e1e1e; color: #fff; padding: 9px 14px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); max-width: min(440px, calc(100vw - 32px)); animation: toast-in 0.18s ease-out; pointer-events: auto; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

dialog { border: 0; padding: 0; width: min(420px, calc(100vw - 32px)); max-height: calc(100vh - 64px); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, 0.25); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 6px 18px; font-weight: 650; font-size: 14px; }
.dialog-body { padding: 4px 18px 16px; overflow-y: auto; max-height: calc(100vh - 160px); }
.dialog-body p { margin: 0 0 12px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 18px; }
.keys { width: 100%; border-collapse: collapse; }
.keys td { padding: 5px 0; border-bottom: 1px solid var(--line); }
.keys td:last-child { text-align: right; color: var(--muted); white-space: nowrap; }
kbd { font: 12px var(--ui); background: var(--hover); border-radius: 4px; padding: 1px 5px; color: var(--ink); }
.versions li { cursor: pointer; }

/* --- sign-in --------------------------------------------------------------------------------------------------- */
.login-page {
  display: grid;
  place-items: center;
  min-height: 100%;
  overflow: auto;
  padding: 16px;
  background-color: var(--board);
  background-image: radial-gradient(circle, var(--dots) 1px, transparent 1.3px);
  background-size: 24px 24px;
}
.login-card { width: min(340px, 100%); padding: 28px 24px 24px; display: grid; gap: 8px; }
.login-card img { border-radius: 9px; }
.login-card h1 { margin: 6px 0 14px; font-size: 20px; font-weight: 700; }
.login-card label { font-weight: 600; font-size: 12px; }
.login-card input { height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--hover); padding: 0 12px; font-size: 16px; outline: none; }
.login-card input:focus { border-color: var(--select); background: #fff; }
.login-card .primary-btn { height: 40px; margin-top: 4px; }
.login-error { margin: 0; min-height: 18px; color: var(--danger); font-size: 12px; }

/* --- small screens: the panel slides over the board, the style panel sits above the tools ---------------------- */
@media (max-width: 720px) {
  #side { width: min(300px, calc(100vw - 16px)); z-index: 6; }
  #props {
    top: auto;
    left: 8px;
    right: 8px;
    width: auto;
    bottom: calc(68px + var(--safe-b));
    max-height: 46vh;
    z-index: 5;
  }
  #props.folded .group { display: none; }
  .props-toggle { display: inline-grid; }
  #props.folded .props-toggle svg { transform: rotate(180deg); }
  #zoombar { top: 8px; right: 8px; bottom: auto; }
  #zoombar #help, #zoombar .sep { display: none; }
  #toolbar { left: 8px; right: 8px; transform: none; justify-content: space-between; }
  .tool { width: 38px; height: 40px; }
  .tool[data-tool="hand"] { display: none; }
  #toolbar .sep { display: none; }
  #toasts { bottom: calc(124px + var(--safe-b)); }
  .field input, .field select { font-size: 16px; }
  .list li { height: 38px; }
  .list li .icon-btn { opacity: 1; }
  body.has-props #toasts { bottom: calc(68px + 46vh + 12px); }
}
@media (max-width: 380px) {
  .tool { width: 34px; }
  .tool.group { width: 44px; padding-left: 2px; }
}
