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

:root {
    /* Curasai palette — deep navy → indigo → purple. */
    --bg-1: #1a1a2e;
    --bg-2: #16213e;
    --bg-3: #0f3460;
    --bg-4: #533483;
    --bg-5: #7209b7;
    --gradient-body: linear-gradient(135deg, #1a1a2e 0%, #16213e 25%, #0f3460 50%, #533483 75%, #7209b7 100%);
    /* Card gradients — blue → indigo → soft violet (less pink). */
    --gradient-card: linear-gradient(135deg, #007AFF 0%, #5856D6 55%, #8B6FE0 100%);
    --gradient-card-hover: linear-gradient(135deg, #1E88E5 0%, #6A52CC 55%, #9C7DE8 100%);
    --accent: #007AFF;
    --accent-light: #5AC8FA;
    --accent-glow: rgba(0, 122, 255, 0.35);
    --surface: rgba(255, 255, 255, 0.05);
    --surface-hover: rgba(255, 255, 255, 0.10);
    --surface-active: rgba(255, 255, 255, 0.14);
    --border: rgba(255, 255, 255, 0.10);
    --border-glow: rgba(0, 122, 255, 0.5);
    --text: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.80);
    --text-tertiary: rgba(255, 255, 255, 0.60);
    --text-muted: rgba(255, 255, 255, 0.45);
    --progress-bg: rgba(255, 255, 255, 0.12);
    --progress-fill: #007AFF;
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    --transition: 200ms cubic-bezier(0.25, 0.1, 0.25, 1);
    /* Back-compat aliases for channel.html. */
    --bg: var(--bg-1);
}

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--gradient-body);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100dvh;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    position: relative;
}

/* Decorative gradient orbs — match the original splash backdrop. */
.bg-orbs {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.bg-orbs .orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    opacity: 0.85;
    animation: orb-drift 22s ease-in-out infinite;
}

.bg-orbs .orb-1 {
    top: 5%; left: 8%;
    width: 480px; height: 480px;
    background: radial-gradient(circle, rgba(0, 122, 255, 0.85), rgba(0, 122, 255, 0) 70%);
    animation-delay: 0s;
}

.bg-orbs .orb-2 {
    top: 10%; right: 6%;
    width: 420px; height: 420px;
    background: radial-gradient(circle, rgba(175, 82, 222, 0.80), rgba(175, 82, 222, 0) 70%);
    animation-delay: -7s;
}

.bg-orbs .orb-3 {
    bottom: 4%; left: 12%;
    width: 360px; height: 360px;
    background: radial-gradient(circle, rgba(88, 86, 214, 0.75), rgba(88, 86, 214, 0) 70%);
    animation-delay: -14s;
}

.bg-orbs .orb-4 {
    bottom: 8%; right: 10%;
    width: 440px; height: 440px;
    background: radial-gradient(circle, rgba(175, 82, 222, 0.75), rgba(175, 82, 222, 0) 70%);
    animation-delay: -3s;
}

@keyframes orb-drift {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50%      { transform: translate(20px, -28px) scale(1.06); }
}

/* ============================================
   STATION SELECTOR PAGE
   ============================================ */

/* The HTML `hidden` attribute is semantically "display:none", but the
   user-agent stylesheet rule has very low specificity. Component-level
   `display: flex` rules (e.g. .selector-page below) silently beat it.
   This restores the spec-intended behaviour so toggling [hidden]=true
   actually hides the element regardless of other display rules. */
[hidden] { display: none !important; }

.selector-page {
    min-height: 100dvh;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.selector-header {
    text-align: center;
    margin-bottom: 60px;
    animation: header-slide-in 0.6s ease-out;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Logo + wordmark stacked, matches the existing splash. */
.logo-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
}

.brand-mark {
    width: 62px;
    height: 62px;
    border-radius: 14px;
    box-shadow:
        0 10px 28px rgba(0, 0, 0, 0.45),
        0 4px 14px rgba(0, 122, 255, 0.32),
        0 0 0 1px rgba(255, 255, 255, 0.06) inset;
    animation: brand-float 6s ease-in-out infinite;
}

@keyframes brand-float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-3px); }
}

.brand-wordmark {
    font-size: 18px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.92);
    letter-spacing: 1px;
    text-transform: lowercase;
}

.selector-header h1 {
    font-size: clamp(22px, 3.2vw, 30px);
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
    margin-bottom: 10px;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.selector-header .tagline {
    font-size: clamp(14px, 1.8vw, 16px);
    color: rgba(255, 255, 255, 0.80);
    font-weight: 400;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
}

/* Stations grid — auto-fit columns at minmax(280px, 1fr). */
.station-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    max-width: 980px;
    width: 100%;
    animation: grid-fade-in 0.8s ease-out 0.2s both;
}

/* Vivid Apple-style gradient pill cards. */
.station-btn {
    position: relative;
    background: var(--gradient-card);
    border: none;
    border-radius: 16px;
    padding: 18px 20px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    color: #fff;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
    overflow: hidden;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.20);
    box-sizing: border-box;
    animation: card-pop-in 0.5s ease-out both;
}

/* Diagonal shine that sweeps across on hover. */
.station-btn::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.18), transparent);
    transition: left 0.6s ease;
    pointer-events: none;
}

.station-btn:hover {
    background: var(--gradient-card-hover);
    transform: translateY(-2px);
    box-shadow:
        0 12px 36px rgba(0, 0, 0, 0.45),
        0 4px 16px rgba(0, 122, 255, 0.25);
}

.station-btn:hover::before {
    left: 100%;
}

.station-btn:active {
    transform: translateY(-1px);
}

.station-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}

@keyframes card-pop-in {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Card content: icon + name on the left, weight 300 like the original. */
.station-content {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 14px;
    position: relative;
    z-index: 1;
}

.station-icon {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.92);
}

.station-icon svg {
    width: 24px;
    height: 24px;
    display: block;
}

.station-info {
    flex: 1;
    text-align: left;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
}

.station-name {
    font-size: 17px;
    font-weight: 400;
    line-height: 1.2;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Trailing pill (e.g. "HD" for ABR/prechunked stations) — sits to the
   right of the name without changing the card height. */
.station-badge {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.95);
    background: rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    padding: 3px 9px;
    line-height: 1;
}

/* Copyright footer. */
.copyright-notice {
    text-align: center;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.55);
    line-height: 1.5;
    margin-top: 48px;
    padding: 0 20px;
    animation: fade-in 1s ease-out 0.4s both;
}

/* Animations. */
@keyframes header-slide-in {
    from { opacity: 0; transform: translateY(-30px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes grid-fade-in {
    from { opacity: 0; transform: translateY(40px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.station-now-playing {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.station-listeners {
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

.station-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #4ade80;
    border-radius: 50%;
    margin-right: 4px;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Tablet/mobile: collapse to single column. */
@media (max-width: 768px) {
    .selector-page {
        padding: 24px 16px;
    }
    .selector-header {
        margin-bottom: 40px;
    }
    .station-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
}

/* ============================================
   PLAYER PAGE
   ============================================ */

.player-page {
    position: relative;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: clamp(1rem, 3vw, 2rem);
    padding-top: clamp(4rem, 10vh, 6rem);
    overflow: hidden;
}

/* Blurred album art background */
.player-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
}

.player-bg img {
    position: absolute;
    inset: -80px;
    width: calc(100% + 160px);
    height: calc(100% + 160px);
    object-fit: cover;
    filter: blur(30px) brightness(0.45) saturate(1.5);
    transform: scale(1.1);
    transition: opacity 1s ease;
}

.player-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    background: radial-gradient(ellipse at center, rgba(13,13,18,0.15) 0%, var(--bg) 85%);
}

/* Top bar */
.player-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: clamp(1.25rem, 3vw, 2rem) clamp(1.5rem, 4vw, 2.5rem);
}

.topbar-left {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.topbar-brand {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.topbar-station {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
}

.close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: var(--text);
    text-decoration: none;
    transition: background var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

.close-btn svg {
    width: 16px;
    height: 16px;
}

/* Player content */
.player-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 420px;
    flex: 1;
}

/* Top section: art + track info — takes up available space */
.player-top {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    justify-content: center;
    gap: clamp(0.75rem, 2vh, 1.5rem);
    width: 100%;
}

/* Bottom section: progress + controls — pinned to bottom */
.player-bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(1rem, 2vh, 1.5rem);
    width: 100%;
    padding-bottom: clamp(1.5rem, 4vh, 3rem);
    flex-shrink: 0;
}

/* Album art */
.album-art-wrapper {
    position: relative;
    width: clamp(240px, 65vw, 360px);
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: 0 16px 64px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.3);
    background: rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

/* AD badge — shown over the album art when an ad is playing */
.album-art-link {
    display: block;
    text-decoration: none;
    color: inherit;
    position: relative;
}

.ad-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 3;
    padding: 4px 10px;
    background: linear-gradient(135deg, #ffd24d 0%, #f3a200 100%);
    color: #1a1300;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* Buffering spinner overlay */
.art-spinner {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
    border-radius: inherit;
}

.art-spinner svg {
    width: 36px;
    height: 36px;
    color: rgba(255, 255, 255, 0.8);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.album-art {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.album-art-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(123, 168, 229, 0.22) 0%, rgba(179, 136, 208, 0.10) 100%);
}

.album-art-placeholder svg {
    width: 48px;
    height: 48px;
    color: var(--text-tertiary);
}

/* Track info */
.track-info {
    text-align: center;
    width: 100%;
}

.track-title {
    font-size: clamp(1.25rem, 4vw, 1.75rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    margin-bottom: 0.3rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.track-artist {
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    color: var(--text-secondary);
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Progress section */
.progress-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.progress-bar-container {
    width: 100%;
    height: 4px;
    background: var(--progress-bg);
    border-radius: 2px;
    overflow: hidden;
    cursor: pointer;
}

.progress-bar {
    height: 100%;
    background: var(--progress-fill);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s linear;
    position: relative;
}

.progress-times {
    display: flex;
    justify-content: space-between;
}

.time {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

/* Controls */
.controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(1.5rem, 4vw, 2.5rem);
}

.play-btn {
    width: clamp(56px, 10vw, 68px);
    height: clamp(56px, 10vw, 68px);
    background: var(--accent);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
    box-shadow: 0 4px 20px var(--accent-glow);
    -webkit-tap-highlight-color: transparent;
}

.play-btn:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 28px var(--accent-glow);
}

.play-btn:active {
    transform: scale(0.96);
}

.play-btn svg {
    width: 28px;
    height: 28px;
}

/* Volume */
.volume-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-tertiary);
}

.volume-control svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: clamp(80px, 15vw, 120px);
    height: 4px;
    background: var(--progress-bg);
    border-radius: 2px;
    outline: none;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.volume-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text);
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* Listener count */
.listeners {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 400;
}

.listeners .live-dot {
    display: inline-block;
    width: 5px;
    height: 5px;
    background: #4ade80;
    border-radius: 50%;
    margin-right: 4px;
    animation: pulse-dot 2s ease-in-out infinite;
}

/* ============================================
   TABLET (iPad) — PORTRAIT
   ============================================ */

@media (min-width: 500px) and (orientation: portrait) {
    .player-page {
        padding-top: clamp(5rem, 10vh, 7rem);
    }

    .album-art-wrapper {
        width: clamp(300px, 60vw, 500px);
    }

    .track-title {
        font-size: clamp(1.5rem, 3.5vw, 2.25rem);
    }

    .track-artist {
        font-size: clamp(1rem, 2.5vw, 1.35rem);
    }

    .player-bottom {
        max-width: 480px;
    }

    .play-btn {
        width: 72px;
        height: 72px;
    }

    .play-btn svg {
        width: 32px;
        height: 32px;
    }

    .time {
        font-size: 0.85rem;
    }

    .topbar-brand {
        font-size: 0.7rem;
    }

    .topbar-station {
        font-size: 1.15rem;
    }

    .close-btn {
        width: 40px;
        height: 40px;
    }

    .close-btn svg {
        width: 18px;
        height: 18px;
    }
}

/* ============================================
   TABLET (iPad) — LANDSCAPE
   ============================================ */

@media (min-width: 900px) and (orientation: landscape) {
    .player-page {
        padding-top: clamp(4rem, 8vh, 6rem);
    }

    .album-art-wrapper {
        width: clamp(300px, 42vh, 460px);
    }

    .track-title {
        font-size: clamp(1.25rem, 2.5vw, 1.75rem);
    }

    .track-artist {
        font-size: clamp(0.95rem, 2vw, 1.15rem);
    }

    .player-content {
        max-width: 640px;
    }

    .player-bottom {
        max-width: 500px;
    }

    .play-btn {
        width: 68px;
        height: 68px;
    }

    .play-btn svg {
        width: 30px;
        height: 30px;
    }
}

/* ============================================
   LANDSCAPE MODE (phone — short viewport)
   ============================================ */

@media (orientation: landscape) and (max-height: 500px) {
    .player-page {
        padding: 0.75rem 2rem;
        padding-top: 0.75rem;
        justify-content: center;
    }

    .player-content {
        flex-direction: row !important;
        align-items: center;
        gap: 1.5rem;
        max-width: 100%;
    }

    /* Left side: art + track info — fixed width */
    .player-top {
        flex: 0 0 auto !important;
        justify-content: center;
        gap: 0.4rem;
        max-width: 45%;
    }

    .album-art-wrapper {
        width: clamp(120px, 38vh, 220px);
    }

    .track-title {
        font-size: 0.95rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }

    .track-artist {
        font-size: 0.8rem;
    }

    /* Right side: progress + play — fills remaining space */
    .player-bottom {
        flex: 1 1 0% !important;
        justify-content: center;
        padding-bottom: 0;
        gap: 0.75rem;
        min-width: 0;
    }

    .play-btn {
        width: 48px;
        height: 48px;
    }

    .play-btn svg {
        width: 22px;
        height: 22px;
    }

    .player-topbar {
        padding: 0.5rem 0.75rem;
    }

    .topbar-brand {
        font-size: 0.6rem;
    }

    .topbar-station {
        font-size: 0.85rem;
    }

    .close-btn {
        width: 30px;
        height: 30px;
    }

    .close-btn svg {
        width: 14px;
        height: 14px;
    }
}

/* ============================================
   LOADING / EMPTY STATES
   ============================================ */

.loading-state {
    color: var(--text-tertiary);
    font-size: 0.9rem;
    text-align: center;
    padding: 2rem;
}

.error-state {
    color: #f87171;
    font-size: 0.9rem;
    text-align: center;
    padding: 2rem;
}

/* ============================================
   REACTIONS ROW (above the progress bar)
   Subtle, secondary visual weight — they're always
   visible but never compete with the play button.
   ============================================ */
.reactions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    margin: 0.25rem 0 0.75rem 0;
}

.reaction-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: color 0.15s ease, transform 0.1s ease, background 0.15s ease;
    line-height: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.reaction-btn:hover {
    color: rgba(255, 255, 255, 0.92);
    background: rgba(255, 255, 255, 0.06);
}

.reaction-btn:active {
    transform: scale(0.92);
}

/* Active states — distinct color per reaction. */
.reaction-btn[aria-pressed="true"] {
    color: var(--accent, #6c82ff);
}
#react-like[aria-pressed="true"]    { color: #ef4567; }
#react-dislike[aria-pressed="true"] { color: #fb923c; }

/* Fill the heart and thumb when liked/disliked, but keep the comment
   icon as an outline (a filled speech bubble doesn't read right). */
#react-like[aria-pressed="true"]    svg path { fill: currentColor; }
#react-dislike[aria-pressed="true"] svg path { fill: currentColor; }

/* ============================================
   ARTIST + LYRICS BUTTONS — flank the play button
   ============================================ */
.controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
}

.ctrl-icon-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
    line-height: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ctrl-icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.32);
}

.ctrl-icon-btn:active {
    transform: scale(0.94);
}

/* Disabled state — used by the chat button when the current track's
 * artist has no canon. Visible but unclickable; tooltip explains. */
.ctrl-icon-btn.is-disabled,
.ctrl-icon-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: auto; /* keep the title tooltip working */
}
.ctrl-icon-btn.is-disabled:hover,
.ctrl-icon-btn:disabled:hover {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.18);
}
.ctrl-icon-btn:disabled:active {
    transform: none;
}

/* ============================================
   INFO PANEL — bottom-sheet on mobile, side-panel on desktop
   ============================================ */
.info-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}
.info-backdrop[data-open="true"] {
    opacity: 1;
    pointer-events: auto;
}

.info-panel {
    position: fixed;
    z-index: 100;
    background: rgba(20, 22, 32, 0.96);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    color: rgba(255, 255, 255, 0.92);
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Default: full-height sheet (mobile portrait + iPad portrait). A
 * FIXED height (not max-height) is critical — otherwise the panel
 * shrinks/grows with each tab's content and switching between Chat
 * (long) and About (short) makes the whole sheet jump. Using `100dvh`
 * adapts to mobile browser chrome (URL bar collapse) without jank. */
.info-panel {
    left: 0;
    right: 0;
    bottom: 0;
    height: 100dvh;
    /* Fallback for browsers without dvh support. */
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    transform: translateY(100%);
    transition: transform 0.25s ease-out;
}
.info-panel[data-open="true"] {
    transform: translateY(0);
}

.info-grabber {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.25);
    margin: 8px auto 4px;
    flex: 0 0 auto;
}

.info-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px 0 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex: 0 0 auto;
}

.info-tabs {
    display: flex;
    gap: 1.25rem;
}

.info-tab {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 12px 4px;
    cursor: pointer;
    position: relative;
    letter-spacing: 0.02em;
}
.info-tab:hover {
    color: rgba(255, 255, 255, 0.85);
}
.info-tab[aria-selected="true"] {
    color: #fff;
}
.info-tab[aria-selected="true"]::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: var(--accent, #6c82ff);
    border-radius: 2px 2px 0 0;
}
.info-tab.is-disabled {
    color: rgba(255, 255, 255, 0.22);
    cursor: not-allowed;
}
.info-tab.is-disabled:hover {
    color: rgba(255, 255, 255, 0.22);
}

/* ── Grouped info tabs ─────────────────────────────────────────────── */
.info-tabs-grouped {
    display: flex;
    align-items: flex-end;
    gap: 18px;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.info-tabs-grouped::-webkit-scrollbar { display: none; }

.tab-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
}
.tab-group-label {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: rgba(255, 255, 255, 0.38);
    padding: 0 4px;
    margin-bottom: 2px;
    user-select: none;
}
.tab-group-tabs {
    display: flex;
    gap: 14px;
}
.tab-group-divider {
    width: 1px;
    align-self: stretch;
    margin: 6px 0 8px 0;
    background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.14) 35%,
        rgba(255, 255, 255, 0.14) 65%,
        rgba(255, 255, 255, 0) 100%
    );
    flex: 0 0 auto;
}

/* Slightly tighten tab padding inside groups so the label sits naturally above */
.tab-group .info-tab {
    padding: 6px 4px 12px 4px;
    font-size: 0.92rem;
}

/* ── Inline chat mount inside the info panel ───────────────────────── */
/* Chat pane is absolutely-positioned to fill .info-body exactly, so the
 * composer textarea stays docked at the bottom of the visible area and
 * only the thread scrolls. Without this the chat surface would size to
 * its content and the user would have to scroll the parent to reach
 * the input. .info-body has `position: relative` to anchor us. */
.info-pane-chat {
    position: absolute;
    inset: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.chat-pane-host {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.chat-pane-host .chat-surface {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: transparent;
}
.chat-current-track-pill {
    margin: 10px 16px 0 16px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(108, 130, 255, 0.10);
    border: 1px solid rgba(108, 130, 255, 0.22);
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.78rem;
    line-height: 1.3;
    display: inline-flex;
    align-self: flex-start;
    max-width: calc(100% - 32px);
    gap: 6px;
    align-items: center;
}
.chat-current-track-pill::before {
    content: "♪";
    color: var(--accent, #6c82ff);
    font-size: 0.85rem;
}

.info-close {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 8px;
    line-height: 0;
    border-radius: 50%;
}
.info-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.info-body {
    /* Becomes the positioning context for the chat pane (which is
     * absolutely-positioned to fill it so the input docks at the
     * bottom instead of pushing past the viewport). About / Lyrics /
     * Credits panes still scroll inside this container. */
    position: relative;
    overflow-y: auto;
    padding: 18px 18px 28px;
    flex: 1 1 auto;
    -webkit-overflow-scrolling: touch;
}
/* When the active pane is Chat, drop the container's padding so the
 * absolutely-positioned chat surface fills edge-to-edge and the
 * composer docks flush with the bottom. */
.info-body:has(> .info-pane-chat:not([hidden])) {
    padding: 0;
    overflow: hidden;
}

.info-pane[hidden] { display: none; }

/* About pane */
.info-artist-image-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}
.info-artist-image {
    display: block;
    max-width: 60%;
    margin: 0 auto;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.info-artist-name {
    text-align: center;
    font-size: 1.4rem;
    margin: 16px 0 8px;
}
.info-bio {
    line-height: 1.55;
    font-size: 0.98rem;
    color: rgba(255, 255, 255, 0.86);
    white-space: pre-wrap;
    word-wrap: break-word;
    text-align: center;
}

/* Lyrics pane */
.info-lyrics {
    font: inherit;
    font-size: 1rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.92);
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
}

/* Credits pane — one line per piece of metadata. */
.info-credits-line {
    margin: 0 0 8px 0;
    font-size: 1rem;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.92);
}
.info-credits-line:first-child {
    margin-top: 0;
    font-size: 1.15rem;
    font-weight: 600;
}

/* Desktop / iPad landscape: side panel from the right. */
@media (min-width: 769px) {
    .info-panel {
        top: 0;
        bottom: 0;
        left: auto;
        right: 0;
        width: min(420px, 90vw);
        max-height: 100vh;
        border-radius: 0;
        transform: translateX(100%);
        box-shadow: -8px 0 30px rgba(0, 0, 0, 0.4);
    }
    .info-panel[data-open="true"] {
        transform: translateX(0);
    }
    .info-grabber {
        display: none;     /* drag-handle is mobile-only */
    }
    .info-header {
        padding-top: 18px;
    }
}

/* ============================================================
   LOGIN PAGE — responsive landing screen with the Curasai logo,
   tagline, three provider buttons, and footer links.
   Three breakpoints carry distinct treatments:
     * Mobile (≤480px)  : edge-to-edge card, no border, tighter spacing
     * iPad   (481-1024): centered card, larger type, more breathing room
     * Desktop (≥1025) : same iPad-ish card but capped at ~420px
   ============================================================ */
.login-page {
    position: relative;
    z-index: 1;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(0.75rem, 3vw, 3rem);
}

/* Card — desktop / iPad base. Mobile override below. */
.login-card {
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
    background: rgba(20, 20, 25, 0.55);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}
.login-logo {
    width: 96px;
    height: 96px;
    border-radius: 22px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    margin: 0 auto 18px;
    display: block;
}
.login-wordmark {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    margin: 0 0 6px;
    color: var(--text);
}
.login-tagline {
    color: rgba(255, 255, 255, 0.62);
    font-size: 0.95rem;
    margin: 0 0 26px;
}
.login-providers {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}
.login-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: var(--text);
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition);
    -webkit-tap-highlight-color: transparent;
    /* keep buttons feeling tactile on touch devices */
    min-height: 48px;
}
.login-btn:hover { background: rgba(255, 255, 255, 0.14); }
.login-btn:active { background: rgba(255, 255, 255, 0.18); }
.login-btn-glyph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    font-size: 0.95rem;
    font-weight: 600;
    flex-shrink: 0;
}
.login-btn-label {
    flex: 1;
    text-align: left;
}

/* Footer links — Privacy Policy | Terms & Conditions. Placeholders
   for now; the hrefs will be wired up when those pages exist. */
.login-fine {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.8rem;
    line-height: 1.4;
    margin: 4px 0 0;
    text-align: center;
}
.login-fine-link {
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
    padding-bottom: 1px;
    transition: color var(--transition), border-color var(--transition);
}
.login-fine-link:hover {
    color: rgba(255, 255, 255, 0.92);
    border-bottom-color: rgba(255, 255, 255, 0.45);
}
.login-fine-sep {
    color: rgba(255, 255, 255, 0.25);
    margin: 0 0.55em;
    user-select: none;
}

/* ---- Mobile (phones, portrait) ---------------------------------- */
@media (max-width: 480px) {
    .login-page {
        /* Edge-to-edge feel on phones; no need for outer padding. */
        padding: 0;
        align-items: stretch;
    }
    .login-card {
        max-width: none;
        width: 100%;
        padding: 2.25rem 1.5rem 1.5rem;
        /* Card occupies the full viewport on mobile — drop the
           rounded corners + border so it reads as the page itself,
           not a floating modal. */
        background: rgba(15, 15, 20, 0.7);
        border: none;
        border-radius: 0;
        box-shadow: none;
        min-height: 100dvh;
        justify-content: center;
    }
    .login-logo {
        width: 84px;
        height: 84px;
        border-radius: 20px;
        margin-bottom: 14px;
    }
    .login-wordmark { font-size: 1.75rem; }
    .login-tagline { font-size: 0.9rem; margin-bottom: 22px; }
    .login-btn {
        padding: 14px 16px;   /* a touch taller for finger targets */
        font-size: 0.95rem;
    }
    .login-fine {
        font-size: 0.78rem;
        padding: 0 0.5rem;
    }
}

/* ---- iPad / tablet (portrait + landscape) ----------------------- */
@media (min-width: 481px) and (max-width: 1024px) {
    .login-card {
        max-width: 460px;
        padding: 2.75rem 2.5rem;
    }
    .login-logo {
        width: 108px;
        height: 108px;
        border-radius: 24px;
        margin-bottom: 20px;
    }
    .login-wordmark { font-size: 2.15rem; }
    .login-tagline { font-size: 1rem; }
    .login-btn {
        padding: 13px 18px;
        font-size: 1.02rem;
        min-height: 52px;
    }
    .login-btn-glyph { width: 34px; height: 34px; }
}

/* ---- Very short viewports (e.g. mobile landscape) --------------- */
@media (max-height: 560px) and (max-width: 1024px) {
    .login-page { align-items: flex-start; padding-top: 1rem; }
    .login-card { min-height: auto; padding-top: 1.5rem; }
    .login-logo { width: 64px; height: 64px; margin-bottom: 10px; }
    .login-wordmark { font-size: 1.4rem; }
    .login-tagline { margin-bottom: 14px; }
    .login-providers { margin-bottom: 12px; }
}

/* ============================================================
   USER WIDGET (station selector page only) — top-right corner.
   Avatar + display name + caret; menu opens below with email,
   Preferences (disabled placeholder), Sign out.
   ============================================================ */
.user-widget {
    position: fixed;
    top: clamp(1rem, 2.5vw, 1.5rem);
    right: clamp(1rem, 2.5vw, 1.75rem);
    z-index: 20;
}
.user-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 8px 14px 8px 10px;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition);
    -webkit-tap-highlight-color: transparent;
}
.user-trigger:hover { background: rgba(255, 255, 255, 0.16); }
/* Avatar comes in two flavors:
   * `.user-avatar.is-icon`  — default stroked SVG (no picture from IdP)
   * `.user-avatar.is-photo` — img element with IdP-supplied picture
   Both are square, share the same outer size so the trigger doesn't
   reflow between providers. The image is clipped to a circle, the
   icon naturally sits inside an unclipped 22px box. */
.user-avatar {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.user-avatar.is-icon {
    opacity: 0.85;
}
.user-avatar.is-photo {
    object-fit: cover;
    background: rgba(255, 255, 255, 0.06);
}
.user-name {
    max-width: 14ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-caret { opacity: 0.65; flex-shrink: 0; }

.user-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    padding: 6px;
    background: rgba(20, 20, 25, 0.96);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.user-menu[hidden] { display: none; }
.user-menu-email {
    padding: 8px 12px 6px;
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.75rem;
    word-break: break-all;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 4px;
}
.user-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 10px;
    color: var(--text);
    font-size: 0.92rem;
    text-align: left;
    cursor: pointer;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
}
.user-menu-item:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); }
.user-menu-item:disabled { color: rgba(255, 255, 255, 0.4); cursor: not-allowed; }
.user-menu-coming-soon {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.45);
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 999px;
}
.user-menu-signout { color: #f47272; }
.user-menu-signout:hover { background: rgba(244, 114, 114, 0.12); }

/* Mobile: the user widget collapses to just the avatar. The display
   name is decorative on narrow screens — the avatar is the
   recognisable signal that "yes, you're signed in". The caret stays
   so the dropdown affordance is still discoverable. */
@media (max-width: 480px) {
    .user-trigger {
        padding: 6px 10px 6px 6px;
        gap: 0.3rem;
    }
    .user-name { display: none; }
}

/* ===========================================================================
 * Chat surface — thread + input. Mounted inside the info-panel's Chat tab.
 * =========================================================================== */
.chat-sheet-thread {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* Firefox + modern Chromium: themed thin scrollbar without the
     * vendor prefix dance. Older Safari falls through to the
     * ::-webkit rules below. */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}
/* WebKit-flavoured browsers (Safari, older Chromium). Setting these
 * EXPLICITLY overrides macOS's "system" overlay scrollbar that was
 * leaking through the thin styles. The 2px transparent border on
 * the thumb (via background-clip:padding-box) keeps it visually
 * compact while still meeting click-target size. */
.chat-sheet-thread::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
.chat-sheet-thread::-webkit-scrollbar-track {
    background: transparent;
}
.chat-sheet-thread::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
.chat-sheet-thread::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
    background-clip: padding-box;
}
.chat-sheet-thread::-webkit-scrollbar-corner {
    background: transparent;
}
/* Same treatment for the growing input textarea — it has its own
 * scrollbar once the user types past max-height. */
.chat-sheet-input textarea {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}
.chat-sheet-input textarea::-webkit-scrollbar {
    width: 8px;
}
.chat-sheet-input textarea::-webkit-scrollbar-track {
    background: transparent;
}
.chat-sheet-input textarea::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
.chat-sheet-input textarea::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
    background-clip: padding-box;
}
.chat-empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem 1rem;
    font-size: 0.95rem;
    line-height: 1.5;
}
.chat-starters {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 1rem;
}
.chat-starter {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: left;
    transition: background var(--transition);
    font-size: 0.9rem;
}
.chat-starter:hover { background: var(--surface-hover); }
.chat-msg-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 6px;
}
.chat-msg-group.is-user { align-items: flex-end; }
.chat-msg-group.is-assistant { align-items: flex-start; }
.chat-msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
}
.chat-msg-group.is-user .chat-msg-row { flex-direction: row-reverse; }
.chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    object-fit: cover;
    background: var(--surface);
    flex-shrink: 0;
}
/* ── iOS-style chat bubbles ────────────────────────────────────────────
 * Tails are drawn as inline-SVG background images on a tiny pseudo
 * element pinned to the bottom-outer corner of each bubble. The SVG's
 * fill color matches the bubble's background; everything outside the
 * tail path is transparent, so an avatar sitting next to the bubble
 * shows through cleanly.
 *
 * Why SVG instead of clip-path: clip-path: path() is only ~4 years
 * old in browsers and silently no-ops in older webviews. Inline-SVG
 * backgrounds work everywhere back to IE9 and render the same on
 * every device.
 *
 * Path geometry (14×18 viewBox):
 *   - Attaches along a 4-unit-wide stripe at the top edge
 *   - Right side curves outward to a rounded tip at the bottom-outer
 *     corner of the viewBox
 *   - Left side curves back up to the attach edge
 * The assistant variant uses the horizontally-mirrored path. */
.chat-msg-bubble {
    position: relative;
    padding: 9px 13px;
    border-radius: 18px;
    line-height: 1.4;
    font-size: 0.92rem;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* User bubble — solid accent, tail bottom-right. The bottom-RIGHT
 * corner is tightened to 4px so the bubble's outer edge extends
 * straight down to meet the tail. Without this, border-radius 18px
 * curves the corner inward and the tail (anchored 10px outside)
 * reads as a detached blob. */
.chat-msg-group.is-user .chat-msg-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg-group.is-user .chat-msg-bubble::after {
    content: "";
    position: absolute;
    bottom: 0;
    right: -10px;
    width: 14px;
    height: 18px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 18'><path d='M0 0 C 0 10 4 16 14 18 C 8 16 4 12 4 0 Z' fill='%23007AFF'/></svg>");
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

/* Assistant bubble — OPAQUE fill, no border, tail bottom-left. The
 * bottom-LEFT corner is tightened to 4px (mirror of the user side)
 * so the bubble's outer edge extends straight down to meet the tail.
 *
 * CRITICAL: fill must be opaque, not rgba(...). The tail pseudo
 * overlaps the bubble's content area by ~4px at the attach edge —
 * if both layers are translucent, the overlap zone composites to
 * ~2× alpha and a visible seam appears where the tail meets the
 * bubble. #353740 is the perceptual equivalent of
 * rgba(255,255,255,0.14) over the panel bg rgb(20,22,32), so the
 * bubble keeps the same visual weight without the stacking artifact. */
.chat-msg-group.is-assistant .chat-msg-bubble {
    background: #353740;
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.chat-msg-group.is-assistant .chat-msg-bubble::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: -10px;
    width: 14px;
    height: 18px;
    /* Horizontal mirror of the user path, fill matches bubble exactly
     * (#353740 = %23353740 url-encoded). */
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 18'><path d='M14 0 C 14 10 10 16 0 18 C 6 16 10 12 10 0 Z' fill='%23353740'/></svg>");
    background-repeat: no-repeat;
    background-size: 100% 100%;
}
.chat-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 9px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    width: fit-content;
}
.chat-typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: chat-dot 1.4s ease-in-out infinite;
}
.chat-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-dot {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}
.chat-sheet-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}
.chat-sheet-input textarea {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text);
    padding: 9px 14px;
    font-size: 0.95rem;
    line-height: 1.35;
    resize: none;
    max-height: 140px;
    font-family: inherit;
}
.chat-sheet-input textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.chat-sheet-send {
    background: var(--accent);
    border: 0;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity var(--transition);
}
.chat-sheet-send:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.chat-sheet-send svg { width: 18px; height: 18px; }

/* Mobile tweaks for the chat surface. */
@media (max-width: 480px) {
    .chat-msg-row { max-width: 92%; }
}
