:root {
    --bg-main: #0a0a0c;
    --bg-grad: radial-gradient(circle at 50% 0%, #1a1a20 0%, #0a0a0c 80%);
    --module-bg: rgba(30, 30, 35, 0.7);
    --module-border: 1px solid rgba(255, 255, 255, 0.08);
    --text-main: #ffffff;
    --text-sub: #888888;
    --accent: #FFD60A;
    --accent-glow: rgba(255, 214, 10, 0.5);
    --pro-grad: linear-gradient(135deg, #00c6ff, #0072ff);
    --input-bg: rgba(0,0,0,0.3);
    --hover-bg: rgba(255,255,255,0.05);
}

[data-theme="light"] {
    --bg-main: #f5f5f7;
    --bg-grad: radial-gradient(circle at 50% 0%, #ffffff 0%, #e8e8ed 100%);
    --module-bg: rgba(255, 255, 255, 0.85);
    --module-border: 1px solid rgba(0,0,0,0.05);
    --text-main: #1d1d1f;
    --input-bg: rgba(0,0,0,0.03);
    --hover-bg: rgba(0,0,0,0.03);
}

* { box-sizing: border-box; outline: none; -webkit-tap-highlight-color: transparent; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    background: var(--bg-main); background-image: var(--bg-grad);
    color: var(--text-main); margin: 0; padding: 20px;
    display: flex; flex-direction: column; align-items: center; min-height: 100vh;
}

/* 顶部开关 */
.navbar { position: absolute; top: 20px; right: 20px; z-index: 100; }
.theme-switch { position: relative; display: inline-block; width: 60px; height: 34px; }
.theme-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(120, 120, 128, 0.2); transition: .4s; border-radius: 34px;
    display: flex; align-items: center; justify-content: space-between; padding: 5px;
}
.slider:before {
    position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px;
    background-color: white; transition: .4s; border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2); z-index: 2;
}
input:checked + .slider { background-color: var(--text-main); }
[data-theme="light"] input:checked + .slider { background-color: #007aff; }
input:checked + .slider:before { transform: translateX(26px); }
.icon-sun, .icon-moon { width: 16px; height: 16px; color: #888; z-index: 1; stroke-width: 2.5px; }

/* 头部 */
.hero-header { text-align: center; margin: 40px 0 30px 0; }
.brand-title {
    font-size: 3.5rem; font-weight: 800; letter-spacing: -1px; position: relative;
    background: var(--pro-grad); -webkit-background-clip: text; color: transparent;
    transition: 0.3s; cursor: default;
}
.brand-title:hover { filter: brightness(1.2) drop-shadow(0 0 15px rgba(0,114,255,0.4)); }
.brand-pro { color: var(--text-main); }
.brand-badge-4k {
    background: var(--accent); color: #000; padding: 4px 10px; border-radius: 6px;
    font-size: 1.2rem; font-weight: 900; font-style: italic; margin-left: 10px;
    transform: skewX(-10deg); display: inline-block; box-shadow: 0 0 15px var(--accent-glow);
}
.brand-sub { font-family: 'SF Mono', monospace; font-size: 12px; color: var(--text-sub); margin-top: 8px; letter-spacing: 2px; }

/* 模块通用 */
.dashboard { width: 100%; max-width: 1000px; display: flex; flex-direction: column; gap: 20px; padding-bottom: 50px; }
.tech-module {
    background: var(--module-bg); border: var(--module-border);
    backdrop-filter: blur(20px); border-radius: 18px; padding: 20px;
    transition: transform 0.2s, border-color 0.2s;
}
.tech-module:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.2); }
.module-header, .module-label {
    font-size: 12px; font-weight: 700; color: var(--text-sub); letter-spacing: 0.5px;
    margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center;
}
.trash-btn {
    background: none; border: none; color: var(--text-sub); cursor: pointer; padding: 6px;
    border-radius: 6px; transition: 0.2s; display: flex;
}
.trash-btn:hover { color: #ff3b30; background: rgba(255, 59, 48, 0.1); }
.trash-btn svg { width: 16px; height: 16px; }

/* API & 按钮组 (Apple 风格) */
.api-module { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; }
.module-left { flex: 1; }
.module-right { display: flex; align-items: center; gap: 12px; }

.input-wrapper { position: relative; display: flex; align-items: center; }
#apiKey {
    width: 100%; background: var(--input-bg); border: 1px solid transparent; color: var(--text-main);
    padding: 12px 40px 12px 12px; border-radius: 12px; font-family: monospace; font-size: 13px;
}
.icon-btn {
    position: absolute; right: 8px; background: none; border: none; color: var(--text-sub);
    cursor: pointer; padding: 4px; display: flex;
}
.icon-btn:hover { color: var(--text-main); }

/* Apple 风格按钮 */
.apple-btn {
    display: flex; align-items: center; gap: 6px; padding: 0 16px; height: 42px;
    border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer;
    transition: all 0.2s; text-decoration: none; border: none;
}
.apple-btn svg { width: 16px; height: 16px; stroke-width: 2.5px; }

.balance-btn {
    background: rgba(255,255,255,0.1); color: var(--text-main);
    border: 1px solid rgba(255,255,255,0.05);
}
.balance-btn:hover { background: rgba(255,255,255,0.15); transform: translateY(-1px); }
[data-theme="light"] .balance-btn { background: rgba(0,0,0,0.05); color: #000; border: 1px solid rgba(0,0,0,0.05); }
[data-theme="light"] .balance-btn:hover { background: rgba(0,0,0,0.1); }

.buy-btn {
    background: #007aff; color: white;
    box-shadow: 0 2px 10px rgba(0,122,255,0.3);
}
.buy-btn:hover { background: #0062cc; transform: translateY(-1px); box-shadow: 0 4px 15px rgba(0,122,255,0.4); }

/* 设置区域 */
.settings-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; }
.right-column { display: flex; flex-direction: column; gap: 20px; }

textarea {
    width: 100%; height: 140px; background: var(--input-bg); border: 1px solid transparent;
    color: var(--text-main); border-radius: 12px; padding: 15px; resize: none; font-family: inherit;
    line-height: 1.5;
}
textarea:focus, #apiKey:focus { border-color: var(--accent); background: var(--hover-bg); }

/* 参考图 (Fix) */
.upload-area {
    border: 2px dashed var(--text-sub); border-radius: 12px; padding: 15px;
    min-height: 100px; cursor: pointer; position: relative; transition: 0.2s;
    background: rgba(0,0,0,0.1);
}
.upload-area:hover { border-color: var(--text-main); background: var(--hover-bg); }
.upload-placeholder {
    height: 80px; display: flex; flex-direction: column; align-items: center;
    justify-content: center; color: var(--text-sub); gap: 8px; font-size: 12px;
}
.thumb-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.thumb-item-wrapper { position: relative; width: 70px; height: 70px; }
.thumb-img {
    width: 100%; height: 100%; object-fit: cover; border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.2); transition: 0.2s;
}
.thumb-img:hover { border-color: var(--accent); }
.thumb-del {
    position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
    background: #ff3b30; color: white; border-radius: 50%; font-size: 14px;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    border: 2px solid var(--module-bg); z-index: 5; /* 确保在最上层 */
}

/* 下拉框 (Fix Dark Mode) */
.params-row { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 10px; }
.tech-module.mini { padding: 15px; }
select {
    width: 100%; background: var(--input-bg); color: var(--text-main);
    border: 1px solid transparent; border-radius: 10px; padding: 10px; font-size: 13px;
    cursor: pointer; appearance: none;
}
/* 强制指定下拉选项颜色 */
select option { background-color: #2c2c2e; color: #fff; padding: 5px; }
[data-theme="light"] select option { background-color: #fff; color: #000; }

/* 开始按钮 */
.action-section { margin-top: 10px; }
.start-btn {
    width: 100%; padding: 20px; border: none; border-radius: 16px;
    background: linear-gradient(135deg, #FFD60A, #FF9F0A);
    color: #000; font-size: 18px; font-weight: 900; letter-spacing: 2px;
    cursor: pointer; position: relative; overflow: hidden; transition: 0.3s;
    box-shadow: 0 10px 30px rgba(255, 214, 10, 0.3);
}
.start-btn:hover { transform: scale(1.02); box-shadow: 0 20px 50px rgba(255, 214, 10, 0.5); }
.start-btn:disabled { filter: grayscale(1); opacity: 0.5; cursor: not-allowed; }

/* 结果区域 (Flex布局 & 尺寸控制) */
.result-module { min-height: 200px; text-align: center; }
.result-container {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; width: 100%;
    margin-top: 20px;
}
.result-wrapper {
    position: relative; display: flex; justify-content: center;
}
.result-img {
    height: 380px; /* 约 10cm */
    width: auto; max-width: 100%;
    border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,0.5); 
    object-fit: contain; cursor: zoom-in;
}

/* 悬浮控制条 (仅 hover 显示) */
.img-controls {
    position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.8); backdrop-filter: blur(10px);
    padding: 8px 16px; border-radius: 30px; display: flex; gap: 15px;
    opacity: 0; transition: 0.2s; border: 1px solid rgba(255,255,255,0.2);
    pointer-events: none; /* 防止遮挡 */
}
.result-wrapper:hover .img-controls { opacity: 1; bottom: 30px; pointer-events: auto; }

.ctrl-btn {
    background: none; border: none; color: white; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10px;
    text-decoration: none; min-width: 40px;
}
.ctrl-btn:hover { color: var(--accent); }
.ctrl-btn svg { width: 18px; height: 18px; }

/* 进度条 & 提示 */
.loading-bar { width: 100%; height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden; display: none; margin-top: 20px; }
.bar-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.5s linear; }
.status-wrapper { margin-top: 15px; min-height: 40px; }
.status-text { font-family: monospace; color: var(--text-sub); font-size: 12px; font-weight: bold; }
.loading-tips { font-size: 12px; color: #aaa; margin-top: 5px; height: 20px; animation: fadeIn 0.5s; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* 余额弹窗 */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 1000;
    display: none; justify-content: center; align-items: center; backdrop-filter: blur(5px);
}
.modal-card {
    background: var(--module-bg); border: var(--module-border); padding: 30px;
    border-radius: 24px; width: 320px; box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.modal-header { font-size: 16px; font-weight: 700; margin-bottom: 25px; display: flex; align-items: center; gap: 8px; color: var(--text-sub); }
.modal-body { display: flex; flex-direction: column; gap: 15px; }
.balance-row { display: flex; justify-content: space-between; align-items: center; }
.main-row .val { font-size: 32px; font-weight: 800; color: var(--accent); font-family: monospace; letter-spacing: -1px; }
.divider { height: 1px; background: rgba(255,255,255,0.1); margin: 5px 0; }
.small-row { font-size: 13px; color: var(--text-sub); }
.small-row .val { font-family: monospace; color: var(--text-main); font-weight: 600; }
.modal-close-btn {
    width: 100%; margin-top: 25px; padding: 14px; border: none; border-radius: 14px;
    background: var(--text-main); color: var(--bg-main); font-weight: bold; cursor: pointer;
    font-size: 14px; transition: 0.2s;
}
.modal-close-btn:hover { opacity: 0.9; }

/* 全屏灯箱 */
.lightbox {
    position: fixed; inset: 0; background: rgba(0,0,0,0.95); z-index: 2000;
    display: none; justify-content: center; align-items: center; cursor: zoom-out;
}
.lightbox img { max-width: 95vw; max-height: 95vh; object-fit: contain; box-shadow: 0 0 50px rgba(0,0,0,0.5); }

@media (max-width: 768px) {
    .settings-grid, .api-module, .params-row { grid-template-columns: 1fr; }
    .hero-header { margin-top: 60px; }
    .brand-title { font-size: 2.5rem; }
    .module-right { width: 100%; justify-content: space-between; }
    .result-img { height: auto; max-width: 100%; }
}