:root {
  --fg: #1a1a1a;
  --bg: #fafafa;
  --border: #ddd;
  --link: #0066cc;
  --muted: #888;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg);
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border); */
  position: sticky;
  top: 0;
  max-width: 760px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  height: 56px;
  background: var(--bg);
  z-index: 10;
}

.site-name { text-decoration: none; color: var(--fg); font-weight: 600; }

nav { display: flex; gap: 0.75rem; align-items: center; }

nav a,
nav button {
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  text-decoration: none;
  font-family: inherit;
  padding: 0;
}
nav a:hover, nav button:hover { color: var(--fg); }

/* ── Buttons ── */
.btn {
  padding: 0.35rem 0.85rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.875rem;
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
}
.btn-primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* ── Main content ── */
main { max-width: 760px; margin: 0 auto; padding: 2rem 1.5rem; }

h1.page-title { font-size: 1.75rem; margin-bottom: 1.5rem; font-weight: 700; }


.placeholder {
  color: var(--muted);
  cursor: pointer;
  padding: 2.5rem;
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: 4px;
}
.placeholder:hover { border-color: var(--muted); }

#page-edit { display: flex; flex-direction: column; gap: 0.75rem; }

#edit-title {
  font-size: 1.75rem;
  font-weight: 700;
  border: none;
  border-bottom: 2px solid var(--border);
  background: transparent;
  padding: 0.25rem 0;
  width: 100%;
  outline: none;
  font-family: inherit;
  color: var(--fg);
}
#edit-title:focus { border-color: var(--fg); }

#edit-body {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.75rem;
  width: 100%;
  min-height: 300px;
  resize: vertical;
  outline: none;
  line-height: 1.5;
}
#edit-body:focus { border-color: var(--fg); }

/* ── Seamless plaintext editing ── */
.seamless-title {
  all: unset;
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  width: 100%;
  color: var(--fg);
  font-family: inherit;
  margin-bottom: 1.5rem;
  cursor: text;
}

.seamless-body {
  all: unset;
  display: block;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  width: 100%;
  min-height: 60vh;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: text;
  color: var(--fg);
  overflow: hidden;
}

/* ── Dirty state indicator ── */
.dirty-indicator {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── No-JS notice (inside <noscript>) ── */
.noscript-notice {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 1.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* ── Tiptap WYSIWYG editor (markdown mode) ── */
.tiptap-editor {
  border: none;
  padding: 0;
  min-height: 300px;
  cursor: text;
}
.tiptap-editor .tiptap {
  outline: none;
  min-height: 280px;
}
.tiptap-editor .tiptap h1 { font-size: 1.5rem; margin: 1.5rem 0 0.5rem; }
.tiptap-editor .tiptap h2 { font-size: 1.25rem; margin: 1.25rem 0 0.5rem; }
.tiptap-editor .tiptap h3 { font-size: 1.1rem; margin: 1rem 0 0.25rem; }
.tiptap-editor .tiptap p { margin-bottom: 1rem; }
.tiptap-editor .tiptap p:last-child { margin-bottom: 0; }
.tiptap-editor .tiptap ul,
.tiptap-editor .tiptap ol { margin-bottom: 1rem; padding-left: 1.5rem; }
.tiptap-editor .tiptap li { margin-bottom: 0.25rem; }
.tiptap-editor .tiptap code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.85em;
  background: #f0f0f0;
  padding: 0.1em 0.3em;
  border-radius: 3px;
}
.tiptap-editor .tiptap pre {
  background: #f0f0f0;
  padding: 1rem;
  border-radius: 4px;
  overflow-x: auto;
  margin-bottom: 1rem;
}
.tiptap-editor .tiptap pre code { background: none; padding: 0; }
.tiptap-editor .tiptap blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  color: var(--muted);
  margin-bottom: 1rem;
}
.tiptap-editor .tiptap a { color: var(--link); }
.tiptap-editor .tiptap strong { font-weight: 700; }
.tiptap-editor .tiptap em { font-style: italic; }

/* ── Markdown rendered output ── */
.view-content h1 { font-size: 1.5rem; margin: 1.5rem 0 0.5rem; }
.view-content h2 { font-size: 1.25rem; margin: 1.25rem 0 0.5rem; }
.view-content h3 { font-size: 1.1rem; margin: 1rem 0 0.25rem; }
.view-content p { margin-bottom: 1rem; }
.view-content ul, .view-content ol { margin-bottom: 1rem; padding-left: 1.5rem; }
.view-content li { margin-bottom: 0.25rem; }
.view-content code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.85em;
  background: #f0f0f0;
  padding: 0.1em 0.3em;
  border-radius: 3px;
}
.view-content pre {
  background: #f0f0f0;
  padding: 1rem;
  border-radius: 4px;
  overflow-x: auto;
  margin-bottom: 1rem;
  white-space: pre-wrap;
}
.view-content pre code { background: none; padding: 0; }
.view-content a { color: var(--link); }
.view-content blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  color: var(--muted);
  margin-bottom: 1rem;
}
.view-content table { border-collapse: collapse; margin-bottom: 1rem; width: 100%; }
.view-content th, .view-content td { border: 1px solid var(--border); padding: 0.4rem 0.75rem; }
.view-content th { background: #f0f0f0; }

/* ── Media (image / video / audio / file) ── */
img, .media-image { max-width: 100%; border-radius: 4px; display: block; }
.media-video { max-width: 100%; border-radius: 4px; display: block; }
.media-audio { width: 100%; }
.media-file::before { content: "📎 "; }

.media-image:hover, .media-audio:hover, .media-video:hover, .media-audio:hover {
  border: 1px dashed grey;
}

/* ── Link tooltip ── */
.link-tooltip {
  position: fixed;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
  font-size: 0.8125rem;
}
.link-tooltip-url {
  color: var(--link);
  text-decoration: none;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-tooltip-url:hover { text-decoration: underline; }
.link-tooltip-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.8125rem;
  font-family: inherit;
  padding: 0;
  flex-shrink: 0;
}
.link-tooltip-btn:hover { color: var(--fg); }
.link-tooltip-inputs { display: flex; flex-direction: column; gap: 0.3rem; }
.link-tooltip-input {
  width: 240px;
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 0.8125rem;
  font-family: inherit;
  outline: none;
  background: var(--bg);
  color: var(--fg);
}
.link-tooltip-input:focus { border-color: var(--fg); }

/* ── Forms (setup, login) ── */
.form-wrap { max-width: 400px; margin: 3rem auto; }
.form-wrap h1 { font-size: 1.5rem; margin-bottom: 1.5rem; }

.fg { margin-bottom: 1rem; }
.fg label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.35rem; }
.fg input, .fg select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  background: var(--bg);
  color: var(--fg);
}
.fg input:focus, .fg select:focus { border-color: var(--fg); }
.fg-hint { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }

.err {
  color: #c00;
  font-size: 0.875rem;
  margin-bottom: 1rem;
  padding: 0.5rem;
  border: 1px solid #f5c6cb;
  background: #fff5f5;
  border-radius: 4px;
}

/* ── History ── */
.sect-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.versions { list-style: none; }
.versions li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  gap: 1rem;
}
.versions li:last-child { border-bottom: none; }
.version-time { color: var(--muted); flex-shrink: 0; }
.version-ct { color: var(--muted); }


/* ── Footer ── */
footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.875rem;
  color: var(--muted);
}
footer a { color: var(--muted); text-decoration: none; }
footer a:hover { text-decoration: underline; }