/* =========================================================================
   Layout & Hero Section (ขยายเต็มความกว้างด้านข้าง)
   ========================================================================= */
.container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 0 8px;
}

.page-hero {
    text-align: center;
    margin-bottom: 26px;
    animation: fadeInDown 0.5s ease-out;
}
.page-hero h1 { font-size: clamp(1.5rem, 3vw, 2.2rem); color: #0f172a; margin-bottom: 6px; }
.page-hero p { color: var(--muted); font-size: 0.98rem; margin-bottom: 14px; }

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

.btn-hw-jump {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 999px;
    background: linear-gradient(135deg, #ea580c, #f97316);
    color: #ffffff;
    font-weight: 700;
    font-size: 0.9rem;
    text-decoration: none;
    box-shadow: 0 6px 16px rgba(234, 88, 12, 0.28);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.btn-hw-jump:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 22px rgba(234, 88, 12, 0.36);
}

.btn-switch-lesson {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 999px;
    background: #ffffff;
    border: 1.5px solid var(--border);
    color: #334155;
    font-weight: 600;
    font-size: 0.88rem;
    text-decoration: none;
    transition: all 0.2s ease;
}
.btn-switch-lesson:hover {
    border-color: var(--primary);
    color: var(--primary-dark);
    background: #eff6ff;
}

/* =========================================================================
   Main 2-Column Split (ฝั่งซ้ายตรึงอยู่กับที่ ฝั่งขวาเลื่อนตามหน้าเว็บปกติไม่มี Scrollbar)
   ========================================================================= */
.split-main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
    scroll-margin-top: calc(var(--nav-height) + 18px);
}
.split-main > * {
    min-width: 0;
}

/* คอลัมน์ซ้าย: ตรึงตำแหน่งตามการเลื่อนหน้าจอ */
.sim-sticky-left {
    position: sticky;
    top: calc(var(--nav-height) + 16px);
    max-height: calc(100vh - var(--nav-height) - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
    border-top: 4px solid var(--primary);
    scrollbar-width: thin;
    scrollbar-color: #94a3b8 #f1f5f9;
}

.sim-sticky-left::-webkit-scrollbar {
    width: 7px;
}
.sim-sticky-left::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 999px;
}
.sim-sticky-left::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 999px;
}
.sim-sticky-left::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* คอลัมน์ขวา: ขยายยาวตามเนื้อหา เลื่อนไปพร้อมหน้าเว็บหลักโดยไม่มี Scrollbar ซ้อน */
.right-column-stack {
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-width: 0;
}

/* บนหน้าจอมือถือ/แท็บเล็ตแนวตั้ง ให้กลับมาเรียงต่อกันตามปกติ */
@media (max-width: 920px) {
    .split-main {
        grid-template-columns: 1fr;
    }
    .sim-sticky-left {
        position: static;
        max-height: none;
        overflow-y: visible;
    }
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.card-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

/* =========================================================================
   Form & Controls
   ========================================================================= */
.type-switcher {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    background: #f1f5f9;
    padding: 5px;
    border-radius: 12px;
    margin-bottom: 16px;
    border: 1px solid #e2e8f0;
}
.type-option { position: relative; cursor: pointer; }
.type-option input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.type-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 9px 10px;
    border-radius: 9px;
    font-size: 0.88rem;
    font-weight: 600;
    color: #475569;
    transition: background 0.22s ease, color 0.22s ease, box-shadow 0.22s ease;
}
.type-label small { font-size: 0.74rem; font-weight: 500; opacity: 0.85; }
.type-option input:checked + .type-label {
    background: #ffffff;
    color: var(--primary-dark);
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.08);
}
.type-option input[value="open"]:checked + .type-label { color: #c2410c; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 8px;
}
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }

.form-group label { display: block; font-size: 0.88rem; font-weight: 600; margin-bottom: 6px; color: #334155; }
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.slider-wrap { margin-top: 6px; }
input[type="range"] { width: 100%; accent-color: var(--primary); cursor: pointer; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 18px;
    border: none;
    border-radius: 10px;
    font-size: 0.98rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.btn:active { transform: scale(0.98); }

.btn-toggle {
    background: #f1f5f9;
    color: #0f172a;
    border: 1px solid #cbd5e1;
    padding: 8px 14px;
    font-size: 0.86rem;
}
.btn-toggle:hover { background: #e2e8f0; }
.btn-toggle.active { background: #0f172a; color: #fff; border-color: #0f172a; }

.error-box {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    padding: 10px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

/* =========================================================================
   3D Simulation Stage & SVG Net View (ขยายพื้นที่ยาวลงมา ไม่มี Scrollbar)
   ========================================================================= */
.stage {
    position: relative;
    background: radial-gradient(circle at 50% 35%, #f8fafc, #e2e8f0);
    border-radius: 14px;
    height: 410px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: 16px;
    border: 1px solid #cbd5e1;
}
.stage svg { width: 100%; height: 100%; max-width: 480px; }

.stage-status-pill {
    position: absolute;
    top: 10px;
    left: 12px;
    z-index: 5;
    font-size: 0.76rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    background: #0f766e;
    color: #ffffff;
    transition: background 0.25s ease;
}
.stage[data-cyl="open"] .stage-status-pill { background: #c2410c; }

.view-3d, .view-net {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.stage[data-mode="3d"] .view-3d { opacity: 1; transform: scale(1); pointer-events: auto; }
.stage[data-mode="3d"] .view-net { opacity: 0; transform: scale(0.85) translateY(20px); pointer-events: none; }
.stage[data-mode="net"] .view-3d { opacity: 0; transform: scale(1.1) translateY(-15px); pointer-events: none; }
.stage[data-mode="net"] .view-net { opacity: 1; transform: scale(1); pointer-events: auto; }

#svgTopClosed, #svgTopOpen, #netTopClosed, #netTopOpen { transition: opacity 0.3s ease; }
.stage[data-cyl="closed"] #svgTopClosed,
.stage[data-cyl="closed"] #netTopClosed { opacity: 1; }
.stage[data-cyl="closed"] #svgTopOpen,
.stage[data-cyl="closed"] #netTopOpen   { opacity: 0; }

.stage[data-cyl="open"] #svgTopClosed,
.stage[data-cyl="open"] #netTopClosed   { opacity: 0; }
.stage[data-cyl="open"] #svgTopOpen,
.stage[data-cyl="open"] #netTopOpen     { opacity: 1; }

.part-base, .part-side { transition: filter 0.25s ease, opacity 0.25s ease; }
.stage.hl-base .part-side { opacity: 0.28; }
.stage.hl-base .part-base { filter: drop-shadow(0 0 8px rgba(13, 148, 136, 0.65)); }
.stage.hl-side .part-base { opacity: 0.28; }
.stage.hl-side .part-side { filter: drop-shadow(0 0 8px rgba(234, 88, 12, 0.65)); }

#cylinderCanvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    touch-action: none;
}
.sim-controls {
    position: absolute;
    bottom: 10px;
    right: 10px;
    display: flex;
    gap: 6px;
    z-index: 6;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.sim-ctrl-btn {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid #cbd5e1;
    color: #0f172a;
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 0.76rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s ease;
}
.sim-ctrl-btn:hover { background: #eff6ff; border-color: var(--primary); color: var(--primary-dark); }
.sim-ctrl-btn.active { background: #0f172a; color: #ffffff; border-color: #0f172a; }
.sim-hint {
    position: absolute;
    top: 10px;
    right: 12px;
    background: rgba(15, 23, 42, 0.72);
    color: #ffffff;
    font-size: 0.72rem;
    padding: 3px 10px;
    border-radius: 999px;
    pointer-events: none;
    z-index: 5;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 18px;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

/* =========================================================================
   Right Column: Formula Banner, Variable Guide & Steps
   ========================================================================= */
.formula-banner {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    color: #fff;
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 18px;
    text-align: center;
}
.formula-banner.open-mode { background: linear-gradient(135deg, #7c2d12, #431407); }
.formula-banner .main-eq { font-size: 1.25rem; font-weight: 700; color: #93c5fd; margin-top: 4px; }
.formula-banner.open-mode .main-eq { color: #fdba74; }

.var-guide {
    background: #f8fafc;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 15px 16px;
    margin-bottom: 16px;
}
.var-guide-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 7px;
}
.var-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}
@media (max-width: 540px) { .var-grid { grid-template-columns: 1fr; } }

.var-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 9px 11px;
    transition: border-color 0.2s ease, transform 0.2s ease;
}
.var-item:hover {
    border-color: #93c5fd;
    transform: translateY(-1px);
}
.var-sym {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1rem;
    flex-shrink: 0;
    font-family: ui-serif, Georgia, serif;
}
.sym-a  { background: #dbeafe; color: #1d4ed8; }
.sym-pi { background: #ede9fe; color: #6d28d9; }
.sym-r  { background: #ccfbf1; color: #0f766e; }
.sym-h  { background: #ffedd5; color: #c2410c; }

.var-desc { font-size: 0.82rem; line-height: 1.45; color: #334155; }
.var-desc strong { color: #0f172a; display: block; font-size: 0.85rem; }

.formula-breakdown {
    background: #ffffff;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 0.83rem;
    color: #334155;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.fb-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}
.fb-pill {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-weight: 700;
    font-size: 0.82rem;
    padding: 2px 8px;
    border-radius: 6px;
    flex-shrink: 0;
}
.fb-pill-base { background: #ccfbf1; color: #0f766e; }
.fb-pill-side { background: #ffedd5; color: #c2410c; }

.step {
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 15px 16px;
    margin-bottom: 14px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.step:last-child { margin-bottom: 0; }
.step:hover { transform: translateX(4px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); }
.step-base { border-left: 5px solid var(--accent-base); background: #f0fdfa; }
.step-side { border-left: 5px solid var(--accent-side); background: #fff7ed; }
.step-total { border: 2px solid var(--primary); background: #eff6ff; }

.step-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; gap: 8px; flex-wrap: wrap; }
.step-badge { font-size: 0.8rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.badge-base { background: var(--accent-base-bg); color: #0f766e; }
.badge-side { background: var(--accent-side-bg); color: #c2410c; }
.badge-total { background: var(--primary); color: #fff; }

.math-line {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.95rem;
    background: rgba(255,255,255,0.75);
    padding: 8px 10px;
    border-radius: 8px;
    margin-top: 6px;
    overflow-x: auto;
}
.result-highlight { font-size: 1.45rem; font-weight: 800; color: var(--primary); }
.tip-text { font-size: 0.84rem; color: var(--muted); margin-top: 4px; }

/* =========================================================================
   Homework Section (คอลัมน์เดียวในคอลัมน์ขวา)
   ========================================================================= */
.hw-section {
    scroll-margin-top: calc(var(--nav-height) + 18px);
}
.hw-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding-bottom: 18px;
    margin-bottom: 20px;
    border-bottom: 1.5px dashed var(--border);
}
.hw-header h2 { font-size: clamp(1.2rem, 2.2vw, 1.5rem); color: #0f172a; margin-bottom: 4px; }
.hw-header p  { font-size: 0.9rem; color: var(--muted); }
.hw-toolbar   { display: flex; gap: 10px; flex-wrap: wrap; }

.btn-random {
    background: linear-gradient(135deg, #2563eb, #0d9488);
    color: #fff;
    padding: 10px 18px;
    font-size: 0.9rem;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25);
}
.btn-random:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(37, 99, 235, 0.34); }
.btn-random.spinning svg { animation: spinOnce 0.55s ease; }

.btn-reveal-all {
    background: #f8fafc;
    color: #0f172a;
    border: 1.5px solid #cbd5e1;
    padding: 10px 16px;
    font-size: 0.9rem;
}
.btn-reveal-all:hover { background: #e2e8f0; }

.hw-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.hw-card {
    background: #f8fafc;
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    animation: cardPopIn 0.42s ease-out forwards;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.hw-card:hover { border-color: #93c5fd; box-shadow: 0 8px 20px -6px rgba(37, 99, 235, 0.12); }
.hw-card.solved { background: #ffffff; border-color: var(--primary); }

.hw-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.hw-num {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 700;
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 4px 11px;
    border-radius: 999px;
}
.hw-pi-tag {
    font-size: 0.76rem;
    font-weight: 600;
    background: #e2e8f0;
    color: #334155;
    padding: 3px 8px;
    border-radius: 6px;
}
.hw-open-tag {
    font-size: 0.74rem;
    font-weight: 700;
    background: #ffedd5;
    color: #c2410c;
    padding: 3px 8px;
    border-radius: 6px;
}
.btn-plot {
    background: #ffffff;
    color: #0f766e;
    border: 1px solid #99f6e4;
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.18s ease, transform 0.15s ease;
}
.btn-plot:hover { background: #ccfbf1; transform: translateY(-1px); }

.hw-question { font-size: 0.96rem; color: #1e293b; line-height: 1.6; }
.hw-val {
    display: inline-block;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    padding: 1px 8px;
    border-radius: 7px;
    font-weight: 700;
    color: #0f172a;
    margin: 0 2px;
}

.btn-sol {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border-radius: 9px;
    border: 1.5px solid #fed7aa;
    background: #fff7ed;
    color: #c2410c;
    font-size: 0.85rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-sol:hover { background: #ffedd5; }
.btn-sol.open { background: #0f172a; color: #ffffff; border-color: #0f172a; }
.btn-sol svg { transition: transform 0.25s ease; }
.btn-sol.open svg { transform: rotate(180deg); }

.hw-sol-wrap {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}
.hw-card.solved .hw-sol-wrap { grid-template-rows: 1fr; }
.hw-sol-inner { overflow: hidden; }
.hw-sol-box {
    margin-top: 4px;
    padding: 13px 14px;
    border-radius: 10px;
    background: #eff6ff;
    border-left: 4px solid var(--primary);
    font-size: 0.88rem;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.hw-sol-step {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.86rem;
    background: rgba(255, 255, 255, 0.85);
    padding: 6px 9px;
    border-radius: 7px;
    color: #1e293b;
    overflow-x: auto;
}
.hw-sol-ans {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid #bfdbfe;
    font-weight: 700;
    color: var(--primary-dark);
}
.hw-ans-pill {
    background: var(--primary);
    color: #ffffff;
    padding: 3px 11px;
    border-radius: 8px;
    font-size: 0.95rem;
}

/* =========================================================================
   Animations
   ========================================================================= */
.float-anim { animation: floatY 4s ease-in-out infinite; transform-origin: center; }
@keyframes floatY { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes cardPopIn {
    from { opacity: 0; transform: translateY(14px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes spinOnce {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.hw-card.hw-target-highlight {
    border-color: #ea580c;
    box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.22);
}