body {
    width: 100%;
    max-width: 440px;
    margin: 0 auto;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Pretendard', sans-serif;
    font-weight: 500; /* Medium */
}

/* 말풍선 색상 변수 */
:root {
    --bubble-bg-normal: white;
    --bubble-bg-wrong: #fff3cd;
    --bubble-bg-celebration: #d4edda;
}

.container {
    width: 100%;
    flex: 1;
    background-image: url('../img/bg 65.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0; /* flex에서 스크롤 작동을 위해 필요 */
    padding-bottom: 10px;
}

.logo {
    display: block;
    width: auto;
    max-width: 200px;
    height: auto;
    padding-top: 50px;
    margin: 20px auto 24px;
    opacity: 0;
    animation: fadeIn 0.8s ease-in forwards;
    z-index: 2;
    position: relative;
}

.logo-subtitle {
    margin: 0 auto 66px;
    text-align: center;
    font-size: 8pt;
    color: rgba(255, 255, 255, 0.85);
    font-family: 'Pretendard', sans-serif;
    font-weight: 500;
    letter-spacing: 0.4px;
    z-index: 2;
    position: relative;
    opacity: 0;
    animation: fadeIn 0.8s ease-in forwards;
    animation-delay: 0.5s;
}

/* 채팅 메시지 컨테이너 */
.chat-message {
    position: relative;
    z-index: 2;
    margin: 20px;
    margin-top: 0px;
    opacity: 0;
    animation: showText 0s 1.2s forwards;
    /* 수평 배치: 프로필 이미지(왼쪽) + 텍스트 영역(오른쪽) */
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.chat-date-divider {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    margin: 28px auto 50px;
    border-radius: 999px;
    background-color: rgba(0, 0, 0, 0.55);
    color: rgba(255, 255, 255, 0.9);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.4px;
    text-align: center;
    position: relative;
    z-index: 2;
    width: fit-content;
    left: 50%;
    transform: translateX(-50%);
}

/* 텍스트 영역 컨테이너 (닉네임 + 말풍선) */
.message-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0; /* flexbox에서 overflow 방지 */
}

/* 메시지 헤더 (발신자 이름) */
.message-header {
    margin-left: 5px;
    margin-bottom: 8px;
}

.profile-image {
    width: 55px;
    height: 55px;
    border-radius: 30%;
    object-fit: cover;
    flex-shrink: 0;
    /* 텍스트 영역의 중간 높이에 위치하도록 */
    align-self: top;
    margin-top: 12px;
    object-position: center; /* 이미지 중심 부분을 보여줌 */
    /* 이미지 다운로드 방지 */
    -webkit-touch-callout: none; /* iOS Safari에서 길게 누르기 방지 */
    -webkit-user-select: none;
    user-select: none;
    pointer-events: auto; /* 클릭은 가능하지만 다운로드는 불가 */
}

.profile-spacer {
    width: 55px;
    height: 55px;
    flex: 0 0 55px;
    margin-top: 12px;
}

.sender-name {
    font-size: 13px;
    font-family: 'Pretendard', sans-serif;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.4;
}

/* 말풍선 */
.message-bubble {
    background: var(--bubble-bg-normal, white);
    border-radius: 18px;
    padding: 12px 12px 12px 12px;
    max-width: 23ch; /* 한 줄에 25자 제한 */
    width: fit-content; /* 콘텐츠에 맞게 너비 설정 */
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    margin-left: 5px;
    margin-right: auto; /* 왼쪽 정렬 유지 (오른쪽만 줄어듦) */
    /* 프로필 이미지와의 간격은 부모의 gap으로 처리 */
}

.message-bubble .tail {
    position: absolute;
    left: -8px; /* 본체 왼쪽 경계 밖으로 */
    top: 14px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 10px solid var(--bubble-bg-normal, white); /* 본체 배경색과 동일 */
    /* 꼬리를 본체와 완전히 같은 색상으로 렌더링 */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.message-text {
    margin: 0;
    font-size: 16px;
    font-family: 'Pretendard', sans-serif;
    font-weight: 500;
    line-height: 1.5;
    color: #333;
    word-wrap: break-word;
}

.message-text--multiline {
    white-space: pre-line;
}

.message-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 8px;
    margin-left: 5px;
    font-family: 'Pretendard', sans-serif;
    font-weight: 400;
}

/* 틀림 메시지 스타일 */
.chat-message.wrong .message-bubble {
    background: var(--bubble-bg-normal, white); /* 첫 번째 말풍선과 동일한 흰색 */
}

.chat-message.wrong .message-bubble .tail {
    border-right-color: var(--bubble-bg-normal, white); /* 첫 번째 말풍선과 동일한 흰색 */
}

/* 축하 메시지 스타일 */
.chat-message.celebration .message-bubble {
    background: var(--bubble-bg-normal, white); /* 첫 번째 말풍선과 동일한 흰색 */
}

.chat-message.celebration .message-bubble .tail {
    border-right-color: var(--bubble-bg-normal, white); /* 첫 번째 말풍선과 동일한 흰색 */
}

/* 사용자 메시지 말풍선 (오른쪽 정렬, 노란색) */
.user-message-bubble {
    display: block;
    position: relative;
    max-width: 23ch; /* 한 줄에 25자 제한 */
    width: fit-content; /* 콘텐츠에 맞게 너비 설정 */
    margin-right: 25px;
    margin-left: auto;
    margin-bottom: 30px;
    background: #FFD700; /* 단색 노란색 */
    border: none;
    border-radius: 18px;
    padding: 12px 12px 12px 12px;
    z-index: 2;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    font-family: 'Pretendard', sans-serif;
    font-weight: 500;
}

/* 사용자 메시지 꼬리 (오른쪽 방향) */
.user-message-bubble .user-message-tail {
    position: absolute;
    right: -8px; /* 본체 오른쪽 경계 밖으로 */
    top: 14px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 10px solid #FFD700; /* 배경색과 동일 */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.user-message-text {
    color: #333;
    font-size: 16px;
    font-weight: 500;
    font-family: 'Pretendard', sans-serif;
    word-wrap: break-word;
    display: block;
}

main {
    position: relative;
    z-index: 3;
}

.result-section {
    position: relative;
    z-index: 4;
    width: 100%;
    padding: 0px 20px 20px 20px;
    box-sizing: border-box;
}

.result-section img {
    max-width: 60%;
    width: fit-content;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    margin-left: 70px;
    cursor: pointer;
}

.image-preview-overlay[hidden] {
    display: none;
}

.image-preview-overlay {
    position: fixed;
    inset: 0;
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-preview-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
}

.image-preview {
    position: relative;
    max-width: 92vw;
    max-height: 92vh;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    object-fit: contain;
    z-index: 1;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes showText {
    to {
        opacity: 1;
    }
}

/* 하단 메시지 입력창 (프레임 구조) */
.message-input-bar {
    width: 100%;
    min-height: 60px;
    background-color: #ffffff;
    border-top: 1px solid #e0e0e0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 100;
    display: flex;
    align-items: center;
    padding: 12px 12px 12px 10px;
    box-sizing: border-box;
    flex-shrink: 0; /* flex에서 크기 고정 */
    gap: 8px;
    position: sticky;
    bottom: 0;
    touch-action: none;
}

.menu-wrapper {
    position: relative;
    flex-shrink: 0;
}

.btn-menu {
    width: 40px;
    height: 40px;
    border: none;
    background-color: #f5f5f5;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 0;
}

.btn-menu:active,
.btn-menu:focus {
    outline: none;
    background-color: #e8e8e8;
}

.material-icons {
    font-size: 24px;
    color: #333333;
}

.menu-panel {
    position: absolute;
    bottom: 50px;
    left: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    background-color: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
    min-width: 140px;
    z-index: 150;
}

.menu-panel[hidden] {
    display: none;
}

.menu-item {
    width: 100%;
    border: none;
    background: none;
    padding: 8px 10px;
    text-align: left;
    font-size: 14px;
    color: #333333;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    font-family: 'Pretendard', sans-serif;
    font-weight: 600;
}

.menu-item:hover,
.menu-item:active {
    background-color: #f2f2f2;
}

.menu-item-backup {
    color: #ff0000;
}

.input-bar-content {
    flex: 1;
    height: 40px;
    background-color: #f5f5f5;
    border-radius: 20px;
    display: flex;
    align-items: center;
    padding: 0 15px;
    box-sizing: border-box;
    min-width: 0;
}

#messageInput {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 16px;
    color: #333;
    padding: 0 8px;
    outline: none;
    min-width: 0;
}

#messageInput::placeholder {
    color: #999;
    font-family: 'Pretendard', sans-serif;
    font-weight: 500;
}

.btn-send {
    height: 40px;
    padding: 0 16px;
    background-color: #000000;
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.3s;
    font-family: 'Pretendard', sans-serif;
    font-weight: 700;
    flex-shrink: 0;
}

.btn-send:active {
    background-color: #333333;
}

.hint-modal[hidden] {
    display: none;
}

.hint-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.hint-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.hint-modal__dialog {
    position: relative;
    background: #ffffff;
    width: min(92%, 65vw);
    max-width: 420px;
    max-height: 80vh;
    height: min(70vh, 560px);
    border-radius: 18px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1;
}
.hint-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    background: #f9f9f9;
}

.hint-modal__header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #222222;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.hint-modal__toggle {
    border: none;
    background: #ededed;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    color: #333333;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    font-family: 'Pretendard', sans-serif;
    margin-left: auto;
    margin-right: 12px;
}

.hint-modal__toggle:hover,
.hint-modal__toggle:focus {
    background: #dddddd;
    outline: none;
}

.hint-modal__toggle.is-active {
    background: #111111;
    color: #ffffff;
}

.hint-modal__status {
    font-size: 9pt;
    font-weight: 400;
    opacity: 0.7;
    margin-left: 6px;
}

.hint-modal__close {
    border: none;
    background: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: #666666;
    padding: 4px 8px;
}

.hint-modal__close:hover,
.hint-modal__close:focus {
    color: #000000;
    outline: none;
}

.hint-modal__body {
    display: flex;
    flex: 1;
    min-height: 0;
    flex-direction: column;
}

.hint-modal__categories {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 12px;
    background: #fbfbfb;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 2;
}

.hint-modal__categories::-webkit-scrollbar {
    height: 4px;
}

.hint-modal__categories::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

.hint-modal__categories {
    overflow-x: auto;
}

.hint-category-button {
    border: none;
    background: none;
    padding: 8px 14px;
    border-radius: 999px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: #444444;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    font-family: 'Pretendard', sans-serif;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.hint-category-button:hover,
.hint-category-button:focus {
    background-color: rgba(0, 0, 0, 0.08);
    outline: none;
}

.hint-category-button.is-active {
    background-color: #111111;
    color: #ffffff;
}

.hint-category-count {
    font-size: 13px;
    font-weight: 500;
    opacity: 0.7;
}

.hint-modal__content {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 16px 18px;
}

.hint-modal__keywords {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.hint-keyword-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-radius: 12px;
    background-color: #f4f4f4;
    color: #222222;
    font-size: 15px;
    font-weight: 600;
}

.hint-keyword-item.is-solved {
    background-color: #111111;
    color: #ffffff;
}

.hint-keyword-item .hint-keyword-status {
    font-size: 13px;
    font-weight: 500;
    opacity: 0.7;
}

.scoreboard {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 200;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 12px;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.scoreboard-item {
    display: grid;
    grid-template-columns: 30px 30px auto;
    gap: 8px;
    line-height: 1.6;
}

/* 편지 버튼 */
.letter-btn {
    position: fixed;
    top: 10px;
    left: 10px;
    margin-top: 180px;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 200;
    transition: background-color 0.2s;
}

.letter-btn:hover {
    background: rgba(0, 0, 0, 0.7);
}

.letter-btn .material-icons {
    font-size: 24px;
    color: #fff;
}

.letter-btn[hidden] {
    display: none;
}

/* 편지 모달 */
.letter-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.letter-modal[hidden] {
    display: none;
}

.letter-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.letter-modal__dialog {
    position: relative;
    background: #ffffff;
    width: min(90%, 400px);
    border-radius: 12px;
    z-index: 1;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.letter-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
}

.letter-modal__header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.letter-modal__close {
    border: none;
    background: none;
    font-size: 28px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.letter-modal__close:hover {
    color: #000;
}

.letter-modal__body {
    padding: 20px;
    flex: 1;
}

.letter-input {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-family: 'Pretendard', sans-serif;
    resize: vertical;
    box-sizing: border-box;
}

.letter-input:focus {
    outline: none;
    border-color: #000;
}

.letter-input__counter {
    text-align: right;
    margin-top: 8px;
    font-size: 12px;
    color: #666;
}

.letter-modal__footer {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
}

.letter-btn-secondary,
.letter-btn-primary {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Pretendard', sans-serif;
}

.letter-btn-secondary {
    background: #f5f5f5;
    color: #333;
}

.letter-btn-secondary:hover {
    background: #e8e8e8;
}

.letter-btn-primary {
    background: #000;
    color: #fff;
}

.letter-btn-primary:hover {
    background: #333;
}

.letter-btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* 편지 메시지 표시 (중앙 오버레이) */
.letter-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 16pt;
    color: #ffffff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 1), 0 0 16px rgba(0, 0, 0, 0.9), 0 4px 12px rgba(0, 0, 0, 0.8);
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    animation: letterFadeInOut 5s ease-in-out;
}

@keyframes letterFadeInOut {
    0% {
        opacity: 0;
    }
    20% {
        opacity: 1;
    }
    80% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

.hint-keyword-item .hint-keyword-new {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 6px;
    margin-right: 6px;
    border-radius: 4px;
    background-color: #ff4444;
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.hint-modal__empty {
    margin: 0;
    font-size: 14px;
    color: #666666;
}

@media (max-width: 480px) {
    .hint-modal__dialog {
        width: 92%;
        max-height: 85vh;
        height: min(75vh, 560px);
    }
    .hint-modal__categories {
        padding: 12px 10px;
    }
}
