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

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --border: #e5e7eb;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --max-width: 800px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ===== Header ===== */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

header nav {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.logo:hover {
  text-decoration: none;
  color: var(--primary);
}

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

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  padding: 0.5rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn:hover {
  text-decoration: none;
  background: var(--bg);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

/* ===== Post List ===== */
.post-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease;
}

.post-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.post-card h2 {
  font-size: 1.3rem;
  margin-bottom: 0.3rem;
}

.post-card h2 a {
  color: var(--text);
}

.post-card h2 a:hover {
  color: var(--primary);
  text-decoration: none;
}

.post-card time {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.post-card .excerpt {
  margin-top: 0.6rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.read-more {
  display: inline-block;
  margin-top: 0.8rem;
  font-size: 0.9rem;
  font-weight: 500;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
}

.empty-state h2 {
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* ===== Single Post ===== */
.post-full .post-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}

.post-full .post-meta .edited {
  font-style: italic;
}

.post-full h1 {
  font-size: 2rem;
  margin-bottom: 1.5rem;
  line-height: 1.3;
}

.post-actions {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.inline-form {
  display: inline;
}

/* ===== Markdown Body ===== */
.markdown-body {
  font-size: 1rem;
  line-height: 1.8;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin-top: 1.8rem;
  margin-bottom: 0.6rem;
  line-height: 1.3;
}

.markdown-body h1 { font-size: 1.8rem; }
.markdown-body h2 { font-size: 1.5rem; }
.markdown-body h3 { font-size: 1.25rem; }

.markdown-body p {
  margin-bottom: 1rem;
}

.markdown-body ul,
.markdown-body ol {
  margin-bottom: 1rem;
  padding-left: 1.8rem;
}

.markdown-body li {
  margin-bottom: 0.3rem;
}

.markdown-body blockquote {
  border-left: 4px solid var(--primary);
  padding: 0.5rem 1rem;
  margin: 1rem 0;
  background: #f0f4ff;
  color: var(--text-muted);
}

.markdown-body code {
  font-family: var(--font-mono);
  background: #f1f5f9;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.88em;
}

.markdown-body pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 1rem 1.2rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1rem 0;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.markdown-body img {
  max-width: 100%;
  border-radius: var(--radius);
  margin: 1rem 0;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.markdown-body th {
  background: var(--bg);
  font-weight: 600;
}

/* ===== Editor ===== */
.editor-page h1 {
  margin-bottom: 1.5rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.label-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.form-group input[type="text"] {
  width: 100%;
  padding: 0.65rem 0.9rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-sans);
  transition: border-color 0.15s ease;
}

.form-group input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* Editor toolbar */
.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}

.editor-toolbar button {
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  min-width: 32px;
  text-align: center;
  transition: all 0.1s ease;
}

.editor-toolbar button:hover {
  background: var(--border);
}

.editor-toolbar button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.toolbar-sep {
  width: 1px;
  background: var(--border);
  margin: 0 4px;
}

/* Editor split pane */
.editor-split {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}

.editor-split textarea {
  flex: 1;
  width: 100%;
  padding: 1rem;
  font-size: 0.95rem;
  font-family: var(--font-mono);
  line-height: 1.6;
  border: none;
  resize: vertical;
  min-height: 400px;
  background: var(--surface);
}

.editor-split textarea:focus {
  outline: none;
}

.editor-split textarea.half {
  width: 50%;
  flex: none;
  border-right: 1px solid var(--border);
}

.preview-pane {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  background: var(--surface);
  max-height: 500px;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  main {
    padding: 1.5rem 1rem;
  }

  .post-full h1 {
    font-size: 1.5rem;
  }

  .editor-split {
    flex-direction: column;
  }

  .editor-split textarea.half {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
