/* ============================================
 * TABLET INK MODE — GoodNotes-like Drawing
 * ============================================
 * Canvas overlay, pen toolbar, drawn note popups
 * Only active when body.tablet-device.ink-mode-active
 */

 
/* ── Ink Mode Canvas Overlay ── */
.ink-canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 50;
    overflow: hidden;
}

body.ink-mode-active .ink-canvas-container {
    pointer-events: auto;
}

.ink-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none; /* Prevent browser gestures on canvas */
    cursor: crosshair;
}

/* Temp canvas layered above main for live highlighter drawing */
.ink-canvas-temp {
    pointer-events: none; /* All events go to the main canvas beneath */
}

/* Allow finger scrolling through the canvas */
body.ink-mode-active .bible-content-wrapper {
    overflow-y: auto !important;
}

/* ── Ink Mode Toggle Button in Top Bar ── */
.tablet-ink-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-color, #333);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.tablet-ink-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

.tablet-ink-btn.active {
    background: rgba(99, 102, 241, 0.15);
    color: #6366f1;
}

.tablet-ink-btn.active::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 2px;
    background: #6366f1;
    border-radius: 1px;
}

[data-theme="dark"] .tablet-ink-btn {
    color: var(--text-color, #e0e0e0);
}

[data-theme="dark"] .tablet-ink-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .tablet-ink-btn.active {
    background: rgba(129, 140, 248, 0.2);
    color: #818cf8;
}

[data-theme="dark"] .tablet-ink-btn.active::after {
    background: #818cf8;
}

/* ── Floating Pen Toolbar ── */
.ink-pen-toolbar {
    position: fixed;
    z-index: 10001;
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.10), 0 1px 3px rgba(0, 0, 0, 0.05);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
    transition: left 0.35s cubic-bezier(.4,0,.2,1), top 0.35s cubic-bezier(.4,0,.2,1), border-radius 0.3s ease, padding 0.3s ease, opacity 0.2s ease, transform 0.2s ease;
    cursor: grab;
}

.ink-pen-toolbar.dragging {
    cursor: grabbing;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.3);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

/* ── Vertical orientation (snapped to left/right edge) ── */
.ink-pen-toolbar.vertical {
    flex-direction: column;
    padding: 8px 4px;
}

.ink-pen-toolbar.vertical .ink-toolbar-tools {
    flex-direction: column;
}

.ink-pen-toolbar.vertical .ink-toolbar-colors {
    flex-direction: column;
}

.ink-pen-toolbar.vertical .ink-toolbar-sizes {
    flex-direction: column;
}

.ink-pen-toolbar.vertical .ink-toolbar-divider {
    width: 24px;
    height: 1px;
    margin: 4px 0;
}

.ink-pen-toolbar.vertical .ink-toolbar-drag {
    width: 28px;
    height: 20px;
}

.ink-pen-toolbar.vertical .ink-toolbar-drag svg {
    transform: rotate(90deg);
}

/* Undo/Redo row in vertical */
.ink-pen-toolbar.vertical .ink-toolbar-undo-group {
    flex-direction: column;
}

/* ── Snapped edge states ── */
.ink-pen-toolbar.snapped-left {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    left: 0 !important;
}

.ink-pen-toolbar.snapped-right {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.ink-pen-toolbar.snapped-top {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.ink-pen-toolbar.snapped-bottom {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.ink-pen-toolbar.collapsed {
    padding: 6px;
    gap: 0;
    border-radius: 12px;
}

.ink-pen-toolbar.collapsed .ink-toolbar-tools,
.ink-pen-toolbar.collapsed .ink-toolbar-divider,
.ink-pen-toolbar.collapsed .ink-toolbar-colors,
.ink-pen-toolbar.collapsed .ink-toolbar-sizes,
.ink-pen-toolbar.collapsed .ink-toolbar-undo-group {
    display: none;
}

/* Drag Ghost — small pill shown at pointer while dragging toolbar */
.ink-drag-ghost {
    position: fixed;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(99, 102, 241, 0.85);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.6);
    transition: opacity 0.15s ease, transform 0.15s ease;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}
.ink-drag-ghost.visible {
    opacity: 1;
    transform: scale(1);
}
[data-theme="dark"] .ink-drag-ghost {
    background: rgba(129, 140, 248, 0.9);
    box-shadow: 0 4px 16px rgba(129, 140, 248, 0.35);
}

[data-theme="dark"] .ink-pen-toolbar {
    background: rgba(38, 38, 42, 0.97);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

/* Drag handle (visual indicator only — entire toolbar is draggable) */
.ink-toolbar-drag {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 28px;
    color: #aaa;
    flex-shrink: 0;
    opacity: 0.6;
}

.ink-toolbar-drag svg {
    pointer-events: none;
}

[data-theme="dark"] .ink-toolbar-drag {
    color: #666;
}

/* Toolbar Divider */
.ink-toolbar-divider {
    width: 1px;
    height: 20px;
    background: rgba(0, 0, 0, 0.08);
    margin: 0 2px;
    flex-shrink: 0;
}

[data-theme="dark"] .ink-toolbar-divider {
    background: rgba(255, 255, 255, 0.1);
}

/* Tool Buttons (Pen, Highlighter, Eraser) */
.ink-tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #555;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    flex-shrink: 0;
}

.ink-tool-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

.ink-tool-btn.active {
    background: rgba(99, 102, 241, 0.12);
    color: #6366f1;
}

[data-theme="dark"] .ink-tool-btn {
    color: #bbb;
}

[data-theme="dark"] .ink-tool-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .ink-tool-btn.active {
    background: rgba(129, 140, 248, 0.2);
    color: #818cf8;
}

/* Undo/Redo buttons */
.ink-undo-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: #888;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    flex-shrink: 0;
}

.ink-undo-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #555;
}

.ink-undo-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

[data-theme="dark"] .ink-undo-btn {
    color: #777;
}

[data-theme="dark"] .ink-undo-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
    color: #bbb;
}

/* Collapse/Expand toggle */
.ink-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: #999;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    flex-shrink: 0;
}

.ink-collapse-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .ink-collapse-btn {
    color: #666;
}

[data-theme="dark"] .ink-collapse-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Color Dots */
.ink-toolbar-colors {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ink-color-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    flex-shrink: 0;
    position: relative;
}

.ink-color-dot:hover {
    transform: scale(1.15);
}

.ink-color-dot.active {
    border-color: rgba(99, 102, 241, 0.6);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.ink-color-dot.active::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.3);
}

/* Size Buttons */
.ink-toolbar-sizes {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ink-size-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    flex-shrink: 0;
}

.ink-size-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

.ink-size-btn.active {
    background: rgba(99, 102, 241, 0.12);
}

.ink-size-dot {
    border-radius: 50%;
    background: #555;
}

[data-theme="dark"] .ink-size-dot {
    background: #bbb;
}

[data-theme="dark"] .ink-size-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .ink-size-btn.active {
    background: rgba(129, 140, 248, 0.2);
}

/* ── Drawn Note Popup (Canvas-based note creation) ── */
.drawn-note-popup {
    position: absolute;
    z-index: 10000;
    width: 360px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    overflow: hidden;
    opacity: 0;
    transform: scale(0.95) translateY(8px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.drawn-note-popup.visible {
    opacity: 1;
    transform: scale(1) translateY(0);
}

[data-theme="dark"] .drawn-note-popup {
    background: rgba(38, 38, 42, 0.98);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

/* Drawn Note Header */
.drawn-note-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .drawn-note-header {
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

.drawn-note-reference {
    font-size: 12px;
    font-weight: 600;
    color: #6366f1;
    letter-spacing: 0.02em;
}

[data-theme="dark"] .drawn-note-reference {
    color: #818cf8;
}

.drawn-note-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #999;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
}

.drawn-note-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #666;
}

[data-theme="dark"] .drawn-note-close:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ccc;
}

/* Drawing Canvas Area */
.drawn-note-canvas-area {
    position: relative;
    width: 100%;
    height: 260px;
    background: #fefefe;
    cursor: crosshair;
}

[data-theme="dark"] .drawn-note-canvas-area {
    background: #2a2a2e;
}

.drawn-note-canvas {
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* Mini Pen Controls inside drawn note */
.drawn-note-pen-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    background: rgba(0, 0, 0, 0.015);
}

[data-theme="dark"] .drawn-note-pen-controls {
    border-color: rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.02);
}

.drawn-note-pen-controls .ink-color-dot {
    width: 18px;
    height: 18px;
}

.drawn-note-pen-controls .ink-size-btn {
    width: 24px;
    height: 24px;
}

.drawn-note-pen-controls .ink-tool-btn {
    width: 28px;
    height: 28px;
}

/* Drawn Note Actions */
.drawn-note-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px 14px;
}

.drawn-note-cancel {
    padding: 6px 14px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #888;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.drawn-note-cancel:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #555;
}

[data-theme="dark"] .drawn-note-cancel:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ccc;
}

.drawn-note-save {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 16px;
    border: none;
    border-radius: 8px;
    background: #6366f1;
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.drawn-note-save:hover {
    background: #5558e6;
}

.drawn-note-save:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ── Drawn Note View Card (Side-slide, Image 2 style) ── */
.drawn-note-card {
    position: absolute;
    z-index: 9999;
    width: 240px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 14px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1), 0 1px 4px rgba(0, 0, 0, 0.05);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    overflow: hidden;
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.drawn-note-card.visible {
    opacity: 1;
    transform: translateX(0);
}

.drawn-note-card.right-side {
    transform: translateX(20px);
}

.drawn-note-card.right-side.visible {
    transform: translateX(0);
}

[data-theme="dark"] .drawn-note-card {
    background: rgba(38, 38, 42, 0.96);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.drawn-note-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .drawn-note-card-header {
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

.drawn-note-card-ref {
    font-size: 11px;
    font-weight: 600;
    color: #6366f1;
}

[data-theme="dark"] .drawn-note-card-ref {
    color: #818cf8;
}

.drawn-note-card-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: #999;
    cursor: pointer;
    padding: 0;
    transition: all 0.15s ease;
}

.drawn-note-card-close:hover {
    background: rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .drawn-note-card-close:hover {
    background: rgba(255, 255, 255, 0.08);
}

.drawn-note-card-image {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
}

.drawn-note-card-image img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    background: #fafafa;
}

[data-theme="dark"] .drawn-note-card-image img {
    filter: invert(0.9) hue-rotate(180deg);
    background: #2a2a2e;
}

.drawn-note-card-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    padding: 4px 10px 8px;
}

.drawn-note-card-edit,
.drawn-note-card-delete {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #999;
    cursor: pointer;
    padding: 0;
    transition: all 0.15s ease;
}

.drawn-note-card-edit:hover {
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
}

.drawn-note-card-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* ── Ink Mode Body State Overrides ── */
body.ink-mode-active #chapter-content {
    position: relative;
}

/* Subtle indicator when ink mode is on */
body.ink-mode-active .bible-content-wrapper::before {
    content: '';
    position: fixed;
    top: 56px;
    right: 12px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6366f1;
    z-index: 10002;
    animation: inkPulse 2s ease-in-out infinite;
}

@keyframes inkPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Force single column in ink mode */
body.ink-mode-active .chapter-content,
body.ink-mode-active #chapter-content {
    column-count: 1 !important;
    max-width: 660px !important;
}

/* ── Clear Ink button ── */
.ink-clear-confirm {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10010;
    background: white;
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
    padding: 24px;
    text-align: center;
    max-width: 300px;
}

[data-theme="dark"] .ink-clear-confirm {
    background: #2a2a2e;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.ink-clear-confirm h3 {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

[data-theme="dark"] .ink-clear-confirm h3 {
    color: #eee;
}

.ink-clear-confirm p {
    margin: 0 0 16px;
    font-size: 13px;
    color: #888;
}

.ink-clear-confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.ink-clear-confirm-actions button {
    padding: 8px 20px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ink-clear-cancel {
    background: rgba(0, 0, 0, 0.06);
    color: #888;
}

.ink-clear-cancel:hover {
    background: rgba(0, 0, 0, 0.1);
}

.ink-clear-delete {
    background: #ef4444;
    color: white;
}

.ink-clear-delete:hover {
    background: #dc2626;
}

.ink-clear-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    z-index: 10009;
}

/* ── Responsive adjustments ── */
@media (min-width: 768px) and (max-width: 1024px) {
    .ink-pen-toolbar {
        padding: 5px 8px;
        gap: 3px;
    }

    .ink-tool-btn {
        width: 30px;
        height: 30px;
    }

    .ink-color-dot {
        width: 20px;
        height: 20px;
    }

    .drawn-note-popup {
        width: 320px;
    }

    .drawn-note-canvas-area {
        height: 220px;
    }
}
