/* Pinboard — application chrome.
   The canvas paints the board itself; everything here is the surrounding UI.

   Layout map
     topbar      top left / top right rails
     toolbar     bottom centre dock
     style-pop   style controls, opened from the dock or the selection bar
     side-panel  right layers list
     context-bar floating bar above the selection
     dock-bl     history + connection
     dock-br     minimap + zoom
*/

/* ------------------------------------------------------------------ tokens */

:root {
  color-scheme: light;

  --surface: #ffffff;
  --surface-2: #f7f7f9;
  --surface-3: #eeeff3;
  --border: rgba(16, 24, 40, 0.08);
  --border-strong: rgba(16, 24, 40, 0.14);
  --text: #131722;
  --text-soft: #4a5163;
  --muted: #79808f;
  --accent: #5b5bd6;
  --accent-hover: #4a4ac4;
  --accent-ink: #ffffff;
  --accent-soft: rgba(91, 91, 214, 0.12);
  --danger: #d92d20;
  --ok: #12b76a;
  --warn: #f79009;

  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.07), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 14px -4px rgba(16, 24, 40, 0.1), 0 1px 4px -1px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 16px 34px -12px rgba(16, 24, 40, 0.18), 0 4px 10px -4px rgba(16, 24, 40, 0.08);
  --shadow-xl: 0 32px 64px -16px rgba(16, 24, 40, 0.3), 0 8px 20px -8px rgba(16, 24, 40, 0.12);
  --ring: 0 0 0 3px var(--accent-soft);

  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 16px;
  --r-xl: 22px;

  --dock: rgba(255, 255, 255, 0.76);
  --dock-border: rgba(16, 24, 40, 0.07);
  --blur: saturate(1.8) blur(22px);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme='dark'] {
  color-scheme: dark;

  --surface: #191c22;
  --surface-2: #21252d;
  --surface-3: #2a2f39;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e9ebf0;
  --text-soft: #b6bcc8;
  --muted: #8d95a3;
  --accent: #8b8bf0;
  --accent-hover: #a3a3f7;
  --accent-ink: #14161b;
  --accent-soft: rgba(139, 139, 240, 0.18);
  --danger: #f97066;
  --ok: #32d583;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 8px 20px -6px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 24px 48px -16px rgba(0, 0, 0, 0.7);
  --shadow-xl: 0 36px 70px -20px rgba(0, 0, 0, 0.8);

  --dock: rgba(25, 28, 34, 0.78);
  --dock-border: rgba(255, 255, 255, 0.07);
}

/* -------------------------------------------------------------- foundation */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--surface-2);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { touch-action: none; }
#app { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; }

#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  pointer-events: none;
}
.icon-sm { width: 16px; height: 16px; stroke-width: 1.8; }

/* Frosted surface shared by every floating piece of chrome. */
.glass {
  background: var(--dock);
  border: 1px solid var(--dock-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

/* While a drag is under way the chrome recedes, so the board has the screen to
   itself; it comes straight back on release. The dock keeps its own opacity so
   the active tool stays readable out of the corner of your eye. */
#app.working #topbar,
#app.working .dock-bl,
#app.working .dock-br,
#app.working .session-rail,
#app.working .side-panel {
  opacity: 0.25;
  pointer-events: none;
}
#app.working .toolbar { opacity: 0.55; }
#topbar, .dock-bl, .dock-br, .session-rail, .toolbar, .side-panel {
  transition: opacity 0.18s var(--ease);
}
@media (prefers-reduced-motion: reduce) {
  #app.working #topbar,
  #app.working .dock-bl,
  #app.working .dock-br,
  #app.working .session-rail,
  #app.working .side-panel,
  #app.working .toolbar { opacity: 1; }
}

/* "Solid interface": the frosted chrome reads beautifully over a busy board and
   poorly for anyone who wants plain contrast, so it can be turned opaque. */
#app.solid-chrome .glass,
#app.solid-chrome .context-bar,
#app.solid-chrome .timer-chip,
#app.solid-chrome .present-bar,
#app.solid-chrome .comment-pop {
  background: var(--surface);
  border-color: var(--border-strong);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* ----------------------------------------------------------------- top bar */

#topbar {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
  z-index: 30;
}

#topbar .bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  pointer-events: auto;
  min-width: 0;
}

.brand { display: flex; align-items: center; gap: 6px; min-width: 0; }

.brand-mark {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px 0 6px;
  font-weight: 640;
  font-size: 13.5px;
  letter-spacing: -0.012em;
  white-space: nowrap;
  color: var(--text);
}
.brand-mark::before {
  content: '';
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: linear-gradient(140deg, var(--accent), #ec4899);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.board-name {
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 6px 9px;
  min-width: 40px;
  max-width: 26vw;
  text-overflow: ellipsis;
  transition: background 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.board-name:hover { background: var(--surface-3); }
.board-name:focus { background: var(--surface); border-color: var(--accent); box-shadow: var(--ring); outline: none; }

.save-state {
  font-size: 11.5px;
  color: var(--muted);
  padding: 0 8px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.save-state.saving { color: var(--accent); }

/* ------------------------------------------------------------------ button */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 11px;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 530;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s var(--ease), color 0.14s var(--ease), transform 0.12s var(--ease);
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(0.96); }
.btn[disabled] { opacity: 0.35; pointer-events: none; }
.btn.icon-btn { width: 34px; padding: 0; }
.btn.sm { height: 28px; font-size: 12px; padding: 0 8px; }
.btn.sm.icon-btn { width: 28px; padding: 0; }
.btn.active { background: var(--accent-soft); color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-xs); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { border: 1px solid var(--border); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(217, 45, 32, 0.12); }

.divider { width: 1px; align-self: stretch; margin: 5px 4px; background: var(--border); }

/* ---------------------------------------------------------------- tool dock */

.toolbar {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  z-index: 30;
  max-width: calc(100vw - 28px);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
[data-theme='dark'] .toolbar { box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.06); }

.tool {
  position: relative;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 0.16s var(--ease), color 0.16s var(--ease), transform 0.16s var(--ease);
}
.tool:hover { background: var(--surface-3); color: var(--text); transform: translateY(-1px); }
.tool:active { transform: translateY(0) scale(0.94); }
.tool[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 4px 12px -4px var(--accent), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}
.tool[aria-pressed='true'] .icon { stroke-width: 1.9; }
.toolbar.voting {
  box-shadow: var(--shadow-lg), 0 0 0 2px #f43f5e;
}
.toolbar.voting::after {
  content: 'Voting';
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  padding: 1px 8px;
  border-radius: 8px;
  background: #f43f5e;
  color: #fff;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tool .caret {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-top: 4px solid currentColor;
  opacity: 0.45;
}
.tool .emoji { font-size: 21px; line-height: 1; }

/* tooltips */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(4px) scale(0.96);
  padding: 5px 9px;
  border-radius: 7px;
  background: #101828;
  color: #fff;
  font-size: 11.5px;
  font-weight: 520;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.13s var(--ease), transform 0.13s var(--ease);
  z-index: 90;
}
[data-tip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
[data-tip-below]::after { bottom: auto; top: calc(100% + 10px); }
[data-theme='dark'] [data-tip]::after { background: #eef0f4; color: #101828; }

/* -------------------------------------------------------------- inspector */

/* The style controls open over the canvas on request instead of standing in a
   permanent side panel, so nothing covers the board while you work. */
.style-pop {
  width: 264px;
  max-height: min(560px, calc(100vh - 150px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
  min-width: auto;
}

.style-pop::-webkit-scrollbar { width: 10px; }
.style-pop::-webkit-scrollbar-track { background: transparent; }
.style-pop::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  border-radius: 8px;
  background-clip: content-box;
}

.tool.style-trigger { color: var(--muted); }
.tool.style-trigger.active { background: var(--accent-soft); color: var(--accent); }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 2px; }

/* Inside the popover everything is a notch tighter: it floats over the board,
   so its height is space taken away from the work. */
.style-pop .field { margin-bottom: 10px; }
.style-pop .field-label { margin-bottom: 5px; font-size: 10px; }
.style-pop .swatches { gap: 5px; }
.style-pop .swatch { width: 22px; height: 22px; border-radius: 7px; }
.style-pop .segment { padding: 2px; }
.style-pop .segment button { height: 25px; min-width: 25px; font-size: 11.5px; }

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10.5px;
  font-weight: 620;
  letter-spacing: 0.055em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.field-label .value { font-weight: 600; letter-spacing: 0; text-transform: none; font-size: 11.5px; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }

.swatch {
  width: 25px;
  height: 25px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease);
}
.swatch:hover { transform: scale(1.14); z-index: 1; }
.swatch[aria-pressed='true'] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.swatch.transparent {
  background-image:
    linear-gradient(45deg, var(--border-strong) 25%, transparent 25%),
    linear-gradient(-45deg, var(--border-strong) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--border-strong) 75%),
    linear-gradient(-45deg, transparent 75%, var(--border-strong) 75%);
  background-size: 9px 9px;
  background-position: 0 0, 0 4.5px, 4.5px -4.5px, -4.5px 0;
}
.swatch input[type='color'] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.segment {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: var(--r-md);
  background: var(--surface-3);
}
.segment button {
  flex: 1;
  height: 28px;
  min-width: 28px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  font-size: 12px;
  font-weight: 540;
  cursor: pointer;
  transition: background 0.13s var(--ease), color 0.13s var(--ease), box-shadow 0.13s var(--ease);
}
.segment button:hover { color: var(--text); }
.segment button[aria-pressed='true'] {
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  color: var(--accent);
}

.stroke-preview { display: block; background: currentColor; border-radius: 99px; }

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 5px;
  background: var(--surface-3);
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2.5px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2.5px solid var(--surface);
  cursor: pointer;
}

.actions-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.actions-grid .btn { width: 100%; padding: 0; height: 32px; }

.panel-hint { font-size: 11.5px; color: var(--muted); line-height: 1.5; margin: 4px 0 0; }

/* --------------------------------------------------- contextual selection */

.context-bar {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  z-index: 28;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  animation: pop 0.14s var(--ease);
}

@keyframes pop {
  from { opacity: 0; transform: translateY(4px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.context-bar .chip {
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  padding: 0;
  position: relative;
}
.context-bar .btn { height: 30px; }
.context-bar .btn.icon-btn { width: 30px; }

/* ----------------------------------------------------------- layers panel */

.side-panel {
  position: absolute;
  right: 14px;
  top: 70px;
  width: 252px;
  max-height: calc(100vh - 200px);
  display: flex;
  flex-direction: column;
  z-index: 25;
  overflow: hidden;
  animation: slide-in-right 0.18s var(--ease);
}

@keyframes slide-in-right {
  from { opacity: 0; transform: translateX(8px); }
  to { opacity: 1; transform: none; }
}

.side-panel header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 9px 9px 13px;
  border-bottom: 1px solid var(--border);
}
.side-panel header h3 {
  margin: 0;
  flex: 1;
  font-size: 11px;
  font-weight: 640;
  letter-spacing: 0.055em;
  text-transform: uppercase;
  color: var(--muted);
}
.side-panel .body { overflow-y: auto; padding: 6px; }

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 7px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.layer-row:hover { background: var(--surface-3); }
.layer-row.selected { background: var(--accent-soft); color: var(--accent); }
.layer-row .swatch-dot {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  flex: none;
}
.layer-row .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row .row-actions { display: flex; gap: 2px; opacity: 0; }
.layer-row:hover .row-actions,
.layer-row.selected .row-actions { opacity: 1; }
.layer-row .row-actions .btn { width: 24px; height: 24px; padding: 0; }
.layer-row.is-hidden .label { opacity: 0.45; text-decoration: line-through; }

/* ---------------------------------------------------------------- corners */

.dock-bl {
  position: absolute;
  left: 14px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  z-index: 30;
}
.dock-br {
  position: absolute;
  right: 14px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  z-index: 30;
}

.zoom-dock { display: flex; align-items: center; gap: 2px; padding: 5px; }
.zoom-value { min-width: 58px; font-variant-numeric: tabular-nums; font-size: 12.5px; }

.conn { display: inline-flex; align-items: center; gap: 7px; padding: 0 9px 0 5px; font-size: 11.5px; color: var(--muted); }
.conn .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); transition: background 0.2s; }
.conn.online .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(18, 183, 106, 0.18); }
.conn.connecting .dot { background: var(--warn); animation: pulse 1.2s infinite; }
.conn.offline .dot { background: var(--danger); }

@keyframes pulse { 50% { opacity: 0.3; } }

.minimap {
  width: 208px;
  height: 132px;
  border-radius: var(--r-md);
  overflow: hidden;
  padding: 0;
  cursor: crosshair;
}
.minimap canvas { display: block; width: 100%; height: 100%; }

/* ------------------------------------------------------------------ peers */

.peers { display: flex; align-items: center; padding-right: 4px; }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  border: 2px solid var(--surface);
  margin-left: -8px;
  cursor: pointer;
  transition: transform 0.16s var(--ease);
}
.avatar:first-child { margin-left: 0; }
.avatar:hover { transform: translateY(-2px) scale(1.06); z-index: 2; }
.avatar.me { box-shadow: 0 0 0 2px var(--accent); cursor: default; }
.avatar.following { box-shadow: 0 0 0 2px var(--ok); }

/* ------------------------------------------------------------------ menus */

.menu {
  position: absolute;
  min-width: 232px;
  padding: 6px;
  z-index: 80;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  animation: pop 0.13s var(--ease);
}

.menu button,
.menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 9px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu button:hover, .menu a:hover { background: var(--surface-3); }
.menu button[disabled] { opacity: 0.4; pointer-events: none; }
.menu .shortcut { margin-left: auto; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.menu .sep { height: 1px; margin: 5px 4px; background: var(--border); }
.menu .menu-title {
  padding: 7px 9px 4px;
  font-size: 10.5px;
  font-weight: 640;
  letter-spacing: 0.055em;
  text-transform: uppercase;
  color: var(--muted);
}
.menu .swatch { width: 24px; height: 24px; padding: 0; flex: none; }
.menu .segment button { width: auto; padding: 0 8px; }

.popover { position: absolute; z-index: 70; }
.shape-flyout { display: grid; grid-template-columns: repeat(5, 42px); gap: 2px; padding: 6px; }
.sticker-pop {
  width: 316px;
  padding: 0;
  min-width: auto;
  overflow: hidden;
}

.sticker-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}
.sticker-search {
  flex: 1;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
  min-width: 0;
}
.sticker-search::placeholder { color: var(--muted); }

.sticker-results {
  max-height: 330px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 8px 10px;
}

.sticker-group {
  font-size: 10.5px;
  font-weight: 620;
  letter-spacing: 0.055em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 4px 6px;
}
.sticker-group:first-child { padding-top: 4px; }

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.sticker-cell {
  width: 100%;
  height: 38px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.12s var(--ease), background 0.12s var(--ease);
}
.sticker-cell:hover { background: var(--surface-3); transform: scale(1.16); }
.sticker-cell:active { transform: scale(0.96); }

/* ----------------------------------------------------------------- modals */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.42);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 24px;
  animation: fade-in 0.15s var(--ease);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: min(800px, 100%);
  max-height: min(84vh, 800px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: modal-in 0.2s var(--ease);
}
.modal.narrow { width: min(480px, 100%); }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.modal header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 17px 18px;
  border-bottom: 1px solid var(--border);
}
.modal header h2 { margin: 0; font-size: 16px; font-weight: 640; letter-spacing: -0.015em; }
.modal header .btn { margin-left: auto; }
.modal .body { padding: 18px; overflow-y: auto; }
.modal footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color 0.14s var(--ease), box-shadow 0.14s var(--ease);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); background: var(--surface); }
textarea.input { height: auto; padding: 9px 12px; resize: vertical; min-height: 74px; line-height: 1.5; }

/* card grids (boards, templates, history) */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 13px; }

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  font: inherit;
  color: var(--text);
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), border-color 0.15s var(--ease);
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.card.current { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card .thumb {
  height: 110px;
  background: var(--surface-3);
  background-size: cover;
  background-position: center;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 28px;
}
.card .meta { padding: 10px 12px 12px; }
.card .meta strong { display: block; font-size: 13px; font-weight: 600; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta span { font-size: 11.5px; color: var(--muted); }
.card .card-actions { position: absolute; top: 8px; right: 8px; display: flex; gap: 3px; opacity: 0; transition: opacity 0.14s; }
.card:hover .card-actions { opacity: 1; }
.card .card-actions .btn { width: 28px; height: 28px; background: var(--surface); box-shadow: var(--shadow-sm); }

/* shortcut sheet */
.shortcut-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(248px, 1fr)); gap: 24px; }
.shortcut-group h3 {
  margin: 0 0 10px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.055em;
  color: var(--muted);
  font-weight: 640;
}
.shortcut-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 13px; }
.shortcut-row + .shortcut-row { border-top: 1px solid var(--border); }

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  background: var(--surface-2);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 620;
  color: var(--text-soft);
  text-align: center;
}

/* -------------------------------------------------------- command palette */

.palette-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.34);
  backdrop-filter: blur(3px);
  z-index: 110;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: min(16vh, 140px);
  animation: fade-in 0.12s var(--ease);
}

.palette {
  width: min(600px, calc(100vw - 32px));
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: modal-in 0.18s var(--ease);
}
.palette-input {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}
.palette-input input {
  flex: 1;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  outline: none;
}
.palette-list { overflow-y: auto; padding: 6px; }
.palette-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.palette-item .group { margin-left: auto; font-size: 11px; color: var(--muted); }
.palette-item .shortcut { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.palette-item[aria-selected='true'] { background: var(--accent-soft); color: var(--accent); }
.palette-item[aria-selected='true'] .group { color: var(--accent); opacity: 0.8; }
.palette-empty { padding: 26px; text-align: center; color: var(--muted); font-size: 13px; }

/* ----------------------------------------------------------- search field */

.search-bar {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  z-index: 40;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  animation: pop 0.14s var(--ease);
}
.search-bar input {
  width: 220px;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
}
.search-bar .count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 54px; text-align: right; }

/* ------------------------------------------------------ timer & presenting */

.session-rail {
  position: absolute;
  top: 72px;
  right: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 26;
  pointer-events: none;
}
.session-rail > * { pointer-events: auto; }

.timer-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px 7px 13px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  font-variant-numeric: tabular-nums;
}
.timer-chip .time { font-size: 17px; font-weight: 650; letter-spacing: -0.02em; min-width: 58px; }
.timer-chip.ending .time { color: var(--danger); }
.timer-chip.ending { animation: nudge 1s infinite; }

@keyframes nudge { 50% { transform: translateX(-2px); } }

.present-bar {
  position: absolute;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 14px;
  z-index: 40;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
}
.present-bar .slide { font-variant-numeric: tabular-nums; color: var(--muted); }

.cursor-chat {
  position: absolute;
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 14px 14px 14px 3px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-md);
}
.cursor-chat input {
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  outline: none;
  width: 190px;
}
.cursor-chat input::placeholder { color: rgba(255, 255, 255, 0.7); }

/* --------------------------------------------------------------- comments */

.comment-pop {
  position: absolute;
  width: 292px;
  z-index: 60;
  padding: 12px;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: pop 0.14s var(--ease);
}
.comment-pop header { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.comment-pop header strong { font-size: 12.5px; }
.comment-pop .thread { max-height: 210px; overflow-y: auto; margin-bottom: 9px; }
.comment-note { padding: 7px 0; font-size: 13px; line-height: 1.45; }
.comment-note + .comment-note { border-top: 1px solid var(--border); }
.comment-note .who { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.comment-pop .row { display: flex; gap: 6px; align-items: flex-end; }

/* ----------------------------------------------------------------- toasts */

/* Bottom left, above the history dock: visible without sitting over the middle
   of the board or the search bar. */
.toasts {
  position: absolute;
  left: 14px;
  bottom: 72px;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-start;
  gap: 8px;
  z-index: 95;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 15px;
  border-radius: var(--r-md);
  background: #101828;
  color: #fff;
  font-size: 13px;
  font-weight: 520;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.22s var(--ease);
  pointer-events: auto;
}
.toast.error { background: var(--danger); }
.toast.leaving { animation: toast-out 0.2s var(--ease) forwards; }
[data-theme='dark'] .toast { background: #f2f4f7; color: #101828; }

@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

.hint {
  position: absolute;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: var(--r-sm);
  background: #101828;
  color: #fff;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  z-index: 35;
  pointer-events: none;
}
[data-theme='dark'] .hint { background: #f2f4f7; color: #101828; }

/* ------------------------------------------------------------ empty state */

.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--muted);
  z-index: 5;
  pointer-events: none;
  animation: fade-in 0.4s var(--ease);
}
.empty-state h2 { margin: 0 0 6px; font-size: 19px; font-weight: 620; color: var(--text-soft); letter-spacing: -0.015em; }
.empty-state p { margin: 0; font-size: 13.5px; }
.empty-state .keys { margin-top: 14px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }

/* ------------------------------------------------------------ text editor */

.text-editor {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 20;
  margin: 0;
  padding: 0;
  border: none;
  outline: none;
  resize: none;
  overflow: hidden;
  background: transparent;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  display: block;
  min-height: 1em;
}

/* -------------------------------------------------------------- drop hint */

.drop-hint {
  position: absolute;
  inset: 12px;
  border: 2.5px dashed var(--accent);
  border-radius: var(--r-xl);
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  z-index: 96;
  pointer-events: none;
}
.drop-hint div {
  padding: 13px 22px;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  font-size: 14px;
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 1180px) {
  .side-panel { display: none; }
}

@media (max-width: 900px) {
  .brand-mark span { display: none; }
  .minimap { display: none; }
  .board-name { max-width: 30vw; }
  #share-btn span { display: none; }
  #share-btn { width: 34px; padding: 0; }
  .tool { width: 38px; height: 38px; }
}

@media (max-width: 720px) {
  .toolbar {
    left: 8px;
    right: 8px;
    bottom: 8px;
    transform: none;
    max-width: none;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .dock-bl { bottom: 68px; left: 8px; }
  .dock-br { bottom: 68px; right: 8px; }
  .panel { top: 66px; bottom: auto; left: 8px; width: 204px; max-height: min(48vh, 400px); }
  .save-state { display: none; }
  .toasts { top: 62px; }
  .hint { bottom: 120px; }
  .present-bar { bottom: 118px; }
  .session-rail { top: 66px; right: 8px; }
}

@media (max-width: 560px) {
  .dock-bl .conn .conn-label { display: none; }
  .zoom-value { min-width: 48px; }
  .board-name { max-width: 40vw; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
