/* ============================================================
   style.css  —  디자인 수정은 맨 위 :root 안의 값만 바꿔도 충분해요 🎨
   ============================================================ */
@font-face {
    font-family: 'IsYun';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_2202-2@1.0/LeeSeoyun.woff') format('woff');
    font-weight: normal;
    font-display: swap;
}

@font-face {
    font-family: 'OngleipParkDahyeon';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2411-3@1.0/Ownglyph_ParkDaHyun.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}

@font-face {
    font-family: 'OkMallangW';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2603-1@1.0/OkMallangW-Regular.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Cafe24MeongiBlack';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2405-3@1.1/Cafe24Meongi-B-v1.0.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}

:root {
  /* ===== 🎨 색상 ===== */
  --color-text: #111111;          /* 연도·Filmography·TOTAL 글자색 */
  --color-caption: #222222;       /* 사진 아래 설명 글자색 */
  --color-number: #ffffff;        /* 사진 위 숫자 글자색 */
  --color-frame: #ffffff;         /* 폴라로이드 틀 색 */
  --color-empty: #595959;         /* 사진이 없을 때 회색 칸 색 */
  --color-empty-text: #ffffff;    /* 회색 칸 안의 글자색 */
  --color-bg-base: #ffffff;       /* 배경 사진이 없을 때 바탕색 */

  /* ===== 🔤 글꼴과 글자 크기 (큰 화면 기준) ===== */
  --font: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  --size-year: 32px;              /* 2 0 2 6 */
  --spacing-year: 0.6em;          /* 연도 글자 사이 간격 */
  --size-subtitle: 28px;          /* Filmography */
  --size-caption: 16px;           /* 사진 아래 설명 */
  --size-total: 24px;             /* TOTAL. / 226 */
  --gap-total: 0.16em;               /* TOTAL. 과 / 226 사이 간격 */

  /* ===== 🖼 폴라로이드 틀 ===== */
  --frame-hw: 1.5;                /* 세로÷가로 비율. 4:6 = 1.5 (4:5로 바꾸려면 1.25) */
  --frame-pad-side: 0.06;         /* 위·좌·우 흰 테두리 두께 (틀 너비 대비, 0.06 = 6%) */
  --frame-pad-bottom: 0.20;       /* 아래 흰 테두리 두께 (폴라로이드는 아래가 두꺼워요) */
  --frame-max-w: 250px;           /* 큰 화면에서 틀 한 장의 최대 너비 */
  --frame-shadow: 0 3px 10px rgba(0, 0, 0, 0.2); /* 그림자 (없애려면 none) */
  --number-size: 0.12;            /* 사진 위 숫자 크기 (틀 너비 대비) */

  /* ===== 📐 배치 계산용 (보통은 안 고쳐도 돼요) ===== */
  --cols: 4;
  --rows: 2;
  --pad: 16px;                    /* 화면 좌우 여백 */
  --head: 130px;                  /* 위쪽 제목 영역 높이 */
  --foot: 90px;                   /* 아래쪽 TOTAL 영역 높이 */
  --cap: 50px;                    /* 설명 글 2줄 높이 */
  --rowgap: clamp(8px, 4dvh, 64px); /* 윗줄과 아랫줄 사이 간격 */
  --safe-v: calc(env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px));

  --cell-w: min(calc((100vw - 2 * var(--pad)) / var(--cols)), 340px);
  --w-by-h: calc(((100dvh - var(--head) - var(--foot) - var(--safe-v) - 30px) / var(--rows) - var(--cap) - var(--rowgap) - 6px) / var(--frame-hw));
  --w: max(56px, min(var(--w-by-h), var(--cell-w), var(--frame-max-w))); /* 사진 틀 한 장의 실제 너비 */
}

/* ===== 영역별 웹폰트 설정 ===== */

/* 연도, 제목, TOTAL */
.year,
.subtitle,
.foot {
  font-family: "Cafe24MeongiBlack", sans-serif;
}

/* 사진 아래 설명 */
.caption {
  font-family: "OngleipParkDahyeon", sans-serif;
}

/* 사진 위 숫자 */
.label,
.num {
  font-family: "OngleipParkDahyeon", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

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

/* ---------- 배경 ---------- */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-color: var(--color-bg-base);
  background-size: cover;
  background-position: center;
  /* 임시 배경: 흐릿한 분홍 무늬 (배경 사진이 불러와지면 자동으로 사라져요) */
}

/* ---------- 오른쪽 위 버튼 ---------- */
.tools {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  display: flex;
  gap: 6px;
  z-index: 10;
}
.tool {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.tool:active { transform: scale(0.94); }

/* ---------- 페이지 ---------- */
.page {
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top, 0px) var(--pad) env(safe-area-inset-bottom, 0px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.head {
  height: var(--head);
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.year {
  margin: 0;
  font-size: var(--size-year);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: var(--spacing-year);
  padding-left: var(--spacing-year); /* 글자 간격 때문에 생기는 오른쪽 쏠림 보정 */
}
.subtitle {
  margin: 4px 0 0;
  font-size: var(--size-subtitle);
  font-weight: 400;
  line-height: 1.2;
}

/* ---------- 사진 8장 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell-w));
  gap: var(--rowgap) 0;
  justify-content: center;
  flex-shrink: 0;
}

.cell {
  width: var(--cell-w);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* 폴라로이드 틀 */
.frame {
  width: var(--w);
  aspect-ratio: 1 / var(--frame-hw);
  display: flex;
  background: var(--color-frame);
  padding:
    calc(var(--w) * var(--frame-pad-side))
    calc(var(--w) * var(--frame-pad-side))
    calc(var(--w) * var(--frame-pad-bottom));
  box-shadow: var(--frame-shadow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.frame:focus-visible { outline: 3px solid #4f7cff; outline-offset: 2px; }
.frame:active { transform: scale(0.98); }

.photo {
  position: relative;
  flex: 1;
  background: var(--color-empty);
  overflow: hidden;
}
.photo img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover; /* 사진이 칸을 꽉 채우도록 가장자리를 잘라요 */
  display: block;
}
.label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--color-empty-text);
  font-size: calc(var(--w) * 0.08);
}
.num {
  position: absolute;
  right: 6%;
  bottom: 3%;
  z-index: 2;
  display: flex;
  align-items: baseline;
  gap: 0.2em;
  color: var(--color-number);
  font-size: calc(var(--w) * var(--number-size));
  font-weight: 800;
  line-height: 1.1;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55); /* 밝은 사진 위에서도 읽히도록 */
}
/* "/" 앞에 방문자가 직접 입력하는 숫자 칸 (글자 크기는 "/ 21"과 동일) */
.num-input {
  width: 2.1em;
  padding: 0;
  margin: 0;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.6); /* 입력할 수 있다는 표시 (없애려면 none) */
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: right;
  text-shadow: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.num-input:focus { border-bottom-color: var(--color-number); }
.cam {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  width: calc(var(--w) * 0.2);
  height: calc(var(--w) * 0.2);
  min-width: 16px;
  min-height: 16px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  font-size: calc(var(--w) * 0.11);
}
.no-hints .cam { display: none; }

.caption {
  margin: 0;
  width: 100%;
  min-height: var(--cap);
  padding: 0 4px;
  text-align: center;
  font-size: var(--size-caption);
  line-height: 1.3;
  color: var(--color-caption);
  word-break: keep-all;
  text-wrap: balance;
}

/* ---------- TOTAL ---------- */
.foot {
  height: var(--foot);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-total);
  font-size: var(--size-total);
  font-weight: 800;
  line-height: 1;
}
.total-right { display: flex; align-items: baseline; gap: 0.3em; }
.total-count { min-width: 2.2ch; text-align: right; } /* 8개 숫자의 합계가 자동으로 들어가는 자리 */

/* ============================================================
   📱 세로 화면 (아이폰 세로): 2열 × 4줄, 한 화면에 다 보이게
   ============================================================ */
@media (orientation: portrait) {
  :root {
    --cols: 2;
    --rows: 4;
    --pad: 14px;
    --head: 96px;
    --foot: 60px;
    --cap: 32px;
    --rowgap: clamp(6px, 1.2dvh, 16px);

    /* 📏 사진 크기를 화면 높이 대신 가로 폭 기준으로 키움 (스크롤 허용) */
    --w: min(var(--frame-max-w), calc(var(--cell-w) - 28px));

    --size-year: 28px;
    --size-subtitle: 24px;
    --size-caption: 15px;
    --size-total: 22px;
    --gap-total: 0.15em;
  }
}

/* ============================================================
   📱 가로 화면인데 높이가 낮을 때 (폰을 눕힌 경우): 4열 × 2줄
   ※ 한 화면에 다 보이게 하지 않고 스크롤을 허용하고 싶다면
      아래 :root 안에 --w-by-h: 999px; 한 줄을 추가하세요.
   ============================================================ */
@media (orientation: landscape) and (max-height: 600px) {
  :root {
    --head: 70px;
    --foot: 46px;
    --cap: 26px;
    --rowgap: 8px;
    --w-by-h: 999px;

    --size-year: 20px;
    --size-subtitle: 17px;
    --size-caption: 10px;
    --size-total: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ============================================================
   📸 캡처 모드
   ============================================================ */
[hidden] { display: none !important; } /* hidden 속성이 항상 먹히도록 */

/* 하단 버튼 (캡처 모드에서만 보여요) */
.capture-bar {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: none;
  gap: 8px;
  z-index: 20;
}
.capture .capture-bar { display: flex; }
.capture-bar button,
.preview-actions button {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 10px 16px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.78);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
.capture-bar button:disabled { opacity: 0.6; }

/* 캡처 모드에서 숨기거나 잠그는 것들 */
.capture .tools,
.capture .cam { display: none; }
.capture .num-input { border-bottom-color: transparent; pointer-events: none; }
.capture .frame { cursor: default; pointer-events: none; }
.capture .frame:active { transform: none; }

/* 저장 전 미리보기 */
.preview {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}
.preview img {
  max-width: 100%;
  max-height: calc(100dvh - 140px);
  object-fit: contain;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.preview p { margin: 0; color: #ffffff; font-size: 13px; text-align: center; }
.preview-actions { display: flex; gap: 8px; }
.preview-actions button { background: #ffffff; color: #111111; }

/* ============================================================
   📸 이미지 저장 시 하단 여백 추가
   ============================================================ */
@media (orientation: portrait) {
  .capture .copyright {
    padding-bottom: 12px;
  }
}

@media (orientation: landscape) {
  .capture .copyright {
    padding-bottom: 12px;
  }
}

/* ============================================================
   카피라이트 표시 추가
   ============================================================ */

.copyright {
  width: 100%;
  padding: 3px 0;
  margin-top: 0;
  color: #cccccc;
  font-size: 9.5px;
  font-family: var(--font);
  text-align: center;
  white-space: nowrap;
  line-height: 1.4;
  pointer-events: none;
  flex-shrink: 0;
}
