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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0f0f0f;
    color: #e1e1e1;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.container {
    width: 100%;
    max-width: 560px;
    padding: 2rem;
}

/* Tab navigation */
.tab-bar {
    display: flex;
    gap: 0;
    margin-bottom: 1.75rem;
    padding: 4px;
    background: #1a1a1a;
    border-radius: 12px;
    border: 1px solid #2a2a2a;
}

.tab-btn {
    flex: 1;
    padding: 0.65rem 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #888;
    background: transparent;
    border: none;
    border-radius: 9px;
    cursor: pointer;
    transition: color 0.2s, background 0.2s, box-shadow 0.2s;
    white-space: nowrap;
}

.tab-btn:hover {
    color: #ccc;
}

.tab-btn.active {
    color: #fff;
    background: linear-gradient(145deg, #2a2a2a, #1f1f1f);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.stub {
    text-align: center;
    padding: 2.5rem 1.5rem;
    background: #1a1a1a;
    border: 1px dashed #333;
    border-radius: 12px;
    color: #888;
}

.stub-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    opacity: 0.6;
}

.stub h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #bbb;
    margin-bottom: 0.5rem;
}

.stub p {
    font-size: 0.9rem;
    line-height: 1.5;
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.subtitle {
    color: #888;
    font-size: 0.9rem;
    margin-bottom: 2rem;
}

.form-group {
    display: flex;
    gap: 0.5rem;
}

input[type="text"] {
    flex: 1;
    padding: 0.75rem 1rem;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 8px;
    color: #e1e1e1;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

input[type="text"]:focus { border-color: #ff4444; }
input[type="text"]::placeholder { color: #555; }

.btn {
    padding: 0.75rem 1.5rem;
    background: #ff4444;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.btn:hover { background: #e03333; }
.btn:active { background: #cc2222; }
.btn:disabled { background: #333; color: #666; cursor: not-allowed; }

.status {
    margin-top: 1rem;
    font-size: 0.9rem;
    min-height: 1.4rem;
}

.status.error { color: #ff6b6b; }
.status.loading { color: #888; }
.status.success { color: #66bb6a; }

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #555;
    border-top-color: #ff4444;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 0.4rem;
}

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

.video-info {
    margin-top: 1.5rem;
    display: none;
}

.video-info.visible { display: block; }

.video-header {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.2rem;
}

.video-thumb {
    width: 160px;
    height: 90px;
    border-radius: 6px;
    object-fit: cover;
    background: #1a1a1a;
    flex-shrink: 0;
}

.video-title {
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.4;
    align-self: center;
}

.formats-label {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 0.6rem;
}

.formats-grid {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.format-card {
    padding: 0.6rem 1rem;
    background: #1a1a1a;
    border: 2px solid #333;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
    min-width: 80px;
}

.format-card:hover { border-color: #555; }

.format-card.selected {
    border-color: #ff4444;
    background: #1f1010;
}

.format-card .res {
    font-size: 1rem;
    font-weight: 600;
}

.format-card .size {
    font-size: 0.8rem;
    color: #888;
    margin-top: 0.15rem;
}

.format-card .cost {
    font-size: 0.75rem;
    color: #f5a623;
    margin-top: 0.25rem;
    font-weight: 600;
}

/* Playlist */
.playlist-info {
    margin-top: 1.5rem;
    display: none;
}

.playlist-info.visible { display: block; }

.playlist-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.playlist-count {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 0.8rem;
}

.playlist-videos {
    max-height: 200px;
    overflow-y: auto;
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
}

.playlist-video-item {
    padding: 0.3rem 0;
    font-size: 0.85rem;
    color: #ccc;
    border-bottom: 1px solid #222;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.playlist-video-item:last-child { border-bottom: none; }

.playlist-hint {
    font-size: 0.8rem;
    color: #888;
    margin: 0.75rem 0 1rem;
    line-height: 1.4;
}

/* Auth + tokens */
.app-header {
    margin-bottom: 1.25rem;
    padding: 1rem 1.1rem;
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
}

.auth-hint {
    font-size: 0.82rem;
    color: #999;
    margin-bottom: 0.75rem;
    line-height: 1.45;
}

.tg-login-container {
    min-height: 40px;
}

#authUser.auth-block {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.token-balance {
    font-size: 0.95rem;
    color: #ccc;
}

.token-balance strong {
    color: #f5a623;
    font-weight: 700;
}

.btn-secondary {
    background: #2a2a2a;
    color: #ccc;
    border: 1px solid #444;
    padding: 0.45rem 0.9rem;
    font-size: 0.85rem;
    border-radius: 8px;
    cursor: pointer;
}

.btn-secondary:hover {
    background: #333;
    color: #fff;
}
