/* Gaegu 폰트를 @font-face로 직접 정의하여 브라우저 간 일관성 보장 */
/* 온라인 웹 폰트만 사용 */
@font-face {
  font-family: "Gaegu";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("https://fonts.gstatic.com/s/gaegu/v15/TuGfUVB3xyZ5EOoW_RvsLw.woff2")
      format("woff2"),
    url("https://fonts.gstatic.com/s/gaegu/v15/TuGfUVB3xyZ5EOoW_RvsLw.woff")
      format("woff");
  unicode-range: U+0020-007F, U+00A0-00FF, U+AC00-D7A3, U+1100-11FF, U+3130-318F,
    U+A960-A97F, U+D7B0-D7FF;
}

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

:root {
  --primary-color: #5f6f52;
  --primary-hover: #46523c;
  --accent-color: #ffc857;
  --background-bg: #f5f5f0;
  --card-bg: #ffffff;
  --text-main: #2c3329;
  --text-sub: #5f6f52;
  --border-color: rgba(44, 51, 41, 0.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: var(--background-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 20px;
  padding-bottom: 50px;
}

.container {
  width: 100%;
  max-width: 600px;
  background: var(--card-bg);
  border-radius: 20px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

/* 시작 화면일 때만 컨텐츠를 세로 가운데 정렬 */
#startScreen.active {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: auto;
  max-height: 70vh;
}

#page-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 80px; /* main card -> FAQ 간격 */
  min-height: 100vh;
  justify-content: flex-start;
  padding-top: 10vh;
}

.screen {
  display: none;
  padding: 40px 20px;
  text-align: center;
}

.screen.active {
  display: block;
}

h1,
h2 {
  color: var(--text-main);
  margin-bottom: 20px;
  word-break: keep-all;
  white-space: normal;
}

h1 {
  font-size: 2.5em;
  color: var(--text-main);
}

/* 서브 텍스트 강조 (옵션) */
#startScreen p {
  color: var(--text-sub);
}

#startScreen p strong,
#startScreen p .accent-number {
  color: var(--accent-color);
  font-weight: 600;
}

.btn {
  padding: 15px 30px;
  font-size: 16px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s ease;
  margin: 10px;
  word-break: keep-all;
  white-space: normal;
}

.btn:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  background: var(--primary-hover);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.btn-secondary {
  background: #e5e4dc;
  color: var(--text-main);
}

.btn-secondary:hover {
  background: #d7d5c9;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 카메라 화면 */
#cameraScreen {
  display: none;
  padding: 0;
}

#cameraScreen.active {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  z-index: 1000;
}

.camera-container {
  position: relative;
  width: 100%;
  max-width: 95vw;
  max-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 40px;
  margin-bottom: 40px;
}

#video {
  width: 100%;
  height: auto;
  max-height: 80vh;
  object-fit: contain;
  display: block;
  transform: scaleX(-1); /* 기본적으로 좌우 반전 적용 */
}

.controls {
  padding: 20px;
}

/* 카운트다운 및 카운터 (비디오 아래) */
.camera-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.timer-container {
  text-align: center;
}

.countdown {
  font-size: 5em;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5), 0 0 20px rgba(0, 0, 0, 0.3);
  line-height: 1;
}

.progress-bar {
  width: 100%;
  height: 10px;
  background: #e0e0e0;
  border-radius: 5px;
  overflow: hidden;
}

.progress {
  height: 100%;
  background: linear-gradient(
    135deg,
    var(--primary-color) 0%,
    var(--primary-hover) 100%
  );
  width: 0%;
  transition: width 0.1s linear;
}

.photo-counter {
  font-size: 1.8em;
  color: #fff;
  font-weight: bold;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5), 0 0 20px rgba(0, 0, 0, 0.3);
  background: rgba(0, 0, 0, 0.4);
  padding: 10px 25px;
  border-radius: 25px;
}

/* 사진 선택 화면 */
.button-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.button-group .btn {
  width: 100%;
  margin: 0;
}

/* 사진 선택 화면 */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 15px;
  margin: 20px 0;
  max-height: 400px;
  overflow-y: auto;
  padding: 10px;
}

.photo-item {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 3px solid transparent;
}

.photo-item:hover {
  transform: scale(1.05);
}

.photo-item.selected {
  border-color: var(--accent-color);
  box-shadow: 0 0 18px rgba(255, 200, 87, 0.5);
}

.photo-item img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
}

.photo-item .checkmark {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  background: var(--accent-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  font-weight: bold;
  font-size: 18px;
}

/* 결과 화면 */
.result-container {
  margin: 20px 0;
  padding: 20px;
  background: #f2f2eb;
  border-radius: 15px;
}

#stickerCanvas {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}

.result-actions {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.share-section {
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.share-label {
  font-size: 13px;
  color: var(--text-sub);
}

.share-btn {
  border-radius: 999px;
  border: 1px solid rgba(95, 111, 82, 0.35);
  background: rgba(95, 111, 82, 0.06);
  color: var(--text-main);
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.share-btn:hover {
  background: rgba(255, 200, 87, 0.15);
  border-color: var(--accent-color);
  color: var(--text-main);
}

/* Processing Modal */
#processing-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.processing-content {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.processing-text {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
  text-align: center;
  word-break: keep-all;
  white-space: normal;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#faq-section {
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#faq-section details {
  border-bottom: 1px solid var(--border-color);
  padding: 15px 0;
}

#faq-section summary {
  list-style: none;
  cursor: pointer;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  word-break: keep-all;
  white-space: normal;
}

#faq-section summary::-webkit-details-marker {
  display: none;
}

#faq-section summary::after {
  content: "▸";
  color: var(--text-main);
  font-size: 14px;
  transition: transform 0.2s ease;
}

#faq-section details[open] summary::after {
  transform: rotate(90deg);
}

#faq-section .faq-body {
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.7;
  margin-top: 6px;
  word-break: keep-all;
  white-space: pre-line;
}

#page-footer {
  padding: 20px 0 50px;
  text-align: center;
}

.footer-links {
  display: flex;
  gap: 10px;
  justify-content: center;
  font-size: 12px;
}

.footer-links a {
  color: var(--text-sub);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--primary-color);
  text-decoration: underline;
}

.ad-placeholder {
  width: 300px;
  max-width: 100%;
  height: 250px;
  background: rgba(95, 111, 82, 0.08);
  border: 1px solid rgba(95, 111, 82, 0.18);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  font-weight: 600;
  text-align: center;
  padding: 8px;
  position: relative;
  overflow: hidden;
}

.ad-placeholder::before {
  content: "Cheezism";
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  font-family: "Gaegu", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 22px;
  letter-spacing: 0.08em;
  color: rgba(95, 111, 82, 0.6);
}

.ad-placeholder::after {
  content: "";
  position: absolute;
  width: 52px;
  height: 52px;
  border-radius: 999px;
  border: 3px solid rgba(95, 111, 82, 0.25);
  top: 52%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-top-color: transparent;
  animation: ad-spinner 1.4s linear infinite;
}

@keyframes ad-spinner {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

.processing-progress-bar {
  width: 100%;
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

#processing-progress {
  height: 100%;
  width: 0%;
  background: var(--accent-color);
  transition: width 0.2s linear;
}

@media (max-width: 600px) {
  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  .photo-item img {
    height: 100px;
  }

  h1 {
    font-size: 2em;
  }

  #cameraScreen {
    padding: 0;
  }

  .camera-container {
    max-width: 95vw;
    max-height: 70vh;
    margin-bottom: 30px;
  }

  #video {
    max-height: 70vh;
  }

  .countdown {
    font-size: 4em;
  }

  .photo-counter {
    font-size: 1.5em;
    padding: 8px 20px;
  }
}
