/* Serif @font-face rules live in fonts.css; the active family is applied via
   the --serif variable, which base.html overrides per the admin's choice. */
:root {
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --faint: #eaeaea;
  --bg: #fdfdfc;
  --accent: #1a5fb4;
  --danger: #b4291a;
  --serif: "Noto Serif", Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --width: 42rem;
}

* { box-sizing: border-box; }

html { font-size: 18px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: var(--width);
  margin: 0 auto;
  padding: 6rem 1.25rem 4rem;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header / footer */
.site-header {
  max-width: var(--width);
  margin: 0 auto;
  padding: 1.75rem 1.25rem 1rem;
  position: relative;
  text-align: center;
}
.site-title {
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.site-header nav { position: absolute; right: 1.25rem; top: 1.75rem; font-family: var(--sans); font-size: 0.85rem; }
.site-header nav a { color: var(--muted); margin-left: 1rem; }

/* Home post list */
.post-list { list-style: none; padding: 0; margin: 1.5rem 0 0; }
.post-item { margin-bottom: 1.75rem; }
.post-link { font-size: 1.25rem; font-weight: 600; color: var(--ink); }
.post-date {
  display: block;
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.15rem;
}
.post-summary { margin: 0.4rem 0 0; color: #333; }
.empty { color: var(--muted); font-style: italic; }

/* Article / prose */
.post-header { margin-bottom: 1.5rem; }
.prose h1 { font-size: 1.9rem; line-height: 1.2; margin: 0 0 0.3rem; letter-spacing: -0.01em; }
.prose h2 { font-size: 1.4rem; margin-top: 2rem; }
.prose h3 { font-size: 1.15rem; margin-top: 1.5rem; }
.prose p { margin: 1rem 0; }
.prose img { max-width: 100%; height: auto; }
.prose blockquote {
  margin: 1.2rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--faint);
  color: var(--muted);
}
.prose code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: #f4f4f2;
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.prose pre {
  background: #f4f4f2;
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.85rem;
}
.prose pre code { background: none; padding: 0; font-size: inherit; }
.prose table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
.prose th, .prose td { border: 1px solid var(--faint); padding: 0.4rem 0.6rem; text-align: left; }
.prose hr { border: none; border-top: 1px solid var(--faint); margin: 2rem 0; }

.draft-badge {
  font-family: var(--sans);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 3px;
  padding: 0.05rem 0.35rem;
  vertical-align: middle;
}
.edit-link { font-family: var(--sans); font-size: 0.8rem; margin-top: 2.5rem; }

.message { text-align: center; padding: 3rem 0; }
.message h1 { font-size: 2rem; }

/* Forms (shared) */
input[type=text], input[type=password], input[type=date], textarea {
  font-family: var(--sans);
  font-size: 0.95rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 5px;
  background: #fff;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
button, .btn {
  font-family: var(--sans);
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:hover, .btn:hover { background: #174f96; text-decoration: none; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-size: inherit;
  cursor: pointer;
}
.link-btn:hover { background: none; text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.inline { display: inline; }
.notice { background: #fff8e6; border: 1px solid #f0d98a; padding: 0.6rem 0.8rem; border-radius: 5px; font-family: var(--sans); font-size: 0.85rem; }
.error { color: var(--danger); font-family: var(--sans); font-size: 0.9rem; }

/* Login */
.auth-form { max-width: 20rem; margin: 3rem auto; font-family: var(--sans); }
.auth-form h1 { font-family: var(--serif); }
.auth-form input, .auth-form button { margin-top: 0.75rem; }
.auth-form button { width: 100%; }

/* Admin dashboard */
.admin { font-family: var(--sans); }
.admin-head { display: flex; align-items: baseline; justify-content: space-between; }
.admin h1 { font-family: var(--serif); }
.admin section { margin-top: 2rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--faint); padding-bottom: 0.4rem; }
.section-head h2 { font-family: var(--serif); margin: 0; font-size: 1.2rem; }
.doc-list { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.doc-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #f3f3f1;
  font-size: 0.9rem;
}
.doc-title { font-weight: 600; color: var(--ink); }
.doc-date { color: var(--muted); font-size: 0.8rem; }
.doc-actions { margin-left: auto; display: flex; gap: 0.8rem; font-size: 0.8rem; }

/* Editor */
/* The editor needs room for the side-by-side write/preview split, so it gets a
   much wider container than the narrow reading width used elsewhere. */
main:has(.editor) { max-width: min(80rem, 95vw); }
.editor { font-family: var(--serif); }
.editor-fields, .editor-tools, .editor-actions, .upload-form { font-family: var(--sans); }
.editor-fields { display: flex; flex-wrap: wrap; gap: 1rem; align-items: end; margin-bottom: 1rem; }
.editor-fields label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.8rem; color: var(--muted); flex: 1 1 8rem; }
.editor-fields .field-title { flex: 3 1 16rem; }
.editor-fields .check { flex-direction: row; align-items: center; gap: 0.4rem; flex: 0 0 auto; }
.editor-fields .check input { width: auto; }
.editor label.full { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.8rem; color: var(--muted); margin-bottom: 1rem; }
.editor-split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; min-height: 60vh; }
.editor-split textarea {
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.65;
  resize: vertical;
  min-height: 60vh;
}
.preview {
  border: 1px solid var(--faint);
  border-radius: 5px;
  padding: 0.5rem 1rem;
  overflow-y: auto;
  min-height: 60vh;
  background: #fff;
}
/* Resizable images in the preview. */
.preview .imgwrap { position: relative; display: inline-block; line-height: 0; max-width: 100%; }
.preview .imgwrap img { display: block; max-width: 100%; height: auto; }
.preview .imghandle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity 0.1s;
}
.preview .imgwrap:hover .imghandle { opacity: 1; }
.preview .imgsize {
  position: absolute;
  right: 0;
  bottom: 20px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-family: var(--sans);
  font-size: 0.7rem;
  line-height: 1.4;
  padding: 1px 5px;
  border-radius: 3px;
  pointer-events: none;
}

.editor-actions { margin-top: 1rem; display: flex; gap: 1rem; align-items: center; }
.editor-actions .cancel { color: var(--muted); }
.editor-actions .visit-link { margin-left: auto; font-family: var(--sans); font-size: 0.85rem; }

.editor-tools { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.6rem; }
.btn-sm {
  font-family: var(--sans);
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--faint);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.btn-sm:hover { background: #f5f5f3; text-decoration: none; }
.hint { color: var(--muted); font-family: var(--sans); font-size: 0.8rem; margin: 0.3rem 0 0; }

@media (max-width: 38rem) {
  .editor-split { grid-template-columns: 1fr; }
  .editor-split .preview { display: none; }
}

/* Media gallery */
.upload-form { display: flex; gap: 0.75rem; align-items: center; margin: 1rem 0 1.5rem; font-family: var(--sans); font-size: 0.85rem; }
.favicon-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; font-family: var(--sans); font-size: 0.85rem; }
.favicon-row .upload-form { margin: 0; }
.favicon-label { display: flex; flex-direction: column; gap: 0.25rem; color: var(--muted); }
.favicon-preview { width: 32px; height: 32px; object-fit: contain; border: 1px solid var(--faint); border-radius: 4px; background: #fff; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 1rem; }
.gallery-item { margin: 0; border: 1px solid var(--faint); border-radius: 6px; overflow: hidden; background: #fff; }
.gallery-item > a { display: block; }
.gallery-item img { display: block; width: 100%; height: 8.5rem; object-fit: cover; background: #f5f5f3; }
.gallery-item figcaption { padding: 0.5rem; font-family: var(--sans); }
.gallery-md { width: 100%; font-family: var(--mono); font-size: 0.7rem; padding: 0.25rem 0.35rem; border: 1px solid var(--faint); border-radius: 4px; }
.gallery-meta { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-top: 0.4rem; font-size: 0.75rem; }
.gallery-name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-link { font-family: var(--sans); font-size: 0.85rem; color: var(--muted); }
