/* langbook.
 *
 * A desk with a notebook on it: warm paper, dark ink, one blue for what can
 * be pressed. Calm on purpose -- the page is for writing, and nothing around
 * it should pull the eye away.
 *
 * Every size and colour is a custom property up here, so the rules below read
 * as layout rather than as numbers. (A media query cannot read one, so the
 * narrow-screen width is written out there, once.) The canvas draws its own paper and ruling
 * (crates/frontend/src/render.rs); --paper here is the same colour.
 */

:root {
  --ink: #26303b;
  --muted: #676d74;
  --ground: #f3eee3;
  --paper: #fffdf7;
  --raised: #fbf8f0;
  --line: #ddd3bf;
  --line-strong: #c4b89f;
  --accent: #1f4fa8;
  --accent-ink: #ffffff;
  --accent-wash: #e3eaf6;
  --danger: #b8322a;
  --danger-wash: #f8e6e3;
  --safe: #2e7d4f;
  --focus: #d48a0f;
  --shadow: 0 1px 2px #3a2f1a14, 0 8px 24px #3a2f1a12;
  --toolbar-ground: #f3eee3eb;
  /* The ruling render.rs draws on the page, for artwork that echoes it. */
  --rule: #c8d6e5;
  --margin-rule: #efc2bb;

  --page: 1100px;
  --sheet: 1000px;
  --gap: 16px;
  --gap-small: 8px;
  --gap-large: 28px;
  --radius: 12px;
  --radius-small: 8px;
  --border: 1px;
  --thick: 3px;
  --hairline: 2px;
  --target: 44px;
  --swatch-size: 30px;
  --icon: 22px;
  --dot-fine: 5px;
  --dot-medium: 9px;
  --dot-bold: 14px;
  --small: 14px;
  --text: 17px/1.5;
  --title: clamp(28px, 5vw, 40px);
  --heading-leading: 1.2;
  --panel-heading: 1.25em;
  --brand-size: 1.4em;
  --card-title: 1.2em;
  --tool-glyph: 1.3em;
  --icon-stroke: 1.8;
  --page-number: 4ch;
  --tracking: 0.1em;
  --prose: 60ch;
  --card: 220px;
  /* A page card is a little over half as tall as it is wide. */
  --page-card-height: calc(var(--card) * 0.6);
  /* A page card's ruling: the space between lines, and the head above them. */
  --card-rule: 24px;
  --card-head: 84px;
  --dim: 0.45;
  /* A page is protocol::page::WIDTH by HEIGHT units: A4's shape. */
  --sheet-shape: 1000 / 1414;
  /* How far past its ink a swatch's edge softens. */
  --swatch-soft: 1px;
  --blur: 8px;
  --layer-bar: 2;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

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

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: var(--text) var(--sans);
}

main {
  max-width: var(--page);
  margin: 0 auto;
  padding: var(--gap);
  padding-left: max(var(--gap), env(safe-area-inset-left));
  padding-right: max(var(--gap), env(safe-area-inset-right));
  padding-bottom: max(var(--gap), env(safe-area-inset-bottom));
}

h1,
h2 {
  margin: 0 0 var(--gap-small);
  font-family: var(--serif);
  font-weight: 600;
  line-height: var(--heading-leading);
}

h1 {
  font-size: var(--title);
}

a {
  color: var(--accent);
}

.status,
.hint {
  color: var(--muted);
}

.hint {
  font-size: var(--small);
}

.lede {
  max-width: var(--prose);
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 var(--gap-small);
  color: var(--muted);
  font-size: var(--small);
  font-weight: 700;
  letter-spacing: var(--tracking);
  text-transform: uppercase;
}

.eyebrow a {
  color: inherit;
}

.refusal {
  margin: var(--gap-small) 0;
  padding: var(--gap-small) var(--gap);
  border: var(--border) solid var(--danger);
  border-radius: var(--radius-small);
  background: var(--danger-wash);
  color: var(--danger);
}

.language {
  display: block;
  margin: 0;
  color: var(--accent);
  font-family: var(--serif);
  font-style: italic;
}

/* ---- controls ----------------------------------------------------------- */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--target);
  padding: var(--gap-small) var(--gap);
  border: var(--border) solid var(--line-strong);
  border-radius: var(--radius-small);
  background: var(--raised);
  color: var(--ink);
  font: inherit;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: var(--thick) solid var(--focus);
  outline-offset: var(--hairline);
}

button:disabled {
  cursor: default;
  opacity: var(--dim);
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

button.quiet {
  border-color: transparent;
  background: transparent;
}

button.quiet:hover:not(:disabled) {
  border-color: var(--line-strong);
}

button.danger {
  color: var(--danger);
}

button.primary.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: var(--accent-ink);
}

input {
  width: 100%;
  min-height: var(--target);
  padding: var(--gap-small) var(--gap-small);
  border: var(--border) solid var(--line-strong);
  border-radius: var(--radius-small);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}

label {
  color: var(--muted);
  font-size: var(--small);
}

.panel {
  padding: var(--gap);
  border: var(--border) solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.panel h2 {
  font-size: var(--panel-heading);
}

/* Two columns, the first twice the second; one on a narrow screen. */
.columns {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: var(--gap-large);
  align-items: start;
  margin: var(--gap) 0;
}

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

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-small) var(--gap);
  margin: var(--gap) 0 0;
}

.actions.tight {
  flex-wrap: nowrap;
  margin: 0;
}

.actions.tight input {
  flex: 1;
  min-width: 0;
}

.fields {
  display: grid;
  gap: var(--gap-small);
  align-content: start;
}

.fields .actions {
  margin: var(--gap-small) 0 0;
}

/* ---- masthead ----------------------------------------------------------- */

.masthead,
.masthead nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-small) var(--gap);
}

.masthead {
  justify-content: space-between;
  margin-bottom: var(--gap);
  padding-bottom: var(--gap-small);
  border-bottom: var(--border) solid var(--line);
}

.masthead form {
  margin: 0;
}

.masthead .who {
  color: var(--muted);
  font-size: var(--small);
}

.brand {
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--brand-size);
  font-style: italic;
  font-weight: 700;
  text-decoration: none;
}

/* ---- the notebooks and their pages -------------------------------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card), 1fr));
  gap: var(--gap);
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  display: grid;
  gap: var(--gap-small);
  height: 100%;
  padding: var(--gap);
  border: var(--border) solid var(--line);
  border-left: var(--thick) solid var(--accent);
  border-radius: var(--radius-small);
  background: var(--paper);
  box-shadow: var(--shadow);
  color: var(--ink);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.card:hover {
  border-color: var(--accent);
}

.card-title {
  font-family: var(--serif);
  font-size: var(--card-title);
  font-weight: 600;
}

/* A page card is a sheet: ruled faintly, the way the page itself is. */
.page-card {
  min-height: var(--page-card-height);
  border-left-color: var(--line-strong);
  background:
    repeating-linear-gradient(
        to bottom,
        transparent 0 calc(var(--card-rule) - var(--border)),
        var(--accent-wash) calc(var(--card-rule) - var(--border))
          var(--card-rule)
      )
      0 var(--card-head) / 100% calc(100% - var(--card-head)) no-repeat,
    var(--paper);
  align-content: start;
}

.contents h1 {
  overflow-wrap: anywhere;
}

.danger-zone p {
  margin-top: 0;
}

.nothing {
  max-width: var(--prose);
}

.profile {
  max-width: var(--prose);
  overflow-wrap: anywhere;
}

/* ---- the writing page --------------------------------------------------- */

.writing {
  margin: 0 auto;
}

/* The tools stay in reach however far down the page the writing is. */
.toolbar {
  position: sticky;
  top: 0;
  z-index: var(--layer-bar);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-small) var(--gap);
  margin: 0 calc(-1 * var(--gap-small)) var(--gap-small);
  padding: var(--gap-small);
  padding-top: max(var(--gap-small), env(safe-area-inset-top));
  border-bottom: var(--border) solid var(--line);
  background: var(--toolbar-ground);
  -webkit-backdrop-filter: blur(var(--blur));
  backdrop-filter: blur(var(--blur));
}

.toolbar .group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--hairline);
}

.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--target);
  min-height: var(--target);
  padding: 0 var(--gap-small);
  border: var(--border) solid transparent;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--ink);
  font-size: var(--tool-glyph);
  line-height: 1;
  text-decoration: none;
}

a.tool:hover,
button.tool:hover:not(:disabled) {
  border-color: var(--line-strong);
}

.tool[aria-disabled="true"] {
  opacity: var(--dim);
}

.tool[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-wash);
  color: var(--accent);
}

.tool .icon {
  width: var(--icon);
  height: var(--icon);
  fill: none;
  stroke: currentColor;
  stroke-width: var(--icon-stroke);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.where {
  min-width: var(--page-number);
  color: var(--muted);
  font-size: var(--small);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* A swatch is the ink itself, set on the element as --swatch; pressed, it
   wears a ring of it. */
.swatch {
  width: var(--target);
  min-width: 0;
  height: var(--target);
  padding: 0;
  border: var(--border) solid transparent;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    var(--swatch) 0 calc(var(--swatch-size) / 2),
    transparent calc(var(--swatch-size) / 2 + var(--swatch-soft))
  );
}

.swatch[aria-pressed="true"] {
  border: var(--thick) solid var(--swatch);
}

.size .dot {
  display: block;
  border-radius: 50%;
  background: currentColor;
}

.size.fine .dot {
  width: var(--dot-fine);
  height: var(--dot-fine);
}

.size.medium .dot {
  width: var(--dot-medium);
  height: var(--dot-medium);
}

.size.bold .dot {
  width: var(--dot-bold);
  height: var(--dot-bold);
}

.save {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-small);
  margin-left: auto;
  color: var(--muted);
  font-size: var(--small);
}

.save[data-state="saved"] {
  color: var(--safe);
}

.save[data-state="saved"]::before {
  content: "\2713";
}

.save .failed {
  border-color: var(--danger);
  background: var(--danger-wash);
  color: var(--danger);
  font-weight: 600;
}

.save .why {
  color: var(--danger);
}

.sheet {
  position: relative;
  max-width: var(--sheet);
  margin: 0 auto;
  border-radius: var(--hairline);
  box-shadow: var(--shadow);
  /* Nothing on the sheet is text to select, and a long press with the
     Pencil must not bring up the magnifier or a callout. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.sheet canvas {
  display: block;
  width: 100%;
  aspect-ratio: var(--sheet-shape);
}

/* A finger scrolls and zooms; it never draws, so the browser may have it.
   The pen and the mouse are prevented in the event handlers instead, and so
   is every touch while a stroke is being written (writing.rs). */
.sheet .paper {
  touch-action: pan-y pinch-zoom;
  cursor: crosshair;
}

.sheet.erasing .paper {
  cursor: cell;
}

.sheet .live {
  position: absolute;
  inset: 0;
  height: 100%;
  pointer-events: none;
}

/* ---- narrow screens ----------------------------------------------------- */

@media (max-width: 800px) {
  .columns {
    grid-template-columns: 1fr;
  }

  main {
    padding-left: max(var(--gap-small), env(safe-area-inset-left));
    padding-right: max(var(--gap-small), env(safe-area-inset-right));
  }

  .toolbar {
    gap: var(--gap-small);
  }

  .save {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
