/*
 * The page is one dark surface throughout. It is not theme-aware on purpose:
 * the field is a night-ish top-down view of grass and soil, and a light chrome
 * around it would fight the thing it frames. The chart's series colours are the
 * dark-mode steps, validated against this surface.
 */

:root {
    --surface: #12140f;
    --surface-2: #171a14;
    --surface-3: #1e2219;
    --line: #2c3126;
    --ink: #e9e6dc;
    --ink-2: #a8a396;
    --ink-3: #726d61;
    --rabbit: #3987e5;
    --fox: #d95926;
    --grass: #199e70;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
}

body {
    background: var(--surface);
    color: var(--ink);
    font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
    overflow: hidden;
}

.app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 366px;
    height: 100%;
}

/* --- Field ------------------------------------------------------------- */

.stage {
    position: relative;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

#field {
    flex: 1;
    width: 100%;
    min-height: 0;
    display: block;
    touch-action: none;
}

.hud {
    position: absolute;
    top: 12px;
    left: 14px;
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 7px 12px;
    border-radius: 8px;
    background: rgba(10, 12, 8, 0.66);
    border: 1px solid var(--line);
    font: 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--ink-2);
    backdrop-filter: blur(6px);
}

.hud b {
    color: var(--ink);
}

.hud .sep {
    width: 1px;
    height: 13px;
    background: var(--line);
}

.hint {
    position: absolute;
    bottom: 10px;
    left: 14px;
    margin: 0;
    font-size: 11.5px;
    color: var(--ink-3);
}

kbd {
    font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
    background: var(--surface-3);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 1px 4px;
    color: var(--ink-2);
}

.scenes {
    position: absolute;
    top: 12px;
    right: 14px;
    display: flex;
    gap: 4px;
    padding: 4px;
    border-radius: 9px;
    background: rgba(10, 12, 8, 0.66);
    border: 1px solid var(--line);
    backdrop-filter: blur(6px);
}

/* Inline bits belonging to the scene that is not showing. Sections are hidden
   from script instead, because they answer to both the scene *and* the current
   tab and expressing that intersection in selectors is far less legible than
   one `hidden` assignment. */
.hud [data-scene],
.checks label[data-scene],
.ctl[data-scene] {
    display: none;
}

body[data-active="meadow"] .hud [data-scene="meadow"],
body[data-active="tank"] .hud [data-scene="tank"] {
    display: revert;
}

body[data-active="meadow"] .checks label[data-scene="meadow"],
body[data-active="tank"] .checks label[data-scene="tank"] {
    display: flex;
}

body[data-active="meadow"] .ctl[data-scene="meadow"],
body[data-active="tank"] .ctl[data-scene="tank"] {
    display: grid;
}

.panel h2.subhead {
    margin-top: 18px;
}

.experiments {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.experiments button {
    font-size: 12px;
    padding: 5px 9px;
}

.tabs {
    display: flex;
    gap: 3px;
    margin-top: 16px;
    padding: 3px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 9px;
}

.tabs button {
    flex: 1;
    justify-content: center;
    border: none;
    background: none;
    padding: 5px 4px;
    border-radius: 6px;
}

.tabs button.on {
    background: var(--surface-3);
    border: none;
}

.run-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 16px;
}

.panel section[data-tab] {
    margin-top: 18px;
}

#brain {
    width: 100%;
    height: 190px;
    display: block;
    margin: 10px 0 4px;
}

#fishchart {
    width: 100%;
    height: 210px;
    display: block;
    touch-action: none;
}

#evospread {
    width: 100%;
    height: 132px;
    display: block;
    margin-top: 10px;
}

/* One tuning control per row, generated from the key list so a new parameter
   cannot be added without a slider appearing for it. */
.tune {
    display: grid;
    grid-template-columns: 96px 1fr 40px;
    align-items: center;
    gap: 9px;
    font-size: 12px;
    color: var(--ink-2);
    margin-bottom: 6px;
}

.tune output {
    text-align: right;
    font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
}

.tune.moved output {
    color: #b9cf7e;
}

/* --- Panel ------------------------------------------------------------- */

.panel {
    border-left: 1px solid var(--line);
    background: var(--surface-2);
    overflow-y: auto;
    padding: 20px 18px 28px;
}

.panel header h1 {
    margin: 0 0 8px;
    font-size: 17px;
    letter-spacing: -0.01em;
}

.panel header p {
    margin: 0;
    color: var(--ink-2);
    font-size: 12.5px;
}

.panel section {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.panel h2 {
    margin: 0 0 10px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--ink-3);
    font-weight: 600;
}

button {
    font: inherit;
    font-size: 12.5px;
    color: var(--ink-2);
    background: var(--surface-3);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 6px 10px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

button:hover:not(:disabled) {
    color: var(--ink);
    border-color: #3d442f;
}

button:disabled {
    opacity: 0.45;
    cursor: default;
}

button.on {
    color: var(--ink);
    background: #2a3220;
    border-color: #4a5a36;
}

.tools,
.row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.row {
    margin-top: 8px;
}

/* --- Inspector --------------------------------------------------------- */

.insp-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.insp-head strong {
    font-size: 14px;
}

#inspector.empty .gauge {
    opacity: 0.35;
}

.meta {
    margin: 6px 0 10px;
    font-size: 12px;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
}

.gauge {
    display: grid;
    grid-template-columns: 62px 1fr;
    align-items: center;
    gap: 10px;
    font-size: 11.5px;
    color: var(--ink-3);
    margin-bottom: 6px;
}

.track {
    height: 6px;
    border-radius: 3px;
    background: var(--surface-3);
    overflow: hidden;
}

.fill {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 3px;
    transition: width 0.12s linear;
}

.fill.energy {
    background: var(--grass);
}

.fill.stamina {
    background: var(--rabbit);
}

/* --- Chart ------------------------------------------------------------- */

#chart {
    width: 100%;
    height: 168px;
    display: block;
    touch-action: none;
}

#evochart {
    width: 100%;
    height: 210px;
    display: block;
    touch-action: none;
}

.feed {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
    font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--ink-3);
    max-height: 96px;
    overflow: hidden;
}

.feed li {
    display: flex;
    gap: 8px;
    padding: 1px 0;
    white-space: nowrap;
}

.feed li time {
    color: #5c5951;
    flex: none;
}

.feed li.extinct,
.feed li.recovered {
    color: var(--ink-2);
}

.tally {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 8px;
    font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--ink-3);
}

.seltrend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: baseline;
    margin-bottom: 3px;
}

.seltrend em {
    font-style: normal;
    color: #5c5951;
    min-width: 48px;
}

.tally b {
    color: var(--ink-2);
}

/* --- Controls ---------------------------------------------------------- */

.ctl {
    display: grid;
    grid-template-columns: 74px 1fr 46px;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--ink-2);
    margin-bottom: 7px;
}

.ctl output {
    text-align: right;
    font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
}

input[type="range"] {
    width: 100%;
    accent-color: #6f8c46;
}

.checks {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 10px;
    font-size: 12.5px;
    color: var(--ink-2);
}

.checks label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

input[type="checkbox"] {
    accent-color: #6f8c46;
}

.panel footer {
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    font-size: 12px;
}

.panel footer a {
    color: var(--ink-3);
    text-decoration: none;
}

.panel footer a:hover {
    color: var(--ink-2);
}

/* --- Narrow ------------------------------------------------------------ */

@media (max-width: 900px) {
    body {
        overflow: auto;
    }

    .app {
        grid-template-columns: 1fr;
        height: auto;
    }

    .stage {
        height: 62vh;
        min-height: 340px;
    }

    .panel {
        border-left: none;
        border-top: 1px solid var(--line);
    }
}
