@font-face {
  font-family: 'Geist Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/Geist.woff2') format('woff2');
}
:root {
  --canvas-bg: rgb(234, 234, 237);
  --canvas-bg-dark: #1c1b22;
  --text-font-family: 'Geist Sans', system-ui;
  --text-font-style: normal;
  --text-font-kerning: none;
  --text-font-stretch: normal;
  --text-font-variant-caps: normal;
  --text-letter-spacing: 0px;
  --text-direction: ltr;
  --regular_text: 400;
  --white_font: #fbfbfe;
  --menu-secondary-color: #70707a;
  --menu-shortcut-color: #b8b8bc;
  --firefox-menu-bg: #42414d;
  --firefox-menu-border: var(--menu-secondary-color);
  --firefox-menu-text: var(--white_font);
  --menu_hover_bg: #5e5d69;
  --menu_pressed_bg: #7b7a84;
  --firefox-menu-hover-bg: var(--menu_hover_bg);
  --firefox-menu-active-bg: var(--menu_pressed_bg);
  --firefox-menu-separator: var(--menu-secondary-color);
  --firefox-menu-shadow:
    0 8px 24px rgba(0,0,0,0.1),
    0 0 0 1px rgba(0,0,0,0.3);
  --ui-radius: 25px;
  --pill-radius: 999px;
  --menu-shell-radius: var(--ui-radius);
  --menu-shell-padding: 8px;
  --menu-item-height: 32px;
  --menu-item-padding: 0 8px;
  --menu-item-radius: var(--pill-radius);
  --menu-item-font-size: 13px;
  --menu-item-letter-spacing: var(--text-letter-spacing);
  --menu-item-line-height: 32px;
  --context-menu-width: 192px;
  --pill-text-line-height: 18px;
  --pill-text-min-width: 44px;
  --pill-text-max-width: min(680px, calc(100vw - 56px));
  --dialog-overlay-bg: rgba(0,0,0,0.18);
  --selection-outline: rgba(10, 132, 255, 1);
  --selection-handle-bg: #f8fafc;
  --selection-handle-shadow: 0 1px 3px rgba(0,0,0,0.28);
  --danger-text: #FF453A;
  --danger-bg: rgba(255, 69, 58, 0.18);
  --danger-hover-bg: rgba(255, 69, 58, 0.26);
  --danger-active-bg: rgba(255, 69, 58, 0.34);
  --menu-active-bg: var(--firefox-menu-active-bg);
  --smooth-slide-duration: 220ms;
  --smooth-slide-ease: cubic-bezier(0.18, 0.9, 0.24, 1.18);
  --highlight-nudge-x: 2px;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
}

body[data-theme="dark"] {
  --canvas-bg: var(--canvas-bg-dark);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

button {
  outline: none;
}
button,
input,
textarea {
  font: inherit;
  font-kerning: inherit;
  font-stretch: inherit;
  font-variant-caps: inherit;
  letter-spacing: inherit;
  direction: inherit;
}
button::-moz-focus-inner {
  border: 0;
}

html {
  width: 100%;
  height: 100%;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: var(--canvas-bg);
  user-select: none;
  overscroll-behavior: none;
  touch-action: none;
  font: var(--text-font-style) var(--regular_text) var(--menu-item-font-size) var(--text-font-family);
  font-kerning: var(--text-font-kerning);
  font-stretch: var(--text-font-stretch);
  font-variant-caps: var(--text-font-variant-caps);
  letter-spacing: var(--text-letter-spacing);
  direction: var(--text-direction);
  -webkit-font-smoothing: auto;
  -moz-osx-font-smoothing: auto;
}

@supports (height: 100dvh) {
  body { height: 100dvh; }
}

#canvas {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: clip;
  contain: paint;
  background: var(--canvas-bg);
  overscroll-behavior: none;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#canvas.panning, #canvas.panning .s-handle { cursor: grabbing !important; }

#board-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: block;
  z-index: 0;
  touch-action: none;
}

#file-input {
  display: none;
}

/* ── Selection overlay ── */
#sel-overlay {
  --text-edit-outline: var(--selection-outline);
  position: absolute;
  top: 0; left: 0;
  display: none;
  border: 0;
  box-shadow: inset 0 0 0 1px var(--text-edit-outline);
  pointer-events: none;
  z-index: 99998;
}
#sel-overlay.visible { display: block; }
#sel-overlay.multi {
  border: 1px dashed var(--text-edit-outline);
  box-shadow: none;
}
#sel-overlay.editing {
  border: 0;
}
#sel-overlay .s-handle[data-dir="w"],
#sel-overlay .s-handle[data-dir="e"] { display: none; }
#sel-overlay.text-resize .s-handle[data-dir="nw"],
#sel-overlay.text-resize .s-handle[data-dir="ne"],
#sel-overlay.text-resize .s-handle[data-dir="sw"],
#sel-overlay.text-resize .s-handle[data-dir="se"] { display: none; }
#sel-overlay.text-resize .s-handle[data-dir="w"],
#sel-overlay.text-resize .s-handle[data-dir="e"] { display: block; }
.s-handle {
  position: absolute;
  width: 7px;
  height: 7px;
  background: var(--selection-handle-bg);
  border-radius: var(--ui-radius);
  box-shadow: var(--selection-handle-shadow);
  pointer-events: all;
}
.s-handle[data-dir="nw"] { top: -4px;    left: -4px;   cursor: nw-resize; }
.s-handle[data-dir="ne"] { top: -4px;    right: -4px;  cursor: ne-resize; }
.s-handle[data-dir="sw"] { bottom: -4px; left: -4px;   cursor: sw-resize; }
.s-handle[data-dir="se"] { bottom: -4px; right: -4px;  cursor: se-resize; }
.s-handle[data-dir="w"]  { top: 50%; left: -4px; transform: translateY(-50%); cursor: ew-resize; }
.s-handle[data-dir="e"]  { top: 50%; right: -4px; transform: translateY(-50%); cursor: ew-resize; }
#multi-sel-overlay {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
  z-index: 99997;
}
#multi-sel-overlay.visible { display: block; }
.multi-sel-box {
  position: absolute;
  box-shadow: inset 0 0 0 1px var(--selection-outline);
  pointer-events: none;
}

/* ── Context menu ── */
#ctx-menu,
#obj-ctx-menu,
#ctx-actions,
#text-ctx-menu,
#dialog,
#island {
  background: var(--firefox-menu-bg);
  border: 1px solid var(--firefox-menu-border);
  border-radius: var(--menu-shell-radius);
  box-shadow: var(--firefox-menu-shadow);
  color: var(--firefox-menu-text);
  font-family: inherit;
  padding: var(--menu-shell-padding);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#ctx-menu,
#obj-ctx-menu,
#text-ctx-menu,
#ctx-actions {
  position: fixed;
  z-index: 99999;
  display: none;
  isolation: isolate;
  transform: translateZ(0);
  max-width: calc(100vw - var(--safe-area-left) - var(--safe-area-right) - 24px);
}

#ctx-menu,
#obj-ctx-menu,
#text-ctx-menu {
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - var(--safe-area-top) - var(--safe-area-bottom) - 24px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  -webkit-tap-highlight-color: transparent;
}

#ctx-menu {
  width: var(--context-menu-width);
}

#obj-ctx-menu,
#text-ctx-menu {
  width: 192px;
}

#ctx-menu.visible,
#obj-ctx-menu.visible,
#text-ctx-menu.visible { display: block; }

#ctx-menu *,
#obj-ctx-menu *,
#text-ctx-menu *,
#ctx-actions * {
  user-select: none;
  -webkit-user-select: none;
}

#ctx-actions {
  width: calc(var(--menu-item-height) + (var(--menu-shell-padding) * 2) + 2px);
}

#ctx-actions.visible {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Highlight-nudge interaction partition. Add .ui-highlight-nudge to opt new controls in. */
:where(.ctx-item, .ui-highlight-nudge) {
  --ui-highlight-nudge-transform: translateX(0);
}

:where(.ctx-item:focus-visible, .ctx-action-item:focus-visible) {
  --ui-highlight-nudge-transform: translateX(var(--highlight-nudge-x));
}

@media (hover: hover) and (pointer: fine) {
  :where(.ctx-item:hover, .ui-highlight-nudge:hover, #island:hover .ui-highlight-nudge) {
    --ui-highlight-nudge-transform: translateX(var(--highlight-nudge-x));
  }
}

.ctx-action-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: var(--menu-item-height);
  width: var(--menu-item-height);
  height: var(--menu-item-height);
  font: var(--text-font-style) var(--regular_text) var(--menu-item-font-size) var(--text-font-family);
  line-height: var(--menu-item-line-height);
  color: var(--firefox-menu-text);
  background: transparent;
  border: 0;
  border-radius: var(--menu-item-radius);
  outline: none;
  box-shadow: none;
  cursor: default;
  letter-spacing: var(--menu-item-letter-spacing);
  white-space: nowrap;
  text-align: left;
  isolation: isolate;
  contain: paint;
  overflow: hidden;
  text-decoration: none;
  transform: var(--ui-highlight-nudge-transform);
  transition: transform var(--smooth-slide-duration) var(--smooth-slide-ease);
}
.ctx-action-item:focus-visible { background: var(--firefox-menu-hover-bg); }
@media (hover: hover) and (pointer: fine) {
  .ctx-action-item:hover { background: var(--firefox-menu-hover-bg); }
}
.ctx-action-item.hotspot-active,
.ctx-action-item[aria-pressed="true"] { background: var(--menu-active-bg); }
.ctx-action-icon svg {
  position: relative;
  z-index: 1;
  display: block;
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.ctx-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 18px;
  align-items: center;
  width: 100%;
  height: var(--menu-item-height);
  padding: var(--menu-item-padding);
  font: var(--text-font-style) var(--regular_text) var(--menu-item-font-size) var(--text-font-family);
  line-height: var(--menu-item-line-height);
  color: var(--firefox-menu-text);
  background: transparent;
  border: none;
  border-radius: var(--menu-item-radius);
  text-align: left;
  cursor: default;
  letter-spacing: var(--menu-item-letter-spacing);
  user-select: none;
  -webkit-user-select: none;
  box-shadow: none;
  transform: var(--ui-highlight-nudge-transform);
  transition:
    background-color var(--smooth-slide-duration) var(--smooth-slide-ease),
    transform var(--smooth-slide-duration) var(--smooth-slide-ease);
}
.ctx-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ctx-shortcut {
  color: var(--menu-shortcut-color);
  font: var(--text-font-style) var(--regular_text) var(--menu-item-font-size) var(--text-font-family);
  line-height: inherit;
  justify-self: end;
  white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) {
  .ctx-item:hover {
    background: var(--firefox-menu-hover-bg);
  }
}
.ctx-item:focus-visible {
  background: var(--firefox-menu-hover-bg);
}
@media (hover: none), (pointer: coarse) {
  .ctx-item:focus-visible {
    --ui-highlight-nudge-transform: translateX(0);
    background: transparent;
  }
}
.ctx-item.menu-pressed {
  background: var(--menu-active-bg);
  transition-duration: 0ms;
}
.ctx-sep {
  height: 1px;
  /* Borders keep a consistent device-pixel width at fractional display scales. */
  border-top: 1px solid var(--firefox-menu-separator);
  margin: 8px 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Island ── */
#island {
  position: fixed;
  bottom: max(5%, calc(var(--safe-area-bottom) + 12px));
  left: 50%;
  translate: -50% 0;
  display: none;
  align-items: center;
  z-index: 9000;
  pointer-events: auto;
  cursor: pointer;
  overscroll-behavior: none;
  touch-action: none;
  border-radius: var(--pill-radius);
  max-width: calc(100vw - 32px);
}

#island[data-mode="message"] {
  cursor: default;
  pointer-events: none;
}

#island * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  pointer-events: none;
}

#island.visible {
  display: flex;
}

@media (hover: hover) and (pointer: fine) {
  #island:hover #isl-zoom {
    background: var(--firefox-menu-hover-bg);
  }
}

#island:active #isl-zoom {
  background: var(--menu-active-bg);
  transition-duration: 0ms;
}

#island[data-mode="message"] #isl-zoom {
  --ui-highlight-nudge-transform: translateX(0);
  background: transparent;
  transform: none;
}

#isl-zoom {
  cursor: default;
  min-height: var(--menu-item-height);
  padding: var(--menu-item-padding);
  font: var(--text-font-style) var(--regular_text) var(--menu-item-font-size) var(--text-font-family);
  line-height: var(--pill-text-line-height);
  color: var(--firefox-menu-text);
  background: transparent;
  border-radius: var(--pill-radius);
  letter-spacing: var(--menu-item-letter-spacing);
  white-space: normal;
  min-width: var(--pill-text-min-width);
  max-width: var(--pill-text-max-width);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  transform: var(--ui-highlight-nudge-transform);
  transition:
    background-color var(--smooth-slide-duration) var(--smooth-slide-ease),
    color var(--smooth-slide-duration) var(--smooth-slide-ease),
    transform var(--smooth-slide-duration) var(--smooth-slide-ease);
}

#opening-shield {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99998;
  cursor: default;
}
#opening-shield.active { display: block; }
#opening-shield.opening-freeze {
  overflow: hidden;
  background: var(--canvas-bg);
}
#opening-shield.opening-freeze *,
#opening-shield.opening-freeze *::before,
#opening-shield.opening-freeze *::after {
  animation: none !important;
  transition: none !important;
}
#rubber-band {
  display: none;
  position: fixed;
  border: 1px solid var(--selection-outline);
  background: transparent;
  pointer-events: none;
  z-index: 8000;
}

/* ── Unsaved changes dialog ── */
#dialog-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--dialog-overlay-bg);
  backdrop-filter: blur(12px) saturate(150%);
  -webkit-backdrop-filter: blur(12px) saturate(150%);
  z-index: 9999999;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}
#dialog-overlay.show { display: flex; }
#dialog-overlay * {
  user-select: none;
  -webkit-user-select: none;
}

#dialog {
  position: relative;
  width: 250px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

#dialog-title {
  pointer-events: none;
}

#dialog-btns {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#dlg-right {
  display: flex;
  gap: 4px;
}

#dialog-btns .dialog-action {
  width: auto;
  display: inline-flex;
  justify-content: center;
  text-align: center;
}

#dlg-discard {
  background: var(--danger-bg);
  color: var(--danger-text);
}
@media (hover: hover) and (pointer: fine) {
  #dlg-discard:hover {
    background: var(--danger-hover-bg);
  }
}
#dlg-discard:focus-visible {
  background: var(--danger-hover-bg);
}
#dlg-discard:active {
  background: var(--danger-active-bg);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
