/**
 * Magazine Issues
 * Low-specificity so themes can override with a single class.
 * Every colour is a custom property — redefine on :root to rebrand.
 */

.mi-issue,
.mi-archive {
  --mi-gap: 2rem;
  --mi-columns: 4;
  --mi-max: 1200px;

  /* Brand — override these to match your palette. */
  --mi-accent: #00a651; /* eyebrows, section headings, pill  */
  --mi-accent-ink: #ffffff; /* text on the accent pill           */
  --mi-time: #000000; /* reading-time badge                */
  --mi-clock: #812990; /* reading-time badge                */
  --mi-rule-from: #00a651; /* gradient rule, left               */
  --mi-rule-to: #00a651; /* gradient rule, right              */
  --mi-muted: color-mix(in srgb, currentColor 62%, transparent);
  --mi-dark: #000000;
}

/* When the plugin renders a full standalone page (theme-override templates),
   centre it. When injected into the theme's content (single issue, archive
   grid, shortcodes) the plugin sets NO width, so the theme's own content
   container governs it — just like a normal post. */
.mi-issue--page,
.mi-archive--page {
  max-width: var(--mi-max);
  margin-inline: auto;
  padding-inline: 1.25rem;
}

/* Masthead / top bar ------------------------------------------------------ */

.mi-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0rem;
  border-bottom: 3px solid;
  border-image: linear-gradient(90deg, var(--mi-rule-from), var(--mi-rule-to)) 1;
  margin-bottom: 40px;
}

.mi-topbar::after {
  content: "";
  width: 100%;
  display: block;
  height: 3px;
  background-color: #812990;
}

.mi-topbar__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 400;
  line-height: 1.2;
}

.mi-topbar__number {
  font-weight: 800;
}

.mi-topbar__label {
  margin-left: 0.5em;
  color: var(--mi-muted);
}

/* Shared button sizing — feedback, back-to-issue, and topbar pills all use
   these so they match. Override any of them in your own CSS to rescale every
   plugin button at once, e.g. :root { --mi-btn-font: 0.8125rem; }

   --mi-ease lives here rather than on .mi-issue/.mi-archive because the
   back-to-issue and feedback buttons render on article pages, outside those
   scopes — an undefined var() in a transition kills the whole declaration. */
:root {
  --mi-btn-font: 1rem;
  --mi-btn-weight: 400;
  --mi-btn-py: 0.6rem;
  --mi-btn-px: 1rem;
  --mi-btn-radius: 999px;
  --mi-btn-line: 1.2;
  --mi-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

.mi-topbar__link {
  flex: none;
  align-self: center;
  display: inline-flex;
  align-items: center;
  padding: var(--mi-btn-py, 0.55em) var(--mi-btn-px, 1.2em);
  border-radius: var(--mi-btn-radius, 999px);
  background: var(--mi-accent);
  color: var(--mi-accent-ink);
  font-size: var(--mi-btn-font, 0.875rem);
  font-weight: var(--mi-btn-weight, 700);
  line-height: var(--mi-btn-line, 1.2);
  text-decoration: none;
  white-space: nowrap;
}

.mi-topbar__link:hover,
.mi-topbar__link:focus-visible {
  color: var(--mi-accent-ink);
}

/* Eyebrows ---------------------------------------------------------------- */

.mi-eyebrow {
  margin: 0 0 0.35em;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
}

.mi-eyebrow--accent,
.mi-eyebrow--accent a {
  color: var(--mi-accent);
  text-decoration: none;
}

.mi-eyebrow--accent a:hover,
.mi-eyebrow--accent a:focus-visible {
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

/* Issue intro ------------------------------------------------------------- */

.mi-issue__intro {
  max-width: 68ch;
  margin-block: var(--mi-gap);
}

/* Section heading --------------------------------------------------------- */

.mi-section-heading {
  margin: calc(var(--mi-gap) * 1.5) 0 var(--mi-gap);
  color: var(--mi-accent);
  font-size: clamp(1.1rem, 0.9rem + 0.9vw, 1.5rem);
  font-weight: 800;
  line-height: 1.2;
  text-wrap: balance;
}

/* Featured article -------------------------------------------------------- */

.mi-featured {
  margin-top: var(--mi-gap);
}

.mi-lead {
  display: grid;
  gap: var(--mi-gap);
  align-items: start;
}

.mi-lead__body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (min-width: 48em) {
  .mi-lead {
    grid-template-columns: 5fr 6fr;
    align-items: center;
  }
}

.mi-lead__media img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px 10px 150px 10px;
}

.mi-lead__title {
  margin: 0.2rem 0 0.75rem;
  font-size: clamp(1.75rem, 1.15rem + 2.2vw, 2.6rem);
  line-height: 1.12;
  text-wrap: balance;
}

.mi-lead__excerpt {
  margin: 0 0 1rem;
  max-width: 52ch;
  color: var(--mi-dark);
}

/* Four-column grid -------------------------------------------------------- */

.mi-grid {
  display: grid;
  gap: var(--mi-gap);
  grid-template-columns: 1fr;
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 40em) {
  .mi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 64em) {
  .mi-grid {
    grid-template-columns: repeat(var(--mi-columns), 1fr);
  }
}

.mi-grid__item {
  margin: 0;
}

.mi-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mi-card__media img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 10px 10px 50px 10px;
}

.mi-card__title {
  margin: 0.3rem 0 0.4rem;
  font-size: 1.125rem;
  line-height: 1.22;
  font-weight: 800;
  text-wrap: balance;
}

.mi-card__excerpt {
  margin: 0 0 0.75rem;
  font-size: 0.9375rem;
  color: var(--mi-dark);
}

/* Reading-time badge ------------------------------------------------------ */

.mi-readtime {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  color: var(--mi-time);
  font-size: 0.8125rem;
  font-weight: 500;
}

.mi-clock {
  flex: none;
}

.mi-clock {
  color: var(--mi-clock) !important;
}

.mi-card .mi-clock {
  color: var(--mi-dark) !important;
}

/* Links ------------------------------------------------------------------- */

.mi-lead a,
.mi-card a {
  color: inherit;
  text-decoration: none;
}

.mi-lead__title a:hover,
.mi-card__title a:hover,
.mi-lead__title a:focus-visible,
.mi-card__title a:focus-visible {
  text-decoration: underline;
  text-underline-offset: 0.15em;
  color: #00a651;
}

:where(.mi-issue, .mi-archive) a:focus-visible {
  outline: 2px solid var(--mi-accent);
  outline-offset: 3px;
}

/* Archive ----------------------------------------------------------------- */

.mi-archive__title {
  margin: 0 0 var(--mi-gap);
  color: var(--mi-accent);
}

.mi-eyebrow {
  line-height: 1.3;
}

/* Utility ----------------------------------------------------------------- */

.mi-empty {
  color: var(--mi-muted);
}

@media (prefers-reduced-motion: reduce) {
  .mi-issue *,
  .mi-archive * {
    transition: none !important;
    animation: none !important;
  }
}

/* ------------------------------------------------------------------ *
 * Archive layout (issues, categories, tags, authors, dates)
 * ------------------------------------------------------------------ */

.mi-archive--grid {
  position: relative;
  /* Faint decorative tree behind the grid. Override with your own asset:
     .mi-archive--grid { --mi-archive-art: url("/path/to/tree.svg"); }      */
  --mi-archive-art: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 300'><g fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round'><path d='M150 300V150'/><path d='M150 190 C120 175 100 150 85 120'/><path d='M150 190 C180 175 200 150 215 120'/><path d='M150 160 C132 140 122 120 116 96'/><path d='M150 160 C168 140 178 120 184 96'/><path d='M85 120 C74 104 68 90 64 74'/><path d='M85 120 C96 108 104 96 110 84'/><path d='M215 120 C226 104 232 90 236 74'/><path d='M215 120 C204 108 196 96 190 84'/><path d='M116 96 C110 82 108 72 108 58'/><path d='M116 96 C124 86 130 78 136 70'/><path d='M184 96 C190 82 192 72 192 58'/><path d='M184 96 C176 86 170 78 164 70'/></g></svg>");
}

.mi-archive__art {
  position: absolute;
  display: none;
  right: 0;
  bottom: 0;
  width: min(55%, 520px);
  aspect-ratio: 1 / 1;
  background: var(--mi-archive-art) no-repeat right bottom;
  background-size: contain;
  opacity: 0.06;
  pointer-events: none;
  z-index: 0;
}

.mi-archive--grid .mi-topbar,
.mi-archive--grid .mi-grid {
  position: relative;
  z-index: 1;
}

.mi-topbar--archive .mi-topbar__title {
  font-size: clamp(1.6rem, 1.1rem + 1.6vw, 2.1rem);
  font-weight: 800;
}

/* Issue card heading: "Issue 1" (accent, bold) + date (regular) */

.mi-card__issueline {
  font-size: 1.35rem;
  line-height: 1.15;
}

.mi-card__issuenum {
  color: var(--mi-accent);
  font-weight: 800;
}

.mi-card__issuedate {
  color: inherit;
  font-weight: 400;
}

/* ------------------------------------------------------------------ *
 * Per-issue next / previous navigation on article pages
 * ------------------------------------------------------------------ */

.mi-post-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem 1.5rem;
  margin-block: 2.5rem;
  padding-top: 1.25rem;
  border-top: 3px solid;
  border-image: linear-gradient(90deg, var(--mi-rule-from), var(--mi-rule-to)) 1;
}

.mi-post-nav--single {
  display: block;
  text-align: center;
}

.mi-post-nav__side {
  min-width: 0;
}

.mi-post-nav__side--next {
  text-align: right;
}

.mi-post-nav__side a {
  display: inline-flex;
  flex-direction: column;
  gap: 0.15em;
  text-decoration: none;
  color: inherit;
  max-width: 100%;
}

.mi-post-nav__dir {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--mi-accent);
}

.mi-post-nav__side--prev .mi-post-nav__dir::before {
  content: "\2190\00a0";
}

.mi-post-nav__side--next .mi-post-nav__dir::after {
  content: "\00a0\2192";
}

.mi-post-nav__title {
  font-weight: 700;
  line-height: 1.2;
}

.mi-post-nav__side a:hover .mi-post-nav__title,
.mi-post-nav__side a:focus-visible .mi-post-nav__title {
  text-decoration: underline;
  text-underline-offset: 0.15em;
  color: var(--mi-accent);
}

.mi-post-nav__issue {
  justify-self: center;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--mi-accent);
  text-decoration: none;
  white-space: nowrap;
}

.mi-post-nav__issue:hover,
.mi-post-nav__issue:focus-visible {
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

@media (max-width: 40em) {
  .mi-post-nav {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .mi-post-nav__side--next {
    text-align: center;
  }

  .mi-post-nav__side a {
    align-items: center;
  }

  .mi-post-nav__issue {
    order: -1;
  }
}

/* ------------------------------------------------------------------ *
 * "Back to the issue" button ([magazine_issue_back])
 * ------------------------------------------------------------------ */

.mi-backbtn-wrap {
  margin-block: 1.5rem;
}

.mi-backbtn-wrap--center {
  text-align: center;
}

.mi-backbtn-wrap--right {
  text-align: right;
}

.mi-backbtn {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: var(--mi-btn-py, 0.55em) var(--mi-btn-px, 1.2em);
  border-radius: var(--mi-btn-radius, 999px);
  /* Fallbacks let the button work even outside a .mi-issue/.mi-archive scope. */
  background: var(--mi-accent, #00a651);
  color: var(--mi-accent-ink, #ffffff);
  font-size: var(--mi-btn-font, 0.875rem);
  font-weight: var(--mi-btn-weight, 400);
  line-height: var(--mi-btn-line, 1.2);
  text-decoration: none;
}

.mi-backbtn::before {
  content: "\2190";
  font-weight: 700;
}

.mi-backbtn:hover,
.mi-backbtn:focus-visible {
  color: var(--mi-accent-ink, #ffffff);
}

/* ------------------------------------------------------------------ *
 * Article feedback CTA + modal ([magazine_issue_feedback])
 * ------------------------------------------------------------------ */

.mi-feedback,
.mi-feedback__open {
  --mi-accent: var(--mi-accent, #00a651);
}

.mi-feedback .mi-feedback__open,
.mi-backbtn-wrap .mi-feedback__open,
.mi-feedback__open {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  width: auto;
  min-height: 0 !important;
  height: auto;
  margin: 0;
  padding: var(--mi-btn-py, 0.55em) var(--mi-btn-px, 1.2em) !important;
  border: 0;
  border-radius: var(--mi-btn-radius, 999px);
  background: var(--mi-accent, #00a651);
  color: var(--mi-accent-ink, #ffffff);
  font: inherit;
  font-size: var(--mi-btn-font, 0.875rem);
  font-weight: var(--mi-btn-weight, 700);
  line-height: var(--mi-btn-line, 1.2) !important;
  text-align: center;
  text-decoration: none;
  text-transform: none;
  letter-spacing: normal;
  vertical-align: middle;
  cursor: pointer;
  box-sizing: border-box;
}

.mi-feedback__open:hover,
.mi-feedback__open:focus-visible {
  color: var(--mi-accent-ink, #ffffff);
}

.mi-feedback__dialog {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  margin: 0 !important; /* centring is handled by the translate */
  width: min(80vw, 900px); /* never wider than 80% of the viewport */
  max-width: 80vw;
  max-height: 90vh;
  overflow: auto;
  padding: 1.75rem;
  border: 0;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  color: inherit;

  /* Centred via translate; animated via scale + opacity. */
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.97);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease,
    overlay 0.22s ease allow-discrete,
    display 0.22s ease allow-discrete;
}

.mi-feedback__dialog[open] {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

@starting-style {
  .mi-feedback__dialog[open] {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.97);
  }
}

.mi-feedback__dialog::backdrop {
  background: rgba(0, 0, 0, 0);
  transition:
    background 0.22s ease,
    overlay 0.22s ease allow-discrete,
    display 0.22s ease allow-discrete;
}

.mi-feedback__dialog[open]::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

@starting-style {
  .mi-feedback__dialog[open]::backdrop {
    background: rgba(0, 0, 0, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .mi-feedback__dialog {
    transition: none;
    transform: translate(-50%, -50%);
  }

  .mi-feedback__dialog[open] {
    transform: translate(-50%, -50%);
  }
}

.mi-feedback__close {
  position: absolute;
  top: 0.5rem;
  right: 0.65rem;
  border: 0;
  background: transparent;
  font-size: 1.75rem;
  line-height: 1;
  color: inherit;
  cursor: pointer;
}

.mi-feedback__heading {
  margin: 0 0 0.25rem;
  padding-right: 1.5rem;
  font-size: 1.35rem;
}

.mi-feedback__context {
  margin: 0 0 1.25rem;
  color: var(--mi-muted, #666);
  font-size: 0.9375rem;
}

/* ------------------------------------------------------------------ *
 * Motion: card hover states + on-scroll reveal
 * Tune with these; set --mi-hover-lift: 0 to drop the lift entirely.
 * (--mi-ease is declared on :root, up with the --mi-btn-* vars.)
 * ------------------------------------------------------------------ */

.mi-issue,
.mi-archive {
  --mi-hover-lift: 0px;
  --mi-hover-zoom: 1.04;
}

/* Media: contain the zoom inside the card's rounded corners. */
.mi-card__media,
.mi-lead__media {
  display: block;
  overflow: hidden;
  border-radius: 10px 10px 50px 10px;
}

.mi-lead__media {
  border-radius: 10px 10px 150px 10px;
}

.mi-card__media img,
.mi-lead__media img {
  transition: transform 0.5s var(--mi-ease);
  will-change: transform;
}

/* Hover / keyboard focus anywhere in the card drives the whole card. */
.mi-card,
.mi-lead {
  transition: transform 0.35s var(--mi-ease);
}

.mi-card:hover,
.mi-card:focus-within,
.mi-lead:hover,
.mi-lead:focus-within {
  transform: translateY(var(--mi-hover-lift));
}

.mi-card:hover .mi-card__media img,
.mi-card:focus-within .mi-card__media img,
.mi-lead:hover .mi-lead__media img,
.mi-lead:focus-within .mi-lead__media img {
  transform: scale(var(--mi-hover-zoom));
}

.mi-card__title a,
.mi-lead__title a {
  transition: color 0.25s var(--mi-ease);
}

.mi-card:hover .mi-card__title a,
.mi-lead:hover .mi-lead__title a {
  color: var(--mi-accent);
}

/* Buttons and pills settle a touch on hover — translate only.
   The inline fallback keeps the transition alive even if a child theme
   redefines :root without --mi-ease. */
.mi-topbar__link,
.mi-backbtn,
.mi-feedback__open {
  transition: transform 0.25s var(--mi-ease, cubic-bezier(0.22, 0.61, 0.36, 1));
}

.mi-topbar__link:hover,
.mi-topbar__link:focus-visible,
.mi-backbtn:hover,
.mi-backbtn:focus-visible,
.mi-feedback__open:hover,
.mi-feedback__open:focus-visible {
  transform: translateY(-1px);
}

/* The global reduced-motion rule above is scoped to .mi-issue/.mi-archive,
   which the back and feedback buttons sit outside of on article pages. */
@media (prefers-reduced-motion: reduce) {
  .mi-topbar__link,
  .mi-backbtn,
  .mi-feedback__open {
    transition: none;
    transform: none !important;
  }
}

/* On-scroll reveal. The class is added by assets/js/motion.js, and only to
   elements that start below the fold, so nothing flashes and no-JS visitors
   see the page exactly as before. */
.mi-reveal {
  opacity: 0;
  transform: translateY(14px);
}

.mi-reveal--ready {
  transition:
    opacity 0.6s var(--mi-ease),
    transform 0.6s var(--mi-ease);
  transition-delay: calc(var(--mi-i, 0) * 70ms);
}

.mi-reveal--in {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .mi-reveal,
  .mi-reveal--ready {
    opacity: 1 !important;
    transform: none !important;
  }
}
