:root {
    --bg-color: #f0f8ff;
    --text-color: #333;
    --card-bg: #ffffff;
    --primary: #ff6b6b;
    --secondary: #4ecdc4;
    --accent: #ffe66d;
    --border: #ddd;
    --shadow: rgba(0, 0, 0, 0.1);
    --ok: #2ecc71;
    --bad: #e74c3c;

    /* Element categories */
    --nm: #a0e6ff;
    --am: #ffb3ba;
    --ae: #ffdfba;
    --tm: #e0e0e0;
    --pt: #baffc9;
    --mt: #ffffba;
    --hl: #f0b3ff;
    --ng: #e6c2ff;
    --la: #ffc2e2;
    --ac: #ffd8b1;
}

body.dark-mode {
    --bg-color: #1a1a2e;
    --text-color: #f5f6fa;
    --card-bg: #16213e;
    --border: #0f3460;
    --shadow: rgba(0, 0, 0, 0.4);

    --nm: #2a7a99; --am: #994d54; --ae: #99794d;
    --tm: #555555; --pt: #4d995c; --mt: #99994d;
    --hl: #8a4d99; --ng: #734d99; --la: #994d73; --ac: #99634d;
}

* { box-sizing: border-box; transition: background-color 0.3s, color 0.3s; font-family: 'Baloo Da 2', 'Baloo 2', cursive, sans-serif; }

body { margin: 0; padding: 10px 10px 10px 270px; background-color: var(--bg-color); color: var(--text-color); overflow-x: hidden; }
[dir="rtl"] body { padding: 10px 270px 10px 10px; }

header { display: flex; flex-wrap: wrap; row-gap: 6px; justify-content: space-between; align-items: center; max-width: 1000px; margin: 0 auto 20px; padding: 10px; background: var(--card-bg); border-radius: 15px; box-shadow: 0 4px 10px var(--shadow); position: relative; z-index: 95; }
h1 { margin: 0; font-size: 24px; color: var(--primary); display: flex; align-items: center; gap: 10px; }
.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

button { background-color: var(--secondary); color: white; border: none; padding: 8px 16px; border-radius: 20px; cursor: pointer; font-size: 16px; font-weight: bold; box-shadow: 0 4px 0 #3b9b95; }
button:hover { transform: translateY(2px); box-shadow: 0 2px 0 #3b9b95; }
button:active { transform: translateY(4px); box-shadow: none; }
button:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
button.icon-btn { background: transparent; box-shadow: none; color: var(--text-color); font-size: 20px; padding: 6px 10px; min-width: 44px; min-height: 44px; }
button.icon-btn:hover, button.icon-btn:active { transform: none; box-shadow: none; }

/* Language switcher */
.lang-switch { display: flex; background: var(--bg-color); border-radius: 20px; padding: 3px; gap: 2px; }
.lang-switch button { background: transparent; color: var(--text-color); box-shadow: none; padding: 6px 10px; font-size: 0.85em; border-radius: 16px; min-height: 36px; }
.lang-switch button:hover { transform: none; box-shadow: none; opacity: 0.75; }
.lang-switch button[aria-pressed="true"] { background: var(--secondary); color: #fff; }

#install-btn { display: none; background: var(--primary); box-shadow: 0 4px 0 #c94f4f; font-size: 0.85em; padding: 8px 12px; }
#install-btn:hover { box-shadow: 0 2px 0 #c94f4f; }

/* Hamburger (mobile only) */
.hamburger-btn { display: none; }

.menu-overlay { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 90; opacity: 0; transition: opacity 0.25s; }
.menu-overlay.open { display: block; opacity: 1; }

/* Sidebar navigation, grouped by subject category */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 250px; z-index: 80;
    background: var(--card-bg); border-right: 1px solid var(--border);
    overflow-y: auto; padding: 18px 12px 30px;
    display: flex; flex-direction: column; gap: 2px;
}
[dir="rtl"] .sidebar { left: auto; right: 0; border-right: none; border-left: 1px solid var(--border); }

.sidebar-brand { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--primary); font-size: 1.1em; padding: 4px 8px 16px; }

.nav-category { margin-bottom: 2px; }
.nav-cat-btn {
    width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
    background: transparent; color: var(--primary); border: none; box-shadow: none;
    padding: 11px 8px; text-align: left; border-radius: 8px;
}
.nav-cat-btn .cat-label { font-family: 'Baloo 2', sans-serif; font-weight: 900; font-size: 1em; letter-spacing: 0.01em; }
[dir="rtl"] .nav-cat-btn { text-align: right; }
.nav-cat-btn:hover, .nav-cat-btn:active { background: var(--bg-color); box-shadow: none; transform: none; }
.nav-cat-btn .chev { display: inline-block; opacity: 0.55; font-size: 0.75em; transition: transform 0.25s ease; }
.nav-category.open .nav-cat-btn .chev { transform: rotate(90deg); }

.nav-cat-items { display: flex; flex-direction: column; gap: 3px; overflow: hidden; max-height: 0; transition: max-height 0.3s ease; padding: 2px 0 2px 6px; }
[dir="rtl"] .nav-cat-items { padding: 2px 6px 2px 0; }
.nav-category.open .nav-cat-items { max-height: 900px; }
.nav-cat-items .tab-btn { width: 100%; text-align: left; font-size: 0.85em; padding: 9px 12px; }
[dir="rtl"] .nav-cat-items .tab-btn { text-align: right; }

.tab-btn { background-color: var(--card-bg); color: var(--text-color); border: 2px solid var(--secondary); box-shadow: none; }
.tab-btn.active { background-color: var(--secondary); color: white; }

.section { display: none; max-width: 1000px; margin: 0 auto; background: var(--card-bg); padding: 20px; border-radius: 15px; box-shadow: 0 4px 15px var(--shadow); }
.section.active { display: block; animation: fadeIn 0.5s; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Periodic table ---------- */
.scroll-hint { display: none; text-align: center; font-size: 0.85em; opacity: 0.7; margin-bottom: 6px; }
.progress-line { text-align: center; font-size: 0.9em; margin-bottom: 4px; opacity: 0.85; }
.progress-track { max-width: 340px; height: 8px; margin: 0 auto 12px; background: var(--bg-color); border-radius: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--secondary); width: 0%; transition: width 0.6s ease; }

.table-toolbar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; margin-bottom: 12px; }
.search-box { flex: 1 1 240px; max-width: 340px; position: relative; }
.search-box input { width: 100%; padding: 10px 34px 10px 14px; border-radius: 20px; border: 2px solid var(--border); background: var(--bg-color); color: var(--text-color); font-size: 0.95em; font-family: inherit; }
.search-box input:focus { outline: none; border-color: var(--secondary); }
.search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: transparent; box-shadow: none; color: var(--text-color); font-size: 1em; padding: 4px 8px; opacity: 0.6; }
.search-clear:hover { transform: translateY(-50%); box-shadow: none; opacity: 1; }

.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 12px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 0.75em; padding: 5px 10px; border-radius: 14px; border: 2px solid transparent; background: var(--bg-color); color: var(--text-color); box-shadow: none; font-weight: 600; }
.chip:hover { transform: none; box-shadow: none; border-color: var(--secondary); }
.chip[aria-pressed="true"] { border-color: var(--primary); }
.chip .legend-swatch { pointer-events: none; }

.pt-grid-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 15px; }
.pt-grid { display: grid; grid-template-columns: repeat(18, 1fr); gap: 4px; }
.element { padding: 0; font-family: inherit; position: relative; aspect-ratio: 1; border-radius: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; border: 1px solid rgba(0, 0, 0, 0.1); box-shadow: 0 2px 4px var(--shadow); }
.element:hover { transform: scale(1.15); z-index: 10; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); }
.element:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; z-index: 11; }
.element .num { font-size: 0.6rem; position: absolute; top: 2px; left: 4px; font-weight: bold; opacity: 0.7; }
.element .sym { font-size: 1.1rem; font-weight: 800; }
.element .mastered-dot { position: absolute; bottom: 2px; right: 3px; font-size: 0.6rem; }
.element.dimmed { opacity: 0.15; pointer-events: none; }
.element.hit { animation: hitPulse 1.2s ease-in-out infinite; }
@keyframes hitPulse { 0%, 100% { box-shadow: 0 0 0 0 var(--primary); } 50% { box-shadow: 0 0 0 3px var(--primary); } }
.empty { visibility: hidden; }

.nm { background-color: var(--nm); color: #000; } .am { background-color: var(--am); color: #000; }
.ae { background-color: var(--ae); color: #000; } .tm { background-color: var(--tm); color: #000; }
.pt { background-color: var(--pt); color: #000; } .mt { background-color: var(--mt); color: #000; }
.hl { background-color: var(--hl); color: #000; } .ng { background-color: var(--ng); color: #000; }
.la { background-color: var(--la); color: #000; } .ac { background-color: var(--ac); color: #000; }

.legend { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; font-size: 0.8em; }
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; border: 1px solid rgba(0, 0, 0, 0.15); }

.empty-note { text-align: center; padding: 20px; opacity: 0.75; font-size: 0.9em; }
.table-footer-row { display: flex; justify-content: center; margin-top: 16px; }
.link-btn { background: transparent; box-shadow: none; color: var(--text-color); font-size: 0.8em; opacity: 0.65; text-decoration: underline; padding: 6px 10px; }
.link-btn:hover { transform: none; box-shadow: none; opacity: 1; }

/* Badges */
.badge-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-top: 10px; }
.badge { background: var(--bg-color); border: 2px solid var(--border); border-radius: 14px; padding: 10px 8px; text-align: center; }
.badge.locked { opacity: 0.45; filter: grayscale(1); }
.badge.earned { border-color: var(--accent); }
.badge-icon { font-size: 1.6em; }
.badge-name { font-size: 0.78em; font-weight: 800; margin-top: 4px; }
.badge-how { font-size: 0.68em; opacity: 0.8; margin-top: 2px; line-height: 1.3; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: none; justify-content: center; align-items: center; z-index: 100; backdrop-filter: blur(3px); overflow-y: auto; padding: 20px 0; }
.modal-overlay.open { display: flex; }
.modal { background: var(--card-bg); padding: 30px; border-radius: 20px; text-align: center; width: min(400px, 92vw); position: relative; animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); margin: auto; }
@keyframes popIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.close-btn { position: absolute; top: 10px; right: 15px; font-size: 24px; cursor: pointer; color: var(--primary); font-weight: bold; background: transparent; box-shadow: none; padding: 4px 8px; }
.close-btn:hover { transform: none; box-shadow: none; }
.modal-emoji { font-size: 60px; margin: 10px 0; }
.modal h2 { margin: 0; font-size: 28px; color: var(--secondary); }
.modal p { font-size: 18px; line-height: 1.4; }
.modal .cat-pill { display: inline-block; font-size: 0.72em; padding: 3px 10px; border-radius: 12px; color: #000; margin-top: 4px; }
.speak-btn { margin-top: 14px; }

/* Atom visualization */
.atom-viz-wrap { display: flex; justify-content: center; margin: 10px 0 4px; }
.atom-viz { position: relative; width: min(200px, 50vw); height: min(200px, 50vw); perspective: 700px; margin: 0 auto; background: radial-gradient(circle at 50% 50%, rgba(255, 107, 107, 0.14), rgba(255, 107, 107, 0) 45%); border-radius: 50%; }
.nucleus { position: absolute; top: 50%; left: 50%; width: 0; height: 0; z-index: 5; }
.nucleus-particle { position: absolute; width: 11px; height: 11px; border-radius: 50%; box-shadow: 0 0 5px rgba(0, 0, 0, 0.35), 0 0 10px rgba(255, 107, 107, 0.35); animation: nucleusPulse 2.6s ease-in-out infinite; }
.nucleus-particle.proton { background: radial-gradient(circle at 32% 28%, #ffb3a8, #ff6b6b 55%, #d94a4a 100%); animation-delay: 0s; }
.nucleus-particle.neutron { background: radial-gradient(circle at 32% 28%, #d5dadb, #95a5a6 55%, #74827e 100%); animation-delay: 0.4s; }
@keyframes nucleusPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}
.shell-ring { position: absolute; top: 50%; left: 50%; border: 1.5px dashed rgba(120, 120, 120, 0.55); border-radius: 50%; transform-style: preserve-3d; animation-timing-function: linear; animation-iteration-count: infinite; }
@keyframes shellSpin {
    from { transform: translate(-50%, -50%) rotateX(var(--tilt, 62deg)) rotateZ(0deg); }
    to { transform: translate(-50%, -50%) rotateX(var(--tilt, 62deg)) rotateZ(360deg); }
}
@keyframes shellSpinReverse {
    from { transform: translate(-50%, -50%) rotateX(var(--tilt, 62deg)) rotateZ(360deg); }
    to { transform: translate(-50%, -50%) rotateX(var(--tilt, 62deg)) rotateZ(0deg); }
}
.electron-dot { position: absolute; width: 9px; height: 9px; border-radius: 50%; background: radial-gradient(circle at 32% 28%, #d8fff7, #4ecdc4 60%, #2e9c90 100%); box-shadow: 0 0 6px #4ecdc4, 0 0 12px rgba(78, 205, 196, 0.5); }
.atom-caption { font-size: 0.8em; text-align: center; opacity: 0.75; margin: 2px 0 12px; line-height: 1.3; }

.stat-chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.stat-chip { background: var(--bg-color); border-radius: 10px; padding: 8px 4px; }
.stat-chip .stat-num { display: block; font-size: 1.2em; font-weight: 800; color: var(--primary); }
.stat-chip .stat-label { display: block; font-size: 0.7em; opacity: 0.8; }

.detail-block { text-align: left; font-size: 0.92em; line-height: 1.4; margin: 8px 0; font-weight: normal; }
.detail-block strong { font-weight: 800; }
.approx-note { font-size: 0.72em; opacity: 0.6; text-align: left; margin: 6px 0 0; line-height: 1.3; }

/* ---------- Magic Lab ---------- */
.lab-container { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.flask { width: 150px; height: 180px; border: 4px solid var(--border); border-top: none; border-radius: 0 0 75px 75px; position: relative; display: flex; flex-wrap: wrap-reverse; align-content: flex-start; justify-content: center; padding: 20px; gap: 5px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.flask::before { content: ''; position: absolute; top: -10px; left: -4px; right: -4px; height: 10px; border: 4px solid var(--border); border-radius: 10px; }
.flask-liquid { position: absolute; bottom: 0; left: 0; right: 0; height: 0%; background: rgba(78, 205, 196, 0.3); transition: height 0.5s; z-index: -1; border-radius: 0 0 70px 70px; }
.lab-element { width: 40px; height: 40px; background: var(--accent); color: #000; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-weight: bold; font-size: 18px; box-shadow: inset -3px -3px 5px rgba(0, 0, 0, 0.2); animation: dropIn 0.5s; }
@keyframes dropIn { 0% { transform: translateY(-100px); } 60% { transform: translateY(10px); } 100% { transform: translateY(0); } }

.element-picker { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.picker-btn { font-size: 18px; padding: 10px 18px; }
.flask-hint { font-size: 0.85em; opacity: 0.7; }

.result-box { min-height: 80px; font-size: 24px; font-weight: bold; text-align: center; color: var(--primary); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.result-emoji { font-size: 50px; animation: tada 1s; }
@keyframes tada { 0% { transform: scale(1); } 10%, 20% { transform: scale(0.9) rotate(-3deg); } 30%, 50%, 70%, 90% { transform: scale(1.1) rotate(3deg); } 40%, 60%, 80% { transform: scale(1.1) rotate(-3deg); } 100% { transform: scale(1) rotate(0); } }

/* Recipe book */
.recipe-wrap { width: 100%; border-top: 2px dashed var(--border); padding-top: 16px; margin-top: 6px; }
.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-top: 10px; }
.recipe-card { color: var(--text-color); width: 100%; font-weight: 400; background: var(--bg-color); border: 2px solid var(--border); border-radius: 14px; padding: 10px 8px; text-align: center; cursor: pointer; }
.recipe-card:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.recipe-card.locked { cursor: default; opacity: 0.55; }
.recipe-card.found { border-color: var(--secondary); }
.recipe-emoji { font-size: 1.7em; }
.recipe-formula { font-weight: 800; font-size: 0.95em; margin-top: 2px; }
.recipe-name { font-size: 0.72em; opacity: 0.85; line-height: 1.3; }

/* ---------- Quiz ---------- */
.quiz-container { text-align: center; }
.mode-select { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 16px; }
.mode-select .choice-btn { background: var(--card-bg); color: var(--text-color); border: 2px solid var(--secondary); box-shadow: none; }
.mode-select .choice-btn.selected { background: var(--secondary); color: #fff; }
.high-score-line { font-size: 1.05em; font-weight: bold; margin-bottom: 10px; }
.quiz-question { font-size: 22px; margin-bottom: 10px; color: var(--secondary); font-weight: bold; line-height: 1.4; }
.score-board { font-size: 20px; font-weight: bold; margin-bottom: 10px; display: flex; justify-content: space-around; flex-wrap: wrap; gap: 6px; background: var(--accent); color: #000; padding: 10px; border-radius: 10px; }
.streak-badge { display: inline-block; margin-top: 6px; font-size: 1.1em; animation: tada 0.6s; }
.timer-wrap { max-width: 400px; margin: 0 auto 14px; }
.timer-bar-bg { background: rgba(0, 0, 0, 0.1); border-radius: 10px; height: 14px; overflow: hidden; }
.timer-bar-fill { height: 100%; background: var(--primary); width: 100%; transition: width 1s linear; }
.timer-label { font-size: 0.85em; opacity: 0.8; margin-top: 4px; }
.mini-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; max-width: 500px; margin: 0 auto; }
.mini-grid .element { font-size: 1.3rem; aspect-ratio: 1; }
.mini-grid .element.correct-flash { outline: 4px solid var(--ok); }
.mini-grid .element.wrong-flash { outline: 4px solid var(--bad); }

/* ---------- Shared topic cards ---------- */
.topic-block { margin-bottom: 34px; }
.topic-block h2 { color: var(--primary); font-size: 1.3em; margin-bottom: 4px; }
.topic-sub { font-size: 0.85em; opacity: 0.8; margin-bottom: 14px; }

.info-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.info-card { color: var(--text-color); width: 100%; font-weight: 400; background: var(--bg-color); border: 2px solid var(--border); border-radius: 14px; padding: 14px; cursor: pointer; text-align: center; }
.info-card:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.info-card .ic-emoji { font-size: 2em; }
.info-card .ic-name { font-weight: 800; margin: 6px 0 4px; font-size: 0.95em; }
.info-card .ic-desc { font-size: 0.82em; line-height: 1.4; display: none; text-align: left; margin-top: 6px; }
.info-card.expanded .ic-desc { display: block; }
.info-card.expanded { border-color: var(--primary); }

/* States of matter */
.state-box { position: relative; height: 170px; border-radius: 14px; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 6px; padding: 18px; background: linear-gradient(180deg, rgba(78, 205, 196, 0.15), rgba(160, 230, 255, 0.25)); transition: background 0.6s; }
.state-box .particle { width: 14px; height: 14px; border-radius: 50%; background: var(--secondary); }
.state-box.phase-solid { gap: 4px; }
.state-box.phase-liquid { gap: 12px; }
.state-box.phase-gas { gap: 24px; background: linear-gradient(180deg, rgba(255, 230, 109, 0.15), rgba(160, 230, 255, 0.15)); }
.state-box.phase-solid .particle { animation: jiggleSolid 1.1s ease-in-out infinite; }
.state-box.phase-liquid .particle { animation: jiggleLiquid 2.2s ease-in-out infinite; }
.state-box.phase-gas .particle { animation: jiggleGas 1.1s linear infinite; }
@keyframes jiggleSolid { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(1px, -1px); } }
@keyframes jiggleLiquid { 0% { transform: translate(0, 0); } 25% { transform: translate(4px, -3px); } 50% { transform: translate(-3px, 4px); } 75% { transform: translate(3px, 3px); } 100% { transform: translate(0, 0); } }
@keyframes jiggleGas { 0% { transform: translate(0, 0); } 20% { transform: translate(18px, -14px); } 40% { transform: translate(-16px, 10px); } 60% { transform: translate(14px, 16px); } 80% { transform: translate(-18px, -10px); } 100% { transform: translate(0, 0); } }
.state-slider-row { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.state-slider-row input[type="range"] { flex: 1; }
.state-label { text-align: center; font-weight: bold; margin-top: 8px; min-height: 44px; }
.state-markers { display: flex; justify-content: space-between; font-size: 0.75em; opacity: 0.7; }

/* Acid-base indicator */
.indicator-row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; justify-content: center; margin: 14px 0; }
.indicator-strip { width: 34px; height: 90px; border-radius: 6px; background: #f5d76e; border: 2px solid #d4b23a; transition: background 0.6s; box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.1); }
.indicator-liquids { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.indicator-liquids button { background: var(--card-bg); color: var(--text-color); border: 2px solid var(--secondary); box-shadow: none; font-size: 0.85em; padding: 8px 12px; }
.indicator-liquids button.selected { background: var(--secondary); color: #fff; }
.indicator-note { text-align: center; font-size: 0.9em; margin-top: 8px; min-height: 24px; }

/* Bonding */
.bond-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.bond-card { background: var(--bg-color); border-radius: 14px; padding: 14px; text-align: center; }
.bond-stage { position: relative; height: 110px; display: flex; align-items: center; justify-content: center; gap: 30px; }
.bond-atom { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.8em; position: relative; }
.bond-electron { position: absolute; width: 9px; height: 9px; border-radius: 50%; background: #333; }
body.dark-mode .bond-electron { background: #eee; }
.ionic-electron { animation: ionicJump 2.4s ease-in-out infinite; }
@keyframes ionicJump { 0%, 15% { left: -6px; top: 4px; } 50%, 65% { left: 60px; top: 4px; } 100% { left: -6px; top: 4px; } }
.covalent-electron-a { animation: covalentShare 2.4s ease-in-out infinite; }
.covalent-electron-b { animation: covalentShare 2.4s ease-in-out infinite reverse; }
@keyframes covalentShare { 0%, 100% { left: 32px; top: 12px; } 50% { left: 32px; top: 28px; } }
.bond-caption { font-size: 0.85em; margin-top: 6px; line-height: 1.4; }

/* Molecules */
.molecule-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.molecule-card { color: var(--text-color); width: 100%; font-weight: 400; background: var(--bg-color); border-radius: 14px; padding: 10px; text-align: center; cursor: pointer; }
.molecule-card:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.molecule-diagram { position: relative; width: 120px; height: 90px; margin: 0 auto 6px; }
.mol-atom { position: absolute; width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.65em; font-weight: 800; color: #000; transform: translate(-50%, -50%); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15); }
.mol-bond { position: absolute; height: 3px; background: #999; transform-origin: 0 50%; }
.molecule-formula { font-weight: 800; }
.molecule-name { font-size: 0.8em; opacity: 0.85; }
.molecule-fact { font-size: 0.78em; margin-top: 6px; display: none; text-align: left; }
.molecule-card.expanded .molecule-fact { display: block; }

/* Body composition */
.body-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.body-bar-label { width: 110px; font-size: 0.85em; flex-shrink: 0; }
.body-bar-track { flex: 1; background: var(--bg-color); border-radius: 8px; height: 20px; overflow: hidden; }
.body-bar-fill { height: 100%; border-radius: 8px; transition: width 0.8s ease; }
.body-bar-pct { width: 50px; text-align: right; font-size: 0.85em; font-weight: bold; flex-shrink: 0; }

/* Recycling */
.recycle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.recycle-card { background: var(--bg-color); border-radius: 14px; padding: 12px; text-align: center; }
.recycle-badge { width: 46px; height: 46px; margin: 0 auto 6px; border: 3px solid var(--secondary); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.1em; }
.recycle-code { font-weight: bold; font-size: 0.85em; }
.recycle-use { font-size: 0.75em; opacity: 0.8; margin-top: 4px; }

/* Scientists */
.scientist-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.scientist-card { background: var(--bg-color); border-radius: 14px; padding: 16px; }
.scientist-header { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.scientist-emoji { font-size: 2em; }
.scientist-name { font-weight: 800; }
.scientist-years { font-size: 0.75em; opacity: 0.7; }
.scientist-bio { font-size: 0.85em; line-height: 1.5; }

/* Timeline */
.timeline { position: relative; padding-left: 24px; border-left: 3px solid var(--secondary); }
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-item::before { content: ''; position: absolute; left: -31px; top: 4px; width: 14px; height: 14px; border-radius: 50%; background: var(--primary); border: 3px solid var(--card-bg); }
.timeline-year { font-weight: 800; color: var(--primary); }
.timeline-text { font-size: 0.88em; margin-top: 2px; }

/* Hazard game */
.hazard-diamond { width: 90px; height: 90px; margin: 0 auto 14px; background: #fff; border: 4px solid #c0392b; transform: rotate(45deg); display: flex; align-items: center; justify-content: center; }
.hazard-diamond span { transform: rotate(-45deg); font-size: 2em; }
.hazard-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 460px; margin: 0 auto; }
.hazard-options button { background: var(--card-bg); color: var(--text-color); border: 2px solid var(--secondary); box-shadow: none; font-size: 0.85em; padding: 10px; }
.hazard-options button.correct-flash { background: var(--ok); color: #fff; }
.hazard-options button.wrong-flash { background: var(--bad); color: #fff; }

/* Equation balancer */
.eq-card { background: var(--bg-color); border-radius: 14px; padding: 16px; margin-bottom: 14px; text-align: center; }
.eq-row { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; font-size: 1.1em; font-weight: bold; margin: 10px 0; }
.eq-row input { width: 44px; text-align: center; font-size: 1em; border: 2px solid var(--secondary); border-radius: 8px; padding: 6px; font-family: inherit; background: var(--card-bg); color: var(--text-color); }
.eq-msg { font-size: 0.9em; min-height: 22px; font-weight: bold; }

/* Metal reactivity */
.reactivity-ladder { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 14px 0; font-size: 0.85em; }
.reactivity-ladder span { background: var(--bg-color); padding: 6px 10px; border-radius: 8px; }
.reactivity-q { text-align: center; font-weight: bold; margin: 10px 0; }

/* Confetti */
.confetti-piece { position: fixed; top: -20px; width: 10px; height: 16px; z-index: 300; pointer-events: none; animation: confetti-fall linear forwards; }
@keyframes confetti-fall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(540deg); opacity: 0.3; }
}

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 120%); background: var(--card-bg); color: var(--text-color); border: 2px solid var(--secondary); border-radius: 16px; padding: 12px 18px; font-weight: bold; font-size: 0.9em; box-shadow: 0 6px 20px var(--shadow); z-index: 400; transition: transform 0.35s ease; max-width: 86vw; text-align: center; }
.toast.show { transform: translate(-50%, 0); }

/* Certificate */
.certificate-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: none; justify-content: center; align-items: center; z-index: 200; padding: 16px; }
.certificate-overlay.open { display: flex; }
.certificate-card { background: #fffdf7; color: #333; border: 6px double #f39c12; border-radius: 14px; padding: 30px; max-width: 420px; width: 100%; text-align: center; position: relative; }
.certificate-card h2 { color: #f39c12; margin: 6px 0; }
.certificate-card .cert-name-input { font-size: 18px; padding: 8px 12px; border-radius: 10px; border: 2px solid var(--border); margin: 10px 0; width: 80%; text-align: center; font-family: inherit; }
.certificate-card .cert-score { font-size: 26px; font-weight: 800; color: var(--primary); margin: 10px 0; }
.certificate-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

/* Footer */
footer { max-width: 1000px; margin: 30px auto 10px; padding: 24px 20px; background: var(--card-bg); border-radius: 15px; box-shadow: 0 4px 10px var(--shadow); text-align: center; }
footer .footer-name { font-size: 1.15em; font-weight: 800; color: var(--primary); }
footer .footer-title { font-size: 0.85em; opacity: 0.8; margin-top: 2px; }
footer .footer-contact { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 20px; margin: 14px 0; font-size: 0.85em; }
footer .footer-contact a { color: var(--text-color); text-decoration: none; }
footer .footer-contact a:hover { color: var(--secondary); text-decoration: underline; }
footer .footer-socials { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
footer .footer-socials a { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; background: var(--bg-color); color: var(--text-color); text-decoration: none; font-size: 1.1em; }
footer .footer-socials a:hover { background: var(--secondary); color: #fff; }
footer .footer-copyright { font-size: 0.75em; opacity: 0.6; margin-top: 16px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media print {
    body * { visibility: hidden; }
    .certificate-card, .certificate-card * { visibility: visible; }
    .certificate-card { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); box-shadow: none; }
    .certificate-actions { display: none; }
}

@media (max-width: 768px) {
    .pt-grid { width: 1000px; }
    .scroll-hint { display: block; }
    h1 { font-size: 20px; }
    .mini-grid { grid-template-columns: repeat(5, 1fr); }

    body { padding: 8px; }
    header { padding: 6px 8px; margin-bottom: 12px; }

    .header-actions { gap: 2px; }
    #theme-btn { min-width: 44px; padding: 6px 8px; }
    .hamburger-btn { display: inline-flex; align-items: center; justify-content: center; padding: 6px 8px; font-size: 20px; }
    .btn-text { display: none; }
    .lang-switch button { padding: 6px 8px; font-size: 0.78em; }

    .modal { padding: 20px; }
    .bond-grid { grid-template-columns: 1fr; }

    [dir="rtl"] body { padding: 8px; }

    .sidebar {
        left: auto; right: 0; bottom: 0; width: 75%; max-width: 300px;
        border-right: none;
        padding: 70px 16px 20px; margin: 0; z-index: 100;
        box-shadow: -6px 0 20px rgba(0, 0, 0, 0.25);
        transform: translateX(100%); transition: transform 0.3s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .menu-close-btn { display: block; position: absolute; top: 14px; right: 14px; background: transparent; box-shadow: none; color: var(--text-color); font-size: 22px; padding: 6px 10px; }
}

.menu-close-btn { display: none; }

@media (max-width: 380px) {
    h1 { font-size: 17px; gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
    .shell-ring, .nucleus-particle, .state-box .particle, .ionic-electron, .covalent-electron-a, .covalent-electron-b, .element.hit { animation: none; }
    * { transition-duration: 0.01ms !important; }
}

/* ---------- Element of the day ---------- */
.eotd-card { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; background: linear-gradient(120deg, rgba(255, 230, 109, 0.35), rgba(78, 205, 196, 0.25)); border: 2px solid var(--accent); border-radius: 16px; padding: 14px 16px; margin-bottom: 16px; }
.eotd-emoji { font-size: 2.4em; line-height: 1; }
.eotd-body { flex: 1 1 200px; min-width: 0; }
.eotd-label { font-size: 0.72em; font-weight: 800; letter-spacing: 0.04em; opacity: 0.75; }
.eotd-name { font-size: 1.1em; font-weight: 800; color: var(--primary); }
.eotd-fact { font-size: 0.85em; line-height: 1.4; opacity: 0.9; }
#eotd-btn { font-size: 0.85em; padding: 8px 14px; }

/* ---------- pH scale ---------- */
.ph-bar { display: grid; grid-template-columns: repeat(15, 1fr); height: 26px; border-radius: 8px; overflow: hidden; margin-bottom: 6px; }
.ph-bar span { display: block; height: 100%; }
.ph-bar span.active { outline: 3px solid var(--text-color); outline-offset: -3px; }
#ph-slider { width: 100%; }
.ph-readout { display: flex; align-items: center; gap: 14px; margin-top: 10px; }
.ph-value { width: 58px; height: 58px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.4em; font-weight: 800; color: #fff; flex-shrink: 0; }
.ph-kind { font-weight: 800; }
.ph-example { font-size: 0.9em; opacity: 0.85; }

/* ---------- Titration ---------- */
.tit-row { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.tit-beaker { width: 80px; height: 110px; border: 4px solid var(--border); border-top: none; border-radius: 0 0 14px 14px; position: relative; overflow: hidden; flex-shrink: 0; }
.tit-liquid { position: absolute; left: 0; right: 0; bottom: 0; height: 62%; background: #f5d76e; transition: background 0.5s; }
.tit-graph { flex: 1 1 200px; min-width: 180px; }
.tit-graph svg { width: 100%; height: 110px; background: var(--bg-color); border-radius: 10px; }
.tit-axis { font-size: 0.72em; opacity: 0.7; text-align: center; margin-top: 2px; }
.tit-controls { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.tit-controls button { font-size: 0.85em; padding: 8px 14px; }
.tit-status { font-weight: 800; margin: 10px 0 2px; }
.tit-msg { font-size: 0.9em; min-height: 22px; margin: 0; }

/* ---------- Flame test ---------- */
.flame-stage { height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; background: #12121e; border-radius: 14px; padding-bottom: 10px; }
.flame { width: 40px; height: 0; border-radius: 50% 50% 46% 46% / 62% 62% 38% 38%; background: #444; transition: height 0.5s ease, background 0.5s ease, box-shadow 0.5s ease; }
.flame.lit { animation: flicker 0.45s ease-in-out infinite alternate; }
@keyframes flicker { from { transform: scaleY(1) scaleX(1); } to { transform: scaleY(1.09) scaleX(0.94); } }
.flame-burner { width: 22px; height: 26px; background: #555; border-radius: 3px 3px 0 0; }
.flame-picker { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.flame-picker button { background: var(--card-bg); color: var(--text-color); border: 2px solid var(--secondary); box-shadow: none; font-size: 0.85em; padding: 8px 12px; }
.flame-picker button.selected { background: var(--secondary); color: #fff; }
.flame-msg { text-align: center; font-weight: bold; min-height: 24px; margin-top: 8px; }

/* ---------- 3D molecule viewer ---------- */
.mol3d-stage { margin: 10px auto 4px; width: min(260px, 70vw); height: min(260px, 70vw); touch-action: none; cursor: grab; }
.mol3d-stage:active { cursor: grabbing; }
.mol3d-stage svg { width: 100%; height: 100%; }
.mol3d-btn { font-size: 0.78em; padding: 6px 12px; margin-top: 6px; }

/* ---------- Syllabus ---------- */
.syl-card { background: var(--bg-color); border: 2px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 10px; }
.syl-chapter { font-weight: 800; }
.syl-how { font-size: 0.86em; line-height: 1.45; margin: 4px 0 8px; }
.syl-card button { font-size: 0.8em; padding: 7px 12px; }

/* ---------- Learning report ---------- */
.report-modal { text-align: left; width: min(460px, 94vw); }
.report-modal h2 { text-align: center; }
.report-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 0.92em; }
.report-row strong { font-size: 1.05em; color: var(--primary); }
.report-list { font-size: 0.8em; line-height: 1.6; opacity: 0.85; margin-top: 10px; }
body.printing-report * { visibility: hidden; }
body.printing-report .report-modal, body.printing-report .report-modal * { visibility: visible; }
body.printing-report .report-modal { position: fixed; top: 0; left: 0; right: 0; box-shadow: none; }
body.printing-report .report-modal .close-btn, body.printing-report #report-print { display: none; }

@media (prefers-reduced-motion: reduce) {
  .flame.lit { animation: none; }
}

/* ---------- Urdu / right-to-left ---------- */
html[lang="ur"], html[lang="ur"] * { font-family: 'Noto Nastaliq Urdu', 'Noto Naskh Arabic', 'Baloo 2', serif; }
html[lang="ur"] body { line-height: 1.9; }
html[lang="ur"] .tab-btn, html[lang="ur"] button { line-height: 1.85; }
html[lang="ur"] .element .sym, html[lang="ur"] .element .num,
html[lang="ur"] .mol-atom, html[lang="ur"] .bond-atom,
html[lang="ur"] .recipe-formula, html[lang="ur"] .molecule-formula,
html[lang="ur"] .eq-row, html[lang="ur"] .reactivity-ladder { font-family: 'Baloo 2', sans-serif; line-height: 1.2; }

/* Chemistry notation always reads left to right */
[dir="rtl"] .pt-grid, [dir="rtl"] .mini-grid, [dir="rtl"] .eq-row,
[dir="rtl"] .reactivity-ladder, [dir="rtl"] .ph-bar, [dir="rtl"] .tit-graph,
[dir="rtl"] .atom-viz, [dir="rtl"] .molecule-diagram, [dir="rtl"] .state-markers { direction: ltr; }

[dir="rtl"] .header-actions { margin-left: 0; margin-right: auto; }
[dir="rtl"] .close-btn { right: auto; left: 15px; }
[dir="rtl"] .search-box input { padding: 10px 14px 10px 34px; }
[dir="rtl"] .search-clear { right: auto; left: 6px; }
[dir="rtl"] .element .num { left: auto; right: 4px; }
[dir="rtl"] .element .mastered-dot { right: auto; left: 3px; }
[dir="rtl"] .detail-block, [dir="rtl"] .approx-note, [dir="rtl"] .report-modal,
[dir="rtl"] .info-card .ic-desc, [dir="rtl"] .molecule-fact, [dir="rtl"] .syl-card { text-align: right; }
[dir="rtl"] .timeline { padding-left: 0; padding-right: 24px; border-left: none; border-right: 3px solid var(--secondary); }
[dir="rtl"] .timeline-item::before { left: auto; right: -31px; }
[dir="rtl"] .body-bar-pct { text-align: left; }
[dir="rtl"] .tit-axis { direction: rtl; }
[dir="rtl"] .math-card-head, [dir="rtl"] .math-qa, [dir="rtl"] .math-example,
[dir="rtl"] .math-section-sub, [dir="rtl"] .math-formula, [dir="rtl"] .math-calc-toggle,
[dir="rtl"] .weight-place { text-align: right; }

@media (max-width: 768px) {
  [dir="rtl"] .sidebar { right: auto; left: 0; border-left: none; transform: translateX(-100%); box-shadow: 6px 0 20px rgba(0, 0, 0, 0.25); }
  [dir="rtl"] .sidebar.open { transform: translateX(0); }
  [dir="rtl"] .menu-close-btn { right: auto; left: 14px; }
}

/* ---------- Rate of reaction ---------- */
.rate-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.rate-beaker { width: 90px; height: 120px; border: 4px solid var(--border); border-top: none; border-radius: 0 0 16px 16px; position: relative; overflow: hidden; background: rgba(160, 230, 255, 0.25); flex-shrink: 0; }
.rate-bubbles { position: absolute; inset: 0; }
.rate-bubbles i { position: absolute; bottom: -12px; width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); border: 1px solid rgba(0, 0, 0, 0.12); animation-name: bubbleUp; animation-timing-function: linear; animation-iteration-count: infinite; }
@keyframes bubbleUp { from { transform: translateY(0); opacity: 0.9; } to { transform: translateY(-125px); opacity: 0; } }
.rate-controls { flex: 1 1 220px; }
.rate-controls label { display: block; font-size: 0.85em; margin-bottom: 10px; }
.rate-controls input[type="range"] { width: 100%; }
.rate-surface { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 0.85em; }
.chip.selected { border-color: var(--primary); background: var(--secondary); color: #fff; }
#rate-svg { width: 100%; height: 90px; background: var(--bg-color); border-radius: 10px; margin-top: 12px; }

/* ---------- Electrolysis ---------- */
.elec-rig { display: flex; align-items: flex-end; justify-content: center; gap: 18px; background: rgba(160, 230, 255, 0.2); border-radius: 14px; padding: 14px; }
.elec-tube { width: 60px; height: 130px; border: 4px solid var(--border); border-bottom: none; border-radius: 14px 14px 0 0; position: relative; overflow: hidden; display: flex; align-items: flex-end; justify-content: center; }
.elec-gas { position: absolute; top: 0; left: 0; right: 0; height: 0%; transition: height 0.3s linear; }
.elec-gas.h2 { background: rgba(78, 205, 196, 0.55); }
.elec-gas.o2 { background: rgba(255, 107, 107, 0.5); }
.elec-cap { position: relative; font-size: 0.6em; font-weight: 800; text-align: center; padding-bottom: 4px; line-height: 1.2; }
.elec-cell { display: flex; flex-direction: column; align-items: center; }
.elec-battery { font-size: 2em; }

/* ---------- Half-life ---------- */
.atom-grid { display: grid; grid-template-columns: repeat(20, 1fr); gap: 3px; margin: 12px 0; max-width: 420px; }
.atom-grid i { display: block; aspect-ratio: 1; border-radius: 50%; background: #f39c12; transition: background 0.4s, opacity 0.4s; }
.atom-grid i.decayed { background: var(--border); opacity: 0.45; }

/* ---------- Chromatography ---------- */
.chrom-stage { display: flex; flex-direction: column; align-items: center; margin: 12px 0; }
.chrom-paper { width: 90px; height: 170px; background: #fdfdf5; border: 1px solid var(--border); position: relative; overflow: hidden; }
.chrom-dot { position: absolute; left: 50%; bottom: 14px; width: 26px; height: 12px; border-radius: 50%; transform: translateX(-50%); background: #1a1a1a; }
.chrom-band { position: absolute; left: 50%; bottom: 14px; width: 26px; height: 10px; border-radius: 50%; transform: translateX(-50%); transition: bottom 2.4s ease-out, opacity 0.4s; }
.chrom-water { width: 130px; height: 16px; background: rgba(78, 205, 196, 0.45); border-radius: 0 0 8px 8px; border: 2px solid var(--border); border-top: none; }

/* ---------- Detective ---------- */
.det-header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.det-jar { font-size: 2.6em; position: relative; line-height: 1; }
.det-jar-label { display: block; font-size: 0.24em; font-weight: 800; opacity: 0.8; }
.det-tests { display: flex; flex-wrap: wrap; gap: 8px; }
.det-tests .chip { font-size: 0.82em; padding: 8px 12px; }
.det-tests .chip[disabled] { opacity: 0.45; }
.det-clues { margin-top: 10px; }
.det-clue { background: var(--bg-color); border-inline-start: 4px solid var(--secondary); border-radius: 8px; padding: 8px 12px; font-size: 0.88em; margin-bottom: 6px; }
.det-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.det-options button { background: var(--card-bg); color: var(--text-color); border: 2px solid var(--secondary); box-shadow: none; font-size: 0.82em; padding: 10px; }
.det-options button.correct-flash { background: var(--ok); color: #fff; }
.det-options button.wrong-flash { background: var(--bad); color: #fff; }

@media (max-width: 480px) {
  .atom-grid { grid-template-columns: repeat(10, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .rate-bubbles i { animation: none; }
}

/* ---------- Ion / formula builder ---------- */
.ion-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ion-head { font-weight: 800; font-size: 0.85em; margin: 0 0 6px; }
.ion-list { display: flex; flex-direction: column; gap: 6px; }
.ion-list button { background: var(--bg-color); color: var(--text-color); border: 2px solid var(--border); box-shadow: none; font-size: 0.85em; padding: 8px 10px; text-align: start; display: flex; justify-content: space-between; gap: 8px; }
.ion-list button:hover { transform: none; box-shadow: none; border-color: var(--secondary); }
.ion-list button.selected { border-color: var(--primary); background: var(--secondary); color: #fff; }
.ion-charge { font-weight: 800; }
.ion-result { margin-top: 16px; text-align: center; background: var(--bg-color); border-radius: 14px; padding: 16px; }
.ion-formula { font-size: 2em; font-weight: 800; color: var(--primary); min-height: 1.2em; font-family: 'Baloo 2', sans-serif; }
.ion-name { font-weight: 800; }

/* ---------- Electron configuration ---------- */
.econf-shells { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 12px 0; }
.econf-shell { background: var(--bg-color); color: var(--text-color); border: 3px dashed var(--border); box-shadow: none; border-radius: 16px; padding: 10px; min-width: 108px; }
.econf-shell:hover { transform: none; box-shadow: none; border-color: var(--secondary); }
.econf-shell-name { font-size: 0.72em; font-weight: 800; opacity: 0.8; }
.econf-count { font-size: 1.3em; font-weight: 800; color: var(--primary); }
.econf-dots { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; min-height: 22px; max-width: 92px; margin: 4px auto 0; }
.econf-dots i { width: 9px; height: 9px; border-radius: 50%; background: #4ecdc4; display: block; }

/* ---------- Element card battle ---------- */
.trump-table { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
.trump-card { background: var(--bg-color); border: 3px solid var(--border); border-radius: 16px; padding: 14px; width: 150px; text-align: center; }
.trump-card.winner { border-color: var(--ok); }
.trump-card.loser { opacity: 0.6; }
.trump-side { font-size: 0.7em; font-weight: 800; opacity: 0.7; }
.trump-emoji { font-size: 2em; }
.trump-sym { font-size: 1.5em; font-weight: 800; font-family: 'Baloo 2', sans-serif; }
.trump-name { font-size: 0.78em; min-height: 2.4em; }
.trump-stat { display: flex; justify-content: space-between; font-size: 0.74em; border-top: 1px dashed var(--border); padding-top: 3px; margin-top: 3px; }
.trump-stat.hidden-val b { filter: blur(5px); }
.trump-vs { font-size: 1.6em; }
#trump-stats button { font-size: 0.8em; padding: 8px 12px; }

/* ---------- Safe experiments ---------- */
.safe-warn { background: rgba(231, 76, 60, 0.12); border: 2px solid var(--bad); border-radius: 12px; padding: 10px 14px; font-size: 0.85em; font-weight: bold; }
.safe-card { background: var(--bg-color); border: 2px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.safe-name { font-weight: 800; font-size: 1.02em; margin-bottom: 6px; }
.safe-part { font-size: 0.86em; line-height: 1.5; margin-bottom: 6px; }
.safe-part b { color: var(--primary); }
body.printing-safe * { visibility: hidden; }
body.printing-safe #safe-block, body.printing-safe #safe-block * { visibility: visible; }
body.printing-safe #safe-block { position: absolute; top: 0; left: 0; right: 0; }
body.printing-safe #safe-print { display: none; }

@media (max-width: 480px) {
  .ion-columns { grid-template-columns: 1fr; }
}

/* ---------- Motion track ---------- */
.track { position: relative; height: 96px; background: linear-gradient(180deg, rgba(160,230,255,0.2), rgba(78,205,196,0.15)); border-radius: 14px; overflow: hidden; margin-bottom: 12px; }
.track-ground { position: absolute; left: 0; right: 0; bottom: 0; height: 12px; background: repeating-linear-gradient(90deg, var(--border) 0 10px, transparent 10px 20px); }
.track-box { position: absolute; bottom: 14px; left: 8px; font-size: 2.2em; line-height: 1; transition: left 0.2s linear; }
.track-box.rolling { animation: rollAcross linear infinite; }
@keyframes rollAcross { from { left: 4%; } to { left: 86%; } }
.rocket-air { position: absolute; bottom: 18px; left: 8px; font-size: 1.4em; opacity: 0; }
.rocket-air.puff { animation: puffBack 1.6s ease-out forwards; }
@keyframes puffBack { 0% { opacity: 0.9; left: 60%; } 100% { opacity: 0; left: 4%; } }
.track-box.launch { animation: flyForward 1.6s ease-out forwards; }
@keyframes flyForward { from { left: 8px; } to { left: 84%; } }

/* ---------- Weight table ---------- */
.weight-input { display: block; font-size: 0.85em; margin-bottom: 10px; }
.weight-input input { width: 100%; }
.weight-table { display: grid; gap: 4px; }
.weight-row { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 6px; align-items: center; background: var(--bg-color); border-radius: 10px; padding: 8px 10px; font-size: 0.82em; }
.weight-row.head { background: transparent; font-weight: 800; opacity: 0.75; font-size: 0.74em; padding-bottom: 0; }
.weight-row.earth { border: 2px solid var(--secondary); }
.weight-place { display: flex; align-items: center; gap: 6px; }
.weight-num { font-weight: 800; text-align: end; font-family: 'Baloo 2', sans-serif; }

/* ---------- Ohm's law / circuits ---------- */
.ohm-stage, .circuit-stage { display: flex; align-items: center; justify-content: center; gap: 20px; background: #14141f; border-radius: 14px; padding: 20px; margin-bottom: 12px; }
.bulb { font-size: 2.6em; line-height: 1; filter: grayscale(1) brightness(0.5); transition: filter 0.3s, text-shadow 0.3s; }
.circuit-battery { font-size: 2.2em; }
.circuit-bulbs { display: flex; gap: 22px; align-items: center; }
.circuit-bulb-wrap { text-align: center; color: #ddd; }
.circuit-bulb-wrap .label { font-size: 0.62em; font-weight: 800; margin-top: 2px; }
.circuit-stage.parallel .circuit-bulbs { flex-direction: column; gap: 10px; }

/* ---------- Physics canvases ---------- */
.phys-svg { width: 100%; background: var(--bg-color); border-radius: 12px; margin-bottom: 10px; }
#refr-svg, #wave-svg { height: 190px; }
#lens-svg { height: 160px; }

/* Prism */
.prism-stage { position: relative; height: 130px; background: #12121e; border-radius: 14px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.prism-shape { font-size: 3em; }
.prism-beam { position: absolute; left: 0; top: 50%; width: 0; height: 4px; background: #fff; box-shadow: 0 0 12px #fff; transform: translateY(-50%); transition: width 0.6s ease; }
.prism-beam.on { width: 46%; }
.prism-fan { position: absolute; right: 6%; top: 50%; width: 44%; height: 0; }
.prism-fan i { position: absolute; left: 0; top: 0; height: 4px; width: 0; border-radius: 2px; transform-origin: 0 50%; transition: width 0.7s ease; }
.prism-fan.on i { width: 100%; }

/* Magnets */
.field-stage { position: relative; background: var(--bg-color); border-radius: 14px; padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.bar-magnet { display: flex; width: 150px; height: 40px; border-radius: 6px; overflow: hidden; font-weight: 800; color: #fff; font-size: 0.9em; }
.bar-magnet.small { width: 96px; height: 32px; font-size: 0.78em; }
.bar-magnet span { flex: 1; display: flex; align-items: center; justify-content: center; }
.bar-magnet .pole-n { background: #e74c3c; }
.bar-magnet .pole-s { background: #2980b9; }
.compass-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; width: 100%; max-width: 380px; }
.compass { aspect-ratio: 1; border-radius: 50%; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; background: var(--card-bg); }
.compass i { display: block; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 15px solid #e74c3c; transition: transform 0.5s ease; }
.pair-stage { display: flex; align-items: center; justify-content: center; gap: 16px; background: var(--bg-color); border-radius: 14px; padding: 20px; }
.bar-magnet.slide-in { transition: transform 0.8s ease; }
.emag-stage { display: flex; align-items: center; justify-content: center; gap: 8px; background: var(--bg-color); border-radius: 14px; padding: 18px; min-height: 74px; flex-wrap: wrap; }
.emag-nail { font-size: 2.4em; transition: filter 0.3s; }
.emag-nail.live { filter: drop-shadow(0 0 10px #4ecdc4); }
.emag-clips { font-size: 1.3em; letter-spacing: 2px; word-break: break-all; }

/* ---------- Relativity clocks ---------- */
.clock-pair { display: flex; justify-content: center; gap: 26px; background: var(--bg-color); border-radius: 14px; padding: 18px; margin-bottom: 12px; }
.clock-box { text-align: center; }
.clock-face { font-size: 2.6em; line-height: 1; animation: tick 2s steps(12) infinite; }
.clock-label { font-size: 0.78em; font-weight: 800; margin-top: 4px; }
@keyframes tick { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .clock-face { animation: none; } }

/* ---------- Mathematics ---------- */
.math-hero { background: linear-gradient(135deg, rgba(99, 102, 241, 0.16), rgba(236, 72, 153, 0.12)); border: 1px solid var(--border); border-radius: 16px; padding: 20px; margin-bottom: 16px; }
.math-hero h2 { margin: 0 0 6px; font-size: 1.3em; color: var(--primary); }
.math-hero p { margin: 0; opacity: 0.85; font-size: 0.92em; }
.math-stats { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.math-stat { background: var(--card-bg); border: 1px solid var(--border); border-radius: 11px; padding: 9px 14px; text-align: center; min-width: 84px; }
.math-stat b { display: block; font-size: 1.2em; color: var(--primary); }
.math-stat span { font-size: 0.7em; opacity: 0.75; }

.math-section { margin-bottom: 30px; scroll-margin-top: 20px; }
.math-section-title { display: flex; align-items: center; gap: 8px; font-size: 1.15em; font-weight: 800; color: var(--primary); margin-bottom: 2px; }
.math-section-sub { font-size: 0.82em; opacity: 0.75; margin: 0 0 12px; }
.math-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }

.math-card { background: var(--bg-color); border: 2px solid var(--border); border-radius: 14px; padding: 14px; content-visibility: auto; contain-intrinsic-size: 340px; }
.math-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.math-card-head h3 { margin: 0; font-size: 1.02em; }
.math-card-head small { display: block; font-weight: 400; opacity: 0.65; font-size: 0.72em; margin-top: 2px; }
.math-card-acts { display: flex; gap: 4px; flex-shrink: 0; }
.math-card-acts button { background: transparent; box-shadow: none; color: var(--text-color); font-size: 1.05em; padding: 4px 6px; min-width: auto; min-height: auto; }
.math-card-acts button:hover, .math-card-acts button:active { transform: none; box-shadow: none; opacity: 0.7; }
.math-card-acts button.fav-on { color: #f39c12; }

.math-badge { display: inline-block; font-size: 0.68em; font-weight: 700; background: var(--bg-color); border: 1px solid var(--border); color: var(--dim, var(--text-color)); padding: 2px 8px; border-radius: 10px; margin-top: 6px; }
.math-formula { font-family: 'Baloo 2', sans-serif; background: var(--card-bg); border-radius: 8px; padding: 8px 10px; margin: 8px 0; white-space: pre-wrap; font-size: 0.9em; line-height: 1.5; }
.math-qa { font-size: 0.85em; line-height: 1.55; margin-bottom: 6px; }
.math-qa b { color: var(--secondary); }
.math-example { background: var(--card-bg); border-radius: 8px; padding: 8px 10px; font-size: 0.85em; white-space: pre-wrap; line-height: 1.5; }
.math-example b { display: block; margin-bottom: 3px; }

.math-calc { margin-top: 10px; border-top: 1px dashed var(--border); padding-top: 8px; }
.math-calc-toggle { width: 100%; background: transparent; color: var(--secondary); box-shadow: none; border: none; font-size: 0.8em; font-weight: 700; text-align: left; padding: 4px 0; }
.math-calc-toggle:hover, .math-calc-toggle:active { transform: none; box-shadow: none; }
.math-calc-body { display: none; margin-top: 8px; }
.math-card.calc-open .math-calc-body { display: block; }
.math-calc-inputs { display: flex; flex-wrap: wrap; gap: 8px; }
.math-calc-inputs div { flex: 1 1 100px; }
.math-calc-inputs label { display: block; font-size: 0.7em; opacity: 0.75; margin-bottom: 3px; }
.math-calc-inputs input { width: 100%; padding: 7px 9px; border-radius: 8px; border: 2px solid var(--border); background: var(--card-bg); color: var(--text-color); font-size: 0.85em; font-family: inherit; }
.math-calc-go { font-size: 0.8em; padding: 7px 14px; margin-top: 8px; }
.math-calc-result { margin-top: 8px; font-size: 0.85em; font-weight: 700; white-space: pre-wrap; line-height: 1.5; min-height: 1.2em; }

@media (prefers-reduced-motion: reduce) {
  .math-calc-body { transition: none; }
}

/* ---------- Global search (sidebar) ---------- */
.gsearch-box { position: relative; margin-bottom: 14px; }
.gsearch-box input { width: 100%; padding: 9px 32px 9px 12px; border-radius: 12px; border: 2px solid var(--border); background: var(--bg-color); color: var(--text-color); font-size: 0.85em; font-family: inherit; }
.gsearch-box input:focus { outline: none; border-color: var(--secondary); }
.gsearch-box .search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: transparent; box-shadow: none; color: var(--text-color); font-size: 0.85em; padding: 4px 6px; opacity: 0.55; min-width: auto; min-height: auto; }
.gsearch-box .search-clear:hover, .gsearch-box .search-clear:active { transform: translateY(-50%); box-shadow: none; opacity: 1; }
[dir="rtl"] .gsearch-box input { padding: 9px 12px 9px 32px; }
[dir="rtl"] .gsearch-box .search-clear { right: auto; left: 6px; }

.gsearch-results { position: absolute; top: calc(100% + 4px); left: 0; right: 0; max-height: 62vh; overflow-y: auto; background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 28px rgba(0,0,0,0.25); z-index: 90; padding: 6px; }
.gsearch-group-label { font-size: 0.68em; font-weight: 800; opacity: 0.6; padding: 8px 8px 3px; text-transform: uppercase; letter-spacing: 0.03em; }
.gsearch-item { display: block; width: 100%; text-align: left; background: transparent; color: var(--text-color); border: none; box-shadow: none; padding: 8px 9px; border-radius: 8px; font-size: 0.85em; min-height: auto; }
[dir="rtl"] .gsearch-item { text-align: right; }
.gsearch-item:hover, .gsearch-item:focus-visible, .gsearch-item:active { background: var(--bg-color); transform: none; box-shadow: none; }
.gsearch-item small { display: block; opacity: 0.65; font-size: 0.82em; margin-top: 1px; }
.gsearch-empty { padding: 14px 10px; font-size: 0.82em; opacity: 0.65; text-align: center; }

@media (max-width: 768px) {
  .gsearch-results { max-height: 50vh; }
}

/* ---------- Worksheet generator ---------- */
.worksheet-open-btn { margin-top: 14px; font-size: 0.85em; padding: 9px 16px; }
.worksheet-modal { width: min(560px, 94vw); text-align: left; max-height: 88vh; overflow-y: auto; }
[dir="rtl"] .worksheet-modal { text-align: right; }
.worksheet-modal h2 { text-align: center; }

.worksheet-field { padding: 7px 10px; border-radius: 8px; border: 2px solid var(--border); background: var(--bg-color); color: var(--text-color); font-family: inherit; font-size: 0.85em; }
.worksheet-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 2px dashed var(--border); }
.worksheet-field#worksheet-name { flex: 2 1 140px; }
.worksheet-field#worksheet-class { flex: 1 1 80px; }
.worksheet-date { font-size: 0.8em; opacity: 0.75; flex: 1 1 100px; text-align: right; }
[dir="rtl"] .worksheet-date { text-align: left; }

.worksheet-questions { list-style: none; margin: 0; padding: 0; counter-reset: wq; }
.worksheet-q { background: var(--bg-color); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.worksheet-q-title { font-weight: 800; color: var(--primary); margin-bottom: 6px; font-size: 0.92em; }
.worksheet-q-given { font-size: 0.85em; line-height: 1.6; margin-bottom: 4px; }
.worksheet-q-given b { color: var(--secondary); }
.worksheet-q-find { font-size: 0.82em; opacity: 0.8; margin-bottom: 8px; }
.worksheet-q-space { border-bottom: 1.5px dashed var(--border); height: 34px; font-size: 0.72em; opacity: 0.45; padding-top: 4px; }

.worksheet-key-list { list-style: decimal; padding-inline-start: 22px; font-size: 0.85em; line-height: 1.7; }
.worksheet-key-list li { margin-bottom: 4px; }
#worksheet-key { margin-top: 14px; padding-top: 10px; border-top: 2px dashed var(--border); }
#worksheet-key h3 { margin: 0 0 6px; font-size: 1em; color: var(--primary); }

@media print {
  body.printing-worksheet * { visibility: hidden; }
  body.printing-worksheet .worksheet-modal, body.printing-worksheet .worksheet-modal * { visibility: visible; }
  body.printing-worksheet .worksheet-modal { position: fixed; inset: 0; box-shadow: none; max-height: none; overflow: visible; width: 100%; }
  body.printing-worksheet #worksheet-builder,
  body.printing-worksheet .close-btn,
  body.printing-worksheet #worksheet-toggle-key,
  body.printing-worksheet #worksheet-regenerate-btn,
  body.printing-worksheet #worksheet-print-btn { display: none; }
  body.printing-worksheet .worksheet-q { break-inside: avoid; }
}

/* ---------- Biology: body system journey ---------- */
.bodysys-journey { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.bodysys-stage { display: flex; align-items: flex-start; gap: 12px; background: var(--bg-color); border: 2px solid var(--border); border-radius: 14px; padding: 12px 14px; }
.bodysys-stage-num { flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--secondary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.8em; }
.bodysys-stage-icon { font-size: 1.8em; flex-shrink: 0; line-height: 1.3; }
.bodysys-stage-body h4 { margin: 0 0 3px; font-size: 0.95em; }
.bodysys-stage-body p { margin: 0; font-size: 0.85em; opacity: 0.9; line-height: 1.5; }
.bodysys-connector { width: 2px; height: 12px; background: var(--border); margin-left: 29px; }
[dir="rtl"] .bodysys-connector { margin-left: 0; margin-right: 29px; }

/* ---------- Biology: photosynthesis ---------- */
.photo-eq-box { background: linear-gradient(135deg, rgba(46, 204, 113, 0.15), rgba(241, 196, 15, 0.12)); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; margin: 12px 0; }
.photo-eq-label { font-size: 0.72em; font-weight: 800; opacity: 0.7; margin-bottom: 4px; }
.photo-eq { font-family: 'Baloo 2', sans-serif; font-size: 0.92em; line-height: 1.6; }
.photo-demo { background: var(--bg-color); border-radius: 14px; padding: 16px; text-align: center; margin-top: 12px; }
.photo-plant { font-size: 3em; line-height: 1; margin-bottom: 10px; transition: filter 0.4s, transform 0.4s; }
.photo-demo .weight-input { text-align: left; max-width: 320px; margin: 0 auto 10px; }
[dir="rtl"] .photo-demo .weight-input { text-align: right; }

/* ---------- Biology: cell/classification badges ---------- */
.cell-part-badge { display: inline-block; font-size: 0.68em; font-weight: 700; padding: 2px 9px; border-radius: 10px; margin-top: 6px; }
.cell-part-badge.only { background: rgba(243, 156, 18, 0.18); color: #b8720a; }
.cell-part-badge.both { background: rgba(46, 204, 113, 0.18); color: #1e8449; }

/* ---------- Biology: food chain ---------- */
.sub-heading { font-size: 1em; font-weight: 800; color: var(--primary); margin: 4px 0 10px; }
.foodchain-example { background: var(--bg-color); border: 2px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.foodchain-example-title { font-weight: 800; font-size: 0.9em; margin-bottom: 10px; }
.foodchain-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.foodchain-link { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 60px; }
.foodchain-link .fc-icon { font-size: 1.8em; line-height: 1; }
.foodchain-link .fc-name { font-size: 0.68em; text-align: center; opacity: 0.85; }
.foodchain-arrow { font-size: 1.1em; opacity: 0.5; flex-shrink: 0; margin: 0 2px; }

/* ---------- Biology: life cycle loop indicator ---------- */
.lifecycle-loop { display: flex; align-items: center; gap: 10px; background: linear-gradient(135deg, rgba(155, 89, 182, 0.12), rgba(52, 152, 219, 0.1)); border: 1px dashed var(--secondary); border-radius: 14px; padding: 10px 14px; margin-top: 4px; font-size: 0.85em; }
.lifecycle-loop .loop-icon { font-size: 1.4em; flex-shrink: 0; }

/* ---------- Geography: country capital badge ---------- */
.country-capital { display: inline-block; font-size: 0.75em; font-weight: 700; padding: 2px 10px; border-radius: 10px; margin-top: 4px; background: rgba(52, 152, 219, 0.15); color: var(--secondary); }
