/* layout.css: Page shell: header, sidebar rail, main column; the Star-Touched top-nav layout. */
/* ===== LAYOUT ===== */
.page-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 18px;
    height: var(--header-height);
    padding: 0 20px;
    background: var(--bg-surface);
    background: color-mix(in srgb, var(--bg-surface) 84%, transparent);
    backdrop-filter: saturate(1.3) blur(12px);
    -webkit-backdrop-filter: saturate(1.3) blur(12px);
    border-bottom: 1px solid var(--border-color);
}

.site-brand {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
    white-space: nowrap;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
@media (hover: hover) { .site-brand:hover { text-decoration: none; filter: brightness(1.08); } }

.site-nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    justify-content: flex-end;
    white-space: nowrap;
}
.site-nav-right a { color: var(--text-secondary); }
@media (hover: hover) { .site-nav-right a:hover { color: var(--text-primary); text-decoration: none; } }

/* Logout is a POST form (M12); style its button to read as a nav link. */
.nav-logout-form { display: inline; margin: 0; }
.nav-logout-form button {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: var(--text-secondary);
    cursor: pointer;
}
@media (hover: hover) { .nav-logout-form button:hover { color: var(--text-primary); } }

/* Nav currency chips (M3). */
.nav-currency {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Toast stack positioning (M1): applies whether the container is pre-rendered
   in base.html or created on demand by main.js. */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    left: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    pointer-events: none;
}

/* Hide Alpine x-cloak regions until Alpine initializes (M2). */
[x-cloak] { display: none !important; }

/* Screen-reader-only content: visually hidden but still announced (e.g.
   aria-live status text that has a visible equivalent elsewhere). */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip-to-content link: visible only on keyboard focus (UX12 a11y). */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 10000;
    padding: 8px 14px;
    background: var(--bg-elevated, #222);
    color: var(--text-primary, #fff);
    border-radius: 0 0 6px 0;
}
.skip-link:focus { left: 0; }

/* Honeypot field for a public form (register): unlike .sr-only, this must be
   invisible to assistive tech too, not just sighted users, or a screen-reader
   user tabbing through would land on a field with nothing telling them to
   skip it. Pair with aria-hidden="true" and tabindex="-1" on the wrapper in
   markup; the class only handles the visual half. */
.form-honeypot { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* Daily-bonus streak milestone track (UX9). */
.streak-track {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    list-style: none;
    padding: 0;
    margin: 8px 0;
}
/* Two-line pip: day above, its Stardust payout below. The payout used to live only in a
   `title=` (plus an .sr-only sentence), so on touch there was no way to learn what any
   milestone paid. `height` became `min-height` for the same reason the reward line exists:
   a fixed 32px clipped the second line outright. */
.streak-milestone {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 32px;
    padding: 3px 8px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    font-size: 0.85rem;
    line-height: 1.15;
}
.streak-milestone__reward {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}
.streak-milestone.reached .streak-milestone__reward { color: inherit; opacity: 0.85; }
/* Reached pips also carry a ✓ glyph in the markup: the colour is reinforcement,
   never the signal on its own. Uses --color-reward (the earned/reward token) rather
   than the previously-hardcoded #7e57c2 fallback of an undefined --accent, which
   rendered the same off-palette purple in every palette. */
.streak-milestone.reached {
    background: color-mix(in srgb, var(--color-reward) 16%, transparent);
    border-color: color-mix(in srgb, var(--color-reward) 55%, var(--border-color));
    color: var(--color-reward);
    font-weight: 700;
}

/* Pet-card image placeholder while generation is pending (UX11): fixed size
   matches the 120x120 img so the grid doesn't jump when images arrive. */
.pet-card-image-pending {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 120px;
    height: 120px;
    border-radius: 8px;
    background: var(--bg-elevated, #2a2a2a);
    color: var(--text-secondary, #aaa);
    font-size: 0.8rem;
}

.staff-nav {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-right: 16px;
    border-right: 1px solid var(--border-color);
}

.weather-chip {
    padding: 4px 10px;
    border-radius: var(--radius-lg);
    background: var(--bg-subtle);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.9em;
}

.site-body {
    display: flex;
    align-items: stretch;
}

.site-sidebar {
    width: 216px;
    flex-shrink: 0;
    border-right: 1px solid var(--border-subtle);
    padding: 20px 14px;
    position: sticky;
    top: var(--header-height);
    align-self: flex-start;
    /* dvh, not vh: on mobile browsers 100vh excludes the URL bar and toolbar, so a
       vh-sized scroll box runs on under the browser chrome and its bottom is
       unreachable. vh first as the fallback for anything without dvh support. */
    height: calc(100vh - var(--header-height));
    height: calc(100dvh - var(--header-height));
    overflow-y: auto;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 0.95rem;
    position: relative;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sidebar-nav a .nav-ico,
.sidebar-nav-group > summary .nav-ico { width: 20px; text-align: center; font-size: 1.05rem; flex-shrink: 0; }
@media (hover: hover) { .sidebar-nav a:hover { background: var(--bg-hover); color: var(--text-primary); text-decoration: none; } }
.sidebar-nav a.is-active { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-nav a:focus-visible,
.staff-subnav a:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.sidebar-nav a.is-active::before {
    content: '';
    position: absolute;
    left: -14px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 22px;
    border-radius: 0 3px 3px 0;
    background: var(--gradient-primary);
}
.sidebar-nav-group { margin-top: 2px; }
.sidebar-nav-group > summary {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: var(--font-heading);
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sidebar-nav-group__label {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.15;
}
.sidebar-nav-group__hint {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: .68rem;
    font-weight: 500;
    letter-spacing: .02em;
}
.sidebar-nav-group > summary::-webkit-details-marker { display: none; }
.sidebar-nav-group > summary:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}
@media (hover: hover) {
    .sidebar-nav-group > summary:hover { background: var(--bg-hover); color: var(--text-primary); }
}
.sidebar-nav-group[open] > summary { color: var(--text-primary); }
.sidebar-nav-group__chevron { margin-left: auto; color: var(--text-muted); font-size: 1.1rem; line-height: 1; transition: transform var(--dur) var(--ease); }
.sidebar-nav-group[open] .sidebar-nav-group__chevron { transform: rotate(180deg); }
.sidebar-nav-group__items { display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav-group__items a { padding-left: 20px; }
.site-body > .page-container {
    flex: 1;
    min-width: 0;
}

@media (width < 1024px) {
    /* Below desktop the sidebar rail is replaced by the fixed bottom tab bar
       (+ "More" drawer). Tablets (768–1023) keep this bar but get full-width
       two-column content: see the grid queries below. */
    .site-header { gap: 12px; padding: 0 14px; }
    .site-sidebar { display: none; }
    body.is-app { padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px)); }
}

/* ============================================================
   Star-Touched Legacy layout: top nav bar, desktop only (1024px+)
   The header (brand/weather/currencies/bell/avatar) is untouched: only
   `.site-sidebar` is retired for this one theme, restyled from a left rail
   into a horizontal strip under the header. This is a pure restyle of the
   EXISTING `.sidebar-nav` markup from base.html: same links, same URLs, same
   badges, same <details> groups. Below 1024px this theme is identical to
   every other theme (the sidebar is already hidden in favor of the bottom
   tab bar, per the rule just above).
   The interface-style exclusion is intentional: UserPreferences keeps the
   Legacy palette selection when a player switches to Frontier, but the
   Legacy palette's alternate layout must not reshape the Frontier shell. The
   Classic interface is excluded too: it shares this palette's menubar markup
   (base.html's menubar_nav flag) but brings its own menubar styling, and the
   two rule sets would otherwise stack.
   ============================================================ */
@media (min-width: 1024px) {
    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .site-body { flex-direction: column; }

    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .site-sidebar {
        width: 100%;
        height: auto;
        position: sticky;
        top: var(--header-height);
        z-index: 90;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 0 14px;
        overflow: visible;
        background: var(--bg-elevated);
    }

    /* flex-wrap, not overflow-x: an auto-scrolling `.sidebar-nav` would force
       its own overflow-y to auto too (a child with overflow-x != visible and
       overflow-y left visible has the latter computed to auto per spec), which
       would clip the absolutely-positioned dropdown panels below instead of
       letting them float over the page. Wrapping to a second row at narrower
       desktop widths is a duller fallback but never clips anything. */
    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: stretch;
        gap: 2px;
    }

    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .sidebar-nav a,
    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .sidebar-nav-group > summary {
        height: 46px;
        padding: 0 12px;
        border-radius: 0;
        border-bottom: 2px solid transparent;
        white-space: nowrap;
    }
    /* The vertical rail's left accent bar reads as a stray mark once the item
       is laid out horizontally: a bottom border under the active/open item
       takes over as the position indicator instead. */
    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .sidebar-nav a.is-active {
        background: none;
        color: var(--color-primary);
        border-bottom-color: var(--color-primary);
    }
    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .sidebar-nav a.is-active::before { content: none; }
    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .sidebar-nav-group[open] > summary { border-bottom-color: var(--color-violet); }

    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .sidebar-nav-group { position: relative; margin-top: 0; }
    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .sidebar-nav-group__label { flex-direction: row; align-items: center; gap: 6px; }
    /* The "Companions" / "Frontier" sub-label has room in a vertical rail; it
       doesn't in a 46px-tall bar, and the group's own name already carries
       enough meaning without it. */
    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .sidebar-nav-group__hint { display: none; }

    /* .sidebar-nav-group (the <details>) is this panel's containing block,
       set above. See game/test_css_positioning.py. */
    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .sidebar-nav-group__items {
        position: absolute;
        top: 100%;
        left: 0;
        margin-top: 1px;
        min-width: 230px;
        padding: 6px;
        background: var(--bg-elevated);
        border: 1px solid var(--border-color);
        border-radius: 0 0 var(--radius-md) var(--radius-md);
        box-shadow: var(--shadow-lg);
        z-index: 95;
    }
    body.theme-star-touched:not(.interface-frontier):not(.interface-classic) .sidebar-nav-group__items a { padding-left: 12px; border-radius: var(--radius-sm); }
}

