:root {
    --ink: #17212b;
    --muted: #637083;
    --line: #d9e0e7;
    --bg: #f7f8fb;
    --panel: #ffffff;
    --green: #0f8b62;
    --red: #c64242;
    --blue: #1e5bb8;
    --amber: #b56b00;
    --soft-green: #e9f8f2;
    --soft-yellow: #fff6d8;
    --soft-gray: #edf1f5;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--ink);
    background: var(--bg);
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 14px clamp(16px, 4vw, 48px);
    background: #ffffff;
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 6px;
    color: var(--ink);
    font-size: 20px;
}

.brand span {
    background: var(--green);
    color: #fff;
    padding: 4px 7px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 700;
}

nav {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 14px;
}

.shell {
    width: min(1180px, calc(100% - 28px));
    margin: 24px auto;
}

.hero {
    display: grid;
    grid-template-columns: 1.35fr .65fr;
    gap: 22px;
    align-items: stretch;
}

.panel, .card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.panel { padding: clamp(18px, 3vw, 34px); }
.card { padding: 18px; }

.auth-panel {
    display: grid;
    gap: 18px;
    max-width: 460px;
    margin: 42px auto;
    padding: clamp(22px, 4vw, 38px);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 16px 45px rgba(23, 33, 43, .08);
}

.eyebrow {
    display: inline-block;
    margin-bottom: 8px;
    color: var(--green);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.student-hero {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 18px;
    margin-bottom: 18px;
}

.exam-builder {
    border-top: 4px solid var(--green);
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
}

.mode-card {
    position: relative;
    display: grid;
    gap: 6px;
    min-height: 112px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
}

.mode-card input {
    position: absolute;
    inset: 12px 12px auto auto;
    width: auto;
    min-height: auto;
}

.mode-card span {
    padding-right: 22px;
    font-size: 18px;
    font-weight: 800;
}

.mode-card small {
    color: var(--muted);
    line-height: 1.45;
}

.mode-card.active {
    border-color: var(--green);
    background: var(--soft-green);
    box-shadow: 0 10px 26px rgba(15, 139, 98, .10);
}

.muted-control {
    opacity: .58;
}

.locked-control input {
    background: #eef3f7;
}

.deploy-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, .7fr);
    gap: 18px;
}

.deploy-rules {
    display: grid;
    gap: 10px;
}

.deploy-rules span {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f7fbf9;
    color: #344154;
}

h1, h2, h3 { margin: 0 0 12px; line-height: 1.15; }
h1 { font-size: clamp(30px, 5vw, 54px); letter-spacing: 0; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
p { color: var(--muted); line-height: 1.55; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 16px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin: 18px 0;
}

.stat {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.stat strong { display: block; font-size: 28px; }
.stat span { color: var(--muted); font-size: 13px; }

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

.page-actions {
    justify-content: space-between;
    margin-bottom: 18px;
}

.btn, button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid var(--blue);
    border-radius: 6px;
    background: var(--blue);
    color: #fff;
    font: inherit;
    cursor: pointer;
}

.btn.secondary, button.secondary {
    background: #fff;
    color: var(--blue);
}

.btn.danger { border-color: var(--red); background: var(--red); }
.link-button {
    display: inline;
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--red);
    font: inherit;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.form-panel {
    max-width: 720px;
    margin: 0 auto;
}

.hint {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

form.stack, .stack {
    display: grid;
    gap: 14px;
}

label { display: grid; gap: 6px; color: #344154; font-weight: 700; }

input, select, textarea {
    width: 100%;
    min-height: 40px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}

textarea { min-height: 92px; resize: vertical; }

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

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

th { background: #eef3f7; font-size: 13px; }
tr:last-child td { border-bottom: 0; }

.badge {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 99px;
    background: #edf4ff;
    color: var(--blue);
    font-size: 12px;
    font-weight: 700;
}

.badge.warning {
    background: var(--soft-yellow);
    color: var(--amber);
}

.flash {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 6px;
    background: #eaf8f2;
    color: #075f43;
    border: 1px solid #b8e3d2;
}

.flash.error {
    background: #fdecec;
    color: #8f2525;
    border-color: #efb9b9;
}

.question {
    display: grid;
    gap: 12px;
    margin-bottom: 14px;
}

.exam-sticky {
    position: sticky;
    top: 64px;
    z-index: 8;
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 14px;
    align-items: center;
    padding: 14px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--green);
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 8px 24px rgba(23, 33, 43, .08);
}

.exam-sticky h1 { font-size: clamp(22px, 3vw, 32px); }
.exam-sticky p { margin: 0; }

.timer-box {
    display: grid;
    gap: 2px;
    min-width: 128px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f7fbf9;
    text-align: center;
}

.timer-box span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.timer-box strong {
    color: var(--green);
    font-size: 22px;
}

.option {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    font-weight: 400;
}

.option input { width: auto; min-height: auto; margin-top: 3px; }
.correct { border-color: #79c7a9; background: #effaf5; }
.wrong { border-color: #e4a1a1; background: #fff0f0; }

.exam-screen {
    display: grid;
    grid-template-columns: minmax(250px, 310px) minmax(0, 1fr);
    gap: 18px;
    min-height: calc(100vh - 136px);
}

.exam-sidebar {
    position: sticky;
    top: 78px;
    align-self: start;
    display: grid;
    gap: 14px;
}

.palette-card {
    display: grid;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.palette-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
}

.palette-head span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.palette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
    gap: 8px;
    max-height: 48vh;
    overflow: auto;
    padding-right: 2px;
}

.compact-label {
    gap: 5px;
    font-size: 13px;
}

.compact-label select {
    min-height: 36px;
    font-size: 13px;
}

.palette-btn {
    min-height: 40px;
    padding: 0;
    border-color: var(--line);
    background: var(--soft-gray);
    color: var(--ink);
    font-weight: 800;
}

.palette-btn.current {
    outline: 3px solid rgba(30, 91, 184, .22);
    border-color: var(--blue);
}

.palette-btn.answered {
    border-color: #78c7a7;
    background: var(--soft-green);
    color: #08734f;
}

.palette-btn.doubt {
    border-color: #e3b12c;
    background: var(--soft-yellow);
    color: #8a5600;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.legend span {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot.gray { background: var(--soft-gray); border: 1px solid var(--line); }
.dot.green { background: var(--soft-green); border: 1px solid #78c7a7; }
.dot.yellow { background: var(--soft-yellow); border: 1px solid #e3b12c; }

.exam-main {
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 16px;
    min-width: 0;
}

.exam-top {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.exam-top h1 {
    font-size: clamp(24px, 3vw, 36px);
}

.exam-question {
    display: grid;
    align-content: start;
    gap: 18px;
    min-height: 58vh;
    padding: clamp(18px, 3vw, 34px);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.exam-question h2 {
    font-size: clamp(22px, 3vw, 34px);
    line-height: 1.3;
}

.question-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

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

.large-option {
    min-height: 58px;
    padding: 14px;
    transition: border-color .15s ease, background .15s ease, transform .15s ease;
}

.large-option:has(input:checked) {
    border-color: var(--blue);
    background: #edf4ff;
}

.large-option:hover {
    transform: translateY(-1px);
    border-color: #aab7c5;
}

.exam-controls {
    position: sticky;
    bottom: 0;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .97);
    box-shadow: 0 -8px 24px rgba(23, 33, 43, .08);
}

.review-btn {
    border-color: var(--amber);
    background: var(--amber);
}

button:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.timer-box.wide {
    min-width: 0;
}

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.footer {
    width: min(1180px, calc(100% - 28px));
    margin: 28px auto;
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 760px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .hero { grid-template-columns: 1fr; }
    .student-hero, .page-actions { align-items: flex-start; flex-direction: column; }
    .exam-sticky {
        top: 122px;
        grid-template-columns: 1fr;
    }
    .exam-sticky button { width: 100%; }
    table, thead, tbody, th, td, tr { display: block; }
    thead { display: none; }
    td { border-bottom: 0; padding: 8px 12px; }
    .responsive-table td {
        display: flex;
        justify-content: space-between;
        gap: 16px;
    }
    .responsive-table td::before {
        content: attr(data-label);
        flex: 0 0 38%;
        color: var(--muted);
        font-size: 12px;
        font-weight: 700;
    }
    tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
}

@media (max-width: 900px) {
    .deploy-grid,
    .exam-screen {
        grid-template-columns: 1fr;
    }

    .exam-sidebar {
        position: static;
        order: 2;
    }

    .exam-main {
        order: 1;
    }

    .palette-grid {
        grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
        max-height: none;
    }

    .exam-top {
        align-items: stretch;
        flex-direction: column;
    }

    .exam-top button {
        width: 100%;
    }
}

@media (max-width: 520px) {
    .shell {
        width: min(100% - 16px, 1180px);
        margin-top: 12px;
    }

    .exam-question {
        min-height: 52vh;
        padding: 16px;
    }

    .exam-controls {
        grid-template-columns: 1fr;
    }

    .palette-card {
        padding: 12px;
    }
}
