/* style.css -- the page, and <collab-editor> (light DOM, so it lives here) */

:root {
  /* every colour in both themes: light-dark(day, night) */
  --bg: light-dark(#fbfaf8, #16171a);
  --paper: light-dark(#ffffff, #1e2024);
  --ink: light-dark(#1d1f23, #e8e6e1);
  --muted: light-dark(#6a6f78, #9aa0a8);
  --line: light-dark(#e4e2dd, #33363c);
  --sent: light-dark(#8f959e, #858b94);  /* grey: sent, awaiting the verdict */
  --held: light-dark(#bcc1c8, #5b6068);  /* pale: typed, not sent yet */
  --gone: light-dark(#b3b8bf, #6a7079);  /* struck: deleted, not confirmed */
  --ok: light-dark(#2f7d4a, #5cc285);
  --warn: light-dark(#b25e09, #e0a050);
  --bad: light-dark(#b42318, #f07b6e);
  --doc-font: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* which of the two: the OS's, with no JS needed, unless the toggle has
     chosen (static/theme.js puts "light" or "dark" on <html>) */
  color-scheme: light dark;
}
:root.light { color-scheme: light; }
:root.dark { color-scheme: dark; }

* { box-sizing: border-box; }
/* the page is a column the height of the window: a compact header, and
   the editor taking the rest, edge to edge */
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--ui-font);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  --gutter: clamp(1rem, 3vw, 2rem);
}
header { padding: 1rem var(--gutter) 0; }
h1 { font: 600 1.6rem/1.2 var(--doc-font); margin: 0 0 .4rem; letter-spacing: -.01em; }
/* the top row: the title, and who serves it */
.top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
/* http-nu's credit sits on a dark tile, the dark theme's background, so
   ellie reads in light mode too */
.credit {
  font-size: 0.8rem; white-space: nowrap;
  display: inline-flex; align-items: center; gap: .4rem;
  background: #16171a; color: #e8e6e1;
  padding: .3rem .5rem .3rem .7rem; border-radius: 8px;
}
.credit img { width: 64px; height: auto; display: block; }
/* day and night: a moon while it's day, a sun while it's night; hidden
   (the hidden attribute) until static/theme.js runs */
.theme-toggle {
  margin-left: auto; align-self: center;
  display: inline-grid; place-items: center; width: 2rem; height: 2rem; padding: 0;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper); color: var(--ink); cursor: pointer;
}
.theme-toggle[hidden] { display: none; }
.theme-toggle svg { width: 1.1rem; height: 1.1rem; }
.theme-toggle .sun, .theme-toggle[aria-pressed="true"] .moon { display: none; }
.theme-toggle[aria-pressed="true"] .sun { display: block; }
/* narrow: ellie stays, the words go */
@media (max-width: 700px) { .credit span { display: none; } .credit img { width: 48px; } .credit { padding: .25rem .4rem; } .top { gap: .5rem; } h1 { font-size: 1.2rem; } .how { display: none; } }
.lede { margin: 0 0 .2rem; color: var(--ink); max-width: 52rem; }
.how { margin: 0 0 .6rem; color: var(--muted); font-size: 13.5px; max-width: 52rem; }
a { color: inherit; text-underline-offset: 2px; }

.legend { display: flex; flex-wrap: wrap; gap: .2rem 1.6rem; margin: 0 0 .9rem; font-size: 13.5px; }
.legend div { display: flex; gap: .5rem; align-items: baseline; }
.legend dt { font: 16px var(--doc-font); min-width: 3.4rem; }
.legend dd { margin: 0; color: var(--muted); }
.legend .sent { color: var(--sent); }
.legend .held { color: var(--held); }
.legend .gone { color: var(--gone); text-decoration: line-through; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
/* the controls across the top; below them the editor and its preview side
   by side, or the preview under the editor when the window is narrow */
.pane {
  flex: 1; min-height: 0; min-width: 0;
  display: grid; row-gap: .5rem;
  grid-template: "controls controls" auto "editor preview" minmax(0, 1fr) / minmax(0, 1fr) minmax(0, 1fr);
}
.pane > .controls { grid-area: controls; }
.pane > collab-editor { grid-area: editor; }
.pane > .preview { grid-area: preview; }
@media (max-width: 800px) {
  .pane { grid-template: "controls" auto "editor" minmax(0, 3fr) "preview" minmax(0, 2fr) / minmax(0, 1fr); }
}
.controls { padding: 0 var(--gutter); }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1rem; font-size: 13.5px; color: var(--muted); }
.controls .who { color: var(--ink); font-weight: 600; display: inline-flex; align-items: center; gap: .4rem; margin-right: auto; }
.controls .who::before { content: ""; width: .6rem; height: .6rem; border-radius: 50%; background: var(--c); }
.controls select { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: .15rem .3rem; }
.controls .rtt { font-variant-numeric: tabular-nums; min-width: 6.5em; }
.controls .rtt.offline { color: var(--bad); }
.controls .switch { display: inline-flex; align-items: center; gap: .25rem; cursor: pointer; }


/* ---- the preview ------------------------------------------------------ */

/* the saved text as markdown; it scrolls on its own */
.preview {
  min-height: 0; overflow: auto;
  background: var(--bg);
  border-top: 1px solid var(--line); border-left: 1px solid var(--line);
  padding: .9rem var(--gutter) 2rem;
}
@media (max-width: 800px) { .preview { border-left: 0; } }
.preview-note { margin: 0 0 .6rem; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.md { font: 16px/1.6 var(--doc-font); overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3 { font-family: var(--doc-font); line-height: 1.25; margin: 1.2em 0 .4em; }
.md h1 { font-size: 1.6rem; } .md h2 { font-size: 1.3rem; } .md h3 { font-size: 1.1rem; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: .6em 0; }
.md blockquote { padding-left: 1em; border-left: 3px solid var(--line); color: var(--muted); }
.md code { font-size: .85em; background: color-mix(in srgb, var(--ink) 7%, transparent); padding: .05em .3em; border-radius: 4px; }
.md pre { padding: .7em .9em; border-radius: 6px; overflow: auto; background: var(--paper); border: 1px solid var(--line); }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--line); padding: .25em .6em; }
.md img { max-width: 100%; }
.md hr { border: 0; border-top: 1px solid var(--line); }

/* ---- <collab-editor> ---------------------------------------------------- */

/* the editor fills the rest of the window, edge to edge; its text scrolls
   inside it, and the status floats over its bottom-right corner */
collab-editor { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ce { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--paper); border-top: 1px solid var(--line); overflow: hidden; }
.ce-scroll { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.ce-bar {
  position: absolute; right: .75rem; bottom: .75rem; z-index: 1;
  max-width: calc(100% - 1.5rem);
  display: flex; align-items: center; justify-content: flex-end; gap: .75rem; flex-wrap: wrap;
  padding: .4rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 10px rgb(0 0 0 / .08);
  font-size: 12.5px; color: var(--muted);
}
.ce-status { display: inline-flex; align-items: center; gap: .45rem; }
.ce-status::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: var(--ok); flex: none; }
.ce-status[data-state="waiting"]::before { background: var(--sent); animation: ce-pulse 1s ease-in-out infinite; }
.ce-status[data-state="offline"]::before { background: var(--held); }
.ce-status[data-state="reconnecting"]::before { background: var(--warn); animation: ce-pulse 1s ease-in-out infinite; }
.ce-status[data-state="refused"] { color: var(--bad); }
.ce-status[data-state="refused"]::before { background: var(--bad); }
@keyframes ce-pulse { 50% { opacity: .35; } }
.ce-rev { font-variant-numeric: tabular-nums; }
.ce-peers { display: inline-flex; gap: .35rem; flex-wrap: wrap; }
.ce-peer {
  font-size: 11.5px; line-height: 1; padding: .25rem .45rem; border-radius: 999px;
  color: #fff; background: var(--c);
}
.ce-me { outline: 2px solid color-mix(in srgb, var(--c) 35%, transparent); outline-offset: 1px; }

.ce-surface { position: relative; flex: 1; display: flex; flex-direction: column; }
.ce-text {
  /* room at the bottom, so the last line can scroll clear of the status */
  flex: 1; padding: 1.1rem var(--gutter) 4.5rem;
  font: 17px/1.65 var(--doc-font); color: var(--ink);
  white-space: pre-wrap; overflow-wrap: anywhere; outline: none;
  caret-color: var(--ink);
}
.ce-sent { color: var(--sent); }
.ce-held { color: var(--held); }
/* a deletion the server has not confirmed: drawn, not part of the text */
.ce-gone::before {
  content: attr(del);
  color: var(--gone);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
  user-select: none;
}

.ce-overlay { position: absolute; inset: 0; pointer-events: none; }
.ce-caret { position: absolute; width: 2px; margin-left: -1px; background: var(--c); }
.ce-caret span {
  position: absolute; bottom: 100%; left: -1px; white-space: nowrap;
  font: 600 10.5px/1 var(--ui-font); color: #fff; background: var(--c);
  padding: .15rem .3rem; border-radius: 3px 3px 3px 0;
}
.ce-sel { position: absolute; background: color-mix(in srgb, var(--c) 18%, transparent); }
.ce-peer.ce-idle { opacity: .55; }
