/* RPG Actor - Sprite Generator Styles */

/* ============================================
   PAGE LAYOUT
   ============================================ */

.gen-coming-soon {
    color: var(--ink-light, #8a7a5e);
    font-style: italic;
    text-align: center;
    padding: 1rem 0;
    margin: 0;
}

.generator-page {
    max-width: 1060px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.generator-panel {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

/* ============================================
   CONTROLS (LEFT)
   ============================================ */

.generator-controls {
    flex: 1;
    min-width: 0;
}

.gen-fieldset {
    border: 1px solid var(--ink-light, #5c4a2e);
    padding: 0.75rem 1rem 1rem;
    margin-bottom: 1rem;
}

.gen-fieldset legend {
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0 0.4rem;
    color: var(--ink, #2c2416);
}

/* Body selector: sprite cards side-by-side, ears centered below */
.body-layout {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.body-selector {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.body-picker-col {
    flex: 0 0 230px;
}

.body-type-row {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.body-type-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    padding: 10px 16px;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.body-type-card:hover {
    border-color: var(--ink-light, #5c4a2e);
    background: rgba(44, 36, 22, 0.03);
}

.body-type-card.active {
    border-color: var(--gold, #c9a227);
    background: rgba(201, 162, 39, 0.08);
}

.body-type-thumb {
    width: 96px;
    height: 96px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background-color: rgba(44, 36, 22, 0.03);
}

.body-type-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ink, #2c2416);
    text-align: center;
}

.body-selector .body-toggle {
    margin: 0 auto;
    width: fit-content;
    justify-content: center;
}

.body-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.5rem;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--ink, #2c2416);
    border: 1px solid var(--ink-light, #5c4a2e);
    transition: background 0.15s ease;
}

.body-toggle:hover {
    background: rgba(44, 36, 22, 0.04);
}

.body-toggle input[type="checkbox"] {
    accent-color: var(--gold, #c9a227);
    margin: 0;
    width: 14px;
    height: 14px;
}

.body-toggle-label {
    font-weight: 500;
    user-select: none;
}

/* --- Randomize button --- */
.btn-randomize {
    display: block;
    margin: 0.5rem auto 0;
    padding: 0.35rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    color: var(--ink, #2c2416);
    background: transparent;
    border: 1px solid var(--ink-light, #5c4a2e);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.btn-randomize:hover {
    background: rgba(201, 162, 39, 0.12);
    border-color: var(--gold, #c9a227);
}
.btn-randomize:active {
    background: rgba(201, 162, 39, 0.22);
}

/* ============================================
   SWATCH GRIDS
   ============================================ */

.swatch-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.swatch {
    width: 28px;
    height: 28px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.1s ease;
    position: relative;
}

.swatch:hover {
    border-color: var(--ink-light, #5c4a2e);
    transform: scale(1.15);
    z-index: 1;
}

.swatch.active {
    border-color: var(--gold, #c9a227);
    box-shadow: 0 0 0 1px var(--gold, #c9a227);
}

/* Smaller swatches for skin grid */
.swatch-grid-sm .swatch {
    width: 18px;
    height: 18px;
    border-width: 1.5px;
}

/* ============================================
   HAIR / CLOTHING PICKER (scrollable thumbnail grid)
   ============================================ */

.hair-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-height: 200px;
    overflow-y: auto;
    padding: 4px;
    border: 1px solid rgba(92, 74, 46, 0.2);
    background: rgba(44, 36, 22, 0.02);
    /* Thin scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--ink-light, #5c4a2e) transparent;
}

.hair-picker::-webkit-scrollbar {
    width: 6px;
}
.hair-picker::-webkit-scrollbar-thumb {
    background: var(--ink-light, #5c4a2e);
}

.hair-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    border: 2px solid transparent;
    padding: 2px;
    transition: border-color 0.15s ease;
    width: 56px;
}

.hair-item:hover {
    border-color: var(--ink-light, #5c4a2e);
}

.hair-item.active {
    border-color: var(--gold, #c9a227);
    background: rgba(201, 162, 39, 0.08);
}

.hair-item.active.stacked {
    border-color: #2e7d32;
    background: rgba(46, 125, 50, 0.12);
    box-shadow: inset 0 0 0 2px rgba(46, 125, 50, 0.25);
}

.hair-thumb {
    width: 48px;
    height: 48px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background: repeating-conic-gradient(rgba(44, 36, 22, 0.06) 0% 25%, transparent 0% 50%) 0 0 / 8px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hair-thumb.hair-none {
    font-size: 1.4rem;
    color: var(--ink-light, #5c4a2e);
    opacity: 0.5;
}

.hair-loading {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(44, 36, 22, 0.15);
    border-top-color: var(--ink-light, #5c4a2e);
    border-radius: 50%;
    animation: hair-spin 0.6s linear infinite;
}

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

.hair-label {
    font-size: 0.58rem;
    color: var(--ink-light, #5c4a2e);
    text-align: center;
    font-family: monospace;
    line-height: 1.2;
    width: 100%;
    word-break: break-word;
    overflow-wrap: break-word;
}

/* ============================================
   SIDEBAR (RIGHT) - Preview + Colours
   ============================================ */

.generator-sidebar {
    width: 300px;
    flex-shrink: 0;
    position: sticky;
    top: 1rem;
}

.preview-card {
    border: 2px solid var(--ink, #2c2416);
    background: var(--parchment, #f4f1e8);
    padding: 1rem;
    text-align: center;
    margin-bottom: 1rem;
}

.gen-assets-notice {
    border: 1px solid var(--ink, #2c2416);
    background: var(--parchment, #f4f1e8);
    padding: 0.75rem 1rem;
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--ink, #2c2416);
    opacity: 0.85;
}
.gen-assets-notice p { margin: 0 0 0.4rem; }
.gen-assets-notice p:last-child { margin-bottom: 0; }
.gen-assets-notice a { color: var(--link, #5a3e28); text-decoration: underline; }
    outline: none;
}

.preview-card:focus-within {
    border-color: var(--gold, #c9a227);
    box-shadow: 0 0 0 1px var(--gold, #c9a227);
}

.preview-label {
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-light, #5c4a2e);
    margin-bottom: 0.75rem;
}

/* Full sprite sheet canvas — hidden but used for export */
#preview-canvas {
    display: none;
}

/* Sprite area: compass + sprite side by side */
.preview-sprite-area {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.5rem;
    margin-bottom: 0.5rem;
    background: repeating-conic-gradient(rgba(44, 36, 22, 0.06) 0% 25%, transparent 0% 50%) 0 0 / 16px 16px;
    border: 1px solid rgba(92, 74, 46, 0.25);
}

/* Animated preview sprite */
.preview-sprite-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 128px;
    height: 128px;
}

.preview-sprite-wrap .showcase-sprite {
    transform: scale(1.3);
}

.preview-hint {
    font-size: 0.65rem;
    color: var(--ink-light, #5c4a2e);
    opacity: 0.6;
    padding-top: 0.3rem;
}

.preview-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.preview-actions .popup-btn {
    flex: 1;
    font-size: 0.82rem;
    padding: 0.4rem 0.75rem;
    text-align: center;
}

/* Prominent "Set Sprite" CTA row */
.preview-actions-cta {
    margin-top: 0.4rem;
}

.btn-set-sprite-cta {
    width: 100%;
    font-size: 1.05rem !important;
    padding: 0.7rem 1rem !important;
    background: var(--accent, #8b5e3c) !important;
    color: var(--parchment, #f4f1e8) !important;
    border: 2px solid var(--ink, #2c2416) !important;
    font-weight: 700;
    letter-spacing: 0.03em;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
    transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.btn-set-sprite-cta:hover {
    background: var(--ink, #2c2416) !important;
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(0, 0, 0, 0.3);
}

.btn-set-sprite-cta:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* ============================================
   COMPASS CONTROLS (direction pad)
   ============================================ */

.compass-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    flex-shrink: 0;
}

.compass-row {
    display: flex;
    gap: 1px;
    align-items: center;
}

.compass-btn {
    width: 26px;
    height: 26px;
    padding: 0;
    font-size: 10px;
    line-height: 1;
    background: var(--parchment, #f4f1e8);
    border: 1px solid var(--ink, #2c2416);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    font-family: inherit;
    color: var(--ink, #2c2416);
}
.compass-btn:hover { opacity: 1; background: rgba(44, 36, 22, 0.08); }
.compass-btn.active {
    background: var(--ink, #2c2416);
    color: var(--parchment, #f4f1e8);
    opacity: 1;
}

.compass-center {
    width: 26px;
    height: 26px;
    padding: 0;
    font-size: 10px;
    line-height: 1;
    background: var(--parchment, #f4f1e8);
    border: 1px solid var(--ink, #2c2416);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    font-family: inherit;
    color: var(--ink, #2c2416);
}
.compass-center:hover { opacity: 1; background: rgba(44, 36, 22, 0.08); }
.compass-center.walking {
    background: var(--gold, #c9a227);
    color: var(--ink, #2c2416);
    opacity: 1;
}

/* ============================================
   IN-PAGE COLOUR PICKER (SV square + hue bar)
   ============================================ */

.color-picker-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
    user-select: none;
    -webkit-user-select: none;
}

.cp-sv-canvas {
    width: 100%;
    aspect-ratio: 1;
    cursor: crosshair;
    border: 1px solid var(--ink-light, #5c4a2e);
    display: block;
}

.cp-hue-canvas {
    width: 100%;
    height: 18px;
    cursor: crosshair;
    border: 1px solid var(--ink-light, #5c4a2e);
    display: block;
}

.cp-info-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.cp-preview {
    width: 28px;
    height: 28px;
    border: 1px solid var(--ink-light, #5c4a2e);
    flex-shrink: 0;
}

.cp-hex {
    width: 6.5em;
    padding: 0.3rem 0.4rem;
    font-family: monospace;
    font-size: 0.85rem;
    border: 1px solid var(--ink-light, #5c4a2e);
    background: transparent;
    color: var(--ink, #2c2416);
}

.cp-hex:focus {
    outline: 1px solid var(--gold, #c9a227);
    border-color: var(--gold, #c9a227);
}

.color-picker-inline {
    flex-direction: row;
    gap: 8px;
    align-items: stretch;
    margin-bottom: 0.5rem;
}

.color-picker-inline .cp-sv-canvas {
    width: 80px;
    height: 80px;
    aspect-ratio: auto;
    flex-shrink: 0;
}

.color-picker-inline .cp-hue-canvas {
    width: 80px;
    height: 14px;
}

.color-picker-inline .cp-right-col {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.color-picker-inline .cp-preview {
    width: 22px;
    height: 22px;
}

.color-picker-inline .cp-hex {
    width: 5.5em;
    font-size: 0.8rem;
}

/* ============================================
   COLOUR TABS (Skin/Eye/Hair & Clothing)
   ============================================ */

.colour-tabs {
    display: flex;
    flex-direction: column;
}

.colour-tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--ink-light, #5c4a2e);
    margin-bottom: 0.5rem;
}

.colour-tab {
    flex: 1;
    padding: 0.3rem 0.4rem;
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    border-bottom: none;
    background: transparent;
    color: var(--ink-light, #5c4a2e);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    transition: color 0.12s ease, background 0.12s ease;
}

.colour-tab:hover {
    color: var(--ink, #2c2416);
    background: rgba(44, 36, 22, 0.04);
}

.colour-tab.active {
    color: var(--ink, #2c2416);
    border-color: var(--ink-light, #5c4a2e);
    background: var(--parchment, #f4f1e8);
    margin-bottom: -1px;
    padding-bottom: calc(0.3rem + 1px);
}

.colour-tab-panel {
    display: none;
}

.colour-tab-panel.active {
    display: block;
}

/* ============================================
   FOLDABLE CONTAINERS (collapsible sections)
   ============================================ */

.gen-foldable {
    border: 1px solid var(--ink-light, #5c4a2e);
    margin-bottom: 1rem;
    padding: 0;
}

.gen-foldable > summary {
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.6rem 1rem;
    cursor: pointer;
    color: var(--ink, #2c2416);
    user-select: none;
    list-style: none;
    background: rgba(44, 36, 22, 0.06);
    transition: background 0.15s ease;
}

.gen-foldable > summary:hover {
    background: rgba(44, 36, 22, 0.1);
}

.gen-foldable[open] > summary {
    border-bottom: 1px solid rgba(92, 74, 46, 0.15);
}

.gen-foldable > summary::-webkit-details-marker { display: none; }
.gen-foldable > summary::marker { display: none; content: ''; }

.gen-foldable > summary::before {
    content: '\25BE  ';
}

.gen-foldable:not([open]) > summary::before {
    content: '\25B8  ';
}

.gen-foldable-body {
    padding: 0.5rem 0.75rem 1rem;
}

/* ============================================
   RESET BUTTON (inside colour pickers)
   ============================================ */

.cp-reset {
    padding: 0.2rem 0.45rem;
    font-family: inherit;
    font-size: 0.65rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--ink-light, #5c4a2e);
    background: transparent;
    color: var(--ink-light, #5c4a2e);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    transition: all 0.15s ease;
    flex-shrink: 0;
    line-height: 1;
}

.cp-reset:hover {
    background: rgba(44, 36, 22, 0.08);
    color: var(--ink, #2c2416);
    border-color: var(--ink, #2c2416);
}

/* ============================================
   HAIR LAYOUT (rear + front stacked, colour right)
   ============================================ */

.hair-layout {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.hair-lists-col {
    flex: 1;
    min-width: 0;
}

.hair-colour-col {
    flex: 0 0 240px;
}

.hair-colour-col .colour-section-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink-light, #5c4a2e);
    margin-bottom: 0.4rem;
}

.hair-colour-col .cp-sv-canvas {
    aspect-ratio: 1;
}

.hair-colour-col .cp-hue-canvas {
    height: 14px;
}

.hair-colour-col .cp-preview {
    width: 20px;
    height: 20px;
}

.hair-colour-col .cp-hex {
    width: 5.5em;
    font-size: 0.8rem;
}

/* Hair picker height inside tabs */
.hair-lists-col .hair-picker {
    max-height: 260px;
}

/* ============================================
   SKIN TONE LAYOUT (swatches left, picker right)
   ============================================ */

.skin-layout {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.skin-swatches-col {
    flex-shrink: 0;
    width: 100px;
    padding-left: 10px;
}

.skin-picker-col {
    flex: 0 0 120px;
}

.skin-picker-col .cp-sv-canvas {
    aspect-ratio: 1;
}

.skin-picker-col .cp-hue-canvas {
    height: 14px;
}

.skin-picker-col .cp-preview {
    width: 20px;
    height: 20px;
}

.skin-picker-col .cp-hex {
    width: 5.5em;
    font-size: 0.8rem;
}

/* ============================================
   CLOTHING LAYOUT (grid left, pickers right)
   ============================================ */

.clothing-layout {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}

.clothing-grid-col {
    flex: 1;
    min-width: 0;
}

.clothing-grid-col .hair-picker {
    max-height: 280px;
}

.clothing-picker-col {
    flex: 0 0 210px;
}

/* ============================================
   CLOTHING PICKER TAB OVERRIDES
   ============================================ */

.clothing-picker-col .cp-sv-canvas {
    aspect-ratio: 1;
}

.clothing-picker-col .cp-hue-canvas {
    height: 14px;
}

.clothing-picker-col .cp-preview {
    width: 22px;
    height: 22px;
}

.clothing-picker-col .cp-hex {
    width: 5.5em;
    font-size: 0.8rem;
}

/* ============================================
   ACCESSORIES LAYOUT (grid left, pickers right)
   ============================================ */

.accessories-layout {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}

.acc-grid-col {
    flex: 1;
    min-width: 0;
}

.acc-grid-col .hair-picker {
    max-height: 280px;
}

.acc-picker-col {
    flex: 0 0 210px;
}

.acc-picker-col .cp-sv-canvas {
    aspect-ratio: 1;
}

.acc-picker-col .cp-hue-canvas {
    height: 14px;
}

.acc-picker-col .cp-preview {
    width: 22px;
    height: 22px;
}

.acc-picker-col .cp-hex {
    width: 5.5em;
    font-size: 0.8rem;
}

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

/* --- Tablets / narrow desktops — tighten fixed columns --- */
@media (max-width: 920px) {
    .generator-sidebar {
        width: 260px;
    }

    .body-picker-col {
        flex: 0 0 200px;
    }

    .hair-colour-col {
        flex: 0 0 140px;
    }

    .clothing-picker-col {
        flex: 0 0 180px;
    }

    .acc-picker-col {
        flex: 0 0 180px;
    }
}

/* --- Mobile — single column, centred, restrained pickers --- */
@media (max-width: 700px) {
    .generator-page {
        margin: 1rem auto;
        padding: 0 0.5rem;
    }

    .generator-panel {
        flex-direction: column-reverse;
        align-items: center;
        gap: 1rem;
    }

    /* Preview: centred with a comfortable cap */
    .generator-sidebar {
        width: 100%;
        max-width: 340px;
        position: static;
        margin: 0 auto;
    }

    .preview-card {
        padding: 0.75rem;
    }

    .preview-hint {
        display: none; /* keyboard hint irrelevant on touch */
    }

    /* Controls fill width, content stays centred inside */
    .generator-controls {
        width: 100%;
    }

    /* Snugger foldable padding on smaller screens */
    .gen-foldable {
        margin-bottom: 0.75rem;
    }

    .gen-foldable > summary {
        padding: 0.65rem 0.75rem;
    }

    .gen-foldable-body {
        padding: 0.5rem 0.5rem 0.75rem;
    }

    /* Colour tabs: friendlier touch targets, full-width bar */
    .colour-tab {
        padding: 0.45rem 0.35rem;
        font-size: 0.7rem;
    }

    /* Tab bars always span the foldable width */
    .colour-tabs {
        width: 100%;
    }

    .colour-tab-bar {
        width: 100%;
    }

    /* ---- BODY ---- */
    .body-layout {
        flex-direction: column;
        align-items: center;
    }

    /* Keep body-type cards side-by-side — they're compact enough */
    .body-type-row {
        flex-direction: row;
        justify-content: center;
    }

    .body-type-card {
        padding: 8px 12px;
    }

    /* Picker column fills the foldable; tab bar is full-width,
       but swatches + picker inside stay at their fixed size */
    .body-picker-col {
        flex: 1 1 auto;
        width: 100%;
    }

    /* Skin swatches + picker stay side-by-side, centred within the full-width panel */
    .skin-layout {
        flex-direction: row;
        justify-content: center;
    }

    .skin-swatches-col {
        width: 100px;
        padding-left: 10px;
        flex-shrink: 0;
    }

    .skin-picker-col {
        flex: 0 0 120px;
    }

    /* ---- HAIR ---- */
    .hair-layout {
        flex-direction: column;
        align-items: center;
    }

    /* Thumbnail grid fills width (more items per row) */
    .hair-lists-col {
        width: 100%;
    }

    /* Colour picker column: full-width tab bar, centred canvas */
    .hair-colour-col {
        flex: 1 1 auto;
        width: 100%;
    }

    .hair-colour-col .color-picker-wrap {
        max-width: 200px;
        margin: 0 auto;
    }

    /* ---- CLOTHING ---- */
    .clothing-layout {
        flex-direction: column;
        align-items: center;
    }

    .clothing-grid-col {
        flex: 1 1 auto;
        width: 100%;
    }

    /* Tab bar fills width; picker canvases stay restrained */
    .clothing-picker-col {
        width: 100%;
    }

    .clothing-picker-col .color-picker-wrap {
        max-width: 210px;
        margin: 0 auto;
    }

    /* ---- ACCESSORIES ---- */
    .accessories-layout {
        flex-direction: column;
        align-items: center;
    }

    .acc-grid-col {
        flex: 1 1 auto;
        width: 100%;
    }

    .acc-picker-col {
        width: 100%;
    }

    .acc-picker-col .color-picker-wrap {
        max-width: 210px;
        margin: 0 auto;
    }
}

/* --- Very small phones — scale down where needed --- */
@media (max-width: 380px) {
    .generator-page {
        padding: 0 0.35rem;
    }

    .body-type-thumb {
        width: 72px;
        height: 72px;
    }

    .body-type-card {
        padding: 6px 8px;
    }

    .generator-sidebar {
        max-width: 300px;
    }

    .body-picker-col {
        max-width: 230px;
    }

    .clothing-picker-col,
    .acc-picker-col {
        max-width: 220px;
    }

    .hair-colour-col {
        max-width: 260px;
    }
}
