.cs-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.65);
    display: flex; align-items: center; justify-content: center;
    z-index: 9000;
}

.cs-modal {
    background: #1e1e2e;
    color: #cdd6f4;
    border-radius: 12px;
    width: min(960px, 96vw);
    max-height: 90vh;
    display: flex; flex-direction: column;
    overflow: auto;
    box-shadow: 0 8px 40px rgba(0,0,0,.6);
}

.cs-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 20px;
    background: #181825;
    font-size: 1.1rem; font-weight: 600;
    border-bottom: 1px solid #313244;
}

.cs-close {
    background: none; border: none; color: #6c7086;
    font-size: 1.2rem; cursor: pointer; padding: 4px 8px;
}
.cs-close:hover { color: #f38ba8; }

.cs-body {
    display: flex; flex: 1 0 auto; overflow: hidden;
}

/* ── Left panel ── */
.cs-left {
    flex: 1.4; display: flex; flex-direction: column;
    background: #11111b; padding: 16px; gap: 12px;
}

.cs-video-wrap {
    position: relative; flex: 1;
    background: #000; border-radius: 8px; overflow: hidden;
}

.cs-video-wrap video {
    width: 100%; height: 100%; object-fit: cover;
}

.cs-overlay-canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    pointer-events: none;
}

/* 90°/270° handled by canvas rendering; 180° is a simple CSS flip */
.cs-video-wrap video.cs-rot-180 { transform: rotate(180deg); }

/* Portrait mode: container reshapes to 9:16 and canvas draws the rotated feed */
.cs-video-wrap.cs-portrait {
    flex: 0 1 auto;
    align-self: center;
    aspect-ratio: 9 / 16;
    height: min(55vh, 480px);
    width: auto;
}

.cs-rotate-btn {
    position: absolute; top: 8px; right: 8px;
    background: rgba(30,30,46,.75); border: 1px solid #45475a; border-radius: 6px;
    color: #89b4fa; font-size: 1rem; padding: 4px 10px;
    cursor: pointer; z-index: 10; line-height: 1.4;
}
.cs-rotate-btn:hover { background: rgba(69,71,90,.9); }

.cs-captured {
    background: #181825; border-radius: 8px;
    padding: 10px; text-align: center;
}

.cs-captured-label {
    font-size: .75rem; color: #6c7086; margin-bottom: 6px;
}

.cs-captured img {
    max-height: 160px; border-radius: 4px;
    border: 1px solid #313244;
}

/* ── Right panel ── */
.cs-right {
    width: 280px; display: flex; flex-direction: column;
    padding: 20px 16px; gap: 16px;
    border-left: 1px solid #313244;
}

.cs-hint  { color: #6c7086; font-size: .9rem; }
.cs-warn  { color: #f38ba8; font-size: .9rem; }

.cs-result { display: flex; flex-direction: column; gap: 6px; }

.cs-card-name { font-size: 1.05rem; font-weight: 600; color: #cba6f7; }
.cs-card-set  { font-size: .85rem; color: #6c7086; }
.cs-card-id   { font-size: .75rem; color: #45475a; font-family: monospace; }

.cs-ocr-panel {
    margin-top: 8px;
    padding: 8px 10px;
    border: 1px solid #313244;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.cs-ocr-row           { display: flex; gap: 8px; align-items: baseline; font-size: .75rem; }
.cs-ocr-label         { color: #45475a; min-width: 58px; flex-shrink: 0; }
.cs-ocr-value         { color: #cdd6f4; font-family: monospace; word-break: break-all; }
.cs-ocr-section-label { font-size: .7rem; color: #45475a; text-transform: uppercase; letter-spacing: .04em; }
.cs-ocr-preview       { display: block; width: 100%; border-radius: 3px; margin: 3px 0; image-rendering: pixelated; }
.cs-ocr-text          { font-size: .75rem; color: #cdd6f4; font-family: monospace; word-break: break-all; min-height: 1em; }

/* Debug breakdown */
.cs-debug-panel {
    border-top: 1px solid #313244;
    background: #11111b;
    padding: 16px;
}

.cs-debug-title {
    color: #cdd6f4;
    font-size: .95rem;
    font-weight: 600;
}

.cs-debug-meta {
    color: #6c7086;
    font-family: monospace;
    font-size: .76rem;
    margin-top: 4px;
}

.cs-debug-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-top: 12px;
}

.cs-debug-figure {
    min-width: 0;
}

.cs-debug-label {
    color: #89b4fa;
    font-size: .78rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.cs-debug-img {
    display: block;
    width: 100%;
    height: auto;
    border: 1px solid #313244;
    border-radius: 6px;
    background: #000;
}

.cs-debug-card-wrap {
    position: relative;
    width: 100%;
}

.cs-debug-ocr-box {
    position: absolute;
    border: 2px solid #f9e2af;
    background: rgba(249,226,175,.12);
    box-sizing: border-box;
    pointer-events: none;
}

.cs-debug-ocr-box span {
    position: absolute;
    left: 0;
    bottom: 100%;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: rgba(17,17,27,.88);
    color: #f9e2af;
    font-size: .7rem;
    font-family: monospace;
    padding: 2px 4px;
}

/* ── Camera settings panel ──────────────────────────────────────────────── */
.cs-cam-settings  { margin-top: 8px; }

.cs-cam-toggle {
    background: #313244; border: 1px solid #45475a; border-radius: 6px;
    color: #89b4fa; padding: 5px 12px; font-size: .8rem;
    cursor: pointer; width: 100%; text-align: left;
}
.cs-cam-toggle:hover { background: #45475a; }

.cs-cam-grid {
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 5px 10px;
    margin-top: 8px;
    align-items: center;
}

.cs-cam-label { font-size: .75rem; color: #6c7086; text-align: right; white-space: nowrap; }

.cs-cam-range-wrap { display: flex; align-items: center; gap: 6px; min-width: 0; }
.cs-cam-slider     { flex: 1; min-width: 0; accent-color: #89b4fa; cursor: pointer; }
.cs-cam-value      { font-size: .72rem; color: #cdd6f4; min-width: 38px; text-align: right; font-family: monospace; }

.cs-cam-select {
    background: #313244; border: 1px solid #45475a; border-radius: 4px;
    color: #cdd6f4; padding: 3px 6px; font-size: .8rem; cursor: pointer; width: 100%;
}
.cs-cam-select:focus { outline: 1px solid #89b4fa; }

.cs-cam-reset {
    background: transparent; border: 1px solid #45475a; border-radius: 6px;
    color: #cdd6f4; padding: 5px 10px; font-size: .78rem;
    cursor: pointer; width: 100%; margin-top: 8px;
}
.cs-cam-reset:hover { background: #313244; color: #89b4fa; }

.cs-badge {
    display: inline-block; background: #313244;
    border-radius: 4px; padding: 2px 8px;
    font-size: .75rem; color: #89dceb;
    width: fit-content;
}

.cs-qty-row {
    display: flex; align-items: center; gap: 12px;
    font-size: .95rem;
}

.cs-qty-row label { color: #6c7086; }

.cs-qty-row button {
    width: 30px; height: 30px;
    background: #313244; border: none; border-radius: 6px;
    color: #cdd6f4; font-size: 1.1rem; cursor: pointer;
}
.cs-qty-row button:hover { background: #45475a; }
.cs-qty-row span { min-width: 24px; text-align: center; font-weight: 600; }

.cs-actions {
    margin-top: auto; display: flex; flex-direction: column; gap: 10px;
}

.cs-btn-scan {
    background: #89b4fa; color: #1e1e2e;
    border: none; border-radius: 8px;
    padding: 10px; font-size: .95rem; font-weight: 600;
    cursor: pointer;
}
.cs-btn-scan:disabled { opacity: .5; cursor: default; }
.cs-btn-scan:not(:disabled):hover { background: #74c7ec; }

.cs-btn-next {
    background: #313244; color: #cdd6f4;
    border: none; border-radius: 8px;
    padding: 10px; font-size: .9rem; cursor: pointer;
}
.cs-btn-next:hover { background: #45475a; }

.cs-btn-add {
    background: #a6e3a1; color: #1e1e2e;
    border: none; border-radius: 8px;
    padding: 10px; font-size: .95rem; font-weight: 600;
    cursor: pointer;
}
.cs-btn-add:hover { background: #94e2d5; }

@media (max-width: 760px) {
    .cs-body {
        flex-direction: column;
    }

    .cs-right {
        width: auto;
        border-left: none;
        border-top: 1px solid #313244;
    }

    .cs-debug-grid {
        grid-template-columns: 1fr;
    }
}
