:root {
    --primary: #4ecdc4;
    --secondary: #ff6b6b;
    --accent: #ffe66d;
    --bg-color: #f0f8ff;
    --text-main: #2c3e50;
    --cooldown-bg: rgba(255, 107, 107, 0.95);
    --bg: #e8f4ff;
    --ink: #1d2b53;
    --sun: #ffc233;
    --ok: #1fae6b;
    --bad: #ff5d73;
    --pu: #5b3fd6;
    --card: #fff;
    --ln: #c9dff5;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Nunito', "Trebuchet MS", sans-serif;
    background: var(--bg-color);
    color: var(--text-main);
    font-size: 18px;
    padding-bottom: 40px;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 12px 18px;
    background: var(--pu);
    color: #fff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}
header b { font-size: 24px; font-weight: 900; letter-spacing: 0.5px; }
header nav { display: flex; gap: 8px; }

button {
    font-family: 'Nunito', sans-serif;
    cursor: pointer;
    border: 0;
    border-radius: 14px;
    padding: 10px 20px;
    background: var(--sun);
    color: var(--ink);
    font-weight: 800;
    font-size: 16px;
    box-shadow: 0 4px 0 #d99a00;
    transition: all 0.15s ease;
}
button:active { transform: translateY(3px); box-shadow: 0 1px 0 #d99a00; }
button:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; transform: none; }

header button { background: #ffffff33; color: #fff; box-shadow: none; padding: 8px 16px; border-radius: 20px; }
header button.on { background: #fff; color: var(--pu); font-weight: 900; }

main { max-width: 860px; margin: 20px auto; padding: 0 18px; }

.card {
    background: var(--card);
    border: 3px solid var(--ln);
    border-radius: 24px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.05);
    position: relative;
    overflow: hidden;
}
h2 { margin: 0 0 15px; color: var(--pu); font-weight: 900; font-size: 1.4em; }
h3 { margin: 20px 0 10px; font-size: 1.2em; color: #34495e; border-bottom: 2px dashed var(--ln); padding-bottom: 5px; }

input, select {
    font-family: 'Nunito', sans-serif;
    padding: 12px 16px;
    border: 3px solid var(--ln);
    border-radius: 16px;
    width: 100%;
    margin: 8px 0 16px;
    font-size: 18px;
    font-weight: 700;
    color: var(--ink);
}
input:focus, select:focus { border-color: var(--pu); outline: none; }

label { font-weight: 700; color: #576574; display: block; }
label.ck { display: flex; gap: 8px; align-items: center; font-size: 16px; cursor: pointer; }
label.ck input { width: 22px; height: 22px; margin: 0; accent-color: var(--pu); }

/* Tiến trình trạm */
.trail {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 20px;
    justify-content: center;
    background: #f8f9fa;
    padding: 12px;
    border-radius: 20px;
    border: 2px dashed #dfe6e9;
    flex-wrap: wrap;
}
.dot {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: #fff;
    border: 4px solid var(--ln);
    display: grid; place-items: center;
    font-weight: 900;
    color: #b2bec3;
    font-size: 18px;
}
.dot.now { border-color: var(--pu); background: var(--sun); color: var(--ink); transform: scale(1.12); }
.dot.ok { background: var(--ok); border-color: var(--ok); color: #fff; }

/* Khu vực đọc Văn xuôi & Thơ */
.read {
    font-size: 23px;
    line-height: 2.0;
    transition: opacity 0.4s;
    text-align: justify;
    white-space: pre-wrap;
    padding: 22px;
    background: #fafbfc;
    border-radius: 16px;
    border: 2px solid #e1e8ed;
}
.read.dim { opacity: 0.15; pointer-events: none; filter: blur(2px); }

/* Bố cục Thơ chia 2 cột như Sách Giáo Khoa */
.read.is-poem {
    text-align: left;
    white-space: normal;
    background: linear-gradient(180deg, #fffdf7 0%, #f4faff 100%);
    border-color: #d6eaf8;
}
.poem-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px 32px;
    align-items: start;
}
.poem-single {
    display: flex;
    justify-content: center;
}
.stanza {
    background: rgba(255, 255, 255, 0.9);
    padding: 14px 20px;
    border-radius: 14px;
    border-left: 4px solid var(--primary);
    box-shadow: 0 3px 8px rgba(0,0,0,0.04);
    line-height: 1.9;
}
.verse-line { display: block; }

/* Hộp Chú giải Từ ngữ SGK */
.glossary-box {
    margin-top: 14px;
    padding: 12px 18px;
    background: #fff9e6;
    border-left: 4px solid var(--sun);
    border-radius: 12px;
    font-size: 16px;
    color: #5c4b13;
    line-height: 1.6;
}
.glossary-box b { color: #d35400; }

/* Tương tác câu & từ */
.sn { border-radius: 8px; padding: 2px 6px; transition: all 0.2s; }
.sn.tap { cursor: pointer; }
.sn.tap:hover { background: #fff1c2; }
.sn.good { background: #c9f3dc; font-weight: 800; color: #1e8449; }
.sn.hint { background: #ffe3e7; color: #c0392b; }

.w { cursor: pointer; border-radius: 8px; padding: 1px 5px; transition: all 0.2s; display: inline-block; margin: 0 1px; user-select: none; }
.w:hover { background: #e2e8f0; transform: translateY(-2px); }
.w.got { background: var(--accent); color: #d35400; font-weight: 900; pointer-events: none; transform: scale(1.08); box-shadow: 0 3px 6px rgba(0,0,0,0.1); }

/* V5.0: Trạm Điền từ thay bông hoa (fill) */
.blank-slot {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 90px;
    padding: 2px 12px;
    margin: 0 4px;
    border: 2px dashed var(--pu);
    border-radius: 12px;
    background: #efeaff;
    color: var(--pu);
    font-weight: 900;
    cursor: pointer;
    vertical-align: baseline;
    font-size: 0.92em;
}
.blank-slot.active {
    background: var(--sun);
    border-style: solid;
    color: var(--ink);
    transform: scale(1.06);
}
.blank-slot.filled {
    background: #c9f3dc;
    border: 2px solid var(--ok);
    color: #1e8449;
    cursor: default;
}
.word-bank {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 15px;
    background: #f1f7ff;
    border-radius: 16px;
    border: 2px solid var(--ln);
    margin-top: 12px;
}
.bank-chip {
    background: #fff;
    border: 2px solid var(--pu);
    color: var(--pu);
    padding: 8px 18px;
    border-radius: 20px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 3px 0 #c9dff5;
}
.bank-chip.used {
    opacity: 0.35;
    pointer-events: none;
}

/* V5.0: Trạm Phân loại từ vào nhiều giỏ (group) */
.group-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 12px 0;
}
.group-tab {
    background: #fff;
    border: 3px solid var(--ln);
    color: var(--ink);
    padding: 10px 18px;
    border-radius: 16px;
    font-weight: 800;
    box-shadow: none;
}
.group-tab.active {
    background: var(--pu);
    border-color: var(--pu);
    color: #fff;
}
.group-baskets {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 15px;
}
.group-box {
    border: 3px dashed var(--ln);
    border-radius: 16px;
    padding: 12px;
    background: #fffcf0;
    min-height: 90px;
}
.group-box.active {
    border-color: var(--pu);
    background: #f6f3ff;
}
.group-box h4 {
    margin: 0 0 8px 0;
    color: var(--pu);
    font-size: 16px;
}

/* V5.0: Trạm Sắp xếp trình tự sự việc (order) */
.order-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    margin: 8px 0;
    text-align: left;
    background: #fff;
    border: 3px solid var(--ln);
    box-shadow: 0 4px 0 var(--ln);
    font-size: 18px;
    border-radius: 16px;
    padding: 14px 18px;
}
.order-badge {
    min-width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #eef2f7;
    color: var(--ink);
    display: grid;
    place-items: center;
    font-weight: 900;
}
.order-item.picked {
    border-color: var(--ok);
    background: #c9f3dc;
}
.order-item.picked .order-badge {
    background: var(--ok);
    color: #fff;
}

.shake { animation: sh 0.35s; }
@keyframes sh { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.msg { min-height: 30px; font-weight: 800; margin: 14px 0; font-size: 1.05em; }
.msg.bad { color: var(--bad); }
.msg.ok { color: var(--ok); }

/* Giỏ từ vựng */
.basket {
    border: 4px dashed var(--sun);
    border-radius: 20px;
    padding: 15px;
    margin-top: 16px;
    min-height: 76px;
    background: #fffcf0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}
.basket .sm { color: #d35400; font-weight: 900; width: 100%; display: block; }
.chip {
    display: inline-block;
    background: var(--sun);
    border-radius: 25px;
    padding: 6px 16px;
    font-weight: 900;
    color: var(--ink);
    box-shadow: 0 3px 0 #d99a00;
    margin: 2px;
}

/* Trắc nghiệm & Nối */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.opt {
    display: block; width: 100%; margin: 8px 0; text-align: left;
    background: #fff; border: 3px solid var(--ln); box-shadow: 0 4px 0 var(--ln);
    font-size: 19px; border-radius: 16px; padding: 14px 18px;
}
.opt:hover { background: #f8f9fa; border-color: #b2bec3; }
.opt.sel { border-color: var(--pu); background: #efeaff; box-shadow: 0 4px 0 var(--pu); }
.opt.done { background: #c9f3dc; border-color: var(--ok); box-shadow: 0 4px 0 var(--ok); color: #1e8449; pointer-events: none; }

.big { font-size: 22px; font-weight: 900; line-height: 1.5; color: var(--pu); margin: 16px 0 12px; }
.big-target { font-size: 24px; font-weight: 900; color: #2980b9; background: #ebf5fb; padding: 18px; border-radius: 14px; border: 2px dashed #3498db; text-align: center; white-space: pre-wrap; }

/* Cooldown Overlay */
.cooldown-overlay {
    display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--cooldown-bg); color: white;
    justify-content: center; align-items: center; flex-direction: column;
    z-index: 10; font-size: 28px; font-weight: 900; border-radius: 20px; padding: 20px; text-align: center;
}
.cd-subtext { font-size: 20px; margin-top: 12px; font-weight: 700; }

/* Bảng giáo viên */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 15px; border: 2px solid var(--ln); border-radius: 12px; overflow: hidden; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--ln); }
th { background: #f1f7ff; font-weight: 900; color: var(--pu); }
.grades { display: grid; grid-template-columns: repeat(auto-fit, minmax(115px, 1fr)); gap: 12px; }
.gr { display: flex; flex-direction: column; align-items: center; padding: 16px 10px; background: #fff; border: 3px solid var(--ln); box-shadow: 0 4px 0 var(--ln); font-size: 20px; border-radius: 16px; }
.gr.sel { background: var(--pu); border-color: var(--pu); color: #fff; }
.gr small { font-size: 14px; margin-top: 4px; opacity: 0.85; }
.ls { display: flex; justify-content: space-between; align-items: center; }
.tw { overflow-x: auto; margin-top: 15px; }
.sm { font-size: 15px; opacity: 0.85; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 15px; }

#confetti-canvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 999; display: none; }

/* V5.0: Khu vực In Phiếu Đọc Sách / Xuất PDF gửi Phụ huynh */
#print-area { display: none; }

@media print {
    header, main, #confetti-canvas { display: none !important; }
    body { background: #fff !important; padding: 0 !important; color: #000 !important; }
    #print-area {
        display: block !important;
        padding: 15px 25px;
        font-family: 'Nunito', Arial, sans-serif;
        color: #1d2b53;
    }
    .print-sheet {
        border: 3px double #1d2b53;
        border-radius: 16px;
        padding: 24px 30px;
        max-width: 100%;
    }
    .print-header {
        text-align: center;
        border-bottom: 2px dashed #95a5a6;
        padding-bottom: 12px;
        margin-bottom: 18px;
    }
    .print-header h1 { margin: 4px 0; color: #5b3fd6; font-size: 24px; text-transform: uppercase; }
    .print-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px 24px;
        margin-bottom: 16px;
        font-size: 16px;
    }
    .print-box {
        border: 1px solid #bdc3c7;
        border-radius: 10px;
        padding: 12px 16px;
        margin-bottom: 14px;
        background: #fafbfc;
    }
    .print-sign {
        display: grid;
        grid-template-columns: 1fr 1fr;
        text-align: center;
        margin-top: 28px;
        font-size: 15px;
    }
}

@media (max-width: 600px) {
    .cols { grid-template-columns: 1fr; }
    .read { font-size: 20px; padding: 15px; }
}