/* ==========================================================
   Reapax 7TV Paints - Stylesheet
   ========================================================== */

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

:root {
    --pv-control-h: 34px;
    --bg: #18181b;
    --bg-surface: #1f1f23;
    --bg-card: #1F1F23;
    --bg-card-hover: #26262C;
    --bg-card-active: #2F2F35;
    --border: #34343a;
    --text: #fafafa;
    --text-muted: #a1a1aa;
    --radius-sm: 8px;
    --radius-md: 10px;
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;

    /* Suppress all scrollbars globally except where explicitly allowed */
    scrollbar-width: none;
}

::-webkit-scrollbar {
    width: 0;
    height: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 700;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* --- App Shell --- */
.app {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1200px;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    padding: 0 24px;
    padding-top: 26vh;
}

/* --- Visualizer --- */
.visualizer {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    min-height: 7rem;
    border-radius: var(--radius-md);
    transition: background-color var(--transition-base);
    --preview-bg: transparent;
}
/* Preview background modes (feature 1) */
.visualizer.bg-dark   { background-color: transparent; }
.visualizer.bg-white  { background-color: #ffffff; }
.visualizer.bg-custom { background-color: var(--preview-bg); }
/* On a light preview background, the default (unpainted) text must not be white */
.visualizer.bg-white .visualizer-input:not(.painted),
.visualizer.bg-white .visualizer-input:not(.painted)::placeholder {
    color: #111 !important;
    -webkit-text-fill-color: #111 !important;
}

.visualizer-frame {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: 100%;
    /* Badge<->text gap tracks the preview font size, exactly like the paint
       maker (--badge-gap, 6px at 75px text). Set here on the flex row so a
       single gap governs badge<->badge AND badge<->text. */
    gap: var(--badge-gap, 6px);
    /* Allow shadows/glow to render outside bounds */
    overflow: visible;
}

.visualizer-input {
    display: block;
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-weight: 700;
    font-size: 64px;
    text-align: center;
    white-space: nowrap;
    padding: 0;
    margin: 0;
    width: auto;
    max-width: 100%;

    /* Default state: plain white text */
    color: white;
    -webkit-text-fill-color: white;
}

.visualizer-input::placeholder {
    -webkit-text-fill-color: rgba(255, 255, 255, 0.35);
    color: rgba(255, 255, 255, 0.35);
}

/* Applied when a paint is active on the visualizer */
.visualizer-input.painted {
    background-clip: text !important;
    -webkit-background-clip: text !important;
    -webkit-text-fill-color: transparent;
    color: transparent;
    /* The text itself is transparent (so the gradient shows through), which
       also hides the caret. Set caret-color explicitly so clicking the text
       shows a visible blinking cursor and it's clear the field is editable. */
    caret-color: #fff;
    /* 7TV default: size [1,1] = 100% 100%, canvas_repeat = no-repeat */
    background-size: 100% 100%;
    background-repeat: no-repeat;
}
/* On a white preview background a white caret would vanish - use a dark one */
.visualizer.bg-white .visualizer-input.painted { caret-color: #111; }

/* --- List Header --- */
.list-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    font-size: 1.25rem;
    letter-spacing: -0.01em;
    color: var(--text);
}

.list-header i {
    font-size: 1.1rem;
    opacity: 0.7;
}

/* --- Paint Grid (scrollable region) --- */
.paint-grid-scroll {
    flex: 1 1 0;
    min-height: 0; /* Critical: allows flex child to shrink below content size */
    overflow-y: auto;
    overflow-x: hidden;
    /* Top padding so a top-row card scaled up on hover - AND its favorite star,
       which pokes ~8px above the card's top-right corner - clear the scroll
       container edge (which sits just under the list header) without clipping.
       overflow-y must stay auto for scrolling, so the buffer does the work. */
    padding: 20px 6px 0;

    /* Subtle scrollbar */
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}

.paint-grid-scroll::-webkit-scrollbar {
    width: 3px;
}
.paint-grid-scroll::-webkit-scrollbar-track {
    background: transparent;
}
.paint-grid-scroll::-webkit-scrollbar-thumb {
    background-color: #333;
    border-radius: 3px;
}
.paint-grid-scroll::-webkit-scrollbar-thumb:hover {
    background-color: #555;
}

.paint-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    padding-bottom: 12px;

    /* Fade transition between pages */
    opacity: 1;
    transition: opacity var(--transition-base);
}

.paint-grid.fading {
    opacity: 0;
}

.paint-grid-message {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.95rem;
    padding: 24px 0;
}

.paint-grid-error {
    color: #e55;
    font-weight: 400;
    font-size: 0.95rem;
    padding: 24px 0;
}

/* --- Paint Card --- */
.paint-card {
    background-color: var(--bg-card);
    border-radius: var(--radius-sm);
    cursor: pointer;
    position: relative;
    transition: transform var(--transition-fast), background-color var(--transition-fast);

    /*
     * CRITICAL: overflow must be visible so drop-shadows and glow
     * effects on paint text are not clipped by the card boundary.
     */
    overflow: visible;

    /* Padding gives room for shadow overflow without layout shift */
    padding: 8px 14px;
    min-width: 60px;

    display: flex;
    align-items: center;
    justify-content: center;
}

.paint-card:hover {
    background-color: var(--bg-card-hover);
    transform: scale(1.08);
    /* Lift the whole card (and its favorite star) above adjacent cards so the
       button, which overflows the card's top-right corner, is never covered by
       the next card in the row. */
    z-index: 20;
}

.paint-card:active {
    transform: scale(1.02);
}

.paint-card.active {
    background-color: var(--bg-card-active);
}

/* Paint text label inside card */
.paint-label {
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
    display: inline-block;

    /* 7TV paint rendering baseline */
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;

    /* 7TV defaults: size [1,1] = 100% 100%, canvas_repeat = no-repeat */
    background-size: 100% 100%;
    background-repeat: no-repeat;

    /* Allow filter effects (drop-shadow) to render */
    overflow: visible;
}

/* --- Pagination --- */
.pagination {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 16px 0 40px;
}

.nav-btn {
    background-color: var(--bg-card);
    border: none;
    color: var(--text);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-fast), transform var(--transition-fast), opacity var(--transition-fast);
}

.nav-btn:hover:not(:disabled) {
    background-color: var(--bg-card-hover);
    transform: scale(1.1);
}

.nav-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.nav-btn:disabled {
    opacity: 0.2;
    cursor: default;
    pointer-events: none;
}

.page-dots {
    display: flex;
    align-items: center;
    gap: 6px;
}

.page-dot {
    width: 7px;
    height: 7px;
    background-color: #333;
    border-radius: 50%;
    transition: background-color var(--transition-base), transform var(--transition-base);
}

.page-dot.active {
    background-color: #fff;
    transform: scale(1.3);
}

/* --- Footer --- */
footer {
    position: fixed;
    bottom: 10px;
    left: 0;
    right: 0;
    text-align: center;
    pointer-events: none;
    z-index: 50;
}

.credit-link {
    pointer-events: auto;
    color: #555;
    text-decoration: none;
    font-size: 0.8rem;
    font-family: 'Inter', monospace;
    font-weight: 400;
    background: rgba(24, 24, 24, 0.85);
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid #222;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

.credit-link:hover {
    color: #aaa;
    border-color: #444;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .app {
        padding: 0 16px;
        padding-top: 15vh;
    }

    .visualizer-input {
        font-size: 44px;
    }

    .list-header {
        font-size: 1.1rem;
        margin-bottom: 12px;
    }

    .paint-card {
        padding: 6px 12px;
    }

    .paint-label {
        font-size: 0.85rem;
    }

    .pagination {
        padding: 12px 0 20px;
    }

    .nav-btn {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 400px) {
    .app {
        padding-top: 8vh;
    }

    .visualizer-input {
        font-size: 32px;
    }

    .list-header {
        font-size: 1rem;
    }
}


/* ==========================================================
   Preview Bar  (background, size, search)
   ========================================================== */
.preview-bar {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px 16px;
    /* Narrower than the list-header/grid; centered, sized to its content so the
       search box sits next to the size controls instead of far to the right. */
    width: fit-content;
    max-width: 100%;
    margin: 0 auto 18px;
    padding: 10px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.pv-group {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.pv-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Segmented BG control */
.pv-seg {
    display: inline-flex;
    height: var(--pv-control-h);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg);
}
.pv-seg button {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.78rem;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
    border-right: 1px solid var(--border);
}
.pv-seg button:last-child { border-right: none; }
.pv-seg button:hover { background: var(--bg-card-hover); color: var(--text); }
.pv-seg button.active { background: #3b82f6; color: #fff; }
/* Icon-only size segment: square-ish buttons, consistent with the BG segment */
.pv-group-size .pv-seg button {
    padding: 6px 10px;
    min-width: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.pv-swatch {
    width: 34px;
    height: var(--pv-control-h);
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    cursor: pointer;
    flex-shrink: 0;
}

.pv-btn {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8rem;
    padding: 5px 9px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}
.pv-btn:hover { background: var(--bg-card-hover); color: var(--text); }

.pv-group-size input[type="range"] {
    width: 120px;
    max-width: 30vw;
    height: var(--pv-control-h);
    accent-color: #3b82f6;
    cursor: pointer;
}
.pv-num {
    width: 52px;
    height: var(--pv-control-h);
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    padding: 0 6px;
    border-radius: var(--radius-sm);
    text-align: center;
}

/* Search box */
.pv-group-search { flex: 0 1 auto; }
.search-box {
    position: relative;
    display: flex;
    align-items: center;
    width: 240px;
    max-width: 100%;
}
.search-icon {
    position: absolute;
    left: 11px;
    color: var(--text-muted);
    font-size: 0.85rem;
    pointer-events: none;
}
.search-input {
    width: 100%;
    height: var(--pv-control-h);
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
    padding: 0 32px;
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color var(--transition-fast);
}
.search-input:focus { border-color: #3b82f6; }
.search-input::placeholder { color: var(--text-muted); }
.search-clear {
    position: absolute;
    right: 6px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 7px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    transition: color var(--transition-fast), background-color var(--transition-fast);
}
.search-clear:hover { color: var(--text); background: var(--bg-card-hover); }

/* ==========================================================
   Badge dock  (feature 5: discreet, hidden by default)
   ========================================================== */
.badge-dock {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 60;
    pointer-events: none;
}
.badge-toggle {
    pointer-events: auto;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: rgba(31, 31, 35, 0.9);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
    transition: color var(--transition-fast), border-color var(--transition-fast), background-color var(--transition-fast);
}
.badge-toggle:hover { color: var(--text); border-color: #555; }
.badge-toggle.active { color: #fff; border-color: #3b82f6; background: rgba(59, 130, 246, 0.18); }

.badge-panel {
    pointer-events: auto;
    position: absolute;
    top: 46px;
    right: 0;
    width: 280px;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    transition: max-height var(--transition-base), opacity var(--transition-fast);
}
.badge-panel.open {
    max-height: 420px;
    opacity: 1;
}
.badge-panel-head {
    padding: 10px 12px 6px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Source toggle: Global vs User */
.badge-source-seg {
    display: flex;
    gap: 4px;
    padding: 0 12px 8px;
}
/* Everything inside the panel shares one horizontal inset so the source
   toggle, search, section heads and chip rows all line up on both edges. */
.bsrc-btn {
    flex: 1;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.76rem;
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}
.bsrc-btn:hover { background: var(--bg-card-hover); color: var(--text); }
.bsrc-btn.active { background: #3b82f6; color: #fff; border-color: #3b82f6; }

/* Username lookup row (User mode) */
.badge-user-row {
    display: flex;
    gap: 6px;
    padding: 0 12px 8px;
}
.badge-user-input {
    flex: 1;
    min-width: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: inherit;
    font-size: 0.82rem;
    padding: 6px 9px;
    border-radius: var(--radius-sm);
    outline: none;
}
.badge-user-input:focus { border-color: #3b82f6; }
.badge-fetch-btn {
    flex-shrink: 0;
    background: #3b82f6;
    border: none;
    color: #fff;
    font-size: 0.8rem;
    padding: 6px 11px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.badge-fetch-btn:hover { background: #2f6fd6; }

/* In-panel badge search */
.badge-search {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    padding: 6px 9px;
    border-radius: var(--radius-sm);
    outline: none;
    margin-bottom: 8px;
}
.badge-search:focus { border-color: #3b82f6; }

.badge-chip-area { width: 100%; }

/* Collapsible source dropdown (Twitch / 7TV) */
.badge-section-head {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.78rem;
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-top: 8px;
    transition: background-color var(--transition-fast), border-color var(--transition-fast);
}
.badge-section-head:first-child { margin-top: 0; }
.badge-section-head:hover { background: var(--bg-card-hover); border-color: #555; }
.badge-caret {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}
.badge-section-head.open .badge-caret { transform: rotate(90deg); }
.badge-section-title { flex: 1; text-align: left; }
.badge-section-count {
    font-size: 0.68rem;
    color: var(--text-muted);
    background: var(--bg-card-hover);
    padding: 1px 7px;
    border-radius: 10px;
}
.badge-section-active {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}
.badge-section-active img { max-width: 100%; max-height: 100%; object-fit: contain; }

.badge-chip-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 6px;
    padding: 8px 0 4px;
}
.badge-chip-row .badge-chip { width: 100%; height: 40px; }
.badge-list {
    display: block;
    padding: 4px 12px 12px;
    max-height: 320px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}
.badge-hint {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-muted);
    margin: 4px 0;
    width: 100%;
}
.badge-retry {
    background: #3b82f6;
    border: none;
    color: #fff;
    font-family: inherit;
    font-size: 0.78rem;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.badge-chip {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    transition: border-color var(--transition-fast), background-color var(--transition-fast);
}
.badge-chip:hover { border-color: #555; }
.badge-chip.active { border-color: #3b82f6; background: rgba(59, 130, 246, 0.15); }
.badge-chip img { max-width: 100%; max-height: 100%; object-fit: contain; }
.badge-none { color: var(--text-muted); font-size: 0.9rem; }

/* Badges shown next to the preview text - height tracks the text size via
   --badge-size (set by the sizing code), so they scale with the name instead
   of shrinking to a tiny icon. Twitch renders first, then 7TV. */
.badge-container {
    display: inline-flex;
    align-items: center;
    gap: var(--badge-gap, 6px);
    flex-shrink: 0;
}
.badge-container:empty { display: none; }
.vis-badge {
    height: var(--badge-size, 56px);
    width: auto;
    display: block;
    flex-shrink: 0;
}



/* Page dots become buttons (feature 4) - keep them looking identical */
button.page-dot {
    border: none;
    padding: 0;
    cursor: pointer;
    font: inherit;
}

@media (max-width: 768px) {
    .preview-bar { gap: 8px 12px; padding: 8px 10px; }
    .pv-group-search { flex-basis: 100%; }
    .pv-group-search .search-box { max-width: none; }
    .pv-group-size input[type="range"] { width: 90px; }
}

/* ==========================================================
   Cross-page search results
   ========================================================== */
.search-group-label {
    grid-column: 1 / -1;
    width: 100%;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 18px 0 4px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.search-group-label:first-child { margin-top: 0; }
.search-group-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    padding: 4px 0 8px;
}

/* Text lock toggle (preview bar) */
.pv-lock {
    flex-shrink: 0;
    width: var(--pv-control-h);
    height: var(--pv-control-h);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}
.pv-lock:hover { background: var(--bg-card-hover); color: var(--text); }
.pv-lock.locked {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #fff;
}

/* ==========================================================
   Favorites
   ========================================================== */

/* Per-card star: same circular corner-button pattern as the paint maker's
   copy/remove, gold accent. Hidden until the card is hovered; no permanent
   indicator, so a favorited card looks identical to any other at rest. */
.fav-card-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: #2a2a2e;
    color: #f5c518;
    font-size: 11px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
    z-index: 10;
    transition: transform 0.12s ease, background-color var(--transition-fast);
}
.paint-card:hover .fav-card-btn,
.fav-card-btn:focus-visible { display: flex; }
.fav-card-btn:hover { transform: scale(1.15); background: #35353a; }
/* Favored state only reads on hover (filled gold star + gold background) */
.fav-card-btn.faved { background: #f5c518; color: #1a1a1a; }
.fav-card-btn.faved:hover { background: #ffd633; }

/* Favorites filter button in the preview bar (reuses .pv-lock sizing) */
.pv-fav { color: #f5c518; }
.pv-fav:hover { color: #ffd633; }
.pv-fav.active {
    background: #f5c518;
    border-color: #f5c518;
    color: #1a1a1a;
}
