/* JET-ED Visualiser page styles. Site-wide rules remain in ../../css/style.css. */

#focus-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.58);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 900;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

#focus-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.visualiser-main-content {
    max-width: 1100px;
}

.visualiser-intro {
    width: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 28px;
    margin-bottom: 24px;
}

.visualiser-intro h2 {
    margin: 0 0 8px;
    font-family: 'Lexend', 'Inter', sans-serif;
    font-size: 1.6rem;
    line-height: 1.25;
    color: #111827;
}

.visualiser-intro p {
    margin: 0;
    max-width: 720px;
    color: #4b5563;
}

.visualiser-tips,
.onboarding-tips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.visualiser-tips {
    justify-content: flex-end;
}

.visualiser-tips span,
.onboarding-tips span {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 5px 10px;
    box-sizing: border-box;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    background: #f8fafc;
    color: #475569;
    font-size: 0.82rem;
    font-weight: 600;
}

.scanner-container {
    position: relative;
    width: 100%;
    height: min(72vh, 760px);
    min-height: 500px;
    overflow: hidden;
    border: 1px solid #1e293b;
    border-radius: 16px;
    background: #020617;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.14);
    perspective: 1000px;
    isolation: isolate;
}

.scanner-container:fullscreen {
    width: 100%;
    height: 100vh;
    min-height: 0;
    border: 0;
    border-radius: 0;
}

.scanner-topbar {
    position: absolute;
    inset: 0 0 auto;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 62px;
    padding: 10px 14px;
    box-sizing: border-box;
    color: #fff;
    background: linear-gradient(to bottom, rgba(2, 6, 23, 0.82), rgba(2, 6, 23, 0));
}

.scanner-context {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.scanner-live-indicator {
    width: 9px;
    height: 9px;
    flex: 0 0 auto;
    border-radius: 999px;
    background: #22c55e;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.16);
}

.icon-button {
    min-width: 44px;
    min-height: 44px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.58);
    color: #fff;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background-color 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.icon-button:hover {
    background: rgba(15, 23, 42, 0.86);
    transform: scale(1.03);
}

.camera-onboarding,
.camera-message {
    position: absolute;
    inset: 62px 24px 24px;
    z-index: 25;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px;
    box-sizing: border-box;
    overflow: auto;
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #fff;
    text-align: center;
}

/* Respect the native [hidden] attribute even if site-wide CSS changes display rules. */
[hidden] {
    display: none !important;
}

.camera-onboarding[hidden],
.camera-message[hidden],
#main-controls[hidden],
#transform-controls[hidden],
#camera-status-overlay[hidden],
#scan-tick-overlay[hidden],
#scan-cross-overlay[hidden],
#dynamic-tooltip[hidden] {
    display: none !important;
}

.onboarding-icon,
.camera-message-icon {
    width: 56px;
    height: 56px;
    display: grid;
    place-items: center;
    margin-bottom: 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.10);
    font-size: 1.8rem;
}

.camera-onboarding h3,
.camera-message h3 {
    margin: 0 0 8px;
    font-family: 'Lexend', 'Inter', sans-serif;
    font-size: 1.45rem;
    line-height: 1.3;
}

.camera-onboarding p,
.camera-message p {
    max-width: 720px;
    margin: 0;
    color: #cbd5e1;
    line-height: 1.65;
}

.onboarding-tips {
    justify-content: center;
    margin: 20px 0;
}

.onboarding-tips span {
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
}

.onboarding-actions,
.message-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 12px;
}

.privacy-note {
    max-width: 700px !important;
    margin-top: 18px !important;
    color: #94a3b8 !important;
    font-size: 0.78rem;
}

.controls {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 16px;
    z-index: 20;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px;
    box-sizing: border-box;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.84);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.camera-picker {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 190px;
    color: #e2e8f0;
    font-size: 0.78rem;
    font-weight: 700;
}

.camera-picker select {
    width: 100%;
    min-height: 44px;
    box-sizing: border-box;
    margin: 0;
    padding: 9px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #111827;
    cursor: pointer;
    font: inherit;
}

.controls .btn,
.onboarding-actions .btn,
.message-actions .btn {
    min-height: 44px;
}

.transform-controls {
    position: absolute;
    left: 16px;
    right: 16px;
    top: 72px;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px;
    box-sizing: border-box;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.84);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.slider-group {
    min-width: 145px;
    flex: 1 1 145px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: #e2e8f0;
    font-size: 0.78rem;
    font-weight: 700;
}

.slider-group label {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.slider-group output {
    color: #94a3b8;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.slider-group input[type='range'] {
    width: 100%;
    min-height: 28px;
    margin: 0;
    accent-color: #60a5fa;
    cursor: pointer;
}

.scanner-container .btn-secondary {
    background: #475569;
    color: #fff;
}

.scanner-container .btn-secondary:hover {
    background: #334155;
}

.transform-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: center;
    transition: transform 0.1s ease-out;
    touch-action: none;
}

#camera-feed,
#capture-canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #020617;
    object-fit: contain;
}

#camera-feed {
    object-position: center;
}

#capture-canvas {
    display: none;
    object-position: center;
}

/* Keep the live/captured media and the interactive word layer in the same coordinate space. */
#transform-wrapper > #camera-feed,
#transform-wrapper > #capture-canvas,
#transform-wrapper > #interactive-layer {
    position: absolute;
    inset: 0;
}

#transform-wrapper > #interactive-layer {
    width: 100%;
    height: 100%;
}

#interactive-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.scanned-word {
    position: absolute;
    display: block;
    padding: 0;
    box-sizing: border-box;
    border: 1px solid transparent;
    border-radius: 4px;
    background: rgba(253, 224, 71, 0.24);
    pointer-events: auto;
    cursor: pointer;
    outline: none;
    transition: background-color 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.scanned-word:hover {
    background: rgba(96, 165, 250, 0.28);
    border-color: rgba(59, 130, 246, 0.55);
}

.scanned-word.defining {
    background: rgba(59, 130, 246, 0.30);
    border-color: #60a5fa;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.45);
    z-index: 901;
}

.scanned-word:focus-visible {
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px #2563eb;
    z-index: 902;
}

.camera-status-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 18;
    max-width: min(80%, 420px);
    transform: translate(-50%, -50%);
    padding: 12px 16px;
    box-sizing: border-box;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.90);
    color: #fff;
    text-align: center;
    font-weight: 700;
}

.scan-tick-overlay,
.scan-cross-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 21;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 200px;
    max-width: min(86%, 380px);
    padding: 24px;
    box-sizing: border-box;
    transform: translate(-50%, -50%);
    border-radius: 18px;
    background: rgba(15, 23, 42, 0.92);
    color: #fff;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
}

.scan-tick-overlay {
    font-size: 2.4rem;
}

.scan-cross-overlay {
    font-size: 1rem;
}

.scan-cross-overlay .error-symbol {
    font-size: 2.2rem;
}

.scan-cross-overlay small {
    color: #cbd5e1;
    line-height: 1.5;
}

.scanner-status {
    width: 100%;
    margin-top: 14px;
    padding: 14px 16px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #f8fafc;
    color: #475569;
}

.scanner-status strong {
    color: #111827;
}

.how-it-works {
    width: 100%;
    margin-top: 40px;
}

.how-it-works h2 {
    margin-bottom: 18px;
}

.how-it-works-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.how-it-works-grid > div {
    padding: 18px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
}

.how-it-works-grid span {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    margin-bottom: 10px;
    border-radius: 999px;
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 800;
}

.how-it-works-grid strong {
    display: block;
    color: #111827;
}

.how-it-works-grid p {
    margin: 6px 0 0;
    font-size: 0.92rem;
}

.definition-tooltip {
    /* Fixed positioning keeps the popup anchored to the viewport in normal mode
       and to the fullscreen viewport when the scanner container is fullscreen. */
    position: fixed;
    z-index: 1000;
    width: min(360px, calc(100vw - 24px));
    max-height: min(60vh, 420px);
    overflow: auto;
    padding: 16px;
    box-sizing: border-box;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #fff;
    color: #334155;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.22);
}

.definition-tooltip .word-title {
    display: block;
    margin-bottom: 2px;
    font-family: 'Lexend', 'Inter', sans-serif;
    font-size: 1.15rem;
    color: #0f172a;
}

.definition-tooltip .definition-pos {
    color: #64748b;
    font-size: 0.85em;
}

.definition-tooltip .definition-text {
    margin-top: 6px;
    line-height: 1.55;
}

.definition-tooltip .definition-message {
    margin-top: 6px;
    color: #475569;
    line-height: 1.5;
}

.definition-tooltip .autocorrect-notice {
    display: block;
    margin-bottom: 8px;
    color: #64748b;
    font-size: 0.8rem;
}

.definition-tooltip .loading {
    color: #64748b;
    font-style: italic;
}

.definition-tooltip .retry-btn {
    width: 100%;
    min-height: 40px;
    margin-top: 12px;
    padding: 8px 10px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: #eff6ff;
    color: #1d4ed8;
    font: inherit;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}

.definition-tooltip .retry-btn:hover,
.definition-tooltip .retry-btn:focus-visible {
    background: #dbeafe;
}

.definition-tooltip .retry-count {
    float: right;
    color: #64748b;
    font-weight: 600;
}

.btn:focus-visible,
select:focus-visible,
input:focus-visible,
.icon-button:focus-visible {
    outline: 3px solid rgba(59, 130, 246, 0.35);
    outline-offset: 2px;
}

.btn[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

@media (max-width: 900px) {
    .visualiser-intro {
        flex-direction: column;
    }

    .visualiser-tips {
        justify-content: flex-start;
    }

    .how-it-works-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .scanner-container {
        height: 72svh;
        height: 72vh;
        min-height: 420px;
    }

    .camera-onboarding,
    .camera-message {
        inset: 60px 12px 12px;
        padding: 22px 16px;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .camera-picker {
        min-width: 0;
    }

    .transform-controls {
        top: 66px;
        max-height: calc(100% - 145px);
        overflow: auto;
    }

    .slider-group {
        min-width: calc(50% - 5px);
        flex-basis: calc(50% - 5px);
    }

    .scanner-status {
        flex-direction: column;
        align-items: flex-start;
    }

    .onboarding-actions,
    .message-actions {
        width: 100%;
    }

    .onboarding-actions .btn,
    .message-actions .btn {
        width: 100%;
    }
}

@media (max-width: 520px) {
    .scanner-container {
        min-height: 390px;
        border-radius: 12px;
    }

    .scanner-topbar {
        padding-inline: 10px;
    }

    .scanner-context {
        font-size: 0.82rem;
    }

    .transform-controls {
        left: 10px;
        right: 10px;
    }

    .slider-group {
        min-width: 100%;
        flex-basis: 100%;
    }

    .definition-tooltip {
        max-height: 55vh;
    }
}

@media (prefers-reduced-motion: reduce) {
    #focus-overlay,
    .icon-button,
    .scanned-word,
    .transform-wrapper {
        transition: none;
    }
}

/* Camera switching + mobile interaction improvements. */
.camera-facing-label {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 3px 9px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    font-size: 0.75rem;
    font-weight: 700;
}

#camera-feed.front-facing {
    transform: scaleX(-1);
}

.camera-flip-button {
    white-space: nowrap;
}

.transform-wrapper {
    touch-action: none;
    overscroll-behavior: contain;
}

.scanner-container:focus-within {
    outline: none;
}

.scanner-container.focus-mode {
    position: fixed;
    inset: 0;
    z-index: 2000;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-sizing: border-box;
}

body.visualiser-focus-mode {
    overflow: hidden;
}

@media (max-width: 768px) {
    .scanner-context {
        flex-wrap: wrap;
        row-gap: 4px;
        max-width: calc(100% - 56px);
    }

    .camera-facing-label {
        font-size: 0.7rem;
    }

    .controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: stretch;
        gap: 8px;
    }

    .controls .camera-flip-button,
    .controls #btn-scan,
    .controls #btn-retake {
        width: 100%;
    }

    .controls .camera-picker {
        grid-column: 1 / -1;
        min-width: 0;
    }

    .camera-picker select {
        min-height: 46px;
    }
}

@media (max-width: 520px) {
    .camera-facing-label {
        width: 100%;
        justify-content: center;
    }

    .controls {
        grid-template-columns: 1fr;
    }

    .controls .camera-picker {
        grid-column: auto;
    }

    .camera-flip-button {
        min-height: 48px;
    }

    .scanner-container.focus-mode .controls {
        left: 10px;
        right: 10px;
        bottom: max(10px, env(safe-area-inset-bottom));
    }
}

@media (max-width: 768px) {
    /* Front/rear switching is the primary mobile camera interaction. */
    .camera-picker {
        display: none !important;
    }
}
