:root {
    --bg-color: #0b0f19;
    --panel-bg: rgba(20, 25, 40, 0.6);
    --panel-border: rgba(255, 255, 255, 0.08);
    --primary-color: #6d28d9;
    --primary-hover: #7c3aed;
    --primary-glow: rgba(124, 58, 237, 0.5);
    --secondary-color: rgba(255, 255, 255, 0.1);
    --secondary-hover: rgba(255, 255, 255, 0.2);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --font-family: 'Inter', sans-serif;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(109, 40, 217, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(56, 189, 248, 0.15) 0%, transparent 50%);
    background-size: cover;
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    width: 100%;
    max-width: 800px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

header {
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -1px;
}

header h1 span {
    background: linear-gradient(135deg, #a78bfa, #38bdf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    color: var(--text-secondary);
    margin-top: 0.5rem;
    font-size: 1.1rem;
}

/* Glass Panel Utilities */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    align-items: center;
    animation: fadeIn 0.5s ease;
}

.glass-panel.active {
    display: flex;
}

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

/* Upload Zone */
#upload-zone {
    border: 2px dashed var(--panel-border);
    cursor: pointer;
    transition: var(--transition);
}

#upload-zone:hover, #upload-zone.dragover {
    border-color: var(--primary-color);
    background: rgba(109, 40, 217, 0.05);
    box-shadow: 0 0 30px var(--primary-glow);
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 4rem 2rem;
    pointer-events: none;
}

.upload-content svg {
    color: var(--primary-hover);
    transition: var(--transition);
}

#upload-zone:hover .upload-content svg {
    transform: translateY(-5px);
}

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

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

/* Crop Zone */
#crop-zone {
    gap: 1.5rem;
}

.ratio-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
    margin-bottom: -0.5rem;
    justify-content: center;
    align-items: center;
}

.custom-ratio {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.2rem 0.2rem 0.2rem 0.5rem;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
}

.custom-ratio input {
    width: 45px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    text-align: center;
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 600;
    outline: none;
}

.custom-ratio input::-webkit-outer-spin-button,
.custom-ratio input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.custom-ratio span {
    color: var(--text-secondary);
    font-weight: bold;
}

.custom-ratio #custom-ratio-btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    margin-left: 0.25rem;
}

.ratio-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--panel-border);
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-family);
    transition: var(--transition);
}

.ratio-btn:hover {
    background: var(--secondary-hover);
    color: var(--text-primary);
}

.ratio-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    box-shadow: 0 0 10px var(--primary-glow);
}

#workspace {
    position: relative;
    width: 100%;
    max-height: 50vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    border-radius: 12px;
    background: #000;
    user-select: none;
}

#source-image {
    max-width: 100%;
    max-height: 50vh;
    display: block;
    object-fit: contain;
}

#crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    pointer-events: none;
    /* We use clip-path dynamically to cut a hole, or implement dark masking differently */
}

#crop-frame {
    position: absolute;
    border: 2px solid white;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
    pointer-events: auto;
    cursor: grab;
    display: flex;
    justify-content: center;
    align-items: center;
}

#crop-frame:active {
    cursor: grabbing;
}

/* Grid lines inside the frame */
#crop-frame::before, #crop-frame::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.3);
    pointer-events: none;
}

/* Horizontal third lines */
#crop-frame::before {
    top: 33.33%;
    height: 33.33%;
    width: 100%;
    border-top: 1px dashed rgba(255,255,255,0.4);
    border-bottom: 1px dashed rgba(255,255,255,0.4);
    background: transparent;
}

/* Vertical third lines */
#crop-frame::after {
    left: 33.33%;
    width: 33.33%;
    height: 100%;
    border-left: 1px dashed rgba(255,255,255,0.4);
    border-right: 1px dashed rgba(255,255,255,0.4);
    background: transparent;
}


.resize-handle {
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
    pointer-events: auto;
    z-index: 10;
}

.resize-handle.nw { top: -8px; left: -8px; cursor: nwse-resize; }
.resize-handle.ne { top: -8px; right: -8px; cursor: nesw-resize; }
.resize-handle.sw { bottom: -8px; left: -8px; cursor: nesw-resize; }
.resize-handle.se { bottom: -8px; right: -8px; cursor: nwse-resize; }

.actions {
    display: flex;
    gap: 1rem;
    width: 100%;
    justify-content: flex-end;
}

/* Result Zone */
#result-zone {
    gap: 1.5rem;
}

.result-display {
    width: 100%;
    display: flex;
    justify-content: center;
    background: rgba(0,0,0,0.2);
    border-radius: 12px;
    padding: 1rem;
}

#cropped-result {
    max-width: 100%;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-family);
    transition: var(--transition);
    text-decoration: none;
    color: white;
}

.btn.primary {
    background: var(--primary-color);
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn.primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--primary-glow);
}

.btn.secondary {
    background: var(--secondary-color);
}

.btn.secondary:hover {
    background: var(--secondary-hover);
}

@media (max-width: 600px) {
    .app-container {
        padding: 1rem;
    }
    
    header h1 {
        font-size: 2rem;
    }
}
