/* The region similarity demo. Colours come from ../../css/theme.css. */

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
}

a {
    color: var(--link-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

:focus-visible {
    outline: 3px solid var(--focus-color);
    outline-offset: 2px;
}

.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
    flex: none;
}

/* --- CONTROLS --- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
    max-width: 1400px;
    margin: 24px auto;
    padding: 14px 20px;
}

/* the toolbar is a card inside the page margins */
.toolbar,
.pair,
.status,
.info {
    width: calc(100% - 48px);
}

h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.3px;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.select,
.number {
    height: 44px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.9rem;
}

.select {
    appearance: none;
    padding-right: 36px;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23334155' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    cursor: pointer;
}

body.dark-mode .select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f8fafc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
}

.number {
    width: 90px;
}

.select:hover,
.number:hover {
    border-color: var(--link-color);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 10px;
    background-color: var(--accent-color);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn:hover:not(:disabled) {
    background-color: var(--accent-hover);
}

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

.text-btn {
    padding: 0 16px;
}

.icon-btn {
    width: 44px;
    padding: 0;
}

.sun-icon,
body.dark-mode .moon-icon {
    display: none;
}

body.dark-mode .sun-icon {
    display: block;
}

/* --- IMAGES --- */

.pair {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(40px, 7vw, 120px);
    max-width: 1400px;
    margin: 0 auto;
}

.panel {
    width: 100%;
    max-width: 75vh;
    justify-self: center;
    padding: 14px;
}

.panel:first-of-type {
    justify-self: end;
}

.panel:nth-of-type(2) {
    justify-self: start;
}

.panel.dragging {
    border-color: var(--link-color);
}

.panel-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.panel-bar h2 {
    margin: 0;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.image-name {
    color: var(--text-muted);
    font-weight: 500;
}

.frame {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
}

.frame canvas,
.frame .grid {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.grid {
    display: grid;
}

.cell {
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: transparent;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}

.cell:hover,
.cell.target {
    border: 2px solid rgba(255, 255, 255, 0.9);
    background-color: rgba(255, 255, 255, 0.12);
}

.cell[aria-pressed="true"] {
    border: 2px solid #fff;
    background-color: rgba(255, 255, 255, 0.28);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.5) inset;
}

.cell:focus-visible {
    outline: 3px solid #fff;
    outline-offset: -3px;
}

.busy,
.drop-hint {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(15, 23, 42, 0.55);
    color: #fff;
    font-size: 0.95rem;
    text-align: center;
}

.busy[hidden] {
    display: none;
}

.drop-hint {
    display: none;
    border: 3px dashed #fff;
    border-radius: 12px;
}

.panel.dragging .drop-hint {
    display: flex;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

/* the connections are drawn over both panels and do not catch the pointer */
.links {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    z-index: 5;
}

.links path {
    fill: none;
    stroke-linecap: round;
}

.links .line {
    stroke: var(--connection-color);
}

.links .halo {
    stroke: rgba(0, 0, 0, 0.45);
}

.links .dot {
    fill: var(--connection-color);
    stroke: #fff;
    stroke-width: 1.5;
}

.status {
    max-width: 1400px;
    min-height: 1.5em;
    margin: 16px auto 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
}

/* --- IMAGE PICKER --- */

.picker {
    width: min(640px, calc(100vw - 32px));
    max-height: min(80vh, 720px);
    padding: 20px;
    color: var(--text-main);
    overflow: auto;
}

.picker::backdrop {
    background: var(--overlay-dim);
}

.picker-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.picker h3 {
    margin: 0;
    font-size: 1.1rem;
}

.close {
    background: transparent;
    font-size: 1.1rem;
}

.thumbs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.thumb {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-color);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
}

.thumb:hover {
    border-color: var(--link-color);
}

.thumb img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 6px;
}

.hint {
    margin: 10px 0 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* --- TEXT --- */

.info {
    max-width: 1400px;
    margin: 40px auto;
}

.info h2 {
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
}

/* --- NARROW SCREENS: the images are stacked --- */

@media (max-width: 800px) {
    .toolbar,
    .pair,
    .status,
    .info {
        width: calc(100% - 24px);
    }

    .pair {
        grid-template-columns: minmax(0, 1fr);
        gap: 72px;
    }

    .panel,
    .panel:first-of-type,
    .panel:nth-of-type(2) {
        max-width: 100%;
        justify-self: stretch;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }

    .spinner {
        animation-duration: 3s;
    }
}
