/* Board desk. Chrome uses the studio tokens (Paper / Graphite); the paper itself is
   content and keeps its own colors. Every rule is scoped to the board (bd-). */

#view-board:not([hidden]) {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  min-width: 0;
  --bd-sel: #0aa8c4;
  --bd-hit: 36px;
  --bd-dot: 28px;
}
#view-board[data-paper="night"] { --bd-sel: #19d3ee; }
html.has-pen #view-board { --bd-hit: 44px; --bd-dot: 36px; }
@media (pointer: coarse) {
  #view-board { --bd-hit: 44px; --bd-dot: 36px; }
}

/* ---------- toolbar ---------- */
.bd-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-wash);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.bd-group { display: flex; align-items: center; gap: 2px; min-height: var(--bd-hit); }
.bd-group + .bd-group { margin-left: 6px; }
.bd-actions { margin-left: auto; }
/* Hairline separators only where the bar fits on one row; wrapped rows rely on spacing. */
@media (min-width: 1280px) {
  .bd-group + .bd-group { margin-left: 0; padding-left: 8px; border-left: 1px solid var(--line); }
  .bd-group.bd-actions { margin-left: auto; }
}

.bd-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: var(--bd-hit);
  height: var(--bd-hit);
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  transition: background-color 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}
.bd-btn .ico { width: 20px; height: 20px; pointer-events: none; }
.bd-btn:hover { background: var(--hover); }
.bd-btn:active { background: var(--chip); }
.bd-btn[aria-pressed="true"] {
  background: var(--raised);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
}
.bd-tool[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 3px;
  width: 12px;
  height: 2px;
  margin-left: -6px;
  border-radius: 2px;
  background: var(--brand);
}
.bd-btn:disabled { opacity: 0.36; cursor: default; background: transparent; }
.bd-btn:focus-visible, .bd-dot:focus-visible, .bd-select:focus-visible, .bd-size input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* color dots */
.bd-dot {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: var(--bd-dot);
  height: var(--bd-dot);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}
.bd-dot::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  transition: transform 140ms ease;
}
.bd-dot:hover::before { transform: scale(1.1); }
html[data-theme="graphite"] .bd-dot::before { box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.3); }
.bd-dot[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--ink);
}
.bd-recents { display: contents; }
.bd-dot-custom::before {
  background:
    radial-gradient(circle, var(--c) 0 42%, transparent 44%),
    conic-gradient(#e4572e, #e8a04a, #f2c94c, #3fbf7f, #19d3ee, #3148ad, #d946ef, #e4572e);
}
.bd-dot-custom.is-on::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--ink);
}
.bd-dot-custom input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}
.bd-dot-custom:focus-within::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  outline: 2px solid var(--focus);
}

/* size and paper */
.bd-settings { gap: 10px; }
.bd-size, .bd-pick {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--bd-hit);
  color: var(--muted);
  font-size: 12px;
}
.bd-pick .ico { width: 18px; height: 18px; flex: 0 0 auto; }
.bd-size-dot { display: inline-grid; place-items: center; width: 20px; height: 20px; flex: 0 0 auto; }
.bd-size-dot i {
  display: block;
  width: var(--d, 6px);
  height: var(--d, 6px);
  border-radius: 50%;
  background: var(--c, var(--ink));
  box-shadow: 0 0 0 1px var(--line-strong);
}
.bd-size input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 92px;
  height: 22px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.bd-size input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--brand) var(--pct, 20%), var(--track) var(--pct, 20%));
}
.bd-size input[type="range"]::-moz-range-track { height: 2px; border-radius: 99px; background: var(--track); }
.bd-size input[type="range"]::-moz-range-progress { height: 2px; border-radius: 99px; background: var(--brand); }
.bd-size input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -7px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--raised);
  box-shadow: var(--shadow-1);
}
.bd-size input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--raised);
}
.bd-size-out {
  min-width: 2ch;
  color: var(--ink);
  font-family: var(--font-num);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.bd-bar select.bd-select {
  -webkit-appearance: none;
  appearance: none;
  width: auto;
  min-width: 0;
  height: 32px;
  min-height: 0;
  margin: 0;
  padding: 0 28px 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
html.has-pen .bd-bar select.bd-select { height: 40px; }
.bd-pick .bd-chev {
  position: absolute;
  right: 8px;
  width: 14px;
  height: 14px;
  color: var(--muted);
  pointer-events: none;
}

/* export menu: lives in the stage so a scrolling toolbar can never clip it */
.bd-float.bd-pop {
  z-index: 20;
  display: grid;
  align-items: stretch;
  min-width: 176px;
  padding: 6px;
  box-shadow: var(--shadow-3);
}
.bd-float.bd-pop[hidden] { display: none; }
.bd-pop button {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.bd-pop button .ico { width: 18px; height: 18px; }
.bd-pop button em { font-style: normal; color: var(--muted); font-size: 12px; }
.bd-pop button:hover, .bd-pop button:focus-visible { background: var(--hover); outline: none; }

.bd-vh {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- canvas ---------- */
.bd-stage { position: relative; min-height: 0; min-width: 0; overflow: hidden; }
.bd-view {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  background-color: #f7f4ee;
  cursor: crosshair;
  outline: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.bd-view:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.bd-view[data-mode="select"] { cursor: default; }
.bd-view[data-mode="text"], .bd-view[data-mode="note"] { cursor: text; }
.bd-view[data-mode="eraser"] { cursor: none; }
.bd-view[data-mode="hand"], .bd-view.is-space { cursor: grab; }
.bd-view.is-panning { cursor: grabbing; }
.bd-paper { position: absolute; inset: 0; display: block; width: 100%; height: 100%; pointer-events: none; }
.bd-world { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; }
.bd-world.is-moving { will-change: transform; }
#board-svg { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; }
.bd-overlay { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.bd-o-sel { fill: none; stroke: var(--bd-sel); stroke-width: 1.5; stroke-dasharray: 5 4; }
.bd-o-item { fill: none; stroke: var(--bd-sel); stroke-opacity: 0.5; stroke-width: 1; }
.bd-o-marquee { fill: var(--bd-sel); fill-opacity: 0.08; stroke: var(--bd-sel); stroke-width: 1; }
.bd-cursor {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(23, 24, 29, 0.6);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.75), inset 0 0 0 1px rgba(255, 255, 255, 0.5);
  pointer-events: none;
}
#view-board[data-paper="night"] .bd-cursor { border-color: rgba(255, 255, 255, 0.8); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5); }

/* text editor over a note or title (lives in world space, so it scales with zoom) */
.bd-world textarea.bd-editor {
  position: absolute;
  box-sizing: border-box;
  display: block;
  min-height: 0;
  margin: 0;
  border: 0;
  border-radius: 10px;
  resize: none;
  overflow: hidden;
  outline: none;
  background: transparent;
  color: #17181d;
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  box-shadow: 0 0 0 2px var(--bd-sel), 0 12px 26px rgba(40, 32, 20, 0.14);
  -webkit-user-select: text;
  user-select: text;
  cursor: text;
}
.bd-world textarea.bd-editor-note { padding: 13px 14px; font-size: 15px; line-height: 21px; font-weight: 450; }
.bd-world textarea.bd-editor-text {
  padding: 0;
  font-size: 28px;
  line-height: 34px;
  font-weight: 600;
  border-radius: 4px;
  box-shadow: 0 0 0 2px var(--bd-sel);
}
.bd-world textarea.bd-editor::placeholder { color: rgba(23, 24, 29, 0.38); }

/* empty sheet hint */
.bd-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
  pointer-events: none;
  color: rgba(23, 24, 29, 0.62);
}
.bd-empty[hidden] { display: none; }
.bd-empty-title { margin: 0; font-size: 15px; font-weight: 600; color: rgba(23, 24, 29, 0.78); }
.bd-empty-line { margin: 0; max-width: 40ch; font-size: 13px; line-height: 1.5; }
#view-board[data-paper="night"] .bd-empty { color: rgba(244, 239, 230, 0.66); }
#view-board[data-paper="night"] .bd-empty-title { color: rgba(244, 239, 230, 0.86); }

/* ---------- floating islands ---------- */
.bd-float {
  position: absolute;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 14px;
  border: 1px solid var(--glass-line);
  background: var(--glass-bg);
  color: var(--ink);
  box-shadow: var(--shadow-2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.bd-float[hidden] { display: none; }
.bd-zoom { right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); }
.bd-pct { width: auto; min-width: 58px; padding: 0 8px; }
.bd-pct-v { font-family: var(--font-num); font-size: 13px; font-variant-numeric: tabular-nums; }
.bd-selbar { left: 0; top: 0; will-change: transform; }
.bd-sb-part { display: flex; align-items: center; gap: 0; }
.bd-sb-part[hidden] { display: none; }
.bd-sb-part + .bd-sb-part, .bd-sb-part + .bd-btn { margin-left: 4px; }
.bd-sep { width: 1px; height: 22px; margin: 0 4px; background: var(--line); }
.bd-selbar .bd-btn[hidden] { display: none; }
.bd-penchip {
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  gap: 8px;
  min-height: 40px;
  padding: 0 14px 0 10px;
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.bd-penchip .ico { width: 18px; height: 18px; color: var(--brand); }
.bd-penchip[aria-pressed="true"] .ico { color: var(--muted); }
.bd-penchip:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

@media (prefers-reduced-motion: no-preference) {
  .bd-selbar:not([hidden]) { animation: bd-rise 140ms ease-out both; }
  .bd-pop:not([hidden]) { animation: bd-rise 140ms ease-out both; }
}
@keyframes bd-rise { from { opacity: 0; } to { opacity: 1; } }

/* ---------- narrow screens ---------- */
@media (max-width: 1100px) {
  .bd-actions { margin-left: 0; }
}
@media (max-width: 720px) {
  .bd-bar { gap: 4px 6px; padding: 6px 8px; }
  .bd-size input[type="range"] { width: 72px; }
  .bd-pct { min-width: 50px; }
  .bd-penchip { max-width: calc(100% - 210px); }
  .bd-penchip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
/* Phones: one row that scrolls sideways, with a soft edge that says "more this way". */
@media (max-width: 560px) {
  .bd-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
    padding-right: 28px;
  }
  .bd-bar::-webkit-scrollbar { display: none; }
  .bd-actions { margin-left: 6px; }
}
html[data-theme="graphite"] .bd-size-dot i { box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.35); }
