:root {
--bg: #f8fafc;
--surface: #ffffff;
--primary: #2563eb;
--primary-hover: #1d4ed8;
--primary-light: #eff6ff;
--text: #1e293b;
--text-secondary: #64748b;
--border: #e2e8f0;
--border-strong: #cbd5e1;
--success: #10b981;
--warning: #f59e0b;
--danger: #ef4444;
--radius: 12px;
--radius-sm: 8px;
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
--shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
--shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
--shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 10px rgba(0, 0, 0, 0.06);
--transition: 0.2s ease;
--font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
--max-width: 1100px;
--nav-height: 64px;
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Skip Link ── */
.skip-link {
    position: absolute;
    top: -100px;
    left: 16px;
    background: var(--primary);
    color: #fff;
    padding: 8px 16px;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    z-index: 1000;
    transition: top 0.3s;
    text-decoration: none;
    font-weight: 600;
}
.skip-link:focus {
    top: 0;
}

/* ── Header & Nav ── */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    height: var(--nav-height);
    display: flex;
    align-items: center;
}
.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    width: 100%;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.logo {
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--primary);
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.logo svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}
nav {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
nav a {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
    padding: 8px 14px;
    border-radius: 20px;
    transition: var(--transition);
    white-space: nowrap;
}
nav a:hover,
nav a.active {
    background: var(--primary-light);
    color: var(--primary);
}
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
}
.mobile-menu-btn:hover {
    background: var(--bg);
}
.mobile-menu-btn svg {
    width: 24px;
    height: 24px;
    stroke: var(--text);
}

/* ── Main ── */
main {
    flex: 1;
    max-width: var(--max-width);
    width: 100%;
    margin: 0 auto;
    padding: 24px 20px 48px;
}

/* ── Section Visibility ── */
.page-section {
    display: none;
}
.page-section.active {
    display: block;
    animation: fadeSlideIn 0.35s ease;
}
@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Homepage ── */
.hero {
    text-align: center;
    padding: 32px 0 20px;
}
.hero h1 {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text);
    margin-bottom: 8px;
}
.hero p {
    color: var(--text-secondary);
    font-size: 1.05rem;
    max-width: 600px;
    margin: 0 auto;
}
.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 24px;
}
.tool-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 20px;
    text-decoration: none;
    color: var(--text);
    transition: var(--transition);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
}
.tool-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
    border-color: var(--primary);
}
.tool-card:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}
.tool-card .icon-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.tool-card .icon-circle svg {
    width: 24px;
    height: 24px;
    stroke: var(--primary);
}
.tool-card h3 {
    font-size: 1.1rem;
    font-weight: 700;
}
.tool-card p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}
.tool-card .arrow {
    margin-top: auto;
    font-weight: 600;
    color: var(--primary);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ── Tool Pages Common ── */
.tool-header {
    margin-bottom: 20px;
}
.tool-header h1 {
    font-size: 1.7rem;
    font-weight: 800;
    letter-spacing: -0.4px;
}
.tool-header p {
    color: var(--text-secondary);
    margin-top: 4px;
}
.breadcrumb {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.breadcrumb a {
    color: var(--primary);
    text-decoration: none;
}
.breadcrumb a:hover {
    text-decoration: underline;
}
.tool-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}
.drop-zone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--bg);
    position: relative;
}
.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}
.drop-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}
.drop-zone .dz-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}
.drop-zone p {
    color: var(--text-secondary);
    font-weight: 500;
}
.drop-zone .dz-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}
.preview-area {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 20px;
    align-items: flex-start;
}
.preview-box {
    flex: 1;
    min-width: 250px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 12px;
    text-align: center;
    border: 1px solid var(--border);
}
.preview-box h4 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.preview-box canvas,
.preview-box img {
    max-width: 100%;
    max-height: 400px;
    border-radius: var(--radius-sm);
    display: block;
    margin: 0 auto;
}
.preview-box .file-size {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 6px;
}
.controls-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 16px;
}
.controls-row label {
    font-weight: 600;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 6px;
}
.controls-row input[type="range"] {
    width: 140px;
    accent-color: var(--primary);
}
.controls-row input[type="number"] {
    width: 70px;
    padding: 6px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    text-align: center;
}
.controls-row select {
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background: var(--surface);
    cursor: pointer;
}
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 24px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-md);
}
.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
}
.btn-secondary:hover {
    background: var(--bg);
}
.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover {
    filter: brightness(0.9);
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}
.btn-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
    border-radius: 18px;
}
.privacy-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    margin-top: 12px;
}
.result-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
    align-items: center;
}
.info-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
.hidden {
    display: none !important;
}
.text-center {
    text-align: center;
}
.mt-8 {
    margin-top: 8px;
}
.mt-16 {
    margin-top: 16px;
}
.mt-24 {
    margin-top: 24px;
}
.gap-8 {
    gap: 8px;
}

/* ── Crop Overlay ── */
.crop-wrapper {
    position: relative;
    display: inline-block;
    cursor: crosshair;
    max-width: 100%;
    user-select: none;
    -webkit-user-select: none;
}
.crop-wrapper canvas {
    display: block;
    max-width: 100%;
    height: auto;
}
.crop-overlay {
    position: absolute;
    border: 2px dashed #fff;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
    cursor: move;
    pointer-events: all;
    transition: none;
}
.crop-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #fff;
    border: 2px solid var(--primary);
    border-radius: 50%;
    pointer-events: all;
    z-index: 2;
}
.crop-handle.tl {
    top: -7px;
    left: -7px;
    cursor: nw-resize;
}
.crop-handle.tr {
    top: -7px;
    right: -7px;
    cursor: ne-resize;
}
.crop-handle.bl {
    bottom: -7px;
    left: -7px;
    cursor: sw-resize;
}
.crop-handle.br {
    bottom: -7px;
    right: -7px;
    cursor: se-resize;
}

/* ── Watermark position grid ── */
.position-grid {
    display: grid;
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(3, 40px);
    gap: 4px;
}
.position-grid button {
    width: 40px;
    height: 40px;
    border: 2px solid var(--border-strong);
    border-radius: 6px;
    background: var(--surface);
    cursor: pointer;
    font-size: 0.7rem;
    transition: var(--transition);
    padding: 0;
}
.position-grid button.active {
    border-color: var(--primary);
    background: var(--primary-light);
}
.position-grid button:hover {
    border-color: var(--primary);
}

/* ── GIF frame list ── */
.frame-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
    min-height: 60px;
    padding: 8px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.frame-item {
    width: 70px;
    height: 70px;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid var(--border);
    cursor: grab;
    position: relative;
    flex-shrink: 0;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.frame-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
}
.frame-item .frame-del {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    padding: 0;
    opacity: 0;
    transition: var(--transition);
}
.frame-item:hover .frame-del {
    opacity: 1;
}
.frame-item.dragging {
    opacity: 0.5;
    border-style: dashed;
}

/* ── FAQ / Content Section ── */
.content-section {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}
.content-section h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 12px;
}
.content-section p,
.content-section li {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 8px;
}
.content-section ul {
    padding-left: 20px;
}

/* ── Footer ── */
footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    text-align: center;
    padding: 16px 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
footer a {
    color: var(--primary);
    text-decoration: none;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    nav {
        display: none;
        position: absolute;
        top: var(--nav-height);
        left: 0;
        right: 0;
        background: var(--surface);
        flex-direction: column;
        padding: 12px;
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow-md);
        gap: 2px;
        z-index: 99;
    }
    nav.open {
        display: flex;
    }
    nav a {
        padding: 10px 16px;
        border-radius: var(--radius-sm);
        font-size: 0.9rem;
    }
    .mobile-menu-btn {
        display: block;
    }
    .hero h1 {
        font-size: 1.5rem;
    }
    .tool-grid {
        grid-template-columns: 1fr;
    }
    .preview-area {
        flex-direction: column;
    }
    .controls-row {
        flex-direction: column;
        align-items: flex-start;
    }
    .tool-container {
        padding: 16px;
    }
}

@media (min-width: 769px) {
    nav {
        display: flex !important;
    }
}
