* { box-sizing: border-box; }

:root {
    --primary: #30AFFF;
    --primary-hover: #0088E6;
    --bg: #f6f7f9;
    --text: #333333;
    --text-light: #666666;
    --white: #ffffff;
    --border: #dddddd;
    --success: #16a34a;
    --error: #dc2626;
    --radius: 8px;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

body.no-scroll {
    overflow: hidden;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 20px;
}

.site-header {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 0;
}

.site-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.logo {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.main-nav a {
    margin-left: 1.25rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 500;
}

.main-nav a:hover {
    color: var(--primary);
}

.tool-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem 1.5rem 1.5rem;
    margin: 1rem auto;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    text-align: center;
}

.tool-card h1 {
    margin: 0 0 0.25rem 0;
    font-size: 1.5rem;
    color: var(--text);
}

.subtitle {
    color: var(--text-light);
    margin: 0 0 1rem 0;
    font-size: 0.95rem;
}

.tool-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    text-align: left;
}

.tool-layout.has-file {
    grid-template-columns: 1.15fr 0.85fr;
    align-items: start;
}

.drop-zone {
    border: 2px dashed var(--primary);
    border-radius: var(--radius);
    padding: 2rem 1rem;
    background: #f0f9ff;
    transition: background 0.3s, border-color 0.3s;
    cursor: pointer;
    text-align: center;
}

.drop-zone.dragover {
    background: #e0f2fe;
    border-color: var(--primary-hover);
}

.drop-zone.has-file {
    padding: 1rem;
    cursor: default;
}

.supported-formats {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 0.9rem;
    margin-bottom: 0;
}

.replace-hint {
    font-size: 0.78rem;
    color: var(--text-light);
    margin: 0.5rem 0 0 0;
}

.upload-status {
    margin: 0.6rem 0 0.1rem 0;
    font-weight: 700;
    font-size: 0.95rem;
    min-height: 1.3rem;
}

.upload-status.success {
    color: var(--success);
}

.upload-status.error {
    color: var(--error);
}

.file-name {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-light);
    word-break: break-all;
}

.file-info {
    font-size: 0.8rem;
    color: var(--text-light);
    margin: 0.2rem 0 0 0;
    font-weight: 600;
}

.savings-badge {
    display: inline-block;
    margin: 0.4rem auto 0 auto;
    padding: 2px 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.savings-badge.good {
    background: #e8f7ee;
    color: var(--success);
}

.savings-badge.bad {
    background: #fff4e5;
    color: #b45309;
}

.btn {
    display: inline-block;
    padding: 0.65rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, opacity 0.2s;
    text-align: center;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    font-size: 0.9rem;
}

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

.btn-block {
    display: block;
    width: 100%;
    margin-top: 0.75rem;
}

.btn-disabled {
    opacity: 0.55;
    pointer-events: none;
    background: #9bb9cc;
}

.hidden {
    display: none !important;
}

.controls {
    text-align: left;
}

.main-input {
    margin-bottom: 0.9rem;
}

.lock-hint {
    font-size: 0.8rem;
    color: var(--text);
    background: #f0f9ff;
    border: 1px solid #cfe9ff;
    border-radius: var(--radius);
    padding: 0.4rem 0.6rem;
    margin: 0.75rem 0 0.6rem 0;
}

.dimensions-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
}

.dimensions-wrapper .form-group {
    flex: 1;
    margin-bottom: 0;
}

.lock-btn {
    background: #f0f9ff;
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    font-size: 1.05rem;
    padding: 0.55rem 0.7rem;
    cursor: pointer;
    margin-bottom: 2px;
}

.lock-btn.unlocked {
    background: #fff4f4;
    border-color: var(--error);
}

.ratio-hint {
    font-size: 0.8rem;
    color: var(--text-light);
    margin: 0.5rem 0 0 0;
}

.ratio-hint.warn {
    color: var(--error);
    font-weight: 600;
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
}

.processing-status {
    font-size: 0.88rem;
    color: var(--primary);
    min-height: 1.3rem;
    margin: 0.6rem 0 0 0;
    text-align: center;
    font-weight: 600;
}

.processing-status.ready {
    color: var(--success);
}

.compare-view {
    position: relative;
    width: 100%;
    max-height: min(42vh, 380px);
    min-height: 160px;
    margin: 0 auto;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--white);
    touch-action: none;
    cursor: ew-resize;
    user-select: none;
}

.compare-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    pointer-events: none;
}

.compare-top {
    clip-path: inset(0 0 0 50%);
}

.compare-divider {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 3px;
    background: var(--white);
    box-shadow: 0 0 6px rgba(0,0,0,0.45);
    transform: translateX(-50%);
    pointer-events: none;
}

.compare-handle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

.compare-label {
    position: absolute;
    bottom: 8px;
    padding: 2px 10px;
    border-radius: 999px;
    background: rgba(0,0,0,0.55);
    color: var(--white);
    font-size: 0.72rem;
    font-weight: 700;
    pointer-events: none;
}

.label-left {
    left: 8px;
}

.label-right {
    right: 8px;
}

.viewer-expand {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 6px;
    background: rgba(0,0,0,0.55);
    color: var(--white);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.viewer-expand:hover {
    background: rgba(0,0,0,0.75);
}

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.lightbox-inner {
    position: relative;
}

.lightbox-view {
    width: 80vw;
    height: 80vh;
    max-height: none;
    min-height: 0;
    cursor: ew-resize;
}

.lightbox-close {
    position: absolute;
    top: -40px;
    right: 0;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 6px;
    background: rgba(255,255,255,0.9);
    color: var(--text);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

.lightbox-close:hover {
    background: var(--white);
}

.site-footer {
    background: var(--white);
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    margin-top: 2rem;
    text-align: center;
}

.footer-links {
    margin-bottom: 0.75rem;
}

.footer-links a {
    margin: 0 0.75rem;
    text-decoration: none;
    color: var(--text-light);
    font-size: 0.9rem;
}

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

@media (max-width: 900px) {
    .tool-layout.has-file {
        grid-template-columns: 1fr;
    }
    .compare-view {
        max-height: 45vh;
    }
}

@media (max-width: 600px) {
    .site-header .container {
        flex-direction: column;
        text-align: center;
    }
    .main-nav a {
        margin: 0 0.5rem;
    }
    .tool-card {
        padding: 1rem;
    }
    .dimensions-wrapper {
        flex-direction: column;
        align-items: stretch;
    }
    .lock-btn {
        align-self: center;
        margin: 0.25rem 0;
    }
    .lightbox-view {
        width: 92vw;
        height: 70vh;
    }
}