/*
 * Styling for dado.work.
 *
 * The whole approach is whitespace and alignment: one measure, one
 * rhythm scale, a clear size hierarchy, and almost no colour.  Nothing
 * is separated by a rule or a box that could be separated by space.
 *
 * Four sections: layout, rhythm, controls, typography.  Every spacing
 * value comes from the scale in :root -- if a number appears inline
 * below, it is because it is a fraction of a glyph rather than a step
 * in the rhythm.
 *
 * Hooks the markup provides:
 *
 *   body > header        the masthead
 *   .search-field        wraps the search input and its results list
 *   #search-results      the suggestion listbox
 *   .page-heading        a page heading with a control beside it
 *   #version-picker      the editor's "load version" control
 *   #editor-toolbar      the editor's icon buttons
 *   #editor              the contenteditable region
 *   #editor-save         Save, disabled until the post is edited
 *   #editor-dirty        the "(edited)" flag
 *   .button              anything that should read as a button
 *   .icon                a button whose label is a single glyph
 *   article footer       the per-post admin actions
 */

:root {
  /* The measure the masthead and the posts line up to. */
  --measure: 42rem;

  /* The rhythm.  Every margin, padding and gap is one of these. */
  --tight: 0.25rem;
  --near: 0.5rem;
  --step: 1rem;
  --wide: 2rem;

  /* Colour, taken from the hand-built dado.work so the two match.
     Text is off-black rather than black; secondary text is grey; a
     hairline separates, a pale surface groups. */
  --text: #1a1a1a;
  --muted: #666;
  --bg: #ffffff;
  --surface: #f5f5f5;
  --border: #e0e0e0;

  /* Controls need a firmer edge than a hairline to read as pressable. */
  --surface-hover: #ececec;
  --surface-active: #e2e2e2;
  --control-border: #cccccc;
  --control-border-hover: #999999;
}

/* -- layout --------------------------------------------------------
 * Rules the markup needs in order to be arranged at all.
 */

/* One centred column. */
body > header,
main {
  max-width: var(--measure);
  margin-left: auto;
  margin-right: auto;
}

/* Masthead:
 *
 *   dado.work                             search [        ] ✚ ⎋
 *
 * Title hard left; margin-left:auto on the search form pushes it and
 * the actions after it to the right.
 */
body > header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--near);
}

body > header form[role="search"] {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--near);
}

body > header nav {
  display: flex;
}

/* Horizontal lists of actions. */
body > header nav ul,
article footer ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--near);
  padding: 0;
  margin: 0;
}

/* A one-button form belongs on the same line as its neighbours. */
article footer form {
  display: inline;
}

/* Heading with a control beside it: heading left, control right. */
.page-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--near);
}

#version-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--near);
  margin: 0;
}

/* The search input and its results share a positioning context so the
 * list can hang directly beneath the input rather than shoving the
 * page down. */
.search-field {
  position: relative;
}

#search-results {
  position: absolute;
  top: calc(100% + var(--tight));
  left: 0;
  right: 0;
  z-index: 10;
  list-style: none;
  margin: 0;
  padding: var(--tight) 0;
  overflow-y: auto;
  max-height: 60vh;
  background: #fff;
  border: 1px solid var(--control-border);
  border-radius: 4px;
}

/* A flex or grid container overrides the hidden attribute, so say it
 * again -- without this the empty listbox is always visible. */
#search-results[hidden] {
  display: none;
}

#search-results li {
  padding: var(--tight) var(--near);
  cursor: pointer;
}

/* The keyboard-highlighted suggestion. */
#search-results li[aria-selected="true"] {
  background: var(--surface);
}

.search-field input {
  width: 100%;
  box-sizing: border-box;
}

/* Keep a pasted screenshot inside the column. */
article img {
  max-width: 100%;
  height: auto;
}

/* -- rhythm --------------------------------------------------------
 * Space and a clear size hierarchy do the work.  The sizes, weights
 * and colours below are dado.work's, so the two sites read alike.
 */

html {
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
}

body {
  margin: 0;
  padding: var(--wide) var(--step);
}

body > header {
  margin-bottom: var(--near);
}

/* Post, space, rule, space, post. */
article {
  margin: 0 0 var(--wide);
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  max-width: var(--measure);
  margin: 0 auto var(--wide);
}

article header {
  margin-bottom: var(--step);
}

/* Title and date belong together, so they sit close. */
article header h2 {
  margin: 0 0 var(--tight);
}

article header p {
  margin: 0;
}

article footer {
  margin-top: var(--step);
}

/* The site footer.  No rule above it: on the front page the last
   post's rule already closes the column, and elsewhere space is
   enough. */
body > footer {
  max-width: var(--measure);
  margin: var(--wide) auto 0;
  font-size: 0.9rem;
  color: var(--muted);
}

body > footer p {
  margin: 0;
}

/* Block elements share one rhythm step. */
p,
ul,
ol,
pre,
blockquote,
figure,
table {
  margin-top: var(--step);
  margin-bottom: var(--step);
}

/* Headings take space above and give little below, which is what ties
 * a heading to the text it introduces. */
h1,
h2,
h3,
h4,
h5,
h6 {
  line-height: 1.25;
  font-weight: 600;
  margin: var(--wide) 0 var(--near);
}

/* Nothing should push the top of its container down. */
main > :first-child,
article > :first-child,
#editor > :first-child {
  margin-top: 0;
}

/* Size hierarchy: the site title, then post and page headings, then
 * headings within a post. */
body > header h1 {
  font-size: 2rem;
  margin: 0;
}

main h2 {
  font-size: 1.4rem;
}

main h3 {
  font-size: 1.15rem;
}

main h4 {
  font-size: 1rem;
}

/* Secondary text: present, but out of the way. */
time,
#editor-dirty,
#version-picker label {
  font-size: 0.9rem;
  color: var(--muted);
}

pre {
  padding: var(--step);
  background: var(--surface);
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Inline code, set apart just enough to read as code. */
:not(pre) > code {
  padding: 0.1em 0.3em;
  background: var(--surface);
  border-radius: 3px;
  font-size: 0.9em;
}

blockquote {
  margin-left: 0;
  margin-right: 0;
  padding-left: var(--step);
  border-left: 2px solid var(--border);
  color: var(--muted);
}

.page-heading {
  margin-bottom: var(--step);
}

#editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tight);
  margin: var(--step) 0 var(--near);
}

/* The editor needs a visible, clickable area before anything is typed
 * into it; an empty div has neither height nor edges. */
#editor {
  min-height: 20rem;
  padding: var(--step);
  border: 1px solid var(--control-border);
  border-radius: 4px;
}

#editor-form label {
  display: block;
  margin-bottom: var(--tight);
}

#editor-dirty {
  margin-left: var(--near);
}

/* -- controls ------------------------------------------------------
 *
 * One appearance for every action, whether it is a <button> that
 * submits or an <a class="button"> that navigates.  The element is
 * chosen by what it does; only the look is shared.
 */

button,
.button {
  font: inherit;
  line-height: 1.2;
  display: inline-block;
  vertical-align: middle;
  padding: 0.35em 0.7em;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--surface);
  /* Links carry their own colour and underline; a button wears
     neither. */
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.button:hover {
  background: var(--surface-hover);
  border-color: var(--control-border-hover);
}

button:active,
.button:active {
  background: var(--surface-active);
}

/* Save is disabled until the post is edited, so it has to read as
   unavailable rather than merely unresponsive. */
button:disabled {
  opacity: 0.45;
  cursor: default;
}

button:disabled:hover {
  background: var(--surface);
  border-color: var(--control-border);
}

/* Square, so a one-glyph label and a three-character one line up. */
.icon,
#editor-toolbar button {
  min-width: 2.4em;
  padding-left: var(--tight);
  padding-right: var(--tight);
  text-align: center;
}

/* Text inputs and selects match the buttons they sit beside. */
input[type="text"],
input[type="search"],
input[type="password"],
select {
  font: inherit;
  padding: 0.35em 0.5em;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: #fff;
}

/* The site title is a link home, but it should read as the heading it
   is: black, and never underlined. */
body > header h1 a {
  color: inherit;
  text-decoration: none;
}

/* -- typography ----------------------------------------------------
 *
 * Two faces:
 *
 *   Inter       everything -- prose, headings, chrome
 *   Comic Code  code
 *
 * Inter stands in for Apple's SF Pro, which the hand-built dado.work
 * picked up through system-ui but which cannot be served on the web:
 * Apple licenses it for Apple-platform development only.  Inter was
 * drawn in the same idiom and is the usual substitute.
 *
 * Inter is self-hosted here: variable, so one file covers every
 * weight, and each subset carries a unicode-range, so latin-ext is
 * fetched only by a page needing an accented character and the italic
 * only by a page that has italics.
 *
 * Comic Code is a licensed retail font, so it is referenced with
 * local() rather than served: nothing is redistributed, and a reader
 * who owns it sees it while everyone else gets their system mono.
 * Serving it would need a webfont licence from tosche.net.
 *
 * Deliberately no colour, size or spacing here -- browser defaults
 * still own all of that.
 */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/static/fonts/inter-latin.woff2") format("woff2");
  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;
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/static/fonts/inter-latin-ext.woff2") format("woff2");
  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: "Inter";
  font-style: italic;
  font-weight: 400 700;
  font-display: swap;
  src: url("/static/fonts/inter-italic-latin.woff2") format("woff2");
  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;
}

@font-face {
  font-family: "Inter";
  font-style: italic;
  font-weight: 400 700;
  font-display: swap;
  src: url("/static/fonts/inter-italic-latin-ext.woff2") format("woff2");
  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;
}

/* Comic Code if the reader has it installed, system mono otherwise.
 *
 * One face per cut rather than one spanning 400-700: with a single
 * source the browser would fake bold by smearing the regular, instead
 * of using the bold Toshi actually drew.
 *
 * Chrome matches local() on full name and PostScript name, not family
 * name, so both are given. */

@font-face {
  font-family: "Comic Code Local";
  font-style: normal;
  font-weight: 400;
  src: local("Comic Code Regular"), local("ComicCode-Regular");
}

@font-face {
  font-family: "Comic Code Local";
  font-style: normal;
  font-weight: 700;
  src: local("Comic Code Bold"), local("ComicCode-Bold");
}

@font-face {
  font-family: "Comic Code Local";
  font-style: italic;
  font-weight: 400;
  src: local("Comic Code Italic"), local("ComicCode-Italic");
}

@font-face {
  font-family: "Comic Code Local";
  font-style: italic;
  font-weight: 700;
  src: local("Comic Code Bold Italic"), local("ComicCode-BoldItalic");
}

/* Everything inherits Inter, including form controls once named. */
body,
input,
button,
select,
textarea {
  font-family: "Inter", -apple-system, system-ui, sans-serif;
}

pre,
code,
kbd,
samp {
  font-family: "Comic Code Local", ui-monospace, SFMono-Regular, Menlo,
               monospace;
}
