/* Front Keypad, Back Keypad and Joysticks: one page at a time, chosen like the joystick outputs. */
#hid-webapp .extra-inputs-tabs {
    display: flex;
    width: fit-content;
    margin: 0 auto 1rem;
    padding: 0.1875rem;
    border-radius: 0.5rem;
    background: var(--menu-well);
}

#hid-webapp .extra-inputs-tab {
    padding: 0.4rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: transparent;
}

#hid-webapp .extra-inputs-tab:hover,
#hid-webapp .extra-inputs-tab:active {
    transform: none;
    filter: none;
}

#hid-webapp .extra-inputs-tab[aria-selected="true"] {
    color: #fff;
    background: var(--accent-color);
}

#hid-webapp .extra-inputs-tab[hidden],
#hid-webapp .extra-inputs-panel[hidden] {
    display: none;
}

/* One page at a time leaves room, so a keypad or the joysticks are drawn larger, all of a piece;
   the section is wide enough for a keypad at that size. */
#hid-webapp #keyboard-section {
    max-width: 54rem;
}

#hid-webapp .extra-inputs-panel {
    zoom: 1.35;
}

#hid-webapp .extra-inputs-board {
    max-width: 40rem;
    margin: 0 auto;
}

/* The left and right joysticks side by side. */
#hid-webapp .joystick-cards {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
}

#hid-webapp .joystick-card {
    flex: 0 0 18rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.4rem;
    box-sizing: border-box;
    padding: 0.85rem 1.25rem;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 0.875rem;
}

#hid-webapp.dark-mode .joystick-card {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.08);
}

#hid-webapp .joystick-title {
    font-family: "Orbitron", sans-serif;
    font-size: 1rem;
    color: var(--accent-color);
    margin: 0;
    letter-spacing: 0.05em;
}

#hid-webapp .joystick-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

#hid-webapp .joystick-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #444;
}

#hid-webapp.dark-mode .joystick-label {
    color: #ccc;
}

#hid-webapp .joystick-output {
    display: flex;
    padding: 0.1875rem;
    border-radius: 0.5rem;
    background: var(--menu-well);
}

#hid-webapp .joystick-output-option {
    padding: 0.3rem 0.6rem;
    border-radius: 0.375rem;
    font-size: 0.85rem;
    color: var(--text-primary);
    background: transparent;
}

#hid-webapp .joystick-output-option:hover,
#hid-webapp .joystick-output-option:active {
    transform: none;
    filter: none;
}

#hid-webapp .joystick-output-option[aria-pressed="true"] {
    color: #fff;
    background: var(--accent-color);
}

#hid-webapp .joystick-art-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* The joystick seen from above, with a key at each side in Keys mode. */
#hid-webapp .joystick-art {
    position: relative;
    flex: 0 0 9.75rem;
    aspect-ratio: 1;
    --stick-base: #e5e7eb;
    --stick-line: #9ca3af;
    --stick-cap: #6b7280;
}

#hid-webapp.dark-mode .joystick-art {
    --stick-base: #2a2f3a;
    --stick-line: #4b5563;
    --stick-cap: #9ca3af;
}

#hid-webapp .joystick-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.joystick-base {
    fill: var(--stick-base);
    stroke: var(--stick-line);
    stroke-width: 2;
}

/* The dead zone: a red dashed outline over everything else, the cap and its click included. */
#hid-webapp .joystick-overlay {
    pointer-events: none;
}

.joystick-dead-zone {
    fill: none;
    stroke: rgba(255, 0, 0, 0.5);
    stroke-width: 1.5;
    stroke-dasharray: 3 2;
}

.joystick-axis {
    stroke: var(--stick-line);
    stroke-width: 1.5;
}

.joystick-arrow {
    fill: var(--accent-color);
    font-size: 10px;
    font-weight: 700;
}

.joystick-cap {
    fill: var(--stick-cap);
    stroke: var(--stick-line);
    stroke-width: 2;
}

/* Keys mode: the keys show what each side presses, so the stick's axis arrows go. */
#hid-webapp .joystick-art.keys .joystick-arrow {
    display: none;
}

#hid-webapp .joystick-key {
    position: absolute;
    width: 2.5rem;
    height: 1.75rem;
    padding: 0 0.2rem;
    overflow: hidden;
    border-radius: 0.45rem;
    font-size: 0.65rem;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #fff;
    background-color: #6b7280;
}

#hid-webapp .joystick-key:hover {
    background-color: #4b5563;
    filter: none;
}

#hid-webapp .joystick-key.active-btn {
    background-color: var(--accent-color);
}

#hid-webapp.dark-mode .joystick-key:not(.active-btn) {
    background-color: #374151;
    color: #e5e7eb;
}

/* The click on the stick's cap, sized with the drawing (the cap is a quarter of it). Like a side's
   key: the accent while it presses something, grey when empty. */
#hid-webapp .joystick-click {
    position: absolute;
    left: 36%;
    top: 36%;
    width: 28%;
    height: 28%;
    padding: 0;
    overflow: hidden;
    border: none;
    border-radius: 50%;
    font-size: 0.75rem;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #fff;
    background-color: #6b7280;
}

#hid-webapp .joystick-click:hover {
    background-color: #4b5563;
    filter: none;
}

#hid-webapp .joystick-click.active-btn {
    background-color: var(--accent-color);
}

#hid-webapp.dark-mode .joystick-click:not(.active-btn) {
    background-color: #374151;
    color: #e5e7eb;
}

/* Centred by offsets, not transforms, which the button hover lift replaces. */
#hid-webapp .joystick-key[data-direction="up"],
#hid-webapp .joystick-key[data-direction="down"] {
    left: calc(50% - 1.25rem);
}

#hid-webapp .joystick-key[data-direction="left"],
#hid-webapp .joystick-key[data-direction="right"] {
    top: calc(50% - 0.875rem);
}

#hid-webapp .joystick-key[data-direction="up"] {
    top: 0;
}

#hid-webapp .joystick-key[data-direction="down"] {
    bottom: 0;
}

#hid-webapp .joystick-key[data-direction="left"] {
    left: 0;
}

#hid-webapp .joystick-key[data-direction="right"] {
    right: 0;
}

#hid-webapp .joystick-inverts {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

#hid-webapp .joystick-invert {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
}

/* Rotation and Dead Zone as one tight pair at the bottom of the card. */
#hid-webapp .joystick-values {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

/* Label, box, unit and slider on one line; one column width each, so the sliders line up. */
#hid-webapp .joystick-value-row {
    display: grid;
    grid-template-columns: 4.6rem 3.4rem 0.8rem minmax(0, 1fr);
    align-items: center;
    gap: 0.35rem;
}

#hid-webapp .joystick-value-row .sensor-number-input {
    width: 100%;
    box-sizing: border-box;
}

#hid-webapp .joystick-unit {
    font-size: 0.85rem;
}

#hid-webapp .joystick-slider {
    width: 100%;
    min-width: 0;
}

#hid-webapp .board-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

#hid-webapp .board-title {
    font-family: "Orbitron", sans-serif;
    font-size: 1.3rem;
    color: var(--accent-color);
    margin: 0;
    letter-spacing: 0.05em;
}

#hid-webapp .board-title-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#hid-webapp .hide-unused-switch {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

#hid-webapp .clear-board-btn {
    font-size: 0.875rem;
    padding: 0.25rem 0.65rem;
}

#hid-webapp .button-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.5rem;
    max-width: 40rem;
    margin: 0 auto;
}

#hid-webapp .input-btn {
    width: 100%;
    aspect-ratio: 1;
    padding: 0;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    background-color: #6b7280;
    border: 2px solid transparent;
    position: relative;
    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        transform 0.15s ease,
        box-shadow 0.2s ease;
    transform: none;
}

#hid-webapp .input-btn .btn-index {
    position: absolute;
    top: 4px;
    left: 5px;
    font-size: 0.6rem;
    font-weight: 600;
    opacity: 0.7;
    line-height: 1;
}

#hid-webapp .input-btn:hover {
    background-color: #4b5563;
    transform: translateY(-2px) scale(1.08);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    filter: none;
}

#hid-webapp .input-btn:active {
    transform: translateY(1px) scale(0.96);
    box-shadow: none;
}

#hid-webapp .input-btn.active-btn {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.3);
}

#hid-webapp.dark-mode .input-btn {
    background-color: #374151;
    color: #e5e7eb;
}

#hid-webapp.dark-mode .input-btn:hover {
    background-color: #4b5563;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

#hid-webapp.dark-mode .input-btn.active-btn {
    background-color: var(--accent-color);
    color: #fff;
}

#hid-webapp .btn-binding {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.65rem;
    font-weight: 600;
    text-align: center;
    width: 90%;
    pointer-events: none;
    line-height: 1.4;
}

/* Tooltip with the full binding above a key. */
#hid-webapp .input-btn[data-binding]:hover::after {
    content: attr(data-binding);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background-color: #1f2937;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    padding: 0.3125rem 0.625rem;
    border-radius: 0.375rem;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#hid-webapp .input-btn[data-binding]:hover::before {
    content: "";
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 0.375rem solid transparent;
    border-top-color: #1f2937;
    pointer-events: none;
    z-index: 100;
}

#hid-webapp .key-binding-modal {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    background-color: #fff;
    border-radius: 0.75rem;
    padding: 2rem 2.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    text-align: center;
    outline: none;
}

#hid-webapp.dark-mode .key-binding-modal {
    background-color: #1a1d24;
}

#key-binding-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

#key-binding-preview {
    min-height: 2rem;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent-color);
    letter-spacing: 0.03em;
}

#hid-webapp .key-binding-controller-switch {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* The controller drawing at its viewBox's aspect; key-binding-modal.js places the buttons on it. */
#key-binding-pad {
    position: relative;
    width: 26rem;
    aspect-ratio: 460 / 390;
    --pad-body: #f9fafb;
    --pad-line: #d1d5db;
    --pad-shade: #e5e7eb;
    --pad-label: #fff;
}

#hid-webapp.dark-mode #key-binding-pad {
    --pad-body: #20242c;
    --pad-line: #3a3f4a;
    --pad-shade: #2a2f3a;
    --pad-label: #e5e7eb;
}

#hid-webapp .key-binding-pad-art {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.key-binding-pad-shadow {
    fill: var(--pad-shade);
}

.key-binding-pad-body {
    fill: var(--pad-body);
    stroke: var(--pad-line);
    stroke-width: 3;
}

.key-binding-pad-seam {
    stroke: var(--pad-shade);
    stroke-width: 2;
}

.key-binding-pad-well {
    fill: none;
    stroke: var(--pad-line);
    stroke-width: 3;
}

#hid-webapp .key-binding-pad-btn {
    position: absolute;
    padding: 0;
    border: none;
    font-size: 0.65rem;
    line-height: 1;
    color: var(--pad-label);
    background-color: #6b7280;
}

#hid-webapp .key-binding-pad-btn:hover {
    background-color: #4b5563;
    filter: none;
}

#hid-webapp .key-binding-pad-btn[aria-pressed="true"] {
    background-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.35);
    --pad-label: #fff;
}

#hid-webapp.dark-mode .key-binding-pad-btn {
    background-color: #374151;
}

#hid-webapp.dark-mode .key-binding-pad-btn:hover {
    background-color: #4b5563;
}

#hid-webapp.dark-mode .key-binding-pad-btn[aria-pressed="true"] {
    background-color: var(--accent-color);
}

/* A D-pad button hides its name behind an arrow pointing --turn from up. */
#hid-webapp .key-binding-pad-btn.pad-arrow {
    color: transparent;
    overflow: hidden;
    border-radius: 25%;
}

#hid-webapp .key-binding-pad-btn.pad-arrow::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    border-left: 0.3rem solid transparent;
    border-right: 0.3rem solid transparent;
    border-bottom: 0.4rem solid var(--pad-label);
    transform: translate(-50%, -50%) rotate(var(--turn));
}

#key-binding-actions {
    display: flex;
    gap: 0.75rem;
}

#key-binding-confirm:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
