/* 폰트 강제 적용 */
* {
    -webkit-font-smoothing: antialiased;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Serif KR', serif;
    /* Modern Literary: Cream Background, Charcoal Text */
    background-color: #FDFBF7;
    color: #2C3E50;
    overscroll-behavior: none;
    /* 스크롤 튕김 방지 */
}

/* 하이라이트 스타일 - 그룹 ID 속성 활용 */
.highlight {
    display: inline;
    background: rgba(255, 235, 59, 0.4);
    padding: 0;
    margin: 0;
    line-height: inherit;
    letter-spacing: inherit;
    vertical-align: baseline;
    border: none;
    outline: none;
    cursor: pointer;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

.highlight-yellow {
    background: rgba(255, 235, 59, 0.4);
}

.highlight-pink {
    background: rgba(255, 182, 193, 0.4);
}

.highlight-mint {
    background: rgba(178, 255, 222, 0.4);
}

.highlight-blue {
    background: rgba(173, 216, 230, 0.4);
}

.highlight-lavender {
    background: rgba(224, 176, 255, 0.4);
    /* Pastel Lavender */
}

.highlight-apricot {
    background: rgba(255, 203, 164, 0.4);
    /* Pastel Apricot */
}

/* 1. Ink Pen Style (Thin, elegant, navy) */
.highlight-ink {
    background: transparent;
    /* Irregular thin line */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='40' viewBox='0 0 200 40' preserveAspectRatio='none'%3E%3Cpath d='M0,35 Q50,34 100,35 T200,35' stroke='%23475569' stroke-width='1.5' fill='none' stroke-linecap='round' opacity='0.9'/%3E%3C/svg%3E");
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: bottom;
    padding-bottom: 2px;
}

/* 2. Watercolor Drop Style (Thick, bottom-aligned, watery blue) */
.highlight-drop {
    background: linear-gradient(to top, rgba(56, 189, 248, 0.4) 0%, rgba(56, 189, 248, 0.1) 30%, transparent 70%);
    background-position: bottom;
    background-repeat: no-repeat;
    background-size: 100% 40%;
    /* Only heavy at bottom */
    padding-bottom: 0px;
}

/* 3. Zigzag/Stitch Style (Dashed/Dotted, warm brown) */
.highlight-zigzag {
    background: transparent;
    /* Dotted Stitch Line */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40' preserveAspectRatio='none'%3E%3Cpath d='M0,35 L40,35' stroke='%2378350f' stroke-width='2' stroke-dasharray='4,4' fill='none' opacity='0.8'/%3E%3C/svg%3E");
    background-size: 40px 100%;
    /* Repeat pattern */
    background-repeat: repeat-x;
    background-position: bottom;
    padding-bottom: 4px;
}



/* 글자 색 스타일 */
.colored-text {
    display: inline;
    cursor: pointer;
    line-height: inherit;
    letter-spacing: inherit;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

/* 글자 색 스타일 (12색 확장) */
.text-crimson {
    color: #be123c;
}

.text-terracotta {
    color: #c2410c;
}

.text-mustard {
    color: #ca8a04;
}

.text-brown {
    color: #78350f;
}

.text-cocoa {
    color: #8d6e63;
}

.text-olive {
    color: #65a30d;
}

.text-forest {
    color: #15803d;
}

.text-teal {
    color: #0f766e;
}

.text-navy {
    color: #1e3a8a;
}

.text-midnight {
    color: #1e1b4b;
}

.text-purple {
    color: #6b21a8;
}

.text-lightgray {
    color: #a1a1aa;
}

/* Light Gray replacing Slate */

/* 글자 색 선택 버튼 (배경색) - Not actively used but kept for reference if needed */
.bg-text-crimson {
    background-color: #be123c;
}

/* 화면용 스타일 - A6 비율 (105:148) */
.page-container {
    /* 깊이감 있는 그림자 */
    /* 깊이감 있는 그림자 */
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    background: white;
    margin: 0 auto;
    /* width/height removed to support inline MM dimensions (A6, A5, B5) */
    flex-shrink: 0;
    padding: 60px 60px 50px 60px;
    position: relative;
    display: flex;
    flex-direction: column;
    transform-origin: top center;
    transition: background-color 0.3s, color 0.3s;
}

/* 테마별 스타일 */
.theme-white.page-container {
    background: #ffffff;
    color: #222222;
}

.theme-cream.page-container {
    background: #fdfbf7;
    color: #2c241b;
}

.theme-kraft.page-container {
    background: #e6dac3;
    color: #33201c;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.05'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: cover;
}

.theme-dark.page-container {
    background: #1a1a1a;
    color: #b0b0b0;
}

.page-content {
    /* Base for A6 (Default) */
    /* REMOVED fixed height to allow dynamic filling via flexbox */
    /* height: 460px; */
    flex: 1;
    font-size: 11.5px;
    line-height: 1.8 !important;
    text-align: justify;
    letter-spacing: -0.02em;
    letter-spacing: -0.02em;
    word-break: normal;
    /* 기본 언어 규칙에 따른 줄바꿈 */
    overflow-wrap: anywhere;
    font-weight: 300;
    font-weight: 300;
    cursor: text;
}

/* A5 Specific Font Size */
.size-a5 .page-content {
    font-size: 11.5px;
}

/* A6 Specific Tweaks */
.size-a6 .page-content {
    font-size: 12px;
    line-height: 22px !important;
    letter-spacing: -0.03em;
    text-align: justify;
    text-justify: inter-character;
}

.size-a6 .page-content p {
    line-height: 22px !important;
    text-indent: 12px;
    margin-bottom: 0 !important;
    font-size: 12px !important;
}

.size-a6 .page-footer-area {
    position: absolute;
    bottom: 50px;
    left: 50px;
    right: 50px;
    width: auto;
    padding-bottom: 0;
    height: auto;
}

/* 하이라이트 상태에서도 스타일 유지 */
.page-content p {
    margin-bottom: 0;
    padding: 0;
    text-indent: 1em;
    line-height: 1.8 !important;
}

.page-content p.continued {
    text-indent: 0 !important;
}

.page-footer-area {
    height: 15px;
    margin-top: auto;
    display: flex;
    align-items: flex-end;
    padding-bottom: 5px;
}

.hidden-measure {
    position: absolute;
    visibility: hidden;
    top: -9999px;
    left: -9999px;
    width: 300px;
    font-size: 11.5px;
    line-height: 1.8 !important;
    text-align: justify;
    letter-spacing: -0.02em;
    word-break: normal;
    /* 단어 단위 줄바꿈 */
    overflow-wrap: anywhere;
    font-weight: 300;
}

.hidden-measure p {
    margin-bottom: 0;
    line-height: 1.8 !important;
}

.circle-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.circle-btn:hover {
    transform: scale(1.1);
}

.circle-btn.active {
    border-color: #333;
    transform: scale(1.1);
}

.theme-btn-white {
    background: #ffffff;
    border: 1px solid #ddd;
}

.theme-btn-cream {
    background: #fdfbf7;
    border: 1px solid #e6e0d4;
}

.theme-btn-kraft {
    background: #e6dac3;
    border: 1px solid #cbbba0;
}

.theme-btn-dark {
    background: #1a1a1a;
    border: 1px solid #444;
}

.btn {
    transition: all 0.2s;
}

.btn:active {
    transform: scale(0.98);
}

.custom-placeholder {
    position: absolute;
    top: 24px;
    left: 24px;
    right: 24px;
    bottom: 24px;
    pointer-events: none;
    color: #94a3b8;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
}

@media (max-width: 450px) {
    #bookViewerWrapper {
        transform: scale(0.82);
        /* 사이즈 축소 0.85 -> 0.82 */
        transform-origin: top center;
    }
}

/* ----------------------------------------------------------------- */
/* MOCKUP STYLES */
/* ----------------------------------------------------------------- */
.mockup-book-wrapper {
    position: relative;
    /* Changed from absolute to relative for better flexbox centering on PC */
    /* width/height removed - let children determine size */
    display: flex;
    transition: transform 0.3s ease;
}

.mockup-page {
    /* width/height removed - inline styles control this (105mm, 148mm etc) */
    position: relative;
    z-index: 10;
    overflow: hidden;
    transform: translateZ(0);
    -webkit-mask-image: -webkit-radial-gradient(white, black);
    mask-image: radial-gradient(white, black);
    isolation: isolate;
}

.effect-gutter-left {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 80px;
    background: linear-gradient(to right,
            transparent 0%,
            rgba(0, 0, 0, 0.01) 30%,
            rgba(0, 0, 0, 0.03) 60%,
            rgba(0, 0, 0, 0.08) 85%,
            rgba(0, 0, 0, 0.15) 100%);
    pointer-events: none;
    z-index: 20;
    mix-blend-mode: multiply;
}

.effect-gutter-right {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 80px;
    background: linear-gradient(to left,
            transparent 0%,
            rgba(0, 0, 0, 0.01) 30%,
            rgba(0, 0, 0, 0.03) 60%,
            rgba(0, 0, 0, 0.08) 85%,
            rgba(0, 0, 0, 0.15) 100%);
    pointer-events: none;
    z-index: 20;
    mix-blend-mode: multiply;
}

.flyleaf {
    width: 100%;
    height: 100%;
    background-color: #1a2233;
    padding: 60px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    position: relative;
    cursor: pointer;
}

.flyleaf.front {
    align-items: flex-start;
    text-align: left;
}

.flyleaf.back {
    align-items: flex-end;
    text-align: right;
}

.flyleaf textarea {
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 300;
}

@keyframes blink {
    0% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.5;
    }
}

.flyleaf-hint {
    position: absolute;
    top: 24px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 11px;
    pointer-events: none;
    white-space: nowrap;
    border: 1px dashed rgba(255, 255, 255, 0.3);
    background-color: rgba(255, 255, 255, 0.05);
    padding: 6px 10px;
    border-radius: 6px;
    animation: blink 2s infinite ease-in-out;
}

.flyleaf.front .flyleaf-hint {
    left: 0;
}

.flyleaf.back .flyleaf-hint {
    right: 0;
}

.mockup-scaler {
    transform-origin: center center;
}

@media (max-width: 900px) {
    .mockup-scaler {
        transform: scale(0.42);
    }
}

/* New Glassmorphism & UI Utilities */
/* iPhone Safe Area Utilities */
.pb-safe {
    padding-bottom: env(safe-area-inset-bottom);
}

.pt-safe {
    padding-top: env(safe-area-inset-top);
}

/* Transparent Glass Button (Header) */
.glass-btn {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #4b5563;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    cursor: pointer;
}

.glass-btn:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.4);
}

/* Transparent Glass Pill (Page Indicator) */
.glass-pill {
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    border-radius: 9999px;
    color: #334155;
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Layer 2 Transition */
.layer2-container {
    transition: transform 0.3s cubic-bezier(0.33, 1, 0.68, 1), opacity 0.3s ease;
}

.layer2-visible {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.layer2-hidden {
    transform: translateY(100%);
    /* Completely slide down */
    opacity: 0;
    pointer-events: none;
}

@keyframes bounceSlight {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

.animate-bounce-slight {
    animation: bounceSlight 1.5s infinite;
}

.no-scrollbar::-webkit-scrollbar {
    display: none;
}

.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Centered Toast Overlay Strategy - Robust for Mobile */
.toast-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-box {
    background-color: #1a1a1a;
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
}

/* Exit Toast Centering */
.toast-exit {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(30, 41, 59, 0.9);
    color: white;
    padding: 12px 24px;
    border-radius: 9999px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
    animation: bounceSlight 1.5s infinite;
}