/*
 * Rosenthal's Algorithm write-up. Requires /newindex.css, /css/themes.css and html[data-theme].
 * Chart colours were checked with the palette validator for both surfaces.
 */
body.ros-page {
    --ros-bg: var(--bg-primary, #0a0a1a);
    --ros-surface: var(--bg-card, #141428);
    --ros-surface-2: var(--bg-surface, #1e1e3a);
    --ros-ink: var(--text-primary, #f1f5f9);
    --ros-ink-2: var(--text-secondary, #94a3b8);
    --ros-ink-3: var(--text-muted, #64748b);
    --ros-line: var(--border-default, rgba(255, 255, 255, 0.10));
    --ros-line-soft: var(--border-subtle, rgba(255, 255, 255, 0.06));
    --ros-accent: #0687c9;
    --ros-accent-soft: rgba(6, 135, 201, 0.16);
    --ros-target: #f59e0b;
    --ros-grover: #0284c7;
    --ros-queries: #d946ef;
    --ros-depth: #16a34a;
    --ros-bar: rgba(148, 163, 184, 0.55);
    --ros-hero-glow: radial-gradient(1200px 520px at 20% -10%, rgba(6, 135, 201, 0.28), transparent 60%),
        radial-gradient(900px 480px at 90% 0%, rgba(171, 111, 175, 0.22), transparent 60%);
    --ros-head-font: 'Khand', 'Inter', sans-serif;
    --ros-body-font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --ros-mono-font: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
    background: var(--ros-bg) !important;
    color: var(--ros-ink) !important;
    font-family: var(--ros-body-font);
}

html[data-theme="light"] body.ros-page {
    --ros-queries: #7c3aed;
    --ros-depth: #15803d;
    --ros-bar: rgba(100, 116, 139, 0.55);
    --ros-hero-glow: radial-gradient(1200px 520px at 20% -10%, rgba(6, 135, 201, 0.16), transparent 60%),
        radial-gradient(900px 480px at 90% 0%, rgba(124, 58, 237, 0.12), transparent 60%);
}

body.ros-page nav.navbar.fixed-top {
    background: var(--subpage-topbar-bg, rgba(10, 10, 26, 0.92)) !important;
}

html[data-theme="light"] body.ros-page nav.navbar.fixed-top {
    background: rgba(255, 255, 255, 0.94) !important;
}

html[data-theme="light"] body.ros-page .navbar-brand img {
    filter: invert(1) hue-rotate(180deg) brightness(0.35);
}

html[data-theme="light"] body.ros-page .navbar-toggler-icon {
    filter: invert(1) brightness(0.4);
}

/* ---- layout ------------------------------------------------------------ */
.ros {
    display: block;
    padding-top: 72px;
}

.ros section,
.ros .ros-section {
    min-height: auto !important;
    padding: 56px 0 !important;
    position: relative;
}

.ros-wrap {
    width: min(1120px, calc(100% - 48px));
    margin: 0 auto;
}

.ros-prose {
    max-width: 780px;
}

.ros h2 {
    font-family: var(--ros-head-font);
    font-weight: 500;
    font-size: clamp(30px, 3.4vw, 42px);
    line-height: 1.15;
    letter-spacing: 0.2px;
    color: var(--ros-ink);
    margin: 0 0 18px;
}

.ros p {
    font-size: 18px;
    line-height: 1.75;
    color: var(--ros-ink);
    margin: 0 0 18px;
}

.ros a {
    color: var(--text-link, #38bdf8);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s ease;
}

.ros a:hover,
.ros a:focus-visible {
    border-bottom-color: currentColor;
}

.ros strong {
    color: var(--ros-ink);
    font-weight: 600;
}

.ros sup,
.ros sub {
    font-size: 0.7em;
}

.ros-math {
    font-family: var(--ros-mono-font);
    font-size: 16px !important;
    padding: 12px 16px;
    border-left: 3px solid var(--ros-accent);
    background: var(--ros-surface);
    border-radius: 0 10px 10px 0;
    overflow-x: auto;
}

.ros-callout {
    border: 1px solid var(--ros-line);
    border-left: 4px solid var(--ros-target);
    background: var(--ros-surface);
    border-radius: 12px;
    padding: 18px 22px 4px;
    margin-top: 8px;
}

.ros-list {
    padding-left: 22px;
    margin: 0 0 18px;
}

.ros-list li {
    font-size: 18px;
    line-height: 1.7;
    margin-bottom: 12px;
    color: var(--ros-ink);
}

.ros-list--claims li {
    margin-bottom: 18px;
}

/* ---- hero -------------------------------------------------------------- */
.ros-hero {
    position: relative;
    padding: 88px 0 40px;
    background: var(--ros-hero-glow);
}

.ros-eyebrow {
    font-family: var(--ros-mono-font);
    font-size: 13px !important;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: var(--ros-ink-2);
    margin-bottom: 14px !important;
}

.ros-title {
    font-family: var(--ros-head-font);
    font-weight: 500;
    font-size: clamp(48px, 7vw, 88px);
    line-height: 1;
    letter-spacing: 0.5px;
    margin: 0 0 22px;
    color: var(--ros-ink);
}

.ros-lead {
    font-size: 21px !important;
    line-height: 1.6 !important;
    max-width: 820px;
    color: var(--ros-ink-2) !important;
}

.ros-tiles {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-top: 32px;
}

.ros-tile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 18px 20px;
    border: 1px solid var(--ros-line);
    background: var(--ros-surface);
    border-radius: 14px;
}

.ros-tile-label {
    font-size: 13px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--ros-ink-2);
}

.ros-tile-value {
    font-family: var(--ros-head-font);
    font-size: 40px;
    line-height: 1.05;
    color: var(--ros-ink);
}

.ros-tile-note {
    font-size: 14px;
    color: var(--ros-ink-3);
}

/* ---- table of contents -------------------------------------------------- */
.ros-toc {
    position: sticky;
    top: 62px;
    z-index: 20;
    background: color-mix(in srgb, var(--ros-bg) 88%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--ros-line-soft);
    border-bottom: 1px solid var(--ros-line-soft);
}

.ros-toc .ros-wrap {
    display: flex;
    gap: 4px 18px;
    flex-wrap: wrap;
    padding: 10px 0;
}

.ros-toc a {
    font-size: 14px;
    color: var(--ros-ink-2);
    padding: 4px 2px;
    border-bottom: 2px solid transparent;
}

.ros-toc a:hover,
.ros-toc a:focus-visible {
    color: var(--ros-ink);
    border-bottom-color: var(--ros-accent);
}

/* ---- figures ----------------------------------------------------------- */
.ros-figure {
    margin: 26px 0 10px;
    padding: 18px 18px 14px;
    border: 1px solid var(--ros-line);
    background: var(--ros-surface);
    border-radius: 16px;
}

.ros-figure figcaption {
    font-size: 15px;
    line-height: 1.5;
    color: var(--ros-ink-2);
    margin-top: 12px;
}

.ros-figure-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
    margin-bottom: 12px;
}

.ros-figure-controls label {
    font-size: 15px;
    color: var(--ros-ink-2);
    display: inline-flex;
    gap: 8px;
    align-items: baseline;
}

.ros-figure-controls output {
    font-family: var(--ros-mono-font);
    color: var(--ros-ink);
    min-width: 2ch;
}

.ros-figure-controls input[type="range"] {
    width: min(260px, 100%);
    accent-color: var(--ros-accent);
}

.ros-figure-hint {
    font-size: 14px;
    color: var(--ros-ink-3);
}

.ros-stage {
    margin-left: auto;
    font-family: var(--ros-mono-font);
    color: var(--ros-ink);
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--ros-accent-soft);
}

.ros-figure-body {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(220px, 0.8fr);
    gap: 18px;
    align-items: center;
}

.ros-svg {
    display: block;
    width: 100%;
    height: auto;
    font-family: var(--ros-body-font);
}

.ros-svg--rotation {
    max-width: 460px;
    margin: 0 auto;
}

.ros-readout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 0;
}

.ros-readout div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 10px;
    background: var(--ros-surface-2);
}

.ros-readout dt {
    font-size: 14px;
    color: var(--ros-ink-2);
    font-weight: 400;
}

.ros-readout dd {
    margin: 0;
    font-family: var(--ros-mono-font);
    font-size: 15px;
    color: var(--ros-ink);
}

.ros-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid var(--ros-line);
    background: var(--ros-surface-2);
    color: var(--ros-ink) !important;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.ros-btn:hover,
.ros-btn:focus-visible {
    border-color: var(--ros-accent);
    background: var(--ros-accent-soft);
    transform: translateY(-1px);
}

.ros-btn--primary {
    background: var(--ros-accent);
    border-color: var(--ros-accent);
    color: #fff !important;
}

.ros-btn--primary:hover,
.ros-btn--primary:focus-visible {
    background: #0a76ad;
    border-color: #0a76ad;
}

.ros-select,
.ros-input {
    font: inherit;
    font-size: 15px;
    color: var(--ros-ink);
    background: var(--ros-surface-2);
    border: 1px solid var(--ros-line);
    border-radius: 8px;
    padding: 6px 10px;
}

.ros-input--mono {
    font-family: var(--ros-mono-font);
    letter-spacing: 2px;
    width: 12ch;
}

.ros-input:invalid {
    border-color: var(--ros-target);
}

/* SVG element styles (shared) */
.ros-svg .axis {
    stroke: var(--ros-ink-3);
    stroke-width: 1.5;
    fill: none;
}

.ros-svg .grid {
    stroke: var(--ros-line);
    stroke-width: 1;
    fill: none;
}

.ros-svg .arc {
    stroke: var(--ros-line);
    stroke-width: 1.5;
    fill: none;
    stroke-dasharray: 4 5;
}

.ros-svg .label {
    fill: var(--ros-ink-2);
    font-size: 13px;
}

.ros-svg .label--strong {
    fill: var(--ros-ink);
    font-size: 14px;
    font-weight: 600;
}

.ros-svg .trail {
    stroke: var(--ros-accent);
    stroke-width: 6;
    stroke-linecap: round;
    fill: none;
    opacity: 0.35;
}

.ros-svg .vec {
    stroke: var(--ros-accent);
    stroke-width: 3;
    stroke-linecap: round;
}

.ros-svg .vec--start {
    stroke: var(--ros-ink-3);
    stroke-width: 2;
    stroke-dasharray: 5 5;
}

.ros-svg .vec--matched {
    stroke: var(--ros-depth);
}

.ros-svg .vec--plain {
    stroke: var(--ros-grover);
}

.ros-svg .vec-head {
    fill: var(--ros-accent);
}

.ros-svg .vec-head--start {
    fill: var(--ros-ink-3);
}

.ros-svg .vec-head--matched {
    fill: var(--ros-depth);
}

.ros-svg .vec-head--plain {
    fill: var(--ros-grover);
}

.ros-svg .target-axis {
    stroke: var(--ros-target);
    stroke-width: 2;
}

.ros-svg .wire {
    stroke: var(--ros-ink-3);
    stroke-width: 1.5;
}

.ros-svg .wire-label {
    fill: var(--ros-ink-2);
    font-family: var(--ros-mono-font);
    font-size: 12px;
}

.ros-svg .oracle {
    fill: var(--ros-accent-soft);
    stroke: var(--ros-accent);
    stroke-width: 2;
    rx: 8;
}

.ros-svg .oracle-label {
    fill: var(--ros-ink);
    font-family: var(--ros-mono-font);
    font-size: 15px;
    text-anchor: middle;
    dominant-baseline: middle;
}

.ros-svg .gate {
    fill: var(--ros-surface-2);
    stroke: var(--ros-ink-2);
    stroke-width: 1.5;
    rx: 5;
}

.ros-svg .gate--h {
    fill: var(--ros-accent-soft);
    stroke: var(--ros-accent);
}

.ros-svg .gate--x {
    fill: rgba(245, 158, 11, 0.16);
    stroke: var(--ros-target);
}

.ros-svg .gate--m {
    fill: var(--ros-surface-2);
    stroke: var(--ros-ink-2);
}

.ros-svg .gate-text {
    fill: var(--ros-ink);
    font-family: var(--ros-mono-font);
    font-size: 12px;
    text-anchor: middle;
    dominant-baseline: middle;
}

.ros-svg .cz-dot {
    fill: var(--ros-depth);
}

.ros-svg .cz-line {
    stroke: var(--ros-depth);
    stroke-width: 2;
}

.ros-svg .stage-band {
    fill: var(--ros-accent);
    opacity: 0.1;
    rx: 10;
    transition: x 0.35s ease, width 0.35s ease;
}

.ros-svg .stage-label {
    fill: var(--ros-ink-2);
    font-size: 12px;
    text-anchor: middle;
}

.ros-svg .stage-label--on {
    fill: var(--ros-ink);
    font-weight: 600;
}

/* chart */
.ros-chart-wrap {
    position: relative;
}

.ros-svg--chart .series {
    fill: none;
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.ros-svg--chart .series--grover {
    stroke: var(--ros-grover);
}

.ros-svg--chart .series--queries {
    stroke: var(--ros-queries);
}

.ros-svg--chart .series--depth {
    stroke: var(--ros-depth);
}

.ros-svg--chart .series-label {
    font-size: 12px;
    font-weight: 600;
}

.ros-svg--chart .series-label--grover {
    fill: var(--ros-grover);
}

.ros-svg--chart .series-label--queries {
    fill: var(--ros-queries);
}

.ros-svg--chart .series-label--depth {
    fill: var(--ros-depth);
}

.ros-svg--chart .crosshair {
    stroke: var(--ros-ink-3);
    stroke-width: 1;
    stroke-dasharray: 3 4;
}

.ros-svg--chart .marker {
    stroke: var(--ros-surface);
    stroke-width: 2;
}

.ros-svg--chart .marker--grover {
    fill: var(--ros-grover);
}

.ros-svg--chart .marker--queries {
    fill: var(--ros-queries);
}

.ros-svg--chart .marker--depth {
    fill: var(--ros-depth);
}

.ros-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin-left: auto;
    font-size: 14px;
    color: var(--ros-ink-2);
}

.ros-legend span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.ros-legend i {
    display: inline-block;
    width: 18px;
    height: 3px;
    border-radius: 2px;
}

.ros-legend i.sw--grover {
    background: var(--ros-grover);
}

.ros-legend i.sw--queries {
    background: var(--ros-queries);
}

.ros-legend i.sw--depth {
    background: var(--ros-depth);
}

.ros-tooltip {
    position: absolute;
    pointer-events: none;
    padding: 8px 12px;
    border-radius: 10px;
    background: var(--subpage-panel-solid, #141428);
    border: 1px solid var(--ros-line);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    font-size: 13px;
    line-height: 1.5;
    color: var(--ros-ink);
    white-space: nowrap;
    z-index: 5;
}

.ros-tooltip b {
    font-weight: 600;
}

.ros-tooltip .tip-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.ros-tooltip .tip-row i {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
}

/* ---- race ---------------------------------------------------------------- */
.ros-section--race {
    padding-top: 0 !important;
}

.ros-race {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.ros-race-panel {
    border: 1px solid var(--ros-line-soft);
    background: var(--ros-surface-2);
    border-radius: 12px;
    padding: 12px 14px 10px;
}

.ros-race-head,
.ros-race-foot {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 14px;
    color: var(--ros-ink-2);
}

.ros-race-name {
    font-weight: 600;
    color: var(--ros-ink);
}

.ros-race-foot {
    font-family: var(--ros-mono-font);
    font-size: 13px;
    margin-top: 6px;
}

.ros-race-canvas {
    display: block;
    width: 100%;
    height: 180px;
    margin-top: 8px;
}

/* ---- tables ------------------------------------------------------------ */
.ros-table-wrap {
    overflow-x: auto;
    margin: 18px 0 22px;
    border: 1px solid var(--ros-line);
    border-radius: 12px;
}

.ros-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 15px;
}

.ros-table th,
.ros-table td {
    padding: 10px 14px;
    text-align: right;
    border-bottom: 1px solid var(--ros-line-soft);
    white-space: nowrap;
}

.ros-table th:first-child,
.ros-table td:first-child {
    text-align: left;
}

.ros-table thead th {
    font-weight: 600;
    color: var(--ros-ink-2);
    background: var(--ros-surface-2);
    font-size: 13px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.ros-table tbody td {
    font-family: var(--ros-mono-font);
    color: var(--ros-ink);
}

.ros-table tbody tr:last-child td {
    border-bottom: 0;
}

/* ---- planner ----------------------------------------------------------- */
.ros-planner {
    margin-top: 20px;
    padding: 18px;
    border: 1px solid var(--ros-line);
    background: var(--ros-surface);
    border-radius: 16px;
}

.ros-planner-controls {
    display: grid;
    grid-template-columns: auto minmax(160px, 1fr) auto minmax(160px, 1fr);
    gap: 10px 14px;
    align-items: center;
    margin-bottom: 16px;
}

.ros-planner-controls label {
    font-size: 15px;
    color: var(--ros-ink-2);
    display: inline-flex;
    gap: 8px;
    white-space: nowrap;
}

.ros-planner-controls output {
    font-family: var(--ros-mono-font);
    color: var(--ros-ink);
    min-width: 2ch;
}

.ros-planner-controls input[type="range"] {
    width: 100%;
    accent-color: var(--ros-accent);
}

.ros-blocks {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.ros-block {
    display: flex;
    gap: 3px;
    padding: 5px;
    border-radius: 8px;
    border: 1px solid var(--ros-accent);
    background: var(--ros-accent-soft);
}

.ros-block--tail {
    border-color: var(--ros-target);
    background: rgba(245, 158, 11, 0.14);
}

.ros-block i {
    display: block;
    width: 12px;
    height: 18px;
    border-radius: 3px;
    background: var(--ros-ink-3);
    opacity: 0.8;
}

.ros-cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.ros-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--ros-surface-2);
    border: 1px solid var(--ros-line-soft);
    min-width: 0;
}

.ros-card--ref {
    border-style: dashed;
}

.ros-card-label {
    font-size: 12px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--ros-ink-2);
}

.ros-card-value {
    font-family: var(--ros-mono-font);
    font-size: 18px;
    color: var(--ros-ink);
    overflow-wrap: anywhere;
}

/* ---- code and actions --------------------------------------------------- */
.ros-code {
    margin: 8px 0 18px;
    padding: 18px 20px;
    border-radius: 12px;
    border: 1px solid var(--ros-line);
    background: var(--subpage-panel-solid, #0d1117);
    color: var(--ros-ink);
    font-family: var(--ros-mono-font);
    font-size: 14.5px;
    line-height: 1.7;
    overflow-x: auto;
}

.ros-code code {
    font-family: inherit;
    color: inherit;
}

.ros-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

/* ---- references and footer --------------------------------------------- */
.ros-refs {
    padding-left: 22px;
}

.ros-refs li {
    font-size: 15.5px;
    line-height: 1.6;
    margin-bottom: 10px;
    color: var(--ros-ink-2);
}

.ros-refs a {
    font-family: var(--ros-mono-font);
    font-size: 14px;
    margin-left: 6px;
}

.ros-footer {
    padding: 28px 0 60px;
    border-top: 1px solid var(--ros-line-soft);
}

.ros-footer p {
    font-size: 15px;
    color: var(--ros-ink-2);
}

/* ---- responsive ---------------------------------------------------------- */
/* budget figure */
.ros-svg--budget .budget-bar {
    fill: var(--ros-bar);
    transition: none;
}

.ros-svg--budget .budget-bar--done {
    fill: var(--ros-target);
}

.ros-svg--budget .finish {
    stroke: var(--ros-target);
    stroke-width: 1.5;
    stroke-dasharray: 6 5;
}

/* optimiser tables */
.ros-table--attack td.attack-found {
    font-weight: 600;
    color: var(--ros-ink);
}

.ros-table--attack td.attack-verdict {
    color: var(--ros-ink-2);
    font-size: 13px;
    white-space: normal;
    min-width: 200px;
}

/* distance dials */
.ros-text {
    font-family: var(--ros-mono-font);
    font-size: 15px;
    letter-spacing: 0.12em;
    color: var(--ros-ink);
    background: var(--ros-surface-2);
    border: 1px solid var(--ros-line);
    border-radius: 8px;
    padding: 4px 10px;
    width: 14ch;
}

.ros-text:focus {
    outline: 2px solid var(--ros-accent);
    outline-offset: 1px;
}

.ros-text--bad {
    border-color: var(--ros-target);
}

.ros-svg--distance .dial-ring {
    fill: var(--ros-surface-2);
    stroke: var(--ros-line);
    stroke-width: 1.5;
}

.ros-svg--distance .dial-tick {
    stroke: var(--ros-ink-3);
    stroke-width: 1.5;
}

.ros-svg--distance .dial--read.dial--zero .dial-ring {
    stroke: var(--ros-depth);
    stroke-width: 2.5;
}

.ros-svg--distance .dial--read.dial--one .dial-ring {
    stroke: var(--ros-target);
    stroke-width: 2.5;
}

.ros-svg--distance .dial--read .vec,
.ros-svg--distance .dial--read .vec-head {
    opacity: 0.25;
}

.ros-svg--distance .dial-digit {
    font-family: var(--ros-mono-font);
    font-size: 26px;
    font-weight: 700;
    fill: var(--ros-ink);
}

@media (max-width: 900px) {
    .ros-tiles,
    .ros-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .ros-figure-body {
        grid-template-columns: 1fr;
    }

    .ros-planner-controls {
        grid-template-columns: auto 1fr;
    }
}

@media (max-width: 640px) {
    .ros-race {
        grid-template-columns: 1fr;
    }

    .ros-tiles {
        grid-template-columns: 1fr;
    }

    .ros-tile-value {
        font-size: 34px;
    }

    .ros p,
    .ros-list li {
        font-size: 17px;
    }

    .ros-toc {
        position: static;
    }

    .ros-stage {
        margin-left: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ros-btn,
    .ros a,
    .ros-svg .stage-band {
        transition: none;
    }
}
