/* Property of Sistema THEAD. All rights reserved. */
/* =====================================================================
   FOCUS — the one keyboard focus look, for the whole app.

   Dora, 14 Nov 2026: every control had its own focus (halos, glows,
   lighter oranges, blue, white, dashed, a ring inside a ring). All of it
   is gone. This file is the only place keyboard focus is drawn:

       the block highlight's look (tj-selection.js): a dashed orange line
       just outside the control, with a soft glow. One colour, one width,
       one gap. Nothing else changes on focus: no colour shift, no lift.

   The glow is a drop-shadow filter, not a box-shadow, so it adds to a
   control's own shadow instead of replacing it.

   Loaded LAST on every page, so it is the last word. Its !important only
   beats what is not ours: SweetAlert, Bootstrap and Blockly style focus
   with heavier selectors.

   Not here, on purpose:
   - the highlight on blocks (tj-selection.js, blockly-a11y.css): the dashed
     "this one" mark for taps and the keyboard, Dora's own design;
   - the gallery's drawing cursor (gallery.css), which shows where the
     next stroke goes.
   ===================================================================== */

:root {
    --tj-focus-color: var(--keyboard-nav-highlight);
    --tj-focus-width: 3px;
    --tj-focus-gap: 3px;
    --tj-focus-glow: drop-shadow(0 0 5px rgba(var(--keyboard-nav-highlight-rgb), 0.45));

    /* SweetAlert draws its own glow on focused buttons and fields. */
    --swal2-action-button-focus-box-shadow: none;
    --swal2-close-button-focus-box-shadow: none;
    --swal2-input-focus-box-shadow: none;
}

/* THE MARK. :focus-visible is the browser's own "keyboard, not a tap" test;
   .app-a11y-selected is where the app voice's keyboard cursor is. */
:focus-visible,
html.app-a11y-keyboard .app-a11y-selected {
    outline: var(--tj-focus-width) dashed var(--tj-focus-color) !important;
    outline-offset: var(--tj-focus-gap) !important;
    filter: var(--tj-focus-glow);
}

/* Bootstrap (the Information page) adds a blue glow on focus. */
.btn:focus, .btn-close:focus, .accordion-button:focus, .form-control:focus,
.form-select:focus, .form-check-input:focus, .navbar-toggler:focus {
    box-shadow: none !important;
}

/* WHERE THE MARK GOES, when the focused element is not what you see.
   Same mark, moved onto the visible shape. */

/* Home and the mode window: the button is the circle and its label; the
   mark follows the circle. */
.home-action:focus-visible,
html.app-a11y-keyboard .home-action.app-a11y-selected,
.home-mode-popup-option:focus-visible,
html.app-a11y-keyboard .home-mode-popup-option.app-a11y-selected {
    outline: none !important;
    filter: none;
}
/* The circle's thick orange rim is its resting look (approved) and stays.
   While that circle is the focused one, the rim would sit inside the dashed
   line and read as two orange rings, so it takes the circle's own fill for
   this state only: same geometry, one ring visible. */
.home-action:focus-visible .home-action-circle,
html.app-a11y-keyboard .home-action.app-a11y-selected .home-action-circle,
.home-mode-popup-option:focus-visible .home-mode-popup-circle,
html.app-a11y-keyboard .home-mode-popup-option.app-a11y-selected .home-mode-popup-circle {
    outline: var(--tj-focus-width) dashed var(--tj-focus-color) !important;
    outline-offset: var(--tj-focus-gap) !important;
    filter: var(--tj-focus-glow);
    border-color: var(--home-white);
}

/* Settings switches: the checkbox is hidden; the mark goes on the switch. */
.toggle-field input:focus-visible + .toggle-slider,
html.app-a11y-keyboard .toggle-field input.app-a11y-selected + .toggle-slider {
    outline: var(--tj-focus-width) dashed var(--tj-focus-color) !important;
    outline-offset: var(--tj-focus-gap) !important;
    filter: var(--tj-focus-glow);
}

/* The gallery canvas is clipped by its frame, so the mark goes on the frame. */
#galleryCanvas:focus-visible,
html.app-a11y-keyboard #galleryCanvas.app-a11y-selected {
    outline: none !important;
    filter: none;
}
.gallery-surface:has(#galleryCanvas:focus-visible),
html.app-a11y-keyboard .gallery-surface:has(#galleryCanvas.app-a11y-selected) {
    outline: var(--tj-focus-width) dashed var(--tj-focus-color) !important;
    outline-offset: var(--tj-focus-gap) !important;
    filter: var(--tj-focus-glow);
}

/* The program canvas: the host .tj-blockly-canvas gets the dashed line above;
   Blockly's own 6px solid ring is a second mark on the same surface, so it
   never draws. Blocks get the highlight, not a ring. Nothing inside Blockly's
   area gets this file's outline either. */
.injectionDiv:focus-visible,
.injectionDiv :focus-visible,
html.app-a11y-keyboard .injectionDiv .app-a11y-selected {
    outline: none !important;
    filter: none;
}

.tj-blockly-canvas .blocklyWorkspaceFocusRing {
    display: none !important;
}

/* Plain Tab lands on Blockly's workspace group (the app-voice cursor lands on
   the host, above). Either way the canvas's one mark is the host's dashed
   line, so the workspace's own focus moves the mark to the same frame. */
.tj-blockly-canvas:has(.blocklyWorkspace:focus-visible) {
    outline: var(--tj-focus-width) dashed var(--tj-focus-color) !important;
    outline-offset: var(--tj-focus-gap) !important;
    filter: var(--tj-focus-glow);
}

@media (forced-colors: active) {
    :focus-visible,
    html.app-a11y-keyboard .app-a11y-selected,
    .home-action:focus-visible .home-action-circle,
    .home-mode-popup-option:focus-visible .home-mode-popup-circle,
    .toggle-field input:focus-visible + .toggle-slider,
    .gallery-surface:has(#galleryCanvas:focus-visible),
    .tj-blockly-canvas:has(.blocklyWorkspace:focus-visible) {
        outline-color: Highlight !important;
        filter: none;
    }

    /* The moved marks, in the app voice's keyboard-cursor form.
     *
     * The block above only covers :focus-visible. Where the voice layer moves
     * the mark (a tile's circle, a switch's slider, the drawing surface), the
     * cursor is .app-a11y-selected instead, and those rules are more specific
     * than :focus-visible — so in Windows High Contrast they kept the orange
     * outline and the glow while the rest of the app went system-coloured. The
     * automated pass found it on Home, Settings and the gallery (16 Nov 2026);
     * the mark must be the system Highlight everywhere, with no glow. */
    html.app-a11y-keyboard .home-action.app-a11y-selected .home-action-circle,
    html.app-a11y-keyboard .home-mode-popup-option.app-a11y-selected .home-mode-popup-circle,
    html.app-a11y-keyboard .toggle-field input.app-a11y-selected + .toggle-slider,
    html.app-a11y-keyboard .gallery-surface:has(#galleryCanvas.app-a11y-selected) {
        outline-color: Highlight !important;
        filter: none;
    }
}
