/* ===== CSS Variables & Reset ===== */
:root {
    --bg-primary: #0d0d0d;
    --bg-secondary: #141414;
    --bg-tertiary: #1a1a1a;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-hover: rgba(255, 255, 255, 0.08);

    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.65);
    --text-muted: rgba(255, 255, 255, 0.4);

    --accent-color: #ffffff;
    --accent-secondary: rgba(255, 255, 255, 0.1);

    --border-color: rgba(255, 255, 255, 0.1);
    --border-hover: rgba(255, 255, 255, 0.2);

    --grid-line-color: rgba(59, 130, 246, 0.7);
    --grid-cell-bg: rgba(59, 130, 246, 0.08);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 100px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ===== App Container ===== */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

/* ===== Header ===== */
.header {
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    gap: 2rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    text-decoration: none;
}

.logo:hover {
    opacity: 0.9;
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--text-primary);
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin: 0;
}

.tagline {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 400;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 0;
}

/* ===== Controls Panel ===== */
.controls-panel {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    overflow-y: auto;
    max-height: calc(100vh - 60px);
}

.panel-section {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.section-title svg {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
}

/* ===== Upload Zone ===== */
.upload-zone {
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    background: transparent;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--text-secondary);
    background: var(--bg-hover);
}

.upload-zone.has-image {
    border-style: solid;
    border-color: var(--text-muted);
}

.upload-icon {
    width: 32px;
    height: 32px;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.upload-zone:hover .upload-icon {
    color: var(--text-secondary);
}

.upload-text {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.upload-text span {
    color: var(--text-primary);
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.upload-hint {
    font-size: 0.6875rem;
    color: var(--text-muted);
}

/* ===== Input Groups ===== */
.input-group {
    margin-bottom: 1rem;
}

.input-group:last-child {
    margin-bottom: 0;
}

.input-group label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

/* Number Input */
.number-input {
    display: flex;
    align-items: stretch;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.number-input input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-weight: 500;
    text-align: center;
    padding: 0.5rem;
    min-width: 0;
}

.number-input input:focus {
    outline: none;
}

.num-btn {
    width: 36px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.125rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

/* Select */
select {
    width: 100%;
    padding: 0.625rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

select:hover {
    border-color: var(--border-hover);
}

select:focus {
    outline: none;
    border-color: var(--text-muted);
}

/* ===== Templates ===== */
.templates {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.templates-label {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-bottom: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.template-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.375rem;
}

.template-btn {
    padding: 0.5rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.template-btn:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.template-btn.active {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: var(--bg-primary);
}

/* ===== Drag Hint ===== */
.drag-hint {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem;
    margin-top: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.drag-hint svg {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.reset-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    width: 100%;
    padding: 0.5rem;
    margin-top: 0.625rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.reset-btn svg {
    width: 12px;
    height: 12px;
}

/* ===== Draggable Grid Lines ===== */
.grid-line {
    position: absolute;
    background: var(--grid-line-color);
    transition: background 0.1s ease;
    z-index: 10;
    pointer-events: auto;
}

.grid-line.horizontal {
    left: 0;
    right: 0;
    height: 2px;
    cursor: ns-resize;
}

.grid-line.vertical {
    top: 0;
    bottom: 0;
    width: 2px;
    cursor: ew-resize;
}

.grid-line:hover,
.grid-line.dragging {
    background: #3b82f6;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.6);
}

.grid-line::before {
    content: '';
    position: absolute;
}

.grid-line.horizontal::before {
    left: 0;
    right: 0;
    top: -8px;
    bottom: -8px;
}

.grid-line.vertical::before {
    top: 0;
    bottom: 0;
    left: -10px;
    right: -10px;
}

/* ===== Checkbox ===== */
.checkbox-group {
    margin-bottom: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    cursor: pointer;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.checkbox-label input {
    display: none;
}

.checkmark {
    width: 16px;
    height: 16px;
    border: 1px solid var(--border-hover);
    border-radius: 4px;
    position: relative;
    transition: all var(--transition-fast);
}

.checkbox-label input:checked+.checkmark {
    background: var(--text-primary);
    border-color: var(--text-primary);
}

.checkmark::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 7px;
    border: solid var(--bg-primary);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.checkbox-label input:checked+.checkmark::after {
    opacity: 1;
}

/* ===== Cut Button ===== */
.cut-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.875rem;
    background: var(--text-primary);
    border: none;
    border-radius: var(--radius-full);
    color: var(--bg-primary);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    margin-top: auto;
}

.cut-btn:hover:not(:disabled) {
    transform: scale(1.02);
    box-shadow: 0 4px 20px rgba(255, 255, 255, 0.15);
}

.cut-btn:active:not(:disabled) {
    transform: scale(0.98);
}

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

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

/* ===== Preview Area ===== */
.preview-area {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    overflow: hidden;
    transition: all var(--transition-normal);
}

.preview-area.dragover {
    background: var(--bg-hover);
    outline: 2px dashed var(--text-muted);
    outline-offset: -12px;
}

.preview-container {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 0;
}

.preview-upload-zone {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 360px;
    padding: 2.5rem 2rem;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-lg);
    background: transparent;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.preview-upload-zone:hover {
    border-color: var(--text-muted);
    background: var(--bg-hover);
}

.preview-upload-content {
    text-align: center;
}

.preview-upload-icon {
    width: 40px;
    height: 40px;
    color: var(--text-muted);
    margin-bottom: 1rem;
    transition: color var(--transition-normal);
}

.preview-upload-zone:hover .preview-upload-icon {
    color: var(--text-secondary);
}

.preview-upload-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}

.preview-upload-text span {
    color: var(--text-primary);
    font-weight: 500;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.preview-upload-text span:hover {
    text-decoration: none;
}

.preview-upload-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.image-wrapper {
    position: relative;
    display: none;
    max-width: 100%;
    max-height: calc(100vh - 180px);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.image-wrapper.active {
    display: block;
}

#previewImage {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 180px);
    object-fit: contain;
}

/* ===== Grid Overlay ===== */
.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
}

.grid-cell {
    border: 1px solid var(--grid-line-color);
    background: var(--grid-cell-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    position: relative;
    pointer-events: auto;
    cursor: pointer;
}

.grid-cell:hover {
    background: rgba(59, 130, 246, 0.25);
    border-color: rgba(59, 130, 246, 0.8);
    box-shadow: inset 0 0 30px rgba(59, 130, 246, 0.15);
    z-index: 5;
}

.cell-number {
    font-size: 1.25rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
    pointer-events: none;
}

.cell-number.hidden {
    display: none;
}

.cell-resolution {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.625rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.6);
    background: rgba(0, 0, 0, 0.6);
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
    white-space: nowrap;
}

/* ===== Image Info ===== */
.image-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 1.25rem;
}

.image-info .separator {
    color: var(--text-muted);
}

/* ===== Footer ===== */
.footer {
    padding: 1rem 2rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.footer p {
    font-size: 0.6875rem;
    color: var(--text-muted);
}

/* ===== Animation Keyframes ===== */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.image-wrapper.active {
    animation: fadeIn 0.3s ease;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .controls-panel {
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .image-wrapper {
        max-height: 60vh;
    }

    #previewImage {
        max-height: 60vh;
    }
}

@media (max-width: 640px) {
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.375rem;
        padding: 1rem;
    }

    .controls-panel {
        padding: 1rem;
    }

    .preview-area {
        padding: 1rem;
    }

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

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* Support Badge */
/* Support Card */
.support-card {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-secondary);
    padding: 12px;
    padding-right: 20px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
    text-decoration: none;
    transition: var(--transition-normal);
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.support-image {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
}

.support-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.fb-badge {
    position: absolute;
    bottom: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #1877F2;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    border: 2px solid var(--bg-secondary);
}

.fb-badge svg {
    width: 12px;
    height: 12px;
}

.support-content {
    display: flex;
    flex-direction: column;
}

.support-title {
    font-size: 0.9375rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.support-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.support-card:hover {
    background: var(--bg-card);
    border-color: #1877F2;
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.support-card:hover .fb-badge {
    transform: scale(1.1);
}

@media (max-width: 768px) {
    .support-card {
        bottom: 16px;
        right: 16px;
        padding: 10px;
        padding-right: 16px;
        gap: 12px;
    }

    .support-image {
        width: 40px;
        height: 40px;
    }

    .support-title {
        font-size: 0.875rem;
    }

    .support-subtitle {
        font-size: 0.7rem;
    }
}