:root {
    --ear-accent: #c9593f;
    --ear-accent-hover: #c9593f;
    --ear-accent-error: #ce0707;
    --ear-bg: rgba(11, 10, 19, 0.9);
    --ear-bg-dark: rgba(11, 10, 19, 0.75);
    --ear-text: #eaeaea;
    --ear-text-dim: #d2cfe1;
    --ear-track-bg: #3a3944;
    --ear-divider: #4a4955;
    --ear-shadow: rgba(0, 0, 0, 0.35);
    --ear-thumb: #e0dee6;
}

.ear-player {
    width: 100%;
    margin-top: 2px;
    padding: 7px 8px 7px 16px;
    background: var(--ear-bg);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: relative;
    box-shadow: 0 1px 4px var(--ear-shadow);
    overflow: hidden;
}

.ear-player::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: -2px;
    width: 8px;
    background: var(--ear-accent);
    border-radius: 90% 0 0 90%;
}

.ear-top-row {
    display: flex;
    align-items: center;
    gap: 3px;
    min-height: 22px;
}

.ear-play-btn {
    background: none;
    border: none;
    color: var(--ear-accent);
    font-size: 14px;
    cursor: pointer;
    padding: 0;
    margin: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: filter 0.15s, transform 0.1s;
}

.ear-play-btn:hover {
    color: var(--ear-accent-hover);
    transform: scale(1.1);
}

.ear-play-btn:active {
    transform: scale(0.92);
}

.ear-track-name {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    color: var(--ear-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
    min-width: 0; /* <--- */
}

.ear-volume-container {
    display: flex;
    align-items: center;
    gap: 3px;
    background: var(--ear-bg-dark);
    padding: 2px 7px;
    border-radius: 10px;
    height: 22px;
    flex-shrink: 0;
}

.ear-volume-icon {
    font-size: 9px;
    color: var(--ear-text-dim);
    width: 16px;
    text-align: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s;
}

.ear-volume-icon:hover {
    color: var(--ear-text);
}

.ear-volume-slider {
    width: 50px;
    max-width: 50px;
    flex-grow: 0;
    height: 3px;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    cursor: pointer;
    border: none;
    border-radius: 2px;
    background: linear-gradient(
    to right,
    var(--ear-accent) var(--ear-vol-pct, 50%),
    var(--ear-track-bg) var(--ear-vol-pct, 50%)
    );
    margin: 0;
    padding: 0;
    flex-shrink: 0;
}

.ear-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    background: var(--ear-thumb);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 0 2px var(--ear-shadow);
}

.ear-volume-slider::-moz-range-thumb {
    width: 10px;
    height: 10px;
    background: var(--ear-thumb);
    border-radius: 50%;
    border: none;
    cursor: pointer;
}

.ear-volume-slider::-moz-range-track {
    height: 3px;
    border: none;
    background: transparent;
}

.ear-vol-text {
    font-size: 9px;
    font-family: monospace;
    color: var(--ear-text-dim);
    min-width: 24px;
    text-align: right;
    flex-shrink: 0;
    user-select: none;
}

.ear-close-btn {
    background: none;
    border: none;
    color: var(--ear-accent);
    cursor: pointer;
    font-size: 14px;
    padding: 0 3px;
    margin-left: auto; /* <--- */
    flex-shrink: 0; /* <--- */
    transition: color 0.15s, transform 0.1s;
    opacity: 0.7;
}

.ear-close-btn:hover {
    color: var(--ear-accent-error);
    opacity: 1;
    transform: scale(1.15);
}

.ear-close-btn:active {
    transform: scale(0.9);
}

.ear-bottom-row {
    display: flex;
    align-items: center;
    gap: 0px;
    min-height: 16px;
}

.ear-time {
    font-size: 10px;
    font-family: monospace;
    color: var(--ear-text-dim);
    min-width: 28px;
    user-select: none;
    flex-shrink: 0;
    line-height: 1;
}

.ear-time.right {
    text-align: right;
    cursor: pointer;
    transition: color 0.15s;
}

.ear-time.right:hover {
    color: var(--ear-text);
}

.ear-seek-track {
    flex: 1;
    height: 4px;
    background: var(--ear-track-bg);
    border-radius: 2px;
    position: relative;
    cursor: pointer;
}

.ear-seek-fill {
    height: 100%;
    background: var(--ear-accent);
    border-radius: 2px;
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.ear-seek-handle {
    position: absolute;
    top: 50%;
    width: 8px;
    height: 8px;
    background: var(--ear-accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    z-index: 1;
    box-shadow: 0 0 3px var(--ear-shadow);
    transition: transform 0.1s;
}

.ear-seek-track:hover .ear-seek-handle {
    transform: translate(-50%, -50%) scale(1.25);
}

.ear-seek-handle:active,
.ear-seek-handle.ear-dragging {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.4);
    transition: none;
}

.ear-controls-group {
    display: flex;
    align-items: center;
    gap: 0px;
    margin-left: 2px;
    flex-shrink: 0;
}

.ear-transport-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ear-text-dim);
    font-size: 10px;
    padding: 1px;
    margin: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
    flex-shrink: 0;
}

.ear-transport-btn:hover {
    color: var(--ear-text);
}

.ear-transport-btn:active {
    transform: scale(0.88);
}

.ear-transport-btn.ear-active {
    color: var(--ear-accent);
}

.ear-divider {
    width: 1px;
    height: 10px;
    background: var(--ear-divider);
    margin: 0 3px;
    flex-shrink: 0;
}

/* Playlist group header — owns the PLAYLIST volume stage. */
.ear-pl-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    margin-top: 6px;
    padding: 4px 8px 4px 10px;
    background: var(--ear-bg-dark);
    border-radius: 6px 6px 0 0;
}

/* Single accent rail for the whole group: ONE element drawn by the header,
   its height (--ear-group-h, set by syncGroupHeaders) reaches from the header
   top to the bottom of the last track. One element = one width, no seams and
   no per-track mismatch. Tips curve to the right like the block corners. */
.ear-pl-header::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: var(--ear-group-h, 100%);
    background: var(--ear-accent);
    /* Tips curve to the RIGHT over the block's 6px corner: horizontal radius
       spans the full 3px width, vertical matches the corner. */
    border-top-right-radius: 3px 6px;
    border-bottom-right-radius: 3px 6px;
    pointer-events: none;
    transition: height 0.25s ease;
}

.ear-pl-header.ear-collapsed {
    border-radius: 6px;
}

.ear-pl-name {
    flex: 1;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ear-text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 5px;
}

.ear-pl-header .ear-volume-slider {
    width: 70px;
    max-width: 70px;
}

.ear-pl-header .ear-controls-group {
    flex-shrink: 0;
}

.ear-pl-header .ear-transport-btn {
    font-size: 11px;
    width: 18px;
    height: 18px;
}

.ear-pl-header .ear-collapse-btn i {
    transition: transform 0.15s;
}

.ear-pl-header .ear-collapse-btn:hover i {
    transform: scale(1.15);
}

/* Foundry's own row spacing would break the continuous group block — collapse
   it so the header's bottom edge and the tracks' top edges absorb each other. */
#playlists .currently-playing .playlist-sounds {
    gap: 0 !important;
    row-gap: 0 !important;
    padding-block: 0 !important;
}

#playlists .currently-playing .sound:has(> .ear-player.ear-grouped) {
    margin: 0;
    padding: 0;
}

/* Collapse/expand animation state (set by animateGroupCollapse). */
#playlists .currently-playing .sound.ear-animating {
    overflow: hidden;
    transition: height 0.25s ease, opacity 0.2s ease;
}

/* Indent grouped tracks: no own top radius, no shadow, no vertical gaps —
   they read as one continuous body under the header. The indent equals the
   rail width (3px), so the track box starts flush at the rail's right edge.
   width:auto cancels the base 100% so nothing overflows the right edge. */
.ear-player.ear-grouped {
    width: auto;
    margin: 0 0 0 3px;
    padding-left: 12px;
    border-radius: 0;
    box-shadow: none;
}

/* No own accent notch — the group rail is drawn by the header. */
.ear-player.ear-grouped::before {
    display: none;
}

/* Last track of the group closes the block (class set by syncGroupHeaders —
   ":last-child" is unusable, .sound siblings of different playlists mix). */
.ear-player.ear-group-end {
    border-radius: 0 0 6px 6px;
}

/* Read-only player (non-GM players): show only volume + progress + time. */
.ear-player.ear-readonly {
    padding-left: 14px;
}

.ear-player.ear-readonly .ear-track-name {
    margin-left: 2px;
}

.ear-player.ear-readonly .ear-seek-track {
    cursor: default;
}

.ear-player.ear-readonly .ear-seek-track:hover .ear-seek-handle {
    transform: translate(-50%, -50%);
}

.ear-player.ear-readonly .ear-time.right {
    cursor: pointer;
}

/* Preview button — 16×16 like the other small controls in .sound-controls. */
/* Preview button — uses Foundry's `.inline-control` mixin, overrides only active state. */
[data-ear-preview][data-ear-preview].ear-active {
    --button-text-color: var(--ear-accent) !important;
}

/* Force horizontal row for sound controls — override Foundry's 32px flex constraint. */
html body #sidebar #playlists .playlist .sound .sound-controls {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    flex: unset !important;
    gap: 0 3px;
}

/* Radio point controls inside AmbientSoundConfig. */
.ear-radio-config {
    margin-block-start: var(--spacer-12);
    min-inline-size: 0;
    border-color: var(--color-fieldset-border, var(--color-border));
}

.ear-radio-config > legend {
    display: flex;
    align-items: center;
    gap: var(--spacer-4);
}

.ear-radio-config .ear-radio-icon-button,
.ear-radio-config .ear-radio-power,
.ear-radio-config .ear-radio-track-play {
    --button-size: 2rem;
    inline-size: var(--button-size);
    block-size: var(--button-size);
    flex: 0 0 var(--button-size);
    display: inline-grid;
    place-items: center;
    padding: 0;
}

.ear-radio-config button:focus-visible,
.ear-radio-config input:focus-visible,
.ear-radio-config select:focus-visible {
    outline: 2px solid var(--input-focus-outline-color, var(--color-warm-1));
    outline-offset: 2px;
}

.ear-radio-config button:disabled {
    cursor: wait;
    opacity: 0.55;
}

.ear-radio-console {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--spacer-8);
    min-inline-size: 0;
    padding: var(--spacer-8);
    margin-block: var(--spacer-8) var(--spacer-12);
    border: 1px solid var(--color-fieldset-border, var(--color-border));
    border-radius: 4px;
    background: var(--color-cool-5-50, var(--background));
}

.ear-radio-transport {
    display: flex;
    align-items: center;
    gap: var(--spacer-2);
}

.ear-radio-config .ear-radio-power.active {
    --button-text-color: var(--color-warm-1);
    color: var(--color-warm-1);
}

.ear-radio-now {
    display: flex;
    flex-direction: column;
    min-inline-size: 0;
    line-height: 1.15;
}

.ear-radio-status {
    color: var(--color-form-hint, var(--color-light-5));
    font-size: var(--font-size-11, 0.6875rem);
}

.ear-radio-now-name {
    overflow: hidden;
    color: var(--color-form-label, var(--color-light-3));
    font-size: var(--font-size-13);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ear-radio-time,
.ear-radio-track-duration {
    font-variant-numeric: tabular-nums;
}

.ear-radio-time {
    flex: none;
    color: var(--color-form-hint, var(--color-light-5));
    font-size: var(--font-size-12);
    white-space: nowrap;
}

.ear-radio-tracks {
    max-block-size: 15rem;
    min-inline-size: 0;
    overflow: auto;
    border: 1px solid var(--color-fieldset-border, var(--color-border));
    border-radius: 4px;
    background: var(--background);
    scrollbar-color: var(--color-warm-1) transparent;
    scrollbar-width: thin;
}

.ear-radio-track {
    display: grid;
    grid-template-columns: 2rem minmax(7rem, 1fr) 3.5rem 5.25rem;
    align-items: center;
    gap: var(--spacer-4);
    min-inline-size: 19rem;
    padding: var(--spacer-2) var(--spacer-4);
    border-block-end: 1px solid var(--color-fieldset-border, var(--color-border));
}

.ear-radio-track:last-child {
    border-block-end: 0;
}

.ear-radio-track:hover {
    background: var(--color-cool-5-50);
}

.ear-radio-track.current {
    background: color-mix(in srgb, var(--color-warm-1) 12%, transparent);
}

.ear-radio-track.current .ear-radio-track-name,
.ear-radio-track.current .ear-radio-track-play {
    color: var(--color-warm-1);
}

.ear-radio-track-name {
    min-inline-size: 0;
    overflow: hidden;
    font-size: var(--font-size-13);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ear-radio-track-duration {
    text-align: end;
    font-size: var(--font-size-12);
}

.ear-radio-seek {
    grid-column: 1 / -1;
    inline-size: 100%;
    block-size: 0.75rem;
    margin: 0;
    padding: 0;
    appearance: none;
    cursor: pointer;
    border: 0;
    border-radius: 999px;
    outline: none;
    background: linear-gradient(
        to right,
        var(--ear-accent) var(--ear-radio-seek-pct, 0%),
        var(--ear-track-bg) var(--ear-radio-seek-pct, 0%)
    );
}

.ear-radio-seek:disabled {
    cursor: default;
    opacity: 0.55;
}

.ear-radio-seek::-webkit-slider-thumb {
    width: 0.75rem;
    height: 0.75rem;
    appearance: none;
    border: 0;
    border-radius: 50%;
    background: var(--ear-thumb);
}

.ear-radio-seek::-moz-range-thumb {
    width: 0.75rem;
    height: 0.75rem;
    border: 0;
    border-radius: 50%;
    background: var(--ear-thumb);
}

.ear-radio-seek:focus-visible {
    outline: 2px solid var(--color-warm-1);
    outline-offset: 3px;
}

.ear-radio-empty {
    padding: var(--spacer-16) var(--spacer-12);
    text-align: center;
}

@media (max-width: 520px) {
    .ear-radio-console {
        grid-template-columns: 1fr auto;
    }

    .ear-radio-transport {
        grid-column: 1 / -1;
    }
}
