* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
    background: #e6e6e6;
    overflow: hidden;
    /* ★追加：バウンススクロールを禁止する（iOS/Android共通） */
    overscroll-behavior: none;
    position: fixed; /* 画面全体を固定して動かさない */
    width: 100%;
    height: 100%;
}

/* ===== ツールバー（上部固定） ===== */
#toolbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 48px;
    background: #474a4d;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 15px;
    gap: 8px;
    z-index: 1000;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* ===== メインレイアウト（ツールバー分下げる） ===== */
#main {
    margin-top: 48px;
    height: calc(100vh - 48px);
    display: flex;
    overflow: hidden;
    position: relative;
}

#thumbnails-container {
    width: 200px;
    height: 100%;
    background: #f4f4f4;
    padding: 20px 10px;
    overflow-y: auto;
    border-right: 1px solid #ccc;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    transition: margin-left 0.3s ease;
    z-index: 100;
}

#thumbnails-container.closed {
    margin-left: -200px;
    padding-left: 0;
    padding-right: 0;
}

#toggle-btn {
    position: absolute;
    top: 58px; /* ツールバーのすぐ下 */
    left: 10px;
    z-index: 1100;
    width: 36px;
    height: 36px;
    background: #333;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== 表示エリア ===== */
#viewer-container {
    flex-grow: 1;
    height: 100%;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 30px;
    position: relative;
    background: #e6e6e6;
    perspective: 2500px;
}

#viewer {
    position: relative;
    user-select: none;
    transform-style: preserve-3d;
}

canvas {
    background: white;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    display: block;
    backface-visibility: hidden;
}

.page-wrapper { margin: 0 auto; }

.textLayer {
    position: absolute;
    left: 0; top: 0; right: 0; bottom: 0;
    overflow: hidden;
    line-height: 1.0;
    white-space: pre;
    pointer-events: auto;
}

.textLayer span {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
}

/* ===== ツールバー要素 ===== */
.tool-group { display: flex; align-items: center; gap: 2px; }
.separator { width: 1px; height: 20px; background: #666; margin: 0 10px; }
.tool-btn {
    background: transparent; border: none; color: #ccc;
    width: 36px; height: 36px; border-radius: 4px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.tool-btn:hover { background: #5a5d60; color: white; }
.tool-btn svg { fill: currentColor; width: 20px; height: 20px; }

.page-input-container {
    display: flex;
    align-items: center;
    gap: 3px;          /* 隙間を少し詰める */
    font-size: 14px;
    background: #5a5d60;
    padding: 4px 8px;  /* 左右の余白を調整 */
    border-radius: 4px;
    margin: 0 2px;     /* 外側の余白を詰める */
    white-space: nowrap; /* 絶対に改行させない */
    min-width: 75px;   /* 3桁でも余裕を持って収まる最小幅 */
    justify-content: center;
}
#page_num_input {
    background: transparent;
    border: none;
    color: #fff;
    width: 32px;       /* 3桁(999)がちょうど収まる幅に固定 */
    text-align: right; /* /16 との距離を一定にするため右寄せ */
    font-size: 14px;
    font-weight: bold;
    outline: none;
    padding: 0;
    margin: 0;
}

.page-total {
    color: #aaa;
    margin-left: 2px;
}

/* ===== スマホ対応（レスポンシブ） ===== */
@media screen and (max-width: 600px) {
    #toolbar {
        gap: 1px;      /* ボタン同士を限界まで詰める */
        padding: 0 4px;
    }

    .tool-group {
        gap: 0px;      /* グループ内のボタンを密着させる */
    }

    .separator {
        margin: 0 2px; /* 区切り線周りもスリムに */
    }
}

/* アニメーション省略（既存のまま） */
.flipping-next { animation: flipNext 0.5s ease-in-out forwards; transform-origin: left center; }
.flipping-prev { animation: flipPrev 0.5s ease-in-out forwards; transform-origin: right center; }
@keyframes flipNext { 0% { transform: rotateY(0deg); opacity: 1; } 100% { transform: rotateY(-90deg); opacity: 0; } }
@keyframes flipPrev { 0% { transform: rotateY(0deg); opacity: 1; } 100% { transform: rotateY(90deg); opacity: 0; } }

#loading-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    
    /* 背景と枠の設定 */
    background: rgba(255, 255, 255, 0.95);
    padding: 20px 30px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    color: #333;
    font-weight: bold;
    text-align: center;
    line-height: 1.5;

    /* ★ここが重要：サイズを文字に合わせ、自動改行を防ぐ */
    width: max-content;       /* 幅を中身（文字）の最大幅に合わせる */
    white-space: nowrap;      /* 改行を禁止する（<br>がある所だけ改行される） */
    
    pointer-events: none;
}

/* スマホで文字が大きすぎると画面を突き抜けるので、少し調整 */
@media screen and (max-width: 480px) {
    #loading-message {
        font-size: 14px;
        padding: 15px 20px;
    }
}