@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap');

:root {
    --primary: #FF4B2B;
    --secondary: #FF416C;
    --bg-color: #0f172a;
    /* Slate 900 */
    --panel-bg: rgba(30, 41, 59, 0.7);
    /* Slate 800 with opacity */
    --text-color: #f8fafc;
    /* Slate 50 */
    --text-muted: #94a3b8;
    /* Slate 400 */
    --border-color: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --glass-border: 1px solid rgba(255, 255, 255, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-color);
    background-image: radial-gradient(circle at top right, #334155, #0f172a);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* 左側控制面板 - Glassmorphism */
.sidebar {
    width: 380px;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 30px;
    border-right: var(--glass-border);
    box-shadow: var(--glass-shadow);
    overflow-y: auto;
    z-index: 10;
    display: flex;
    flex-direction: column;
}

.sidebar h2 {
    font-size: 1.25rem;
    font-weight: 800;
    margin-top: 10px;
    margin-bottom: 24px;
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.5px;
}

.form-group {
    margin-bottom: 22px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 14px 16px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 1rem;
    color: var(--text-color);
    outline: none;
    transition: all 0.3s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(255, 75, 43, 0.2);
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2394a3b8%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem top 50%;
    background-size: 0.65rem auto;
}

select option {
    background: #0f172a;
    color: white;
}

.custom-size {
    display: none;
    align-items: center;
    gap: 12px;
    margin-top: -10px;
}

.custom-size.show {
    display: flex;
}

.custom-size span {
    color: var(--text-muted);
    font-weight: 600;
}

hr {
    border: none;
    border-top: var(--glass-border);
    margin: 28px 0;
}

.error-msg {
    color: #ef4444;
    font-size: 0.85rem;
    margin-top: 8px;
    font-weight: 600;
    display: none;
    /* 預設隱藏，不要佔據空間 */
}

.error-msg.show {
    display: block;
    /* 有錯誤時才顯示 */
}

.template-presets {
    display: flex;
    gap: 12px;
}

.template-btn {
    flex: 1;
    padding: 12px;
    background: rgba(15, 23, 42, 0.4);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.template-btn:hover {
    background: rgba(15, 23, 42, 0.8);
    color: var(--text-color);
}

.template-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 15px rgba(255, 65, 108, 0.4);
}

/* ===== 條碼深淺色切換按鈕 ===== */
.barcode-theme-toggle {
    display: flex;
    gap: 6px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 14px;
    padding: 5px;
}

.theme-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    border: none;
    border-radius: 10px;
    font-size: 0.88em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background: transparent;
    color: var(--text-muted);
    letter-spacing: 0.03em;
}

.theme-btn:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-color);
}

.theme-btn.active {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-color);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.theme-preview {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

input[type="color"] {
    width: 100%;
    height: 45px;
    padding: 0;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    background: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: 1px solid var(--border-color);
    border-radius: 10px;
}

.primary-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: auto;
    box-shadow: 0 8px 20px rgba(255, 65, 108, 0.3);
    letter-spacing: 0.5px;
}

.primary-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(255, 65, 108, 0.5);
}

.primary-btn:active:not(:disabled) {
    transform: translateY(0);
}

.primary-btn:disabled {
    background: #334155;
    color: #64748b;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* 右側預覽區 - 動態光影背景 */
.preview-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
}

.preview-area::before {
    content: '';
    position: absolute;
    top: -20%;
    left: -10%;
    width: 50%;
    height: 50%;
    background: radial-gradient(circle, rgba(255, 75, 43, 0.15) 0%, transparent 70%);
    filter: blur(60px);
    animation: float 10s infinite alternate ease-in-out;
}

.preview-area::after {
    content: '';
    position: absolute;
    bottom: -20%;
    right: -10%;
    width: 50%;
    height: 50%;
    background: radial-gradient(circle, rgba(255, 65, 108, 0.15) 0%, transparent 70%);
    filter: blur(60px);
    animation: float 12s infinite alternate-reverse ease-in-out;
}

@keyframes float {
    0% {
        transform: translate(0, 0);
    }

    100% {
        transform: translate(50px, 50px);
    }
}

#preview-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform-origin: center center;
    display: inline-block;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    border-radius: 40px;
    overflow: hidden;
    border: 8px solid #1e293b;
    z-index: 1;
}

#wallpaper-design {
    width: 1179px;
    height: 2556px;
    position: relative;
    background-color: #fcf5e5;
    overflow: hidden;
}

.layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.background-layer {
    z-index: 1;
    background-size: cover;
    background-position: center;
}

.barcode-layer {
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 25%;
    overflow: visible;
    /* 讓 box-shadow 不被裁切 */
}

.barcode-wrapper {
    background: rgba(255, 255, 255, 0.95);
    padding: 0;
    border-radius: 20px;
}

.foreground-layer {
    z-index: 3;
    position: absolute;
    height: 60%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: left bottom;
    pointer-events: none;
    top: auto;
    /* translateY 由 JS 動態改寫，依顯示文字問而定 */
}

/* ===== 特殊輸入元件加強美化 ===== */
/* 美化選色器 */
input[type="color"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 100%;
    height: 45px;
    background-color: transparent;
    border: none;
    cursor: pointer;
    border-radius: 12px;
    padding: 0;
    overflow: hidden;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

input[type="color"]::-moz-color-swatch {
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
}

/* 美化滑桿 (Range) */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
    margin: 15px 0;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #FF4757;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(255, 71, 87, 0.5);
    transition: transform 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #FF4757;
    cursor: pointer;
    border: none;
    box-shadow: 0 0 10px rgba(255, 71, 87, 0.5);
    transition: transform 0.2s;
}

input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.2);
}

/* 控制設定群組與標題 */
.setting-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-value {
    color: #FF4757;
    font-size: 0.9em;
    font-weight: bold;
    background: rgba(255, 71, 87, 0.1);
    padding: 2px 8px;
    border-radius: 10px;
}

.color-row {
    display: flex;
    gap: 15px;
}

.color-row>div {
    flex: 1;
}

/* ===== 美化 Toggle Switch ===== */
.custom-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
}

.custom-toggle .toggle-label {
    margin: 0;
    font-weight: normal;
    color: var(--text-color);
    cursor: pointer;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
    margin: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-radius: 28px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* 裡面的白色推鈕 */
.switch .slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: #fff;
    transition: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* 勾選時的背景色與發光 */
.switch input:checked+.slider {
    background-color: #FF4757;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1), 0 0 10px rgba(255, 71, 87, 0.4);
}

/* 勾選時推鈕往右移動 */
.switch input:checked+.slider:before {
    transform: translateX(22px);
}

/* ===== iOS 及手機版 RWD ===== */
@media screen and (max-width: 768px) {
    .app-container {
        flex-direction: column;
        /* 處理 iOS Safari 底部導航列高度問題 */
        height: 100dvh;
    }

    /* 面板改到下方或浮動，讓出空間給預覽區 */
    .sidebar {
        width: 100%;
        /* 限制高度並允許內部滾動 */
        height: 45vh;
        border-right: none;
        border-top: var(--glass-border);
        border-radius: 30px 30px 0 0;
        padding: 24px 20px;
        /* 在手機端陰影往上打 */
        box-shadow: 0 -8px 32px 0 rgba(0, 0, 0, 0.4);
        z-index: 20;
        /* 讓它貼底 */
        position: absolute;
        bottom: 0;
    }

    /* 手機預覽區設定佔比更大，並稍微往上推 */
    .preview-area {
        width: 100%;
        /* 留出下方控制面板的空間，上方可以多佔一點 */
        height: 55vh;
        position: absolute;
        top: 0;
    }
}