:root {
  --bg: #FFFFFF;
  --bg-sub: #F7F7F8;
  --text: #1F2328;
  --muted: #8A8F98;
  --line: #E5E7EB;
  --accent: #3B6FE0;
  --accent-soft: #EEF3FD;
  --danger: #D64545;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 35, 40, .04);
  --shadow-lift: 0 14px 32px -12px rgba(31, 35, 40, .18);
  --font: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  --serif: "Noto Serif KR", "Nanum Myeongjo", Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img, video, iframe { max-width: 100%; height: auto; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 24px; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 64px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 19px; letter-spacing: -.02em; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--text); color: #fff; font-size: 15px;
}
.header-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-chip { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 999px;
  border: 1px solid transparent; font-size: 14px; font-weight: 600;
  transition: background .2s, color .2s, border-color .2s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--text); color: #fff; }
.btn-primary:hover { background: #000; }
.btn-primary:disabled { opacity: .55; cursor: progress; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg-sub); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #bd3535; }
.btn-danger:disabled { opacity: .55; }
.btn-block { width: 100%; height: 44px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-size: 14px; }
.link-btn:hover { text-decoration: underline; }

/* Views */
.page { padding-top: 8px; padding-bottom: 80px; min-height: 70vh; }
.view { display: none; }
.view.is-active { display: block; animation: fadeUp .35s ease both; }

/* Hero */
.hero { padding: 56px 0 28px; text-align: center; }
.hero h1 { margin: 0; font-size: clamp(28px, 5vw, 40px); font-weight: 800; letter-spacing: -.03em; line-height: 1.25; }
.hero-sub { margin: 12px 0 28px; color: var(--muted); font-size: 17px; }
.search { position: relative; max-width: 560px; margin: 0 auto; }
.search input {
  width: 100%; height: 52px; padding: 0 48px 0 50px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg-sub);
  font-size: 16px; transition: border-color .2s, background .2s, box-shadow .2s;
}
.search input:focus { outline: none; background: #fff; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.search input::-webkit-search-cancel-button { display: none; }
.search-icon { position: absolute; left: 18px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search-clear {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 22px; line-height: 1;
  display: none;
}
.search-clear.is-visible { display: block; }
.search-clear:hover { background: var(--line); color: var(--text); }

.tag-filter { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 22px; }
.chip {
  height: 34px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  font-size: 14px; transition: all .2s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 48px; align-items: start; }
.content { min-width: 0; }
.result-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 18px; min-height: 24px; }
.result-info { margin: 0; color: var(--muted); font-size: 14px; }
.result-info strong { color: var(--text); font-weight: 600; }
#resetFilters { display: none; }
#resetFilters.is-visible { display: inline; }

/* Cards */
.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 24px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; color: var(--text); box-shadow: var(--shadow);
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
  animation: cardIn .4s ease both;
  min-width: 0;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lift); border-color: transparent; }
.card-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.card-cat { color: var(--text); font-weight: 600; }
.dot { width: 3px; height: 3px; border-radius: 50%; background: var(--muted); }
.card-title { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.4; letter-spacing: -.02em; word-break: keep-all; overflow-wrap: anywhere; }
.card-summary {
  margin: 0; color: #4B5058; font-size: 15px; line-height: 1.7;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.card-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; margin-top: auto; padding-top: 6px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 500; }
button.tag { border: 0; }
button.tag:hover { background: var(--accent); color: #fff; }
.views { color: var(--muted); font-size: 12px; white-space: nowrap; }

.skeleton { height: 220px; border-radius: var(--radius); background: linear-gradient(90deg, var(--bg-sub) 25%, #EFEFF1 37%, var(--bg-sub) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }

.empty { display: none; padding: 64px 20px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--bg-sub); }
.empty.is-visible { display: block; animation: fadeUp .3s ease both; }
.empty-title { margin: 0 0 6px; font-weight: 700; }
.empty-sub { margin: 0; color: var(--muted); font-size: 14px; }
.empty .btn { margin-top: 16px; }

/* Sidebar */
.sidebar { position: sticky; top: 88px; display: flex; flex-direction: column; gap: 28px; min-width: 0; }
.side-block { padding: 22px; border-radius: var(--radius); background: var(--bg-sub); }
.side-title { margin: 0 0 14px; font-size: 13px; font-weight: 700; letter-spacing: .04em; color: var(--muted); }
.popular-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.popular-list a { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 8px; color: var(--text); }
.popular-list a:hover .pop-title { color: var(--accent); }
.pop-rank { font-size: 20px; font-weight: 800; color: var(--line); line-height: 1.2; }
.popular-list li:first-child .pop-rank { color: var(--accent); }
.pop-title { display: block; font-size: 14px; font-weight: 600; line-height: 1.45; transition: color .2s; overflow-wrap: anywhere; }
.pop-views { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.category-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.cat-btn {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  padding: 9px 12px; border: 0; border-radius: 10px; background: transparent;
  color: var(--text); font-size: 15px; text-align: left; transition: background .2s, color .2s;
}
.cat-btn:hover { background: #fff; }
.cat-btn.is-active { background: #fff; color: var(--accent); font-weight: 600; box-shadow: var(--shadow); }
.cat-count { color: var(--muted); font-size: 13px; }
.side-empty { color: var(--muted); font-size: 14px; margin: 0; }

/* Article */
.article { min-width: 0; max-width: 720px; padding-top: 40px; }
.back-link { display: inline-block; color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.back-link:hover { color: var(--text); }
.article-cat { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; font-size: 14px; }
.article-cat:hover { text-decoration: underline; }
.article h1 { margin: 10px 0 16px; font-size: clamp(28px, 5vw, 40px); line-height: 1.3; letter-spacing: -.03em; word-break: keep-all; overflow-wrap: anywhere; }
.article-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.article-summary { margin: 28px 0 0; font-size: 19px; color: #4B5058; line-height: 1.75; }
.prose { margin-top: 28px; font-family: var(--serif); font-size: 18px; line-height: 1.95; color: var(--text); overflow-wrap: anywhere; }
.prose p { margin: 0 0 1.4em; }
.prose h2, .prose h3 { font-family: var(--font); letter-spacing: -.02em; line-height: 1.4; margin: 2em 0 .7em; }
.prose h2 { font-size: 24px; }
.prose h3 { font-size: 20px; }
.prose ul, .prose ol { padding-left: 1.3em; margin: 0 0 1.4em; }
.prose li { margin: .35em 0; }
.prose blockquote { margin: 0 0 1.4em; padding: 4px 0 4px 20px; border-left: 3px solid var(--text); color: #4B5058; font-style: italic; }
.prose code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; background: var(--bg-sub); padding: 2px 6px; border-radius: 6px; }
.prose pre { margin: 0 0 1.4em; padding: 18px 20px; border-radius: 12px; background: var(--bg-sub); border: 1px solid var(--line); overflow-x: auto; line-height: 1.6; }
.prose pre code { background: none; padding: 0; font-size: 14px; }
.prose a { text-decoration: underline; text-underline-offset: 3px; }
.article-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--line); }
.article-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 32px; flex-wrap: wrap; }
.article-state { padding: 80px 0; text-align: center; color: var(--muted); }

/* Write */
.write-wrap { max-width: 760px; margin: 0 auto; padding-top: 40px; }
.write-title { margin: 0 0 28px; font-size: 32px; letter-spacing: -.03em; }
.write-form { display: flex; flex-direction: column; gap: 20px; }
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field label { font-size: 14px; font-weight: 600; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.hint { color: var(--muted); font-weight: 400; font-size: 13px; }
.field input, .field textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; transition: border-color .2s, box-shadow .2s; line-height: 1.6;
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.field input.is-invalid, .field textarea.is-invalid { border-color: var(--danger); }
#fTitle { font-size: 22px; font-weight: 700; padding: 14px 16px; }
#fBody { font-family: var(--serif); font-size: 17px; line-height: 1.85; min-height: 320px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tag-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -8px; min-height: 0; }
.form-error { margin: 0; color: var(--danger); font-size: 14px; min-height: 0; }
.form-error:empty { display: none; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: none; place-items: center; padding: 20px; }
.modal.is-open { display: grid; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(31, 35, 40, .35); animation: fadeIn .2s ease both; }
.modal-card {
  position: relative; width: min(420px, 100%); max-height: calc(100vh - 40px); overflow-y: auto;
  padding: 32px 28px 28px; border-radius: 18px; background: #fff;
  box-shadow: 0 24px 60px -20px rgba(31, 35, 40, .35);
  animation: popIn .25s ease both;
}
.modal-sm { width: min(380px, 100%); }
.modal-close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 24px; line-height: 1; }
.modal-close:hover { background: var(--bg-sub); color: var(--text); }
.modal-title { margin: 0 0 6px; font-size: 22px; letter-spacing: -.02em; }
.modal-sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 12px; background: var(--bg-sub); margin-bottom: 20px; }
.tab { height: 36px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; transition: all .2s; }
.tab.is-active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
#nameField { display: none; }
#nameField.is-visible { display: flex; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 12px 20px; border-radius: 999px;
  background: var(--text); color: #fff; font-size: 14px; text-align: center;
  transition: opacity .25s, transform .25s;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--danger); }

.site-footer { border-top: 1px solid var(--line); padding: 28px 0; color: var(--muted); font-size: 13px; text-align: center; }

/* Animations */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes cardIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.post-grid.is-leaving { opacity: 0; transform: translateY(4px); transition: opacity .15s ease, transform .15s ease; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Responsive */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 40px; }
  .sidebar { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
  .article { max-width: none; }
}
@media (max-width: 640px) {
  .container { padding: 0 16px; }
  .header-inner { height: 58px; }
  .brand-name { display: none; }
  .user-chip { display: none; }
  .btn { padding: 0 13px; }
  .hero { padding: 36px 0 20px; }
  .hero-sub { font-size: 15px; margin-bottom: 22px; }
  .tag-filter { justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; margin-left: -16px; margin-right: -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
  .tag-filter::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; }
  .post-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .card { padding: 20px; }
  .sidebar { grid-template-columns: minmax(0, 1fr); }
  .field-row { grid-template-columns: minmax(0, 1fr); }
  .article { padding-top: 24px; }
  .prose { font-size: 17px; }
  .write-wrap { padding-top: 24px; }
  .write-title { font-size: 26px; }
  .form-actions .btn { flex: 1; }
  .modal-card { padding: 28px 20px 22px; }
}
