/* BrowserNotes – editor, toolbar, drawing */

.toolbar {
  position: relative;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.1rem;
  flex-wrap: nowrap;
  height: var(--toolbar-h);
  min-height: var(--toolbar-h);
  padding: 0 0.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-ui);
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.toolbar::after {
  content: "";
  flex: 0 0 0.75rem;
}

.search-bar {
  flex-shrink: 0;
}

.toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: 0.05rem;
  padding-right: 0.3rem;
  margin-right: 0.3rem;
  border-right: 1px solid var(--line);
  flex-shrink: 0;
}

.toolbar-group:last-child {
  border-right: none;
  margin-right: 0;
  padding-right: 0;
}

.toolbar .btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.toolbar .btn {
  min-width: 1.75rem;
  min-height: 1.75rem;
  padding: 0.3rem;
  justify-content: center;
  font-weight: 600;
  font-size: 0.7rem;
}

.main-editor {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 52rem;
  margin: 0 auto;
  padding: 0.4rem 0.75rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-shell {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  /* y-only: avoids the classic auto-scrollbar feedback loop
     (vertical bar → narrower content → horizontal bar) */
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.editor {
  position: relative;
  z-index: 1;
  flex: 1 0 auto;
  max-width: 100%;
  padding: 1.1rem 1.25rem 1.5rem;
  outline: none;
  overflow-wrap: break-word;
  word-break: break-word;
  caret-color: var(--accent);
}

.editor:empty::before {
  content: attr(data-placeholder);
  color: var(--ink-muted);
  pointer-events: none;
  font-style: italic;
}

.editor h1,
.editor h2 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 1.25em 0 0.5em;
}

.editor h1 {
  font-size: 1.85rem;
}

.editor h2 {
  font-size: 1.4rem;
}

.editor p {
  margin: 0 0 0.85em;
}

.editor ul,
.editor ol {
  margin: 0 0 0.85em;
  padding-left: 1.4rem;
}

.editor blockquote {
  margin: 0 0 0.85em;
  padding: 0.25rem 0 0.25rem 1rem;
  border-left: 3px solid var(--accent);
  color: var(--ink-muted);
}

/* Don't leave a gap under the last block (noticeable after clear-format → <p>) */
.editor > :last-child {
  margin-bottom: 0;
}

.editor pre,
.editor .code-block {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  overflow-x: auto;
  margin: 0 0 0.85em;
  white-space: pre-wrap;
}

.editor code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--paper-deep);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}

.editor .task-list {
  list-style: none;
  padding-left: 0;
}

.editor .task-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.35em;
}

.editor .task-list input[type="checkbox"] {
  margin-top: 0.4em;
  accent-color: var(--accent);
}

.editor img.note-image {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.75em 0;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

#draw-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  touch-action: none;
  display: none;
}

.draw-svg {
  display: none !important;
}

.draw-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  display: none;
  object-fit: fill;
  user-select: none;
}

.editor-shell.is-draw-mode #draw-canvas {
  pointer-events: auto;
  cursor: crosshair;
  display: block;
}

.editor-shell.is-draw-mode .draw-preview {
  display: none !important;
}

.editor-shell.is-draw-mode .editor {
  user-select: none;
}

.drawing-tools {
  display: none;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: nowrap;
}

.drawing-tools.is-visible {
  display: inline-flex;
}

.mode-toggle.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.editor mark.search-hit {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
  color: inherit;
  border-radius: 2px;
}

.editor-shell.is-drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

@media (max-width: 640px) {
  .editor {
    padding: 0.85rem 0.85rem 1.25rem;
  }

  .main-editor {
    padding: 0.3rem 0.45rem;
  }

  .toolbar {
    padding: 0 0.25rem;
    gap: 0.05rem;
  }

  .toolbar-group {
    margin-right: 0.1rem;
    padding-right: 0.1rem;
  }

  .toolbar .btn {
    min-width: 2.5rem;
    min-height: 2.5rem;
    padding: 0.4rem;
    font-size: 0.75rem;
  }

  .drawing-tools .btn {
    min-width: 2.5rem;
  }
}
