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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #fafafa;
    min-height: 100vh;
    padding: 0;
    margin: 0;
    touch-action: manipulation;
    color: #1a1a1a;
    letter-spacing: 0.01em;
    overflow: hidden;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f5f5f5;
}

::-webkit-scrollbar-thumb {
    background: #cccccc;
    border-radius: 0;
}

::-webkit-scrollbar-thumb:hover {
    background: #999999;
}

.container {
    max-width: 100%;
    margin: 0;
    padding: 0;
    background: #ffffff;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: #ffffff;
    color: #1a1a1a;
    padding: 0;
    border-bottom: 1px solid #e8e8e8;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 54px;
    min-height: 54px;
    flex-shrink: 0;
    position: relative;
}

.header-brand {
    padding: 0 40px;
    border-right: 1px solid #e8e8e8;
    height: 100%;
    display: flex;
    align-items: center;
}

h1 {
    font-family: 'Playfair Display', serif;
    font-size: 1.5em;
    font-weight: 400;
    letter-spacing: 0.08em;
    margin: 0;
    color: #000000;
}

.subtitle {
    display: none;
}

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

.header-bar {
    display: flex;
    gap: 0;
    margin: 0;
    align-items: center;
    flex-wrap: nowrap;
    padding: 0;
    border-bottom: none;
    height: 100%;
    flex: 1;
}

.dropdown {
    position: relative;
    display: inline-block;
    height: 100%;
}

.dropdown-toggle {
    background: transparent;
    color: #1a1a1a;
    border: none;
    border-right: 1px solid #e8e8e8;
    padding: 0 20px;
    border-radius: 0;
    font-size: 0.75em;
    font-weight: 400;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    touch-action: manipulation;
    transition: all 0.2s ease;
    height: 100%;
    position: relative;
}

.dropdown-toggle:hover {
    background: #fafafa;
}

.dropdown-toggle:active {
    background: #f0f0f0;
}

.menu-icon {
    font-size: 1.2em;
    display: none;
}

.menu-text {
    display: inline;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 10px;
    background: white;
    border-radius: 0;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
    min-width: 240px;
    z-index: 1000;
    overflow: hidden;
    border: 1px solid #e8e8e8;
}

.dropdown-menu.show {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown-item {
    padding: 16px 24px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid #f5f5f5;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.8em;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-weight: 400;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: #fafafa;
    padding-left: 28px;
}

.dropdown-item:active {
    background: #f0f0f0;
}

.dropdown-item.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.upload-area {
    border: none;
    border-right: 1px solid #e8e8e8;
    border-radius: 0;
    padding: 0 20px;
    text-align: center;
    background: transparent;
    transition: all 0.2s ease;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75em;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 400;
    height: 100%;
}

.upload-area:hover {
    background: #fafafa;
}

.upload-area:active {
    background: #f0f0f0;
}

.upload-area h3 {
    font-size: 1em;
    margin: 0;
    font-weight: 400;
}

.upload-area p {
    display: none;
}

.upload-icon {
    font-size: 1.2em;
    margin: 0;
}

input[type="file"] {
    display: none;
}

.canvas-container {
    position: relative;
    width: 100%;
    flex: 1;
    background: #fafafa;
    border-radius: 0;
    overflow: hidden;
    touch-action: none;
    display: flex;
    flex-direction: column;
    border: none;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    background: #ffffff;
    overflow: hidden;
}

.collage-item {
    position: absolute;
    cursor: move;
    touch-action: none;
    user-select: none;
    border: 1px solid transparent;
    transition: border-color 0.2s ease;
    overflow: hidden;
}

.collage-item.selected {
    border: 1px solid #1a1a1a;
    box-shadow: 0 0 0 1px #1a1a1a;
}

.collage-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #1a1a1a;
    border: 2px solid white;
    border-radius: 0;
    display: none;
    cursor: nwse-resize;
    touch-action: none;
    z-index: 10;
}

.collage-item.selected .resize-handle {
    display: block;
}

.resize-handle.nw { top: -6px; left: -6px; cursor: nwse-resize; }
.resize-handle.ne { top: -6px; right: -6px; cursor: nesw-resize; }
.resize-handle.sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.resize-handle.se { bottom: -6px; right: -6px; cursor: nwse-resize; }

.rotate-handle {
    position: absolute;
    top: -36px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 24px;
    background: #1a1a1a;
    border: 2px solid white;
    border-radius: 50%;
    display: none;
    cursor: grab;
    touch-action: none;
    z-index: 10;
    font-size: 12px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rotate-handle:active {
    cursor: grabbing;
}

.collage-item.selected .rotate-handle {
    display: flex;
}

.delete-handle {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 24px;
    height: 24px;
    background: #1a1a1a;
    border: 2px solid white;
    border-radius: 50%;
    display: none;
    cursor: pointer;
    touch-action: manipulation;
    z-index: 10;
    color: white;
    font-size: 14px;
    line-height: 20px;
    text-align: center;
    font-weight: 300;
}

.collage-item.selected .delete-handle {
    display: flex;
    align-items: center;
    justify-content: center;
}

.collage-item.crop-mode {
    border: 2px solid #1a1a1a;
    box-shadow: 0 0 0 2px #1a1a1a;
}

.collage-item.crop-mode .resize-handle,
.collage-item.crop-mode .rotate-handle,
.collage-item.crop-mode .delete-handle {
    display: none !important;
}

.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    display: none;
}

.collage-item.crop-mode .crop-overlay {
    display: block;
}

.crop-area {
    position: absolute;
    border: 2px dashed #fff;
    background: transparent;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    pointer-events: all;
    cursor: move;
}

.crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #1a1a1a;
    border: 2px solid white;
    border-radius: 0;
    cursor: nwse-resize;
    touch-action: none;
    z-index: 11;
}

.crop-handle.nw { top: -6px; left: -6px; cursor: nwse-resize; }
.crop-handle.ne { top: -6px; right: -6px; cursor: nesw-resize; }
.crop-handle.sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.crop-handle.se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.crop-handle.n { top: -6px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.crop-handle.s { bottom: -6px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.crop-handle.e { top: 50%; right: -6px; transform: translateY(-50%); cursor: ew-resize; }
.crop-handle.w { top: 50%; left: -6px; transform: translateY(-50%); cursor: ew-resize; }

.crop-buttons {
    position: fixed;
    display: none;
    gap: 12px;
    z-index: 10000;
    pointer-events: all;
    background: rgba(255, 255, 255, 0.98);
    padding: 10px 16px;
    border: 1px solid #1a1a1a;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.collage-item.crop-mode .crop-buttons {
    display: flex;
}

.crop-btn-confirm,
.crop-btn-cancel {
    padding: 8px 20px;
    border: 1px solid #1a1a1a;
    border-radius: 0;
    font-weight: 400;
    cursor: pointer;
    font-size: 0.7em;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    touch-action: manipulation;
    background: white;
    color: #1a1a1a;
    transition: all 0.2s ease;
    pointer-events: all;
}

.crop-btn-confirm:hover {
    background: #1a1a1a;
    color: white;
}

.crop-btn-confirm:active,
.crop-btn-cancel:active {
    transform: scale(0.97);
}

.crop-btn-cancel {
    background: transparent;
    border: 1px solid #cccccc;
    color: #666666;
}

.crop-btn-cancel:hover {
    background: #f0f0f0;
    border-color: #999999;
}

.template-controls {
    display: none;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.template-controls.active {
    display: grid;
}

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

label {
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 0.9em;
}

input[type="number"],
select {
    padding: 10px;
    border: 1px solid #e0e0e0;
    border-radius: 0;
    font-size: 0.85em;
    transition: all 0.3s ease;
    font-family: 'Inter', sans-serif;
    background: white;
}

input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: #1a1a1a;
    background: #fafafa;
}

select {
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%231a1a1a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.toolbar-section input[type="number"],
.toolbar-section select {
    padding: 6px 8px;
    font-size: 0.85em;
    border-radius: 6px;
}

.toolbar-section span {
    color: #999;
    font-weight: 600;
}

.btn {
    background: #1a1a1a;
    color: white;
    border: 1px solid #1a1a1a;
    padding: 12px 32px;
    border-radius: 0;
    font-size: 0.75em;
    font-weight: 400;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin: 5px;
    touch-action: manipulation;
}

.btn:hover {
    background: transparent;
    color: #1a1a1a;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: #cccccc;
    border-color: #cccccc;
    color: #ffffff;
}

.btn:disabled:hover {
    background: #cccccc;
    color: #ffffff;
}

.btn-secondary {
    background: transparent;
    border: 1px solid #999999;
    color: #666666;
}

.btn-secondary:hover {
    background: #f0f0f0;
}

.btn-success {
    background: #1a1a1a;
}

.btn-danger {
    background: transparent;
    border: 1px solid #999999;
    color: #666666;
}

.unified-toolbar {
    display: none;
    flex-direction: column;
    gap: 12px;
    padding: 15px;
    background: linear-gradient(135deg, #f8f9ff 0%, #ffffff 100%);
    border-radius: 15px;
    margin: 0 0 15px 0;
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.1);
}

.unified-toolbar.active {
    display: flex;
}

.toolbar-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.toolbar-section {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
    padding: 8px 12px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.toolbar-label {
    font-size: 0.8em;
    color: #667eea;
    font-weight: 700;
    margin-right: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.85em;
}

.btn-icon {
    padding: 8px 12px;
    font-size: 1.1em;
    min-width: 40px;
}

.upload-section-compact {
    display: flex;
    justify-content: center;
    align-items: center;
}

.image-preview {
    display: none;
}

.preview-item {
    display: none;
}

.remove-btn {
    display: none;
}

.collage-result {
    margin-top: 20px;
    text-align: center;
}

.collage-result img {
    max-width: 100%;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.loading {
    display: none;
    text-align: center;
    padding: 60px 20px;
}

.loading.active {
    display: block;
}

.loading p {
    font-size: 0.75em;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #666666;
    margin-top: 20px;
}

.spinner {
    border: 2px solid #f0f0f0;
    border-top: 2px solid #1a1a1a;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.collage-result h3 {
    font-family: 'Playfair Display', serif;
    font-size: 2em;
    font-weight: 400;
    letter-spacing: 0.05em;
    margin-bottom: 30px;
    color: #1a1a1a;
}

.collage-result img {
    border: 1px solid #e8e8e8;
    max-width: 100%;
}

.download-btn {
    margin-top: 30px !important;
    display: inline-block;
    text-decoration: none;
}

.error {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.98);
    color: #1a1a1a;
    padding: 16px 32px;
    border-radius: 0;
    border: 1px solid #1a1a1a;
    display: none;
    font-size: 0.75em;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    z-index: 10000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.error.active {
    display: block;
    animation: slideDown 0.3s ease;
}

.success {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.98);
    color: #1a1a1a;
    padding: 16px 32px;
    border-radius: 0;
    border: 1px solid #1a1a1a;
    display: none;
    font-size: 0.75em;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    z-index: 10000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.success.active {
    display: block;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translate(-50%, -10px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@media (max-width: 768px) {
    html, body {
        margin: 0;
        padding: 0;
        height: 100%;
        overflow: hidden;
        position: fixed;
        width: 100%;
    }

    .container {
        height: 100vh;
        height: 100dvh;
    }

    header {
        height: 48px;
        min-height: 48px;
    }

    .header-brand {
        padding: 0 12px;
        min-width: auto;
    }

    h1 {
        font-size: 0.9em;
        letter-spacing: 0.05em;
    }

    .header-bar {
        flex-wrap: nowrap;
        overflow-x: visible;
    }

    .dropdown-toggle, .upload-area {
        padding: 0 12px;
        min-width: auto;
    }

    .menu-icon {
        display: block;
        font-size: 1.2em;
    }

    .menu-text {
        display: none;
    }

    .upload-area span {
        display: none;
    }

    .upload-area::before {
        content: "\1f4e4";
        font-size: 1.2em;
    }

    .error, .success {
        top: 58px;
        font-size: 0.7em;
        padding: 10px 16px;
    }
}
