:root {
    --bg: #f3efe7;
    --panel: #fffdf9;
    --panel-border: #d8d1c5;
    --text: #1f2523;
    --muted: #5b655f;
    --blue-main: #2e3a53;
    --blue-soft: #56627a;
    --blue-pale: #edf1f7;
    --red-main: #8c0709;
    --red-soft: #e07a76;
    --red-pale: #f4c4c2;
    --accent: var(--blue-main);
    --accent-strong: #243044;
    --ok-bg: var(--blue-pale);
    --ok-text: var(--blue-main);
    --ko-bg: #f9e3e2;
    --ko-text: var(--red-main);
    --shadow: 0 18px 40px rgba(49, 53, 46, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top, rgba(46, 58, 83, 0.11), transparent 32%),
        linear-gradient(180deg, #f7f4ed 0%, var(--bg) 100%);
    color: var(--text);
    font-family: Georgia, "Times New Roman", serif;
}

.page {
    width: min(960px, calc(100% - 32px));
    margin: 0 auto;
    padding: 48px 0 64px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.topbar-brand,
.topbar-links a {
    color: var(--blue-main);
    text-decoration: none;
}

.topbar-brand {
    font-size: 1.1rem;
    font-weight: 700;
}

.topbar-links {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.hero,
.exercise-section {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.hero {
    padding: 32px;
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: "";
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    height: 6px;
    background: linear-gradient(90deg, var(--blue-main) 0%, var(--red-main) 100%);
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    font-weight: 600;
}

h1 {
    font-size: clamp(2rem, 5vw, 3.2rem);
    line-height: 1.05;
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 18px;
}

.intro {
    max-width: 62ch;
    margin: 16px 0 0;
    color: var(--muted);
    line-height: 1.6;
}

.hero-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 24px;
}

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

.info-card {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 22px;
}

.info-card p {
    margin: 12px 0 0;
    color: var(--muted);
    line-height: 1.6;
}

.toolbar {
    margin-top: 24px;
}

.generation-form {
    display: grid;
    gap: 18px;
}

.composer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.composer-title {
    margin: 0;
    color: var(--blue-main);
    font-size: 1.05rem;
    font-weight: 700;
}

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

.blocks-grid {
    display: grid;
    gap: 14px;
}

.generation-block {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    gap: 14px;
    align-items: end;
    padding: 16px;
    border: 1px solid #e4ddd2;
    border-radius: 14px;
    background: linear-gradient(180deg, #fffdfa 0%, var(--blue-pale) 100%);
}

.field {
    display: grid;
    gap: 8px;
}

.field span {
    color: var(--muted);
    font-size: 0.95rem;
}

.field select,
.field input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #c9c1b4;
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

.field select:focus,
.field input:focus {
    outline: 2px solid rgba(46, 58, 83, 0.16);
    border-color: var(--accent);
}

.ghost-button,
.remove-block {
    border: 1px solid rgba(46, 58, 83, 0.22);
    border-radius: 999px;
    background: #fff;
    color: var(--blue-main);
    cursor: pointer;
    font: inherit;
    padding: 10px 16px;
}

.remove-block {
    color: var(--red-main);
    border-color: rgba(140, 7, 9, 0.22);
}

.remove-block:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.form-error {
    margin: 16px 0 0;
    color: var(--red-main);
}

.check-actions {
    margin-top: 20px;
}

.primary-button,
.secondary-button {
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    font: inherit;
    padding: 12px 20px;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.primary-button {
    background: linear-gradient(135deg, var(--blue-main) 0%, var(--blue-soft) 100%);
    color: #fff;
    box-shadow: 0 12px 24px rgba(46, 58, 83, 0.18);
}

.secondary-button {
    background: linear-gradient(135deg, var(--red-main) 0%, var(--red-soft) 100%);
    color: #fff;
    box-shadow: 0 12px 24px rgba(140, 7, 9, 0.16);
}

.primary-button:hover,
.secondary-button:hover {
    transform: translateY(-1px);
}

.primary-button:hover {
    background: linear-gradient(135deg, var(--accent-strong) 0%, var(--blue-main) 100%);
}

.secondary-button:hover {
    background: linear-gradient(135deg, #730507 0%, var(--red-main) 100%);
}

.exercise-section {
    padding: 28px 24px;
    margin-bottom: 20px;
}

.section-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 18px;
}

.add-section,
.sub-section {
    border-top: 5px solid var(--blue-main);
}

.add-section h2,
.sub-section h2 {
    color: var(--blue-main);
}

.mul-section,
.div-section {
    border-top: 5px solid var(--red-main);
}

.mul-section h2,
.div-section h2 {
    color: var(--red-main);
}

.exercise-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 16px;
}

.exercise-item {
    padding: 18px;
    border: 1px solid #e4ddd2;
    border-radius: 14px;
    background: #fffdfa;
}

.add-section .exercise-item,
.sub-section .exercise-item {
    background: linear-gradient(180deg, #fffdfa 0%, var(--blue-pale) 100%);
    border-color: rgba(86, 98, 122, 0.28);
}

.mul-section .exercise-item,
.div-section .exercise-item {
    background: linear-gradient(180deg, #fffdfa 0%, #fff4f3 100%);
    border-color: rgba(224, 122, 118, 0.35);
}

.exercise-question {
    display: block;
    margin-bottom: 12px;
    font-size: 1.05rem;
}

.exercise-answer {
    max-width: 220px;
}

.exercise-answer input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #c9c1b4;
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

.exercise-answer input:focus {
    outline: 2px solid rgba(46, 58, 83, 0.16);
    border-color: var(--accent);
}

.feedback {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.result {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.92rem;
    font-weight: 700;
}

.result.ok {
    background: var(--ok-bg);
    color: var(--ok-text);
}

.result.ko {
    background: var(--ko-bg);
    color: var(--ko-text);
}

.correction {
    color: var(--muted);
}

@media (max-width: 640px) {
    .page {
        width: min(100% - 20px, 960px);
        padding-top: 24px;
    }

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

    .hero,
    .exercise-section {
        padding: 20px;
    }

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

    .generation-block {
        grid-template-columns: 1fr;
    }
}
