/* ====== Design Tokens ====== */
:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #3b82f6;
    --accent-hover: #60a5fa;
    --border-color: #334155;
    --radius-lg: 12px;
    --radius-md: 8px;
    --danger: #ef4444;
    --success: #22c55e;
}

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

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

/* ====== Header ====== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background-color: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.4rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent-color), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0;
}

.header-content {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

/* ====== Buttons ====== */
.btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 0.5rem 1.15rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
}

.btn:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}

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

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

.btn-secondary:hover {
    background-color: #475569;
}

/* ====== Layout ====== */
.container {
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1.5rem;
    flex: 1;
}

@media (min-width: 1100px) {
    .container {
        flex-direction: row;
        align-items: flex-start;
        padding: 2rem;
        gap: 1.5rem;
    }

    .pane {
        flex: 1;
        min-width: 0;
    }
}

/* ====== Cards ====== */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.15),
        0 2px 4px -1px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.3s;
}

.card:hover {
    box-shadow:
        0 8px 16px -2px rgba(0, 0, 0, 0.25),
        0 4px 8px -2px rgba(0, 0, 0, 0.12);
}

/* ====== Typography ====== */
h2 {
    font-size: 1.1rem;
    margin-bottom: 0.35rem;
    font-weight: 600;
}

p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.subtitle {
    font-size: 0.78rem;
    font-style: italic;
    margin-top: -0.25rem;
}

/* ====== Controls ====== */
.control-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.control-row label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
}

select {
    background-color: var(--border-color);
    color: var(--text-primary);
    border: 1px solid #475569;
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    outline: none;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

select:focus {
    border-color: var(--accent-color);
}

.file-upload {
    margin-bottom: 0.75rem;
}

input[type="file"] {
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

input[type="file"]::file-selector-button {
    background-color: var(--border-color);
    color: var(--text-primary);
    border: none;
    padding: 0.4rem 0.9rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-right: 0.75rem;
    transition: background-color 0.2s;
    font-family: inherit;
    font-size: 0.85rem;
}

input[type="file"]::file-selector-button:hover {
    background-color: #475569;
}

/* ====== Canvas ====== */
.canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #000;
    border-radius: var(--radius-md);
    overflow: hidden;
    padding: 0;
    position: relative;
    border: 1px solid var(--border-color);
}

canvas {
    background-color: #000;
    image-rendering: auto;
    display: block;
}

#source-canvas,
#recon-canvas {
    width: 256px;
    max-width: 100%;
    aspect-ratio: 1 / 1;
}

/* Wrapper tightly wraps the DFT canvas so overlay matches exactly */
.canvas-wrapper {
    position: relative;
    display: inline-block;
    width: 256px;
    max-width: 100%;
}

.canvas-wrapper canvas:first-child {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
}

#mask-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.45;
}

.interactable {
    cursor: crosshair;
    touch-action: none;
}

/* ====== Mask Info ====== */
.mask-info {
    font-family: 'Inter', monospace;
    font-size: 0.8rem;
    color: var(--accent-hover);
    min-height: 1.4em;
    margin-bottom: 0.5rem;
    padding: 0.25rem 0;
}

/* ====== Info Box ====== */
.info-box {
    margin-top: 1rem;
    background-color: rgba(0, 0, 0, 0.25);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.info-box h3 {
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.value-display {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.9rem;
    color: var(--accent-hover);
    word-break: break-word;
    line-height: 1.5;
}

/* ====== DFT header ====== */
.dft-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35rem;
}

/* ====== Responsive ====== */
@media (max-width: 600px) {
    header {
        padding: 0.75rem 1rem;
    }

    header h1 {
        font-size: 1.1rem;
    }

    .container {
        padding: 1rem;
        gap: 1rem;
    }

    .card {
        padding: 1rem;
    }

    .canvas-container {
        width: 100%;
    }

    /* Canvases already have max-width:100% + aspect-ratio:1/1,
       so they scale properly without any !important overrides */
}

/* ====== Animations ====== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card {
    animation: fadeIn 0.4s ease-out both;
}

.card:nth-child(2) {
    animation-delay: 0.08s;
}

.card:nth-child(3) {
    animation-delay: 0.16s;
}