:root {
    --ink: #17231e;
    --muted: #627069;
    --paper: #ffffff;
    --canvas: #f4f6f1;
    --line: #d9dfda;
    --green: #74b82f;
    --green-dark: #397725;
    --green-soft: #e9f5dc;
    --red: #dc4d45;
    --red-dark: #9f2e2a;
    --red-soft: #fde9e6;
    --yellow: #e6c42f;
    --shadow: 0 18px 50px rgba(31, 52, 42, 0.10);
}

* {
    box-sizing: border-box;
}

html {
    background: var(--canvas);
}

body {
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 7% 5%, rgba(116, 184, 47, 0.12), transparent 28rem),
        radial-gradient(circle at 92% 14%, rgba(230, 196, 47, 0.11), transparent 25rem),
        var(--canvas);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button,
input {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.site-header {
    width: min(1180px, calc(100% - 40px));
    min-height: 108px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 15px;
    color: var(--ink);
    text-decoration: none;
    font-size: 15px;
    font-weight: 900;
    letter-spacing: 0.16em;
}

.brand img {
    width: 72px;
    height: 72px;
    object-fit: contain;
}

.back-link {
    color: var(--green-dark);
    text-decoration: none;
    font-size: 14px;
    font-weight: 800;
}

.back-link:hover {
    text-decoration: underline;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 18px;
}

.header-download {
    min-height: 42px;
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    border: 0;
    border-radius: 11px;
    background: var(--green-dark);
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 850;
    box-shadow: 0 10px 24px rgba(57, 119, 37, 0.18);
    transition: transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

.header-download:hover {
    transform: translateY(-1px);
    background: #2e651d;
    box-shadow: 0 13px 28px rgba(57, 119, 37, 0.24);
}

.header-download:focus-visible {
    outline: 3px solid rgba(116, 184, 47, 0.28);
    outline-offset: 3px;
}

.landing-shell,
.test-page main {
    width: min(1180px, calc(100% - 40px));
    margin: 0 auto;
}

.hero {
    max-width: 780px;
    padding: 70px 0 58px;
}

.eyebrow {
    margin: 0 0 12px;
    color: var(--green-dark);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.18em;
}

.hero h1,
.test-intro h1 {
    margin: 0;
    font-size: clamp(42px, 8vw, 82px);
    line-height: 0.95;
    letter-spacing: -0.055em;
}

.hero > p:last-child,
.test-intro > div > p:last-child {
    max-width: 670px;
    margin: 24px 0 0;
    color: var(--muted);
    font-size: 18px;
    line-height: 1.65;
}

.level-grid {
    display: grid;
    grid-template-columns: 1.25fr 1fr 1fr;
    gap: 20px;
}

.level-card {
    position: relative;
    min-height: 390px;
    padding: 30px;
    overflow: hidden;
    border: 1px solid rgba(25, 53, 40, 0.11);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.84);
    color: var(--ink);
    box-shadow: var(--shadow);
    text-decoration: none;
}

.level-card--active {
    border-color: transparent;
    background: linear-gradient(145deg, #315f29, #74b82f);
    color: white;
    transition: transform 180ms ease, box-shadow 180ms ease;
}

.level-card--active::after {
    content: "+  −";
    position: absolute;
    right: -12px;
    bottom: -26px;
    color: rgba(255, 255, 255, 0.10);
    font-size: 120px;
    font-weight: 900;
    letter-spacing: -0.14em;
}

.level-card--active:hover {
    transform: translateY(-5px);
    box-shadow: 0 24px 60px rgba(47, 94, 38, 0.24);
}

.level-status {
    display: inline-flex;
    min-height: 27px;
    padding: 5px 10px;
    align-items: center;
    border: 1px solid currentColor;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.level-card--locked .level-status {
    color: #8c9791;
}

.level-roman {
    display: block;
    margin-top: 28px;
    font-family: Georgia, serif;
    font-size: 92px;
    line-height: 0.9;
}

.level-card h2 {
    margin: 20px 0 7px;
    font-size: 24px;
    letter-spacing: -0.02em;
}

.level-card p {
    margin: 0;
    opacity: 0.76;
}

.level-card ul {
    margin: 24px 0 0;
    padding: 0;
    list-style: none;
    line-height: 1.8;
}

.level-action {
    position: absolute;
    bottom: 28px;
    left: 30px;
    z-index: 1;
    font-weight: 900;
}

.level-card--locked {
    color: #6e7973;
    box-shadow: none;
}

.level-card--locked .level-roman {
    color: #cbd2ce;
}

.how-it-works {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 40px;
    margin: 72px 0 100px;
    padding-top: 40px;
    border-top: 1px solid var(--line);
}

.how-it-works > div {
    display: grid;
    grid-template-columns: 46px 1fr;
    column-gap: 16px;
}

.how-it-works span {
    grid-row: 1 / 3;
    color: var(--green-dark);
    font-weight: 900;
}

.how-it-works h3,
.how-it-works p {
    margin: 0;
}

.how-it-works p {
    margin-top: 8px;
    color: var(--muted);
    line-height: 1.55;
}

.test-intro {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 40px;
    padding: 70px 0 50px;
}

.test-totals {
    display: flex;
    gap: 12px;
}

.test-totals > div {
    min-width: 120px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.75);
}

.test-totals strong,
.test-totals span {
    display: block;
}

.test-totals strong {
    font-size: 30px;
}

.test-totals span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.control-panel,
.instructions {
    padding: 30px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
}

.control-panel {
    padding: 0;
    overflow: hidden;
}

.control-heading {
    display: flex;
    justify-content: space-between;
    gap: 30px;
    padding: 30px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(135deg, #ffffff, #f5f9f0);
}

.control-heading h2,
.instructions h2 {
    margin: 0;
    font-size: 26px;
}

.control-help {
    max-width: 500px;
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
}

.form-grid {
    display: grid;
    grid-template-columns: 2fr 1.4fr 0.6fr;
    gap: 16px;
    margin-top: 18px;
}

.form-grid label > span {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.form-grid input {
    width: 100%;
    min-height: 48px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 11px;
    outline: none;
}

.form-grid input:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(116, 184, 47, 0.15);
}

.setup-section {
    padding: 24px 30px;
    border-bottom: 1px solid var(--line);
}

.setup-section--last {
    border-bottom: 0;
}

.setup-section__title {
    display: flex;
    align-items: center;
    gap: 13px;
}

.setup-section__title h3,
.setup-section__title p {
    margin: 0;
}

.setup-section__title h3 {
    font-size: 16px;
}

.setup-section__title p {
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
}

.setup-number {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--green-soft);
    color: var(--green-dark);
    font-size: 12px;
    font-weight: 950;
}

.setup-section__title--with-action .preset-button {
    margin-left: auto;
}

.preset-button {
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: white;
    color: var(--green-dark);
    cursor: pointer;
    font-size: 10px;
    font-weight: 850;
}

.layout-settings {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-top: 18px;
}

.layout-settings label > span {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
}

.layout-settings label {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #f8faf6;
}

.layout-settings input,
.layout-settings select {
    width: 100%;
    min-height: 43px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: white;
    color: var(--ink);
    outline: none;
}

.layout-settings input:focus,
.layout-settings select:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(116, 184, 47, 0.15);
}

.layout-settings label > small {
    display: block;
    min-height: 25px;
    margin-top: 7px;
    color: var(--muted);
    font-size: 9px;
    line-height: 1.35;
}

.control-actions,
.print-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 22px;
}

.print-actions {
    padding-top: 22px;
    border-top: 1px solid var(--line);
}

.print-actions > span {
    margin-right: 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

.button {
    min-height: 43px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: white;
    color: var(--ink);
    cursor: pointer;
    font-size: 13px;
    font-weight: 850;
    transition: transform 150ms ease, box-shadow 150ms ease;
}

.button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(30, 44, 37, 0.10);
}

.button--primary,
.button--dark,
.button--green,
.button--red {
    border-color: transparent;
    color: white;
}

.button--primary,
.button--green {
    background: var(--green-dark);
}

.button--dark {
    background: var(--ink);
}

.button--red {
    background: var(--red-dark);
}

.button--large {
    min-height: 48px;
    padding-right: 20px;
    padding-left: 20px;
}

.print-choice {
    min-width: 145px;
    min-height: 62px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 11px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: white;
    color: var(--ink);
    cursor: pointer;
    text-align: left;
    transition: transform 150ms ease, box-shadow 150ms ease;
}

.print-choice:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(30, 48, 39, 0.10);
}

.print-choice strong,
.print-choice small {
    display: block;
}

.print-choice strong {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    color: white;
    font-size: 13px;
}

.print-choice small {
    font-size: 10px;
    font-weight: 850;
}

.print-choice--all strong {
    background: var(--ink);
}

.print-choice--single strong {
    background: var(--green-dark);
}

.print-choice--double strong {
    background: var(--red-dark);
}

.answer-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    font-size: 13px;
    font-weight: 750;
}

.answer-toggle input {
    width: 17px;
    height: 17px;
    accent-color: var(--green-dark);
}

.result-message {
    min-height: 21px;
    margin: 0;
    padding: 0 30px 24px;
    color: var(--green-dark);
    font-size: 14px;
    font-weight: 800;
}

.instructions {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 30px;
    margin-top: 18px;
    box-shadow: none;
}

.instructions ol {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px 34px;
    margin: 0;
    padding-left: 22px;
    color: var(--muted);
    line-height: 1.55;
}

.worksheet-section {
    margin: 64px 0 90px;
}

.worksheet-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
}

.worksheet-heading span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.15em;
}

.worksheet-heading h2 {
    margin: 6px 0 0;
    font-size: 34px;
}

.worksheet-heading p {
    margin: 0;
    color: var(--muted);
}

.exercise-page {
    margin-bottom: 22px;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--paper);
    box-shadow: 0 8px 30px rgba(24, 41, 33, 0.07);
}

.print-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 15px;
}

.print-page-header > div {
    display: flex;
    align-items: center;
    gap: 12px;
}

.print-page-header strong {
    font-size: 15px;
}

.print-page-header span,
.print-page-header small {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
}

.exercise-table {
    width: 100%;
    margin-top: 14px;
    table-layout: fixed;
    border-collapse: collapse;
    font-family: Arial, sans-serif;
}

.exercise-table th,
.exercise-table td {
    height: 29px;
    padding: 2px;
    border: 1px solid #526059;
    text-align: center;
    vertical-align: middle;
}

.exercise-table th {
    height: 24px;
    color: #132018;
    font-size: 11px;
}

.exercise-table--single th {
    background: var(--green);
}

.exercise-table--double th {
    background: var(--red);
}

.exercise-table td {
    font-size: 15px;
    font-weight: 750;
}

.checking-row td,
.answer-row td {
    height: 34px;
    padding: 3px;
}

.checking-row td {
    background: #fff;
}

.answer-row td {
    background: #fafbf9;
}

.checking-input,
.answer-input {
    width: 100%;
    height: 25px;
    padding: 0 2px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    text-align: center;
    outline: none;
    font-size: 14px;
    font-weight: 800;
    -moz-appearance: textfield;
}

.checking-input::-webkit-outer-spin-button,
.checking-input::-webkit-inner-spin-button,
.answer-input::-webkit-outer-spin-button,
.answer-input::-webkit-inner-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.checking-input:focus,
.answer-input:focus {
    border-color: #8ba69a;
    background: white;
}

.answer-input.is-correct {
    border-color: #3c9a50;
    background: #e9f8ec;
    color: #1f6d30;
}

.answer-input.is-wrong {
    border-color: #d24c48;
    background: #fff0ef;
    color: #a32421;
}

.answer-value,
.answer-line,
.checking-line {
    display: none;
}

.show-answers .answer-input {
    display: none;
}

.show-answers .answer-value {
    display: inline;
    color: var(--green-dark);
    font-weight: 900;
}

.print-only {
    display: none;
}

@media (max-width: 800px) {
    .level-grid,
    .how-it-works,
    .form-grid,
    .instructions {
        grid-template-columns: 1fr;
    }

    .layout-settings {
        grid-template-columns: 1fr 1fr;
    }

    .level-card {
        min-height: 340px;
    }

    .test-intro,
    .control-heading,
    .worksheet-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .answer-toggle {
        width: 100%;
        margin: 8px 0 0;
    }

    .exercise-page {
        padding: 12px;
        overflow-x: auto;
    }

    .exercise-table {
        min-width: 650px;
    }
}

@media (max-width: 520px) {
    .site-header {
        min-height: 92px;
    }

    .brand {
        gap: 9px;
        font-size: 12px;
    }

    .brand img {
        width: 60px;
        height: 60px;
    }

    .header-actions {
        gap: 10px;
    }

    .header-download {
        min-height: 38px;
        padding: 0 12px;
        font-size: 11px;
    }

    .back-link {
        font-size: 11px;
    }

    .layout-settings {
        grid-template-columns: 1fr;
    }

    .setup-section__title--with-action {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .setup-section__title--with-action .preset-button {
        width: 100%;
        margin: 5px 0 0 45px;
    }

    .print-choice {
        width: 100%;
    }
}

@page {
    size: A4 portrait;
    margin: 9mm;
}

@media print {
    html,
    body {
        background: white !important;
    }

    body {
        color: #000;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .no-print,
    .site-header,
    .worksheet-heading {
        display: none !important;
    }

    .test-page main {
        width: 100%;
        margin: 0;
    }

    .print-only {
        display: block;
    }

    .print-cover {
        position: relative;
        min-height: 277mm;
        padding: 15mm 12mm;
        page-break-after: always;
    }

    .cover-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        font-weight: 900;
        letter-spacing: 0.15em;
    }

    .cover-brand img {
        width: 72px;
        height: 72px;
        object-fit: contain;
    }

    .print-cover h1 {
        margin: 24mm 0 9mm;
        text-align: center;
        font-family: Georgia, serif;
        font-size: 22px;
    }

    .student-table,
    .sign-table {
        width: 100%;
        border-collapse: collapse;
    }

    .student-table th,
    .student-table td,
    .sign-table th,
    .sign-table td {
        height: 11mm;
        padding: 2mm 3mm;
        border: 1px solid #222;
        text-align: left;
    }

    .student-table th {
        width: 38%;
        font-size: 11px;
    }

    .student-table td {
        font-size: 14px;
    }

    .cover-rules {
        width: 70%;
        margin: 16mm auto;
        border: 1px solid #222;
        text-align: center;
    }

    .cover-rules h2 {
        margin: 0;
        padding: 2mm;
        border-bottom: 1px solid #222;
        font-size: 14px;
    }

    .cover-rule {
        padding: 4mm;
        border-bottom: 1px solid #222;
        font-weight: 900;
    }

    .cover-rule:last-child {
        border-bottom: 0;
    }

    .cover-rule--green {
        background: var(--green);
    }

    .cover-rule--red {
        background: var(--red);
    }

    .sign-table {
        margin-top: 20mm;
    }

    .sign-table th {
        width: 16%;
        font-size: 10px;
    }

    .worksheet-section {
        margin: 0;
    }

    .exercise-page {
        display: flex;
        height: 277mm;
        min-height: 277mm;
        flex-direction: column;
        margin: 0;
        padding: 0;
        overflow: hidden;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        break-after: page;
        page-break-after: always;
    }

    .exercise-page:last-child {
        break-after: auto;
        page-break-after: auto;
    }

    .print-page-header {
        height: 12mm;
        flex: 0 0 12mm;
        margin: 0 0 3mm;
        border-bottom: 1px solid #777;
    }

    .exercise-table {
        height: auto;
        min-height: 0;
        flex: 1 1 0;
        margin: 0 0 5mm;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .exercise-table:last-child {
        margin-bottom: 0;
    }

    .exercise-table th {
        height: auto;
    }

    .exercise-table td {
        height: auto;
        font-size: 12px;
    }

    .checking-row td,
    .answer-row td {
        height: auto;
    }

    .checking-input,
    .answer-input {
        display: none !important;
    }

    .checking-line,
    .answer-line {
        display: block;
        min-height: 4mm;
    }

    .show-answers .answer-line {
        display: none;
    }

    .show-answers .answer-value {
        display: inline;
        color: #000;
    }

    body[data-print-mode="single"] .print-cover,
    body[data-print-mode="single"] #double-section,
    body[data-print-mode="double"] .print-cover,
    body[data-print-mode="double"] #single-section {
        display: none !important;
    }

    body[data-print-mode="all"] #single-section .exercise-page:last-child {
        break-after: page;
        page-break-after: always;
    }
}
