:root {
    --background: #15202b;
    /*--background: #081725;*/
    --card-bg: #1d272a;
    --reply-bg: #1c2733;
    --text-primary: #e1e8ed;
    --text-secondary: #8899a6;
    --border: #38444d;
    --border-light: rgba(255, 255, 255, 0.05);
    --blue-verified: #1da1f2;
    --gold-verified: #FFD700;
    --quoted-bg: #16181c;
    /*--header-bg: #1c2526;*/
    --header-bg: #171e1f;
    --button-bg: #1da1f2;
    --status-bg: #5e2b2b;
    --url-bg: #2563eb;
    --accent-title-color: #1DA1F2;
    --accent-pause-color: #ff4444;
}

html, body {
    overflow: hidden;
    height: 100%;
    margin: 0;
    padding: 0;
    overscroll-behavior-y: contain;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.tracker-container {
    max-width: 550px;
    margin: 0 auto;
    padding: 16px;
    box-sizing: border-box;
    height: 100%;
    min-height: 100vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.tracker-container::-webkit-scrollbar {
    display: none;
}

#tweets {
    overflow-y: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    max-height: calc(var(--tg-viewport-height, 100vh) - 80px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding-bottom: 32px;
    box-sizing: border-box;
}

#tweets::-webkit-scrollbar {
    display: none;
}

#tweets > .tweet-wrapper:last-child {
    margin-bottom: 16px;
}

.header {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 1000;
    align-items: center;
    justify-content: space-between;
    background: var(--header-bg);
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 16px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.header:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.header-logo:hover {
    transform: scale(1.05);
}

.header-title {
    font-size: 18px;
    font-weight: bold;
    color: var(--text-primary);
    transition: color 0.3s ease;
    white-space: nowrap;
}

.header-title:hover {
    color: var(--accent-title-color, #1DA1F2);
}

.pause-indicator {
    font-size: 18px;
    color: var(--accent-pause-color, #ff4444);
    margin-left: 5px;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
}

.pause-indicator svg {
    width: 16px;
    height: 16px;
    vertical-align: middle;
}

.pause-indicator:hover {
    color: #cc0000;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 50%;
}

.start-tracking-btn, .open-in-browser-btn {
    width: 100%;
    height: 48px;
    background: var(--button-bg, #1DA1F2);
    color: var(--button-text, white);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease;
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    margin-bottom: 16px;
}

.start-tracking-btn:hover, .open-in-browser-btn:hover {
    background: #0d8bd9;
}

.start-tracking-btn:active, .open-in-browser-btn:active {
    transform: translateY(1px);
}

.telegram-login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 16px;
    box-sizing: border-box;
    margin-top: 20px;
}

.telegram-login-inner {
    width: 100%;
    max-width: 320px;
    display: flex;
    justify-content: center;
}

.scroll-top-btn {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom));
    right: calc(24px + env(safe-area-inset-right));
    width: 48px;
    height: 48px;
    background: rgba(29, 161, 242, 1);
    border-radius: 12px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    transition: opacity 0.3s ease, transform 0.3s ease, background 0.3s ease;
    z-index: 2000;
    border: 2px solid #fff;
}

.scroll-top-btn.visible {
    display: flex !important;
    opacity: 1;
    transform: translateY(0);
}

.scroll-top-btn.hidden {
    opacity: 0;
    transform: translateY(20px);
}

.scroll-top-btn:hover {
    background: var(--blue-verified);
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.scroll-top-btn:active {
    transform: scale(0.95);
}

.scroll-top-btn svg {
    width: 24px;
    height: 24px;
    fill: var(--text-primary);
    transition: fill 0.3s ease;
}

.scroll-top-btn:hover svg {
    fill: #fff;
}

.connection-status {
    background: var(--status-bg);
    color: var(--text-primary);
    padding: 10px 20px;
    text-align: center;
    font-size: 16px;
    margin: 12px 0;
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.sound-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.sound-label {
    font-size: 14px;
    color: var(--text-secondary);
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #1da1f2;
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.switch.disabled .slider {
    background-color: #999;
    cursor: not-allowed;
}

.switch.disabled .slider:before {
    background-color: #ccc;
}

.switch.disabled input:checked + .slider {
    background-color: #999;
}

.tweet-wrapper {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
    opacity: 0;
    transform: translateY(-20px) scale(0.98);
    transition: opacity 0.5s ease, transform 0.5s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.tweet-wrapper:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.tweet-wrapper.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.tweet-header {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    position: relative;
    justify-content: space-between;
}

.tweet-header img.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    margin-right: 12px;
    transition: transform .2s ease;
}

.tweet-header img.avatar:hover {
    transform: scale(1.05);
}

.tweet-header .names {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    margin-right: 12px;
}

.tweet-header .names .full-name {
    font-weight: bold;
    font-size: 16px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.tweet-header .names .handle {
    font-size: 14px;
    color: var(--text-secondary);
}

a.handle {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.3s ease;
}

a.handle:hover {
    color: var(--blue-verified);
    text-decoration: underline;
}

.tweet-header .tweet-copy-link,
.tweet-header .tweet-link {
    margin-left: 8px;
    color: var(--text-secondary);
    transition: color 0.3s ease, transform 0.3s ease;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.tweet-header .tweet-copy-link:hover,
.tweet-header .tweet-link:hover {
    color: var(--blue-verified);
    transform: scale(1.1);
}

.tweet-header .tweet-copy-link.copied {
    color: #28a745;
}

.tweet-header .tweet-copy-link svg,
.tweet-header .tweet-link svg {
    width: 20px;
    height: 20px;
}

.tweet-timer {
    font-size: 14px;
    font-weight: bold;
}

.tweet-text {
    font-size: 16px;
    line-height: 1.5;
    margin-bottom: 12px;
    word-wrap: break-word;
    color: var(--text-primary);
}

.tweet-media, .quoted-tweet .tweet-media {
    /*display: flex;*/
    /*flex-wrap: wrap;*/
    /*gap: 8px;*/
    margin: 8px 0;
    max-width: 100%;
    margin-bottom: 16px;
    position: relative;
}

.tweet-media img,
.tweet-media video {
    border-radius: 8px;
    width: 100%;
    object-fit: contain;
    display: block;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: opacity 0.3s ease;
}

.video-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-shadow: 0 0 5px black;
    pointer-events: none;
    z-index: 10;
}

.tweet-media iframe {
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tweet-media.carousel {
    position: relative;
    overflow: hidden;
    width: 100%;
}

.tweet-media.carousel .carousel-inner {
    position: relative;
    width: 100%;
}

.tweet-media.carousel img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tweet-media.carousel img.active {
    opacity: 1;
    position: relative;
}

.tweet-media.carousel img.hidden {
    opacity: 0;
}

.tweet-media.carousel .carousel-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 20px;
    line-height: 32px;
    text-align: center;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
}

.tweet-media.carousel .carousel-arrow.left {
    left: 8px;
}

.tweet-media.carousel .carousel-arrow.right {
    right: 8px;
}

.tweet-media.carousel .carousel-arrow:hover {
    opacity: 1;
    transform: translateY(-50%) scale(1.1);
}

.tweet-media.carousel .carousel-arrow.left svg {
    transform: rotate(180deg);
}

.tweet-media.carousel .carousel-arrow svg {
    width: 20px;
    height: 20px;
    fill: white;
    transition: fill 0.3s ease;
}

.tweet-media.carousel .carousel-arrow:hover svg {
    fill: #ffeb3b;
}

.tweet-media.carousel .carousel-dots {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
}

.tweet-media.carousel .carousel-dot {
    width: 8px;
    height: 8px;
    background: #bbb;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.tweet-media.carousel .carousel-dot.active {
    background: #1DA1F2;
}

.reply-tweet {
    background: var(--reply-bg);
    border-radius: 12px;
    padding: 12px;
    margin-top: 16px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.reply-header {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.reply-header img.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 8px;
    transition: transform .2s ease;
}

.reply-header img.avatar:hover {
    transform: scale(1.05);
}

.reply-header .names {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.reply-header .names .full-name {
    font-weight: bold;
    font-size: 14px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.reply-header .names .handle {
    font-size: 12px;
    color: var(--text-secondary);
}

.reply-text {
    font-size: 16px;
    line-height: 1.5;
    margin-bottom: 12px;
    word-wrap: break-word;
    color: var(--text-primary);
}

.gold-verified svg, .blue-verified svg {
    fill: none;
    stroke: var(--gold-verified);
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease;
}

.blue-verified svg {
    stroke: var(--blue-verified);
}

.gold-verified:hover svg, .blue-verified:hover svg {
    transform: scale(1.1);
}

.quoted-tweet {
    background: var(--quoted-bg);
    border-radius: 12px;
    padding: 12px;
    margin: 12px 0 0 0;
    margin-bottom: 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.quoted-header {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.quoted-header img.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin-right: 8px;
    transition: transform .2s ease;
}

.quoted-header img.avatar:hover {
    transform: scale(1.05);
}

.quoted-header .names {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.quoted-header .names .full-name {
    font-weight: bold;
    font-size: 14px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.quoted-header .names .handle {
    font-size: 12px;
    color: var(--text-secondary);
}

.text {
    font-size: 15px;
    line-height: 1.5;
    margin-bottom: 12px;
    word-wrap: break-word;
    color: var(--text-primary);
}

.tweet-text a, .text a, .reply-text a {
    color: var(--url-bg);
    transition: color 0.2s ease;
    text-decoration: none;
}

.tweet-text a:hover, .text a:hover, .reply-text a:hover {
    color: var(--url-bg);
    text-decoration: underline;
}

.tweet-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

@media (max-width: 600px) {

    body {
        position: fixed;
        width: 100%;
        overscroll-behavior-y: none;
    }

    .tracker-container {
        padding: 12px;
    }

    #tweets {
        max-height: calc(var(--tg-viewport-height, 100vh) - 70px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        padding-bottom: 24px;
    }

    .header {
        padding: 10px 12px;
        align-items: center;
    }

    .header-left, .header-right {
        gap: 8px;
    }

    .header-logo {
        width: 40px;
        height: 40px;
    }

    .header-title {
        font-size: 16px;
    }

    .pause-indicator {
        margin-left: 4px;
        font-size: 16px;
    }

    .pause-indicator svg {
        width: 14px;
        height: 14px;
    }

    .start-tracking-btn, .open-in-browser-btn {
        height: 40px;
        font-size: 14px;
    }

    .scroll-top-btn {
        width: 44px;
        height: 44px;
        bottom: calc(24px + env(safe-area-inset-bottom));
        right: calc(20px + env(safe-area-inset-right));
        border-radius: 10px;
    }

    .scroll-top-btn svg {
        width: 24px;
        height: 24px;
    }

    .tweet-wrapper {
        padding: 10px;
    }

    .tweet-header img.avatar, .reply-header img.avatar {
        width: 40px;
        height: 40px;
    }

    .quoted-header img.avatar {
        width: 32px;
        height: 32px;
    }

    .full-name {
        font-size: 15px;
    }

    .handle, .reply-time {
        font-size: 13px;
    }

    .tweet-text, .reply-text {
        font-size: 14px;
    }

    .sound-label {
        font-size: 13px;
    }

    .tweet-media, .quoted-tweet .tweet-media {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .tweet-media.carousel .carousel-arrow {
        display: none;
    }

    .tweet-media.carousel .carousel-dot {
        width: 8px;
        height: 8px;
    }
}

@media (max-width: 400px) {

    body {
        position: fixed;
        width: 100%;
        overscroll-behavior-y: none;
    }

    .tracker-container {
        padding: 8px;
    }

    #tweets {
        max-height: calc(var(--tg-viewport-height, 100vh) - 60px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        padding-bottom: 20px;
    }

    .header {
        padding: 8px 10px;
        justify-content: space-between;
        align-items: center;
    }

    .header-left, .header-right {
        gap: 6px;
    }

    .header-logo {
        width: 36px;
        height: 36px;
    }

    .header-title {
        font-size: 14px;
    }

    .pause-indicator {
        margin-left: 3px;
        font-size: 14px;
    }

    .pause-indicator svg {
        width: 12px;
        height: 12px;
    }

    .start-tracking-btn, .open-in-browser-btn {
        height: 36px;
        font-size: 12px;
    }

    .scroll-top-btn {
        width: 40px;
        height: 40px;
        bottom: calc(20px + env(safe-area-inset-bottom));
        right: calc(16px + env(safe-area-inset-right));
        border-radius: 8px;
    }

    .scroll-top-btn svg {
        width: 20px;
        height: 20px;
    }

    .sound-label {
        font-size: 12px;
    }

    .tweet-wrapper {
        padding: 8px;
    }

    .tweet-header img.avatar, .reply-header img.avatar {
        width: 36px;
        height: 36px;
    }

    .quoted-header img.avatar {
        width: 28px;
        height: 28px;
    }

    .full-name {
        font-size: 14px;
    }

    .handle, .reply-time {
        font-size: 12px;
    }

    .tweet-text, .reply-text {
        font-size: 13px;
    }

    .tweet-media, .quoted-tweet .tweet-media {
        flex-direction: column;
        gap: 6px;
    }

    .tweet-media.carousel .carousel-arrow {
        display: none;
    }

    .tweet-media.carousel .carousel-dot {
        width: 6px;
        height: 6px;
    }
}