/* avatar.css — the Avatar Studio overlay + profile avatar chrome.
   Leans on the site tokens (site.css --mybackrooms-*): dark liminal surfaces, gold accents.
   Fully responsive: two-pane studio on desktop, stacked sheet (sticky portrait) on phones,
   iOS safe-areas respected (the app renders edge-to-edge in the Capacitor shell). */

/* ---------- profile-page avatar ---------- */
/* Both the wrap and the avatar are <span>s in the header markup — they MUST be given a
   block formatting display or width/height are ignored and the inner svg (width:100%)
   collapses to zero (the avatar vanished on phones, leaving only the absolutely-
   positioned edit button poking past the viewport edge). */
.pf-avatar-wrap { display: inline-block; position: relative; flex: none; }
.pf-avatar {
    display: block;
    width: 96px;
    height: 96px;
    border-radius: 26%;
    overflow: hidden;
    border: 2px solid var(--mybackrooms-border-strong);
    box-shadow: var(--mybackrooms-shadow-sm), 0 0 22px rgba(233, 200, 63, 0.18);
    background: #221e14;
}
.pf-avatar svg { display: block; width: 100%; height: 100%; }
@media (max-width: 575.98px) {
    .pf-avatar { width: 76px; height: 76px; }   /* phones: keep the header compact */
}
.pf-avatar-edit {
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--mybackrooms-border-strong);
    background: var(--mybackrooms-surface-2);
    color: var(--mybackrooms-primary);
    font-size: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--mybackrooms-transition);
    touch-action: manipulation;
}
.pf-avatar-edit::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; }
.pf-avatar-edit:hover { transform: scale(1.08); box-shadow: var(--mybackrooms-glow); }

/* ---------- studio overlay ---------- */
body.avs-locked { overflow: hidden; }

.avs-overlay {
    position: fixed;
    inset: 0;
    overscroll-behavior: contain;
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: rgba(8, 7, 4, 0.72);
    backdrop-filter: blur(10px) saturate(130%);
    animation: avsFade 0.22s ease;
}
@keyframes avsFade { from { opacity: 0; } }

.avs-card {
    display: flex;
    touch-action: manipulation;
    flex-direction: column;
    width: min(980px, 100%);
    max-height: min(92vh, 780px);
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid var(--mybackrooms-border-strong);
    background:
        radial-gradient(1200px 400px at 50% -10%, rgba(233, 200, 63, 0.10), transparent 60%),
        var(--mybackrooms-surface);
    box-shadow: var(--mybackrooms-shadow-lg), 0 0 60px rgba(233, 200, 63, 0.10);
    animation: avsPop 0.26s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes avsPop { from { transform: translateY(14px) scale(0.98); opacity: 0; } }

.avs-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: none;
    padding: 0.85rem 0.85rem 0.85rem 1.25rem;
    border-bottom: 1px solid var(--mybackrooms-border);
}
.avs-head h2 { margin: 0; font-size: 1.1rem; font-weight: 800; letter-spacing: 0.3px; color: var(--mybackrooms-ink); }
.avs-head-ico { margin-right: 0.35rem; }
.avs-close {
    width: 38px; height: 38px; border-radius: 50%;
    border: 1px solid var(--mybackrooms-border);
    background: transparent; color: var(--mybackrooms-muted);
    font-size: 15px; cursor: pointer; transition: var(--mybackrooms-transition);
    touch-action: manipulation;
}
.avs-close:hover { color: var(--mybackrooms-ink); border-color: var(--mybackrooms-border-strong); }

/* body: portrait stage | options panel */
.avs-body { display: flex; flex: 1 1 auto; min-height: 0; }

.avs-stage {
    flex: 0 0 42%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.7rem;
    padding: 1.4rem;
    border-right: 1px solid var(--mybackrooms-border);
    background:
        radial-gradient(circle at 1.5px 1.5px, rgba(233, 200, 63, 0.10) 1.5px, transparent 0) 0 0 / 18px 18px,
        linear-gradient(180deg, rgba(233, 200, 63, 0.05), transparent 55%);
}
.avs-portrait {
    /* Flexible: never wider than the stage column can give (the fixed 300px clipped on
       short/landscape viewports before the stage got a flexible cap). */
    position: relative;
    width: min(300px, 68vw, 38vh);
    aspect-ratio: 1;
    border-radius: 24px;
    overflow: hidden;
    border: 2px solid transparent;
    background:
        linear-gradient(#171307, #171307) padding-box,
        conic-gradient(from var(--avs-ring, 0deg), #e9c83f, #7a6420, #f2d564, #4a3d12, #e9c83f) border-box;
    box-shadow: 0 14px 44px rgba(0, 0, 0, 0.55), 0 0 34px rgba(233, 200, 63, 0.16);
    animation: avsRing 9s linear infinite;
}
@property --avs-ring { syntax: '<angle>'; initial-value: 0deg; inherits: false; }
@keyframes avsRing { to { --avs-ring: 360deg; } }
@media (prefers-reduced-motion: reduce) { .avs-portrait { animation: none; } }
.avs-portrait:hover { box-shadow: 0 14px 44px rgba(0, 0, 0, 0.55), 0 0 48px rgba(233, 200, 63, 0.32); }
.avs-portrait .avs-svg, .avs-portrait svg { display: block; width: 100%; height: 100%; }
.avs-nick { font-weight: 700; letter-spacing: 0.4px; color: var(--mybackrooms-primary); }
.avs-stage-actions { display: flex; gap: 0.5rem; }

.avs-panel { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* category rail */
.avs-tabs {
    display: flex;
    flex-wrap: wrap;            /* desktop: all categories visible — mouse wheels can't h-scroll */
    gap: 0.35rem;
    padding: 0.75rem 0.9rem 0.55rem;
    flex: none;
}
.avs-tabs::-webkit-scrollbar { display: none; }
.avs-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.42rem 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--mybackrooms-border);
    background: transparent;
    color: var(--mybackrooms-muted);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: var(--mybackrooms-transition);
    touch-action: manipulation;
}
.avs-tab:hover { color: var(--mybackrooms-ink); border-color: var(--mybackrooms-border-strong); }
.avs-tab.is-active {
    color: #1a160b;
    background: var(--mybackrooms-primary, #e9c83f);
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(233, 200, 63, 0.25);
}

/* option tiles / swatches */
.avs-options { flex: 1 1 auto; overflow-y: auto; overscroll-behavior-y: contain; padding: 0.4rem 0.9rem 1rem; scrollbar-width: thin; scrollbar-color: var(--mybackrooms-border-strong) transparent; }
.avs-sect {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.35rem 0.2rem 0.65rem;
}
.avs-sect-ico { font-size: 1rem; }
.avs-sect-name { font-weight: 800; letter-spacing: 0.3px; color: var(--mybackrooms-ink); }
.avs-sect-count { font-size: 0.78rem; color: var(--mybackrooms-muted); }
.avs-spin { display: inline-block; animation: avsSpin 0.5s ease; }
@keyframes avsSpin { to { transform: rotate(360deg); } }
.avs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: 0.6rem;
}
.avs-tile {
    position: relative;
    aspect-ratio: 1;
    padding: 0;
    border-radius: 16px;
    overflow: hidden;
    border: 2px solid var(--mybackrooms-border);
    background: #221e14;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    touch-action: manipulation;
    animation: avsTileIn 0.3s ease backwards;
    animation-delay: calc(var(--stg, 0) * 26ms);
}
@keyframes avsTileIn { from { opacity: 0; transform: translateY(8px) scale(0.96); } }
@media (prefers-reduced-motion: reduce) { .avs-tile, .avs-swatch { animation: none; } }
.avs-tile svg { display: block; width: 100%; height: 100%; }
.avs-tile:hover { transform: translateY(-3px) scale(1.03); border-color: var(--mybackrooms-border-strong); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5); }
.avs-tile.is-sel { border-color: var(--mybackrooms-primary); box-shadow: 0 0 0 2px rgba(233, 200, 63, 0.35), 0 8px 20px rgba(0, 0, 0, 0.5); }
.avs-tile.is-sel::after {
    content: "✓";
    position: absolute;
    top: 5px; right: 5px;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: var(--mybackrooms-primary);
    color: #1a160b;
    font-size: 12px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avs-swatches { display: flex; flex-wrap: wrap; gap: 0.7rem; padding: 0.6rem 0.2rem; }
.avs-swatch {
    width: 46px; height: 46px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.14);
    background: var(--sw);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    touch-action: manipulation;
}
.avs-swatch:hover { transform: scale(1.12); }
.avs-swatch.is-sel { border-color: var(--mybackrooms-primary); box-shadow: 0 0 0 3px rgba(233, 200, 63, 0.35), 0 0 14px rgba(233, 200, 63, 0.4); transform: scale(1.12); }

/* footer */
.avs-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex: none;
    padding: 0.8rem 1.1rem calc(0.8rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--mybackrooms-border);
    background: rgba(0, 0, 0, 0.18);
}
.avs-hint { font-size: 0.8rem; color: var(--mybackrooms-muted); }
.avs-hint em { color: var(--mybackrooms-primary); font-style: normal; }
.avs-hint-err { color: #e88a84; }
.avs-foot-btns { display: flex; gap: 0.55rem; flex: none; }

.avs-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--mybackrooms-border-strong);
    background: var(--mybackrooms-surface-2);
    color: var(--mybackrooms-ink);
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: var(--mybackrooms-transition);
    touch-action: manipulation;
}
.avs-btn:hover { border-color: var(--mybackrooms-primary); color: var(--mybackrooms-primary); }
.avs-btn:active { transform: translateY(1px); }
.avs-btn:disabled { opacity: 0.45; cursor: default; }
.avs-btn:disabled:hover { border-color: var(--mybackrooms-border-strong); color: var(--mybackrooms-ink); }
.avs-save {
    color: #1a160b;
    font-weight: 800;
    padding: 0.6rem 1.5rem;
    background: linear-gradient(145deg, #ffe27a, #f2d564 45%, var(--mybackrooms-primary, #e9c83f));
    border-color: transparent;
    box-shadow: 0 6px 22px rgba(233, 200, 63, 0.55), 0 0 0 1px rgba(255, 226, 122, 0.6) inset;
}
.avs-save:hover { color: #1a160b; filter: brightness(1.06); }
.avs-save:disabled { opacity: 0.45; cursor: default; box-shadow: none; filter: none; }

/* ---------- phones/tablets: stacked sheet ----------
   991.98px matches the repo's editor mobile breakpoint (a 767.98px cut left landscape
   phones on the desktop two-pane layout, clipping the fixed-width portrait). */
@media (max-width: 991.98px) {
    .avs-overlay { padding: 0; align-items: stretch; }
    .avs-card { width: 100%; max-height: none; height: 100dvh; border-radius: 0; border: 0; }
    .avs-head {
        padding-top: calc(0.85rem + env(safe-area-inset-top));
        padding-left: calc(1.25rem + env(safe-area-inset-left));
        padding-right: calc(0.85rem + env(safe-area-inset-right));
    }
    .avs-body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
    .avs-foot { padding-left: calc(1.1rem + env(safe-area-inset-left)); padding-right: calc(1.1rem + env(safe-area-inset-right)); }
    .avs-tabs { flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }   /* phones: swipeable rail */
    .avs-tabs::-webkit-scrollbar { display: none; }
    .avs-body { flex-direction: column; overflow: hidden; }
    .avs-stage {
        flex: none;
        flex-direction: row;
        justify-content: center;   /* centre portrait + actions; no dead flank on tablets */
        gap: 1.4rem;
        padding: 0.8rem 1rem;
        border-right: 0;
        border-bottom: 1px solid var(--mybackrooms-border);
    }
    .avs-portrait { width: clamp(96px, min(24vw, 26vh), 220px); border-radius: 18px; }   /* vh term: landscape phones must keep room for the tile panel */
    .avs-nick { display: none; }
    .avs-stage-actions { flex-direction: column; align-items: stretch; }
    .avs-hint:not(.avs-hint-err) { display: none; }   /* errors stay visible */
    .avs-foot-btns { flex: 1 1 auto; }
    .avs-foot-btns .avs-btn { flex: 1 1 auto; justify-content: center; }
    .avs-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
}

/* ---- paint mode ---------------------------------------------------------- */
.avs-painting .avs-svg { cursor: crosshair; touch-action: none; }
.avs-painting .avs-portrait { animation-play-state: paused; }   /* the ring repaints every frame — not while the brush is out */
.avs-painting .avs-paint { background: rgba(233, 200, 63, 0.16); }
.avs-paint-color { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; margin-bottom: 0.6rem; }
.avs-paint-color input { width: 3.2rem; height: 2.2rem; border: none; border-radius: 8px; background: none; cursor: pointer; }
.avs-paint-recent { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-bottom: 0.7rem; min-height: 1.6rem; }
.avs-swatch-sm { width: 26px; height: 26px; }
.avs-paint-scopes { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.avs-scope {
    position: relative;
    user-select: none; -webkit-user-select: none;
    display: inline-flex; align-items: center; gap: 0.35rem; cursor: pointer;
    border: 1.5px solid rgba(255,255,255,0.18); border-radius: 999px;
    padding: 0.3rem 0.8rem; font-size: 0.85rem;
}
.avs-scope input { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); pointer-events: none; }
.avs-scope:hover { border-color: rgba(233, 200, 63, 0.55); }
.avs-scope.is-sel { border-color: var(--bs-warning, #e9c83f); background: rgba(233, 200, 63, 0.14); }
.avs-paint-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }

/* ---- polish: keyboard, touch, motion ------------------------------------- */
/* keyboard users get the same affordance mouse users get from hover */
.avs-tab:focus-visible, .avs-tile:focus-visible, .avs-swatch:focus-visible,
.avs-btn:focus-visible, .avs-close:focus-visible, .avs-scope:has(input:focus-visible),
.pf-avatar-edit:focus-visible {
    outline: 2px solid var(--mybackrooms-primary, #e9c83f);
    outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
    .avs-overlay, .avs-card, .avs-spin { animation: none; }
    .avs-tile { animation: none; }
    .avs-tile:hover { transform: none; }
}
/* touch devices: paint mode needs a big canvas and finger-sized controls */
@media (pointer: coarse) {
    .avs-paint-color input { width: 4rem; height: 2.6rem; }
    .avs-swatch-sm { width: 44px; height: 44px; }
    .avs-scope { padding: 0.5rem 1rem; min-height: 42px; }
    .avs-paint-actions .avs-btn { min-height: 42px; }
}
@media (max-width: 991.98px) {
    /* painting needs precision — grow the portrait while the brush is out */
    .avs-painting .avs-stage { padding: 0.5rem; }
    .avs-painting .avs-portrait { width: min(86vw, 42vh, 380px); }
}
