/*
 * theme.css — TipTap Editor. A calm writing desk: cool slate paper, one deep
 * teal accent for the active tool and the brand mark, a serif for the words
 * being written and a quiet sans for the chrome. Dark mode is a night desk,
 * not an inversion: near-black slate with a lifted mint accent.
 */

:root {
  --canvas: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --border: #dcdfe5;
  --border-strong: #b4b9c3;
  --ink: #161a22;
  --muted: #5b6270;
  --accent: #0f6e66;
  --accent-hover: #0b5a53;
  --accent-ink: #ffffff;
  --accent-text: #0d655e;
  --accent-strong: #0a4f49;
  --accent-soft: #dcefec;
  --accent-border: #9fd0ca;
  --success: #15803d;
  --success-ink: #ffffff;
  --success-soft: #dfebe3;
  --success-strong: #137638;
  --warning: #b45309;
  --warning-ink: #ffffff;
  --warning-soft: #f2e6dd;
  --warning-strong: #a64c08;
  --danger: #b91c1c;
  --danger-ink: #ffffff;
  --danger-soft: #f2dfdf;
  --danger-strong: #b91c1c;
  --chart-1: #0f6e66;
  --chart-2: #7c285c;
  --chart-3: #7c350c;
  --chart-4: #425605;
  --chart-5: #0b5668;
  --chart-6: #5152a5;

  --font-display: "Literata", Georgia, "Times New Roman", serif;
  --font-body: "Instrument Sans", ui-sans-serif, system-ui, sans-serif;
  --font-sans: "Instrument Sans", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --display-weight: 700;
  --display-tracking: -0.02em;
  --eyebrow-tracking: 0.06em;

  --radius-btn: 0.625rem;
  --radius-card: 1rem;
  --radius-input: 0.625rem;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 12px 32px rgba(0, 0, 0, 0.06);
}

html[data-theme="dark"] {
  --canvas: #0f1216;
  --surface: #171b21;
  --surface-2: #1f242c;
  --border: #2a3039;
  --border-strong: #46505d;
  --ink: #e8ebf0;
  --muted: #9aa3b0;
  --accent: #5ccfc1;
  --accent-hover: #7fdbcf;
  --accent-ink: #08201d;
  --accent-text: #6fd6c9;
  --accent-strong: #8fe3d8;
  --accent-soft: #12302d;
  --accent-border: #23524c;
  --success: #15803d;
  --success-ink: #ffffff;
  --success-soft: #172f22;
  --success-strong: #58a474;
  --warning: #b45309;
  --warning-ink: #ffffff;
  --warning-soft: #3a2517;
  --warning-strong: #ca854f;
  --danger: #b91c1c;
  --danger-ink: #ffffff;
  --danger-soft: #3b191b;
  --danger-strong: #d57575;
  --chart-1: #5ccfc1;
  --chart-2: #cb70a4;
  --chart-3: #be6436;
  --chart-4: #98911a;
  --chart-5: #159670;
  --chart-6: #1c9ec8;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.35);
}

/* app.css — the editor's own screen: the brand mark, the toolbar, the document,
   the co-editing marks (presence avatars, other people's cursors) and the
   print layout used by "Print or save as PDF". */

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  flex: none;
  border-radius: 0.5rem;
  background: var(--accent);
  color: var(--accent-ink);
}

.editor-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: clip;
}

/* Toolbar: one line, scrolls sideways inside itself on a phone. */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
}
.tool-group {
  display: flex;
  flex: none;
  gap: 0.125rem;
}
.tool-sep {
  flex: none;
  width: 1px;
  height: 1.5rem;
  margin: 0 0.25rem;
  background: var(--border);
}
.tool {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tool:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--ink);
}
.tool[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.tool:disabled {
  opacity: 0.4;
  cursor: default;
}
.tool:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* The writing surface. */
.editor-area {
  padding: 2rem 1.25rem;
}
@media (min-width: 768px) {
  .editor-area {
    padding: 3rem 4rem;
  }
}
.editor-loading {
  min-height: 55vh;
}
.editor-error {
  min-height: 55vh;
  color: var(--danger-strong);
}

.doc {
  max-width: 68ch;
  min-height: 55vh;
  margin: 0 auto;
  outline: none;
  font-family: var(--font-display);
  font-size: 1.125rem;
  line-height: 1.75;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  caret-color: var(--accent);
}
.doc > * + * {
  margin-top: 0.9em;
}
.doc h1,
.doc h2,
.doc h3 {
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 1.4em;
}
.doc > :first-child {
  margin-top: 0;
}
.doc h1 {
  font-size: 2.25rem;
  line-height: 1.15;
}
.doc h2 {
  font-size: 1.6rem;
  line-height: 1.25;
}
.doc h3 {
  font-size: 1.25rem;
  line-height: 1.35;
}
.doc strong {
  font-weight: 700;
}
.doc ul {
  list-style: disc;
  padding-left: 1.5rem;
}
.doc ol {
  list-style: decimal;
  padding-left: 1.5rem;
}
.doc li + li {
  margin-top: 0.25em;
}
.doc li > p {
  margin: 0;
}
.doc blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--muted);
  font-style: italic;
}
.doc code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.1em 0.35em;
}
.doc pre {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  white-space: pre;
}
.doc pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
}
.doc hr {
  border: 0;
  border-top: 1px solid var(--border-strong);
  margin: 2em 0;
}
.doc hr.ProseMirror-selectednode {
  border-top-color: var(--accent);
}
.doc a {
  color: var(--accent-text);
  text-decoration: underline;
}
.doc p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  height: 0;
  color: var(--muted);
  pointer-events: none;
}
.doc ::selection {
  background: var(--accent-soft);
}
.doc[contenteditable="false"] {
  cursor: progress;
}

.editor-foot {
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem;
  background: var(--surface-2);
}

/* ---- Co-editing ---------------------------------------------------------- */

/* Avatars of the other people in the book, overlapping, in their cursor colour. */
.presence {
  display: flex;
  align-items: center;
}
.presence:empty {
  display: none;
}
.peer {
  display: inline-grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  flex: none;
  border-radius: 999px;
  border: 2px solid var(--surface);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--surface);
  user-select: none;
}
.peer + .peer {
  margin-left: -0.5rem;
}
.peer-more {
  background: var(--surface-2);
  color: var(--muted);
}

/* Another writer's caret and name tag (colour set inline from their --chart-N). */
.collaboration-cursor__caret {
  position: relative;
  margin-left: -1px;
  margin-right: -1px;
  border-left: 1px solid;
  border-right: 1px solid;
  word-break: normal;
  pointer-events: none;
}
.collaboration-cursor__label {
  position: absolute;
  top: -1.4em;
  left: -1px;
  padding: 0.05rem 0.35rem;
  border-radius: 0.25rem 0.25rem 0.25rem 0;
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-style: normal;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0;
  white-space: nowrap;
  color: var(--surface);
  user-select: none;
  pointer-events: none;
}

/* ---- Print: "Print or save as PDF" prints the book alone, on paper colours ---- */

@media print {
  @page {
    margin: 18mm 16mm;
  }
  html {
    color-scheme: light;
  }
  body {
    background: none;
    color: CanvasText;
  }
  .app-bar,
  .toolbar,
  .editor-foot,
  .presence,
  dialog,
  .collaboration-cursor__caret {
    display: none !important;
  }
  main {
    padding: 0 !important;
    max-width: none !important;
  }
  .editor-shell {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
    background: none;
  }
  .editor-area {
    padding: 0;
  }
  .doc {
    max-width: none;
    min-height: 0;
    font-size: 11.5pt;
    color: CanvasText;
  }
  .doc blockquote,
  .doc code,
  .doc pre {
    color: CanvasText;
    background: none;
  }
  .doc h1 {
    break-before: page;
  }
  .doc > h1:first-child {
    break-before: auto;
  }
  .doc h1,
  .doc h2,
  .doc h3 {
    break-after: avoid;
  }
  .doc pre,
  .doc blockquote {
    break-inside: avoid;
  }
  .ProseMirror-yjs-selection {
    background: none !important;
  }
}
