/* code.munir.sh. The same plain monospace page as munir.sh, plus a command
   to copy. Follows the system light/dark setting. */

@font-face {
  font-family: "JetBrains Mono";
  font-weight: 100 800;
  font-display: swap;
  src: url("/fonts/jetbrains-mono-var.woff2") format("woff2");
}

:root {
  --sh-bg: #060607;
  --sh-fg: #f3ede6;
  --sh-link: #35c2c2;
  --sh-line: #211d23;
  --sh-dim: #8d8790;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --sh-bg: #f5f5f4;
    --sh-fg: #2f2f2f;
    --sh-link: #137a7b;
    --sh-line: #e2e2e0;
    --sh-dim: #77777a;
    color-scheme: light;
  }
}

* {
  box-sizing: border-box;
}
body,
h2,
p,
pre,
ul,
table {
  margin: 0;
  padding: 0;
}
ul {
  list-style: none;
}
body {
  background: var(--sh-bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.sh {
  display: grid;
  grid-template-areas:
    "main"
    "side"
    "foot";
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  min-height: 100svh;
  background: var(--sh-bg);
  color: var(--sh-fg);
  font-family: "JetBrains Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
  font-variant-ligatures: none;
  font-size: 1rem;
  line-height: 1.65;
}

a {
  color: var(--sh-link);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
:focus-visible {
  outline: 1px solid var(--sh-link);
  outline-offset: 3px;
}
code,
pre {
  font-family: inherit;
}

/* ---- main column -------------------------------------------------- */

.sh-main {
  grid-area: main;
  padding: 1.5rem 0.75rem 1rem;
  min-width: 0;
}
.sh-main > p,
.sh-main > table,
.sh-main > ul {
  max-width: 80ch;
  margin-bottom: 2em;
}
/* The banner is 53 characters wide. On a narrow screen the letters shrink
   until it fits, down to a size that can still be read. */
.sh-banner {
  margin-bottom: 2.2em;
  font-size: clamp(0.5rem, calc((100vw - 1.5rem) / 32), 1rem);
  line-height: 1.2;
  overflow-x: auto;
}
.sh-banner a {
  color: inherit;
  text-decoration: none;
}
.sh-banner small {
  display: block;
  margin-left: 6em;
  font-size: 0.8rem;
  font-style: italic;
}
.sh-main h2 {
  margin-bottom: 0.6rem;
  font-size: 1.3rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.sh-main h2::before {
  content: "$ ";
  color: var(--sh-dim);
}
table {
  border-collapse: collapse;
}
td {
  padding: 0;
  text-align: left;
  vertical-align: top;
}
.sh-list td:first-child {
  width: 20ch;
  padding-right: 1ch;
  white-space: nowrap;
}
.sh-list td:nth-child(2) {
  padding-right: 1ch;
  color: var(--sh-dim);
}
.sh-list em {
  color: var(--sh-dim);
}
.sh-main > .sh-above {
  margin-bottom: 0.8em;
}

/* ---- a command, and the row under it ------------------------------ */

.sh-usage {
  max-width: 100ch;
  margin-bottom: 0.6em;
  padding: 0.6em 2ch;
  border-left: 4px solid var(--sh-line);
  /* A long command wraps at its spaces. Copying it still gives one line. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.sh-usage code {
  user-select: all;
  -webkit-user-select: all;
}
.sh-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2em 2ch;
}
.sh-main > .sh-actions {
  margin-bottom: 0.8em;
}
.sh-actions button {
  min-width: 10ch; /* "copied" is longer than "copy"; the row must not move. */
  padding: 0.2em 1.5ch;
  border: 1px solid var(--sh-fg);
  border-radius: 0.6em;
  background: var(--sh-line);
  color: var(--sh-fg);
  font: inherit;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 160ms cubic-bezier(0.23, 1, 0.32, 1);
}
/* Pressed: it gives a little, at once. */
.sh-actions button:active {
  transform: scale(0.97);
  background: var(--sh-fg);
  color: var(--sh-bg);
}
.sh-notes li {
  padding-left: 2ch;
  text-indent: -2ch;
}
.sh-notes li::before {
  content: "- ";
  color: var(--sh-dim);
}
.sh-key {
  overflow-wrap: anywhere;
}

/* Only where there is a pointer that hovers: on a touch screen a hover
   style stays stuck on after the tap. */
@media (hover: hover) and (pointer: fine) {
  a:hover {
    text-decoration: underline dotted;
  }
  .sh-actions button:hover {
    background: var(--sh-fg);
    color: var(--sh-bg);
  }
}
/* A finger needs more to aim at than a mouse does. */
@media (pointer: coarse) {
  .sh-actions button {
    min-height: 44px;
  }
  .sh-actions a,
  .sh-side a {
    padding: 0.55em 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .sh-actions button {
    transition: none;
  }
  .sh-actions button:active {
    transform: none;
  }
}

/* ---- sidebar and footer ------------------------------------------- */

.sh-block {
  max-width: 80ch;
  margin-bottom: 1em;
  padding: 0.5em 0 0.5em 2ch;
  border-left: 4px solid var(--sh-line);
}
.sh-side {
  grid-area: side;
  padding: 0.5rem 0.75rem;
}
.sh-side ul {
  margin: 0.6em 0;
}
.sh-side a {
  display: inline-block;
}
.sh-foot {
  grid-area: foot;
  padding: 0.5em;
  border-top: 4px solid var(--sh-line);
  background: var(--sh-bg);
  text-align: center;
}
@media (min-height: 30em) {
  .sh-foot {
    position: sticky;
    bottom: 0;
  }
}

@media (min-width: 70ch) {
  .sh-main,
  .sh-side {
    padding-left: 4.5em;
  }
}
@media (min-width: 120ch) {
  .sh {
    grid-template-columns: 1fr 34ch;
    grid-template-rows: 1fr auto;
    grid-template-areas:
      "main side"
      "foot foot";
  }
  .sh-side {
    padding: 0.5rem 0.5rem 0 0;
  }
}
/* Phones: one entry per block, its description under its name. */
@media (max-width: 60ch) {
  .sh-list tr {
    display: block;
    margin-bottom: 0.7em;
  }
  .sh-list td,
  .sh-list td:first-child {
    display: block;
    width: auto;
    white-space: normal;
  }
  .sh-list td:nth-child(2) {
    display: none;
  }
}
