/* Writing Tool, stage one.
   Dark text on a warm light ground. Serif manuscript body at a
   comfortable measure. Interface furniture in sans, kept quiet so the
   prose is the only thing with any weight on the page. */

:root {
  --paper:      #faf9f6;
  --paper-edge: #f2efe9;
  --ink:        #1d1b19;
  --ink-soft:   #5c574f;
  --ink-faint:  #8d8679;
  --rule:       #e2ddd3;
  --accent:     #7a5c3e;
  --accent-bg:  #f0e8dd;
  --warn:       #9a4a2f;
  --measure:    40rem;
  --editor-size: 19px;
  --editor-lead: 1.72;
  --indent: 0;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans:  system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
}

a { color: var(--accent); }

.shell {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 290px;
  height: 100vh;
}

/* ---- rails ---- */

.rail {
  background: var(--paper-edge);
  border-right: 1px solid var(--rule);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.rail-right { border-right: 0; border-left: 1px solid var(--rule); }

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--rule);
}

.rail-foot {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid var(--rule);
  font-size: 13px;
}

.mini {
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-soft);
  width: 22px; height: 22px;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}
.mini:hover { border-color: var(--accent); color: var(--accent); }

/* ---- project tree ---- */

.tree { padding: 8px 0; }

.tree .proj {
  padding: 10px 16px 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--ink-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tree .proj button {
  border: 0; background: none; cursor: pointer;
  color: var(--ink-faint); font-size: 15px; line-height: 1;
}
.tree .proj button:hover { color: var(--accent); }

.tree a.doc {
  display: block;
  padding: 6px 16px 6px 22px;
  font-size: 13.5px;
  color: var(--ink-soft);
  text-decoration: none;
  border-left: 2px solid transparent;
}
.tree a.doc:hover { background: rgba(0,0,0,.03); color: var(--ink); }
.tree a.doc.active {
  background: var(--accent-bg);
  border-left-color: var(--accent);
  color: var(--ink);
}
.tree a.doc span { float: right; color: var(--ink-faint); font-size: 11px; }

/* ---- main ---- */

.main { overflow-y: auto; }

.doc-head {
  position: sticky; top: 0; z-index: 3;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.doc-title {
  font-family: var(--serif);
  font-size: 20px;
  color: var(--ink);
  border: 0;
  background: none;
  text-align: center;
  width: var(--measure);
  max-width: 90%;
  padding: 2px 6px;
  border-radius: 4px;
}
.doc-title:focus { outline: 0; background: var(--accent-bg); }
.crumb { font-size: 11px; color: var(--ink-faint); letter-spacing: .06em; text-transform: uppercase; }

.editor-wrap { display: flex; justify-content: center; padding: 44px 24px 60vh; }

/* The manuscript itself. */
.editor {
  width: var(--measure);
  max-width: 100%;
  font-family: var(--serif);
  font-size: var(--editor-size);
  line-height: var(--editor-lead);
  color: var(--ink);
  outline: 0;
}
.editor em { font-style: italic; }
.editor strong { font-weight: 700; }
.editor p {
  margin: 0 0 1.15em;
  text-indent: var(--indent);
}
/* Set by app.js: first paragraph of a chapter, any scene break, and the
   paragraph immediately after one. */
.editor p.no-indent { text-indent: 0; }
/* A scene break gets a clear blank line either side, which is what
   manuscript format expects and what makes it read as a break. */
.editor p.scene-break {
  text-align: center;
  color: var(--ink-faint);
  letter-spacing: .3em;
  margin-top: 2.4em;
  margin-bottom: 2.4em;
}
.editor p.is-active {
  box-shadow: -14px 0 0 -12px var(--accent);
}
/* Keep empty paragraphs clickable without inserting a zero-width space.
   Using U+200B here would be a poor joke in this particular application. */
.editor p:empty {
  min-height: calc(var(--editor-lead) * 1em);
}

.empty {
  padding: 22vh 40px;
  text-align: center;
  color: var(--ink-soft);
}
.empty h1 { font-family: var(--serif); font-weight: 400; font-size: 28px; }

/* ---- panels ---- */

.panel {
  padding: 14px 16px;
  border-bottom: 1px solid var(--rule);
}
.panel.muted { opacity: .65; }
.panel h3 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 600;
}
.hint { font-size: 12.5px; color: var(--ink-faint); margin: 6px 0 0; line-height: 1.5; }
.row { display: flex; gap: 6px; margin: 6px 0 0; flex-wrap: wrap; }
.check { margin: 0 0 4px; font-size: 12.5px; color: var(--ink-soft); }
.check label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.btn {
  display: inline-block;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-soft);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--sans);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }

.stats { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin: 0; font-size: 13px; }
.stats dt { color: var(--ink-faint); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.snaps, .versions { list-style: none; margin: 10px 0 0; padding: 0; font-size: 12.5px; }
.snaps li, .versions li {
  padding: 6px 0;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.snaps li button, .versions li button {
  border: 0; background: none; color: var(--accent);
  cursor: pointer; font-size: 12px; padding: 0; white-space: nowrap;
}
.versions li p {
  margin: 0;
  color: var(--ink-soft);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-family: var(--serif);
}
.v-body { min-width: 0; }
.v-when {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.scan-out { font-size: 12.5px; margin-top: 8px; color: var(--ink-soft); line-height: 1.6; }
.qlist { list-style: none; margin: 8px 0 0; padding: 0; font-size: 12px; }
.qlist li {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 2px 0; border-top: 1px solid var(--rule);
}
.qlist li span { color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.scan-out .clean { color: #3e6b46; }
.scan-out .dirty { color: var(--warn); }
.scan-out code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11.5px; }

/* ---- view toolbar ---- */

.viewbar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  opacity: .35;
  transition: opacity .15s;
}
.doc-head:hover .viewbar, .viewbar:focus-within { opacity: 1; }

.vb {
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--sans);
  line-height: 1.4;
}
.vb:hover { border-color: var(--accent); color: var(--accent); }
.vb.on { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.vb-label { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }
.vb-sep { width: 1px; height: 14px; background: var(--rule); margin: 0 6px; }

/* Width presets, applied to <body> and read by the editor and title. */
/* First-line indent. Presentation only: no tab or space is ever stored in
   the text, which keeps word counts, exports and the sanitiser honest. */
body.ind-none   { --indent: 0; }
body.ind-small  { --indent: 1.2em; }
body.ind-medium { --indent: 2em; }
body.ind-large  { --indent: 3em; }

/* Line spacing. "double" is the manuscript submission standard rather
   than a literal 2x, which reads as a gap at this measure. */
body.lead-single { --editor-lead: 1.45; }
body.lead-half   { --editor-lead: 1.75; }
body.lead-double { --editor-lead: 2.15; }

body.w-narrow { --measure: 32rem; }
body.w-medium { --measure: 40rem; }
body.w-wide   { --measure: 50rem; }

/* ---- assist panel ---- */

/* Sits directly under the document stats: it is the reason the tool
   exists, so it should not be below three panels of housekeeping. */
.panel.assist { background: #fff; }

.assist-scope {
  font-size: 11.5px;
  color: var(--ink-faint);
  margin-bottom: 8px;
  min-height: 15px;
  line-height: 1.4;
}
.assist-scope strong { color: var(--accent); font-weight: 600; }

.modes { display: flex; flex-wrap: wrap; gap: 5px; }
.modes .mode { flex: 1 1 auto; padding: 6px 8px; }
.modes .mode.busy { opacity: .5; pointer-events: none; }

.assist-free { display: flex; gap: 5px; margin-top: 8px; align-items: flex-start; }
.assist-free textarea {
  flex: 1; resize: vertical; min-height: 34px;
  border: 1px solid var(--rule); border-radius: 4px;
  padding: 6px 8px; font-family: var(--sans); font-size: 12.5px;
  background: var(--paper); color: var(--ink);
}
.assist-free textarea:focus { outline: 0; border-color: var(--accent); }

.assist-meta { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.assist-meta select {
  flex: 1; min-width: 0; font-size: 12px; padding: 4px 6px;
  border: 1px solid var(--rule); border-radius: 4px;
  background: var(--paper); color: var(--ink-soft); font-family: var(--sans);
}
.assist-meta .hint { margin: 0; white-space: nowrap; font-variant-numeric: tabular-nums; }

.assist-out { margin-top: 10px; }
.assist-out .waiting { font-size: 12.5px; color: var(--ink-faint); }

.sugg {
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 9px 10px;
  margin-bottom: 7px;
  background: var(--paper);
}
.sugg .lab {
  font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-faint); display: flex; justify-content: space-between; gap: 6px;
}
.sugg .body {
  font-family: var(--serif); font-size: 13.5px; line-height: 1.55;
  color: var(--ink); margin: 5px 0 0; white-space: pre-wrap;
}
.sugg .body em { font-style: italic; }
.sugg .acts { display: flex; gap: 5px; margin-top: 7px; }
.sugg .acts .btn { padding: 3px 8px; font-size: 11.5px; }
.sugg.bad .body { color: var(--warn); font-family: var(--sans); font-size: 12.5px; }
.sugg .flag { color: var(--warn); font-size: 10.5px; }

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

.toast {
  position: fixed;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 9px 16px;
  border-radius: 5px;
  font-size: 13px;
  z-index: 20;
}
.toast.warn { background: var(--warn); }

/* ---- narrow screens ---- */

@media (max-width: 1100px) {
  .shell { grid-template-columns: 190px minmax(0,1fr) 250px; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; height: auto; }
  .rail { border: 0; border-bottom: 1px solid var(--rule); max-height: 40vh; }
  .editor-wrap { padding: 24px 18px 40vh; }
}
