/* --- 全局样式和颜色变量 --- */
:root {
    --primary: #165DFF;
    --primary-light: #4080FF;
    --secondary: #36D399;
    --dark: #1E293B;
    --light: #F8FAFC;
    --gray: #94A3B8;
    --danger: #F87272;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --radius: 12px;
    --transition: all 0.3s ease;
}

/* --- 基础重置和页面布局 --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    background-color: #0F172A;
    color: var(--light);
    min-height: 100vh;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* --- 头部样式 --- */
header {
    width: 100%;
    max-width: 500px;
    text-align: center;
    margin-bottom: 20px;
    padding-top: 10px;
}

h1 {
    font-size: 24px;
    font-weight: 600;
    background: linear-gradient(90deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--gray);
    font-size: 14px;
    min-height: 20px; /* 防止文本变化时布局跳动 */
}

/* --- 扫描器容器和视频区域 --- */
#reader-container {
    width: 100%;
    max-width: 500px;
    height: 500px;
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    background-color: #000;
}

@media (max-width: 600px) {
    #reader-container {
        height: 400px;
    }
}

@media (max-width: 400px) {
    #reader-container {
        height: 300px;
    }
}

#reader {
    width: 100%;
    height: 100%;
    min-height: 250px;
    display: block;
    object-fit: cover;
    border: none;
}

#reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
}

/* --- 扫描动画覆盖层 --- */
.scan-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.scan-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 250px; /* 默认值 */
    height: 250px;
    transform: translate(-50%, -50%);
    border: 2px solid var(--secondary);
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(54, 211, 153, 0.5);
}

.scan-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--secondary);
    animation: scan 2s linear infinite;
}

@keyframes scan {
    0% { top: 0; }
    50% { top: calc(100% - 2px); }
    100% { top: 0; }
}

/* --- 控制按钮和下拉菜单 --- */
.controls {
    width: 100%;
    max-width: 500px;
    margin: 25px 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.camera-selector {
    position: relative;
}

#cameraSel {
    width: 100%;
    padding: 12px 15px;
    background-color: var(--dark);
    color: var(--light);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    font-size: 16px;
    appearance: none;
    cursor: pointer;
}

.select-arrow {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid var(--gray);
    pointer-events: none;
}

.btn-group {
    display: flex;
    gap: 15px;
}

button {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

button:disabled {
    background-color: #475569 !important;
    color: #64748B !important;
    cursor: not-allowed !important;
    border: none !important;
}

#btnStart {
    background-color: var(--primary);
    color: white;
}
#btnStart:hover:not(:disabled) {
    background-color: var(--primary-light);
}

#btnStop {
    background-color: var(--dark);
    color: var(--light);
    border: 1px solid rgba(255, 255, 255, 0.1);
}
#btnStop:hover:not(:disabled) {
    background-color: #334155;
}

.icon {
    width: 18px;
    height: 18px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.icon-play {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E");
}

.icon-stop {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23F8FAFC'%3E%3Cpath d='M6 6h12v12H6z'/%3E%3C/svg%3E");
}

/* --- 结果弹窗 (Modal) 样式 --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal-overlay.show {
    display: flex;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: linear-gradient(135deg, var(--dark), #1E293B);
    border-radius: 16px;
    padding: 0;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transform: translateY(50px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.modal-overlay.show .modal-content {
    transform: translateY(0);
    opacity: 1;
}

.modal-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

.modal-header h3 {
    color: var(--secondary);
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.close-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--gray);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    border-radius: 50%;
    transition: var(--transition);
}
.close-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--light);
}

.modal-body {
    padding: 24px;
}

.result-content {
    text-align: center;
    margin-bottom: 24px;
}

.result-icon {
    width: 60px;
    height: 60px;
    background-color: var(--secondary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    margin: 0 auto 16px;
}

.result-text {
    background-color: rgba(255, 255, 255, 0.05);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 16px;
    word-break: break-all;
    max-height: 120px;
    overflow-y: auto;
    color: var(--light);
    text-align: left;
}

.modal-actions {
    display: flex;
    gap: 12px;
}

.btn-primary, .btn-secondary {
    flex: 1;
    padding: 14px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    text-align: center;
}

.btn-primary {
    background-color: var(--secondary);
    color: var(--dark);
    font-weight: 600;
}
.btn-primary:hover {
    background-color: #2BB189;
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--light);
    border: 1px solid rgba(255, 255, 255, 0.2);
}
.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* --- 其他样式 --- */
.features {
    display: flex; justify-content: center; gap: 20px;
    margin-top: 30px; padding-bottom: 20px;
}
.feature {
    display: flex; flex-direction: column; align-items: center;
    gap: 5px; font-size: 12px; color: var(--gray);
}
.feature-icon {
    width: 24px; height: 24px; background-size: contain;
    background-repeat: no-repeat; background-position: center;
}
.icon-qr { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2394A3B8'%3E%3Cpath d='M3 11h8V3H3v8zm2-6h4v4H5V5zM3 21h8v-8H3v8zm2-6h4v4H5v-4zm8-12v8h8V3h-8zm6 6h-4V5h4v4zm-2 4h2v2h-2v-2zm-4 0h2v2h-2v-2zm-4 4h2v2H7v-2zm-4 0h2v2H3v-2zm12 2h-2v-2h2v2zm2-2h2v2h-2v-2zm2 2h2v2h-2v-2zm-4 0h2v2h-2v-2zm-8-2h2v2H7v-2z'/%3E%3C/svg%3E");}
.icon-barcode { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2394A3B8'%3E%3Cpath d='M2 6h2v12H2V6zm3 0h1v12H5V6zm2 0h2v12H7V6zm3 0h1v12h-1V6zm2 0h1v12h-1V6zm3 0h2v12h-2V6zm3 0h1v12h-1V6zm2 0h2v12h-2V6z'/%3E%3C/svg%3E");}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }