/* shared/base.css — 모든 사이트 공통 리셋 + 토스트 + 푸터 + 크로스 프로모 + 언어 전환 + 별점 위젯 (모바일 우선, --app-width) */

:root {
  --font-sans: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Malgun Gothic', sans-serif;
  --max-width: 480px;
  /* 모든 미니앱은 모바일 화면이 기본: 데스크톱에서도 이 폭의 한 줄 레이아웃을 가운데에 둔다(배경은 꽉 채움).
     여러 칸 데스크톱 레이아웃은 쓰지 않는다. 화면 고정 요소(모달·하단 바·전체 화면 탭 영역)도 이 폭 안에 둔다. */
  --app-width: 480px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --toast-bg: rgba(20, 18, 30, 0.94);
  --toast-fg: #fff;
}

/* 일본어 페이지: 가나/한자는 일본어 글꼴로 (Pretendard에는 가나가 없다) */
html:lang(ja) {
  --font-sans: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN',
    'Yu Gothic UI', 'Yu Gothic', Meiryo, 'Noto Sans JP', 'Pretendard', sans-serif;
}
/* 일본어 제목은 문절 단위로 줄바꿈 (지원 브라우저만, 나머지는 무시) */
html:lang(ja) :is(h1, h2, h3, summary) { word-break: auto-phrase; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
img, svg { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ---------------- 토스트 ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(12px);
  background: var(--toast-bg);
  color: var(--toast-fg);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 9999;
  /* 긴 문구(번역 포함)도 좁은 화면 안에서 줄바꿈 */
  width: max-content;
  max-width: calc(min(100vw, var(--app-width, 480px)) - 32px);
  white-space: normal;
  text-align: center;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------------- 크로스 프로모 ---------------- */
#more-tests {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: var(--max-width);
  margin: 0 auto;
}
.more-test-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: transform 0.15s ease, background 0.15s ease;
}
.more-test-card:active { transform: scale(0.98); }
.more-test-emoji { font-size: 26px; line-height: 1; flex-shrink: 0; }
.more-test-body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.more-test-title { font-weight: 700; font-size: 15px; }
.more-test-desc {
  font-size: 12.5px;
  opacity: 0.65;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.more-test-arrow { opacity: 0.4; font-size: 16px; flex-shrink: 0; }

/* ---------------- 푸터 ---------------- */
.site-footer {
  max-width: var(--max-width);
  margin: 40px auto 0;
  padding: 24px 20px 40px;
  text-align: center;
  font-size: 12px;
  opacity: 0.55;
  line-height: 1.8;
}
.site-footer a { text-decoration: underline; text-underline-offset: 2px; }

/* ---------------- 언어 전환 (셀렉트박스) ----------------
   사이트마다 --lang-bg / --lang-fg / --lang-border 로 색을 바꿀 수 있다. */
.lang-switch {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 12px 0 0;
  line-height: 1;
}
.lang-select {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.lang-globe {
  position: absolute;
  left: 10px;
  font-size: 13px;
  pointer-events: none;
}
.lang-select select {
  -webkit-appearance: none;
  appearance: none;
  min-height: 34px;
  padding: 6px 30px 6px 30px;
  border: 1px solid var(--lang-border, rgba(150, 150, 160, 0.35));
  border-radius: 999px;
  background-color: var(--lang-bg, rgba(150, 150, 160, 0.12));
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  color: var(--lang-fg, inherit);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.lang-select select:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.lang-select select option { color: #111; background: #fff; }
.lang-links a { margin-right: 8px; font-size: 12px; text-decoration: underline; }

/* 언어별 글꼴 (본문 기본 글꼴 뒤에 쓰인다) */
:lang(zh) { font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', var(--font-sans); }
:lang(th) { font-family: 'Sukhumvit Set', 'Thonburi', 'Leelawadee UI', 'Noto Sans Thai', var(--font-sans); line-height: 1.7; }
:lang(vi) { font-family: var(--font-sans), 'Noto Sans', 'Segoe UI', sans-serif; }

/* ---------------- 유틸 ---------------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ---------------- 별점 위젯 (common.js renderRating) ----------------
   사이트마다 --mg-star-on / --mg-star-off / --mg-rating-font 로 색·글꼴을 바꿀 수 있다. */
.mg-rating {
  text-align: center;
  margin: 24px auto;
  max-width: var(--max-width, 480px);
  font-family: var(--mg-rating-font, inherit);
}
.mg-rating-title { font-weight: 700; font-size: 15px; margin: 0 0 6px; }
.mg-rating-stars { display: inline-flex; gap: 2px; }
.mg-star {
  font-size: 34px;
  line-height: 1;
  background: none;
  border: 0;
  padding: 4px;
  cursor: pointer;
  color: var(--mg-star-off, rgba(128, 128, 128, 0.35));
  transition: transform 0.12s ease, color 0.12s ease;
}
.mg-star.is-on { color: var(--mg-star-on, #f5b301); }
.mg-star:hover, .mg-star:focus-visible { transform: scale(1.12); }
.mg-star:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; border-radius: 6px; }
.mg-rating-meta { font-size: 13px; opacity: 0.75; margin: 6px 0 0; }
@media (prefers-reduced-motion: reduce) { .mg-star { transition: none; } }

/* ---------------- 앱 중간 광고 (common.js renderAd) ----------------
   자리를 미리 잡지 않는다: 광고가 없거나(unfilled) 아직 안 불렀으면 높이가 없다. */
.mg-ad {
  display: block;
  min-height: 1px;
  width: 100%;
  max-width: var(--app-width, 480px);
  margin: 16px auto;
  overflow: hidden;
}
.mg-ad:not([data-mg-ad-ready]) { margin: 0 auto; }
.mg-ad:has(ins.adsbygoogle[data-ad-status="unfilled"]) { display: none; }

/* ---------------- 하트 버튼 (common.js heartButton) ---------------- */
.mg-rating-row { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
.mg-heart {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 14px 6px 12px;
  border: 1.5px solid var(--mg-heart-border, rgba(255, 59, 92, 0.35));
  border-radius: 999px;
  background: var(--mg-heart-bg, rgba(255, 59, 92, 0.08));
  color: var(--mg-heart-fg, #ff3b5c);
  font: inherit;
  font-weight: 800;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.mg-heart-icon { font-size: 18px; display: inline-block; transform-origin: 50% 60%; }
.mg-heart.is-on .mg-heart-icon { color: var(--mg-heart-on, #ff3b5c); }
.mg-heart.is-pop .mg-heart-icon { animation: mg-heart-pop 0.45s cubic-bezier(.2, 1.6, .4, 1); }
.mg-heart-num:empty { display: none; }
.mg-heart:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
@keyframes mg-heart-pop { 0% { transform: scale(1); } 35% { transform: scale(1.45); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .mg-heart.is-pop .mg-heart-icon { animation: none; } }

/* ---------------- 공유 줄 (data-mg-social) ---------------- */
.mg-share {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 14px auto 0;
  max-width: var(--app-width, 480px);
}
.mg-share-btn {
  min-height: 44px;
  padding: 8px 4px;
  border: 1px solid var(--mg-share-border, rgba(150, 150, 160, 0.3));
  border-radius: 12px;
  background: var(--mg-share-bg, rgba(150, 150, 160, 0.08));
  color: inherit;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  word-break: keep-all;
}
.mg-share-native { background: var(--mg-share-primary-bg, #151b2e); color: var(--mg-share-primary-fg, #fff); border-color: transparent; }
.mg-share-btn:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

/* ---------------- 끝 화면 공통 (data-mg-end) ----------------
   사이트는 --mg-end-* 변수로 색만 맞춘다. 순서: 별점·하트 → 광고 → 공유 → 다시 하기 → 다른 미니앱 */
.mg-end { max-width: var(--app-width, 480px); margin: 20px auto 0; display: flex; flex-direction: column; gap: 4px; }
.mg-end .mg-rating { margin: 8px auto 4px; }
.mg-end .mg-ad { margin: 8px auto; }
.mg-end-h { margin: 18px 0 10px; font-weight: 800; font-size: 15px; text-align: center; }
/* 6개는 3×2 — 480px 한 줄 6칸이면 'Link kopieren' 같은 이름이 잘린다 */
.mg-share-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mg-end .mg-share-btn {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  min-height: 62px; padding: 9px 4px 7px; font-size: 12px; font-weight: 700;
}
.mg-sico { flex-shrink: 0; }
.mg-share-label { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-share-x .mg-sico { color: var(--mg-x, currentColor); }
.mg-share-instagram .mg-sico { color: #e1306c; }
.mg-share-tiktok .mg-sico { color: var(--mg-tiktok, currentColor); }
.mg-share-fb .mg-sico { color: #1877f2; }
.mg-share-kakao .mg-sico { color: #3a1d1d; background: #fee500; border-radius: 6px; padding: 2px; }
.mg-share-line .mg-sico { color: #06c755; }
.mg-share-whatsapp .mg-sico { color: #25d366; }
.mg-end-retry {
  display: block; width: 100%; min-height: 52px; margin: 18px 0 4px;
  border: 0; border-radius: 16px;
  background: var(--mg-end-retry-bg, #151b2e); color: var(--mg-end-retry-fg, #fff);
  font: inherit; font-size: 16px; font-weight: 800; cursor: pointer;
}
.mg-end-retry:focus-visible { outline: 3px solid currentColor; outline-offset: 2px; }
.mg-end-more { margin-top: 6px; }
.mg-end-more-list { display: flex; flex-direction: column; gap: 8px; }

/* ---------------- 맨 위 타이틀 바 (G.topBar) — 누르면 포털 홈 ----------------
   사이트는 --mg-top-fg / --mg-top-badge-bg / --mg-top-badge-fg 로 색만 맞춘다. */
.mg-top {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: var(--app-width, 480px);
  margin: 0 auto;
  padding: 10px 16px 0;
  min-height: 52px;
}
.mg-top .lang-switch { margin: 0 0 0 auto; padding: 0; max-width: none; }
.mg-home {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  color: var(--mg-top-fg, inherit);
  text-decoration: none;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.mg-home-mark {
  width: 22px; height: 22px; border-radius: 7px; flex-shrink: 0;
  background:
    radial-gradient(circle at 70% 70%, #ff3b5c 0 3.2px, transparent 3.6px),
    linear-gradient(135deg, #3355ff, #6a7dff);
}
.mg-home-word { font-size: 16px; }
.mg-home-badge {
  padding: 3px 6px 2px;
  border-radius: 6px;
  background: var(--mg-top-badge-bg, #3355ff);
  color: var(--mg-top-badge-fg, #fff);
  font-size: 10.5px;
  font-weight: 800;
  line-height: 1.2;
}
.mg-top-app { font-size: 13px; font-weight: 700; opacity: 0.7; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mg-home:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; border-radius: 8px; }

/* 끝 화면 ④ 자주 묻는 질문 (접이식) */
.mg-end-faq { margin-top: 4px; }
.mg-faq {
  border: 1px solid var(--mg-faq-border, rgba(150, 150, 160, 0.28));
  border-radius: 12px;
  background: var(--mg-faq-bg, rgba(150, 150, 160, 0.06));
  margin: 0 0 8px;
}
.mg-faq summary {
  list-style: none;
  cursor: pointer;
  padding: 13px 40px 13px 14px;
  position: relative;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.45;
}
.mg-faq summary::-webkit-details-marker { display: none; }
.mg-faq summary::after {
  content: '';
  position: absolute; right: 16px; top: 50%;
  width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg); opacity: 0.55; transition: transform 0.2s ease;
}
.mg-faq[open] summary::after { transform: rotate(225deg); margin-top: -2px; }
.mg-faq p { margin: 0; padding: 0 14px 14px; font-size: 13.5px; line-height: 1.65; opacity: 0.85; }
@media (prefers-reduced-motion: reduce) { .mg-faq summary::after { transition: none; } }
