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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    color: #fff;
    overflow-x: hidden;
}

html {
    height: -webkit-fill-available;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

header {
    text-align: center;
    margin-bottom: 1.5rem;
}

header h1 {
    font-size: 2rem;
    margin-bottom: 0.3rem;
    background: linear-gradient(90deg, #00d2ff, #3a7bd5);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: #888;
    font-size: 1rem;
}

/* Upload Zone */
.upload-zone {
    border: 3px dashed #3a7bd5;
    border-radius: 16px;
    padding: 3rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(58, 123, 213, 0.1);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: #00d2ff;
    background: rgba(0, 210, 255, 0.15);
}

.upload-icon {
    font-size: 3.5rem;
    margin-bottom: 1rem;
}

.upload-content p {
    color: #aaa;
    font-size: 1rem;
    line-height: 1.5;
}

.upload-content strong {
    color: #00d2ff;
}

.privacy-notice {
    text-align: center;
    color: #666;
    font-size: 0.85rem;
    margin-top: 1rem;
}

.paste-btn {
    margin-top: 1rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    background: linear-gradient(90deg, #00d2ff, #3a7bd5);
    border: none;
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.paste-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(0, 210, 255, 0.4);
}

.paste-btn:active {
    transform: scale(0.98);
}

/* Editor */
.editor {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 1rem;
}

/* Toolbar */
.toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.toolbar-simple {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.toolbar-simple .tool-group {
    flex: 0 0 auto;
}

.toolbar-advanced {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1rem;
    margin-top: 0;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tool-group:nth-child(3) {
    grid-column: 1 / -1;
}

.tool-group:nth-child(4) {
    grid-column: 1 / -1;
}

.tool-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.95rem;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    flex: 1;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.tool-btn:active {
    transform: scale(0.96);
}

.tool-btn.active {
    background: #3a7bd5;
    border-color: #3a7bd5;
}

.tool-btn.primary {
    background: linear-gradient(90deg, #00d2ff, #3a7bd5);
    border: none;
    font-weight: 600;
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
    min-height: 56px;
}

.tool-btn.primary:hover {
    box-shadow: 0 4px 20px rgba(0, 210, 255, 0.4);
}

.tool-btn.primary:active {
    transform: scale(0.98);
}

/* Brush size control */
.brush-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.5rem 1rem;
    border-radius: 10px;
}

.brush-control label {
    color: #aaa;
    font-size: 0.9rem;
    white-space: nowrap;
}

input[type="range"] {
    flex: 1;
    height: 36px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #00d2ff, #3a7bd5);
    border-radius: 50%;
    margin-top: -10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

input[type="range"]::-moz-range-track {
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

input[type="range"]::-moz-range-thumb {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #00d2ff, #3a7bd5);
    border-radius: 50%;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#brushSizeLabel {
    color: #fff;
    min-width: 45px;
    text-align: right;
    font-weight: 500;
}

/* Canvas */
.canvas-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    touch-action: none;
}

#canvas {
    max-width: 100%;
    max-height: 60vh;
    cursor: default;
    touch-action: none;
}

/* Actions */
.actions {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1rem;
}

.actions button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 0.9rem 1.25rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
    min-height: 48px;
}

.actions button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.actions button:active {
    transform: scale(0.96);
}

/* Loading */
.loading {
    text-align: center;
    padding: 3rem 1rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: #3a7bd5;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading #progressStage {
    color: #fff;
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.progress-container {
    width: 100%;
    max-width: 400px;
    height: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    margin: 0 auto 0.5rem;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #00d2ff, #3a7bd5);
    border-radius: 6px;
    transition: width 0.3s ease;
}

.progress-percent {
    color: #888;
    font-size: 0.9rem;
}

/* Results */
.result {
    margin-top: 1.5rem;
}

.result h3 {
    text-align: center;
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.comparison {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.compare-item {
    text-align: center;
    flex: 1;
    min-width: 0;
}

.compare-item img {
    max-width: 100%;
    max-height: 35vh;
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    object-fit: contain;
}

.compare-item span {
    display: block;
    margin-top: 0.5rem;
    color: #888;
    font-size: 0.9rem;
}

/* Mobile-specific styles */
@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }

    header {
        margin-bottom: 1rem;
    }

    header h1 {
        font-size: 1.6rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .upload-zone {
        padding: 2rem 1rem;
        min-height: 180px;
    }

    .upload-icon {
        font-size: 2.5rem;
    }

    .upload-content p {
        font-size: 0.95rem;
    }

    .editor {
        padding: 0.75rem;
        border-radius: 12px;
    }

    /* Mobile toolbar - vertical stacking */
    .toolbar {
        display: flex;
        flex-direction: column;
        gap: 0.6rem;
    }

    .tool-group {
        width: 100%;
    }

    .tool-group:first-child {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .tool-group:nth-child(2) {
        width: 100%;
    }

    .brush-control {
        width: 100%;
    }

    .tool-group:nth-child(3) {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .tool-btn {
        padding: 0.7rem 0.75rem;
        font-size: 0.9rem;
        min-height: 46px;
    }

    .tool-btn.primary {
        padding: 0.9rem 1rem;
        font-size: 1rem;
        min-height: 52px;
    }

    #canvas {
        max-height: 50vh;
    }

    .actions {
        flex-direction: row;
    }

    .actions button {
        flex: 1;
        padding: 0.8rem 1rem;
        font-size: 0.95rem;
    }

    .comparison {
        flex-direction: column;
        align-items: stretch;
    }

    .compare-item {
        width: 100%;
    }

    .compare-item img {
        max-height: 30vh;
        width: 100%;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .container {
        padding: 0.75rem;
    }

    header {
        margin-bottom: 0.5rem;
    }

    header h1 {
        font-size: 1.4rem;
    }

    .subtitle {
        display: none;
    }

    .toolbar {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .tool-group {
        width: auto;
    }

    #canvas {
        max-height: 45vh;
    }

    .comparison {
        flex-direction: row;
    }

    .compare-item img {
        max-height: 35vh;
    }
}

/* Tablet */
@media (min-width: 601px) and (max-width: 900px) {
    .toolbar {
        grid-template-columns: repeat(4, auto);
        justify-content: start;
    }

    .tool-group:nth-child(3),
    .tool-group:nth-child(4) {
        grid-column: auto;
    }
}

/* Desktop */
@media (min-width: 901px) {
    .container {
        padding: 2rem;
    }

    header h1 {
        font-size: 2.5rem;
    }

    .subtitle {
        font-size: 1.1rem;
    }

    .upload-zone {
        padding: 4rem 2rem;
    }

    .upload-zone:hover {
        transform: scale(1.01);
    }

    .editor {
        padding: 1.5rem;
    }

    .toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 1rem;
    }

    .tool-group:nth-child(3),
    .tool-group:nth-child(4) {
        grid-column: auto;
    }

    #canvas {
        max-height: 65vh;
    }

    .compare-item img {
        max-height: 400px;
    }
}
