/**
 * Furigana Generator Frontend Styles
 * @package FuriganaGenerator
 * @version 1.0.0
 */

/* Ruby (HTML5) Display Mode */
.furigana-ruby {
    ruby-align: center;
    ruby-position: over;
    line-height: 2.2;
}

.furigana-ruby ruby {
    display: ruby;
    ruby-align: center;
    ruby-position: over;
}

.furigana-ruby rt {
    display: ruby-text;
    font-size: 0.5em;
    line-height: 1;
    text-align: center;
    color: #666;
    font-weight: normal;
}

.furigana-rt {
    font-size: 0.5em !important;
    line-height: 1 !important;
    text-align: center !important;
    color: #666 !important;
    font-weight: normal !important;
}

/* Fallback for browsers that don't support ruby */
@supports not (display: ruby) {
    .furigana-ruby ruby {
        display: inline-block;
        text-align: center;
        vertical-align: text-bottom;
        margin: 0 0.1em;
        line-height: 1;
    }
    
    .furigana-ruby rt {
        display: block;
        font-size: 0.7em;
        line-height: 1.2;
        text-align: center;
        margin-bottom: 0.2em;
    }
}

/* Tooltip Display Mode */
.furigana-tooltip {
    position: relative;
    cursor: help;
    border-bottom: 1px dotted #999;
    text-decoration: none;
}

.furigana-tooltip:hover {
    color: #333;
}

.furigana-tooltip::after {
    content: attr(data-reading);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 1000;
    pointer-events: none;
}

.furigana-tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    border: 4px solid transparent;
    border-top-color: #333;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 1000;
}

.furigana-tooltip:hover::after,
.furigana-tooltip:hover::before {
    opacity: 1;
    visibility: visible;
}

/* Annotation Display Mode */
.furigana-annotations {
    margin-top: 10px;
    padding: 10px;
    background: #f9f9f9;
    border-left: 4px solid #ddd;
    font-size: 0.9em;
    color: #666;
}

.furigana-annotation-item {
    display: inline-block;
    margin-right: 15px;
    margin-bottom: 5px;
}

.furigana-annotation-item:last-child {
    margin-right: 0;
}

/* Responsive Design */
@media (max-width: 768px) {
    .furigana-ruby {
        line-height: 2.5;
    }
    
    .furigana-ruby rt {
        font-size: 0.6em;
    }
    
    .furigana-tooltip::after {
        font-size: 14px;
        padding: 6px 10px;
    }
    
    .furigana-annotations {
        font-size: 0.85em;
    }
}

@media (max-width: 480px) {
    .furigana-ruby {
        line-height: 2.8;
    }
    
    .furigana-ruby rt {
        font-size: 0.65em;
    }
    
    .furigana-annotations {
        padding: 8px;
        margin-top: 8px;
    }
    
    .furigana-annotation-item {
        display: block;
        margin-right: 0;
        margin-bottom: 8px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .furigana-ruby rt {
        color: #aaa;
    }
    
    .furigana-tooltip {
        border-bottom-color: #666;
    }
    
    .furigana-tooltip:hover {
        color: #eee;
    }
    
    .furigana-tooltip::after {
        background: #eee;
        color: #333;
    }
    
    .furigana-tooltip::before {
        border-top-color: #eee;
    }
    
    .furigana-annotations {
        background: #2a2a2a;
        border-left-color: #555;
        color: #ccc;
    }
}

/* Print Styles */
@media print {
    .furigana-tooltip {
        border-bottom: none;
    }
    
    .furigana-tooltip::after,
    .furigana-tooltip::before {
        display: none;
    }
    
    .furigana-ruby {
        line-height: 2;
    }
    
    .furigana-ruby rt {
        color: #000;
    }
    
    .furigana-annotations {
        background: none;
        border: 1px solid #ccc;
        color: #000;
    }
}

/* Accessibility */
.furigana-tooltip[aria-label]::after {
    content: attr(aria-label);
}

@media (prefers-reduced-motion: reduce) {
    .furigana-tooltip::after,
    .furigana-tooltip::before {
        transition: none;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .furigana-ruby rt {
        color: #000;
        font-weight: bold;
    }
    
    .furigana-tooltip {
        border-bottom: 2px solid #000;
    }
    
    .furigana-tooltip::after {
        background: #000;
        color: #fff;
        border: 2px solid #fff;
    }
    
    .furigana-annotations {
        background: #fff;
        border: 2px solid #000;
        color: #000;
    }
}

/* Text Selection */
.furigana-ruby rt::selection {
    background: rgba(0, 123, 255, 0.3);
}

.furigana-ruby rt::-moz-selection {
    background: rgba(0, 123, 255, 0.3);
}

/* Custom Properties for Theme Integration */
:root {
    --furigana-rt-color: #666;
    --furigana-rt-size: 0.5em;
    --furigana-tooltip-bg: #333;
    --furigana-tooltip-color: #fff;
    --furigana-annotation-bg: #f9f9f9;
    --furigana-annotation-border: #ddd;
}

[data-theme="dark"] {
    --furigana-rt-color: #aaa;
    --furigana-tooltip-bg: #eee;
    --furigana-tooltip-color: #333;
    --furigana-annotation-bg: #2a2a2a;
    --furigana-annotation-border: #555;
}

/* Using custom properties */
.furigana-ruby rt {
    color: var(--furigana-rt-color);
    font-size: var(--furigana-rt-size);
}

.furigana-tooltip::after {
    background: var(--furigana-tooltip-bg);
    color: var(--furigana-tooltip-color);
}

.furigana-tooltip::before {
    border-top-color: var(--furigana-tooltip-bg);
}

.furigana-annotations {
    background: var(--furigana-annotation-bg);
    border-left-color: var(--furigana-annotation-border);
}