/* ==========================================================================
   PremiApp — public UI stylesheet
   Design: light, airy app-store look. Floating rounded header, soft cards
   (hairline border + faint diffused shadow), violet accent, per-category
   color tones, generous radii. No gradients, no transform hovers.
   Dark theme: tokens swap via [data-theme="dark"] on <html> (cookie-backed,
   set server-side to avoid FOUC — CSP forbids inline scripts) with a
   prefers-color-scheme fallback when no explicit choice was made.
   ========================================================================== */

:root {
    color-scheme: light;

    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f2f3f6;
    --border: #e7e9ee;
    --border-strong: #d5d8e0;
    --text: #191b20;
    /* #646a78: >=4.9:1 on --bg for WCAG AA small text */
    --text-muted: #646a78;

    /* Violet accent: 5.9:1 on white — AA for text and UI. */
    --accent: #5b4be0;
    --accent-hover: #4938cf;
    --accent-soft: #edebfc;
    --accent-soft-border: #dcd7f8;

    /* #12813d: 4.96:1 against white (download / success actions). */
    --green: #12813d;
    --green-hover: #0f6b33;
    --green-soft: #e6f5ec;
    --amber: #b45309;
    --amber-soft: #fdf3e2;
    --danger: #dc2626;
    --danger-soft: #fdeeee;

    --radius-lg: 18px;  /* header shell, featured cards, modals */
    --radius: 14px;     /* cards, panels */
    --radius-sm: 10px;  /* buttons, inputs, chips */

    --shadow-card: 0 1px 2px rgba(18, 20, 26, 0.04), 0 4px 14px rgba(18, 20, 26, 0.05);
    --shadow-raised: 0 2px 4px rgba(18, 20, 26, 0.05), 0 10px 24px rgba(18, 20, 26, 0.08);
    --shadow-pop: 0 12px 40px rgba(18, 20, 26, 0.16);
}

/* Dark tokens. Keep the two blocks below in sync: the attribute block wins
   when the user picked a theme; the media block covers "no choice yet". */
[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #21252d;
    --border: #262b34;
    --border-strong: #364050;
    --text: #e8eaf0;
    --text-muted: #9ba2b1;

    --accent: #948af0;
    --accent-hover: #a89ff4;
    --accent-soft: #272440;
    --accent-soft-border: #383260;

    --green: #45c67e;
    --green-hover: #5cd692;
    --green-soft: #16291e;
    --amber: #e39a34;
    --amber-soft: #2b2314;
    --danger: #f27272;
    --danger-soft: #2e1a1a;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.25);
    --shadow-raised: 0 2px 4px rgba(0, 0, 0, 0.4), 0 10px 24px rgba(0, 0, 0, 0.35);
    --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.55);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --bg: #0f1115;
        --surface: #181b21;
        --surface-2: #21252d;
        --border: #262b34;
        --border-strong: #364050;
        --text: #e8eaf0;
        --text-muted: #9ba2b1;

        --accent: #948af0;
        --accent-hover: #a89ff4;
        --accent-soft: #272440;
        --accent-soft-border: #383260;

        --green: #45c67e;
        --green-hover: #5cd692;
        --green-soft: #16291e;
        --amber: #e39a34;
        --amber-soft: #2b2314;
        --danger: #f27272;
        --danger-soft: #2e1a1a;

        --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.25);
        --shadow-raised: 0 2px 4px rgba(0, 0, 0, 0.4), 0 10px 24px rgba(0, 0, 0, 0.35);
        --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.55);
    }
}

/* Category tones: deterministic per category (tone_class() in helpers.php).
   Each tone exposes --tone-bg/--tone-fg consumed by .cat-chip / .cat-label. */
.tone-1 { --tone-bg: #e3f2e8; --tone-fg: #1b7a43; }
.tone-2 { --tone-bg: #fcecdc; --tone-fg: #b05416; }
.tone-3 { --tone-bg: #e3edfa; --tone-fg: #2160b8; }
.tone-4 { --tone-bg: #ddf2f0; --tone-fg: #107569; }
.tone-5 { --tone-bg: #ece9fc; --tone-fg: #5b4be0; }
.tone-6 { --tone-bg: #fbe7ee; --tone-fg: #b93765; }
.tone-7 { --tone-bg: #e9ecf2; --tone-fg: #4f5866; }
.tone-8 { --tone-bg: #f4edda; --tone-fg: #8a6a1f; }

[data-theme="dark"] .tone-1 { --tone-bg: #17301f; --tone-fg: #6fd396; }
[data-theme="dark"] .tone-2 { --tone-bg: #322112; --tone-fg: #eda366; }
[data-theme="dark"] .tone-3 { --tone-bg: #16273e; --tone-fg: #7fb1f2; }
[data-theme="dark"] .tone-4 { --tone-bg: #122b28; --tone-fg: #5ecfc2; }
[data-theme="dark"] .tone-5 { --tone-bg: #272440; --tone-fg: #a89ff4; }
[data-theme="dark"] .tone-6 { --tone-bg: #341b25; --tone-fg: #ef8fae; }
[data-theme="dark"] .tone-7 { --tone-bg: #242933; --tone-fg: #aab3c2; }
[data-theme="dark"] .tone-8 { --tone-bg: #2e2812; --tone-fg: #d9b95e; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .tone-1 { --tone-bg: #17301f; --tone-fg: #6fd396; }
    :root:not([data-theme="light"]) .tone-2 { --tone-bg: #322112; --tone-fg: #eda366; }
    :root:not([data-theme="light"]) .tone-3 { --tone-bg: #16273e; --tone-fg: #7fb1f2; }
    :root:not([data-theme="light"]) .tone-4 { --tone-bg: #122b28; --tone-fg: #5ecfc2; }
    :root:not([data-theme="light"]) .tone-5 { --tone-bg: #272440; --tone-fg: #a89ff4; }
    :root:not([data-theme="light"]) .tone-6 { --tone-bg: #341b25; --tone-fg: #ef8fae; }
    :root:not([data-theme="light"]) .tone-7 { --tone-bg: #242933; --tone-fg: #aab3c2; }
    :root:not([data-theme="light"]) .tone-8 { --tone-bg: #2e2812; --tone-fg: #d9b95e; }
}

/* Utilities --------------------------------------------------------------- */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.muted {
    color: var(--text-muted);
}

/* Base ------------------------------------------------------------------- */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: "Inter", ui-sans-serif, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14.5px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

img {
    max-width: 100%;
}

a {
    color: inherit;
    text-decoration: none;
}

h1, h2, h3 {
    line-height: 1.3;
    letter-spacing: -0.015em;
    font-weight: 700;
}

.container {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 20px;
}

.site-main {
    flex: 1;
    padding: 30px 0 56px;
}

/* Buttons ----------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    font: inherit;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex: none;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

[data-theme="dark"] .btn-primary,
[data-theme="dark"] .btn-green {
    color: #0f1115;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .btn-primary,
    :root:not([data-theme="light"]) .btn-green {
        color: #0f1115;
    }
}

.btn-green {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

.btn-green:hover {
    background: var(--green-hover);
    border-color: var(--green-hover);
}

.btn-outline {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--surface-2);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 13px;
    border-radius: 9px;
}

.btn-lg {
    padding: 11px 22px;
    font-size: 15px;
    border-radius: 12px;
}

.btn-lg svg {
    width: 18px;
    height: 18px;
}

.btn-block {
    width: 100%;
}

.btn[disabled],
.btn.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-note {
    font-weight: 400;
    opacity: 0.85;
}

/* Icon-only header button (theme toggle, search reveal) */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex: none;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
}

.icon-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

/* Header ------------------------------------------------------------------ */

/* Floating rounded header: a card that sticks with a small gap above it. */
.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    padding: 12px 0 4px;
    background: transparent;
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 60px;
    padding: 8px 10px 8px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.01em;
    flex: none;
}

/* No tile, no padding, no rounding: the transparent logo sits straight on the
   page. It carries its own dark gamepad body, so it holds up on the light skin
   without anything behind it — checked side by side at true size against a dark
   tile, a white tile and a neutral tint, on both skins.

   A tile costs twice over at this size: it reads as a sticker on the light
   header, and box-sizing is border-box globally, so its padding comes straight
   out of the 26px the mark has to be recognised in. */
.brand-mark {
    display: block;
}

.main-nav {
    display: flex;
    gap: 4px;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    padding: 7px 13px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 550;
    /* A pill's label never breaks into two lines: when the row runs out of
       room the nav SCROLLS (mobile block below) — a two-line pill stretches
       the whole header into a second row, which is the uglier failure. */
    white-space: nowrap;
    transition: background-color 120ms ease, color 120ms ease;
}

.nav-link:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav-link.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}

/* The sign-in link renders as text on desktop; its person icon only
   appears in the compact mobile header. */
.header-signin svg {
    display: none;
    width: 18px;
    height: 18px;
    flex: none;
}

/* Mobile-only search reveal button; hidden on desktop where the
   search field is always visible. */
.search-toggle {
    display: none;
}

.search-form {
    position: relative;
    flex: 1;
    max-width: 320px;
    margin-left: auto;
}

.search-form > svg {
    position: absolute;
    left: 12px;
    top: 50%;
    margin-top: -8px;
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    font: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    transition: border-color 120ms ease, background-color 120ms ease;
}

.search-input:hover {
    border-color: var(--border-strong);
}

.search-input:focus {
    outline: 3px solid var(--accent-soft);
    outline-offset: 0;
    border-color: var(--accent);
    background: var(--surface);
}

.header-auth {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none;
}

.header-user {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 4px 12px 4px 4px;
    border-radius: 999px;
    font-weight: 600;
    max-width: 190px;
    transition: background-color 120ms ease;
}

.header-user:hover {
    background: var(--surface-2);
}

.header-user span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Avatar disc: the member's uploaded picture, or their initial on the accent
   tint. The two sizing rules are for the picture and cost nothing without one
   — the disc is a fixed square, so a photo has to be told to fill it rather
   than tile at its own size. The picture arrives as an inline
   background-image (user_avatar()), which beats the shorthand below it. */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: 50%;
    background: var(--accent-soft);
    background-size: cover;
    background-position: center;
    border: 1px solid var(--accent-soft-border);
    color: var(--accent);
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
}

.logout-form {
    display: inline-flex;
}

.logout-btn {
    border-color: transparent;
    background: none;
    color: var(--text-muted);
}

.logout-btn:hover {
    color: var(--text);
}

/* Header user menu (account dropdown) -------------------------------------- */

.header-user-wrap {
    position: relative;
    flex: none;
}

/* .header-user is now a <button> trigger: reset the UA button chrome. */
.header-user {
    border: 0;
    background: none;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.header-user-caret {
    width: 15px;
    height: 15px;
    flex: none;
    color: var(--text-muted);
    transition: transform 140ms ease;
}

.header-user-wrap.is-open .header-user-caret {
    transform: rotate(180deg);
}

/* Unread cue on the trigger: a small dot at the wrapper's top-right so it sits
   on the avatar on mobile (where the button collapses to avatar-only). */
.notif-dot {
    position: absolute;
    top: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    border: 2px solid var(--surface);
    pointer-events: none;
}

.user-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 224px;
    max-width: calc(100vw - 24px);
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-pop);
    /* Above the sticky header (50), below the toast region (1100). */
    z-index: 60;
}

.user-menu[hidden] {
    display: none;
}

.user-menu form {
    margin: 0;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    background: none;
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
}

.user-menu-item svg {
    width: 18px;
    height: 18px;
    flex: none;
    color: var(--text-muted);
    transition: color 120ms ease;
}

.user-menu-item:hover {
    background: var(--surface-2);
}

.user-menu-logout:hover,
.user-menu-logout:hover svg {
    color: var(--danger);
}

.user-menu-sep {
    height: 1px;
    margin: 6px 4px;
    background: var(--border);
}

/* Count badge — shared by the menu's Notifications row and the account-hub
   card. Token-only on-color text (var(--surface)) adapts to light/dark. */
.notif-badge {
    margin-left: auto;
    min-width: 18px;
    height: 18px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    background: var(--danger);
    color: var(--surface);
}

/* Toast notifications (flash) --------------------------------------------- */

/* A compact fixed stack pinned to the top-right; toasts slide in, auto-dismiss
   and can be closed. Class names are kept so theme skins that accent .flash /
   .flash-success / .flash-error still apply. z sits above the header (50) and
   modals (90). */
.flash-region {
    position: fixed;
    /* Clear of the sticky floating header (~76px tall) so toasts never overlap
       it — themes use translucent surfaces, so overlapping would bleed. */
    top: 84px;
    right: 16px;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 360px;
    max-width: calc(100vw - 32px);
    /* Let clicks fall through the gaps between toasts; each toast re-enables. */
    pointer-events: none;
}

.flash {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-raised);
    font-size: 13.5px;
    line-height: 1.5;
    pointer-events: auto;
}

/* Slide-in / slide-out, gated behind reduced-motion (see below). */
@media (prefers-reduced-motion: no-preference) {
    .flash {
        animation: toast-in 260ms cubic-bezier(0.21, 1.02, 0.73, 1) both;
    }

    .flash.is-leaving {
        animation: toast-out 180ms ease forwards;
    }
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(24px); }
    to { opacity: 1; transform: none; }
}

@keyframes toast-out {
    to { opacity: 0; transform: translateX(24px); }
}

/* Tinted hairline + soft bg per type; the message stays neutral so only the
   icon/accent carries the color (reads cleaner than fully-tinted text). */
.flash-success {
    border-color: color-mix(in srgb, var(--green) 30%, transparent);
    background: var(--green-soft);
    color: var(--green);
}

.flash-error {
    border-color: color-mix(in srgb, var(--danger) 30%, transparent);
    background: var(--danger-soft);
    color: var(--danger);
}

.flash-icon {
    flex: none;
    width: 18px;
    height: 18px;
    margin-top: 1px;
    color: inherit;
}

.flash-msg {
    flex: 1;
    min-width: 0;
    color: var(--text);
    font-weight: 550;
    overflow-wrap: anywhere;
}

.flash-close {
    margin-left: auto;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: 0;
    background: none;
    color: inherit;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 120ms ease;
}

.flash-close:hover {
    /* currentColor-based tint so the hover reads on both themes. */
    background: color-mix(in srgb, currentColor 14%, transparent);
}

.flash-close svg {
    width: 14px;
    height: 14px;
}

@media (max-width: 480px) {
    .flash-region {
        left: 12px;
        right: 12px;
        top: 76px;
        width: auto;
    }
}

/* Sections / page furniture ------------------------------------------------ */

.page-intro {
    color: var(--text-muted);
    font-size: 15px;
    margin: 4px 0 26px;
}

.home-section {
    margin-bottom: 46px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.section-head h2 {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
}

/* Small accent glyph in front of a section title. */
.section-icon {
    display: inline-flex;
    color: var(--accent);
}

.section-icon svg {
    width: 20px;
    height: 20px;
}

.section-links {
    display: flex;
    gap: 18px;
}

.section-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--accent);
    transition: color 120ms ease;
}

.section-link:hover {
    color: var(--accent-hover);
}

/* Category chip / label ------------------------------------------------------
   .cat-chip = tinted pill (featured cards, detail pages);
   .cat-label = bare colored micro-label (compact list rows).
   Both take a .tone-N class for their color pair. */

.cat-chip {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    padding: 3px 10px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--tone-fg, var(--text-muted));
    background: var(--tone-bg, var(--surface-2));
    border-radius: 7px;
    white-space: nowrap;
}

.cat-label {
    display: block;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--tone-fg, var(--text-muted));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* App cards (compact row: icon left, category label + name + line) ---------- */

.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(258px, 1fr));
    gap: 14px;
}

.app-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

.app-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-raised);
}

.app-card:hover .app-card-name {
    color: var(--accent);
}

.app-card-top {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.app-card-icon {
    width: 52px;
    height: 52px;
    flex: none;
    border-radius: 14px;
    object-fit: cover;
    background: var(--surface-2);
}

.app-card-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.app-card-name {
    font-size: 15px;
    font-weight: 650;
    letter-spacing: -0.01em;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    transition: color 140ms ease;
}

/* The app's highlight (signature feature): its own full-width row under
   the icon+title block, clamped to two lines; margin-top:auto anchors it
   to the card bottom so grid rows stay level. */
.app-card-highlight {
    display: block;
    margin-top: auto;
}

.app-card-highlight-text {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.app-card .app-card-highlight-text {
    min-height: 3em;
}

/* Chips (category filters: catalog, guides, payment tabs) ------------------- */

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 16px 0;
}

/* Subcategories of the currently open category. */
.chip-row-sub {
    margin-top: -8px;
}

.chip-row-sub .chip {
    font-size: 12.5px;
    padding: 4px 11px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 13px;
    /* Chips render as <a> AND <button> (bill-page method/network tabs) —
       buttons need the font + cursor resets. */
    font: inherit;
    cursor: pointer;
    font-size: 13px;
    font-weight: 550;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.chip:hover {
    background: var(--surface-2);
    border-color: var(--border-strong);
}

.chip.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

[data-theme="dark"] .chip.is-active {
    color: #0f1115;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .chip.is-active {
        color: #0f1115;
    }
}

.chip-count {
    font-size: 11.5px;
    font-weight: 400;
    color: var(--text-muted);
}

.chip.is-active .chip-count {
    color: inherit;
    opacity: 0.72;
}

/* Empty state ----------------------------------------------------------------- */

.empty-state {
    text-align: center;
    padding: 64px 20px;
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    color: var(--text-muted);
}

.empty-state svg {
    display: block;
    width: 36px;
    height: 36px;
    margin: 0 auto 12px;
    color: var(--border-strong);
}

.empty-state h2 {
    font-size: 16px;
    color: var(--text);
    margin-bottom: 4px;
}

/* Pagination -------------------------------------------------------------------- */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
    margin: 30px 0 4px;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 11px;
    font-size: 13px;
    font-weight: 550;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: background-color 120ms ease, border-color 120ms ease;
}

a.page-link:hover {
    background: var(--surface-2);
    border-color: var(--border-strong);
}

.page-link[aria-current="page"] {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

[data-theme="dark"] .page-link[aria-current="page"] {
    color: #0f1115;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .page-link[aria-current="page"] {
        color: #0f1115;
    }
}

.page-link.is-disabled {
    opacity: 0.45;
}

.page-ellipsis {
    color: var(--text-muted);
    padding: 0 2px;
}

/* Breadcrumb (app detail, blog, purchase) ----------------------------------- */

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12.5px;
    color: var(--text-muted);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.breadcrumb a {
    transition: color 120ms ease;
}

.breadcrumb a:hover {
    color: var(--accent);
}

.breadcrumb .crumb-current {
    color: var(--text);
    font-weight: 500;
}

/* Narrow page wrapper + card (account, purchase) ---------------------------- */

.page-narrow {
    max-width: 640px;
}

.page-narrow > h1 {
    font-size: 23px;
    letter-spacing: -0.02em;
    margin-bottom: 20px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 22px;
    margin-bottom: 18px;
}

.card > h2 {
    font-size: 16px;
    margin-bottom: 14px;
}

/* Content section (app detail, blog article) -------------------------------- */

.app-section {
    margin: 34px 0;
}

.app-section > h2 {
    font-size: 18px;
    margin-bottom: 14px;
}

.screenshot-strip {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 8px;
    /* Only claim horizontal touch gestures — vertical swipes fall through to
       the page so the strip never traps a downward scroll on mobile. */
    touch-action: pan-x;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
}

.screenshot-thumb {
    flex: none;
    scroll-snap-align: start;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
    cursor: zoom-in;
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

.screenshot-thumb:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-card);
}

.screenshot-thumb img {
    display: block;
    height: 300px;
    width: auto;
    max-width: none;
}

/* Feature checklist shared by the plan cards (/plans, account plan page).
   The app-detail mod panel has its own richer .mod-* structure in
   app-detail.css. */
.premium-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 8px 20px;
    margin-top: 10px;
}

.premium-list li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13.5px;
    font-weight: 550;
    line-height: 1.45;
}

.premium-list svg {
    width: 16px;
    height: 16px;
    flex: none;
    margin-top: 2px;
    color: var(--amber);
}

/* Forms -------------------------------------------------------------------------------- */

.field {
    margin-bottom: 14px;
}

.field label {
    display: block;
    font-size: 13.5px;
    font-weight: 550;
    margin-bottom: 6px;
}

.input {
    width: 100%;
    padding: 9px 13px;
    font: inherit;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    transition: border-color 120ms ease, background-color 120ms ease;
}

.input:hover {
    border-color: var(--border-strong);
}

.input:focus {
    outline: 3px solid var(--accent-soft);
    outline-offset: 0;
    border-color: var(--accent);
    background: var(--surface);
}

.input.is-invalid {
    border-color: var(--danger);
}

.input::placeholder {
    color: var(--text-muted);
    opacity: 0.75;
}

.field-error {
    font-size: 12.5px;
    color: var(--danger);
    margin-top: 4px;
}

/* Fact list (app detail, account, purchase) --------------------------------- */

.fact-list > div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 0;
    border-top: 1px solid var(--border);
}

.fact-list > div:first-child {
    border-top: 0;
    padding-top: 0;
}

.fact-list dt {
    color: var(--text-muted);
}

.fact-list dd {
    font-weight: 550;
    text-align: right;
    overflow-wrap: anywhere;
}

/* Muted note (account, purchase) -------------------------------------------- */

.pay-muted {
    font-size: 13.5px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Footer ------------------------------------------------------------------------------------------ */

.site-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.footer-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    flex-wrap: wrap;
    padding: 32px 0 24px;
}

.footer-tagline {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 8px;
    max-width: 340px;
}

.social-links {
    list-style: none;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.social-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    background: var(--surface);
    transition: color 120ms ease, border-color 120ms ease, background-color 120ms ease;
}

.social-links a:hover {
    color: var(--accent);
    border-color: var(--accent-soft-border);
    background: var(--accent-soft);
}

.social-links svg {
    width: 16px;
    height: 16px;
}

.footer-links {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
}

.footer-links a {
    font-size: 13.5px;
    color: var(--text-muted);
    transition: color 120ms ease;
}

.footer-links a:hover {
    color: var(--accent);
}

.footer-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 14px 0 24px;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
    color: var(--text-muted);
}

/* Theme toggle icons: moon shown in light mode, sun in dark. -------------- */

.theme-toggle .icon-sun {
    display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
    display: none;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icon-sun {
        display: block;
    }

    :root:not([data-theme="light"]) .theme-toggle .icon-moon {
        display: none;
    }
}

/* Responsive ---------------------------------------------------------------- */

@media (max-width: 760px) {
    .site-header {
        padding-top: 8px;
    }

    /* Single-row header: logo-only brand + text nav on the left, search
       toggle + theme + slim auth on the right. The search field stays
       hidden until the toggle opens it (as a second row). */
    .header-inner {
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px 10px;
        min-height: 0;
    }

    .brand {
        order: 1;
        gap: 0;
    }

    .brand-name {
        display: none;
    }

    .brand-mark {
        width: 28px;
        height: 28px;
    }

    /* Text nav sits right next to the logo, behind a hairline divider.
       The Discover link is dropped here — the logo already goes home.

       It takes the flexible middle and SCROLLS horizontally when the
       Vietnamese labels outgrow it (below ~410px they did — the header
       broke into two rows, three under 360px). One row at every width
       beats a wrapped header; the scrollbar is hidden because the cut-off
       last pill is its own affordance. */
    .main-nav {
        order: 2;
        flex: 1 1 0;
        min-width: 0;
        gap: 0;
        margin-left: 2px;
        padding-left: 8px;
        border-left: 1px solid var(--border);
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        /* The fade is the "there is more" hint. It only ever paints where
           content actually reaches the box edge: when the row fits, the
           pills end short of it (the nav is the flexible middle) and the
           gradient covers empty space. */
        -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 18px), transparent);
        mask-image: linear-gradient(90deg, #000 calc(100% - 18px), transparent);
    }

    .main-nav::-webkit-scrollbar {
        display: none;
    }

    .main-nav .nav-link {
        flex: none;
    }

    .nav-link-home {
        display: none;
    }

    .main-nav .nav-link {
        padding: 6px 8px;
        font-size: 13.5px;
    }

    .search-toggle {
        display: inline-flex;
        order: 3;
        margin-left: auto;
    }

    .theme-toggle {
        order: 4;
    }

    .header-auth {
        order: 5;
        gap: 4px;
    }

    /* Auth condenses to icons: person = sign in / avatar = account,
       arrow = sign out. Registration stays one tap away on the sign-in
       page. */
    .header-signin {
        width: 36px;
        height: 36px;
        padding: 0;
        justify-content: center;
        color: var(--text);
    }

    .header-signin svg {
        display: block;
    }

    .header-signin span {
        display: none;
    }

    .header-register {
        display: none;
    }

    .logout-btn {
        width: 32px;
        height: 32px;
        padding: 0;
    }

    .logout-btn span {
        display: none;
    }

    .header-user {
        padding: 0;
        border-radius: 50%;
    }

    /* Collapse the trigger to the avatar only. Target the username span by its
       class — a bare `> span` would also hit the .avatar span (same element
       type) and blank the whole trigger (the avatar is the account icon). */
    .header-user > .header-user-name,
    .header-user > .header-user-caret {
        display: none;
    }

    .search-form {
        display: none;
        order: 6;
        flex-basis: 100%;
        max-width: none;
        margin: 2px 0;
    }

    .header-inner.is-search-open .search-form {
        display: block;
    }

    .search-form .search-input {
        padding: 9px 14px 9px 38px;
        border-radius: 999px;
    }

    .search-form > svg {
        left: 14px;
    }
}

@media (max-width: 480px) {
    /* Reclaim width on small phones so the header stays one row. */
    .main-nav {
        margin-left: 0;
        padding-left: 4px;
    }

    .main-nav .nav-link {
        padding: 6px 6px;
        font-size: 13px;
    }

    .search-toggle,
    .theme-toggle,
    .header-signin,
    .header-user,
    .avatar {
        width: 32px;
        height: 32px;
    }

    .header-auth {
        gap: 4px;
    }
}

@media (max-width: 640px) {
    .app-grid {
        grid-template-columns: 1fr 1fr;
    }

    .app-card {
        padding: 14px;
        gap: 11px;
    }

    .app-card-icon {
        width: 44px;
        height: 44px;
        border-radius: 12px;
    }
}

@media (max-width: 460px) {
    .app-grid {
        grid-template-columns: 1fr;
    }

    .fact-list > div {
        flex-direction: column;
        gap: 2px;
    }

    .fact-list dd {
        text-align: left;
    }
}

/* ---- Copy buttons: brief success state (copy.js toggles it). The
       background is reset too so the state stays readable on filled
       buttons (e.g. the affiliate modal's btn-primary copy button). ---- */

.btn.is-copied {
    background: var(--green-soft);
    border-color: var(--green);
    color: var(--green);
}

/* ---- Modal (shared dialog scaffold: key gate, referral-link popup).
       Page modules add their own content styles on top; a page may widen
       the panel with a modifier class (e.g. .aff-modal-panel). ---- */

body.modal-open {
    overflow: hidden;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 48px 20px;
    overflow-y: auto;
    background: rgba(15, 17, 21, 0.6);
}

.modal-overlay[hidden] {
    display: none;
}

.modal-panel {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-pop);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 15.5px;
    font-weight: 650;
}

.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    font-size: 18px;
    line-height: 1;
    color: var(--text-muted);
    background: none;
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
}

.modal-close:hover {
    color: var(--text);
    background: var(--surface-2);
}

.modal-body {
    padding: 18px 20px 20px;
}

/* ---- "VipMod is an Android app" notice (partials/pc-notice-modal.php).
       Lives here rather than in a page module because the four pages that
       raise it load four different stylesheets — home, app-detail and the
       two premibox pages — and core is the only sheet all of them share. ---- */
.pcn-lead {
    margin-bottom: 12px;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--text-muted);
}

.pcn-tip {
    display: flex;
    /* flex-start, not center: the line wraps to two or three on a narrow
       panel, and a centred icon drifts down beside the middle of a sentence
       instead of marking where it starts. */
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 16px;
    padding: 11px 13px;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--text-muted);
    background: var(--accent-soft);
    border: 1px solid var(--accent-soft-border);
    border-radius: var(--radius);
}

.pcn-tip strong {
    /* The lead-in ends in a question mark and the next word follows in the
       same line; a condensed bold face closes "?C" up until they read as one
       word. A hair of air, not a line break. */
    margin-right: 2px;
    color: var(--text);
    font-weight: 650;
}

.pcn-tip-icon {
    display: flex;
    flex: none;
    /* Optical centring on an ~21px first line. */
    margin-top: 2px;
    color: var(--accent);
}

.pcn-tip-icon svg {
    width: 17px;
    height: 17px;
}

/* ---- Floating contact buttons (partials/floating-contact.php).
       Chat links pinned to the bottom-right of every public page. Each link
       carries its brand color in --fab-color (inline). Sits above the sticky
       header (z 50) but below modal overlays (z 90) so a dialog covers it.
       The hover label is a tooltip pill, not a card transform. ---- */
.floating-contact {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 80;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.fab-contact {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--fab-color, var(--accent));
    color: #fff;
    box-shadow: var(--shadow-raised);
    transition: box-shadow 150ms ease, filter 150ms ease;
}

.fab-contact:hover {
    box-shadow: var(--shadow-pop);
    filter: brightness(1.06);
}

.fab-contact:focus-visible {
    outline: 3px solid var(--accent-soft);
    outline-offset: 2px;
}

.fab-contact svg {
    width: 26px;
    height: 26px;
}

/* Tooltip label revealed to the left on hover/focus (desktop pointers). */
.fab-label {
    position: absolute;
    right: calc(100% + 10px);
    top: 50%;
    padding: 6px 11px;
    border-radius: var(--radius-sm);
    background: var(--text);
    color: var(--bg);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: var(--shadow-card);
    opacity: 0;
    transform: translate(6px, -50%);
    pointer-events: none;
    transition: opacity 150ms ease, transform 150ms ease;
}

.fab-contact:hover .fab-label,
.fab-contact:focus-visible .fab-label {
    opacity: 1;
    transform: translate(0, -50%);
}

@media (max-width: 640px) {
    .floating-contact {
        right: 14px;
        bottom: 14px;
        gap: 10px;
    }

    .fab-contact {
        width: 38px;
        height: 38px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .fab-contact,
    .fab-label {
        transition: none;
    }
}
