/* ===== CSS Variables & Reset ===== */
:root {
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8eef4;
    --text-primary: #1a1a2e;
    --text-secondary: #5a6270;
    --border-color: #d0d8e0;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.15);

    /* Bond Colors */
    --ionic-color: #e63946;
    --covalent-color: #2ecc71;
    --polar-color: #f39c12;

    /* Atom Colors */
    --metal-color: #ffa94d;
    --nonmetal-color: #74c0fc;
    --halogen-color: #be4bdb;

    --radius: 12px;
    --transition: all 0.3s ease;
}

[data-theme="dark"] {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252540;
    --text-primary: #f0f4f8;
    --text-secondary: #a0a8b8;
    --border-color: #2a2a45;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: var(--transition);
}

/* ===== App Container ===== */
.app-container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 15px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    margin-bottom: 15px;
    box-shadow: var(--shadow);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--ionic-color), var(--covalent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-controls {
    display: flex;
    gap: 10px;
}

.control-btn {
    width: 42px;
    height: 42px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.control-btn:hover {
    border-color: var(--ionic-color);
    transform: scale(1.05);
}

.control-btn svg {
    width: 20px;
    height: 20px;
    color: var(--text-primary);
}

.moon-icon {
    display: none;
}

[data-theme="dark"] .sun-icon {
    display: none;
}

[data-theme="dark"] .moon-icon {
    display: block;
}

/* Fullscreen toggle */
.compress-icon {
    display: none;
}

.fullscreen-active .expand-icon {
    display: none;
}

.fullscreen-active .compress-icon {
    display: block;
}

/* ===== Main Content ===== */
.main-content {
    display: grid;
    grid-template-columns: minmax(240px, 260px) minmax(0, 1fr) minmax(250px, 280px);
    gap: 15px;
    flex: 1;
}

/* ===== Atoms Palette ===== */
.atoms-palette {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    overflow-y: auto;
}

.atoms-palette h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.category-section {
    margin-bottom: 20px;
}

.category-section h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--border-color);
}

.atoms-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

/* Draggable Atom */
.atom-item {
    width: 100%;
    max-width: 55px;
    aspect-ratio: 1 / 1;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: grab;
    transition: var(--transition);
    position: relative;
    font-weight: 600;
    justify-self: center;
}

.atom-item:active {
    cursor: grabbing;
}

.atom-item:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-hover);
}

.atom-item .symbol {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1;
}

.atom-item .valence {
    font-size: 0.6rem;
    opacity: 0.8;
    margin-top: 2px;
}

.atom-item.metal {
    background: linear-gradient(135deg, var(--metal-color), #ff8c00);
    color: #1a1a2e;
}

.atom-item.nonmetal {
    background: linear-gradient(135deg, var(--nonmetal-color), #339af0);
    color: #1a1a2e;
}

.atom-item.halogen {
    background: linear-gradient(135deg, var(--halogen-color), #9b59b6);
    color: white;
}

/* Examples Section */
.examples-section {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 2px solid var(--border-color);
}

.examples-section h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.examples-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.example-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.example-btn:hover {
    border-color: var(--ionic-color);
    background: var(--bg-primary);
}

.example-btn span {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--text-secondary);
    background: var(--bg-primary);
    padding: 3px 8px;
    border-radius: 10px;
}

/* ===== Workspace ===== */
.workspace-container {
    display: flex;
    flex-direction: column;
}

.workspace {
    flex: 1;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    min-height: 500px;
}

#bondsCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.workspace-atoms {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.workspace-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-secondary);
    pointer-events: none;
}

.workspace-hint p {
    font-size: 1rem;
    opacity: 0.6;
}

.workspace-hint.hidden {
    display: none;
}

/* Atom in workspace */
.workspace-atom {
    position: absolute;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: move;
    transition: box-shadow 0.2s;
    z-index: 10;
}

.workspace-atom:hover {
    z-index: 20;
}

.workspace-atom.selected {
    box-shadow: 0 0 0 4px #fff, 0 0 25px 10px rgba(230, 57, 70, 0.5);
}

.workspace-atom .symbol {
    font-size: 1.4rem;
    font-weight: 700;
}

.workspace-atom .name {
    font-size: 0.6rem;
    margin-top: 2px;
    opacity: 0.9;
}

/* Electron cloud ring */
.workspace-atom::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px dashed rgba(255, 255, 255, 0.3);
    animation: rotate 10s linear infinite;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Valence electrons */
.valence-electron {
    position: absolute;
    width: 10px;
    height: 10px;
    background: linear-gradient(135deg, #a5d8ff, #339af0);
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(51, 154, 240, 0.6);
}

/* ===== Info Panel ===== */
.info-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    overflow-y: auto;
}

.info-panel h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-section {
    margin-bottom: 20px;
}

.info-placeholder {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    background: var(--bg-tertiary);
    border-radius: 10px;
}

/* Molecule Display */
.molecule-display {
    text-align: center;
    margin-bottom: 20px;
    padding: 20px;
    background: var(--bg-tertiary);
    border-radius: 12px;
}

.molecule-formula {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.molecule-name {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Bond Type Display */
.bond-type-display {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    margin-bottom: 15px;
}

.bond-type-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bond-type-icon.ionic {
    background: linear-gradient(135deg, var(--ionic-color), #c0392b);
}

.bond-type-icon.covalent {
    background: linear-gradient(135deg, var(--covalent-color), #27ae60);
}

.bond-type-icon.polar {
    background: linear-gradient(135deg, var(--polar-color), #e67e22);
}

.bond-type-name {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
}

.bond-type-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Property Grid */
.property-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.property-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.prop-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.prop-value {
    font-size: 0.85rem;
    font-weight: 600;
}

/* Electron Transfer Visual */
.electron-transfer {
    padding: 15px;
    background: var(--bg-tertiary);
    border-radius: 12px;
}

.electron-transfer h4 {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
    text-transform: uppercase;
}

.transfer-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 20px 0;
}

.transfer-atom {
    text-align: center;
}

.transfer-atom .symbol {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0 auto 5px;
}

.transfer-atom .charge {
    font-size: 0.9rem;
    font-weight: 600;
}

.transfer-arrow {
    font-size: 1.5rem;
    color: var(--ionic-color);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

/* Legend */
.legend-section {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 2px solid var(--border-color);
}

.legend-section h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
}

.ionic-dot {
    background: var(--ionic-color);
}

.polar-dot {
    background: var(--polar-color);
}

.covalent-dot {
    background: var(--covalent-color);
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: minmax(220px, 240px) minmax(0, 1fr) minmax(230px, 250px);
    }
}

@media (max-width: 949px) {
    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }

    .atoms-palette {
        order: 1;
    }

    .workspace-container {
        order: 2;
        min-height: 400px;
    }

    .info-panel {
        order: 3;
    }

    .atoms-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* ===== Bond Lines ===== */
.bond-line {
    position: absolute;
    pointer-events: none;
    z-index: 5;
}

/* Shared electron pair */
.shared-pair {
    position: absolute;
    width: 20px;
    height: 8px;
    display: flex;
    gap: 4px;
    z-index: 15;
}

.shared-electron {
    width: 8px;
    height: 8px;
    background: linear-gradient(135deg, #a5d8ff, #339af0);
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(51, 154, 240, 0.8);
    animation: electronPulse 1s ease-in-out infinite alternate;
}

@keyframes electronPulse {
    from {
        transform: scale(0.9);
        opacity: 0.7;
    }

    to {
        transform: scale(1.1);
        opacity: 1;
    }
}

/* ===== Delete Button on Atoms ===== */
.workspace-atom .delete-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #e63946;
    border: 2px solid white;
    color: white;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    z-index: 30;
}

.workspace-atom:hover .delete-btn {
    display: flex;
}

.workspace-atom .delete-btn:hover {
    transform: scale(1.2);
    background: #c0392b;
}

/* ===== Bond Explanation ===== */
.bond-explanation {
    margin-top: 15px;
    padding: 15px;
    background: linear-gradient(135deg, rgba(46, 204, 113, 0.1), rgba(52, 152, 219, 0.1));
    border-radius: 12px;
    border-left: 4px solid var(--covalent-color);
}

.bond-explanation h4 {
    font-size: 0.85rem;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.bond-explanation p {
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* ===== Impossible Bond Warning ===== */
.impossible-bond-warning {
    background: linear-gradient(135deg, rgba(231, 76, 60, 0.15), rgba(241, 196, 15, 0.15));
    border: 2px solid #e74c3c;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    margin-bottom: 20px;
    animation: warningPulse 2s ease-in-out infinite;
}

@keyframes warningPulse {

    0%,
    100% {
        border-color: #e74c3c;
    }

    50% {
        border-color: #f39c12;
    }
}

.impossible-bond-warning .warning-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.impossible-bond-warning h4 {
    font-size: 1rem;
    color: #e74c3c;
    margin-bottom: 10px;
}

.impossible-bond-warning p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 15px;
}

.close-warning-btn {
    padding: 8px 20px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.close-warning-btn:hover {
    background: var(--ionic-color);
    border-color: var(--ionic-color);
    color: white;
}
