body {
    margin: 0;
    background: #eeeeee;
    font-family: 'Pretendard', sans-serif;
}

#header {
    padding: 14px 16px 10px;
    background: #f6f6f6;
    border-bottom: 1px solid #ccc;
}

.titleInput {
    width: auto;
    min-width: 180px;
    max-width: 420px;
    border: none;
    background: transparent;
    font-size: 24px;
    font-weight: 700;
    outline: none;
}

#topButtons {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

button {
    padding: 8px 14px;
    font-size: 14px;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    color: #2f3747;
    background: #ffffff;
    border: 1px solid #d7dfec;
    border-radius: 10px;
    box-shadow: 0 1px 0 rgba(30, 60, 100, 0.05);
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

button:hover {
    background: #f3f8ff;
    border-color: #9dc2ff;
}

button:active {
    transform: translateY(1px);
}

button:disabled {
    color: #aeb7c4;
    background: #f6f7f9;
    border-color: #e1e5eb;
    cursor: default;
    transform: none;
}

.iconHelpBtn {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 999px;
    font-size: 17px;
    color: #2f80ff;
}

.divider {
    width: 1px;
    height: 28px;
    background: #bbb;
    margin: 0 8px;
}

#pageInfo {
    font-weight: bold;
    margin: 0 8px;
}

#layout {
    display: grid;
    grid-template-columns: 560px 300px 230px auto;
    gap: 18px;
    padding: 16px;
    align-items: start;
}

#pageCanvas {
    width: 560px;
    height: 793px;
    background: white;
    border: 2px solid black;
    position: relative;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

#pageGuide {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
}

.workLine {
    position: absolute;
    left: 19px;
    top: 19px;
    right: 19px;
    bottom: 19px;
    border: 1px dashed #4a90ff;
}

.safeLine {
    position: absolute;
    left: 56px;
    top: 56px;
    right: 56px;
    bottom: 56px;
    border: 1px dashed #cfcfcf;
}

#sidePanel {
    background: white;
    border: 1px solid #ccc;
    padding: 16px;
}

#sidePanel label {
    display: block;
    margin-top: 12px;
    font-weight: bold;
}

textarea {
    width: 100%;
    height: 105px;
    box-sizing: border-box;
    margin-top: 6px;
    resize: vertical;
}

#cutSettingsPanel {
    margin-top: 18px;
    padding: 8px;
    border: 1px solid #dfe7f3;
    border-radius: 12px;
    background: #f8fbff;
}

#cutSettingsToggleBtn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border: none;
    background: transparent;
    box-shadow: none;
    font-size: 14px;
    border-radius: 9px;
}

#cutSettingsToggleBtn:hover {
    background: #eef5ff;
}

.cutSettingsArrow {
    font-size: 13px;
    transition: transform 0.16s ease;
}

#cutSettingsPanel:not(.collapsed) .cutSettingsArrow {
    transform: rotate(180deg);
}

#cutSettingsBody {
    padding: 4px 4px 6px;
}

#cutSettingsPanel.collapsed #cutSettingsBody {
    display: none;
}

.cutSettingRow {
    display: grid;
    grid-template-columns: 1fr 70px 24px;
    align-items: center;
    gap: 6px;
    margin-top: 8px !important;
    font-size: 13px;
}

.cutSettingRow > input[type="number"] {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    border: 1px solid #d7dfec;
    border-radius: 8px;
    font: inherit;
    text-align: right;
}

.cutSettingTitleWithCheck {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.fontCheckbox {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    margin: 0 !important;
    padding: 3px 7px;
    border: 1px solid #d7dfec;
    border-radius: 999px;
    background: white;
    color: #4d5a6b;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

.fontCheckbox input {
    width: 13px;
    height: 13px;
    margin: 0;
    accent-color: #2f80ff;
}

.cutSettingRow .unit {
    color: #7b8794;
    font-size: 12px;
}

.cutSettingToggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 10px !important;
    font-size: 13px;
}

.cutSettingToggle input {
    width: 18px;
    height: 18px;
    accent-color: #2f80ff;
}

.cutSettingSelect {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 10px !important;
    font-size: 13px;
}

.cutSettingSelect select {
    width: 92px;
    box-sizing: border-box;
    padding: 6px 8px;
    border: 1px solid #d7dfec;
    border-radius: 8px;
    background: white;
    font: inherit;
    font-weight: 700;
}




#drawingCanvas {
    position: absolute;
    left: 0;
    top: 0;
    width: 560px;
    height: 793px;
    z-index: 999;
    pointer-events: none;
    touch-action: none;
}

.polygonCut {
    pointer-events: none;
    touch-action: none;
}

.polygonCut polygon,
.polygonCut circle,
.polygonCut ellipse,
.polygonCut text,
.polygonCut rect {
    pointer-events: all;
    touch-action: none;
}

.inlineTextEditor {
    position: absolute;
    z-index: 1000;
    box-sizing: border-box;
    margin: 0;
    padding: 6px 8px;
    border: 2px solid #2f80ff;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.96);
    color: #111;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.35;
    resize: none;
    outline: none;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.16);
    touch-action: manipulation;
}

.inlineTextEditor-bubble,
.inlineTextEditor-narration {
    text-align: center;
}

.inlineTextEditor-memo {
    color: #1f6fff;
    font-weight: 600;
}

.toolActive {
    background: #2f80ff;
    color: white;
    border-color: #2f80ff;
    box-shadow: 0 4px 12px rgba(47, 128, 255, 0.24);
}

#eraserCursor {
    position: fixed;
    border: 1px solid #2f80ff;
    border-radius: 50%;
    pointer-events: none;
    z-index: 9999;
    display: none;
}

#previewOverlay {
    position: fixed;
    inset: 0;
    background: #eeeeee;
    z-index: 10000;
    display: none;
    overflow: auto;
}

#previewHeader {
    position: sticky;
    top: 0;
    background: white;
    border-bottom: 1px solid #ccc;
    padding: 12px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#previewBook {
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    align-items: center;
}

#helpOverlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(38, 45, 56, 0.28);
    z-index: 30000;
    padding: 24px;
    box-sizing: border-box;
}

#helpPanel {
    width: min(420px, 100%);
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    background: white;
    border: 1px solid #d7dfec;
    border-radius: 14px;
    box-shadow: 0 18px 48px rgba(30, 60, 100, 0.2);
}

#helpHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid #e6edf7;
}

#helpHeader strong {
    font-size: 18px;
}

#helpHeader button {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 9px;
}

.helpSection {
    padding: 12px 16px 4px;
}

.helpSection:last-child {
    padding-bottom: 16px;
}

.helpSection h4 {
    margin: 0 0 8px;
    font-size: 14px;
}

.helpSection p {
    margin: 5px 0;
    color: #3e4856;
    font-size: 13px;
    line-height: 1.45;
}

.helpSignature {
    margin: 10px 16px 16px;
    padding-top: 12px;
    border-top: 1px solid #e6edf7;
    color: #8b96a6;
    font-size: 12px;
    font-weight: 800;
    text-align: right;
    letter-spacing: 0;
}

.previewSpread {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.previewPage {
    width: 280px;
    height: 396px;
    background: white;
    border: 1px solid #999;
    position: relative;
}

.previewPage.blank {
    background: transparent;
    border: none;
}

.previewPageLabel {
    text-align: center;
    font-weight: bold;
    margin-top: 6px;
}

#pagePreviewPanel {
    background: white;
    border: 1px solid #ccc;
    padding: 10px;
    max-height: 760px;
    overflow-y: auto;
}

#pageViewButtons {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

#pageViewButtons button {
    flex: 1;
    padding: 7px 8px;
    font-size: 12px;
    border-radius: 9px;
}

.viewActive {
    background: #2f80ff;
    color: white;
    border-color: #2f80ff;
    box-shadow: 0 4px 12px rgba(47, 128, 255, 0.22);
}

#pageList {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pageSpread {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: flex-start;
}

.pageThumb {
    width: 78px;
    height: 113px;
    background: white;
    border: 2px solid #999;
    cursor: pointer;
    font-size: 11px;
    flex-shrink: 0;
    position: relative;
}

.pageThumb.blank {
    border: none;
    background: transparent;
    cursor: default;
}

.pageThumb.active {
    border-color: #2f80ff;
    background: #eef5ff;
}

.thumbSvg {
    width: 78px;
    height: 113px;
    display: block;
}

.pageThumbLabel {
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(255,255,255,0.9);
    padding: 1px 4px;
    font-size: 10px;
    font-weight: bold;
    border-radius: 3px;
}

.pageThumb.dragging {
    opacity: 0.4;
}

.pageThumb.dragOver {
    outline: 3px solid #ff9900;
    outline-offset: 2px;
}

#pageContextMenu {
    position: fixed;
    display: none;
    background: white;
    border: 1px solid #d7dfec;
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(30, 60, 100, 0.16);
    z-index: 20000;
    padding: 6px;
}

#pageContextMenu button {
    display: block;
    width: 142px;
    padding: 8px 10px;
    border: none;
    background: transparent;
    text-align: left;
    box-shadow: none;
    border-radius: 8px;
}

#pageContextMenu button:hover {
    background: #eef5ff;
}

#saveMenu {
    position: fixed;
    display: none;
    background: white;
    border: 1px solid #d7dfec;
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(30, 60, 100, 0.16);
    z-index: 20000;
    padding: 6px;
}

#saveMenu button {
    display: block;
    width: 170px;
    padding: 8px 10px;
    border: none;
    background: transparent;
    text-align: left;
    box-shadow: none;
    border-radius: 8px;
}

#saveMenu button:hover {
    background: #eef5ff;
}

#bookPreviewModal {
    position: fixed;
    inset: 0;
    background: #222;
    display: none;
    z-index: 99999;
    flex-direction: column;
}

#bookPreviewHeader {
    height: 52px;
    background: #111;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 0 18px;
}

#bookPreviewHeader button {
    padding: 6px 12px;
}

#bookPreviewHeader input {
    width: 60px;
    padding: 6px;
    text-align: center;
}

#closeBookPreviewBtn {
    position: absolute;
    right: 18px;
}

#bookPreviewContent {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.bookSpread {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    width: 100%;
    height: 100%;
}

.bookPage {
    height: calc(100vh - 80px);
    aspect-ratio: 560 / 793;
    background: white;
    border: 1px solid #777;
    position: relative;
}

.bookPage canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.bookPage.active {
    outline: 4px solid #2f80ff;
}

.bookPageLabel {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(255,255,255,0.9);
    padding: 2px 6px;
    font-size: 13px;
    font-weight: bold;
}

.bookBlank {
    height: calc(100vh - 80px);
    aspect-ratio: 560 / 793;
}

#titleArea {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}

#titleArea .titleInput {
    flex: 0 0 auto;
    margin-bottom: 0;
}

#projectMenuBtn {
    padding: 6px 10px;
    font-size: 13px;
}

#projectMenu {
    position: fixed;
    display: none;
    background: white;
    border: 1px solid #aaa;
    box-shadow: 0 4px 12px rgba(0,0,0,0.18);
    z-index: 20000;
    padding: 6px;
    min-width: 240px;
}

.projectMenuTitle {
    font-weight: bold;
    padding: 8px 10px;
    border-bottom: 1px solid #ddd;
}

.recentProjectItem {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: none;
    background: white;
    text-align: left;
    cursor: pointer;
}

.recentProjectItem:hover {
    background: #eef5ff;
}

.recentProjectRow {
    display: flex;
    align-items: stretch;
    width: 100%;
}

.recentProjectOpenBtn {
    flex: 1;
}

.recentProjectDeleteBtn {
    flex: 0 0 auto;
    margin: 3px;
    padding: 4px 8px;
    border: 1px solid #ddd;
    background: #fff;
    color: #c0392b;
    font-size: 12px;
}

.recentProjectDeleteBtn:hover {
    background: #fff1f1;
    border-color: #e07a7a;
}

.recentProjectEmpty {
    padding: 10px;
    color: #777;
    font-size: 13px;
}

#saveStatus {
    font-size: 12px;
    color: #777;
    margin-left: 4px;
}

#saveStatus.dirty {
    color: #d98200;
    font-weight: bold;
}

#saveStatus.saved {
    color: #2f8f46;
    font-weight: bold;
}

#cutContextMenu {
    position: fixed;
    display: none;
    background: white;
    border: 1px solid #d7dfec;
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(30, 60, 100, 0.16);
    z-index: 20000;
    padding: 6px;
}

#cutContextMenu button {
    display: block;
    width: 150px;
    padding: 8px 10px;
    border: none;
    background: transparent;
    text-align: left;
    box-shadow: none;
    border-radius: 8px;
}

#cutContextMenu button:hover {
    background: #eef5ff;
}

.contextMenuSeparator {
    height: 1px;
    margin: 4px 6px;
    background: #e3e3e3;
}

#cutContextMenu button:disabled {
    color: #aaa;
    cursor: default;
}

#cutContextMenu button:disabled:hover {
    background: transparent;
}

#memoTabBtn {
    position: absolute;
    left: 0;
    top: 0;
    width: 54px;
    height: 36px;
    padding: 0;
    border: 1px solid #d7dfec;
    background: #ffffff;
    color: #2f3747;
    cursor: pointer;
    font-size: 13px;
    font-weight: 800;
    line-height: 36px;
    text-align: center;
    border-radius: 0 12px 12px 0;
    box-shadow: 2px 3px 10px rgba(30, 60, 100, 0.08);
    white-space: nowrap;
    transition: left 0.25s ease, width 0.25s ease, border-radius 0.25s ease, color 0.15s ease;
    z-index: 10;
}

#memoTabBtn:hover {
    background: #f3f8ff;
    border-color: #9dc2ff;
}

#memoDock.open #memoTabBtn {
    opacity: 0;
    pointer-events: none;
}

#memoDock {
    position: relative;
    display: flex;
    align-items: flex-start;
    height: calc(100vh - 130px);
    align-self: start;
    margin-left: -18px;
}

#memoPanel {
    width: 0;
    height: 100%;

    overflow: hidden;

    background: white;
    border: 0;
    border-radius: 12px;

    transition: width 0.25s ease, border 0.25s ease, box-shadow 0.25s ease;

    display: flex;
    flex-direction: column;
}

#memoDock.open #memoPanel {
    width: 420px;
    border: 1px solid #d7dfec;
    box-shadow: 0 8px 24px rgba(30, 60, 100, 0.12);
}

#memoPanelHeader {
    height: 50px;

    min-width: 420px;

    display: flex;
    justify-content: space-between;
    align-items: center;

    padding: 0 16px;
    border-bottom: 1px solid #ddd;

    font-weight: bold;
    box-sizing: border-box;
}

#memoPanelInput {
    flex: 1;

    min-width: 420px;

    border: none;
    resize: none;

    padding: 24px;

    font-family:
        "Pretendard",
        "Noto Sans KR",
        sans-serif;

    font-size: 15px;
    font-weight: 400;

    line-height: 1.9;
    letter-spacing: -0.01em;

    color: #222;

    outline: none;
    box-sizing: border-box;
}

#memoPanelHeader {
    height: 50px;

    min-width: 420px;

    display: flex;
    justify-content: space-between;
    align-items: center;

    padding: 0 16px;
    border-bottom: 1px solid #ddd;

    font-weight: bold;
    box-sizing: border-box;
}
#sidePanelHeader {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}

#sidePanelHeader h3 {
    margin: 0;
    font-size: 24px;
    line-height: 1.25;
}

#sidePanelActions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
    flex-shrink: 0;
}

#sidePanelActions button {
    padding: 5px 9px;
    font-size: 12px;
    border-radius: 9px;
}

#sidePanelActions button:hover {
    background: #f3f8ff;
    border-color: #9dc2ff;
}

#sidePanelActions button:disabled {
    color: #aaa;
    cursor: default;
}

#sidePanelActions button:disabled:hover {
    background: #f6f7f9;
    border-color: #e1e5eb;
}

#clearPageBtn:hover {
    background: #fff1f1;
    border-color: #e07a7a;
    color: #c0392b;
}

@media (max-width: 1180px) {
    #header {
        padding: 12px;
    }

    #topButtons {
        gap: 7px;
    }

    #topButtons button,
    #topButtons input,
    #topButtons span {
        min-height: 38px;
    }

    button {
        padding: 9px 12px;
        font-size: 14px;
    }

    #layout {
        grid-template-columns: 560px minmax(280px, 1fr);
        gap: 12px;
        padding: 12px;
    }

    #sidePanel {
        min-width: 0;
    }

    #pagePreviewPanel {
        grid-column: 1 / -1;
        max-height: none;
        overflow: visible;
    }

    #pageList {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-start;
    }

    #memoDock {
        grid-column: 1 / -1;
        height: auto;
        min-height: 42px;
        margin-left: 0;
    }

    #memoDock.open #memoPanel {
        width: min(420px, calc(100vw - 24px));
        height: 360px;
    }
}

@media (max-width: 900px) {
    body {
        overflow-x: auto;
    }

    .titleInput {
        min-width: 140px;
        max-width: 280px;
        font-size: 21px;
    }

    #layout {
        grid-template-columns: minmax(560px, 1fr);
        align-items: start;
    }

    #pageCanvas {
        justify-self: start;
    }

    #sidePanel,
    #pagePreviewPanel,
    #memoDock {
        width: 560px;
        box-sizing: border-box;
    }

    textarea {
        min-height: 94px;
    }

    #sidePanelActions button,
    #pageViewButtons button {
        min-height: 38px;
    }
}

@media (pointer: coarse) {
    button {
        min-height: 40px;
    }

    #pageContextMenu button,
    #cutContextMenu button,
    #saveMenu button {
        padding: 11px 12px;
        font-size: 15px;
    }

    .pageThumb {
        width: 88px;
        height: 128px;
    }

    .thumbSvg {
        width: 88px;
        height: 128px;
    }

    #sidePanelActions button {
        min-height: 36px;
    }
}
