/* ══════════════════════════════════════════════════════════
   Aura Vision Scanner — Glassmorphic Modal Styles
   ══════════════════════════════════════════════════════════ */

/* ── Backdrop ── */
.vision-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

.vision-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* ── Modal Shell ── */
.vision-modal {
    position: fixed;
    top: calc(50% + 30px);
    left: 50%;
    transform: translate(-50%, -50%) scale(0.92);
    z-index: 9999;
    width: 92vw;
    max-width: 920px;   /* was 800 — the Castling control (~116px) pushed the toolbar's
                           last group onto its own line; widened to keep every group on
                           one row on typical desktop widths. Still capped by 92vw, so it
                           degrades to the same wrap on narrow viewports as before. */
    max-height: 78vh;
    overflow-y: auto;
    background: #0f1016;
    border-radius: 16px;
    border: 1px solid rgba(120, 80, 255, 0.25);
    box-shadow:
        0 0 40px rgba(100, 60, 255, 0.12),
        0 0 80px rgba(0, 200, 255, 0.06),
        0 25px 60px rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-family: 'Cairo', 'Montserrat', sans-serif;
}

.vision-modal.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

/* Scrollbar styling */
.vision-modal::-webkit-scrollbar {
    width: 4px;
}

.vision-modal::-webkit-scrollbar-track {
    background: transparent;
}

.vision-modal::-webkit-scrollbar-thumb {
    background: rgba(120, 80, 255, 0.3);
    border-radius: 4px;
}

/* ── Header ── */
.vision-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.vision-header-text {
    text-align: center;
    flex: 1;
}

.vision-title {
    font-size: 1.3rem;
    font-weight: 800;
    color: #e2e8f0;
    text-shadow: 0 0 20px rgba(120, 80, 255, 0.5), 0 0 40px rgba(0, 200, 255, 0.2);
    margin: 0;
    letter-spacing: 0.5px;
}

.vision-subtitle {
    font-size: 0.78rem;
    color: #64748b;
    margin-top: 4px;
    line-height: 1.5;
}

.vision-kbd {
    display: inline-block;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85em;
    color: #cbd5e1;
}

.vision-header-actions {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    gap: 12px;
    align-items: center;
    z-index: 2;
}

[dir="rtl"] .vision-header-actions {
    right: auto;
    left: 16px;
}

.vision-close-btn {
    width: 32px;
    height: 32px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    color: #94a3b8;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.vision-close-btn:hover {
    background: rgba(255, 60, 60, 0.15);
    border-color: rgba(255, 60, 60, 0.3);
    color: #ff6b6b;
}

.vision-new-btn {
    padding: 6px 12px;
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 8px;
    background: rgba(56, 189, 248, 0.1);
    color: #38bdf8;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.vision-new-btn:hover {
    background: rgba(56, 189, 248, 0.2);
    border-color: rgba(56, 189, 248, 0.5);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.2);
}

/* ── Main Content Grid ── */
.vision-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    padding: 15px 20px;
}

/* ── Drop Zone (Right Column in RTL) ── */
.vision-drop-col {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.vision-drop-zone {
    position: relative;
    min-height: 250px;
    max-width: 360px;
    aspect-ratio: 1 / 1;
    border: 2px dashed rgba(120, 80, 255, 0.4);
    border-radius: 14px;
    background: rgba(120, 80, 255, 0.04);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    overflow: hidden;
    animation: visionBorderPulse 3s ease-in-out infinite;
    justify-self: center;
}

@keyframes visionBorderPulse {
    0%, 100% { border-color: rgba(120, 80, 255, 0.3); }
    50% { border-color: rgba(120, 80, 255, 0.6); box-shadow: inset 0 0 25px rgba(120, 80, 255, 0.06); }
}

.vision-drop-zone.drag-over {
    border-color: rgba(0, 229, 255, 0.7);
    background: rgba(0, 229, 255, 0.08);
    box-shadow: inset 0 0 30px rgba(0, 229, 255, 0.1);
    animation: none;
}

.vision-drop-zone.has-image {
    border-color: rgba(120, 80, 255, 0.2);
    cursor: default;
    animation: none;
}

/* Drop Zone Placeholder Content */
.vision-drop-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 20px;
    text-align: center;
}

.vision-drop-icon {
    font-size: 3rem;
    color: rgba(120, 80, 255, 0.5);
    filter: drop-shadow(0 0 12px rgba(120, 80, 255, 0.3));
}

.vision-drop-text {
    font-size: 0.82rem;
    color: #64748b;
    line-height: 1.6;
    max-width: 220px;
}

.vision-drop-browse-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: 1px solid rgba(120, 80, 255, 0.3);
    border-radius: 8px;
    background: rgba(120, 80, 255, 0.1);
    color: #a78bfa;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.vision-drop-browse-btn:hover {
    background: rgba(120, 80, 255, 0.2);
    border-color: rgba(120, 80, 255, 0.5);
}

/* Mobile Camera Button */
.vision-camera-btn {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: 1px solid rgba(0, 229, 255, 0.3);
    border-radius: 8px;
    background: rgba(0, 229, 255, 0.1);
    color: #00E5FF;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    margin-top: 4px;
}

.vision-camera-btn:hover {
    background: rgba(0, 229, 255, 0.2);
}

@media (max-width: 768px) {
    .vision-camera-btn {
        display: inline-flex;
    }
}

/* ── Uploaded Image Display ── */
.vision-image-container {
    position: absolute;
    inset: 0;
    display: none;
}

.vision-drop-zone.has-image .vision-image-container {
    display: block;
}

.vision-drop-zone.has-image .vision-drop-placeholder {
    display: none;
}

.vision-uploaded-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0.85;
    padding: 8px;
    border-radius: 8px;
}

/* ── Crop Toolbar & Tools ── */
.vision-crop-toolbar {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    background: rgba(11, 15, 20, 0.9);
    padding: 10px 15px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

.vision-tool-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(255, 255, 255, 0.05);
    color: #e2e8f0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.vision-tool-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    transform: translateY(-1px);
}

.vision-tool-btn.btn-smart-crop {
    background: rgba(0, 229, 255, 0.15);
    color: #00E5FF;
    border: 1px solid rgba(0, 229, 255, 0.3);
}

.vision-tool-btn.btn-smart-crop:hover {
    background: rgba(0, 229, 255, 0.25);
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.2);
}

.vision-tool-btn.btn-manual-crop {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
    border: 1px solid rgba(168, 85, 247, 0.3);
}

.vision-tool-btn.btn-manual-crop:hover {
    background: rgba(168, 85, 247, 0.25);
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.2);
}

.vision-tool-btn.btn-primary {
    background: #00E5FF;
    color: #0b0f14;
}

.vision-tool-btn.btn-primary:hover {
    background: #00b3cc;
}

/* ── Cropper Container ── */
.vision-cropper-container {
    position: absolute;
    inset: 0;
    background: #0b0f14;
    z-index: 20;
    display: none;
    border-radius: 14px;
    overflow: hidden;
}

.vision-cropper-container img {
    display: block;
    max-width: 100%;
}

.vision-cropper-actions {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 21;
    background: rgba(11, 15, 20, 0.9);
    padding: 10px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ── Laser Scan Animation ── */
.vision-laser-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent 0%, #00E5FF 20%, #a855f7 50%, #00E5FF 80%, transparent 100%);
    box-shadow:
        0 0 15px rgba(0, 229, 255, 0.8),
        0 0 30px rgba(0, 229, 255, 0.4),
        0 0 60px rgba(168, 85, 247, 0.3);
    top: 0;
    opacity: 0;
    pointer-events: none;
    z-index: 5;
}

.vision-drop-zone.scanning .vision-laser-line {
    opacity: 1;
    animation: laserScan 1.8s ease-in-out infinite;
}

@keyframes laserScan {
    0% { top: 2%; }
    50% { top: 95%; }
    100% { top: 2%; }
}

/* Scanning Status Text */
.vision-scan-status {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.78rem;
    font-weight: 700;
    color: #00E5FF;
    text-shadow: 0 0 12px rgba(0, 229, 255, 0.6);
    z-index: 6;
    opacity: 0;
    white-space: nowrap;
    animation: none;
}

.vision-drop-zone.scanning .vision-scan-status {
    opacity: 1;
    animation: scanTextPulse 1.2s ease-in-out infinite;
}

@keyframes scanTextPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* ── Preview Board (Left Column in RTL) ── */
.vision-preview-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 250px;
    max-width: 360px;
    justify-self: center;
}

.vision-preview-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: #334155;
}

.vision-preview-empty i {
    font-size: 3rem;
    opacity: 0.4;
}

.vision-preview-empty span {
    font-size: 0.78rem;
    color: #475569;
}

.vision-preview-board {
    width: 100%;
    max-width: 360px;
    aspect-ratio: 1;
    display: none;
    position: relative;
}

.vision-preview-board.active {
    display: block;
    animation: boardFadeIn 0.5s ease forwards;
}

@keyframes boardFadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.vision-preview-canvas {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* ── Success Badge ── */
.vision-success-badge {
    display: none;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 6px 14px;
    border-radius: 8px;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: #10b981;
    font-size: 0.78rem;
    font-weight: 700;
}

.vision-success-badge.active {
    display: inline-flex;
    animation: badgePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes badgePop {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* ── Error Badge ── */
.vision-error-badge {
    display: none;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 8px 16px;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #ef4444;
    font-size: 0.78rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.5;
    max-width: 300px;
}

.vision-error-badge.active {
    display: inline-flex;
    animation: badgePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ── Warning Badge (illogical / illegal position) ── */
.vision-warning-badge {
    display: none;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 8px 16px;
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #f59e0b;
    font-size: 0.78rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.5;
    max-width: 340px;
}

.vision-warning-badge.active {
    display: inline-flex;
    animation: badgePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.vision-warning-badge::before {
    content: '\f071'; /* fa-triangle-exclamation */
    font-family: 'Font Awesome 6 Free', 'Font Awesome 5 Free';
    font-weight: 900;
    flex-shrink: 0;
}

/* Shake feedback when an illegal position blocks analysis */
@keyframes visionShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-7px); }
    40%, 80% { transform: translateX(7px); }
}

.vision-cta-btn.vision-shake {
    animation: visionShake 0.4s ease-in-out;
}

/* ── Control Toolbar ── */
.vision-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 16px 24px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.vision-fen-field {
    flex: 1;
    min-width: 200px;
    display: flex;
    align-items: center;
    gap: 0;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    overflow: hidden;
}

.vision-fen-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #94a3b8;
    font-size: 0.72rem;
    font-family: 'Courier New', monospace;
    padding: 8px 12px;
    direction: ltr;
    text-align: left;
}

.vision-fen-copy-btn {
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    color: #64748b;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

[dir="rtl"] .vision-fen-copy-btn {
    border-left: none;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.vision-fen-copy-btn:hover {
    color: #00E5FF;
    background: rgba(0, 229, 255, 0.06);
}

.vision-fen-copy-btn.copied {
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

/* Toolbar Action Buttons */
.vision-tool-btn {
    padding: 8px 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    color: #94a3b8;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: inherit;
    white-space: nowrap;
}

.vision-tool-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
}

.vision-tool-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.vision-tool-btn:disabled:hover {
    background: rgba(255, 255, 255, 0.04);
    color: #94a3b8;
}

/* ── Custom Dropdowns ── */
.vision-dropdown {
    position: relative;
}

.vision-dropdown-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    background: rgba(15, 16, 22, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(120, 80, 255, 0.3);
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(120, 80, 255, 0.2);
    list-style: none;
    padding: 6px;
    min-width: 140px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease;
    z-index: 100;
}

.vision-dropdown.active .vision-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.vision-dropdown-menu li {
    padding: 8px 12px;
    border-radius: 6px;
    color: #e2e8f0;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s ease;
    white-space: nowrap;
}

.vision-dropdown-menu li:hover {
    background: rgba(120, 80, 255, 0.2);
}

.vision-dropdown-menu li label {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    cursor: pointer;
    white-space: nowrap;
}

.vision-dropdown-menu li label input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: #7c5cff;
    flex-shrink: 0;
}

/* Castling sits at the outer (leading) edge of the toolbar, so its menu is anchored to
   the button's OPPOSITE edge and opens inward — anchoring it like the other dropdowns
   (outer edge) pushed the menu past the modal boundary, and the modal's overflow-y:auto
   clips overflow-x too (per spec, one auto axis forces the other), truncating the text.
   ID-scoped so only this menu is affected; also wider for the longer Arabic castling labels. */
#visionCastleMenu {
    min-width: 190px;
    right: auto;
    left: 0;
}
[dir="rtl"] #visionCastleMenu {
    right: auto;
    left: 0;
}

[dir="rtl"] .vision-dropdown-menu {
    right: 0;
    left: auto;
}

/* ── Main CTA Button ── */
.vision-cta-btn {
    width: 100%;
    padding: 12px 20px;
    margin-top: 15px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #7c3aed 0%, #0ea5e9 50%, #06b6d4 100%);
    background-size: 200% 200%;
    color: #fff;
    font-size: 1rem;
    font-weight: 800;
    font-family: 'Cairo', 'Montserrat', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    animation: ctaShine 3s ease-in-out infinite;
    letter-spacing: 0.3px;
}

@keyframes ctaShine {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.vision-cta-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(14, 165, 233, 0.4);
}

.vision-cta-btn:active:not(:disabled) {
    transform: translateY(1px);
}

/* ── Vision Notes (Helpful Info) ── */
.vision-notes {
    margin-top: 20px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 15px;
    text-align: right;
    animation: fadeIn 0.4s ease-out forwards;
}

[dir="ltr"] .vision-notes {
    text-align: left;
}

.vision-notes h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #0ea5e9;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    font-weight: 600;
}

.vision-notes ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.vision-notes li {
    font-size: 13px;
    color: #94a3b8;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    text-align: right;
    gap: 8px;
    line-height: 1.4;
}

[dir="ltr"] .vision-notes li {
    text-align: left;
}

.vision-notes li i {
    color: #64748b;
    margin-top: 3px;
    font-size: 12px;
}

.vision-cta-btn:disabled {
    opacity: 0.85; /* Keep it vibrant as per mockup */
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    animation: none;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .vision-modal {
        width: 96vw;
        max-height: 92vh;
        border-radius: 14px;
    }

    .vision-grid {
        grid-template-columns: 1fr;
        gap: 14px;
        padding: 14px 16px;
    }

    .vision-drop-zone {
        min-height: 240px;
    }

    .vision-preview-col {
        min-height: 260px;
    }

    .vision-toolbar {
        padding: 12px 16px 16px;
        gap: 8px;
    }

    .vision-fen-field {
        min-width: 0;
        width: 100%;
    }

    .vision-cta-btn {
        margin-top: 10px;
        font-size: 0.92rem;
    }

    .vision-title {
        font-size: 1.1rem;
    }

    .vision-header {
        padding: 16px 16px 10px;
    }
}

@media (max-width: 400px) {
    .vision-toolbar {
        flex-direction: column;
    }

    .vision-tool-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ── Keyboard shortcut badge ── */
.vision-kbd {
    display: inline-block;
    padding: 1px 5px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.06);
    font-size: 0.7rem;
    font-family: 'Courier New', monospace;
    color: #94a3b8;
    vertical-align: middle;
    direction: ltr;
}

/* ── Button trigger style override in nav bar ── */
#btnVisionScanner {
    position: relative;
}

#btnVisionScanner::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(120, 80, 255, 0.15), rgba(0, 229, 255, 0.1));
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

#btnVisionScanner:hover::after {
    opacity: 1;
}
/* ?? Cropper UI ?? */
.vision-cropper-container {
    position: absolute;
    inset: 0;
    display: none;
    z-index: 10;
    background: #000;
}

.vision-cropper-actions {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    z-index: 15;
}

.vision-cropper-actions .vision-tool-btn {
    background: rgba(15, 16, 22, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    padding: 10px 18px;
}

.vision-cropper-actions .vision-tool-btn.btn-primary {
    background: rgba(16, 185, 129, 0.2);
    border-color: rgba(16, 185, 129, 0.5);
    color: #10b981;
}

.vision-cropper-actions .vision-tool-btn.btn-primary:hover {
    background: rgba(16, 185, 129, 0.3);
}

/* ?? Interactive Board Palette ?? */
.vision-preview-board-wrap {
    width: 100%;
    max-width: 450px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.vision-piece-palette {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    flex-wrap: wrap;
}

.palette-group {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px;
    border-radius: 6px;
    align-items: center;
}

.palette-group img {
    width: 28px;
    height: 28px;
    cursor: grab;
    transition: transform 0.1s;
}

.palette-group img:hover {
    transform: scale(1.1);
}

.palette-group img:active {
    cursor: grabbing;
}

.palette-tool-btn {
    background: transparent;
    border: 1px solid transparent;
    color: #64748b;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.palette-tool-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.palette-tool-btn.active {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
    background: rgba(239, 68, 68, 0.15);
}

/* ── Custom Board Markers ── */
.cb-marker-low-confidence {
    fill: rgba(255, 165, 0, 0.25);
    stroke: rgba(255, 165, 0, 0.5);
    stroke-width: 2px;
    stroke-dasharray: 4, 4;
    animation: lowConfidencePulse 3s infinite ease-in-out;
}

@keyframes lowConfidencePulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; fill: rgba(255, 100, 0, 0.35); }
}

/* ── Mobile Responsiveness (Max Width: 768px) ── */
@media (max-width: 768px) {
    /* 1. The Board Constraint Fix */
    .vision-grid {
        grid-template-columns: 1fr;
        padding: 10px;
        gap: 15px;
    }
    
    .vision-drop-zone, .vision-preview-board {
        width: 100% !important;
        max-width: 100vw;
        aspect-ratio: 1 / 1;
        box-sizing: border-box;
    }
    
    .vision-preview-col {
        width: 100% !important;
        max-width: 100vw;
        height: auto;
        box-sizing: border-box;
    }

    .vision-modal {
        top: 55%; /* Push it down to avoid the header */
        width: 95vw;
        max-height: 85vh;
        padding-bottom: 10px;
    }

    /* Make text and padding smaller to fit better */
    .vision-header {
        padding: 16px 15px 12px;
        flex-direction: column;
        position: relative;
    }

    .vision-header-actions {
        position: static;
        width: 100%;
        justify-content: center;
        margin-top: 10px;
    }

    .vision-close-btn {
        position: absolute;
        top: 12px;
        right: 12px;
    }

    [dir="rtl"] .vision-close-btn {
        right: auto;
        left: 12px;
    }

    .vision-title {
        font-size: 1.2rem;
        padding: 0 20px; /* give room for close button */
    }

    .vision-subtitle {
        font-size: 0.8rem;
    }

    .vision-tool-btn {
        font-size: 13px;
        padding: 8px 10px;
    }

    .vision-fen-input {
        font-size: 12px;
        padding: 8px 10px;
    }

    .vision-preview-col {
        gap: 8px; /* prevents board overlapping player tags */
    }

    /* 2. The Mobile Toolbar Flex */
    .vision-toolbar {
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 15px;
    }

    .toolbar-group {
        display: flex;
        flex-direction: row;
        gap: 10px;
        width: 100%;
    }

    .vision-fen-field {
        width: 100%;
        margin-bottom: 0px;
    }
    
    #visionTurnBtn { flex: 1; justify-content: center; }
    #visionOrientationDropdown { flex: 1; }
    
    #visionFlipBtn { flex: 1; justify-content: center; }
    #visionClearBtn { flex: 1; justify-content: center; }

    #visionOpenWithDropdown { 
        width: 100%; 
        margin-top: 0px;
    }
    
    .vision-dropdown {
        width: 100%;
        flex: 1;
    }
    
    .vision-dropdown-menu {
        width: 100%; /* Ensure dropdown menus match button width */
    }

    .vision-tool-btn {
        width: 100%;
        justify-content: center;
    }

    /* 3. The Main CTA Positioning */
    .vision-cta-btn {
        width: 100%;
        margin-top: 10px;
        position: sticky;
        bottom: 10px;
        z-index: 10;
        box-shadow: 0 5px 20px rgba(0,0,0,0.5);
    }

    /* 4. Drop Zone Height Adjustment */
    .vision-drop-zone {
        min-height: 120px;
        height: auto;
        aspect-ratio: auto;
        padding: 20px 10px;
    }
    
    .vision-drop-zone.has-image {
        aspect-ratio: 1 / 1;
    }
}

/* ?? Mini Vision Dropzone (Trigger in Panel) ?? */
.mini-vision-dropzone {
    margin: 15px 16px;
    border-radius: 12px;
    border: 2px dashed rgba(181, 60, 255, 0.5);
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all 0.3s ease;
    cursor: pointer;
    overflow: hidden;
    position: relative;
    min-height: 120px;
}

.mini-vision-dropzone:hover, .mini-vision-dropzone.drag-over {
    border-color: #00e5ff;
    background: rgba(181, 60, 255, 0.08);
    box-shadow: inset 0 0 20px rgba(0, 229, 255, 0.2), 0 0 15px rgba(181, 60, 255, 0.4);
}

.mvd-desktop-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    gap: 12px;
    text-align: center;
}

[dir="ltr"] .mvd-desktop-content {
    text-align: center;
}

.mvd-icon {
    font-size: 2.2rem;
    color: rgba(181, 60, 255, 0.8);
    filter: drop-shadow(0 0 8px rgba(181, 60, 255, 0.4));
    transition: all 0.3s ease;
}

.mini-vision-dropzone:hover .mvd-icon {
    color: #00e5ff;
    transform: scale(1.15) translateY(-2px);
    filter: drop-shadow(0 0 12px rgba(0, 229, 255, 0.6));
}

.mvd-text-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.mvd-title {
    font-size: 1rem;
    font-weight: 700;
    color: #e2e8f0;
    margin-bottom: 4px;
}

.mvd-subtitle {
    font-size: 0.75rem;
    color: #64748b;
    line-height: 1.4;
}

.mvd-mobile-btn {
    display: none;
    width: 100%;
    padding: 12px;
    background: rgba(181, 60, 255, 0.1);
    border: none;
    color: #a78bfa;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.mvd-mobile-btn:hover {
    background: rgba(181, 60, 255, 0.2);
    color: #c4b5fd;
}

.mvd-mobile-icon {
    display: none;
}

@media (max-width: 768px) {
    .mini-vision-dropzone {
        margin: 10px 0;
        border: 1px solid rgba(181, 60, 255, 0.3);
        border-style: solid; /* Not dashed on mobile */
        display: flex;
        flex-direction: column;
    }
    
    .mvd-desktop-content {
        display: none; /* Hide desktop drop area on mobile */
    }
    
    .mvd-mobile-btn {
        display: flex; /* Show mobile button */
    }

    .mvd-mobile-icon {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 1; /* Take up the remaining space */
        min-height: 60px;
        font-size: 2.5rem;
        color: rgba(181, 60, 255, 0.15); /* Faint eye icon */
    }
}
