* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "MS Sans Serif", "Segoe UI", Tahoma, sans-serif;
    font-size: 11px;
    background: #008080;
    color: #000;
    min-height: 100vh;
    padding: 16px;
    overflow-x: hidden;
}

.window {
    background: #c0c0c0;
    border: 1px solid;
    border-color: #dfdfdf #808080 #808080 #dfdfdf;
    box-shadow: 2px 2px 0 #000;
    max-width: 400px;
    width: 100%;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    user-select: none;
}

.title-bar {
    background: linear-gradient(90deg, #000080 0%, #1084d0 100%);
    color: #fff;
    padding: 2px 4px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: move;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

.title-btn {
    background: transparent;
    border: 1px solid transparent;
    color: #fff;
    cursor: pointer;
    padding: 0 6px;
    font-size: 14px;
    flex-shrink: 0;
}

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

.title {
    margin-left: 2px;
}

.toolbar {
    display: flex;
    gap: 2px;
    padding: 4px;
    background: #c0c0c0;
    border-bottom: 1px solid #808080;
}

.tool-btn {
    padding: 2px 12px;
    font-size: 11px;
    background: #c0c0c0;
    color: #000;
    border: 1px solid;
    border-color: #dfdfdf #808080 #808080 #dfdfdf;
    cursor: pointer;
}

.tool-btn:hover {
    background: #d4d0c8;
}

.tool-btn.active {
    border-color: #808080 #dfdfdf #dfdfdf #808080;
    background: #a0a0a0;
    box-shadow: inset 1px 1px 2px #606060;
    font-weight: bold;
}

.palette-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: #c0c0c0;
    border-bottom: 1px solid #808080;
}

.palette-label {
    font-size: 11px;
}

.palette-bar select {
    padding: 2px 4px;
    font-size: 11px;
    background: #fff;
    border: 1px solid #808080;
}

.content {
    padding: 8px;
    background: #fff;
    border: 1px solid #808080;
    margin: 4px;
    min-height: 280px;
}

.section.hidden {
    display: none;
}

.upload-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.drop-zone {
    border: 2px dashed #808080;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    background: #fff;
}

.drop-zone:hover,
.drop-zone.dragover {
    background: #f0f0f0;
}

.drop-text {
    font-size: 11px;
    color: #404040;
}

.btn {
    padding: 4px 12px;
    font-size: 11px;
    background: #c0c0c0;
    color: #000;
    border: 1px solid;
    border-color: #dfdfdf #808080 #808080 #dfdfdf;
    cursor: pointer;
    align-self: flex-start;
}

.btn:hover:not(:disabled) {
    background: #d4d0c8;
}

.btn:disabled {
    color: #808080;
    cursor: default;
    border-color: #808080 #dfdfdf #dfdfdf #808080;
}

.btn:active:not(:disabled) {
    border-color: #808080 #dfdfdf #dfdfdf #808080;
    box-shadow: inset 1px 1px 0 #000;
}

.camera-controls {
    margin-bottom: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.crop-mode-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.crop-mode-bar select {
    padding: 2px 4px;
    font-size: 11px;
    background: #fff;
    border: 1px solid #808080;
    min-height: 28px;
}

.canvas-frame {
    border: 1px solid #808080;
    padding: 4px;
    background: #fff;
    display: inline-block;
    margin-bottom: 8px;
    max-width: 100%;
}

.camera-frame {
    display: flex;
    justify-content: center;
}

.preview,
#camera-canvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.preview {
    max-width: 100%;
}

#camera-canvas {
    max-width: 100%;
    width: auto;
    height: auto;
    border-radius: 8px;
    background: #111;
}

.result .toolbar {
    border-bottom: none;
}

.status-bar {
    background: #c0c0c0;
    border-top: 1px solid #808080;
    padding: 2px 4px;
    font-size: 11px;
    color: #000;
}

.error {
    margin: 4px 8px 8px;
    padding: 4px 8px;
    background: #fff;
    border: 1px solid #f00;
    color: #f00;
    font-size: 11px;
}

.error.hidden {
    display: none;
}

.hidden {
    display: none !important;
}

#fullscreen-target:fullscreen,
#fullscreen-target:-webkit-full-screen {
    max-width: 100%;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    transform: none;
}

#fullscreen-target:fullscreen .preview,
#fullscreen-target:fullscreen #camera-canvas,
#fullscreen-target:-webkit-full-screen .preview,
#fullscreen-target:-webkit-full-screen #camera-canvas {
    width: 640px;
    height: 480px;
    max-width: 90vw;
    max-height: 70vh;
}

#fullscreen-target:fullscreen .content,
#fullscreen-target:-webkit-full-screen .content {
    min-height: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

@media (max-width: 480px) {
    body {
        padding: 8px;
    }

    .window {
        max-width: 100%;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
    }

    .btn, .tool-btn {
        min-height: 44px;
        padding: 8px 16px;
    }

    #camera-canvas-frame {
        max-width: min(100vw - 24px, 400px);
        margin: 0 auto;
    }

    .crop-mode-bar select {
        min-height: 44px;
        padding: 8px 12px;
        font-size: 14px;
    }

    .content {
        min-height: 240px;
    }
}
