/* Light is the default. Dark applies when the system asks for it and the
   user has not picked light, or when the user picks dark. */
:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #efefea;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --border: #e2e2dc;
  --accent: #2459d6;
  --accent-fg: #ffffff;
  --focus: #2459d655;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --bad: #c2362f;
  --notice-bg: #fff6dc;
  --notice-fg: #6b4e0b;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141413;
    --surface: #1c1c1a;
  --surface-2: #2a2a27;
    --fg: #e8e8e3;
    --muted: #9a9a93;
    --border: #2f2f2c;
    --accent: #6d95ff;
    --accent-fg: #0d1220;
    --focus: #6d95ff55;
    --ok: #4cc27f;
    --warn: #e0b04f;
    --bad: #ef6f67;
    --notice-bg: #3a3016;
    --notice-fg: #f2dda3;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413;
  --surface: #1c1c1a;
  --surface-2: #2a2a27;
  --fg: #e8e8e3;
  --muted: #9a9a93;
  --border: #2f2f2c;
  --accent: #6d95ff;
  --accent-fg: #0d1220;
  --focus: #6d95ff55;
  --ok: #4cc27f;
  --warn: #e0b04f;
  --bad: #ef6f67;
  --notice-bg: #3a3016;
  --notice-fg: #f2dda3;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font);
  display: flex;
  flex-direction: column;
}

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

/* Header bar */
.bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { font-weight: 650; color: var(--fg); text-decoration: none; }
.spacer { flex: 1; }
.pad-name {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.meta { font-size: 13px; color: var(--muted); }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.status[data-state="online"] .dot { background: var(--ok); }
.status[data-state="slow"] .dot { background: var(--warn); }
.status[data-state="bad"] .dot,
.status[data-state="offline"] .dot,
.status[data-state="full"] .dot { background: var(--bad); }
.status { font-variant-numeric: tabular-nums; }

.badge {
  font-size: 12px;
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
}

/* Buttons and inputs */
.btn {
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--fg); border-color: var(--border); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input {
  font: inherit;
  font-family: var(--mono);
  font-size: 15px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg);
  min-width: 0;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }

/* Home page */
.home { width: 100%; max-width: 640px; margin: 0 auto; padding: 48px 16px; }
.home h1 { font-size: 28px; margin: 0 0 8px; letter-spacing: -0.01em; }
.lead { margin: 0 0 32px; color: var(--muted); }
.open-form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.error { color: var(--bad); margin: 8px 0 0; font-size: 14px; }
.notes { margin: 32px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.notes li + li { margin-top: 6px; }

/* Pad page */
.notice {
  padding: 8px 16px;
  background: var(--notice-bg);
  color: var(--notice-fg);
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

/* Editor area: [gutter | textarea] and the Markdown preview, side by side */
.editor-wrap { flex: 1; display: flex; min-height: 0; }
.editor-pane { flex: 1; display: flex; min-width: 0; }
.editor-box { flex: 1; display: flex; min-width: 0; position: relative; }
.editor-wrap[data-view="edit"] .preview { display: none; }
.editor-wrap[data-view="preview"] .editor-pane { display: none; }
.editor-wrap[data-view="split"] .preview { border-left: 1px solid var(--border); }

#editor {
  flex: 1;
  width: 100%;
  margin: 0;
  padding: 16px;
  border: 0;
  resize: none;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.6 var(--mono);
  tab-size: 4;
}
#editor[wrap="off"] { white-space: pre; overflow-x: auto; }
#editor:focus { outline: none; }
#editor[readonly] { color: var(--muted); }

.gutter {
  position: relative;
  flex: none;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font: 14px/1.6 var(--mono);
  user-select: none;
}
.gutter[hidden] { display: none; }
.gutter > div { position: absolute; right: 10px; opacity: 0.7; }

/* Other writers' carets and selections, drawn by cursors.js */
.cursors { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.remote-caret {
  position: absolute;
  width: 2px;
  margin-left: -1px;
  background: var(--c);
  border-radius: 1px;
}
.remote-sel { position: absolute; background: var(--c); }

/* Header: one dot per writer, in the color of their caret */
.editors { display: inline-flex; gap: 4px; }
.editor-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.editor-dot.me { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--c); margin-right: 4px; }

/* Markdown preview */
.preview {
  flex: 1;
  min-width: 0;
  overflow: auto;
  padding: 16px 24px 48px;
  font-size: 15px;
  line-height: 1.6;
  overflow-wrap: break-word;
}
.preview.empty::before { content: "Nothing to preview yet."; color: var(--muted); }
.preview > :first-child { margin-top: 0; }
.preview h1, .preview h2, .preview h3, .preview h4 { line-height: 1.25; margin: 1.4em 0 0.5em; }
.preview h1 { font-size: 1.8em; }
.preview h2 { font-size: 1.4em; padding-bottom: 0.2em; border-bottom: 1px solid var(--border); }
.preview h3 { font-size: 1.15em; }
.preview p, .preview ul, .preview ol, .preview blockquote, .preview pre, .preview table { margin: 0 0 1em; }
.preview code {
  font: 0.9em var(--mono);
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.preview pre { background: var(--surface-2); padding: 12px 14px; border-radius: 6px; overflow: auto; }
.preview pre code { background: none; padding: 0; }
.preview blockquote { margin-left: 0; padding-left: 14px; border-left: 3px solid var(--border); color: var(--muted); }
.preview table { border-collapse: collapse; display: block; overflow: auto; }
.preview th, .preview td { border: 1px solid var(--border); padding: 6px 10px; }
.preview th { background: var(--surface-2); }
.preview img { max-width: 100%; }
.preview hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }

/* Shared files, above the editor */
.files {
  max-height: 30vh;
  overflow: auto;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
}
.files[hidden] { display: none; }
.file { display: flex; align-items: center; gap: 10px; padding: 3px 0; min-width: 0; }
.file .editor-dot { flex: none; }
.file-name { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.file-status { color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.file .btn { flex: none; text-decoration: none; }

/* Shown while files are dragged over the page */
.drop {
  position: fixed;
  inset: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  color: var(--accent);
  font-size: 18px;
  font-weight: 600;
  pointer-events: none;
}
.drop[hidden] { display: none; }

/* Bottom bar */
.bar.bottom {
  border-bottom: 0;
  border-top: 1px solid var(--border);
  padding: 6px 16px;
  font-size: 13px;
}
.btn.small { font-size: 13px; padding: 3px 10px; }
.btn[aria-pressed="true"] { color: var(--fg); background: var(--surface-2); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button {
  font: inherit;
  font-size: 13px;
  padding: 3px 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--fg); }

.meter { display: inline-flex; align-items: center; gap: 6px; color: var(--warn); }
.meter[hidden] { display: none; }
.meter[data-level="bad"] { color: var(--bad); }
.meter-track { width: 80px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter-fill { display: block; height: 100%; background: currentColor; }

@media (max-width: 700px) {
  .editor-wrap[data-view="split"] { flex-direction: column; }
  .editor-wrap[data-view="split"] .preview { border-left: 0; border-top: 1px solid var(--border); }
}

@media (max-width: 560px) {
  .pad-name { order: 10; flex-basis: 100%; }
  .home { padding-top: 32px; }
}
