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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 15px;
    width: 100%;
}

h1 {
    color: #2196F3;
    text-align: center;
    margin-bottom: 15px;
    font-size: 20px;
}

h2 {
    color: #333;
    font-size: 16px;
    margin-bottom: 8px;
}

.hidden {
    display: none !important;
}

#camera-view {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.video-wrapper {
    position: relative;
    width: 100%;
    /* keep camera area compact so page doesn't need vertical scroll on mobile */
    height: 38vh;
    overflow: hidden;
}

video {
    width: 100%;
    height: 100%;
    background: #000;
    border-radius: 6px;
    display: block;
    object-fit: cover; /* crop to fill the compact area */
}

.roi-box {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 2px solid #4CAF50;
    border-radius: 6px;
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.3);
}

canvas.hidden {
    display: none;
}

/* hide debug preview by default on small screens to save space */
#debug-canvas {
    width: auto;
    max-width: 100%;
    max-height: 70px;
    height: auto;
    background: #000;
    border: 2px solid #2196F3;
    border-radius: 4px;
    margin: 6px auto 0;
    display: block;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .container {
        padding: 8px;
    }
    
    h1 {
        font-size: 18px;
        margin-bottom: 10px;
    }
    
    h2 {
        font-size: 14px;
        margin-bottom: 6px;
    }
    
    video {
        max-height: none;
        height: 100%;
    }
    
    /* hide debug canvas on small screens */
    #debug-canvas {
        display: none;
    }
    /* hide ROI preview label to save space */
    #camera-view > p { display: none; }
    
    #camera-view {
        gap: 8px;
    }
    
    .result-text {
        font-size: 18px;
    }
    
    .comparison {
        gap: 8px;
    }
    
    .result-column {
        padding: 6px;
    }
    
    .btn-primary, .btn-secondary, .btn-freeze {
        padding: 12px 20px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    /* keep camera area even more compact for very small screens */
    .video-wrapper { height: 28vh; }
    video { object-fit: cover; }
    #debug-canvas {
        display: block;
        max-height: 40px;
        margin-bottom: 4px;
    }
    .result-text { font-size: 15px; }
    .comparison {
        grid-template-columns: 1fr 1fr;
        gap: 4px;
    }
    .result-column {
        padding: 2px;
        font-size: 12px;
    }
    .result-column h3 {
        font-size: 10px;
        margin-bottom: 2px;
    }
    .result-box {
        padding: 6px;
        margin-bottom: 6px;
    }
    #timestamp, .last-detection, .status { display: none; }
}

.controls {
    display: flex;
    gap: 10px;
}

#capture-btn {
    background: #4CAF50;
}

.btn-freeze {
    background: #FF9800;
    color: white;
    padding: 15px 25px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
    margin-bottom: 10px;
}

.btn-freeze:active {
    background: #F57C00;
}

.btn-primary, .btn-secondary {
    padding: 15px 25px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
}

.btn-primary {
    background: #2196F3;
    color: white;
}

#start-btn {
    flex: 1;
}

.btn-primary:active {
    background: #1976D2;
}

.btn-secondary {
    background: #757575;
    color: white;
}

.btn-secondary:active {
    background: #616161;
}

.result-box {
    background: white;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 8px;
}

.result-column {
    padding: 8px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
}

.result-column h3 {
    font-size: 11px;
    color: #666;
    margin-bottom: 6px;
    text-align: center;
    text-transform: uppercase;
    font-weight: 600;
}

.result-text {
    font-size: 20px;
    font-weight: bold;
    color: #2196F3;
    text-align: center;
    letter-spacing: 1px;
    margin: 6px 0;
    word-break: break-all;
}

.confidence {
    text-align: center;
    color: #666;
    font-size: 10px;
    line-height: 1.3;
}

.status {
    margin-top: 15px;
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    font-size: 14px;
}

.status.info {
    background: #E3F2FD;
    color: #1976D2;
}

.status.error {
    background: #FFEBEE;
    color: #C62828;
}

.version-info {
    margin-top: 8px;
    text-align: center;
    font-size: 11px;
    color: #777;
}

.version-info strong {
    color: #4CAF50;
    margin-left: 4px;
}

#result-view {
    margin-top: 15px;
}

.last-detection {
    text-align: center;
    color: #666;
    margin-top: 10px;
    font-size: 14px;
}
