/* Cellular automata applet — styled to sit inside the RTD docs page.
   Palette from custom.css: Founder's Rock masthead (#3B7EA1), dark navy
   (#07223f) stage, California Gold (#FDB515) accents and live cells.
   The simulation fills the card below the header; the controls and the
   meters float over it as translucent panels. */

#ca-app {
    --ca-rock: #3B7EA1;
    --ca-navy: #07223f;
    --ca-gold: #FDB515;
    font-family: 'Lato', 'Helvetica Neue', Arial, sans-serif;
    border: 1px solid #d8d8d8;
    border-radius: 10px;
    overflow: hidden;
    margin: 1.5em 0;
    background: var(--ca-navy);
}

#ca-head {
    background: var(--ca-rock);
    color: #fff;
    font-family: 'Roboto Slab', Georgia, serif;
    font-weight: 700;
    font-size: 0.92em;
    padding: 5px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

#ca-head .ca-title { flex: 1; }

#ca-head select {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 4px;
    padding: 3px 6px;
    font-family: 'Lato', 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
}

#ca-head select option { color: #07223f; background: #fcfcfc; }

.ca-hbtn {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 4px;
    padding: 3px 12px;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
}

.ca-hbtn:hover { background: rgba(255, 255, 255, 0.3); }

/* The canvas fills the card. Cells are painted at lattice resolution and
   stretched, so keep them crisp. */
#ca-stage {
    position: relative;
    background: var(--ca-navy);
    line-height: 0;
}

#ca-canvas {
    display: block;
    width: 100%;
    height: 420px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Translucent panels floating on the simulation. */
.ca-ov {
    position: absolute;
    background: rgba(4, 16, 30, 0.45);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 5px;
    color: #d8d8d8;
    font-size: 14px;
    line-height: 1.35;
    padding: 6px 8px;
}

/* Controls, bottom left: shown and hidden by the selector. */
#ca-controls {
    bottom: 8px;
    left: 8px;
    width: 230px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ca-ctl label {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 1px;
    color: #9fb2c5;
}

.ca-ctl label .val {
    font-weight: 700;
    color: var(--ca-gold);
    font-variant-numeric: tabular-nums;
}

#ca-rule,
.ca-ctl input[type=text] {
    width: 100%;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.10);
    color: #eef2f6;
    border: 1px solid rgba(255, 255, 255, 0.30);
    border-radius: 3px;
    padding: 2px 6px;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

#ca-rule {
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

/* The rule drop-up: a scrollable grid of all 256 rules, anchored above
   the control panel and fully contained in the stage. Same translucent
   treatment as the panels. */
#ca-rulemenu {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    width: 100%;
    box-sizing: border-box;
    max-height: 180px;
    overflow-y: auto;
    grid-template-columns: repeat(8, 1fr);
    gap: 1px;
    padding: 4px;
    background: rgba(4, 16, 30, 0.45);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 5px;
}

.ca-ruleopt {
    background: none;
    border: none;
    color: #d8d8d8;
    font-family: inherit;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    text-align: center;
    padding: 2px 0;
    border-radius: 3px;
    cursor: pointer;
}

.ca-ruleopt:hover { background: rgba(255, 255, 255, 0.15); }

.ca-ruleopt.sel {
    background: var(--ca-gold);
    color: #07223f;
    font-weight: 700;
}

.ca-ctl input[type=range] {
    display: block;
    width: 100%;
    height: 13px;
    margin: 0;
    accent-color: var(--ca-gold);
}

/* The phase plot, top right: for looking at, not touching. */
#ca-meters {
    top: 8px;
    right: 8px;
    pointer-events: none;
}

#ca-plotrow { display: flex; align-items: center; }

/* The y-axis label is rotated inside a fixed-width gutter, so the rotation
   cannot disturb the layout around it. */
#ca-ylab {
    width: 19px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#ca-ylab > span {
    transform: rotate(-90deg);
    white-space: nowrap;
    line-height: 1;
}

#ca-ylab, #ca-xlab {
    color: #9fb2c5;
    font-size: 14px;
}

#ca-xlab {
    text-align: center;
    margin-top: 2px;
    padding-left: 15px;   /* centre under the plot, not the gutter */
}

/* Square, and kept square: equal axes. */
#ca-phase {
    display: block;
    width: 160px;
    height: 160px;
}

/* MathJax renders into its own container; keep it inline, at our size, and
   in the panel's colour rather than the page's body colour. */
.ca-ov mjx-container {
    display: inline !important;
    margin: 0 !important;
    font-size: 105% !important;
    color: inherit;
}

@media (max-width: 640px) {
    #ca-canvas { height: 300px; }
    #ca-meters { display: none; }
    #ca-controls { width: 170px; }
    #ca-rulemenu { max-height: 110px; grid-template-columns: repeat(6, 1fr); }
}
