/* 공통 레이아웃: 기본 요소, 사이드바, 상단바, 섹션, 카드, 푸터 */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--top-h) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  line-height: 1.6;
  word-break: keep-all;
  transition: background-color .2s, color .2s;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 32px; }

.icon-btn {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
  background: transparent; cursor: pointer;
}
.icon-btn:hover { background: color-mix(in srgb, currentColor 8%, transparent); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

@keyframes blink { 50% { opacity: 0; } }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px; border-radius: 12px; font-weight: 600; font-size: 15px;
  transition: transform .15s, background-color .15s, border-color .15s, color .15s;
  border: 0; cursor: pointer;
}
.btn:hover { transform: translateY(-2px); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 30;
  width: var(--side-w);
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line);
  transition: width .22s ease, transform .25s ease, background-color .2s;
  overflow: hidden;
}
.brand { display: flex; align-items: center; gap: 10px; height: var(--top-h); padding: 0 16px; flex: none; }
.brand .mark {
  display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  font-family: var(--mono); font-weight: 700; font-size: 15px;
}
.brand b { display: block; font-size: 16px; letter-spacing: -0.01em; line-height: 1.2; }
.brand small { display: block; color: var(--muted); font-size: 12px; line-height: 1.2; white-space: nowrap; }

.search {
  position: relative; flex: none; margin: 4px 14px 8px;
  display: flex; align-items: center; height: 36px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--bg);
}
.search svg { flex: none; width: 15px; height: 15px; margin: 0 8px 0 10px; color: var(--muted); }
.search input {
  flex: 1; min-width: 0; height: 100%; padding: 0 40px 0 0;
  border: 0; outline: 0; background: transparent; color: var(--fg); font: inherit; font-size: 14px;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search kbd {
  position: absolute; right: 8px; padding: 0 6px;
  border: 1px solid var(--line); border-radius: 4px;
  color: var(--muted); font-size: 11px; font-family: inherit;
}

.tree { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px 10px 24px; }
.tree-label {
  margin: 18px 10px 6px; font-size: 11.5px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted); white-space: nowrap;
}
.row { display: flex; align-items: center; }
.item, .children a {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
  height: 36px; padding: 0 10px; border-radius: 8px;
  font-size: 14px; white-space: nowrap; cursor: pointer;
}
.item:hover, .children a:hover { background: var(--hover); }
.item .ico { flex: none; width: 24px; text-align: center; font-size: 17px; }
.txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.item.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.item.on .count { color: var(--accent); }
.chev {
  display: grid; place-items: center; flex: none; width: 28px; height: 28px; margin-left: 2px;
  border: 0; border-radius: 6px; background: transparent; cursor: pointer; color: var(--muted);
}
.chev:hover { background: var(--hover); color: var(--fg); }
.chev::before {
  content: ""; width: 6px; height: 6px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s;
}
.chev[aria-expanded="true"]::before { transform: rotate(45deg); }
.children { margin: 2px 0 6px 22px; padding-left: 12px; border-left: 1px solid var(--line); }
.children[hidden] { display: none; }
.children a { height: 32px; font-size: 13.5px; color: var(--muted); }
.children a:hover { color: var(--fg); }
.children a.on { color: var(--accent); font-weight: 600; background: var(--accent-soft); }

.side-foot {
  display: flex; align-items: center; gap: 14px; flex: none;
  padding: 14px 20px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); white-space: nowrap;
}
.side-foot a:hover { color: var(--accent); }
.side-foot .keys { margin-left: auto; font-family: var(--mono); font-size: 11px; opacity: .8; }

/* 접힌 상태: 아이콘 레일 (데스크톱 전용) */
@media (min-width: 861px) {
  :root[data-side="collapsed"] { --side-w: var(--rail-w); }
  :root[data-side="collapsed"] .brand { padding: 0 16px; }
  :root[data-side="collapsed"] .brand > span:last-child,
  :root[data-side="collapsed"] .txt,
  :root[data-side="collapsed"] .count,
  :root[data-side="collapsed"] .chev,
  :root[data-side="collapsed"] .children,
  :root[data-side="collapsed"] .search input,
  :root[data-side="collapsed"] .search kbd,
  :root[data-side="collapsed"] .side-foot { display: none; }
  :root[data-side="collapsed"] .search { margin: 4px 12px 8px; justify-content: center; cursor: pointer; }
  :root[data-side="collapsed"] .search svg { margin: 0; }
  :root[data-side="collapsed"] .tree { padding: 4px 10px 24px; }
  :root[data-side="collapsed"] .tree-label { height: 1px; margin: 14px 8px; background: var(--line); font-size: 0; }
  :root[data-side="collapsed"] .item { justify-content: center; padding: 0; gap: 0; }
}
.tip {
  position: fixed; z-index: 50; pointer-events: none;
  padding: 4px 10px; border-radius: 6px;
  background: var(--fg); color: var(--bg); font-size: 13px; font-weight: 600; white-space: nowrap;
  transform: translateY(-50%); opacity: 0; transition: opacity .12s;
}
.tip.show { opacity: 1; }

/* ---------- Shell / Topbar ---------- */
.shell { margin-left: var(--side-w); transition: margin-left .22s ease; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  height: var(--top-h); padding: 0 24px;
  color: var(--fg);
  transition: background-color .25s, box-shadow .25s, color .25s;
}
.has-hero .topbar:not(.scrolled) { color: var(--hero-fg); }
.topbar.scrolled {
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 1px 0 var(--line);
  color: var(--fg);
}
.topbar .logo { display: none; font-weight: 800; letter-spacing: -0.02em; font-size: 17px; }
.topbar .logo b { color: var(--accent-2); }
.where { font-family: var(--mono); font-size: 13px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.where b { color: var(--accent-2); font-weight: 400; }
.menu { display: flex; align-items: center; gap: 22px; margin-left: auto; font-size: 15px; }
.menu a { opacity: .8; white-space: nowrap; }
.menu a:hover { opacity: 1; }

/* ---------- Sections ---------- */
main { container-type: inline-size; }
/* .wrap의 padding 단축 속성보다 우선하도록 section.wrap으로 지정 */
main > section.wrap { padding-top: 128px; }
.sec-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.sec-head h2 { margin: 0; font-size: 28px; letter-spacing: -0.03em; }
.sec-head p { margin: 6px 0 0; color: var(--muted); }

.cats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.cat {
  position: relative; display: flex; align-items: center; gap: 16px;
  padding: 20px; border-radius: 16px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  transition: transform .2s, border-color .2s, box-shadow .2s;
}
.cat:hover, .cat.on { transform: translateY(-4px); border-color: var(--accent); box-shadow: var(--shadow); }
.cat .icon {
  flex: none; display: grid; place-items: center;
  width: 50px; height: 50px; border-radius: 14px; font-size: 25px;
  background: var(--accent-soft);
}
.cat h3 { margin: 0; font-size: 17px; }
.cat small { color: var(--muted); font-size: 14px; }
.cat > div { min-width: 0; }
.rank { position: absolute; top: 12px; right: 14px; font-size: 13px; font-weight: 800; color: var(--muted); }
.cat.top .rank { color: #f59e0b; }
.cat.top .rank::before { content: "👑 "; }

/* 현재 필터를 셸 명령어처럼 보여주는 바 */
.filterbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px;
  margin-bottom: 20px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.filterbar code { flex: 1; min-width: 0; font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filterbar code .p { color: var(--accent); font-weight: 700; }
.filterbar code .a { color: var(--accent-2); }
.filterbar .n { color: var(--muted); font-size: 13px; white-space: nowrap; }
.filterbar button {
  border: 1px solid var(--line); background: transparent; border-radius: 8px;
  padding: 3px 10px; font-size: 13px; color: var(--muted); cursor: pointer;
}
.filterbar button:hover { border-color: var(--accent); color: var(--accent); }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.card {
  display: flex; flex-direction: column;
  border-radius: 18px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  transition: transform .2s, box-shadow .2s, border-color .2s;
  animation: pop .35s ease both;
}
@keyframes pop { from { opacity: 0; transform: translateY(12px); } }
.card:hover { transform: translateY(-6px); box-shadow: var(--shadow); }
.thumb {
  position: relative; aspect-ratio: 16 / 9;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--c1), var(--c2));
  color: rgba(255,255,255,.95); font-size: 44px;
}
.thumb::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255,255,255,.18) 1px, transparent 1px);
  background-size: 14px 14px;
}
.thumb .label {
  position: absolute; left: 14px; top: 14px; z-index: 1;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(0,0,0,.28); font-size: 12px; font-weight: 600;
  backdrop-filter: blur(4px);
}
.card-body { display: flex; flex-direction: column; flex: 1; padding: 20px 22px 22px; }
.card h3 { margin: 0 0 8px; font-size: 18px; line-height: 1.45; letter-spacing: -0.01em; }
.card p { margin: 0 0 14px; color: var(--muted); font-size: 15px; }
.card .meta { margin-top: auto; color: var(--muted); font-size: 13px; }

/* 카드 호버 시 명령어 타이핑: 평소엔 "$ _" 프롬프트만 */
.cmdline {
  display: block; height: 1.7em; margin-top: 4px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.7; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card .cmdline { margin-top: 10px; padding-top: 10px; height: calc(1.7em + 11px); border-top: 1px dashed var(--line); }
.cmdline .p { color: var(--accent); font-weight: 700; }
.cmdline .tc { color: var(--fg); }
.cmdline .cur {
  display: inline-block; width: .55em; height: 1.05em; margin-left: 1px;
  background: currentColor; vertical-align: -0.15em; opacity: .45;
}
.cat:hover .cur, .card:hover .cur, .cat:focus-visible .cur, .card:focus-visible .cur {
  opacity: 1; color: var(--accent-2); animation: blink 1s steps(1) infinite;
}
mark { background: color-mix(in srgb, var(--accent) 25%, transparent); color: inherit; border-radius: 2px; }
.empty { grid-column: 1 / -1; padding: 56px 0; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 18px; }
.empty code { font-family: var(--mono); color: var(--accent); }

.more-row { text-align: center; margin-top: 44px; }
.btn-outline { border: 1px solid var(--line); background: var(--surface); color: var(--fg); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.reveal { opacity: 0; transform: translateY(24px); transition: opacity .6s ease, transform .6s ease; }
.reveal.in { opacity: 1; transform: none; }

.scrim { display: none; }

/* ---------- Container queries: 사이드바 폭에 따라 본문이 반응 ---------- */
@container (max-width: 960px) {
  .cats, .cards { grid-template-columns: repeat(2, 1fr); }
}
@container (max-width: 600px) {
  .cats, .cards { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 1100px) {
  .menu a { display: none; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  body.drawer .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  body.drawer .scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.4); }
  .shell { margin-left: 0; }
  .topbar { padding: 0 16px; }
  .topbar .logo { display: block; }
  .where { display: none; }
}
@media (max-width: 600px) {
  .wrap { padding: 0 16px; }
  main > section.wrap { padding-top: 104px; }
  .sec-head h2 { font-size: 23px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; transform: none; }
}
