/**
 * Brutal Blocks: Inline Tooltip (Format Type)
 * Pure CSS implementation using data-attributes and pseudo-elements.
 * ZERO JavaScript required on the frontend. Extremely lightweight.
 * Fluid typography and fluid spacing enforced via clamp().
 *
 * @package BrutalBlocks
 */

/* ── 1. TRIGGER ELEMENT (The highlighted text) ───────────────────────────── */

.bbt-inline-tooltip {
    position: relative;
    display: inline-block; /* Secure boundaries for absolute positioning */
    cursor: help;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
    transition: color 0.2s ease, text-decoration-color 0.2s ease;
    
    /* Theme Defaults (Fallback to dark aesthetic) */
    --bbt-tt-bg: var(--wp--preset--color--contrast, #111111);
    --bbt-tt-fg: var(--wp--preset--color--base, #ffffff);
}

.bbt-inline-tooltip:hover,
.bbt-inline-tooltip:focus {
    color: var(--bbt-tt-bg);
    text-decoration-color: var(--bbt-tt-bg);
    outline: none;
}

/* ── 2. THEMES (PRO) ─────────────────────────────────────────────────────── */

.bbt-inline-tooltip[data-theme="light"] {
    --bbt-tt-bg: var(--wp--preset--color--base, #ffffff);
    --bbt-tt-fg: var(--wp--preset--color--contrast, #111111);
}

.bbt-inline-tooltip[data-theme="brand"] {
    --bbt-tt-bg: var(--wp--preset--color--primary, #6366f1);
    --bbt-tt-fg: var(--wp--preset--color--base, #ffffff);
}

/* ── 3. BUBBLE & ARROW (SHARED) ──────────────────────────────────────────── */

.bbt-inline-tooltip::before,
.bbt-inline-tooltip::after {
    position: absolute;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 9999;
    /* Hardware-accelerated entrance animation */
    transition: 
        opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), 
        transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), 
        visibility 0.3s linear;
}

/* The Arrow */
.bbt-inline-tooltip::before {
    content: '';
    border-style: solid;
    display: block;
    width: 0;
    height: 0;
}

/* The Bubble (Reads content from data-tooltip) */
.bbt-inline-tooltip::after {
    content: attr(data-tooltip);
    width: max-content;
    
    /* Fluid bounding: Prevents tooltip from overflowing small viewports */
    max-width: clamp(200px, 85vw, 320px);
    
    /* Fluid spacing and typography */
    padding: clamp(0.5rem, 3vw, 0.75rem) clamp(0.75rem, 4vw, 1.25rem);
    font-size: clamp(0.75rem, 2vw, 0.875rem);
    line-height: 1.5;
    font-family: inherit;
    font-weight: 500;
    text-align: left;
    
    background-color: var(--bbt-tt-bg);
    color: var(--bbt-tt-fg);
    border-radius: clamp(4px, 1vw, 8px);
    
    /* Brutalist sharp shadow */
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    
    /* Ensure long text wraps correctly */
    white-space: normal;
    word-wrap: break-word;
}

/* Add a subtle border for the light theme to ensure readability */
.bbt-inline-tooltip[data-theme="light"]::after {
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* ── 4. HOVER & FOCUS STATES ─────────────────────────────────────────────── */

.bbt-inline-tooltip:hover::before,
.bbt-inline-tooltip:hover::after,
.bbt-inline-tooltip:focus-within::before,
.bbt-inline-tooltip:focus-within::after {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ── 5. POSITIONS (With directional slide-in animations) ─────────────────── */

/* --- TOP (Default/Free) --- */
.bbt-inline-tooltip[data-position="top"]::after {
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(10px);
}
.bbt-inline-tooltip[data-position="top"]::before {
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    border-width: 6px 6px 0 6px;
    border-color: var(--bbt-tt-bg) transparent transparent transparent;
}
.bbt-inline-tooltip[data-position="top"]:hover::after,
.bbt-inline-tooltip[data-position="top"]:hover::before,
.bbt-inline-tooltip[data-position="top"]:focus-within::after,
.bbt-inline-tooltip[data-position="top"]:focus-within::before {
    transform: translateX(-50%) translateY(0);
}

/* --- BOTTOM (PRO) --- */
.bbt-inline-tooltip[data-position="bottom"]::after {
    top: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
}
.bbt-inline-tooltip[data-position="bottom"]::before {
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    border-width: 0 6px 6px 6px;
    border-color: transparent transparent var(--bbt-tt-bg) transparent;
}
.bbt-inline-tooltip[data-position="bottom"]:hover::after,
.bbt-inline-tooltip[data-position="bottom"]:hover::before,
.bbt-inline-tooltip[data-position="bottom"]:focus-within::after,
.bbt-inline-tooltip[data-position="bottom"]:focus-within::before {
    transform: translateX(-50%) translateY(0);
}

/* --- LEFT (PRO) --- */
.bbt-inline-tooltip[data-position="left"]::after {
    right: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) translateX(10px);
}
.bbt-inline-tooltip[data-position="left"]::before {
    right: 100%;
    top: 50%;
    transform: translateY(-50%) translateX(10px);
    border-width: 6px 0 6px 6px;
    border-color: transparent transparent transparent var(--bbt-tt-bg);
}
.bbt-inline-tooltip[data-position="left"]:hover::after,
.bbt-inline-tooltip[data-position="left"]:hover::before,
.bbt-inline-tooltip[data-position="left"]:focus-within::after,
.bbt-inline-tooltip[data-position="left"]:focus-within::before {
    transform: translateY(-50%) translateX(0);
}

/* --- RIGHT (PRO) --- */
.bbt-inline-tooltip[data-position="right"]::after {
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) translateX(-10px);
}
.bbt-inline-tooltip[data-position="right"]::before {
    left: 100%;
    top: 50%;
    transform: translateY(-50%) translateX(-10px);
    border-width: 6px 6px 6px 0;
    border-color: transparent var(--bbt-tt-bg) transparent transparent;
}
.bbt-inline-tooltip[data-position="right"]:hover::after,
.bbt-inline-tooltip[data-position="right"]:hover::before,
.bbt-inline-tooltip[data-position="right"]:focus-within::after,
.bbt-inline-tooltip[data-position="right"]:focus-within::before {
    transform: translateY(-50%) translateX(0);
}