/* ===== CSS Variables ===== */
:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #242424;
    --bg-tertiary: #2d2d2d;
    --text-primary: #f5f5f5;
    --text-secondary: #a0a0a0;
    --text-muted: #666;
    --accent: #c9a962;
    --accent-hover: #dbb970;
    --border: #3a3a3a;
    --shadow: rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --transition: 0.2s ease;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

/* ===== Custom Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
    transition: background 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

::-webkit-scrollbar-corner {
    background: transparent;
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

*:hover {
    scrollbar-color: var(--accent) transparent;
}

/* ===== App Layout ===== */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
}

.sidebar-header {
    text-align: center;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-primary);
}

.sidebar-header .subtitle {
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 400;
    margin-top: 4px;
    font-style: italic;
}

/* ===== Settings Groups ===== */
.settings-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-group.hidden {
    display: none;
}

.setting-label {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

/* ===== Radio Buttons ===== */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
    border: 1px solid transparent;
}

.radio-option:hover {
    background: #353535;
}

.radio-option input {
    display: none;
}

.radio-custom {
    width: 18px;
    height: 18px;
    border: 2px solid var(--text-muted);
    border-radius: 50%;
    position: relative;
    transition: border-color var(--transition);
}

.radio-option input:checked+.radio-custom {
    border-color: var(--accent);
}

.radio-option input:checked+.radio-custom::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
}

.radio-option input:checked~.radio-text {
    color: var(--text-primary);
}

.radio-text {
    display: flex;
    flex-direction: column;
    color: var(--text-secondary);
    transition: color var(--transition);
}

.radio-text small {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ===== Input Fields ===== */
.input-with-unit {
    display: flex;
    align-items: center;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: border-color var(--transition);
}

.input-with-unit:focus-within {
    border-color: var(--accent);
}

.input-with-unit input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    min-width: 0;
}

.input-with-unit input::-webkit-inner-spin-button,
.input-with-unit input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.input-with-unit .unit {
    padding: 12px 16px;
    color: var(--text-muted);
    font-size: 0.875rem;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
}

.dimension-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dimension-separator {
    color: var(--text-muted);
    font-size: 1.25rem;
}

/* ===== Slider ===== */
.slider-container {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 0;
}

.slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 0 8px rgba(201, 169, 98, 0.5);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.slider-value {
    min-width: 32px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
}

/* ===== Checkbox ===== */
.checkbox-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}

.checkbox-option:hover {
    background: #353535;
}

.checkbox-option input {
    display: none;
}

.checkbox-custom {
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-muted);
    border-radius: 4px;
    position: relative;
    transition: border-color var(--transition), background var(--transition);
}

.checkbox-option input:checked+.checkbox-custom {
    border-color: var(--accent);
    background: var(--accent);
}

.checkbox-option input:checked+.checkbox-custom::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 6px;
    width: 5px;
    height: 10px;
    border: solid var(--bg-primary);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox-text {
    color: var(--text-secondary);
    transition: color var(--transition);
}

.checkbox-option input:checked~.checkbox-text {
    color: var(--text-primary);
}

/* ===== Generate Button ===== */
.generate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 16px 24px;
    background: linear-gradient(135deg, var(--accent) 0%, #b8944d 100%);
    border: none;
    border-radius: var(--radius);
    color: var(--bg-primary);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 4px 12px rgba(201, 169, 98, 0.3);
}

.generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(201, 169, 98, 0.4);
}

.generate-btn:active {
    transform: translateY(0);
}

.btn-icon {
    font-size: 1.2rem;
}

/* ===== Action Buttons ===== */
.action-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.action-btn {
    flex: 1;
    min-width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
}

.action-btn:hover {
    background: #353535;
    border-color: var(--accent);
    color: var(--accent);
}

.action-btn svg {
    width: 20px;
    height: 20px;
}

/* ===== Sidebar Footer ===== */
.sidebar-footer {
    margin-top: auto;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    text-align: center;
}

.sidebar-footer p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.sidebar-footer .year {
    font-size: 0.75rem;
    margin-top: 4px;
}

/* ===== Canvas Area ===== */
.canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    background: var(--bg-primary);
    overflow: auto;
}

#canvas-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

#canvas-container canvas {
    box-shadow: 0 8px 40px var(--shadow);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column-reverse;
        height: 100vh;
        height: 100dvh;
        /* Dynamic viewport height for mobile */
    }

    .sidebar {
        width: 100%;
        min-width: auto;
        padding: 16px;
        border-right: none;
        border-top: 1px solid var(--border);
        gap: 16px;
        max-height: 45vh;
        overflow-y: auto;
    }

    .sidebar-header {
        padding-bottom: 12px;
    }

    .sidebar-header h1 {
        font-size: 1.2rem;
    }

    .sidebar-footer {
        display: none;
    }

    .canvas-area {
        flex: 1;
        padding: 16px;
        min-height: 0;
        overflow: hidden;
    }

    #canvas-container {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #canvas-container canvas {
        max-width: 100%;
        max-height: 100%;
        width: auto !important;
        height: auto !important;
        object-fit: contain;
    }

    .settings-group {
        gap: 8px;
    }

    .setting-label {
        font-size: 0.7rem;
    }

    .radio-group {
        flex-direction: row;
        gap: 8px;
    }

    .radio-option {
        flex: 1;
        padding: 10px 12px;
    }

    .radio-text {
        font-size: 0.9rem;
    }

    .radio-text small {
        font-size: 0.65rem;
    }

    /* Prevent iOS zoom on input focus */
    .input-with-unit input {
        font-size: 16px;
        padding: 10px 12px;
    }

    .input-with-unit .unit {
        padding: 10px 12px;
        font-size: 0.8rem;
    }

    .dimension-inputs {
        flex-direction: row;
        align-items: center;
    }

    .dimension-inputs .input-with-unit {
        flex: 1;
    }

    .dimension-separator {
        text-align: center;
        flex-shrink: 0;
    }

    .slider-container {
        padding: 4px 0;
    }

    .slider::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }

    .checkbox-option {
        padding: 10px 12px;
    }

    .generate-btn {
        padding: 14px 20px;
        font-size: 0.95rem;
    }

    .action-buttons {
        gap: 6px;
    }

    .action-btn {
        padding: 10px 6px;
        font-size: 0.7rem;
        min-width: 70px;
    }

    .action-btn svg {
        width: 18px;
        height: 18px;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .sidebar {
        padding: 12px;
        gap: 12px;
        max-height: 50vh;
    }

    .sidebar-header h1 {
        font-size: 1.1rem;
    }

    .sidebar-header .subtitle {
        font-size: 0.75rem;
    }

    .radio-option {
        padding: 8px 10px;
    }

    .radio-text {
        font-size: 0.85rem;
    }

    .radio-text small {
        display: none;
    }

    .checkbox-option {
        padding: 8px 10px;
    }

    .checkbox-text {
        font-size: 0.9rem;
    }

    .generate-btn {
        padding: 12px 16px;
        font-size: 0.9rem;
    }

    .action-btn {
        flex-direction: row;
        gap: 4px;
        min-width: auto;
        padding: 10px 12px;
    }

    .action-btn svg {
        width: 16px;
        height: 16px;
    }

    .canvas-area {
        padding: 12px;
    }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .app-container {
        flex-direction: row;
    }

    .sidebar {
        width: 280px;
        min-width: 280px;
        max-height: none;
        border-top: none;
        border-left: 1px solid var(--border);
    }

    .canvas-area {
        flex: 1;
    }

    .radio-group {
        flex-direction: column;
    }
}