/* travel_notes. Colours are the ones of https://wmahaney.github.io (its
   assets/theme-light.scss and assets/theme-dark.scss); see docs/ARCHITECTURE.md. */

:root {
  --bg: #FBF5E6;
  --panel: #FFFDF7;
  --text: #1E2430;
  --muted: #4A5160;
  --border: #E3D8BA;
  --accent: #2B4FB8;
  --accent-text: #FFFFFF;
  --tint: #F2E9CF;
  --danger: #B93A2B;

  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --serif: Georgia, "Times New Roman", Times, serif;
  --radius: 6px;
  --split: 50%;
  color-scheme: light;
}
/* Dark: the system setting, unless the toggle has chosen light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171C; --panel: #1E2128; --text: #F2EDE0; --muted: #B3B8C5; --border: #343947;
    --accent: #9DB3F7; --accent-text: #15171C; --tint: #262A33; --danger: #F08D7C;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171C; --panel: #1E2128; --text: #F2EDE0; --muted: #B3B8C5; --border: #343947;
  --accent: #9DB3F7; --accent-text: #15171C; --tint: #262A33; --danger: #F08D7C;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--ui);
}
button, a, textarea, .toolbar, .status, .pane, .errors, .divider {
  transition: color 120ms, background-color 120ms, border-color 120ms;
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.grow { flex: 1 1 auto; }

/* ---- toolbar (44px) and status bar (28px) ---- */
.toolbar {
  flex: none;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  white-space: nowrap;
}
.brand { font-weight: 600; margin-right: 6px; }
.sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; flex: none; }
button {
  font: inherit;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 10px;
  cursor: pointer;
  flex: none;
}
button:hover { border-color: var(--accent); }
button:focus-visible, a:focus-visible, textarea:focus-visible, .divider:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button[aria-pressed="true"] { background: var(--tint); }
button:disabled { opacity: 0.6; cursor: default; }

.status {
  flex: none;
  height: 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
}
.status a { color: var(--muted); }
.status a:hover { color: var(--accent); }
#status { overflow: hidden; text-overflow: ellipsis; }
#status.stale { color: var(--danger); }
.status-button {
  font-size: 12px;
  padding: 1px 8px;
  color: var(--danger);
  border-color: var(--danger);
}

/* ---- the two panes ---- */
.panes {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, var(--split)) 7px minmax(0, 1fr);
}
.pane { min-width: 0; min-height: 0; overflow: auto; }
.editor { display: flex; }
#source {
  flex: 1 1 auto;
  width: 100%;
  border: 0;
  resize: none;
  padding: 14px 16px;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--mono);
  tab-size: 4;
}
#source:focus-visible { outline-offset: -2px; }
.divider { background: var(--border); cursor: col-resize; touch-action: none; }
.divider:hover { background: var(--accent); }
.preview { background: var(--panel); padding: 18px 26px 40px; }
body.no-preview .panes { grid-template-columns: minmax(0, 1fr); }
body.no-preview .divider, body.no-preview .preview { display: none; }

/* ---- the rendered note ---- */
.tn-doc {
  max-width: 46rem;
  margin: 0 auto;
  font: 17px/1.6 var(--serif);
  overflow-wrap: break-word;
}
.tn-doc > :first-child { margin-top: 0; }
.tn-doc h1, .tn-doc h2, .tn-doc h3, .tn-doc h4, .tn-doc h5, .tn-doc h6 { line-height: 1.25; margin: 1.4em 0 0.5em; }
.tn-doc h1 { font-size: 1.8em; }
.tn-doc h2 { font-size: 1.4em; }
.tn-doc h3 { font-size: 1.17em; }
.tn-doc a { color: var(--accent); }
.tn-doc hr { border: 0; border-top: 1px solid var(--border); margin: 1.6em 0; }
.tn-doc blockquote { margin: 1em 0; padding: 0 1em; border-left: 3px solid var(--border); color: var(--muted); }
/* A theorem-like block: a block quote that opens with a bold "Theorem." and the like. */
.tn-doc blockquote.tn-env { border-left-color: var(--accent); color: inherit; }
.tn-doc blockquote.tn-env > :first-child { margin-top: 0.4em; }
.tn-doc blockquote.tn-env > :last-child { margin-bottom: 0.4em; }
.tn-doc blockquote.tn-theorem, .tn-doc blockquote.tn-lemma, .tn-doc blockquote.tn-proposition,
.tn-doc blockquote.tn-corollary, .tn-doc blockquote.tn-conjecture, .tn-doc blockquote.tn-claim { font-style: italic; }
.tn-doc blockquote.tn-env .tn-env-head, .tn-doc blockquote.tn-env .tn-math { font-style: normal; }
.tn-doc blockquote.tn-proof, .tn-doc blockquote.tn-remark { border-left-color: var(--border); }
.tn-doc blockquote.tn-proof .tn-env-head, .tn-doc blockquote.tn-remark .tn-env-head { font-style: italic; font-weight: normal; }
.tn-doc blockquote.tn-proof > :last-child::after { content: "\25A1"; float: right; font-style: normal; }
/* The block that Locate found. It stays marked until the next Locate or Compile. */
.tn-located { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }
.tn-doc code { font: 0.88em var(--mono); background: var(--tint); border-radius: 4px; padding: 0.1em 0.3em; }
.tn-doc pre { background: var(--tint); border-radius: var(--radius); padding: 0.8em 1em; overflow: auto; }
.tn-doc pre code { background: none; padding: 0; }
.tn-doc table { border-collapse: collapse; margin: 1em 0; }
.tn-doc th, .tn-doc td { border: 1px solid var(--border); padding: 0.3em 0.7em; }
.tn-doc th { background: var(--tint); }
.tn-left { text-align: left; }
.tn-center { text-align: center; }
.tn-right { text-align: right; }
.tn-doc li.tn-task { list-style: none; margin-left: -1.3em; }
.tn-doc li.tn-task input { margin-right: 0.4em; }
/* Images: no wider than the note, with a sensible largest height. */
.tn-doc img { max-width: 100%; max-height: 70vh; height: auto; vertical-align: middle; }
/* A link or image that was not kept, and an image that failed to load: the text,
   in a marked box. */
.tn-blocked-link { border-bottom: 1px dashed var(--danger); }
.tn-blocked-image, .tn-failed-image {
  display: inline-block;
  border: 1px dashed var(--danger);
  border-radius: 4px;
  padding: 0.1em 0.5em;
  color: var(--muted);
  font: 0.85em var(--ui);
}
.tn-blocked-image::before { content: "image not shown: "; color: var(--danger); }
.tn-failed-image::before { content: "image did not load: "; color: var(--danger); }
/* Math. Display math is a block; MathJax's SVG takes the text colour. */
.tn-display { display: block; margin: 1em 0; text-align: center; overflow-x: auto; overflow-y: hidden; }
.tn-math mjx-container { color: inherit; }
.tn-math-error {
  outline: 1px solid var(--danger);
  outline-offset: 2px;
  border-radius: 3px;
  font: 0.85em var(--mono);
  color: var(--danger);
}

/* ---- the error list ---- */
.errors {
  flex: none;
  max-height: 34vh;
  overflow: auto;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.errors-head { display: flex; align-items: center; gap: 6px; padding: 6px 10px; position: sticky; top: 0; background: var(--panel); border-bottom: 1px solid var(--border); }
.errors ol { margin: 0; padding: 6px 10px 10px 10px; list-style: none; }
.errors li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.errors li:last-child { border-bottom: 0; }
.errors li button { padding: 1px 6px; margin-right: 8px; font-size: 12px; }
.outline li { border-bottom: 0; padding: 1px 0; }
.outline li button { border-color: transparent; background: none; text-align: left; margin: 0; font-size: 13px; }
.outline li button:hover { border-color: var(--accent); }
.outline li[data-level="2"] { padding-left: 1.2em; }
.outline li[data-level="3"] { padding-left: 2.4em; }
.outline li[data-level="4"], .outline li[data-level="5"], .outline li[data-level="6"] { padding-left: 3.6em; }
.outline li.empty { color: var(--muted); padding: 4px 6px; }
.errors li code { font: 12px var(--mono); color: var(--muted); display: block; margin: 2px 0 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- narrow screens: one pane above the other ---- */
@media (max-width: 700px) {
  .panes { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  .divider { display: none; }
  .preview { border-top: 1px solid var(--border); padding: 14px 16px 30px; }
}

/* ---- printing: the note only, in light colours ---- */
@page { margin: 20mm 18mm; }
@media print {
  :root, :root[data-theme="dark"], :root:not([data-theme="light"]) {
    /* the light palette, on white paper */
    --bg: #FFFFFF; --panel: #FFFFFF; --text: #1E2430; --muted: #4A5160; --border: #E3D8BA;
    --accent: #2B4FB8; --accent-text: #FFFFFF; --tint: #F2E9CF; --danger: #B93A2B;
    color-scheme: light;
  }
  * { transition: none !important; }
  html, body { height: auto; display: block; background: #FFFFFF; }
  .toolbar, .status, .editor, .divider, .errors { display: none !important; }
  .panes { display: block; }
  .pane { overflow: visible; }
  .preview, body.no-preview .preview { display: block; padding: 0; background: #FFFFFF; }
  .tn-doc { max-width: none; font-size: 11.5pt; }
  .tn-doc h1, .tn-doc h2, .tn-doc h3, .tn-doc h4, .tn-doc h5, .tn-doc h6 { break-after: avoid; page-break-after: avoid; }
  .tn-display, .tn-math mjx-container, .tn-doc pre, .tn-doc table, .tn-doc img, .tn-doc blockquote { break-inside: avoid; page-break-inside: avoid; }
  .tn-display { overflow: visible; }
  .tn-doc pre { white-space: pre-wrap; }
  .tn-doc a { color: inherit; text-decoration: underline; }
  .tn-located { outline: 0; }
}
