:root {
    --green: #1f5a41;
    --green-dark: #173f31;
    --green-soft: #e9f2ee;
    --gray: #66706b;
    --border: #d7dfda;
    --bg: #f5f7f6;
    --white: #fff;
    --danger: #b42318
}

* {
    box-sizing: border-box
}

body {
    margin: 0;
    font-family: Arial, "Helvetica Neue", sans-serif;
    color: #202522;
    background: var(--bg);
    line-height: 1.5
}

a {
    color: var(--green);
    text-decoration: none
}

.topbar {
    height: 64px;
    background: var(--green-dark);
    color: white;
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 18px;
    position: sticky;
    top: 0;
    z-index: 20
}

.topbar img {
    width: 40px;
    height: 40px;
    border-radius: 7px
}

.topbar .brand {
    font-weight: 800;
    font-size: 20px
}

.topbar nav {
    display: flex;
    gap: 16px;
    margin-left: 24px
}

.topbar nav a {
    color: #eaf4ef
}

.topbar .user {
    margin-left: auto;
    display: flex;
    gap: 14px;
    align-items: center
}

.mobile-menu-button {
    display: none;
    border: 1px solid rgba(255, 255, 255, .55);
    border-radius: 7px;
    padding: 8px 12px;
    background: transparent;
    color: white;
    font: inherit;
    font-weight: 700;
    cursor: pointer
}

.container {
    max-width: 1240px;
    margin: 24px auto;
    padding: 0 18px
}

.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(20, 60, 40, .05);
    margin-bottom: 18px
}

.banner {
    width: 100%;
    max-height: 250px;
    object-fit: cover;
    border-radius: 12px
}

.grid {
    display: grid;
    gap: 16px
}

.grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr))
}

.stat {
    font-size: 28px;
    color: var(--green);
    font-weight: 800
}

.muted {
    color: var(--gray)
}

h1,
h2,
h3 {
    color: var(--green-dark);
    margin-top: 0
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white
}

th,
td {
    border-bottom: 1px solid var(--border);
    padding: 10px;
    text-align: left;
    vertical-align: top
}

th {
    background: var(--green);
    color: white
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 7px;
    padding: 9px 14px;
    background: var(--green);
    color: white;
    cursor: pointer;
    font-weight: 700
}

.btn.secondary {
    background: #e7ece9;
    color: var(--green-dark)
}

.btn.danger {
    background: var(--danger)
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap
}

.field {
    margin-bottom: 14px
}

.field label {
    display: block;
    font-weight: 700;
    margin-bottom: 5px
}

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #bfc9c3;
    border-radius: 7px;
    background: white;
    font: inherit
}

.field textarea {
    min-height: 110px
}

.errors,
.alert {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px
}

.errors {
    background: #feeceb;
    color: #8a1c14
}

.alert {
    background: var(--green-soft);
    color: var(--green-dark)
}

.pagination {
    margin-top: 16px
}

.exam-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    height: calc(100vh - 115px)
}

.exam-panel {
    background: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: auto;
    padding: 20px
}

.timer {
    position: sticky;
    top: 0;
    background: var(--green-dark);
    color: white;
    padding: 10px;
    border-radius: 8px;
    font-size: 20px;
    font-weight: 800;
    text-align: center;
    z-index: 4
}

.question {
    padding: 16px 0;
    border-bottom: 1px solid var(--border)
}

.option {
    display: block;
    padding: 9px;
    margin: 6px 0;
    border: 1px solid var(--border);
    border-radius: 7px
}

.mobile-tabs {
    display: none
}

.rich-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    padding: 7px;
    margin-bottom: 0;
    border: 1px solid #bfc9c3;
    border-bottom: 0;
    border-radius: 7px 7px 0 0;
    background: #f4f7f5
}

.rich-toolbar button,
.rich-toolbar select {
    min-height: 32px;
    padding: 5px 9px;
    border: 1px solid #aebbb4;
    border-radius: 5px;
    background: #fff;
    color: #17231e;
    cursor: pointer
}

.rich-toolbar button:hover,
.rich-toolbar select:hover {
    background: #e7f1ec
}

.rich-toolbar button:disabled {
    cursor: wait;
    opacity: .65
}

.wysiwyg-color {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 32px;
    padding: 3px 7px;
    border: 1px solid #aebbb4;
    border-radius: 5px;
    background: #fff;
    font-size: 13px
}

.wysiwyg-color input {
    width: 25px;
    height: 24px;
    padding: 0;
    border: 0
}

.rich-editor {
    min-height: 95px;
    border: 1px solid #bfc9c3;
    border-radius: 0 0 7px 7px;
    padding: 10px;
    background: #fff;
    line-height: 1.55;
    overflow-wrap: anywhere
}

.rich-editor:focus {
    border-color: var(--green);
    box-shadow: inset 0 0 0 1px var(--green);
    outline: none
}

.rich-editor img,
.passage-instructions img,
.passage-content img,
.question-content img,
.option-content img,
.answer-explanation-content img,
.exam-instructions img,
.rich-content img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 10px auto;
    border-radius: 6px
}

.rich-editor p:first-child,
.rich-content p:first-child {
    margin-top: 0
}

.rich-editor p:last-child,
.rich-content p:last-child {
    margin-bottom: 0
}

.builder-passage {
    border-left: 4px solid var(--green);
    padding-left: 14px;
    margin-bottom: 24px
}

.builder-question {
    background: #f6f8f7;
    padding: 14px;
    border-radius: 8px;
    margin: 12px 0
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 20px;
    background: var(--green-soft);
    color: var(--green-dark);
    font-size: 12px
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(rgba(16, 47, 37, .72), rgba(16, 47, 37, .72)), url('/assets/banner.jpg') center/cover
}

.login-card {
    width: min(430px, 92vw);
    background: #fff;
    padding: 32px;
    border-radius: 16px
}

.login-card .logo {
    width: 90px;
    display: block;
    margin: 0 auto 14px
}

.answer-correct {
    background: #e8f6ed;
    border-left: 4px solid #218739;
    padding: 8px
}

.answer-wrong {
    background: #fff0ef;
    border-left: 4px solid #c7352a;
    padding: 8px
}

.page-heading-actions,
.section-heading,
.lesson-sentences-heading,
.lesson-detail-heading,
.sentence-card-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap
}

.page-heading-actions h1,
.section-heading h2,
.lesson-sentences-heading h2,
.sentence-card-heading h3 {
    margin-bottom: 0
}

.lesson-sentences-heading {
    margin: 24px 0 12px
}

.lesson-input-methods h2 {
    margin-bottom: 12px
}

.lesson-method-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap
}

.lesson-method-button.is-active {
    background: var(--green);
    color: white
}

.bulk-input-panel {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--border)
}

.bulk-input-panel[hidden] {
    display: none
}

.bulk-input-note {
    margin: 7px 0 0;
    font-size: 14px
}

.bulk-result {
    margin-top: 12px;
    color: var(--green-dark);
    font-weight: 700
}

.bulk-result.is-error.is-error {
    color: var(--danger)
}

.lesson-editor-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px
}

.lesson-sentence-card textarea {
    min-height: 82px
}

.lesson-card-list {
    display: grid;
    gap: 12px
}

.lesson-list-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 0;
    color: inherit;
    transition: border-color .15s, transform .15s
}

.lesson-list-card:hover {
    border-color: var(--green);
    transform: translateY(-1px)
}

.lesson-list-card h2,
.lesson-list-card h3,
.lesson-list-card p {
    margin-bottom: 0
}

.lesson-list-card time,
.lesson-detail-heading time {
    flex: 0 0 auto;
    color: var(--gray);
    font-size: 14px
}

.lesson-detail-heading {
    margin-bottom: 18px
}

.lesson-detail-heading h1 {
    margin: 8px 0 0
}

.lesson-table-wrapper,
.table-scroll {
    overflow-x: auto
}

.lesson-table {
    min-width: 900px;
    table-layout: fixed
}

.lesson-table th,
.lesson-table td {
    width: 31.333%;
    white-space: pre-wrap;
    overflow-wrap: anywhere
}

.lesson-table .lesson-number-column {
    width: 6%;
    text-align: center
}

@media(max-width:800px) {
    .mobile-menu-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin-left: auto
    }

    .topbar nav {
        display: none;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        max-height: calc(100vh - 64px);
        overflow-y: auto;
        flex-direction: column;
        gap: 0;
        margin-left: 0;
        padding: 8px 12px 14px;
        background: var(--green-dark);
        border-top: 1px solid rgba(255, 255, 255, .18);
        box-shadow: 0 8px 18px rgba(0, 0, 0, .2)
    }

    .topbar nav.is-open {
        display: flex
    }

    .topbar nav a {
        display: block;
        width: 100%;
        padding: 11px 10px;
        border-bottom: 1px solid rgba(255, 255, 255, .12)
    }

    .topbar .user {
        margin-left: 0
    }

    .topbar .user span {
        display: none
    }

    .grid-4 {
        grid-template-columns: 1fr 1fr
    }

    .exam-shell {
        display: block;
        height: auto
    }

    .exam-panel {
        display: none;
        min-height: 70vh
    }

    .exam-panel.active {
        display: block
    }

    .mobile-tabs {
        display: flex;
        position: sticky;
        top: 64px;
        z-index: 10;
        background: var(--bg);
        padding: 8px;
        gap: 8px
    }

    .mobile-tabs button {
        flex: 1
    }

    .container {
        margin-top: 14px
    }

    table {
        display: block;
        overflow: auto
    }

    .lesson-editor-grid {
        grid-template-columns: 1fr
    }

    .lesson-list-card {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px
    }
}

@media(max-width:480px) {
    .grid-4 {
        grid-template-columns: 1fr
    }

    .topbar {
        padding: 0 12px
    }

    .topbar .brand {
        display: none
    }

}

.pagination-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 20px;
}

.pagination-summary {
    color: var(--gray);
    font-size: 14px;
}

.pagination-links {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.pagination-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--white);
    color: var(--green);
    font-weight: 700;
    text-decoration: none;
}

a.pagination-item:hover {
    border-color: var(--green);
    background: var(--green-soft);
}

.pagination-active {
    border-color: var(--green);
    background: var(--green);
    color: var(--white);
}

.pagination-disabled {
    color: #9ca3af;
    cursor: not-allowed;
}

@media (max-width: 600px) {
    .pagination-wrapper {
        flex-direction: column;
        align-items: flex-start;
    }

    .pagination-summary {
        order: 2;
    }

    .pagination-links {
        order: 1;
    }
}

.builder-header {
    position: sticky;
    top: 64px;
    z-index: 15;

    margin: 0 0 16px;
    padding: 12px 0 8px;

    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.builder-label {
    margin: 0 0 4px;
    font-size: 18px;
}

.builder-exam-title {
    margin: 0 0 10px;
}

.builder-header-actions {
    display: flex;
    justify-content: flex-end;
    width: 100%;
    margin-bottom: 5px;
}

.builder-action-button {
    padding-top: 4px;
    padding-bottom: 4px;
}

@media (max-width: 800px) {
    .builder-header {
        top: 64px;
        padding: 8px 0;
    }

    .builder-exam-title {
        font-size: 24px;
    }
}

.exercise-list-content {
    flex: 1;
}

.exercise-list-content h2 {
    margin: 0 0 6px;
}

.exercise-list-content p {
    margin: 0 0 8px;
}

.exercise-list-actions {
    justify-content: flex-end;
}

.exercise-status {
    color: #9a3412;
}

.exercise-status.is-completed {
    color: var(--green);
}

.exercise-matching-board {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) 90px minmax(280px, 1fr);
    gap: 12px;
    min-width: 760px;
}

.exercise-column-heading,
.exercise-answer-heading {
    padding: 10px;
    border-radius: 6px;
    background: var(--green);
    color: var(--white);
    font-weight: 700;
    text-align: center;
}

.exercise-match-row,
.exercise-answer-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--white);
}

.exercise-answer-row {
    justify-content: center;
}

.exercise-answer-row select {
    width: 70px;
}

.exercise-result-item.is-correct {
    border-left: 5px solid #15803d;
}

.exercise-result-item.is-wrong {
    border-left: 5px solid #b91c1c;
}
