:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --line: #e3e8f0;
  --text: #1f2430;
  --muted: #6b7488;
  --primary: #3b5bdb;
  --primary-dark: #2f49b0;
  --ok: #2f9e44;
  --bad: #e03131;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }

/* 상단바 */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50;
}
.topbar .brand a { font-weight: 800; font-size: 18px; }
.topbar nav { display: flex; gap: 18px; margin-left: 8px; }
.topbar nav a { color: var(--muted); font-weight: 600; }
.topbar nav a:hover { color: var(--primary); }
.topbar .auth { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.me { color: var(--muted); font-weight: 600; }

/* 레이아웃: 광고 여백 + 본문 */
.layout {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 180px;
  gap: 20px; max-width: 1200px; margin: 20px auto; padding: 0 16px;
}
.ad { }
.ad-slot {
  position: sticky; top: 80px;
  height: 600px; display: flex; align-items: center; justify-content: center;
  text-align: center; color: #adb5bd; font-size: 13px; line-height: 1.6;
  background: repeating-linear-gradient(45deg, #f8f9fb, #f8f9fb 10px, #f1f3f7 10px, #f1f3f7 20px);
  border: 1px dashed var(--line); border-radius: var(--radius);
}
.content { min-height: 70vh; }
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .ad { display: none; }
}

/* 카드 / 버튼 */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.btn-primary {
  background: var(--primary); color: #fff; border: none; padding: 10px 16px;
  border-radius: 8px; font-weight: 700; cursor: pointer; font-size: 14px;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: 9px 14px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* 설정 슬라이더 */
.slider-row { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.slider-row label { width: 130px; font-weight: 600; }
.slider-row input[type=range] { flex: 1; }
.slider-row .val { width: 44px; text-align: right; color: var(--primary); font-weight: 700; }
.hint { color: var(--muted); font-size: 13px; }

/* 문제 */
.q-block { border-bottom: 1px solid var(--line); padding: 16px 0; }
.q-block:last-child { border-bottom: none; }
.q-title { font-weight: 700; margin-bottom: 6px; }
.q-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tag {
  font-size: 12px; background: #eef1fb; color: var(--primary);
  padding: 2px 8px; border-radius: 20px; font-weight: 600;
}
.choice { display: block; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 8px; margin: 6px 0; cursor: pointer; }
.choice:hover { border-color: var(--primary); }
.choice input { margin-right: 8px; }
.choice.correct { border-color: var(--ok); background: #ebfbee; }
.choice.wrong { border-color: var(--bad); background: #fff0f0; }
.explain { background: #f8f9fb; border-left: 3px solid var(--primary);
  padding: 10px 12px; margin-top: 8px; border-radius: 6px; font-size: 14px; }

/* 결과 요약 */
.summary { display: flex; gap: 16px; }
.metric { flex: 1; text-align: center; background: #f8f9fb; border-radius: 10px; padding: 16px; }
.metric .num { font-size: 28px; font-weight: 800; color: var(--primary); }
.metric .lbl { color: var(--muted); font-size: 13px; }

/* 댓글 */
.comment { border-top: 1px solid var(--line); padding: 10px 0; }
.comment .head { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.comment .who { font-weight: 700; color: var(--text); }
.comment .body { margin: 4px 0; }
.comment .actions { display: flex; gap: 10px; font-size: 12px; }
.comment .like { cursor: pointer; color: var(--muted); background: none; border: none; }
.comment .like.liked { color: var(--bad); font-weight: 700; }
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.filter-bar select, .filter-bar input[type=text] {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
}

/* 유튜브 PIP */
.pip {
  position: fixed; top: 70px; right: 16px; width: 300px; z-index: 80;
  background: #111; color: #fff; border-radius: 10px; overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,.3); font-size: 13px;
}
.pip.collapsed { display: none; }
.pip-head { display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; background: #1c1c1c; cursor: move; }
.pip-controls button { background: none; border: none; color: #ccc; cursor: pointer; font-size: 13px; }
.pip-body { padding: 8px; }
.pip-input { display: flex; gap: 6px; margin-bottom: 6px; }
.pip-input input { flex: 1; padding: 5px; border-radius: 6px; border: none; }
.pip-input button { border: none; border-radius: 6px; padding: 5px 8px; cursor: pointer; }
.pip-player iframe { width: 100%; height: 165px; border: 0; border-radius: 6px; }
.pip-open {
  position: fixed; top: 70px; right: 16px; z-index: 79;
  background: #e03131; color: #fff; border: none; padding: 8px 12px;
  border-radius: 20px; cursor: pointer; font-weight: 700; box-shadow: 0 4px 12px rgba(0,0,0,.2);
}

/* 오류 신고 */
.report-bar { margin: 6px 0; }
.btn-report {
  background: #fff4e6; color: #e8590c; border: 1px solid #ffd8a8;
  font-size: 12px; padding: 4px 10px; border-radius: 20px; cursor: pointer; font-weight: 700;
}
.btn-report:hover { background: #ffe8cc; }
.reports-box { background: #fff9f2; border: 1px solid #ffe3c2; border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.report { border-top: 1px dashed #ffd8a8; padding: 8px 0; }
.report:first-of-type { border-top: none; }
.reply { margin: 4px 0 4px 14px; font-size: 13px; color: #495057; }
.reply .who { font-weight: 700; color: var(--text); }

/* 구글 로그인 버튼 */
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; cursor: pointer; font-weight: 700; color: #3c4043; text-decoration: none;
}
.btn-google:hover { background: #f8f9fb; }
.divider { text-align: center; color: var(--muted); font-size: 13px; margin: 14px 0; }

.msg { padding: 10px 12px; border-radius: 8px; margin: 8px 0; font-size: 14px; }

/* 설정 마법사 */
.wizard { max-width: 720px; margin: 0 auto; }
.wizard-steps {
  display: flex; gap: 8px; margin-bottom: 24px; padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.wstep {
  flex: 1; text-align: center; font-size: 12px; color: var(--muted); font-weight: 600;
}
.wstep span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; background: var(--line);
  color: var(--muted); font-size: 12px; margin-right: 4px;
}
.wstep.active { color: var(--primary); }
.wstep.active span { background: var(--primary); color: #fff; }
.wstep.done span { background: var(--ok); color: #fff; }

.choice-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-top: 16px;
}
.mode-grid { grid-template-columns: 1fr; }
@media (min-width: 640px) { .mode-grid { grid-template-columns: repeat(3, 1fr); } }

.choice-card {
  text-align: left; padding: 16px; border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--card); cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.choice-card:hover:not(:disabled) { border-color: var(--primary); }
.choice-card.selected { border-color: var(--primary); background: #f0f4ff; box-shadow: 0 0 0 1px var(--primary); }
.choice-card:disabled { opacity: .55; cursor: not-allowed; }
.choice-icon { font-size: 28px; margin-bottom: 8px; }
.choice-title { font-weight: 800; font-size: 15px; margin-bottom: 4px; }
.choice-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }
.choice-badge {
  display: inline-block; margin-top: 8px; font-size: 11px; padding: 2px 8px;
  border-radius: 12px; background: #ebfbee; color: var(--ok); font-weight: 700;
}
.choice-badge.soon { background: #f1f3f5; color: var(--muted); }

.wizard-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line);
}
.wizard-actions { text-align: right; }

/* 연습 모드 진행 */
.practice-progress {
  height: 6px; background: var(--line); border-radius: 3px; margin-bottom: 16px; overflow: hidden;
}
.practice-progress-bar { height: 100%; background: var(--primary); transition: width .2s; }

.right { text-align: right; }
.mt { margin-top: 16px; }
.msg.error { background: #fff0f0; color: var(--bad); }
.msg.ok { background: #ebfbee; color: var(--ok); }

/* 결제 모달 · 요금제 */
.pay-modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.pay-modal.hidden { display: none; }
.pay-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.pay-dialog {
  position: relative; background: var(--card); border-radius: var(--radius);
  padding: 24px; max-width: 560px; width: 92%; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,.2);
}
.pay-close { position: absolute; top: 12px; right: 12px; border: none; background: none; font-size: 18px; cursor: pointer; color: var(--muted); }
.pay-plans { display: grid; gap: 12px; margin-top: 16px; }
@media (min-width: 520px) { .pay-plans { grid-template-columns: repeat(3, 1fr); } }
.pay-plan {
  border: 2px solid var(--line); border-radius: var(--radius); padding: 16px;
  text-align: center; position: relative;
}
.pay-plan.featured { border-color: var(--primary); background: #f0f4ff; }
.pay-badge {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: #fff; font-size: 11px; padding: 2px 10px; border-radius: 12px; font-weight: 700;
}
.pay-plan-name { font-weight: 800; margin-top: 8px; }
.pay-plan-price { font-size: 22px; font-weight: 800; color: var(--primary); margin: 8px 0; }
.pay-plan-desc { font-size: 12px; color: var(--muted); min-height: 36px; margin-bottom: 12px; }
.pay-buy { width: 100%; }
.pay-legal { font-size: 11px; margin-top: 16px; text-align: center; }
.pay-status { margin: 12px 0; }
.free-premium-grid { display: grid; gap: 12px; }
@media (min-width: 520px) { .free-premium-grid { grid-template-columns: 1fr 1fr; } }
.fp-box { border-radius: var(--radius); padding: 16px; border: 1px solid var(--line); }
.fp-box.free { background: #f8f9fb; }
.fp-box.premium { background: #f0f4ff; border-color: var(--primary); }
.fp-box h3 { margin: 0 0 10px; font-size: 15px; }
.fp-box ul { margin: 0; padding-left: 18px; font-size: 14px; color: var(--muted); }
.fp-box li { margin: 4px 0; }
.lock-overlay { text-align: center; padding: 32px 16px; background: #f8f9fb; border: 2px dashed var(--line); border-radius: var(--radius); }

/* 저작권·법적 안내 */
.legal-page h1 { margin: 0 0 8px; font-size: 22px; }
.legal-page h2 { margin: 24px 0 10px; font-size: 16px; }
.legal-list { margin: 8px 0; padding-left: 20px; line-height: 1.6; }
.legal-list li { margin: 6px 0; }
.legal-table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 12px 0; }
.legal-table th, .legal-table td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.legal-table th { background: #f8f9fb; font-weight: 700; }
.site-footer {
  text-align: center; padding: 20px 16px 28px; font-size: 13px; color: var(--muted);
  border-top: 1px solid var(--line); margin-top: 24px;
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--primary); text-decoration: underline; }
.site-footer .sep { margin: 0 8px; opacity: 0.5; }
.legal-nav { display: flex; flex-wrap: wrap; gap: 8px; }
.legal-page a { color: var(--primary); }

/* 마법사 상단 · 피드백 */
.wizard-topbar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.wizard-topbar .wizard-steps { margin-bottom: 0; flex: 1; }
.quiz-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.quiz-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-theme { padding: 7px 10px; font-size: 13px; white-space: nowrap; }

/* 피드백 모달 */
.feedback-modal {
  position: fixed; inset: 0; z-index: 210;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.feedback-modal.hidden { display: none; }
.feedback-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.feedback-dialog {
  position: relative; width: min(520px, 100%); max-height: 90vh; overflow: auto;
  margin: 0; z-index: 1;
}
.feedback-close {
  position: absolute; top: 12px; right: 12px; border: none; background: transparent;
  font-size: 18px; cursor: pointer; color: var(--muted);
}
.feedback-textarea {
  width: 100%; min-height: 180px; padding: 12px; margin-top: 12px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 15px;
  font-family: inherit; resize: vertical; background: var(--card); color: var(--text);
}
.feedback-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.feedback-item {
  border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px;
  background: var(--bg);
}
.feedback-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.feedback-body { white-space: pre-wrap; line-height: 1.55; font-size: 14px; }

/* 다크 모드 */
[data-theme="dark"] {
  --bg: #0f1117;
  --card: #1a1d27;
  --line: #2e3444;
  --text: #e8ecf4;
  --muted: #9aa3b5;
  --primary: #6b8cff;
  --primary-dark: #5578f0;
  --ok: #51cf66;
  --bad: #ff6b6b;
}
[data-theme="dark"] .ad-slot {
  background: repeating-linear-gradient(45deg, #161922, #161922 10px, #1e2230 10px, #1e2230 20px);
  color: #5c6578;
}
[data-theme="dark"] .fp-box.free { background: #161922; }
[data-theme="dark"] .fp-box.premium { background: #1a2238; }
[data-theme="dark"] .pay-plan.featured { background: #1a2238; }
[data-theme="dark"] .legal-table th { background: #161922; }
[data-theme="dark"] .lock-overlay { background: #161922; }
[data-theme="dark"] .feedback-backdrop { background: rgba(0,0,0,.65); }
[data-theme="dark"] input, [data-theme="dark"] textarea, [data-theme="dark"] select {
  background: var(--card); color: var(--text); border-color: var(--line);
}
