/* --- CSS Variables --- */
:root {
    --bg: #faf9f7;
    --bg-elevated: #ffffff;
    --card: #ffffff;
    --border: #e5e3df;
    --border-hover: #d4d1cb;
    --fg: #1a1817;
    --muted: #6b6560;
    --accent: #2563eb; /* Blue for Editor */
    --accent-light: #e0e7ff;
    --accent-glow: rgba(37, 99, 235, 0.15);
    --secondary: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --input-bg: #ffffff;
    --pattern-opacity: 0.3;
}

[data-theme="dark"] {
    --bg: #0a0a0f;
    --bg-elevated: #12121a;
    --card: #16161f;
    --border: #2a2a3a;
    --border-hover: #3a3a4a;
    --fg: #e8e8ed;
    --muted: #6b6b7a;
    --accent: #3b82f6;
    --accent-light: #3b82f620;
    --accent-glow: rgba(59, 130, 246, 0.2);
    --secondary: #a78bfa;
    --success: #34d399;
    --danger: #f87171;
    --input-bg: #0f0f14;
    --pattern-opacity: 0.05;
}

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

body {
    font-family: 'Space Grotesk', sans-serif;
    background-color: var(--bg);
    color: var(--fg);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* --- Background --- */
.bg-decoration {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.bg-pattern {
    position: absolute;
    inset: 0;
    background-image: radial-gradient(circle, var(--muted) 1px, transparent 1px);
    background-size: 24px 24px;
    opacity: var(--pattern-opacity);
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 500px;
    height: 500px;
    background: linear-gradient(135deg, #bfdbfe, #93c5fd);
    top: -150px;
    right: -100px;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: linear-gradient(135deg, #c4b5fd, #a78bfa);
    bottom: -100px;
    left: -100px;
    animation-delay: -5s;
}

[data-theme="dark"] .orb-1 { background: var(--accent); opacity: 0.15; }
[data-theme="dark"] .orb-2 { background: var(--secondary); opacity: 0.15; }

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(30px, 20px) scale(1.05); }
}

/* --- Layout --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.main-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 900px) {
    .main-grid {
        grid-template-columns: 340px 1fr;
    }
}

/* --- Header --- */
header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.header-top {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 50px;
    border: 1px solid var(--border);
    background: var(--card);
    font-size: 14px;
    color: var(--muted);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -1px;
    margin-bottom: 0.5rem;
}

h1 span { color: var(--accent); }

.subtitle {
    color: var(--muted);
    font-size: 1.1rem;
}

/* --- Theme Toggle --- */
.theme-toggle {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 100;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--card);
    border: 2px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.theme-toggle:hover {
    transform: rotate(15deg) scale(1.1);
    border-color: var(--accent);
    background: var(--accent-light);
}

.theme-toggle svg {
    width: 24px;
    height: 24px;
    stroke: var(--fg);
    fill: none;
    stroke-width: 2;
}

/* --- Panel --- */
.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.03);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- Tools Panel --- */
.tools-panel {
    padding: 0;
}

.tabs-nav {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.tab-btn {
    flex: 1;
    padding: 14px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.tab-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; }
.tab-btn:hover { color: var(--fg); background: var(--bg-elevated); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--card); }

.tab-content { display: none; padding: 1.5rem; flex: 1; }
.tab-content.active { display: flex; flex-direction: column; gap: 1.5rem; }

.tool-section h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin-bottom: 0.75rem;
    font-weight: 600;
}

/* Ratio Grid */
.ratio-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.ratio-btn {
    padding: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s;
    color: var(--fg);
}

.ratio-btn:hover { border-color: var(--accent); }
.ratio-btn.active { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }

/* Dimension Inputs */
.dimension-inputs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.input-group label {
    display: block;
    font-size: 0.7rem;
    color: var(--muted);
    margin-bottom: 4px;
    text-align: center;
}

.input-group input {
    width: 100%;
    padding: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    color: var(--fg);
}

.input-group input:focus { outline: none; border-color: var(--accent); }

/* Angle Display */
.angle-display {
    background: var(--accent-light);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
}

/* Quick Buttons */
.quick-btns {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.quick-btn {
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    color: var(--fg);
}

.quick-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Slider */
.slider-group input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    -webkit-appearance: none;
    cursor: pointer;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 4px;
}

/* Mirror Buttons */
.mirror-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.mirror-btn {
    padding: 1.5rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    color: var(--muted);
}

.mirror-btn svg { width: 32px; height: 32px; stroke: currentColor; fill: none; }
.mirror-btn span { font-weight: 600; font-size: 0.9rem; }
.mirror-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* Image Stats */
.image-stats {
    background: var(--bg);
    border-radius: 12px;
    padding: 1rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
}

.stat-row:last-child { border: none; }
.stat-row span:last-child { font-weight: 600; font-family: 'JetBrains Mono', monospace; color: var(--accent); }

/* Action Button */
.btn-action {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    margin-top: auto;
}

.btn-action svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn-action:hover { transform: translateY(-2px); box-shadow: 0 8px 20px var(--accent-glow); }

/* --- Preview Panel --- */
.preview-panel {
    position: relative;
    min-height: 500px;
}

/* Upload Zone */
.upload-zone {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    cursor: pointer;
    transition: all 0.3s;
}

.upload-zone:hover .upload-icon { transform: scale(1.05); color: var(--accent); }

.upload-icon {
    width: 80px;
    height: 80px;
    color: var(--muted);
    margin-bottom: 1.5rem;
    transition: all 0.3s;
}

.upload-icon svg { width: 100%; height: 100%; stroke: currentColor; fill: none; }

.upload-zone h3 { font-size: 1.25rem; margin-bottom: 0.5rem; }
.upload-zone p { color: var(--muted); font-size: 0.9rem; margin-bottom: 1.5rem; }

.btn-upload {
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-upload:hover { transform: translateY(-2px); box-shadow: 0 4px 12px var(--accent-glow); }

/* Canvas Container */
.canvas-container {
    position: absolute;
    inset: 0;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: 
        linear-gradient(45deg, var(--border) 25%, transparent 25%),
        linear-gradient(-45deg, var(--border) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--border) 75%),
        linear-gradient(-45deg, transparent 75%, var(--border) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

#imageCanvas {
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    border-radius: 4px;
}

/* Preview Actions */
.preview-actions {
    position: absolute;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 10;
    background: var(--card);
    padding: 10px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.btn-ghost, .btn-success {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.btn-ghost {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--fg);
}

.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn-success {
    background: var(--success);
    border: none;
    color: white;
}

.btn-success:hover { filter: brightness(1.1); transform: translateY(-1px); }

.btn-ghost svg, .btn-success svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--card);
    border: 1px solid var(--accent);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1000;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast svg { width: 20px; height: 20px; stroke: var(--accent); fill: none; stroke-width: 2.5; }

/* Utility */
.hidden { display: none !important; }
.fade-in { animation: fadeIn 0.6s ease forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* Responsive */
@media (max-width: 900px) {
    .main-grid { grid-template-columns: 1fr; }
    .preview-panel { min-height: 400px; }
    .ratio-grid { grid-template-columns: repeat(3, 1fr); }
    .dimension-inputs { grid-template-columns: repeat(2, 1fr); }
}