/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* App theme (learningcurve_app seed #005377, Material 3–style) */
    --primary-color: #005377;
    --primary-container: #cce5f0;
    --secondary-color: #4a90a4;
    --secondary-container: #e0f2f7;
    --tertiary-color: #006d5b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --bg-color: #f5f9fb;
    --card-bg: #ffffff;
    --text-color: #1a1a1a;
    --text-light: #5f6b73;
    --border-color: #e2e8ec;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
    --radius-card: 16px;
    --radius-button: 12px;
    --radius-pill: 999px;
}

body {
    font-family: 'Montserrat', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    margin: 0;
    padding: 0;
}

/* Playful headline font */
.playful-font {
    font-family: 'Gloria Hallelujah', cursive;
}

/* Stories: reading typography (EB Garamond ≈ classic Garamond for web) */
.stories-reading {
    font-family: 'EB Garamond', Garamond, 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
}
.stories-reading .card-title,
.stories-reading h1,
.stories-reading h2,
.stories-reading h3 {
    font-family: 'EB Garamond', Garamond, 'Palatino Linotype', Georgia, serif;
    font-weight: 600;
}
.stories-reading .btn {
    font-family: 'Montserrat', sans-serif;
}
.stories-reading select,
.stories-reading label {
    font-family: 'Montserrat', sans-serif;
}

h1, h2, h3, .card-title, .logo {
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
}

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

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--card-bg);
    border-right: 2px solid var(--border-color);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    text-decoration: none;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-color);
    cursor: pointer;
    padding: 0.5rem;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.sidebar-user {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0.5rem;
}

.sidebar-user-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: inherit;
}

.sidebar-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.sidebar-avatar-default {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.user-info {
    color: var(--text-color);
    font-weight: 600;
    font-size: 0.95rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.5rem;
    color: var(--text-color);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background-color: var(--bg-color);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
}

.sidebar-link.active {
    background-color: #e0e7ff;
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 600;
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

.sidebar-link-logout {
    color: var(--error-color);
}

.sidebar-link-logout:hover {
    background-color: #fee2e2;
    border-left-color: var(--error-color);
}

.sidebar-link-locked {
    opacity: 0.7;
    position: relative;
    cursor: pointer;
}

.sidebar-link-locked:hover {
    opacity: 1;
    background-color: #fef3c7;
    border-left-color: var(--warning-color);
}

.sidebar-lock-icon {
    margin-left: auto;
    font-size: 0.875rem;
    color: var(--text-light);
    opacity: 0.6;
}

.sidebar-link-locked:hover .sidebar-lock-icon {
    opacity: 1;
    color: var(--warning-color);
}

.sidebar-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.5rem 1.5rem;
}

/* Sidebar Overlay (Mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Main Wrapper */
.main-wrapper {
    flex: 1;
    margin-left: 260px;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1001;
    background-color: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 1.25rem;
    color: var(--text-color);
    cursor: pointer;
    box-shadow: var(--shadow);
}

.mobile-menu-toggle:hover {
    background-color: var(--bg-color);
}

.notif-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 1.1rem;
    height: 1.1rem;
    padding: 0 4px;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1.1rem;
    text-align: center;
    color: #fff;
    background: #ef4444;
    border-radius: 999px;
}

.notif-badge-inline {
    top: -6px;
    right: -8px;
}

.notification-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.notification-item {
    border-bottom: 1px solid var(--border-color);
}

.notification-item:last-child {
    border-bottom: none;
}

.notification-item-unread {
    background: rgba(59, 130, 246, 0.06);
}

.notification-item-form {
    margin: 0;
}

.notification-item-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 1rem 0.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.notification-item-btn:hover {
    background: rgba(0, 0, 0, 0.03);
}

.notification-item-title {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.notification-item-body {
    display: block;
    color: var(--text-light);
    font-size: 0.95rem;
    margin-bottom: 0.35rem;
}

.notification-item-meta {
    font-size: 0.8rem;
    color: var(--text-light);
}

/* Get App Button (Top Right) */
.get-app-btn {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1001;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-color);
    background-color: var(--card-bg);
    border: 2px solid var(--primary-color);
    border-radius: 6px;
    text-decoration: none;
    box-shadow: var(--shadow);
}

.get-app-btn-icon {
    font-size: 1rem;
    line-height: 1;
}

.get-app-btn:hover {
    background-color: var(--primary-color);
    color: white;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem 0;
}

/* Messages */
.messages {
    margin-bottom: 1.5rem;
}

.message {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.message-success {
    background-color: #d1fae5;
    color: #065f46;
    border-left: 4px solid var(--success-color);
}

.message-error {
    background-color: #fee2e2;
    color: #991b1b;
    border-left: 4px solid var(--error-color);
}

.message-warning {
    background-color: #fef3c7;
    color: #92400e;
    border-left: 4px solid var(--warning-color);
}

/* Cards */
.card {
    background-color: var(--card-bg);
    border-radius: var(--radius-card);
    padding: 2rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.card-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--primary-color);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-button);
    text-decoration: none;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: #4f46e5;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #7c3aed;
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover {
    background-color: #059669;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-color);
}

.form-input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Topic Cards */
.topics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.topic-card {
    background-color: var(--card-bg);
    border-radius: var(--radius-card);
    padding: 2rem;
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--text-color);
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
}

.topic-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.topic-card h2 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.topic-card p {
    color: var(--text-light);
}

/* ========== Play Hub (app-style home) ========== */
.play-hub-page {
    min-height: 100vh;
    padding-bottom: 2rem;
}

.play-hub-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--tertiary-color) 100%);
    color: white;
    padding: 1.25rem 1.5rem 1.5rem;
    /* Keep header within the card padding on all screen sizes to avoid horizontal overflow */
    margin: 0 0 1.5rem 0;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
    position: relative;
}

.play-hub-header .play-hub-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 1rem 0;
    color: rgba(255, 255, 255, 0.98);
}

.player-card {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 18px;
    padding: 1rem;
}

.player-card-top {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.875rem;
}

.player-card-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: white;
    flex-shrink: 0;
}

.player-card-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.player-card-info {
    flex: 1;
    min-width: 0;
}

.player-card-greeting {
    font-weight: 700;
    font-size: 1rem;
    color: white;
    margin: 0 0 0.125rem 0;
}

.player-card-meta {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.9);
    margin: 0;
}

.player-card-rank {
    background: rgba(255, 255, 255, 0.25);
    padding: 0.35rem 0.65rem;
    border-radius: var(--radius-pill);
    font-size: 0.8rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.player-card-xp {
    height: 8px;
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.25);
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.player-card-xp-bar {
    height: 100%;
    border-radius: var(--radius-pill);
    background: #fcd34d;
    transition: width 0.3s ease;
}

.player-card-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.95);
}

.player-card-streak {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.player-card-streak i {
    color: #fdba74;
}

/* Welcome to akiliQuest features (below Play Hub header) */
.welcome-features {
    background: linear-gradient(135deg, var(--primary-container) 0%, var(--secondary-container) 100%);
    border-left: 4px solid var(--primary-color);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-card);
    margin-bottom: 1.5rem;
}

.welcome-features-lead {
    font-size: 1.05rem;
    color: var(--text-color);
    margin: 0 0 1rem 0;
    font-weight: 600;
}

.welcome-features-list {
    color: var(--text-color);
    margin: 0;
    padding-left: 1.5rem;
    line-height: 1.8;
}

.welcome-features-list li {
    margin-bottom: 0.25rem;
}

.welcome-features-cta {
    margin-top: 1rem;
    margin-bottom: 0;
    font-weight: 600;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-color);
    margin: 0 0 0.75rem 0;
}

.section-title i {
    font-size: 1.1rem;
    color: var(--primary-color);
}

/* Horizontal scroll sections (mobile-first, app-like) */
.quest-cards-scroll,
.contest-cards-scroll {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    padding-bottom: 0.9rem;
    margin-bottom: 1.5rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.quest-cards-scroll::-webkit-scrollbar,
.contest-cards-scroll::-webkit-scrollbar {
    height: 6px;
}

/* Today's Missions: single-row carousel + dot pointers */
.missions-carousel-wrap {
    margin-bottom: 1.5rem;
}

.quest-cards-scroll.missions-carousel {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    margin-bottom: 0;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 0.75rem;
    padding-inline: 0.75rem;
    padding-bottom: 1rem;
}

.quest-cards-scroll.missions-carousel .quest-card {
    scroll-snap-align: start;
}

.quest-cards-scroll.missions-carousel::-webkit-scrollbar {
    height: 10px;
}

.quest-cards-scroll.missions-carousel::-webkit-scrollbar-track {
    background: var(--border-color);
    border-radius: 999px;
}

.quest-cards-scroll.missions-carousel::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 999px;
}

.missions-carousel-dots {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.35rem 0 0.15rem;
    min-height: 1.25rem;
}

.missions-carousel-dot {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    border: none;
    padding: 0;
    margin: 0;
    background: var(--border-color);
    cursor: pointer;
    opacity: 0.55;
    transition: background 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
}

.missions-carousel-dot:hover {
    opacity: 0.9;
}

.missions-carousel-dot[aria-current='true'] {
    background: var(--primary-color);
    opacity: 1;
    transform: scale(1.2);
}

.quest-card,
.contest-card {
    flex: 0 0 auto;
    border-radius: 12px;
    padding: 0.875rem;
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    border: none;
    cursor: pointer;
    display: block;
    text-align: left;
    width: 100%;
}

.quest-card {
    width: 220px;
    min-height: 160px;
    background: var(--card-bg);
    box-shadow: var(--shadow);
}

.quest-card:hover,
.contest-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.quest-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}

.quest-card-reward {
    flex-shrink: 0;
    display: inline-block;
    background: var(--primary-container);
    color: var(--primary-color);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 700;
}

.quest-card-title {
    flex: 1;
    min-width: 0;
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-color);
}

.quest-card-subtitle {
    font-size: 0.8rem;
    color: var(--text-light);
    margin: 0;
    line-height: 1.35;
}

/* CBC grades hub */
.cbc-grades-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.cbc-grade-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    background: var(--card-bg);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow);
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cbc-grade-row:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.cbc-grade-name {
    font-weight: 600;
}

.cbc-grade-chevron {
    color: var(--text-light);
    font-size: 0.85rem;
}

.cbc-grade-row--soon {
    cursor: default;
    opacity: 0.95;
}

.cbc-grade-row--soon:hover {
    transform: none;
    box-shadow: var(--shadow);
}

.cbc-grade-soon {
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-light);
    background: var(--secondary-container);
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-pill);
}

.contest-card {
    width: 260px;
    min-height: 150px;
    background: var(--secondary-container);
    background: color-mix(in srgb, var(--secondary-container) 80%, transparent);
}

/* Time floats right; title text wraps beside it (same visual row at the top). */
.contest-card-title-row {
    display: flow-root;
    margin-bottom: 0.25rem;
}

.contest-card-title-row .contest-card-time {
    float: right;
    margin-left: 0.5rem;
    margin-bottom: 0.1rem;
    max-width: 45%;
    text-align: right;
    line-height: 1.3;
}

.contest-card-title-row .contest-card-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-color);
}

.contest-card-badge {
    display: inline-block;
    background: var(--tertiary-color);
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-pill);
    font-size: 0.7rem;
    font-weight: 700;
    margin-top: 0.35rem;
}

.contest-card-time {
    font-size: 0.7rem;
    color: var(--text-light);
}

.contest-card-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0 0 0.25rem 0;
    color: var(--text-color);
}

.contest-card-desc {
    font-size: 0.8rem;
    color: var(--text-light);
    margin: 0;
    line-height: 1.35;
}

.contest-card-join {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-color);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.contest-card-join:hover {
    text-decoration: underline;
}

/* Quiz categories grid (app order: Progressive Learning, Grade 1, Reasoning, Trivia, Stories) */
.home-categories-grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(2, 1fr);
}

.home-category-card {
    background: var(--card-bg);
    border-radius: var(--radius-card);
    padding: 1rem;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

.home-category-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.home-category-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary-container), var(--secondary-container));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--primary-color);
    margin-bottom: 0.75rem;
}

.home-category-card h3 {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 0.5rem 0;
    color: var(--text-color);
}

.home-category-card p {
    font-size: 0.7rem;
    color: var(--text-light);
    margin: 0;
    line-height: 1.35;
    flex: 1;
}

.home-category-play {
    display: inline-block;
    margin-top: auto;
    padding: 0.35rem 0.65rem;
    background: var(--primary-container);
    color: var(--primary-color);
    border-radius: var(--radius-pill);
    font-size: 0.8rem;
    font-weight: 700;
    width: fit-content;
}

/* Level List */
.level-list {
    list-style: none;
    margin-top: 1.5rem;
}

.level-item {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.level-item.locked {
    opacity: 0.6;
    background-color: #f3f4f6;
}

.level-info h3 {
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.level-info p {
    color: var(--text-light);
    font-size: 0.9rem;
}

.level-status {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.progress-badge {
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 600;
}

.progress-badge.completed {
    background-color: #d1fae5;
    color: #065f46;
}

.progress-badge.in-progress {
    background-color: #dbeafe;
    color: #1e40af;
}

/* Chat Interface */
.chat-container {
    background-color: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow);
    max-width: 800px;
    margin: 0 auto;
}

.chat-header {
    text-align: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.chat-header h1 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.chat-header p {
    color: var(--text-light);
}

/* Open Tests: full-screen generating state + session complete feedback */
.open-tests-generating-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    pointer-events: none;
}

.open-tests-generating-overlay.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.open-tests-generating-card {
    background: var(--card-bg);
    padding: 1.75rem 2rem;
    border-radius: var(--radius-card, 12px);
    box-shadow: var(--shadow-lg);
    text-align: center;
    max-width: 22rem;
    margin: 1rem;
}

.open-tests-generating-spinner {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: open-tests-spin 0.8s linear infinite;
}

@keyframes open-tests-spin {
    to {
        transform: rotate(360deg);
    }
}

.open-tests-generating-text {
    font-weight: 700;
    margin: 0 0 0.35rem;
    color: var(--text-color);
}

.open-tests-generating-sub {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-light);
    line-height: 1.4;
}

.open-tests-complete-banner {
    background: linear-gradient(
        135deg,
        color-mix(in srgb, var(--primary-color) 12%, var(--card-bg)),
        var(--card-bg)
    );
    border: 1px solid color-mix(in srgb, var(--primary-color) 35%, var(--border-color));
    padding: 1.35rem 1.5rem 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.35rem;
    box-shadow: var(--shadow);
    text-align: center;
    animation: open-tests-complete-in 0.5s ease-out;
}

@keyframes open-tests-complete-in {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.open-tests-complete-icon {
    font-size: 2.25rem;
    line-height: 1;
    margin-bottom: 0.5rem;
    animation: open-tests-celebrate 0.65s ease-out 1;
}

@keyframes open-tests-celebrate {
    from {
        opacity: 0;
        transform: scale(0.88);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.open-tests-complete-kicker {
    margin: 0 0 0.35rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-color);
}

.open-tests-complete-trophy {
    color: var(--warning-color, #f59e0b);
    font-size: 2.5rem;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.open-tests-complete-title {
    margin: 0 0 0.75rem;
    color: var(--primary-color);
    font-size: 1.25rem;
}

.open-tests-complete-line {
    margin: 0.3rem 0;
    color: var(--text-color);
}

.open-tests-complete-hint {
    margin: 1rem 0 1rem;
    font-size: 0.9rem;
    color: var(--text-light);
}

.open-tests-another-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    text-decoration: none;
}

#open-tests-topic-pick {
    scroll-margin-top: 6rem;
}

.chat-messages {
    min-height: 400px;
    max-height: 600px;
    overflow-y: auto;
    padding: 1rem;
    background-color: var(--bg-color);
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.chat-message {
    margin-bottom: 1rem;
    display: flex;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.system {
    justify-content: flex-start;
}

.chat-message.user {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 70%;
    padding: 1rem 1.25rem;
    border-radius: 20px;
    word-wrap: break-word;
    line-height: 1.5;
}

.message-bubble.system {
    background-color: #e0e7ff;
    color: #3730a3;
    border-bottom-left-radius: 6px;
}

.message-bubble.system.correct {
    background-color: #d1fae5;
    color: #065f46;
    border-left: 3px solid var(--success-color);
}

.message-bubble.system.incorrect {
    background-color: #fef3c7;
    color: #92400e;
}

.message-bubble.user {
    background-color: var(--primary-color);
    color: white;
    border-bottom-right-radius: 6px;
}

/* Inline XP reward styling */
.xp-reward {
    display: inline-block;
    background-color: var(--success-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.875rem;
    margin-left: 0.5rem;
}

.chat-form {
    display: flex;
    gap: 1rem;
}

.chat-form.mcq-form {
    flex-direction: column;
}

.chat-input {
    flex: 1;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 24px;
    font-size: 1rem;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.chat-submit {
    padding: 1rem 2rem;
    border-radius: 24px;
}

/* Multiple-choice options (shared UI) */
.mcq-options {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.mcq-radio {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.mcq-option {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background-color: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.mcq-option:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
    border-color: #c7d2fe;
}

.mcq-option-letter {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #3730a3;
    background-color: #e0e7ff;
    border: 1px solid #c7d2fe;
    margin-top: 2px;
}

.mcq-option-text {
    color: var(--text-color);
    font-size: 1.05rem;
    line-height: 1.4;
}

.mcq-radio:focus-visible + .mcq-option {
    outline: 3px solid #a5b4fc;
    outline-offset: 2px;
}

.mcq-radio:checked + .mcq-option {
    background-color: #eef2ff;
    border-color: var(--primary-color);
    box-shadow: var(--shadow-lg);
}

.mcq-radio:checked + .mcq-option .mcq-option-letter {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.mcq-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

@media (min-width: 768px) {
    .mcq-options {
        grid-template-columns: 1fr 1fr;
    }
}

/* Play Hub desktop: slightly larger header padding */
@media (min-width: 768px) {
    .play-hub-header {
        padding: 1.5rem 2rem 2rem;
    }
    .player-card {
        max-width: 480px;
    }
    .quest-cards-scroll:not(.missions-carousel),
    .contest-cards-scroll {
        flex-wrap: wrap;
        overflow-x: visible;
        gap: 1rem;
    }
    .quest-cards-scroll:not(.missions-carousel) .quest-card {
        flex: 0 0 calc(50% - 0.5rem);
        max-width: 260px;
    }
    .quest-cards-scroll.missions-carousel {
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 1rem;
        padding-inline: 1rem;
        scroll-padding-inline: 1rem;
    }
    .quest-cards-scroll.missions-carousel .quest-card {
        flex: 0 0 auto;
        width: 220px;
        max-width: 260px;
    }
    .contest-card {
        flex: 0 0 calc(50% - 0.5rem);
        max-width: 300px;
    }
    .home-categories-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
    }
    .home-category-card {
        min-height: 220px;
    }
}

@media (min-width: 1024px) {
    .home-categories-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Leaderboard */
.leaderboard-table {
    width: 100%;
    background-color: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.leaderboard-table thead {
    background-color: var(--primary-color);
    color: white;
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 1rem;
    text-align: left;
}

.leaderboard-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s;
}

.leaderboard-table tbody tr:hover {
    background-color: var(--bg-color);
}

.leaderboard-table tbody tr:last-child {
    border-bottom: none;
}

.rank-badge {
    display: inline-block;
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    border-radius: 50%;
    font-weight: bold;
    color: white;
}

.leaderboard-username-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.leaderboard-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.leaderboard-avatar-default {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.rank-badge.gold {
    background-color: #fbbf24;
}

.rank-badge.silver {
    background-color: #9ca3af;
}

.rank-badge.bronze {
    background-color: #d97706;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease-in;
}

.modal-content {
    background-color: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-close {
    color: var(--text-light);
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

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

.modal-body {
    padding: 1.5rem;
}

.modal-body p {
    margin: 0;
    color: var(--text-color);
    line-height: 1.6;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 2px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

.rank-badge.default {
    background-color: var(--primary-color);
}

.bot-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background-color: #fef3c7;
    color: #92400e;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

/* Footer */
.footer {
    background-color: var(--card-bg);
    border-top: 2px solid var(--border-color);
    padding: 1.5rem 0;
    text-align: center;
    color: var(--text-light);
    margin-top: auto;
    width: 100%;
}

/* Difficulty Badges */
.difficulty-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

.difficulty-badge.easy {
    background-color: #d1fae5;
    color: #065f46;
}

.difficulty-badge.medium {
    background-color: #fef3c7;
    color: #92400e;
}

.difficulty-badge.hard {
    background-color: #fee2e2;
    color: #991b1b;
}

/* Locked Topics */
.locked-topic {
    position: relative;
    cursor: pointer;
}

.topic-card.locked-topic:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--warning-color);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: block;
    }

    .main-wrapper {
        margin-left: 0;
    }

    .mobile-menu-toggle {
        display: block;
    }

    .topics-grid {
        grid-template-columns: 1fr;
    }

    .message-bubble {
        max-width: 85%;
    }

    .chat-form {
        flex-direction: column;
    }

    .chat-submit {
        width: 100%;
    }

    .sidebar-link span {
        display: inline;
    }

    /* Stack player card header content on small screens so it doesn't squeeze into one row */
    .player-card-top {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .player-card-rank {
        align-self: flex-start;
    }
}

/* Story reader (story_read.html): themes + focus column */
.story-reader-panel.story-reader-sepia {
    background-color: #f4ecd8 !important;
    border-color: #d4c4a8 !important;
}

.story-reader-panel.story-reader-sepia .story-reader-text {
    color: #3d3326 !important;
}

.story-reader-panel.story-reader-dark {
    background-color: #1e1e1e !important;
    border-color: #333 !important;
}

.story-reader-panel.story-reader-dark .story-reader-text {
    color: #e8e8e8 !important;
}

body.story-reader-focus-mode .main-content .container {
    max-width: 42rem;
}

.story-reader-toolbar #srFocus[aria-pressed="true"] {
    box-shadow: 0 0 0 2px var(--primary-color);
}

