/* 
 * HKZMB Marathon 2026 Website Styles
 * WCAG 2.1 AA Compliant | Responsive Design | Bilingual Support
 */

/* Font Family Definitions */
:root {
    --font-chinese: 'Noto Sans TC', 'Microsoft JhengHei', '微軟正黑體', sans-serif;
    --font-english: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', monospace;
}

/* Base Typography */
body {
    font-family: var(--font-english);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Chinese Text Styling */
.chinese-text, 
[lang="zh-Hant"], 
[lang="zh-Hans"] {
    font-family: var(--font-chinese);
    line-height: 1.8; /* Increased line height for Chinese characters */
    letter-spacing: 0.02em;
}

/* WCAG Compliant Focus Styles */
:focus {
    outline: 3px solid #2563eb; /* blue-600 with good contrast */
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 3px solid #2563eb;
    outline-offset: 2px;
}

/* Skip Link Styles */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sr-only:focus {
    position: fixed;
    top: 1rem;
    left: 1rem;
    width: auto;
    height: auto;
    padding: 0.75rem 1.5rem;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    background: #1d4ed8; /* blue-700 */
    color: white;
    border-radius: 0.375rem;
    z-index: 9999;
    font-weight: 600;
}

/* High Contrast Mode Support */
@media (prefers-conduced-contrast: high) {
    :root {
        --text-color: #000000;
        --background-color: #ffffff;
    }
    
    body {
        color: var(--text-color);
        background-color: var(--background-color);
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Print Styles */
@media print {
    .no-print {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.5;
        color: #000000;
        background: #ffffff;
    }
    
    a {
        color: #000000;
        text-decoration: underline;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 90%;
    }
    
    .break-after {
        page-break-after: always;
    }
}

/* Custom Utility Classes */
.text-balance {
    text-wrap: balance;
}

.text-pretty {
    text-wrap: pretty;
}

/* Chinese Text Optimization */
.chinese-paragraph {
    text-align: justify;
    text-justify: inter-ideograph;
    hyphens: none;
}

/* Responsive Typography */
@media (max-width: 640px) {
    .chinese-text,
    [lang="zh-Hant"],
    [lang="zh-Hans"] {
        line-height: 1.9; /* Even more line height on mobile for readability */
    }
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: "";
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-right-color: transparent;
    animation: spin 0.75s linear infinite;
    margin-left: 0.5em;
    vertical-align: middle;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Custom Scrollbar (WCAG compliant) */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9; /* slate-100 */
    border-radius: 6px;
}

::-webkit-scrollbar-thumb {
    background: #94a3b8; /* slate-400 */
    border-radius: 6px;
    border: 3px solid #f1f5f9;
}

::-webkit-scrollbar-thumb:hover {
    background: #64748b; /* slate-500 */
}

/* Selection Color */
::selection {
    background-color: #3b82f6; /* blue-500 */
    color: #ffffff;
}

/* Image Loading Optimization */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Accessible Data Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

th {
    background-color: #f8fafc; /* slate-50 */
    font-weight: 600;
    text-align: left;
    padding: 0.75rem;
    border-bottom: 2px solid #e2e8f0; /* slate-200 */
}

td {
    padding: 0.75rem;
    border-bottom: 1px solid #e2e8f0; /* slate-200 */
}

tr:hover {
    background-color: #f1f5f9; /* slate-100 */
}

/* Accessible Form Controls */
input, select, textarea, button {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

input:disabled,
select:disabled,
textarea:disabled,
button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Required Field Indicator */
.required::after {
    content: " *";
    color: #dc2626; /* red-600 */
}

/* Tooltip Accessibility */
[data-tooltip] {
    position: relative;
}

[data-tooltip]:hover::before,
[data-tooltip]:focus::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem;
    background: #1f2937; /* gray-800 */
    color: #ffffff;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    white-space: nowrap;
    z-index: 50;
    margin-bottom: 0.5rem;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus::after {
    content: "";
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 0.5rem solid transparent;
    border-top-color: #1f2937; /* gray-800 */
    margin-bottom: -0.5rem;
}

/* High Contrast Focus for Interactive Elements */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.5); /* blue-600 with opacity */
}

/* Language Specific Styles */
[lang="en"] {
    font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
}

[lang="zh-Hant"] {
    font-feature-settings: "kern" 1, "liga" 1, "clig" 1, "calt" 1;
}

/* Performance Optimizations */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

/* Custom Container for Chinese Text */
.chinese-container {
    max-width: 65ch;
    margin-left: auto;
    margin-right: auto;
}

.english-container {
    max-width: 75ch;
    margin-left: auto;
    margin-right: auto;
}

/* Color Accessibility Overrides for High Contrast */
.high-contrast {
    --text-color: #000000 !important;
    --background-color: #ffffff !important;
    --border-color: #000000 !important;
}

.high-contrast * {
    color: var(--text-color) !important;
    background-color: var(--background-color) !important;
    border-color: var(--border-color) !important;
}

/* Responsive Spacing for Chinese Text */
@media (min-width: 768px) {
    .chinese-text-lg {
        font-size: 1.125rem; /* 18px */
        line-height: 1.9;
    }
}

/* Print-friendly link URLs */
@media print {
    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 90%;
        font-weight: normal;
    }
    
    a[href^="#"]::after {
        content: "";
    }
}

/* Loading Font Fallback */
.font-loading {
    font-family: system-ui, -apple-system, sans-serif;
}

.font-loaded {
    font-family: var(--font-chinese), system-ui, -apple-system, sans-serif;
}