/* The tokens of DESIGN.md. Every color, size and border below them is one of these (`make css-check`). */

:root {
  color-scheme: light dark;

  /* Color roles */
  --color-bg: #fbfbf9;
  --color-surface: #f1f1ed;
  --color-text: #1d1d1b;
  --color-muted: #6b6b66;
  --color-border: #dcdcd5;
  --color-accent: #9a4a12;
  --color-accent-text: #ffffff;
  --color-danger: #a3261b;
  --color-ok: #2f6b2f;
  --color-notice: #fdf3e1;
  --color-notice-border: #e3b665;
  --color-added: #e6f4e6;
  --color-removed: #fbe9e7;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2.5rem;

  /* Type */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.2rem;
  --text-xl: 1.5rem;
  --leading-tight: 1.25;
  --leading-base: 1.55;
  --weight-strong: 650;

  /* Shapes: borders, rules, radii and the focus ring; no shadows */
  --border-width: 1px;
  --rule-thin: 2px;
  --rule: 3px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-pill: 999px;
  --focus-ring: 2px solid var(--color-accent);
  --focus-offset: 1px;

  /* Controls: every input, select, button and button-like link */
  --control-height: 2.5rem;
  --control-padding-x: var(--space-3);
  --control-padding-y: var(--space-2);
  --control-font-size: var(--text-base);
  --control-line-height: var(--leading-tight);

  /* Widths */
  --width-measure: 70ch;
  --width-page: 52rem;
  --width-wide: 90rem;
  --width-panel: 31.25rem;
  --width-indent: 1.25rem;
  --width-search: 12rem;
  --width-menu: 13rem;
  --badge-size: 1.25rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #161615;
    --color-surface: #202020;
    --color-text: #e9e9e4;
    --color-muted: #a2a29b;
    --color-border: #3a3a36;
    --color-accent: #f0a060;
    --color-accent-text: #161615;
    --color-danger: #ff8a7a;
    --color-ok: #8fd18f;
    --color-notice: #33291a;
    --color-notice-border: #8a6a32;
    --color-added: #1d3320;
    --color-removed: #3d2220;
  }
}

/* End of the tokens */

/* Base */

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "header" "main" "footer";
  background: var(--color-bg);
  color: var(--color-text);
  font: var(--text-base) / var(--leading-base) var(--font-sans);
  overflow-wrap: anywhere;
}

body > header { grid-area: header; }
body > main { grid-area: main; }
body > footer { grid-area: footer; }

body > header,
body > main,
body > footer {
  width: 100%;
  max-width: var(--width-page);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

main { padding-block: var(--space-5) var(--space-6); }

main p, main li, .text { max-width: var(--width-measure); }

h1, h2, h3 { line-height: var(--leading-tight); font-weight: var(--weight-strong); margin: var(--space-5) 0 var(--space-2); }
h1 { font-size: var(--text-xl); margin-top: 0; }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-base); }

p { margin: 0 0 var(--space-2); }

a { color: var(--color-accent); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: var(--rule-thin); }

pre, code { font-family: var(--font-mono); font-size: var(--text-sm); }
pre {
  margin: 0 0 var(--space-4);
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  overflow-x: auto;
  white-space: pre-wrap;
}

blockquote {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-4);
  border-left: var(--rule) solid var(--color-border);
  color: var(--color-muted);
}

hr { border: 0; border-top: var(--border-width) solid var(--color-border); margin: var(--space-5) 0; }

/* Header and nav */

body > header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  padding-block: var(--space-4);
  border-bottom: var(--border-width) solid var(--color-border);
}

.brand { font-weight: var(--weight-strong); color: var(--color-text); text-decoration: none; }

header nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-4);
  font-size: var(--text-sm);
}

header nav a, header .sign-in, header .search-link { color: var(--color-muted); text-decoration: none; font-size: var(--text-sm); }
header nav a:hover, header .sign-in:hover, header .search-link:hover { color: var(--color-text); }

/* One row: the brand and the feeds on the left; the search, Submit and the account on the right. */
header form[role="search"] { margin: 0 0 0 auto; }
header form[role="search"] input { flex: none; width: var(--width-search); max-width: 40vw; }
header .search-link, header .break { display: none; }

/* The account menu: a <details>, so it works with no script; menu.js closes it with Escape or a click outside. */
details.account { position: relative; display: flex; margin: 0; font-size: var(--text-sm); }
details.account > summary { gap: var(--space-1); list-style: none; }
details.account > summary::-webkit-details-marker { display: none; }
.viewer { font-weight: var(--weight-strong); color: var(--color-text); }
.badge {
  min-width: var(--badge-size);
  padding: 0 var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--color-accent);
  color: var(--color-accent-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  text-align: center;
}
details.account .menu {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-1));
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-width: var(--width-menu);
  padding: var(--space-1) 0;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}
details.account .menu > a, details.account .menu button {
  display: block;
  width: 100%;
  height: auto;
  padding: var(--space-1) var(--space-4);
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--color-text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
details.account .menu > a:hover, details.account .menu button:hover { background: var(--color-bg); }
details.account .menu form { display: block; margin: 0; }
details.account .menu .group {
  margin: var(--space-2) 0 0;
  padding: 0 var(--space-4);
  color: var(--color-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
details.account .menu hr { margin: var(--space-1) 0; }
details.account .menu .updates { color: var(--color-accent); font-weight: var(--weight-strong); }

/* Footer */

body > footer {
  padding-block: var(--space-4) var(--space-5);
  border-top: var(--border-width) solid var(--color-border);
  color: var(--color-muted);
  font-size: var(--text-sm);
}

/* Notices and messages */

.banner, .notice {
  margin-block: var(--space-4) var(--space-5);
  padding: var(--space-2) var(--space-4);
  background: var(--color-notice);
  border-left: var(--rule) solid var(--color-notice-border);
  border-radius: var(--radius-md);
}

main > .banner:first-child { margin-top: 0; }
.banner > p { margin-block: 0; }
.banner > form { margin-top: var(--space-2); }

.problem {
  margin-block: var(--space-4);
  padding: var(--space-2) var(--space-4);
  border-left: var(--rule) solid var(--color-danger);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-danger);
}

.state, .reason, .voted, .count, .host, .meta, .snippet { color: var(--color-muted); font-size: var(--text-sm); }
.state { font-style: italic; }
.state, .reason, .voted { margin-block: var(--space-2); }

/* Feeds and search */

ol.feed, ol.results, ol.queue, ol.log, ul.emails, ul.passkeys, ul.agents, ul.keys, ol.history {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-5);
}

.feed > li, .results > li { margin-bottom: var(--space-4); }
.feed > li::marker { color: var(--color-muted); font-size: var(--text-sm); }
.item > a:first-child, .hit > a:first-child { font-weight: 500; }
.item .meta, .hit .meta { margin: var(--space-1) 0 0; }
.meta a { color: inherit; }


/* A post */

.post h1 .host { font-size: var(--text-sm); font-weight: 400; }
.post .meta { margin-bottom: var(--space-4); }
.post form, .comment form[action$="/vote"] { margin: 0 var(--space-2) var(--space-2) 0; }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-4); }
.text { margin-block: var(--space-4); }
.text > :last-child { margin-bottom: 0; }

/* Comments */

.comments { margin-top: var(--space-6); }
.comment {
  margin: var(--space-4) 0;
  padding-left: var(--space-4);
  border-left: var(--rule-thin) solid var(--color-border);
}
.comment .meta { margin-bottom: var(--space-1); }
.comment .text { margin-block: var(--space-1) var(--space-2); }
.depth-1 { margin-left: calc(1 * var(--width-indent)); }
.depth-2 { margin-left: calc(2 * var(--width-indent)); }
.depth-3 { margin-left: calc(3 * var(--width-indent)); }
.depth-4 { margin-left: calc(4 * var(--width-indent)); }
.depth-5 { margin-left: calc(5 * var(--width-indent)); }
.depth-6 { margin-left: calc(6 * var(--width-indent)); }
.depth-7 { margin-left: calc(7 * var(--width-indent)); }
.depth-8 { margin-left: calc(8 * var(--width-indent)); }

details { margin-block: var(--space-2); }
summary { cursor: pointer; color: var(--color-accent); font-size: var(--text-sm); }

/* Forms */

[hidden] { display: none !important; }

/* Every form is one column: each field, text area, message and button on its own line, one spacing step apart, the
   fields as wide as the content and the buttons as wide as their text. The forms of one row are the exceptions below:
   the header search and the forms of a single button (vote, sign out, remove). */
form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-4);
  margin: 0 0 var(--space-5);
}
form > *, form > .problem { margin-block: 0; }
form > button { align-self: flex-start; }
form > textarea, form > input, form > select { width: 100%; }
form label { display: block; }
form label > input, form label > select, form label > textarea { display: block; width: 100%; margin-top: var(--space-1); }

/* A search box and its button: one row, one height. */
form[role="search"] { display: flex; flex-direction: row; align-items: stretch; gap: var(--space-1); }
form[role="search"] input { flex: 1; min-width: 0; }
form .actions { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-start; }
.hint { color: var(--color-muted); font-size: var(--text-sm); }
.source .url code { overflow-wrap: anywhere; }
.post form, .comment form[action$="/vote"], form[action$="/delete"], form[action$="/revoke"] {
  display: inline-flex;
  flex-direction: row;
}

/* Controls: one size for every input, select, button and button-like link, so the ones of a row line up. The
   variants change only colors. */
input:not([type="checkbox"]):not([type="radio"]), select, textarea, button, a.button, a[rel~="next"],
details.account > summary {
  height: var(--control-height);
  padding: 0 var(--control-padding-x);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--control-font-size);
  line-height: var(--control-line-height);
}
input, select, textarea { background: var(--color-bg); color: var(--color-text); }
textarea { height: auto; min-height: var(--control-height); padding-block: var(--control-padding-y); resize: vertical; }
input[type="search"] { appearance: none; -webkit-appearance: none; }
input[type="checkbox"], input[type="radio"] { width: auto; display: inline; }

button, a.button, a[rel~="next"], details.account > summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button, a.button { border-color: var(--color-accent); background: var(--color-accent); color: var(--color-accent-text); }
button:hover, a.button:hover { filter: brightness(1.08); }
header form[role="search"] button, button.use-reason, a[rel~="next"], details.account > summary {
  border-color: var(--color-border);
  background: transparent;
  color: var(--color-accent);
}
header form[role="search"] button { color: var(--color-muted); }
details.account > summary { color: var(--color-text); }
button.danger { border-color: var(--color-danger); background: transparent; color: var(--color-danger); }

input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

/* Moderation, Living Posts and history */

.moderation, .living, .contributions, .revision {
  margin-block: var(--space-5);
  padding: var(--space-4);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
}
.moderation h2, .contributions h2 { margin-top: 0; }
details.mod { margin-block: var(--space-2); }
details.mod > summary { color: var(--color-muted); }
.queue > li, .log > li { margin-bottom: var(--space-1); }
.log { font-size: var(--text-sm); color: var(--color-muted); }
.log .meta { display: block; }

pre.changes { white-space: pre-wrap; padding: 0; }
pre.changes > span { display: block; padding: 0 var(--space-4); }
pre.changes > .added { background: var(--color-added); }
pre.changes > .removed { background: var(--color-removed); }

.copy { display: flex; gap: var(--space-2); align-items: flex-start; margin-bottom: var(--space-4); }
.copy > span { color: var(--color-muted); font-size: var(--text-sm); align-self: center; }
.copy pre { flex: 1; min-width: 0; margin: 0; }
.copy code { overflow-wrap: anywhere; }
#mcp-url { user-select: all; }

.codes { font-family: var(--font-mono); columns: 2; }

table { border-collapse: collapse; margin-bottom: var(--space-4); }
th, td { padding: var(--space-1) var(--space-2); border-bottom: var(--border-width) solid var(--color-border); text-align: left; }

/* Phone width */

@media (max-width: 40rem) {
  :root { --width-indent: 0.6rem; }
  body > header, body > main, body > footer { padding-inline: var(--space-4); }
  /* Row one: the brand and the account; row two: the feeds, a Search link and Submit. */
  header form[role="search"] { display: none; }
  header .brand { order: 1; }
  header details.account, header .sign-in { order: 2; margin-left: auto; }
  header .break { display: block; order: 3; flex-basis: 100%; height: 0; }
  header nav.feeds { order: 4; }
  header .search-link { display: inline; order: 5; margin-left: auto; }
  header .submit { order: 6; }
  .codes { columns: 1; }
}
ol.activity { list-style: none; padding: 0; }
ol.activity > li { display: flex; gap: var(--space-2); margin-bottom: var(--space-2); }
.activity .mark { flex: none; width: 1em; }
.activity .approved .mark { color: var(--color-ok); }
.activity .rejected .mark { color: var(--color-danger); }
.activity .reason { margin: var(--space-1) 0 0; }
.advice { margin-bottom: var(--space-4); padding: var(--space-2) var(--space-4); border-left: var(--rule) solid var(--color-border); background: var(--color-surface); }
.advice p { margin: 0 0 var(--space-1); }
.advice .advice-reason { white-space: pre-wrap; }
.verdict { display: inline-block; padding: 0 var(--space-2); border: var(--border-width) solid var(--color-border); border-radius: var(--radius-sm); font-size: var(--text-sm); font-weight: var(--weight-strong); }
.verdict.approve { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-accent-text); }
.verdict.reject, .verdict.failed { color: var(--color-danger); border-color: var(--color-danger); }
.verdict.needs_review { background: var(--color-notice); border-color: var(--color-notice-border); color: var(--color-text); }
.verdict.pending { color: var(--color-muted); }
.verdict.decided { color: var(--color-muted); font-weight: normal; }
.advice.past .advice-reason { color: var(--color-muted); }
.advice .decided { font-size: var(--text-sm); }

/* Wide screens: a feed page is wider, with the reading panel beside the list (public/panel.js swaps what it shows).
   Below the breakpoint the panel is hidden and the page is as on any screen. Every rule needs :has, so a browser
   without it keeps the page as it was. */

.panel { display: none; }

@media (min-width: 75rem) {
  body:has(.feed-page) > header,
  body:has(.feed-page) > main,
  body:has(.feed-page) > footer { max-width: var(--width-wide); }

  body:has(.feed-page) .feed-page {
    display: grid;
    grid-template-columns: minmax(0, 1fr) min(var(--width-panel), 37%);
    gap: var(--space-6);
    align-items: start;
  }
  body:has(.feed-page) .feed-page.alone { display: block; }
  body:has(.feed-page) .feed-column p,
  body:has(.feed-page) .feed-column li { max-width: none; }

  body:has(.feed-page) .panel {
    display: block;
    position: sticky;
    top: var(--space-4);
    max-height: calc(100vh - 2 * var(--space-4));
    overflow-y: auto;
    padding: var(--space-4);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
  }
  .panel h2:first-child { margin-top: 0; }
  .panel .living, .panel .comments { margin-top: var(--space-4); }
  #panel-title:focus-visible { outline: var(--focus-ring); outline-offset: var(--focus-offset); }

  /* No panel: the source, the time and the comments sit at the right of each row; the numbers stay. */
  body:has(.feed-page) .feed-page.alone .feed { padding-left: 0; list-style: none; counter-reset: row; }
  body:has(.feed-page) .feed-page.alone .item {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-1) var(--space-2);
  }
  body:has(.feed-page) .feed-page.alone .item::before {
    counter-increment: row;
    content: counter(row) ".";
    min-width: var(--space-5);
    color: var(--color-muted);
    font-size: var(--text-sm);
  }
  body:has(.feed-page) .feed-page.alone .item .meta { margin: 0 0 0 auto; text-align: right; }
}
