/* Squared notebook: date in the margin, note to the right of the red line. Sizes: 16 note / 13 meta, 24px rhythm. */
:root {
  color-scheme: light;
  --paper: #fbfcfd;
  --grid: #e3ebf5;
  --margin-line: #d6453d;
  --red-text: #b2342d;
  --ink: #1f2a44;
  --muted: #5d6782;
  --pen: #1f4fbf;
  --pen-dark: #183d94;
  --rule: #c9d5e6;
  --wash: #dce7fb;
  --margin-w: 168px;
  --sheet-w: 960px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Corner brackets: the one focus mark for every control */
  --b: linear-gradient(var(--pen), var(--pen));
  --brackets: var(--b), var(--b), var(--b), var(--b), var(--b), var(--b), var(--b), var(--b);
}

* { box-sizing: border-box; }

html {
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  /* Grid lines land on the sheet's centre, so its edges (20 squares out) and the red line (7 squares in) sit on them at any width */
  background-position: calc(50% + 12px) 0;
  scrollbar-color: var(--rule) var(--paper);
}

body {
  margin: 0;
  font: 16px/24px var(--font);
  color: var(--ink);
  caret-color: var(--pen);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--wash); color: var(--ink); }

main {
  position: relative;
  max-width: var(--sheet-w);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 0 96px;
  /* The sheet: 1px edges on grid lines and a light veil that keeps the squares readable */
  border-inline: 1px solid var(--rule);
  background: rgb(251 252 253 / 0.45);
}

/* The red margin line: the whole sheet hangs off it */
main::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 var(--margin-w);
  width: 1px;
  background: var(--margin-line);
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* Header */
.masthead {
  display: grid;
  grid-template-columns: var(--margin-w) 1fr;
  align-items: center;
  height: 96px;
}
.masthead h1 {
  margin: 0;
  padding-right: 24px;
  text-align: right;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.search { justify-self: end; padding-right: 24px; }

/* Shared controls: 1px rules, zero radius */
input, textarea, button { font: inherit; color: inherit; border-radius: 0; }

input[type="search"], textarea {
  display: block;
  width: 100%;
  border: 1px solid var(--ink);
  background: #fff;
  padding: 11px 14px;
}
input[type="search"] { width: 288px; height: 48px; }
textarea { resize: vertical; min-height: 96px; }
::placeholder { color: var(--muted); opacity: 1; }

input[type="search"]::-webkit-search-cancel-button { appearance: none; }

input:focus, textarea:focus, button:focus, a:focus { outline: none; }
input:focus, textarea:focus { border-color: var(--pen); }

/* Focus: corner brackets 4px outside the control, never a glow */
.field { display: block; }
.search .field, .compose-bar .field, .actions .field { display: inline-block; }
.field:has(:focus-visible),
a:focus-visible, .link:focus-visible {
  background-image: var(--brackets);
  background-repeat: no-repeat;
  background-size: 6px 1px, 1px 6px, 6px 1px, 1px 6px, 6px 1px, 1px 6px, 6px 1px, 1px 6px;
  background-position: 0 0, 0 0, 100% 0, 100% 0, 0 100%, 0 100%, 100% 100%, 100% 100%;
}
.field { padding: 4px; margin: -4px; }
a:focus-visible, .link:focus-visible { padding: 2px 4px; margin: -2px -4px; }

button { cursor: pointer; }
.primary {
  border: 1px solid var(--pen);
  background: var(--pen);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  height: 36px;
  padding: 0 20px;
}
.primary:hover { background: var(--pen-dark); border-color: var(--pen-dark); }

a, .link {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 4px;
}
a:hover, .link:hover { text-decoration-color: currentColor; }
.link { border: 0; background: none; padding: 0; font-size: inherit; }
.danger { color: var(--red-text); }

.primary:focus-visible { background: var(--pen-dark); }

/* Writing */
.compose { margin: 0 24px 0 calc(var(--margin-w) + 24px); }
.compose-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}
.hint { font-size: 13px; color: var(--muted); }
kbd {
  font: 13px/18px var(--font);
  border: 1px solid var(--rule);
  background: #fff;
  padding: 0 6px;
}

/* Search result line */
.result {
  display: flex;
  gap: 24px;
  margin: 48px 24px 0 calc(var(--margin-w) + 24px);
  font-size: 13px;
  color: var(--muted);
}

/* List */
.notes { list-style: none; margin: 48px 0 0; padding: 0; }

.note, .empty {
  display: grid;
  grid-template-columns: var(--margin-w) 1fr;
  padding: 12px 0;
  scroll-margin-top: 96px;
}

.margin {
  padding-right: 24px;
  text-align: right;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.margin time { display: block; }
/* Red belongs to the margin line and to deleting; "edited" is just a quiet note in the margin */
.edited { display: block; font-style: italic; }

/* Search hits: a highlighter stroke */
mark { background: var(--wash); color: inherit; box-shadow: 0 0 0 2px var(--wash); }

.confirming span { color: var(--red-text); }

.content, .edit, .empty p { padding: 0 24px; margin: 0; }
.body { margin: 0; max-width: 68ch; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty p { color: var(--muted); }

.actions {
  display: flex;
  gap: 24px;
  align-items: center;
  margin-top: 0;
  font-size: 13px;
}
.actions form { margin: 0; }
.content .actions { opacity: 0; }
.note:hover .actions, .note:focus-within .actions, .content .confirming { opacity: 1; }
.edit .actions { margin-top: 12px; }

/* Editing: one note owns the focus, the rest step back */
.editing .note:not(.is-editing) .body { color: var(--muted); }

/* Signature moment: a just-saved note gets an ink wash that dries */
.note.saved .content { animation: ink 1.6s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes ink {
  from { background: var(--wash); }
  to { background: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .note.saved .content { animation: none; }
}

/* Narrow windows: the margin folds above the note, the red line stays at the left */
@media (max-width: 720px) {
  :root { --margin-w: 24px; }
  .masthead { grid-template-columns: 1fr auto; padding-left: 48px; }
  .masthead h1 { text-align: left; }
  input[type="search"] { width: 180px; }
  .note, .empty { grid-template-columns: 1fr; padding-left: 24px; }
  .margin { text-align: left; padding: 0 24px; display: flex; gap: 12px; }
  .content .actions { opacity: 1; }
}
