:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --text: #16161a;
  --muted: #6b6b76;
  --line: #e4e4ea;
  --accent: #ff3b5c;
  --accent-text: #ffffff;
  --chip: #ececf1;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f12;
    --surface: #1a1a20;
    --text: #f2f2f5;
    --muted: #9a9aa6;
    --line: #2a2a33;
    --chip: #24242c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
  line-height: 1.4;
}

/* 상단 */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.brand { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.updated { font-size: 12px; color: var(--muted); white-space: nowrap; }
.platforms {
  display: flex; margin-top: 10px; padding: 3px; gap: 3px;
  background: var(--chip); border-radius: 12px;
}
.platforms button {
  flex: 1; border: 0; border-radius: 9px; padding: 7px 10px;
  font: inherit; font-size: 14px; font-weight: 700;
  background: transparent; color: var(--muted); cursor: pointer;
}
.platforms button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tabs[hidden] { display: none; }
.chips {
  display: flex; gap: 6px; margin: 10px -16px 0; padding: 0 16px;
  overflow-x: auto; scrollbar-width: none; scroll-padding: 0 16px;
}
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 12px;
  font: inherit; font-size: 14px; font-weight: 600;
  background: var(--surface); color: var(--text);
  cursor: pointer;
}
.chips button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.section-title { margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.tabs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none;
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  background: var(--chip);
  color: var(--text);
  cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }
.tabs .count { opacity: 0.7; font-weight: 500; }

/* 카드 그리드 */
main { padding: 14px 16px calc(env(safe-area-inset-bottom) + 24px); max-width: 1400px; margin: 0 auto; }
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px 14px;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* 인스타그램 릴스: 세로 카드, 휴대폰에서 2열 */
.grid.reels { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 10px; }
@media (min-width: 700px) { .grid.reels { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .grid.reels { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.grid.reels .thumb { aspect-ratio: 9 / 16; }
.grid.reels .title { font-size: 14px; }
.grid.reels .meta { font-size: 12px; }
.badge.views { background: rgba(0,0,0,.6); }

.card { all: unset; display: block; width: 100%; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.card:focus-visible .thumb { outline: 3px solid var(--accent); outline-offset: 2px; }
.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--chip);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
@media (hover: hover) { .card:hover .thumb img { transform: scale(1.03); } }
.rank {
  position: absolute; top: 8px; left: 8px;
  min-width: 28px; padding: 2px 8px;
  border-radius: 8px;
  background: rgba(0,0,0,.72); color: #fff;
  font-size: 13px; font-weight: 800; text-align: center;
}
.rank.top { background: var(--accent); }
.badge {
  position: absolute; bottom: 8px; right: 8px;
  padding: 2px 6px; border-radius: 6px;
  background: rgba(0,0,0,.78); color: #fff;
  font-size: 12px; font-weight: 600;
}
.badge.short { background: var(--accent); }
.info { padding: 10px 2px 0; }
.title {
  margin: 0; font-size: 15px; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.meta { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

.notice {
  margin: 24px 0; padding: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-size: 14px; text-align: center;
}

/* 불러오는 중 */
.skeleton .thumb { animation: pulse 1.2s ease-in-out infinite; }
.skeleton .bar { height: 14px; margin-top: 10px; border-radius: 6px; background: var(--chip); animation: pulse 1.2s ease-in-out infinite; }
.skeleton .bar.short { width: 55%; }
@keyframes pulse { 50% { opacity: .5; } }

/* 재생 창 */
.player { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.player[hidden] { display: none; }
.player-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.7); }
.player-sheet {
  position: relative;
  width: 100%; max-width: 900px; max-height: 100dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: up .22s ease-out;
}
@media (min-width: 900px) {
  .player { align-items: center; }
  .player-sheet { border-radius: 18px; }
}
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.player-frame { background: #000; aspect-ratio: 16 / 9; }
.player-frame.vertical { aspect-ratio: 9 / 16; max-height: 70dvh; margin: 0 auto; }
.player-frame.instagram { aspect-ratio: auto; height: min(78dvh, 760px); max-width: 480px; margin: 0 auto; background: #fff; }
.player-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.player-info { padding: 14px 16px 18px; }
.player-info h2 { margin: 0; font-size: 17px; }
.player-actions { display: flex; gap: 10px; margin-top: 14px; }
.player-actions a, .player-actions button {
  flex: 1; text-align: center; text-decoration: none;
  border: 0; border-radius: 12px; padding: 12px;
  font: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
}
.player-actions a { background: var(--accent); color: var(--accent-text); }
.player-actions button { background: var(--chip); color: var(--text); }
.section-title a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
