/* ===================================
   CSS Variables & Base Styles
   =================================== */
:root {
    --color-bg: #0a0a0f;
    --color-surface: rgba(255, 255, 255, 0.03);
    --color-surface-hover: rgba(255, 255, 255, 0.06);
    --color-border: rgba(255, 255, 255, 0.08);
    --color-text: #ffffff;
    --color-text-muted: rgba(255, 255, 255, 0.6);
    --color-text-subtle: rgba(255, 255, 255, 0.4);
    --color-primary: #6366f1;
    --color-primary-glow: rgba(99, 102, 241, 0.4);
    --color-accent: #22d3ee;
    --color-accent-glow: rgba(34, 211, 238, 0.3);
    --color-success: #10b981;
    --color-success-glow: rgba(16, 185, 129, 0.3);
    --color-error: #ef4444;
    --color-error-glow: rgba(239, 68, 68, 0.3);
    --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
    --gradient-accent: linear-gradient(135deg, #22d3ee 0%, #6366f1 100%);
    --font-family: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --shadow-glow: 0 0 60px var(--color-primary-glow);
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

/* ===================================
   Background Effects
   =================================== */
.background-effects {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.5;
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 600px;
    height: 600px;
    background: var(--color-primary);
    top: -200px;
    right: -100px;
    animation-delay: 0s;
}

.orb-2 {
    width: 500px;
    height: 500px;
    background: var(--color-accent);
    bottom: -150px;
    left: -100px;
    animation-delay: -7s;
}

.orb-3 {
    width: 400px;
    height: 400px;
    background: #d946ef;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -14s;
    opacity: 0.3;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    33% {
        transform: translate(30px, -30px) scale(1.05);
    }

    66% {
        transform: translate(-20px, 20px) scale(0.95);
    }
}

/* ===================================
   Container & Layout
   =================================== */
.container {
    max-width: 700px;
    margin: 0 auto;
    padding: 3rem 1.5rem;
    min-height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* ===================================
   Hero Section
   =================================== */
.hero {
    text-align: center;
    padding: 2rem 0;
}

.logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 1.5rem;
    background: var(--gradient-primary);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-glow);
    animation: pulse 3s ease-in-out infinite;
}

.logo svg {
    width: 32px;
    height: 32px;
    color: white;
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 40px var(--color-primary-glow);
    }

    50% {
        box-shadow: 0 0 80px var(--color-primary-glow);
    }
}

.hero h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 1.125rem;
    color: var(--color-text-muted);
    margin-bottom: 1.5rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 100px;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    backdrop-filter: blur(10px);
}

.badge-dot {
    width: 8px;
    height: 8px;
    background: var(--color-success);
    border-radius: 50%;
    animation: blink 2s ease-in-out infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

/* ===================================
   Upload Section
   =================================== */
.upload-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-area {
    position: relative;
    width: 100%;
    min-height: 280px;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    overflow: hidden;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--color-primary);
    background: var(--color-surface-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.upload-hover-effect {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at var(--mouse-x, 50%) var(--mouse-y, 50%), var(--color-primary-glow), transparent 60%);
    opacity: 0;
    transition: opacity var(--transition-normal);
    pointer-events: none;
}

.upload-area:hover .upload-hover-effect {
    opacity: 1;
}

.upload-content {
    text-align: center;
    z-index: 1;
    padding: 2rem;
}

.upload-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    background: var(--gradient-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-normal);
}

.upload-area:hover .upload-icon {
    transform: scale(1.1);
}

.upload-icon svg {
    width: 40px;
    height: 40px;
    color: white;
}

.upload-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.upload-content p {
    color: var(--color-text-muted);
}

.file-label {
    color: var(--color-accent);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: color var(--transition-fast);
}

.file-label:hover {
    color: var(--color-primary);
}

/* ===================================
   Glass Card
   =================================== */
.glass-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: 2rem;
    backdrop-filter: blur(20px);
}

/* ===================================
   File Info & Settings Card
   =================================== */
.settings-card {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.settings-card .file-info {
    margin-bottom: 0;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.file-icon {
    width: 48px;
    height: 48px;
    background: var(--gradient-primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-icon svg {
    width: 24px;
    height: 24px;
    color: white;
}

.file-details {
    flex: 1;
}

.file-details h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.125rem;
    word-break: break-all;
}

.file-details p {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.change-file-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-family: var(--font-family);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.change-file-btn:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
    border-color: var(--color-text-muted);
}

/* ===================================
   Image Gallery (Yahoo Auctions style)
   =================================== */
.image-gallery {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gallery-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.image-count {
    font-size: 0.875rem;
    color: var(--color-accent);
    margin-left: 0.5rem;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 2px solid var(--color-border);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.gallery-item:hover {
    border-color: var(--color-primary);
    transform: scale(1.03);
}

.gallery-item.active {
    border-color: var(--color-accent);
    box-shadow: 0 0 12px var(--color-accent-glow);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(239, 68, 68, 0.9);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.gallery-item:hover .gallery-item-remove {
    opacity: 1;
}

.gallery-item-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 2px 4px;
    background: rgba(0, 0, 0, 0.7);
    font-size: 0.625rem;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-add {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.gallery-add:hover {
    border-color: var(--color-primary);
    color: var(--color-text);
    background: var(--color-surface-hover);
}

.gallery-add svg {
    width: 24px;
    height: 24px;
}

.gallery-add span {
    font-size: 0.875rem;
}

/* ===================================
   Direction Selector
   =================================== */
.crop-direction {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.direction-selector {
    display: flex;
    gap: 0.5rem;
}

.dir-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-family: var(--font-family);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.dir-btn:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.dir-btn.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--color-primary);
    color: var(--color-text);
}

/* ===================================
   Output Format Selector
   =================================== */
.output-format-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.output-format-selector {
    display: flex;
    gap: 0.5rem;
}

.format-btn {
    flex: 1;
    padding: 0.625rem 0.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-family: var(--font-family);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.format-btn:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.format-btn.active {
    background: rgba(34, 211, 238, 0.12);
    border-color: var(--color-accent);
    color: var(--color-text);
}

/* ===================================
   Crop Settings
   =================================== */
.crop-settings {
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    border: 1px solid var(--color-border);
}

.settings-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-weight: 500;
}

.crop-value {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.slider-container {
    padding: 0 0.25rem;
}

.crop-slider {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 100px;
    outline: none;
    cursor: pointer;
}

.crop-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--gradient-primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 10px var(--color-primary-glow);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.crop-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 20px var(--color-primary-glow);
}

.crop-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: var(--gradient-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 10px var(--color-primary-glow);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--color-text-subtle);
}

/* ===================================
   Preview Container
   =================================== */
.preview-container {
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-lg);
    padding: 1rem;
    border: 1px solid var(--color-border);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.preview-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.page-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.nav-btn:hover:not(:disabled) {
    background: var(--color-surface-hover);
    border-color: var(--color-primary);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-btn svg {
    width: 16px;
    height: 16px;
}

#pageIndicator,
#resultPageIndicator {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    min-width: 60px;
    text-align: center;
}

.preview-wrapper {
    display: flex;
    justify-content: center;
}

.preview-frame {
    position: relative;
    background: white;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 100%;
}

#previewCanvas {
    display: block;
    max-width: 100%;
    max-height: 400px;
    object-fit: contain;
}

/* Crop Overlay - Bottom */
.crop-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(239, 68, 68, 0.5);
    border-top: 2px dashed var(--color-error);
    pointer-events: none;
    transition: height var(--transition-fast), top var(--transition-fast), bottom var(--transition-fast);
}

/* Crop Overlay - Top */
.crop-overlay.crop-top {
    bottom: auto;
    top: 0;
    border-top: none;
    border-bottom: 2px dashed var(--color-error);
}

/* Drag Handle */
.drag-handle {
    position: absolute;
    top: -20px;
    left: 0;
    right: 0;
    height: 40px;
    pointer-events: auto;
    cursor: ns-resize;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.crop-overlay.crop-top .drag-handle {
    top: auto;
    bottom: -20px;
}

.drag-handle:hover .drag-handle-line {
    background: var(--color-error);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

.drag-handle:hover .drag-handle-grip {
    background: var(--color-error);
    transform: scaleY(1.2);
}

.drag-handle-line {
    width: 100%;
    height: 2px;
    background: rgba(239, 68, 68, 0.8);
    transition: all var(--transition-fast);
}

.drag-handle-grip {
    width: 40px;
    height: 6px;
    background: rgba(239, 68, 68, 0.6);
    border-radius: 3px;
    margin-top: 4px;
    transition: all var(--transition-fast);
}

.drag-handle.dragging .drag-handle-line {
    background: var(--color-error);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.8);
}

/* ===================================
   Process Button
   =================================== */
.process-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 1rem 2rem;
    background: var(--gradient-primary);
    border: none;
    border-radius: var(--radius-lg);
    color: white;
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: 0 4px 20px var(--color-primary-glow);
}

.process-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--color-primary-glow);
}

.process-btn:active {
    transform: translateY(0);
}

.process-btn svg {
    width: 20px;
    height: 20px;
}

/* ===================================
   Progress Section
   =================================== */
.progress-container {
    margin-top: 1rem;
}

.progress-bar {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 100px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--gradient-primary);
    border-radius: 100px;
    transition: width var(--transition-fast);
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

.progress-text {
    display: flex;
    justify-content: space-between;
    margin-top: 0.75rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

/* ===================================
   Result Section
   =================================== */
.result-card {
    text-align: center;
}

.result-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: scaleIn 0.4s ease-out;
}

@keyframes scaleIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.result-icon.success {
    background: linear-gradient(135deg, var(--color-success), #059669);
    box-shadow: 0 0 40px var(--color-success-glow);
}

.result-icon.error {
    background: linear-gradient(135deg, var(--color-error), #dc2626);
    box-shadow: 0 0 40px var(--color-error-glow);
}

.result-icon svg {
    width: 40px;
    height: 40px;
    color: white;
}

.result-card h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
}

.result-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 2rem;
}

.stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.result-preview {
    margin-bottom: 1.5rem;
}

.result-preview h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
}

.result-page-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.result-preview-frame {
    display: flex;
    justify-content: center;
}

#resultCanvas {
    display: block;
    max-width: 100%;
    max-height: 400px;
    object-fit: contain;
    background: white;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 1rem 2rem;
    background: var(--gradient-primary);
    border: none;
    border-radius: var(--radius-lg);
    color: white;
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: 0 4px 20px var(--color-primary-glow);
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--color-primary-glow);
}

.download-btn:active {
    transform: translateY(0);
}

.download-btn svg {
    width: 20px;
    height: 20px;
}

.reset-btn {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-family: var(--font-family);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.reset-btn:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
    border-color: var(--color-text-muted);
}

/* ===================================
   Error Section
   =================================== */
.error-card h2 {
    color: var(--color-error);
}

.error-card p {
    color: var(--color-text-muted);
    margin-bottom: 1.5rem;
}

/* ===================================
   Footer
   =================================== */
.footer {
    text-align: center;
    padding: 2rem;
    color: var(--color-text-subtle);
    font-size: 0.875rem;
}

/* ===================================
   Responsive
   =================================== */
@media (max-width: 640px) {
    .hero h1 {
        font-size: 1.75rem;
    }

    .container {
        padding: 2rem 1rem;
    }

    .gallery-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .result-stats {
        gap: 1.5rem;
    }

    .direction-selector,
    .output-format-selector {
        flex-wrap: wrap;
    }
}