@font-face {
    font-family: "Maru Buri";
    src: url("../fonts/stationery/maruburi/OruMaruSerif-Regular.woff2") format("woff2");
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    unicode-range: U+0020-007E, U+00A0-00FF, U+2000-206F,
        U+3000-303F, U+3130-318F, U+AC00-D7A3, U+FF00-FFEF;
}

@font-face {
    font-family: "Maru Buri";
    src: url("../fonts/stationery/maruburi/OruMaruSerif-SemiBold.woff2") format("woff2");
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    unicode-range: U+0020-007E, U+00A0-00FF, U+2000-206F,
        U+3000-303F, U+3130-318F, U+AC00-D7A3, U+FF00-FFEF;
}

@font-face {
    font-family: "Oru Gowun Dodum";
    src: url("../fonts/stationery/gowun-dodum/GowunDodum-Regular.woff2") format("woff2");
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Oru Nanum Pen";
    src: url("../fonts/stationery/nanum-pen-script/NanumPenScript-Regular.woff2") format("woff2");
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

/* 오루 꾸미기 장면. 모든 규칙은 stationery-surface 아래로 한정한다. */
.stationery-surface {
    --stationery-paper: #fffdf8;
    --stationery-ink: #2d312e;
    --stationery-muted: #727874;
    --stationery-line: rgba(90, 107, 95, .16);
    --stationery-grid: rgba(90, 107, 95, .13);
    --stationery-shadow: rgba(55, 48, 38, .14);
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    color: var(--stationery-ink);
    isolation: isolate;
}

.stationery-surface[data-collection="mono-note"] {
    --stationery-paper: #fafaf7;
    --stationery-ink: #222524;
    --stationery-muted: #707471;
    --stationery-line: rgba(38, 42, 40, .16);
    --stationery-grid: rgba(38, 42, 40, .11);
}

.stationery-surface[data-collection="pastel-memo"] {
    --stationery-paper: #fff7fc;
    --stationery-ink: #493f4c;
    --stationery-muted: #89798d;
    --stationery-line: rgba(190, 148, 194, .18);
    --stationery-grid: rgba(183, 148, 194, .13);
}

.stationery-surface[data-collection="travel-notebook"] {
    --stationery-paper: #f4e3c7;
    --stationery-ink: #4e4030;
    --stationery-muted: #806d55;
    --stationery-line: rgba(128, 92, 48, .18);
    --stationery-grid: rgba(128, 92, 48, .13);
}

.stationery-surface *,
.stationery-surface *::before,
.stationery-surface *::after { box-sizing: border-box; }

.stationery-surface .stationery-canvas {
    position: relative;
    width: 100%;
    min-width: 0;
    overflow: hidden;
    background: var(--stationery-paper);
    box-shadow: 0 10px 32px var(--stationery-shadow);
}

.stationery-surface[data-frame="print"] .stationery-canvas {
    padding: clamp(8px, 2.4vw, 16px);
    border: 1px solid rgba(105, 95, 78, .16);
    border-radius: 4px;
}

.stationery-surface[data-frame="rounded"] .stationery-canvas {
    border: 1px solid rgba(105, 95, 78, .15);
    border-radius: 24px;
}

.stationery-surface[data-frame="line"] .stationery-canvas {
    border: 1px solid rgba(68, 67, 61, .58);
    box-shadow: 0 10px 32px var(--stationery-shadow), inset 0 0 0 5px var(--stationery-paper), inset 0 0 0 6px rgba(68, 67, 61, .2);
}

.stationery-surface[data-frame="tape"] .stationery-canvas {
    margin-block: 13px;
    overflow: visible;
    border: 1px solid rgba(105, 95, 78, .13);
}

.stationery-surface[data-frame="tape"] .stationery-canvas::before,
.stationery-surface[data-frame="tape"] .stationery-canvas::after {
    position: absolute;
    z-index: 5;
    top: -11px;
    width: 74px;
    height: 24px;
    content: "";
    pointer-events: none;
    background: rgba(224, 199, 146, .60);
    border: 1px solid rgba(151, 123, 75, .12);
    box-shadow: 0 1px 2px rgba(72, 58, 35, .08);
}

.stationery-surface[data-frame="tape"] .stationery-canvas::before {
    left: 8%;
    transform: rotate(-4deg);
}

.stationery-surface[data-frame="tape"] .stationery-canvas::after {
    right: 8%;
    transform: rotate(3deg);
}

.stationery-surface .stationery-photo {
    position: relative;
    z-index: 1;
    width: 100%;
    aspect-ratio: 4 / 3;
    min-height: 180px;
    max-height: 440px;
    margin: 0;
    overflow: hidden;
    background: #e8e2d6;
}

.stationery-surface[data-frame="rounded"] .stationery-photo:first-child {
    border-radius: 23px 23px 0 0;
}

.stationery-surface .stationery-photo img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.stationery-surface .stationery-media-error {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 24px;
    color: var(--stationery-muted);
    font: 500 1rem/1.55 Pretendard, "Noto Sans KR", sans-serif;
    text-align: center;
    background: linear-gradient(145deg, #f0ece2, #e7e0d2);
}

.stationery-surface .stationery-photo--failed .stationery-media-error { display: flex; }
.stationery-surface .stationery-photo--failed img { display: none; }

.stationery-surface .stationery-paper {
    --stationery-paper-min-height: clamp(240px, 58vw, 620px);
    --stationery-paper-padding-block: clamp(34px, 7vw, 72px);
    position: relative;
    min-height: var(--stationery-paper-min-height);
    padding: var(--stationery-paper-padding-block) clamp(24px, 8vw, 84px);
    overflow-wrap: anywhere;
    background-color: var(--stationery-paper);
}

@media (max-width: 767px) {
    /* Let an unillustrated entry use a tall phone's remaining writing space.
       The same rule applies when reading, so saved sticker coordinates retain
       the same canvas geometry. svh avoids resizing the paper with browser chrome. */
    :is(#stationery-writing-surface, #stationery-read-surface)
        .stationery-surface:not(:has(.stationery-photo, #panel-read-media)) .stationery-paper {
        --stationery-paper-min-height: max(clamp(240px, 58vw, 620px), calc(100svh - 500px - var(--sat, 0px) - var(--sab, 0px)));
    }
}

.stationery-surface:has(.stationery-photo) .stationery-paper { margin-top: -1px; }

.stationery-surface[data-paper="ruled"] .stationery-paper {
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0,
        transparent calc(1.85rem - 1px),
        var(--stationery-line) calc(1.85rem - 1px),
        var(--stationery-line) 1.85rem
    );
    background-position: 0 calc(clamp(34px, 7vw, 72px) + .35rem);
}

.stationery-surface[data-paper="grid"] .stationery-paper {
    background-image:
        linear-gradient(var(--stationery-grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--stationery-grid) 1px, transparent 1px);
    background-size: 24px 24px;
}

.stationery-surface .stationery-eyebrow,
.stationery-surface .stationery-title,
.stationery-surface .stationery-body {
    position: relative;
    z-index: 5;
    text-shadow: 1px 0 var(--stationery-paper), -1px 0 var(--stationery-paper),
        0 1px var(--stationery-paper), 0 -1px var(--stationery-paper);
}
.stationery-surface[data-editable="true"] :is(.stationery-eyebrow, .stationery-title, .stationery-body) {
    pointer-events: none;
}

.stationery-surface .stationery-eyebrow {
    margin: 0 0 12px;
    color: var(--stationery-muted);
    font: 600 .8125rem/1.5 Pretendard, "Noto Sans KR", sans-serif;
    letter-spacing: .02em;
}

.stationery-surface .stationery-title {
    margin: 0 0 22px;
    color: var(--stationery-ink);
    font-size: clamp(1.3rem, 4.4vw, 1.8rem);
    font-weight: 600;
    line-height: 1.45;
    letter-spacing: -.02em;
    text-wrap: balance;
}

.stationery-surface .stationery-body {
    margin: 0;
    color: var(--stationery-ink);
    font-size: clamp(1rem, 3.7vw, 1.12rem);
    font-weight: 400;
    line-height: 1.9;
    white-space: pre-wrap;
    text-wrap: pretty;
}

.stationery-surface[data-font="default"] .stationery-title,
.stationery-surface[data-font="default"] .stationery-body {
    font-family: Pretendard, "Noto Sans KR", sans-serif;
}

.stationery-surface[data-font="serif"] .stationery-title,
.stationery-surface[data-font="serif"] .stationery-body {
    font-family: "Maru Buri", MaruBuri, Lora, AppleMyungjo, serif;
}

.stationery-surface[data-font="soft"] .stationery-title,
.stationery-surface[data-font="soft"] .stationery-body {
    font-family: "Oru Gowun Dodum", Pretendard, "Noto Sans KR", sans-serif;
    font-weight: 400;
    letter-spacing: -.012em;
}

.stationery-surface[data-font="handwriting"] .stationery-title,
.stationery-surface[data-font="handwriting"] .stationery-body {
    font-family: "Oru Nanum Pen", "Maru Buri", MaruBuri, AppleMyungjo, serif;
    font-weight: 400;
    letter-spacing: .01em;
}

.stationery-surface[data-font="handwriting"] .stationery-title { font-size: clamp(1.65rem, 5.4vw, 2.2rem); }
.stationery-surface[data-font="handwriting"] .stationery-body {
    font-size: clamp(1.28rem, 4.6vw, 1.52rem);
    line-height: 1.7;
}

.stationery-surface .stationery-sticker-layer {
    position: absolute;
    z-index: 4;
    inset: 0;
    pointer-events: none;
}

.stationery-surface .stationery-sticker {
    position: absolute;
    left: var(--stationery-x);
    top: var(--stationery-y);
    display: block;
    width: clamp(52px, 14%, 96px);
    aspect-ratio: 1;
    margin: 0;
    padding: 0;
    transform: translate(-50%, -50%) rotate(var(--stationery-rotation)) scale(var(--stationery-scale));
    transform-origin: center;
    appearance: none;
    user-select: none;
    touch-action: none;
    background: transparent;
    border: 0;
    filter: drop-shadow(0 3px 3px rgba(52, 45, 34, .13));
}

.stationery-surface .stationery-sticker img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.stationery-surface[data-editable="true"] .stationery-sticker-layer { pointer-events: auto; }
.stationery-surface[data-editable="true"] .stationery-sticker { cursor: grab; pointer-events: auto; }
.stationery-surface[data-editable="true"] .stationery-sticker:active { cursor: grabbing; }
.stationery-surface[data-editable="true"] .stationery-sticker:focus-visible {
    outline: 3px solid var(--oru-primary, #48594e);
    outline-offset: 4px;
    border-radius: 12px;
}

.stationery-surface .stationery-transform-controls {
    position: absolute;
    z-index: 6;
    left: var(--stationery-x);
    top: var(--stationery-y);
    width: clamp(52px, 14%, 96px);
    aspect-ratio: 1;
    transform: translate(-50%, -50%) rotate(var(--stationery-rotation)) scale(var(--stationery-scale));
    transform-origin: center;
    border: 2px dashed var(--oru-primary, #596b5d);
    border-radius: 12px;
    pointer-events: none;
}

.stationery-surface .stationery-transform-handle {
    position: absolute;
    display: grid;
    place-items: center;
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    margin: 0;
    padding: 0;
    color: #fffdf8;
    font: 700 19px/1 Pretendard, sans-serif;
    background: var(--oru-primary, #596b5d);
    border: 2px solid #fffdf8;
    border-radius: 50%;
    box-shadow: 0 3px 10px rgba(42, 48, 39, .24);
    touch-action: none;
    pointer-events: auto;
}

.stationery-surface .stationery-rotate-handle {
    top: -45px;
    left: 50%;
    transform: translateX(-50%) var(--stationery-handle-correction);
}

.stationery-surface .stationery-scale-handle {
    right: -18px;
    bottom: -18px;
    transform: var(--stationery-handle-correction);
}

html.dark .stationery-surface .stationery-transform-handle {
    color: #252821;
    background: #bac99a;
    border-color: #252821;
}

html.dark .stationery-surface {
    --stationery-paper: #292b26;
    --stationery-ink: #e4e6e0;
    --stationery-muted: #aeb4ad;
    --stationery-line: rgba(195, 200, 193, .15);
    --stationery-grid: rgba(195, 200, 193, .12);
    --stationery-shadow: rgba(0, 0, 0, .30);
}

html.dark .stationery-surface[data-collection="mono-note"] {
    --stationery-paper: #242526; --stationery-ink: #f0f0ed; --stationery-muted: #aeb0ac;
    --stationery-line: rgba(228, 230, 226, .17); --stationery-grid: rgba(228, 230, 226, .12);
}
html.dark .stationery-surface[data-collection="pastel-memo"] {
    --stationery-paper: #302d35; --stationery-ink: #f1eaf3; --stationery-muted: #c2b7c6;
    --stationery-line: rgba(224, 199, 226, .16); --stationery-grid: rgba(224, 199, 226, .12);
}
html.dark .stationery-surface[data-collection="travel-notebook"] {
    --stationery-paper: #332c23; --stationery-ink: #f1e4cf; --stationery-muted: #c0ad91;
    --stationery-line: rgba(210, 177, 128, .18); --stationery-grid: rgba(210, 177, 128, .13);
}
html.dark .stationery-surface[data-frame="line"] .stationery-canvas {
    border-color: rgba(231, 229, 218, .58);
    box-shadow: 0 10px 32px var(--stationery-shadow), inset 0 0 0 5px var(--stationery-paper), inset 0 0 0 6px rgba(231, 229, 218, .18);
}

html.dark .stationery-surface .stationery-photo { background: #383b36; }
html.dark .stationery-surface .stationery-media-error {
    background: linear-gradient(145deg, #33362f, #292c27);
}
html.dark .stationery-surface[data-frame="tape"] .stationery-canvas::before,
html.dark .stationery-surface[data-frame="tape"] .stationery-canvas::after {
    background: rgba(151, 130, 87, .62);
}

@media (max-width: 359px) {
    .stationery-surface .stationery-paper { padding-inline: 20px; }
    .stationery-surface .stationery-sticker { width: clamp(46px, 15%, 64px); }
}

@media (min-width: 768px) {
    .stationery-surface .stationery-photo { aspect-ratio: 16 / 10; }
    .stationery-surface .stationery-paper { min-height: 360px; }
}

@media (prefers-reduced-motion: reduce) {
    .stationery-surface .stationery-sticker { transition: none !important; }
}

@media print {
    .stationery-surface .stationery-canvas { box-shadow: none; }
}
