/* --- グローバルCSS変数とリセット --- */
:root {
    --bg-gray: #e6e6e6; /* フラットでプレミアムなニュートラルライトグレー */
    --border-color: rgba(0, 0, 0, 0.08);
    --text-primary: #333333;
    --text-muted: #666666;
    --primary-color: #3b82f6; /* モダンブルー */
    --primary-hover: #2563eb;
    --primary-glow: rgba(59, 130, 246, 0.2);
    --font-main: 'Outfit', 'Noto Sans JP', sans-serif;
    --transition-smooth: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html, body {
    width: 100vw;
    height: 100vh;
    overflow: hidden; /* 横および縦のスクロールバーを防止 */
    background-color: var(--bg-gray);
    color: var(--text-primary);
    font-family: var(--font-main);
}

/* --- フローティングサイドナビゲーションボタン --- */
.float-nav-btn {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 42px;
    height: 70px;
    background: rgba(220, 220, 220, 0.85);
    border: 1px solid var(--border-color);
    color: #666666;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 90;
    transition: var(--transition-smooth);
    outline: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
}

.float-left {
    left: 0;
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
    border-left: none;
}

.float-right {
    right: 0;
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
    border-right: none;
}

.float-nav-btn:hover {
    background: rgba(205, 205, 205, 0.95);
    width: 48px;
    color: #222222;
}

.float-nav-btn:active {
    background: rgba(190, 190, 190, 0.95);
}

.float-nav-btn:disabled {
    opacity: 0; /* 完全に見えなくする */
    pointer-events: none; /* クリック不可にする */
}

/* --- 下部コントローラーツールバー --- */
.bottom-toolbar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 75px;
    background: rgba(228, 228, 228, 0.96);
    border-top: 1px solid var(--border-color);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 24px;
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.03);
}

.toolbar-inner {
    display: flex;
    align-items: center;
    justify-content: center; /* すべてのアイテムを中央揃えにする */
    gap: 48px; /* ナビゲーショングループとアクショングループの間の余白 */
}

.nav-group {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.5);
    padding: 4px 10px;
    border-radius: 30px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.nav-btn, .nav-btn-text {
    background: transparent;
    border: none;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    outline: none;
}

.nav-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
}

.nav-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.nav-btn-text {
    padding: 0 10px;
    height: 30px;
    border-radius: 15px;
    font-size: 0.82rem;
    font-weight: 600;
    gap: 6px;
}

.nav-btn-text:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.05);
}

.nav-btn:disabled, .nav-btn-text:disabled {
    opacity: 0.3;
    pointer-events: none;
    cursor: not-allowed;
}

.nav-btn-text .btn-icon {
    color: var(--text-muted);
}

.page-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 0 6px;
}

#input-page {
    width: 48px;
    height: 26px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 4px;
    color: var(--text-primary);
    text-align: center;
    font-family: var(--font-main);
    font-size: 0.88rem;
    font-weight: 600;
    outline: none;
    -webkit-appearance: textfield;
    -moz-appearance: textfield;
    appearance: textfield;
}

#input-page::-webkit-inner-spin-button, 
#input-page::-webkit-outer-spin-button { 
    -webkit-appearance: none;
    margin: 0;
}

.page-separator {
    color: var(--text-muted);
}

.total-pages {
    color: var(--text-primary);
    font-weight: 600;
}

/* --- アクションボタンのグループ --- */
.action-group {
    display: flex;
    align-items: center;
    gap: 16px;
}

.action-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.action-label {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    outline: none;
}

.action-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #111111;
    transform: translateY(-1px);
}

.action-btn:active {
    transform: translateY(1px);
}

/* --- メインビューアワークスペース --- */
.viewer-container {
    height: calc(100vh - 75px); /* 下部ツールバーに合わせて調整 */
    width: 100vw;
    position: relative;
    overflow: hidden; /* コンテナのスクロールバーを非表示にする！ */
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-gray);
    user-select: none;
}

/* ズーム＆パンコンテナ */
.zoom-pan-wrapper {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    transform-origin: center center;
    will-change: transform;
}

.zoom-pan-wrapper:active {
    cursor: grabbing;
}

/* フリップブック要素のスタイル */
.flipbook {
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12), 0 2px 10px rgba(0, 0, 0, 0.06);
    background-color: transparent;
    transition: box-shadow 0.3s ease;
}

.flipbook:hover {
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.18);
}

/* StPageFlipのページスタイル */
.page {
    background-color: #ffffff;
    box-shadow: inset -10px 0 30px rgba(0,0,0,0.02), inset 10px 0 30px rgba(0,0,0,0.02);
    overflow: hidden;
    position: relative;
}

.page-content {
    width: 100%;
    height: 100%;
    position: relative;
}

.page canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* 紙のカール効果を再現するグラデーションの影 */
.page-shadow {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
    z-index: 10;
}

.page-shadow-left {
    right: 0;
    background: linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.08));
}

.page-shadow-right {
    left: 0;
    background: linear-gradient(to left, rgba(0,0,0,0), rgba(0,0,0,0.08));
}

.page-shadow-center {
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    background: linear-gradient(to right, rgba(0,0,0,0) 0%, rgba(0,0,0,0.06) 35%, rgba(0,0,0,0.12) 50%, rgba(0,0,0,0.06) 65%, rgba(0,0,0,0) 100%);
}

/* --- ローディングオーバーレイ --- */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(230, 230, 230, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.loading-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.spinner-container {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(0, 0, 0, 0.05);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.loading-progress {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* --- カスタムモーダルダイアログ（ライトテーマのグラスモルフィズム） --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition-smooth);
}

.modal.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: rgba(245, 245, 245, 0.98);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 90%;
    max-width: 440px;
    padding: 28px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.15);
    transform: translateY(30px);
    transition: var(--transition-smooth);
}

.modal.show .modal-content {
    transform: translateY(0);
}

.modal-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.modal-body {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 24px;
    line-height: 1.5;
}

.print-range-inputs {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 20px 0;
    gap: 12px;
}

.input-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.input-group input {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.15);
    color: var(--text-primary);
    border-radius: 6px;
    padding: 8px 12px;
    font-family: var(--font-main);
    font-size: 0.95rem;
    font-weight: 600;
    outline: none;
    text-align: center;
    transition: var(--transition-smooth);
}

.input-group input:disabled {
    background: #f5f5f5;
    color: #aaaaaa;
    border-color: #e0e0e0;
    cursor: not-allowed;
    opacity: 0.7;
}

.input-group input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-arrow {
    font-size: 1.2rem;
    color: var(--text-muted);
    padding-top: 20px;
}

.print-options {
    margin-top: 16px;
}

.checkbox-container {
    display: flex;
    align-items: center;
    position: relative;
    padding-left: 28px;
    cursor: pointer;
    font-size: 0.9rem;
    user-select: none;
    color: var(--text-primary);
}

.checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    position: absolute;
    top: 1px;
    left: 0;
    height: 18px;
    width: 18px;
    background-color: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    transition: var(--transition-smooth);
}

.checkbox-container:hover input ~ .checkmark {
    background-color: rgba(0, 0, 0, 0.05);
}

.checkbox-container input:checked ~ .checkmark {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
    display: block;
}

.checkbox-container .checkmark:after {
    left: 6px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn {
    padding: 10px 18px;
    border-radius: 6px;
    font-family: var(--font-main);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
    border: none;
}

.btn-secondary {
    background: #ffffff;
    color: var(--text-primary);
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.btn-secondary:hover {
    background: rgba(0, 0, 0, 0.05);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 10px var(--primary-glow);
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 6px 14px rgba(59, 130, 246, 0.3);
}

/* --- 印刷用スタイル --- */
@media print {
    body * {
        visibility: hidden;
    }
    #print-iframe {
        visibility: visible;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
    }
}

/* --- ページローダーアニメーション --- */
.page-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.8);
    border: 3px solid rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(0, 0, 0, 0.4);
    font-size: 11px;
    font-weight: bold;
    font-family: var(--font-main);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    animation: pulse-soft 2s infinite ease-in-out;
    pointer-events: none;
    z-index: 5;
}

@keyframes pulse-soft {
    0% { opacity: 0.3; transform: translate(-50%, -50%) scale(0.9); }
    50% { opacity: 0.8; transform: translate(-50%, -50%) scale(1.1); box-shadow: 0 8px 24px rgba(0,0,0,0.1); }
    100% { opacity: 0.3; transform: translate(-50%, -50%) scale(0.9); }
}

/* --- レスポンシブ（狭幅画面・モバイル用）スタイル --- */
@media (max-width: 768px) {
    /* 下部コントローラーのページ送りボタン（最初/前/次/最後）を非表示にする（画面左右のフローティングボタンとスワイプで操作） */
    #btn-first,
    #btn-prev,
    #btn-next,
    #btn-last {
        display: none !important;
    }

    /* ツールバー全体の余白とボタン間隔をコンパクトに調整 */
    .bottom-toolbar {
        padding: 0 12px;
    }

    .toolbar-inner {
        gap: 20px;
    }

    .nav-group {
        padding: 4px 10px;
        gap: 0;
    }

    .action-group {
        gap: 10px;
    }
}
