/* ============================================================
   Reader Annotations: ink overlays, note blocks, seams, toolbar
   ============================================================ */

/* Per-section ink overlay (SVG). Inert while reading; live in annotate mode.
   position:absolute means overflowing stroke paint never expands page scroll
   (verified), so overflow:visible is safe and avoids clipping ink near a short
   section's edge. */
.ra-ink-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    overflow: visible;
}

body.ra-annotating .ra-ink-layer {
    pointer-events: auto;
    cursor: crosshair;
    /* finger pans, pen draws; ra-touch-draw flips fingers to drawing */
    touch-action: pan-y pinch-zoom;
}

body.ra-annotating.ra-touch-draw .ra-ink-layer {
    touch-action: none;
}

.ra-ink-layer path.ra-hl {
    opacity: 0.38;
    mix-blend-mode: multiply;
}
.dark .ra-ink-layer path.ra-hl {
    mix-blend-mode: screen;
}

/* Hide everything mine when toggled off */
body.ra-hidden-notes .ra-ink-layer,
body.ra-hidden-notes .ra-note-block,
body.ra-hidden-notes .ra-seam,
body.ra-hidden-notes .ra-orphan-tray,
body.ra-hidden-notes #ra-toolbar {
    display: none !important;
}

/* Insert-space seams: zero-height, hover zone floats over the section gap */
.ra-seam {
    position: relative;
    height: 0;
    z-index: 6;
}
/* topic seams live INSIDE .markdown-body — its generic child margins must not
   inflate the article with invisible spacing per seam */
.markdown-body .ra-seam,
.markdown-body div.ra-seam {
    margin: 0 !important;
    padding: 0 !important;
}
.ra-seam-zone {
    position: absolute;
    left: 0;
    right: 0;
    /* the zero-height seam lands flush with the neighboring card when margins
       collapse (NOTES cards add mb-6) — straddle the boundary instead */
    top: -0.875rem;
    height: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ra-seam-add {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.7rem;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: hsl(var(--muted-foreground));
    background: hsl(var(--background));
    border: 1px dashed hsl(var(--border));
    border-radius: 999px;
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.15s ease, transform 0.15s ease, color 0.15s, border-color 0.15s;
}
.ra-seam-add svg { width: 12px; height: 12px; }
.ra-seam-zone:hover .ra-seam-add,
.ra-seam-add:focus-visible,
body.ra-annotating .ra-seam-add {
    opacity: 1;
    transform: scale(1);
}
.ra-seam-add:hover {
    color: hsl(var(--primary));
    border-color: hsl(var(--primary) / 0.5);
}
/* touch devices: always show a faint pill instead of relying on hover */
@media (pointer: coarse) {
    .ra-seam-add { opacity: 0.45; transform: scale(1); }
}
/* "Add Note Section" from the menu: make every seam obvious */
body.ra-insert-mode .ra-seam-add {
    opacity: 1;
    transform: scale(1.05);
    color: hsl(var(--primary));
    border-color: hsl(var(--primary) / 0.6);
    background: hsl(var(--primary) / 0.08);
    box-shadow: 0 0 0 4px hsl(var(--primary) / 0.08);
}

.ra-seam-chooser {
    position: absolute;
    top: 1.9rem;
    display: flex;
    gap: 0.5rem;
    padding: 0.4rem;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 0.75rem;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
    z-index: 50;
}
.ra-seam-chooser button {
    padding: 0.45rem 0.75rem;
    font-size: 12px;
    font-weight: 700;
    border-radius: 0.5rem;
    white-space: nowrap;
}
.ra-seam-chooser button small { display: block; font-size: 9px; font-weight: 500; color: hsl(var(--muted-foreground)); }
.ra-seam-chooser button:hover { background: hsl(var(--muted)); }

/* User note blocks (Apple Notes "insert space" / Kindle Active Canvas) */
.ra-note-block {
    position: relative;
    border: 1.5px dashed hsl(var(--primary) / 0.35);
    background: hsl(var(--primary) / 0.03);
    border-radius: 0.75rem;
    padding: 0.5rem 0.75rem 0.75rem;
}
.ra-note-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}
.ra-note-label {
    font-size: 9px;
    font-weight: 900;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: hsl(var(--primary) / 0.75);
}
.ra-note-del {
    padding: 0.25rem;
    border-radius: 0.4rem;
    color: hsl(var(--muted-foreground));
}
.ra-note-del:hover { color: #dc2626; background: rgba(220, 38, 38, 0.08); }
.ra-note-del svg { width: 13px; height: 13px; }

.ra-note-text {
    min-height: 84px;
    font-size: 0.95rem;
    line-height: 1.65;
    outline: none;
    white-space: pre-wrap;
    color: hsl(var(--foreground));
    /* generous hit target for OS stylus handwriting (Scribble / S Pen) */
    padding: 0.25rem 0.1rem;
}
.ra-note-text:empty::before {
    content: attr(data-placeholder);
    color: hsl(var(--muted-foreground) / 0.6);
    pointer-events: none;
}

/* The anti-piracy rule `#secure-content-container *` (id specificity) outranks the
   generic [contenteditable] exemption in document-reader.css — re-exempt notes at
   equal-or-higher specificity so the caret and text selection work inside them. */
#secure-content-container .ra-note-text,
#secure-content-container [contenteditable="true"] {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
    -webkit-touch-callout: default !important;
}

.ra-note-pad {
    position: relative;
    border-radius: 0.5rem;
    background:
        repeating-linear-gradient(
            to bottom,
            transparent,
            transparent 27px,
            hsl(var(--border) / 0.55) 27px,
            hsl(var(--border) / 0.55) 28px
        );
}
.ra-note-pad .ra-ink-layer {
    position: absolute;
    inset: 0;
    pointer-events: auto; /* pads are always drawable */
    /* dedicated drawing space: fingers draw here (phone users have no stylus);
       the page still scrolls everywhere outside the pad */
    touch-action: none;
}
.ra-note-grow {
    margin-top: 0.4rem;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: hsl(var(--muted-foreground));
    border: 1px dashed hsl(var(--border));
    border-radius: 0.5rem;
    padding: 0.25rem 0.6rem;
}
.ra-note-grow:hover { color: hsl(var(--primary)); border-color: hsl(var(--primary) / 0.5); }

/* Floating annotation toolbar */
#ra-toolbar {
    position: fixed;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%) translateY(150%);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.45rem 0.6rem;
    background: hsl(var(--background) / 0.96);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid hsl(var(--border));
    border-radius: 999px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
    z-index: 80;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: calc(100vw - 1rem);
    overflow-x: auto;
    scrollbar-width: none;
}
#ra-toolbar::-webkit-scrollbar { display: none; }
#ra-toolbar.show { transform: translateX(-50%) translateY(0); }
#ra-toolbar .ra-t {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-size: 15px;
    flex-shrink: 0;
    opacity: 0.55;
    transition: opacity 0.15s, background 0.15s, transform 0.1s;
}
#ra-toolbar .ra-t:hover { background: hsl(var(--muted)); opacity: 0.9; }
#ra-toolbar .ra-t.active { opacity: 1; background: hsl(var(--primary) / 0.12); }
#ra-toolbar .ra-c {
    width: 22px;
    height: 22px;
    border-radius: 999px;
    border: 2px solid transparent;
    flex-shrink: 0;
    transition: transform 0.12s;
}
#ra-toolbar .ra-c.active { border-color: hsl(var(--foreground)); transform: scale(1.18); }
#ra-toolbar .ra-sep { width: 1px; height: 20px; background: hsl(var(--border)); flex-shrink: 0; }
#ra-toolbar #ra-size-dot {
    display: block;
    border-radius: 999px;
    background: currentColor;
    width: 9px;
    height: 9px;
}
#ra-toolbar .ra-done {
    padding: 0.35rem 0.9rem;
    font-size: 12px;
    font-weight: 800;
    border-radius: 999px;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    flex-shrink: 0;
}

/* Toast */
#ra-toast {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    padding: 0.5rem 1rem;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    background: rgba(15, 23, 42, 0.92);
    border-radius: 999px;
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
#ra-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Orphaned notes tray */
.ra-orphan-tray {
    border: 1.5px dashed hsl(var(--border));
    border-radius: 0.75rem;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.ra-orphan-head { font-size: 12px; font-weight: 800; color: hsl(var(--muted-foreground)); }
.ra-orphan-head small { font-weight: 500; }
.ra-orphan-ink { font-size: 12px; color: hsl(var(--muted-foreground)); }
.ra-orphan-clear {
    margin-left: 0.4rem;
    font-weight: 700;
    color: #dc2626;
    text-decoration: underline;
}

/* The floating toolbar and the back-to-top button share the bottom edge */
body.ra-annotating #backToTopBtn {
    display: none !important;
}

/* Annotate-mode affordance on section cards */
body.ra-annotating #secure-content-container > [data-section-id] {
    outline: 1.5px dashed hsl(var(--primary) / 0.25);
    outline-offset: 2px;
}

/* My-notes visibility switch knob in the 3-dot menu */
#raVisSwitch.active {
    background: hsl(var(--primary));
}
#raVisSwitch.active #raVisKnob {
    transform: translateX(1rem);
}
