/* Remix's element reset (rmx-reset) must sit below component styles (rmx).
   Name it here, or it's appended after rmx and zeroes every css() margin on
   headings, paragraphs and lists. */
@layer app, rmx-reset, rmx;

@view-transition {
  navigation: auto;
}

/* Respect reduced-motion: disable cross-document view transitions entirely. */
@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }
}

/* CSS Reset */
@layer app {
  *,
  *::before,
  *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  button,
  input,
  select,
  textarea {
    font: inherit;
    color: inherit;
    line-height: inherit;
  }
  button {
    background: none;
    border: none;
    cursor: pointer;
    appearance: none;
  }
  img {
    display: block;
    max-width: 100%;
  }

  /* Archivo, self-hosted (public/fonts, SIL OFL): one variable file per
     script with both axes, weight 100–900 and width 62–125%. */
  @font-face {
    font-family: Archivo;
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    font-stretch: 62% 125%;
    src: url('/fonts/archivo-latin-ext-wdth-normal.woff2') format('woff2-variations');
    unicode-range:
      U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
      U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
      U+A720-A7FF;
  }
  @font-face {
    font-family: Archivo;
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    font-stretch: 62% 125%;
    src: url('/fonts/archivo-latin-wdth-normal.woff2') format('woff2-variations');
    unicode-range:
      U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
      U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }

  /*
   * The whole palette — see docs/design-guidelines.md. Components take every
   * color from these tokens; nothing else defines a color. Light mode is
   * black on white, dark mode the straight inversion. The cover blue is the
   * same in both.
   */
  :root {
    color-scheme: light dark;
    /* Links and focus. */
    --theme-color: #0000ee;
    /* The site header and the cover: the same bold blue in both schemes. */
    --ui-cover: #0000ee;
    --ui-on-cover: #ffffff;
    /* The event pane's title: the cover's blue as text. White in dark mode,
       where the blue is too weak on the dark pane. */
    --ui-cover-text: var(--ui-cover);
    --ui-background: #ffffff;
    --ui-foreground: #000000;
    /* Day labels and venues in the timeline. */
    --ui-foreground-muted: color-mix(in srgb, var(--ui-foreground) 68%, var(--ui-background));
    --ui-link: var(--theme-color);
    /* Panes and grouped blocks. */
    --ui-background-subtle: #efefef;
    /* The first pane (#122): a shade darker than the subtle grey. */
    --ui-pane: #e7e7e7;
    --ui-focus: var(--theme-color);

    --ui-font: Archivo, Helvetica, Arial, sans-serif;

    /* Motion: panes enter on a drawer curve and leave faster on a strong
       ease-out (see "Pane motion" below). */
    --ui-ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
    --ui-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
    --ui-duration-pane: 320ms;
    --ui-duration-pane-exit: 200ms;
    /* Room between the floating pane column and the viewport edges (#75). */
    --ui-pane-inset: 0.75rem;
    /* Where the pane column comes from and goes back to: 2rem from the
       right, 40px from below on phones (#142). */
    --ui-pane-column-offset: translateX(2rem);
    /* Entrances, 0 until after the first paint (see "Pane motion"). */
    --ui-pane-enter: calc(var(--ui-duration-pane) * var(--ui-pane-motion, 0));
    --ui-pane-enter-fade: calc(var(--ui-duration-pane-exit) * var(--ui-pane-motion, 0));

    /*
     * Not a color of its own: the field behind a group of form controls (a
     * date block, the links block) and behind secondary buttons. It contrasts
     * with whatever surrounds it — grey on the page, the page color inside
     * the grey pane.
     */
    --ui-group: var(--ui-background-subtle);
  }
  /* Phones: the pane column covers the screen, no inset. */
  @media (max-width: 800px) {
    :root {
      --ui-pane-inset: 0px;
      --ui-pane-column-offset: translateY(40px);
    }
  }
  /* The first pane sits on the subtle grey, so a group there is the page
     color. A second pane is the page color again, so its groups are grey. */
  /* The pane's own color, for things that stick inside it (a form's footer):
     the page color in a stacked pane, the grey in the first. */
  aside[data-pane] {
    --ui-surface: var(--ui-background);
  }
  aside[data-pane='1'] {
    --ui-surface: var(--ui-pane);
    --ui-group: var(--ui-background);
    /* The theme's --rmx-* vars resolved var(--ui-group) at :root; re-resolve
       them here so secondary buttons turn white inside the grey pane. */
    --rmx-color-action-secondary-background: var(--ui-group);
    --rmx-color-action-secondary-background-hover: var(--ui-group);
    --rmx-color-action-secondary-background-active: var(--ui-group);
    --rmx-color-action-secondary-border: var(--ui-group);
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --theme-color: #8cb4ff;
      --ui-background: #000000;
      --ui-foreground: #ffffff;
      --ui-background-subtle: #1c1c1c;
      --ui-pane: #1f1f1f;
      --ui-cover-text: var(--ui-foreground);
    }
  }

  /* Base Styles */
  /* Focused or scrolled-to elements stop below the sticky site header
     (app/layout.tsx), also on phones where it may come back over them;
     admin has none (var unset). */
  html {
    scroll-padding-top: var(--site-header-height, 0px);
  }
  body {
    font-family: var(--ui-font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--ui-foreground);
    background: var(--ui-background);
  }
  a {
    color: var(--ui-link);
    text-underline-offset: 0.15em;
  }
  :focus-visible {
    outline: 2px solid var(--ui-focus);
    outline-offset: 2px;
  }
  .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
  }

  main {
    view-transition-name: main;
  }

  table {
    width: 100%;
    border-collapse: collapse;
    background: var(--ui-background);
  }
  th,
  td {
    padding: 0.375rem 1rem 0.375rem 0;
    text-align: left;
    vertical-align: baseline;
    font-size: 0.9375rem;
  }
  th {
    font-weight: 700;
  }
}

/* The cover title's words rise out of their masks (app/components/cover.tsx). */
/* Starts and ends past the mask's 0.2em clip margin plus the glyphs' own
   overflow of the tight line box, so no sliver of a letter shows at rest
   (app/assets/cover-carousel.tsx). */
@keyframes cover-rise {
  from {
    transform: translateY(calc(100% + 0.45em));
  }
}

/* The cover's contents dissolve into a soft edge under the sticky site header
   (coverFadeStyle in app/layout.tsx). Registered, so the scroll-driven
   animations can interpolate them inside the mask gradient. */
@property --cover-exit {
  syntax: '<number>';
  inherits: false;
  initial-value: 0;
}
@property --cover-fade {
  syntax: '<length>';
  inherits: false;
  initial-value: 0px;
}
@keyframes cover-exit {
  to {
    --cover-exit: 1;
  }
}
@keyframes cover-fade {
  to {
    --cover-fade: 6rem;
  }
}

/*
 * Pane motion (docs/design-guidelines.md → Motion). Panes open and close by
 * in-document navigations, so cross-document view transitions never run for
 * them: entrances use @starting-style, exits a short-lived ghost copy
 * (`app/assets/pane-behavior.tsx`). Entrances only run once
 * `--ui-pane-motion` is 1, which PaneBehavior sets after the first paint (in
 * an adopted stylesheet, out of reach of DOM diffing), so a page that loads
 * with a pane open shows it at rest.
 *
 * - The pane column (level 1) slides in 2rem from the right and fades in
 *   (on phones it rises 40px from below instead).
 * - A stacked pane (level 2) slides in from the column's right edge, a
 *   sheet over the first pane, which fades back to 35% underneath.
 */
[data-pane-stack] {
  transition:
    transform var(--ui-pane-enter) var(--ui-ease-drawer),
    opacity var(--ui-pane-enter) var(--ui-ease-drawer);
  @starting-style {
    transform: var(--ui-pane-column-offset);
    opacity: 0;
  }
}

[data-pane-stack] > aside:not([data-pane='1']) {
  transition: transform var(--ui-pane-enter) var(--ui-ease-drawer);
  @starting-style {
    transform: translateX(100%);
  }
}

[data-pane-back] {
  transition: opacity var(--ui-pane-enter) var(--ui-ease-drawer);
  @starting-style {
    opacity: 0;
  }
}

/* The covered pane fades both ways: down when a pane lands on it, back up
   when that pane leaves. */
[data-pane-stack] > aside > * {
  transition: opacity var(--ui-pane-enter) var(--ui-ease-drawer);
}
/* Opening a stacked pane re-renders the one below (new nodes, so no
   transition), so the fade down is an animation from fully visible. */
@keyframes pane-cover-fade {
  from {
    opacity: 1;
  }
}
[data-pane-stack] > aside:has(~ aside:not(:empty)) > * {
  animation: pane-cover-fade var(--ui-pane-enter) var(--ui-ease-drawer);
}

/* Wide screens: the covered pane also steps back, shrinking to 95% about its
   center as the sheet lands, and growing back when it leaves (#75). The
   aside itself is usually kept by the navigation, so a transition carries
   both ways; the animation covers a re-created one. Pane-behavior adds the
   uncover animation for one close, like the fade. */
@keyframes pane-cover-scale {
  from {
    transform: none;
  }
}
@keyframes pane-uncover-scale {
  from {
    transform: scale(0.95);
  }
}
@media (min-width: 801px) {
  [data-pane-stack] > aside[data-pane='1'] {
    transform-origin: center;
    transition: transform var(--ui-pane-enter) var(--ui-ease-drawer);
  }
  [data-pane-stack] > aside:has(~ aside:not(:empty)) {
    transform: scale(0.95);
    animation: pane-cover-scale var(--ui-pane-enter) var(--ui-ease-drawer);
  }
}

/* Closing a stacked pane re-renders the one below too, so it fades back up
   by animation. PaneBehavior switches this on for one close only. */
@keyframes pane-uncover-fade {
  from {
    opacity: 0.35;
  }
}

/* Exits: the ghost leaves the way its pane came in, a little faster. */
@keyframes pane-column-exit {
  to {
    transform: var(--ui-pane-column-offset);
    opacity: 0;
  }
}
@keyframes pane-sheet-exit {
  to {
    transform: translateX(100%);
  }
}
[data-pane-ghost='column'] {
  animation: pane-column-exit var(--ui-duration-pane-exit) var(--ui-ease-out) both;
}
[data-pane-ghost='sheet'] {
  animation: pane-sheet-exit var(--ui-duration-pane-exit) var(--ui-ease-out) both;
}

/* Reduced motion: no movement, the panes only fade. */
@keyframes pane-fade-exit {
  to {
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  [data-pane-stack],
  [data-pane-stack] > aside:not([data-pane='1']) {
    transition: opacity var(--ui-pane-enter-fade) var(--ui-ease-out);
    @starting-style {
      transform: none;
      opacity: 0;
    }
  }
  [data-pane-ghost] {
    animation-name: pane-fade-exit;
  }
  /* The covered pane still sits back, but doesn't move there. */
  [data-pane-stack] > aside {
    transition: none;
    animation: none;
  }
}

/* A prefilled control the visitor changed (suggest-an-edit panes, see
   app/assets/changed-fields.tsx): 2px border, padding shrunk by 1px so the
   field doesn't grow. */
:is(input, textarea)[data-changed] {
  border-width: 2px;
  padding: 5px 7px;
}

/* Link hover (docs/design-guidelines.md → Links): the link turns black and
   its underline thickens. Unlayered so it wins over every component css()
   class. Button-shaped links (ButtonLink, `data-button`) keep their own
   hover. Event rows are one link whose title is a span inside it. */
a:hover:not([data-button]),
a[data-event-id]:hover [data-row-title] {
  color: var(--ui-foreground);
  text-decoration-thickness: 2px;
  /* Event titles rest on a muted underline (event-row.tsx); hover matches the text. */
  text-decoration-color: currentColor;
}
/* …except on the blue site header, where links stay white. */
[data-site-header] a:hover,
[data-site-cover] a:hover {
  color: var(--ui-on-cover);
}
/* …but the header's menus and popovers are white surfaces: their links go
   black like everywhere else (#202). */
[data-site-header] [popover] a:hover {
  color: var(--ui-foreground);
}

/* The cover carousel's exit (app/assets/cover-carousel.tsx): each word rises
   on out of the top of its mask, the inverse of cover-rise. */
@keyframes cover-leave {
  to {
    transform: translateY(calc(-100% - 0.45em));
  }
}

/*
 * iOS Safari zooms the page into any focused field whose text is under 16px,
 * and the controls use 14–15px (#136). On touch screens every field is 16px.
 * Unlayered, so it wins over the components' own css() sizes in the rmx layer.
 * Pinch zoom stays available: the viewport meta doesn't cap the scale.
 */
@media (pointer: coarse) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}
