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

body {
    font-family: system-ui, sans-serif;
    min-height: 100vh;
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem 1.5rem 2rem;
    color: #1a1a2e;
    background: #fafafa;
    line-height: 1.7;
}

hr {
    margin: 1em 0 1em 0;
    border: none;
    border-top: 1px solid #e8e8ee;
}

a {
    color: #1a1a2e;
    text-decoration-color: #c0c0d0;
    text-underline-offset: 3px;
    transition: color 0.15s ease, text-decoration-color 0.15s ease;
}
a:hover {
    color: #4a4a6a;
    text-decoration-color: #4a4a6a;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1.5rem;
    margin-bottom: 2.5rem;
    border-bottom: 1px solid #e8e8ee;
}

.logo-link {
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 600;
    color: #1a1a2e;
}

.menu ul {
    list-style: none;
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.menu li {
    display: inline;
}

.menu a {
    text-decoration: none;
    color: #5a5a7a;
    padding: 0.4em 0.9em;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    transition: background 0.15s ease, color 0.15s ease;
}
.menu a:hover {
    background: #eeeef4;
    color: #1a1a2e;
}
.menu a.active {
    background: #dbeafe;
    color: #1e40af;
}

/*Article Cards (index) */
.article {
    margin: 0 0 1px;
    padding: 1.75rem 0;
    border-bottom: 1px solid #e8e8ee;
}
.article:first-of-type {
    padding-top: 0;
}
.article:last-of-type {
    border-bottom: none;
}

.article h2 {
    display: block;
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.35;
    margin: 0;
}
.article h2 a {
    text-decoration: none;
    color: #1a1a2e;
}
.article h2 a:hover {
    color: #4a4a6a;
}

.article p {
    margin: 0.75em 0;
    line-height: 1.7;
    color: #3a3a5a;
}

/* Timestamp */
.timestamp {
    font-size: 0.8rem;
    color: #8a8aa0;
    margin-top: 0.3em;
    letter-spacing: 0.01em;
}

/*Single Post */
.post {
    margin: 0;
    padding: 0;
}
.post h1 {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.35;
    margin-bottom: 0.15em;
    color: #1a1a2e;
}
.post p {
    margin: 0.75em 0;
    line-height: 1.7;
    color: #3a3a5a;
}

/* User / Profile Icon */
.user-icon {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    cursor: pointer;
    color: #b0b0c0;
    padding: 0.4em 0.6em;
    border-radius: 6px;
    transition: background 0.15s ease, color 0.15s ease;
    line-height: 1;
    text-decoration: none;
}
.user-icon:hover {
    background: #eeeef4;
    color: #1a1a2e;
}
.user-icon.authenticated {
    color: #4a4a8a;
}
.user-icon.authenticated:hover {
    color: #1a1a2e;
}

/* Profile Dropdown */
.profile-menu {
    position: relative;
}
.profile-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: #fff;
    border: 1px solid #e8e8ee;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.10);
    min-width: 180px;
    z-index: 100;
    padding: 0.5rem 0;
}
.profile-dropdown.open {
    display: block;
}
.profile-email {
    font-size: 0.78rem;
    color: #8a8aa0;
    padding: 0.5rem 1rem 0.4rem;
    border-bottom: 1px solid #e8e8ee;
    margin-bottom: 0.25rem;
    word-break: break-all;
}
.profile-dropdown a,
.profile-dropdown button.btn-link {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.45rem 1rem;
    font-size: 0.875rem;
    color: #3a3a5a;
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    transition: background 0.12s ease;
    box-sizing: border-box;
}
.profile-dropdown a:hover,
.profile-dropdown button.btn-link:hover {
    background: #f4f4f8;
    color: #1a1a2e;
}

/* Login page */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 40vh;
}

/* Members list */
.admin-members-list {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
}
.admin-members-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0;
    border-bottom: 1px solid #e8e8ee;
    font-size: 0.875rem;
    color: #3a3a5a;
}
.admin-form-inline {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}
.admin-form-inline .form-group {
    margin-bottom: 0;
    flex: 1;
}

/* Dark mode: profile dropdown */
html.dark .profile-dropdown {
    background: #1a1a2e;
    border-color: #2a2a40;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
html.dark .profile-email {
    color: #6a6a80;
    border-bottom-color: #2a2a40;
}
html.dark .profile-dropdown a,
html.dark .profile-dropdown button.btn-link {
    color: #c0c0d8;
}
html.dark .profile-dropdown a:hover,
html.dark .profile-dropdown button.btn-link:hover {
    background: #2a2a40;
    color: #e0e0f0;
}
html.dark .admin-members-list li {
    border-bottom-color: #2a2a40;
    color: #b0b0c8;
}
html.dark .user-icon.authenticated {
    color: #8080c0;
}

/* Dark Mode Toggle */
.dark-toggle {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    cursor: pointer;
    color: #b0b0c0;
    padding: 0.4em 0.6em;
    border-radius: 6px;
    transition: background 0.15s ease, color 0.15s ease;
    line-height: 1;
}
.dark-toggle:hover {
    background: #eeeef4;
    color: #1a1a2e;
}
.dark-toggle .icon-sun { display: none; }
.dark-toggle .icon-moon { display: block; }

/*Study Session */
.study-question h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

.study-choices {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.study-choice {
    display: block;
    width: 100%;
    padding: 0.85rem 1.1rem;
    text-align: left;
    background: #fff;
    border: 1px solid #d8d8e4;
    border-radius: 6px;
    font-size: 0.95rem;
    color: #1a1a2e;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    font-family: inherit;
    line-height: 1.5;
}
.study-choice:hover:not(:disabled) {
    background: #eeeef4;
    border-color: #c0c0d0;
}
.study-choice:disabled {
    cursor: default;
    opacity: 0.85;
}
.study-choice-correct {
    background: #d4edda !important;
    border-color: #28a745 !important;
    color: #155724 !important;
}
.study-choice-wrong {
    background: #f8d7da !important;
    border-color: #dc3545 !important;
    color: #721c24 !important;
}

.study-result {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
}
.study-result-pass {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}
.study-result-fail {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.study-done {
    text-align: center;
    color: #8a8aa0;
    padding: 2rem 0;
    font-size: 1rem;
}

.study-loading {
    text-align: center;
    color: #8a8aa0;
    padding: 2rem 0;
}

.study-error {
    color: #dc3545;
    text-align: center;
    padding: 1rem 0;
}

/* Admin */
.admin-back {
    margin-bottom: 1.5rem;
}
.admin-heading {
    margin-bottom: 1.5rem;
}
.admin-subheading {
    margin-bottom: 1rem;
}
.admin-section-sep {
    margin: 2rem 0;
}
.admin-delete-form {
    margin-top: 0.75rem;
}
.admin-question-form {
    max-width: 600px;
}
.admin-questions-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 1rem;
}
.admin-empty {
    color: #8a8aa0;
}
.admin-import-help {
    margin-bottom: 1rem;
}
.admin-import-heading {
    margin-bottom: 0.5rem;
}
.admin-actions {
    white-space: nowrap;
}
.admin-inline-form {
    display: inline;
}
.label-hint {
    color: #8a8aa0;
}
.admin-question-id-col {
    width: 30%;
}
.admin-actions-col {
    width: 10%;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}
.admin-table th,
.admin-table td {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid #e8e8ee;
}
.admin-table th {
    font-weight: 600;
    color: #5a5a7a;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.admin-form {
    max-width: 480px;
}
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
    color: #3a3a5a;
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="file"],
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d8d8e4;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    color: #1a1a2e;
    background: #fff;
    transition: border-color 0.15s ease;
    line-height: 1.5;
}
.form-group input[type="file"] {
    padding: 0.4rem 0.5rem;
}
.form-group input[type="text"]:focus,
.form-group input[type="email"]:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #6060a0;
}
.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.btn-primary {
    display: inline-block;
    padding: 0.5rem 1.1rem;
    background: #1e40af;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s ease;
    text-decoration: none;
    line-height: 1.5;
}
.btn-primary:hover {
    background: #1d3a98;
    color: #fff;
    text-decoration: none;
}
.btn-danger {
    display: inline-block;
    padding: 0.5rem 1.1rem;
    background: #dc3545;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s ease;
    text-decoration: none;
    line-height: 1.5;
}
.btn-danger:hover {
    background: #c82333;
    color: #fff;
}
.btn-link {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
    line-height: inherit;
}
.btn-link-danger {
    color: #dc3545;
}
.btn-link-danger:hover {
    color: #a71d2a;
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}
.flash-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}
.flash-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/*Responsive */
@media (max-width: 640px) {
    body {
        padding: 1.25rem 1rem 1.25rem;
    }

    .menu a {
        font-size: 0.78rem;
        padding: 0.35em 0.65em;
    }

    .menu ul {
        gap: 0.15rem;
    }

    .header {
        margin-bottom: 1.5rem;
        padding-bottom: 1rem;
    }

    .article {
        padding: 1.25rem 0;
    }
    .article h2 {
        font-size: 1.1rem;
    }

    .post h1 {
        font-size: 1.25rem;
    }
}

/* Dark Mode */
html.dark body {
    color: #e0e0f0;
    background: #13131f;
}
html.dark a {
    color: #c8c8e8;
    text-decoration-color: #4a4a6a;
}
html.dark a:hover {
    color: #e8e8ff;
    text-decoration-color: #8080a0;
}
html.dark .header {
    border-bottom-color: #2a2a40;
}
html.dark .menu a {
    color: #9090b0;
}
html.dark .menu a:hover {
    background: #1e1e30;
    color: #e0e0f0;
}
html.dark .article {
    border-bottom-color: #2a2a40;
}
html.dark .article h2 a {
    color: #e0e0f0;
}
html.dark .article h2 a:hover {
    color: #c8c8ff;
}
html.dark .article p {
    color: #b0b0c8;
}
html.dark .timestamp {
    color: #6a6a80;
}
html.dark .post h1 {
    color: #e0e0f0;
}
html.dark .post p {
    color: #b0b0c8;
}
html.dark .logo-link {
    color: #e0e0f0;
}
html.dark .dark-toggle {
    color: #9090b0;
}
html.dark .dark-toggle:hover {
    background: #1e1e30;
    color: #e0e0f0;
}
html.dark .dark-toggle .icon-sun { display: block; }
html.dark .dark-toggle .icon-moon { display: none; }
html.dark hr {
    border-top-color: #2a2a40;
}

/* Dark mode study session */
html.dark .study-choice {
    background: #1e1e30;
    border-color: #2a2a40;
    color: #e0e0f0;
}
html.dark .study-choice:hover:not(:disabled) {
    background: #282840;
    border-color: #3a3a55;
}
html.dark .study-choice-correct {
    background: #1a3a2a !important;
    border-color: #28a745 !important;
    color: #8ada8a !important;
}
html.dark .study-choice-wrong {
    background: #3a1a1a !important;
    border-color: #dc3545 !important;
    color: #f5a0a0 !important;
}
html.dark .study-result-pass {
    background: #1a3a2a;
    color: #8ada8a;
    border-color: #28a745;
}
html.dark .study-result-fail {
    background: #3a1a1a;
    color: #f5a0a0;
    border-color: #dc3545;
}
html.dark .study-done,
html.dark .study-loading {
    color: #6a6a80;
}

/* Dark mode admin */
html.dark .admin-table th {
    color: #9090b0;
}
html.dark .admin-table th,
html.dark .admin-table td {
    border-bottom-color: #2a2a40;
}
html.dark .form-group label {
    color: #b0b0c8;
}
html.dark .form-group input[type="text"],
html.dark .form-group input[type="email"],
html.dark .form-group input[type="file"],
html.dark .form-group textarea {
    background: #1e1e30;
    border-color: #2a2a40;
    color: #e0e0f0;
}
html.dark .form-group input[type="text"]:focus,
html.dark .form-group textarea:focus {
    border-color: #8080c0;
}
html.dark .flash-success {
    background: #1a3a2a;
    color: #8ada8a;
    border-color: #28a745;
}
html.dark .flash-error {
    background: #3a1a1a;
    color: #f5a0a0;
    border-color: #dc3545;
}
html.dark .admin-empty,
html.dark .label-hint {
    color: #6a6a80;
}
