/* Wider than a config section so the plot and the controls sit side by side. */
#hid-webapp #accel-section {
    position: relative;
    width: 100%;
    max-width: 72rem;
}

#hid-webapp:has(#tab-acceleration.active) #main-container {
    display: flex;
    flex-direction: column;
}

/* Top-anchored, so switching curves does not move the plot. */
#hid-webapp #tab-acceleration.active {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    flex: 1 1 auto;
}

#hid-webapp .accel-layout {
    display: flex;
    gap: 3.33rem;
    align-items: stretch;
    flex-wrap: wrap;
}

#hid-webapp .accel-controls-col {
    flex: 0 1 21rem;
    min-width: 16rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

#hid-webapp .accel-preview-col {
    order: -1;
    flex: 1 1 32rem;
    min-width: 20rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

#hid-webapp .accel-stat-row {
    padding: 0.5rem 1rem 0.95rem;
    border-bottom: 1px solid rgba(128, 128, 128, 0.08);
}

#hid-webapp .accel-stat-row:last-child {
    border-bottom: none;
}

#hid-webapp .accel-stat-row--inactive {
    opacity: 0.4;
    pointer-events: none;
}

#hid-webapp .accel-stat-top {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.5rem;
}

#hid-webapp .accel-label {
    font-size: 0.82rem;
    font-weight: 400;
    opacity: 0.75;
    color: var(--text-primary);
    margin: 0;
    min-width: 0;
}

#hid-webapp .accel-stat-row .accel-number-input {
    width: 4.5rem;
    height: auto;
    padding: 0.1rem 0.35rem;
    border: 1px solid transparent;
    border-radius: 0.3rem;
    background: transparent;
    color: var(--accent-color);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: right;
    box-sizing: border-box;
    transition:
        border-color 0.15s,
        background 0.15s;
    -moz-appearance: textfield;
}

#hid-webapp .accel-stat-row .accel-number-input::-webkit-outer-spin-button,
#hid-webapp .accel-stat-row .accel-number-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#hid-webapp .accel-stat-row .accel-number-input:hover {
    border-color: rgba(128, 128, 128, 0.25);
}

#hid-webapp .accel-stat-row .accel-number-input:focus {
    border-color: var(--accent-color);
    background: rgba(128, 128, 128, 0.07);
    outline: none;
}

/* The inline margin keeps the thumb inside the card at both ends. */
#hid-webapp .accel-slider.settings-slider {
    display: block;
    width: calc(100% - 1.25rem);
    margin: 0.45rem 0.625rem 0.25rem;
}

/* Curve "Off" has no parameters: hide the empty card. */
#hid-webapp .accel-card:has(.accel-card-body:empty) {
    display: none;
}

#hid-webapp .accel-card-body.accel-body--animating {
    height: var(--accel-body-h, auto);
    overflow: hidden;
    transition:
        height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.22s ease;
}

#hid-webapp .accel-card-body.accel-body--fade-out {
    opacity: 0;
}

/* Keeps the emptied card in flow until its height has animated to zero. */
#hid-webapp .accel-card.accel-card--collapsing:has(.accel-card-body:empty) {
    display: block;
}

#hid-webapp .accel-card.accel-card--entering {
    animation: accelCardEnter 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes accelCardEnter {
    from {
        opacity: 0;
        transform: translateY(-6px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

#hid-webapp #accel-canvas {
    transition: opacity 0.22s ease;
}

/* Hides the jump between two curve formulas. */
#hid-webapp #accel-canvas.accel-canvas--swapping {
    opacity: 0.15;
}

#hid-webapp .accel-curve-row {
    display: flex;
    gap: 0.6rem;
    align-items: stretch;
    position: relative;
}

#hid-webapp .accel-curve-row .accel-curve-select {
    flex: 1 1 auto;
    min-width: 0;
}

#hid-webapp .accel-curve-select {
    position: relative;
    min-width: 8rem;
}

/* Same height as the info and Reset buttons beside it. */
#hid-webapp .accel-curve-select__btn {
    width: 100%;
    box-sizing: border-box;
    height: 2.875rem;
    padding: 0 1rem;
    border-radius: 0.5rem;
    background-color: var(--surface-input);
    border: 1px solid var(--border-input);
    color: var(--text-primary);
    font: inherit;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-align: left;
}

#hid-webapp .accel-curve-select__btn:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 1px;
}

/* A select, not an action: no button bounce. */
#hid-webapp .accel-curve-select__btn:hover,
#hid-webapp .accel-curve-select__btn:active {
    transform: none;
    filter: none;
}

#hid-webapp .accel-curve-select__btn-label {
    flex: 1 1 auto;
    min-width: 0;
}

#hid-webapp .accel-curve-select__btn-icon {
    flex: 0 0 auto;
    width: 2.1rem;
    height: 1.25rem;
    color: var(--accent-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#hid-webapp .accel-curve-select__btn-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

#hid-webapp .accel-curve-select__caret {
    flex: 0 0 auto;
    width: 0.6rem;
    height: 0.38rem;
    opacity: 0.6;
    transition: transform 0.15s;
}

#hid-webapp .accel-curve-select__btn[aria-expanded="true"] .accel-curve-select__caret {
    transform: rotate(180deg);
}

#hid-webapp .accel-curve-select__panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    margin: 0;
    padding: 0.25rem;
    list-style: none;
    background: var(--surface-input);
    border: 1px solid var(--border-input);
    border-radius: 0.5rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 100;
}

#hid-webapp .accel-curve-select__panel [role="option"] {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.3rem;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    outline: none;
    user-select: none;
}

#hid-webapp .accel-curve-select__panel [role="option"]:focus,
#hid-webapp .accel-curve-select__panel [role="option"]:hover {
    background: rgba(128, 128, 128, 0.12);
}

#hid-webapp .accel-curve-select__panel [role="option"][aria-selected="true"] {
    color: var(--accent-color);
}

#hid-webapp .accel-curve-select__opt-label {
    flex: 1 1 auto;
    min-width: 0;
}

#hid-webapp .accel-curve-select__opt-icon {
    flex: 0 0 auto;
    width: 2.1rem;
    height: 1.25rem;
    color: var(--accent-color);
    display: block;
}

#hid-webapp #accel-reset-btn {
    flex: 0 0 auto;
    box-sizing: border-box;
    width: auto;
    height: 2.875rem;
    padding: 0 1.25rem;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1;
    color: #fff;
    box-shadow: none;
    white-space: nowrap;
}

#hid-webapp .accel-info-btn {
    flex: 0 0 auto;
    box-sizing: border-box;
    width: 2.875rem;
    height: 2.875rem;
    padding: 0;
    border-radius: 0.5rem;
    background-color: var(--surface-input);
    border: 1px solid var(--border-input);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition:
        color 0.15s ease,
        border-color 0.15s ease,
        background-color 0.15s ease;
}

#hid-webapp .accel-info-btn svg {
    width: 1.2rem;
    height: 1.2rem;
    display: block;
}

#hid-webapp .accel-info-btn:hover {
    color: var(--accent-color);
    border-color: rgba(26, 115, 232, 0.45);
}

#hid-webapp .accel-info-btn:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 1px;
}

#hid-webapp .accel-info-btn.is-active,
#hid-webapp .accel-info-btn[aria-expanded="true"] {
    color: var(--accent-color);
    border-color: var(--accent-color);
}

#hid-webapp .accel-info-modal {
    max-width: 52rem;
    width: min(52rem, 94vw);
}

#hid-webapp .accel-info-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    color: inherit;
}

#hid-webapp .accel-info-list {
    margin: 0;
    display: grid;
    grid-template-columns: 6rem 1fr;
    font-size: 0.88rem;
    line-height: 1.5;
}

#hid-webapp .accel-info-list dt,
#hid-webapp .accel-info-list dd {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid rgba(128, 128, 128, 0.08);
    margin: 0;
}

#hid-webapp .accel-info-list dt {
    color: var(--text-primary);
    font-weight: 700;
}

#hid-webapp .accel-info-list dd {
    color: var(--text-secondary);
}

#hid-webapp .accel-info-list dt:nth-last-of-type(1),
#hid-webapp .accel-info-list dd:nth-last-of-type(1) {
    border-bottom: none;
}

#hid-webapp .accel-info-list dd sup {
    font-size: 0.68rem;
    line-height: 0;
    margin-left: 0.05rem;
}

#hid-webapp .accel-info-foot {
    font-size: 0.78rem;
    color: var(--text-muted);
    padding-top: 0.5rem;
    border-top: 1px dashed rgba(128, 128, 128, 0.25);
    font-style: italic;
}

#hid-webapp .accel-canvas-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    min-height: 320px;
    box-sizing: border-box;
    border: 1px solid rgba(128, 128, 128, 0.2);
    border-radius: 0.625rem;
    background: rgba(128, 128, 128, 0.04);
    overflow: hidden;
}

#hid-webapp .accel-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#hid-webapp .accel-readouts {
    display: flex;
    gap: 1.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

#hid-webapp .accel-readouts span {
    color: var(--text-secondary);
    font-weight: 600;
}

#hid-webapp .accel-history-toggle {
    position: absolute;
    right: 0.65rem;
    bottom: 0.65rem;
    z-index: 2;
    box-sizing: border-box;
    height: 1.85rem;
    padding: 0 0.7rem 0 0.55rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border-radius: 999px;
    background-color: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(128, 128, 128, 0.35);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition:
        background-color 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease,
        box-shadow 0.15s ease;
}

#hid-webapp.dark-mode .accel-history-toggle {
    background-color: rgba(20, 24, 32, 0.55);
}

/* A toggle, not an action: no button bounce. */
#hid-webapp .accel-history-toggle:hover {
    transform: none;
    filter: none;
    border-color: rgba(var(--accent-rgb), 0.6);
    color: var(--accent-color);
}

#hid-webapp .accel-history-toggle:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 1px;
}

#hid-webapp .accel-history-toggle__icon {
    width: 0.95rem;
    height: 0.7rem;
    flex: 0 0 auto;
    opacity: 0.85;
}

#hid-webapp .accel-history-toggle__label {
    white-space: nowrap;
}

#hid-webapp .accel-history-toggle__dot {
    width: 0.42rem;
    height: 0.42rem;
    border-radius: 50%;
    background-color: var(--text-muted);
    box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0);
    transition:
        background-color 0.15s ease,
        box-shadow 0.25s ease;
    flex: 0 0 auto;
}

#hid-webapp .accel-history-toggle[aria-pressed="true"] {
    background-color: rgba(var(--accent-rgb), 0.18);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

#hid-webapp .accel-history-toggle[aria-pressed="true"] .accel-history-toggle__dot {
    background-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.22);
    animation: accelHistDotPulse 1.8s ease-in-out infinite;
}

@keyframes accelHistDotPulse {
    0%,
    100% {
        box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.22);
    }
    50% {
        box-shadow: 0 0 0 5px rgba(var(--accent-rgb), 0.1);
    }
}

/* Spans both columns and collapses by animating its single grid row between 0fr and 1fr. */
#hid-webapp .accel-history-section {
    display: grid;
    grid-template-rows: 0fr;
    transition:
        grid-template-rows 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        margin-top 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 0;
    width: 100%;
}

#hid-webapp .accel-history-section[aria-hidden="false"] {
    grid-template-rows: 1fr;
    margin-top: 1.5rem;
}

#hid-webapp .accel-history-section__inner {
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    opacity: 0;
    transition: opacity 0.18s ease;
    transition-delay: 0s;
}

/* Fades in once the row has started to open. */
#hid-webapp .accel-history-section[aria-hidden="false"] .accel-history-section__inner {
    opacity: 1;
    transition-delay: 0.12s;
}

#hid-webapp .accel-canvas-wrap--history {
    aspect-ratio: 12 / 5;
    min-height: 220px;
}

#hid-webapp .accel-history-bar {
    position: absolute;
    top: 0.6rem;
    right: 0.85rem;
    z-index: 2;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 1.2rem;
    pointer-events: none;
    text-shadow: 0 0 4px rgba(255, 255, 255, 0.7);
}

#hid-webapp.dark-mode .accel-history-bar {
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.45);
}

#hid-webapp .accel-history-readout {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    white-space: nowrap;
}

#hid-webapp .accel-history-readout span {
    color: var(--accent-color);
    font-weight: 600;
    margin-left: 0.35rem;
}

/* Sits after the chart title the canvas draws; the chart moves it once it knows the title width. */
#hid-webapp .accel-history-pause {
    position: absolute;
    top: 0.32rem;
    left: 15rem;
    z-index: 2;
    box-sizing: border-box;
    height: 1.45rem;
    padding: 0 0.55rem 0 0.45rem;
    display: inline-flex;
    align-items: center;
    gap: 0.32rem;
    border-radius: 999px;
    background-color: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(128, 128, 128, 0.35);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition:
        background-color 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease;
}

#hid-webapp.dark-mode .accel-history-pause {
    background-color: rgba(20, 24, 32, 0.55);
}

#hid-webapp .accel-history-pause:hover {
    transform: none;
    filter: none;
    border-color: rgba(var(--accent-rgb), 0.6);
    color: var(--accent-color);
}

#hid-webapp .accel-history-pause:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 1px;
}

#hid-webapp .accel-history-pause__icon {
    width: 0.8rem;
    height: 0.8rem;
    flex: 0 0 auto;
    opacity: 0.9;
}

#hid-webapp .accel-history-pause__label {
    white-space: nowrap;
}

#hid-webapp .accel-history-pause[aria-pressed="true"] {
    background-color: rgba(245, 158, 11, 0.18);
    border-color: rgba(245, 158, 11, 0.8);
    color: rgb(245, 158, 11);
}

#hid-webapp .accel-history-pause:not([aria-pressed="true"]) .accel-history-pause__icon-play,
#hid-webapp .accel-history-pause[aria-pressed="true"] .accel-history-pause__icon-pause {
    display: none;
}

/* Report 15 is unreadable: everything but Rotation (report 2) is inert and dimmed. */
#hid-webapp #accel-section.accel-gated [inert] {
    opacity: 0.4;
}

#hid-webapp #accel-section.accel-gated::after {
    content: "Update firmware to unlock Acceleration";
    position: absolute;
    bottom: 0.5rem;
    right: 0.75rem;
    font-weight: 600;
    color: var(--accent-color);
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    #hid-webapp .accel-info-btn,
    #hid-webapp .accel-history-section,
    #hid-webapp .accel-history-section__inner {
        transition: none;
    }
}
