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

:root {
  --bg: #000000;
  --surface: #0d0d0d;
  --surface2: #1a1a1a;
  --border: #262626;
  --primary: #00ffa3;
  --primary-hover: #00cc82;
  --correct: #00ffa3;
  --wrong: #ff4d4d;
  --text: #ffffff;
  --text-muted: #888888;
  --radius: 8px;
  --font: "Pretendard Variable", "Pretendard", -apple-system, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
}

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

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 1.1rem; font-weight: 700; }
header a { color: var(--text-muted); font-size: 0.9rem; transition: color .15s; }
header a:hover { color: var(--text); }
header nav { display: flex; gap: 16px; margin-left: auto; }

main { max-width: 900px; margin: 0 auto; padding: 32px 16px; }

/* period toggle */
.period-group {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}
.period-btn {
  padding: 6px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.875rem;
  transition: all .15s;
}
.period-btn:hover { border-color: var(--primary); color: var(--text); }
.period-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #000;
  font-weight: 600;
}

/* search */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 24px;
}
.search-input {
  width: 100%;
  padding: 9px 40px 9px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--primary); }
.search-input::placeholder { color: var(--text-muted); }
.search-clear {
  position: absolute;
  right: 10px;
  display: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0;
}
.search-clear:hover { color: var(--text); }

.search-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
}
.search-result-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.search-rank {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 44px;
}
.search-cat-type {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface2);
  color: var(--text-muted);
}
.search-cat-name { font-weight: 700; font-size: 1rem; }
.search-viewers { color: var(--primary); font-size: 0.9rem; font-weight: 600; }
.search-meta { color: var(--text-muted); font-size: 0.8rem; margin-left: auto; }

/* chart section */
.chart-section { margin-bottom: 40px; }
.chart-section h2 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; color: var(--text-muted); }
.chart-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.chart-wrap--bar  { height: 520px; }
.chart-wrap--line { height: 360px; }

/* quiz */
.quiz-score {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.quiz-score span { color: var(--primary); font-weight: 700; font-size: 1.1rem; }

.quiz-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 600px) { .quiz-cards { grid-template-columns: 1fr; } }

.quiz-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  aspect-ratio: 3 / 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.quiz-card:hover { border-color: var(--primary); background: var(--surface2); }
.quiz-card .cat-type {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(0,0,0,0.45);
  color: rgba(255,255,255,0.7);
  margin-bottom: 10px;
}
.quiz-card .cat-name {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 4px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.9), 0 0 4px rgba(0,0,0,0.8);
}
.quiz-card .cat-viewers {
  font-size: 0.95rem;
  color: var(--text-muted);
  visibility: hidden;
  margin-top: 12px;
  background: rgba(0,0,0,0.55);
  padding: 3px 12px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}
.quiz-card .cat-meta {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.95);
  visibility: hidden;
  margin-top: 6px;
  text-shadow: 0 1px 6px rgba(0,0,0,0.9);
  white-space: pre-line;
  line-height: 1.6;
}

.quiz-card.correct { border-color: var(--correct); background: rgba(0,255,163,.08); }
.quiz-card.wrong   { border-color: var(--wrong);   background: rgba(255,77,77,.08); }
.quiz-card.correct .cat-viewers,
.quiz-card.wrong   .cat-viewers { visibility: visible; }
.quiz-card.correct .cat-meta,
.quiz-card.wrong   .cat-meta   { visibility: visible; opacity: 1; }
.quiz-card.correct .cat-viewers { color: var(--correct); font-weight: 600; }
.quiz-card.wrong   .cat-viewers { color: var(--wrong); }

/* 배경 이미지 */
.quiz-card.has-image {
  background-size: cover;
  background-position: center;
  position: relative;
  overflow: hidden;
}
.quiz-card.has-image::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.92) 0%, rgba(0,0,0,0.5) 45%, rgba(0,0,0,0.1) 100%);
  transition: background .15s;
}
.quiz-card.has-image:hover::before {
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.4) 45%, rgba(0,0,0,0.05) 100%);
}
.quiz-card.has-image.correct::before {
  background: linear-gradient(to top, rgba(0,255,163,0.55) 0%, rgba(0,255,163,0.2) 60%, rgba(0,0,0,0.2) 100%);
}
.quiz-card.has-image.wrong::before {
  background: linear-gradient(to top, rgba(255,77,77,0.55) 0%, rgba(255,77,77,0.2) 60%, rgba(0,0,0,0.2) 100%);
}
.quiz-card.has-image > * { position: relative; z-index: 1; }

/* higher or lower 버튼 */
.hol-buttons {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}
.hol-btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.hol-btn:active { transform: scale(0.97); }
.hol-btn:disabled { opacity: .4; cursor: default; transform: none; }
.hol-btn-higher { background: var(--correct); color: #000; }
.hol-btn-lower  { background: var(--wrong);   color: #fff; }

/* 왼쪽 오픈 카드 — viewers 항상, meta는 hover시만 */
.quiz-card.is-open .cat-viewers { visibility: visible; color: var(--primary); font-weight: 700; }
.quiz-card.is-open .cat-meta {
  visibility: visible;
  opacity: 0;
  transition: opacity .2s;
}
.quiz-card.is-open:hover .cat-meta { opacity: 1; }

/* 계속하기 버튼 */
.quiz-next {
  display: none;
  margin-top: 16px;
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.quiz-next:hover { background: var(--primary-hover); }
.quiz-next.visible { display: block; }

/* 게임 오버 */
.quiz-gameover {
  display: none;
  padding: 0 0 48px;
}
.quiz-gameover.visible { display: block; }

.gameover-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
  align-items: center;
}
@media (max-width: 600px) { .gameover-layout { grid-template-columns: 1fr; } }

.gameover-info {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.gameover-info h2 { font-size: 1.6rem; font-weight: 800; }
.gameover-info .streak-count { font-size: 4rem; font-weight: 800; color: var(--primary); line-height: 1.1; }
.gameover-info p { color: var(--text-muted); margin: 0 0 8px; }
.gameover-gif { width: 100%; max-width: 160px; border-radius: var(--radius); }
.gameover-msg { font-size: 1rem; font-weight: 600; color: var(--text) !important; margin-bottom: 12px !important; }

.quiz-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 8px; }

/* marquee background */
.marquee-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  overflow: hidden;
  opacity: 0;
  transition: opacity .6s;
}
.marquee-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.92) 75%);
}
.marquee-track {
  display: flex;
  gap: 10px;
  width: max-content;
  animation: marquee-left 35s linear infinite;
}
.marquee-reverse { animation: marquee-right 40s linear infinite; }
@keyframes marquee-left {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}
@keyframes marquee-right {
  0%   { transform: translateX(-50%); }
  100% { transform: translateX(0); }
}
.marquee-item {
  width: 180px;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  opacity: 0.55;
}

/* index landing */
header { position: relative; z-index: 10; }
main { position: relative; z-index: 2; }
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: calc(100vh - 57px);
  padding: 80px 16px;
  text-align: center;
}
.landing h2 { font-size: 2rem; font-weight: 800; }
.landing p { color: var(--text-muted); max-width: 520px; line-height: 1.6; }
.landing .btn-group { display: flex; gap: 12px; margin-top: 16px; }
.btn {
  padding: 12px 28px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s;
}
.btn-primary { background: var(--primary); color: #000; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); }

/* footer */
.site-footer {
  padding: 16px 24px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
.site-footer a { color: var(--text-muted); transition: color .15s; }
.site-footer a:hover { color: var(--text); }
.site-footer--fixed {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ── 반응형 ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  header { padding: 12px 16px; }
  header h1 { font-size: 1rem; }
  main { padding: 24px 12px; }

  .landing { padding: 40px 16px; }
  .landing h2 { font-size: 1.5rem; }
  .landing .btn-group { flex-direction: column; width: 100%; }
  .landing .btn-group .btn { width: 100%; text-align: center; }

  .marquee-item { width: 120px; }

  .search-meta { margin-left: 0; width: 100%; }

  .chart-wrap--bar  { height: 360px; }
  .chart-wrap--line { height: 260px; }

  .streak-count { font-size: 3rem; }
}

@media (max-width: 480px) {
  .quiz-card { aspect-ratio: 1 / 1; }
  .hol-buttons { flex-direction: column; }
  .hol-btn { padding: 12px; }
  .gameover-gif { max-width: 120px; }
}
