/* ============================================================
   TikTok Widget — Styles
   ============================================================ */

/* ── Shared base ────────────────────────────────────────────── */
.tw-feed {
    --tw-primary: #fe2c55;
    --tw-dark:    #010101;
    --tw-text:    #333;
    --tw-muted:   #777;
    --tw-bg:      #f4f4f4;
    --tw-radius:  10px;
    --tw-gap:     10px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    box-sizing: border-box;
}

.tw-feed *,
.tw-feed *::before,
.tw-feed *::after {
    box-sizing: inherit;
}

.tw-notice {
    color: var(--tw-muted, #777);
    font-size: 13px;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 6px;
    margin: 0;
}

.tw-notice.tw-error {
    color: #c0392b;
    background: #fdf0ef;
    border: 1px solid #f5c6c6;
}

.tw-follow-link {
    text-align: center;
    margin: 14px 0 0;
    padding: 0;
}

.tw-follow-link a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--tw-primary);
    text-decoration: none;
    transition: opacity 0.2s;
}

.tw-follow-link a:hover { opacity: 0.8; }

.tw-follow-link svg {
    width: 14px;
    height: 14px;
    fill: var(--tw-primary);
}

/* ── Thumbnail shared ───────────────────────────────────────── */
.tw-thumb {
    position: relative;
    overflow: hidden;
    border-radius: var(--tw-radius);
    background: var(--tw-bg);
    aspect-ratio: 9 / 16;
}

.tw-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.tw-card:hover .tw-thumb img {
    transform: scale(1.06);
}

.tw-thumb-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--tw-bg);
}

.tw-thumb-placeholder svg {
    width: 40px;
    height: 40px;
    fill: #ccc;
}

.tw-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.tw-card:hover .tw-overlay {
    background: rgba(0, 0, 0, 0.35);
}

.tw-play-icon {
    opacity: 0;
    transform: scale(0.7);
    transition: opacity 0.2s, transform 0.2s;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tw-play-icon svg {
    width: 22px;
    height: 22px;
    fill: var(--tw-primary);
    margin-left: 3px;
}

.tw-card:hover .tw-play-icon {
    opacity: 1;
    transform: scale(1);
}

.tw-views {
    position: absolute;
    bottom: 6px;
    left: 7px;
    font-size: 11px;
    color: #fff;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,0.7);
    pointer-events: none;
}

.tw-caption {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--tw-text);
    line-height: 1.4;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ── Stats row ──────────────────────────────────────────────── */
.tw-stats {
    display: flex;
    gap: 10px;
    margin: 5px 0 0;
    flex-wrap: wrap;
}

.tw-stat {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 12px;
    color: var(--tw-muted);
}

.tw-stat svg {
    width: 13px;
    height: 13px;
    fill: var(--tw-muted);
}

/* ============================================================
   LAYOUT: GRID
   ============================================================ */
.tw-grid {
    display: grid;
    gap: var(--tw-gap);
}

.tw-grid.tw-cols-2 { grid-template-columns: repeat(2, 1fr); }
.tw-grid.tw-cols-3 { grid-template-columns: repeat(3, 1fr); }

.tw-card--grid {
    display: block;
    text-decoration: none;
    color: inherit;
    border-radius: var(--tw-radius);
    overflow: hidden;
}

/* Sidebar: force 2-col when container is narrow */
@media (max-width: 320px) {
    .tw-grid.tw-cols-3 { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   LAYOUT: LIST
   ============================================================ */
.tw-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tw-card--list {
    display: flex;
    gap: 12px;
    text-decoration: none;
    color: inherit;
    align-items: flex-start;
    padding: 8px;
    border-radius: var(--tw-radius);
    transition: background 0.2s;
}

.tw-card--list:hover {
    background: #f4f4f4;
}

.tw-thumb--list {
    flex: 0 0 76px;
    width: 76px;
    aspect-ratio: 9 / 16;
}

.tw-card--list .tw-meta {
    flex: 1;
    min-width: 0;
    padding-top: 2px;
}

.tw-card--list .tw-caption {
    font-size: 13px;
    -webkit-line-clamp: 3;
    margin: 0 0 6px;
}

/* ============================================================
   LAYOUT: CAROUSEL
   ============================================================ */
.tw-carousel {
    position: relative;
}

.tw-carousel__track-wrap {
    position: relative;
    overflow: hidden;
}

.tw-carousel__track {
    display: flex;
    gap: var(--tw-gap);
    overflow-x: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
}

.tw-carousel__track::-webkit-scrollbar { display: none; }

.tw-card--carousel {
    display: block;
    text-decoration: none;
    color: inherit;
    flex: 0 0 140px;
    border-radius: var(--tw-radius);
    overflow: hidden;
    transition: transform 0.2s;
}

.tw-card--carousel:hover {
    transform: translateY(-2px);
}

.tw-thumb--carousel {
    width: 140px;
    aspect-ratio: 9 / 16;
}

.tw-stats--carousel {
    justify-content: center;
    margin-top: 4px;
}

/* Nav buttons */
.tw-carousel__btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    padding: 0;
    transition: box-shadow 0.2s, opacity 0.2s;
    opacity: 0.85;
}

.tw-carousel__btn:hover { opacity: 1; box-shadow: 0 3px 10px rgba(0,0,0,0.2); }
.tw-carousel__btn--prev { left: -14px; }
.tw-carousel__btn--next { right: -14px; }
.tw-carousel__btn svg { width: 18px; height: 18px; fill: var(--tw-dark); }

.tw-carousel__btn.is-hidden { opacity: 0; pointer-events: none; }

/* Dots */
.tw-carousel__dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
}

.tw-carousel__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #ddd;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

.tw-carousel__dot.is-active {
    background: var(--tw-primary);
    transform: scale(1.3);
}

/* ── In-post / wide context: bigger carousel cards ─────────── */
@media (min-width: 600px) {
    .tw-card--carousel {
        flex: 0 0 160px;
    }
    .tw-thumb--carousel {
        width: 160px;
    }
}
