/* === Reset & Base === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-page: #F3EBD3;
    --bg-card: #FFFDF5;
    --bg-card-hover: #fff;
    --border: #d4c9b0;
    --border-dash: #AAAAAA;
    --text-primary: #5A4235;
    --text-secondary: #8a7560;
    --accent: #6B4E3D;
    --accent-hover: #8a6a56;
    --accent-rose: #e8a0b4;
    --fg-green: #8BA888;
    --fg-green-bright: #6dbd6d;
    --bg-red: #f87171;
    --shadow-pixel: 4px 4px 0px 0px rgba(0, 0, 0, 0.12);
    --shadow-pixel-hover: 2px 2px 0px 0px rgba(0, 0, 0, 0.12);
    --transition: 150ms ease;
    --font-pixel: 'Press Start 2P', cursive;
    --font-retro: 'VT323', monospace;
}

/* === Dark Mode === */
html.dark {
    --bg-page: #2D2420;
    --bg-card: #3E322C;
    --bg-card-hover: #4a3d35;
    --border: #5a4a3e;
    --border-dash: #666666;
    --text-primary: #EAD8C0;
    --text-secondary: #b39e87;
    --accent: #EAD8C0;
    --accent-hover: #f5ead8;
    --accent-rose: #d48fa5;
    --fg-green: #a3c4a0;
    --fg-green-bright: #8ddb8d;
    --shadow-pixel: 4px 4px 0px 0px rgba(0, 0, 0, 0.3);
    --shadow-pixel-hover: 2px 2px 0px 0px rgba(0, 0, 0, 0.3);
}

html, body {
    height: 100%;
    font-family: var(--font-retro);
    font-size: 20px;
    background: var(--bg-page);
    color: var(--text-primary);
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

.font-pixel {
    font-family: var(--font-pixel);
}

/* === Privacy Banner === */
.privacy-banner {
    background: var(--accent);
    color: var(--bg-page);
    padding: 8px 16px;
    text-align: center;
    font-family: var(--font-retro);
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

html.dark .privacy-banner {
    background: #1e1714;
    color: #EAD8C0;
}

/* === Site Header === */
.site-header {
    position: relative;
    width: 100%;
    padding: 32px 24px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    z-index: 5;
}

.site-title {
    font-size: 36px;
    color: var(--accent);
    letter-spacing: -1px;
    cursor: default;
    user-select: none;
    transition: transform 0.2s ease;
    filter: drop-shadow(2px 2px 0 rgba(0,0,0,0.08));
}

.site-title:hover {
    transform: scale(1.05);
}

.site-badges {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 8px;
    gap: 4px 8px;
    font-family: var(--font-retro);
    font-size: 20px;
    color: var(--text-secondary);
}

.site-badges span {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.site-badges span + span::before {
    content: '·';
    margin-right: 8px;
    color: var(--border);
    font-style: normal;
}

.site-quote {
    font-family: var(--font-retro);
    font-size: 18px;
    color: var(--text-secondary);
    opacity: 0.55;
    letter-spacing: 0.5px;
}

/* === Dark Mode Toggle === */
.dark-toggle {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--bg-card);
    box-shadow: var(--shadow-pixel);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    color: var(--accent);
}

.dark-toggle:hover {
    box-shadow: var(--shadow-pixel-hover);
    transform: translateY(2px);
}

.dark-toggle:active {
    transform: translateY(3px);
}

.dark-toggle .dark-icon { display: none; }
html.dark .dark-toggle .light-icon { display: none; }
html.dark .dark-toggle .dark-icon { display: block; color: #f6c644; }

/* === States === */
.state {
    display: none;
    width: 100%;
    height: calc(100% - 120px); /* subtract header height */
}

.state.active {
    display: flex;
}

/* === Landing / Upload === */
#landing {
    align-items: center;
    justify-content: center;
}

.landing-inner {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    width: 100%;
    max-width: 460px;
    padding: 32px 24px 60px;
}

.landing-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
}

.mascot-img {
    width: 200px;
    height: 200px;
    object-fit: contain;
    filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.15));
    transition: transform 0.3s ease;
}

.mascot-img:hover {
    transform: scale(1.1);
}

.landing-header h1 {
    font-size: 20px;
    line-height: 1.6;
    color: var(--accent);
    letter-spacing: 1px;
}

.subtitle {
    font-size: 22px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* === Drop Zone (dashed box style from pixl.pet) === */
.drop-zone {
    position: relative;
    width: 100%;
    cursor: pointer;
    transition: all var(--transition);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-align: center;
    padding: 48px 40px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.5);
    transition: all var(--transition);
    /* Dashed border via SVG background */
    background-image: url("data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='12' ry='12' stroke='%23AAAAAA' stroke-width='3' stroke-dasharray='12%2c 12' stroke-dashoffset='0' stroke-linecap='square'/%3e%3c/svg%3e");
}

html.dark .drop-zone-content {
    background: rgba(0, 0, 0, 0.2);
    background-image: url("data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='12' ry='12' stroke='%23666666' stroke-width='3' stroke-dasharray='12%2c 12' stroke-dashoffset='0' stroke-linecap='square'/%3e%3c/svg%3e");
}

.drop-zone-content:hover {
    background-color: rgba(255, 255, 255, 0.9);
    background-image: url("data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='12' ry='12' stroke='%236B4E3D' stroke-width='3' stroke-dasharray='12%2c 12' stroke-dashoffset='0' stroke-linecap='square'/%3e%3c/svg%3e");
}

html.dark .drop-zone-content:hover {
    background-color: rgba(0, 0, 0, 0.4);
    background-image: url("data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='12' ry='12' stroke='%23EAD8C0' stroke-width='3' stroke-dasharray='12%2c 12' stroke-dashoffset='0' stroke-linecap='square'/%3e%3c/svg%3e");
}

.drop-zone.drag-over .drop-zone-content {
    background-color: rgba(255, 255, 255, 0.95);
    background-image: url("data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='12' ry='12' stroke='%236B4E3D' stroke-width='3' stroke-dasharray='12%2c 12' stroke-dashoffset='0' stroke-linecap='square'/%3e%3c/svg%3e");
}

.drop-icon {
    font-size: 36px;
    color: var(--accent-rose);
    transition: color var(--transition);
}

.drop-zone-content:hover .drop-icon {
    color: var(--accent);
}

.drop-label {
    font-family: var(--font-pixel);
    font-size: 12px;
    font-weight: 700;
}

.drop-hint {
    font-size: 16px;
    color: var(--text-secondary);
    opacity: 0.7;
}

/* === Model Status === */
.model-status {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
    font-size: 14px;
    font-family: var(--font-retro);
}

.model-status.loaded .model-progress-ring .ring-fill {
    stroke: var(--fg-green);
    stroke-dashoffset: 0;
}

.model-status.loaded .ring-pct {
    color: var(--fg-green-bright);
    font-size: 14px;
}

.model-status-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#model-status-label {
    font-size: 16px;
}

.model-status-detail {
    font-size: 14px;
    opacity: 0.7;
}

/* === Progress Ring (landing page) === */
.model-progress-ring {
    position: relative;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.model-progress-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.model-progress-ring .ring-bg {
    fill: none;
    stroke: var(--border);
    stroke-width: 3;
}

.model-progress-ring .ring-fill {
    fill: none;
    stroke: var(--accent);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 100.53;
    stroke-dashoffset: 100.53;
    transition: stroke-dashoffset 0.3s ease;
}

.ring-pct {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-retro);
}

/* === Download Overlay (processing state) === */
.download-overlay {
    position: absolute;
    inset: 0;
    background: rgba(45, 36, 32, 0.88);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(4px);
}

html.dark .download-overlay {
    background: rgba(30, 23, 20, 0.92);
}

.download-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    text-align: center;
}

.download-overlay-content p {
    color: #EAD8C0;
    font-size: 18px;
    font-weight: 500;
    font-family: var(--font-retro);
}

.download-overlay-detail {
    font-size: 15px !important;
    font-weight: 400 !important;
    color: #b39e87 !important;
}

.download-ring {
    position: relative;
    width: 64px;
    height: 64px;
}

.download-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.download-ring .ring-bg {
    fill: none;
    stroke: #5a4a3e;
    stroke-width: 4;
}

.download-ring .ring-fill {
    fill: none;
    stroke: var(--accent-rose);
    stroke-width: 4;
    stroke-linecap: round;
    stroke-dasharray: 163.36;
    stroke-dashoffset: 163.36;
    transition: stroke-dashoffset 0.3s ease;
}

.download-ring-pct {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: #EAD8C0;
    font-family: var(--font-retro);
}

/* === Spinner (kept for compatibility) === */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* === Processing === */
#processing {
    align-items: center;
    justify-content: center;
}

.processing-container {
    position: relative;
    max-width: 80%;
    max-height: 80%;
}

.processing-container canvas {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 12px;
    display: block;
    box-shadow: var(--shadow-pixel);
}

/* Cream veil that fades out as progress increases */
.processing-overlay {
    position: absolute;
    inset: 0;
    background: rgba(243, 235, 211, var(--reveal, 1));
    border-radius: 12px;
    transition: background 0.6s ease;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 32px;
}

html.dark .processing-overlay {
    background: rgba(45, 36, 32, var(--reveal, 1));
}

/* Animated shimmer sweep */
.shimmer {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        105deg,
        transparent 40%,
        rgba(255, 255, 255, 0.4) 50%,
        transparent 60%
    );
    background-size: 200% 100%;
    animation: shimmer 2s ease-in-out infinite;
    pointer-events: none;
}

@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Status bar inside the overlay */
.processing-status-bar {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 80%;
    max-width: 320px;
}

.processing-status-bar p {
    color: var(--accent);
    font-size: 18px;
    font-weight: 600;
    text-align: center;
    font-family: var(--font-retro);
    text-shadow: 0 0 12px rgba(243, 235, 211, 0.8);
}

html.dark .processing-status-bar p {
    color: #EAD8C0;
    text-shadow: 0 0 12px rgba(45, 36, 32, 0.8);
}

.progress-track {
    width: 100%;
    height: 6px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

html.dark .progress-track {
    background: rgba(255, 255, 255, 0.1);
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* === Result Screen === */
#result {
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 24px;
}

.result-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    max-width: 90%;
    max-height: 85%;
    animation: resultFadeIn 0.5s ease;
}

@keyframes resultFadeIn {
    from { opacity: 0; transform: scale(0.97); }
    to   { opacity: 1; transform: scale(1); }
}

.result-canvas-wrap {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-pixel);
    /* Default: light transparent (checkerboard) */
    background-image:
        linear-gradient(45deg, #e0d8c0 25%, transparent 25%),
        linear-gradient(-45deg, #e0d8c0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e0d8c0 75%),
        linear-gradient(-45deg, transparent 75%, #e0d8c0 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    background-color: #f5eed8;
}

.result-canvas-wrap[data-bg="dark"] {
    background-color: #3E322C;
    background-image:
        linear-gradient(45deg, #4a3d35 25%, transparent 25%),
        linear-gradient(-45deg, #4a3d35 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #4a3d35 75%),
        linear-gradient(-45deg, transparent 75%, #4a3d35 75%);
}

.result-canvas-wrap[data-bg="white"] {
    background: #ffffff;
    background-image: none;
}

.result-canvas-wrap[data-bg="grey"] {
    background: #3E322C;
    background-image: none;
}

.result-canvas-wrap canvas {
    display: block;
    max-width: 100%;
    max-height: 60vh;
}

.result-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

/* Background toggle circles */
.bg-toggles {
    display: flex;
    gap: 10px;
}

.bg-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid transparent;
    background: transparent;
    padding: 3px;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.bg-toggle:hover {
    transform: scale(1.1);
}

.bg-toggle.active {
    border-color: var(--accent);
}

.bg-swatch {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.bg-swatch.light-trans {
    background-image:
        linear-gradient(45deg, #ddd 25%, transparent 25%),
        linear-gradient(-45deg, #ddd 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ddd 75%),
        linear-gradient(-45deg, transparent 75%, #ddd 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0;
    background-color: #f5f5f5;
}

.bg-swatch.dark-trans {
    background-image:
        linear-gradient(45deg, #444 25%, transparent 25%),
        linear-gradient(-45deg, #444 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #444 75%),
        linear-gradient(-45deg, transparent 75%, #444 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0;
    background-color: #2a2a2a;
}

.bg-swatch.white-solid {
    background: #ffffff;
}

.bg-swatch.grey-solid {
    background: #3E322C;
}

/* Result action buttons */
.result-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
}

.result-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: var(--font-retro);
    box-shadow: var(--shadow-pixel);
}

.result-btn:hover {
    box-shadow: var(--shadow-pixel-hover);
    transform: translateY(2px);
}

.result-btn.primary {
    background: var(--accent);
    color: var(--bg-page);
}

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

.result-btn.ghost {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.result-btn.ghost:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
}

/* === Footer === */
footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 10px 16px;
    text-align: center;
    font-size: 16px;
    font-family: var(--font-retro);
    color: var(--text-secondary);
    background: transparent;
    pointer-events: none;
    z-index: 100;
}

footer a {
    color: var(--text-secondary);
    text-decoration: none;
    pointer-events: auto;
}

footer a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.heart {
    color: #e55;
    font-size: 18px;
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-page);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* === Responsive === */
@media (max-width: 768px) {
    .site-header {
        padding: 20px 16px 12px;
    }

    .site-title {
        font-size: 26px;
    }

    .site-badges {
        font-size: 16px;
        gap: 2px 6px;
    }

    .site-quote {
        font-size: 15px;
    }

    .dark-toggle {
        top: 12px;
        right: 12px;
        width: 38px;
        height: 38px;
    }

    .landing-inner {
        padding: 16px 16px 60px;
    }

    .mascot-img {
        width: 120px;
        height: 120px;
    }

    .landing-header h1 {
        font-size: 16px;
    }

    .subtitle {
        font-size: 18px;
    }

    .drop-label {
        font-size: 10px;
    }

    .privacy-banner {
        font-size: 14px;
        padding: 6px 12px;
    }
}
