/* ==========================================================================
   My Profile page (profile.html, js/pages/profile.js)
   Colors come only from the variables in css/styles.css.
   ========================================================================== */

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

/* ---- Layout: a column of cards, each one with one job (profile.html) ---- */

.profile-layout {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.profile-box {
    padding: var(--space-md);
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

.profile-box h2 {
    margin: 0;
    font-size: 18px;
    color: var(--color-heading);
}

/* Title row of a card: a round icon, the title and a short hint under it. */
.profile-box-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: var(--space-sm);
}

.profile-box-head .profile-hint {
    margin-top: 2px;
}

.profile-box-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-primary-soft);
    color: var(--color-primary-ink);
    font-size: 21px;
}

.profile-box-icon .ti { margin: 0; }
.profile-box-icon--gold { background: var(--color-highlight-soft); color: var(--color-highlight-dark); }
.profile-box-icon--accent { background: var(--color-accent-soft); color: var(--color-accent-ink); }
.profile-box-icon--error { background: var(--color-error-soft); color: var(--color-error-ink); }

/* The first card: avatar and eggs on top (on the left on wide screens), nickname and progress next to them. */
.profile-hero {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.profile-hero-main {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    min-width: 0;
}

.profile-hero .profile-form h2 {
    margin-bottom: 8px;
}

@media (min-width: 640px) {
    .profile-hero {
        flex-direction: row;
        align-items: center;
    }

    .profile-hero .profile-summary {
        flex: 0 0 180px;
    }

    .profile-hero-main {
        flex: 1;
    }
}

/* A note at the bottom of a card, separated from the content above it. */
.profile-note {
    margin-top: var(--space-sm);
    padding-top: 12px;
    border-top: 1px solid var(--color-border-light);
}

.profile-summary {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    text-align: center;
}

.profile-avatar--large {
    width: 120px;
    height: 120px;
    font-size: 76px;
}

/* ---- Nickname form ---- */

.profile-field {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.profile-input {
    flex: 1 1 200px;
    min-width: 0;
    padding: 12px 14px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    color: var(--color-text);
    font-family: inherit;
    font-size: 16px;   /* 16px or more: iOS does not zoom the page when the field is focused */
    transition: var(--transition);
}

.profile-input::placeholder {
    color: var(--color-muted);
}

.profile-input:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
    border-color: var(--color-primary);
}

.profile-hint {
    margin-top: 8px;
    font-size: 13px;
    color: var(--color-muted);
}

.profile-status {
    min-height: 20px;   /* the page does not jump when a message appears */
    margin-top: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-success-ink);
}

.profile-status.is-error {
    color: var(--color-error-ink);
}

/* ---- Buttons (same "chunky" look as the quiz buttons) ---- */

.profile-btn {
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;

    --btn-shadow: transparent;
    box-shadow: 0 4px 0 var(--btn-shadow);
    transition: var(--transition);
}

.profile-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 var(--btn-shadow);
}

.profile-btn:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
}

.profile-btn--primary {
    --btn-shadow: var(--color-primary-dark);
    background: var(--color-primary);
    color: var(--color-on-fill);
}

.profile-btn--secondary {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    color: var(--color-label);
}

.profile-btn--danger {
    --btn-shadow: var(--color-error-dark);
    background: var(--color-error);
    color: var(--color-on-fill);
}

@media (hover: hover) {
    .profile-btn:hover {
        filter: brightness(1.07);
    }
}

/* ---- Delete data ---- */

.profile-data .profile-box-head {
    margin-bottom: 4px;
}

/* A text link, but a <button>: it does an action, it does not go to another page. */
.profile-erase-link {
    margin-top: 10px;
    padding: 4px 0;
    border: none;
    background: none;
    color: var(--color-error-ink);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
}

.profile-erase-link:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
    border-radius: 4px;
}

@media (hover: hover) {
    .profile-erase-link:hover {
        color: var(--color-error-ink-strong);
    }
}

/* ---- Confirmation dialog (native <dialog>; the browser puts it above everything, bottom bar included) ---- */

.profile-dialog {
    width: calc(100% - 32px);
    max-width: 400px;
    margin: auto;
    padding: 28px 24px;
    border: none;
    border-radius: var(--radius-lg);
    background: var(--color-bg);
    color: var(--color-text);
    box-shadow: var(--shadow-card);
    text-align: center;
}

.profile-dialog::backdrop {
    background: rgba(23, 32, 51, 0.55);
}

.profile-dialog-icon {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: var(--color-error-soft);
    color: var(--color-error-ink);
    font-size: 30px;
}

.profile-dialog h2 {
    margin-bottom: 8px;
    font-size: 21px;
    color: var(--color-heading);
}

.profile-dialog-text {
    margin-bottom: 22px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-label);
}

.profile-dialog-actions {
    display: flex;
    flex-direction: column-reverse;   /* the safe option ends up on top on phones */
    gap: 12px;
}

.profile-dialog-actions .profile-btn {
    width: 100%;
}

@media (min-width: 480px) {
    .profile-dialog-actions {
        flex-direction: row;
    }

    .profile-dialog-actions .profile-btn {
        flex: 1;
    }
}

/* The big avatar and, at the hen stage, the hint "Tap your avatar to switch between hen and rooster" */
.profile-avatar-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.profile-avatar-hint {
    max-width: 180px;
    margin: 0;
    font-size: 13px;
    line-height: 1.4;
    text-align: center;
    color: var(--color-label);
}

/* ---- My collection: still thumbnails of the animations won (js/pages/profile.js) ---- */
.collection-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.collection-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-top: 6px solid var(--color-highlight);
    border-radius: var(--radius-md);
    color: var(--color-heading-alt);
    font: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.collection-item:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 3px;
}

@media (hover: hover) {
    .collection-item:hover {
        border-color: var(--color-primary-light);
        border-top-color: var(--color-highlight);
        transform: translateY(-2px);
    }
}

/* The thumbnail is "disabled": still and a little faded, with a play sign until it is opened. */
.collection-thumb {
    position: relative;
    display: block;
}

.collection-thumb .gold-egg-anim {
    opacity: 0.75;
    filter: saturate(0.7);
}

.profile-language {
    margin-left: 4px;
    font-size: 0.85em;
    font-weight: 600;
    color: var(--color-muted);
}

.collection-count {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 28px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--color-gold);
    color: var(--color-on-highlight);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.3;
    text-align: center;
    box-shadow: 0 2px 6px rgba(20, 33, 61, 0.25);
}

.collection-play {
    position: absolute;
    right: 0;
    bottom: 0;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-on-fill);
    font-size: 15px;
    box-shadow: 0 2px 6px rgba(20, 33, 61, 0.25);
}

.collection-name {
    font-size: 13px;
    font-weight: 700;
}

.collection-empty {
    margin-top: 8px;
    font-size: 14px;
    color: var(--color-label);
}

/* The big view: the animation as it was won, on a soft gold glow (no dark background, no pause button). */
.collection-dialog {
    text-align: center;
}

.collection-stage {
    display: grid;
    place-items: center;
    margin: 0 auto 8px;
    padding: 8px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--color-highlight-soft) 0%, transparent 70%);
}

/* ---- Shop: animations bought with eggs (js/pages/profile.js, js/core/shop.js) ---- */
/* The eggs the visitor can spend: a pill, so it reads as a "wallet" and not as one more line of text. */
.shop-balance {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 var(--space-sm);
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--color-highlight-soft);
    color: var(--color-heading-alt);
    font-size: 14px;
    font-weight: 600;
}

.shop-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.shop-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    max-width: 180px;
}

.shop-item .collection-item {
    border-top-color: var(--color-accent);
}

/* The purchase button (the Shop and the "Buy" of its confirmation): flat, in the yellow of the site, no shadow and little
   padding, so it takes less room than the other buttons. Yellow goes with dark text (--color-text), never with white. */
.shop-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 36px;
    padding: 6px 10px;
    border: 0;
    border-radius: 8px;
    background: var(--color-highlight);
    color: var(--color-on-highlight);
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
    box-shadow: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: var(--transition);
}

.shop-btn:active:not(:disabled) {
    background: var(--color-gold);
}

.shop-btn:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
}

@media (hover: hover) {
    .shop-btn:hover:not(:disabled) {
        background: var(--color-gold);
    }
}

/* Not enough eggs: a pale yellow that still reads (the line under it says how many are missing). */
.shop-btn:disabled {
    background: var(--color-highlight-soft);
    color: var(--color-highlight-dark);
    cursor: not-allowed;
}

.shop-btn--dialog {
    padding-inline: 18px;
}

.shop-buy {
    width: 100%;
}

.shop-need,
.shop-owned {
    margin: 0;
    font-size: 13px;
    text-align: center;
    color: var(--color-label);
}

.shop-owned {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 700;
    color: var(--color-success-ink);
}

/* An animation of the Shop that is not bought yet: a still picture, not a button (no play sign, no hover). */
.collection-item.is-locked {
    cursor: default;
}

.collection-item.is-locked:hover {
    transform: none;
    border-color: var(--color-border);
}

/* ---- Appearance: the dark mode switch (js/core/theme.js) ---- */

.profile-setting {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.profile-setting-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.profile-setting-text .profile-hint {
    margin-top: 2px;
}

.profile-setting-label {
    font-weight: 700;
    color: var(--color-heading);
}

/* A real <button role="switch">: the state is aria-checked (read aloud) AND the knob moves and shows a sun or a moon. */
.theme-switch {
    position: relative;
    flex: none;
    width: 60px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--color-track);
    box-shadow: inset 0 0 0 1px var(--color-border);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.2s ease;
}

.theme-switch-knob {
    position: absolute;
    top: 4px;
    left: 4px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 4px rgba(13, 22, 38, 0.3);
    font-size: 16px;
    transition: transform 0.2s var(--ease-out);
}

.theme-switch-knob .ti { grid-area: 1 / 1; margin: 0; }
.theme-switch-knob .ti-sun { color: var(--color-gold-dark); }
.theme-switch-knob .ti-moon { color: #3373c3; display: none; }

.theme-switch[aria-checked="true"] {
    background: var(--color-primary);
    box-shadow: none;
}

.theme-switch[aria-checked="true"] .theme-switch-knob { transform: translateX(26px); }
.theme-switch[aria-checked="true"] .ti-sun { display: none; }
.theme-switch[aria-checked="true"] .ti-moon { display: block; }

.theme-switch:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .theme-switch,
    .theme-switch-knob { transition: none; }
}

/* ==========================================================================
   Account page (account.html, js/pages/account.js) and the policy page (privacy.html)
   Colors only through tokens (both themes). Fields reuse the look of .profile-input.
   ========================================================================== */

.account { display: flex; flex-direction: column; gap: var(--space-md); }
.account-view[hidden], .account-form[hidden] { display: none; }
.account-view { display: flex; flex-direction: column; gap: var(--space-sm); }
.account-loading { color: var(--color-muted); }

.account-status:empty { display: none; }
.account-status { margin: 0; padding: 12px 14px; border-radius: var(--radius-md); background: var(--color-primary-soft); color: var(--color-text); }
.account-status--error { background: var(--color-error-soft); color: var(--color-error-ink-strong); }
.account-status--ok { background: var(--color-success-soft, var(--color-primary-soft)); color: var(--color-success-ink); }

/* Sign in | Create an account: a two-button switch (aria-pressed carries the state) */
.account-switch { display: flex; gap: 8px; flex-wrap: wrap; }
.account-switch-btn {
    flex: 1 1 140px; min-height: 44px; padding: 10px 14px;
    border: 2px solid var(--color-border); border-radius: var(--radius-md);
    background: var(--color-bg); color: var(--color-text); font: inherit; font-weight: 600; cursor: pointer;
}
.account-switch-btn[aria-pressed="true"] { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-on-fill); }
.account-switch-btn:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }

.account-form { display: flex; flex-direction: column; gap: 14px; }
.account-form h2, .account-view > h2 { margin: 0; font-size: 20px; color: var(--color-heading); }
.account-view h2:focus:not(:focus-visible) { outline: none; }
.account-field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; color: var(--color-label); }
.account-field input {
    min-height: 44px; padding: 10px 14px; border: 2px solid var(--color-border); border-radius: var(--radius-md);
    background: var(--color-bg); color: var(--color-text); font: inherit; font-size: 16px;   /* 16px: iOS does not zoom */
}
.account-field input:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; border-color: var(--color-primary); }
.account-check { display: flex; align-items: flex-start; gap: 10px; min-height: 24px; color: var(--color-text); cursor: pointer; }
.account-check input { width: 22px; height: 22px; margin: 1px 0 0; flex: none; accent-color: var(--color-primary); }
.account-note { margin: 0; font-size: 14px; color: var(--color-muted); }
.account-policy-link, .account-link {
    align-self: flex-start; min-height: 24px; padding: 2px 0; border: 0; background: none;
    color: var(--color-primary-ink); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer;
}
.account-form .quiz-btn { align-self: flex-start; }
.account-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.account-email { overflow-wrap: anywhere; }

.account-details { display: grid; gap: 10px; margin: 0; }
.account-details > div { display: flex; flex-direction: column; gap: 4px; }
.account-details dt { font-weight: 600; color: var(--color-label); min-width: 120px; }
.account-details dd { margin: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.account-code { font-size: 18px; font-weight: 700; letter-spacing: 1px; color: var(--color-heading); }
.account-copy { min-height: 32px; padding: 4px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-bg); color: var(--color-primary-ink); font: inherit; font-weight: 600; cursor: pointer; }

.account-delete { border-top: 1px solid var(--color-border); padding-top: var(--space-sm); }
.account-delete summary { min-height: 24px; color: var(--color-error-ink); font-weight: 600; cursor: pointer; }
.account-delete .account-form { margin-top: 12px; }
.account-danger { background: var(--color-error); border-color: var(--color-error); color: var(--color-on-fill); --btn-shadow: var(--color-error-dark); }

.privacy h2 { margin: var(--space-md) 0 8px; font-size: 20px; color: var(--color-heading); }
.privacy p { line-height: 1.6; }
.privacy a { color: var(--color-primary-ink); font-weight: 600; overflow-wrap: anywhere; }

.profile-account[hidden] { display: none; }   /* hidden must win over .profile-box (AGENTS.md: "hidden and display") */
.profile-account .quiz-btn { align-self: flex-start; }
