/* ===== RESET ===== */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===== DESIGN TOKENS ===== */

:root {
    --neo-bg: #FFFDF5;
    --neo-fg: #000000;
    --neo-accent: #FF6B6B;
    --neo-secondary: #FFD93D;
    --neo-muted: #C4B5FD;
    --neo-white: #FFFFFF;
    --neo-border: 4px solid #000;
    --neo-shadow-sm: 4px 4px 0px 0px #000;
    --neo-shadow-md: 8px 8px 0px 0px #000;
    --neo-shadow-lg: 12px 12px 0px 0px #000;
    --gap: 12px;
}

/* ===== BASE ===== */

html {
    font-size: 16px;
}

body {
    background: var(--neo-bg);
    color: var(--neo-fg);
    font-family: 'Mochiy Pop One', sans-serif;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-image:
        linear-gradient(to right, rgba(0, 0, 0, 0.035) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0, 0, 0, 0.035) 1px, transparent 1px);
    background-size: 32px 32px;
}

/* ===== HEADER ===== */

header {
    width: 100%;
    background: var(--neo-secondary);
    border-bottom: var(--neo-border);
    padding: 2.5rem 1rem 2rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}

header::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(#000 1px, transparent 1px);
    background-size: 20px 20px;
    opacity: 0.045;
    pointer-events: none;
}

.header-inner {
    position: relative;
    z-index: 1;
}

header h1 {
    font-size: 3.5rem;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--neo-fg);
    text-shadow: 4px 4px 0px var(--neo-accent);
    margin-bottom: 0.4rem;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--neo-fg);
    margin-bottom: 1rem;
}

.header-desc {
    font-size: 0.8rem;
    line-height: 1.8;
    color: var(--neo-fg);
    opacity: 0.7;
}

/* ===== HEADER BADGE ===== */

.header-badge {
    display: inline-block;
    background: var(--neo-accent);
    border: 3px solid #000;
    padding: 0.25rem 0.8rem;
    font-size: 0.75rem;
    box-shadow: 3px 3px 0px 0px #000;
    transform: rotate(3deg);
    margin-bottom: 0.8rem;
    color: #000;
}

/* ===== MAIN ===== */

main {
    width: 100%;
    max-width: 600px;
    padding: 0 1rem 3rem;
}

/* ===== INSTRUCTION ===== */

.instruction {
    display: inline-block;
    background: var(--neo-muted);
    border: 3px solid #000;
    padding: 0.4rem 1rem;
    font-size: 0.8rem;
    margin: 1.5rem 0 1rem;
    box-shadow: 3px 3px 0px 0px #000;
    transform: rotate(-1deg);
}

/* ===== GRID ===== */

.grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--gap);
}

/* ===== SLOT ===== */

.slot {
    position: relative;
    aspect-ratio: 1 / 1.4;
    border: var(--neo-border);
    background: var(--neo-white);
    overflow: hidden;
    cursor: pointer;
    box-shadow: var(--neo-shadow-md);
    transition: transform 200ms ease-out, box-shadow 200ms ease-out;
}

.slot:hover {
    transform: translateY(-4px);
    box-shadow: 12px 12px 0px 0px #000;
}

.slot:active {
    transform: translateY(0px);
    box-shadow: var(--neo-shadow-sm);
}

/* ===== SLOT EMPTY ===== */

.slot-empty {
    width: 100%;
    height: 100%;
    border: 3px dashed #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    background: var(--neo-bg);
    transition: background 100ms;
}

.slot:hover .slot-empty {
    background: var(--neo-secondary);
}

.slot-empty .plus {
    font-size: 2.5rem;
    color: var(--neo-fg);
    line-height: 1;
}

.slot-empty .slot-num {
    font-size: 0.75rem;
    color: var(--neo-fg);
    opacity: 0.5;
}

/* ===== SLOT FILLED ===== */

.slot-filled {
    width: 100%;
    height: 100%;
    position: relative;
}

.slot-filled img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.slot-filled .slot-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--neo-muted);
    color: var(--neo-fg);
    font-size: 0.8rem;
}

.slot-nocover-title {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: var(--neo-white);
    color: var(--neo-fg);
    font-size: 0.8rem;
    text-align: center;
    word-break: break-word;
}

/* ===== SLOT CLEAR ===== */

.slot-clear {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 28px;
    height: 28px;
    border: 3px solid #000;
    background: var(--neo-accent);
    color: #000;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 150ms;
    z-index: 2;
    box-shadow: 2px 2px 0px 0px #000;
}

.slot:hover .slot-clear {
    opacity: 1;
}

.slot-clear:hover {
    background: #ff4444;
}

/* ===== SLOT REMOVE COVER LABEL ===== */

.slot-remove-cover-label {
    position: absolute;
    bottom: 18px;
    left: 0;
    right: 0;
    width: 100%;
    padding: 3px 0;
    background: var(--neo-muted);
    border: none;
    border-top: 2px solid #000;
    border-bottom: 2px solid #000;
    color: #000;
    font-family: 'Mochiy Pop One', sans-serif;
    font-size: 0.6rem;
    text-align: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 150ms;
    z-index: 2;
}

.slot:hover .slot-remove-cover-label {
    opacity: 1;
}

.slot-remove-cover-label:hover {
    background: var(--neo-accent);
}

/* ===== SLOT NAME ===== */

.slot-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 4px 6px;
    background: #000;
    color: #fff;
    font-size: 0.55rem;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-top: 2px solid #000;
}

/* ===== ACTIONS ===== */

.actions {
    margin-top: 1.5rem;
    text-align: center;
}

#generate-btn {
    background: var(--neo-accent);
    color: var(--neo-fg);
    border: var(--neo-border);
    padding: 0.9rem 2.5rem;
    font-size: 1.05rem;
    font-family: 'Mochiy Pop One', sans-serif;
    cursor: pointer;
    box-shadow: 6px 6px 0px 0px #000;
    transition: transform 100ms ease-out, box-shadow 100ms ease-out, background 100ms;
}

#generate-btn:hover:not(:disabled) {
    background: #ff5252;
}

#generate-btn:active:not(:disabled) {
    transform: translate(3px, 3px);
    box-shadow: none;
}

#generate-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#generate-btn.loading {
    pointer-events: none;
    opacity: 0.6;
}

/* ===== RESULT ===== */

.result {
    margin-top: 2rem;
    text-align: center;
}

.result img {
    max-width: 100%;
    border: var(--neo-border);
    box-shadow: var(--neo-shadow-md);
}

.result-actions {
    margin-top: 1.2rem;
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    display: inline-block;
    padding: 0.7rem 1.5rem;
    font-size: 0.85rem;
    font-family: 'Mochiy Pop One', sans-serif;
    text-decoration: none;
    cursor: pointer;
    border: var(--neo-border);
    transition: transform 100ms ease-out, box-shadow 100ms ease-out;
}

.btn:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.btn-download {
    background: var(--neo-secondary);
    color: var(--neo-fg);
    box-shadow: var(--neo-shadow-sm);
}

.btn-download:hover {
    background: #f5cd2a;
}

.btn-share {
    background: #000;
    color: #fff;
    box-shadow: var(--neo-shadow-sm);
}

.btn-share:hover {
    background: #222;
}

/* ===== MODAL ===== */

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 10vh;
}

.modal[hidden] {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}

.modal-content {
    position: relative;
    width: 90%;
    max-width: 480px;
    max-height: 70vh;
    background: var(--neo-white);
    border: var(--neo-border);
    box-shadow: var(--neo-shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    gap: 0.5rem;
    border-bottom: var(--neo-border);
    background: var(--neo-bg);
}

.modal-header input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--neo-fg);
    font-size: 1rem;
    font-family: 'Mochiy Pop One', sans-serif;
    padding: 0.6rem 0.5rem;
}

.modal-header input::placeholder {
    color: rgba(0, 0, 0, 0.35);
}

.modal-close-btn {
    background: #000;
    border: none;
    color: #fff;
    font-size: 1.4rem;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 100ms;
}

.modal-close-btn:hover {
    background: var(--neo-accent);
}

/* ===== SEARCH RESULTS ===== */

.search-results {
    overflow-y: auto;
    flex: 1;
}

.search-hint {
    color: rgba(0, 0, 0, 0.4);
    font-size: 0.8rem;
    text-align: center;
    padding: 2rem 1rem;
}

.search-result {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 2px solid #000;
    transition: background 100ms;
}

.search-result:last-child {
    border-bottom: none;
}

.search-result:hover {
    background: var(--neo-secondary);
}

.search-result-name {
    font-size: 0.9rem;
}

.search-result-meta {
    font-size: 0.7rem;
    color: rgba(0, 0, 0, 0.5);
    margin-top: 0.15rem;
}

.search-no-results {
    color: rgba(0, 0, 0, 0.4);
    font-size: 0.8rem;
    text-align: center;
    padding: 2rem 1rem;
}

/* ===== FOOTER ===== */

footer {
    width: 100%;
    background: #000;
    color: #fff;
    text-align: center;
    padding: 1.5rem 1rem;
    font-size: 0.75rem;
    border-top: var(--neo-border);
    margin-top: auto;
}

footer a {
    color: var(--neo-secondary);
    text-decoration: none;
    border-bottom: 2px solid var(--neo-secondary);
}

footer a:hover {
    color: var(--neo-accent);
    border-color: var(--neo-accent);
}

/* ===== ANIMATIONS ===== */

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* ===== RESPONSIVE ===== */

@media (max-width: 480px) {
    header {
        padding: 1.5rem 1rem 1.25rem;
    }

    header h1 {
        font-size: 2.2rem;
        text-shadow: 3px 3px 0px var(--neo-accent);
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .header-desc {
        font-size: 0.7rem;
    }

    .header-badge {
        font-size: 0.65rem;
        padding: 0.2rem 0.6rem;
    }

    main {
        padding: 0 0.5rem 2rem;
    }

    .instruction {
        font-size: 0.7rem;
        margin: 1rem 0 0.75rem;
    }

    .grid {
        gap: 8px;
    }

    .slot {
        box-shadow: var(--neo-shadow-sm);
    }

    .slot:hover {
        box-shadow: 8px 8px 0px 0px #000;
    }

    .slot-name {
        font-size: 0.5rem;
    }

    #generate-btn {
        padding: 0.75rem 1.5rem;
        font-size: 0.9rem;
        box-shadow: var(--neo-shadow-sm);
    }

    .result img {
        box-shadow: var(--neo-shadow-sm);
    }

    .btn {
        padding: 0.6rem 1.2rem;
        font-size: 0.8rem;
    }
}
