:root {
  scroll-behavior: smooth;
}

.history-shell {
  --history-rule: color-mix(in srgb, var(--panel-border) 72%, transparent);
  --history-paper: color-mix(in srgb, var(--panel-flat) 90%, transparent);
  --history-hero-ink: #f4eedb;
  --history-hero-muted: #cec7ad;
  --history-olive: #313b25;
  --history-olive-deep: #1d2417;
}

.history-view {
  display: none;
}

.history-view--active {
  display: block;
}

.history-load-error {
  max-width: 1080px;
  margin: 36px auto;
  padding: 28px 24px;
  color: var(--ink);
  text-align: center;
}

body.night .history-shell {
  --history-paper: rgba(14, 19, 12, 0.82);
  --history-hero-ink: #e6cd7a;
  --history-hero-muted: #94b8a5;
  --history-olive: #10150e;
  --history-olive-deep: #080b07;
}

.history-shell .site-header-row {
  max-width: 1080px;
}

.history-shell .site-brand,
.history-shell .nav-button {
  text-decoration: none;
}

.history-shell .site-brand:hover,
.history-shell .site-brand:focus-visible,
.history-shell .nav-button:hover,
.history-shell .nav-button:focus-visible {
  text-decoration: none;
}

.history-shell .nav-button {
  white-space: nowrap;
}

.history-shell .theme-button {
  line-height: normal;
}

.history-progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 80;
  height: 3px;
  pointer-events: none;
}

.history-progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent-bright);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent-bright) 70%, transparent);
  transform: scaleX(0);
  transform-origin: left center;
}

.history-page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 34px 24px 72px;
}

.history-hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: clamp(32px, 6vw, 72px);
  color: var(--history-hero-ink);
  border: var(--border-w) solid var(--panel-border);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px) 0 0 / 42px 42px,
    radial-gradient(circle at 84% 18%, rgba(200, 169, 81, 0.25), transparent 30%),
    linear-gradient(145deg, var(--history-olive), var(--history-olive-deep));
  box-shadow: var(--panel-shadow);
}

.history-hero-grid {
  display: grid;
  align-items: end;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
  gap: clamp(28px, 5vw, 72px);
}

.history-eyebrow,
.history-section-number,
.history-chart-kicker,
.history-rail > p {
  margin: 0;
  color: var(--accent-bright);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.history-hero h1 {
  max-width: 780px;
  margin: 14px 0 20px;
  font-family: var(--font-display);
  font-size: clamp(40px, 6.4vw, 76px);
  line-height: 0.97;
  letter-spacing: -0.045em;
}

.history-hero h1 span {
  color: var(--accent-bright);
}

body.night .history-hero h1 {
  font-size: clamp(32px, 5.2vw, 58px);
  line-height: 1.15;
  letter-spacing: -0.025em;
  text-shadow: var(--header-glow);
}

.history-deck {
  max-width: 720px;
  margin: 0;
  color: var(--history-hero-muted);
  font-size: clamp(16px, 2vw, 20px);
  line-height: 1.58;
}

.history-hero-aside {
  display: flex;
  min-width: 0;
  align-self: stretch;
  flex-direction: column;
  justify-content: space-between;
  gap: clamp(24px, 4vw, 42px);
}

.history-hero-mark {
  display: block;
  width: min(100%, 240px);
  margin: auto auto 0;
  aspect-ratio: 1;
  background: #000;
  -webkit-mask: url("../assets/images/modathon-brand-mark.png") center / contain no-repeat;
  mask: url("../assets/images/modathon-brand-mark.png") center / contain no-repeat;
  opacity: 0.9;
  filter: drop-shadow(0 0 14px color-mix(in srgb, var(--accent-bright) 24%, transparent));
  pointer-events: none;
  user-select: none;
}

body:not(.night) .history-hero-mark {
  background: #c8a951;
  filter:
    drop-shadow(-1px -1px 0 rgba(230, 205, 122, 0.62))
    drop-shadow(1px 2px 2px rgba(35, 32, 26, 0.42))
    drop-shadow(0 0 14px color-mix(in srgb, var(--accent-bright) 24%, transparent));
}

.history-hero-ledger {
  display: grid;
  border-top: 1px solid rgba(230, 205, 122, 0.36);
}

.history-hero-ledger div {
  display: grid;
  padding: 17px 0;
  border-bottom: 1px solid rgba(230, 205, 122, 0.36);
  grid-template-columns: 86px 1fr;
  gap: 14px;
}

.history-hero-ledger strong {
  color: var(--accent-bright);
  font-family: var(--font-display);
  font-size: 25px;
  line-height: 1;
}

.history-hero-ledger span {
  color: var(--history-hero-muted);
  font-size: 12px;
  line-height: 1.35;
  text-transform: uppercase;
}

.history-hero-intro {
  display: grid;
  margin-top: clamp(34px, 6vw, 62px);
  padding-top: 30px;
  border-top: 1px solid rgba(230, 205, 122, 0.36);
  grid-template-columns: minmax(0, 1.12fr) minmax(280px, 0.88fr);
  gap: clamp(28px, 5vw, 60px);
}

.history-hero-intro p {
  margin: 0 0 14px;
  color: var(--history-hero-muted);
  font-size: 15px;
  line-height: 1.7;
}

.history-hero-intro blockquote {
  margin: 0;
  padding-left: 24px;
  color: var(--history-hero-ink);
  border-left: 3px solid var(--accent-bright);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.6;
}

.history-hero-intro blockquote footer {
  margin-top: 15px;
  color: var(--accent-bright);
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.history-layout {
  display: grid;
  margin-top: 44px;
  align-items: start;
  grid-template-columns: 188px minmax(0, 1fr);
  gap: clamp(34px, 6vw, 78px);
}

.history-rail {
  position: sticky;
  top: calc(var(--site-header-offset) + 26px);
}

.history-rail > p {
  margin-bottom: 14px;
}

.history-rail nav {
  display: grid;
  border-top: 1px solid var(--history-rule);
}

.history-rail a {
  display: grid;
  padding: 9px 2px;
  align-items: center;
  color: var(--muted);
  border-bottom: 1px solid var(--history-rule);
  font-size: 12px;
  font-weight: 600;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 7px;
  transition: color 140ms ease, padding-left 140ms ease;
}

.history-rail a span {
  color: var(--soft);
  font-family: var(--font-flavor);
  font-size: 14px;
}

.history-rail a:hover,
.history-rail a:focus-visible,
.history-rail a.is-active {
  padding-left: 7px;
  color: var(--accent);
  text-decoration: none;
}

.history-rail a.is-active span {
  color: var(--accent-bright);
}

.history-article {
  min-width: 0;
  max-width: 860px;
}

.history-section {
  padding: 0 0 72px;
  scroll-margin-top: calc(var(--site-header-offset) + 28px);
}

.history-section + .history-section {
  padding-top: 12px;
  border-top: 1px solid var(--history-rule);
}

.history-section-heading {
  margin: 32px 0 30px;
}

.history-section:first-child .history-section-heading {
  margin-top: 0;
}

.history-section-number {
  display: block;
  margin-bottom: 10px;
}

.history-section h2 {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(28px, 4vw, 43px);
  line-height: 1.12;
  letter-spacing: -0.025em;
}

body.night .history-section h2 {
  font-size: clamp(23px, 3.2vw, 34px);
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.history-year-heading {
  display: flex;
  margin: 54px 0 20px;
  align-items: center;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 31px;
  gap: 16px;
  scroll-margin-top: calc(var(--site-header-offset) + 28px);
}

.history-year-heading::after {
  height: 1px;
  content: '';
  background: var(--history-rule);
  flex: 1;
}

.history-article > .history-section > p,
.history-section > p {
  max-width: 74ch;
  margin: 0 0 1.15em;
  font-size: clamp(16px, 1.6vw, 18px);
  line-height: 1.78;
}

.history-section > p a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.history-section > p a:hover,
.history-section > p a:focus-visible {
  color: var(--accent-bright);
  text-decoration-color: currentColor;
}

.history-pullquote {
  max-width: none !important;
  margin: 34px 0 !important;
  padding: 24px clamp(22px, 4vw, 40px);
  color: var(--tile-ink);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--tile-2);
  box-shadow: var(--panel-shadow);
  font-family: var(--font-display);
  font-size: clamp(20px, 3vw, 29px) !important;
  font-weight: 700;
  line-height: 1.35 !important;
  text-align: center;
}

.history-finale-line {
  max-width: none !important;
  margin: 0 !important;
  padding: 26px clamp(24px, 5vw, 48px);
  color: var(--tile-ink);
  border-right: 1px solid var(--accent);
  border-left: 1px solid var(--accent);
  background: var(--tile-1);
  font-size: clamp(18px, 2.4vw, 24px) !important;
  font-weight: 700;
  line-height: 1.55 !important;
  text-align: center;
}

.history-finale-line:nth-last-of-type(3) {
  margin-top: 46px !important;
  padding-top: 42px;
  border: 1px solid var(--accent);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}

.history-finale-line:last-of-type {
  padding-bottom: 42px;
  color: var(--accent-bright);
  border: 1px solid var(--accent);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}

.history-figure {
  width: 100%;
  margin: 36px auto 42px;
}

.history-image-button {
  position: relative;
  display: block;
  overflow: hidden;
  box-sizing: border-box;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 0;
  color: inherit;
  border: var(--border-w) solid var(--panel-border);
  border-radius: var(--radius);
  background: transparent;
  box-shadow: var(--panel-shadow);
  cursor: zoom-in;
}

.history-image-button img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 760px;
  margin: 0 auto;
  object-fit: contain;
  transition: transform 240ms ease, filter 240ms ease;
}

body.night .history-image-button {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.history-image-button:hover img,
.history-image-button:focus-visible img {
  filter: brightness(1.05);
  transform: scale(1.012);
}

.history-image-button:focus-visible {
  outline: 3px solid var(--accent-bright);
  outline-offset: 3px;
}

.history-figure figcaption {
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.history-figure--portrait {
  max-width: 560px;
  margin-right: auto;
  margin-left: auto;
}

.history-figure--strip {
  max-width: 720px;
}

.history-chart {
  overflow: hidden;
  margin: 38px 0 46px;
  border: var(--border-w) solid var(--panel-border);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--panel-border) 14%, transparent) 1px, transparent 1px) 0 0 / 20% 100%,
    var(--history-paper);
  box-shadow: var(--panel-shadow);
}

.history-chart-header {
  display: flex;
  padding: 18px 20px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: var(--border-w) solid var(--panel-border);
  background: var(--panel);
}

.history-chart-header > span {
  display: grid;
  gap: 4px;
}

.history-chart-header strong {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 18px;
}

.history-chart-sort {
  padding: 7px 10px;
  color: var(--chip-ink);
  border: 1px solid var(--chip-border);
  border-radius: var(--pill-r);
  background: var(--chip-bg);
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.history-chart-sort:hover,
.history-chart-sort:focus-visible,
.history-chart-sort[aria-pressed='true'] {
  color: var(--nav-active-ink);
  border-color: var(--nav-active-border);
  outline: none;
  background: var(--nav-active-bg);
}

.history-bars {
  display: grid;
  margin: 0;
  padding: 20px;
  gap: 9px;
  list-style: none;
}

.history-bar-row {
  display: grid;
  min-height: 26px;
  align-items: center;
  grid-template-columns: minmax(170px, 0.9fr) minmax(170px, 1.5fr) 34px;
  gap: 12px;
  border-radius: 3px;
}

.history-bar-row:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 3px;
}

.history-bar-label {
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
}

.history-bar-track {
  position: relative;
  overflow: hidden;
  height: 12px;
  border: 1px solid color-mix(in srgb, var(--panel-border) 74%, transparent);
  background: var(--bar-bg);
}

.history-bar-fill {
  display: block;
  width: var(--bar-size);
  height: 100%;
  background: var(--bar-fill);
  box-shadow: var(--bar-glow);
  transform-origin: left center;
  animation: historyBarReveal 680ms cubic-bezier(0.2, 0.76, 0.24, 1) both;
}

.history-bar-row:hover .history-bar-fill,
.history-bar-row:focus-visible .history-bar-fill {
  filter: brightness(1.16);
}

.history-bar-value {
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 15px;
  text-align: right;
}

@keyframes historyBarReveal {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.history-lightbox {
  width: min(1280px, calc(100vw - 48px));
  max-width: none;
  height: min(900px, calc(100vh - 48px));
  max-height: none;
  padding: 50px 20px 18px;
  color: #f3ecd8;
  border: 1px solid #8a6d2a;
  background: #0d0f0a;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.7);
}

.history-lightbox::backdrop {
  background: rgba(5, 5, 3, 0.88);
  backdrop-filter: blur(5px);
}

.history-lightbox[open] {
  display: grid;
  box-sizing: border-box;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
}

.history-lightbox img {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
}

.history-lightbox p {
  margin: 0;
  color: #c9c3ae;
  font-size: 13px;
  text-align: center;
}

.history-lightbox-close {
  position: absolute;
  top: 12px;
  right: 14px;
  padding: 7px 10px;
  color: #e6cd7a;
  border: 1px solid #8a6d2a;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.history-lightbox-close:hover,
.history-lightbox-close:focus-visible {
  color: #17130a;
  outline: none;
  background: #e6cd7a;
}

.history-footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 46px;
  color: var(--muted);
}

@media (max-width: 980px) {
  .history-shell .site-header-row {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .history-shell .site-brand {
    order: 1;
  }

  .history-shell .site-header-row > mms-site-switcher {
    order: 2;
    margin-left: auto;
  }

  .history-shell .site-nav {
    width: 100%;
    max-width: 100%;
    padding-bottom: 4px;
    order: 3;
    overflow-x: auto;
  }

  .history-hero-grid,
  .history-hero-intro {
    grid-template-columns: 1fr;
  }

  .history-hero-aside {
    display: grid;
    align-items: center;
    grid-template-columns: minmax(120px, 170px) minmax(0, 1fr);
    gap: clamp(28px, 6vw, 54px);
  }

  .history-hero-mark {
    width: 100%;
    margin: 0;
  }

  .history-hero-ledger {
    grid-template-columns: repeat(3, 1fr);
  }

  .history-hero-ledger div {
    align-content: start;
    border-right: 1px solid rgba(230, 205, 122, 0.36);
    grid-template-columns: 1fr;
  }

  .history-hero-ledger div:last-child {
    border-right: 0;
  }

  .history-layout {
    grid-template-columns: 1fr;
    gap: 34px;
  }

  .history-rail {
    position: static;
    z-index: 40;
    margin: 0 -24px;
    padding: 10px 24px 8px;
    background: var(--sticky-bg);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
  }

  .history-rail > p {
    display: none;
  }

  .history-rail nav {
    display: flex;
    overflow-x: auto;
    border: 0;
    gap: 7px;
    scrollbar-width: thin;
  }

  .history-rail a {
    display: inline-flex;
    padding: 7px 10px;
    border: 1px solid var(--chip-border);
    border-radius: var(--pill-r);
    background: var(--chip-bg);
    flex: 0 0 auto;
  }

  .history-rail a:hover,
  .history-rail a:focus-visible,
  .history-rail a.is-active {
    padding-left: 10px;
    color: var(--nav-active-ink);
    border-color: var(--nav-active-border);
    background: var(--nav-active-bg);
  }

  .history-article {
    max-width: none;
  }

  .history-section {
    scroll-margin-top: 70px;
  }
}

@media (max-width: 680px) {
  .history-page {
    padding: 20px 14px 54px;
  }

  .history-hero {
    padding: 28px 20px 32px;
  }

  .history-hero h1 br {
    display: none;
  }

  .history-hero-aside {
    grid-template-columns: 1fr;
    gap: 26px;
  }

  .history-hero-mark {
    width: min(48vw, 150px);
    margin: 0 auto;
  }

  .history-hero-ledger {
    grid-template-columns: 1fr;
  }

  .history-hero-ledger div {
    border-right: 0;
    grid-template-columns: 74px 1fr;
  }

  .history-hero-intro blockquote {
    padding-left: 18px;
  }

  .history-layout {
    margin-top: 28px;
  }

  .history-rail {
    margin: 0 -14px;
    padding-right: 14px;
    padding-left: 14px;
  }

  .history-section {
    padding-bottom: 50px;
  }

  .history-section-heading {
    margin-top: 22px;
  }

  .history-bar-row {
    padding: 5px 0 8px;
    grid-template-columns: minmax(0, 1fr) 34px;
    gap: 5px 10px;
  }

  .history-bar-label {
    font-size: 11px;
  }

  .history-bar-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .history-bar-value {
    grid-column: 2;
    grid-row: 1;
  }

  .history-chart-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .history-chart-sort {
    white-space: normal;
  }

  .history-bars {
    padding: 16px;
    gap: 4px;
  }

  .history-lightbox {
    width: calc(100vw - 20px);
    height: calc(100vh - 20px);
    padding-right: 10px;
    padding-left: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    scroll-behavior: auto;
  }

  .history-bar-fill,
  .history-image-button img,
  .history-rail a {
    animation: none;
    transition: none;
  }
}

@media print {
  .history-progress,
  .history-shell .site-header,
  .history-rail,
  .history-chart-sort,
  .history-footer {
    display: none !important;
  }

  .history-page {
    max-width: none;
    padding: 0;
  }

  .history-hero,
  .history-chart,
  .history-image-button {
    box-shadow: none;
  }

  .history-layout {
    display: block;
  }

  .history-section {
    break-before: page;
  }
}
