@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700;800&display=swap');

/* ===== THE COMPILED ARCHIVE — Design Tokens ===== */
:root {
  /* Surface Hierarchy (Parchment Stack) */
  --surface: #fff9ea;
  --surface-container-low: #faf3e1;
  --surface-container: #f4edd6;
  --surface-container-high: #eee7cc;
  --surface-container-highest: #e8e2d0;
  --surface-lowest: #ffffff;

  /* Ink */
  --on-surface: #0a0a0a;
  --on-surface-variant: #685d4b;
  --on-surface-ghost: #9e9484;

  /* Structural */
  --outline-variant: #c4c7c7;

  /* Primary (Lithographic Ink) */
  --primary: #0a0a0a;
  --primary-container: #212121;

  /* Secondary */
  --secondary: #685d4b;
  --secondary-container: #eeddc6;

  /* Status */
  --error: #ba1a1a;
  --error-container: #ffdad6;

  /* Font */
  --font: 'Space Grotesk', system-ui, -apple-system, sans-serif;

  /* Layout */
  --layout-width: 680px;
}

/* ===== RESET ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background-color: var(--surface);
  color: var(--on-surface);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* Archival Grid */
  background-image: radial-gradient(circle, rgba(104, 93, 75, 0.2) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: -16px -16px;
}

::selection {
  background-color: rgba(10, 10, 10, 0.12);
  color: var(--on-surface);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--surface-container-highest); }
::-webkit-scrollbar-thumb:hover { background: var(--on-surface-ghost); }

/* ===== HEADER ===== */
header {
  width: 100%;
  max-width: var(--layout-width);
  margin: 0 auto;
  padding: 4rem 1.5rem 2rem;
}

header nav { margin-bottom: 2rem; }

header nav a {
  display: inline-flex;
  align-items: center;
  color: var(--on-surface-variant);
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: color 0.15s ease;
}

header nav a:hover { color: var(--on-surface); }

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--on-surface);
  margin-bottom: 0.4rem;
  line-height: 1.2;
}

header h1::before {
  content: '# ';
  color: var(--on-surface-variant);
  font-weight: 400;
}

header p {
  color: var(--on-surface-variant);
  font-size: 0.9rem;
  line-height: 1.5;
}

header p::before {
  content: '> ';
  color: var(--on-surface-ghost);
  font-size: 0.85rem;
}

/* ===== MAIN ===== */
main {
  width: 100%;
  max-width: var(--layout-width);
  margin: 0 auto;
  padding: 0 1.5rem 6rem;
  flex: 1;
}

/* ===== POST CARDS (Homepage) ===== */
.post-card {
  display: block;
  padding: 1.75rem 0;
  text-decoration: none;
  background-color: var(--surface);
  transition: background-color 0.15s ease;
}

/* Tonal separation — no borders */
.post-card + .post-card {
  border-top: none;
  background: linear-gradient(180deg, var(--surface-container-low) 0%, var(--surface) 16px);
  padding-top: 2rem;
}

.post-card:hover {
  background-color: var(--surface-container-low);
  padding-left: 1.5rem;
  padding-right: 1.5rem;
  margin: 0 -1.5rem;
}

.post-card .meta {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--on-surface-ghost);
  margin-bottom: 0.5rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.post-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--on-surface);
  margin-bottom: 0.4rem;
  line-height: 1.3;
}

.post-card h2::before {
  content: '## ';
  color: var(--on-surface-ghost);
  font-weight: 400;
  font-size: 1rem;
}

.post-card h2 a {
  color: inherit;
  text-decoration: none;
}

.post-card h2 a:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-color: var(--on-surface-variant);
}

.post-card .excerpt {
  color: var(--on-surface-variant);
  font-size: 0.9rem;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.post-card .read-link {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--on-surface);
  text-decoration: none;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.post-card .read-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ===== SINGLE POST ===== */
.metadata-gutter {
  display: flex;
  gap: 2rem;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
}

.metadata-gutter .gutter-item {
  display: flex;
  flex-direction: column;
}

.metadata-gutter .gutter-label {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--on-surface-ghost);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.15rem;
}

.metadata-gutter .gutter-value {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

main > h1 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.post-author {
  font-size: 0.8rem;
  color: var(--on-surface-variant);
  margin-bottom: 0.25rem;
}

.post-author strong {
  color: var(--on-surface);
  font-weight: 600;
}

main > .meta {
  font-size: 0.75rem;
  color: var(--on-surface-ghost);
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  letter-spacing: 0.02em;
}

/* ===== CONTENT (Markdown) ===== */
.content {
  font-size: 1rem;
  color: var(--on-surface);
  line-height: 1.75;
}

.content p { margin-bottom: 1.5rem; }

.content h2, .content h3, .content h4 {
  color: var(--on-surface);
  font-weight: 700;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  line-height: 1.35;
}

.content h2 { font-size: 1.35rem; }
.content h3 { font-size: 1.15rem; }
.content h4 { font-size: 1rem; }

.content h2::before { content: '## '; color: var(--on-surface-ghost); font-weight: 400; }
.content h3::before { content: '### '; color: var(--on-surface-ghost); font-weight: 400; }
.content h4::before { content: '#### '; color: var(--on-surface-ghost); font-weight: 400; }

.content a {
  color: var(--on-surface);
  text-decoration: underline;
  text-decoration-color: var(--on-surface-ghost);
  text-underline-offset: 4px;
  transition: all 0.2s ease;
}

.content a:hover {
  background-color: var(--on-surface);
  color: var(--surface);
  text-decoration: none;
  padding: 0 2px;
}

.content ul, .content ol {
  margin-bottom: 1.5rem;
  padding-left: 1.25rem;
}

.content li { margin-bottom: 0.5rem; }
.content li::marker { color: var(--on-surface-ghost); }

.content blockquote {
  border-left: 3px solid var(--on-surface-variant);
  padding-left: 1.25rem;
  margin: 1.5rem 0;
  color: var(--on-surface-variant);
  font-style: italic;
}

.content pre {
  background: var(--surface-container-low) !important;
  padding: 1.25rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-size: 0.88rem;
  line-height: 1.55;
}

.content code {
  background: var(--surface-container-low);
  padding: 0.15rem 0.35rem;
  font-size: 0.85em;
  color: var(--on-surface);
}

.content pre code {
  background: transparent;
  padding: 0;
  font-size: 1em;
}

.content img {
  max-width: 100%;
  height: auto;
  margin: 2rem 0;
}

.content hr {
  border: 0;
  height: 4px;
  background: var(--surface-container-low);
  margin: 3rem 0;
}

/* ===== BUTTONS ===== */
button, .btn-primary {
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-container) 100%);
  color: var(--surface);
  border: none;
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: opacity 0.2s ease;
}

button:hover, .btn-primary:hover { opacity: 0.85; }

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(196, 199, 199, 0.4);
  color: var(--on-surface-variant);
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s ease;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.btn-ghost:hover {
  border-color: var(--on-surface-variant);
  color: var(--on-surface);
}

.btn-ghost.active {
  border-color: var(--on-surface);
  color: var(--on-surface);
  background: var(--surface-container-low);
}

.btn-danger {
  background: var(--error);
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: opacity 0.2s ease;
}

.btn-danger:hover { opacity: 0.85; }

.btn-arrow {
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-container) 100%);
  color: var(--surface);
  border: none;
  padding: 0.8rem 1.5rem;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: opacity 0.2s ease;
}

.btn-arrow:hover { opacity: 0.85; }
.btn-arrow::after { content: ' →'; }

/* ===== FORM INPUTS ===== */
label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--on-surface-ghost);
  margin-bottom: 0.25rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

input[type="text"], input[type="password"], textarea {
  width: 100%;
  padding: 0.8rem 0;
  margin-bottom: 1.25rem;
  border: none;
  border-bottom: 1px solid rgba(196, 199, 199, 0.4);
  font-family: var(--font);
  font-size: 0.95rem;
  background-color: transparent;
  color: var(--on-surface);
  transition: border-color 0.2s ease;
}

textarea {
  min-height: 250px;
  resize: vertical;
  padding: 0.8rem 0;
}

input:focus, textarea:focus {
  outline: none;
  border-bottom-color: var(--primary);
  border-bottom-width: 2px;
}

input::placeholder, textarea::placeholder {
  color: var(--on-surface-ghost);
}

/* ===== ERROR BANNER ===== */
.error {
  color: var(--error);
  background: var(--error-container);
  padding: 0.85rem 1rem;
  margin-bottom: 1.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.error::before {
  content: 'AUTHENTICATION_ERROR — ';
  font-weight: 700;
}

/* ===== ADMIN NAV ===== */
.admin-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.admin-nav h1 {
  font-size: 1rem;
  font-weight: 700;
}

.admin-nav h1::before { content: none; }

.admin-nav a {
  color: var(--on-surface-variant);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  transition: color 0.15s ease;
}

.admin-nav a:hover { color: var(--on-surface); }

/* ===== DASHBOARD ===== */
.dashboard-title {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.25rem;
}

.dashboard-title::before { content: none; }

.dashboard-subtitle {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--on-surface-ghost);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 2rem;
}

.stats-row {
  display: flex;
  gap: 2rem;
  margin-bottom: 2.5rem;
  background: var(--surface-container-low);
  padding: 1.5rem;
}

.stat-box { flex: 1; }

.stat-label {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--on-surface-ghost);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--on-surface);
  letter-spacing: -0.02em;
}

/* ===== SECTION HEADERS ===== */
.section-heading {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--on-surface);
  margin-bottom: 1rem;
}

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 1rem;
}

.section-link {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--on-surface-ghost);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
}

.section-link:hover { color: var(--on-surface-variant); }

/* ===== COMMENT CARD (Dashboard) ===== */
.admin-comment-card {
  padding: 1.25rem 0;
  background-color: var(--surface);
}

.admin-comment-card + .admin-comment-card {
  background: linear-gradient(180deg, var(--surface-container-low) 0%, var(--surface) 8px);
  padding-top: 1.5rem;
}

.admin-comment-card .commenter-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--on-surface);
}

.admin-comment-card .commenter-context {
  font-size: 0.65rem;
  color: var(--on-surface-ghost);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

.admin-comment-card .comment-quote {
  color: var(--on-surface-variant);
  font-size: 0.9rem;
  font-style: italic;
  line-height: 1.5;
  margin-bottom: 0.75rem;
}

.admin-comment-card .comment-quote::before { content: '"'; }
.admin-comment-card .comment-quote::after { content: '"'; }

/* ===== ADMIN POST ROW ===== */
.admin-post-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  background-color: var(--surface);
}

.admin-post-row + .admin-post-row {
  background: linear-gradient(180deg, var(--surface-container-low) 0%, var(--surface) 4px);
  padding-top: 1.25rem;
}

.admin-post-row h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.admin-post-row h3 a {
  color: var(--on-surface);
  text-decoration: none;
}

.admin-post-row h3 a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.admin-post-row .meta {
  font-size: 0.7rem;
  color: var(--on-surface-ghost);
  margin-top: 0.25rem;
  letter-spacing: 0.02em;
}

.admin-post-row .edit-link {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--on-surface-ghost);
  text-decoration: none;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.admin-post-row .edit-link:hover { color: var(--on-surface); }

/* Badges */
.badge {
  font-size: 0.55rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-block;
}

.badge-published {
  background: var(--on-surface);
  color: var(--surface);
}

.badge-draft {
  background: transparent;
  color: var(--on-surface-ghost);
  border: 1px solid rgba(196, 199, 199, 0.4);
}

/* ===== DIVIDER (Tonal) ===== */
.divider {
  border: 0;
  height: 4px;
  background: var(--surface-container-low);
  margin: 2.5rem 0;
}

/* ===== COMMENT SECTION (Post Page) ===== */
.comment-card {
  padding: 1.25rem 0;
  background-color: var(--surface);
}

.comment-card + .comment-card {
  background: linear-gradient(180deg, var(--surface-container-low) 0%, var(--surface) 4px);
  padding-top: 1.5rem;
}

.comment-card .comment-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.comment-card .comment-author {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--on-surface);
}

.comment-card .comment-time {
  font-size: 0.65rem;
  color: var(--on-surface-ghost);
  letter-spacing: 0.02em;
}

.comment-card .comment-body {
  margin: 0;
  color: var(--on-surface-variant);
  line-height: 1.55;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

/* ===== LOGIN ===== */
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 2.5rem;
  background: var(--surface-container-low);
}

.login-card h2 {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.5rem;
}

.login-card h2::before { content: none; }

.login-subtitle {
  font-size: 0.6rem;
  color: var(--on-surface-ghost);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 2rem;
}

/* ===== PUBLISH TOGGLE ===== */
.publish-toggle {
  background: var(--surface-container-low);
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
}

.publish-toggle label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.85rem;
  text-transform: none;
  color: var(--on-surface-variant);
  letter-spacing: 0;
}

.publish-toggle input[type="checkbox"] {
  width: auto;
  margin: 0;
  accent-color: var(--on-surface);
}

/* ===== EMPTY STATE ===== */
.empty-state {
  color: var(--on-surface-ghost);
  font-size: 0.85rem;
  padding: 2rem 0;
  font-style: italic;
}

/* ===== FOOTER ===== */
.site-footer {
  text-align: center;
  padding: 2rem 1.5rem 3rem;
  font-size: 0.65rem;
  color: var(--on-surface-ghost);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  max-width: var(--layout-width);
  margin: 0 auto;
  width: 100%;
}

.site-footer a {
  color: var(--on-surface-ghost);
  text-decoration: underline;
  text-underline-offset: 3px;
  margin: 0 0.5rem;
  transition: color 0.15s ease;
}

.site-footer a:hover { color: var(--on-surface); }
