:root {
  --bg: #fbfaf7;
  --paper: #ffffff;
  --ink: #1d2320;
  --muted: #66706b;
  --line: #e3e1da;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --hl: #fff1a8;
  --hl-active: #ffd84d;
  --ins-bg: #dff3e4;
  --ins-ink: #1c6b3a;
  --del-bg: #fbe1df;
  --del-ink: #9b2c24;
  --ian: #2f5f9b;
  --claude: #9a5b1f;
  --warn-bg: #fff4d6;
  --warn-line: #e9c46a;
  --sug: #1c6b3a;
  --sug-ink: #ffffff;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --side-w: min(380px, 92vw);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161917;
    --paper: #1d211f;
    --ink: #e6e8e4;
    --muted: #9aa39e;
    --line: #333a36;
    --accent: #6fbf93;
    --accent-ink: #0f1311;
    --hl: #5c5217;
    --hl-active: #8a7a1a;
    --ins-bg: #1e3b28;
    --ins-ink: #8fdcaa;
    --del-bg: #43211f;
    --del-ink: #f0a39c;
    --ian: #8db4ea;
    --claude: #e6b27a;
    --warn-bg: #3a3218;
    --warn-line: #8a7426;
    --sug: #8fdcaa;
    --sug-ink: #0f1311;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: var(--font); font-size: 16px; line-height: 1.85; }
button, input, textarea { font: inherit; color: inherit; }

/* Top bar, and the formatting bar under it */
.top { position: sticky; top: 0; z-index: 20; }
.bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--paper); border-bottom: 1px solid var(--line);
}
.fmt {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 4px 16px; background: var(--paper); border-bottom: 1px solid var(--line);
}
.fmt .group { display: inline-flex; gap: 2px; padding-right: 8px; border-right: 1px solid var(--line); }
.fmt .group:last-of-type { border-right: 0; }
.fmt .spacer { flex: 1; }
.fbtn {
  min-width: 30px; height: 26px; padding: 0 7px; border: 1px solid transparent; border-radius: 5px;
  background: transparent; color: var(--ink); font-size: 13px; line-height: 1; cursor: pointer; white-space: nowrap;
}
.fbtn:hover { background: var(--bg); border-color: var(--line); }
.fbtn.on {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent);
}
.mode { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.mode button {
  border: 0; background: var(--paper); color: var(--muted); padding: 3px 11px;
  font-size: 13px; line-height: 1.6; cursor: pointer; white-space: nowrap;
}
.mode button + button { border-left: 1px solid var(--line); }
.mode button.on[data-mode="edit"] { background: var(--accent); color: var(--accent-ink); }
.mode button.on[data-mode="suggest"] { background: var(--sug); color: var(--sug-ink); }
.bar .path { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.bar .status { font-size: 12px; color: var(--muted); }
.bar .spacer { flex: 1; }
.btn {
  border: 1px solid var(--line); background: var(--paper); border-radius: 6px;
  padding: 3px 10px; font-size: 13px; line-height: 1.6; cursor: pointer; text-decoration: none; color: var(--ink);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 1px 8px; font-size: 12px; }

.banner {
  padding: 10px 16px; background: var(--warn-bg); border-bottom: 1px solid var(--warn-line);
  font-size: 14px; display: flex; gap: 12px; align-items: flex-start;
}
.banner .grow { flex: 1; }

/* Document */
.wrap { position: relative; padding: 24px 16px 120px; }
.doc {
  max-width: 800px; margin: 0 auto; background: var(--paper);
  border: 1px solid var(--line); border-radius: 10px; padding: 32px 48px 48px;
}
@media (max-width: 700px) { .doc { padding: 20px 18px 32px; } }
.doc h1 { font-size: 1.6em; line-height: 1.4; margin: 0.6em 0 0.5em; }
.doc h2 { font-size: 1.3em; line-height: 1.45; margin: 1.6em 0 0.5em; padding-bottom: 0.2em; border-bottom: 1px solid var(--line); }
.doc h3 { font-size: 1.1em; line-height: 1.5; margin: 1.4em 0 0.4em; }
.doc h4, .doc h5, .doc h6 { font-size: 1em; margin: 1.2em 0 0.3em; }
.doc p { margin: 0.6em 0; }
.doc p.fine { font-size: 0.78em; line-height: 1.6; color: var(--muted); }
.doc ul, .doc ol { margin: 0.4em 0; padding-left: 1.6em; }
.doc li { margin: 0.35em 0; }
.doc li > .blk + .blk { margin-top: 0.4em; }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.doc a { color: var(--accent); overflow-wrap: anywhere; }
.doc code { font-family: var(--mono); font-size: 0.88em; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; overflow-wrap: anywhere; }
.doc pre { font-family: var(--mono); font-size: 13px; line-height: 1.6; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; overflow-x: auto; }
.doc pre code { border: 0; padding: 0; background: none; }
.doc blockquote { margin: 0.8em 0; padding: 0 0 0 14px; border-left: 3px solid var(--line); color: var(--muted); }
.doc table { border-collapse: collapse; margin: 0.8em 0; font-size: 14px; display: block; overflow-x: auto; }
.doc th, .doc td { border: 1px solid var(--line); padding: 4px 10px; vertical-align: top; text-align: left; }
.doc th { background: var(--bg); }

/* Editing in place */
.doc[contenteditable="true"] { outline: none; caret-color: var(--accent); }
body.suggesting .doc { border-color: var(--sug); box-shadow: 0 0 0 1px var(--sug); caret-color: var(--sug); }
.blk { position: relative; border-radius: 4px; }
.blk:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }
/* A new empty line, not in the file until something is typed on it */
.doc .phantom { min-height: 1.85em; }
.doc .phantom::before {
  content: attr(data-hint); position: absolute; left: 0; top: 0;
  color: var(--muted); opacity: 0.55; pointer-events: none; font-weight: normal;
}
.doc .phantom-li.plain { list-style: none; }
.copy-box { position: fixed; left: -10000px; top: 0; white-space: pre-wrap; }

/* The 💬 in the left margin, beside whichever part the pointer is over */
.gutter { position: absolute; z-index: 5; user-select: none; -webkit-user-select: none; }
.gutter button {
  width: 28px; height: 24px; border: 1px solid var(--line); background: var(--paper);
  border-radius: 5px; font-size: 12px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0;
}
.gutter button:hover { color: var(--accent); border-color: var(--accent); }

/* Critic markup */
mark.cm-hl { background: var(--hl); color: inherit; border-radius: 2px; cursor: pointer; }
mark.cm-hl.active, mark.cm-hl.flash { background: var(--hl-active); }
ins.cm-ins { background: var(--ins-bg); color: var(--ins-ink); text-decoration: none; border-bottom: 1px solid var(--ins-ink); }
del.cm-del { background: var(--del-bg); color: var(--del-ink); }
.cm-sug.flash ins, .cm-sug.flash del { outline: 2px solid var(--hl-active); }
.badge {
  display: inline-flex; align-items: center; gap: 2px; margin: 0 2px; padding: 0 6px;
  font-size: 11px; line-height: 1.6; border-radius: 9px; vertical-align: 2px; cursor: pointer;
  background: var(--ian); color: #fff; user-select: none; -webkit-user-select: none;
}
.badge.claude { background: var(--claude); }
.badge.flash { outline: 2px solid var(--hl-active); }
.sug-actions { display: inline-flex; gap: 2px; margin-left: 2px; vertical-align: 1px; user-select: none; -webkit-user-select: none; }
.sug-actions button {
  border: 1px solid var(--line); background: var(--paper); border-radius: 4px; font-size: 11px;
  line-height: 1.5; padding: 0 5px; cursor: pointer;
}
.sug-actions .ok:hover { border-color: var(--ins-ink); color: var(--ins-ink); }
.sug-actions .no:hover { border-color: var(--del-ink); color: var(--del-ink); }

/* Source: the whole file as text */
.editor { margin: 0.4em 0; }
.editor textarea {
  width: 100%; min-height: 6em; resize: vertical; padding: 10px 12px; line-height: 1.7; font-size: 14px;
  font-family: var(--mono); border: 1px solid var(--accent); border-radius: 6px; background: var(--paper);
}
.editor .row { display: flex; gap: 8px; margin-top: 6px; align-items: center; }
.editor .hint { font-size: 12px; color: var(--muted); }
.source-editor textarea { min-height: 70vh; }

/* Sidebar */
.side {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--side-w); z-index: 30;
  background: var(--paper); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.side-body { overflow-y: auto; padding: 10px 12px 60px; }
.side-empty { color: var(--muted); font-size: 14px; padding: 8px 4px; }
.side-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.side-bar .ghost { margin-left: auto; color: var(--muted); }
.card .when { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; font-size: 14px; line-height: 1.7; }
.card.flash { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.card .quote { color: var(--muted); font-size: 13px; border-left: 3px solid var(--hl-active); padding-left: 8px; margin-bottom: 6px; cursor: pointer; }
.card .quote.sug { border-left-color: var(--ins-ink); }
.card .c { margin: 4px 0; }
.card .who { font-weight: 600; margin-right: 4px; }
.card .who.ian { color: var(--ian); }
.card .who.claude { color: var(--claude); }
.card .state { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card .acts { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.card textarea { width: 100%; min-height: 4em; margin-top: 6px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); font-size: 14px; }
.card del { background: var(--del-bg); color: var(--del-ink); }
.card ins { background: var(--ins-bg); color: var(--ins-ink); text-decoration: none; }

/* Popover for new comments */
.pop {
  position: absolute; z-index: 40; background: var(--paper); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); padding: 8px; width: min(340px, 90vw); font-size: 14px;
}
.pop.button-only { width: auto; padding: 4px; }
.pop textarea { width: 100%; min-height: 5em; padding: 6px 8px; border: 1px solid var(--accent); border-radius: 6px; background: var(--paper); }
.pop .row { display: flex; gap: 8px; margin-top: 6px; align-items: center; }
.pop .hint { font-size: 12px; color: var(--muted); }
.pop .quote { color: var(--muted); font-size: 13px; border-left: 3px solid var(--hl-active); padding-left: 8px; margin-bottom: 6px; max-height: 4.5em; overflow: hidden; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 6px 14px; border-radius: 16px; font-size: 13px; box-shadow: var(--shadow);
}

/* File list */
.files h1 { font-size: 1.3em; margin-top: 0; }
.files .filter { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.files .filter input[type=search] { flex: 1; min-width: 200px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }
.files ul { list-style: none; padding: 0; margin: 0; }
.files li { display: flex; gap: 12px; justify-content: space-between; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.files li a { color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.files li a:hover { color: var(--accent); }
.files li time { color: var(--muted); white-space: nowrap; font-size: 12px; }
.files .note { font-size: 12px; color: var(--muted); }
.error { color: var(--del-ink); }

/* Cloud: someone who may suggest and comment, but not edit the file in Drive */
body.limited .sug-actions, body.limited #mode [data-mode="edit"] { display: none; }
