/* ===========================================================================
   ERCIHS Teaching Journal — Riso Notebook (neo-brutalist)
   Accents are fills only: text on an accent is always --on-accent (#1A1714)
   in both themes. Sections: tokens, base, controls, dialogs, toast, theme,
   then layout / prose / stars / editor / figure (appended by later tasks),
   then reduced motion LAST.
   =========================================================================== */

:root {
  color-scheme: light;
  --paper: #F7ECD9;
  --paper-2: #EDDCC4;
  --card: #FFF8EC;
  --ink: #1A1714;
  --ink-60: #6B6259;
  --on-accent: #1A1714;
  --pen: #2B4BA0;
  --shadow-ink: #1A1714;
  --rule: rgba(169, 200, 228, .55);
  --margin-rule: rgba(226, 122, 77, .55);

  --pink: #EFA8BC;
  --sage: #8CC7B4;
  --orange: #E27A4D;
  --mustard: #F0C044;
  --sky: #A9C8E4;

  /* editor palettes: stored in entries as var() so they follow the theme */
  --hl-mustard: #F0C044;
  --hl-pink: #EFA8BC;
  --hl-sage: #8CC7B4;
  --hl-sky: #A9C8E4;
  --hl-orange: #E27A4D;
  --tc-pen: #2B4BA0;
  --tc-rust: #B4481D;
  --tc-green: #2F7A62;
  --tc-berry: #B03A63;

  --radius-sm: 10px;
  --radius: 12px;
  --radius-lg: 20px;
  --bw: 3px;
  --border: var(--bw) solid var(--ink);
  --shadow-sm: 3px 3px 0 var(--shadow-ink);
  --shadow: 5px 5px 0 var(--shadow-ink);
  --shadow-lg: 7px 7px 0 var(--shadow-ink);
  --t-fast: 120ms cubic-bezier(.16, 1, .3, 1);
  --t: 220ms cubic-bezier(.16, 1, .3, 1);

  --font-display: 'Archivo Black', 'Arial Black', system-ui, sans-serif;
  --font-body: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-hand: 'Caveat', 'Segoe Print', cursive;
  /* the patch panel's jacks and LED strip stay dark in both themes, like real hardware */
  --jack: #1A1714;
  --jack-ink: #F7ECD9;
  --font-mono: ui-monospace, 'Cascadia Code', 'Cascadia Mono', Consolas, 'Courier New', monospace;
}

/* Night desk: navy paper, cream ink, mustard shadows. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1B1E2B;
  --paper-2: #151722;
  --card: #262A3B;
  --ink: #F3E9D6;
  --ink-60: #C9BFAE;
  --pen: #A9C8E4;
  --shadow-ink: #F0C044;
  --rule: rgba(169, 200, 228, .18);
  --margin-rule: rgba(226, 122, 77, .45);
  --tc-pen: #A9C8E4;
  --tc-rust: #F4A37E;
  --tc-green: #8CC7B4;
  --tc-berry: #EFA8BC;
}

/* ------------------------------------------------------------------ base */

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

/* Components set display, which would otherwise beat the UA [hidden] rule. */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; scrollbar-color: var(--ink) var(--paper-2); }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  caret-color: var(--pen);
}

/* Paper grain. Non-interactive. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0; /* on the paper, under the panels, so photos and text stay clean */
  pointer-events: none;
  opacity: .4;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E");
}
[data-theme="dark"] body::before { opacity: .18; }

::selection { background: var(--mustard); color: var(--on-accent); }

h1, h2, h3 { margin: 0; font-weight: 400; }
p { margin: 0; }
img, svg { max-width: 100%; }
a { color: inherit; text-underline-offset: .2em; }

svg.lucide { width: 18px; height: 18px; stroke-width: 2.4; flex: none; }

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  background: var(--mustard);
  color: var(--on-accent);
  border: var(--border);
  border-radius: 0 0 var(--radius) 0;
  padding: 10px 14px;
  font-weight: 700;
}
.skip:focus { left: 0; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 9px 16px;
  background: var(--card);
  color: var(--ink);
  border: var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: .8125rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: translate var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.btn:hover { translate: 2px 2px; box-shadow: 1px 1px 0 var(--shadow-ink); }
.btn:active { translate: 3px 3px; box-shadow: 0 0 0 var(--shadow-ink); }
.btn:disabled { opacity: .55; cursor: not-allowed; translate: none; box-shadow: var(--shadow-sm); }

.btn--sage, .btn--mustard, .btn--orange, .btn--sky, .btn--pink { color: var(--on-accent); }
.btn--sage    { background: var(--sage); }
.btn--mustard { background: var(--mustard); }
.btn--orange  { background: var(--orange); }
.btn--sky     { background: var(--sky); }
.btn--pink    { background: var(--pink); }
.btn--sm { min-height: 36px; padding: 6px 12px; font-size: .75rem; }

.iconbtn {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  background: var(--card);
  color: var(--ink);
  border: var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: translate var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.iconbtn:hover { translate: 2px 2px; box-shadow: 1px 1px 0 var(--shadow-ink); }
.iconbtn:active { translate: 3px 3px; box-shadow: none; }
.iconbtn:disabled { opacity: .45; cursor: not-allowed; translate: none; box-shadow: var(--shadow-sm); }
.iconbtn--lock { background: var(--orange); color: var(--on-accent); }
.iconbtn--lock[data-unlocked] { background: var(--sage); }

.linkbtn {
  padding: 0;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: .2em;
  cursor: pointer;
}

/* Theme button shows the theme you would switch TO. */
.theme-icon--sun { display: none; }
[data-theme="dark"] .theme-icon--sun { display: contents; }
[data-theme="dark"] .theme-icon--moon { display: none; }

/* ----------------------------------------------------------------- fields */

.field { display: block; }
.field__label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  font-size: .75rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.field__input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--card);
  color: var(--ink);
  border: var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 16px;
}
.field__input::placeholder { color: var(--ink-60); }
.field__input:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* ---------------------------------------------------------------- dialogs */

.dlg {
  width: min(430px, calc(100vw - 32px));
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.dlg::backdrop { background: rgba(26, 23, 20, .55); }
.dlg[open] { animation: dlg-in 180ms cubic-bezier(.16, 1, .3, 1); }
@keyframes dlg-in { from { transform: translateY(10px) scale(.97); opacity: 0; } }

.dlg__body { padding: 20px; display: grid; gap: 14px; }
.dlg__title { font-family: var(--font-display); font-size: 1.25rem; text-transform: uppercase; }
.dlg__hint { color: var(--ink-60); font-size: .875rem; }
.dlg__error {
  padding: 9px 12px;
  background: var(--orange);
  color: var(--on-accent);
  border: var(--border);
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: .875rem;
}
.dlg__actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

.shake { animation: shake 260ms; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 600;
  translate: -50% 0;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  background: var(--sage);
  color: var(--on-accent);
  border: 3px solid var(--on-accent);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-weight: 700;
  font-size: .875rem;
}
.toast--error { background: var(--orange); }

/* ------------------------------------------------------------------ theme */

::view-transition-old(root),
::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

.theme-fade, .theme-fade * {
  transition: background-color 250ms ease, color 250ms ease, border-color 250ms ease, box-shadow 250ms ease !important;
}

/* ------------------------------------------------------------------ shell */

.shell {
  position: relative; /* no z-index: the drawer (z 50) must stack above the scrim (z 40) */
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 190px;
  align-items: start;
  gap: 24px;
  min-height: 100dvh;
  padding: 24px;
}

.topbar { display: none; }
.bottombar { display: none; }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(26, 23, 20, .45);
}

/* ---------------------------------------------------------------- sidebar */

.sidebar {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-height: calc(100dvh - 48px);
}

.nameplate {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  padding: 15px 16px;
  background: var(--mustard);
  color: var(--on-accent);
  border: 3px solid var(--on-accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.nameplate__title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  line-height: .88;
  letter-spacing: -.02em;
  text-transform: uppercase;
}
.nameplate__tools { display: grid; gap: 8px; }
/* On the mustard plate the ink must not flip at night, or the shadow vanishes into the fill. */
.nameplate .iconbtn { border-color: var(--on-accent); box-shadow: 3px 3px 0 var(--on-accent); }
.nameplate .iconbtn:hover { box-shadow: 1px 1px 0 var(--on-accent); }
.nameplate .iconbtn:active { box-shadow: none; }
.nameplate__by { margin-top: 8px; font-family: var(--font-hand); font-weight: 700; font-size: 1.3rem; line-height: 1.1; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--card);
  border: var(--border);
  border-radius: var(--radius-sm);
}
.search:focus-within { outline: 3px solid var(--ink); outline-offset: 2px; }
.search svg { color: var(--ink-60); }
.search input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  background: none;
  border: 0;
  outline: 0;
  color: var(--ink);
  font: inherit;
}
.search input::placeholder { color: var(--ink-60); }

.sidebar__status { font-size: .875rem; color: var(--ink-60); }
.sidebar__status:empty { display: none; }

/* Entry dropdown: the trigger is the current entry card; the panel holds search and the list. */
.picker { position: relative; z-index: 5; }

.picker__trigger {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  column-gap: 12px;
  row-gap: 2px;
  align-items: center;
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  text-align: left;
  background: var(--accent, var(--card));
  color: var(--on-accent);
  border: 3px solid var(--on-accent);
  border-radius: var(--radius-sm);
  box-shadow: 5px 5px 0 var(--shadow-ink);
  font: inherit;
  cursor: pointer;
  transition: translate var(--t-fast), box-shadow var(--t-fast);
}
.picker__trigger:hover { translate: 2px 2px; box-shadow: 3px 3px 0 var(--shadow-ink); }
.picker__trigger:active { translate: 4px 4px; box-shadow: 1px 1px 0 var(--shadow-ink); }
.picker__trigger:disabled { cursor: default; translate: none; box-shadow: var(--shadow-sm); background: var(--card); color: var(--ink); border-color: var(--ink); }
.picker__trigger.is-loading { animation: pulse 1.1s ease-in-out infinite alternate; }
.picker__current { display: contents; }
.picker__no {
  grid-row: 1 / span 2;
  font-family: var(--font-display);
  font-size: 1.75rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.picker__date { grid-column: 2; font-weight: 700; font-size: .8125rem; font-variant-numeric: tabular-nums; }
.picker__excerpt { grid-column: 2; overflow: hidden; font-size: .8125rem; white-space: nowrap; text-overflow: ellipsis; }
.picker__chev {
  grid-column: 3;
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  background: var(--card);
  color: var(--ink);
  border: 2px solid var(--on-accent);
  border-radius: 50%;
  transition: rotate var(--t);
}
.picker__trigger[aria-expanded="true"] .picker__chev { rotate: 180deg; }
.picker__trigger:disabled .picker__chev { display: none; }

.picker__panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  left: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* nowrap excerpts must not widen the panel */
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  max-height: min(60dvh, 440px);
  padding: 10px;
  background: var(--paper);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.entrylist {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 0;
  margin: 0;
  padding: 2px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  scrollbar-width: thin;
}

/* Compact rows: one line of excerpt so hundreds of entries stay scannable. */
.entrycard {
  display: grid;
  grid-template-columns: 2.1em 1fr;
  column-gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 6px 10px;
  text-align: left;
  background: var(--card);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
  transition: background var(--t-fast);
}
.entrycard:hover { background: var(--paper-2); }
.entrycard[aria-current="true"] { background: var(--accent, var(--sky)); color: var(--on-accent); border-color: var(--on-accent); }
.entrycard__no {
  grid-row: span 2;
  font-family: var(--font-display);
  font-size: 1.1rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.entrycard__date { font-weight: 700; font-size: .8125rem; font-variant-numeric: tabular-nums; }
.entrycard__excerpt { overflow: hidden; color: var(--ink-60); font-size: .75rem; white-space: nowrap; text-overflow: ellipsis; }
.entrycard[aria-current="true"] .entrycard__excerpt { color: var(--on-accent); }
.entrycard--skeleton { height: 48px; opacity: .5; animation: pulse 1.1s ease-in-out infinite alternate; }

/* journal.sh: a small terminal that prints the journal's numbers. */
.term {
  overflow: hidden;
  background: var(--card);
  border: var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-mono);
  font-size: .8125rem;
  line-height: 1.55;
}
.term__bar { display: flex; align-items: center; gap: 5px; padding: 5px 10px; background: var(--paper-2); }
.term__dot { width: 9px; height: 9px; border: 2px solid var(--ink); border-radius: 50%; background: var(--pink); }
.term__dot:nth-child(2) { background: var(--mustard); }
.term__dot:nth-child(3) { background: var(--sage); }
.term__name { margin-left: 6px; color: var(--ink-60); font-size: .75rem; font-weight: 700; }
.term__body { display: grid; gap: 2px; padding: 8px 12px 6px; }
.term__log {
  max-height: 170px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  font-size: .75rem;
}
.term__log:empty { display: none; }
.term__row { padding-left: 12ch; text-indent: -12ch; white-space: pre-wrap; overflow-wrap: anywhere; } /* wrapped values stay in their column */
.term__echo { font-weight: 700; }
.term__prompt { display: flex; align-items: center; gap: 8px; min-height: 44px; border-radius: 7px; }
.term__prompt:focus-within { outline: 3px solid var(--ink); outline-offset: 2px; }
.term__ps { color: var(--pen); font-weight: 700; }
.term__input {
  flex: 1;
  min-width: 0;
  padding: 0;
  background: none;
  border: 0;
  outline: 0;
  color: var(--ink);
  font: inherit;
  caret-color: var(--pen);
}
.term__input::placeholder { color: var(--ink-60); }
@media (pointer: coarse) { .term__input { font-size: 16px; } } /* no zoom-on-focus on phones */

.sidebar__foot { display: flex; align-items: center; gap: 10px; margin-top: auto; padding-top: 6px; }
.sidebar__foot:not(:has(:not([hidden]))) { display: none; }
.sidebar__foot .btn { margin-left: auto; }

/* ------------------------------------------------------------------- page */

.page-wrap { min-width: 0; outline: none; }

.page {
  position: relative;
  background: var(--card);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: clip;
}

.page__head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 4px 16px;
  padding: 18px 26px 14px;
  background: var(--accent, var(--sky));
  color: var(--on-accent);
  border-bottom: 3px solid var(--on-accent);
}
.page__no {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2.25rem);
  line-height: 1;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}
.page__date { font-family: var(--font-hand); font-weight: 700; font-size: 1.6rem; line-height: 1; text-align: right; }
.page__scribble { grid-column: 1; width: 150px; height: 12px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; }

.page__meta { display: none; }
.page__endmeta { display: none; margin-top: 30px; color: var(--ink-60); font-size: .875rem; line-height: 30px; }

/* Ruled paper: a line every 30px with a red margin rule. */
.page__body {
  --margin-x: 56px;
  position: relative;
  padding: 30px 32px 60px calc(var(--margin-x) + 22px);
  background-image: repeating-linear-gradient(to bottom, transparent 0 29px, var(--rule) 29px 30px);
}
.page__body::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--margin-x);
  border-left: 2px solid var(--margin-rule);
}

.page__actions {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: var(--paper);
  border-top: var(--border);
}

.page__message { display: grid; justify-items: start; gap: 12px; padding: 48px 32px; }
.page__message-title { font-family: var(--font-display); font-size: 1.25rem; }
.page__message-text { color: var(--ink-60); }

.page.is-loading .skeleton__head { height: 92px; background: var(--paper-2); border-bottom: var(--border); animation: pulse 1.1s ease-in-out infinite alternate; }
.page.is-loading .skeleton__body {
  height: 360px;
  background-image: repeating-linear-gradient(to bottom, transparent 0 29px, var(--rule) 29px 30px);
}
@keyframes pulse { to { opacity: .45; } }

/* ------------------------------------------------------------------- rail */

.rail { position: sticky; top: 24px; display: grid; justify-items: start; gap: 15px; }

.stamp {
  display: inline-block;
  padding: 6px 14px;
  background: var(--pink);
  color: var(--on-accent);
  border: 3px solid var(--on-accent);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-display);
  font-size: 1.75rem;
  line-height: 1;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  rotate: -3deg;
}
.stamp--sm { padding: 3px 9px; font-size: 1rem; box-shadow: none; }

/* ICT patch panel: uplink ports page through entries, the middle ports carry
   the entry's details, the link LEDs show how far into the journal it sits. */
.patch {
  display: grid;
  justify-self: stretch;
  gap: 6px;
  padding: 8px;
  background: var(--card);
  border: var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
.patch__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px 2px;
  color: var(--ink-60);
  font-family: var(--font-mono);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.patch__screw {
  width: 10px;
  height: 10px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: linear-gradient(45deg, transparent 40%, var(--ink) 40% 60%, transparent 60%);
}
.patch__port {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 5px 8px;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 7px;
  font: inherit;
  text-align: left;
}
/* At night the faceplate lightens so the dark jacks still read as holes. */
[data-theme="dark"] .patch__port { background: color-mix(in srgb, var(--ink) 16%, var(--card)); }
.patch__port--uplink {
  box-shadow: 2px 2px 0 var(--shadow-ink);
  cursor: pointer;
  transition: translate var(--t-fast), box-shadow var(--t-fast);
}
.patch__port--uplink:hover { translate: 1px 1px; box-shadow: 1px 1px 0 var(--shadow-ink); }
.patch__port--uplink:active { translate: 2px 2px; box-shadow: none; }
.patch__port--uplink:disabled { opacity: .5; cursor: not-allowed; translate: none; box-shadow: 2px 2px 0 var(--shadow-ink); }

/* An RJ45 socket: dark opening, latch slot underneath, gold contacts along the top. */
.patch__jack {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 26px;
  background: var(--jack);
  color: var(--jack-ink);
  border-radius: 3px;
  clip-path: polygon(0 0, 100% 0, 100% 74%, 70% 74%, 70% 100%, 30% 100%, 30% 74%, 0 74%);
}
.patch__jack::before {
  content: '';
  position: absolute;
  top: 3px;
  right: 5px;
  left: 5px;
  height: 5px;
  background: repeating-linear-gradient(90deg, var(--mustard) 0 1.5px, transparent 1.5px 3px);
}
.patch__port--uplink .patch__jack::before { display: none; }
.patch__jack svg { width: 14px; height: 14px; margin-top: -6px; }
.patch__text { display: grid; min-width: 0; line-height: 1.2; }
.patch__value { overflow: hidden; font-size: .875rem; font-weight: 700; white-space: nowrap; text-overflow: ellipsis; }
.patch__caption { color: var(--ink-60); font-family: var(--font-mono); font-size: .75rem; }
.patch__led { width: 10px; height: 10px; background: var(--sage); border: 2px solid var(--ink); border-radius: 50%; }
.patch__port--uplink .patch__led { background: var(--mustard); }
.patch__port--uplink:disabled .patch__led { background: transparent; }

.patch__links {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  background: var(--jack);
  border-radius: 7px;
}
.patch__leds { display: flex; flex-wrap: wrap; gap: 4px; }
.led { width: 8px; height: 8px; border-radius: 2px; background: color-mix(in srgb, var(--jack-ink) 20%, transparent); }
.led.is-on { background: var(--sage); }
.led.is-current { background: var(--mustard); animation: blink 1.2s steps(1) infinite; }
@keyframes blink { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .led.is-current { animation: none; } }
.patch__count { color: var(--jack-ink); font-family: var(--font-mono); font-size: .75rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 1199px) {
  .shell { grid-template-columns: 230px minmax(0, 1fr); }
  .rail { display: none; }
  .page__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
    padding: 10px 26px;
    background: var(--paper);
    border-bottom: var(--border);
  }
  /* The panel lies flat as one slim row: jack-only uplinks at the ends, bare readouts between. */
  .page__meta .patch { display: flex; flex: 1; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 0; background: none; border: 0; box-shadow: none; }
  .page__meta .patch__head { display: none; }
  .page__meta .patch__port { width: auto; }
  .page__meta .patch__port--uplink { grid-template-columns: auto; padding: 5px 7px; }
  .page__meta .patch__port--uplink .patch__text, .page__meta .patch__port--uplink .patch__led { display: none; }
  .page__meta .patch__port:not(.patch__port--uplink) { min-height: 0; padding: 0; background: none; border: 0; }
  .page__meta .patch__port:not(.patch__port--uplink) .patch__jack,
  .page__meta .patch__port:not(.patch__port--uplink) .patch__led { display: none; }
  .page__meta .js-next { margin-left: auto; }
  .nameplate__title { font-size: 1.35rem; }
  .picker__no { font-size: 1.35rem; }
}

@media (max-width: 719px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--paper);
    border-bottom: var(--border);
  }
  .topbar__title { flex: 1; min-width: 0; overflow: hidden; font-family: var(--font-display); font-size: 1rem; text-transform: uppercase; white-space: nowrap; text-overflow: ellipsis; }

  .shell { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 12px 12px 96px; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(86vw, 340px);
    max-height: none;
    padding: 16px;
    background: var(--paper);
    border-right: 4px solid var(--ink);
    transform: translateX(-105%);
    visibility: hidden;
  }
  .sidebar.is-open { transform: none; visibility: visible; }

  /* Date under the title frees the band's right side for the phone stars. */
  .page__head { grid-template-columns: 1fr; padding: 14px 16px 12px; }
  .page__date { font-size: 1.35rem; text-align: left; }
  .page__head > * { justify-self: start; } /* boxes hug their text so stars can use the rest */
  .page__meta { display: none; }
  .page__endmeta { display: block; }
  .page__body { --margin-x: 20px; padding: 0 16px 60px calc(var(--margin-x) + 14px); } /* first line right under the band */

  .bottombar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: var(--paper);
    border-top: var(--border);
  }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

/* ------------------------------------------------------------------ prose */

.prose {
  max-width: 68ch;
  font-size: 1.125rem;
  line-height: 30px;
  overflow-wrap: break-word;
}
.prose > * { margin: 0 0 30px; }
.prose > :last-child { margin-bottom: 0; }

/* Every paragraph takes a first-line indent, the way a written journal reads,
   the opening one included. A paragraph the author has block-indented keeps
   its margin-left instead. */
.prose > p:not([style*="margin-left"]) { text-indent: 2em; }

.prose h2 {
  margin-top: 30px;
  margin-bottom: 0;
  font-family: var(--font-display);
  font-size: 1.5rem;
  line-height: 30px;
  letter-spacing: -.01em;
}
.prose h3 { margin-top: 30px; margin-bottom: 0; font-weight: 700; font-size: 1.1875rem; line-height: 30px; }
.prose > h2:first-child, .prose > h3:first-child { margin-top: 0; }

.prose ul, .prose ol { padding-left: 1.4em; }
.prose li > p { margin: 0; }
.prose li > ul, .prose li > ol { margin: 0; }
.prose li::marker { color: var(--pen); font-weight: 700; }

/* Outline, not border, so the note never shifts text off the ruling. */
.prose blockquote {
  padding: 15px 20px;
  background: var(--sage);
  color: var(--on-accent);
  outline: 3px solid var(--on-accent);
  outline-offset: -3px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
.prose blockquote > * { margin: 0; }

.prose hr {
  height: 30px;
  border: 0;
  background: linear-gradient(var(--ink), var(--ink)) center / 40% 3px no-repeat;
}

.prose mark {
  padding: 0 2px;
  background: var(--hl-mustard);
  color: var(--on-accent) !important; /* Tiptap writes color: inherit inline */
  border-radius: 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.prose strong { font-weight: 700; }
.prose s { text-decoration-thickness: 2px; }
.prose u { text-decoration-thickness: 2px; text-underline-offset: .2em; }

@media (max-width: 719px) {
  .prose { font-size: 1.0625rem; }
}

/* ------------------------------------------------------------ saved stamp */

.saved-stamp {
  position: absolute;
  top: 110px;
  right: 28px;
  z-index: 5;
  padding: 6px 16px;
  background: var(--sage);
  color: var(--on-accent);
  border: 3px solid var(--on-accent);
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-size: 1.5rem;
  text-transform: uppercase;
  rotate: -6deg;
  pointer-events: none;
}

/* ------------------------------------------------------------------ stars */

.stars { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

/* The shell spans the viewport above the stars; only its panels catch clicks. */
.shell { pointer-events: none; }
.shell > * { pointer-events: auto; }

.star {
  position: absolute;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  pointer-events: auto;
  cursor: pointer;
}
.star svg { width: 22px; height: 22px; fill: currentColor; stroke: var(--ink); stroke-width: 1.4; }
[data-theme="dark"] .star svg { stroke: none; filter: drop-shadow(0 0 6px currentColor); }
.page__head { position: relative; }
.star--band svg, [data-theme="dark"] .star--band svg { stroke: var(--on-accent); filter: none; }

.inkdot {
  position: fixed;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  background: var(--ink);
  border-radius: 50%;
  pointer-events: none;
}

/* ----------------------------------------------------------------- editor */

.page--editing { overflow: visible; }

.editor__toolbar { position: sticky; top: 0; z-index: 20; padding: 10px 10px 0; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: var(--card);
  border: var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
.toolbar__group { display: flex; align-items: center; gap: 2px; padding: 0 4px; border-right: 2px solid color-mix(in srgb, var(--ink) 20%, transparent); }
.toolbar__group:last-child { border-right: 0; }

.tool {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  height: 36px;
  padding: 0 6px;
  background: none;
  color: var(--ink);
  border: 2px solid transparent;
  border-radius: 7px;
  font: inherit;
  font-weight: 700;
  font-size: .8125rem;
  cursor: pointer;
}
.tool:hover { background: var(--paper); border-color: var(--ink); }
.tool[aria-pressed="true"] { background: var(--mustard); color: var(--on-accent); border-color: var(--on-accent); }
.tool--select { padding: 0 8px; background: var(--paper); border-color: var(--ink); }
.tool--swatch { display: inline-flex; gap: 4px; }
.tool__chip { width: 12px; height: 12px; border: 2px solid var(--ink); border-radius: 3px; }

.swatch__pop {
  position: fixed;
  inset: auto;
  margin: 0;
  display: none;
  gap: 6px;
  padding: 8px;
  background: var(--card);
  color: var(--ink);
  border: var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.swatch__pop:popover-open { display: flex; }
.swatch__chip { width: 32px; height: 32px; border: 3px solid var(--on-accent); border-radius: 7px; cursor: pointer; }
.swatch__none { padding: 0 10px; background: var(--paper); color: var(--ink); border: 2px solid var(--ink); border-radius: 7px; font: inherit; font-weight: 700; cursor: pointer; }

.editbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: var(--border); }
.editbar__field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 10px;
  background: var(--card);
  border: var(--border);
  border-radius: 999px;
}
.editbar__field:focus-within { outline: 3px solid var(--ink); outline-offset: 2px; }
.editbar__input { min-width: 0; padding: 0; background: none; border: 0; outline: 0; color: var(--ink); font: inherit; font-weight: 700; font-variant-numeric: tabular-nums; }
.editbar__input[type="number"] { width: 4ch; }
.editbar__spacer { flex: 1; }

.editor__error {
  margin: 12px 16px 0;
  padding: 9px 12px;
  background: var(--orange);
  color: var(--on-accent);
  border: 3px solid var(--on-accent);
  border-radius: var(--radius-sm);
  font-weight: 700;
}

.prose--editor { min-height: 60vh; outline: none; cursor: url("pen.svg") 3 27, text; }
.prose--editor p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  height: 0;
  color: var(--ink-60);
  pointer-events: none;
}

@media (max-width: 719px) {
  .is-editing .bottombar { display: none; }
  .editor__toolbar { top: 66px; padding: 8px 0 0; }
  .toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
  .tool { min-width: 44px; height: 44px; }
  .editbar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--paper);
    border-top: var(--border);
    border-bottom: 0;
  }
  .editbar .btn { padding: 9px 12px; }
}

/* ----------------------------------------------------------------- figure */

.prose figure { margin-left: 0; margin-right: 0; max-width: 100%; }
.prose figure img {
  display: block;
  width: 100%;
  height: auto;
  background: var(--paper-2);
  border: var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
.prose figcaption {
  padding-top: 4px;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 1.3rem;
  line-height: 30px;
  color: var(--pen);
}
.prose figcaption:empty { display: none; }

.figure-edit { position: relative; }
.figure-edit.is-uploading img { opacity: .55; }
.figure-edit figcaption { min-height: 30px; }
.figure-edit figcaption[data-empty="true"]::before {
  content: "Add a caption (optional)";
  color: var(--ink-60);
  pointer-events: none;
}
.figure-edit__alt {
  width: 100%;
  margin-top: 4px;
  padding: 4px 8px;
  background: var(--paper);
  color: var(--ink);
  border: 2px dashed var(--ink-60);
  border-radius: 6px;
  font: inherit;
  font-size: .875rem;
  line-height: 20px;
}
.figure-edit__handle {
  position: absolute;
  top: 8px;
  right: -12px;
  width: 24px;
  height: 24px;
  background: var(--mustard);
  border: 3px solid var(--on-accent);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  cursor: ew-resize;
  touch-action: none;
}
.ProseMirror-selectednode.figure-edit img { outline: 3px solid var(--pen); outline-offset: 3px; }

/* === later tasks append sections above this line === */

/* --------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
  .btn:hover, .btn:active, .iconbtn:hover, .iconbtn:active { translate: none; }
}
