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

:root {
  --font-head: 'Cal Sans', 'Noto Sans', sans-serif;
  --font-body: 'Noto Sans', sans-serif;
  --font-mono: 'Space Mono', monospace;
  --black: #111;
  --gray-1: #333;
  --gray-2: #666;
  --gray-3: #999;
  --gray-4: #ccc;
  --gray-5: #eee;
  --white: #fff;
  --accent: #111;
  --radius: 6px;
}

html, body {
  height: 100%;
  font-family: var(--font-body);
  color: var(--black);
  background: var(--white);
  font-size: 16px;
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea { font-family: inherit; }

/* ── NAV ── */
nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--white);
  border-bottom: 1px solid var(--gray-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
}

.nav-logo {
  font-family: var(--font-head);
  font-size: 1.4rem;
  letter-spacing: -0.5px;
  color: var(--black);
}

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

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  border: 1.5px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-primary {
  background: var(--black);
  color: var(--white);
  border-color: var(--black);
}
.btn-primary:hover { background: var(--gray-1); border-color: var(--gray-1); }
.btn-ghost {
  background: transparent;
  color: var(--black);
  border-color: var(--gray-4);
}
.btn-ghost:hover { background: var(--gray-5); }
.btn-danger {
  background: transparent;
  color: #c00;
  border-color: #fcc;
}
.btn-danger:hover { background: #fff0f0; }

/* ── LAYOUT ── */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ── FEED ── */
.feed-header {
  padding: 2.5rem 0 1.5rem;
  border-bottom: 1px solid var(--gray-5);
  margin-bottom: 2rem;
}
.feed-header h1 {
  font-family: var(--font-head);
  font-size: 2rem;
}
.feed-header p { color: var(--gray-2); margin-top: 0.25rem; }

.feed-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--gray-5);
}
.feed-tab {
  padding: 0.6rem 1.2rem;
  font-size: 0.875rem;
  font-weight: 600;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--gray-2);
  margin-bottom: -1px;
}
.feed-tab.active {
  color: var(--black);
  border-bottom-color: var(--black);
}

.post-card {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--gray-5);
  cursor: pointer;
  transition: opacity 0.15s;
}
.post-card:hover { opacity: 0.75; }
.post-card-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
  color: var(--gray-2);
}
.post-card-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gray-4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--gray-1);
  flex-shrink: 0;
}
.post-card h2 {
  font-family: var(--font-head);
  font-size: 1.2rem;
  margin-bottom: 0.35rem;
}
.post-card p {
  color: var(--gray-2);
  font-size: 0.9rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-card-footer {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--gray-3);
}
.post-card-tag {
  background: var(--gray-5);
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  font-size: 0.75rem;
  color: var(--gray-1);
}

.empty-state {
  text-align: center;
  padding: 4rem 0;
  color: var(--gray-3);
}
.empty-state h3 { font-family: var(--font-head); font-size: 1.2rem; margin-bottom: 0.5rem; color: var(--gray-2); }

/* ── POST VIEW ── */
.post-view { padding: 2.5rem 0 4rem; }
.post-view-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--gray-2);
  margin-bottom: 2rem;
  background: none;
  border: none;
  padding: 0;
  font-weight: 600;
}
.post-view-back:hover { color: var(--black); }
.post-view-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--gray-2);
}
.post-view-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--gray-4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--gray-1);
}
.post-view h1 {
  font-family: var(--font-head);
  font-size: 2.2rem;
  line-height: 1.2;
  margin-bottom: 1.5rem;
}
.post-view-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--gray-5);
}

.post-body { font-size: 1.05rem; line-height: 1.75; }
.post-body h1,.post-body h2,.post-body h3 { font-family: var(--font-head); margin: 1.5rem 0 0.5rem; }
.post-body p { margin-bottom: 1rem; }
.post-body code { font-family: var(--font-mono); background: var(--gray-5); padding: 0.15em 0.4em; border-radius: 3px; font-size: 0.875em; }
.post-body pre { background: var(--gray-5); padding: 1rem; border-radius: var(--radius); overflow-x: auto; margin-bottom: 1rem; }
.post-body pre code { background: none; padding: 0; }
.post-body blockquote { border-left: 3px solid var(--gray-4); padding-left: 1rem; color: var(--gray-2); margin-bottom: 1rem; font-style: italic; }
.post-body ul, .post-body ol { padding-left: 1.5rem; margin-bottom: 1rem; }
.post-body li { margin-bottom: 0.25rem; }
.post-body a { text-decoration: underline; }
.post-body img { max-width: 100%; border-radius: var(--radius); }

/* ── COMMENTS ── */
.comments-section { margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--gray-5); }
.comments-section h3 { font-family: var(--font-head); font-size: 1.1rem; margin-bottom: 1.5rem; }
.comment-form { margin-bottom: 2rem; display: flex; flex-direction: column; gap: 0.75rem; }
.comment-form textarea {
  width: 100%; padding: 0.75rem; border: 1.5px solid var(--gray-4);
  border-radius: var(--radius); resize: vertical; font-size: 0.9rem;
  min-height: 80px; outline: none;
}
.comment-form textarea:focus { border-color: var(--black); }
.comment {
  padding: 1rem 0;
  border-bottom: 1px solid var(--gray-5);
}
.comment-meta { font-size: 0.8rem; color: var(--gray-2); margin-bottom: 0.4rem; display: flex; gap: 0.5rem; align-items: center; }
.comment p { font-size: 0.9rem; }

/* ── EDITOR ── */
.editor-page { padding: 2rem 0 4rem; }
.editor-page h2 { font-family: var(--font-head); font-size: 1.5rem; margin-bottom: 1.5rem; }
.editor-form { display: flex; flex-direction: column; gap: 1rem; }
.editor-form input[type="text"],
.editor-form input[type="email"],
.editor-form input[type="password"],
.editor-form select {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--gray-4);
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
}
.editor-form input:focus,
.editor-form select:focus { border-color: var(--black); }
.editor-form .title-input {
  font-family: var(--font-head);
  font-size: 1.5rem;
  border: none;
  border-bottom: 2px solid var(--gray-5);
  border-radius: 0;
  padding: 0.5rem 0;
}
.editor-form .title-input:focus { border-bottom-color: var(--black); }
.editor-form .title-input::placeholder { color: var(--gray-3); }

.editor-toolbar {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem;
  background: var(--gray-5);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1.5px solid var(--gray-4);
  border-bottom: none;
  flex-wrap: wrap;
}
.editor-toolbar button {
  padding: 0.3rem 0.6rem;
  background: none;
  border: none;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  color: var(--gray-1);
}
.editor-toolbar button:hover { background: var(--gray-4); }
.editor-toolbar .sep { width: 1px; background: var(--gray-4); margin: 0.2rem; }

.editor-textarea {
  width: 100%;
  min-height: 340px;
  padding: 1rem;
  border: 1.5px solid var(--gray-4);
  border-radius: 0 0 var(--radius) var(--radius);
  resize: vertical;
  font-size: 0.95rem;
  line-height: 1.7;
  outline: none;
  font-family: var(--font-mono);
}
.editor-textarea:focus { border-color: var(--black); }

.editor-row { display: flex; gap: 1rem; }
.editor-row > * { flex: 1; }

.editor-preview { 
  border: 1.5px solid var(--gray-4); 
  border-radius: var(--radius); 
  padding: 1rem 1.25rem; 
  background: var(--gray-5);
  font-size: 0.9rem;
}
.editor-preview-label { font-size: 0.75rem; color: var(--gray-3); font-family: var(--font-mono); margin-bottom: 0.5rem; }

.editor-actions { display: flex; gap: 0.75rem; justify-content: flex-end; }

/* ── AUTH MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--white);
  border-radius: 10px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  margin: 1rem;
  box-shadow: 0 8px 40px rgba(0,0,0,0.12);
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal h2 { font-family: var(--font-head); font-size: 1.4rem; margin-bottom: 0.25rem; }
.modal p { font-size: 0.85rem; color: var(--gray-2); margin-bottom: 1.5rem; }
.modal-form { display: flex; flex-direction: column; gap: 0.75rem; }
.modal-form input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--gray-4);
  border-radius: var(--radius);
  font-size: 0.95rem;
  outline: none;
}
.modal-form input:focus { border-color: var(--black); }
.modal-switch { margin-top: 1rem; text-align: center; font-size: 0.85rem; color: var(--gray-2); }
.modal-switch button { background: none; border: none; font-weight: 700; color: var(--black); font-size: 0.85rem; }
.modal-error { color: #c00; font-size: 0.82rem; }

/* ── PROFILE ── */
.profile-header {
  padding: 2.5rem 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  border-bottom: 1px solid var(--gray-5);
  margin-bottom: 2rem;
}
.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--black);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--white);
  flex-shrink: 0;
}
.profile-info h2 { font-family: var(--font-head); font-size: 1.5rem; }
.profile-info p { color: var(--gray-2); font-size: 0.875rem; }

/* ── TOAST ── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: var(--black);
  color: var(--white);
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  animation: slideUp 0.2s ease;
  pointer-events: none;
}
.toast.error { background: #c00; }

/* ── TAG FILTER ── */
.tags-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.tag-btn {
  padding: 0.25rem 0.65rem;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--gray-5);
  border: 1.5px solid transparent;
  color: var(--gray-1);
}
.tag-btn.active { background: var(--black); color: var(--white); }
.tag-btn:hover:not(.active) { border-color: var(--gray-3); }

/* ── LIKES ── */
.like-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: 1.5px solid var(--gray-4);
  border-radius: 99px;
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
  color: var(--gray-2);
  font-family: var(--font-body);
}
.like-btn:hover { border-color: var(--gray-3); color: var(--black); }
.like-btn.liked { border-color: var(--black); color: var(--black); font-weight: 600; }

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  nav { padding: 0 1rem; }
  .container { padding: 0 1rem; }
  .post-view h1 { font-size: 1.6rem; }
  .editor-row { flex-direction: column; }
  .feed-header h1 { font-size: 1.5rem; }
}