@font-face {
    font-family: 'Kathen';
    src: url('../fonts/kathen.otf') format('opentype');
    font-display: swap;
}

:root {
    --blue: #0077FF;
    --bg: #1C1D1E;
    /* main background */
    --bg-alt: #242628;
    /* subtle alt */
    --panel: #2c2f31;
    /* panels slightly lighter */
    --border: #3a3d40;
    /* borders */
    --accent: var(--blue);
    --accent-hover: #1585ff;
    --text: #FFFFFF;
    --muted: #747E8A;
    --radius: 10px;
    --focus: 0 0 0 2px #fff, 0 0 0 4px var(--accent);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Kathen', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    min-height: 100svh;
}

main {
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

html, body {
    max-width: 100%;
    overflow-x: hidden;
}

h1 {
    font-size: clamp(1.8rem, 4vw, 3rem);
    letter-spacing: 2px;
    margin: 0;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button {
    font: inherit;
    cursor: pointer;
    border: none;
}

button:focus-visible {
    outline: none;
    box-shadow: var(--focus);
}

.site-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.landing {
    height: 100svh;
    width: 100svw;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    text-align: center;
    background: url('../assets/banner.png') repeat center center;
    background-size: cover;
    /* horizontal infinite scroll animation */
    animation: scroll 20s linear infinite;
    background-position: 0 0;
}

@keyframes scroll {
    from {
        background-position: 0 0;
    }
    to {
        background-position: -100% 0;
    }
    to {
        background-position: 100% 0;
    }
}

.tagline {
    font-size: 1rem;
    letter-spacing: 1px;
    color: var(--muted);
    margin: 0 0 1rem;
}

.primary {
    background: var(--accent);
    color: #fff;
    padding: .9rem 2.2rem;
    border-radius: 999px;
    font-weight: 600;
    letter-spacing: 1px;
    transition: .2s background, .2s transform;
}

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

.primary:active {
    transform: scale(.97);
}

.ghost {
    background: var(--panel);
    color: var(--text);
    padding: .6rem 1.1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.ghost:hover {
    background: var(--bg-alt);
}

.icon {
    background: var(--panel);
    border: 1px solid var(--border);
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: var(--accent);
    transition: .2s background, .2s color;
}

.icon:hover {
    background: var(--accent);
    color: #fff;
}

.icon-text {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}

.material-symbols-rounded {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    line-height: 1;
}

.hidden {
    display: none !important;
}

.editor {
    padding: 1rem;
    max-width: 1600px;
    margin: 0 auto;
}

.editor-layout {
    display: grid;
    grid-template-columns: 150px 210px 1fr;
    gap: .6rem;
    padding: .55rem;
    height: calc(100dvh - 140px);
    min-height: 600px;
}

@media (max-width:1400px) {
    .editor-layout {
        grid-template-columns: 140px 200px 1fr;
    }
}

@media (max-width:1280px) {
    .editor-layout {
        grid-template-columns: 130px 180px 1fr;
        gap: .5rem;
        padding: .5rem;
    }
}

@media (max-width:980px) {
    .editor-layout {
        grid-template-columns: 150px 1fr;
        grid-template-rows: auto 1fr;
    }

    .options-panel {
        order: 3;
        grid-column: 1 / -1;
        min-height: 150px;
        max-height: 220px;
        padding: .5rem;
    }
}

@media (max-width:720px) {
    .editor-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
        height: calc(100dvh - 120px);
    }

    nav.categories {
        flex-direction: row;
        overflow-x: auto;
        flex-shrink: 0;
    }

    .options-panel {
        order: 3;
        min-height: 180px;
        max-height: 220px;
        padding: .5rem;
    }

    .canvas-panel {
        order: 2;
        min-height: 320px;
    }

    .thumb {
        min-height: 50px;
        min-width: 50px;
        flex-shrink: 0;
    }

    .actions {
        flex-wrap: wrap;
        justify-content: space-between;
        gap: .5rem;
    }

    /* Better spacing for section dividers on mobile */
    .options-panel > div[style*="grid-column: 1 / -1"] {
        margin: .3rem 0 .1rem 0;
        padding: .2rem 0;
    }
}

@media (max-width:480px) {
    .options-panel {
        padding: .4rem;
        min-height: 160px;
        max-height: 200px;
    }

    .thumb {
        min-height: 48px;
        min-width: 48px;
    }
}

nav.categories {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .5rem;
    display: flex;
    flex-direction: column;
    gap: .4rem;
    overflow-y: auto;
}

nav.categories button {
    background: transparent;
    color: var(--text);
    padding: .6rem .8rem;
    text-align: left;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: .85rem;
    letter-spacing: .5px;
}

nav.categories button.active {
    background: var(--accent);
    color: #fff;
}

nav.categories button:not(.active):hover {
    background: var(--bg-alt);
}

.options-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .5rem;
    overflow: hidden;
}

.options-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: .4rem;
    overflow-y: auto;
    max-height: 100%;
    align-content: start;
    scrollbar-width: thin;
    align-items: start;
}

.thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 1/1;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: .12s border, .12s transform;
}

.thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
}

.thumb:hover {
    border-color: var(--accent);
}

.thumb.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent) inset;
}

.thumb:active {
    transform: scale(.95);
}

.thumb.off-thumb {
    background: var(--bg-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: .55rem;
    letter-spacing: 1px;
}

.thumb.off-thumb.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent) inset;
}

.canvas-panel {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.2rem 2.6rem 1.8rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.4rem;
}

#bunnyCanvas {
    width: 100%;
    height: 100%;
    background: #000;
    image-rendering: pixelated;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    max-width: 836px;
    aspect-ratio: 1/1;
    background: #000;
    border: 1px solid var(--border);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Visual downscale of preview while keeping internal resolution */
.canvas-wrapper.scaled-small {
    max-width: 460px;
}

@media (max-width:1600px) {
    .canvas-wrapper.scaled-small {
        max-width: 440px;
    }
}

@media (max-width:1400px) {
    .canvas-wrapper.scaled-small {
        max-width: 420px;
    }
}

@media (max-width:1280px) {
    .canvas-wrapper.scaled-small {
        max-width: 400px;
    }
}

@media (max-width:1100px) {
    .canvas-wrapper.scaled-small {
        max-width: 360px;
    }
}

@media (max-width:980px) {
    .canvas-wrapper.scaled-small {
        max-width: 320px;
    }
}

@media (max-height:760px) {
    .canvas-wrapper {
        max-width: min(836px, 70vh);
    }
}

@media (max-width:1280px) {
    .canvas-wrapper {
        max-width: min(836px, 65vh);
    }
}

@media (max-height:720px) {
    .canvas-wrapper {
        max-width: min(836px, 60vh);
    }
}

@media (max-width:1100px) {
    .canvas-wrapper {
        max-width: min(760px, 58vh);
    }
}

#bunnyCanvas {
    width: 100%;
    height: 100%;
    background: #000;
}

.loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0009;
    font-size: 1.2rem;
    letter-spacing: 2px;
    backdrop-filter: blur(2px);
}

.actions {
    margin-top: .25rem;
    width: 100%;
    display: flex;
    gap: .6rem;
    justify-content: flex-end;
}

.hint {
    margin-top: .25rem;
    color: var(--muted);
    font-size: .65rem;
    letter-spacing: 1px;
    text-align: center;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--bg-alt);
    border-radius: 20px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Accessibility focus outlines for key sections */


/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none !important;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: #000c;
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: clamp(320px, 70vw, 720px);
    max-height: 85vh;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1rem 1.25rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: 0 10px 40px -10px #000;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.modal-header h2 {
    font-size: 1.1rem;
    margin: 0;
    letter-spacing: 1px;
}

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

.share-text {
    white-space: pre-line;
    font-size: .75rem;
    background: var(--bg-alt);
    padding: .75rem .9rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    flex: 1 1 240px;
    line-height: 1.4;
}

.preview-small {
    flex: 1 1 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 200px;
}

#sharePreview {
    width: 220px;
    height: 220px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #000;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: .6rem;
    flex-wrap: wrap;
}

.close-btn {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: var(--accent);
    color: #fff;
}

.modal-actions .primary,
.modal-actions .ghost {
    height: 42px;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
}