html,
body {
    min-height: 100%;
    margin: 0;
    background: #0f0f0f;
    color: #f1f1f1;
    font-family: Arial, Helvetica, sans-serif;
}

body {
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

button,
textarea,
input {
    font: inherit;
}

header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    width: 100%;
    max-width: 550px;
    box-sizing: border-box;
    margin: 0 auto;
    padding: 12px 14px 10px;
    border-bottom: 1px solid #2a2a2a;
    background: rgba(15, 15, 15, 0.96);
}

.headerActions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 6px;
    align-self: flex-start;
    margin-left: auto;
}

h1,
h2,
p {
    margin: 0;
}

#brandWordmark {
    display: block;
    width: 188px;
    max-width: 52vw;
    height: auto;
    margin-bottom: 8px;
}

h2 {
    font-size: 18px;
}

.appInfo {
    font-size: 12px;
    font-weight: 400;
    color: #aab6c5;
    margin-bottom: 4px;
}

#appName {
    color: #f1f1f1;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 3px;
}

#roomLabel,
#statusLine,
#timeLine {
    color: #aab6c5;
    font-size: 12px;
}

#roomLabel {
    max-width: 550px;
    margin: 0 auto;
    box-sizing: border-box;
    padding: 0 14px 18px;
    text-align: center;
}

#commsInfoDiv,
.backToAppsButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    box-sizing: border-box;
    border: 1px solid #303030;
    border-radius: 999px;
    background: #1d1d1d;
    color: #dce3eb;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
}

#commsInfoDiv {
    padding: 0 11px;
    max-width: 46vw;
}

#commsInfo,
.backToAppsButton {
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
}

#commsInfo {
    overflow: hidden;
    text-overflow: ellipsis;
}

.backToAppsButton {
    padding: 0 12px;
}

.backToAppsButton:hover,
#commsInfoDiv:hover {
    border-color: #4a4a4a;
    background: #272727;
}

.statusDot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 7px;
    border-radius: 50%;
    background: #d9a441;
    box-shadow: 0 0 12px rgba(217, 164, 65, 0.55);
}

.statusDot.statusDotConnected {
    background: #20d66b;
    box-shadow: 0 0 12px rgba(32, 214, 107, 0.65);
}

.statusDot.statusDotDisconnected {
    background: #CD201F;
    box-shadow: 0 0 12px rgba(205, 32, 31, 0.72);
}

main {
    display: grid;
    max-width: 550px;
    margin: 0 auto;
    padding: 14px;
    box-sizing: border-box;
}

#appTabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    width: 100%;
    padding: 4px;
    border: 1px solid #303030;
    border-radius: 8px;
    background: #151515;
    box-sizing: border-box;
}

.tabButton {
    min-height: 40px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #aab6c5;
    font-size: 14px;
}

.tabButton:hover {
    background: #242424;
}

.tabButton.active,
.tabButton[aria-selected="true"] {
    background: #CD201F;
    color: #fff;
}

.tabPanel {
    display: none;
    gap: 14px;
}

.tabPanel.activeTabPanel {
    display: grid;
}

form,
#nowPlaying,
#audioControls,
#displayControls,
#loopControls,
#playlistTools,
#queueSection,
#searchSection {
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    background: #181818;
    padding: 14px;
}

label {
    display: block;
    margin-bottom: 8px;
    color: #f1f1f1;
    font-weight: 700;
}

textarea {
    width: 100%;
    min-height: 76px;
    box-sizing: border-box;
    resize: vertical;
    border: 1px solid #303030;
    border-radius: 8px;
    background: #0f0f0f;
    color: #fff;
    padding: 10px;
}

input[type="search"] {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    border: 1px solid #303030;
    border-radius: 8px;
    background: #0f0f0f;
    color: #fff;
    padding: 0 10px;
}

input[type="search"]:focus,
textarea:focus {
    border-color: #CD201F;
    outline: none;
}

.buttonRow,
#transport,
#displayControls,
#loopControls,
#playlistTools,
.sectionHeader {
    display: flex;
    gap: 8px;
}

.buttonRow {
    margin-top: 10px;
}

button {
    min-height: 44px;
    border: 1px solid #303030;
    border-radius: 8px;
    background: #272727;
    color: #f1f1f1;
    cursor: pointer;
    font-weight: 700;
}

button:hover {
    background: #343434;
}

button:disabled {
    opacity: 0.42;
    cursor: default;
}

button:disabled:hover {
    background: #272727;
}

button:active {
    transform: translateY(1px);
}

#queueButton {
    flex: 1;
}

#searchSection {
    display: grid;
    gap: 10px;
}

#searchForm {
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 0;
}

#searchControls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

#searchInput {
    min-height: 44px;
}

#searchButton {
    min-width: 92px;
    padding: 0 14px;
}

#popularSearchButtons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

#popularSearchButtons button {
    flex: 0 0 auto;
    min-height: 28px;
    padding: 0 10px;
    font-size: 12px;
}

#popularSearchButtons button.activeCategory {
    border-color: #CD201F;
    background: #CD201F;
    color: #fff;
}

#searchPager {
    display: none;
    grid-template-columns: 68px minmax(72px, auto) 68px;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

#searchPager.searchPagerVisible {
    display: grid;
}

#searchPager button {
    width: 68px;
    min-height: 34px;
    padding: 0;
    font-size: 12px;
}

#searchPageLabel {
    color: #aab6c5;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
}

#currentTitle {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

#currentSummary {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
}

#currentSummary.noThumbnail {
    grid-template-columns: minmax(0, 1fr);
}

#currentThumbnail {
    width: 112px;
    aspect-ratio: 16 / 9;
    border-radius: 6px;
    object-fit: cover;
    background: #0f0f0f;
}

#currentThumbnail[hidden] {
    display: none;
}

#statusLine {
    margin-top: 5px;
    max-width: 100%;
    color: #cfcfcf;
    font-size: 14px;
    line-height: 1.35;
    overflow-wrap: normal;
}

#seekSlider {
    width: 100%;
    margin: 16px 0 6px;
    accent-color: #CD201F;
}

#timeLine {
    display: flex;
    justify-content: space-between;
}

#transport {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

#transport button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 6px;
}

#transport svg {
    width: 24px;
    height: 24px;
    display: block;
    fill: currentColor;
    flex: 0 0 auto;
}

#transport .transportPrimary {
    border-color: #303030;
    background: #272727;
    color: #fff;
}

#transport .transportPrimary:hover {
    background: #343434;
}

#transport .transportPrimary.active,
#transport .transportPrimary[aria-pressed="true"] {
    border-color: #CD201F;
    background: #CD201F;
}

#transport .transportPrimary.active:hover,
#transport .transportPrimary[aria-pressed="true"]:hover {
    background: #A91B1A;
}

#audioControls {
    display: grid;
    grid-template-columns: auto auto minmax(120px, 1fr);
    gap: 10px;
    align-items: center;
}

#audioControls label {
    margin-bottom: 0;
    white-space: nowrap;
}

#volumeSlider {
    width: 100%;
    min-width: 0;
    accent-color: #CD201F;
}

#volumeSlider:disabled {
    opacity: 0.42;
}

#displayControls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

#loopControls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

#displayControls button {
    padding: 0 6px;
}

#displayControls button[aria-pressed="true"],
#muteButton[aria-pressed="true"],
#loopControls button[aria-pressed="true"] {
    border-color: #CD201F;
    background: #CD201F;
}

#playlistTools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

#playlistFileInput {
    display: none;
}

.sectionHeader {
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

#clearButton {
    min-height: 36px;
    padding: 0 12px;
    border-color: #4a4a4a;
    background: #3a3a3a;
    color: #f1f1f1;
}

#queueList {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.searchResult {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr) auto;
    gap: 8px;
    align-items: stretch;
}

.searchThumbnail {
    width: 86px;
    height: 48px;
    border-radius: 5px;
    object-fit: cover;
    background: #0f0f0f;
}

.searchTitle {
    display: grid;
    align-content: center;
    min-width: 0;
    padding: 6px 0;
}

.searchName,
.searchChannel,
.searchPublished {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.searchName {
    color: #f1f1f1;
    font-size: 14px;
    font-weight: 700;
}

.searchMeta {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    margin-top: 3px;
    min-width: 0;
}

.searchChannel {
    color: #aab6c5;
    font-size: 12px;
}

.searchPublished {
    color: #8d99a8;
    font-size: 12px;
    text-align: right;
}

.searchAddButton {
    min-width: 44px;
    padding: 0 10px;
    font-size: 24px;
    line-height: 1;
}

#searchResults {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
    transition: opacity 160ms ease;
}

#searchResultsWrap {
    position: relative;
    min-height: 0;
}

#searchSection.searchLoading #searchResults {
    opacity: 0.38;
}

#searchSection.searchLoading #searchResultsWrap {
    min-height: 52px;
}

#searchLoadingLine {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 12px;
    border: 1px solid #303030;
    border-radius: 8px;
    background: rgba(24, 24, 24, 0.72);
    color: #aab6c5;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    pointer-events: none;
}

#searchSection.searchLoading #searchLoadingLine {
    display: flex;
}

.queueItem {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 8px;
    align-items: stretch;
    will-change: transform;
}

.queueItem.current {
    outline: 2px solid #CD201F;
    outline-offset: 2px;
    border-radius: 8px;
}

.queueItem.current .queueTitle {
    background: #303030;
}

.queueItem.dragging {
    opacity: 0.86;
    filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.36));
    z-index: 2;
}

.queue-reordering {
    user-select: none;
}

.dragHandle {
    position: relative;
    min-width: 42px;
    padding: 0;
    border-color: #3a3a3a;
    background: #242424;
    cursor: grab;
    touch-action: none;
}

.dragHandle:active {
    cursor: grabbing;
}

.dragHandle::before {
    content: "";
    position: absolute;
    left: 13px;
    right: 13px;
    top: 50%;
    height: 14px;
    background: repeating-linear-gradient(to bottom,
            #cfcfcf 0,
            #cfcfcf 2px,
            transparent 2px,
            transparent 6px);
    transform: translateY(-50%);
}

.queueTitle {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    min-width: 0;
    padding: 6px 10px 6px 6px;
    text-align: left;
    touch-action: pan-y;
}

.queueThumbnail {
    width: 72px;
    aspect-ratio: 16 / 9;
    border-radius: 5px;
    object-fit: cover;
    background: #0f0f0f;
}

.queueLabel {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.removeButton {
    min-width: 44px;
    padding: 0;
    border-color: #4a4a4a;
    background: #3a3a3a;
    color: #f1f1f1;
    font-size: 24px;
    line-height: 1;
    touch-action: pan-y;
}

.emptyQueue {
    color: #aab6c5;
    font-size: 14px;
    padding: 8px 0;
}

#complianceFooter {
    max-width: 550px;
    margin: 0 auto;
    box-sizing: border-box;
    padding: 2px 14px 18px;
    color: #8d99a8;
    font-size: 11px;
    line-height: 1.4;
    text-align: center;
}

#complianceFooter a {
    color: #dce3eb;
    font-weight: 700;
}

#queueToast {
    position: fixed;
    left: 50%;
    bottom: 14px;
    z-index: 6;
    width: calc(100% - 28px);
    max-width: 520px;
    box-sizing: border-box;
    padding: 13px 16px;
    border: 1px solid #333;
    border-radius: 8px;
    background: #f1f1f1;
    color: #101010;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.35;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 12px);
    transition: opacity 180ms ease, transform 180ms ease;
}

#queueToast.queueToastVisible {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (min-width: 620px) {
    #transport {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}

@media (max-width: 380px) {
    header {
        align-items: flex-start;
    }

    .headerActions {
        align-items: flex-end;
    }

    #transport button {
        font-size: 18px;
    }

    #currentSummary {
        grid-template-columns: 88px minmax(0, 1fr);
    }

    #currentThumbnail {
        width: 88px;
    }

    .queueTitle {
        grid-template-columns: 60px minmax(0, 1fr);
    }

    .queueThumbnail {
        width: 60px;
    }

    #searchControls,
    .searchResult {
        grid-template-columns: minmax(0, 1fr);
    }

    .searchAddButton {
        width: 100%;
    }
}
