/*
 * Forge Events, front end.
 *
 * NO COLOUR IS NAMED IN THIS FILE. Not one hex value, not one rgb(), on any
 * element that paints over the page. Every rule, divider and tint is mixed from
 * currentColor, so the calendar borrows the theme's own text colour and
 * composites it against the theme's own background. A dark theme gets faint
 * light rules, a light theme gets faint dark rules, and neither needs a setting.
 *
 * This is a direct answer to how the previous calendar failed: it shipped
 * light-theme CSS with hard-coded greys and white panels, and on a dark site it
 * rendered near-black on near-black. The only legible thing left on the page
 * was the event time. An option to pick a theme would not have fixed it, since
 * the real fault was CSS asserting a background it did not own.
 *
 * The one exception is --forgeev-accent, which an owner may set. It defaults to
 * currentColor, so leaving it alone is always safe.
 *
 * color-mix() is used with an @supports fallback. Where it is missing, the
 * fallback uses the same currentColor trick through opacity on a pseudo
 * element, never a guessed grey.
 */

.forgeev {
  --forgeev-accent: currentColor;
  /*
   * Transparent by default, which is the whole no-configuration promise: the
   * calendar sits on the page and the page's own background shows through.
   * An owner who sets a background gets --forgeev-bg AND a `color` on this
   * same element, and because every token below is mixed from currentColor,
   * the entire set re-derives itself against the new text colour with no
   * other rule needing to know a panel exists.
   */
  --forgeev-bg: transparent;
  --forgeev-line: color-mix(in srgb, currentColor 16%, transparent);
  --forgeev-line-strong: color-mix(in srgb, currentColor 28%, transparent);
  --forgeev-tint: color-mix(in srgb, currentColor 5%, transparent);
  --forgeev-tint-hover: color-mix(in srgb, currentColor 11%, transparent);
  --forgeev-dim: color-mix(in srgb, currentColor 55%, transparent);
  --forgeev-faint: color-mix(in srgb, currentColor 35%, transparent);
  --forgeev-gap: 0.75rem;
  --forgeev-radius: 3px;

  color: inherit;
  font-size: inherit;
  line-height: 1.45;
}

@supports not (color: color-mix(in srgb, currentColor 10%, transparent)) {
  .forgeev {
    --forgeev-line: currentColor;
    --forgeev-line-strong: currentColor;
    --forgeev-tint: transparent;
    --forgeev-tint-hover: transparent;
    --forgeev-dim: currentColor;
    --forgeev-faint: currentColor;
  }
  /* Without color-mix, borders would be full-strength text colour and shout.
     Opacity on the border-carrying element is the one way to soften a colour
     we are not allowed to name. */
  .forgeev-grid th,
  .forgeev-grid td {
    border-color: currentColor;
    opacity: 0.999; /* establishes a stacking context, see below */
  }
  .forgeev-grid {
    --forgeev-fallback-note: "borders are stronger here, which is legible, just plainer";
  }
}

.forgeev-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- month bar */

.forgeev-monthbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--forgeev-gap);
  margin-bottom: 0.9rem;
}

.forgeev-monthlabel {
  margin: 0;
  font-size: 1.25em;
  line-height: 1.2;
  text-align: center;
  flex: 1 1 auto;
}

.forgeev-nav {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--forgeev-line);
  border-radius: var(--forgeev-radius);
  text-decoration: none;
  color: inherit;
  font-size: 1em;
  line-height: 1;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.forgeev-nav:hover,
.forgeev-nav:focus-visible {
  background-color: var(--forgeev-tint-hover);
  border-color: var(--forgeev-line-strong);
}

/* ------------------------------------------------------------------- grid */

.forgeev-grid {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin: 0;
}

.forgeev-grid th {
  padding: 0.4rem 0.3rem;
  font-size: 0.75em;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: left;
  color: var(--forgeev-dim);
  border-bottom: 1px solid var(--forgeev-line-strong);
}

.forgeev-grid th abbr {
  text-decoration: none;
  border: 0;
  cursor: inherit;
}

.forgeev-cell {
  vertical-align: top;
  padding: 0.35rem 0.35rem 0.5rem;
  border: 1px solid var(--forgeev-line);
  /* A month grid with uneven row heights reads as broken, and one tall cell
     should not stretch the whole week. */
  height: 5.75rem;
}

.forgeev-cell.is-outside {
  /* Days from the neighbouring months square the grid off. They are context,
     not content, so they recede without disappearing. */
  color: var(--forgeev-faint);
  background-color: var(--forgeev-tint);
}

.forgeev-cell.is-today {
  box-shadow: inset 0 0 0 2px var(--forgeev-accent);
}

.forgeev-cell.is-past:not(.is-today) .forgeev-daynum {
  color: var(--forgeev-faint);
}

.forgeev-daynum {
  display: block;
  font-size: 0.8em;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  color: var(--forgeev-dim);
}

.forgeev-cell.is-today .forgeev-daynum {
  color: inherit;
  font-weight: 700;
}

/* Shown only in the phone layout, where the column headers are gone. */
.forgeev-celldate {
  display: none;
  font-size: 0.78em;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--forgeev-dim);
}

.forgeev-daylist {
  list-style: none;
  margin: 0.15rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.forgeev-pill {
  display: block;
  padding: 2px 4px;
  border-left: 2px solid var(--forgeev-accent);
  border-radius: 0 var(--forgeev-radius) var(--forgeev-radius) 0;
  background-color: var(--forgeev-tint);
  color: inherit;
  text-decoration: none;
  font-size: 0.75em;
  line-height: 1.3;
  transition: background-color 120ms ease;
}

.forgeev-pill:hover,
.forgeev-pill:focus-visible {
  background-color: var(--forgeev-tint-hover);
}

.forgeev-pill-time {
  display: block;
  font-variant-numeric: tabular-nums;
  color: var(--forgeev-dim);
}

.forgeev-pill-title {
  display: block;
  /* Two lines, then clip. A long title must not push the grid around. */
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.forgeev-more {
  display: block;
  margin-top: 2px;
  padding-left: 4px;
  font-size: 0.72em;
  color: var(--forgeev-dim);
}

.forgeev-empty {
  margin: 1rem 0 0;
  color: var(--forgeev-dim);
  font-style: italic;
}

/* ------------------------------------------------------------------- cards */

.forgeev-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.forgeev-card {
  display: flex;
  gap: 1rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--forgeev-line);
}

.forgeev-card:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.forgeev-card-media {
  flex: 0 0 clamp(96px, 26%, 190px);
}

.forgeev-card-media img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--forgeev-radius);
}

.forgeev-card-body {
  flex: 1 1 auto;
  min-width: 0;
}

.forgeev-card-when {
  margin: 0 0 0.2rem;
  font-size: 0.82em;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--forgeev-dim);
}

.forgeev-card-title {
  margin: 0 0 0.3rem;
  font-size: 1.1em;
  line-height: 1.25;
  text-wrap: balance;
}

.forgeev-card-title a {
  color: inherit;
  text-decoration: none;
}

.forgeev-card-title a:hover,
.forgeev-card-title a:focus-visible {
  text-decoration: underline;
}

.forgeev-card-meta {
  margin: 0 0 0.35rem;
  font-size: 0.85em;
  color: var(--forgeev-dim);
}

.forgeev-card-text {
  margin: 0 0 0.5rem;
  font-size: 0.92em;
}

/* ------------------------------------------------------------------ single */

.forgeev-facts {
  display: grid;
  grid-template-columns: minmax(5.5rem, auto) 1fr;
  gap: 0.45rem 1.1rem;
  margin: 0 0 1.1rem;
  padding: 0.9rem 0;
  border-top: 1px solid var(--forgeev-line);
  border-bottom: 1px solid var(--forgeev-line);
}

.forgeev-facts dt {
  margin: 0;
  font-size: 0.78em;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--forgeev-dim);
  padding-top: 0.15em;
}

.forgeev-facts dd {
  margin: 0;
}

.forgeev-dates {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.forgeev-recurs {
  margin: 0.35rem 0 0;
  font-size: 0.85em;
  color: var(--forgeev-dim);
}

.forgeev-venue-name {
  font-weight: 600;
}

/* ------------------------------------------------------------------ button */

/*
 * Deliberately NOT styled as a filled button. A filled button needs a
 * background colour and a text colour that contrasts with it, which is exactly
 * the pair this file is not allowed to assert. An outlined control built from
 * currentColor is legible on any ground. A theme that wants its own button can
 * target .forgeev-button and will win on specificity.
 */
.forgeev-button {
  display: inline-block;
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--forgeev-line-strong);
  border-radius: var(--forgeev-radius);
  color: inherit;
  text-decoration: none;
  font-size: 0.9em;
  letter-spacing: 0.04em;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.forgeev-button:hover,
.forgeev-button:focus-visible {
  background-color: var(--forgeev-tint-hover);
  border-color: var(--forgeev-accent);
}

.forgeev-cta {
  margin: 0.6rem 0 0;
}

/* ------------------------------------------------------------------ phone */

/*
 * A seven-column month grid does not work at 360px. Rather than shrink it to
 * illegibility, the grid becomes a list of the days that have something on.
 * Empty days and neighbouring-month days are dropped, since in a list they
 * carry no information at all; in the grid they were only there to square it
 * off. Each row then shows its own full date, which is why the renderer always
 * emits one.
 */
@media (max-width: 640px) {
  .forgeev-grid,
  .forgeev-grid tbody,
  .forgeev-grid tr,
  .forgeev-grid td {
    display: block;
    width: auto;
  }

  .forgeev-grid thead,
  .forgeev-grid caption {
    display: none;
  }

  .forgeev-grid tr {
    /* Without this, consecutive weeks run together with no separation. */
    margin: 0;
  }

  .forgeev-cell {
    height: auto;
    border: 0;
    border-bottom: 1px solid var(--forgeev-line);
    padding: 0.6rem 0 0.7rem;
  }

  .forgeev-cell:not(.has-events),
  .forgeev-cell.is-outside {
    display: none;
  }

  .forgeev-cell.is-today {
    box-shadow: none;
    border-left: 2px solid var(--forgeev-accent);
    padding-left: 0.6rem;
  }

  .forgeev-daynum {
    display: none;
  }

  .forgeev-celldate {
    display: block;
    margin-bottom: 0.3rem;
  }

  .forgeev-pill {
    font-size: 0.9em;
    padding: 0.35rem 0.5rem;
  }

  .forgeev-pill-title {
    -webkit-line-clamp: 3;
  }

  .forgeev-card {
    flex-direction: column;
    gap: 0.6rem;
  }

  .forgeev-card-media {
    flex: 0 0 auto;
    max-width: 100%;
  }

  .forgeev-facts {
    grid-template-columns: 1fr;
    gap: 0.1rem 0;
  }

  .forgeev-facts dt {
    padding-top: 0.6rem;
  }

  .forgeev-facts dt:first-child {
    padding-top: 0;
  }
}

/* ------------------------------------------------------------------ panel */

/*
 * The optional background, set from the Appearance screen.
 *
 * The colour arrives inline on this element, so the only job here is to paint
 * it and to stop the grid touching the panel edge. Deliberately NOT applied to
 * .forgeev unconditionally: without the class, background-color would resolve
 * to transparent and still create a paint layer that can break a theme's own
 * backdrop filters.
 */
.forgeev.has-forgeev-bg {
  background-color: var(--forgeev-bg);
  border-radius: var(--forgeev-radius);
}

.forgeev.has-forgeev-bg.is-padded {
  padding: 1.25rem 1.35rem 1.4rem;
}

/*
 * A panelled calendar needs its outer rule removed, or the panel edge and the
 * table edge draw two lines a few pixels apart.
 */
.forgeev.has-forgeev-bg .forgeev-facts {
  border-top: 0;
  padding-top: 0;
}

@media (max-width: 640px) {
  .forgeev.has-forgeev-bg.is-padded {
    /* A phone has 16px of page gutter already; another 22px inside the panel
       leaves the grid squeezed into the middle third of the screen. */
    padding: 0.9rem 0.9rem 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .forgeev-nav,
  .forgeev-pill,
  .forgeev-button {
    transition: none;
  }
}
