body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

body > .main-container {
    flex: 1 0 auto;
    width: 100%;
}

.app-footer {
    flex: 0 0 auto;
    background: #ffffff;
    border-top: 1px solid #dbe4ee;
    padding: 20px 30px;
}

.app-footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px 24px;
    max-width: 1220px;
    margin: 0 auto;
    color: #475569;
    font-size: 14px;
}

.app-footer-brand {
    color: #2563eb;
    font-size: 18px;
    font-weight: 700;
}

.app-footer-brand:hover {
    text-decoration: underline;
}

.app-footer small {
    font-size: 12px;
}

@media (max-width: 600px) {
    .app-footer-inner {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }
}

/* Navbar */
.navbar {
    width: 100%;
    background: #ffffff;
    border-bottom: 1px solid #dbe4ee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 40px;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-toggle {
    display: none;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 5px;
    border: 1px solid #cfe0ff;
    border-radius: 10px;
    background: #ffffff;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.nav-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    border-radius: 999px;
    background: #1e293b;
    transform-origin: center;
    transition: transform 0.24s ease, opacity 0.18s ease, background-color 0.2s ease;
}

.nav-toggle:hover {
    border-color: #8fb4ff;
    box-shadow: 0 10px 22px rgba(37, 99, 235, 0.12);
    transform: translateY(-1px);
}

.navbar.nav-open .nav-toggle {
    background: #eff6ff;
    border-color: #2f6fec;
}

.navbar.nav-open .nav-toggle span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.navbar.nav-open .nav-toggle span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0.4);
}

.navbar.nav-open .nav-toggle span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.nav-left,
.nav-center,
.nav-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.nav-left,
.nav-right {
    position: relative;
    z-index: 2;
}

.nav-center {
    left: 50%;
    position: absolute;
    transform: translateX(-50%);
    z-index: 1;
}

.logo {
    font-size: 28px;
    font-weight: bold;
    color: #2563eb;
}

.nav-link {
    color: #334155;
    font-size: 16px;
    font-weight: 600;
    padding: 10px 14px;
    border-radius: 8px;
    transition: 0.3s;
}

.nav-link--with-badge {
    align-items: center;
    display: inline-flex;
    gap: 8px;
}

.nav-notification-badge {
    align-items: center;
    background: #dc2626;
    border: 2px solid #ffffff;
    border-radius: 999px;
    color: #ffffff;
    display: inline-flex;
    font-size: 12px;
    font-weight: 800;
    justify-content: center;
    line-height: 1;
    min-height: 20px;
    min-width: 20px;
    padding: 2px 6px;
}

.nav-link--active {
    color: #6366f1;
    font-weight: 600;
    border-bottom: 2px solid #6366f1;
}

.nav-link:hover {
    background: #eef4ff;
    color: #2563eb;
}

.mobile-auth-link {
    display: none;
}

.user-greeting-compact {
    display: none;
}

.nav-learning-menu {
    position: relative;
}

.nav-learning-btn {
    background: transparent;
    border: 0;
    cursor: pointer;
    font-family: inherit;
    margin: 0;
}

.nav-learning-btn.nav-link--active {
    background: transparent;
    border-bottom: 2px solid #6366f1;
}

.nav-learning-caret {
    color: #64748b;
    font-size: 10px;
    margin-left: 2px;
}

.nav-learning-dropdown {
    background: #ffffff;
    border: 1px solid #dbe4ee;
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
    display: block;
    left: 0;
    min-width: 190px;
    opacity: 0;
    padding: 8px;
    pointer-events: none;
    position: absolute;
    top: calc(100% + 8px);
    transform: translateY(-6px) scale(0.98);
    transform-origin: top left;
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
    visibility: hidden;
    z-index: 1100;
}

.nav-learning-dropdown.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    visibility: visible;
}

.nav-learning-item {
    align-items: center;
    border-radius: 8px;
    color: #334155;
    display: flex;
    font-size: 15px;
    font-weight: 600;
    justify-content: space-between;
    padding: 10px 12px;
    text-decoration: none;
}

.nav-learning-item:hover {
    background: #eef4ff;
    color: #2563eb;
}

.nav-submenu-badge {
    align-items: center;
    background: #dc2626;
    border-radius: 999px;
    color: #ffffff;
    display: inline-flex;
    font-size: 11px;
    font-weight: 800;
    justify-content: center;
    line-height: 1;
    min-height: 17px;
    min-width: 17px;
    padding: 2px 5px;
}

.nav-user {
    font-weight: bold;
    color: #1d4ed8;
    padding: 10px 12px;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    min-height: 48px;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 700;
    text-decoration: none;
    transition: 0.3s;
}

.nav-btn-outline {
    border: 1px solid #2563eb;
    color: #2563eb;
    background: white;
}

.nav-btn-outline:hover {
    background: #2563eb;
    color: white;
}

.nav-btn-primary {
    background: #2563eb;
    color: white;
}

.nav-btn-primary:hover {
    background: #1d4ed8;
    color: white;
}

@media (max-width: 1360px) {
    .navbar {
        padding-left: clamp(20px, 2.4vw, 40px);
        padding-right: clamp(20px, 2.4vw, 40px);
    }

    .nav-left,
    .nav-center,
    .nav-right {
        gap: clamp(8px, 1vw, 14px);
    }

    .nav-link {
        padding-left: clamp(8px, 0.9vw, 14px);
        padding-right: clamp(8px, 0.9vw, 14px);
    }

    .logo {
        font-size: clamp(24px, 2.1vw, 28px);
    }

    .user-menu-btn {
        padding-left: clamp(10px, 1vw, 16px);
        padding-right: clamp(10px, 1vw, 16px);
    }
}

@media (max-width: 1100px) {
    .navbar {
        display: grid;
        grid-template-columns: auto 1fr auto;
        grid-template-areas: "toggle logo user";
        gap: 12px 16px;
        padding: 16px 24px;
        overflow: visible;
    }

    .nav-toggle {
        display: inline-flex;
        grid-area: toggle;
    }

    .nav-center {
        grid-area: logo;
        position: static;
        transform: none;
        justify-content: center;
    }

    .nav-right {
        grid-area: user;
        justify-content: flex-end;
    }

    .nav-left {
        display: flex;
        position: absolute;
        top: calc(100% + 4px);
        left: 24px;
        width: min(210px, calc(100vw - 48px));
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        opacity: 0;
        padding: 8px;
        pointer-events: none;
        background: #ffffff;
        border: 1px solid #dbe4ee;
        border-radius: 12px;
        box-shadow: 0 20px 42px rgba(15, 23, 42, 0.16);
        transform: translateY(-8px) scale(0.96);
        transform-origin: top left;
        transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s ease;
        visibility: hidden;
    }

    .navbar.nav-open .nav-left {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0) scale(1);
        visibility: visible;
    }

    .nav-left .nav-link,
    .nav-learning-menu {
        opacity: 0;
        transform: translateX(-8px);
        transition: opacity 0.2s ease, transform 0.2s ease;
    }

    .navbar.nav-open .nav-left .nav-link,
    .navbar.nav-open .nav-learning-menu {
        opacity: 1;
        transform: translateX(0);
    }

    .navbar.nav-open .nav-left > :nth-child(1) {
        transition-delay: 0.03s;
    }

    .navbar.nav-open .nav-left > :nth-child(2) {
        transition-delay: 0.06s;
    }

    .navbar.nav-open .nav-left > :nth-child(3) {
        transition-delay: 0.09s;
    }

    .navbar.nav-open .nav-left > :nth-child(4) {
        transition-delay: 0.12s;
    }

    .navbar.nav-open .nav-left > :nth-child(5) {
        transition-delay: 0.15s;
    }

    .navbar.nav-open .nav-left > :nth-child(6) {
        transition-delay: 0.18s;
    }

    .nav-left .nav-link,
    .nav-learning-btn {
        width: 100%;
        justify-content: flex-start;
        padding: 9px 10px;
    }

    .nav-learning-dropdown {
        position: absolute;
        left: calc(100% + 10px);
        top: 0;
        min-width: 220px;
        width: max-content;
        max-width: min(280px, calc(100vw - 320px));
        margin-top: 0;
        box-shadow: 0 16px 34px rgba(15, 23, 42, 0.14);
    }

    .logo {
        font-size: 30px;
    }
}

@media (max-width: 640px) {
    .navbar--guest {
        grid-template-columns: auto 1fr;
        grid-template-areas: "toggle logo";
    }

    .nav-right--guest {
        display: none;
    }

    .mobile-auth-link {
        display: flex;
    }

    .nav-learning-dropdown {
        display: none;
        position: static;
        width: 100%;
        max-width: none;
        min-width: 0;
        margin-top: 0;
        box-shadow: none;
        opacity: 1;
        padding: 0;
        pointer-events: auto;
        transform: none;
        transition: none;
        visibility: visible;
    }

    .nav-learning-dropdown.show {
        display: block;
        margin-top: 6px;
        padding: 8px;
    }
}

@media (max-width: 600px) and (orientation: portrait) {
    .user-menu-btn {
        padding-left: 10px;
        padding-right: 10px;
        min-width: 0;
        white-space: nowrap;
    }

    .user-greeting-full {
        display: none;
    }

    .user-greeting-compact {
        display: inline;
    }

    .user-menu-btn .caret {
        margin-left: 4px;
    }
}

/* Main Layout */
.main-container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 40px 30px;
}

/* Hero Section */
.hero {
    background: linear-gradient(135deg, #dbeafe, #eff6ff);
    padding: 60px 40px;
    border-radius: 24px;
    margin-bottom: 40px;
    text-align: center;
}

.hero h1 {
    font-size: 48px;
    color: #1d4ed8;
    margin-bottom: 16px;
}

.hero p {
    font-size: 20px;
    color: #334155;
    max-width: 800px;
    margin: 0 auto;
}

/* Subjects Section */
.subjects-section {
    margin-top: 20px;
}

.subjects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
}

.subject-card {
    background: white;
    border-radius: 20px;
    padding: 28px;
    border: 1px solid #dbe4ee;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.05);
    transition: 0.3s;
    color: #1e293b;
}

.subject-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 14px 30px rgba(37, 99, 235, 0.12);
    border-color: #93c5fd;
}

.subject-card h2 {
    color: #2563eb;
    margin-bottom: 12px;
    font-size: 28px;
}

.subject-card p {
    font-size: 16px;
    line-height: 1.6;
    color: #475569;
}

/* Subject Page */
.subject-header {
    margin-bottom: 30px;
}

.subject-header h1 {
    font-size: 42px;
    color: #1d4ed8;
    margin-bottom: 10px;
}

.subject-header p {
    font-size: 18px;
    color: #475569;
}

.subject-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 24px;
    align-items: start;
}

.grades-panel,
.topics-panel {
    background: white;
    border-radius: 20px;
    padding: 24px;
    border: 1px solid #dbe4ee;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.04);
}

.grades-panel h2,
.topics-panel h2 {
    margin-bottom: 20px;
    color: #1e293b;
    font-size: 26px;
}

.grade-button {
    width: 100%;
    background: #eff6ff;
    color: #1d4ed8;
    border: none;
    padding: 16px;
    margin-bottom: 12px;
    border-radius: 14px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
}

.grade-button:hover {
    background: #2563eb;
    color: white;
}

.topics-box {
    background: #f8fbff;
    border: 1px solid #dbe4ee;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
}

.topics-box h3 {
    margin-bottom: 14px;
    color: #1d4ed8;
}

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

.topic-item {
    padding: 14px 0;
    border-bottom: 1px solid #e5edf5;
}

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

.topic-section-heading {
    margin: 18px 0 8px;
    padding: 0 0 8px;
    border-bottom: 1px solid #dbeafe;
    color: #0f172a;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 0.04em;
    list-style: none;
    text-transform: uppercase;
}

.topic-section-heading:first-child {
    margin-top: 0;
}

.topic-item-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.topic-item-copy {
    min-width: 0;
}

.topic-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.topic-title-link {
    color: #4c1d95;
    font: inherit;
    font-size: 18px;
    text-align: left;
}

.topic-expand-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    background: transparent;
    border: 0;
    padding: 0;
    cursor: pointer;
}

.topic-expand-toggle:hover {
    color: #1d4ed8;
}

.topic-expand-icon {
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    background: #eff6ff;
    color: #2563eb;
    font-size: 13px;
    font-weight: 900;
    line-height: 1;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.topic-expand-toggle.is-expanded .topic-expand-icon {
    background: #2563eb;
    border-color: #2563eb;
    color: #ffffff;
}

.topic-page-list {
    display: grid;
    gap: 8px;
    margin: 12px 0 2px 0;
    padding: 10px 0 0 16px;
    border-left: 3px solid #bfdbfe;
}

.topic-page-list.hidden {
    display: none;
}

.topic-subsection {
    display: grid;
    gap: 8px;
}

.topic-subsection-title {
    align-items: center;
    background: #ffffff;
    border: 1px solid #dbeafe;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    color: #0f172a;
    cursor: pointer;
    display: list-item;
    font-size: 16px;
    font-weight: 800;
    margin: 2px 0;
    padding: 10px 14px;
    text-align: left;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
    width: 100%;
}

.topic-subsection-title:hover {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1d4ed8;
    transform: translateX(2px);
}

.topic-subsection[open] .topic-subsection-title {
    background: #dbeafe;
    border-color: #93c5fd;
    color: #ffffff;
    color: #1d4ed8;
}

.topic-subsection-pages {
    display: grid;
    gap: 6px;
    padding: 2px 0 4px;
}

.topic-subsection .topic-page-link {
    margin-left: 18px;
}

.topic-page-link {
    display: flex;
    align-items: center;
    gap: 10px;
    width: fit-content;
    max-width: 100%;
    color: #1e293b;
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
}

.topic-page-link:hover {
    background: #eff6ff;
    color: #1d4ed8;
}

.topic-page-number {
    display: inline-flex;
    width: 24px;
    height: 24px;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 13px;
    font-weight: 800;
    flex: 0 0 auto;
}

.topic-view-btn {
    background: #2563eb;
    color: white;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: bold;
    transition: 0.3s;
    white-space: nowrap;
}

.topic-view-btn:hover {
    background: #1d4ed8;
}

.subject-card-disabled {
    opacity: 0.68;
}

.subject-card-disabled:hover {
    transform: none;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.05);
    border-color: #dbe4ee;
}

.subscription-lock-note {
    display: inline-block;
    margin-top: 0.65rem;
    color: #64748b;
    font-size: 0.86rem;
    font-weight: 700;
}

.disabled-link {
    background: #e5e7eb !important;
    border-color: #d1d5db !important;
    color: #6b7280 !important;
    cursor: not-allowed;
    opacity: 1;
    pointer-events: none;
    filter: grayscale(0.25);
}

.grade-button-disabled,
.topic-item-disabled {
    opacity: 0.62;
}

.topics-placeholder {
    color: #64748b;
    font-size: 18px;
    padding: 30px 10px;
}

/* Generic Page Card */
.page-card {
    background: white;
    border-radius: 20px;
    padding: 32px;
    border: 1px solid #dbe4ee;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.04);
    width: 100%;
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
}

.page-card h1 {
    font-size: 38px;
    color: #1d4ed8;
    margin-bottom: 20px;
}

.page-card p {
    font-size: 18px;
    line-height: 1.8;
    color: #475569;
    margin-bottom: 16px;
}

/* Responsive */
@media (max-width: 900px) {
    .subject-layout {
        grid-template-columns: 1fr;
    }

    .hero h1 {
        font-size: 36px;
    }

    .subject-header h1 {
        font-size: 34px;
    }
}

@media (max-width: 600px) and (orientation: portrait) {
    .subject-layout {
        display: block;
        width: 100%;
        max-width: 100%;
    }

    .grades-panel {
        width: 100%;
        max-width: 100%;
        overflow: hidden;
        box-sizing: border-box;
        margin-bottom: 16px;
    }

    .grades-panel .grade-button {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .topics-panel {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
    }

    .topic-item-main {
        align-items: flex-start;
        flex-direction: column;
    }

    .topic-actions {
        justify-content: flex-start;
        width: 100%;
    }

    .topic-view-btn {
        padding: 9px 12px;
        font-size: 13px;
    }

    .topic-page-list {
        padding-left: 10px;
    }

    .topic-page-link {
        width: 100%;
        box-sizing: border-box;
    }

    .homework-card {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }

    .homework-btn {
        box-sizing: border-box;
        max-width: 100%;
    }

}
