:root {
    --bg-color: #FAFAFA;
    --surface-color: #FFFFFF;
    --primary-color: #111827;
    --accent-color: #2563EB;
    --accent-light: #EFF6FF;
    --text-main: #1F2937;
    --text-sub: #6B7280;
    --border-color: #E5E7EB;
    --success-color: #10B981;
    --selected-border: #2563EB;
    --selected-bg: #EFF6FF;
    --radius-lg: 16px;
    --radius-md: 8px;
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.05), 0 4px 6px -2px rgba(0,0,0,0.025);
    --transition: all 0.3s cubic-bezier(0.16,1,0.3,1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Noto Sans JP', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 40px 0 0;
}

.container {
    width: calc(100% - 40px);
    max-width: 960px;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    margin-bottom: 40px;
    animation: fadeIn 0.8s ease-out;
}

header { text-align: center; margin-bottom: 40px; }

h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.subtitle { font-size: 14px; color: var(--text-sub); }
.sp-br { display: none; }

/* Cross Nav */
.cross-nav {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 32px;
    flex-wrap: wrap;
}
.cross-nav a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 30px;
    background: #F3F4F6;
    color: var(--text-sub);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: var(--transition);
    border: 1px solid var(--border-color);
}
.cross-nav a:hover {
    background: var(--accent-light);
    color: var(--accent-color);
    border-color: var(--accent-color);
    transform: translateY(-1px);
}
.cross-nav a svg { width: 16px; height: 16px; }

/* Drop Zone */
.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background-color: #fff;
    position: relative;
    overflow: hidden;
    margin-bottom: 32px;
}
.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--accent-color);
    background-color: var(--accent-light);
    transform: scale(1.01);
}
.drop-zone input[type="file"] { display: none; }
.drop-zone-icon {
    font-size: 32px;
    color: var(--border-color);
    margin-bottom: 8px;
    transition: var(--transition);
}
.drop-zone:hover .drop-zone-icon {
    color: var(--accent-color);
    transform: translateY(-5px);
}
.drop-zone-text { font-weight: 500; color: var(--text-main); margin-bottom: 4px; }
.drop-zone-subtext { font-size: 12px; color: var(--text-sub); }
.drop-zone.has-file {
    border-style: solid;
    border-color: var(--border-color);
    padding: 16px 20px;
    cursor: default;
}
.drop-zone.has-file .drop-zone-icon { display: none; }
.drop-zone.has-file .drop-zone-text { font-size: 14px; }

/* File Info Bar */
.file-info-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
}
.file-info-bar .file-icon-small {
    width: 36px; height: 36px;
    border-radius: 6px;
    background-color: #FEF2F2;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.file-info-bar .file-icon-small svg { width: 20px; height: 20px; color: #DC2626; }
.file-info-bar .file-details { text-align: left; }
.file-info-bar .file-name {
    font-weight: 600; font-size: 14px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-width: 300px;
}
.file-info-bar .file-meta {
    font-size: 11px; color: var(--text-sub);
    display: flex; gap: 12px;
}
.file-info-bar .file-meta .page-count { color: var(--accent-color); font-weight: 600; }
.file-info-bar .change-btn {
    font-size: 12px; color: var(--text-sub);
    border: none; background: none; cursor: pointer;
    text-decoration: underline; flex-shrink: 0;
}
.file-info-bar .change-btn:hover { color: var(--accent-color); }

/* Preview Area */
.preview-area { display: none; margin-bottom: 32px; }

/* Toolbar */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}
.selection-count { font-size: 14px; color: var(--text-sub); }
.selection-count strong { color: var(--accent-color); font-size: 18px; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar-btn {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--border-color);
    background: #fff;
    color: var(--text-sub);
}
.toolbar-btn:hover {
    background: var(--accent-light);
    color: var(--accent-color);
    border-color: var(--accent-color);
}
.toolbar-btn.active {
    background: var(--accent-color);
    color: #fff;
    border-color: var(--accent-color);
}

/* Page Grid */
.page-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
}
.page-card {
    position: relative;
    border-radius: var(--radius-md);
    border: 2px solid var(--border-color);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    background: #fff;
}
.page-card:hover {
    border-color: #9CA3AF;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.page-card.selected {
    border-color: var(--selected-border);
    background: var(--selected-bg);
    box-shadow: 0 0 0 1px var(--selected-border);
}
.page-card .canvas-wrapper {
    width: 100%;
    aspect-ratio: 210 / 297;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #F9FAFB;
}
.page-card canvas { max-width: 100%; max-height: 100%; display: block; }
.page-card .page-number {
    text-align: center;
    padding: 6px 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-sub);
    border-top: 1px solid var(--border-color);
    background: #fff;
}
.page-card.selected .page-number {
    color: var(--accent-color);
    background: var(--selected-bg);
    border-top-color: #BFDBFE;
}
.page-card .check-overlay {
    position: absolute;
    top: 8px; right: 8px;
    width: 26px; height: 26px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--border-color);
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
    opacity: 0.7;
}
.page-card:hover .check-overlay { opacity: 1; }
.page-card.selected .check-overlay {
    background: var(--accent-color);
    border-color: var(--accent-color);
    opacity: 1;
}
.page-card .check-overlay svg { width: 14px; height: 14px; color: transparent; }
.page-card.selected .check-overlay svg { color: #fff; }

/* Loading */
.page-card .loading-placeholder {
    width: 100%;
    aspect-ratio: 210 / 297;
    display: flex; align-items: center; justify-content: center;
    background: #F3F4F6;
}
.page-card .loading-placeholder .loading-spinner {
    width: 24px; height: 24px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 0.8s ease-in-out infinite;
}

/* Actions */
.actions {
    margin-top: 32px;
    display: flex;
    justify-content: center;
    gap: 16px;
}
.btn {
    padding: 14px 40px;
    border-radius: 30px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    border: none; outline: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 200px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.btn-primary:hover:not(:disabled) {
    background-color: #000;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}

.spinner {
    width: 20px; height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    display: none;
}

/* Progress */
.progress-area { display: none; margin-top: 24px; }
.progress-bar-track {
    width: 100%; height: 8px;
    background: var(--border-color);
    border-radius: 4px; overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background: var(--accent-color);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}
.progress-text {
    text-align: center;
    font-size: 13px;
    color: var(--text-sub);
    margin-top: 8px;
}

/* Range Input */
.range-input-area { display: none; margin-top: 12px; margin-bottom: 16px; }
.range-input-row { display: flex; gap: 8px; align-items: center; }
.range-input-row input[type="text"] {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    font-family: 'Noto Sans JP', sans-serif;
    outline: none;
    transition: var(--transition);
}
.range-input-row input[type="text"]:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.range-input-row .apply-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: var(--accent-color);
    color: #fff;
    transition: var(--transition);
    white-space: nowrap;
}
.range-input-row .apply-btn:hover { background: #1D4ED8; }
.range-hint { font-size: 11px; color: var(--text-sub); margin-top: 6px; }

/* SEO */
.seo-section {
    width: calc(100% - 40px);
    max-width: 960px;
    margin-top: 32px;
    padding: 0 20px;
    color: var(--text-main);
}
.seo-section h2, .seo-section h3 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--primary-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
}
.seo-section h2 { margin-top: 0; font-size: 22px; }
.seo-section h3 { margin-top: 32px; }
.seo-section p {
    font-size: 14px;
    color: var(--text-sub);
    margin-bottom: 16px;
    line-height: 1.8;
}
.seo-section ol, .seo-section ul {
    margin-left: 20px;
    margin-bottom: 24px;
    color: var(--text-sub);
    font-size: 14px;
}
.seo-section li { margin-bottom: 8px; line-height: 1.8; }
.seo-section a { color: var(--accent-color); }

footer {
    width: 100%;
    margin-top: 32px;
    padding: 40px 20px;
    background-color: white;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 12px;
    color: var(--text-sub);
}
footer a {
    color: var(--text-sub);
    text-decoration: none;
    transition: color 0.2s;
}
footer a:hover {
    color: var(--accent-color);
    text-decoration: underline;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
    .sp-br { display: inline; }
    .container { padding: 24px; }
    .page-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 10px;
    }
    .btn { width: 100%; min-width: unset; }
    .toolbar { flex-direction: column; align-items: flex-start; }
    .file-info-bar .file-name { max-width: 160px; }
}
