/* Puddle.

   An early-web look: white page, blue underlined links (purple once visited), square
   corners, thin grey lines, the browser's own form controls. Dark when the system is:
   the same look, with light text, and lighter blue and purple links. */

/* ABC Areal Superfamily (Dinamo), in site/shared/. The files aren't in git (see the
   README's "Font" section); without them the system font is used. One variable file
   covers Areal, Semi Mono and Mono (a MONO axis, --mono below), weights 400-700 and the
   italics (a slant axis). The map and stats pages use the Semi Mono file. */
@font-face {
  font-family: "ABC Areal Superfamily";
  src: url("shared/ABCAreal/ABCArealSuperfamilyVariable.woff2") format("woff2");
  font-weight: 400 700;
  font-style: oblique 0deg 12deg;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --font: "ABC Areal Superfamily", system-ui, sans-serif;
  --mono: 22; /* 0 is Areal, 50 Semi Mono, 100 Mono, and anything between */
  --pad: 0.8rem; /* space around the page, and the header's sides */
  --fg: #000;
  --bg: #cff2f2;
  --muted: #919191;
  --line: #ccc;
  --edge: #999; /* the site, the search suggestions, results headings */
  --card: #eee;
  --bar: #cff2f2; /* the header */
  --search: #f4f4f4; /* the search box, while hovered or typed in (see-through otherwise) */
  --link: #ff0000;
  --visited: #c147da;

  /* Sizes, which the Dev mode panel changes too (see site/shared/devmode.js). */
  --text: 14px;
  --small: 15px; /* the header, the sidebar, "Up next" */
  --leading: 1.3;
  --weight: 400;
  --col: 380px; /* the narrowest a listing's column gets */
  --thumb: 320px; /* a listing's thumbnails */
  --thumb-next: 140px; /* "Up next" thumbnails */
  --card-lines: 6; /* the most lines of a listing's title (then "…") */
  --next-lines: 4; /* the same in "Up next" */
  --thumb-ratio: 1.85; /* width / height */
  --row-pad: 5px; /* around a listing's rows */
  --row-gap: 0.75rem; /* between a thumbnail and its text */
  --aside: 300px; /* the site page's sidebar */
  --hero: 75vh; /* the site, in a narrow window */
  --tint: 41%; /* how much of the thumbnail's color a hovered row gets */
  --tint-floor: 6%;
  /* How dark a hovered row may get, from 0 (no darker than white) to 1 (no limit): a
     darker tint is lightened to 1 minus this (OKLCH lightness), keeping its hue. */
  --tint-ceiling: 0.16;
  --fade: 300ms; /* the hover tint's transition */
  --tracking: -0.02em; /* letter spacing */
  --underline: 0.07em; /* its thickness (the font's own) */
  --underline-gap: 0.1em; /* below the baseline (the font's own) */
  --border: 1px; /* every line's width */
  --radius: 0px; /* corners: square */
  --page-max: 4000px; /* the page's widest (centered past that) */
  --bar-pad: 4px; /* the header's padding above and below */
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #ddd;
    --bg: #003450;
    --muted: #999;
    --line: #333;
    --edge: #555;
    --card: #222;
    --bar: #003450;
    --search: #1e1e1e;
    --link: #ff6d61;
    --visited: #ae76fe;
    --tint-ceiling: 1; /* no limit: in dark mode the tint lightens */
  }
}

* {
  box-sizing: border-box;
  text-decoration-thickness: var(--underline);
  text-underline-offset: var(--underline-gap);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: var(--weight) var(--text) / var(--leading) var(--font);
  font-variation-settings: "MONO" var(--mono);
  letter-spacing: var(--tracking);
}

a {
  color: var(--link);
  text-decoration-line: none;

  &:hover {
    text-decoration-line: underline;
  }
  &:visited {
    color: var(--visited);
  }
}

.loading {
  padding: 2rem;
  color: var(--muted);
}

/* The label over a site shown as a screenshot (shared/components.js siteFrame). */
.frame-note {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  padding: 0.2rem 0.5rem;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
}

/* --- Listings (views.js siteCard): thumbnail, then title (domain) --- */

/* As many columns of rows as fit (one in a narrow window), read across like a page. */
.listing {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--col), 100%), 1fr));
  margin: 0;
}

.card,
.next {
  display: flex;
  align-items: flex-start;
  gap: var(--row-gap);
  padding: var(--row-pad);
  border-radius: var(--radius);
  text-decoration: none;
  transition: background-color var(--fade) ease;

  /* A pale tint of the thumbnail's main color (--avg, from index.json), mixed into the
     page's background so the text reads as usual; the text color mixed in too is
     a floor, so a white site's tint still shows, and --tint-ceiling a ceiling, so a
     dark site's isn't too dark. */
  &:hover {
    text-decoration-line: none;

    background-color: oklch(
      from
        color-mix(
          in srgb,
          color-mix(in srgb, var(--avg) var(--tint), var(--bg)),
          var(--fg) var(--tint-floor)
        )
        max(l, 1 - var(--tint-ceiling)) c h
    );
  }

  /* Narrower in a narrow column, so the text beside it keeps at least 8rem. */
  .thumb {
    flex: none;
    width: min(var(--thumb), 100% - 8rem);
  }

  /* The title and domain: free to be narrower than their longest word, which wraps
     instead (below), so a long one doesn't widen the page. */
  > span {
    min-width: 0;
  }
}

.next .thumb {
  width: min(var(--thumb-next), 100% - 8rem);
}

/* On a phone a listing's thumbnail goes above its text, as wide as the page, rather
   than beside it (where it left the text no room and made the page wider than the
   screen). */
@media (width <= 600px) {
  .card {
    flex-direction: column;
    gap: 0.25rem;

    .thumb {
      width: 100%;
    }
  }
}

.thumb {
  display: block;
  width: 100%;
  aspect-ratio: var(--thumb-ratio);
  object-fit: cover;
  object-position: top;
  background: var(--card);
  border: var(--border) solid var(--line);
  border-radius: var(--radius);
}

.card-title,
.card-meta {
  overflow-wrap: anywhere; /* a long word or domain wraps rather than widening the page */
}

.card-meta {
  color: var(--muted);
}

/* The title on its own lines, the domain under it. A very long title stops after a few
   lines (--card-lines in a listing, --next-lines in "Up next"), with "…"; the domain
   still shows. */
.card-title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--lines);
  line-clamp: var(--lines);
  overflow: hidden;
}

.card {
  --lines: var(--card-lines);
}

.next {
  --lines: var(--next-lines);
}

.next {
  font-size: var(--small);
}

header {
  display: flex;
  align-items: baseline; /* the texts on one line, the search box's included */
  gap: 1rem;
  padding: var(--bar-pad) var(--pad);
  background: var(--bar);
  font-size: var(--small);

  /* Breadcrumbs, then the page's links. */
  > .page-head {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 1rem;
    min-width: 0;

    h1 {
      display: flex;
      align-items: center;
      gap: 0.4rem;
      min-width: 0;
      margin: 0;
      font-size: inherit;
      font-weight: 400;
    }

    small {
      flex: none;
      color: var(--muted);
      font-size: inherit;
    }

    .crumb-home {
      font-weight: 700;
    }

    .crumb-sep {
      color: var(--muted);
    }

    .crumb-title {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .site-icon {
      flex: none;
      width: 16px;
      height: 16px;
      object-fit: contain;
    }
  }

  /* channels, about, after a line that sets them apart from the page's own links */
  > nav {
    display: flex;
    flex: none;
    gap: 1rem;
    padding-left: 1rem;
    border-left: var(--border) solid var(--edge);
  }

  /* The search box, its suggestions dropping down from it. */
  > form {
    position: relative;
    display: flex;
    gap: 4px;

    .search {
      appearance: none; /* not Safari's own search field, which sets its text lower */
      width: min(220px, 40vw);
      margin: 0;
      border: none;
      background: transparent;
      color: inherit;
      font: inherit;
      transition: background-color var(--fade) ease;
      padding: 1px 3px;
      border-radius: 2px;

      &:hover,
      &:focus {
        background: var(--search);
      }

      &:focus {
        outline: none; /* the fill shows it's being typed in */
      }
    }
  }

  /* On a phone: the breadcrumbs on their own line, then the nav and the search box
     (filling the rest of the line) under them. */
  @media (width <= 600px) {
    flex-wrap: wrap;
    row-gap: 0.25rem;

    > .page-head {
      flex-basis: 100%;
    }

    > nav {
      padding-left: 0;
      border-left: none;
    }

    > form {
      flex: 1;

      .search {
        width: 100%;
      }
    }
  }
}

/* Suggestions drop down from the search box. */
.suggest {
  position: absolute;
  z-index: 1;
  top: calc(100% + 2px);
  right: 0;
  width: max(100%, 320px);
  margin: 0;
  padding: 2px;
  border: var(--border) solid var(--edge);
  border-radius: var(--radius);
  background: var(--bg);
  list-style: none;

  a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px;
    text-decoration: none;

    &.active {
      background: var(--bar);
    }

    > span {
      display: flex;
      flex-direction: column;
      min-width: 0;
    }
  }
}

.suggest-heading,
.suggest-status {
  padding: 4px 3px 2px;
  color: var(--muted);
  font-size: 11px;
}

.suggest-heading {
  font-weight: 700;
}

.suggest-thumb {
  flex: none;
  width: 48px;
  height: 30px;
  object-fit: cover;
  object-position: top;
  border: var(--border) solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.suggest-title,
.suggest-domain {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggest-title {
  font-size: var(--small);
  text-decoration-line: underline;
}

.suggest-domain {
  color: var(--muted);
  font-size: 12px;
}

/* --- Home, search, channels, about --- */

.home {
  max-width: var(--page-max);
  margin-inline: auto;
  padding: var(--pad);
}

.results-heading {
  margin: 1.5rem 0 0.25rem;
  padding-bottom: 2px;
  border-bottom: var(--border) solid var(--edge);
  font-size: var(--text);
  font-weight: 700;

  &:first-child {
    margin-top: 0;
  }
}

.channel-list {
  margin: 0;
  padding: 0;
  columns: 240px;
  list-style: none;

  li {
    padding: 1px 0;
    break-inside: avoid;
  }
}

/* The categories' boxes (views.js channelsView), down as many columns as fit, like
   Craigslist's front page: a bar with the name, then the channels, each over a line. */
.channel-groups {
  columns: 300px;
  column-gap: 1.5rem;
}

.channel-group {
  break-inside: avoid;
  margin-bottom: 1.5rem;

  h2 {
    margin: 0;
    padding: 4px 6px;
    background: var(--card);
    font-size: var(--small);
    font-weight: 700;
    text-align: center;
  }

  .channel-list {
    columns: auto;

    li {
      padding: 3px 6px;
      border-bottom: var(--border) solid var(--line);
    }
  }
}

.channel-meta,
.results-status,
.more {
  color: var(--muted);
}

/* A channel's owner, linking to their Are.na page, in the same grey. */
.channel-meta a,
.channel-meta a:visited {
  color: inherit;
}

/* --- Site ("watch") page --- */

/* With two columns the site page is exactly the window's height: the header, then
   the page in the rest. The page itself doesn't scroll. */
@media (width > 900px) {
  #app:has(> .watch) {
    display: flex;
    flex-direction: column;
    height: 100dvh;
  }
}

.watch {
  display: grid;
  width: 100%;
  max-width: var(--page-max);
  margin-inline: auto;
  grid-template-columns: minmax(0, 1fr) var(--aside);
  gap: 1rem;
  padding: var(--pad);

  @media (width <= 900px) {
    /* No wider than the window, whatever's in it. */
    grid-template-columns: minmax(0, 1fr);
  }

  /* Two columns filling the window under the header: the site fills its column and
     only the "Up next" list scrolls. */
  @media (width > 900px) {
    flex: 1;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr);

    article {
      display: flex;
      flex-direction: column;
    }

    aside {
      overflow-y: auto;
    }

    .hero-frame,
    .hero-shot {
      flex: 1;
      min-height: 0;
      height: auto;
    }

    .hero-shot .hero-img {
      height: 100%;
    }
  }
}

.hero-shot {
  position: relative;
  display: block;
}

.hero-img {
  display: block;
  width: 100%;
  height: var(--hero);
  object-fit: contain;
  border: var(--border) solid var(--edge);
  border-radius: var(--radius);
  background: var(--card);
}

.hero-frame {
  display: block;
  width: 100%;
  height: var(--hero);
  border: var(--border) solid var(--edge);
  border-radius: var(--radius);
  background: #fff; /* white in dark mode too: what a page with no background expects */
}

.links {
  display: flex;
  flex: none;
  gap: 1rem;
  margin: 0;
  color: var(--muted);
}

/* The sidebar's top row: the radio buttons, and (in a narrow window) the site's links. */
.aside-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap; /* the links under the radio buttons if they don't fit beside them */
  justify-content: space-between;
  gap: 0.25rem 1rem;
  margin-bottom: 0.25rem;
  font-size: var(--small);
}

/* On a site page in a narrow window the header has no room for the site's links (the
   title gets it): they move beside the sidebar's radio buttons. */
.aside-links {
  display: none;
}

@media (width <= 900px) {
  header:has(~ .watch) .page-head .links {
    display: none;
  }

  .aside-links {
    display: flex;
  }
}

/* "Related" / "Same channel": plain radio buttons. */
.up-next {
  display: flex;
  gap: 0.75rem;

  label {
    display: flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
    cursor: pointer;
  }

  input {
    margin: 0;
  }
}

/* "Same channel": a heading per channel, linking to its page. */
.up-next-channel {
  display: block;
  margin: 0.25rem 0;
  font-size: var(--small);
  font-weight: 700;

  .next + & {
    margin-top: 1rem;
  }
}

/* Dev mode's category controls (the dev server only: see views.js channelsView). */
.dev-new-category {
  display: flex;
  gap: 4px;
  margin-bottom: 1rem;
}

.dev-button {
  margin-left: 0.5rem;
  font: inherit;
  font-size: 11px;
  font-weight: 400;
}

.dev-category {
  margin-left: 0.5rem;
  font: inherit;
  font-size: 11px;
}

/* About: a few lines of text. */
.about p {
  max-width: 36rem;
  margin: 0 0 0.75rem;
}
