/* --- Nuclear decay simulation page styles (loaded after simulation_styles.css) --- */

.nuclear-sim {
    --nuc-btn: 40px;                                    /* tray button height */
    --nuc-side-open: 94px;                              /* the tray column beside the canvas... */
    --nuc-side-closed: 30px;                            /* ...and folded to a strip */
    --nuc-side-w: var(--nuc-side-open);
    --nuc-side-gap: 8px;
    /* decay-mode colours (as on the chart) */
    --nuc-stable: #24272c;
    --nuc-beta-minus: #2f8fd6;
    --nuc-beta-plus: #e7862f;
    --nuc-alpha: #e2b711;
    --nuc-fission: #2fae64;
    --nuc-gamma: #c2459f;
    --nuc-proton-emitter: #de3a4d;
    --nuc-neutron-emitter: #8c63d6;
}

html.dark-mode .nuclear-sim {
    --nuc-stable: #eceff3;
    --nuc-beta-minus: #4ea7f0;
    --nuc-beta-plus: #f39c4a;
    --nuc-alpha: #f2d14f;
    --nuc-fission: #5fcf8c;
    --nuc-gamma: #e07ad0;
    --nuc-proton-emitter: #ef5a6a;
    --nuc-neutron-emitter: #a985ea;
}

.nuclear-sim.nuc-tray-collapsed {
    --nuc-side-w: var(--nuc-side-closed);
}

@media (pointer: coarse) {
    .nuclear-sim {
        --nuc-btn: 44px;
    }
}

/* ---------- The tray: particles and ready-made nuclei ----------
   Portrait / narrow: one row under the canvas that scrolls sideways. Landscape: one column beside the
   canvas that scrolls up and down (see the media query below). Either folds away with its toggle. */
.nuc-toolbar {
    display: flex;
    align-items: stretch;
    gap: 4px;
    margin-top: 0.5em;
    padding: 4px;
    box-sizing: border-box;
    background-color: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--sim-radius, 6px);
    font-size: 0.85em;
    line-height: 1.3;
}

.nuc-toolbar .nuc-tray-toggle {
    -webkit-appearance: none;
    appearance: none;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6em;
    width: 30px;
    height: auto;
    min-height: 30px;
    margin: 0;
    padding: 0;
    overflow: visible;
    font-family: inherit;
    font-size: 0.75em;
    font-weight: 900;
    line-height: 1;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--color-text) !important;
    background-color: transparent;
    border: 0;
    border-radius: 4px;
    box-shadow: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.nuc-toolbar .nuc-tray-toggle .icon {
    font-size: 1.15em;
    opacity: 0.8;
    transform: rotate(-90deg);                          /* a row: the chevron points down, to fold it away */
    transition: transform 0.2s ease;
}

.nuc-tray-label {
    display: none;
    opacity: 0.75;
}

@media (hover: hover) {
    .nuc-toolbar .nuc-tray-toggle:hover {
        color: var(--color-accent) !important;
        background-color: var(--color-bg-button-active-overlay);
        box-shadow: none;
    }
}

.nuc-toolbar .nuc-tray-toggle:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}

.nuc-palette {
    display: flex;
    flex: 1 1 auto;
    gap: 4px;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

.nuc-toolbar .nuc-item {
    -webkit-appearance: none;
    appearance: none;
    position: relative;
    flex: 0 0 auto;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 52px;
    height: 54px;
    margin: 0;
    padding: 0 3px;
    box-sizing: border-box;
    overflow: visible;
    font-family: inherit;
    font-size: 1em;
    font-weight: 700;
    letter-spacing: 0;
    line-height: 1;
    text-transform: none;
    white-space: nowrap;
    color: var(--color-text) !important;
    background-color: var(--color-bg);
    border: 0;
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px var(--color-border);
    cursor: grab;
    touch-action: pan-x;                /* a sideways swipe scrolls the row; a drag up goes to the canvas */
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
    .nuc-toolbar .nuc-item:hover {
        box-shadow: inset 0 0 0 1px var(--color-accent);
    }
}

.nuc-toolbar .nuc-item:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}

.nuc-toolbar .nuc-item.is-dragging {
    box-shadow: inset 0 0 0 2px var(--color-accent);
    background-color: var(--color-bg-button-active-overlay);
    cursor: grabbing;
}

/* The nucleus itself, drawn by the simulation (bigger for heavier nuclei) */
.nuc-icon-box {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.nuc-icon {
    display: block;
    flex: 0 0 auto;
    pointer-events: none;
}

.nuc-item-text sup {
    position: relative;
    top: -0.45em;
    margin-right: 0.5px;
    font-size: 0.66em;
    line-height: 0;
    vertical-align: baseline;
}

/* A small dot in the corner: how the nuclide decays (the chart's colours) */
.nuc-mode {
    position: absolute;
    right: 4px;
    top: 4px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.nuc-mode-stable { background-color: var(--nuc-stable); }
.nuc-mode-b { background-color: var(--nuc-beta-minus); }
.nuc-mode-e { background-color: var(--nuc-beta-plus); }
.nuc-mode-a { background-color: var(--nuc-alpha); }
.nuc-mode-f { background-color: var(--nuc-fission); }
.nuc-mode-i { background-color: var(--nuc-gamma); }
.nuc-mode-p { background-color: var(--nuc-proton-emitter); }
.nuc-mode-n { background-color: var(--nuc-neutron-emitter); }

/* Folded away: a slim bar that unfolds it again */
.nuc-tray-collapsed .nuc-palette {
    display: none;
}

.nuc-tray-collapsed .nuc-toolbar .nuc-tray-toggle {
    flex: 1 1 auto;
    width: auto;
}

.nuc-tray-collapsed .nuc-tray-label {
    display: inline;
}

.nuc-tray-collapsed .nuc-toolbar .nuc-tray-toggle .icon {
    transform: rotate(90deg);
}

/* Phones in portrait: the canvas stays (nearly) as wide as the screen even where the tray and info bar
   would not fit under it on screen; the page scrolls a little instead (on a small phone, fitting
   everything would leave a canvas too small to drag things onto). */
@media (max-width: 600px) and (orientation: portrait) {
    .nuclear-sim .simulation-main-content {
        --sim-canvas-max-h: max(14em, calc(100vh - var(--sim-above-h) - var(--sim-below-h) - var(--sim-fit-gap)), calc((100vw - 2 * var(--sim-page-gutter)) * 1.05));
    }

    @supports (height: 100svh) {
        .nuclear-sim .simulation-main-content {
            --sim-canvas-max-h: max(14em, calc(100svh - var(--sim-above-h) - var(--sim-below-h) - var(--sim-fit-gap)), calc((100vw - 2 * var(--sim-page-gutter)) * 1.05));
        }
    }
}

/* ---------- Landscape: the tray in a column beside the canvas ----------
   The column has a fixed width, so the display container is that much wider than the canvas (which the
   shared layout sizes from the screen height). */
@media (orientation: landscape) and (min-width: 640px) {
    .nuclear-sim .simulation-display-container {
        display: grid;
        grid-template-columns: var(--nuc-side-w) minmax(0, 1fr);
        grid-template-areas: "tools canvas" "info info";
        column-gap: var(--nuc-side-gap);
        width: min(100%, calc(var(--sim-canvas-max-h) * (var(--aspect-ratio, 2 / 1)) + 2px + var(--nuc-side-w) + var(--nuc-side-gap)));
    }

    .nuclear-sim .sim-canvas-wrapper {
        grid-area: canvas;
        min-width: 0;
    }

    .nuclear-sim .sim-info-bar {
        grid-area: info;
    }

    /* As tall as the canvas beside it, never taller; the buttons scroll if they need more room. */
    .nuc-toolbar {
        grid-area: tools;
        flex-direction: column;
        margin-top: 0;
        min-height: 0;
        contain: size;
        overflow: hidden;
    }

    .nuc-toolbar .nuc-tray-toggle {
        justify-content: space-between;
        width: 100%;
        min-height: 28px;
        padding: 0 7px 0 8px;
    }

    .nuc-tray-label {
        display: inline;
    }

    .nuc-toolbar .nuc-tray-toggle .icon {
        transform: none;                                /* a column: the chevron points left, to fold it away */
    }

    .nuc-palette {
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .nuc-toolbar .nuc-item {
        flex-direction: row;
        justify-content: flex-start;
        gap: 6px;
        width: 100%;
        height: var(--nuc-btn);
        padding: 0 6px 0 4px;
        touch-action: pan-y;            /* a swipe up or down scrolls the column; a drag sideways goes to the canvas */
    }

    .nuc-tray-collapsed .nuc-toolbar .nuc-tray-toggle {
        flex-direction: column;
        justify-content: flex-start;
        gap: 12px;
        height: 100%;
        padding: 8px 0;
    }

    .nuc-tray-collapsed .nuc-toolbar .nuc-tray-toggle .icon {
        order: -1;
        transform: rotate(180deg);
    }

    .nuc-tray-collapsed .nuc-tray-label {
        writing-mode: vertical-rl;
    }

    /* Fullscreen: the grid fills the space above the fixed info bar */
    body.sim-fullscreen-active .nuclear-sim .simulation-display-container {
        display: grid;
        grid-template-rows: minmax(0, 1fr);
        grid-template-areas: "tools canvas";
        width: 100%;
    }

    body.sim-fullscreen-active .nuclear-sim .sim-canvas-wrapper {
        height: 100%;
    }
}

/* ---------- Settings panel ---------- */
.sim-controls-content .nuc-control-note {
    margin-top: -0.3em;
    font-size: 0.8em;
    opacity: 0.75;
}

.sim-controls-content .nuc-add-caption {
    margin: 0.1em 0 -0.2em 0;
    font-size: 0.8em;
    opacity: 0.75;
}

/* Ready-made scenes: two to a row */
.nuc-setups {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4em;
}

.sim-controls-content .nuc-setup {
    -webkit-appearance: none;
    appearance: none;
    display: flex;
    align-items: center;
    min-height: 2.9em;
    height: auto;
    margin: 0;
    padding: 0.4em 0.7em;
    overflow: visible;
    font-family: inherit;
    font-size: 0.85em;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0;
    text-align: left;
    text-transform: none;
    white-space: normal;
    color: var(--color-text) !important;
    background-color: var(--color-bg);
    border: 0;
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px var(--color-border);
    cursor: pointer;
}

@media (hover: hover) {
    .sim-controls-content .nuc-setup:hover {
        color: var(--color-accent) !important;
        box-shadow: inset 0 0 0 1px var(--color-accent);
    }
}

.sim-controls-content .nuc-setup:active {
    background-color: var(--color-bg-button-active-overlay);
}

.sim-controls-content .nuc-setup:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 1px;
}

.nuc-add-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.45em;
}

.nuc-add-row #elementSelect {
    grid-column: 1 / -1;
}

.nuc-add-row select {
    width: 100%;
    min-width: 0;
}

.sim-controls-content .nuc-add-button {
    -webkit-appearance: none;
    appearance: none;
    height: 2.6em;
    margin: 0;
    padding: 0 1.2em;
    font-family: inherit;
    font-size: 0.9em;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.06em;
    text-transform: none;
    color: #ffffff !important;
    background-color: var(--color-accent);
    border: 0;
    border-radius: 4px;
    box-shadow: none;
    cursor: pointer;
}

@media (hover: hover) {
    .sim-controls-content .nuc-add-button:hover {
        background-color: var(--color-accent-active);
    }
}

.sim-controls-content .nuc-add-button:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* "Label nuclei as 14/6 C": mass number over atomic number */
.nuc-notation {
    display: inline-flex;
    align-items: center;
    margin-left: 0.2em;
    font-weight: 700;
}

.nuc-scripts {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-end;
    margin-right: 1px;
    font-size: 0.62em;
    line-height: 1.05;
}

.nuc-scripts sup,
.nuc-scripts sub {
    position: static;
    font-size: 1em;
    line-height: 1.05;
    vertical-align: baseline;
}

/* ---------- Info bar ---------- */
/* The readouts are words ("Uranium-238", "4.468 billion years"), so they read from the left. */
.nuclear-sim .sim-info-bar .sim-value {
    text-align: left;
}
