:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --text: #1b1b1f;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #0f766e;
  --accent-soft: #e6f4f2;
  --amber: #b45309;
  --amber-soft: #fdf0e2;
  --danger: #b91c1c;
  --radius: 10px;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Malgun Gothic', sans-serif;
}

[data-theme='dark'] {
  --bg: #0f1115;
  --surface: #171a21;
  --text: #e7e9ee;
  --muted: #9aa1ac;
  --border: #2a2e37;
  --accent: #2dd4bf;
  --accent-soft: #10312d;
  --amber: #f59e0b;
  --amber-soft: #3a2a10;
  --danger: #f87171;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.2s ease, color 0.2s ease;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ---------------- Header ---------------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 32px 20px;
  background: var(--surface);
  transition: background 0.2s ease;
}

.brand {
  font-weight: 800;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Small icon-only or icon+label buttons (search toggle, image insert, etc.) */
.icon-btn {
  border: none;
  background: none;
  font-size: 1.05rem;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
}

.icon-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

/* Sliding theme toggle */
.theme-toggle {
  position: relative;
  width: 44px;
  height: 25px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--border);
  cursor: pointer;
  padding: 2px;
  flex-shrink: 0;
}

.theme-toggle-thumb {
  display: block;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transform: translateX(0);
  transition: transform 0.2s ease;
}

[data-theme='dark'] .theme-toggle {
  background: var(--accent);
  border-color: var(--accent);
}

[data-theme='dark'] .theme-toggle-thumb {
  transform: translateX(19px);
}

/* ---------------- Search popup ---------------- */

.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  z-index: 100;
}

.search-overlay[hidden] {
  display: none;
}

.search-modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 560px;
  max-width: 92vw;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
}

.search-modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.search-modal-header .search-icon {
  opacity: 0.5;
  font-size: 0.9rem;
}

.search-modal-header #search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 0.98rem;
  font-family: inherit;
  background: transparent;
  color: var(--text);
  padding: 4px 0;
}

.search-results {
  overflow-y: auto;
  padding: 8px;
}

.search-result-item {
  display: block;
  padding: 12px 14px;
  border-radius: 8px;
}

.search-result-item:hover {
  background: var(--accent-soft);
}

.search-result-title {
  font-weight: 700;
  font-size: 0.92rem;
  margin-bottom: 2px;
}

.search-result-meta {
  font-size: 0.76rem;
  color: var(--muted);
}

.search-empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

/* ---------------- Password modal ---------------- */

.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.auth-modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  width: 320px;
  max-width: 90vw;
  position: relative;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
}

.auth-close {
  position: absolute;
  top: 12px;
  right: 14px;
  border: none;
  background: none;
  font-size: 1.2rem;
  color: var(--muted);
  cursor: pointer;
}

.auth-title {
  font-size: 1.1rem;
  font-weight: 800;
  margin: 0 0 6px;
}

.auth-message {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 16px;
}

.auth-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.auth-input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  width: 100%;
}

.auth-input:focus {
  border-color: var(--accent);
}

.auth-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin: 0 0 10px;
}

.auth-submit {
  width: 100%;
}

.auth-link {
  display: block;
  width: 100%;
  text-align: center;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 12px;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
}

.auth-link:hover {
  color: var(--accent);
}

.btn-primary, .btn-ghost, .btn-danger {
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

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

.btn-primary:hover {
  background: #0c5f58;
}

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border: 1px solid #f3d0d0;
}

.btn-danger:hover {
  background: #fdf1f1;
}

/* ---------------- Category tabs ---------------- */

.category-tabs {
  display: flex;
  gap: 28px;
  padding: 0 32px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tab {
  border: none;
  background: none;
  color: var(--muted);
  padding: 0 2px 14px;
  margin-bottom: -1px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab:hover {
  color: var(--accent);
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* ---------------- Post grid / cards ---------------- */

.post-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  padding: 24px 32px 64px;
}

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.post-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.category-badge {
  align-self: flex-start;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--accent);
}

.category-badge[data-category='삽질'] {
  color: var(--amber);
}

.category-badge[data-category='공부'] {
  color: #2563eb;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.card-excerpt {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--muted);
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-chip {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}

.card-dates {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  white-space: nowrap;
  font-family: 'JetBrains Mono', 'Pretendard', monospace;
}

.card-date {
  white-space: nowrap;
  font-family: 'JetBrains Mono', 'Pretendard', monospace;
}

.card-updated {
  font-size: 0.72rem;
  opacity: 0.85;
}

.post-dates {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 80px 20px;
}

/* ---------------- Post detail ---------------- */

.post-detail {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 24px 96px;
}

.post-detail-meta {
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 10px;
  margin-top: 12px;
}

.post-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.post-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

.post-actions[hidden] {
  display: none;
}

.post-heading h1 {
  font-size: 1.9rem;
  letter-spacing: -0.02em;
  margin: 14px 0 8px;
}

.post-detail-category {
  display: inline-flex;
}

.markdown-body {
  margin-top: 32px;
  font-size: 1.02rem;
}

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

.markdown-body pre {
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
}

.markdown-body code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9em;
}

.markdown-body p code {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
}

.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 0;
  padding: 4px 16px;
  color: var(--muted);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
}

/* ---------------- Write form ---------------- */

.write-form {
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 24px 96px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.write-heading {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 20px 0 6px;
}

#title-input {
  font-size: 1.05rem;
  font-weight: 700;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: var(--surface);
  font-family: inherit;
  letter-spacing: -0.01em;
  padding: 13px 16px;
}

#title-input:focus {
  border-color: var(--accent);
}

.write-meta {
  display: flex;
  gap: 10px;
}

#category-select,
#tags-input {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
}

#category-select {
  font-weight: 600;
  color: var(--accent);
  min-width: 150px;
}

#tags-input {
  flex: 1;
}

#category-select:focus,
#tags-input:focus {
  border-color: var(--accent);
}

.editor-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

.editor-toolbar .icon-btn {
  font-size: 0.85rem;
  font-weight: 600;
}

.editor-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.editor-pane {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.pane-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

#content-input,
#preview-pane {
  min-height: 50vh;
  border: none;
  padding: 18px;
  font-size: 0.92rem;
  flex: 1;
}

#content-input {
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.7;
  resize: vertical;
  outline: none;
  tab-size: 2;
  background: var(--surface);
  color: var(--text);
}

#preview-pane {
  overflow-y: auto;
  margin-top: 0;
}

.md-dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 22px;
  color: var(--muted);
  font-size: 0.88rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.md-dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone-btn {
  pointer-events: none;
  padding: 7px 16px;
  font-size: 0.82rem;
}

/* ---------------- Responsive ---------------- */

@media (max-width: 640px) {
  .site-header {
    padding: 16px 18px;
  }

  .category-tabs,
  .post-grid {
    padding-left: 18px;
    padding-right: 18px;
  }

  .post-detail,
  .write-form {
    padding-left: 18px;
    padding-right: 18px;
  }

  .editor-split {
    grid-template-columns: 1fr;
  }
}
