/* ============================================================
   PhotoResizer — Premium Dark Theme Design System
   ============================================================ */

/* --- Google Fonts Import --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* --- Design Tokens --- */
:root {
    --bg-body: #f1f5f9;
    --bg-primary: #ffffff;
    --bg-secondary: #e8edf5;
    --bg-card: #ffffff;
    --bg-glass: rgba(15, 23, 42, 0.03);
    --bg-glass-hover: rgba(15, 23, 42, 0.06);
    --border-glass: #dde3ee;
    --border-glass-hover: rgba(249, 115, 22, 0.4);

    --text-primary: #0d1117;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --text-accent: #f97316;

    --accent-purple: #f97316;
    --accent-purple-light: #fb923c;
    --accent-cyan: #6366f1;
    --accent-cyan-light: #818cf8;
    --accent-gradient: linear-gradient(135deg, #f97316 0%, #6366f1 100%);
    --accent-gradient-hover: linear-gradient(135deg, #fb923c 0%, #818cf8 100%);

    --success: #16a34a;
    --success-light: #4ade80;
    --error: #dc2626;
    --warning: #f59e0b;

    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 8px 32px rgba(15, 23, 42, 0.12);
    --shadow-glow-purple: 0 0 30px rgba(249, 115, 22, 0.15);
    --shadow-glow-cyan: 0 0 30px rgba(99, 102, 241, 0.15);
    --shadow-glow-accent: 0 4px 20px rgba(249, 115, 22, 0.25);

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition-fast: 150ms var(--ease);
    --transition: 300ms var(--ease);
    --transition-slow: 500ms var(--ease);

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    font-family: var(--font);
    background: var(--bg-body);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse 80% 50% at 50% -10%, rgba(249, 115, 22, 0.06) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 80% 50%, rgba(99, 102, 241, 0.03) 0%, transparent 50%);
}

img {
    max-width: 100%;
    display: block;
}

input, button, select, textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

/* --- Layout Container --- */
.app-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 3rem 1.5rem 5rem;
}

/* --- Global Nav --- */
.nav {
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    background: rgba(255, 255, 255, 0.85);
    border-bottom: 1px solid var(--border-glass);
    padding: 0 2rem;
    width: 100%;
}

.nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 2rem;
    height: 64px;
}

.nav-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    flex-shrink: 0;
}

.nav-logo .logo-icon {
    width: 36px;
    height: 36px;
    background: var(--accent-gradient);
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    box-shadow: var(--shadow-glow-accent);
}

.nav-logo .logo-text-group {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.nav-logo .logo-brand {
    font-size: 1.35rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.nav-logo .logo-sub {
    font-size: 0.72rem;
    font-weight: 550;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    list-style: none;
    flex: 1;
    overflow-x: auto;
}

.nav-links::-webkit-scrollbar { display: none; }

.nav-links a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    transition: var(--transition);
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--text-primary);
    background: var(--bg-glass-hover);
}

.nav-links a.active {
    background: rgba(249, 115, 22, 0.2);
    color: var(--accent-purple-light);
}

.nav-links .nav-divider {
    border-left: 1px solid var(--border-glass);
    margin: 0 10px;
    height: 20px;
    align-self: center;
    flex-shrink: 0;
}

@media (max-width: 640px) {
    .nav { padding: 0 1rem; }
    .nav-inner { flex-direction: row; gap: 0.5rem; }
    .nav-links a { padding: 4px 8px; font-size: 0.78rem; }
}

/* --- Header --- */
.app-header {
    text-align: center;
    padding: 5rem 1.5rem 0;
    margin-bottom: 3rem;
}

.logo-group {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
    text-decoration: none;
}

.logo-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-glow-accent);
    position: relative;
    overflow: hidden;
    font-size: 1.6rem;
    color: #fff;
}

.logo-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%);
}

.logo-text-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.2;
}

.app-title {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 900;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.75rem;
    line-height: 1.15;
}

.logo-sub {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.app-tagline {
    font-size: 1.05rem;
    color: var(--text-secondary);
    max-width: 520px;
    margin: 0 auto;
}

/* --- Tab Navigation --- */
.tab-nav {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 5px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-full);
    margin-bottom: 36px;
    max-width: 580px;
    margin-left: auto;
    margin-right: auto;
    position: relative;
}

.tab-btn {
    flex: 1;
    padding: 11px 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
}

.tab-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: #fff;
    background: var(--accent-gradient);
    box-shadow: var(--shadow-glow-accent);
}

/* --- Tool Panels --- */
.tool-panel {
    display: none;
    animation: panelFadeIn 0.4s var(--ease);
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.tool-panel:hover {
    border-color: var(--border-glass-hover);
}

.tool-panel.active {
    display: block;
}

@keyframes panelFadeIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Glass Card --- */
.glass-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 28px;
    transition: var(--transition);
}

.glass-card:hover {
    border-color: var(--border-glass-hover);
}

/* --- Upload Zone --- */
.upload-zone {
    border: 2px dashed rgba(249, 115, 22, 0.25);
    border-radius: var(--radius-lg);
    padding: 52px 28px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    background: var(--bg-glass);
}

.upload-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, rgba(249, 115, 22, 0.04) 0%, transparent 70%);
    transition: var(--transition);
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--accent-purple-light);
    background: rgba(249, 115, 22, 0.06);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow-purple);
}

.upload-zone:hover::before,
.upload-zone.drag-over::before {
    background: radial-gradient(circle at 50% 50%, rgba(249, 115, 22, 0.08) 0%, transparent 70%);
}

.upload-zone.drag-over {
    border-style: solid;
}

.upload-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 18px;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.12), rgba(6, 182, 212, 0.08));
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.upload-zone:hover .upload-icon {
    transform: scale(1.08);
}

.upload-icon svg {
    width: 28px;
    height: 28px;
    stroke: var(--accent-purple-light);
    fill: none;
    stroke-width: 1.5;
}

.upload-zone p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.upload-zone p .browse-link {
    color: var(--accent-purple-light);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.upload-zone .supported-formats {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.upload-zone input[type="file"] {
    display: none;
}

/* --- Workspace (shown after upload) --- */
.workspace {
    display: none;
    animation: panelFadeIn 0.4s var(--ease);
}

.workspace.visible {
    display: block;
}

/* --- Section Title --- */
.section-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 14px;
}

/* --- Image Preview --- */
.preview-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 28px;
}

.preview-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
}

.preview-box .preview-label {
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 2;
}

.preview-box img {
    width: 100%;
    height: 200px;
    object-fit: contain;
    background: repeating-conic-gradient(#ffffff 0% 25%, #e2e8f0 0% 50%) 50% / 16px 16px;
}

/* --- Size Comparison Bar --- */
.size-comparison {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 22px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    margin-bottom: 28px;
}

.size-card {
    flex: 1;
    text-align: center;
}

.size-card .size-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.size-card .size-value {
    display: block;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.size-card.estimated .size-value {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.size-arrow {
    font-size: 1.2rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.size-reduction {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--success);
    flex-shrink: 0;
    padding: 4px 12px;
    background: rgba(16, 185, 129, 0.1);
    border-radius: var(--radius-full);
}

/* --- Controls Section --- */
.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 28px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.control-group label svg {
    width: 14px;
    height: 14px;
}

/* --- Custom Range Slider --- */
.slider-wrapper {
    display: flex;
    align-items: center;
    gap: 14px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-card);
    border-radius: var(--radius-full);
    outline: none;
    cursor: pointer;
    position: relative;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-gradient);
    border: 3px solid var(--bg-body);
    box-shadow: 0 0 10px rgba(249, 115, 22, 0.4);
    cursor: pointer;
    transition: box-shadow var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    box-shadow: 0 0 18px rgba(249, 115, 22, 0.6);
    transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-gradient);
    border: 3px solid var(--bg-body);
    box-shadow: 0 0 10px rgba(249, 115, 22, 0.4);
    cursor: pointer;
}

.slider-value {
    min-width: 48px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--accent-purple-light);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* --- Text & Number Inputs --- */
.input-field {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    outline: none;
    transition: var(--transition);
}

.input-field:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.12);
}

.input-field::placeholder {
    color: var(--text-muted);
}

.input-with-suffix {
    display: flex;
    align-items: stretch;
}

.input-with-suffix .input-field {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: none;
}

.input-suffix {
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-left: none;
    border-top-right-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    align-items: center;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 28px;
    font-weight: 600;
    font-size: 0.875rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    box-shadow: var(--shadow-glow-accent);
}

.btn-primary:hover {
    background: var(--accent-gradient-hover);
    box-shadow: 0 4px 28px rgba(249, 115, 22, 0.35);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0) scale(0.97);
}

.btn-secondary {
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-glass-hover);
}

.btn-secondary.active {
    background: rgba(249, 115, 22, 0.15);
    border-color: var(--accent-purple);
    color: var(--accent-purple-light);
}

.btn-success {
    background: linear-gradient(135deg, #059669, #10b981);
    color: #fff;
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.25);
}

.btn-success:hover {
    box-shadow: 0 4px 24px rgba(16, 185, 129, 0.35);
    transform: translateY(-1px);
}

.btn-icon {
    padding: 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    color: var(--text-primary);
    border-color: var(--border-glass-hover);
    background: var(--bg-glass-hover);
}

.btn-icon.active {
    color: var(--accent-purple-light);
    border-color: var(--accent-purple);
    background: rgba(249, 115, 22, 0.1);
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

.btn-full {
    width: 100%;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* --- Download Section --- */
.download-section {
    display: none;
    background: rgba(16, 185, 129, 0.04);
    border: 1px solid rgba(16, 185, 129, 0.15);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-top: 24px;
    animation: panelFadeIn 0.4s var(--ease);
}

.download-section.visible {
    display: block;
}

.download-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
}

.download-header .check-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--success);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.download-header .check-icon svg {
    width: 14px;
    height: 14px;
    stroke: #fff;
    fill: none;
    stroke-width: 2.5;
}

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

.download-row {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.download-row .input-field {
    flex: 1;
}

.download-meta {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.download-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* --- Format Selector --- */
.format-selector {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.format-option {
    flex: 1;
    min-width: 100px;
}

.format-option input[type="radio"] {
    display: none;
}

.format-option label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 18px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.format-option label:hover {
    border-color: var(--border-glass-hover);
    background: var(--bg-glass-hover);
}

.format-option input:checked + label {
    border-color: var(--accent-purple);
    background: rgba(249, 115, 22, 0.1);
    box-shadow: 0 0 16px rgba(249, 115, 22, 0.1);
}

.format-option .format-ext {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.format-option .format-name {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* --- Editor Toolbar --- */
.editor-toolbar {
    display: flex;
    gap: 8px;
    padding: 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar-divider {
    width: 1px;
    height: 28px;
    background: var(--border-glass);
    margin: 0 6px;
}

.toolbar-group {
    display: flex;
    gap: 6px;
    align-items: center;
}

.toolbar-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-right: 4px;
}

/* --- Editor Canvas Container --- */
.editor-canvas-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 20px;
    max-height: 500px;
}

.editor-canvas-container img {
    display: block;
    max-width: 100%;
    max-height: 500px;
}

/* --- Resize Controls (used by Resize panel) --- */
.resize-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.resize-controls .input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.resize-controls .input-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.resize-controls .input-group .input-field {
    width: 100px;
}

.lock-aspect-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.lock-aspect-btn.active {
    color: var(--accent-purple-light);
    border-color: var(--accent-purple);
    background: rgba(249, 115, 22, 0.1);
}

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

/* --- Custom Aspect Ratio Row --- */
.custom-ratio-row {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    animation: panelFadeIn 0.3s var(--ease);
}

.custom-ratio-row.visible {
    display: flex;
}

.custom-ratio-row .input-group .input-field {
    width: 70px;
    text-align: center;
}

.ratio-separator {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-muted);
}

/* --- Unit Selector --- */
.unit-select {
    width: 80px !important;
    padding: 10px 8px;
    cursor: pointer;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
}

.unit-select option {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* --- Live Dimensions Bar --- */
.live-dims-bar {
    display: flex;
    gap: 20px;
    padding: 12px 18px;
    background: rgba(249, 115, 22, 0.04);
    border: 1px solid rgba(249, 115, 22, 0.12);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.dpi-input {
    width: 60px !important;
    padding: 4px 8px !important;
    font-size: 0.78rem !important;
    text-align: center;
    background: var(--bg-secondary) !important;
}

/* --- Dimension Selector (Resize Preview) --- */
.resize-preview-section {
    display: none;
    margin-bottom: 20px;
    animation: panelFadeIn 0.4s var(--ease);
}

.resize-preview-section.visible {
    display: block;
}

.dim-selector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 12px;
    flex-wrap: wrap;
}

.dim-selector-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.5;
    margin-bottom: 12px;
}

.dim-selector-hint svg {
    width: 14px;
    height: 14px;
    stroke: var(--accent-purple-light);
    flex-shrink: 0;
}

.dim-selector-badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    background: rgba(249, 115, 22, 0.15);
    border: 1px solid rgba(249, 115, 22, 0.3);
    color: var(--accent-purple-light);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* The wrapper that holds the image + overlay, confined to a fixed display height */
.dim-selector-wrap {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: crosshair;
    user-select: none;
    -webkit-user-select: none;
    line-height: 0; /* remove inline gap under img */
}

.dim-selector-wrap img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 400px;
    object-fit: contain;
    pointer-events: none;
    background: repeating-conic-gradient(#ffffff 0% 25%, #e2e8f0 0% 50%) 50% / 14px 14px;
}

/* The draggable selection frame */
.dim-selector-frame {
    position: absolute;
    border: 2px solid var(--accent-purple-light);
    box-shadow:
        0 0 0 1px rgba(0,0,0,0.6),
        0 0 20px rgba(249, 115, 22, 0.4),
        inset 0 0 20px rgba(249, 115, 22, 0.06);
    cursor: grab;
    transition: box-shadow 80ms;
    box-sizing: border-box;
}

.dim-selector-frame:active {
    cursor: grabbing;
    box-shadow:
        0 0 0 1px rgba(0,0,0,0.8),
        0 0 28px rgba(249, 115, 22, 0.6),
        inset 0 0 20px rgba(249, 115, 22, 0.1);
}

/* Rule-of-thirds grid lines inside frame */
.dim-selector-frame::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(167,139,250,0.25) 1px, transparent 1px),
        linear-gradient(90deg, rgba(167,139,250,0.25) 1px, transparent 1px);
    background-size: 33.333% 33.333%;
    pointer-events: none;
}

/* Corner handles */
.dim-selector-frame::after {
    content: '';
    position: absolute;
    inset: -4px;
    pointer-events: none;
    background:
        /* TL */
        linear-gradient(var(--accent-purple-light), var(--accent-purple-light)) top left / 14px 3px no-repeat,
        linear-gradient(var(--accent-purple-light), var(--accent-purple-light)) top left / 3px 14px no-repeat,
        /* TR */
        linear-gradient(var(--accent-purple-light), var(--accent-purple-light)) top right / 14px 3px no-repeat,
        linear-gradient(var(--accent-purple-light), var(--accent-purple-light)) top right / 3px 14px no-repeat,
        /* BL */
        linear-gradient(var(--accent-purple-light), var(--accent-purple-light)) bottom left / 14px 3px no-repeat,
        linear-gradient(var(--accent-purple-light), var(--accent-purple-light)) bottom left / 3px 14px no-repeat,
        /* BR */
        linear-gradient(var(--accent-purple-light), var(--accent-purple-light)) bottom right / 14px 3px no-repeat,
        linear-gradient(var(--accent-purple-light), var(--accent-purple-light)) bottom right / 3px 14px no-repeat;
}

/* Dim overlay outside the selection frame */
.dim-selector-shade {
    position: absolute;
    inset: 0;
    pointer-events: none;
    /* clipped via clip-path set dynamically in JS */
    background: rgba(7, 7, 13, 0.55);
}

/* Dimension label inside frame */
.dim-selector-label {
    position: absolute;
    bottom: 6px;
    right: 8px;
    font-size: 0.65rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
    pointer-events: none;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
.image-info-bar {
    display: flex;
    gap: 20px;
    padding: 12px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
}

.info-item .info-label {
    color: var(--text-muted);
    font-weight: 500;
}

.info-item .info-value {
    color: var(--text-primary);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* --- Change Image Button --- */
.change-image-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 20px;
}

.change-image-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-glass-hover);
}

.change-image-btn svg {
    width: 14px;
    height: 14px;
}

/* --- Loading Spinner --- */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Processing Overlay --- */
.processing-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(7, 7, 13, 0.7);
    backdrop-filter: blur(4px);
    z-index: 100;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
}

.processing-overlay.visible {
    display: flex;
}

.processing-overlay .spinner {
    width: 40px;
    height: 40px;
    border-width: 3px;
    border-color: rgba(249, 115, 22, 0.3);
    border-top-color: var(--accent-purple-light);
}

.processing-overlay p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* --- Toast / Notification --- */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    padding: 12px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(12px);
    z-index: 200;
    opacity: 0;
    transition: var(--transition);
    pointer-events: none;
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.error {
    border-color: rgba(239, 68, 68, 0.3);
}

/* --- Footer --- */
footer,
.app-footer {
    text-align: center;
    padding: 2.5rem 1.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-glass);
    margin-top: 4rem;
}

/* --- Cropper.js Overrides --- */
.cropper-view-box {
    outline: 2px solid var(--accent-purple-light);
    outline-offset: 0;
}

.cropper-line {
    background-color: var(--accent-purple-light);
}

.cropper-point {
    background-color: var(--accent-purple-light);
    width: 8px;
    height: 8px;
    opacity: 1;
}

.cropper-dashed {
    border-color: rgba(167, 139, 250, 0.4);
}

.cropper-modal {
    background-color: rgba(7, 7, 13, 0.6);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .app-container {
        padding: 0 16px;
    }

    .app-header {
        padding: 32px 0 24px;
    }

    .app-title {
        font-size: 1.4rem;
    }

    .controls-grid {
        grid-template-columns: 1fr;
    }

    .preview-container {
        grid-template-columns: 1fr;
    }

    .size-comparison {
        flex-direction: column;
        gap: 8px;
    }

    .size-arrow {
        transform: rotate(90deg);
    }

    .format-selector {
        flex-direction: column;
    }

    .format-option {
        min-width: unset;
    }

    .editor-toolbar {
        justify-content: center;
    }

    .toolbar-divider {
        display: none;
    }

    .download-row {
        flex-direction: column;
    }

    .resize-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .resize-controls .input-group {
        flex: 1;
    }

    .resize-controls .input-group .input-field {
        width: 100%;
        flex: 1;
    }
}

@media (max-width: 480px) {
    .tab-btn {
        padding: 9px 10px;
        font-size: 0.75rem;
    }

    .tab-btn svg {
        display: none;
    }

    .glass-card {
        padding: 20px;
    }

    .upload-zone {
        padding: 36px 20px;
    }
}

/* ============================================================
   CROP PANEL
   ============================================================ */

/* Crop canvas + live preview side-by-side */
.crop-layout {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 20px;
    margin-bottom: 20px;
    align-items: start;
}

.crop-canvas-wrap .section-label,
.crop-preview-wrap .section-label {
    margin-bottom: 8px;
}

.crop-preview-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    overflow: hidden;
}

/* Cropper.js preview injection target — JS sets exact W×H to match crop ratio */
.crop-preview-box {
    width: 100%;
    height: 200px;          /* default; overridden by JS syncPreviewBox() */
    overflow: hidden;
    background: repeating-conic-gradient(#ffffff 0% 25%, #e2e8f0 0% 50%) 50% / 12px 12px;
    position: relative;
    transition: width 0.15s ease, height 0.15s ease;
    display: block;
}

/* Cropper.js injects its own preview img into this container */
.crop-preview-box img {
    width: 100% !important;
}

.crop-preview-info {
    padding: 10px 14px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-glass);
}

/* Aspect preset buttons with icons */
.aspect-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.aspect-preset-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.aspect-preset-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.aspect-preset-btn:hover {
    border-color: var(--border-glass-hover);
    color: var(--text-primary);
}

.aspect-preset-btn.active {
    border-color: var(--accent-purple);
    color: var(--accent-purple-light);
    background: rgba(249, 115, 22, 0.1);
}

@media (max-width: 768px) {
    .crop-layout {
        grid-template-columns: 1fr;
    }
    .crop-preview-box {
        height: 160px;
    }
}

/* ============================================================
   RESIZE PANEL
   ============================================================ */

/* Quick preset grid */
.size-presets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    margin-bottom: 24px;
}

.size-preset-btn {
    padding: 9px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    text-align: center;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    line-height: 1.3;
}

.size-preset-btn:hover {
    border-color: var(--border-glass-hover);
    color: var(--text-primary);
    background: var(--bg-glass-hover);
}

.size-preset-btn.active {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan-light);
    background: rgba(6, 182, 212, 0.08);
}

/* Resize dimension controls */
.resize-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.resize-controls .input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.resize-controls .input-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.resize-controls .input-group .input-field {
    width: 90px;
}

/* Options row (algorithm + format) */
.resize-options-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.resize-option-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.resize-option-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Before/After preview */
.resize-preview-area {
    display: none;
    margin-bottom: 8px;
    animation: panelFadeIn 0.4s var(--ease);
}

.resize-preview-area.visible {
    display: block;
}

.resize-preview-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 16px;
    align-items: center;
}

.resize-preview-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.resize-preview-card .preview-label {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 3px 8px;
    border-radius: var(--radius-full);
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    z-index: 2;
    color: var(--text-primary);
}

.resize-preview-card canvas {
    width: 100%;
    height: 180px;
    object-fit: contain;
    background: repeating-conic-gradient(#ffffff 0% 25%, #e2e8f0 0% 50%) 50% / 14px 14px;
}

.preview-dim-label {
    display: block;
    width: 100%;
    text-align: center;
    padding: 8px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-card);
    font-variant-numeric: tabular-nums;
}

.resize-preview-arrow {
    font-size: 1.4rem;
    color: var(--text-muted);
    font-weight: 300;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .resize-preview-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .resize-preview-arrow {
        transform: rotate(90deg);
        text-align: center;
    }
    .resize-options-row {
        grid-template-columns: 1fr;
    }
    .resize-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .resize-controls .input-group .input-field {
        width: 100%;
        flex: 1;
    }
}

/* ── Home Page Cards ── */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin-top: 3rem;
}

.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 2rem 1.75rem;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.tool-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent-gradient);
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 0;
}
.tool-card:hover::after { opacity: 0.06; }
.tool-card:hover { transform: translateY(-6px); border-color: var(--border-glass-hover); box-shadow: var(--shadow-glow-accent); }
.tool-card > * { position: relative; z-index: 1; }

.tool-card-icon {
  width: 52px; height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.tool-card-icon.violet { background: rgba(249,115,22,0.2); }
.tool-card-icon.cyan   { background: rgba(99,102,241,0.2); }
.tool-card-icon.pink   { background: rgba(236,72,153,0.2); }
.tool-card-icon.green  { background: rgba(16,185,129,0.2); }

.tool-card h3 { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.tool-card p  { font-size: 0.875rem; color: var(--text-secondary); line-height: 1.6; flex: 1; }

.tool-card-arrow {
  align-self: flex-start;
  color: var(--text-muted);
  font-size: 1.2rem;
  transition: transform 0.3s;
}
.tool-card:hover .tool-card-arrow { transform: translate(4px, -4px); color: var(--accent-purple-light); }

/* ── Hero ── */
.hero {
  text-align: center;
  padding: 5rem 1.5rem 0;
  max-width: 720px;
  margin: 0 auto;
}
.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-radius: 99px;
  background: rgba(249,115,22,0.1);
  border: 1px solid rgba(249,115,22,0.25);
  color: var(--accent-purple-light);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 1.5rem;
}
.hero h1 {
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 900;
  line-height: 1.1;
  margin-bottom: 1.25rem;
}
.hero h1 .grad {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 540px;
  margin: 0 auto;
}

/* ─── Ratio lock badge in toolbar ─── */
.ratio-lock-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    background: rgba(6, 182, 212, 0.12);
    border: 1px solid rgba(6, 182, 212, 0.3);
    color: var(--accent-cyan-light);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    min-width: 48px;
    justify-content: center;
}

/* ─── Section subtitle ─── */
.section-sub {
    font-size: 0.65rem;
    font-weight: 400;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
    margin-left: 4px;
}
