/* ================================================================
   Chemistry – subject-specific overrides
   Base styles loaded from ../shared/css/subject-base.css
   ================================================================ */

:root {
    --primary: #00bcd4;
    --primary-light: #e0f7fa;
}

/* ---- Chemistry topic tags ---- */
.topic-tag.atom { background: #e3f2fd; color: #1565c0; }
.topic-tag.bond { background: #fff8e1; color: #f57f17; }
.topic-tag.stoi { background: #e0f2f1; color: #00695c; }
.topic-tag.energ { background: #fce4ec; color: #c2185b; }
.topic-tag.kin { background: #fff3e0; color: #e65100; }
.topic-tag.equil { background: #e8f5e9; color: #2e7d32; }
.topic-tag.acid { background: #f3e5f5; color: #6a1b9a; }
.topic-tag.org { background: #e1f5fe; color: #01579b; }
.topic-tag.states { background: #ede7f6; color: #4527a0; }
.topic-tag.react { background: #fff9c4; color: #f9a825; }
.topic-tag.metal { background: #efebe9; color: #4e342e; }
.topic-tag.electro { background: #e8eaf6; color: #1a237e; }
.topic-tag.sep { background: #f1f8e9; color: #33691e; }
.topic-tag.env { background: #dcedc8; color: #1b5e20; }
.topic-tag.ctest { background: #fbe9e7; color: #bf360c; }

/* ---- Calculator FAB shadow ---- */
.calc-btn { box-shadow: 0 4px 16px rgba(0,188,212,0.4); }
.calc-btn:hover { background: #0097a7; }

/* ---- Periodic Table floating ---- */
.pt-btn {
    position: fixed; bottom: 24px; right: 148px; z-index: 1000;
    width: 48px; height: 48px; border-radius: 50%;
    background: #5c6bc0; color: #fff; border: none;
    box-shadow: 0 4px 16px rgba(92,107,192,0.4);
    cursor: pointer; font-size: 1.4rem; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
}
.pt-btn:hover { transform: scale(1.1); background: #3f51b5; }
.pt-btn.active { background: var(--error); }
.pt-modal {
    display: none; position: fixed; bottom: 82px; right: 24px; z-index: 1001;
    width: min(95vw, 720px); background: var(--card);
    border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    overflow: hidden; animation: slideUp 0.2s ease;
}
.pt-modal.show { display: block; }
.pt-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: #5c6bc0; color: #fff; font-weight: 700; font-size: 0.9rem; }
.pt-close { background: none; border: none; color: #fff; font-size: 1.4rem; cursor: pointer; line-height: 1; }
.pt-container { padding: 10px; overflow-x: auto; }
.pt-info { min-height: 36px; display: flex; align-items: center; gap: 8px; padding: 4px 8px; margin-bottom: 6px; font-size: 0.82rem; flex-wrap: wrap; }
.pt-info-hint { color: var(--text-light); font-style: italic; font-size: 0.78rem; }
.pt-info-z { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; font-weight: 700; font-size: 0.8rem; }
.pt-info-sym { font-size: 1.3rem; font-weight: 800; }
.pt-info-name { font-weight: 600; }
.pt-info-mass { color: var(--text-light); font-size: 0.8rem; }
.pt-info-cat { padding: 2px 8px; border-radius: 10px; font-size: 0.72rem; font-weight: 600; }
.pt-grid {
    display: grid; grid-template-columns: repeat(18, 1fr); grid-template-rows: repeat(10, auto);
    gap: 1px; font-size: 0.6rem;
}
.pt-cell {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 2px 1px; border-radius: 3px; cursor: pointer; min-height: 32px;
    transition: transform 0.15s, box-shadow 0.15s; border: 1px solid rgba(0,0,0,0.08);
}
.pt-cell:hover { transform: scale(1.4); z-index: 10; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.pt-marker { cursor: default; font-size: 0.55rem; opacity: 0.7; }
.pt-marker:hover { transform: none; box-shadow: none; }
.pt-z { font-size: 0.5rem; line-height: 1; opacity: 0.7; }
.pt-sym { font-size: 0.72rem; font-weight: 700; line-height: 1.2; }
/* Category colours */
.pt-cat-alkali { background: #ff6b6b; color: #fff; }
.pt-cat-alkaline { background: #ffa94d; color: #fff; }
.pt-cat-transition { background: #ffd43b; color: #333; }
.pt-cat-post-trans { background: #69db7c; color: #333; }
.pt-cat-metalloid { background: #38d9a9; color: #333; }
.pt-cat-nonmetal { background: #4dabf7; color: #fff; }
.pt-cat-halogen { background: #9775fa; color: #fff; }
.pt-cat-noble { background: #da77f2; color: #fff; }
.pt-cat-lanthanide { background: #f783ac; color: #fff; }
.pt-cat-actinide { background: #e599f7; color: #fff; }
/* Legend */
.pt-legend { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; justify-content: center; }
.pt-legend-item { padding: 2px 8px; border-radius: 8px; font-size: 0.65rem; font-weight: 600; }
/* Gap row between main table and lanthanides/actinides */
.pt-grid > .pt-cell[style*="grid-row: 9"] { margin-top: 6px; }
.pt-grid > .pt-cell[style*="grid-row: 10"] { margin-top: 1px; }
@media (max-width: 480px) {
    .pt-btn { bottom: 16px; right: 128px; width: 42px; height: 42px; font-size: 1.1rem; }
    .pt-modal { width: calc(100vw - 16px); right: 8px; bottom: 68px; }
    .pt-grid { font-size: 0.45rem; }
    .pt-cell { min-height: 24px; padding: 1px; }
    .pt-z { font-size: 0.38rem; }
    .pt-sym { font-size: 0.55rem; }
}

/* ---- TTS Reader Bar ---- */
.tts-bar { display: flex; align-items: center; gap: 6px; margin-bottom: 16px; padding: 8px 12px; background: var(--bg-subtle, #f5f6fa); border-radius: 10px; border: 1px solid var(--border); }
.tts-btn { width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--primary); color: #fff; font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: transform 0.15s, opacity 0.2s; flex-shrink: 0; }
.tts-btn:hover { transform: scale(1.1); }
.tts-btn:active { transform: scale(0.95); }
.tts-speed { background: var(--primary-light, #eef0ff); color: var(--primary); font-weight: 700; font-size: 0.7rem; width: auto; padding: 0 10px; border-radius: 8px; }
.tts-voice-select { border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; font-size: 0.75rem; background: var(--card); color: var(--text); max-width: 140px; cursor: pointer; }
.tts-label { font-size: 0.78rem; color: var(--text-light); margin-left: 4px; }
body.dark-mode .tts-bar { background: rgba(255,255,255,0.06); }
.tts-word { cursor: default; border-radius: 3px; transition: background 0.2s, color 0.2s; }
.tts-word-ready { background: var(--primary-light, #eef0ff); color: var(--primary); cursor: pointer; }
body.dark-mode .tts-word-ready { background: rgba(67,97,238,0.2); }

/* ---- Loading screen ---- */
.loading-screen {
    background: linear-gradient(135deg, #004d40 0%, #00695c 40%, #00838f 70%, #006064 100%);
}
.loading-flask {
    animation: flask-bubble 2s ease-in-out infinite;
}
@keyframes flask-bubble {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}
.loading-bubble {
    animation: bubble-rise 2s ease-in-out infinite;
    transform-origin: center;
}
@keyframes bubble-rise {
    0% { opacity: 0; transform: translateY(0); }
    50% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-20px); }
}
.loading-bar {
    background: linear-gradient(90deg, #00bcd4, #26c6da, #00e5ff);
    background-size: 200% 100%;
}

/* ---- Dark Mode ---- */
body.dark-mode {
    --primary-light: rgba(0,188,212,0.15);
}
body.dark-mode .lb-table th { background: rgba(0,188,212,0.15); }

/* ---- Paper Generator (chemistry-coloured) ---- */
.topic-tag.paper { background: linear-gradient(135deg, #00838f, #26c6da); color: #fff; }
.pg-context-box {
    background: #e0f7fa; border-left: 4px solid #00838f;
}
.pg-context-title { color: #00838f; }
.pg-topic-label {
    background: #00838f; color: #fff;
}
.pg-grade-circle {
    background: linear-gradient(135deg, #00838f, #26c6da);
    box-shadow: 0 4px 20px rgba(0,131,143,0.3);
}
.pg-q-topic {
    background: #00838f; color: #fff;
}
body.dark-mode .pg-context-box { background: rgba(0,131,143,0.1); border-left-color: #26c6da; }
body.dark-mode .pg-context-title { color: #26c6da; }
.pg-working-marked { background: rgba(0,188,212,0.06); border: 2px solid rgba(0,188,212,0.25); }
body.dark-mode .pg-working-marked { background: rgba(0,188,212,0.08); border-color: rgba(0,188,212,0.3); }

/* ---- Formula Booklet ---- */
.formula-section { background: var(--card-bg, rgba(255,255,255,0.92)); border-radius: 12px; padding: 16px 20px; margin-bottom: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.formula-section h3 { color: var(--primary); border-bottom: 2px solid var(--primary); padding-bottom: 4px; margin-bottom: 8px; margin-top: 0; }
.formula-table { width: 100%; border-collapse: collapse; }
.formula-table td, .formula-table th { padding: 8px 12px; border-bottom: 1px solid rgba(128,128,128,0.15); }
.formula-table td:first-child, .formula-table th:first-child { width: 40%; font-weight: 500; }
.formula-table td:last-child, .formula-table th:last-child { text-align: center; }
.formula-table tr:last-child td { border-bottom: none; }
.formula-table tr:hover { background: rgba(128,128,128,0.05); }
/* Formula FAB */
.formula-fab { position: fixed; bottom: 24px; right: 24px; width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: #fff; border: none; font-size: 1.4rem; cursor: pointer; z-index: 999; box-shadow: 0 4px 14px rgba(0,0,0,0.3); display: none; align-items: center; justify-content: center; transition: transform 0.2s; }
.formula-fab:hover { transform: scale(1.1); }
/* Formula slide-out panel */
.formula-panel-backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.formula-panel-backdrop.open { opacity: 1; pointer-events: auto; }
.formula-panel { position: fixed; top: 0; right: 0; width: 420px; max-width: 90vw; height: 100vh; background: var(--bg, #fff); z-index: 1001; overflow-y: auto; padding: 20px; box-shadow: -4px 0 24px rgba(0,0,0,0.2); transform: translateX(100%); transition: transform 0.3s ease; }
.formula-panel.open { transform: translateX(0); }
.formula-panel .formula-section { box-shadow: none; background: rgba(128,128,128,0.06); }
.formula-panel-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text); padding: 4px 10px; border-radius: 8px; margin-bottom: 12px; }
.formula-panel-close:hover { background: rgba(128,128,128,0.1); }

/* ---- Molecule Builder ---- */
.builder-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.builder-toolbar .btn-sm { font-size: 0.8rem; padding: 4px 12px; border-radius: 8px; border: 1.5px solid var(--primary); background: var(--card); color: var(--text); cursor: pointer; }
.builder-toolbar .btn-sm:hover { background: var(--primary-light); }
.builder-chain { display: flex; gap: 4px; flex-wrap: wrap; min-height: 48px; padding: 12px; border: 2px dashed var(--primary); border-radius: 12px; margin-bottom: 12px; align-items: center; }
.builder-placeholder { color: var(--text-light); font-style: italic; font-size: 0.9rem; }
.builder-group { display: inline-flex; align-items: center; padding: 8px 14px; border-radius: 8px; background: var(--primary-light); color: var(--text); font-weight: 600; font-size: 0.95rem; cursor: pointer; transition: background 0.2s, text-decoration 0.2s; }
.builder-group:hover { background: var(--error-light); text-decoration: line-through; }
.builder-bond { color: var(--text-light); font-weight: bold; line-height: 1; }
.builder-palette-label { font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; color: var(--text-light); }
.builder-palette { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 16px; }
.builder-palette-btn { padding: 10px 16px; border-radius: 10px; border: 2px solid var(--primary); background: var(--card); color: var(--text); font-weight: 600; font-size: 0.9rem; cursor: pointer; transition: background 0.2s, color 0.2s; }
.builder-palette-btn:hover { background: var(--primary); color: #fff; }
.builder-preview { text-align: center; margin: 8px 0; }
.builder-preview canvas { border-radius: 8px; background: #fafafa; border: 1px solid var(--border); max-width: 100%; height: auto; }
.smiles-display { text-align: center; margin: 16px 0; }
.smiles-display canvas { border: 1px solid var(--border); border-radius: 12px; background: #fff; max-width: 100%; height: auto; }

/* Dark mode overrides */
body.dark-mode .builder-chain { border-color: var(--primary); }
body.dark-mode .builder-group { background: rgba(0,188,212,0.15); }
body.dark-mode .builder-group:hover { background: rgba(239,71,111,0.2); }
body.dark-mode .builder-palette-btn { background: #1a1a2e; border-color: var(--primary); color: #e0e0e0; }
body.dark-mode .builder-palette-btn:hover { background: var(--primary); color: #fff; }
body.dark-mode .builder-toolbar .btn-sm { background: #1a1a2e; color: #e0e0e0; }
body.dark-mode .builder-preview canvas { background: #1e1e2e; border-color: #333; }
body.dark-mode .smiles-display canvas { background: #1e1e2e; border-color: #333; }

/* ---- Chemistry Glossary Tooltips ---- */
.chem-term {
    position: relative;
    border-bottom: 1.5px dotted var(--primary);
    cursor: help;
    color: inherit;
}
.chem-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a2e;
    color: #f0f0f0;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.82rem;
    font-weight: 400;
    white-space: normal;
    min-width: 200px;
    max-width: 300px;
    text-align: center;
    z-index: 100;
    pointer-events: none;
    line-height: 1.45;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.chem-term:hover .chem-tooltip,
.chem-term:focus .chem-tooltip {
    display: block;
}
.chem-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1a1a2e;
}
/* Flip tooltip below if near top of viewport */
.question-text:first-child .chem-tooltip {
    bottom: auto;
    top: calc(100% + 8px);
}
.question-text:first-child .chem-tooltip::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: #1a1a2e;
}
@media (max-width: 480px) {
    .chem-tooltip { min-width: 160px; max-width: 250px; font-size: 0.78rem; }
}

/* ---- Molecule Lab FAB + Dialog ---- */
.mol-lab-fab {
    position: fixed; bottom: 20px; right: 20px; z-index: 100;
    width: 52px; height: 52px; border-radius: 50%;
    background: var(--primary); color: #fff; border: none;
    box-shadow: 0 4px 16px rgba(0,188,212,0.4);
    cursor: pointer; font-size: 1.4rem; transition: all 0.2s;
    display: none; align-items: center; justify-content: center;
}
.mol-lab-fab:hover { transform: scale(1.1); background: #0097a7; }
.mol-lab-fab.show { display: flex; }
.mol-lab-overlay {
    display: none; position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    justify-content: center; align-items: center;
}
.mol-lab-overlay.show { display: flex; }
.mol-lab-dialog {
    background: var(--card); border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.25);
    padding: 24px; max-width: 480px; width: 92%;
    max-height: 85vh; overflow-y: auto;
    animation: slideIn 0.3s ease;
}
.mol-lab-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.mol-lab-header h3 { margin: 0; font-size: 1.15rem; color: var(--primary); }
.mol-lab-close { background: none; border: none; font-size: 1.6rem; color: var(--text-light); cursor: pointer; padding: 4px; }
.mol-lab-close:hover { color: var(--error); }
.mol-lab-formula {
    text-align: center; font-size: 1.3rem; font-weight: 700;
    color: var(--text); margin: 12px 0 8px; min-height: 1.5em;
}
.mol-lab-formula sub { font-size: 0.75em; vertical-align: baseline; position: relative; top: 0.3em; }
.mol-lab-presets-label { font-weight: 600; font-size: 0.85rem; color: var(--text-light); margin-bottom: 6px; }
.mol-lab-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.mol-lab-preset-btn {
    padding: 6px 14px; border-radius: 20px;
    border: 1.5px solid var(--primary); background: var(--card);
    color: var(--text); font-size: 0.82rem; font-weight: 600;
    cursor: pointer; transition: all 0.15s;
}
.mol-lab-preset-btn:hover { background: var(--primary); color: #fff; }

/* Dark mode */
body.dark-mode .mol-lab-dialog { background: var(--card); }
body.dark-mode .mol-lab-preset-btn { background: #1a1a2e; color: #e0e0e0; }
body.dark-mode .mol-lab-preset-btn:hover { background: var(--primary); color: #fff; }

/* Glassmorphism */
body.has-bg .mol-lab-dialog { background: rgba(255,255,255,0.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
body.has-bg.dark-mode .mol-lab-dialog { background: rgba(22,33,62,0.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }

/* Mobile */
@media (max-width: 480px) {
    .mol-lab-fab { bottom: 16px; right: 16px; width: 46px; height: 46px; font-size: 1.2rem; }
    .mol-lab-dialog { padding: 18px; max-width: calc(100vw - 24px); }
}

/* ---- Structural Formula SVG ---- */
.struct-formula { border-radius: 8px; overflow: visible; }
body.dark-mode .struct-formula rect:first-child { fill: #1e1e2e; stroke: #333; }
