/* 기본 변수 */
:root {
    --ink: #1c2838;
    --ink-2: #4a586b;
    --ink-3: #7f8a99;
    --line: rgba(28, 40, 56, 0.1);
    --sky: #2b8bd0;
    --sky-soft: rgba(111, 187, 232, 0.16);
    --pink: #c4609a;
    --pink-soft: rgba(233, 168, 213, 0.28);
    --card: rgba(255, 255, 255, 0.78);
    --card-solid: #f7fbfe;
    --online: #23a55a;
    --idle: #f0b232;
    --dnd: #f23f43;
    --offline: #80848e;
    --spotify: #1db954;
    --radius: 18px;
    /* 디스코드 프로필 테마 색 (스크립트가 최신 값으로 덮어씀) */
    --theme-1: 153 236 255;
    --theme-2: 45 255 245;
}

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

[hidden] {
    display: none !important;
}

body {
    font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    color: var(--ink);
    background: #8fcdf0;
    min-height: 100vh;
    min-height: 100svh;
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

img {
    display: block;
}

/* 입장 화면 */
.intro {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    width: 100%;
    border: none;
    background: #101a28;
    color: rgba(255, 255, 255, 0.72);
    font: inherit;
    cursor: pointer;
    transition: opacity 0.6s ease, visibility 0s 0.6s;
}

.intro:focus-visible {
    outline: none;
}

.intro-text {
    font-size: 0.82rem;
    letter-spacing: 0.08em;
    animation: breathe 2.4s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { opacity: 0.45; }
    50% { opacity: 1; }
}

.intro.is-leaving {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* 입장하기 전엔 카드 등장 애니메이션을 멈춰 둠 */
body.is-intro .card,
body.is-intro .fold-bubble {
    animation-play-state: paused;
}

/* 배경 영상 */
.video-background {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    background: #8fcdf0 url('assets/bg-poster.jpg') center / cover no-repeat;
}

.video-background video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 위아래만 살짝 어둡게 해서 시선이 가운데로 */
.video-background::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(
        to bottom,
        rgba(8, 24, 48, 0.38) 0%,
        rgba(8, 24, 48, 0) 30%,
        rgba(8, 24, 48, 0) 68%,
        rgba(8, 24, 48, 0.42) 100%
    );
}

/* 레이아웃 */
.page {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 480px;
    padding: 24px 16px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* 카드 */
.card {
    position: relative;
    isolation: isolate;
    /* 유리 카드 위에 테마 색을 위→아래로 은은하게 */
    background:
        linear-gradient(to bottom, rgb(var(--theme-1) / 0.3), rgb(var(--theme-2) / 0.14)),
        var(--card);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--radius);
    box-shadow: 0 24px 60px -24px rgba(16, 58, 104, 0.45);
    overflow: hidden;
    animation: rise 0.6s ease-out backwards;
    will-change: transform;
    cursor: grab;
}

/* 끌어서 옮기기: 터치로 끌 때 화면이 같이 스크롤되지 않게,
   더블클릭해도 글자가 선택되지 않게 */
.card,
.fold-bubble {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

body.is-dragging,
body.is-dragging * {
    cursor: grabbing !important;
    -webkit-user-select: none;
    user-select: none;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .card {
        background:
            linear-gradient(to bottom, rgb(var(--theme-1) / 0.3), rgb(var(--theme-2) / 0.14)),
            var(--card-solid);
    }
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* 디스코드 배너 비율(5:2) 그대로 */
.banner {
    aspect-ratio: 5 / 2;
    background: #8fcdf0;
}

.banner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 디스코드 프로필 효과: 카드 너비에 맞춰 위에서부터 덮고, 클릭은 통과 */
.profile-effect {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
}

.profile-effect img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
}

/* 접기 버튼 */
.fold-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 3;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: var(--ink-2);
    font-size: 0.85rem;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.2s, color 0.2s;
}

.fold-btn:focus-visible {
    outline: 2px solid var(--sky);
    outline-offset: 2px;
}

/* 접기: 카드가 살짝 작아지며 사라지고 프사 버튼만 남음 */
.card.is-closing {
    animation: fold-away 0.22s ease-in forwards;
}

@keyframes fold-away {
    to {
        opacity: 0;
        transform: scale(0.92);
    }
}

.page.is-folded .card {
    display: none;
}

.fold-bubble {
    display: none;
    position: relative;
    width: 88px;
    height: 88px;
    margin: 0 auto;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: none;
    cursor: pointer;
    box-shadow: 0 16px 36px -14px rgba(16, 58, 104, 0.55);
    animation: pop 0.3s ease-out backwards;
    transition: transform 0.2s ease;
}

.page.is-folded .fold-bubble {
    display: block;
}

.fold-bubble:focus-visible {
    outline: 2px solid var(--sky);
    outline-offset: 6px;
}

@keyframes pop {
    from {
        opacity: 0;
        transform: scale(0.6);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.card-body {
    padding: 0 22px 22px;
}

/* 프사 (배너에 반쯤 걸침) + 오른쪽 배지 */
.card-top {
    display: flex;
    align-items: flex-end;
    margin-top: -54px;
}

.avatar-wrap {
    position: relative;
    width: 108px;
    height: 108px;
    flex-shrink: 0;
}

.avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    background: #fff;
    box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.92);
}

/* 디스코드 아바타 장식은 프로필 사진보다 20% 큼 */
.avatar-deco {
    position: absolute;
    top: -10%;
    left: -10%;
    width: 120%;
    height: 120%;
    pointer-events: none;
}

.status-dot {
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--offline);
    border: 4px solid #fff;
}

.status-dot.online { background: var(--online); }
.status-dot.idle { background: var(--idle); }
.status-dot.dnd { background: var(--dnd); }
.status-dot.offline { background: var(--offline); }

/* 배너 아래 빈 자리(프사 아랫부분 높이)의 가운데에 */
.card-side {
    flex: 1;
    min-width: 0;
    min-height: 54px;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    align-content: center;
    gap: 6px;
    padding-left: 12px;
}

.badges {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 28px;
    padding: 0 6px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid var(--line);
}

.badges img {
    width: 20px;
    height: 20px;
}

.chip {
    display: inline-flex;
    align-items: center;
    height: 28px;
    padding: 0 10px;
    border-radius: 8px;
    background: rgb(var(--theme-1) / 0.35);
    color: var(--ink-2);
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

/* 이름 + 서버 태그 */
.name-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 8px;
    row-gap: 4px;
}

.guild-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    padding: 2px 7px 2px 5px;
    border-radius: 6px;
    background: var(--pink-soft);
    color: var(--pink);
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.guild-tag img {
    width: 16px;
    height: 16px;
    image-rendering: pixelated;
}

/* 이름 */
.identity {
    position: relative;
    margin-top: 12px;
    border-radius: 12px;
    overflow: hidden;
}

.nameplate {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: right center;
    pointer-events: none;
}

.identity.has-plate .identity-text {
    padding: 10px 12px;
}

.identity-text {
    position: relative;
}

.display-name {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    word-break: break-all;
}

.handle {
    font: inherit;
    font-size: 0.9rem;
    color: var(--ink-2);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
}

.handle:focus-visible {
    outline: 2px solid var(--sky);
    outline-offset: 2px;
    border-radius: 4px;
}

.presence {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--ink-3);
}

/* 상태 앞 태그는 한 줄 높이에 맞게 조금 작게 */
.presence .chip {
    height: 24px;
    margin-right: 2px;
    padding: 0 8px;
}

.device:not(:empty)::before {
    content: '·';
    margin-right: 6px;
}

/* 커스텀 상태 */
.custom-status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid var(--line);
    border-radius: 12px;
    font-size: 0.9rem;
    color: var(--ink-2);
    word-break: break-word;
}

.custom-status-emoji {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* 활동 / Spotify */
.activity {
    display: block;
    margin-top: 16px;
    padding: 12px;
    background: rgb(var(--theme-1) / 0.22);
    border-radius: 14px;
    color: inherit;
    text-decoration: none;
}

.activity-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ink-3);
}

.activity-time {
    color: var(--online);
    font-variant-numeric: tabular-nums;
}

.spotify .fa-spotify {
    color: var(--spotify);
}

.activity-body {
    display: flex;
    align-items: center;
    gap: 12px;
}

.activity-art {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.7);
    display: grid;
    place-items: center;
    overflow: hidden;
    color: var(--ink-3);
    font-size: 1.4rem;
}

.activity-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.activity-text {
    flex: 1;
    min-width: 0;
}

.activity-name {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.activity-sub {
    font-size: 0.82rem;
    color: var(--ink-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.activity-sub:empty {
    display: none;
}

.progress {
    height: 4px;
    margin-top: 8px;
    background: rgba(28, 40, 56, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--spotify);
    transition: width 1s linear;
}

.time-info {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 0.72rem;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
}

/* 소셜 링크 */
.links {
    display: flex;
    gap: 8px;
    margin-top: 22px;
}

.link {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--ink);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.link i {
    font-size: 1.05rem;
}

.link:focus-visible {
    outline: 2px solid var(--sky);
    outline-offset: 2px;
}

.footer {
    margin-top: 18px;
    text-align: center;
    font-size: 0.72rem;
    color: var(--ink-3);
}

/* 방문자 수 · 하트: 왼쪽 아래, 배경이 비치는 유리 (음악 버튼과 높이 중심을 맞춤) */
.stats {
    position: fixed;
    left: 16px;
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 6px);
    z-index: 10;
    display: flex;
    gap: 8px;
    /* 하트 연타해도 글자 선택·화면 확대가 안 되게 */
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

.stat {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 1px 3px rgba(8, 24, 48, 0.45);
}

.stat i {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.85);
}

.heart-btn {
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.heart-btn i {
    color: #ffb8de;
}

.heart-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.heart-btn.is-pop > i:not(.heart-float) {
    animation: heart-pop 0.25s ease-out;
}

@keyframes heart-pop {
    50% { transform: scale(1.35); }
}

/* 위로 떠오르는 작은 하트 */
.heart-float {
    position: absolute;
    left: 14px;
    top: 10px;
    pointer-events: none;
    animation: heart-float 0.8s ease-out forwards;
}

@keyframes heart-float {
    to {
        opacity: 0;
        transform: translate(var(--drift), -36px) scale(0.7);
    }
}

/* 배경음악: 오른쪽 아래 동그란 버튼 + 위로 열리는 패널 */
.music {
    position: fixed;
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 10;
}

.music-btn {
    position: relative;
    width: 48px;
    height: 48px;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 10px 28px -12px rgba(16, 58, 104, 0.5);
    color: var(--ink-2);
    font-size: 1.05rem;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.2s, color 0.2s;
}

.music-btn:focus-visible {
    outline: 2px solid var(--sky);
    outline-offset: 3px;
}

/* 재생 중이면 음표 대신 막대 3개 */
.eq {
    display: none;
    align-items: flex-end;
    gap: 3px;
    height: 16px;
}

.eq span {
    width: 3px;
    height: 100%;
    border-radius: 2px;
    background: var(--sky);
    transform-origin: bottom;
    animation: eq 0.9s ease-in-out infinite;
}

.eq span:nth-child(2) { animation-delay: -0.3s; }
.eq span:nth-child(3) { animation-delay: -0.6s; }

@keyframes eq {
    0%, 100% { transform: scaleY(0.35); }
    50% { transform: scaleY(1); }
}

.music-btn.is-playing i {
    display: none;
}

.music-btn.is-playing .eq {
    display: flex;
}

.music-panel {
    position: absolute;
    right: 0;
    bottom: 60px;
    width: 264px;
    max-width: calc(100vw - 32px);
    padding: 14px;
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 16px;
    box-shadow: 0 20px 48px -20px rgba(16, 58, 104, 0.5);
    transform-origin: bottom right;
    /* 닫혀 있어도 플레이어는 살아 있어야 음악이 안 끊김 */
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px) scale(0.97);
    transition: opacity 0.18s, transform 0.18s, visibility 0s 0.18s;
}

.music.is-open .music-panel {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: opacity 0.18s, transform 0.18s;
}

.music-title {
    margin-bottom: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ink-3);
}

.playlist {
    list-style: none;
}

.track {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px;
    border: none;
    border-radius: 10px;
    background: none;
    font: inherit;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
}

.track.is-active {
    background: rgb(var(--theme-1) / 0.3);
}

.track:focus-visible {
    outline: 2px solid var(--sky);
    outline-offset: -2px;
}

.track-cover {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 8px;
    object-fit: cover;
    background: #2a3446;
}

.track-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.track-title {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-artist {
    font-size: 0.75rem;
    color: var(--ink-3);
}

.track i {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #fff;
    color: var(--sky);
    font-size: 0.72rem;
}

.music-error {
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--dnd);
}

/* 재생 위치 */
.music-progress {
    margin-top: 10px;
    padding: 0 4px;
}

.music-time {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
}

.music-volume {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
    padding: 0 4px;
    color: var(--ink-3);
    font-size: 0.85rem;
}

/* 얇은 슬라이더 (누르는 영역은 넉넉하게) */
.music-panel input[type='range'] {
    -webkit-appearance: none;
    appearance: none;
    display: block;
    width: 100%;
    height: 18px;
    background: linear-gradient(to right, var(--sky) var(--fill, 0%), rgba(28, 40, 56, 0.12) var(--fill, 0%)) center / 100% 4px no-repeat;
    border-radius: 2px;
    cursor: pointer;
}

.music-panel input[type='range']::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(28, 40, 56, 0.15), 0 1px 3px rgba(16, 58, 104, 0.3);
}

.music-panel input[type='range']::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border: none;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(28, 40, 56, 0.15), 0 1px 3px rgba(16, 58, 104, 0.3);
}

.music-panel input[type='range']:focus-visible {
    outline: 2px solid var(--sky);
    outline-offset: 2px;
}

.music-volume input {
    flex: 1;
}

/* 마우스가 있는 기기에서만 호버 효과 */
@media (hover: hover) {
    .music-btn:hover {
        background: #fff;
        color: var(--ink);
    }

    .track:hover {
        background: rgb(var(--theme-1) / 0.22);
    }

    .track.is-active:hover {
        background: rgb(var(--theme-1) / 0.36);
    }

    .link:hover {
        background: #fff;
        border-color: var(--sky);
        color: var(--sky);
    }

    .handle:hover {
        color: var(--ink);
    }

    .heart-btn:hover {
        background: rgba(255, 255, 255, 0.26);
        border-color: rgba(255, 255, 255, 0.6);
    }

    .fold-btn:hover {
        background: #fff;
        color: var(--ink);
    }

    .fold-bubble:hover {
        transform: scale(1.05);
    }

    a.activity:hover {
        background: rgb(var(--theme-1) / 0.34);
    }
}

/* 세로 모바일: 영상 속 얼굴이 화면에 들어오도록 위치 조정 */
@media (max-width: 768px) and (orientation: portrait) {
    .video-background {
        background-position: 30% 50%;
    }

    .video-background video {
        object-position: 30% 50%;
    }
}

@media (max-width: 360px) {
    .card-body {
        padding: 0 16px 16px;
    }

    .display-name {
        font-size: 1.4rem;
    }

    .avatar-wrap {
        width: 84px;
        height: 84px;
    }

    .card-top {
        margin-top: -42px;
    }

    .card-side {
        min-height: 42px;
        padding-left: 8px;
    }

    .link {
        gap: 6px;
        padding: 11px 6px;
        font-size: 0.82rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .card,
    .fold-bubble {
        animation: none;
    }

    .fold-bubble {
        transition: none;
    }

    .eq span {
        animation: none;
    }

    .intro-text,
    .heart-btn.is-pop > i:not(.heart-float) {
        animation: none;
    }

    .intro {
        transition: none;
    }

    .music-panel,
    .music.is-open .music-panel {
        transition: none;
    }

    .progress-bar {
        transition: none;
    }
}
