:root {
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --text-main: #000000;
    --text-sub: #000000;
    --accent: #a63737;
    --btn-bg: rgba(255, 255, 255, 0.9);
    --btn-text: #333333;
    --modal-bg: #ffffff;
    --modal-text: #555555;
}

body.dark-mode {
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-main: #e0e0e0;
    --text-sub: #b0b0b0;
    --accent: #ff6b6b;
    --btn-bg: rgba(45, 45, 45, 0.9);
    --btn-text: #f0f0f0;
    --modal-bg: #2d2d2d;
    --modal-text: #cccccc;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Noto Serif SC', serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    transition: background-color 0.5s, color 0.5s;
    -webkit-font-smoothing: antialiased;
}

/* 右上角控制按钮 */
.controls {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 12px;
    z-index: 100;
}

.btn {
    background: var(--btn-bg);
    backdrop-filter: blur(5px);
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'Noto Serif SC', serif;
    color: var(--btn-text);
    text-transform: uppercase;
}

.btn:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.12); }
.btn-icon { font-size: 1.1rem; }

/* 语言选择器特有样式 */
.lang-selector {
    padding-right: 8px;
}
.lang-selector select {
    background: transparent;
    border: none;
    color: var(--btn-text);
    font-family: 'Noto Serif SC', serif;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    padding-right: 4px;
}

/* 主卡片 */
.card-container {
    width: 100%;
    max-width: 1000px;
    background: var(--card-bg);
    border-radius: 0px;
    box-shadow: 0 30px 60px rgba(0,0,0,0.1);
    display: flex;
    overflow: hidden;
    position: relative;
    min-height: 650px;
    transition: transform 0.3s;
    aspect-ratio: 16 / 10; /* 保持一定的长宽比 */
}

/* 左侧视觉区 */
.visual-side {
    flex: 1;
    background-color: #eee;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 10px;
    transition: background-color 0.6s ease;
    background-size: cover;
    background-position: center;
}

.color-codes {
    z-index: 2;
    position: absolute;
    bottom: 30px;
    left: 30px;
    display: flex;
    flex-direction: row;
    gap: 15px;
    align-items: flex-end;
}

/* 
   核心修复：放弃不稳定的 writing-mode，改用高兼容性的布局方式 
   确保截图与网页显示 100% 一致
*/
.date-vertical, .tradition-label {
    display: block;
    width: 1.2em; /* 限制宽度强制汉字换行，实现物理竖排 */
    word-break: break-all;
    line-height: 1.4;
    text-align: center;
}

.date-vertical {
    position: absolute;
    bottom: 60px;
    left: 30px;
    font-size: 0.7rem;
    opacity: 0.8;
    font-family: 'Noto Serif SC', serif;
}

.tradition-label {
    position: absolute;
    top: 30px;
    left: 30px;
    font-size: 0.7rem;
    opacity: 0.8;
}

.color-codes {
    position: absolute;
    bottom: 30px;
    left: 30px;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
    font-family: 'Courier New', monospace;
}

.hex-code {
    font-size: 0.7rem;
    opacity: 0.8;
    letter-spacing: 1px;
}

.pinyin {
    font-size: 0.7rem;
    color: var(--text-sub);
    font-weight: 300;
    letter-spacing: 1px;
}

.color-name {
    font-size: 4rem;
    font-weight: 200;
    margin: 0;
    letter-spacing: 4px;
    line-height: 1;
    /* 汉字竖排：限制宽度 */
    width: 1em;
    display: block;
    text-align: center;
}

/* 右侧内容区 */
.content-side {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--card-bg);
    position: relative;
    transition: background-color 0.8s ease-in-out;
    overflow: hidden; /* 防止溢出 */
}

/* 色阶网格布局 */
.shades-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr); /* 一行5个 */
    grid-template-rows: repeat(7, 1fr);    /* 7行 */
    gap: 0; /* 无间隙 */
    width: 100%;
    height: 100%;
}

.shade-box {
    width: 100%;
    height: 100%;
    transition: transform 0.2s, z-index 0.2s;
    cursor: pointer;
    position: relative;
}

.shade-box:hover {
    transform: scale(1.05);
    z-index: 10;
    box-shadow: 0 0 20px rgba(0,0,0,0.2);
}

.shade-box::after {
    content: attr(data-hex);
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.65rem;
    color: #666;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    font-family: monospace;
}

.shade-box:hover::after {
    opacity: 1;
}

.content-side > * {
    position: relative;
    z-index: 2;
}

.date-info {
    font-size: 0.85rem;
    color: #888;
    letter-spacing: 3px;
    margin-bottom: 30px;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 15px;
    display: inline-block;
    width: 100%;
}

/* 颜色标题区域 */
.header-group {
    cursor: pointer;
    transition: opacity 0.3s;
    position: relative;
}
.header-group:hover { opacity: 0.7; }

.click-hint {
    font-size: 0.75rem;
    color: var(--accent);
    margin-bottom: 5px;
    opacity: 0;
    transform: translateY(5px);
    transition: all 0.3s;
    font-weight: bold;
}
.header-group:hover .click-hint { opacity: 1; transform: translateY(0); }

/* 诗词展示 */
.poem-container {
    flex-grow: 1;
    display: flex;
    flex-direction: row-reverse;
    justify-content: center;
    align-items: flex-start;
    gap: 30px;
    margin: 20px 0;
    min-height: 200px;
}

.poem-line {
    writing-mode: vertical-rl;
    font-size: 1.4rem;
    line-height: 1.8;
    letter-spacing: 6px;
    font-family: 'Ma Shan Zheng', cursive;
    color: #333;
    text-shadow: 1px 1px 0px rgba(0,0,0,0.05);
}

.poem-author {
    writing-mode: vertical-rl;
    font-size: 0.9rem;
    color: #999;
    margin-top: 40px;
    letter-spacing: 2px;
}

.footer-mark {
    margin-top: auto;
    text-align: center;
    font-size: 0.8rem;
    color: #ccc;
    letter-spacing: 4px;
}

/* 弹窗 Modal */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(8px);
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.modal.active { opacity: 1; pointer-events: all; }

.modal-card {
    background: var(--modal-bg);
    width: 90%;
    max-width: 550px;
    border-radius: 0px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    transform: translateY(30px);
    transition: transform 0.3s, background-color 0.3s;
    max-height: 85vh;
    overflow-y: auto;
    color: var(--text-main);
}
.modal.active .modal-card { transform: translateY(0); }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    border-bottom: 1px solid rgba(128, 128, 128, 0.2);
    padding-bottom: 15px;
}
.modal-title { font-size: 1.4rem; font-weight: bold; }
.modal-close { font-size: 1.8rem; cursor: pointer; color: #999; line-height: 1; }
.modal-close:hover { color: var(--text-main); }

.story-block {
    line-height: 1.8;
    color: var(--modal-text);
    margin-bottom: 35px;
    text-align: justify;
}

.palette-title { font-size: 0.9rem; font-weight: bold; margin-bottom: 10px; color: var(--text-main); opacity: 0.8; }

.palette-group {
    margin-bottom: 25px;
}

.palette-row {
    display: flex;
    gap: 10px;
    margin-bottom: 5px;
}

.swatch {
    flex: 1;
    height: 60px;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 0.7rem;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    transition: transform 0.2s;
    cursor: pointer;
    position: relative;
}

.swatch:hover {
    transform: scale(1.05);
    z-index: 1;
}

.swatch span {
    font-family: monospace;
    font-size: 0.65rem;
}

/* 分享网格 */
.share-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-top: 20px;
}

.share-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.3s;
    padding: 15px;
    border-radius: 12px;
    background: rgba(128, 128, 128, 0.05);
}

.share-item:hover {
    background: rgba(128, 128, 128, 0.1);
    transform: translateY(-3px);
}

.share-icon {
    font-size: 1.5rem;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: white;
}

.share-item span {
    font-size: 0.8rem;
    color: var(--modal-text);
}

/* 品牌色 */
.bg-facebook { background-color: #1877F2; }
.bg-twitter { background-color: #1DA1F2; }
.bg-linkedin { background-color: #0A66C2; }
.bg-pinterest { background-color: #E60023; }
.bg-weibo { background-color: #E6162D; }
.bg-copy { background-color: #4CAF50; }

/* 页脚 Copyright */
.footer {
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-sub);
    opacity: 0.5;
    font-family: 'Courier New', monospace;
    pointer-events: none;
    z-index: 10;
}

/* 移动端适配 */
@media (max-width: 768px) {
    body { align-items: center; padding: 15px; overflow-x: hidden; }
    
    .controls { 
        top: auto; 
        bottom: 40px; 
        right: 0;
        left: 0;
        justify-content: center;
        padding: 0 10px;
        width: 100%;
        gap: 6px;
    }
    
    .footer {
        bottom: 10px;
        font-size: 0.65rem;
        opacity: 0.4;
    }
    
    .btn {
        padding: 8px 12px;
        font-size: 0.85rem;
        border-radius: 15px;
    }
    .btn span:not(.btn-icon) { display: none; } /* 移动端只显示图标，节省空间 */
    
    .card-container { 
        flex-direction: column; 
        height: auto;
        min-height: 85vh; 
        aspect-ratio: auto;
        margin-bottom: 80px; /* 为底部按钮留出空间 */
    }
    
    .visual-side { 
        height: 40vh; 
        flex: none; 
        padding: 10px;
        overflow: hidden;
    }

    .color-name { font-size: 3.5rem; }
    
    .content-side { 
        height: 45vh;
        flex: none;
    }

    .shades-grid {
        grid-template-columns: repeat(5, 1fr);
        grid-template-rows: repeat(7, 1fr);
    }

    .color-codes {
        bottom: 20px;
        left: 20px;
        gap: 10px;
    }

    .tradition-label {
        top: 20px;
        left: 20px;
        font-size: 0.75rem;
    }
    .date-vertical {
        left:20px;
        bottom: 40px;
    }
    /* 弹窗适配 */
    .modal-card {
        padding: 25px 20px;
        width: 95%;
    }

    .share-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .share-item {
        padding: 10px 5px;
    }
}