body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(34, 197, 94, 0.25), transparent 30%),
        radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.28), transparent 35%),
        linear-gradient(135deg, #06111f, #111827 45%, #022c22);
    font-family: "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    color: #fff;
}

.counting-page {
    min-height: calc(100vh - 40px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.counting-main-card {
    width: min(1180px, 96vw);
    padding: 28px;
    border-radius: 34px;
    background: rgba(255, 255, 255, 0.13);
    border: 1px solid rgba(255, 255, 255, 0.28);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.counting-title-area { text-align: center; }
.counting-title-area h1 {
    margin: 0;
    font-size: clamp(28px, 4vw, 48px);
    font-weight: 800;
    letter-spacing: 1px;
    text-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
}
.counting-title-area p { margin: 8px 0 0; color: rgba(255,255,255,0.72); }

.language-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.language-row label { font-weight: 700; color: rgba(255,255,255,0.86); }
.language-select {
    min-width: 220px;
    border: 1px solid rgba(255,255,255,0.32);
    border-radius: 999px;
    padding: 10px 16px;
    color: #fff;
    background: rgba(15, 23, 42, 0.72);
    outline: none;
}
.language-select option { color: #111827; background: #fff; }

.counting-workspace {
    display: grid;
    grid-template-columns: minmax(300px, 450px) minmax(300px, 1fr);
    gap: 20px;
    align-items: start;
    justify-content: center;
}

.counting-camera-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.counting-camera-card {
    position: relative;
    width: min(420px, 82vw);
    aspect-ratio: 3 / 5;
    border-radius: 28px;
    overflow: hidden;
    background: #000;
    border: 1px solid rgba(255, 255, 255, 0.45);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.22), 0 24px 60px rgba(0,0,0,0.28);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

#countingCameraVideo,
#countingCapturedImage {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    background: #000;
    transform: translateZ(0);
}

#countingCapturedImage { display: none; }

.counting-guide {
    position: absolute;
    inset: 22px;
    z-index: 4;
    border-radius: 24px;
    border: 2px dashed rgba(255, 255, 255, 0.78);
    box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.08), inset 0 0 24px rgba(255, 255, 255, 0.08);
    pointer-events: none;
}

.counting-scan-overlay {
    position: absolute;
    inset: 22px;
    z-index: 30;
    display: none;
    border-radius: 24px;
    pointer-events: none;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(34, 197, 94, 0.08), rgba(34, 197, 94, 0.015));
    box-shadow: inset 0 0 32px rgba(34, 197, 94, 0.25), 0 0 30px rgba(34, 197, 94, 0.22);
    transform: translateZ(0);
}

.counting-scan-overlay.is-scanning { display: block; }

.counting-scan-overlay::before {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        to bottom,
        rgba(34, 197, 94, 0.00) 0px,
        rgba(34, 197, 94, 0.00) 18px,
        rgba(34, 197, 94, 0.10) 19px,
        rgba(34, 197, 94, 0.00) 21px
    );
    opacity: 0.85;
}

.counting-scan-line {
    position: absolute;
    left: -8%;
    right: -8%;
    top: 0;
    height: 52px;
    border-radius: 999px;
    background: transparent;
    animation: countingScan 1.45s ease-in-out infinite;
    will-change: top;
}

.counting-scan-line::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 18px;
    border-radius: 999px;
    background: linear-gradient(to bottom, rgba(187, 247, 208, 0), rgba(134, 239, 172, 0.95), rgba(34, 197, 94, 1), rgba(187, 247, 208, 0));
    box-shadow: 0 0 22px rgba(34, 197, 94, 1), 0 0 52px rgba(34, 197, 94, 0.78), 0 0 98px rgba(34, 197, 94, 0.44);
}

.counting-scan-line::after {
    content: "Recognizing...";
    position: absolute;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    padding: 5px 14px;
    border-radius: 999px;
    background: rgba(3, 7, 18, 0.72);
    border: 1px solid rgba(134, 239, 172, 0.70);
    color: #bbf7d0;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 0.04em;
    white-space: nowrap;
    text-shadow: 0 0 12px rgba(34, 197, 94, 0.95);
}

/* Use top animation instead of translateY(calc(min(...))) so iPhone/Safari can animate reliably. */
@keyframes countingScan {
    0% { top: 0; }
    50% { top: calc(100% - 52px); }
    100% { top: 0; }
}

/* During recognition, keep the green scanning line above result panels. */
.counting-camera-card.is-recognizing .counting-recognized-info {
    display: none !important;
}

.counting-floating-hint {
    position: absolute;
    left: 16px;
    right: 16px;
    top: 18px;
    z-index: 6;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(0,0,0,0.52);
    border: 1px solid rgba(255,255,255,0.25);
    color: rgba(255,255,255,0.92);
    text-align: center;
    font-weight: 700;
}

.counting-recognized-info {
    position: absolute;
    inset: 22px;
    z-index: 7;
    display: none;
    border-radius: 24px;
    overflow: auto;
    padding: 18px;
    background: rgba(3, 7, 18, 0.72);
    border: 1px solid rgba(255,255,255,0.28);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.counting-recognized-info.show { display: block; }
.counting-empty-info { color: rgba(255,255,255,0.72); text-align: center; padding-top: 40%; }

.counting-result-title { margin: 0 0 10px; font-size: 20px; }
.counting-result-list { display: flex; flex-direction: column; gap: 10px; }
.counting-result-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border-radius: 18px;
    background: rgba(255,255,255,0.11);
    border: 1px solid rgba(255,255,255,0.18);
}
.counting-item-name { font-weight: 800; }
.counting-item-qty { font-weight: 900; color: #bbf7d0; white-space: nowrap; }
.counting-item-note { grid-column: 1 / -1; color: rgba(255,255,255,0.68); font-size: 13px; }

.counting-media-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}
.counting-glass-btn,
.counting-small-btn {
    border: 1px solid rgba(255,255,255,0.28);
    border-radius: 999px;
    padding: 11px 18px;
    color: #fff;
    background: rgba(255,255,255,0.13);
    cursor: pointer;
    font-weight: 800;
    box-shadow: 0 12px 30px rgba(0,0,0,0.18);
}
.counting-primary-btn { background: linear-gradient(135deg, #16a34a, #22c55e); }
.counting-glass-btn:disabled,
.counting-small-btn:disabled { opacity: 0.48; cursor: not-allowed; }

.counting-info-section { display: flex; flex-direction: column; gap: 16px; }
.counting-info-card {
    border-radius: 26px;
    padding: 22px;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.22);
    box-shadow: 0 18px 45px rgba(0,0,0,0.18);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}
.counting-info-card h2 { margin: 0 0 12px; }
.counting-summary { color: rgba(255,255,255,0.78); line-height: 1.55; }
.counting-saved-pic { margin-top: 12px; color: rgba(255,255,255,0.76); word-break: break-word; }
.recent-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.counting-recent-results { color: rgba(255,255,255,0.76); }
.recent-row {
    display: grid;
    grid-template-columns: 74px 1fr;
    gap: 12px;
    padding: 10px 0;
    border-top: 1px solid rgba(255,255,255,0.15);
}
.recent-row img {
    width: 74px;
    height: 74px;
    object-fit: cover;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.22);
}
.recent-name { font-weight: 800; color: #fff; }
.recent-meta { font-size: 13px; color: rgba(255,255,255,0.68); }

@media (max-width: 840px) {
    .counting-main-card { width: 94vw; padding: 18px; border-radius: 26px; }
    .counting-workspace { grid-template-columns: 1fr; justify-items: center; }
    .counting-info-section { width: 100%; }
    .counting-camera-card { width: min(360px, 86vw); }
}

/* =========================================================
   Mobile glass fix for the two lower information cards
   ========================================================= */
.counting-info-card,
.counting-info-card h2,
.counting-summary,
.counting-saved-pic,
.counting-recent-results,
.recent-name,
.recent-meta {
    color: #0b2a5b;
    text-shadow: none;
}

.counting-info-card {
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.62), rgba(191, 219, 254, 0.34)),
        rgba(219, 234, 254, 0.32);
    border: 1px solid rgba(255, 255, 255, 0.56);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.72),
        0 18px 45px rgba(15, 23, 42, 0.20);
    backdrop-filter: blur(24px) saturate(145%);
    -webkit-backdrop-filter: blur(24px) saturate(145%);
}

.counting-info-card h2 {
    font-weight: 900;
    letter-spacing: 0.4px;
}

.counting-summary,
.counting-saved-pic,
.counting-recent-results {
    color: rgba(11, 42, 91, 0.88);
    font-weight: 650;
}

.recent-row {
    border-top: 1px solid rgba(11, 42, 91, 0.15);
}

.recent-name {
    color: #0b2a5b;
    font-weight: 900;
}

.recent-meta {
    color: rgba(11, 42, 91, 0.72);
}

@media (max-width: 840px) {
    .counting-info-card {
        background:
            linear-gradient(135deg, rgba(255, 255, 255, 0.58), rgba(147, 197, 253, 0.28)),
            rgba(219, 234, 254, 0.30);
        border: 1px solid rgba(255, 255, 255, 0.62);
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, 0.78),
            0 20px 48px rgba(15, 23, 42, 0.22);
        backdrop-filter: blur(26px) saturate(155%);
        -webkit-backdrop-filter: blur(26px) saturate(155%);
    }

    .counting-info-card h2,
    .counting-summary,
    .counting-saved-pic,
    .counting-recent-results,
    .recent-name,
    .recent-meta {
        color: #0b2a5b;
        text-shadow: none;
    }

    .counting-summary,
    .counting-saved-pic,
    .counting-recent-results {
        color: rgba(11, 42, 91, 0.90);
    }
}

/* =========================================================
   CountingRobot search / browse overlay
   ========================================================= */
.counting-search-panel,
.counting-search-results,
.counting-search-detail {
    color: #0b2a5b;
}

.counting-search-panel h3,
.counting-search-results h3,
.counting-search-detail h3 {
    margin: 0 0 12px;
    color: #0b2a5b;
    font-weight: 900;
}

.counting-search-help {
    margin: 0 0 14px;
    color: rgba(11, 42, 91, 0.78);
    font-weight: 650;
    line-height: 1.45;
}

.counting-search-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.counting-search-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 800;
    color: #0b2a5b;
}

.counting-search-field input {
    width: 100%;
    border: 1px solid rgba(11, 42, 91, 0.22);
    border-radius: 14px;
    padding: 11px 12px;
    color: #0b2a5b;
    background: rgba(255, 255, 255, 0.70);
    outline: none;
    font-weight: 750;
}

.counting-search-actions,
.counting-detail-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.counting-blue-btn,
.counting-back-btn {
    border: 1px solid rgba(11, 42, 91, 0.20);
    border-radius: 999px;
    padding: 10px 15px;
    color: #fff;
    background: linear-gradient(135deg, #1d4ed8, #2563eb);
    cursor: pointer;
    font-weight: 900;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.20);
}

.counting-back-btn {
    background: rgba(255, 255, 255, 0.72);
    color: #0b2a5b;
}

.counting-search-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.counting-search-row {
    display: grid;
    grid-template-columns: 78px 1fr;
    gap: 12px;
    align-items: center;
    width: 100%;
    border: 1px solid rgba(11, 42, 91, 0.14);
    border-radius: 18px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.62);
    cursor: pointer;
    text-align: left;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

.counting-search-row img {
    width: 78px;
    height: 78px;
    object-fit: cover;
    border-radius: 14px;
    border: 1px solid rgba(11, 42, 91, 0.18);
    background: rgba(255, 255, 255, 0.64);
}

.counting-search-row-title {
    color: #0b2a5b;
    font-weight: 950;
    line-height: 1.25;
}

.counting-search-row-summary,
.counting-search-row-date {
    margin-top: 4px;
    color: rgba(11, 42, 91, 0.76);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.35;
}

.counting-detail-image {
    width: 100%;
    max-height: 46vh;
    object-fit: contain;
    border-radius: 18px;
    border: 1px solid rgba(11, 42, 91, 0.16);
    background: rgba(255, 255, 255, 0.56);
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.18);
}

.counting-detail-items {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.counting-detail-item-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.66);
    border: 1px solid rgba(11, 42, 91, 0.13);
    color: #0b2a5b;
}

.counting-detail-item-name { font-weight: 950; }
.counting-detail-item-qty { font-weight: 950; white-space: nowrap; }
.counting-detail-item-note {
    grid-column: 1 / -1;
    color: rgba(11, 42, 91, 0.72);
    font-size: 13px;
    font-weight: 650;
}

.counting-recognized-info.search-mode {
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.62), rgba(191, 219, 254, 0.34)),
        rgba(219, 234, 254, 0.32);
    border: 1px solid rgba(255, 255, 255, 0.58);
    color: #0b2a5b;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.74),
        0 18px 45px rgba(15, 23, 42, 0.22);
}

.counting-recognized-info.search-mode::-webkit-scrollbar { width: 8px; }
.counting-recognized-info.search-mode::-webkit-scrollbar-track { background: rgba(255,255,255,0.35); border-radius: 999px; }
.counting-recognized-info.search-mode::-webkit-scrollbar-thumb { background: rgba(37, 99, 235, 0.55); border-radius: 999px; }


/* Translation waiting overlay: shown inside the small glass panel while search results are being translated. */
.counting-recognized-info.is-translating {
    position: absolute;
}

.counting-translate-overlay {
    position: absolute;
    inset: 0;
    z-index: 120;
    pointer-events: none;
    overflow: hidden;
    border-radius: inherit;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.20), rgba(15, 23, 42, 0.40));
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.counting-translate-moving-text {
    position: absolute;
    left: 18px;
    right: 18px;
    top: 0;
    text-align: center;
    padding: 8px 14px;
    border-radius: 999px;
    color: #bbf7d0;
    background: rgba(3, 7, 18, 0.78);
    border: 1px solid rgba(134, 239, 172, 0.72);
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.65), 0 0 52px rgba(34, 197, 94, 0.28);
    font-size: 15px;
    font-weight: 900;
    letter-spacing: 0.04em;
    text-shadow: 0 0 12px rgba(34, 197, 94, 0.95);
    animation: countingTranslateMove 1.45s ease-in-out infinite;
}

@keyframes countingTranslateMove {
    0% { top: 12px; }
    50% { top: calc(100% - 56px); }
    100% { top: 12px; }
}
