@property --edge-line { syntax: '<color>'; inherits: false; initial-value: transparent; }
/* Fonts: local files so the app works from file://. Latin subset only. */
@font-face { font-family: "Manrope"; src: url("../fonts/manrope-latin-wght-normal.woff2") format("woff2"); font-weight: 200 800; font-style: normal; font-display: swap; }
@font-face { font-family: "Passion One"; src: url("../fonts/passion-one-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }

:root {
  /* Colours */
  --bg-color: #000000;
  --text-color: #ffffff;
  --panel-bg: rgba(20, 20, 20, 0.88);
  --panel-bg-solid: rgba(18, 18, 18, 0.97);
  --surface-1: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.08);
  --surface-3: rgba(255, 255, 255, 0.14);
  --divider: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.2);
  --danger: #ff5555;
  --danger-surface: rgba(255, 85, 85, 0.12);
  --danger-surface-strong: rgba(255, 85, 85, 0.2);
  --danger-border: rgba(255, 85, 85, 0.3);
  /* Opacity levels */
  --opacity-secondary: 0.85;
  --opacity-muted: 0.6;
  --opacity-faint: 0.4;
  --opacity-mark: 0.5;
  --opacity-mark-faint: 0.12;
  --opacity-rest: 0.25;
  --opacity-dim: 0.5;
  --opacity-dim-deep: 0.75;
  --opacity-dim-faint: 0.25;
  /* Text sizes */
  --font-xs: 10px;
  --font-sm: 11px;
  --font-md: 13px;
  --font-lg: 19px;
  --font-xl: 30px;
  /* Font families */
  --font-body: Manrope, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-title: "Passion One", Manrope, ui-sans-serif, system-ui, sans-serif;
  /* Shadows */
  --shadow-panel: 0 4px 12px rgba(0, 0, 0, 0.2);
  /* Motion */
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
}

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

body {
  font-family: var(--font-body);
  background-color: var(--bg-color);
  color: var(--text-color);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  /* No double-tap zoom on buttons; they stay tappable. */
  touch-action: manipulation;
}

/* Stops pull-to-refresh and overscroll bounce on touch screens. */
html, body {
  overscroll-behavior: none;
}

/* Keeps the UI from being selected or highlighted by taps, drags or key presses. Text fields stay selectable. */
html, body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
input, textarea, [contenteditable="true"] { -webkit-user-select: text; user-select: text; }

#canvas-background {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--bg-color);
  pointer-events: none;
}

/* The tracing ghost sits BEHIND the strokes by default (between the background and the canvas) in plain white (the same brightness as the in-front guide at the same opacity), so drawn lines cover it. With the "Guide in front of strokes" setting it moves in front and uses a difference blend, so it shows the inverse of whatever strokes lie beneath it. */
#trace-reference-layer {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 1;
  transform: translate(-50%, -50%);
  color: var(--text-color);
  transition: opacity 1000ms var(--ease-out-quart);
  pointer-events: none;
}
#trace-reference-layer.trace-in-front {
  z-index: 3;
  color: var(--text-color);
  mix-blend-mode: difference;
}
#trace-reference-layer.trace-fade-out { opacity: 0; }
#trace-reference-layer.trace-fade-in-start { opacity: 0; transition: none; }
#trace-reference-layer[hidden] { display: none; }
#trace-reference-layer svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* Contextual UI Transitions */
.ui-element {
  transition: opacity 0.3s var(--ease-out-quart), transform 0.3s var(--ease-out-quart) !important;
}

#infinite-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: none;
  pointer-events: none;
  transform-origin: 0 0;
  z-index: 2;
}

/* Stable hit-test layer. The drawing bitmap may be temporarily compositor-
   transformed during camera movement without moving the input surface. */
#canvas-input-surface {
  position: absolute;
  inset: 0;
  z-index: 3;
  cursor: none;
  background: transparent;
  /* The browser must not claim touch or pen gestures (scroll, zoom) from the drawing surface. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Stroke ripple: a gentle ring of dimming that travels out from where a stroke was released. Visual only; above the canvas, never receives input. */
#stroke-ripple-layer {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
}

#infinite-canvas.camera-preview-active {
  will-change: transform;
}

.toolbar {
  position: absolute;
  top: 50%;
  left: 24px;
  transform: translateY(-50%);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  --brush-panel-height: 280px;
  --brush-panel-width: 48px;
  --brush-panel-collapsed-width: 12px;
  width: var(--brush-panel-collapsed-width);
  height: var(--brush-panel-height);
  overflow: hidden;
  box-shadow: var(--shadow-panel);
  z-index: 10;
  transition: opacity 0.4s var(--ease-out-quart), transform 0.3s var(--ease-out-quart), width 0.4s var(--ease-out-quart), border-color 0.4s var(--ease-out-quart) !important;
}

.toolbar.is-expanded { width: var(--brush-panel-width); }
@media (hover: none) { .toolbar { width: var(--brush-panel-width); } }

.tool-group {
  width: 100%;
  height: 100%;
}

.top-left-save {
  position: absolute;
  top: 24px;
  left: 24px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--text-color);
  --panel-open-width: 48px;
  width: var(--panel-open-width);
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-panel);
  transition: background-color 0.2s var(--ease-out-quart), color 0.2s var(--ease-out-quart), transform 0.2s var(--ease-out-quart), box-shadow 0.2s var(--ease-out-quart), border-color 0.2s var(--ease-out-quart);
  z-index: 10;
}

.top-left-save:hover {
  background-image: linear-gradient(var(--surface-2), var(--surface-2));
}

.top-left-clear {
  position: absolute;
  top: 84px;
  left: 24px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--text-color);
  --panel-open-width: 48px;
  width: var(--panel-open-width);
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-panel);
  transition: background-color 0.2s var(--ease-out-quart), color 0.2s var(--ease-out-quart), transform 0.2s var(--ease-out-quart), box-shadow 0.2s var(--ease-out-quart), border-color 0.2s var(--ease-out-quart);
  z-index: 10;
}

.top-left-clear:hover {
  background-image: linear-gradient(var(--danger-surface-strong), var(--danger-surface-strong));
  color: var(--danger);
  border-color: var(--danger-border);
}

/* Receding (mouse and pen only): Save and Clear rest as thin bars on their left edge, dimmed to --opacity-rest, and open when the mouse is near.
   The bar changes its real width like the brush panel (constant radius, overflow: hidden), so the border, shadow and corners travel with the edge.
   The class is-expanded is set by updateRecedingPanels() in js/app/13-render-and-strokes.js. */
@media (hover: hover) {
  .top-left-save, .top-left-clear {
    padding: 0;
    justify-content: flex-start;
    overflow: hidden;
    transition: opacity 0.4s var(--ease-out-quart), transform 0.3s var(--ease-out-quart), width 0.4s var(--ease-out-quart), border-color 0.4s var(--ease-out-quart), color 0.2s var(--ease-out-quart) !important;
    border-image-slice: 0 0 0 1;
    border-image-width: 0 0 0 1px;
  }
  .top-left-save svg, .top-left-clear svg { flex: none; margin-left: 11px; transition: opacity 0.4s var(--ease-out-quart); }
  .top-left-save:not(.is-expanded), .top-left-clear:not(.is-expanded) {
    width: 12px;
    border-color: transparent;
    --edge-line: var(--text-color);
    border-image-source: linear-gradient(to bottom, transparent 0, transparent 6px, var(--edge-line) 6px, var(--edge-line) calc(100% - 6px), transparent calc(100% - 6px));
    transition: opacity 0.4s var(--ease-out-quart), transform 0.3s var(--ease-out-quart), width 0.4s var(--ease-out-quart), border-color 0.4s var(--ease-out-quart), color 0.2s var(--ease-out-quart), --edge-line 0.2s var(--ease-out-quart) 0.2s, border-image-source 0s var(--ease-out-quart) 0.2s allow-discrete !important;
    pointer-events: none;
  }
  body:not(.ui-hidden) .top-left-save:not(.is-expanded), body:not(.ui-hidden) .top-left-clear:not(.is-expanded) { opacity: var(--opacity-rest); }
  .top-left-save:not(.is-expanded) svg, .top-left-clear:not(.is-expanded) svg { opacity: 0; }
}

