/* soundbot: shared system (tokens, controls, shell) and the Remote */

:root {
    --ground: #111318;
    --surface: #181a20;
    --tile: #1e2129;
    --tile-hover: #262a33;
    --tile-press: #2c303a;
    --line: #2a2e38;
    --text: #f2f3f5;
    --muted: #a3a8b4;
    --faint: #8b909c;
    --accent: #2f5bd8;
    --accent-text: #8fb0ff;
    --online: #5fd08a;
    --stop: #c93638;
    --stop-hover: #b32f31;
    --warn-bg: #3a1f22;
    --warn-text: #ffd7d7;

    --radius: 12px;
    --radius-large: 14px;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --fast: 160ms;

    --top-h: 64px;
    --now-h: 80px;
    --dock-h: 0px;

    color-scheme: dark;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scrollbar-color: var(--tile-press) var(--ground);
}

body.sb {
    margin: 0;
    min-height: 100vh;
    background: var(--ground);
    color: var(--text);
    font-family: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 0.9375rem;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    caret-color: var(--accent-text);
}

.sb-remote {
    padding-bottom: calc(var(--now-h) + var(--dock-h) + env(safe-area-inset-bottom));
}

::selection {
    background: var(--accent);
    color: #fff;
}

:focus-visible {
    outline: 2px solid var(--accent-text);
    outline-offset: 2px;
}

h1,
h2,
p {
    margin: 0;
}

a {
    color: inherit;
}

kbd {
    font: inherit;
}

.sb-sprite {
    position: absolute;
}

.sb-icon {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sb-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Buttons */

.sb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 14px;
    border: 0;
    border-radius: 10px;
    background: var(--tile);
    color: var(--text);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--fast) var(--ease), transform var(--fast) var(--ease);
}

.sb-btn:hover {
    background: var(--tile-hover);
}

.sb-btn:active {
    transform: scale(0.97);
}

.sb-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.sb-btn--ghost {
    background: transparent;
    color: var(--muted);
}

.sb-btn--ghost:hover {
    color: var(--text);
}

.sb-btn--icon {
    width: 40px;
    padding: 0;
    background: transparent;
    color: var(--muted);
}

.sb-btn--icon:hover {
    color: var(--text);
}

.sb-btn--primary {
    background: var(--accent);
    color: #fff;
}

.sb-btn--primary:hover {
    background: #2a51c4;
}

.sb-btn--stop {
    background: var(--stop);
    color: #fff;
}

.sb-btn--stop:hover {
    background: var(--stop-hover);
}

.sb-top .sb-btn--stop {
    background: transparent;
    color: #ff8f91;
    box-shadow: inset 0 0 0 1px rgba(255, 143, 145, 0.35);
}

.sb-top .sb-btn--stop:hover {
    background: var(--warn-bg);
}

.sb-now[data-state='idle'] .sb-now__stop {
    visibility: hidden;
}

.sb-btn--stop kbd {
    padding: 2px 5px;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.22);
    font-size: 0.6875rem;
    font-weight: 600;
}

/* Top bar */

.sb-top {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: auto minmax(0, 520px) 1fr;
    align-items: center;
    gap: 24px;
    height: var(--top-h);
    padding: 0 32px;
    background: rgba(17, 19, 24, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: saturate(140%) blur(12px);
}

.sb-logo {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-decoration: none;
}

.sb-search {
    position: relative;
    display: flex;
    align-items: center;
    height: 42px;
    padding: 0 12px;
    border-radius: 10px;
    background: var(--tile);
    color: var(--muted);
    transition: box-shadow var(--fast) var(--ease);
}

.sb-search:focus-within {
    box-shadow: 0 0 0 2px var(--accent-text);
}

.sb-search input {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0 10px;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.9375rem;
    outline: none;
}

.sb-search input::placeholder {
    color: var(--faint);
}

.sb-search input::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

.sb-search__hint {
    padding: 2px 7px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--muted);
    font-size: 0.75rem;
}

.sb-search:focus-within .sb-search__hint,
.sb-search__clear:not([hidden]) + .sb-search__hint {
    display: none;
}

.sb-search__clear {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    margin-right: -4px;
    padding: 0;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.sb-search__clear[hidden] {
    display: none;
}

.sb-search__clear:hover {
    background: var(--tile-hover);
    color: var(--text);
}

.sb-search__clear .sb-icon {
    width: 16px;
    height: 16px;
}

.sb-top__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.sb-presence {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    margin: 0 8px;
    padding: 0 12px;
    border-radius: 999px;
    background: var(--tile);
    color: var(--muted);
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
}

.sb-presence__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--faint);
}

.sb-presence[data-state='online'] {
    color: var(--text);
}

.sb-presence[data-state='online'] .sb-presence__dot {
    background: var(--online);
}

.sb-presence[data-state='offline'] {
    background: var(--warn-bg);
    color: var(--warn-text);
}

.sb-presence[data-state='offline'] .sb-presence__dot {
    background: #ff6b6d;
}

.sb-volume {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.sb-volume input {
    width: 96px;
    accent-color: var(--accent-text);
}

/* Banner */

.sb-banner {
    position: sticky;
    top: var(--top-h);
    z-index: 15;
    padding: 10px 32px;
    background: var(--warn-bg);
    color: var(--warn-text);
    font-weight: 600;
}

/* Sections */

.sb-main {
    padding: 8px 32px 40px;
}

.sb-section {
    margin-top: 28px;
}

.sb-section__head {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 14px;
}

.sb-section h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.sb-section__meta {
    color: var(--muted);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

.is-searching #favourites {
    display: none;
}

/* Tiles */

.sb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(164px, 1fr));
    gap: 10px;
}

.sb-grid--large {
    grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
    gap: 12px;
}

.sb-tile {
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
    min-height: 60px;
    padding: 10px 12px;
    overflow: hidden;
    border: 0;
    border-radius: var(--radius);
    background: var(--tile);
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color var(--fast) var(--ease), transform var(--fast) var(--ease),
        box-shadow var(--fast) var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.sb-tile:hover {
    background: var(--tile-hover);
}

.sb-tile:active {
    transform: scale(0.97);
    background: var(--tile-press);
}

.sb-tile[hidden] {
    display: none;
}

.sb-tile__key {
    display: inline-grid;
    place-items: center;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    border-radius: 7px;
    background: var(--tile-press);
    box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.45);
    color: var(--text);
    font-size: 0.8125rem;
    font-weight: 700;
    text-transform: uppercase;
}

.sb-tile__key--none {
    background: transparent;
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--faint);
}

.sb-tile__key .sb-icon {
    width: 14px;
    height: 14px;
    fill: currentColor;
    stroke-width: 1.5;
}

.sb-tile__name {
    display: -webkit-box;
    overflow: hidden;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.25;
    overflow-wrap: break-word;
    hyphens: auto;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.sb-tile--plain {
    grid-template-columns: 1fr;
    padding-left: 14px;
}

.sb-tile__count {
    position: absolute;
    top: 12px;
    right: 14px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.sb-tile__status {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    color: var(--accent-text);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    opacity: 0;
    transition: opacity var(--fast) var(--ease);
}

.sb-tile::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: var(--accent-text);
    transform: scaleX(0);
    transform-origin: left;
}

.sb-grid--large .sb-tile {
    grid-template-columns: 1fr;
    align-content: space-between;
    min-height: 108px;
    padding: 14px;
    border-radius: var(--radius-large);
}

.sb-grid--large .sb-tile__key {
    order: -1;
    justify-self: start;
    min-width: 36px;
    height: 36px;
    font-size: 1rem;
    border-radius: 9px;
}

.sb-grid--large .sb-tile--plain {
    align-content: end;
    padding-top: 40px;
}

.sb-grid--large .sb-tile__name {
    font-size: 1.0625rem;
    font-weight: 600;
}

/* Tile states */

.sb-tile.is-sent {
    box-shadow: inset 0 0 0 2px var(--accent-text);
}

.sb-tile.is-sent .sb-tile__status,
.sb-tile.is-playing .sb-tile__status {
    opacity: 1;
}

.sb-grid:not(.sb-grid--large) .sb-tile.is-sent .sb-tile__key,
.sb-grid:not(.sb-grid--large) .sb-tile.is-playing .sb-tile__key {
    visibility: hidden;
}

.sb-grid--large .sb-tile__status {
    top: auto;
    bottom: 12px;
    right: 14px;
    transform: none;
}

.sb-tile.is-playing,
.sb-tile.is-playing:hover {
    background: var(--accent);
    color: #fff;
}

.sb-tile.is-playing .sb-tile__status,
.sb-tile.is-playing .sb-tile__count {
    color: #fff;
}

.sb-tile.is-playing .sb-tile__key {
    background: rgba(0, 0, 0, 0.25);
}

.sb-tile.is-playing::after {
    background: #fff;
}

.sb-tile.is-playing::after {
    animation: sb-progress var(--duration, 2s) linear forwards;
}

.sb-tile.is-last:not(.is-playing):not(.is-sent) {
    box-shadow: inset 0 0 0 2px var(--accent);
}

@keyframes sb-progress {
    from {
        transform: scaleX(var(--start, 0));
    }
    to {
        transform: scaleX(1);
    }
}

/* Empty states */

.sb-empty {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    padding: 20px;
    border: 1px dashed var(--line);
    border-radius: var(--radius-large);
    color: var(--muted);
}

.sb-empty[hidden] {
    display: none;
}

.sb-empty--search {
    flex-direction: column;
    align-items: flex-start;
    padding: 28px;
    color: var(--text);
    font-size: 1.0625rem;
}

/* YouTube */

.sb-youtube {
    margin-top: 16px;
    max-width: 760px;
}

.sb-youtube > label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 0.8125rem;
    font-weight: 600;
}

.sb-youtube__row {
    display: flex;
    gap: 8px;
}

.sb-youtube input,
#speak-text {
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--ground);
    color: var(--text);
    font: inherit;
}

.sb-youtube input::placeholder,
#speak-text::placeholder {
    color: var(--faint);
}

.sb-youtube input:focus,
#speak-text:focus {
    border-color: var(--accent-text);
    outline: none;
}

#youtube-url {
    flex: 1;
    min-width: 0;
}

.sb-field-small {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 0.8125rem;
}

.sb-field-small input {
    width: 64px;
    font-variant-numeric: tabular-nums;
}

.sb-form-error {
    margin-top: 8px;
    color: #ff9a9c;
    font-size: 0.875rem;
}

/* Now playing */

.sb-now {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--dock-h) + env(safe-area-inset-bottom));
    z-index: 20;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 560px) minmax(0, 1fr);
    align-items: center;
    gap: 24px;
    height: var(--now-h);
    padding: 0 32px;
    background: var(--surface);
    border-top: 1px solid var(--line);
}

.sb-now__info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.sb-now__icon {
    width: 40px;
    height: 40px;
    padding: 9px;
    border-radius: 10px;
    background: var(--tile);
    color: var(--muted);
}

.sb-now[data-state='playing'] .sb-now__icon {
    background: var(--accent);
    color: #fff;
}

.sb-now__text {
    min-width: 0;
}

.sb-now__title {
    overflow: hidden;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sb-now__sub {
    overflow: hidden;
    color: var(--muted);
    font-size: 0.8125rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sb-now__progress {
    display: grid;
    grid-template-columns: 40px 1fr 40px;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.sb-now__time:last-child {
    text-align: right;
}

.sb-now__track {
    height: 4px;
    overflow: hidden;
    border-radius: 2px;
    background: var(--tile-press);
}

.sb-now__fill {
    display: block;
    height: 100%;
    background: var(--text);
    transform: scaleX(0);
    transform-origin: left;
}

.sb-now[data-state='idle'] .sb-now__progress {
    visibility: hidden;
}

.sb-now__stop {
    justify-self: end;
}

/* Popovers */

.sb-panel {
    position: fixed;
    inset: auto;
    top: calc(var(--top-h) + 8px);
    right: 24px;
    width: min(380px, calc(100vw - 32px));
    margin: 0;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-large);
    background: var(--tile);
    color: var(--text);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.sb-panel__body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
}

.sb-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: -4px -8px -4px 0;
}

.sb-panel h2 {
    font-size: 1rem;
    font-weight: 700;
}

.sb-panel__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sb-panel__note {
    color: var(--muted);
    font-size: 0.8125rem;
}

.sb-counter {
    color: var(--muted);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

.sb-counter.is-full {
    color: #ff9a9c;
}

.sb-panel--menu .sb-panel__body {
    gap: 2px;
    padding: 8px;
}

.sb-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 44px;
    padding: 0 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.sb-menu-item:hover {
    background: var(--tile-hover);
}

.sb-menu-item .sb-icon {
    color: var(--muted);
}

.sb-volume--menu {
    display: none;
    min-height: 48px;
    padding: 0 10px;
    color: var(--text);
    font-weight: 500;
}

.sb-volume--menu input {
    flex: 1;
}

.sb-menu-hint {
    margin-top: 6px;
    padding: 10px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.8125rem;
    line-height: 1.6;
}

.sb-menu-hint kbd {
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--tile-press);
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 600;
}

/* Toast */

.sb-toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--now-h) + var(--dock-h) + 16px + env(safe-area-inset-bottom));
    z-index: 30;
    max-width: min(520px, calc(100vw - 32px));
    padding: 12px 16px;
    border-radius: 12px;
    background: #f2f3f5;
    color: #111318;
    font-weight: 600;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 8px);
    transition: opacity var(--fast) var(--ease), transform var(--fast) var(--ease);
}

.sb-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* Dock (phones) */

.sb-dock {
    display: none;
}

/* Not found page */

.sb-missing {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    max-width: 560px;
    margin: 18vh auto 0;
    padding: 0 24px;
}

.sb-missing h1 {
    font-size: 2rem;
    line-height: 1.15;
    letter-spacing: -0.02em;
}

.sb-missing p {
    color: var(--muted);
    font-size: 1.0625rem;
}

.sb-missing form {
    margin-top: 8px;
}

/* Responsive */

@media (max-width: 1100px) {
    .sb-top {
        grid-template-columns: auto minmax(0, 1fr) auto;
    }

    .sb-volume:not(.sb-volume--menu) {
        display: none;
    }

    .sb-volume--menu {
        display: flex;
    }
}

@media (max-width: 720px) {
    :root {
        --top-h: 112px;
        --now-h: 56px;
        --dock-h: 64px;
    }

    .sb-hide-phone {
        display: none !important;
    }

    .sb-top {
        grid-template-columns: 1fr auto;
        grid-template-rows: 52px 48px;
        gap: 0 8px;
        padding: 0 16px 8px;
    }

    .sb-search {
        grid-column: 1 / -1;
        grid-row: 2;
        height: 44px;
    }

    .sb-search__hint {
        display: none;
    }

    .sb-presence {
        margin: 0;
    }

    .sb-banner {
        padding: 10px 16px;
    }

    .sb-main {
        padding: 0 16px 24px;
    }

    .sb-section {
        margin-top: 22px;
    }

    .sb-grid,
    .sb-grid--large {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .sb-tile {
        min-height: 56px;
    }

    .sb-grid--large .sb-tile {
        min-height: 72px;
        padding: 10px 12px;
    }

    .sb-grid--large .sb-tile__key {
        min-width: 28px;
        height: 28px;
        font-size: 0.8125rem;
    }

    .sb-grid--large .sb-tile__name {
        font-size: 0.9375rem;
    }

    .sb-youtube__row {
        flex-wrap: wrap;
    }

    #youtube-url {
        flex-basis: 100%;
    }

    .sb-now {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
        padding: 0 16px;
    }

    .sb-now__icon {
        width: 32px;
        height: 32px;
        padding: 6px;
    }

    .sb-now__progress {
        position: absolute;
        top: -1px;
        left: 0;
        right: 0;
        display: block;
    }

    .sb-now__time {
        display: none;
    }

    .sb-now__track {
        display: block;
        height: 2px;
        border-radius: 0;
        background: transparent;
    }

    .sb-now__fill {
        background: var(--accent-text);
    }

    .sb-now__stop {
        display: none;
    }

    .sb-dock {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 21;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        height: calc(var(--dock-h) + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: var(--surface);
        border-top: 1px solid var(--line);
    }

    .sb-dock__btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        border: 0;
        background: transparent;
        color: var(--muted);
        font: inherit;
        font-size: 0.75rem;
        font-weight: 600;
        cursor: pointer;
    }

    .sb-dock__btn:active {
        color: var(--text);
    }

    .sb-dock__btn--stop {
        color: #ff8f91;
    }

    .sb-panel {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 80vh;
        overflow: auto;
        border-radius: 16px 16px 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .sb-panel__body {
        padding: 20px 16px 24px;
    }

    .sb-panel .sb-btn--primary {
        height: 48px;
    }

    .sb-panel::backdrop {
        background: rgba(0, 0, 0, 0.5);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 1ms !important;
    }

    .sb-tile.is-playing::after {
        animation: none;
        transform: scaleX(1);
    }
}
