body.profile-page {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, sans-serif;
    background: #e8eef5;
    color: var(--text);
}

.profile-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 3.5rem;
    padding: 0.7rem 1.25rem;
    background: #0f766e;
    border-bottom: 1px solid #0d5f59;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.profile-brand,
.back-link {
    color: #f0fdfa;
    text-decoration: none;
    font-weight: 800;
}

.profile-brand {
    font-size: 1rem;
}

.back-link {
    font-size: 0.9rem;
    font-weight: 700;
    opacity: 0.92;
}

.profile-brand:hover,
.back-link:hover {
    color: #fff;
}

.profile-main {
    max-width: 52rem;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 4rem;
}

.profile-billing {
    grid-template-columns: 1fr auto;
    margin-top: 1rem;
    align-items: center;
}

.profile-billing h2 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--heading);
}

.profile-billing .primary {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.billing-warning {
    margin: 0.45rem 0 0;
    color: #b45309;
    font-weight: 700;
}

.year-tile.is-locked::after {
    content: "Unlock";
    display: block;
    margin-top: 0.15rem;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #0f766e;
}

.profile-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 1rem 1.1rem;
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 1.1rem;
    padding: 1.25rem 1.35rem;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.profile-avatar {
    width: 56px;
    height: 56px;
}

.eyebrow {
    margin: 0 0 4px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.profile-id h1 {
    margin: 0;
    font-size: 1.55rem;
    color: var(--heading);
}

.profile-email {
    margin: 0.2rem 0 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.profile-email a {
    color: var(--accent);
    font-weight: 700;
    text-decoration: none;
}

.profile-email a:hover {
    color: var(--accent-hover);
}

.profile-stats {
    display: flex;
    gap: 0.75rem;
    margin: 0;
}

.profile-stats div {
    min-width: 5.2rem;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--line);
    border-radius: 0.85rem;
    background: var(--panel-soft);
    text-align: center;
}

.profile-stats dt {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.profile-stats dd {
    margin: 0.15rem 0 0;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--heading);
}

.profile-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 1.25rem 0 1rem;
}

.profile-tab {
    min-height: 40px;
    padding: 0 16px;
    border-radius: 30px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--heading);
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
}

.profile-tab.is-selected {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

#subjectsTab,
#examsTab,
#bookmarksTab,
#picksTab {
    display: flex;
    flex-direction: column;
    gap: 28px;
}

#subjectsTab[hidden],
#examsTab[hidden],
#bookmarksTab[hidden],
#picksTab[hidden] {
    display: none;
}

.subject-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 1.1rem;
    padding: 1.15rem 1.2rem 1.3rem;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.05);
}

.year-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
    gap: 8px;
}

.year-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 3.35rem;
    padding: 0.4rem 0.35rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-soft);
    color: var(--heading);
    text-decoration: none;
    font-weight: 800;
    font-size: 0.95rem;
    letter-spacing: 0.01em;
}

.year-tile-g0 { background: #e8f4f1; }
.year-tile-g1 { background: #eaf1f8; }
.year-tile-g2 { background: #f1ecf6; }
.year-tile-g3 { background: #f5efe6; }

.year-tile:hover,
.year-tile:focus-visible {
    border-color: var(--accent);
    color: var(--accent);
    outline: none;
}

.year-tile-g0:hover,
.year-tile-g0:focus-visible { background: #d5ebe6; }
.year-tile-g1:hover,
.year-tile-g1:focus-visible { background: #dce7f2; }
.year-tile-g2:hover,
.year-tile-g2:focus-visible { background: #e6ddee; }
.year-tile-g3:hover,
.year-tile-g3:focus-visible { background: #eee4d4; }

.year-tile.is-missing {
    opacity: 0.45;
    pointer-events: none;
}

.panel-empty {
    margin: 0;
    padding: 28px 16px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
    border: 1px dashed var(--line-strong);
    border-radius: 12px;
}

.section-head {
    margin-bottom: 14px;
}

.section-head-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 8px;
}

.profile-picks-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.profile-save-exam-btn {
    min-height: 36px;
    padding: 0 12px;
    border-radius: 999px;
    font-size: 0.84rem;
    white-space: nowrap;
}

.profile-clear-selection-btn {
    min-height: 36px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--heading);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.profile-clear-selection-btn:hover {
    border-color: var(--line-strong);
}

.exam-pick-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-bottom: 8px;
}

.exam-pick-group-head .bookmark-subject {
    margin: 0;
}

.exam-pick-year-select {
    min-height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--heading);
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.exam-pick-year-select:hover {
    border-color: var(--line-strong);
}

.section-head h2 {
    margin: 0 0 4px;
    font-size: 1.15rem;
    color: var(--heading);
}

.bookmark-groups {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.bookmark-groups[hidden] {
    display: none;
}

.bookmark-subject {
    margin: 0 0 8px;
    font-size: 0.95rem;
    color: var(--heading);
}

.past-exam-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.past-exam {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.past-exam-open {
    flex: 1;
    min-width: 0;
    text-align: left;
    color: var(--text);
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--panel-soft);
    padding: 12px;
    font: inherit;
    cursor: pointer;
}

.past-exam-open:hover {
    border-color: var(--accent);
}

.past-exam-open strong {
    display: block;
    color: var(--heading);
}

.past-exam-open span {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.past-exam.is-selected .past-exam-open {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

.past-exam.is-locked .past-exam-open {
    cursor: default;
}

.past-exam.is-locked .past-exam-open:hover {
    border-color: var(--line);
}

.past-exam-share,
.past-exam-remove,
.past-exam-select {
    flex: 0 0 auto;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--panel);
    font-weight: 700;
    padding: 0 14px;
    font-family: inherit;
    cursor: pointer;
}

.past-exam-remove {
    display: grid;
    place-items: center;
    color: var(--danger);
}

.past-exam-remove svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.past-exam-remove:hover:not(:disabled) {
    border-color: var(--danger);
    background: #fbe5e5;
}

.past-exam-share.is-code {
    letter-spacing: 0.08em;
    font-variant-numeric: tabular-nums;
}

.past-exam-select {
    min-width: 84px;
    color: var(--heading);
}

.past-exam-select.is-on {
    border-color: var(--accent);
    background: rgba(var(--accent-rgb), 0.12);
    color: var(--accent-hover);
}

#confirmOk {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

body.preview-open {
    padding-right: min(42vw, 28rem);
}

.question-preview {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 70;
    width: min(42vw, 28rem);
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow);
    transform: translateX(100%);
    transition: transform 0.22s ease;
}

.question-preview.is-open {
    transform: translateX(0);
}

.question-preview-head {
    padding: 0.85rem 1rem 0.95rem;
    border-bottom: 1px solid var(--line);
    background: var(--panel-2);
}

.question-preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-bottom: 0.7rem;
}

.question-preview-close {
    width: 2.2rem;
    height: 2.2rem;
    display: grid;
    place-items: center;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--heading);
    cursor: pointer;
}

.question-preview-close svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
}

.question-preview-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.question-preview-print {
    min-height: 40px;
    padding: 0 14px;
    border-radius: 30px;
    border: 1px solid var(--line);
    background: var(--panel);
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
}

.question-preview-print[hidden],
.question-preview-view[hidden] {
    display: none;
}

.question-preview-view {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.question-preview-view.is-disabled {
    pointer-events: none;
    opacity: 0.45;
}

.question-preview-id h2 {
    margin: 0;
    font-size: 1.15rem;
    color: var(--heading);
}

.question-preview-id .hint {
    margin: 0.2rem 0 0;
}

.question-preview-stage {
    flex: 1;
    overflow: auto;
    padding: 1rem;
    background: #f8fafc;
}

.preview-q {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.95rem 1rem;
    margin-bottom: 0.85rem;
}

.preview-q h3 {
    margin: 0 0 0.65rem;
    font-size: 0.95rem;
    color: var(--heading);
}

.preview-q-prompt {
    color: var(--text);
    font-weight: 600;
    line-height: 1.45;
}

.preview-q-frame {
    margin: 0.75rem auto 0;
}

.preview-q-image {
    display: block;
    max-width: 100%;
    margin: 0;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #fff;
    filter: brightness(1.04) contrast(0.95);
}

.preview-q-frame::after {
    border-radius: 10px;
    background: rgba(255, 252, 248, 0.22);
}

.preview-locked,
.preview-missing {
    margin: 0;
    padding: 1.4rem 1rem;
    text-align: center;
    color: var(--muted);
    border: 1px dashed var(--line-strong);
    border-radius: 12px;
    background: #fff;
}

@media (max-width: 720px) {
    .profile-card {
        grid-template-columns: auto 1fr;
    }

    .profile-billing {
        grid-template-columns: 1fr;
    }

    .profile-stats {
        grid-column: 1 / -1;
        justify-content: stretch;
    }

    .profile-stats div {
        flex: 1;
    }

    body.preview-open {
        padding-right: 0;
    }

    .question-preview {
        width: 100%;
    }
}

@media print {
    body.profile-page > *:not(#questionPreview) {
        display: none !important;
    }

    body.preview-open {
        padding-right: 0;
    }

    .question-preview {
        position: static;
        width: auto;
        height: auto;
        transform: none;
        box-shadow: none;
        border: 0;
    }

    .question-preview-bar {
        display: none;
    }
}
