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

html {
    overflow-x: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    overflow-x: hidden;
}

.container {
    max-width: 800px;
    margin: 0 auto;
}

header {
    background: white;
    padding: 20px 30px;
    border-radius: 15px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    color: #333;
    font-size: 28px;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #f0f0f0;
    border-radius: 20px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ff4444;
    animation: pulse 2s infinite;
}

.connection-status.connected .status-dot {
    background: #44ff44;
}

.status-text {
    font-size: 14px;
    font-weight: 600;
    color: #666;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.print-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-top: 16px;
}

.print-hint {
    margin-top: 14px;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.5;
    color: #4a5568;
    background: #f7fafc;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.print-hint strong {
    color: #2d3748;
}

.btn.pulse {
    animation: pulseButton 1.5s infinite;
}

@keyframes pulseButton {
    0% {
        box-shadow: 0 4px 6px rgba(102, 126, 234, 0.3);
    }
    50% {
        box-shadow: 0 4px 20px rgba(102, 126, 234, 0.8);
        transform: scale(1.02);
    }
    100% {
        box-shadow: 0 4px 6px rgba(102, 126, 234, 0.3);
    }
}

.card {
    background: white;
    padding: 25px;
    border-radius: 15px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.card h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 20px;
    border-bottom: 2px solid #667eea;
    padding-bottom: 10px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    touch-action: manipulation;
}

.btn-large {
    padding: 16px 32px;
    font-size: 18px;
    width: 100%;
    justify-content: center;
}

.connection-actions {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.serial-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.serial-row .serial-btn {
    flex: 1 1 220px;
    min-width: 0;
}

.serial-label {
    font-size: 14px;
    font-weight: 600;
    color: #444;
}

.serial-baud {
    padding: 10px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    font-size: 15px;
    background: #fff;
}

.connection-help {
    background: #f0f7ff;
    border-left: 4px solid #667eea;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 8px;
}

.connection-help p {
    margin: 5px 0;
    color: #333;
}

.connection-help strong {
    color: #667eea;
}

.troubleshooting {
    margin-top: 20px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 15px;
    background: #f8f9fa;
}

.troubleshooting summary {
    cursor: pointer;
    font-weight: 600;
    color: #f59e0b;
    user-select: none;
    list-style: none;
}

.troubleshooting summary::-webkit-details-marker {
    display: none;
}

.troubleshooting summary:hover {
    color: #d97706;
}

.troubleshooting-content {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e2e8f0;
}

.troubleshooting-content h4 {
    margin-bottom: 10px;
    color: #333;
}

.troubleshooting-content ol {
    margin-left: 20px;
    line-height: 1.8;
}

.troubleshooting-content li {
    margin: 8px 0;
    color: #555;
}

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

.btn-icon {
    font-size: 20px;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

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

.btn-secondary:hover:not(:disabled) {
    background: #38a169;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(72, 187, 120, 0.3);
}

.btn-success {
    background: #38b2ac;
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #319795;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(56, 178, 172, 0.3);
}

.btn-print {
    background: #ed8936;
    color: white;
    width: 100%;
    justify-content: center;
    font-size: 18px;
    padding: 16px;
}

.btn-print:hover:not(:disabled) {
    background: #dd6b20;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(237, 137, 54, 0.3);
}

.printer-info {
    margin-top: 15px;
    padding: 15px;
    background: #f7fafc;
    border-radius: 8px;
    border-left: 4px solid #48bb78;
}

.camera-container {
    position: relative;
    width: 100%;
    max-width: 100%;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 15px;
}

#cameraPreview {
    width: 100%;
    height: auto;
    display: block;
}

.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.button-group .btn {
    flex: 1;
    min-width: 150px;
    justify-content: center;
}

.preview-container {
    position: relative;
    width: 100%;
    min-height: 300px;
    background: #f7fafc;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    border: 2px dashed #cbd5e0;
}

#previewCanvas {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.no-photo-text {
    color: #a0aec0;
    font-size: 18px;
    position: absolute;
}

.print-controls {
    margin-bottom: 20px;
}

.print-option-row .checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 600;
    color: #555;
}

.print-option-row input[type='checkbox'] {
    width: 18px;
    height: 18px;
    accent-color: #667eea;
}

.slider-group {
    margin-bottom: 15px;
}

.slider-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.slider-group input[type="range"] {
    width: calc(100% - 50px);
    margin-right: 10px;
    touch-action: pan-x;
}

.slider-group span {
    display: inline-block;
    min-width: 40px;
    text-align: right;
    font-weight: 600;
    color: #667eea;
}

.status-messages {
    position: fixed;
    top: 20px;
    right: 20px;
    max-width: 350px;
    z-index: 1000;
}

.status-message {
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease;
    border-left: 4px solid #667eea;
    transition: opacity 0.3s ease, transform 0.3s ease;
    cursor: default;
}

.status-message.success {
    border-left-color: #48bb78;
}

.status-message.error {
    border-left-color: #f56565;
}

.status-message.info {
    border-left-color: #4299e1;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

footer {
    text-align: center;
    color: white;
    padding: 20px;
    font-size: 14px;
}

@media (max-width: 768px) {
    .slider-group {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px;
    }

    .slider-group label {
        width: 100%;
        margin-bottom: 0;
    }

    .slider-group input[type="range"] {
        flex: 1;
        width: auto;
        min-width: 0;
        margin-right: 0;
    }

    .slider-group span {
        flex: 0 0 auto;
        min-width: 35px;
        text-align: right;
    }

    .connection-help ul {
        padding-left: 15px;
    }

    .connection-help ul ul {
        margin-left: 0 !important;
        max-width: 100%;
        box-sizing: border-box;
    }
}

@media (max-width: 600px) {
    body {
        padding: 10px;
    }
    
    header {
        flex-direction: column;
        gap: 15px;
        padding: 15px 20px;
    }

    h1 {
        font-size: 22px;
        text-align: center;
    }

    .connection-status {
        width: 100%;
        justify-content: center;
    }

    .button-group {
        flex-direction: column;
    }

    .button-group .btn {
        width: 100%;
        min-height: 48px; /* Touch-friendly height */
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .btn {
        min-height: 48px; /* Touch-friendly buttons */
        padding: 12px 20px;
        font-size: 16px;
    }
    
    .btn-large {
        min-height: 54px;
        font-size: 17px;
    }

    .status-messages {
        left: 10px;
        right: 10px;
        max-width: none;
        bottom: 10px;
        top: auto;
    }
    
    .message {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    .card {
        padding: 20px;
    }
    
    .camera-container video {
        max-height: 300px; /* Limit height on mobile */
    }
    
    .print-actions {
        flex-direction: column;
        width: 100%;
    }
    
    .print-actions .btn {
        width: 100%;
    }
    
    .control-group label {
        font-size: 14px;
    }
    
    input[type="range"] {
        width: 100%;
    }
    
    select {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 44px;
    }
    
    .serial-row {
        flex-direction: column;
        align-items: stretch !important;
    }
    
    .serial-label {
        text-align: left;
        margin-bottom: 5px;
    }
    
    .serial-baud {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .serial-btn {
        width: 100% !important;
    }
}

/* Additional touch improvements */
@media (hover: none) and (pointer: coarse) {
    /* Touch device specific styles */
    .btn:active {
        transform: scale(0.98);
    }
    
    select, input, button {
        font-size: 16px; /* Prevent iOS zoom */
    }
}

/* Android Chrome prompt banner */
.android-prompt-banner {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    background: #fff8e1;
    border: 2px solid #f59e0b;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
}

.android-prompt-icon {
    font-size: 32px;
    flex-shrink: 0;
    line-height: 1;
}

.android-prompt-body {
    flex: 1;
}

.android-prompt-body strong {
    display: block;
    font-size: 16px;
    color: #92400e;
    margin-bottom: 6px;
}

.android-prompt-body p {
    font-size: 14px;
    color: #78350f;
    margin-bottom: 12px;
    line-height: 1.5;
}

.btn-chrome {
    background: #4285f4;
    color: white;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
    touch-action: manipulation;
    border: none;
    cursor: pointer;
    width: 100%;
    justify-content: center;
    box-sizing: border-box;
}

.btn-chrome:hover, .btn-chrome:active {
    background: #3367d6;
    color: white;
}

.android-prompt-alt {
    background: #f0f9ff;
    border-left: 4px solid #0ea5e9;
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 14px;
    color: #0c4a6e;
    margin-bottom: 20px;
    line-height: 1.5;
}

#androidChromePrompt {
    margin-bottom: 0;
}

/* Camera permission row */
.camera-permission-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}

.camera-permission-row .btn {
    flex: 0 1 auto;
}

.camera-permission-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    background: #edf2f7;
    color: #4a5568;
    border-left: 4px solid #cbd5e0;
}

.camera-permission-status.granted {
    background: #f0fff4;
    color: #22543d;
    border-left-color: #48bb78;
}

.camera-permission-status.denied {
    background: #fff5f5;
    color: #742a2a;
    border-left-color: #f56565;
}

.camera-permission-status.prompt {
    background: #fffaf0;
    color: #7b341e;
    border-left-color: #ed8936;
}

/* Modal (print preview) */
.modal[aria-hidden="true"] {
    display: none;
}

.modal[aria-hidden="false"] {
    display: block;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.modal-card {
    position: relative;
    width: min(920px, calc(100% - 24px));
    margin: 12px auto;
    background: white;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    overflow: hidden;
}

.modal-header, .modal-footer {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-footer {
    border-top: 1px solid #e2e8f0;
    border-bottom: none;
}

.modal-header h3 {
    font-size: 16px;
    color: #2d3748;
}

.modal-body {
    padding: 14px 16px;
}

.modal-preview-wrap {
    width: 100%;
    background: #f7fafc;
    border: 2px dashed #cbd5e0;
    border-radius: 10px;
    padding: 10px;
    display: flex;
    justify-content: center;
    overflow: auto;
    max-height: 70vh;
}

#processedPreviewCanvas {
    max-width: 100%;
    height: auto;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    image-rendering: pixelated;
}

.modal-hint {
    margin-top: 10px;
    font-size: 13px;
    color: #4a5568;
    line-height: 1.4;
}

.modal-close {
    padding: 10px 14px;
    font-size: 14px;
}
