:root {
    /* Dark Mode (Default) */
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent-color: #bb86fc;
    --btn-text-color: #000000;
    --accent-hover: #9965f4;
    --border-color: #333;
    --modal-bg: rgba(0,0,0,0.8);
}

body.light-mode {
    --bg-color: #f0f2f5;
    --surface-color: #ffffff;
    --text-primary: #121212;
    --text-secondary: #555555;
    --accent-color: #2563eb;
    --btn-text-color: #ffffff;
    --accent-hover: #1d4ed8;
    --border-color: #e5e7eb;
    --modal-bg: rgba(0,0,0,0.5);
}

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Top Half: Preview */
.preview-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 20px;
    overflow: hidden;
}

.placeholder-content { text-align: center; opacity: 0.5; }
.icon-large { font-size: 3rem; margin-bottom: 1rem; }
.subtext { color: var(--text-secondary); font-size: 0.9rem; }

#imagePreview {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    object-fit: contain;
}

/* Bottom Half: Controls */
.controls-area {
    background-color: var(--surface-color);
    border-radius: 24px 24px 0 0;
    padding: 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    gap: 20px;
    z-index: 10;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-color);
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 0.9rem;
}
.stat { display: flex; flex-direction: column; }
.label { font-size: 0.75rem; color: var(--text-secondary); }
.value { font-weight: bold; }
.highlight { color: var(--accent-color); }
.meta { font-size: 0.7rem; color: var(--text-secondary); margin-top: 2px; }

/* Slider */
.slider-container { width: 100%; }
.slider-header { display: flex; justify-content: space-between; margin-bottom: 10px; font-weight: 500; }
input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--bg-color);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    background: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 12px;
    padding: 16px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s;
    text-align: center;
    text-decoration: none;
    display: inline-flex;
    justify-content: center;
    align-items: center;
}
.btn:active { transform: scale(0.98); }
.btn-large { width: 100%; }
.btn-primary { background-color: var(--accent-color); color: var(--btn-text-color); }
.btn-secondary { background-color: var(--bg-color); color: var(--text-primary); border: 1px solid var(--border-color); }

.button-group { display: flex; gap: 10px; }
.button-group .btn { flex: 1; }

.primary-controls { display: flex; align-items: center; gap: 12px; width: 100%; margin-bottom: 10px; }
.primary-controls #selectBtn { flex: 1; }
.icon-group { display: flex; gap: 4px; }

.btn-icon { background: none; border: 1px solid var(--border-color); border-radius: 12px; color: var(--text-secondary); cursor: pointer; padding: 12px; display: flex; align-items: center; justify-content: center; transition: background-color 0.2s; }
.btn-icon:active { background-color: var(--bg-color); }

/* Modal */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--modal-bg);
    display: flex; justify-content: center; align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}
.modal-content {
    background: var(--surface-color);
    width: 90%; max-width: 350px;
    border-radius: 20px;
    padding: 24px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.setting-item { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.radio-group { display: flex; gap: 12px; font-size: 0.9rem; }
.radio-group label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.about-section { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border-color); font-size: 0.9rem; color: var(--text-secondary); }
.about-section ul { padding-left: 20px; }

/* Utilities */
.hidden { display: none !important; }
.loader {
    border: 4px solid var(--bg-color);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    width: 40px; height: 40px;
    animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
