:root {
    --navy: #112D4E;
    --blue: #3F72AF;
    --light: #DBE2EF;
    --paper: #F9F7F7;
    --gold: #F7C873;
    --gold-light: #FAEBCD;
    --red: #BE4747;
    --muted: #5a6b80;
    --line: #d5dce6;
}

html {
    font-size: 15px;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--navy);
    line-height: 1.4;
}

html * {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 16px 20px 40px;
    background: var(--paper);
}

a {
    color: var(--blue);
}

button,
select,
input {
    font: inherit;
}

button {
    border: none;
    border-radius: 4px;
    background: var(--blue);
    color: var(--paper);
    padding: 6px 10px;
    cursor: pointer;
}

button:hover {
    background: #34629b;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 1px;
}

/* ---- layout ------------------------------------------------------------ */

.topbar {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 16px;
    margin-bottom: 12px;
}

.topbar h1 {
    margin: 0;
    font-size: 1.5rem;
}

.topbar p {
    margin: 0;
    color: var(--muted);
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 16px;
    align-items: start;
}

.stage {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.panels {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 12px;
}

.panel {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
    min-width: 0;
}

.panel h3 {
    margin: 0 0 8px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.panel-head h3 {
    margin: 0;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@media (max-width: 900px) {
    .layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .panels {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ---- 3D viewport -------------------------------------------------------- */

.viewport {
    position: relative;
    height: min(62vh, 620px);
    min-height: 340px;
    border: 1px solid var(--navy);
    border-radius: 6px;
    overflow: hidden;
    background: #dfe8f1;
}

.viewport canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.hud {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    pointer-events: none;
}

.hud > * {
    pointer-events: auto;
}

.hud-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
}

.hud-stats div {
    background: rgba(249, 247, 247, 0.88);
    border-radius: 4px;
    padding: 4px 10px;
    min-width: 84px;
}

.hud-stats dt {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.hud-stats dd {
    margin: 0;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.hud-views {
    display: flex;
    background: rgba(249, 247, 247, 0.88);
    border-radius: 4px;
    padding: 3px;
    gap: 2px;
}

.hud-views button {
    background: transparent;
    color: var(--navy);
    padding: 4px 9px;
    font-size: 0.85rem;
}

.hud-views button:hover {
    background: var(--light);
}

.hud-views button.active {
    background: var(--blue);
    color: var(--paper);
}

.hud-bottom {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 8px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.8rem;
    pointer-events: none;
}

.hud-bottom span {
    background: rgba(249, 247, 247, 0.85);
    border-radius: 4px;
    padding: 2px 8px;
}

.hud-bottom .hint {
    color: var(--muted);
}

.viewport.replaying::after {
    content: "Top replay";
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--red);
    color: #fff;
    padding: 3px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
}

.status {
    position: absolute;
    left: 50%;
    bottom: 40px;
    transform: translateX(-50%);
    background: var(--navy);
    color: var(--paper);
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
    padding: 20px;
    background: rgba(249, 247, 247, 0.92);
    font-size: 1.05rem;
}

.overlay[hidden],
.status[hidden] {
    display: none;
}

/* shown instead of the simulation when JavaScript is off */
.noscript {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: var(--paper);
}

.noscript img {
    display: block;
    width: 100%;
    height: calc(100% - 7em);
    object-fit: cover;
}

.noscript p {
    margin: 0;
    padding: 12px 16px;
    font-size: 0.9rem;
}

/* ---- graph, scores, minimap ---------------------------------------------- */

#graphcanvas {
    display: block;
    width: 100%;
    height: 190px;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
    font-size: 0.8rem;
    color: var(--muted);
}

.legend i {
    display: inline-block;
    width: 12px;
    height: 3px;
    margin-right: 5px;
    vertical-align: middle;
}

.topscores {
    margin: 0;
    padding-left: 26px;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

.topscores li span {
    color: var(--muted);
    margin-left: 6px;
}

.topscores .empty {
    list-style: none;
    margin-left: -26px;
    color: var(--muted);
}

#minimap {
    display: block;
    width: 100%;
    height: 150px;
    cursor: pointer;
}

/* ---- sidebar ----------------------------------------------------------- */

.buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    margin-bottom: 12px;
}

.buttons button {
    font-size: 0.85rem;
    padding: 6px 6px;
}

.label {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 3px;
}

.seed {
    display: flex;
    gap: 5px;
}

.seed input {
    flex: 1;
    min-width: 0;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 4px;
}

.settings {
    width: 100%;
    border-collapse: collapse;
}

.settings td {
    padding: 4px 0;
    border-bottom: 1px solid #eef1f5;
}

.settings tr:last-child td {
    border-bottom: none;
}

.settings select {
    width: 100%;
    padding: 3px 4px;
}

.healthlist {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
}

.healthbar {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    color: var(--navy);
    padding: 2px 4px;
    border-radius: 3px;
    text-align: left;
}

.healthbar:hover {
    background: var(--light);
}

.healthbar.following {
    background: var(--gold-light);
}

.healthtext {
    width: 30px;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.healthtrack {
    flex: 1;
    height: 12px;
    border: 1px solid var(--navy);
    padding: 1px;
}

.health {
    display: block;
    height: 100%;
    width: 100%;
    background: #E0A030;
}

.healthbar.elite .health {
    background: var(--blue);
}

.healthbar.dead .healthtext {
    color: var(--red);
}

.healthbar.finished .healthtext {
    color: #3c8a2e;
    font-weight: 600;
}

/* ---- explanation ------------------------------------------------------- */

.explanation {
    max-width: 900px;
    margin-top: 36px;
    font-size: 0.85rem;
    color: #444;
}

.explanation h2 {
    font-size: 1.17em;
    color: var(--navy);
    margin: 20px 0 6px;
}

.explanation table {
    border-collapse: collapse;
}

.explanation .disclaimer {
    margin-top: 16px;
    font-size: 0.75rem;
    color: var(--muted);
}

.explanation th,
.explanation td {
    padding: 2px 8px 2px 0;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid #ddd;
}

.explanation th {
    white-space: nowrap;
}

/* ---- parts list -------------------------------------------------------- */

.bom-title {
    margin: 0 0 6px;
    font-size: 0.85rem;
    font-weight: 600;
}

.bom {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.8rem;
}

.bom li {
    padding: 2px 0;
    border-bottom: 1px solid #eef1f5;
}

.bom li:last-child {
    border-bottom: none;
}

.bom i {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 6px;
    border: 1px solid rgba(0, 0, 0, 0.35);
    border-radius: 2px;
    vertical-align: -1px;
}

.bom .partid {
    color: var(--muted);
}
