/* ============================================================
   GoodNotes — Standalone Handwriting Overlay Module
   Author: SeouLink · License: MIT

   Usage: Include this CSS + goodnotes.js, then call GoodNotes.init()
   No other dependencies required.
   ============================================================ */

/* --- CSS Custom Properties (override to theme) --- */
:root {
  --gn-toolbar-bg: rgba(30, 30, 30, 0.92);
  --gn-toolbar-blur: 16px;
  --gn-toolbar-radius: 16px;
  --gn-toolbar-shadow: 0 8px 32px rgba(0,0,0,0.28);
  --gn-active-color: #4A90D9;
  --gn-hover-bg: rgba(255,255,255,0.10);
  --gn-divider: rgba(255,255,255,0.12);
  --gn-text: #e0e0e0;
  --gn-text-dim: #888;
  --gn-fab-size: 52px;
  --gn-z-overlay: 9000;
  --gn-z-toolbar: 9100;
  --gn-z-fab: 9200;
  --gn-z-submenu: 9150;
}

/* --- FAB (Floating Action Button) --- */
.gn-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: var(--gn-fab-size);
  height: var(--gn-fab-size);
  border-radius: 50%;
  border: none;
  background: var(--gn-toolbar-bg);
  backdrop-filter: blur(var(--gn-toolbar-blur));
  -webkit-backdrop-filter: blur(var(--gn-toolbar-blur));
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  z-index: var(--gn-z-fab);
  box-shadow: var(--gn-toolbar-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s;
  touch-action: manipulation;
}
.gn-fab:hover { transform: scale(1.08); }
.gn-fab.active {
  background: var(--gn-active-color);
}

/* --- Canvas Overlay --- */
.gn-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  z-index: var(--gn-z-overlay);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.gn-overlay.active {
  pointer-events: auto;
  opacity: 1;
}
.gn-overlay canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* subtle grid hint when overlay active */
.gn-overlay.active::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  /* very subtle dot grid */
  background-image: radial-gradient(circle, rgba(0,0,0,0.04) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* --- Toolbar --- */
.gn-toolbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  z-index: var(--gn-z-toolbar);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  background: var(--gn-toolbar-bg);
  backdrop-filter: blur(var(--gn-toolbar-blur));
  -webkit-backdrop-filter: blur(var(--gn-toolbar-blur));
  border-radius: var(--gn-toolbar-radius);
  box-shadow: var(--gn-toolbar-shadow);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.4,0,0.2,1),
              opacity 0.25s;
  user-select: none;
  -webkit-user-select: none;
}
.gn-toolbar.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Toolbar button base */
.gn-toolbar button {
  position: relative;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--gn-text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  touch-action: manipulation;
  flex-shrink: 0;
}
.gn-toolbar button:hover {
  background: var(--gn-hover-bg);
}
.gn-toolbar button:active {
  transform: scale(0.92);
}
.gn-toolbar button.active {
  background: var(--gn-active-color);
  color: #fff;
}
.gn-toolbar button:disabled {
  opacity: 0.3;
  cursor: default;
}

/* Divider */
.gn-divider {
  width: 1px;
  height: 24px;
  background: var(--gn-divider);
  margin: 0 4px;
  flex-shrink: 0;
}

/* --- Tool icon SVGs (inline for portability) --- */
.gn-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Color Swatch in toolbar --- */
.gn-color-indicator {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  transition: border-color 0.15s;
  flex-shrink: 0;
}

/* --- Sub-menus (color picker, width picker) --- */
.gn-submenu {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  background: var(--gn-toolbar-bg);
  backdrop-filter: blur(var(--gn-toolbar-blur));
  -webkit-backdrop-filter: blur(var(--gn-toolbar-blur));
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--gn-toolbar-shadow);
  z-index: var(--gn-z-submenu);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  min-width: 180px;
}
.gn-submenu.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) scale(1);
}

/* Color palette grid */
.gn-color-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.gn-color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
}
.gn-color-swatch:hover {
  transform: scale(1.15);
}
.gn-color-swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--gn-active-color);
}

/* Width picker */
.gn-width-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}
.gn-width-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
  color: var(--gn-text);
}
.gn-width-option:hover {
  background: var(--gn-hover-bg);
}
.gn-width-option.active {
  background: rgba(74,144,217,0.25);
}
.gn-width-preview {
  flex: 1;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}
.gn-width-label {
  font-size: 11px;
  color: var(--gn-text-dim);
  min-width: 28px;
  text-align: right;
}

/* --- Cursor indicators --- */
.gn-cursor-pen { cursor: crosshair; }
.gn-cursor-highlighter { cursor: crosshair; }
.gn-cursor-eraser { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' fill='none' stroke='%23666' stroke-width='1.5'/%3E%3C/svg%3E") 12 12, auto; }

/* --- Stroke preview (cursor follower) --- */
.gn-cursor-dot {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: var(--gn-z-overlay);
  opacity: 0;
  transition: opacity 0.15s;
  mix-blend-mode: multiply;
}
.gn-cursor-dot.visible {
  opacity: 0.5;
}

/* --- Save indicator --- */
.gn-save-indicator {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: var(--gn-z-toolbar);
  background: rgba(30,30,30,0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #4ADE80;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
.gn-save-indicator.visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- Page navigation hint when overlay is on --- */
.gn-scroll-hint {
  position: fixed;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  z-index: var(--gn-z-toolbar);
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.gn-scroll-hint.visible {
  opacity: 1;
  pointer-events: auto;
}
.gn-scroll-hint button {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--gn-toolbar-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .gn-toolbar {
    bottom: 16px;
    padding: 4px 6px;
    gap: 1px;
    border-radius: 12px;
  }
  .gn-toolbar button {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
  .gn-fab {
    bottom: 16px;
    right: 16px;
    width: 46px;
    height: 46px;
    font-size: 20px;
  }
  .gn-submenu {
    min-width: 160px;
    padding: 10px;
  }
  .gn-color-swatch {
    width: 24px;
    height: 24px;
  }
}

@media (max-width: 480px) {
  .gn-toolbar {
    bottom: 12px;
    padding: 3px 5px;
  }
  .gn-toolbar button {
    width: 32px;
    height: 32px;
    font-size: 14px;
    border-radius: 8px;
  }
  .gn-fab {
    width: 42px;
    height: 42px;
    font-size: 18px;
  }
}

/* --- Print: hide everything --- */
@media print {
  .gn-fab,
  .gn-toolbar,
  .gn-overlay,
  .gn-submenu,
  .gn-save-indicator,
  .gn-scroll-hint,
  .gn-cursor-dot { display: none !important; }
}
