:root {
    --primary: #2563eb;
    --bg-sidebar: #ffffff;
    --bg-app: #f3f4f6;
    --border: #e5e7eb;
    --text: #1f2937;
    --text-muted: #6b7280;
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --bg-sidebar: #1f2937;
    --bg-app: #111827;
    --border: #374151;
    --text: #f9fafb;
    --text-muted: #9ca3af;
}

* { box-sizing: border-box; }

body.photocard-standalone-body,
body.photocard-fullscreen-active {
    margin: 0;
    height: 100vh;
    overflow: hidden;
}

.photocard-studio-wrapper {
    display: flex;
    position: relative;
    width: 100%;
    min-height: 780px;
    height: 85vh;
    background: var(--bg-app);
    border-radius: 18px;
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: 0 15px 40px -10px rgba(0,0,0,0.08);
}

body.photocard-fullscreen-active .photocard-studio-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999999;
    border-radius: 0;
    border: none;
    min-height: 100vh;
}

.photocard-studio-wrapper .app-container, .app-container { width: 100%;
    display: flex;
    height: 100%;
}

.sidebar {
    width: 360px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.sidebar-header > div:first-child {
    flex: 1;
}

.sidebar-header h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.sidebar-header p {
    margin: 5px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

.controls {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-top: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--border);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

label {
    font-size: 13px;
    font-weight: 500;
}

input, select, textarea {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    width: 100%;
    font-family: inherit;
    background: var(--bg-input, #f9fafb);
    color: var(--text);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-input-focus, #fff);
}

textarea { resize: vertical; }

/* Color input styling */
input[type="color"] {
    padding: 4px 8px;
    height: 42px;
    cursor: pointer;
    -webkit-appearance: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-sidebar);
}

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

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 4px;
}

input[type="color"]:focus {
    outline: none;
    border-color: var(--primary);
}

.dual-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.actions {
    padding: 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-sidebar);
    display: flex;
    gap: 10px;
}

.secondary-btn {
    width: 100%;
    padding: 12px;
    background: var(--bg-btn-secondary, white);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.secondary-btn:hover {
    background: var(--bg-btn-secondary-hover, #f9fafb);
}

.primary-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.primary-btn:hover {
    background: #1d4ed8;
}

.mobile-toggle {
    display: none;
    position: fixed;
    bottom: 74px;
    right: 16px;
    z-index: 1045;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 10px 18px;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
    cursor: pointer;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.mobile-only {
    display: none;
}

.close-btn {
    background: none;
    border: none;
    font-size: 26px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 8px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    width: 36px;
    height: 36px;
}

.close-btn:hover {
    background: var(--bg-app);
    color: var(--text);
}

.mobile-drawer-handle {
    display: none;
    width: 44px;
    height: 5px;
    background: var(--border);
    border-radius: 10px;
    margin: 8px auto 0;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 24999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.active {
    display: block;
    opacity: 1;
}

.photocard-mobile-dock {
    display: none;
}

@media (max-width: 768px) {
    .photocard-studio-wrapper .app-container, .app-container {
        width: 100%;
        flex-direction: column;
    }

    .mobile-toggle {
        display: none;
    }

    .mobile-only {
        display: inline-flex !important;
    }

    .mobile-drawer-handle {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
        z-index: 25000 !important;
        box-shadow: 0 -10px 40px rgba(0,0,0,0.25);
        display: flex;
        flex-direction: column;
        border-radius: 20px 20px 0 0;
        overflow: hidden;
    }

    .sidebar.open {
        transform: translateY(0);
    }

    .sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 14px 16px;
        background: var(--bg-sidebar);
    }

    .sidebar-header h1 {
        font-size: 16px;
        line-height: 1.2;
    }

    .sidebar-header p {
        font-size: 11px;
    }

    .controls {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px;
        gap: 14px;
        padding-bottom: 90px;
    }

    .sidebar .actions {
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-sidebar);
        border-top: 1px solid var(--border);
        padding: 10px 14px;
        display: flex;
        gap: 8px;
        z-index: 20;
        box-shadow: 0 -4px 15px rgba(0,0,0,0.06);
    }

    .photocard-mobile-dock {
        display: flex;
        align-items: center;
        justify-content: space-around;
        position: fixed;
        bottom: 74px;
        left: 12px;
        right: 12px;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border: 1px solid rgba(226, 232, 240, 0.95);
        border-radius: 50px;
        padding: 6px 8px;
        box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.16), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        z-index: 1045;
        gap: 6px;
    }

    [data-theme="dark"] .photocard-mobile-dock {
        background: rgba(30, 41, 59, 0.96);
        border-color: rgba(51, 65, 85, 0.95);
    }

    body.photocard-fullscreen-active .photocard-mobile-dock {
        bottom: 16px;
        z-index: 1000000;
    }

    .dock-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 6px 4px;
        border: none;
        background: transparent;
        color: var(--text);
        font-size: 11px;
        font-weight: 600;
        border-radius: 30px;
        cursor: pointer;
        transition: all 0.2s ease;
        gap: 2px;
        min-height: 44px;
        line-height: 1.1;
    }

    .dock-btn i {
        font-size: 16px;
    }

    .dock-btn:active {
        transform: scale(0.94);
    }

    .dock-btn-primary {
        background: #2563eb !important;
        color: #ffffff !important;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    }

    .dock-btn-success {
        background: #16a34a !important;
        color: #ffffff !important;
        box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
    }

    .photocard-studio-wrapper {
        min-height: 350px !important;
        height: auto !important;
        border-radius: 14px;
        margin-bottom: 20px;
    }

    .preview-area {
        width: 100%;
        min-height: 350px;
        height: min(90vw + 20px, 450px);
        max-height: 480px;
        padding: 12px 8px 36px;
        background: #e2e8f0;
    }

    body.photocard-fullscreen-active .mobile-bottom-nav,
    body.photocard-fullscreen-active header,
    body.photocard-fullscreen-active footer,
    body.photocard-fullscreen-active .site-header,
    body.photocard-fullscreen-active #header {
        display: none !important;
    }

    body.photocard-fullscreen-active .photocard-studio-wrapper {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        min-height: 100vh !important;
        border-radius: 0 !important;
        z-index: 999999 !important;
    }

    body.photocard-fullscreen-active .preview-area {
        height: 100vh !important;
        max-height: 100vh !important;
        padding-bottom: 85px !important;
    }
}

.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    background: #e5e5e5;
    overflow: hidden;
    position: relative;
}

.canvas-wrapper {
    box-shadow: 0 20px 50px rgba(0,0,0,0.15);
    background: white;
    /* Scale down to fit screen */
    transform-origin: center center;
    width: 1080px;
    height: 1080px;
    /* Initially scaled down via JS */
}

#renderTarget {
    width: 100%;
    height: 100%;
    background: white;
}

.zoom-controls {
    position: absolute;
    bottom: 6px;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    pointer-events: none;
}

.help-text {
    font-size: 12px;
    color: var(--text-muted);
    margin: 4px 0 0;
}

#dynamicContent > div {
    margin-bottom: 10px;
}
/* Choices.js overrides */
.choices {
    position: relative !important;
}

.choices__inner {
    background-color: var(--bg-sidebar) !important;
    border: 1px solid var(--border) !important;
    border-radius: 6px;
    min-height: 42px;
    padding: 4px 8px;
    color: var(--text) !important;
}

.choices__list--dropdown {
    z-index: 100;
    background-color: var(--bg-sidebar) !important;
    border: 1px solid var(--border) !important;
}

.choices__list--dropdown .choices__list {
    max-height: 300px;
    overflow-y: auto;
}

.choices__item {
    font-size: 14px;
    color: var(--text) !important;
}

.choices__item--selectable.is-highlighted {
    background-color: var(--bg-btn-secondary-hover, #f3f4f6) !important;
}

.choices[data-type*="select-one"] .choices__input {
    background-color: var(--bg-input, #f3f4f6) !important;
    border-radius: 4px;
    color: var(--text) !important;
}

.choices__placeholder {
    color: var(--text-muted) !important;
}

.choices[data-type*="select-one"]::after {
    border-color: var(--text-muted) transparent transparent transparent !important;
}

.text-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.text-btn:hover {
    color: #1d4ed8;
}

.image-controls {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

/* Dark mode button styles */
[data-theme="dark"] {
    --bg-input: #374151;
    --bg-input-focus: #4b5563;
    --bg-btn-secondary: #374151;
    --bg-btn-secondary-hover: #4b5563;
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: var(--bg-btn-secondary-hover, #f9fafb);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

.theme-toggle .sun-icon {
    display: none;
}

.theme-toggle .moon-icon {
    display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
    display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    display: none;
}

.footer-credit {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-sidebar);
    text-align: center;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.footer-credit a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.footer-credit a:hover {
    color: var(--primary);
}

.footer-credit a .external-link-icon {
    flex-shrink: 0;
    opacity: 0.7;
}

.footer-credit a:hover .external-link-icon {
    opacity: 1;
}

.footer-credit span {
    color: var(--text-muted);
    opacity: 0.7;
}

.footer-credit .separator {
    opacity: 0.4;
}
