:root {
    --bg: #111;
    --panel: #1b1b1b;
    --fg: #eee;
    --muted: #888;
    --accent: #4da3ff;
    --danger: #ff6b6b;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Hiragino Sans, "Yu Gothic", sans-serif;
}

a { color: inherit; }

.muted { color: var(--muted); font-size: 0.85rem; }
.error { color: var(--danger); font-size: 0.85rem; }

/* ログイン画面 */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-box {
    background: var(--panel);
    padding: 32px;
    border-radius: 12px;
    width: 90%;
    max-width: 320px;
    text-align: center;
}
.login-box h1 { margin: 0 0 4px; font-size: 1.3rem; }
.login-box input[type="password"] {
    width: 100%;
    padding: 10px;
    margin: 16px 0;
    border-radius: 6px;
    border: 1px solid #333;
    background: #0d0d0d;
    color: var(--fg);
    font-size: 1rem;
}
.login-box button {
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
}

/* ヘッダー */
.site-header {
    padding: 16px 16px 12px;
    border-bottom: 1px solid #222;
}
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.breadcrumbs { font-size: 0.9rem; }
.breadcrumbs .crumb { text-decoration: none; }
.breadcrumbs .crumb:not(.current):hover { text-decoration: underline; }
.breadcrumbs .current { color: var(--muted); }
.breadcrumbs .sep { color: var(--muted); margin: 0 6px; }
.logout-link { font-size: 0.85rem; color: var(--muted); text-decoration: none; }
.logout-link:hover { color: var(--fg); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid #333;
    background: #222;
    color: var(--fg);
    font-size: 0.85rem;
    cursor: pointer;
}
.btn:hover { background: #2a2a2a; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(1.1); }

.sort-select {
    appearance: auto;
    margin-left: auto;
}

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* グリッド共通 */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 4px;
    padding: 12px;
}
.folders-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

.cell {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: #1c1c1c;
    display: block;
    text-decoration: none;
}
.cell img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.2s ease;
}
.cell:hover img { transform: scale(1.05); }

.photo-date {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 3px 6px;
    font-size: 0.7rem;
    text-align: center;
    background: rgba(0,0,0,0.55);
    color: #fff;
    pointer-events: none;
}

.folder-cell-wrap { background: transparent; }
.folder-cell-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #1c2733;
    border-radius: 8px;
    width: 100%;
    height: 100%;
    text-decoration: none;
}
.folder-cell-link:hover { background: #223244; }
.folder-icon { font-size: 2.2rem; }
.folder-name {
    font-size: 0.85rem;
    text-align: center;
    padding: 0 8px;
    word-break: break-word;
}

/* 削除ボタン(写真・フォルダ共通の小さい×) */
.del-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
}
.del-btn:hover { background: var(--danger); }

.lb-delete-btn {
    background: #333;
    color: #fff;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
}
.lb-delete-btn:hover { background: var(--danger); }

/* 動画のグリッドプレースホルダー */
.video-thumb {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #1a1a24;
    color: #fff;
}
.video-play {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    padding-left: 3px;
}
.video-name {
    font-size: 0.7rem;
    color: var(--muted);
    text-align: center;
    padding: 0 8px;
    word-break: break-word;
    max-width: 100%;
}

/* いいねボタン(グリッド) */
.like-btn {
    position: absolute;
    left: 6px;
    bottom: 6px;
    display: flex;
    align-items: center;
    gap: 3px;
    border: none;
    background: rgba(0,0,0,0.55);
    color: #fff;
    border-radius: 14px;
    padding: 3px 9px;
    font-size: 0.75rem;
    cursor: pointer;
    z-index: 5;
}
.like-btn .like-icon { font-size: 0.85rem; opacity: 0.7; }
.like-btn.liked .like-icon { color: #ff5c7a; opacity: 1; }
.like-btn.liked { background: rgba(255,92,122,0.25); }

/* ライトボックス */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.96);
    z-index: 100;
    display: flex;
    flex-direction: column;
}
.lightbox[hidden] { display: none; }

.lb-imgwrap {
    position: relative;
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    touch-action: none;
}
.lb-imgwrap.grabbing { cursor: grabbing; }

#lb-img {
    max-width: 100%;
    max-height: 100%;
    user-select: none;
    -webkit-user-drag: none;
    will-change: transform;
}

#lb-video {
    max-width: 100%;
    max-height: 100%;
    width: 100%;
}

.lb-progress {
    position: absolute;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    width: min(320px, 80%);
    background: rgba(0,0,0,0.7);
    border-radius: 10px;
    padding: 12px 16px;
    text-align: center;
}
.lb-progress-bar {
    background: #333;
    border-radius: 6px;
    height: 8px;
    overflow: hidden;
    margin-bottom: 8px;
}
.lb-progress-fill {
    background: var(--accent);
    height: 100%;
    width: 0%;
    transition: width 0.15s ease;
}
#lb-progress-text { margin: 0; font-size: 0.8rem; color: var(--fg); }

.lb-like-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #333;
    color: #fff;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
}
.lb-like-btn .like-icon { opacity: 0.7; }
.lb-like-btn.liked .like-icon { color: #ff5c7a; opacity: 1; }
.lb-like-btn.liked { background: rgba(255,92,122,0.25); }

.lb-bottom-bar {
    text-align: center;
    padding: 8px 0 14px;
}
.btn-quality {
    background: #333;
    color: #fff;
    border: 1px solid #444;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}
.btn-quality:hover { background: #3d3d3d; }
.btn-quality[hidden] { display: none; }

.lb-nav {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.5);
    color: #fff;
    border: none;
    width: 40px;
    height: 32px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    z-index: 102;
    display: none;
}
.lb-nav:disabled { opacity: 0.25; cursor: default; }
.lb-nav-prev { top: 56px; }
.lb-nav-next { bottom: 70px; }

@media (min-width: 700px) {
    .lb-nav { display: block; }
}

.lb-right-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 102;
    display: flex;
    align-items: center;
    gap: 8px;
}

.lb-close {
    font-size: 1.6rem;
    background: none;
    border: none;
    color: var(--fg);
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
}

.lb-download-menu {
    position: absolute;
    top: 14px;
    left: 16px;
    z-index: 102;
}
.lb-dl-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
}
.lb-dl-options {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: var(--panel);
    border: 1px solid #333;
    border-radius: 8px;
    overflow: hidden;
    min-width: 200px;
}
.lb-dl-options[hidden] { display: none; }
.lb-dl-options a {
    display: block;
    padding: 10px 14px;
    text-decoration: none;
    font-size: 0.85rem;
    color: var(--fg);
}
.lb-dl-options a:hover { background: #2a2a2a; }

.lb-hint {
    text-align: center;
    color: var(--muted);
    font-size: 0.75rem;
    margin: 0;
    padding: 8px 0 12px;
}

/* モーダル */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.modal[hidden] { display: none; }
.modal-box {
    background: var(--panel);
    padding: 24px;
    border-radius: 12px;
    width: 90%;
    max-width: 380px;
}
.modal-box h2 { margin: 0 0 12px; font-size: 1.1rem; }
.modal-box input[type="text"] {
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #333;
    background: #0d0d0d;
    color: var(--fg);
    font-size: 1rem;
    margin-top: 8px;
}
.modal-box input[type="file"] {
    width: 100%;
    margin-top: 12px;
    color: var(--fg);
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

.upload-progress { margin-top: 14px; }
.upload-bar {
    background: #333;
    border-radius: 6px;
    height: 8px;
    overflow: hidden;
}
.upload-bar-fill {
    background: var(--accent);
    height: 100%;
    width: 0%;
    transition: width 0.2s ease;
}

@media (max-width: 600px) {
    .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 2px; padding: 6px; }
    .folders-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
    .toolbar { width: 100%; }
    .btn { flex: 1; }
}
