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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
                 "Microsoft JhengHei", Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 20px;
}

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

header h1 {
    font-size: 2.5rem;
    margin-bottom: 12px;
    font-weight: 700;
}

.subtitle {
    font-size: 1rem;
    opacity: 0.95;
}

.badge {
    display: inline-block;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    margin-right: 8px;
    font-weight: 600;
}

main {
    background: white;
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.upload-area {
    border: 2px dashed #cbd5e0;
    border-radius: 12px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #f7fafc;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: #667eea;
    background: #ebf4ff;
}

.upload-icon {
    color: #667eea;
    margin-bottom: 16px;
}

.upload-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 4px;
}

.upload-hint {
    font-size: 0.9rem;
    color: #718096;
}

.file-info {
    margin-top: 24px;
    background: #f7fafc;
    border-radius: 12px;
    padding: 20px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: #718096;
    font-size: 0.9rem;
}

.info-value {
    font-weight: 600;
    color: #2d3748;
}

.info-value.highlight {
    color: #667eea;
    font-size: 1.1rem;
}

.settings {
    margin-top: 24px;
}

.settings h2,
.result h2 {
    font-size: 1.3rem;
    margin-bottom: 20px;
    color: #2d3748;
}

.setting-group {
    margin-bottom: 24px;
}

.setting-label {
    display: block;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 12px;
}

.radio-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.radio-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    flex: 1;
    min-width: 140px;
    justify-content: center;
}

.radio-item:hover {
    border-color: #cbd5e0;
}

.radio-item input[type="radio"] {
    accent-color: #667eea;
}

.radio-item:has(input:checked) {
    border-color: #667eea;
    background: #ebf4ff;
    color: #667eea;
}

input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    transition: transform 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.8rem;
    color: #718096;
    gap: 8px;
}

.scale-hint {
    font-weight: 400;
    color: #718096;
    font-size: 0.85rem;
    margin-left: 6px;
}

.info-box {
    background: #ebf4ff;
    border-left: 4px solid #667eea;
    padding: 12px 16px;
    border-radius: 8px;
}

.info-box strong {
    color: #4c51bf;
    display: block;
    margin-bottom: 4px;
}

.info-box p {
    font-size: 0.9rem;
    color: #4a5568;
    margin: 0;
}

.target-input {
    display: flex;
    gap: 8px;
    align-items: center;
}

.target-input input[type="number"] {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.target-input input[type="number"]:focus {
    border-color: #667eea;
}

.target-input select {
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
    outline: none;
}

.target-input select:focus {
    border-color: #667eea;
}

.hint {
    margin-top: 8px;
    font-size: 0.85rem;
    color: #718096;
}

.btn {
    padding: 14px 28px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-secondary {
    background: #edf2f7;
    color: #2d3748;
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.progress {
    margin-top: 24px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    text-align: center;
    margin-top: 12px;
    color: #718096;
    font-size: 0.95rem;
}

.result {
    margin-top: 24px;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: #f7fafc;
    border-radius: 12px;
    padding: 16px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.85rem;
    color: #718096;
    margin-bottom: 8px;
}

.stat-value {
    display: block;
    font-size: 1.2rem;
    font-weight: 700;
    color: #2d3748;
}

.stat-value.highlight {
    color: #667eea;
}

.stat-value.success {
    color: #48bb78;
}

.result-detail {
    background: #f7fafc;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.detail-label {
    color: #718096;
}

.detail-value {
    color: #2d3748;
    font-weight: 600;
}

.actions {
    display: flex;
    gap: 12px;
}

footer {
    text-align: center;
    color: white;
    margin-top: 32px;
    padding: 20px;
    font-size: 0.9rem;
    opacity: 0.9;
}

footer strong {
    color: #fff;
}

/* ── Tabs ─────────────────────────────────────────── */

.tabs {
    display: flex;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 28px;
}

.tab-btn {
    padding: 12px 24px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: #718096;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
    flex-shrink: 0;
}

.tab-btn:hover:not(.active) {
    color: #4a5568;
}

.tab-btn.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

/* ── Image toolbar ────────────────────────────────── */

.img-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 16px 0 8px;
    flex-wrap: wrap;
    gap: 8px;
}

.img-count {
    font-weight: 600;
    color: #4a5568;
    font-size: 0.95rem;
}

.img-toolbar-actions {
    display: flex;
    gap: 8px;
}

/* ── Image grid ───────────────────────────────────── */

.img-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
    margin-top: 4px;
}

.img-item {
    position: relative;
    background: #f7fafc;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e2e8f0;
    cursor: grab;
    transition: border-color 0.15s, box-shadow 0.15s;
    user-select: none;
}

.img-item:hover {
    border-color: #cbd5e0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.img-item.dragging {
    opacity: 0.4;
    cursor: grabbing;
}

.img-item.drag-over {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
}

.img-item img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: contain;
    background: white;
    display: block;
}

.img-order {
    position: absolute;
    top: 6px;
    left: 6px;
    background: #667eea;
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    pointer-events: none;
}

.img-remove {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.45);
    color: white;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    transition: background 0.2s;
}

.img-remove:hover {
    background: #e53e3e;
}

.img-name {
    padding: 6px 8px;
    font-size: 0.72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #4a5568;
    background: white;
    border-top: 1px solid #e2e8f0;
}

/* ── Image actions ────────────────────────────────── */

.img-actions {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.img-actions .hint {
    margin: 0;
    text-align: center;
}

/* ── Button variants ──────────────────────────────── */

.btn-sm {
    padding: 8px 14px;
    font-size: 0.875rem;
    width: auto;
}

.btn-outline-danger {
    background: transparent;
    color: #e53e3e;
    border: 2px solid #e53e3e;
}

.btn-outline-danger:hover {
    background: #fff5f5;
}

/* ── PDF 轉圖片 ───────────────────────────────────── */

.result-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.result-header h2 {
    margin-bottom: 0;
}

.result-summary {
    font-size: 0.9rem;
    color: #667eea;
    font-weight: 600;
}

.image-actions {
    margin-bottom: 24px;
}

.p2i-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
}

.p2i-card {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.p2i-thumb {
    width: 100%;
    height: 180px;
    object-fit: contain;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.p2i-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.p2i-page {
    font-weight: 600;
    color: #2d3748;
}

.p2i-size {
    color: #718096;
}

.p2i-card .btn-sm {
    width: 100%;
}

/* ── Responsive ───────────────────────────────────── */

@media (max-width: 600px) {
    header h1 {
        font-size: 1.8rem;
    }

    main {
        padding: 20px;
    }

    .result-stats {
        grid-template-columns: 1fr;
    }

    .actions {
        flex-direction: column;
    }

    .radio-item {
        min-width: 100%;
    }

    .tab-btn {
        padding: 10px 8px;
        font-size: 0.9rem;
    }

    .p2i-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .p2i-thumb {
        height: 140px;
    }
}

@media (max-width: 380px) {
    .p2i-grid {
        grid-template-columns: 1fr;
    }
}
