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

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --border: #e2e5ea;
    --accent: #4361ee;
    --accent-hover: #3a56d4;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
}

html {
    font-size: 14px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

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

.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Main layout */
.main {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 2rem;
    align-items: start;
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 1.5rem;
}

.control-section {
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.control-section:last-of-type {
    border-bottom: none;
    padding-bottom: 0;
}

.control-section h2 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.75rem;
    margin-top: 0.75rem;
}

.label-hint {
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    font-size: 0.8rem;
}

/* Upload zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--accent);
    background: rgba(67, 97, 238, 0.04);
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.upload-content svg {
    opacity: 0.5;
}

.upload-content p {
    font-size: 0.9rem;
    font-weight: 500;
}

.upload-hint {
    font-size: 0.75rem;
    opacity: 0.6;
}

.upload-zone.has-image {
    border-style: solid;
    border-color: var(--accent);
    background: rgba(67, 97, 238, 0.04);
    padding: 0.75rem;
}

.upload-zone.has-image .upload-content {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
}

.upload-info {
    flex: 1;
    min-width: 0;
}

/* Inline delete button in upload zone */
.upload-remove-btn {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.12);
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.upload-remove-btn:hover {
    background: rgba(220, 53, 69, 0.15);
    color: #dc3545;
}

.upload-zone.has-image .upload-content svg {
    display: none;
}

.upload-zone.has-image .upload-hint {
    display: none;
}

.upload-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
}

.upload-filename {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    word-break: break-all;
    text-align: left;
}

.upload-filesize {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Ratio buttons */
.ratio-buttons {
    display: flex;
    gap: 0.5rem;
}

.ratio-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.25rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.15s;
}

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

.ratio-btn.active {
    border-color: var(--accent);
    background: rgba(67, 97, 238, 0.06);
    color: var(--accent);
}

.ratio-icon {
    display: block;
    width: 100%;
    max-width: 28px;
    max-height: 28px;
    border: 2px solid currentColor;
    border-radius: 2px;
}

/* Input with suffix */
.input-with-suffix {
    display: flex;
    align-items: center;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.15s;
}

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

.input-with-suffix input {
    flex: 1;
    border: none;
    outline: none;
    padding: 0.6rem 0.75rem;
    font-size: 0.95rem;
    font-family: inherit;
    min-width: 0;
    background: transparent;
}

.input-with-suffix .suffix {
    padding: 0.6rem 0.75rem;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    border-left: 2px solid var(--border);
}

.input-small {
    max-width: 100px;
    flex-shrink: 0;
}

.input-small input {
    padding: 0.4rem 0.5rem;
    font-size: 0.85rem;
}

.input-small .suffix {
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
}

/* Frame ratio control */
.frame-ratio-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.frame-ratio-control input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.frame-ratio-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(67, 97, 238, 0.3);
    transition: transform 0.15s;
}

.frame-ratio-control input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.frame-ratio-control input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(67, 97, 238, 0.3);
}

/* Color presets */
.color-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border: 2px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    padding: 2px;
    background: var(--surface);
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.color-swatch span {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
}

.color-swatch:hover {
    border-color: var(--accent);
    transform: scale(1.1);
}

.color-swatch.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.25);
}

.color-picker-wrap {
    position: relative;
    width: 32px;
    height: 32px;
}

.color-picker-wrap input[type="color"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.color-picker-wrap svg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    color: var(--text-secondary);
}

/* Info section */
.info-section {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 1rem !important;
    border: none !important;
    margin-top: 0.5rem;
}

.info-section h2 {
    margin-top: 0 !important;
}

.info-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 1rem;
    font-size: 0.85rem;
}

.info-label {
    color: var(--text-secondary);
}

.info-value {
    font-weight: 600;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.warning {
    margin-top: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #fff3cd;
    color: #856404;
    border-radius: var(--radius);
    font-size: 0.8rem;
    line-height: 1.4;
}

/* Download button */
.download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.85rem;
    margin-top: 1rem;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.download-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

.download-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.download-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Preview area */
.preview-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.preview-container {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: repeating-conic-gradient(#d0d0d0 0% 25%, #f0f0f0 0% 50%) 50% / 20px 20px;
    border-radius: var(--radius-lg);
    padding: 2rem;
    min-height: 400px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.preview-container.has-image {
    cursor: default;
}

.preview-container.drag-over {
    box-shadow: 0 0 0 3px var(--accent);
}

#preview-canvas {
    max-width: 100%;
    max-height: 70vh;
    box-shadow: var(--shadow-lg);
    image-rendering: auto;
}

.preview-container:not(.has-image) #preview-canvas {
    pointer-events: none;
}

/* Preview upload prompt overlay */
.preview-upload-prompt {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    pointer-events: none;
    z-index: 1;
}

.preview-upload-prompt svg {
    opacity: 0.4;
}

.preview-upload-prompt p {
    font-size: 0.95rem;
    font-weight: 500;
}

.preview-upload-prompt .prompt-mobile {
    display: none;
}

.preview-upload-prompt span {
    font-size: 0.75rem;
    opacity: 0.6;
}

.preview-container.has-image .preview-upload-prompt {
    display: none;
}

/* Preview toolbar (hint + delete button) */
.preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 1rem;
}

.preview-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.preview-remove-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.preview-remove-btn:hover {
    background: #fef2f2;
    color: #dc3545;
    border-color: #dc3545;
}

/* Bottom sheet handle (hidden on desktop) */
.sheet-handle {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 12px 0 8px;
    cursor: grab;
    touch-action: none;
    flex-shrink: 0;
}

.sheet-handle-bar {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #d1d5db;
}

/* Sheet backdrop */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s;
}

.sheet-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

/* Responsive - Mobile bottom sheet layout */
@media (max-width: 900px) {
    body {
        overflow: hidden;
        height: 100vh;
        height: 100dvh;
    }

    .app {
        height: 100vh;
        height: 100dvh;
        max-width: none;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding: 0.75rem 0.75rem 0;
    }

    .header {
        flex-shrink: 0;
        margin-bottom: 0.75rem;
    }

    .header h1 {
        font-size: 1.35rem;
    }

    .subtitle {
        font-size: 0.8rem;
    }

    .main {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        gap: 0;
    }

    .preview-area {
        flex: 1;
        overflow: hidden;
        padding-bottom: 56px;
        gap: 0.5rem;
    }

    .preview-container {
        flex: 1;
        min-height: 0;
        padding: 1rem;
    }

    #preview-canvas {
        max-height: 100%;
    }

    .preview-upload-prompt .prompt-desktop {
        display: none;
    }

    .preview-upload-prompt .prompt-mobile {
        display: block;
    }

    .preview-toolbar {
        flex-shrink: 0;
    }

    /* Bottom sheet */
    .sheet-handle {
        display: flex;
    }

    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 200;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
        max-height: 80vh;
        transform: translateY(calc(100% - 48px));
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
        padding: 0 1.25rem 1.25rem;
    }

    .sidebar.sheet-open {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Hide redundant sections on mobile */
    .upload-section {
        display: none;
    }

    .canvas-size-section {
        display: none;
    }

    /* Download button inside sheet (not fixed) */
    .download-btn {
        position: static;
        border-radius: var(--radius);
        box-shadow: none;
        padding: 0.85rem;
    }
}

@media (max-width: 480px) {
    .app {
        padding: 0.5rem 0.5rem 0;
    }

    .header h1 {
        font-size: 1.15rem;
    }

    .ratio-buttons {
        flex-wrap: wrap;
    }

    .ratio-btn {
        min-width: calc(33% - 0.5rem);
    }

    .preview-container {
        padding: 0.75rem;
    }
}

/* Number input spinner hide */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}
