:root {
    --bg: #fdf6ec;
    --fg: #3a2e26;
    --accent: #d97a4a;
    --frame: #fff;
    --shadow: 0 8px 32px rgba(58, 46, 38, 0.15);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
    background: var(--bg);
    color: var(--fg);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 100px 16px 16px;  /* 위쪽 말풍선 공간 확보 */
    min-height: 100vh;
    overflow-x: hidden;
}

main {
    width: 100%;
    max-width: min(1400px, 95vw);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 100px;  /* 아래쪽 말풍선이 입력창과 안 겹치게 */
}

.stage {
    position: relative;
    display: inline-block;  /* 사진 크기에 맞춰서 줄어듦 */
}

.photo-frame {
    position: relative;
    background: var(--frame);
    padding: 12px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    min-height: 200px;
    cursor: pointer;
    transition: transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

#photo {
    -webkit-user-drag: none;
    pointer-events: none;
}

.photo-frame:hover {
    transform: translateY(-2px);
}

.photo-frame:active {
    transform: translateY(0);
}

#photo {
    /* 좌우/상하에 말풍선이 들어갈 공간을 viewport에서 빼고 사진 크기 결정 */
    max-width: min(1000px, calc(100vw - 440px));
    max-height: calc(100vh - 290px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    display: block;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#photo.loaded {
    opacity: 1;
}

.loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--fg);
    opacity: 0.6;
    font-size: 0.9rem;
}

.loading.hidden {
    display: none;
}

button {
    padding: 12px 28px;
    font-size: 1rem;
    font-family: inherit;
    color: white;
    background: var(--accent);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

button:hover {
    background: #c66a3a;
}

button:active {
    transform: scale(0.97);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── 액션 버튼 (공유 / 좋아요) ────────────────────── */

.photo-actions {
    position: absolute;
    bottom: 24px;
    right: 24px;
    display: flex;
    gap: 8px;
    z-index: 10;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px 10px 12px;
    margin: 0;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: none;
    border-radius: 999px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--fg);
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.action-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.action-btn:active {
    transform: scale(0.95);
}

.action-btn > * {
    pointer-events: none;
}

.action-btn svg {
    width: 22px;
    height: 22px;
}

#share-btn {
    padding: 10px;
}

.like-btn .heart {
    fill: none;
    stroke: var(--fg);
    stroke-width: 2;
    stroke-linejoin: round;
    transition: fill 0.2s ease, stroke 0.2s ease, transform 0.2s ease;
}

.like-btn[aria-pressed="true"] .heart {
    fill: #e63946;
    stroke: #e63946;
}

.like-btn.pulse .heart {
    animation: heart-pulse 0.4s ease;
}

@keyframes heart-pulse {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.4); }
    100% { transform: scale(1); }
}

#share-btn.pulse svg {
    animation: heart-pulse 0.4s ease;
}

.like-count {
    min-width: 1ch;
    font-variant-numeric: tabular-nums;
}

/* ── 댓글 (스캐터 말풍선) ─────────────────────────── */

.bubble-scatter {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}

.comment-bubble {
    position: absolute;
    pointer-events: auto;
    background: white;
    color: var(--fg);
    border-radius: 14px;
    padding: 10px 14px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
    /* 절대 위치에서도 폭이 안 쪼그라들도록 명시 */
    width: max-content;
    max-width: 180px;
    font-size: 0.92rem;
    line-height: 1.4;
    word-break: keep-all;       /* 한글 단어 중간에 안 끊김 */
    overflow-wrap: anywhere;    /* 그래도 안 들어가면 강제 줄바꿈 */
    animation: bubble-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: center;
}

@keyframes bubble-in {
    from { opacity: 0; transform: scale(0.6) rotate(0deg); }
    to   { opacity: 1; }
}

/* 어드민 모드: × 삭제 버튼 노출 */
.comment-delete {
    display: none;
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #e63946;
    color: white;
    font-size: 14px;
    line-height: 1;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

body.admin-mode .comment-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.comment-input {
    display: flex;
    gap: 8px;
    width: min(520px, 100%);
}

.comment-input input {
    flex: 1;
    min-width: 0;
    padding: 12px 18px;
    border: 1px solid rgba(58, 46, 38, 0.15);
    border-radius: 999px;
    font-size: 0.95rem;
    font-family: inherit;
    background: white;
    color: var(--fg);
}

.comment-input input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.comment-input button {
    padding: 12px 20px;
    font-size: 0.95rem;
    flex-shrink: 0;
}

/* ── 어드민 트리거 (우상단 작은 톱니) ──────────── */

#admin-trigger {
    position: fixed;
    top: 10px;
    right: 12px;
    width: 28px;
    height: 28px;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    opacity: 0.18;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    z-index: 100;
    color: var(--fg);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#admin-trigger:hover {
    opacity: 0.7;
    transform: rotate(45deg);
    background: transparent;  /* 글로벌 button:hover 오버라이드 */
}

body.admin-mode #admin-trigger {
    opacity: 0.9;
    color: var(--accent);
}

/* ── 업로드 버튼 (관리자 모드일 때만) ──────────── */

#upload-trigger {
    position: fixed;
    top: 8px;
    right: 48px;
    width: 32px;
    height: 32px;
    padding: 0;
    margin: 0;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    z-index: 100;
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}

#upload-trigger:hover {
    transform: scale(1.1);
    background: #c66a3a;
}

#upload-trigger[hidden] {
    display: none;
}

#upload-trigger:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* ── 토스트 알림 ─────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(58, 46, 38, 0.92);
    color: white;
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 0.9rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 200;
    max-width: 80vw;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── 좁은 화면 (< 900px): 스캐터 → 스택 ──────────── */

@media (max-width: 899px) {
    body {
        padding: 16px;  /* 위 말풍선 공간 더 이상 필요 없음 */
    }
    main {
        gap: 16px;
    }
    #photo {
        /* 사진 다시 크게 */
        max-width: 95vw;
        max-height: 65vh;
    }
    .bubble-scatter {
        position: static;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        min-height: 0;
    }
    .bubble-scatter:empty {
        display: none;
    }
    .comment-bubble {
        position: static;
        transform: none !important;
        max-width: min(80vw, 280px);
        animation: bubble-in-mobile 0.25s ease;
    }
    @keyframes bubble-in-mobile {
        from { opacity: 0; transform: translateY(-4px); }
        to   { opacity: 1; transform: translateY(0); }
    }
}

@media (max-width: 480px) {
    .photo-frame {
        padding: 8px;
    }
    #photo {
        max-height: 55vh;
    }
    .photo-actions {
        bottom: 16px;
        right: 16px;
    }
    .action-btn {
        padding: 8px 14px 8px 10px;
        font-size: 0.95rem;
    }
    .action-btn svg {
        width: 20px;
        height: 20px;
    }
    #share-btn {
        padding: 8px;
    }
}
