/*
 * style.css - Optimized Version
 * Author: Haoran Xie Personal Homepage Stylesheet
 * Fixes:
 *   - Fixed font encoding issues
 *   - Removed IE6/IE7 compatibility hacks
 *   - Added responsive design
 *   - Unified color management with CSS variables
 *   - Replaced px units with rem
 *   - Added modern transition animations
 *   - Fixed selector syntax errors
 *   - Merged duplicate selectors
 *   - Added profile card, pub-row, topic-section styles
 *   - Reduced line-height for compact display
 */

/* =============================================
   CSS Variables
   ============================================= */
:root {
    /* Colors */
    --color-text: #5D5D5D;
    --color-text-light: #888888;
    --color-text-dark: #333333;
    --color-primary: #337ED2;
    --color-primary-light: #56AEE1;
    --color-primary-dark: #2a6ab8;
    --color-border: #cccccc;
    --color-border-light: #e1e3e8;
    --color-bg-light: #EFEFEF;
    --color-bg-white: #ffffff;
    --color-highlight-pink: #ffb6c1;
    --color-highlight-lavender: #e6e6fa;
    --color-highlight-blue: #f0f8ff;
    --color-award: #ff0000;

    /* Typography */
    --font-family: Verdana, Arial, "Hiragino Kaku Gothic Pro W3", "MS PGothic", sans-serif;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-xxl: 3rem;

    /* Border Radius */
    --border-radius: 4px;
    --border-radius-lg: 10px;

    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;

    /* Layout */
    --max-width: 950px;
}

/* =============================================
   Base Reset
   ============================================= */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 14px;
    padding: 0;
    margin: 0;
    -webkit-text-size-adjust: 100%;
}

body {
    font-size: 0.8125rem; /* 13px */
    line-height: 1.4;
    text-align: center;
    color: var(--color-text);
    margin: 0 auto;
    padding: 0;
    font-family: var(--font-family);
    background-color: var(--color-bg-white);
}

/* =============================================
   Typography
   ============================================= */
p {
    line-height: 1.4;
    text-align: justify;
    text-justify: distribute;
    margin-bottom: var(--spacing-md);
}

li {
    line-height: 1.4;
}

p, ul, ol, dl, table, pre {
    font-size: 100%;
    letter-spacing: 0.00em;
}

img {
    border: none;
    vertical-align: bottom;
    max-width: 100%;
    height: auto;
}

/* =============================================
   Link Styles
   ============================================= */
#out a {
    text-decoration: none;
    color: var(--color-primary);
    border-bottom: 1px solid transparent;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

#out a:visited {
    color: var(--color-primary-light);
    border-bottom: 1px solid var(--color-primary-light);
}

#out a:hover,
#out a:focus {
    color: var(--color-primary-dark);
    border-bottom: 1px solid var(--color-primary);
}

/* =============================================
   Main Layout
   ============================================= */
#out {
    margin: 20px auto 10px auto;
    text-align: left;
    max-width: var(--max-width);
    width: 100%;
    border: 1px solid var(--color-border);
    background-color: var(--color-bg-white);
}

#head {
    letter-spacing: 0.1em;
    text-align: left;
    margin: 0 auto 20px auto;
    padding: 25px;
    border-bottom: 1px solid var(--color-border);
    background-color: var(--color-bg-light);
}

#menu {
    text-align: right;
    font-size: 0.875rem;
    color: var(--color-border);
}

#main {
    letter-spacing: 0.1em;
    font-size: 1rem;
    margin: 0 var(--spacing-xxl);
    line-height: 1.4;
    padding: var(--spacing-md);
}

#main ul {
    margin: 0 5px 5px 0;
    padding: var(--spacing-xs);
    list-style: square;
}

#main li {
    margin: 0 0 0 2.5em;
    letter-spacing: 0.02em;
    padding: 0 0 0.3em 0.1em;
}

#footer {
    margin: var(--spacing-xxl) 0 0 0;
    padding: var(--spacing-xl) 0;
    border-top: 1px solid var(--color-border);
    background-color: var(--color-bg-light);
    line-height: 1.4;
    text-align: center;
    letter-spacing: 0.1em;
    font-size: 0.875rem;
    color: var(--color-text-light);
}

/* =============================================
   Heading Styles
   ============================================= */
h1 {
    font-size: 1.6rem;
    font-weight: normal;
    margin: 0 0 5px 0;
    padding: 0;
    color: var(--color-text-dark);
}

h2 {
    font-size: 1rem;
    font-weight: normal;
    margin: 1em 0.5em 0.5em 0;
    padding: 0 0 0 var(--spacing-sm);
    border-left: 3px solid var(--color-primary);
    color: var(--color-text-dark);
}

h3 {
    font-size: 1.125rem;
    font-weight: bold;
    margin: 1.5em 0 0.5em 0;
    padding: var(--spacing-sm) var(--spacing-md);
    background-color: var(--color-bg-light);
    border-radius: var(--border-radius);
    color: var(--color-text-dark);
}

h4 {
    font-size: 1.25rem;
    font-weight: normal;
    margin: 0.5em 0;
    padding: 0 0 1px 1px;
}

/* =============================================
   Navigation
   ============================================= */
nav {
    font-weight: normal;
}

nav a {
    padding: var(--spacing-xs) var(--spacing-sm);
    transition: background-color var(--transition-fast);
    border-radius: var(--border-radius);
}

nav a:hover {
    background-color: var(--color-bg-light);
}

/* Compact Navigation */
.nav-compact {
    font-size: 0.9em;
    white-space: nowrap;
    padding: 5px 0;
    margin: 0;
    background: none;
}

.nav-compact a {
    padding: 2px 5px;
}

/* =============================================
   Profile Card
   ============================================= */
.profile-card {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    padding: 15px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: var(--border-radius-lg);
    margin-bottom: 20px;
}

.profile-photo {
    flex-shrink: 0;
}

.profile-photo img {
    width: 160px;
    height: auto;
    border-radius: var(--border-radius-lg);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

.profile-info {
    flex: 1;
}

.profile-name {
    font-size: 1.4em;
    font-weight: bold;
    color: var(--color-text-dark);
    margin: 0 0 5px 0;
}

.profile-title {
    font-size: 0.95em;
    color: #555;
    margin: 0 0 8px 0;
    line-height: 1.4;
}

.profile-affiliation {
    font-size: 0.85em;
    color: #666;
    line-height: 1.4;
}

.profile-contact {
    font-size: 0.85em;
    color: #666;
    margin-top: 8px;
}

.profile-links {
    margin-top: 10px;
}

.profile-links a {
    margin-right: 5px;
}

.profile-links img {
    height: 26px;
    transition: transform var(--transition-fast);
}

.profile-links a:hover img {
    transform: translateY(-2px);
}

/* =============================================
   Topic Section & Publication Row
   ============================================= */
.topic-section {
    margin-bottom: var(--spacing-lg);
}

.topic-section h4 {
    margin: 0;
    padding: 8px 12px;
    font-size: 0.9em;
    font-weight: bold;
}

.pub-row {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    padding: 15px;
    border-bottom: 1px solid var(--color-border-light);
}

.pub-row:last-child {
    border-bottom: none;
}

.pub-row img {
    width: 180px;
    flex-shrink: 0;
    border-radius: var(--border-radius);
}

.pub-info {
    font-size: 0.85em;
    line-height: 1.5;
}

.pub-info strong {
    color: var(--color-text-dark);
}

/* =============================================
   Table Styles
   ============================================= */
table {
    border-collapse: collapse;
    width: 100%;
}

.table th,
.table td {
    padding: var(--spacing-sm);
    vertical-align: top;
}

.table-hover tbody tr:hover {
    background-color: var(--color-bg-light);
}

.text-right {
    text-align: right;
}

/* Project display tables */
#main table[border="0"] {
    width: 100%;
}

#main table[border="0"] td {
    padding: var(--spacing-sm);
    vertical-align: top;
}

/* Project Table */
.project-table {
    width: 100%;
    border-collapse: collapse;
}

.project-table td {
    padding: var(--spacing-sm);
    vertical-align: top;
}

/* =============================================
   Project Section Background Colors
   ============================================= */
td[bgcolor="#ffb6c1"],
.section-pink {
    background-color: var(--color-highlight-pink);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius);
    margin: var(--spacing-md) 0;
}

td[bgcolor="#e6e6fa"],
.section-lavender {
    background-color: var(--color-highlight-lavender);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius);
    margin: var(--spacing-md) 0;
}

td[bgcolor="#f0f8ff"],
.section-blue {
    background-color: var(--color-highlight-blue);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius);
    margin: var(--spacing-md) 0;
}

/* =============================================
   Project Image Styles
   ============================================= */
#main table img {
    border-radius: var(--border-radius);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

#main table img:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* =============================================
   Award Highlight
   ============================================= */
span[style*="color: #ff0000"],
.award-text {
    color: var(--color-award) !important;
    font-weight: bold;
}

/* =============================================
   Utility Classes
   ============================================= */
.hidden {
    display: none;
}

.unhidden {
    display: block;
}

.text-small {
    font-size: 0.875rem;
}

.text-smaller {
    font-size: 0.85em;
    line-height: 1.3;
}

.text-large {
    font-size: 1.1em;
}

/* Two-column layout */
#col1 {
    width: 49%;
    float: left;
}

#col2 {
    width: 49%;
    float: right;
}

.clearfix::after {
    content: "";
    display: table;
    clear: both;
}

/* Textarea */
.textarea-large {
    width: 95%;
    height: 200px;
    font-size: 1em;
    border: solid 2px var(--color-border-light);
    border-radius: var(--border-radius);
    padding: var(--spacing-sm);
    font-family: var(--font-family);
    resize: vertical;
}

.textarea-large:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(51, 126, 210, 0.1);
}

/* =============================================
   Grants & Media Lists
   ============================================= */
ol.grants-list,
ol.media-list {
    line-height: 1.3;
}

ol.grants-list li,
ol.media-list li {
    margin-bottom: 4px;
    padding-bottom: 4px;
}

/* Research Topics List */
.research-topics {
    font-size: 0.85em;
    line-height: 1.4;
}

.research-topics li {
    margin-bottom: 4px;
}

/* News List */
.news-list {
    line-height: 1.4;
}

.news-list li {
    margin-bottom: 4px;
}

/* =============================================
   Bio & Vision Sections
   ============================================= */
.bio-section {
    line-height: 1.4;
}

.vision-section {
    line-height: 1.4;
}

.vision-section img {
    margin-bottom: var(--spacing-sm);
}

/* =============================================
   Social Icons
   ============================================= */
#main a img[height="30"],
#main a img[height="20"] {
    transition: opacity var(--transition-fast), transform var(--transition-fast);
    vertical-align: middle;
    margin: 0 2px;
}

#main a:hover img[height="30"],
#main a:hover img[height="20"] {
    opacity: 0.8;
    transform: translateY(-2px);
}

/* =============================================
   Copyright
   ============================================= */
.copyright {
    font-size: 0.75rem;
    margin: 0 15px 0 0;
    padding: 10px 0 20px 0;
    text-align: right;
    color: var(--color-text-light);
    letter-spacing: 0.1em;
}

.copyright a:link,
.copyright a:visited,
.copyright a:hover {
    color: var(--color-text-light);
    border-bottom: none;
    text-decoration: none;
}

/* =============================================
   Contact Table
   ============================================= */
.table-condensed th,
.table-condensed td {
    padding: var(--spacing-xs) var(--spacing-sm);
}

/* =============================================
   Ordered/Unordered List Optimization
   ============================================= */
ol[reversed] {
    padding-left: 2.5em;
}

ol[reversed] li {
    margin-bottom: var(--spacing-xs);
}

/* =============================================
   Profile Photo
   ============================================= */
img[src*="xiehaoran"] {
    border-radius: var(--border-radius-lg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* =============================================
   Responsive Design
   ============================================= */

/* Tablet devices */
@media (max-width: 992px) {
    :root {
        --max-width: 100%;
    }

    #out {
        margin: 10px;
        border: none;
        box-shadow: none;
    }

    #main {
        margin: 0 var(--spacing-lg);
        font-size: 0.9375rem;
    }

    #main table td {
        display: block;
        width: 100% !important;
        text-align: center;
        margin-bottom: var(--spacing-md);
    }

    #main table td img {
        max-width: 250px;
        height: auto;
    }

    .pub-row {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .pub-row img {
        width: 100%;
        max-width: 250px;
    }

    .profile-card {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .profile-photo img {
        width: 140px;
    }
}

/* Mobile devices */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    #out {
        margin: 0;
        border: none;
    }

    #main {
        margin: 0 var(--spacing-md);
        padding: var(--spacing-sm);
    }

    h2 {
        font-size: 0.95rem;
    }

    h3 {
        font-size: 1rem;
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    nav {
        font-size: 0.875rem;
        line-height: 2;
    }

    nav a {
        display: inline-block;
        margin: var(--spacing-xs) 0;
    }

    .nav-compact {
        white-space: nowrap;
        overflow-x: auto;
        font-size: 0.82em;
        -webkit-overflow-scrolling: touch;
    }

    /* Two-column to single-column */
    #col1,
    #col2 {
        width: 100%;
        float: none;
    }

    /* Responsive tables */
    #main table,
    #main table tbody,
    #main table tr,
    #main table td {
        display: block;
        width: 100%;
    }

    #main table td {
        text-align: center;
        padding: var(--spacing-sm) 0;
    }

    #main table td img {
        width: 200px;
        max-width: 200px;
        height: auto;
    }

    /* List optimization */
    #main li {
        margin-left: 1.5em;
        font-size: 0.875rem;
    }

    ol[reversed] {
        padding-left: 1.5em;
    }

    /* Footer */
    #footer {
        padding: var(--spacing-lg) var(--spacing-md);
        font-size: 0.8rem;
    }

    /* Profile card mobile */
    .profile-photo img {
        width: 120px;
        max-width: 120px;
    }

    .profile-name {
        font-size: 1.2em;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    html {
        font-size: 13px;
    }

    #main {
        margin: 0 var(--spacing-sm);
    }

    h3 {
        font-size: 0.95rem;
    }

    nav a {
        padding: var(--spacing-xs);
        font-size: 0.8rem;
    }

    #main table td img {
        max-width: 200px;
    }

    .profile-photo img {
        width: 100px;
    }
}

/* =============================================
   Print Styles
   ============================================= */
@media print {
    #out {
        border: none;
        max-width: 100%;
    }

    #main a::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: var(--color-text-light);
    }

    #footer {
        background-color: transparent;
        border-top: 1px solid var(--color-border);
    }

    .hidden {
        display: none !important;
    }

    .profile-card {
        background: none;
        border: 1px solid var(--color-border);
    }
}

/* =============================================
   Dark Mode Support
   ============================================= */
@media (prefers-color-scheme: dark) {
    :root {
        --color-text: #e0e0e0;
        --color-text-light: #a0a0a0;
        --color-text-dark: #ffffff;
        --color-bg-light: #2a2a2a;
        --color-bg-white: #1a1a1a;
        --color-border: #444444;
        --color-border-light: #555555;
        --color-highlight-pink: #5c4045;
        --color-highlight-lavender: #454560;
        --color-highlight-blue: #3a4550;
    }

    img {
        opacity: 0.9;
    }

    img:hover {
        opacity: 1;
    }

    .profile-card {
        background: linear-gradient(135deg, #2a2a2a 0%, #333333 100%);
    }

    .profile-title,
    .profile-affiliation,
    .profile-contact {
        color: #aaa;
    }
}

/* =============================================
   Accessibility Enhancements
   ============================================= */

/* Focus visibility */
a:focus,
button:focus,
input:focus,
textarea:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

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

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --color-border: #000000;
        --color-text: #000000;
        --color-primary: #0000ff;
    }

    a {
        text-decoration: underline;
    }
}
