@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Work+Sans:wght@500;600&display=swap');

:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-alt: #f8f8fb;
    --text: #1f2430;
    --muted: #6b728a;
    --border: #d9dce5;
    --border-strong: #c2c6d6;
    --accent: #4b61d1;
    --accent-dark: #3c4ea5;
    --accent-soft: #edf0ff;
    --legacy-light: #f1f1f4;
    --legacy-mid: #d4d4de;
    --legacy-dark: #464b5e;
    --shadow-soft: 0 4px 12px rgba(31, 36, 48, 0.06);
    --shadow-subtle: 0 1px 4px rgba(31, 36, 48, 0.05);
    --radius-lg: 18px;
    --radius-md: 12px;
}

body.theme-dark {
    --bg: #090c14;
    --surface: #151926;
    --surface-alt: #1b2032;
    --text: #f2f4ff;
    --muted: #a8b2d5;
    --border: #2a2f44;
    --border-strong: #3b4360;
    --accent: #8aa4ff;
    --accent-dark: #6f85dd;
    --accent-soft: rgba(138, 164, 255, 0.14);
    --legacy-light: #1f2537;
    --legacy-mid: #2d3448;
    --legacy-dark: #e8ebff;
    --shadow-soft: 0 6px 18px rgba(1, 3, 9, 0.45);
    --shadow-subtle: 0 2px 10px rgba(1, 3, 9, 0.3);
}

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

html {
    font-size: 16px;
}

body {
    margin: 0;
    min-height: 100vh;
    padding: 2.5rem 1.5rem 3rem;
    background: var(--bg);
    color: var(--text);
    font-family: 'Roboto', sans-serif;
    line-height: 1.7;
    transition: background 0.4s ease, color 0.2s ease;
}

::selection {
    background: var(--accent);
    color: #fff;
}

p {
    font-size: 1rem;
    margin: 0 0 1rem;
    color: var(--text);
}

a {
    color: var(--accent);
    font-weight: 500;
    text-decoration: none;
    transition: color 0.2s ease, box-shadow 0.2s ease;
}

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

a:focus-visible {
    outline: 3px solid var(--accent-soft);
    outline-offset: 3px;
    border-radius: 6px;
}

code {
    font-family: 'Roboto Mono', 'Fira Code', monospace;
    font-size: 0.9rem;
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
    background: var(--surface-alt);
}

img,
video,
iframe {
    max-width: 100%;
    height: auto;
    display: block;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0 2rem;
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-subtle);
    border: 1px solid var(--legacy-mid);
    overflow: hidden;
}

th,
td {
    border: 1px solid var(--legacy-mid);
    padding: 0.7rem 0.9rem;
    font-size: 0.95rem;
}

th {
    background: var(--legacy-light);
    font-weight: 600;
    letter-spacing: 0.02em;
}

tr:nth-child(even) td {
    background: var(--surface-alt);
}

ul {
    margin: 0.35rem 0 1rem 1.2rem;
    padding: 0;
}

ul li {
    margin-bottom: 0.35rem;
}

ol {
    margin: 0.6rem 0 1.2rem 1.4rem;
    padding-left: 1rem;
}

ol li {
    margin-bottom: 0.35rem;
}

h1,
h2,
h3,
h4,
h5 {
    font-family: 'Work Sans', 'Roboto', sans-serif;
    color: var(--text);
    margin: 1.8rem 0 0.5rem;
    line-height: 1.3;
}

h1 {
    font-size: 2.1rem;
}

h2 {
    font-size: 1.8rem;
}

h3 {
    font-size: 1.45rem;
}

h4 {
    font-size: 1.2rem;
}

h5 {
    font-size: 1rem;
    letter-spacing: 0.01em;
}

.content h1 {
    font-size: 1.4rem;
    margin-top: 1rem;
}

.content h2 {
    font-size: 1.25rem;
}

.content h3 {
    font-size: 1.15rem;
}

.content h4 {
    font-size: 1.05rem;
}

.mainpage {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--legacy-mid);
    border-radius: var(--radius-lg);
    padding: 2.5rem 3rem 3rem;
    box-shadow: 0 2px 10px rgba(31, 36, 48, 0.08);
}

.header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1.2rem;
    margin-bottom: 2.5rem;
    border-bottom: 1px solid var(--legacy-mid);
    padding-bottom: 1.2rem;
}

.header > a {
    text-decoration: none;
    color: inherit;
}

.pagetitle {
    display: inline-flex;
    flex-direction: column;
    gap: 0.2rem;
}

.pagetitle h2 {
    margin: 0;
    font-size: 2rem;
    letter-spacing: -0.02em;
}

.pagetitle h4 {
    margin: 0;
    font-weight: 500;
    color: var(--muted);
}

.menu {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.menu ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    align-items: center;
}

.menu li {
    display: flex;
    gap: 0.4rem;
}

.menu li a {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1rem;
    padding: 0.55rem 1.25rem;
    border-radius: 999px;
    background: var(--legacy-light);
    color: var(--legacy-dark);
    border: 1px solid var(--legacy-mid);
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    text-align: center;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.menu li a:hover {
    background: var(--surface-alt);
    color: var(--accent-dark);
    box-shadow: 0 1px 6px rgba(31, 36, 48, 0.08);
}

.menu li a.active,
.menu li a:focus {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(75, 97, 209, 0.24);
}

.menu-label {
    font-weight: 500;
}

.menu-sublabel {
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 400;
    letter-spacing: 0;
}

.menu li a:hover .menu-sublabel,
.menu li a:focus .menu-sublabel,
.menu li a.active .menu-sublabel {
    color: currentColor;
    opacity: 0.85;
}

.description,
.desc {
    font-size: 0.98rem;
    font-style: italic;
    color: var(--muted);
    margin: 0.2rem 0 1rem;
}

.mainpage > .description:first-of-type {
    margin-bottom: 1.5rem;
}

.post,
.mypost,
.lesson {
    display: block;
    width: 100%;
    border: 1px solid var(--legacy-mid);
    border-radius: var(--radius-md);
    background: var(--surface);
    padding: 1.35rem 1.6rem;
    margin: 1.5rem 0;
    box-shadow: var(--shadow-subtle);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.post:hover,
.mypost:hover,
.lesson:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(31, 36, 48, 0.1);
}

.mypost {
    border-width: 2px;
    border-color: var(--accent);
}

.lesson {
    border-left: 6px solid transparent;
    background: var(--surface);
}

.lesson h4 {
    margin-top: 0;
    font-size: 1.2rem;
}

.lesson.current {
    border-left-color: var(--accent);
    box-shadow: 0 4px 12px rgba(75, 97, 209, 0.12);
    background: var(--surface);
}

.lesson ol {
    margin-top: 0.9rem;
}

.lesson h5 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.lesson h5 li {
    list-style-position: inside;
}

.lesson ol li {
    padding: 0.4rem 0.6rem;
    border-left: 3px solid var(--legacy-mid);
    border-radius: 8px;
    transition: background 0.2s ease, border-color 0.2s ease;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.lesson ol li:hover {
    background: var(--accent-soft);
    border-left-color: var(--accent);
}

.lesson ol li i {
    color: var(--accent);
    margin-right: 0.35rem;
}

.lesson ol li a {
    color: inherit;
}

.lesson-item__info {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex: 1;
    min-width: 0;
}

.lesson-item__info a {
    flex: 1;
    min-width: 0;
}

.assignment-status {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.assignment-status-pill {
    padding: 0.15rem 0.65rem;
    font-size: 0.72rem;
}

.assignment-grade-chip {
    font-size: 0.75rem;
    color: var(--muted);
}

.lesson ol dl.short {
    margin-left: 1.5rem;
    padding-left: 0.25rem;
}

.lesson ol .description {
    margin-left: 1.5rem;
    padding-left: 0.25rem;
}

.grades-page {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    margin-top: 1.5rem;
}

.grades-sections {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.grades-toolbar {
    margin-top: 1rem;
    display: flex;
    justify-content: flex-end;
}

.view-toggle {
    border: 1px solid var(--legacy-mid);
    background: var(--surface-alt);
    color: var(--legacy-dark);
    font-size: 0.9rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 1rem;
    border-radius: 999px;
    box-shadow: none;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.view-toggle:hover {
    background: var(--legacy-light);
    border-color: var(--border-strong);
    transform: none;
    box-shadow: none;
}

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

body.theme-dark .view-toggle {
    color: var(--text);
}

.grades-section {
    border: 1px solid var(--legacy-mid);
    border-radius: var(--radius-lg);
    padding: 1.8rem;
    background: var(--surface);
    box-shadow: 0 2px 10px rgba(31, 36, 48, 0.08);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.grades-section.is-current {
    border-color: var(--accent);
    box-shadow: 0 3px 12px rgba(75, 97, 209, 0.12);
}

.grades-section__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--legacy-mid);
}

.lesson-description {
    margin: 0.25rem 0 0;
    color: var(--muted);
}

.grades-grid {
    margin-top: 1.2rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.1rem;
}

.grades-table {
    margin-top: 1.2rem;
    display: none;
}

.grades-table__wrapper {
    border: 1px solid var(--legacy-mid);
    border-radius: var(--radius-md);
    overflow-x: auto;
    box-shadow: 0 1px 6px rgba(31, 36, 48, 0.06);
    background: var(--surface);
}

.grades-table table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
    font-size: 0.92rem;
}

.grades-table thead {
    background: var(--surface-alt);
    text-align: left;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.grades-table th,
.grades-table td {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--legacy-mid);
    vertical-align: top;
}

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

.grade-row.is-graded .grade-row__primary {
    color: var(--accent-dark);
}

.grade-row__lesson,
.grade-row__title {
    min-width: 220px;
}

.grade-row__primary {
    font-weight: 600;
    color: var(--text);
}

.grade-row__secondary {
    margin-top: 0.25rem;
    color: var(--muted);
    font-size: 0.85rem;
}

.grade-row__type {
    font-weight: 600;
    color: var(--accent-dark);
}

.grade-row__status .grade-status-pill {
    display: inline-flex;
}

.grade-row__score {
    white-space: nowrap;
}

.grade-row__score .score {
    font-weight: 700;
    margin-right: 0.15rem;
}

.grade-row__score .max {
    color: var(--muted);
}

.grade-row__action {
    text-align: center;
    white-space: nowrap;
}

.grade-row__action .grade-link {
    display: inline-block;
}

.grades-page.compact-mode .grades-sections {
    display: none;
}

.grades-page.compact-mode .grades-table {
    display: block;
}

.grade-card {
    border: 1px solid var(--legacy-mid);
    border-left: 4px solid var(--legacy-mid);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    background: var(--surface);
    box-shadow: 0 1px 6px rgba(31, 36, 48, 0.06);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 220px;
}

.grade-card.is-graded {
    border-left-color: var(--accent);
}

.grade-card.is-submitted {
    border-left-color: var(--accent-dark);
    background: var(--surface);
}

.grade-card.is-pending {
    border-left-color: var(--legacy-mid);
}

.grade-card__meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--muted);
    gap: 0.5rem;
}

.grade-type {
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--accent-dark);
}

.grade-card.is-pending .grade-type {
    color: var(--legacy-dark);
}

.grade-status-pill {
    padding: 0.2rem 0.8rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--legacy-mid);
    background: var(--legacy-light);
    color: var(--legacy-dark);
    text-transform: none;
}

.status-graded {
    border-color: var(--accent);
    background: rgba(75, 97, 209, 0.12);
    color: var(--accent-dark);
}

.status-submitted {
    border-color: var(--accent);
    background: rgba(75, 97, 209, 0.08);
    color: var(--accent-dark);
}

.status-pending {
    border-style: dashed;
    background: transparent;
    color: var(--muted);
}

.grade-score {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
}

.grade-score .score {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text);
}

.grade-score .max {
    font-size: 0.95rem;
    color: var(--muted);
}

.grade-desc,
.grade-comment {
    margin: 0;
    font-size: 0.92rem;
    color: var(--muted);
}

.grade-card__actions {
    margin-top: auto;
}

.grade-link {
    font-weight: 600;
}

.empty-grades {
    margin-top: 1.5rem;
    padding: 1.5rem;
    border-radius: var(--radius-md);
    border: 1px dashed var(--legacy-mid);
    background: var(--surface-alt);
    text-align: center;
    color: var(--muted);
}

.output,
.input {
    display: block;
    width: 100%;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    border: 1px dashed var(--legacy-mid);
    background: var(--legacy-light);
    margin: 0.8rem 0 1.2rem;
}

.output {
    font-size: 0.85rem;
    font-family: 'Roboto Mono', monospace;
}

.output input[type=text] {
    width: 100%;
}

.footer {
    max-width: 1200px;
    margin: 2rem auto 1rem;
    background: var(--surface);
    padding: 1.5rem 3rem;
    border-radius: var(--radius-lg);
    color: var(--muted);
    box-shadow: 0 2px 8px rgba(31, 36, 48, 0.08);
    border: 1px solid var(--legacy-mid);
}

.bottombox {
    background: var(--legacy-light);
    padding: 1.75rem 2rem;
    border-radius: var(--radius-md);
    font-size: 1.05rem;
    box-shadow: 0 1px 6px rgba(31, 36, 48, 0.08);
    border: 1px solid var(--legacy-mid);
}

dl.short {
    margin-top: 0.4rem;
    margin-bottom: 1rem;
}

dl.short dt {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.2rem;
}

dl.short dd {
    margin-left: 0;
    color: var(--muted);
}

dl.short code {
    padding: 0.2rem 0.4rem;
}

button,
input[type=submit] {
    background: var(--accent);
    border: none;
    color: #fff;
    padding: 0.75rem 1.6rem;
    text-align: center;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(75, 97, 209, 0.18);
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

button:hover,
input[type=submit]:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(75, 97, 209, 0.2);
}

button:disabled,
input[type=submit]:disabled {
    cursor: not-allowed;
    background: var(--border-strong);
    box-shadow: none;
}

.theme-toggle {
    margin-left: 0.6rem;
    padding: 0.45rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--legacy-mid);
    background: var(--surface-alt);
    color: var(--legacy-dark);
    font-size: 0.9rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    box-shadow: none;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.theme-toggle i {
    font-size: 0.95rem;
}

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

.theme-toggle:hover {
    background: var(--legacy-light);
    border-color: var(--border-strong);
    transform: none;
    box-shadow: none;
}

body.theme-dark .theme-toggle {
    color: var(--text);
}

input[type=text],
input[type=password],
input[type=number],
input[type=file],
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    margin: 0.5rem 0;
    box-sizing: border-box;
    font-size: 1rem;
    font-family: inherit;
    border-radius: 12px;
    border: 1px solid var(--legacy-mid);
    background: var(--legacy-light);
    color: var(--text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

input[type=number] {
    max-width: 220px;
    font-family: monospace;
}

input.shorttext {
    width: 40%;
}

textarea {
    min-height: 160px;
    resize: vertical;
}

input[type=text]:focus,
input[type=password]:focus,
input[type=number]:focus,
input[type=file]:focus,
textarea:focus {
    border-color: var(--accent);
    outline: none;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 0 0 3px rgba(75, 97, 209, 0.18);
}

input[type=text]::placeholder,
input[type=password]::placeholder,
textarea::placeholder {
    color: var(--muted);
}

.fa-solid {
    color: var(--accent);
}

@media (max-width: 1024px) {
    body {
        padding: 2rem 1.25rem 2.5rem;
    }

    .mainpage {
        padding: 2rem;
    }

    .footer {
        padding: 1.2rem 2rem;
    }

    .header {
        gap: 1rem;
    }

    .menu ul {
        flex-wrap: wrap;
    }

    .grades-section {
        padding: 1.5rem;
    }

    .grades-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
}

@media (max-width: 900px) {
    .pagetitle h2 {
        font-size: 1.7rem;
    }

    .pagetitle h4 {
        font-size: 1.05rem;
    }

    .post,
    .mypost,
    .lesson {
        padding: 1.2rem 1.35rem;
    }

    .grade-card {
        min-height: 200px;
    }
}

@media (max-width: 720px) {
    body {
        padding: 1.3rem 0.75rem 1.9rem;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    .menu {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .menu ul {
        justify-content: flex-start;
        flex-direction: column;
        align-items: stretch;
        gap: 0.4rem;
    }

    .menu li {
        width: 100%;
    }

    .menu li a {
        width: 100%;
        justify-content: center;
        padding: 0.45rem 0.95rem;
        border-radius: 32px;
        font-size: 0.9rem;
    }

    .mainpage {
        padding: 1.5rem;
        border-radius: 16px;
    }

    .footer {
        padding: 1.2rem 1.4rem;
        border-radius: 16px;
    }

    table,
    th,
    td {
        font-size: 0.9rem;
    }

    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    th,
    td {
        white-space: nowrap;
    }

    .pagetitle h2 {
        font-size: 1.6rem;
    }

    .pagetitle h4 {
        font-size: 1rem;
    }

    .theme-toggle {
        width: auto;
        align-self: flex-start;
        justify-content: center;
        margin-left: 0;
        margin-top: 0.3rem;
        padding: 0.4rem 0.9rem;
    }

    .post,
    .mypost,
    .lesson {
        padding: 1.1rem 1.2rem;
    }

    .lesson ol li {
        flex-direction: column;
        align-items: flex-start;
    }

    .assignment-status {
        width: 100%;
        justify-content: space-between;
        margin-left: 0;
    }

    .grades-grid {
        gap: 0.9rem;
    }

    .grade-card {
        padding: 1.1rem;
    }

    input.shorttext,
    textarea,
    input[type=number] {
        width: 100%;
        max-width: 100%;
    }
}

@media (max-width: 600px) {
    html {
        font-size: 15px;
    }

    body {
        padding: 1.15rem 0.65rem 1.7rem;
    }

    .header {
        gap: 0.9rem;
    }

    .pagetitle h2 {
        font-size: 1.5rem;
    }

    .pagetitle h4 {
        font-size: 0.95rem;
    }

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

    .grade-card {
        min-height: auto;
    }

    .grade-card__meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
    }

    .grade-score {
        gap: 0.2rem;
    }

    .lesson ol {
        margin-left: 0;
        padding-left: 0;
    }

    .lesson ol li {
        border-left-width: 2px;
    }

    .input,
    .output {
        padding: 0.85rem 1rem;
    }

    .bottombox {
        padding: 1.25rem;
    }
}

@media (max-width: 480px) {
    body {
        padding: 0.9rem 0.55rem 1.4rem;
    }

    .mainpage,
    .footer {
        padding: 0.95rem 0.8rem;
        border-radius: 12px;
    }

    .footer {
        margin: 1.5rem auto 1rem;
    }

    .pagetitle {
        width: 100%;
    }

    .pagetitle h2 {
        font-size: 1.4rem;
    }

    .pagetitle h4 {
        font-size: 0.9rem;
    }

    .menu li a {
        font-size: 0.9rem;
        padding: 0.4rem 0.85rem;
    }

    .lesson {
        border-radius: 14px;
    }

    .grade-card h4 {
        font-size: 1rem;
    }

    .grade-score .score {
        font-size: 1.35rem;
    }

    button,
    input[type=submit] {
        width: 100%;
    }

    .theme-toggle {
        font-size: 0.85rem;
    }
}
