/* The public site's one stylesheet. Plain CSS, no build step: shared values are custom
   properties on :root, components nest their own rules. */

:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --line: #e4e2dc;
  --accent: #0b6e4f;
  --up: #0b6e4f;
  --down: #a4372b;
  --error: #a4372b;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --radius: 6px;
  --measure: 48rem;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #1f1f1d;
    --text: #ecebe6;
    --muted: #9c9a93;
    --line: #34332f;
    --accent: #4cc39a;
    --up: #4cc39a;
    --down: #e4796b;
    --error: #e4796b;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--step-0) / 1.45 var(--font);
}

a {
  color: inherit;
}

button {
  font: inherit;
}

.top {
  border-bottom: 1px solid var(--line);
  background: var(--surface);

  & .bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    max-width: var(--measure);
    margin: 0 auto;
    padding: var(--space-2) var(--space-3);
  }

  & .brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-weight: 700;
    text-decoration: none;
    color: var(--accent);
  }

  & .feeds {
    display: flex;
    gap: var(--space-3);
    flex: 1;

    & a {
      text-decoration: none;
      color: var(--muted);
    }

    & a[aria-current="page"] {
      color: var(--text);
      font-weight: 600;
    }
  }

  & .account {
    display: flex;
    gap: var(--space-3);
    white-space: nowrap;

    & form {
      margin: 0;
    }
  }
}

button.link {
  border: 0;
  padding: 0;
  background: none;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: var(--space-3);
}

.hint,
.empty,
.muted {
  color: var(--muted);
  font-size: var(--step--1);
}

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
}

.item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: start;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--line);

  & .title {
    font-weight: 600;
    text-decoration: none;

    &:visited {
      color: var(--muted);
    }
  }
}

/* The middle of a feed row or a post's head. min-width: 0 lets the grid shrink it below its
   longest word, so a long title or byline wraps instead of pushing the votes off-screen. */
.entry {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* The card's thumbnail, cropped square; a neutral square keeps the row aligned without one. */
.thumb {
  display: block;
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--line);
}

.meta {
  margin: var(--space-1) 0 0;
  color: var(--muted);
  font-size: var(--step--1);

  /* Each piece wraps as a whole, never "há 9" on one line and "h" on the next; the whitespace
     between pieces in the templates is where a line may break. */
  & span {
    white-space: nowrap;
  }

  /* The separator ends a piece rather than starting the next, so a wrapped line never begins
     with it. */
  & span:not(:last-child)::after {
    content: " ·";
  }
}

.vote {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 2.5rem;
  margin: 0;

  & .arrow {
    border: 0;
    background: none;
    color: var(--muted);
    cursor: pointer;
    padding: 2px var(--space-2);
    border-radius: 4px;
    line-height: 1;
    font-size: var(--step--1);
  }

  /* The pressed arrow's colour is about as dark as the unpressed grey, so hue alone barely
     shows it (and not at all to colour-blind readers): a tinted chip marks it by shape too. */
  & .arrow[value="1"][aria-pressed="true"] {
    color: var(--up);
    background: color-mix(in srgb, var(--up) 18%, transparent);
  }

  & .arrow[value="-1"][aria-pressed="true"] {
    color: var(--down);
    background: color-mix(in srgb, var(--down) 18%, transparent);
  }

  & .score {
    font-size: var(--step--1);
    font-variant-numeric: tabular-nums;
  }

  &.htmx-request {
    opacity: 0.5;
  }
}

.card {
  max-width: 24rem;
  margin: var(--space-4) auto;
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);

  & h1 {
    font-size: var(--step-1);
    margin: 0 0 var(--space-1);
  }
}

.stack {
  display: grid;
  gap: var(--space-3);

  & label {
    display: grid;
    gap: var(--space-1);
    font-size: var(--step--1);
  }

  & input {
    font: inherit;
    padding: var(--space-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
  }
}

button.primary {
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  cursor: pointer;
}

.error {
  color: var(--error);
}

/* The sign-up captcha widget, as wide as the fields around it. */
altcha-widget {
  --altcha-max-width: 100%;
}

/* A post's own page: the same row as the feed, larger, then the comments. */
.post {
  & .post-row {
    display: grid;
    grid-template-columns: 112px 1fr auto;
    align-items: start;
    gap: var(--space-3);
  }

  & .thumb {
    width: 112px;
    height: 112px;
  }

  & h1 {
    font-size: var(--step-1);
    line-height: 1.3;
    margin: 0;

    & a {
      text-decoration: none;
    }
  }

  & .vote {
    min-width: 3rem;

    & .arrow {
      font-size: var(--step-1);
      padding: var(--space-1) var(--space-2);
    }

    & .score {
      font-size: var(--step-0);
      font-weight: 600;
    }
  }

  & .lede {
    margin: var(--space-3) 0 0;
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--line);
  }

  & .comments {
    padding-top: var(--space-3);

    & h2 {
      font-size: var(--step-0);
      margin: 0 0 var(--space-2);
    }
  }
}

/* A page's own heading, above a list of posts. */
.page-title {
  font-size: var(--step-1);
  margin: 0 0 var(--space-2);
}

/* An account's alias in a byline: a site user, not an article's author. */
a.user {
  color: inherit;
}
