/* Avatar Maker. Flat, square, neutral hairlines. Orange is used only as a fill. */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Palette taken from the Ven's Horror Sims logo and hub.css: blood red on warm near-black. */
    --bg: #0a0707;
    --panel: #120c0c;
    --raised: #1b1212;
    --raised-hover: #271819;
    --hair: rgba(255, 255, 255, 0.09);
    --hair-strong: rgba(255, 255, 255, 0.2);
    --text: #f3ece3;
    --muted: #a49a92;
    --faint: #6e6560;
    --accent: #d81818;
    --accent-hover: #ff4444;
    --accent-tint: rgba(216, 24, 24, 0.2);
    --checker: repeating-conic-gradient(#2c2222 0% 25%, #1d1515 0% 50%) 0 0 / 16px 16px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

button { font-family: inherit; color: inherit; }
:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* Header */
.page-header {
    /* Back button left, logo dead center, title right. Inset to the same 940px column as
       .maker so the edges line up with the content below. */
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    padding: 12px max(20px, calc((100% - 940px) / 2 + 20px));
    border-bottom: 1px solid var(--hair);
}
.brand { display: block; line-height: 0; justify-self: center; }
.brand img { display: block; height: 88px; width: auto; }
/* Same voice as the hub's own header links (hub.css): small spaced Oswald caps, no fill, no box. */
.btn-back {
    justify-self: start;
    font-family: 'Oswald', 'Arial', sans-serif;
    font-size: 0.82rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 5px;
    text-decoration-color: var(--faint);
    white-space: nowrap;
    transition: color 0.15s, text-decoration-color 0.15s;
}
.btn-back:hover { color: var(--accent-hover); text-decoration-color: var(--accent-hover); }
/* Page heading kept for screen readers and search, hidden visually: the logo is the header. */
.page-title {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Layout */
.maker {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 940px;
    margin: 0 auto;
    padding: 24px 20px 28px;
}

/* Avatar on top, controls under it, options below */
.stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

/* Preview */
.preview-wrap {
    position: relative;
    width: 200px;
    height: 200px;
    background: var(--checker);
    overflow: hidden;
}
#previewImg { display: block; width: 100%; height: 100%; object-fit: contain; }
.preview-loading {
    position: absolute;
    left: 0; right: 0; top: 0;
    height: 3px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s;
}
.preview-loading.on { opacity: 1; }
.preview-loading .bar {
    width: 40%;
    height: 100%;
    background: var(--accent);
    animation: slide 0.9s ease-in-out infinite alternate;
}
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

.preview-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px 20px;
    font-size: 0.8rem;
}
.preview-meta div { display: flex; align-items: baseline; gap: 8px; }
.preview-meta dt {
    color: var(--muted);
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    align-self: center;
}
.preview-meta dd { font-weight: 600; overflow-wrap: anywhere; }

/* Fields and buttons */
.field-lbl {
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: -6px;
}
.seed-input {
    width: 100%;
    background: var(--raised);
    border: 1px solid var(--hair);
    border-radius: 0;
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    padding: 9px 11px;
}
.seed-input:hover { border-color: var(--hair-strong); }
.seed-input::placeholder { color: var(--faint); }

.seed-row { display: flex; gap: 8px; width: 100%; }
.seed-row .seed-input { flex: 1; min-width: 0; }
.btn-row { display: grid; gap: 8px; }
.btn-row.three { grid-template-columns: repeat(3, auto); justify-content: center; }

.btn {
    background: var(--raised);
    border: 1px solid var(--hair);
    border-radius: 0;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 9px 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--raised-hover); border-color: var(--hair-strong); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.block { width: 100%; padding: 12px; font-size: 0.95rem; }

.group-lbl {
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    padding-top: 14px;
    border-top: 1px solid var(--hair);
    margin-bottom: -6px;
}
.hint-note, .url-tip { font-size: 0.74rem; color: var(--muted); line-height: 1.55; text-align: center; }

/* Picker: category tabs across the top, options underneath */
.picker {
    background: var(--panel);
    border: 1px solid var(--hair);
}

.parts-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 10px;
    border-bottom: 1px solid var(--hair);
}
.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--raised);
    border: 1px solid var(--hair);
    border-radius: 0;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 7px 12px;
    cursor: pointer;
    white-space: nowrap;
}
.tab-btn:hover { background: var(--raised-hover); border-color: var(--hair-strong); color: var(--text); }
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.picker-main { padding: 14px 16px 18px; min-width: 0; }
.picker-head { margin-bottom: 10px; }
.picker-head h2 { font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; }
.picker-head p { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

/* Thumbnails */
.thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 5px;
}
.thumb-grid.style-mode { grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 4px; }
.option-thumb {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    padding: 4px 4px 5px;
    background: var(--raised);
    border: 1px solid var(--hair);
    border-radius: 0;
    cursor: pointer;
    text-align: center;
    transition: background 0.12s, border-color 0.12s;
}
.option-thumb:hover { background: var(--raised-hover); border-color: var(--hair-strong); }
.option-thumb.selected { background: var(--accent-tint); }
.option-thumb.selected::after {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 18px; height: 18px;
    background: var(--accent)
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M4.5 9.5l3 3 6-7' fill='none' stroke='white' stroke-width='2'/%3E%3C/svg%3E") center / 100% no-repeat;
}
.option-thumb img {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    background: var(--checker);
}
.thumb-lbl {
    font-size: 0.62rem;
    color: var(--muted);
    line-height: 1.2;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow-wrap: anywhere;
}
.option-thumb.selected .thumb-lbl { color: var(--text); font-weight: 600; }

/* Color swatches */
.color-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.color-item, .color-picker-wrap { background: none; border: 0; padding: 0; cursor: pointer; }
.color-circle, .color-picker-circle {
    position: relative;
    width: 38px;
    height: 38px;
    border: 1px solid var(--hair-strong);
    border-radius: 0;
    transition: transform 0.1s;
}
.color-item:hover .color-circle, .color-picker-wrap:hover .color-picker-circle { transform: scale(1.08); }
.color-item.selected .color-circle { outline: 2px solid #fff; outline-offset: 2px; }
.color-circle.transparent-swatch { background: var(--checker); background-size: 10px 10px; }
.color-picker-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--raised);
    color: var(--muted);
    font-size: 1.1rem;
}
.color-picker-circle input[type="color"] { opacity: 0; position: absolute; width: 1px; height: 1px; }

.empty-state { padding: 40px 0; color: var(--muted); font-size: 0.85rem; }

/* Attribution and footer */
.attribution {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 24px;
    font-size: 0.74rem;
    color: var(--muted);
    line-height: 1.65;
}
.attribution a { color: var(--text); text-underline-offset: 2px; }
footer {
    max-width: 1120px;
    margin: 40px auto 0;
    padding: 24px;
    border-top: 1px solid var(--hair);
    text-align: center;
    color: var(--faint);
    font-size: 0.78rem;
    line-height: 1.8;
}
footer a { color: var(--muted); text-decoration: none; }
footer a:hover { color: var(--text); }

/* Narrow screens and embedded iframe */
@media (max-width: 600px) {
    .page-header { padding: 10px 12px; grid-template-columns: 1fr 1fr; }
    .brand { grid-column: 1 / -1; grid-row: 1; }
    .brand img { height: 72px; }
    .btn-back { grid-row: 2; grid-column: 1 / -1; justify-self: center; }
    .maker { padding: 16px 12px 24px; }
    .seed-row { flex-wrap: wrap; }
    .seed-row .seed-input { flex: 1 1 100%; }
    .seed-row .btn { flex: 1; }
    .picker-main { padding: 14px 12px 20px; }
    .attribution { padding: 0 12px; }
}
@media (max-width: 480px) {
    .thumb-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
    .btn-row.three { grid-template-columns: 1fr 1fr; }
    .btn-row.three .primary { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
    .preview-loading .bar { animation: none; width: 100%; }
    .color-item:hover .color-circle, .color-picker-wrap:hover .color-picker-circle { transform: none; }
}
