/* =========================================================================
   Main Layout & Hero Section
   ========================================================================= */
.def-container {
    max-width: 1120px;
    margin: 0 auto;
}

.def-hero {
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
    color: #ffffff;
    border-radius: 20px;
    padding: 32px 28px;
    margin-bottom: 22px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
    animation: fadeInDown 0.5s ease-out;
}
.def-hero-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.def-hero h1 { font-size: clamp(1.45rem, 2.8vw, 2.1rem); margin-bottom: 6px; }
.def-hero p  { color: #cbd5e1; font-size: 0.94rem; max-width: 640px; }

.btn-print {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 20px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, #10b981, #0d9488);
    color: #ffffff;
    font-family: inherit;
    font-size: 0.94rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(13, 148, 136, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.btn-print:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 22px rgba(13, 148, 136, 0.45);
}

/* Live Search Box */
.search-bar-wrap {
    position: relative;
    max-width: 560px;
}
.search-bar-wrap svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #64748b;
    pointer-events: none;
}
.search-input {
    width: 100%;
    padding: 12px 16px 12px 42px;
    border-radius: 12px;
    border: 2px solid transparent;
    font-size: 0.96rem;
    font-family: inherit;
    color: #0f172a;
    background: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.search-input:focus {
    outline: none;
    border-color: #38bdf8;
    box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.28);
}
.search-count {
    margin-top: 8px;
    font-size: 0.82rem;
    color: #cbd5e1;
}

/* Quick Category Pills */
.cat-tabs {
    display: flex;
    gap: 9px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}
.cat-pill {
    padding: 8px 15px;
    border-radius: 999px;
    background: #ffffff;
    border: 1.5px solid var(--border);
    color: #334155;
    font-size: 0.86rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
}
.cat-pill:hover {
    border-color: var(--primary);
    color: var(--primary-dark);
    background: #eff6ff;
    transform: translateY(-2px);
}

/* =========================================================================
   Category Sections & Standard Definition Cards
   ========================================================================= */
.def-section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 26px;
    scroll-margin-top: calc(var(--nav-height) + 18px);
    animation: fadeUp 0.45s ease-out both;
}
.def-sec-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding-bottom: 13px;
    margin-bottom: 18px;
    border-bottom: 2px solid #f1f5f9;
}
.def-sec-head h2 { font-size: 1.24rem; color: #0f172a; }

.def-badge {
    font-size: 0.78rem;
    font-weight: 700;
    padding: 4px 11px;
    border-radius: 999px;
}
.b-blue   { background: var(--primary-light); color: var(--primary-dark); }
.b-teal   { background: var(--accent-base-bg); color: #0f766e; }
.b-orange { background: var(--accent-side-bg); color: #c2410c; }
.b-purple { background: #ede9fe; color: #6d28d9; }
.b-rose   { background: #ffe4e6; color: #be123c; }

.def-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
}
.def-card {
    background: #f8fafc;
    border: 1.5px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.def-card:hover {
    transform: translateY(-3px);
    background: #ffffff;
    box-shadow: 0 8px 18px -6px rgba(15, 23, 42, 0.1);
}
.def-card.teal   { border-left-color: var(--accent-base); }
.def-card.orange { border-left-color: var(--accent-side); }
.def-card.purple { border-left-color: #7c3aed; }
.def-card.rose   { border-left-color: #e11d48; }

.def-term {
    font-size: 1.02rem;
    font-weight: 700;
    color: #0f172a;
}
.def-eng {
    display: inline-block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    margin-left: 4px;
}
.def-desc {
    font-size: 0.9rem;
    color: #334155;
    line-height: 1.6;
}
.def-desc strong { color: #0f172a; }
.def-desc em     { font-style: normal; font-weight: 700; color: var(--primary-dark); }

.def-math {
    margin-top: auto;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 11px;
    font-size: 0.95rem;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.75;
    overflow-x: auto;
}

.empty-state {
    display: none;
    text-align: center;
    padding: 40px 20px;
    background: #ffffff;
    border-radius: 16px;
    border: 1.5px dashed #cbd5e1;
    color: var(--muted);
    margin-bottom: 24px;
}

/* =========================================================================
   Wide Definition Cards (2-Column Detailed Layout)
   ========================================================================= */
.def-card-wide {
    grid-column: 1 / -1;
    background: #ffffff;
    border: 1.5px solid #bfdbfe;
    border-left: 5px solid var(--primary);
    padding: 20px;
}

.exp-layout {
    display: grid;
    grid-template-columns: 1fr 1.15fr;
    gap: 18px;
    margin-top: 6px;
}
@media (max-width: 780px) { .exp-layout { grid-template-columns: 1fr; } }

.exp-anatomy {
    display: flex;
    align-items: center;
    gap: 14px;
    background: linear-gradient(135deg, #eff6ff, #f0fdfa);
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 12px;
}
.exp-big-sym {
    font-size: 2.3rem;
    font-weight: 800;
    line-height: 1;
    color: #1d4ed8;
    font-family: ui-serif, Georgia, serif;
    padding: 6px 14px;
    background: #ffffff;
    border-radius: 10px;
    border: 1.5px solid #93c5fd;
    flex-shrink: 0;
}
.exp-big-sym sup {
    font-size: 1.25rem;
    color: #ea580c;
    margin-left: 2px;
}
.exp-anatomy-info { font-size: 0.85rem; color: #334155; line-height: 1.55; }

.exp-subhead {
    font-size: 0.86rem;
    font-weight: 700;
    color: #0f172a;
    margin: 10px 0 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.exp-rules-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
@media (max-width: 520px) { .exp-rules-grid { grid-template-columns: 1fr; } }

.exp-rule-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 9px;
    padding: 8px 10px;
    font-size: 0.82rem;
}
.exp-rule-name {
    font-weight: 700;
    color: #0f172a;
    font-size: 0.78rem;
    margin-bottom: 3px;
}
.exp-rule-eq {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-weight: 700;
    color: var(--primary-dark);
    font-size: 0.88rem;
}
.exp-rule-ex {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 2px;
}

.exp-warn-box {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-left: 4px solid #ea580c;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 0.82rem;
    color: #7c2d12;
    line-height: 1.55;
    margin-top: 10px;
}
.exp-warn-box strong { color: #9a3412; }

/* =========================================================================
   Topic-Specific Visuals (Fraction, Integers, Decimals, Ratio, GCD, PEMDAS, Eq)
   ========================================================================= */

/* เศษส่วน */
.exp-big-sym.frac-big {
    font-size: 1.55rem;
    padding: 6px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.exp-big-sym.frac-big .frac > span:first-child {
    color: #1d4ed8;
    border-bottom: 2.5px solid #0f172a;
    padding: 0 8px 3px;
}
.exp-big-sym.frac-big .frac > span:last-child {
    color: #ea580c;
    padding: 3px 8px 0;
}

/* จำนวนเต็ม (เส้นจำนวน) */
.int-line-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 12px 8px;
    margin: 10px 0 12px;
    text-align: center;
}
.int-line-box svg {
    width: 100%;
    max-width: 380px;
    height: auto;
    display: block;
    margin: 0 auto;
}
.int-line-caption {
    display: flex;
    justify-content: space-between;
    font-size: 0.74rem;
    font-weight: 600;
    margin-top: 4px;
    color: var(--muted);
}
.int-neg { color: #c2410c; }
.int-pos { color: #0f766e; }

/* ทศนิยม (ค่าประจำหลัก) */
.dec-place-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 10px 9px;
    margin: 10px 0 12px;
}
.dec-place-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 22px 1fr 1fr 1fr;
    gap: 5px;
    align-items: center;
    text-align: center;
}
.dec-cell {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 5px 3px;
}
.dec-cell.dec-whole { border-top: 3px solid #1d4ed8; }
.dec-cell.dec-frac  { border-top: 3px solid #0d9488; }
.dec-digit {
    font-size: 1.08rem;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.2;
}
.dec-pos {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--muted);
    margin-top: 2px;
}
.dec-val {
    font-size: 0.68rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--primary-dark);
    font-weight: 700;
}
.dec-dot {
    font-size: 1.8rem;
    font-weight: 900;
    color: #ea580c;
    line-height: 1;
    align-self: center;
}
.exp-big-sym.dec-big {
    font-size: 1.5rem;
    padding: 10px 12px;
}
.exp-big-sym.dec-big .dot-hl {
    color: #ea580c;
    font-weight: 900;
}

/* อัตราส่วน สัดส่วน และร้อยละ */
.exp-big-sym.ratio-big {
    font-size: 1.45rem;
    padding: 10px 12px;
    white-space: nowrap;
}
.exp-big-sym.ratio-big .colon-hl {
    color: #ea580c;
    margin: 0 2px;
}
.ratio-link-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 12px;
    margin: 10px 0 12px;
}
.ratio-link-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 0.84rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 8px;
}
.ratio-chip {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 4px 9px;
    text-align: center;
    flex: 1;
    min-width: 68px;
}
.ratio-chip small {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--muted);
}
.ratio-bar-track {
    height: 10px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}
.ratio-bar-fill {
    width: 25%;
    height: 100%;
    background: linear-gradient(90deg, #2563eb, #0d9488);
    border-radius: 999px;
}
.ratio-bar-caption {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--muted);
    margin-top: 4px;
}

/* ห.ร.ม. และ ค.ร.น. */
.exp-big-sym.gcd-big {
    font-size: 1.05rem;
    padding: 10px 10px;
    text-align: center;
    line-height: 1.3;
}
.exp-big-sym.gcd-big span {
    display: block;
    color: #ea580c;
    font-size: 0.95rem;
}
.gcd-visual-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 12px;
    margin: 10px 0 12px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 14px;
    align-items: center;
}
@media (max-width: 480px) { .gcd-visual-box { grid-template-columns: 1fr; } }

.gcd-ladder {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9rem;
    font-weight: 700;
    border-collapse: collapse;
    margin: 0 auto;
}
.gcd-ladder td {
    padding: 2px 9px;
    text-align: center;
}
.gcd-ladder .div-col {
    color: #1d4ed8;
    border-right: 2px solid #0f172a;
}
.gcd-ladder .row-line td:not(.div-col) {
    border-bottom: 2px solid #0f172a;
}
.gcd-ladder .rem-row td:not(.div-col) {
    color: #ea580c;
    padding-top: 4px;
}
.gcd-legend {
    font-size: 0.8rem;
    line-height: 1.6;
    color: #334155;
}
.gcd-pill-i {
    display: inline-block;
    background: #dbeafe;
    color: #1d4ed8;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 6px;
    font-size: 0.75rem;
}
.gcd-pill-l {
    display: inline-block;
    background: #ffedd5;
    color: #c2410c;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 6px;
    font-size: 0.75rem;
}

/* ลำดับการดำเนินการ (PEMDAS) */
.exp-big-sym.ops-big {
    font-size: 1.02rem;
    padding: 10px 10px;
    text-align: center;
    line-height: 1.3;
}
.exp-big-sym.ops-big span {
    display: block;
    color: #ea580c;
    font-size: 0.78rem;
    font-weight: 700;
    margin-top: 2px;
}
.ops-flow-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 12px;
    margin: 10px 0 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.ops-tier {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.81rem;
}
.ops-num {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 800;
    color: #ffffff;
    flex-shrink: 0;
}
.ops-n1 { background: #1d4ed8; }
.ops-n2 { background: #7c3aed; }
.ops-n3 { background: #0d9488; }
.ops-n4 { background: #ea580c; }
.ops-sym {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-weight: 700;
    color: #0f172a;
    min-width: 78px;
    flex-shrink: 0;
}
.ops-note {
    color: #334155;
    font-size: 0.78rem;
}

/* สมการและอสมการ */
.exp-big-sym.eqi-big {
    font-size: 1.05rem;
    padding: 10px 10px;
    text-align: center;
    line-height: 1.3;
}
.exp-big-sym.eqi-big span {
    display: block;
    color: #ea580c;
    font-size: 0.9rem;
    font-weight: 800;
    margin-top: 2px;
}
.eqi-compare-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 12px;
    margin: 10px 0 12px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
@media (max-width: 480px) { .eqi-compare-box { grid-template-columns: 1fr; } }

.eqi-col {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.8rem;
}
.eqi-col.eqi-eq { border-top: 3px solid #1d4ed8; }
.eqi-col.eqi-iq { border-top: 3px solid #0d9488; }
.eqi-col-title {
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 4px;
    font-size: 0.82rem;
}
.eqi-sym-list {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-weight: 700;
    color: var(--primary-dark);
    font-size: 0.86rem;
    margin-bottom: 3px;
}
.eqi-col.eqi-iq .eqi-sym-list { color: #0f766e; }

/* =========================================================================
   Animations & Print A4 Optimization
   ========================================================================= */
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@media print {
    @page { size: A4; margin: 12mm; }
    .def-hero {
        background: #ffffff !important;
        color: #000000 !important;
        border: 2px solid #000000 !important;
        box-shadow: none !important;
        padding: 14px 18px !important;
    }
    .def-hero p { color: #333333 !important; }
    .def-section {
        box-shadow: none !important;
        border: 1px solid #94a3b8 !important;
        padding: 14px !important;
        margin-bottom: 14px !important;
    }
    .def-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
    .def-card { break-inside: avoid; background: #ffffff !important; box-shadow: none !important; }
    .def-card-wide { break-inside: avoid; }
    .exp-layout { grid-template-columns: 1fr 1fr !important; }
}/* CSS Document */

.search-input {
    width: 100%;
    padding: 12px 42px 12px 42px; /* เพิ่ม padding ขวาเป็น 42px เผื่อพื้นที่ปุ่มกากบาท */
    border-radius: 12px;
    border: 2px solid transparent;
    font-size: 0.96rem;
    font-family: inherit;
    color: #0f172a;
    background: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-clear-btn {
    position: absolute;
    right: 10px;
    top: 23px; /* จัดกึ่งกลางแนวตั้งของช่อง input (สูง ~46px) */
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: #e2e8f0;
    color: #475569;
    display: none; /* ซ่อนไว้ก่อนเมื่อยังไม่มีข้อความ */
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 0.18s ease, color 0.18s ease, transform 0.15s ease;
}
.search-clear-btn.visible {
    display: inline-flex;
}
.search-clear-btn:hover {
    background: #cbd5e1;
    color: #0f172a;
}
.search-clear-btn:active {
    transform: translateY(-50%) scale(0.92);
}

