/* ============================================================
   Detailed project history page
   ============================================================ */

/* One editorial measure for prose across the whole page.
   Fixed cap of 640px on desktop, but always ≤ available width on small screens. */
:root {
  --hist-measure: min(640px, 100%);
}

.hist-hero {
  padding: 180px 0 80px;
  border-bottom: 1px solid var(--rule);
  position: relative;
  overflow: hidden;
}

.hist-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule) 1px, transparent 1px);
  background-size: 80px 80px;
  background-position: -1px -1px;
  opacity: 0.3;
  mask-image: radial-gradient(ellipse at 30% 60%, black 20%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse at 30% 60%, black 20%, transparent 70%);
  pointer-events: none;
}

.hist-hero > * { position: relative; z-index: 1; }

.hist-stats {
  display: flex;
  gap: 48px;
  margin-top: 80px;
  padding-top: 36px;
  border-top: 1px solid var(--rule);
  flex-wrap: wrap;
}

.hist-stat-num {
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(40px, 5vw, 64px);
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--accent);
  margin-bottom: 12px;
}

.hist-stat-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-mute);
  line-height: 1.5;
}

/* ---------- TOC ---------- */

.toc-section {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in oklab, var(--ink) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--rule);
  padding: 24px 0 0;
  margin-top: 0;
}

.toc-head {
  margin-bottom: 16px;
}

.toc {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-top: 1px solid var(--rule);
}

.toc li { display: contents; }

.toc a {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 14px 22px;
  border-right: 1px solid var(--rule);
  transition: background 0.2s, color 0.2s;
  position: relative;
}

.toc li:last-child a { border-right: 0; }

.toc a:hover { background: var(--ink-2); }
.toc a.current,
.toc a:hover .toc-years {
  color: var(--accent);
}

.toc a.current::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--accent);
}

.toc-years {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
  transition: color 0.2s;
}

.toc-role {
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: -0.01em;
  color: var(--text-mute);
  line-height: 1.3;
  font-weight: 400;
}

.toc-count {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-top: 4px;
}

@media (max-width: 1024px) {
  .toc {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    border-top: 1px solid var(--rule);
  }
  .toc a {
    min-width: 200px;
    scroll-snap-align: start;
  }
}

/* ---------- Main ---------- */

.hist-main {
  padding: 80px 0 140px;
}

.period {
  padding-top: 80px;
  scroll-margin-top: 200px;
}

.period:first-child {
  padding-top: 0;
}

.period-head {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 48px;
  align-items: baseline;
  padding-bottom: 32px;
  margin-bottom: 56px;
  border-bottom: 1px solid var(--rule-strong);
  position: relative;
}

.period-head::before {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 80px;
  height: 2px;
  background: var(--accent);
}

.period-label {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.period-role {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.1;
  letter-spacing: -0.025em;
  color: var(--text);
}

.period-intro {
  max-width: var(--hist-measure);
  margin-bottom: 56px;
  padding: 28px 32px;
  background: var(--ink-2);
  border-left: 2px solid var(--accent);
  box-sizing: border-box;
}

.period-intro p {
  font-family: var(--serif);
  font-weight: 300;
  font-size: 17px;
  line-height: 1.6;
  letter-spacing: -0.005em;
  color: var(--text);
  max-width: none;
}

.period-intro p + p { margin-top: 1em; }

.period-general {
  margin: 32px 0 36px;
  max-width: var(--hist-measure);
}

.period-general p {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-mute);
  margin-bottom: 0.9em;
}

.period-general ul {
  list-style: none;
  margin: 16px 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 4px 24px;
  padding: 0;
}

.period-general li {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--text-mute);
  padding: 6px 0;
  border-bottom: 1px dotted var(--rule);
}

/* ---------- Sub-period heading (used inside Jaune Sistemas) ---------- */

.period-subhead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 18px;
  margin: 64px 0 24px;
  padding-top: 28px;
  border-top: 1px solid var(--rule);
  max-width: var(--hist-measure);
}

.period-subhead .sub-years {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  white-space: nowrap;
}

.period-subhead .sub-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(20px, 2.4vw, 28px);
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text);
}

@media (max-width: 820px) {
  .period-subhead { gap: 8px; margin-top: 48px; }
}

/* ---------- Project list ---------- */

.proj-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 1px solid var(--rule);
}

.proj-list-control {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 14px;
}

.proj-toggle-all {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--rule-strong);
  padding: 9px 14px;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.proj-toggle-all:hover {
  border-color: var(--accent);
  background: color-mix(in oklab, var(--accent) 10%, transparent);
  color: var(--text);
}

.proj {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 32px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
  position: relative;
  transition: background 0.3s, padding 0.3s;
}

.proj:hover { background: var(--ink-2); padding-left: 16px; padding-right: 16px; margin-left: -16px; margin-right: -16px; }

/* Expanded rows breathe a bit more */
.proj.expandable.open,
.proj:not(.expandable):hover { padding-top: 16px; padding-bottom: 20px; }

.proj-num {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  padding-top: 2px;
}

.proj-body { min-width: 0; }

.proj-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(15px, 1.2vw, 17px);
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 2px;
  /* Reserve space on the right for the "Read more →" affordance */
  padding-right: 110px;
}

.proj:hover .proj-title { color: var(--accent); }

.proj-client {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-mute);
  margin-bottom: 0;
  line-height: 1.5;
}

/* Tags hidden in collapsed state — surface on hover or when open */
.proj-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 0;
  margin-bottom: 0;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.25s, opacity 0.25s, margin 0.25s;
}

.proj:hover .proj-tags,
.proj.open .proj-tags {
  max-height: 200px;
  margin-top: 10px;
  opacity: 1;
}

.proj-tag {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-mute);
  border: 1px solid var(--rule);
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
  background: color-mix(in oklab, var(--ink) 60%, transparent);
}

.proj-desc {
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text);
  max-width: var(--hist-measure);
  margin-top: 14px;
  padding-top: 18px;
  border-top: 1px dashed var(--rule);
}

/* Non-expandable rows: hide description by default, reveal on hover */
.proj:not(.expandable) .proj-desc {
  max-height: 0;
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.3s, opacity 0.3s, margin 0.3s, padding 0.3s;
}
.proj:not(.expandable):hover .proj-desc {
  max-height: 4000px;
  margin-top: 14px;
  padding-top: 18px;
  border-top: 1px dashed var(--rule);
  opacity: 1;
}

.proj-desc p {
  margin-bottom: 0.8em;
  color: var(--text);
}

.proj-desc ul {
  list-style: none;
  padding: 0;
  margin: 8px 0;
}

.proj-desc ul li {
  position: relative;
  padding: 4px 0 4px 22px;
  color: var(--text-mute);
  font-size: 14px;
  line-height: 1.6;
}

.proj-desc ul li::before {
  content: "—";
  position: absolute;
  left: 0;
  top: 4px;
  color: var(--accent);
  font-family: var(--mono);
}

.proj-desc b, .proj-desc strong {
  color: var(--text);
  font-weight: 600;
}

/* Expandable rows: description fully hidden until clicked open */
.proj.expandable .proj-desc {
  max-height: 0;
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  transition: max-height 0.3s, opacity 0.3s, margin 0.3s, padding 0.3s;
  opacity: 0;
}

.proj.expandable .proj-desc::after { display: none; }

.proj.expandable.open .proj-desc {
  max-height: 4000px;
  overflow: visible;
  opacity: 1;
  margin-top: 14px;
  padding-top: 18px;
  border-top: 1px dashed var(--rule);
}

.proj.expandable.open .proj-desc::after { display: none; }

/* "Read more" pinned to the right edge so it never adds row height */
.proj.expandable .proj-body::after {
  content: "Read more →";
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.25s, top 0.25s, transform 0.25s;
}

.proj.expandable:hover .proj-body::after { right: 16px; }

.proj.expandable.open .proj-body::after {
  content: "Show less ↑";
  top: 18px;
  transform: none;
}

@media (max-width: 820px) {
  .period-head { grid-template-columns: 1fr; gap: 16px; }
  .proj-list-control { justify-content: flex-start; margin-bottom: 10px; }
  .proj { grid-template-columns: 1fr; gap: 4px; padding: 14px 0; }
  .proj:hover { padding-left: 0; padding-right: 0; margin: 0; }
  .proj-num { padding-top: 0; font-size: 11px; opacity: 0.6; }
  /* No padding-right reservation on mobile — "Read more" is inline (see hover:none block) */
  .proj-title { padding-right: 0; font-size: 17px; }
  .hist-stats { gap: 32px; margin-top: 48px; padding-top: 24px; }
  .hist-hero { padding: 120px 0 56px; }
  .hist-hero .display-1 { margin-top: 20px !important; }
  .period-intro { padding: 22px 20px; margin-bottom: 36px; }
  .period-intro p { font-size: 15px; }
  .period-general { margin: 24px 0 28px; }
  .hist-main { padding: 56px 0 80px; }
  .period { padding-top: 56px; scroll-margin-top: 160px; }
  .toc-section { padding: 16px 0 0; }
  .toc-head { margin-bottom: 12px; }
  .toc { padding: 0 var(--gutter); scroll-padding-left: var(--gutter); }
  .toc a { min-width: 170px; padding: 14px 12px 16px; }
  .toc-role { font-size: 12px; }
  /* On narrow viewports "Read more" goes inline so it can't collide with a wrapped title */
  .proj.expandable .proj-body::after {
    position: static;
    display: inline-block;
    top: auto;
    transform: none;
    margin-top: 6px;
  }
}

@media (max-width: 480px) {
  .proj-title { font-size: 16px; line-height: 1.3; }
  .proj-tag { font-size: 11px; }
  .period-intro { padding: 18px 16px; }
  .period-general ul { grid-template-columns: 1fr; }
  .hist-stat-num { font-size: 36px; }
  .hist-stats { gap: 24px; }
  .period-role { font-size: 26px; line-height: 1.15; }
}

/* Touch devices have no :hover — surface tags + descriptions inline,
   small enough not to bloat the row but always visible. */
@media (hover: none) {
  .proj-tags { max-height: 200px; opacity: 1; margin-top: 8px; }
  .proj:not(.expandable) .proj-desc {
    max-height: 4000px;
    margin-top: 12px;
    padding-top: 14px;
    border-top: 1px dashed var(--rule);
    opacity: 1;
  }
  /* "Read more" on touch is the tap target; pin it inline so it's reachable */
  .proj.expandable .proj-body::after {
    position: static;
    display: inline-block;
    margin-top: 8px;
    transform: none;
  }
  .proj.expandable.open .proj-body::after { top: auto; }
  /* Disable the hover-padding shift since it just adds jitter on tap */
  .proj:hover { padding-left: 0; padding-right: 0; margin: 0; background: transparent; }
}

/* Override main script's smooth-scroll offset – we have a sticky toc */
html { scroll-padding-top: 220px; }

@media (max-width: 1024px) {
  html { scroll-padding-top: 280px; }
}
