:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f1ece4;
  --text: #1f1b16;
  --muted: #71675b;
  --line: #e5ded3;
  --accent: #d9480f;
  --accent-text: #ffffff;
  --heart: #e03131;
  --danger: #c92a2a;
  --kakao: #fee500;
  --shadow: 0 6px 24px rgba(31, 27, 22, .12);
  --radius: 14px;
  --top-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14120f;
    --surface: #1e1b17;
    --surface-2: #2a2620;
    --text: #f3eee7;
    --muted: #a99f92;
    --line: #36302a;
    --accent: #ff7a3d;
    --accent-text: #1a0d05;
    --shadow: 0 6px 24px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
a { color: inherit; }
img { display: block; }

/* 상단바 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: calc(var(--top-h) + var(--safe-t));
  padding: var(--safe-t) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.brand span { font-weight: 700; font-size: 18px; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 600; white-space: nowrap; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; cursor: pointer;
  display: inline-grid; place-items: center; padding: 0;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.light { color: #fff; }
.avatar-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); padding: 0; overflow: hidden;
  background: var(--surface-2); cursor: pointer; display: grid; place-items: center; font-weight: 700;
}
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

/* 앨범 탭 */
.album-bar {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 10px 16px; position: sticky; top: calc(var(--top-h) + var(--safe-t)); z-index: 15;
  background: var(--bg);
}
.album-bar::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; min-height: 36px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; white-space: nowrap;
}
.chip .n { color: var(--muted); font-weight: 500; margin-left: 4px; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.active .n { color: inherit; opacity: .7; }
.chip.add { border-style: dashed; color: var(--muted); background: transparent; }
.album-tools { display: flex; gap: 8px; padding: 0 16px 8px; flex-wrap: wrap; }
.album-tools .btn { min-height: 34px; padding: 0 12px; font-size: 14px; }

main { padding: 0 0 calc(96px + var(--safe-b)); max-width: 1600px; margin: 0 auto; }

/* 첫 화면 */
.welcome {
  text-align: center; padding: 12vh 24px 48px; max-width: 460px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.welcome h1 { margin: 12px 0 0; font-size: 26px; letter-spacing: -.02em; }
.welcome p { color: var(--muted); margin: 4px 0 20px; }
.kakao-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; max-width: 320px; height: 50px; border-radius: 12px;
  background: var(--kakao); color: rgba(0, 0, 0, .85); font-weight: 700; font-size: 16px; text-decoration: none;
}
.kakao-btn svg { width: 20px; height: 20px; fill: currentColor; }

.notice {
  margin: 12px 16px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
.notice p { margin: 0; flex: 1 1 240px; }
.card { margin: 12px 16px; padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.card h2 { margin: 0 0 4px; font-size: 17px; }
.card p { margin: 0 0 12px; color: var(--muted); }
.row { display: flex; gap: 8px; }
.row input {
  flex: 1; min-width: 0; height: 42px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); font-size: 16px;
}

/* 사진 그리드 */
.month { margin: 18px 16px 8px; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.month small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 2px; }
.tile {
  position: relative; aspect-ratio: 1; padding: 0; border: 0; cursor: pointer; overflow: hidden;
  background: var(--surface-2); display: block; width: 100%;
}
.tile img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s; }
.tile .placeholder {
  position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; font-weight: 700;
}
.tile .badge {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0, 0, 0, .5); color: #fff; display: grid; place-items: center;
}
.tile .badge svg { width: 12px; height: 12px; }
.tile .meta {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 4px; display: flex; gap: 8px;
  font-size: 11px; font-weight: 700; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .55));
}
.tile .meta:empty { display: none; }
.tile .check {
  position: absolute; top: 6px; left: 6px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0, 0, 0, .2); display: none; place-items: center; color: #fff;
}
.tile .check svg { width: 14px; height: 14px; opacity: 0; }
body.selecting .tile .check { display: grid; }
.tile.selected .check { background: var(--accent); border-color: var(--accent); }
.tile.selected .check svg { opacity: 1; }
.tile.selected img { transform: scale(.88); border-radius: 6px; }
.sentinel { height: 1px; }
.empty { text-align: center; color: var(--muted); padding: 60px 24px; }

/* 올리기 버튼(모바일) */
.fab {
  position: fixed; right: 18px; bottom: calc(20px + var(--safe-b)); z-index: 25;
  width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-text); box-shadow: var(--shadow); display: grid; place-items: center;
}
.fab svg { width: 28px; height: 28px; }
body.selecting .fab { display: none; }

.selection-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px calc(10px + var(--safe-b)); background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.selection-actions { display: flex; gap: 4px; }

.drop-overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 22%, transparent); pointer-events: none;
}
.drop-overlay div {
  padding: 24px 32px; border-radius: var(--radius); background: var(--surface); border: 2px dashed var(--accent);
  font-weight: 700; box-shadow: var(--shadow);
}

/* 업로드 진행 */
.upload-panel {
  position: fixed; z-index: 35; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b));
  max-height: 46vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.upload-panel header { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 4px 16px; }
.upload-total { height: 4px; margin: 0 16px 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.upload-total div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.upload-panel ul { list-style: none; margin: 0; padding: 0 16px 12px; overflow-y: auto; }
.upload-panel li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.upload-panel li .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-panel li .status { color: var(--muted); }
.upload-panel li.fail .status { color: var(--danger); }
.upload-panel li .bar { grid-column: 1 / -1; height: 3px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.upload-panel li .bar i { display: block; height: 100%; width: 0; background: var(--accent); }

/* 사진 보기 */
.viewer {
  position: fixed; inset: 0; z-index: 50; background: #000; color: #fff;
  display: grid; grid-template-columns: 1fr; grid-template-rows: 1fr;
  overscroll-behavior: contain;
}
.viewer-stage {
  grid-area: 1 / 1; position: relative; overflow: hidden; touch-action: none; user-select: none;
  display: grid; place-items: center;
}
.viewer-stage .media { transform-origin: center center; will-change: transform; }
.viewer-stage img.media, .viewer-stage video.media {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
}
.viewer-stage video.media { background: #000; }
.viewer-stage .media.animate { transition: transform .22s ease-out, opacity .22s; }
.viewer-stage .no-preview { color: #bbb; text-align: center; padding: 24px; }
.viewer-top {
  grid-area: 1 / 1; align-self: start; z-index: 2;
  display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--safe-t)) 12px 18px;
  background: linear-gradient(rgba(0, 0, 0, .6), transparent); pointer-events: none;
}
.viewer-top > * { pointer-events: auto; }
.viewer-info { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.viewer-info strong { font-size: 15px; }
.viewer-info span { font-size: 12px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-count { font-size: 13px; opacity: .8; }
.viewer-nav {
  grid-area: 1 / 1; z-index: 2; align-self: center; width: 48px; height: 48px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, .14); color: #fff; cursor: pointer; display: none; place-items: center;
}
.viewer-nav svg { width: 26px; height: 26px; }
.viewer-nav.prev { justify-self: start; margin-left: 16px; }
.viewer-nav.next { justify-self: end; margin-right: 16px; }
.viewer-bottom {
  grid-area: 1 / 1; align-self: end; z-index: 2;
  display: flex; justify-content: space-around; padding: 18px 8px calc(8px + var(--safe-b));
  background: linear-gradient(transparent, rgba(0, 0, 0, .65));
}
.vb-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 64px; padding: 6px 4px;
  border: 0; background: none; color: #fff; cursor: pointer; font-size: 12px; text-decoration: none;
}
.vb-btn .ico svg { width: 26px; height: 26px; }
.vb-btn.liked { color: var(--heart); }
.vb-btn.liked .num { color: #fff; }
.viewer.chrome-hidden .viewer-top, .viewer.chrome-hidden .viewer-bottom, .viewer.chrome-hidden .viewer-nav { opacity: 0; pointer-events: none; }
.viewer-top, .viewer-bottom, .viewer-nav { transition: opacity .2s; }

.viewer-side {
  grid-area: 1 / 1; align-self: end; z-index: 3;
  height: min(70dvh, 560px); display: flex; flex-direction: column;
  background: var(--surface); color: var(--text); border-radius: 18px 18px 0 0;
  transform: translateY(102%); transition: transform .25s ease-out;
  padding-bottom: var(--safe-b);
}
.viewer.show-side .viewer-side { transform: translateY(0); }
.side-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; flex-shrink: 0; }
.side-head { padding: 8px 16px 0; }
.side-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-weight: 600; text-decoration: none; font-size: 14px;
}
.pill svg { width: 18px; height: 18px; }
.pill.liked { color: var(--heart); border-color: color-mix(in srgb, var(--heart) 40%, var(--line)); }
.pill.danger { color: var(--danger); }
.likers { margin: 0; font-size: 13px; color: var(--muted); }
.comments { list-style: none; margin: 0; padding: 8px 16px; overflow-y: auto; flex: 1; }
.comments li { display: grid; grid-template-columns: 32px 1fr auto; gap: 2px 10px; padding: 8px 0; }
.comments .av { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); grid-row: span 2; object-fit: cover; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.comments .who { font-weight: 700; font-size: 13px; }
.comments .who time { font-weight: 400; color: var(--muted); margin-left: 6px; }
.comments .body { grid-column: 2; white-space: pre-wrap; word-break: break-word; }
.comments .del { grid-row: 1; grid-column: 3; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px; }
.comments .none { display: block; color: var(--muted); text-align: center; padding: 24px 0; }
.comment-form { display: flex; gap: 8px; padding: 8px 12px 12px; border-top: 1px solid var(--line); align-items: flex-end; }
.comment-form textarea {
  flex: 1; resize: none; min-height: 42px; max-height: 120px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); font-size: 16px; line-height: 1.35;
}
.comment-locked { margin: 0; padding: 12px 16px 16px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }

/* 메뉴 시트 */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .35); }
.sheet {
  position: fixed; z-index: 41; left: 0; right: 0; bottom: 0; padding: 8px 8px calc(12px + var(--safe-b));
  background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
}
.sheet-user { display: flex; align-items: center; gap: 12px; padding: 12px; }
.sheet-user img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
.sheet-user div { display: flex; flex-direction: column; }
.sheet-user span { color: var(--muted); font-size: 13px; }
.sheet-item { display: block; width: 100%; text-align: left; padding: 14px 12px; border: 0; border-radius: 10px; background: none; cursor: pointer; font-weight: 600; }
.sheet-item:hover { background: var(--surface-2); }

/* 관리자 */
.admin {
  position: fixed; inset: 0; z-index: 45; background: var(--bg); display: flex; flex-direction: column;
  padding-top: var(--safe-t);
}
.admin-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 16px; }
.admin-head strong { font-size: 18px; }
.admin-tabs { display: flex; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.admin-tabs button { border: 0; background: none; padding: 8px 14px; border-radius: 999px; cursor: pointer; font-weight: 600; color: var(--muted); }
.admin-tabs button.active { background: var(--text); color: var(--bg); }
.admin-body { flex: 1; overflow-y: auto; padding: 12px 16px calc(24px + var(--safe-b)); max-width: 820px; width: 100%; margin: 0 auto; }
.member { display: grid; grid-template-columns: 44px 1fr; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.member .av { width: 44px; height: 44px; border-radius: 50%; background: var(--surface-2); object-fit: cover; grid-row: span 2; display: grid; place-items: center; font-weight: 700; }
.member .name { font-weight: 700; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.member .sub { color: var(--muted); font-size: 12px; }
.member .acts { grid-column: 2; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.member .acts .btn { min-height: 34px; padding: 0 12px; font-size: 13px; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag.pending { background: #fff3bf; color: #8a6100; }
.tag.approved { background: #d3f9d8; color: #22662f; }
.tag.blocked { background: #ffe3e3; color: #a51d1d; }
.tag.is-admin { background: var(--text); color: var(--bg); }
.setting { padding: 14px 0; border-bottom: 1px solid var(--line); }
.setting label { display: flex; gap: 12px; align-items: center; justify-content: space-between; font-weight: 600; }
.setting p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.setting input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.trash { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.trash figure { margin: 0; }
.trash img, .trash .ph { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.trash figcaption { font-size: 12px; color: var(--muted); margin: 4px 0; }
.trash .btn { width: 100%; min-height: 32px; font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); z-index: 70; transform: translate(-50%, 20px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: #1f1b16; color: #fff;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.desktop-only { display: none; }

@media (min-width: 720px) {
  .tiles { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; padding: 0 16px; }
  .tile { border-radius: 8px; }
  .month { margin: 26px 16px 10px; font-size: 16px; }
  .desktop-only { display: inline-flex; }
  .mobile-only { display: none !important; }
  .upload-panel { left: auto; width: 380px; right: 20px; bottom: 20px; }
  .sheet { left: auto; right: 16px; top: calc(var(--top-h) + var(--safe-t) + 4px); bottom: auto; width: 280px; border-radius: 14px; padding: 8px; }
  .sheet-backdrop { background: transparent; }
  .selection-bar { left: 50%; right: auto; bottom: 20px; transform: translateX(-50%); border-radius: 999px; padding: 8px 8px 8px 20px; border: 1px solid var(--line); min-width: 420px; }
  .tile:hover img { transform: scale(1.03); }
}

@media (min-width: 960px) {
  .viewer { grid-template-columns: 1fr 360px; }
  .viewer-stage, .viewer-top, .viewer-nav { grid-column: 1; }
  .viewer-nav { display: grid; }
  .viewer-bottom { display: none; }
  .viewer-side {
    grid-column: 2; grid-row: 1; align-self: stretch; height: auto; transform: none; border-radius: 0;
    padding-top: var(--safe-t);
  }
  .side-head { padding-top: 16px; }
}

@media (hover: none) and (max-width: 959px) {
  .viewer-nav { display: none; }
}
