/* ============================================================
   Card Finder — Real-Time Camera Scanner Styles
   ============================================================ */

/* ---- Scanner Container ---- */
.scanner-container {
    position: relative;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    border-radius: 16px;
    overflow: hidden;
    background: #000;
    aspect-ratio: 3/4;
}

.scanner-container.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: none;
    border-radius: 0;
    z-index: 5000;
    aspect-ratio: auto;
}

/* ---- Video Element ---- */
.scanner-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ---- Hidden Canvas for Frame Capture ---- */
.scanner-canvas {
    display: none;
}

/* ---- Card Guide Overlay ---- */
.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 10;
}

.guide-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 65%;
    aspect-ratio: 63/88; /* Standard TCG card ratio */
    border: 3px solid rgba(255, 255, 255, 0.6);
    border-radius: 12px;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.guide-frame.scanning {
    border-color: rgba(102, 126, 234, 0.8);
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.3);
    animation: guidePulse 2s ease-in-out infinite;
}

.guide-frame.matched {
    border-color: rgba(34, 197, 94, 0.9);
    box-shadow: 0 0 30px rgba(34, 197, 94, 0.4);
    animation: none;
}

.guide-frame.low-confidence {
    border-color: rgba(245, 158, 11, 0.8);
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.3);
}

.guide-frame.locked {
    border-color: rgba(34, 197, 94, 1);
    box-shadow: 0 0 40px rgba(34, 197, 94, 0.6);
    animation: none;
}

/* Semi-transparent card placement guide fill */
.guide-fill {
    position: absolute;
    top: 4px;
    left: 4px;
    right: 4px;
    bottom: 4px;
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    pointer-events: none;
    transition: opacity 0.3s;
}

.guide-frame.matched .guide-fill,
.guide-frame.locked .guide-fill {
    border-color: rgba(34, 197, 94, 0.2);
}

.guide-frame.low-confidence .guide-fill {
    border-color: rgba(245, 158, 11, 0.2);
}

@keyframes guidePulse {
    0%, 100% { border-color: rgba(102, 126, 234, 0.5); }
    50% { border-color: rgba(102, 126, 234, 0.9); }
}

/* Guide corner accents */
.guide-frame::before,
.guide-frame::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    border-color: inherit;
    border-style: solid;
}

.guide-frame::before {
    top: -2px;
    left: -2px;
    border-width: 4px 0 0 4px;
    border-radius: 8px 0 0 0;
}

.guide-frame::after {
    top: -2px;
    right: -2px;
    border-width: 4px 4px 0 0;
    border-radius: 0 8px 0 0;
}

.guide-corners-bottom::before,
.guide-corners-bottom::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    border-color: inherit;
    border-style: solid;
}

.guide-corners-bottom::before {
    bottom: -2px;
    left: -2px;
    border-width: 0 0 4px 4px;
    border-radius: 0 0 0 8px;
}

.guide-corners-bottom::after {
    bottom: -2px;
    right: -2px;
    border-width: 0 4px 4px 0;
    border-radius: 0 0 8px 0;
}

.guide-text {
    position: absolute;
    top: 8%;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 14px;
    font-weight: 600;
    text-shadow: 0 1px 4px rgba(0,0,0,0.7);
    text-align: center;
    white-space: nowrap;
}

/* ---- Scanning Indicator ---- */
.scan-indicator {
    position: absolute;
    bottom: 160px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    z-index: 15;
    transition: opacity 0.3s, transform 0.3s;
}

.scan-indicator.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
    pointer-events: none;
}

.scan-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    animation: scanDotPulse 1s ease-in-out infinite;
}

.scan-dot.active {
    background: #22c55e;
    animation: none;
}

@keyframes scanDotPulse {
    0%, 100% { opacity: 0.4; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
}

/* ---- Match Result Overlay ---- */
.match-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.85) 30%);
    padding: 60px 16px 16px;
    z-index: 20;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
}

.match-overlay.visible {
    transform: translateY(0);
}

.match-card-info {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.match-card-thumb {
    width: 60px;
    height: 84px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid rgba(255,255,255,0.3);
    flex-shrink: 0;
}

.match-card-details {
    flex: 1;
    min-width: 0;
}

.match-card-name {
    color: white;
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.match-card-model {
    color: rgba(255,255,255,0.7);
    font-size: 12px;
    margin-bottom: 6px;
}

.match-confidence-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.confidence-fill-track {
    flex: 1;
    height: 6px;
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

.confidence-fill.high { background: #22c55e; }
.confidence-fill.medium { background: #f59e0b; }
.confidence-fill.low { background: #ef4444; }

.confidence-label {
    color: white;
    font-size: 14px;
    font-weight: 700;
    min-width: 40px;
    text-align: right;
}

.match-price-row {
    display: flex;
    gap: 12px;
    align-items: baseline;
    margin-top: 4px;
}

.match-price-jpy {
    color: #a5b4fc;
    font-size: 18px;
    font-weight: 700;
}

.match-price-sgd {
    color: #86efac;
    font-size: 14px;
    font-weight: 600;
}

.match-rarity-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    color: white;
}

/* ---- Match Action Buttons ---- */
.match-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.match-action-btn {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: transform 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.match-action-btn:active {
    transform: scale(0.97);
}

.confirm-btn {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.3);
}

.rescan-btn {
    background: rgba(255,255,255,0.15);
    color: white;
    border: 1px solid rgba(255,255,255,0.25);
}

/* ---- Scanner Controls (bottom bar) ---- */
.scanner-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    padding: 16px;
    background: linear-gradient(transparent, rgba(0,0,0,0.6));
    z-index: 25;
}

.scanner-controls.hidden-by-match {
    z-index: 5; /* Behind match overlay */
}

.ctrl-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.2);
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.2s;
}

.ctrl-btn:active {
    background: rgba(255,255,255,0.35);
}

.ctrl-btn.close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 30;
    background: rgba(0,0,0,0.5);
}

/* ---- Pause/Play Toggle ---- */
.pause-btn.paused {
    background: rgba(239, 68, 68, 0.6);
}

/* ---- Flash/Torch ---- */
.torch-btn.active {
    background: rgba(250, 204, 21, 0.5);
}

/* ---- Debug Overlay ---- */
.debug-overlay {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: #86efac;
    padding: 6px 10px;
    border-radius: 8px;
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: 10px;
    line-height: 1.5;
    z-index: 30;
    display: none;
    pointer-events: none;
}

.debug-overlay.visible {
    display: block;
}

/* ---- Mode Switcher (Scanner / Upload tabs) ---- */
.mode-switcher {
    display: flex;
    background: rgba(255,255,255,0.15);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 16px;
}

.mode-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.7);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.mode-tab.active {
    background: white;
    color: #667eea;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* ---- Camera Permission States ---- */
.camera-permission {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    background: #1a1a2e;
    border-radius: 16px;
    min-height: 300px;
}

.camera-permission .icon {
    font-size: 56px;
    margin-bottom: 16px;
}

.camera-permission h3 {
    color: white;
    font-size: 18px;
    margin-bottom: 8px;
}

.camera-permission p {
    color: rgba(255,255,255,0.6);
    font-size: 13px;
    margin-bottom: 20px;
    max-width: 280px;
}

.camera-permission .retry-btn {
    padding: 12px 28px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

/* ---- Lock-on Animation ---- */
@keyframes lockOnPulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.guide-frame.locked {
    animation: lockOnPulse 1s ease-out;
    border-color: #22c55e;
}

/* ---- Scan Line Animation ---- */
.scan-line {
    position: absolute;
    left: 5%;
    right: 5%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #667eea, transparent);
    opacity: 0;
    z-index: 11;
    transition: opacity 0.3s;
}

.scan-line.active {
    opacity: 1;
    animation: scanLineMove 2s ease-in-out infinite;
}

@keyframes scanLineMove {
    0% { top: 20%; }
    50% { top: 75%; }
    100% { top: 20%; }
}

/* ---- Top matches strip (during scanning) ---- */
.top-matches-strip {
    position: absolute;
    bottom: 70px;
    left: 0;
    right: 0;
    display: flex;
    gap: 6px;
    padding: 0 12px;
    overflow-x: auto;
    z-index: 15;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.top-matches-strip::-webkit-scrollbar {
    display: none;
}

.mini-match {
    flex-shrink: 0;
    width: 52px;
    background: rgba(0,0,0,0.7);
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-color 0.3s;
}

.mini-match.top-1 {
    border-color: #22c55e;
    width: 56px;
}

.mini-match img {
    width: 100%;
    aspect-ratio: 63/88;
    object-fit: cover;
    display: block;
}

.mini-match-conf {
    text-align: center;
    font-size: 8px;
    font-weight: 700;
    color: white;
    padding: 2px 0;
    background: rgba(0,0,0,0.5);
}

/* ---- Fullscreen adjustments ---- */
.scanner-container.fullscreen .guide-text {
    top: max(env(safe-area-inset-top, 16px), 60px);
}

.scanner-container.fullscreen .ctrl-btn.close-btn {
    top: max(env(safe-area-inset-top, 16px), 16px);
}

.scanner-container.fullscreen .scanner-controls {
    padding-bottom: max(env(safe-area-inset-bottom, 16px), 16px);
}

/* ---- Responsive ---- */
@media (max-width: 500px) {
    .scanner-container {
        border-radius: 12px;
    }

    .guide-frame {
        width: 72%;
    }

    .guide-text {
        font-size: 13px;
    }

    .match-card-name {
        font-size: 14px;
    }

    .match-action-btn {
        padding: 12px;
        font-size: 14px;
    }
}

/* Orientation change handling */
@media (orientation: landscape) and (max-height: 500px) {
    .scanner-container {
        aspect-ratio: auto;
        height: 100vh;
    }

    .guide-frame {
        width: 35%;
    }

    .match-overlay {
        padding: 30px 16px 12px;
    }

    .match-actions {
        margin-top: 8px;
    }
}

/* ---- Scanner Card Selection (detail view) ---- */

.scanner-selectable {
    transition: all 0.15s ease;
    border: 2px solid #e0e0e0;
    position: relative;
}

.scanner-selectable:active {
    transform: scale(0.95);
}

.scanner-selected {
    border-color: #667eea !important;
    background: #f0f4ff !important;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.3);
}

.scanner-selected::before {
    content: '\2713';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 18px;
    height: 18px;
    background: #667eea;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    z-index: 2;
}
