/* The mirror's stylesheet.
 *
 * It follows Discourse's own default theme: the same color roles
 * (`--primary` for text, `--secondary` for the background, `--tertiary` for
 * links and accents), a similar topic list and post layout, and styling for
 * the markup that Discourse's server-rendered post HTML brings with it
 * (quotes, oneboxes, mentions, lightboxed images, footnotes, tables).
 */

:root {
  color-scheme: light;
  --primary: #222222;
  --primary-medium: #646464;
  --primary-low-mid: #999999;
  --primary-low: #e9e9e9;
  --primary-very-low: #f4f4f4;
  --secondary: #ffffff;
  --tertiary: #0088cc;
  --tertiary-low: #e5f3f9;
  --highlight-low: #fdf8c3;
  --warning-bg: #fff8e6;
  --warning-border: #f0c36d;
  --warning-text: #7a5b00;
  --shadow: rgba(0, 0, 0, 0.07);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

/* Discourse's default dark scheme, used when the viewer's system asks for a
 * dark theme and they haven't overridden it here... */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --primary: #dddddd;
    --primary-medium: #9b9b9b;
    --primary-low-mid: #767676;
    --primary-low: #333333;
    --primary-very-low: #1e1e1e;
    --secondary: #111111;
    --tertiary: #3c9fd4;
    --tertiary-low: #17313d;
    --highlight-low: #4a3c16;
    --warning-bg: #302812;
    --warning-border: #7a5b00;
    --warning-text: #e3c66d;
    --shadow: rgba(0, 0, 0, 0.5);
  }
}

/* ...and whenever they pick dark with the header's toggle. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --primary: #dddddd;
  --primary-medium: #9b9b9b;
  --primary-low-mid: #767676;
  --primary-low: #333333;
  --primary-very-low: #1e1e1e;
  --secondary: #111111;
  --tertiary: #3c9fd4;
  --tertiary-low: #17313d;
  --highlight-low: #4a3c16;
  --warning-bg: #302812;
  --warning-border: #7a5b00;
  --warning-text: #e3c66d;
  --shadow: rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--secondary);
  color: var(--primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

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

a:hover {
  text-decoration: underline;
}

/* --- Page chrome ---------------------------------------------------- */

.wrap {
  max-width: 62rem;
  margin: 0 auto;
  padding: 0 1rem;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--secondary);
  border-bottom: 1px solid var(--primary-low);
  box-shadow: 0 2px 4px -2px var(--shadow);
}

.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 3.25rem;
  flex-wrap: wrap;
}

.site-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--primary);
  margin-right: auto;
}

.site-title:hover {
  text-decoration: none;
  color: var(--tertiary);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.site-nav a {
  padding: 0.35rem 0.6rem;
  border-radius: 0.25rem;
  color: var(--primary-medium);
}

.site-nav a:hover {
  background: var(--primary-very-low);
  color: var(--primary);
  text-decoration: none;
}

.site-nav a[aria-current="page"] {
  background: var(--primary-very-low);
  color: var(--primary);
  font-weight: 600;
}

/* The header's light/dark toggle. It shows the theme it would switch *to*,
 * which is also why the icons are swapped in CSS rather than in script: the
 * right one shows before any JavaScript runs. */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: 0.25rem;
  background: none;
  color: var(--primary-medium);
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--primary-very-low);
  color: var(--primary);
}

.theme-toggle svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: currentColor;
}

.theme-toggle .sun {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun {
    display: block;
  }

  :root:not([data-theme="light"]) .theme-toggle .moon {
    display: none;
  }
}

:root[data-theme="dark"] .theme-toggle .sun {
  display: block;
}

:root[data-theme="dark"] .theme-toggle .moon {
  display: none;
}

:root[data-theme="light"] .theme-toggle .sun {
  display: none;
}

:root[data-theme="light"] .theme-toggle .moon {
  display: block;
}

main {
  padding: 1.5rem 0 2rem;
}

.page-title {
  font-size: 1.6rem;
  line-height: 1.25;
  margin: 0 0 0.5rem;
}

.page-subtitle {
  color: var(--primary-medium);
  margin: 0 0 1.5rem;
  font-size: 0.95em;
}

.breadcrumb {
  margin: 0 0 1rem;
  font-size: 0.9em;
  color: var(--primary-medium);
}

footer.build {
  margin-top: 3rem;
  padding: 1rem 0 2rem;
  border-top: 1px solid var(--primary-low);
  font-size: 0.85em;
  color: var(--primary-medium);
  text-align: center;
}

/* --- Category and tag pages ----------------------------------------- */

.category-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
  gap: 1rem;
}

.category-card {
  padding: 0.75rem 1rem;
  border: 1px solid var(--primary-low);
  border-left: 6px solid var(--category-color, var(--primary-low-mid));
  border-radius: 0.25rem;
}

.category-card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.category-card h2 a {
  color: var(--primary);
}

.category-description {
  margin: 0 0 0.5rem;
  color: var(--primary-medium);
  font-size: 0.9em;
}

.category-count {
  margin: 0;
  color: var(--primary-low-mid);
  font-size: 0.85em;
}

.subcategories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.6rem;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag-list .discourse-tag {
  font-size: 0.95em;
  padding: 0.25rem 0.6rem;
}

.tag-count {
  margin-left: 0.4rem;
  color: var(--primary-low-mid);
  font-size: 0.85em;
}

a.discourse-tag:hover,
a.badge-category:hover {
  background: var(--tertiary-low);
  color: var(--primary);
  text-decoration: none;
}

/* The header's link off to the source site sits apart from the mirror's own
 * pages, and is the first thing to drop on a narrow screen. */
.site-nav .source-link {
  margin-left: 0.5rem;
  border-left: 1px solid var(--primary-low);
  padding-left: 0.85rem;
}

@media (max-width: 34rem) {
  .site-nav .source-link {
    display: none;
  }
}

/* --- Topic list ----------------------------------------------------- */

.topic-list {
  width: 100%;
  border-collapse: collapse;
}

.topic-list th {
  padding: 0.5rem;
  text-align: left;
  font-weight: normal;
  font-size: 0.9em;
  color: var(--primary-medium);
  border-bottom: 2px solid var(--primary-low);
}

.topic-list td {
  padding: 0.7rem 0.5rem;
  border-bottom: 1px solid var(--primary-low);
  vertical-align: middle;
}

.topic-list tbody tr:hover td {
  background: var(--primary-very-low);
}

.topic-list .title {
  font-size: 1.05em;
  font-weight: 500;
  color: var(--primary);
}

.topic-list .title:hover {
  color: var(--tertiary);
  text-decoration: none;
}

.topic-list .title:visited {
  color: var(--primary-medium);
}

.topic-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.3rem;
}

.topic-list th.num,
.topic-list td.num {
  width: 4.5rem;
  text-align: right;
  white-space: nowrap;
  color: var(--primary-medium);
  font-size: 0.9em;
}

.topic-list td.num a {
  color: var(--primary-medium);
}

.topic-list td.num a:hover {
  color: var(--tertiary);
  text-decoration: none;
}

.topic-list .posters {
  width: 9.5rem;
  white-space: nowrap;
}

img.poster {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  margin-right: 0.25rem;
  vertical-align: middle;
}

/* The original poster and whoever posted last are the two faces worth
 * telling apart, as Discourse does. */
img.poster.op {
  box-shadow: 0 0 0 2px var(--tertiary);
}

img.poster.latest {
  box-shadow: 0 0 0 2px var(--primary-low-mid);
}

.badge-category {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.1rem 0.4rem;
  border-radius: 0.2rem;
  background: var(--primary-very-low);
  color: var(--primary-medium);
  font-size: 0.85em;
}

.badge-category::before {
  content: "";
  flex: none;
  width: 0.65em;
  height: 0.65em;
  border-radius: 2px;
  background: var(--category-color, var(--primary-low-mid));
}

.discourse-tag {
  padding: 0.1rem 0.4rem;
  border-radius: 0.2rem;
  background: var(--primary-very-low);
  color: var(--primary-medium);
  font-size: 0.8em;
}

/* Narrow screens: the columns stack under the title, labelled by the
 * `data-label` the renderer puts on each of them. */
@media (max-width: 45rem) {
  .topic-list thead {
    display: none;
  }

  .topic-list,
  .topic-list tbody,
  .topic-list tr,
  .topic-list td {
    display: block;
    width: auto;
  }

  .topic-list tr {
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--primary-low);
  }

  .topic-list td {
    padding: 0.15rem 0;
    border: 0;
  }

  .topic-list td.num {
    display: inline-block;
    width: auto;
    margin-right: 1rem;
    text-align: left;
  }

  .topic-list td.num::before {
    content: attr(data-label) " ";
  }

  .topic-list .posters {
    margin-top: 0.3rem;
  }
}

.topic-filter {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.topic-filter input {
  flex: 1 1 auto;
  max-width: 24rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--primary-low-mid);
  border-radius: 0.25rem;
  background: var(--secondary);
  color: var(--primary);
  font-family: inherit;
  font-size: 0.95em;
}

.topic-filter input:focus {
  outline: 2px solid var(--tertiary);
  outline-offset: -1px;
}

.filter-count {
  color: var(--primary-medium);
  font-size: 0.9em;
}

.filter-empty {
  color: var(--primary-medium);
  padding: 1rem 0;
}

/* The stacked layout of a narrow screen gives rows a `display` of their own,
 * which would otherwise win over the browser's rule for `[hidden]`. */
.topic-list tbody tr[hidden] {
  display: none;
}

/* --- Topic page ----------------------------------------------------- */

.topic .wrap {
  max-width: 53rem;
}

.topic-header {
  border-bottom: 1px solid var(--primary-low);
  padding-bottom: 0.75rem;
  margin-bottom: 0.5rem;
}

.topic-meta {
  color: var(--primary-medium);
  font-size: 0.9em;
}

/* Discourse's "topic map": the topic's dates and counts and everyone who
 * posted in it, shown under the first post. */
.topic-map {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin: 0 0 0.5rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--primary-low);
  border-radius: 0.3rem;
  background: var(--primary-very-low);
}

.topic-map-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.topic-map .stat {
  display: flex;
  flex-direction: column;
  font-size: 0.8em;
  color: var(--primary-medium);
}

.topic-map .stat .value {
  font-size: 1.3em;
  font-weight: 600;
  color: var(--primary);
}

.topic-map-users {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-left: auto;
}

.participant {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--primary-medium);
  font-size: 0.85em;
}

.participant:hover {
  text-decoration: none;
  color: var(--primary);
}

.participant img {
  width: 25px;
  height: 25px;
  border-radius: 50%;
}

/* The topic map sits where a reply to the first post would, so it is indented
 * to line up with the posts' bodies rather than their avatars. */
.topic .topic-map {
  margin-left: calc(45px + 0.85rem);
}

@media (max-width: 40rem) {
  .topic .topic-map {
    margin-left: 0;
  }

  .topic-map-users {
    margin-left: 0;
  }
}

.post {
  display: grid;
  grid-template-columns: 45px minmax(0, 1fr);
  gap: 0 0.85rem;
  padding: 1.25rem 0;
  border-top: 1px solid var(--primary-low);
}

.post:first-of-type {
  border-top: 0;
}

.post:target {
  background: var(--highlight-low);
  box-shadow: 0 0 0 0.5rem var(--highlight-low);
  border-radius: 2px;
}

.post-avatar img {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  display: block;
}

.post-main {
  min-width: 0;
}

.post-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.post-author {
  font-weight: 700;
  color: var(--primary);
}

.post-info {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  color: var(--primary-low-mid);
  font-size: 0.85em;
}

.post-info a {
  color: var(--primary-low-mid);
}

.post-info a:hover {
  color: var(--primary-medium);
}

.reply-to {
  display: inline-block;
  font-size: 0.85em;
  color: var(--primary-medium);
  margin-bottom: 0.4rem;
}

.missing-posts {
  border: 1px solid var(--warning-border);
  background: var(--warning-bg);
  color: var(--warning-text);
  border-radius: 0.25rem;
  padding: 0.5rem 1rem;
  margin: 1rem 0;
  font-size: 0.9em;
}

/* --- Post content (Discourse's "cooked" HTML) ----------------------- */

.cooked > *:first-child {
  margin-top: 0;
}

.cooked > *:last-child {
  margin-bottom: 0;
}

.cooked p {
  margin: 0 0 1em;
}

.cooked h1,
.cooked h2,
.cooked h3,
.cooked h4 {
  line-height: 1.25;
  margin: 1.5em 0 0.5em;
}

.cooked h1 {
  font-size: 1.4em;
}

.cooked h2 {
  font-size: 1.25em;
}

.cooked h3 {
  font-size: 1.1em;
}

.cooked img {
  max-width: 100%;
  height: auto;
}

.cooked hr {
  border: 0;
  border-top: 1px solid var(--primary-low);
  margin: 1.5em 0;
}

.cooked code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--primary-very-low);
  padding: 0.1em 0.3em;
  border-radius: 0.2rem;
}

.cooked pre {
  background: var(--primary-very-low);
  border-radius: 0.3rem;
  padding: 0.75rem;
  overflow-x: auto;
  margin: 1em 0;
}

.cooked pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
  line-height: 1.45;
}

.cooked blockquote {
  margin: 1em 0;
  padding: 0.6em 1em;
  border-left: 5px solid var(--primary-low);
  background: var(--primary-very-low);
}

.cooked blockquote > *:first-child {
  margin-top: 0;
}

.cooked blockquote > *:last-child {
  margin-bottom: 0;
}

/* Quoting another post: a header naming the quoted author, then the quote. */
aside.quote {
  margin: 1em 0;
}

aside.quote .title {
  padding: 0.5em 0.8em;
  border: 1px solid var(--primary-low);
  border-bottom: 0;
  border-left: 5px solid var(--primary-low);
  background: var(--primary-very-low);
  color: var(--primary-medium);
  font-size: 0.9em;
}

aside.quote .title img.avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  vertical-align: -0.3em;
  margin-right: 0.35em;
}

aside.quote .quote-controls {
  display: none;
}

aside.quote blockquote {
  margin: 0;
  border: 1px solid var(--primary-low);
  border-left: 5px solid var(--primary-low);
  background: var(--secondary);
}

.cooked table {
  border-collapse: collapse;
  margin: 1em 0;
}

.cooked th,
.cooked td {
  border: 1px solid var(--primary-low);
  padding: 0.4em 0.7em;
  text-align: left;
}

.cooked thead th {
  background: var(--primary-very-low);
}

.md-table {
  overflow-x: auto;
  margin: 1em 0;
}

.md-table table {
  margin: 0;
}

a.mention,
a.hashtag-cooked {
  background: var(--primary-very-low);
  color: var(--primary-medium);
  padding: 0.1em 0.35em;
  border-radius: 0.6em;
  font-size: 0.93em;
}

a.mention:hover,
a.hashtag-cooked:hover {
  background: var(--tertiary-low);
  color: var(--primary);
  text-decoration: none;
}

.hashtag-icon-placeholder {
  display: none;
}

img.emoji {
  width: 1.2em;
  height: 1.2em;
  vertical-align: -0.2em;
}

.only-emoji img.emoji {
  width: 2em;
  height: 2em;
}

/* TeX that Discourse's math plugin renders client-side; without it, show the
 * source as code rather than as broken prose. */
span.math {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--primary-very-low);
  padding: 0.1em 0.3em;
  border-radius: 0.2rem;
}

div.math {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--primary-very-low);
  border-radius: 0.3rem;
  padding: 0.6em 0.75em;
  margin: 1em 0;
  overflow-x: auto;
  white-space: pre-wrap;
}

/* KaTeX draws in the inherited text colour, so it follows the page into dark
 * mode on its own; all it needs is somewhere to go when a display equation is
 * wider than the column. */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.3rem 0;
}

/* Once a formula has been typeset, the styling that made its TeX source
 * legible as code would only fight the result. */
.math-rendered {
  padding: 0;
  background: none;
  font-family: inherit;
  white-space: normal;
}

.discourse-local-date {
  background: var(--primary-very-low);
  padding: 0.1em 0.3em;
  border-radius: 0.2rem;
}

.footnotes {
  margin-top: 1.5em;
  padding-top: 0.5em;
  border-top: 1px solid var(--primary-low);
  font-size: 0.9em;
  color: var(--primary-medium);
}

/* Discourse's lightbox chrome: the caption bar carries unsized <svg> icons
 * that, without Discourse's CSS, fall back to the 300x150 default and leave a
 * big gap under each image. It is only useful for the (absent) JS lightbox. */
.lightbox-wrapper .meta {
  display: none;
}

svg.d-icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
}

/* --- Oneboxes (rich link previews) ---------------------------------- */

aside.onebox {
  border: 1px solid var(--primary-low);
  border-left-width: 5px;
  border-radius: 0.25rem;
  padding: 0.75rem 1rem;
  margin: 1em 0;
  overflow: hidden;
}

aside.onebox .source {
  font-size: 0.85em;
  color: var(--primary-medium);
  margin-bottom: 0.5rem;
}

aside.onebox .source .site-icon {
  width: 1em;
  height: 1em;
  vertical-align: text-bottom;
  margin-right: 0.35em;
}

aside.onebox .onebox-body {
  overflow: hidden;
}

aside.onebox .onebox-body h3,
aside.onebox .onebox-body h4 {
  margin: 0.2em 0;
  font-size: 1.05em;
}

aside.onebox .onebox-body p {
  margin: 0.4em 0;
}

aside.onebox .aspect-image,
aside.onebox .onebox-body img.thumbnail {
  float: right;
  max-width: 25%;
  height: auto;
  margin: 0 0 0.5rem 1rem;
}

/* GitHub-blob oneboxes wrap an <ol class="lines"> in a <pre>, whose literal
 * newlines and indentation render as blank lines without Discourse's CSS.
 * Reset the pre's whitespace and render the list as a line-numbered block. */
pre.onebox {
  white-space: normal;
  background: none;
  padding: 0;
  margin: 0.5rem 0;
}

pre.onebox ol.lines {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--primary-very-low);
  border-radius: 0.25rem;
  overflow-x: auto;
}

pre.onebox ol.lines li {
  counter-increment: li-counter;
  white-space: pre;
}

pre.onebox ol.lines li::before {
  content: counter(li-counter);
  display: inline-block;
  width: 3em;
  margin-right: 1em;
  color: var(--primary-low-mid);
  text-align: right;
}

@media (max-width: 40rem) {
  .post {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 0 0.6rem;
  }

  .post-avatar img {
    width: 30px;
    height: 30px;
  }

  .post-info {
    margin-left: 0;
  }
}

/* --- Category colors (from the source site) ---------- */

.category-1 { --category-color: #0088CC; }
.category-2 { --category-color: #808281; }
.category-5 { --category-color: #9EB83B; }
.category-6 { --category-color: #ED207B; }
.category-7 { --category-color: #F7941D; }
.category-8 { --category-color: #12A89D; }
.category-9 { --category-color: #652D90; }
.category-10 { --category-color: #0088CC; }
