/* Font faces */
@font-face {
  font-family: "Instrument Serif";
  src: url("../fonts/InstrumentSerif-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Instrument Serif";
  src: url("../fonts/InstrumentSerif-Italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/InstrumentSans-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/InstrumentSans-Italic-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

/* Base reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
}

/* Chart container and hover styles */
.chart-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.chart-container svg {
  max-width: 100%;
  height: auto;
}

.chart-hoverable {
  cursor: pointer;
  transition: opacity 0.15s;
}

.chart-hoverable:hover {
  opacity: 1 !important;
}

/* Base */
html {
  font-family: var(--font-sans);
  font-size: 18px;
  line-height: 1.6;
  background: var(--color-bg);
  color: var(--color-text);
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

/* Shared header styles */
.site-header,
.panel-header {
  height: var(--header-height);
  padding: 0 2rem;
  border-bottom: 1px solid var(--push-10);
  background: var(--color-bg);
}

/* Site header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.site-branding {
  min-width: 0;
}

.site-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.125rem;
}

.site-tagline {
  font-size: 0.8125rem;
  color: var(--push-50);
  font-style: italic;
}

/* Filters */
.site-filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  max-width: 600px;
  justify-content: center;
  padding: 0 1rem;
}

.filter-categories {
  display: flex;
  gap: 0.375rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.filter-categories::-webkit-scrollbar {
  display: none;
}

.filter-btn {
  background: none;
  border: 1px solid var(--push-10);
  color: var(--push-80);
  padding: 0.25rem 0.625rem;
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.filter-btn:hover {
  color: var(--color-text);
  border-color: var(--color-text);
}

.filter-btn.active {
  background: var(--color-text);
  color: var(--color-bg);
  border-color: var(--color-text);
}

/* Sort button label */
[data-sort="default"]::after { content: ''; }
[data-sort="date"]::after { content: ' ↓'; font-size: 0.625rem; }
[data-sort="alpha"]::after { content: ' Az'; font-size: 0.625rem; }

/* Search */
.search-wrapper {
  display: flex;
  align-items: center;
  gap: 0;
}

.search-input {
  width: 0;
  opacity: 0;
  padding: 0;
  border: none;
  border-bottom: 1px solid transparent;
  background: none;
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.8125rem;
  outline: none;
  transition: width 0.2s ease, opacity 0.2s ease, padding 0.2s ease;
}

.search-wrapper.search-active .search-input {
  width: 180px;
  opacity: 1;
  padding: 0.25rem 0.5rem;
  border-bottom-color: var(--push-10);
}

.search-input::placeholder {
  color: var(--push-50);
}

/* No results */
.no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--push-50);
  font-size: 0.9375rem;
}

/* Floating preference pill */
.site-controls {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  display: flex;
  gap: 0.125rem;
  background: var(--lift-60);
  border: 1px solid var(--push-10);
  border-radius: 2rem;
  padding: 0.25rem;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Left-handed: pill on left side */
[data-handed="left"] .site-controls {
  right: auto;
  left: 1.5rem;
  flex-direction: row-reverse;
}


.control-btn {
  background: none;
  border: none;
  color: var(--push-80);
  padding: 0.5rem;
  border-radius: 50%;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}

.control-btn:hover {
  color: var(--color-text);
  background: var(--lift-40);
}

/* Square radius for header buttons (sort, search) */
.site-filters .control-btn {
  border-radius: 4px;
}


/* Hand toggle icons - default shows right hand (right-handed mode) */
.icon-hand-left { display: none; }
[data-handed="left"] .icon-hand-right { display: none; }
[data-handed="left"] .icon-hand-left { display: block; }

/* Full-screen sections */
.section-intro,
.section-contact {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  transition: opacity 0.3s ease;
}

body.panel-open .section-intro,
body.panel-open .section-contact {
  opacity: 0;
  height: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.section-inner {
  max-width: 42rem;
  text-align: center;
}

/* Intro section */
.intro-text {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  line-height: 1.4;
  color: var(--color-text);
  font-style: italic;
}

/* Contact section */
.contact-heading {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 400;
  margin-bottom: 2rem;
  color: var(--color-text);
}

.contact-links {
  display: flex;
  gap: 2rem;
  justify-content: center;
  flex-wrap: wrap;
}

.contact-link {
  color: var(--push-50);
  text-decoration: none;
  font-size: 1.125rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--push-10);
  border-radius: 4px;
  transition: color 0.15s, border-color 0.15s;
}

.contact-link:hover {
  color: var(--color-text);
  border-color: var(--color-text);
}

/* Main container */
.main-container {
  display: flex;
  min-height: calc(100vh - var(--header-height));
}

/* Cards grid */
.cards-grid {
  flex: 1;
  padding: 1rem 2rem 2rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(max(300px, calc((100% - 4 * 1.25rem) / 5)), 1fr));
  gap: 1.25rem;
  align-content: start;
  transition: padding 0.3s ease;
}

/* When panel is open, add padding to prevent overlap */
/* Default (right-handed): panel on left, cards push right */
body.panel-open .cards-grid {
  padding-left: var(--panel-width);
  padding-right: 0;
}

/* Left-handed: panel on right, cards push left */
[data-handed="left"] body.panel-open .cards-grid {
  padding-left: 0;
  padding-right: var(--panel-width);
}

/* Card */
@keyframes card-enter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card {
  padding: 1.5rem;
  cursor: pointer;
  animation: card-enter 0.25s ease-out both;
  animation-delay: calc(var(--i, 0) * 100ms);
}

.card h1,
.card h2 {
  position: static;
}

.series-number {
  display: none;
}

.card-title {
  font-size: 1.5rem;
  font-weight: 900;
  line-height: 1.3;
  margin-top: -0.5rem;
  padding-bottom: .4rem;
  border-top: 4px solid var(--color-text);
  border-bottom: 2px solid var(--color-text);
  margin-bottom: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-tags {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0.5rem;
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  overflow: hidden;
  max-width: 100%;
}

.card-tag {
  font-size: 0.6rem;
  color: var(--color-text);
  background: var(--lift-40);
  padding: 0.2rem 0.5rem;
  border-radius: 1rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.card-cover {
  width: 100%;
  height: auto;
  margin-bottom: 0.75rem;
}

.card-description {
  font-size: 0.875rem;
  color: var(--push-80);
  line-height: 1.3;
  margin-top: 0.5rem;
  margin-bottom: 1rem;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--color-text);
  padding-top: 0.5rem;
}

.card-category {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--push-80);
}

.card-date {
  font-size: 0.7rem;
  color: var(--push-80);
}

/* Panel - default is right-handed (panel on left) */
.panel {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--panel-width);
  height: 100vh;
  background: var(--color-bg);
  border-right: 1px solid var(--push-10);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

body.panel-open .panel {
  transform: translateX(0);
}

/* Left-handed mode: panel on right */
[data-handed="left"] .panel {
  left: auto;
  right: 0;
  border-right: none;
  border-left: 1px solid var(--push-10);
  transform: translateX(100%);
}

[data-handed="left"] body.panel-open .panel {
  transform: translateX(0);
}

.panel-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Left-handed: close button on left */
[data-handed="left"] .panel-header {
  flex-direction: row-reverse;
}

.panel-title {
  min-width: 0;
  flex: 1;
}

.panel-category {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--push-50);
  display: block;
  margin-bottom: 0.125rem;
}

.panel-heading {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-close {
  margin-left: 1rem;
  flex-shrink: 0;
}

[data-handed="left"] .panel-close {
  margin-left: 0;
  margin-right: 1rem;
}

/* Scroll-sync inside panel */
.panel scroll-sync {
  flex: 1;
  overflow-y: auto;
  --scroll-sync-padding: 0 2rem 2rem;
  --scroll-sync-gap: 24px;
}

/* Article typography */
article {
  min-width: 0;
}

article h1 {
  font-weight: 600;
  font-size: 1.75rem;
  margin-bottom: 1.5rem;
  line-height: 1.2;
}

article h2 {
  font-weight: 600;
  font-size: 1.25rem;
  margin: 2rem 0 1rem;
  line-height: 1.3;
  position: sticky;
  top: 0;
  background: var(--color-bg);
  padding: 0.5rem 0;
  z-index: 9;
}

article h3 {
  font-weight: 600;
  font-size: 1.25rem;
  margin: 1.5rem 0 0.75rem;
}

article p {
  margin-bottom: 1rem;
  line-height: 1.5;
}

article a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

article a:hover {
  text-decoration-thickness: 2px;
}

article strong {
  font-weight: 600;
}

article em {
  font-style: italic;
}

article mark {
  display: inline;
  -webkit-mask-image: var(--marked-fx);
  mask-image: var(--marked-fx);
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  background-color: var(--accent);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  padding: .2rem .5rem;
}

article del {
  display: inline;
  -webkit-mask-image: var(--deleted-fx);
  mask-image: var(--deleted-fx);
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  background-color: var(--color-text);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  padding: .2rem .5rem;
  margin: .1rem;
  color: transparent !important;
  text-decoration: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

article code {
  background: var(--push-10);
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.875em;
}

article ul, article ol {
  margin: 1rem 0;
  padding-left: 1.5rem;
}

article li {
  margin-bottom: 0.5rem;
}

/* Media figures in article - hidden on desktop, visible on mobile */
article figure[data-media] {
  display: block;
  height: 1px;
  overflow: hidden;
  margin: 2rem 0;
}

article figure[data-media] img,
article figure[data-media] figcaption,
article figure[data-media] blockquote,
article figure[data-media] pre {
  visibility: hidden;
}

/* Loading state */
.loading {
  color: var(--push-50);
  font-style: italic;
  padding: 2rem;
}

.error {
  color: #c00;
}

/* Mobile: full-screen panel */
@media (max-width: 900px) {
  :root {
    --panel-width: 100vw;
  }

  .site-header,
  .panel-header {
    padding: 0 1rem;
  }

  .site-title,
  .panel-heading {
    font-size: 1.125rem;
  }

  .site-tagline {
    display: none;
  }

  .site-filters {
    padding: 0 0.5rem;
  }

  .filter-categories {
    display: none;
  }

  .search-wrapper.search-active {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: var(--header-height);
    background: var(--color-bg);
    z-index: 60;
    padding: 0 1rem;
    justify-content: center;
  }

  .search-wrapper.search-active .search-input {
    width: 100%;
    max-width: 400px;
  }

  .search-wrapper.search-active .control-btn {
    flex-shrink: 0;
  }

  .site-controls {
    bottom: 1rem;
    right: 1rem;
  }

  [data-handed="left"] .site-controls {
    right: auto;
    left: 1rem;
  }

  .site-controls .control-btn {
    padding: 0.375rem;
  }

  .cards-grid {
    padding: 0;
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  body.panel-open .cards-grid,
  [data-handed="left"] body.panel-open .cards-grid {
    padding-left: 0;
    padding-right: 0;
  }

  .panel {
    border-left: none;
  }

  .panel scroll-sync {
    --scroll-sync-padding: 0 1rem 1rem;
  }

  /* Show inline media on mobile */
  article figure[data-media] {
    height: auto;
    overflow: visible;
  }

  article figure[data-media] img,
  article figure[data-media] figcaption,
  article figure[data-media] blockquote,
  article figure[data-media] pre {
    visibility: visible;
  }

  article figure[data-media] img {
    max-width: 100%;
    height: auto;
  }

  article figure[data-media] figcaption {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--push-50);
  }

  article figure[data-media] blockquote {
    font-family: var(--font-serif);
    font-size: 1.125rem;
    font-style: normal;
    border-left: 3px solid var(--color-text);
    padding-left: 1rem;
    margin: 0;
  }

  article figure[data-media] pre {
    background: var(--color-text);
    color: var(--color-bg);
    padding: 1rem;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 0.8125rem;
  }

  article figure[data-media] code {
    font-family: var(--font-mono);
    background: none;
    padding: 0;
  }

  /* Charts and graphs on mobile */
  article figure[data-media] flow-chart,
  article figure[data-media] flow-graph {
    display: block;
    width: 100%;
  }

  /* Prevent body scroll when panel is open on mobile */
  body.panel-open {
    overflow: hidden;
  }
}

/* Small mobile */
@media (max-width: 480px) {
  .card {
    padding: 1.25rem;
  }

  .card-title {
    font-size: 1rem;
  }

  article h1 {
    font-size: 1.5rem;
  }

  article h2 {
    font-size: 1.25rem;
  }
}
