:root {
  color-scheme: light dark;
  --bg: #fafafa;
  --fg: #1b1b1b;
  --muted: #6b6b6b;
  --card: #ffffff;
  --border: #e2e2e2;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --danger: #dc2626;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #f0f0f0;
    --muted: #9a9a9a;
    --card: #1e1e1e;
    --border: #2e2e2e;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--fg);
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 16px 16px 96px; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.notice { background: #e7f5e9; color: #1e7d32; padding: 8px 12px; border-radius: 8px; display: inline-block; }

/* 홈 화면에서 실행할 때(standalone) 노치·홈바 영역 확보 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--card); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; color: var(--fg); }
.topnav { display: flex; align-items: center; gap: 12px; }
.whoami { color: var(--muted); font-size: 14px; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 14px; padding: 0; }

/* 로그인 */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box {
  width: 100%; max-width: 360px; padding: 32px 24px; background: var(--card);
  border: 1px solid var(--border); border-radius: 16px; text-align: center;
}
.login-box form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; text-align: left; }
.login-box label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
input[type="text"], input[type="password"] {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); font-size: 16px;
}
button, .btn-primary, .btn-secondary, .btn-danger {
  cursor: pointer; border-radius: 8px; border: none; font-size: 14px; padding: 10px 16px;
}
.login-box button[type="submit"], .btn-primary {
  background: var(--accent); color: var(--accent-fg); font-weight: 600;
}
.btn-secondary { background: var(--card); border: 1px solid var(--border); color: var(--fg); }
.btn-danger { background: var(--danger); color: #fff; }
.small { padding: 6px 10px; font-size: 12px; }

/* 앨범 목록 */
.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; margin-top: 16px; }
.album-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; color: var(--fg); }
.album-cover { aspect-ratio: 1/1; background: #ddd; display: flex; align-items: center; justify-content: center; }
.album-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-placeholder { font-size: 40px; }
.album-parent { padding: 8px 10px 0; font-size: 11px; color: var(--muted); }
.album-name { padding: 4px 10px 0; font-weight: 600; word-break: break-all; }
.album-count { padding: 2px 10px 10px; font-size: 12px; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 24px 0; }

/* 앨범 상세 */
.album-header { margin: 16px 0; }
.back-link { font-size: 14px; }
.album-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
:root { --tile: 120px; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
  gap: 8px;
  touch-action: pan-y;   /* 세로 스크롤은 유지하고 핀치는 직접 처리 */
}
.photo-tile { position: relative; display: block; aspect-ratio: 1/1; border-radius: 8px; overflow: hidden; background: #ddd; }
.photo-tile input.photo-check { position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; z-index: 2; }
.photo-img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.file-placeholder { display: flex; align-items: center; justify-content: center; text-align: center; font-size: 12px; padding: 8px; word-break: break-all; }
.check-mark {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0,0,0,0.4); color: #fff; display: none; align-items: center; justify-content: center; z-index: 2;
}
.photo-tile input.photo-check:checked ~ .check-mark { display: flex; background: var(--accent); }
.photo-tile input.photo-check:checked ~ .photo-img { outline: 3px solid var(--accent); outline-offset: -3px; }

/* 선택 액션바 */
.selection-bar {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: space-between; z-index: 20;
}

/* iOS Safari에서 "홈 화면에 추가" 안내 */
.install-hint {
  display: none; margin: 12px 0; padding: 12px 14px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--border); font-size: 13px; line-height: 1.6;
  align-items: flex-start; justify-content: space-between; gap: 12px;
}
.install-hint.show { display: flex; }
.install-hint button { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 0 4px; }

/* 라이트박스 */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.lightbox img {
  max-width: 100vw; max-height: 86vh; object-fit: contain;
  touch-action: none;            /* 핀치·팬을 직접 처리 */
  transform-origin: center center;
  will-change: transform;
  user-select: none; -webkit-user-drag: none;
}
.lightbox.zoomed .lb-prev, .lightbox.zoomed .lb-next { opacity: 0.25; }
.zoom-badge {
  position: absolute; top: 12px; left: 16px; color: #fff; font-size: 13px;
  background: rgba(0,0,0,0.45); padding: 4px 10px; border-radius: 999px; display: none;
}
.lightbox.zoomed .zoom-badge { display: block; }
.lb-close, .lb-prev, .lb-next { position: absolute; background: none; border: none; color: #fff; font-size: 28px; cursor: pointer; padding: 12px; }
.lb-close { top: 8px; right: 12px; }
.lb-prev { left: 4px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 4px; top: 50%; transform: translateY(-50%); }
.lb-actions { position: absolute; bottom: 16px; right: 16px; display: flex; gap: 8px; }
.lb-download { background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; }
.lb-select { background: rgba(255,255,255,0.15); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; border: 1px solid rgba(255,255,255,0.3); }
.lb-select.is-selected { background: var(--accent); border-color: var(--accent); }
.selection-actions { display: flex; gap: 8px; align-items: center; }
.enhance-toggle { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); white-space: nowrap; }

/* 관리자 */
.admin-section { margin: 24px 0; padding: 16px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.admin-form { display: flex; flex-direction: column; gap: 12px; max-width: 480px; }
.admin-form label, .checkbox-line { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.checkbox-line { flex-direction: row; align-items: center; gap: 6px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td { border-bottom: 1px solid var(--border); padding: 8px; text-align: left; vertical-align: top; }
.inline-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.admin-row-actions { display: flex; flex-direction: column; gap: 8px; }
.file-list { columns: 2; font-size: 13px; }
.perm-table { border-collapse: collapse; font-size: 13px; margin: 6px 0; }
.perm-table th, .perm-table td { border-bottom: 1px solid var(--border); padding: 4px 10px 4px 0; text-align: left; }
.perm-table th { font-weight: 600; color: var(--muted); font-size: 12px; }
.small-text { font-size: 12px; }

/* 확대/축소 컨트롤 */
.zoom-controls { display: inline-flex; align-items: center; gap: 4px; }
.zoom-controls .zoom-btn {
  width: 36px; height: 36px; padding: 0; font-size: 18px; line-height: 1;
  background: var(--card); border: 1px solid var(--border); color: var(--fg); border-radius: 8px;
}
.zoom-controls .zoom-btn:disabled { opacity: 0.4; }
.zoom-label { font-size: 12px; color: var(--muted); margin-right: 2px; }

/* 2단계 인증 */
.qr-image { display: block; margin: 12px 0; border-radius: 8px; background: #fff; padding: 8px; }
.secret-key { font-size: 15px; letter-spacing: 1px; word-break: break-all; background: var(--bg); padding: 4px 8px; border-radius: 6px; }
.setup-steps { padding-left: 20px; line-height: 1.9; font-size: 14px; }
.recovery-codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.recovery-codes code { display: block; padding: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; text-align: center; font-size: 15px; }

/* PC 화면에서 더 넓게 */
@media (min-width: 1200px) {
  .wrap { max-width: 1500px; }
}

/* 폴더 선택기 */
.folder-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
.folder-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; font-size: 14px; border-radius: 6px; cursor: pointer; }
.folder-row:hover { background: var(--bg); }
.folder-name { flex: 1; word-break: break-all; }
.folder-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
