/* =========================================================
   롤링 페이퍼 화면 (모바일 우선)
   틀: cherry(체리) / block(블록이) / berry(베리)
   ========================================================= */
:root {
    --bg: #fdf8f3;
    --ink: #2e2622;
    --ink-soft: #7a6e66;
    --line: #ece2d8;
    --white: #ffffff;
    --point: #ff6b6b;

    /* 체리 */
    --cherry-paper: #fff3f0;
    --cherry-main: #ff6b6b;
    --cherry-deep: #e5484d;
    --cherry-rule: rgba(255, 107, 107, .16);
    --cherry-tape: rgba(255, 107, 107, .35);

    /* 블록이 */
    --block-paper: #f1f8ff;
    --block-main: #8cc8f2;
    --block-deep: #3d8fd1;
    --block-rule: rgba(61, 143, 209, .14);
    --block-tape: rgba(249, 80, 110, .30);

    /* 베리 */
    --berry-paper: #f6f0fb;
    --berry-main: #532275;
    --berry-deep: #532275;
    --berry-rule: rgba(83, 34, 117, .12);
    --berry-tape: rgba(213, 75, 99, .32);
}

/** { box-sizing: border-box; }*/

html, body {
}

body.is-dialog-open { overflow: hidden; }

.rp {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 16px calc(110px + env(safe-area-inset-bottom)); /* 하단 고정 버튼 공간 */
}

/* ---------- 상단 ---------- */
.rp-hero { padding: 40px 4px 8px; text-align: center; }
@media (min-width: 720px) {
    .rp-hero{padding-top: 90px;}
}
.rp-hero__eyebrow { margin: 0 0 8px; font-size: 12px; font-weight: 800; letter-spacing: .2em; color: var(--point); }
.rp-hero__title { margin: 0; font-size: 28px; line-height: 1.3; font-weight: 800; }
.rp-hero__desc { margin: 10px 0 0; color: var(--ink-soft); line-height: 1.6; font-size: 15px; }
.rp-hero__friends {
    display: flex; justify-content: center; align-items: flex-end; gap: 6px;
    margin-top: 20px; height: 108px;
}
.rp-hero__friends img { height: 92px; width: auto; }
.rp-hero__friends img:nth-child(2) { height: 108px; }
.rp-hero__friends img:nth-child(1) { transform: rotate(-6deg); }
.rp-hero__friends img:nth-child(3) { height: 76px; transform: rotate(6deg); }

.rp-section-title { margin: 0 0 16px; font-size: 20px; font-weight: 800; }

/* ---------- 작성 버튼 (하단 고정) ---------- */
.write-fab-wrap {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    display: flex; justify-content: center;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--bg) 40%, rgba(253, 248, 243, 0));
    pointer-events: none;
}
@media (min-width: 720px) {
    .write-fab-wrap {
        position: relative;
        padding-top: 50px;
    }
}

.write-fab {
    pointer-events: auto;
    width: 100%; max-width: 688px;
    padding: 16px; border: 0; border-radius: 16px;
    font: inherit; font-size: 16px; font-weight: 800;
    background: var(--point); color: var(--white);
    box-shadow: 0 8px 20px rgba(255, 107, 107, .35);
    cursor: pointer;
    transition: transform .1s;
}
.write-fab:active { transform: scale(.98); }
.write-fab:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* ---------- 작성 시트 (화면 위에 덮어서 노출) ---------- */
.write-sheet {
    width: 100%; max-width: 720px;
    max-height: 92vh; max-height: 92dvh;
    margin: auto auto 0;            /* 하단에 붙는 바텀시트 */
    padding: 0;
    border: 0;
    background: transparent;
    overflow: visible;
}
.write-sheet::backdrop { background: rgba(30, 22, 18, .55); backdrop-filter: blur(2px); }
.write-sheet[open] { animation: sheet-up .28s ease-out; }
@keyframes sheet-up {
    from { transform: translateY(100%); }
    to   { transform: none; }
}
@media (prefers-reduced-motion: reduce) { .write-sheet[open] { animation: none; } }

.rp-write {
    box-sizing: border-box;
    max-height: 92vh; max-height: 92dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
    background: var(--white);
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -10px 30px rgba(46, 38, 34, .12);
}
.rp-write__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.rp-write__head .rp-section-title { margin: 0; }
.rp-write__close {
    width: 36px; height: 36px;
    border: 0; border-radius: 50%;
    background: #f5f1ec;
    font-size: 24px; line-height: 1; color: var(--ink);
    cursor: pointer;
}

/* 넓은 화면에서는 가운데 카드 형태 */
@media (min-width: 720px) {
    .write-sheet { margin: auto; width: min(92vw, 560px); }
    .rp-write { border-radius: 24px; padding-bottom: 22px; }
    .write-sheet[open] { animation-name: dialog-in; }
}
.rp-form { display: grid; gap: 18px; }
.rp-label { display: block; font-size: 14px; font-weight: 700; margin-bottom: 8px; padding: 0; }

.rp-field { display: grid; }
.rp-field input, .rp-field textarea {
    width: 100%;
    font: inherit; font-size: 16px; /* iOS 확대 방지 */
    color: var(--ink);
    background: #fffdfb;
    border: 1.5px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    resize: none;
    transition: border-color .15s;
    box-sizing: border-box;
}
.rp-field input:focus, .rp-field textarea:focus { outline: none; border-color: var(--point); }
.rp-field__count { justify-self: end; margin-top: 6px; font-size: 12px; color: var(--ink-soft); }
.rp-bottom{display:flex ; justify-content: space-between; align-items: center; padding: 3px 4px; }
.rp-bottom p {color: var(--text-muted) ; font-size: 14px; }

  /* ---------- 작성: 사진 첨부 (1장, 선택) ---------- */
    .rp-photo { display: grid; }
    .rp-label__opt { font-style: normal; font-weight: 500; color: var(--ink-soft); }

    .rp-photo__row { display: flex; align-items: center; gap: 14px; }

    .rp-photo__slot {
        position: relative;
        place-items: center;
        box-sizing: border-box;
        width: 84px;
        height: 84px;
        border: 1.5px dashed #d6c9bd;
        border-radius: 14px;
        cursor: pointer;
        flex-shrink: 0;
    }

    .rp-photo__slot.active{
        border:none;
    }

    .rp-photo__slot.active img {
        border-radius: 0;
    }
    /* 사진 선택 칸 */
    .rp-photo__picker {
        position: relative;
        display: grid; place-items: center;
        box-sizing: border-box;
        width: 100%; height: 100%;
        border-radius: 14px;
        background: #fffdfb;
        color: var(--ink-soft);
        cursor: pointer;
        overflow: hidden;
        transition: border-color .15s, background-color .15s;
    }
    .rp-photo__picker:hover { border-color: var(--point); background: #fff6f4; }
    .rp-photo__picker:focus-within { outline: 3px solid var(--point); outline-offset: 2px; }

    /* 실제 input 은 숨기고 칸 전체를 클릭 영역으로 사용 */
    .rp-photo__input {
        position: absolute; width: 1px; height: 1px;
        opacity: 0; pointer-events: none;
    }

    .rp-photo__empty { display: grid; justify-items: center; gap: 4px; font-size: 12px; font-weight: 700; }
    .rp-photo__empty svg { width: 26px; height: 26px; }

    .rp-photo__thumb {
        position: absolute; inset: 0;
        width: 100%; height: 100%;
        object-fit: cover;
    }
    .rp-photo__thumb[hidden] { display: none; }

    /* 삭제 버튼 */
    .rp-photo__remove {
        position: absolute; top: -8px; right: -8px; z-index: 1;
        display: grid; place-items: center;
        width: 26px; height: 26px; padding: 0;
        border: 2px solid var(--white); border-radius: 50%;
        background: var(--ink); color: var(--white);
        font-size: 16px; line-height: 1;
        cursor: pointer;
    }
    .rp-photo__remove[hidden] { display: none; }

    .rp-photo__help { margin: 0; font-size: 13px; line-height: 1.6; color: var(--ink-soft); }
    .rp-photo__help b { display: block; font-size: 14px; color: var(--ink); }

    /* 사진 선택 후: 실선 테두리 */
    .rp-photo.is-selected .rp-photo__picker { border-style: solid; border-color: var(--line); }
    .rp-photo.is-selected .rp-photo__empty { visibility: hidden; }

/* 틀 선택 */
.frame-picker { border: 0; margin: 0; padding: 0; min-width: 0; }
.frame-picker__list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }

.frame-option { cursor: pointer; }
.frame-option input { position: absolute; opacity: 0; pointer-events: none; }
.frame-option__box {
    display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px;
    height: 104px; padding: 10px 4px 8px;
    border-radius: 16px;
    border: 2px solid transparent;
    transition: transform .15s, border-color .15s, box-shadow .15s;
}
.frame-option__box img { height: 58px; width: auto; transition: transform .2s; }
.frame-option__name { font-size: 13px; font-weight: 700; }
.frame-option__dice {
    display: grid; place-items: center;
    width: 52px; height: 52px; margin-bottom: 3px;
    border-radius: 14px;
    background: var(--white);
    border: 2px dashed #c9bdb2;
    font-size: 24px; font-weight: 800; color: var(--ink-soft);
}

.frame-option--cherry .frame-option__box { background: var(--cherry-paper); }
.frame-option--block .frame-option__box { background: var(--block-paper); }
.frame-option--berry  .frame-option__box { background: var(--berry-paper); }
.frame-option--random .frame-option__box { background: #f5f1ec; }

.frame-option input:checked + .frame-option__box { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(46, 38, 34, .1); }
.frame-option input:checked + .frame-option__box img { transform: scale(1.08) rotate(-4deg); }
.frame-option--cherry input:checked + .frame-option__box { border-color: var(--cherry-main); }
.frame-option--block input:checked + .frame-option__box { border-color: var(--block-deep); }
.frame-option--berry  input:checked + .frame-option__box { border-color: var(--berry-main); }
.frame-option--random input:checked + .frame-option__box { border-color: var(--ink); }
.frame-option input:focus-visible + .frame-option__box { outline: 3px solid var(--point); outline-offset: 2px; }

.rp-btn {
    appearance: none; border: 0; cursor: pointer;
    width: 100%; padding: 16px; border-radius: 16px;
    font: inherit; font-size: 16px; font-weight: 800;
    background: var(--point); color: var(--white);
    transition: transform .1s;
}
.rp-btn:active { transform: scale(.98); }

/* ---------- 보드 ---------- */
.rp-board { margin-top: 24px; }
.rp-board__count { color: var(--point); }
.rp-board__empty { text-align: center; color: var(--ink-soft); padding: 32px 0; }

.rollingRelay{
    background-color: var(--bg);
}

.rollingBg{
    background-color: var(--bg);
}

.paper-list {
    list-style: none; margin: 0; padding: 40px 0 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 14px;
    row-gap: 42px; /* 캐릭터가 위로 튀어나오는 공간 */
}
@media (min-width: 560px) { .paper-list { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* 롤링 페이퍼 한 장 */
.paper {
    --paper: var(--cherry-paper);
    --main: var(--cherry-main);
    --rule: var(--cherry-rule);
    --tape: var(--cherry-tape);

    position: relative;
    display: flex; flex-direction: column;
    width: 100%; height: 224px;   /* 고정 높이: 본문 길이·사진 유무와 상관없이 모든 카드 동일 */
    padding: 30px 14px 12px;
    text-align: left;
    font: inherit; color: var(--ink);
    cursor: pointer;
    border: 0;
    border-radius: 6px 6px 18px 6px;
    background-color: var(--paper);
    /* 노트 줄 */
    background-image: repeating-linear-gradient(
            to bottom, transparent 0, transparent 25px, var(--rule) 25px, var(--rule) 26px);
    background-position: 0 29px;
    box-shadow: 0 6px 16px rgba(46, 38, 34, .08), inset 0 4px 0 var(--main);
    transform: rotate(var(--tilt, 0deg));
    transition: transform .2s, box-shadow .2s;
}
.paper-list li:nth-child(3n+1) .paper { --tilt: -1.4deg; }
.paper-list li:nth-child(3n+2) .paper { --tilt: 1deg; }
.paper-list li:nth-child(3n)   .paper { --tilt: -.4deg; }

.paper:hover, .paper:focus-visible {
    transform: rotate(0deg) translateY(-3px);
    box-shadow: 0 12px 24px rgba(46, 38, 34, .14), inset 0 4px 0 var(--main);
}
.paper:focus-visible { outline: 3px solid var(--main); outline-offset: 3px; }

/* 마스킹 테이프 */
.paper::before {
    content: "";
    position: absolute; top: -9px; left: 16px;
    width: 52px; height: 18px;
    background: var(--tape);
    transform: rotate(-6deg);
    border-radius: 2px;
}

/* 캐릭터: 오른쪽 위로 빼꼼 */
.paper__character {
    position: absolute;
    top: -34px; right: 6px;
    height: 58px; width: auto;
    pointer-events: none;
    filter: drop-shadow(0 3px 4px rgba(46, 38, 34, .12));
}

.paper__content {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    flex-shrink: 0;
    height: 130px;                /* 5줄(26px × 5) 영역을 항상 확보 */
    -webkit-line-clamp: 5;        /* 5줄 넘으면 말줄임 */
    line-clamp: 5;
    overflow: hidden;
    font-size: 14.5px;
    line-height: 26px;            /* 노트 줄 간격과 맞춤 */
    white-space: pre-line;
    overflow-wrap: anywhere;
}

/* ---------- 사진 있는 카드 (폴라로이드) ---------- */
.paper__photo {
    display: block;
    flex-shrink: 0;
    margin: 0 2px 10px;
    padding: 5px 5px 14px;              /* 아래 여백을 넓게: 폴라로이드 느낌 */
    background: var(--white);
    border-radius: 3px;
    box-shadow: 0 3px 8px rgba(46, 38, 34, .14);
    transform: rotate(var(--photo-tilt, 1.6deg));
}
.paper__photo img {
    display: block;
    width: 100%;
    height: 80px;                       /* 고정 높이: 사진 비율과 상관없이 카드 높이를 맞춤 */
    object-fit: cover;
    border-radius: 2px;
    background: #eee5dc;                /* 로딩 중 자리 표시 */
}
.paper-list li:nth-child(2n) .paper__photo { --photo-tilt: -1.4deg; }

/* 사진이 있으면 본문은 1줄까지 (전체는 팝업에서) */
.paper--has-photo .paper__content {
    height: 26px;                       /* 사진이 있으면 본문은 1줄 미리보기 */
    -webkit-line-clamp: 1;
    line-clamp: 1;
}
/* 사진 아래부터 노트 줄이 시작되도록 줄 무늬 위치 이동 */
.paper--has-photo {
    background-position: 0 138px;
}

.paper__more {
    display: none;
    position: absolute;           /* 날짜 줄 오른쪽에 겹쳐 배치 → 카드 높이에 영향 없음 */
    right: 14px; bottom: 12px;
    font-size: 12px; font-weight: 700;
    color: var(--main);
}
.paper.is-truncated .paper__more { display: inline-block; }

.paper__meta {
    display: flex; flex-direction: column; gap: 2px;
    margin-top: auto; padding-top: 12px;
    font-size: 12px; color: var(--ink-soft);
}
.paper__from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.paper__nick { color: var(--ink); font-weight: 800; }

/* 틀별 색 */
.paper--cherry, .paper-dialog__paper.paper--cherry {
    --paper: var(--cherry-paper); --main: var(--cherry-main); --rule: var(--cherry-rule); --tape: var(--cherry-tape);
}
.paper--block, .paper-dialog__paper.paper--block {
    --paper: var(--block-paper); --main: var(--block-deep); --rule: var(--block-rule); --tape: var(--block-tape);
}
.paper--berry, .paper-dialog__paper.paper--berry {
    --paper: var(--berry-paper); --main: var(--berry-main); --rule: var(--berry-rule); --tape: var(--berry-tape);
}
.paper--block .paper__character { height: 50px; top: -28px; }

/* ---------- 팝업 ---------- */
.paper-dialog {
    width: min(92vw, 440px);
    max-height: none;
    padding: 0;
    border: 0;
    background: transparent;
    overflow: visible;
}
.paper-dialog::backdrop { background: rgba(30, 22, 18, .55); backdrop-filter: blur(2px); }
.paper-dialog[open] { animation: dialog-in .25s ease-out; }
@keyframes dialog-in {
    from { opacity: 0; transform: translateY(16px) scale(.96); }
    to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .paper-dialog[open] { animation: none; } }

.paper-dialog__paper {
    --paper: var(--cherry-paper); --main: var(--cherry-main); --rule: var(--cherry-rule);
    position: relative;
    margin-top: 70px; /* 캐릭터 공간 */
    padding: 64px 0 0;              /* 좌우·아래 여백은 .paper-dialog__body 에서 */
    border-radius: 10px 10px 24px 10px;
    background-color: var(--paper);
    background-image: repeating-linear-gradient(
            to bottom, transparent 0, transparent 29px, var(--rule) 29px, var(--rule) 30px);
    background-position: 0 63px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, .25), inset 0 6px 0 var(--main);
}
.paper-dialog__character {
    position: absolute;
    top: -84px; left: 50%;
    height: 132px; width: auto;
    transform: translateX(-50%);
    filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .15));
}
.paper-dialog__close {
    position: absolute; top: 12px; right: 12px;
    width: 36px; height: 36px;
    border: 0; border-radius: 50%;
    background: rgba(255, 255, 255, .8);
    font-size: 24px; line-height: 1; color: var(--ink);
    cursor: pointer;
}
.paper-dialog__content {
    margin: 0;
    font-size: 16px;
    line-height: 30px;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

/* ---------- 팝업: 레이아웃 ----------
   팝업은 화면 높이 안에 고정하고, 사진·본문·From 은 .paper-dialog__body 안에서 함께 스크롤 */
.paper-dialog__paper {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;             /* padding 포함해서 높이 계산 (전역 border-box 미적용 대응) */
    max-height: min(calc(100vh - 110px), 640px);    /* 화면 안 + 너무 길어지지 않게 */
    max-height: min(calc(100dvh - 110px), 640px);
}
.paper-dialog__body {
    box-sizing: border-box;
    flex: 1 1 auto;
    min-height: 0;                      /* flex 안에서 스크롤 되도록 */
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0 22px 20px;
}

/* ---------- 팝업: 사진 ---------- */
.paper-dialog__photo {
    display: table;                     /* 사진 크기에 맞춰 프레임이 줄어듦 */
    box-sizing: border-box;
    max-width: calc(100% - 8px);
    margin: 0 auto 20px;
    padding: 8px 8px 22px;              /* 폴라로이드: 아래 여백 넓게 */
    background: var(--white);
    border-radius: 4px;
    box-shadow: 0 6px 16px rgba(46, 38, 34, .16);
    transform: rotate(-1.2deg);
}
.paper-dialog__photo[hidden] { display: none; }
.paper-dialog__photo img {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
    max-height: 36vh;                   /* 세로 사진도 잘리지 않게 전체 노출 */
    max-height: 36dvh;
    object-fit: contain;
    border-radius: 2px;
    background: #f3ede7;
}
/* 낮은 화면(iPhone SE 등)에서는 사진을 더 작게 */
@media (max-height: 700px) {
    .paper-dialog__photo img { max-height: 30vh; max-height: 30dvh; }
}

/* 사진이 있을 땐 노트 줄을 본문에만 */
.paper-dialog__paper.has-photo { background-image: none; }
.paper-dialog__paper.has-photo .paper-dialog__content {
    background-image: repeating-linear-gradient(
            to bottom, transparent 0, transparent 29px, var(--rule) 29px, var(--rule) 30px);
}

.paper-dialog__meta {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    margin-top: 18px; padding-top: 12px;
    border-top: 1px dashed var(--rule);
    font-size: 13px; color: var(--ink-soft);
}
.paper-dialog__meta b { color: var(--ink); }

.rp-photo input[type="file"] {
    width: 0;
    height: 0;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    visibility: hidden;
}

.rp-photo .customImg{
    position: relative;
    z-index: 1;
    place-items: center;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    border-radius: 14px;
    overflow: hidden;
}