:root {
    --bg-color: #f5f0e1;
    --card-bg: #ffffff;
    --primary-color: #c0392b;
    --highlight-color: #e6b422;
    --success-color: #27ae60;
    --btn-main: #8b5e3c;
    --text-main: #3e2723;
    --text-sec: #8d6e63;
    --border-color: #d4c5a9;
    --shadow-block: 0 2px 6px rgba(0,0,0,0.08);
    --shadow-card: 0 4px 20px rgba(0,0,0,0.06);
    --font-base: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

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

html, body {
    width: 100%;
    min-height: 100%;
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-base);
    font-size: 16px;
}

/* Base App Layout */
body {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 100vh;
    margin: 0 auto;
    position: relative;
    background-color: var(--bg-color);
}

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

/* Top Nav */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: calc(48px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 16px 0;
    background-color: var(--card-bg);
    flex-shrink: 0;
    z-index: 100;
    width: 100%;
    position: sticky;
    top: 0;
    box-shadow: var(--shadow-card);
}
.nav-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
}
.nav-right {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-main);
    text-decoration: none; /* 清除 a 标签默认下划线 */
}
.nav-right { justify-content: flex-end; }

/* PC 顶栏（默认隐藏） */
.pc-nav { display: none; }

/* Main Content Area */
.main-content {
    flex: 1 0 auto;
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    margin: 0 auto;
    min-height: calc(100vh - 48px - env(safe-area-inset-top)); /* 确保至少撑满一屏高度减去头部 */
}

/* Views */
.view-section {
    display: none;
    flex-direction: column;
    width: 100%;
    padding-bottom: 20px;
}
.view-section.active {
    display: flex;
}

/* Generator View Layout adjustments */
#view-generator {
    padding: 16px;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: var(--shadow-card);
    padding: 20px;
    margin-bottom: 16px;
}

/* AI Input */
.ai-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.input-group input {
    width: 100%;
    height: 52px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0 16px;
    font-size: 18px;
    font-family: inherit;
    color: var(--text-main);
    outline: none;
    transition: border-color 0.3s;
}
.input-group input::placeholder {
    color: #bcaaa4;
}
.input-group input:focus {
    border-color: var(--highlight-color);
}
.quick-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.tag {
    background: var(--bg-color);
    color: var(--text-sec);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}
.tag:active, .tag.active {
    background: var(--btn-main);
    color: #fff;
}

/* Palette Preview */
.palette-preview-container {
    margin-top: 8px;
}
.palette-preview {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.color-block {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s;
    animation: fadeIn 0.4s ease-out;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.color-block.flash {
    animation: flash 0.3s ease-in-out;
}
@keyframes flash {
    0% { opacity: 1; }
    50% { opacity: 0.5; transform: scale(0.95); }
    100% { opacity: 1; transform: scale(1); }
}
.color-rect {
    width: 100%;
    height: 80px;
    border-radius: 8px;
    box-shadow: var(--shadow-block);
    margin-bottom: 8px;
}
.color-hex {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-sec);
    text-transform: uppercase;
}

/* Buttons */
.btn {
    border: none;
    background: none;
    font-family: inherit;
    cursor: pointer;
    outline: none;
}
.btn-text {
    width: 100%;
    padding: 12px 0;
    color: var(--btn-main);
    font-size: 16px;
    font-weight: 500;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: background 0.2s;
}
.btn-text:active {
    background: var(--bg-color);
}
.btn-primary {
    background: var(--btn-main);
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 16px;
}
.btn-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-sec);
}
.btn-icon span {
    font-size: 12px;
}
.btn-icon.active {
    color: var(--highlight-color);
}

/* Palette Info */
.palette-info {
    text-align: center;
    margin-bottom: 24px;
}
.score {
    font-size: 16px;
    font-weight: 600;
    color: var(--highlight-color);
    margin-bottom: 8px;
}
.desc {
    font-size: 14px;
    color: var(--text-sec);
    margin-bottom: 16px;
    line-height: 1.5;
}
.actions {
    display: flex;
    justify-content: center;
    gap: 24px;
}

/* Manual Tuning */
.manual-card {
    transition: all 0.3s;
    overflow: hidden;
}
.manual-card.collapsed {
    display: none;
}
.manual-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.manual-header h3 {
    font-size: 18px;
    font-weight: 600;
}
.btn-close {
    font-size: 24px;
    color: var(--text-sec);
    background: none;
    border: none;
}
.manual-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
#color-wheel {
    border-radius: 50%;
    cursor: crosshair;
}
.color-inputs {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}
.current-color-preview {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    box-shadow: var(--shadow-block);
    flex-shrink: 0;
}
#manual-hex {
    flex: 1;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0 12px;
    font-family: var(--font-mono);
    font-size: 14px;
    text-transform: uppercase;
}

/* Ad Slot */
.ad-slot {
    display: none;
    min-height: 60px;
    max-height: 60px;
    margin: 10px 0;
    color: #999;
    font-size: 14px;
    border-radius: 8px;
    border: 1px dashed #ccc;
    background: #fafafa;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.ad-slot:not(:empty) {
    display: flex;
    flex: 0 0 60px;
}

/* Recommended Section (Mini Library) */
.recommended-section {
    padding: 24px 0;
    margin-bottom: 24px;
}
.recommended-section .palette-grid {
    padding: 0;
}
.recommended-section h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* 正文说明区块 */
.site-intro {
    text-align: center;
    margin: 40px 0 20px;
    padding-top: 40px;
    border-top: 1px dashed rgba(212, 197, 169, 0.4);
}
.site-intro h1 {
    font-size: 22px;
    color: var(--text-main);
    margin-bottom: 8px;
    font-weight: 600;
}
.site-intro h2 {
    font-size: 14px;
    color: var(--text-sec);
    font-weight: normal;
}

.content-block {
    margin: 0 0 40px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.content-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.04);
    text-align: left;
    border: 1px solid rgba(212, 197, 169, 0.3);
}

.content-card h3 {
    font-size: 18px;
    color: var(--text-main);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px dashed rgba(212, 197, 169, 0.5);
    display: flex;
    align-items: center;
    gap: 8px;
}

.content-card p {
    font-size: 15px;
    color: var(--text-sec);
    line-height: 1.8;
    margin-bottom: 12px;
}

.content-card ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.content-card li {
    font-size: 14px;
    color: var(--text-sec);
    line-height: 1.7;
    padding-left: 20px;
    position: relative;
    background: #fdfaf5;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid rgba(212, 197, 169, 0.2);
}

.content-card li strong {
    color: var(--primary-color);
    display: block;
    margin-bottom: 4px;
    font-size: 15px;
}

.content-card dl {
    margin: 0;
}

.content-card dt {
    font-weight: 600;
    color: var(--text-main);
    font-size: 15px;
    margin-bottom: 8px;
    margin-top: 16px;
    position: relative;
    padding-left: 24px;
}
.content-card dt::before {
    content: "Q";
    position: absolute;
    left: 0;
    color: var(--highlight-color);
    font-weight: bold;
}

.content-card dd {
    margin: 0 0 0 24px;
    font-size: 14px;
    color: var(--text-sec);
    line-height: 1.6;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(212, 197, 169, 0.2);
}
.content-card dd:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

/* Library View */
.library-header {
    padding: 16px;
    background: var(--card-bg);
    margin-bottom: 16px;
}
.library-header h2 {
    font-size: 20px;
    margin-bottom: 12px;
}
.filter-tags {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
}
.filter-tags::-webkit-scrollbar {
    display: none;
}

/* Palette Grid */
.palette-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 0 16px;
}
.palette-item {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow-card);
    cursor: pointer;
}
.palette-item-colors {
    display: flex;
    height: 40px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 12px;
}
.palette-item-color {
    flex: 1;
}
.palette-item-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.palette-item-name {
    font-size: 16px;
    font-weight: 500;
}
.palette-item-desc {
    font-size: 13px;
    color: var(--text-sec);
    margin-top: 4px;
}

/* Empty State */
.empty-state {
    text-align: center;
    color: var(--text-sec);
    padding: 40px 0;
    font-size: 16px;
}

/* Bottom TabBar */
.bottom-tabbar {
    display: flex;
    background: var(--card-bg);
    height: calc(50px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid rgba(0,0,0,0.05);
    order: 999;
    flex-shrink: 0;
    width: 100%;
    position: sticky;
    bottom: 0;
    z-index: 100;
}
.tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-sec);
    cursor: pointer;
}
.tab-item.active {
    color: var(--btn-main);
}
.tab-item span {
    font-size: 12px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: calc(70px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 1000;
}
.toast.show {
    opacity: 1;
}

/* Site Footer */
.site-footer {
    display: block;
    background: var(--card-bg);
    padding: 24px 16px calc(24px + 50px + env(safe-area-inset-bottom)); /* 移动端增加底部内边距，防遮挡 */
    text-align: center;
    border-top: 1px solid rgba(0,0,0,0.05);
    order: 1000;
    flex-shrink: 0;
    width: 100%;
    margin-top: auto; /* Push to bottom when content is short */
}
.site-footer p {
    font-size: 13px;
    color: var(--text-sec);
    margin-bottom: 8px;
}
.site-footer a {
    color: var(--text-sec);
    text-decoration: none;
}
.site-footer a:hover {
    color: var(--btn-main);
}

/* PC Specific Layout */
@media (min-width: 880px) {
    .main-content {
        max-width: 880px;
        margin: 0 auto;
    }

    .top-nav {
        display: none;
    }

    .bottom-tabbar {
        display: none;
    }

    .pc-nav {
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
        padding: 14px 24px;
        background: rgba(255, 255, 255, 0.96);
        border-bottom: 1px solid rgba(212, 197, 169, 0.45);
        flex-shrink: 0;
        box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6), 0 0 0 100vmax rgba(255, 255, 255, 0.96);
        clip-path: inset(0 -100vmax);
    }

    .pc-nav-brand {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        font-size: 18px;
        font-weight: 600;
        color: var(--text-main);
        margin-right: auto;
        text-decoration: none;
    }

    .pc-nav-brand:hover {
        text-decoration: none;
        opacity: 0.9;
    }

    .pc-nav-link {
        font-size: 16px;
        color: var(--text-sec);
        padding: 8px 14px;
        border-radius: 10px;
        transition: background 0.15s, color 0.15s;
        text-decoration: none;
    }

    .pc-nav-link.active {
        color: var(--btn-main);
        font-weight: 600;
    }

    .pc-nav-link:hover {
        background: rgba(139, 94, 60, 0.06);
    }

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

    .content-head h1 {
        font-size: 32px;
    }

    .content-block {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    
    /* Show Site Footer normally on PC without extra padding */
    .site-footer {
        padding: 24px 16px;
    }
    
    .view-section {
        padding-bottom: 40px;
    }
}
