/* =========================================================
   AULAQUEST LAB · SIMULADOR DE ISÓTOPOS
   CSS modular · mobile first
   ========================================================= */

*, *::before, *::after { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; overflow-x: hidden; }
body {
    font-family: 'Inter', sans-serif;
    background-color: #0f172a;
    color: #e2e8f0;
}

/* ---------- Layout principal ---------- */
.app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* ---------- Canvas ---------- */
#canvas-container {
    width: 100%;
    height: 460px;
    min-height: 460px;
    flex: 0 0 auto;
    position: relative;
    overflow: hidden;
    background-color: #0f172a;
    background-image:
        linear-gradient(rgba(56, 189, 248, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(56, 189, 248, 0.07) 1px, transparent 1px);
    background-size: 40px 40px;
    box-shadow: inset 0 0 60px rgba(0,0,0,0.5);
}
#canvas-container > canvas { display: block; max-width: 100%; touch-action: none; }

/* ---------- Cabecera sobre canvas ---------- */
.canvas-overlay {
    position: absolute;
    top: .65rem;
    left: .65rem;
    right: .65rem;
    width: auto;
    max-width: calc(100% - 1.3rem);
    z-index: 20;
    pointer-events: none;
}
#aq-brand-text {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    max-width: calc(100% - 115px);
    margin: 0;
    font-size: 1rem !important;
    line-height: 1.1;
}
#aq-brand-text + p {
    max-width: calc(100% - 115px);
    margin-top: .15rem;
    font-size: .67rem !important;
    line-height: 1.25;
}
#aq-sim-title-text { display: none; }

/* Controles Z/N: compactos a la derecha en mobile/tablet */
.canvas-overlay > .mt-4.flex.gap-3 {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    width: 104px;
    max-width: 104px;
    margin: 0 !important;
    gap: .3rem !important;
    pointer-events: auto;
}
.canvas-overlay > .mt-4.flex.gap-3 > div {
    width: 100%;
    padding: .28rem .38rem !important;
    gap: .18rem !important;
    border-radius: .5rem !important;
    background: rgba(30, 41, 59, .9) !important;
    box-shadow: 0 3px 10px rgba(0,0,0,.16);
}
.canvas-overlay > .mt-4.flex.gap-3 > div > div:first-child {
    font-size: .45rem !important;
    line-height: 1;
    white-space: nowrap;
    letter-spacing: .05em;
}
.canvas-overlay > .mt-4.flex.gap-3 > div > .flex { justify-content: center; gap: .22rem !important; }
.canvas-overlay > .mt-4.flex.gap-3 button {
    width: 1.7rem !important;
    min-width: 1.7rem !important;
    height: 1.55rem !important;
    padding: 0 !important;
    font-size: .9rem !important;
    line-height: 1 !important;
    border-radius: .35rem !important;
}
.canvas-overlay > .mt-4.inline-flex {
    margin-top: .55rem !important;
    padding: .28rem .7rem !important;
    gap: .4rem !important;
}
.canvas-overlay > .mt-4.inline-flex span { font-size: .72rem !important; }
#status-dot { width: .65rem !important; height: .65rem !important; }

/* Matter labels */
.bucket-label {
    position: absolute;
    top: 180px;
    width: 70px;
    font-size: .6rem;
    font-weight: 700;
    color: #64748b;
    pointer-events: none;
    text-align: center;
}
#label-protons { left: 15px; }
#label-neutrons { left: 95px; }

#btn-toggle-tools {
    font-size: .68rem !important;
    padding: .55rem .95rem !important;
    border-radius: 999px !important;
    backdrop-filter: blur(8px);
    box-shadow: 0 5px 18px rgba(0,0,0,.22);
}

/* ---------- Side panel ---------- */
#side-panel {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    height: auto;
    padding: .9rem .45rem 3rem;
    overflow: visible;
    overflow-x: hidden;
    background-color: #1e293b;
    border-top: 1px solid #334155;
}
#side-panel::-webkit-scrollbar { width: 7px; }
#side-panel::-webkit-scrollbar-track { background: #0f172a; }
#side-panel::-webkit-scrollbar-thumb { background: #475569; border-radius: 10px; }

.glass-card {
    background: rgba(30,41,59,.62);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(71,85,105,.75);
    border-radius: .7rem;
    padding: .85rem;
    margin-bottom: .75rem;
    box-shadow: 0 4px 14px rgba(2,6,23,.08);
}

.control-btn { transition: transform .15s ease, background-color .15s ease, border-color .15s ease; }
.control-btn:active { transform: scale(.94); }

/* Perfil superior */
#side-panel > .flex.items-center.p-2 { margin-bottom: .7rem !important; padding: .55rem .65rem !important; border-radius: .65rem !important; }
#side-panel > .flex.items-center.p-2 img { width: 1.8rem !important; height: 1.8rem !important; }
#side-panel > .flex.items-center.p-2 a { font-size: .76rem !important; }
#side-panel > .flex.items-center.p-2 span { font-size: .5rem !important; }

/* Guía / modo claro / reset */
#side-panel > .flex.gap-2.mb-4 { margin-bottom: .75rem !important; gap: .4rem !important; }
#btn-teoria {
    min-height: 42px !important;
    padding: .55rem .75rem !important;
    font-size: .72rem !important;
    border-radius: .65rem !important;
    box-shadow: 0 3px 10px rgba(2,132,199,.08) !important;
}
#btn-teoria svg { width: 1rem !important; height: 1rem !important; }
#btn-modo-claro, #btn-reiniciar {
    width: 42px !important;
    min-width: 42px !important;
    height: 42px !important;
    border-radius: .65rem !important;
}
#btn-modo-claro svg, #btn-reiniciar svg { width: 1rem !important; height: 1rem !important; }

/* ---------- Tabla periódica ---------- */
#panel-tabla-mini {
    width: 100%;
    max-width: 100%;
    padding-left: .5rem;
    padding-right: .5rem;
    overflow: hidden;
}
#panel-tabla-mini h2 { margin-bottom: .45rem !important; font-size: .65rem !important; letter-spacing: .05em !important; }
#mini-periodic-table {
    display: grid;
    width: 100%;
    max-width: 100%;
    grid-template-columns: repeat(18, minmax(0,1fr));
    gap: 1px;
    margin-bottom: .3rem;
}
.pt-cell {
    aspect-ratio: 1;
    width: 100%;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(.38rem, 2vw, .52rem);
    font-weight: 700;
    border-radius: 2px;
    cursor: pointer;
    color: #0f172a;
    transition: transform .12s ease, box-shadow .12s ease;
}
.pt-cell:hover { transform: scale(1.1); z-index: 10; }
.pt-cell.selected { box-shadow: 0 0 0 2px #fff; transform: scale(1.1); z-index: 10; }
.cat-reactive-nonmetal { background-color: #7dd3fc; }
.cat-noble-gas { background-color: #c4b5fd; }
.cat-alkali-metal { background-color: #fca5a5; }
.cat-alkaline-earth-metal { background-color: #fdba74; }
.cat-metalloid { background-color: #6ee7b7; }
.cat-post-transition-metal { background-color: #93c5fd; }
.cat-transition-metal { background-color: #fef08a; }
.cat-lanthanide { background-color: #fcd34d; }
.cat-actinide { background-color: #f472b6; }

/* ---------- Elemento actual ---------- */
#panel-tabla-mini + .glass-card { padding: .8rem; }
#panel-tabla-mini + .glass-card > .flex.items-center.justify-between { margin-bottom: .7rem !important; padding-bottom: .65rem !important; }
#panel-tabla-mini + .glass-card .w-16.h-16 { width: 3.2rem !important; height: 3.2rem !important; border-radius: .6rem !important; }
#display-symbol { font-size: 1.5rem !important; }
#display-atomic-number, #display-mass-number { font-size: .58rem !important; }
#data-element-title { font-size: 1rem !important; line-height: 1.15 !important; }
#data-element-title + p { margin-top: .1rem; font-size: .67rem !important; }
#panel-tabla-mini + .glass-card .flex.flex-col.items-center.relative > span { font-size: .6rem !important; }
#toggle-model { width: 1.8rem !important; height: 1.8rem !important; }
#toggle-model svg { width: .95rem !important; height: .95rem !important; }
#panel-tabla-mini + .glass-card > .flex.items-center.justify-around { padding: .6rem !important; }
#big-box-z, #big-box-n { padding-left: 1rem !important; padding-right: 1rem !important; }
#big-box-z > div:first-child, #big-box-n > div:first-child { margin-bottom: .15rem !important; font-size: .6rem !important; }
#data-atomic-number-display, #control-neutron-number { font-size: 1.25rem !important; }

/* ---------- Panels ---------- */
#panel-propiedades, #panel-registro-nuclear { padding: .8rem; }
#panel-propiedades h3 { margin-bottom: .65rem !important; padding-bottom: .45rem !important; font-size: .75rem !important; }
#panel-propiedades .grid { gap: .55rem .8rem !important; font-size: .72rem !important; }
#data-electron-config { font-size: .65rem !important; }
#panel-registro-nuclear h3 { font-size: .7rem !important; }

@property --p { syntax: '<number>'; inherits: true; initial-value: 0; }
.pie {
    transition: --p .5s;
    background: radial-gradient(farthest-side,#1e293b 79%,transparent 80% 100%,#1e293b 100%), conic-gradient(#10b981 calc(var(--p) * 1%),#334155 0);
    width: 52px;
    height: 52px;
}
#panel-abundancia { padding: .75rem !important; }
#panel-abundancia h3 { margin-bottom: .4rem !important; font-size: .6rem !important; }
#abundance-text { font-size: 1.05rem !important; }
#panel-aplicacion { padding: .8rem !important; border-radius: .7rem !important; }
#panel-aplicacion h3 { font-size: .72rem !important; }
#fun-fact-text { font-size: .72rem !important; line-height: 1.45 !important; }

/* ---------- Herramientas avanzadas ---------- */
#advanced-tools-hud {
    width: 100%;
    background: rgba(15,23,42,.97);
    padding: .85rem;
    display: none;
    position: relative;
    border-bottom: 1px solid #334155;
    z-index: 40;
}
.tool-tab {
    flex: 1;
    text-align: center;
    font-size: .68rem;
    font-weight: 700;
    padding: .5rem .2rem;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    color: #64748b;
    transition: color .2s ease, border-color .2s ease;
}
.tool-tab.active { color: #38bdf8; border-bottom-color: #38bdf8; }
#valley-canvas {
    width: 100%;
    height: 200px;
    background-color: #020617;
    border-radius: .5rem;
    border: 1px solid #1e293b;
    margin-top: .75rem;
}
#tool-spectro-content .relative { height: 200px; }

/* ---------- Modo claro ---------- */
#canvas-container.modo-claro {
    background-color: #f8fafc;
    background-image:
        linear-gradient(rgba(15,23,42,.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(15,23,42,.05) 1px, transparent 1px);
    box-shadow: inset 0 0 60px rgba(0,0,0,.05);
}
#canvas-container.modo-claro h1.text-white { color: #0f172a !important; }
#canvas-container.modo-claro p.text-slate-400 { color: #475569 !important; }

/* ---------- Tablet ---------- */
@media (min-width: 640px) and (max-width: 1023px) {
    #canvas-container { height: 520px; min-height: 520px; }
    .canvas-overlay { top: .8rem; left: .9rem; right: .9rem; max-width: calc(100% - 1.8rem); }
    #aq-brand-text { font-size: 1.1rem !important; }
    #aq-brand-text + p { font-size: .72rem !important; }
    .canvas-overlay > .mt-4.flex.gap-3 { width: 112px; max-width: 112px; }
    #side-panel { padding: 1rem .9rem 3rem; }
    .glass-card { padding: .95rem; }
    #panel-tabla-mini { padding-left: .7rem; padding-right: .7rem; }
    .pt-cell { font-size: .58rem; }
}

/* ---------- Escritorio ---------- */
@media (min-width: 1024px) {
    .app-container { flex-direction: row; height: 100vh; min-height: 0; overflow: hidden; }
    #canvas-container { flex: 1 1 auto; height: 100%; min-height: 0; }
    .canvas-overlay { top: 1rem; left: 1rem; right: auto; width: auto; max-width: none; }
    #aq-brand-text { max-width: none; font-size: 1.35rem !important; }
    #aq-brand-text + p { max-width: 340px; margin-top: .15rem; font-size: .75rem !important; }
    #aq-sim-title-text { display: inline; }
    .canvas-overlay > .mt-4.flex.gap-3 {
        position: static;
        display: flex;
        flex-direction: row;
        width: auto;
        max-width: none;
        margin-top: .8rem !important;
        gap: .5rem !important;
    }
    .canvas-overlay > .mt-4.flex.gap-3 > div { width: auto; padding: .38rem .5rem !important; }
    .canvas-overlay > .mt-4.flex.gap-3 > div > div:first-child { font-size: .48rem !important; }
    .canvas-overlay > .mt-4.flex.gap-3 button { width: 1.75rem !important; min-width: 1.75rem !important; height: 1.7rem !important; }
    #side-panel {
        width: 450px;
        max-width: 450px;
        height: 100vh;
        padding: 1rem 1rem 2rem;
        overflow-x: hidden;
        overflow-y: auto;
        border-top: none;
        border-left: 1px solid #334155;
    }
    .glass-card { margin-bottom: .7rem; padding: .8rem; }
    #side-panel > .flex.items-center.p-2 { margin-bottom: .65rem !important; }
    #side-panel > .flex.gap-2.mb-4 { margin-bottom: .7rem !important; }
    #btn-teoria { min-height: 40px !important; height: 40px !important; font-size: .7rem !important; }
    #btn-modo-claro, #btn-reiniciar { width: 40px !important; min-width: 40px !important; height: 40px !important; }
    #panel-tabla-mini { padding-left: .75rem; padding-right: .75rem; }
    #mini-periodic-table { gap: 2px; }
    .pt-cell { font-size: .55rem; }
    #panel-tabla-mini + .glass-card { padding: .75rem; }
    #panel-tabla-mini + .glass-card .w-16.h-16 { width: 3rem !important; height: 3rem !important; }
    #data-element-title { font-size: .95rem !important; }
    #data-atomic-number-display, #control-neutron-number { font-size: 1.15rem !important; }
    #tool-spectro-content .relative { height: 180px; }
    #advanced-tools-hud {
        position: absolute;
        right: calc(450px + 1rem);
        bottom: 1rem;
        width: 340px;
        border: 1px solid #334155;
        border-radius: .75rem;
        box-shadow: 0 10px 25px -5px rgba(0,0,0,.5);
    }
}

/* ---------- Mobile pequeño ---------- */
@media (max-width: 380px) {
    #canvas-container { height: 450px; min-height: 450px; }
    .canvas-overlay { left: .5rem; right: .5rem; max-width: calc(100% - 1rem); }
    #aq-brand-text { max-width: calc(100% - 108px); font-size: .92rem !important; }
    #aq-brand-text + p { max-width: calc(100% - 108px); font-size: .62rem !important; }
    .canvas-overlay > .mt-4.flex.gap-3 { width: 98px; max-width: 98px; }
    #side-panel { padding-left: .35rem; padding-right: .35rem; }
    #panel-tabla-mini { padding-left: .4rem; padding-right: .4rem; }
    .pt-cell { font-size: .38rem; }
}

#footer-original { margin-top: 1.4rem !important; padding-top: 1rem !important; }
#aq-footer { margin-top: .75rem !important; }


/* =========================================================
   DIDÁCTICA NUCLEAR · NOTACIÓN, N/Z Y ANÁLISIS
   ========================================================= */

#nuclear-notation {
    background: linear-gradient(145deg, rgba(30,41,59,.95), rgba(15,23,42,.95));
}

#nuclear-notation::after {
    content: "A / Z";
    position: absolute;
    right: .3rem;
    bottom: .18rem;
    font-size: .38rem;
    font-weight: 800;
    letter-spacing: .05em;
    color: #475569;
}

#analysis-tabs {
    scrollbar-width: none;
}
#analysis-tabs::-webkit-scrollbar { display: none; }

#analysis-tabs .tool-tab {
    min-width: max-content;
    padding-left: .55rem;
    padding-right: .55rem;
}

#tool-energy-content {
    min-height: 200px;
}

@media (max-width: 639px) {
    #analysis-tabs {
        justify-content: flex-start;
    }
    #analysis-tabs .tool-tab {
        flex: 0 0 auto;
        font-size: .62rem;
    }
}
