.diary-paper {
    background: var(--paper-color);
    min-height: 380px;
    height: auto;
    width: 100%;
    max-width: 460px;
    margin: 0 auto;
    flex-shrink: 0;
    border-radius: 15px;
    padding: 25px 30px 20px 30px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    position: relative;
    touch-action: pan-y;
    user-select: none;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.05);
    margin: 0 2px;
    transition: box-shadow 0.3s, transform 0.3s ease, opacity 0.3s ease;
    background-size: 100% auto;
    background-position: top center;
    background-repeat: repeat;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] {
    --diary-fixed-reply-slot-height: 154px;
    height: var(--diary-fixed-paper-height, 720px);
    min-height: 0;
    overflow: hidden;
    background-size: 100% 100%;
    background-position: center center;
    background-repeat: no-repeat;
}

.diary-paper::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: inherit;
    pointer-events: none;
    box-shadow: inset 0 0 0 1.5px var(--active-border);
    z-index: 5;
}

.diary-paper.active::after {
    box-shadow: inset 0 0 0 1.5px var(--active-border);
}

.diary-paper.edit-mode::after {
    box-shadow: inset 0 0 0 3px var(--accent-color);
}

.diary-paper[data-post-type="photo"] {
    min-height: 0;
    padding: 0;
    background: none;
    overflow: hidden;
}

.diary-paper[data-post-type="photo"] .photo-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: 15px;
}

.diary-paper[data-post-type="photo"] .missing-photo-wrapper {
    display: flex;
    min-height: 220px;
    border: 1px dashed rgba(140, 109, 72, 0.28);
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, rgba(255, 250, 243, 0.96), rgba(244, 234, 219, 0.92));
}

.diary-paper[data-post-type="photo"] .photo-missing-state {
    padding: 28px 24px 44px;
    color: rgba(92, 66, 36, 0.86);
    line-height: 1.65;
    text-align: center;
}

.diary-paper[data-post-type="photo"] .photo-missing-title {
    margin-bottom: 8px;
    font-size: 15px;
    font-weight: 700;
}

.diary-paper[data-post-type="photo"] .photo-missing-copy {
    font-size: 13px;
}

.diary-paper[data-post-type="photo"] .post-photo-img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
}

.diary-paper[data-post-type="photo"] .post-photo-img.is-loading {
    visibility: hidden;
}

.diary-paper[data-post-type="photo"] .photo-loading-state {
    display: flex;
    padding: 24px;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    color: rgba(92, 66, 36, 0.72);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(251, 246, 239, 0.92));
    font-size: 14px;
    text-align: center;
}

.diary-paper[data-post-type="photo"] .photo-loading-state[hidden] {
    display: none;
}

.diary-paper[data-post-type="photo"] .delete-post-btn {
    display: flex;
    width: 36px;
    height: 36px;
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 10;
    border: none;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.6);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    font-size: 16px;
}

.diary-paper.active {
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.12);
    z-index: 10;
}

.diary-paper.edit-mode {
    box-shadow: 0 12px 40px rgba(212, 163, 115, 0.2);
    z-index: 100;
}

.diary-ai-reply {
    --diary-ai-reply-divider-gap: 15px;
    /* 답장 점선 위까지 스티커를 배치할 수 있도록 바깥 여백을 두지 않아요. */
    margin-top: 0;
    padding: var(--diary-ai-reply-divider-gap) 0;
    border-top: 1.5px dashed var(--border-color);
    display: flex;
    gap: 12px;
    align-items: flex-start;
    animation: fadeIn 0.5s ease;
    user-select: text;
    -webkit-user-select: text;
}

.ai-reply-avatar {
    width: 43px;
    height: 43px;
    object-fit: contain;
    flex-shrink: 0;
    filter: drop-shadow(0 0 8px rgba(21, 39, 63, 0.8));
    animation: floating 3s ease-in-out infinite;
    margin-top: 6px;
}

.ai-reply-bubble {
    background: rgba(255, 255, 255, 0.65);
    border-radius: 4px 15px 15px 15px;
    padding: 12px 16px;
    font-size: 9pt;
    font-family: inherit;
    color: #5d4037;
    line-height: 1.8;
    letter-spacing: -0.3px;
    position: relative;
    border: 1px solid #f0e6dd;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
    user-select: text;
    -webkit-user-select: text;
}

.diary-paper.glass-dark .ai-reply-bubble {
    background: rgba(0, 0, 0, 0.58);
    border-color: rgba(255, 255, 255, 0.24);
    color: #f4f4f4;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

.ai-reply-loading {
    font-size: 13px;
    color: var(--accent-color);
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: blink 1.5s infinite;
    padding: 10px 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.diary-header {
    border-bottom: 1.5px solid var(--accent-color);
    padding-bottom: 10px;
    margin-bottom: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.date-label {
    font-size: 12px;
    color: var(--accent-color);
    font-weight: bold;
    letter-spacing: 0.5px;
}

.diary-content-area {
    flex: none;
    position: relative;
    z-index: 0;
    width: calc(100% + 60px);
    margin-left: -30px;
    height: auto;
    min-height: 230px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.diary-body-scroll-frame {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    min-height: 230px;
}

.diary-scroll-area {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    min-height: 0;
    overflow: visible;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .diary-scroll-area {
    flex: 1 1 auto;
    overflow: visible;
    overflow-x: visible;
    overscroll-behavior: contain;
    gap: 0;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .diary-content-area {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

/* 편집 중에는 경계 밖으로 돌출된 스티커 조작 버튼까지 보여준다. */
.diary-paper.edit-mode[data-post-type="text"][data-background-type="fixed"] .diary-content-area {
    overflow: visible;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"][data-has-ai-reply="true"] .diary-content-area {
    flex: 1 1 0;
    min-height: 120px;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"][data-reserve-ai-reply="true"] .diary-content-area {
    flex: 1 1 0;
    min-height: 120px;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"][data-reserve-ai-reply="true"][data-has-ai-reply="false"] .diary-scroll-area::after {
    content: "별친구의 답장이 도착할 자리예요.";
    display: flex;
    flex: 0 0 var(--diary-fixed-reply-slot-height);
    height: var(--diary-fixed-reply-slot-height);
    max-height: var(--diary-fixed-reply-slot-height);
    min-height: 0;
    box-sizing: border-box;
    align-items: center;
    justify-content: center;
    padding: 15px 8px;
    border-top: 1.5px dashed var(--border-color);
    color: rgba(93, 64, 55, 0.62);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.6;
    letter-spacing: -0.2px;
    text-align: center;
    pointer-events: none;
}

.diary-paper.glass-dark[data-post-type="text"][data-background-type="fixed"][data-reserve-ai-reply="true"][data-has-ai-reply="false"] .diary-scroll-area::after {
    border-top-color: rgba(255, 255, 255, 0.4);
    color: rgba(255, 255, 255, 0.78);
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .diary-ai-reply {
    margin-top: 0;
    box-sizing: border-box;
    min-height: 0;
    min-width: 0;
    align-items: stretch;
    overflow: visible;
    padding-left: 0;
    padding-right: 0;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .ai-reply-avatar {
    align-self: flex-start;
    transform: translateX(-6px);
    margin-right: -6px;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"][data-has-ai-reply="true"] .diary-ai-reply {
    flex: 0 0 var(--diary-fixed-reply-slot-height);
    height: var(--diary-fixed-reply-slot-height);
    max-height: var(--diary-fixed-reply-slot-height);
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .ai-reply-bubble {
    --ai-reply-scroll-peek: 5px;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    height: 100%;
    align-self: stretch;
    max-height: none;
    overflow: hidden;
    word-break: break-word;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .ai-reply-scroll-content {
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(
        to bottom,
        #000 0,
        #000 calc(100% - var(--ai-reply-scroll-peek)),
        transparent 100%
    );
    mask-image: linear-gradient(
        to bottom,
        #000 0,
        #000 calc(100% - var(--ai-reply-scroll-peek)),
        transparent 100%
    );
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .ai-reply-scroll-content::after {
    content: "";
    display: block;
    height: var(--ai-reply-scroll-peek);
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .ai-reply-scroll-content::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .text-glass-underlay,
.diary-paper[data-post-type="text"][data-background-type="fixed"] .diary-body-underlay {
    bottom: auto;
    min-height: 100%;
    overflow: visible;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .diary-body-scroll-frame {
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    overflow-y: hidden;
    overflow-x: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    scrollbar-width: none;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .diary-body-scroll-frame.is-scrollable {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .diary-body-input {
    display: block;
    min-height: 100%;
    max-height: none;
    overflow-y: hidden;
    overflow-x: hidden;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .diary-body-scroll-frame::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.diary-paper[data-post-type="text"][data-background-type="fixed"] .post-actions {
    flex: 0 0 auto;
    margin-top: 0;
}

.diary-paper.edit-mode:not([data-background-type="fixed"]) .diary-content-area {
    overflow: visible;
}

.text-glass-underlay,
.diary-body-underlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 15px 30px 30px 30px;
    font-size: 12px;
    font-family: inherit;
    line-height: 22px;
    color: transparent;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-sizing: border-box;
    z-index: 0;
    pointer-events: none;
}

.text-glass-underlay span,
.diary-body-underlay span {
    border-radius: 4px;
    transition: background 0.4s ease, backdrop-filter 0.4s ease, border 0.4s ease;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

.text-glass-underlay.glass-light span,
.diary-body-underlay.glass-light span {
    background: rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
}

.text-glass-underlay.glass-dark span,
.diary-body-underlay.glass-dark span {
    background: rgba(0, 0, 0, 0.58);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.58);
}

textarea,
.diary-body-input {
    width: 100%;
    height: auto;
    min-height: 230px;
    border: none;
    resize: none;
    font-size: 12px;
    font-family: inherit;
    line-height: 22px;
    outline: none;
    background: transparent;
    color: var(--text-color);
    padding: 15px 30px 30px 30px;
    box-sizing: border-box;
    overflow-y: hidden;
    position: relative;
    z-index: 1;
    transition: color 0.4s ease;
}

textarea::placeholder,
.diary-body-input::placeholder {
    color: #bfaea0;
}

textarea[readonly],
.diary-body-input[readonly] {
    cursor: default;
}
