/* ========== 全局变量 ========== */
:root {
    --primary: #3498db;
    --primary-dark: #2980b9;
    --primary-light: #d6eaf8;
    --text-dark: #2c3e50;
    --text-light: #666;
    --gray: #95a5a6;
    --border: #bdc3c7;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --transition: all 0.25s ease;
}

/* ========== 重置 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #f0f7ff, #e3f2fd);
    color: var(--text-dark);
    line-height: 1.6;
    padding: 0;
    min-height: 100vh;
}

/* ========== 图标 ========== */
.icon-palette-sm::before { content: "🎨"; margin-right: 6px; }
.icon-image::before { content: "🖼️"; margin-right: 6px; }
.icon-history::before { content: "🕗"; margin-right: 6px; }
.icon-swatches::before { content: "🔖"; margin-right: 6px; }
.upload-icon::before {
    content: "📤";
    font-size: 1rem;
    color: var(--primary);
    display: block;
    margin-bottom: 0.1rem;
}

/* ========== 布局 ========== */
header {
    text-align: center;
    padding: 1.2rem 1rem;
    background: white;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}
header h1 { font-size: 1.8rem; color: var(--primary); margin-bottom: 0.4rem; }
header p { color: var(--gray); font-size: 0.95rem; }

main {
    max-width: 1200px;
    margin: 0 auto;
}

/* ========== 标签页 ========== */
.tabs {
    display: flex;
    gap: 1px;
    background: #e0e0e0;
    border-radius: 0;
    overflow: hidden;
    margin-bottom: 0.8rem;
}
.tab-btn {
    flex: 1;
    padding: 0.8rem 1rem;
    background: white;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tab-btn:hover { background: #f8f9fa; }
.tab-btn.active { background: var(--primary); color: white; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ========== 新网格布局：左 3/4，右 1/4 ========== */
.layout-grid {
    display: flex;
    gap: 0.8rem;
    min-height: 0;
}
.main-controls {
    flex: 3;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-height: 0;
}
.side-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-width: 260px;
    max-width: 300px;
    min-height: 0;
}

/* ========== 通用控件 ========== */
.hue-slider-container {
    width: 100%;
}
.hue-slider {
    width: 100%;
    height: 12px;
    -webkit-appearance: none;
    background: linear-gradient(to right,
        #ff0000 0%, #ffff00 16.6%, #00ff00 33.3%,
        #00ffff 50%, #0000ff 66.6%, #ff00ff 83.3%, #ff0000 100%);
    border-radius: 2px;
    outline: none;
}
.hue-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
    cursor: pointer;
}

.canvas-container,
.image-preview-container {
    background: white;
    border-radius: 0;
    box-shadow: var(--shadow);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.canvas-container {
    position: relative;
}

#color-canvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 480 / 300;
    cursor: crosshair;
    border: 1px solid var(--border);
    border-radius: 0;
    background: white;
}

/* ========== 点击标记 ========== */
.click-marker-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.click-marker {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    background: rgba(0,0,0,0.5);
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
}
.click-marker.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* ========== 上传区域 ========== */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: 0;
    padding: 0.6rem;
    text-align: center;
    background: white;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.upload-area p {
    font-size: 0.95rem;
    color: var(--gray);
}

.upload-area:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}
#image-input { display: none; }

.image-preview-container { flex: 1; }
.image-preview {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: calc(300 / 480 * 100%);
    background: white;
    border: 1px solid var(--border);
    overflow: hidden;
    border-radius: 0;
    margin-bottom: 0.8rem;
}
#image-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    background:
        linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
        linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
        linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
}

.zoom-controls {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}
.zoom-controls button {
    width: 32px;
    height: 32px;
    border-radius: 0;
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: var(--transition);
}
.zoom-controls button:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

/* ========== 颜色结果显示 ========== */
.color-result {
    background: white;
    border-radius: 0;
    box-shadow: var(--shadow);
    padding: 1.2rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.color-swatch {
    width: 100%;
    height: 100px;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: 0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.color-values { flex: 1; }
.color-row {
    display: flex;
    align-items: center;
    margin-bottom: 0.8rem;
    gap: 0.6rem;
}
.color-row .label {
    flex: 0 0 50px;
    font-weight: 600;
    color: var(--gray);
    font-size: 0.95rem;
}
.color-row input {
    flex: 1;
    min-width: 0;
    flex-shrink: 1;
    padding: 0.45rem 0.7rem;
    border: 1px solid #ddd;
    border-radius: 0;
    background: #fafafa;
    font-family: Consolas, monospace;
    font-size: 0.95rem;
    outline: none;
    overflow: hidden;
    text-overflow: ellipsis;
}
.color-row .copy-single {
    flex: 0 0 32px;
    height: 32px;
    border: none;
    background: #f1f3f5;
    border-radius: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray);
    transition: var(--transition);
    font-size: 0.9rem;
}
.color-row .copy-single:hover {
    background: var(--primary);
    color: white;
}

/* ========== 历史记录 ========== */
.history-section {
    background: white;
    border-radius: 0;
    box-shadow: var(--shadow);
    padding: 1rem;
}
.history-section h3 {
    margin-bottom: 0.8rem;
    color: var(--text-dark);
    font-size: 1.15rem;
}
.history-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.history-item {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 0;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: var(--transition);
}
.history-item:hover {
    transform: scale(1.15);
    z-index: 2;
    box-shadow: 0 3px 6px rgba(0,0,0,0.15);
}

/* ========== 色卡网格 ========== */
.swatches-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); /* ✅ 自适应列，精准对齐 */
    gap: 0;
    padding: 0;
    background: white;
    border-radius: 0;
    box-shadow: var(--shadow);
    flex: 1;
    min-height: 0;
}

.swatch-item {
    aspect-ratio: 1 / 1;
    border-radius: 0;
    cursor: pointer;
    border: none;
    box-shadow: inset 0 1px 1px rgba(0,0,0,0.05);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    overflow: hidden;
    display: block;
}

.swatch-item::before {
    content: '';
    display: block;
    padding-bottom: 100%; /* 维持正方形 */
}

.swatch-item-name {
    position: absolute;
    bottom: 2px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    color: rgba(0,0,0,0.6);
}
.swatch-item.light .swatch-item-name {
    color: rgba(255,255,255,0.8);
}
.swatch-item:hover .swatch-item-name {
    opacity: 1;
}

.swatch-item:hover {
    transform: scale(1.08);
    z-index: 2;
    box-shadow: 0 2px 4px rgba(0,0,0,0.12);
}
.swatch-item.active,
.swatch-item:active {
    transform: scale(1.30) translateY(-8px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.2);
    z-index: 3;
}
.swatch-item::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.swatch-item:hover::after {
    opacity: 1;
}

footer {
    text-align: center;
    margin-top: 10px;
    margin-bottom: 10px;
    color: var(--text-light);
    font-size: 0.9rem;
  }

footer a,
footer a:visited,
footer a:hover,
footer a:active {
color: var(--text-light);
text-decoration: none;
}

@media (max-width: 900px) {
    .layout-grid {
        flex-direction: column;
    }
    .main-controls,
    .side-panel {
        width: 100%;
    }
    .side-panel {
        order: -1;
    }
    .swatches-grid {
        grid-template-columns: repeat(10, 1fr);
    }
}
@media (max-width: 600px) {
    .swatches-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}
@media (max-width: 400px) {
    .swatches-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}