/* ── 기본 ─────────────────────────────────────────────────────────── */
:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --text: #1d2229;
    --muted: #6b7480;
    --line: #e2e5ea;
    --accent: #2f6fdf;
    --accent-text: #ffffff;
    --radius: 12px;
    --tile-min: 104px;          /* 휴대폰 3열 기준, 넓은 화면에서는 자동으로 열 증가 */
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171b;
        --card: #1e2228;
        --text: #e7eaee;
        --muted: #9aa3ae;
        --line: #2d333b;
        --accent: #5b8ff0;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
    font-size: 17px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--accent); text-decoration: none; }

h1 { font-size: 1.6rem; margin: .4em 0; }

.page { max-width: 1400px; margin: 0 auto; padding: 12px 12px 48px; }

.muted, .summary { color: var(--muted); }
.summary { margin: .2em 0 .6em; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* ── 머리글 ───────────────────────────────────────────────────────── */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 10px 14px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; color: var(--text); font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar nav { display: flex; align-items: center; gap: 4px; }
.topbar nav a, .topbar nav button {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 6px 10px; border-radius: 8px; border: 0; background: none;
    color: var(--text); font: inherit; cursor: pointer;
}
.topbar nav a:hover, .topbar nav button:hover { background: var(--bg); }
.topbar nav form { margin: 0; }
.topbar nav span { font-size: .9rem; }
@media (max-width: 520px) { .topbar nav span { display: none; } }

/* ── 버튼 ─────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 44px; padding: 8px 16px;
    border: 1px solid var(--line); border-radius: 10px;
    background: var(--card); color: var(--text);
    font: inherit; cursor: pointer;
}
.btn small { color: var(--muted); font-size: .85em; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary small { color: inherit; opacity: .85; }
.btn.big { font-size: 1.15rem; padding: 12px 28px; }
.btn.toggle.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

/* ── 경로 ─────────────────────────────────────────────────────────── */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 8px; font-size: .95rem; }
.crumbs span { color: var(--muted); }

/* ── 첫 화면 ──────────────────────────────────────────────────────── */
.hero { text-align: center; padding: 16px 0; }
.hero img { display: block; width: min(100%, 720px); margin: 12px auto 20px; border-radius: var(--radius); }
h2.section { font-size: 1.1rem; margin: 24px 0 8px; color: var(--muted); }

/* ── 폴더 목록 ────────────────────────────────────────────────────── */
.folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.folder {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px; min-height: 56px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    color: var(--text);
}
.folder:hover { border-color: var(--accent); }
.folder .ico { font-size: 1.4rem; }
.folder .name { overflow-wrap: anywhere; }

/* ── 갤러리 ───────────────────────────────────────────────────────── */
h2.date { font-size: 1.05rem; margin: 22px 0 8px; position: sticky; top: 54px; z-index: 5; background: var(--bg); padding: 4px 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--tile-min), 1fr)); gap: 4px; }
@media (min-width: 900px) { :root { --tile-min: 150px; } }
.tile { position: relative; display: block; aspect-ratio: 1; overflow: hidden; border-radius: 6px; background: var(--line); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .15s; }
.tile:hover img { transform: scale(1.04); }
.tile.video::after {
    content: "▶"; position: absolute; right: 6px; bottom: 4px;
    color: #fff; font-size: .8rem; text-shadow: 0 0 4px rgba(0,0,0,.8);
}

.pager { display: flex; justify-content: center; align-items: center; gap: 6px; margin: 14px 0; }
.pager a {
    min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
    background: var(--card); border: 1px solid var(--line); border-radius: 10px; font-size: 1.2rem;
}
.pager a.disabled { pointer-events: none; opacity: .35; }
.pager span { min-width: 80px; text-align: center; color: var(--muted); }

/* ── 뷰어 (전체 화면, 어두운 배경) ───────────────────────────────── */
body:has(.photo-viewer), body:has(.viewer-missing) { background: #000; color: #eee; }
.photo-viewer { position: fixed; inset: 0; display: flex; flex-direction: column; background: #000; touch-action: pan-y pinch-zoom; }
.viewer-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 8px 12px; background: rgba(0,0,0,.6); z-index: 2;
}
.viewer-bar a { color: #fff; font-size: 1.4rem; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.viewer-bar .info { display: flex; gap: 12px; align-items: baseline; color: #ccc; font-size: .95rem; }
.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.stage img, .stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.stage .heic { text-align: center; color: #ccc; padding: 16px; }
.stage .heic img { width: min(80vw, 270px); }
.nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 56px; height: 96px; display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 2.6rem; background: rgba(0,0,0,.25); border-radius: 10px; z-index: 2;
}
.nav.prev { left: 6px; }
.nav.next { right: 6px; }
@media (hover: none) { .nav { background: none; opacity: .5; } }
.viewer-missing { padding: 40px 16px; text-align: center; }

/* ── 음악 ─────────────────────────────────────────────────────────── */
.player {
    position: sticky; top: 54px; z-index: 5;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 12px; margin: 8px 0 12px;
}
.player .now { font-weight: 600; margin-bottom: 6px; overflow-wrap: anywhere; }
.player audio { width: 100%; }
.player .controls { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.playlist { margin: 0; padding: 0 0 0 2.2em; }
.playlist li { padding: 10px 6px; border-bottom: 1px solid var(--line); cursor: pointer; overflow-wrap: anywhere; }
.playlist li:hover { background: var(--card); }
.playlist li.active { color: var(--accent); font-weight: 700; }

/* ── 검색 ─────────────────────────────────────────────────────────── */
.search { display: flex; gap: 8px; margin: 8px 0 12px; }
.search input {
    flex: 1; min-width: 0; min-height: 44px; padding: 8px 12px; font: inherit;
    border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text);
}
.results { list-style: none; padding: 0; margin: 0; }
.results a { display: block; padding: 10px 4px; border-bottom: 1px solid var(--line); color: var(--text); }
.results .path { display: block; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }

/* ── 로그인 ───────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
    width: min(100%, 360px); display: flex; flex-direction: column; gap: 12px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
}
.login-card h1 { font-size: 1.3rem; text-align: center; margin: 0 0 8px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: .95rem; }
.login-card label.check { flex-direction: row; align-items: center; gap: 8px; }
.login-card input[type=text], .login-card input[type=password], .login-card input:not([type]) {
    min-height: 44px; padding: 8px 12px; font: inherit;
    border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
}
.login-card .error { color: #d33; margin: 0; }

/* ── 관리 ─────────────────────────────────────────────────────────── */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.panel h2 { font-size: 1.1rem; margin: 0 0 10px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 600; font-size: .9rem; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .85rem; background: var(--bg); border: 1px solid var(--line); }
.badge.role-admin { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.cmd { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: .82rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ── 갤러리 관리자 도구 ──────────────────────────────────────────── */
.admin-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0 10px; }
.admin-bar form { display: contents; }
.btn.on { border-color: var(--accent); color: var(--accent); }
.tile.is-hidden img { opacity: .35; filter: grayscale(1); }
.tile.is-hidden::before {
    content: "숨김"; position: absolute; left: 4px; top: 4px; z-index: 1;
    font-size: .7rem; padding: 1px 6px; border-radius: 999px; background: rgba(0,0,0,.65); color: #fff;
}
.tile.selectable { cursor: pointer; }
.tile.selectable input { position: absolute; right: 6px; top: 6px; width: 22px; height: 22px; z-index: 2; accent-color: var(--accent); }
.tile.selectable:has(input:checked) { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile.selectable:has(input:checked) img { filter: brightness(.75); }
.viewer-bar .badge { color: #fff; background: rgba(255,255,255,.15); border-color: transparent; }
details summary { cursor: pointer; margin: 8px 0; }
.actions form { margin: 0; }

/* ── 내 계정 (비밀번호 변경) ──────────────────────────────────────── */
.form-stack { display: flex; flex-direction: column; gap: 12px; max-width: 420px; }
.form-stack label { display: flex; flex-direction: column; gap: 4px; font-size: .95rem; }
.form-stack input[type=password] {
    min-height: 44px; padding: 8px 12px; font: inherit;
    border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
}
.form-stack .actions { margin: 4px 0 0; }
.notice { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); }
.notice.ok { color: #1a7f37; border-color: #1a7f3755; background: #1a7f3712; }
.notice.error { color: #d33; border-color: #dd333355; background: #dd333312; }

/* ── 업로드 ───────────────────────────────────────────────────────── */
.btn.danger { color: #d33; border-color: #dd333366; }
.upload-panel .actions { margin: 0 0 8px; align-items: flex-start; }
.upload-panel .actions form { margin: 0; }
.upload-panel .hint { font-size: .85rem; margin: 8px 0 0; }
.mkdir summary { list-style: none; display: flex; width: fit-content; margin: 0; }   /* 줄 상자 여백 없이 옆 버튼과 높이 맞춤 */
.mkdir[open] { flex-basis: 100%; }          /* 열면 이름 입력 줄을 한 줄 전체로 */
.mkdir summary::-webkit-details-marker { display: none; }
.mkdir[open] summary { border-color: var(--accent); color: var(--accent); }
.inline-form { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.inline-form input[type=text] {
    min-height: 44px; padding: 8px 12px; font: inherit; flex: 1 1 160px;
    border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
}
.up-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.up-list:empty { display: none; }
.up-list li { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg); }
.up-head { display: flex; align-items: center; gap: 8px; }
.up-name { flex: 1; overflow-wrap: anywhere; font-size: .95rem; }
.up-x { border: 0; background: none; color: var(--muted); font-size: 1.1rem; min-width: 36px; min-height: 36px; cursor: pointer; }
.up-list li.ok .up-x, .up-list li.err .up-x { visibility: hidden; }
.up-list progress { width: 100%; height: 8px; accent-color: var(--accent); }
.up-state { font-size: .85rem; }
.up-list li.ok .up-state { color: #1a7f37; }
.up-list li.err .up-state { color: #d33; }
.up-reload { margin-top: 8px; }
.viewer-bar .tools { display: flex; align-items: center; }
.viewer-bar .tools form { margin: 0; }
.viewer-bar .tools button { color: #fff; background: none; border: 0; font-size: 1.2rem; min-width: 44px; min-height: 44px; cursor: pointer; }
.viewer-bar .by { color: #aaa; }
.warn { color: #d33; }
/* 썸네일 준비 전: 자리표시 위에 파일 이름 */
.tile .cap {
    position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 5px 14px;
    font-size: .72rem; line-height: 1.25; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.75));
    overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.up-state a { font-weight: 600; }
