/* Reserve a real top row for the Med v karmane navigation so it never overlays Moodle content. */
body:has(.mpm-moodle-toolbar)::before {
    content: "";
    display: block;
    width: 100%;
    height: calc(58px + env(safe-area-inset-top));
    flex: 0 0 calc(58px + env(safe-area-inset-top));
}

.mpm-moodle-toolbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2147483000;
    box-sizing: border-box;
    min-height: calc(54px + env(safe-area-inset-top));
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    gap: 8px;
    padding: calc(6px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
    border: 0;
    border-bottom: 1px solid rgba(196,164,119,0.22);
    border-radius: 0 0 14px 14px;
    background: rgba(17,17,31,0.96);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.mpm-moodle-toolbar a {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 10px;
    border-radius: 10px;
    color: #f7f1e8 !important;
    text-decoration: none !important;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
}

.mpm-moodle-toolbar-home {
    background: linear-gradient(135deg, #5c4530, #5c4530);
}

.mpm-moodle-toolbar-lms {
    background: rgba(196,164,119,0.07);
}

.mpm-moodle-host {
    margin: 14px 0 16px;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.mpm-moodle-action-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.mpm-moodle-model-wrap {
    display: grid;
    gap: 4px;
    min-width: 210px;
    max-width: 320px;
}

.mpm-moodle-model-label {
    padding-left: 2px;
    color: color-mix(in srgb, CanvasText 58%, transparent);
    font-size: 10px;
    font-weight: 850;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.mpm-moodle-model-select {
    appearance: none;
    min-height: 40px;
    width: 100%;
    padding: 0 36px 0 12px;
    border: 1px solid rgba(196,164,119,0.2);
    border-radius: 12px;
    background:
        linear-gradient(45deg, transparent 50%, rgba(92,69,48,0.82) 50%) calc(100% - 16px) 17px / 5px 5px no-repeat,
        linear-gradient(135deg, rgba(196,164,119,0.06), rgba(196,164,119,0.06)),
        Canvas;
    color: CanvasText;
    font: inherit;
    font-size: 13px;
    font-weight: 750;
    outline: none;
    box-shadow: 0 8px 22px rgba(196,164,119,0.07);
    transition: border-color .18s ease, box-shadow .18s ease, opacity .18s ease, transform .18s ease;
}

.mpm-moodle-model-select:hover:not(:disabled),
.mpm-moodle-model-select:focus {
    border-color: rgba(196,164,119,0.44);
    box-shadow: 0 0 0 3px rgba(196,164,119,0.08), 0 8px 24px rgba(196,164,119,0.1);
}

.mpm-moodle-model-select:disabled {
    opacity: .58;
    cursor: progress;
}

.mpm-moodle-model-select.is-saving {
    opacity: .72;
}

.mpm-moodle-button {
    appearance: none;
    border: 0;
    border-radius: 12px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #5c4530, #5c4530);
    color: #f7f1e8;
    font: inherit;
    font-weight: 800;
    line-height: 1.2;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(196,164,119,0.22);
}

.mpm-moodle-button:disabled {
    opacity: .62;
    cursor: progress;
}

.mpm-moodle-panel {
    display: none;
    margin-top: 10px;
    border: 1px solid rgba(196,164,119,0.18);
    border-radius: 14px;
    background: color-mix(in srgb, Canvas 96%, #5c4530 4%);
    color: CanvasText;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .07);
    overflow: hidden;
}

.mpm-moodle-panel[data-state="loading"],
.mpm-moodle-panel[data-state="ready"],
.mpm-moodle-panel[data-state="error"] {
    display: block;
}

.mpm-moodle-panel[data-state="loading"] {
    border-color: rgba(196,164,119,0.24);
    background: linear-gradient(135deg, rgba(196,164,119,0.06), rgba(196,164,119,0.06)), Canvas;
}

.mpm-moodle-panel[data-state="error"] {
    border-color: rgba(219,112,132,0.3);
}

.mpm-moodle-error-actions {
    display: flex;
    align-items: center;
    margin-top: 12px;
}

.mpm-moodle-topup-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 15px;
    border: 1px solid rgba(196,164,119,0.48);
    border-radius: 11px;
    background: linear-gradient(135deg, #5c4530, #5c4530);
    color: #f7f1e8 !important;
    text-decoration: none !important;
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 8px 20px rgba(196,164,119,0.18);
    transition: transform .15s ease, filter .15s ease, box-shadow .15s ease;
}

.mpm-moodle-topup-button:hover {
    filter: brightness(1.06);
    box-shadow: 0 10px 24px rgba(196,164,119,0.25);
}

.mpm-moodle-topup-button:active {
    transform: scale(.98);
}

.mpm-moodle-panel-body {
    padding: 14px 16px;
    font-size: 14px;
    line-height: 1.55;
}

.mpm-moodle-thinking {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 92px;
}

.mpm-moodle-thinking-animation {
    position: relative;
    flex: 0 0 76px;
    width: 76px;
    height: 76px;
    overflow: hidden;
    border-radius: 22px;
    background:
        radial-gradient(circle at 50% 48%, rgba(196,164,119,0.13), transparent 56%),
        linear-gradient(145deg, rgba(196,164,119,0.06), rgba(196,164,119,0.05));
    box-shadow: inset 0 0 0 1px rgba(196,164,119,0.09), 0 8px 24px rgba(196,164,119,0.08);
}

.mpm-moodle-thinking-animation canvas,
.mpm-moodle-thinking-animation svg {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.mpm-moodle-thinking-copy {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.mpm-moodle-thinking-copy strong {
    color: CanvasText;
    font-size: 14px;
    font-weight: 850;
    letter-spacing: -.01em;
}

.mpm-moodle-thinking-copy span {
    color: color-mix(in srgb, CanvasText 68%, transparent);
    font-size: 13px;
    line-height: 1.45;
}

.mpm-moodle-assistant-message {
    width: 100%;
    color: CanvasText;
    animation: mpm-moodle-answer-reveal .34s cubic-bezier(.2,.85,.25,1) both;
}

.mpm-moodle-assistant-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.mpm-moodle-assistant-avatar {
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    object-fit: cover;
    box-shadow: 0 0 0 1px rgba(196,164,119,0.18), 0 6px 16px rgba(0,0,0,.10);
}

.mpm-moodle-assistant-identity {
    display: grid;
    gap: 1px;
    min-width: 0;
}

.mpm-moodle-assistant-identity strong {
    color: CanvasText;
    font-size: 13px;
    font-weight: 900;
    line-height: 1.25;
}

.mpm-moodle-assistant-identity span {
    color: color-mix(in srgb, CanvasText 58%, transparent);
    font-size: 10px;
    font-weight: 650;
    line-height: 1.25;
}

.mpm-moodle-answer {
    white-space: pre-wrap;
}

.mpm-moodle-panel[data-state="ready"] .mpm-moodle-answer {
    position: relative;
    padding: 12px 14px;
    border: 1px solid rgba(196,164,119,0.34);
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(196,164,119,0.16), rgba(196,164,119,0.08));
    color: CanvasText;
    box-shadow: 0 8px 24px rgba(196,164,119,0.1), inset 0 0 0 1px rgba(196,164,119,0.08);
    animation: mpm-moodle-answer-reveal .42s cubic-bezier(.2,.85,.25,1) both;
}

.mpm-moodle-meta {
    display: grid;
    gap: 4px;
    margin-top: 11px;
    padding-top: 9px;
    border-top: 1px solid color-mix(in srgb, CanvasText 10%, transparent);
    color: color-mix(in srgb, CanvasText 66%, transparent);
    font-size: 12px;
    line-height: 1.35;
    opacity: 1;
}

.mpm-moodle-meta-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
    min-height: 17px;
}

.mpm-moodle-meta-label {
    font-weight: 500;
}

.mpm-moodle-meta-value {
    color: color-mix(in srgb, CanvasText 82%, transparent);
    font-weight: 750;
}

.mpm-moodle-meta-billing {
    gap: 3px;
}

.mpm-moodle-coin-icon {
    display: inline-block;
    width: 15px;
    height: 15px;
    margin: 0 1px;
    object-fit: contain;
    vertical-align: middle;
}

.mpm-moodle-correct {
    position: relative;
    border-radius: 12px !important;
    background: linear-gradient(135deg, rgba(139,189,164,0.22), rgba(139,189,164,0.1)) !important;
    box-shadow:
        inset 0 0 0 2px rgba(75,118,96,0.62),
        0 8px 24px rgba(139,189,164,0.12) !important;
    transition: background .2s ease, box-shadow .2s ease, transform .2s ease;
    animation:
        mpm-moodle-correct-reveal .46s cubic-bezier(.2,.9,.25,1) both,
        mpm-moodle-correct-glow 1.7s ease-in-out .46s 2;
}

.mpm-moodle-correct::after {
    content: "✓ Верный ответ";
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    padding: 4px 9px;
    border: 1px solid rgba(139,189,164,0.28);
    border-radius: 999px;
    background: rgba(139,189,164,0.18);
    color: #9bcfb3;
    box-shadow: 0 4px 14px rgba(139,189,164,0.12);
    font-size: 11px;
    font-weight: 850;
    line-height: 1.2;
    vertical-align: middle;
    animation: mpm-moodle-badge-pop .38s cubic-bezier(.18,.9,.3,1.2) .12s both;
}

@keyframes mpm-moodle-correct-reveal {
    0% {
        transform: scale(.985);
        filter: saturate(.7);
        box-shadow: inset 0 0 0 0 rgba(196,164,119,0), 0 0 0 rgba(196,164,119,0);
    }
    65% {
        transform: scale(1.008);
    }
    100% {
        transform: scale(1);
        filter: saturate(1);
    }
}

@keyframes mpm-moodle-correct-glow {
    0%, 100% {
        box-shadow: inset 0 0 0 2px rgba(92,69,48,0.62), 0 8px 24px rgba(196,164,119,0.12);
    }
    50% {
        box-shadow: inset 0 0 0 2px rgba(92,69,48,0.88), 0 0 0 5px rgba(196,164,119,0.08), 0 10px 30px rgba(196,164,119,0.2);
    }
}

@keyframes mpm-moodle-badge-pop {
    0% {
        opacity: 0;
        transform: scale(.72) translateY(2px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes mpm-moodle-answer-reveal {
    0% {
        opacity: 0;
        transform: translateY(5px) scale(.99);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .mpm-moodle-assistant-message,
    .mpm-moodle-correct,
    .mpm-moodle-correct::after,
    .mpm-moodle-panel[data-state="ready"] .mpm-moodle-answer {
        animation: none !important;
    }
}

@media (max-width: 640px) {
    body:has(.mpm-moodle-toolbar)::before {
        height: calc(62px + env(safe-area-inset-top));
        flex-basis: calc(62px + env(safe-area-inset-top));
    }

    .mpm-moodle-toolbar {
        min-height: calc(58px + env(safe-area-inset-top));
        justify-content: space-between;
    }

    .mpm-moodle-toolbar a {
        min-height: 38px;
        padding: 0 12px;
    }

    .mpm-moodle-action-row {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
    }

    .mpm-moodle-model-wrap {
        max-width: none;
        width: 100%;
    }

    .mpm-moodle-model-select,
    .mpm-moodle-button {
        min-height: 44px;
        width: 100%;
    }

    .mpm-moodle-thinking {
        gap: 11px;
    }

    .mpm-moodle-thinking-animation {
        flex-basis: 64px;
        width: 64px;
        height: 64px;
        border-radius: 18px;
    }

    .mpm-moodle-meta {
        gap: 5px;
        font-size: 11.5px;
    }

    .mpm-moodle-coin-icon {
        width: 14px;
        height: 14px;
    }
}
.mpm-practice-controls{display:flex;align-items:center;gap:12px;flex-wrap:wrap;margin:0 0 12px;padding:12px 14px;border:1px solid rgba(196,164,119,0.28);border-radius:12px;background:rgba(196,164,119,0.08)}.mpm-practice-controls label{display:flex;align-items:center;gap:7px;font-size:15px;font-weight:700;cursor:pointer}.mpm-practice-controls input{width:18px;height:18px;accent-color:#2cae88}.mpm-practice-status{flex-basis:100%;font-size:12px;line-height:1.4}

/* Persistent web-search preference beside auto-solve, on both light/dark Moodle themes. */
.mpm-practice-controls .mpm-practice-web-search{white-space:nowrap}
.mpm-practice-controls [data-web-search]{accent-color:#2cae88}
@media(max-width:480px){.mpm-practice-controls{gap:10px 14px}.mpm-practice-controls label{font-size:13px}}
