/* mahmoud.tasarro.co.uk v5 — Swiss Modernism × engineering-drawing, refined.
   v5 adds: self-hosted variable fonts (OFL), page frame with registration
   marks, MuJoCo render + ART autotuner figures. */

@font-face {
  font-family: "Archivo";
  src: url("fonts/archivo.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/jetbrains-mono.woff2") format("woff2");
  font-weight: 100 800;
  font-display: swap;
}

:root {
  --paper: #F4F2EC;
  --ink: #16181B;
  --muted: #6B6659;
  --rule: #C9C4B8;
  --accent: #B5321C;
  --chart-ink: #2A2E33;
  --term: #101215;
  --term-ink: #D8E0EA;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --sans: "Archivo", "Helvetica Neue", Helvetica, Inter, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17181A;
    --ink: #E7E4DC;
    --muted: #A5A093;
    --rule: #3A3B3E;
    --accent: #E87B63;
    --chart-ink: #D8D5CC;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  counter-reset: fig;
}

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: var(--paper);
  padding: 0.5rem 1rem; z-index: 10; font-family: var(--mono);
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 76rem; margin: 0 auto; padding: 0 1.25rem; }

a { color: inherit; }

/* ── nav: a thin drawing-border strip ── */
.site-nav {
  position: sticky; top: 0; z-index: 5;
  background: var(--paper);
  border-bottom: 2px solid var(--ink);
}
.site-nav .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; min-height: 2.9rem;
}
.nav-name {
  font-family: var(--mono); font-weight: 700; font-size: 0.85rem;
  color: var(--ink); text-decoration: none; text-transform: uppercase;
  letter-spacing: 0.08em;
}
.site-nav ul { display: flex; gap: 1.4rem; list-style: none; padding: 0; flex-wrap: wrap; }
.site-nav ul a {
  font-family: var(--mono); font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--muted); text-decoration: none;
  transition: color 120ms linear;
}
.site-nav ul a:hover { color: var(--accent); }

/* ── title block (engineering-drawing header) ── */
.hero { padding: 2.4rem 0 0; }
.titleblock {
  border: 2px solid var(--ink);
  display: grid;
  grid-template-columns: repeat(12, 1fr);
}
.tb-cell {
  border-right: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 0.5rem 0.75rem 0.6rem;
  min-width: 0;
}
.tb-cell:last-child, .tb-cell.endrow { border-right: 0; }
.tb-cell .lbl {
  display: block; font-family: var(--mono); font-size: 0.6rem;
  text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted);
  margin-bottom: 0.15rem;
}
.tb-cell .val { font-size: 0.92rem; }
.tb-cell .val a { color: var(--accent); text-decoration: none; }
.tb-cell .val a:hover { text-decoration: underline; text-underline-offset: 3px; }
.tb-name { grid-column: 1 / 9; border-bottom: 1px solid var(--rule); }
.tb-name h1 {
  font-family: var(--sans); font-weight: 800;
  font-size: clamp(2rem, 5.5vw, 3.1rem);
  line-height: 0.98; letter-spacing: -0.02em; text-transform: uppercase;
}
.tb-name .role { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); margin-top: 0.45rem; }
.tb-rev { grid-column: 9 / 11; }
.tb-date { grid-column: 11 / 13; }
.tb-degree { grid-column: 1 / 5; border-bottom: 0; }
.tb-loc { grid-column: 5 / 9; border-bottom: 0; }
.tb-contact { grid-column: 9 / 13; border-bottom: 0; }
@media (max-width: 720px) {
  .tb-name { grid-column: 1 / 13; }
  .tb-rev { grid-column: 1 / 7; }
  .tb-date { grid-column: 7 / 13; }
  .tb-degree, .tb-loc, .tb-contact { grid-column: 1 / 13; border-bottom: 1px solid var(--rule); }
  .tb-contact { border-bottom: 0; }
  .tb-cell { border-right: 0; }
}

/* ── abstract row (asymmetric) ── */
.row { display: grid; grid-template-columns: repeat(12, 1fr); gap: 1.25rem; }
.c-left { grid-column: 1 / 4; }
.c-main { grid-column: 4 / 13; }
@media (max-width: 860px) { .c-left, .c-main { grid-column: 1 / 13; } .c-left { margin-bottom: -0.6rem; } }
.abstract { padding: 1.6rem 0 0.6rem; }
.marginlabel {
  font-family: var(--mono); font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--muted); padding-top: 0.2rem;
}
.lede { max-width: 44rem; font-size: 1.08rem; }

/* ── spec table (stats) ── */
.stats { padding: 1.6rem 0 0; }
.spec-caption {
  font-family: var(--mono); font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--muted); margin-bottom: 0.4rem;
}
.stats .wrap-inner {
  border: 2px solid var(--ink);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}
.stat { border-right: 1px solid var(--rule); padding: 0.9rem 1rem 1rem; min-width: 0; }
.stat:last-child { border-right: 0; }
@media (max-width: 860px) { .stat { border-right: 0; border-bottom: 1px solid var(--rule); } .stat:last-child { border-bottom: 0; } }
.stat b {
  display: block; font-family: var(--mono); font-size: 1.75rem; font-weight: 700;
  color: var(--accent); line-height: 1.15;
}
.stat span { font-size: 0.8rem; color: var(--muted); }

/* ── numbered section heads ── */
section { padding: 3rem 0 0.25rem; }
.sec-head {
  display: flex; align-items: baseline; gap: 0.9rem;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 0.45rem; margin-bottom: 0.25rem;
}
.secnum { font-family: var(--mono); font-size: 0.95rem; font-weight: 700; color: var(--accent); }
.sec-head h2 {
  font-family: var(--sans); font-weight: 800; font-size: 1.35rem;
  text-transform: uppercase; letter-spacing: 0.01em;
}

/* ── projects: flat numbered entries, no cards ── */
.project { border-bottom: 1px solid var(--rule); padding: 1.9rem 0 2rem; }
.project-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 1.25rem; }
.project h3 {
  font-family: var(--sans); font-weight: 700; font-size: 1.22rem;
  margin-bottom: 0.75rem; letter-spacing: -0.01em;
}
.pnum { font-family: var(--mono); color: var(--accent); font-size: 0.95rem; margin-right: 0.5rem; }
.tags { list-style: none; padding: 0; margin: 0 0 1rem; }
.tags li {
  display: inline-block; font-family: var(--mono); font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted);
  margin-right: 0.9rem;
}
.tags li::before { content: "/ "; color: var(--accent); }
.project p { max-width: 46rem; margin-bottom: 0.85rem; }
.project p:last-child { margin-bottom: 0; }
.project .aside { font-family: var(--mono); font-size: 0.74rem; color: var(--muted); }
.project a { color: var(--accent); text-decoration: none; }
.project a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ── figures with drawing numbers ── */
.figures {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1.25rem; margin: 1.3rem 0 1rem;
}
.figures figure { margin: 0; border: 1px solid var(--rule); padding: 0.6rem; }
.figures img {
  width: 100%; height: 13.5rem; object-fit: cover; display: block;
  filter: none;
}
.figures figcaption, .consolefig figcaption {
  font-family: var(--mono); font-size: 0.7rem; color: var(--muted);
  margin-top: 0.5rem; line-height: 1.5;
}
.figures figcaption::before, .consolefig figcaption::before {
  counter-increment: fig;
  content: "FIG. " counter(fig) " — ";
  color: var(--accent); font-weight: 700;
}

/* ── terminals: the only dark objects on the paper ── */
.consolefig { margin: 1.3rem 0 1rem; }
.console, .proto-exchange {
  background: var(--term);
  border: 1px solid var(--ink);
  padding: 1rem 1.1rem;
  font-family: var(--mono); font-size: 0.78rem; line-height: 1.7;
  color: var(--term-ink);
  overflow-x: auto; margin: 0;
}
.console { min-height: 11.5rem; }
.console .ok { color: #4CC98A; }
.console .dim { color: #8B96A5; }
.console .sum { color: var(--term-ink); font-weight: 700; }
.console.cursor::after { content: "▌"; color: #4CC98A; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.proto-exchange { line-height: 1.8; margin-bottom: 0.9rem; }
.proto-exchange .host { color: #6AA5FF; }
.proto-exchange .dev { color: #4CC98A; }
.proto-exchange .err { color: #E89B5B; }

/* ── chart/viz frames: figure objects, not cards ── */
.chart-card { border: 1px solid var(--rule); padding: 0.9rem 1.1rem 0.9rem; margin: 1.3rem 0 1rem; }
.chart-card h4 {
  font-family: var(--mono); font-size: 0.74rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  border-bottom: 1px solid var(--rule); padding-bottom: 0.45rem; margin-bottom: 0.3rem;
}
.chart-card h4::before { counter-increment: fig; content: "FIG. " counter(fig) " — "; color: var(--accent); }
.chart-card .sub { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); margin-bottom: 0.7rem; }
.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.chart-wrap .grid { stroke: var(--rule); stroke-width: 1; }
.chart-wrap .tick { fill: var(--muted); font-family: var(--mono); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart-wrap .meanline { stroke: var(--accent); stroke-width: 1; }
.chart-wrap .meanlabel { fill: var(--accent); font-family: var(--mono); font-size: 10px; }
.chart-wrap .series { stroke: var(--chart-ink); stroke-width: 2; fill: none; }
.chart-wrap .dot { fill: var(--chart-ink); }
.chart-wrap .crosshair { stroke: var(--muted); stroke-width: 1; opacity: 0.7; }
.chart-wrap .hidot { fill: var(--accent); stroke: var(--paper); stroke-width: 2; }
.chart-tip {
  position: absolute; pointer-events: none;
  background: var(--paper); border: 1px solid var(--ink);
  padding: 0.3rem 0.55rem; font-family: var(--mono); font-size: 0.72rem;
  color: var(--ink); transform: translate(-50%, -130%);
  white-space: nowrap; display: none; z-index: 2;
}
.chart-note { font-size: 0.8rem; color: var(--muted); margin-top: 0.6rem; max-width: 46rem; }
details.chart-table { margin-top: 0.6rem; }
details.chart-table summary { font-family: var(--mono); font-size: 0.72rem; color: var(--accent); cursor: pointer; text-transform: uppercase; letter-spacing: 0.08em; }
details.chart-table .tscroll { max-height: 14rem; overflow: auto; margin-top: 0.5rem; border: 1px solid var(--rule); }
details.chart-table table { border-collapse: collapse; width: 100%; }
details.chart-table th, details.chart-table td {
  text-align: left; padding: 0.25rem 0.7rem; border-bottom: 1px solid var(--rule);
  font-family: var(--mono); font-size: 0.72rem; font-variant-numeric: tabular-nums;
}
details.chart-table th { position: sticky; top: 0; background: var(--paper); color: var(--muted); font-weight: 400; }

/* FIC timeline */
.commitdot { fill: var(--chart-ink); }
.commitcount { fill: var(--paper); font-family: var(--mono); font-size: 10px; font-weight: 700; }

/* rv32ui grid */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.rv-grid { display: grid; gap: 0.45rem; margin: 0.2rem 0 0.6rem; }
.rv-row { display: flex; gap: 0.8rem; align-items: baseline; flex-wrap: wrap; }
.rv-group { font-family: var(--mono); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); flex: 0 0 10rem; }
.rv-tiles { display: flex; flex-wrap: wrap; gap: 0.3rem; flex: 1; min-width: 14rem; }
.rv-tile {
  font-family: var(--mono); font-size: 0.72rem; color: var(--ink);
  border: 1px solid var(--rule); padding: 0.14rem 0.45rem; cursor: default;
}
.rv-tile .g { margin-right: 0.3rem; font-weight: 700; }
.rv-tile.pass .g { color: #177245; }
.rv-tile.fail .g { color: #B4530A; }
.rv-tile.fail { border-color: #B4530A; }
.rv-tile.skip, .rv-tile.skip .g { color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .rv-tile.pass .g { color: #4CC98A; }
  .rv-tile.fail .g { color: #E89B5B; }
  .rv-tile.fail { border-color: #E89B5B; }
}
.rv-notes { font-size: 0.8rem; color: var(--muted); margin-top: 0.4rem; }

/* protocol chips + arch layers: flat spec buttons */
.proto-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.6rem; }
.proto-chip, .arch-layer {
  font-family: var(--mono); color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  cursor: pointer;
  transition: border-color 120ms linear, color 120ms linear;
}
.proto-chip { font-size: 0.72rem; padding: 0.2rem 0.55rem; }
.proto-chip:hover, .arch-layer:hover { border-color: var(--accent); }
.proto-chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
#proto-info { min-height: 2.6rem; font-size: 0.85rem; color: var(--muted); max-width: 44rem; margin-bottom: 0; }

.arch-title {
  font-family: var(--mono); font-size: 0.74rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em; margin: 1.4rem 0 0.6rem;
}
.arch { display: grid; gap: 0.4rem; margin: 0 0 0.6rem; max-width: 36rem; }
.arch-layer { display: block; width: 100%; text-align: left; border-left: 3px solid var(--rule); padding: 0.5rem 0.9rem; font-size: 0.8rem; }
.arch-layer[aria-pressed="true"] { border-left-color: var(--accent); color: var(--accent); }
.arch-layer .ll { display: block; color: var(--muted); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em; }
#arch-info { min-height: 3.4rem; font-size: 0.88rem; color: var(--muted); max-width: 36rem; margin-bottom: 0; }

/* ── research ── */
.papers { list-style: none; padding: 0; max-width: 46rem; }
.papers li { border-left: 2px solid var(--accent); padding: 0.1rem 0 0.1rem 1rem; margin: 1.2rem 0; }
.papers .status { font-family: var(--mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); display: block; margin-top: 0.15rem; }

/* ── skills: spec sheet rows ── */
.skills { max-width: 60rem; }
.skills div { display: grid; grid-template-columns: 11rem 1fr; gap: 1rem; border-bottom: 1px solid var(--rule); padding: 0.55rem 0; }
@media (max-width: 640px) { .skills div { grid-template-columns: 1fr; gap: 0.1rem; } }
.skills h3 {
  font-family: var(--mono); font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted);
  padding-top: 0.2rem;
}
.skills p { font-size: 0.92rem; }

/* ── about / footer ── */
.about p { max-width: 44rem; margin-bottom: 0.85rem; }

footer { border-top: 2px solid var(--ink); margin-top: 3.2rem; padding: 1.6rem 0 2.6rem; }
footer .contact { display: flex; flex-wrap: wrap; gap: 1.6rem; margin: 0.5rem 0 1.4rem; }
footer a { color: var(--accent); text-decoration: none; font-family: var(--mono); font-size: 0.85rem; }
footer a:hover { text-decoration: underline; text-underline-offset: 3px; }
footer .fine {
  font-family: var(--mono); font-size: 0.66rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.12em;
  border-top: 1px solid var(--rule); padding-top: 0.8rem;
}

@media (max-width: 640px) {
  .figures img { height: 11rem; }
  .project { padding: 1.4rem 0 1.5rem; }
}

/* ── v5 refinements ────────────────────────────────────────── */

/* fixed drawing frame with registration corners (wide screens only) */
.pageframe {
  position: fixed; inset: 10px;
  border: 1px solid var(--rule);
  pointer-events: none; z-index: 50;
}
.pageframe::before, .pageframe::after {
  content: ""; position: absolute; width: 14px; height: 14px;
  border-color: var(--ink); border-style: solid;
}
.pageframe::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.pageframe::after { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }
@media (max-width: 900px) { .pageframe { display: none; } }

/* photos slightly desaturated toward the paper; renders/graphics untouched */
.figures img { filter: grayscale(0.15) contrast(1.02); }
.figures figure.nofx img { filter: none; }

/* wide single-figure variant (the MuJoCo render) */
.figures.single { grid-template-columns: 1fr; }
.figures.single img { height: auto; max-height: 24rem; object-fit: contain; }

/* display type: Archivo's heavier voice */
.tb-name h1 { font-weight: 800; letter-spacing: -0.025em; }
.sec-head h2 { letter-spacing: 0.005em; }

/* ART autotuner panels */
.art-panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1.25rem; margin-bottom: 0.4rem; }
.art-t { font-family: var(--mono); font-size: 0.7rem; color: var(--muted); margin-bottom: 0.25rem; }
.art-panel svg { width: 100%; height: auto; display: block; }
.art-panel .axis { stroke: var(--rule); stroke-width: 1; }
.art-panel .tick { fill: var(--muted); font-family: var(--mono); font-size: 10px; font-variant-numeric: tabular-nums; }
.art-panel .series { stroke: var(--chart-ink); stroke-width: 2; fill: none; }
.art-panel .dot { fill: var(--chart-ink); }
.art-panel .dot:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.art-panel .endlabel { fill: var(--ink); font-family: var(--mono); font-size: 10px; font-variant-numeric: tabular-nums; }
