.kal-ms-app,
.kal-ms-app * { box-sizing: border-box; }
.kal-ms-app {
    --ms-green: #6f8423;
    --ms-green-dark: #516417;
    --ms-cream: #fffdf5;
    --ms-line: #dbe3ba;
    --ms-text: #31401c;
    --ms-muted: #687253;
    --ms-red: #c94c43;
    max-width: 1220px;
    width: 100%;
    container-type: inline-size;
    margin: 28px auto 70px;
    padding: 0 18px;
    color: var(--ms-text);
    font-family: inherit;
}
.kal-ms-app button,
.kal-ms-app select,
.kal-ms-app input { font: inherit; }
.kal-ms-hero {
    display: grid;
    grid-template-columns: 1.4fr .8fr;
    gap: 24px;
    align-items: center;
    padding: 30px 34px;
    border: 1px solid var(--ms-line);
    border-radius: 28px;
    background: linear-gradient(135deg, #fffef8, #eef4d2);
}
.kal-ms-hero h1 { margin: 0 0 8px; font-size: clamp(30px, 4vw, 48px); line-height: 1.05; }
.kal-ms-hero p { margin: 0; font-size: 18px; line-height: 1.7; color: var(--ms-muted); font-weight: 700; }
.kal-ms-hero-note { padding: 18px; border: 1px dashed #b8c77a; border-radius: 18px; background: rgba(255,255,255,.7); line-height: 1.65; font-weight: 700; }
.kal-ms-tabs { display: flex; gap: 10px; margin: 20px 0; padding: 7px; border: 1px solid var(--ms-line); border-radius: 18px; background: #f8faef; }
.kal-ms-tabs button { flex: 1; min-height: 48px; border: 0; border-radius: 13px; background: transparent; color: var(--ms-text); font-weight: 900; cursor: pointer; }
.kal-ms-tabs button.is_active { background: var(--ms-green); color: #fff; }
.kal-ms-panel { margin-top: 18px; }
.kal-ms-controls,
.kal-ms-worksheet-options { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.kal-ms-controls { margin-bottom: 16px; }
.kal-ms-controls label,
.kal-ms-worksheet-options label,
.kal-ms-library-head label { min-width: 180px; color: var(--ms-muted); font-size: 14px; font-weight: 800; }
.kal-ms-app select,
.kal-ms-app input[type="search"] { width: 100%; min-height: 44px; margin-top: 5px; padding: 8px 11px; border: 1px solid #ccd6a5; border-radius: 12px; background: #fff; color: var(--ms-text); }
.kal-ms-app button { min-height: 44px; padding: 8px 15px; border: 1px solid #bdc99a; border-radius: 12px; background: #fff; color: var(--ms-text); font-weight: 900; cursor: pointer; }
.kal-ms-app button:hover { border-color: var(--ms-green); }
.kal-ms-app button.primary { border-color: var(--ms-green); background: var(--ms-green); color: #fff; }
.kal-ms-app button:disabled { opacity: .45; cursor: not-allowed; }
.kal-ms-stage { overflow: hidden; border: 1px solid var(--ms-line); border-radius: 26px; background: var(--ms-cream); }
.kal-ms-stage-head { display: flex; gap: 24px; justify-content: space-between; align-items: start; padding: 24px 28px 14px; }
.kal-ms-stage-head h2 { margin: 5px 0 8px; font-size: clamp(24px, 3vw, 36px); }
.kal-ms-stage-head p { margin: 0; color: var(--ms-muted); font-size: 17px; font-weight: 700; }
.kal-ms-tags { display: flex; gap: 7px; flex-wrap: wrap; }
.kal-ms-tags span { padding: 5px 9px; border-radius: 999px; background: #e9efc9; color: var(--ms-green-dark); font-size: 13px; font-weight: 900; }
.kal-ms-counter { white-space: nowrap; padding: 8px 11px; border-radius: 999px; background: #fff; border: 1px solid var(--ms-line); font-weight: 800; color: var(--ms-muted); }
.kal-ms-board-wrap { position: relative; margin: 0 20px; border: 1px solid #e0e3d7; border-radius: 22px; background: #fff; }
.kal-ms-board { display: block; width: 100%; height: auto; min-height: 360px; touch-action: none; user-select: none; }
.kal-ms-slot-guide { stroke: #dce2cc; stroke-width: 5; stroke-linecap: round; opacity: 0; }
.kal-ms-slot-guide.is_target { opacity: .65; stroke: #9cad5b; stroke-dasharray: 4 8; }
.kal-ms-slot-guide.is_action { opacity: .55; stroke: #9cad5b; stroke-dasharray: 4 8; cursor: pointer; pointer-events: stroke; }
.kal-ms-match { cursor: grab; }
.kal-ms-match.is_action_match { cursor: pointer; }
.kal-ms-match.is_selected line { stroke: #9b6b2f; stroke-width: 12; }
.kal-ms-match line { stroke: #d7a45b; stroke-width: 9; stroke-linecap: round; }
.kal-ms-match circle { fill: var(--ms-red); stroke: #9e3029; stroke-width: 1.4; pointer-events: none; }
.kal-ms-fixed-match line { stroke: #d7a45b; stroke-width: 9; stroke-linecap: round; }
.kal-ms-fixed-match circle { fill: var(--ms-red); stroke: #9e3029; stroke-width: 1.4; }
.kal-ms-move-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 28px; color: var(--ms-muted); font-weight: 800; }
.kal-ms-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 28px 20px; }
.kal-ms-feedback { min-height: 48px; padding: 0 28px 22px; font-weight: 900; line-height: 1.55; }
.kal-ms-feedback.ok { color: #39721f; }
.kal-ms-feedback.bad { color: #a84038; }
.kal-ms-feedback.hint { color: #805f16; }
.kal-ms-worksheet-head,
.kal-ms-library-head { display: flex; justify-content: space-between; gap: 24px; align-items: end; margin-bottom: 18px; }
.kal-ms-worksheet-head h2,
.kal-ms-library-head h2 { margin: 0 0 6px; font-size: 30px; }
.kal-ms-worksheet-head p,
.kal-ms-library-head p { margin: 0; color: var(--ms-muted); }
.kal-ms-check { display: flex; align-items: center; gap: 7px; min-height: 44px; }
.kal-ms-check input { width: 18px; height: 18px; }
.kal-ms-panel[data-panel="worksheet"] { padding-bottom: 120px; }
.kal-ms-builder { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.kal-ms-builder > div,
.kal-ms-builder aside { min-width: 0; padding: 18px; border: 1px solid var(--ms-line); border-radius: 20px; background: #fff; }
.kal-ms-builder aside { display: flex; flex-direction: column; gap: 10px; align-self: start; position: static; }
.kal-ms-builder-title { margin-bottom: 12px; font-weight: 900; font-size: 18px; }
.kal-ms-pick-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.kal-ms-pick { display: flex; min-width: 0; gap: 10px; align-items: start; padding: 13px 14px; border: 1px solid #e0e5cf; border-radius: 14px; background: #fff; }
.kal-ms-pick > span { min-width: 0; flex: 1; }
.kal-ms-pick input { flex: 0 0 auto; margin-top: 4px; }
.kal-ms-pick strong { display: block; margin-bottom: 4px; font-size: 18px; line-height: 1.35; }
.kal-ms-pick-title.is-equation,
.kal-ms-picked-title.is-equation { direction: ltr; unicode-bidi: isolate; text-align: left; white-space: nowrap; font-variant-numeric: tabular-nums; }
.kal-ms-pick small { display: block; color: var(--ms-muted); line-height: 1.55; }
.kal-ms-picked { min-height: 80px; color: var(--ms-muted); line-height: 1.7; }
.kal-ms-picked-list { margin: 0; padding-inline-start: 22px; display: grid; gap: 6px; }
.kal-ms-picked-list li { padding-inline-start: 4px; }
.kal-ms-picked-title { display: inline-block; max-width: 100%; }
.kal-ms-sheet-preview { margin-top: 20px; }
.kal-ms-library { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kal-ms-lib-card { display: flex; flex-direction: column; justify-content: space-between; gap: 12px; min-height: 190px; padding: 16px; border: 1px solid var(--ms-line); border-radius: 18px; background: #fff; }
.kal-ms-lib-card h3 { margin: 7px 0 4px; font-size: 20px; }
.kal-ms-lib-card p { margin: 0; color: var(--ms-muted); font-size: 14px; line-height: 1.55; }
.kal-ms-lib-meta { font-size: 12px; font-weight: 900; color: var(--ms-green-dark); }
.kal-ms-empty { padding: 30px; border: 1px dashed var(--ms-line); border-radius: 16px; color: var(--ms-muted); text-align: center; }
.kal-ms-sheet-page { width: min(100%, 794px); min-height: 1123px; margin: 20px auto; padding: 42px 44px; background: #fff; border: 1px solid #ddd; }
.kal-ms-sheet-page h2 { margin: 0 0 4px; text-align: center; font-size: 28px; }
.kal-ms-sheet-page > p { margin: 0 0 24px; text-align: center; color: #555; }
.kal-ms-sheet-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.kal-ms-sheet-item { min-height: 290px; padding: 13px; border: 1px solid #bdbdbd; border-radius: 10px; break-inside: avoid; }
.kal-ms-sheet-item h3 { margin: 0 0 5px; font-size: 17px; }
.kal-ms-sheet-item p { margin: 0 0 6px; font-size: 13px; line-height: 1.4; }
.kal-ms-sheet-item svg { width: 100%; height: 190px; display: block; }
.kal-ms-answer { margin-top: 7px; padding-top: 7px; border-top: 1px dashed #aaa; font-size: 13px; font-weight: 800; }
.kal-ms-print-root { display: none; }

.kal-ms-tool-card { direction: rtl; display: flex; min-height: 100%; flex-direction: column; justify-content: space-between; gap: 18px; padding: 22px; border: 1px solid #d5e0ae; border-radius: 20px; background: linear-gradient(145deg,#fffef8,#eef5d1); color: #34421e; text-align: right; }
.kal-ms-tool-card h3 { margin: 0 0 8px; font-size: 24px; }
.kal-ms-tool-card p { margin: 0 0 13px; line-height: 1.6; color: #65704e; font-weight: 700; }
.kal-ms-tool-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.kal-ms-tool-meta span { padding: 5px 8px; border-radius: 999px; background: #fff; font-size: 12px; font-weight: 800; }
.kal-ms-tool-card a { display: flex; min-height: 48px; align-items: center; justify-content: center; padding: 0 18px; border-radius: 13px; background: #6f8423; color: #fff !important; text-decoration: none !important; font-weight: 900; }
.kal-ms-account-tools,
.kal-ms-teacher-tools { margin: 26px 0; }
.kal-ms-account-tools > h2 { margin: 0 0 14px; }


@container (min-width: 980px) {
    .kal-ms-builder { grid-template-columns: minmax(0, 1fr) 280px; }
    .kal-ms-builder aside { position: sticky; top: 16px; }
    .kal-ms-pick-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .kal-ms-hero { grid-template-columns: 1fr; }
    .kal-ms-builder { grid-template-columns: 1fr; }
    .kal-ms-builder aside { position: static; }
    .kal-ms-pick-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kal-ms-library { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
    .kal-ms-app { padding: 0 10px; margin-top: 14px; }
    .kal-ms-hero { padding: 22px 18px; border-radius: 20px; }
    .kal-ms-tabs { flex-direction: column; }
    .kal-ms-stage-head,
    .kal-ms-worksheet-head,
    .kal-ms-library-head { flex-direction: column; align-items: stretch; }
    .kal-ms-board-wrap { margin: 0 8px; }
    .kal-ms-move-row,
    .kal-ms-actions,
    .kal-ms-feedback { padding-left: 14px; padding-right: 14px; }
    .kal-ms-pick-list,
    .kal-ms-library { grid-template-columns: 1fr; }
    .kal-ms-sheet-page { min-height: 0; padding: 24px 18px; }
    .kal-ms-sheet-grid { grid-template-columns: 1fr; }
}

@media print {
    body * { visibility: hidden !important; }
    .kal-ms-print-root,
    .kal-ms-print-root * { visibility: visible !important; }
    .kal-ms-print-root { display: block !important; position: absolute; inset: 0; width: 100%; }
    .kal-ms-sheet-page { width: 210mm; min-height: 297mm; margin: 0; padding: 12mm; border: 0; page-break-after: always; }
    .kal-ms-sheet-page:last-child { page-break-after: auto; }
    .kal-ms-sheet-grid { gap: 5mm; }
    .kal-ms-sheet-item { min-height: 0; }
    .kal-ms-sheet-item svg { height: 55mm; }
    @page { size: A4 portrait; margin: 0; }
}

/* 1.1.3 — inviting worksheet puzzle picker */
.kal-ms-puzzle-picker {
    background: linear-gradient(180deg, #fffef9 0%, #fbfdf4 100%) !important;
    padding: 22px !important;
}
.kal-ms-builder-title-row,
.kal-ms-summary-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}
.kal-ms-builder-title-row { margin-bottom: 18px; }
.kal-ms-step-kicker {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 9px;
    margin-bottom: 7px;
    border-radius: 999px;
    background: #edf3d2;
    color: var(--ms-green-dark);
    font-size: 12px;
    font-weight: 900;
}
.kal-ms-builder-subtitle {
    max-width: 620px;
    margin: 4px 0 0;
    color: var(--ms-muted);
    font-size: 14px;
    line-height: 1.6;
    font-weight: 700;
}
.kal-ms-total-count,
.kal-ms-picked-count {
    flex: 0 0 auto;
    padding: 7px 10px;
    border: 1px solid #d9e2b5;
    border-radius: 999px;
    background: #fff;
    color: var(--ms-green-dark);
    font-size: 12px;
    font-weight: 900;
    white-space: nowrap;
}
.kal-ms-pick-list {
    grid-template-columns: 1fr;
    gap: 16px;
}
.kal-ms-pick {
    position: relative;
    display: grid;
    grid-template-rows: 132px auto;
    min-width: 0;
    padding: 0;
    overflow: hidden;
    border: 1.5px solid #dfe6c5;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 8px 22px rgba(69, 83, 31, .06);
    cursor: pointer;
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease, background .18s ease;
}
.kal-ms-pick:hover {
    transform: translateY(-2px);
    border-color: #aebd6f;
    box-shadow: 0 12px 28px rgba(69, 83, 31, .12);
}
.kal-ms-pick.is-picked {
    border-color: var(--ms-green);
    background: linear-gradient(180deg, #ffffff 0%, #f5f9e4 100%);
    box-shadow: 0 0 0 3px rgba(111,132,35,.11), 0 12px 28px rgba(69,83,31,.12);
}
.kal-ms-pick-checkbox {
    position: absolute;
    inset-inline-start: 14px;
    top: 14px;
    width: 28px !important;
    height: 28px !important;
    margin: 0 !important;
    opacity: 0;
    z-index: 4;
    cursor: pointer;
}
.kal-ms-pick-check {
    position: absolute;
    inset-inline-start: 14px;
    top: 14px;
    z-index: 3;
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    border: 2px solid #c8d3a1;
    border-radius: 50%;
    background: rgba(255,255,255,.95);
    color: transparent;
    font-size: 16px;
    font-weight: 1000;
    box-shadow: 0 2px 6px rgba(0,0,0,.06);
    transition: .18s ease;
}
.kal-ms-pick-checkbox:focus-visible + .kal-ms-pick-check {
    outline: 3px solid rgba(111,132,35,.25);
    outline-offset: 3px;
}
.kal-ms-pick.is-picked .kal-ms-pick-check {
    border-color: var(--ms-green);
    background: var(--ms-green);
    color: #fff;
    transform: scale(1.04);
}
.kal-ms-pick-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    overflow: hidden;
    padding: 8px 12px;
    border-bottom: 1px solid #e8ecd8;
    background:
        radial-gradient(circle at 25% 15%, rgba(239,244,211,.95), transparent 34%),
        linear-gradient(135deg, #fffdf6 0%, #f6f9e7 100%);
}
.kal-ms-pick-preview svg {
    display: block;
    width: 100%;
    height: 118px;
    max-width: 330px;
}
.kal-ms-pick-preview .kal-ms-match,
.kal-ms-pick-preview .kal-ms-fixed-match { pointer-events: none; }
.kal-ms-pick-body {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 9px;
    padding: 15px 16px 16px;
}
.kal-ms-pick-number {
    color: #8b9475;
    font-size: 11px;
    font-weight: 900;
}
.kal-ms-pick strong.kal-ms-pick-title {
    margin: 0;
    color: #283416;
    font-size: 21px;
    line-height: 1.3;
}
.kal-ms-pick-title.is-equation {
    text-align: center;
    direction: ltr;
    unicode-bidi: isolate;
    font-size: 23px !important;
    letter-spacing: .01em;
}
.kal-ms-pick-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.kal-ms-pick-badges span {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 8px;
    border: 1px solid #e1e7c7;
    border-radius: 999px;
    background: #fafcf2;
    color: #667047;
    font-size: 11px;
    font-weight: 800;
}
.kal-ms-pick-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    margin-top: 2px;
    padding: 6px 10px;
    border-radius: 11px;
    background: #f3f5eb;
    color: #667047;
    font-size: 12px;
    font-weight: 900;
    transition: .18s ease;
}
.kal-ms-pick.is-picked .kal-ms-pick-cta {
    background: var(--ms-green);
    color: #fff;
}
.kal-ms-selection-summary {
    background: linear-gradient(180deg, #f8faee, #fff) !important;
    border-color: #d7e1b3 !important;
}
.kal-ms-summary-head {
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid #e4ead0;
}
.kal-ms-selection-summary .kal-ms-builder-title { margin: 0; }
.kal-ms-picked {
    min-height: 120px;
    max-height: 420px;
    overflow: auto;
    padding-inline-end: 2px;
}
.kal-ms-picked-empty {
    display: flex;
    min-height: 120px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 20px 14px;
    border: 1px dashed #ced9a9;
    border-radius: 15px;
    background: rgba(255,255,255,.75);
    text-align: center;
}
.kal-ms-picked-empty strong { color: var(--ms-text); font-size: 14px; }
.kal-ms-picked-empty span { color: var(--ms-muted); font-size: 12px; line-height: 1.55; }
.kal-ms-picked-list {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
}
.kal-ms-picked-item {
    display: grid;
    grid-template-columns: 28px minmax(0,1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 9px;
    border: 1px solid #e0e7c8;
    border-radius: 13px;
    background: #fff;
}
.kal-ms-picked-index {
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    border-radius: 50%;
    background: #edf3d2;
    color: var(--ms-green-dark);
    font-size: 11px;
    font-weight: 900;
}
.kal-ms-picked-details { min-width: 0; }
.kal-ms-picked-title {
    display: block;
    overflow: hidden;
    color: var(--ms-text);
    font-size: 13px;
    font-weight: 900;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kal-ms-picked-title.is-equation { text-align: right; }
.kal-ms-picked-details small {
    display: block;
    margin-top: 2px;
    color: var(--ms-muted);
    font-size: 10px;
    font-weight: 700;
}
.kal-ms-app button.kal-ms-picked-remove {
    min-height: 30px;
    padding: 4px 8px;
    border-color: #e2d8d0;
    color: #87594d;
    font-size: 10px;
}
.kal-ms-clear-picks { background: #fafbf5 !important; }
.kal-ms-build-button { min-height: 50px !important; }

@container (min-width: 720px) {
    .kal-ms-pick-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container (min-width: 1180px) {
    .kal-ms-pick-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@container (min-width: 980px) {
    .kal-ms-builder { grid-template-columns: minmax(0, 1fr) 310px; }
}
@media (max-width: 620px) {
    .kal-ms-puzzle-picker { padding: 14px !important; }
    .kal-ms-builder-title-row,
    .kal-ms-summary-head { flex-direction: column; align-items: stretch; }
    .kal-ms-total-count,
    .kal-ms-picked-count { align-self: flex-start; }
    .kal-ms-pick { grid-template-rows: 118px auto; }
    .kal-ms-pick-preview svg { height: 105px; }
}
