:root {
    --bg-color: #0b0e14;
    --card-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --primary: #00ffa3; /* Chzzk Green */
    --primary-glow: rgba(0, 255, 163, 0.3);
    --secondary: #8b5cf6; /* Purple */
    --text-main: #ffffff;
    --text-muted: #94a3b8;
    --error: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(at 0% 0%, rgba(139, 92, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(0, 255, 163, 0.1) 0px, transparent 50%);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

.container {
    width: 100%;
    max-width: 600px;
    padding: 2rem;
    z-index: 1;
}

.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2.5rem;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    text-align: center;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

p.subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 2.5rem;
    font-size: 0.9rem;
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem 1rem 1rem 3rem;
    color: white;
    font-size: 1rem;
    transition: all 0.3s ease;
}

input[type="text"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.input-icon {
    position: absolute;
    left: 1rem;
    color: var(--text-muted);
}

.options-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

select {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.8rem;
    color: white;
    font-size: 0.9rem;
    appearance: none;
    cursor: pointer;
}

.download-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--primary), #00d488);
    border: none;
    border-radius: 12px;
    padding: 1.2rem;
    color: #0b0e14;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.download-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--primary-glow);
}

.download-btn:active:not(:disabled) {
    transform: translateY(0);
}

.download-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--text-muted);
    box-shadow: none;
}

.progress-container {
    margin-top: 2.5rem;
    padding-top: 2rem;
    border-top: 1px solid var(--glass-border);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.8rem;
    font-size: 0.9rem;
}

.progress-bar-bg {
    width: 100%;
    height: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px var(--primary-glow);
}

.log-container {
    margin-top: 1.5rem;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    padding: 1rem;
    height: 150px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    border: 1px solid var(--glass-border);
}

.log-line {
    margin-bottom: 0.3rem;
    color: var(--text-muted);
}

.log-line.stdout { color: var(--text-main); }
.log-line.stderr { color: var(--error); }
.log-line.status { color: var(--primary); font-weight: bold; }

/* Custom Scrollbar */
.log-container::-webkit-scrollbar {
    width: 6px;
}
.log-container::-webkit-scrollbar-track {
    background: transparent;
}
.log-container::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 3px;
}

/* Cookie Section */
.cookie-section {
    margin-bottom: 1.5rem;
    background: rgba(139, 92, 246, 0.08);
    border: 1px solid rgba(139, 92, 246, 0.25);
    border-radius: 16px;
    padding: 1.2rem;
}

.cookie-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
}

.required {
    color: var(--error);
    font-size: 0.75rem;
    margin-left: 0.3rem;
}

.optional {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: 0.3rem;
}

.help-btn {
    background: rgba(139, 92, 246, 0.2);
    border: 1px solid rgba(139, 92, 246, 0.4);
    border-radius: 8px;
    color: #a78bfa;
    font-size: 0.75rem;
    padding: 0.3rem 0.7rem;
    cursor: pointer;
    transition: all 0.2s;
}

.help-btn:hover {
    background: rgba(139, 92, 246, 0.35);
}

.cookie-help {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 0.9rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.82rem;
    line-height: 1.9;
    color: var(--text-muted);
}

.cookie-help strong { color: var(--text-main); }
.cookie-help code {
    background: rgba(255,255,255,0.1);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-family: monospace;
    color: var(--primary);
}

.cookie-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.cookie-inputs .input-group { margin-bottom: 0; }

/* Tab Bar */
.tab-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background: rgba(0,0,0,0.2);
    border-radius: 12px;
    padding: 4px;
}
.tab-btn {
    flex: 1;
    padding: 0.6rem;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.tab-btn.active {
    background: rgba(0,255,163,0.12);
    color: var(--primary);
    border: 1px solid rgba(0,255,163,0.25);
}
.tab-btn:hover:not(.active) { color: var(--text-main); }

/* Channel clips */
.channel-input-row {
    display: flex;
    gap: 0.8rem;
    margin-bottom: 1rem;
}
.channel-input-row .input-wrapper input {
    padding-left: 3rem;
}
.load-btn {
    padding: 0 1.2rem;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), #00d488);
    color: #0b0e14;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}
.load-btn:hover:not(:disabled) { filter: brightness(1.1); }
.load-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.clips-error {
    background: rgba(239,68,68,0.08);
    border: 1px solid rgba(239,68,68,0.25);
    border-radius: 10px;
    padding: 0.8rem 1rem;
    color: var(--error);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}
.clips-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 2rem 0;
}
.clips-header {
    margin-bottom: 0.8rem;
}
.clips-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.clip-list {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    max-height: 420px;
    overflow-y: auto;
    padding-right: 4px;
}
.clip-list::-webkit-scrollbar { width: 4px; }
.clip-list::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 2px; }

.clip-item {
    display: flex;
    gap: 0.8rem;
    align-items: flex-start;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.8rem;
    transition: border-color 0.2s;
}
.clip-item:hover { border-color: rgba(0,255,163,0.25); }

.clip-thumb {
    width: 80px;
    min-width: 80px;
    height: 45px;
    border-radius: 7px;
    object-fit: cover;
    background: rgba(255,255,255,0.05);
}
.clip-thumb-placeholder {
    width: 80px;
    min-width: 80px;
    height: 45px;
    border-radius: 7px;
    background: rgba(255,255,255,0.05);
}
.clip-info { flex: 1; min-width: 0; }
.clip-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 3px;
}
.clip-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.clip-dl-btn {
    background: rgba(0,255,163,0.1);
    border: 1px solid rgba(0,255,163,0.3);
    border-radius: 7px;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 10px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.clip-dl-btn:hover:not(:disabled) { background: rgba(0,255,163,0.2); }
.clip-dl-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.clip-dl-btn.done { background: rgba(0,255,163,0.15); color: var(--primary); border-color: var(--primary); }
.clip-dl-btn.err { background: rgba(239,68,68,0.1); color: var(--error); border-color: var(--error); }

.load-more-btn {
    width: 100%;
    margin-top: 0.8rem;
    padding: 0.7rem;
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}
.load-more-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.load-more-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Cookie saved toast */
.cookie-saved-toast {
    background: rgba(0, 255, 163, 0.15);
    border: 1px solid rgba(0, 255, 163, 0.4);
    border-radius: 12px;
    padding: 0.8rem 1.2rem;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease;
}

/* Cookie saved badge */
.cookie-saved-badge {
    display: inline-block;
    background: rgba(0, 255, 163, 0.15);
    border: 1px solid rgba(0, 255, 163, 0.35);
    border-radius: 6px;
    color: var(--primary);
    font-size: 0.68rem;
    font-weight: 700;
    padding: 1px 7px;
    margin-left: 8px;
    vertical-align: middle;
}

/* Cookie header actions */
.cookie-header-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-shrink: 0;
}

.cookie-action-btn {
    border: none;
    border-radius: 8px;
    font-size: 0.73rem;
    font-weight: 600;
    padding: 0.3rem 0.7rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.check-btn {
    background: rgba(0, 255, 163, 0.12);
    border: 1px solid rgba(0, 255, 163, 0.3);
    color: var(--primary);
}
.check-btn:hover:not(:disabled) { background: rgba(0, 255, 163, 0.22); }
.check-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.clear-btn {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #f87171;
}
.clear-btn:hover { background: rgba(239, 68, 68, 0.2); }

/* Cookie check result */
.cookie-check-result {
    border-radius: 10px;
    padding: 0.6rem 0.9rem;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 0.8rem;
}
.cookie-check-result.valid {
    background: rgba(0, 255, 163, 0.08);
    border: 1px solid rgba(0, 255, 163, 0.3);
    color: var(--primary);
}
.cookie-check-result.invalid {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #f87171;
}

/* Bookmarklet section in help */
.help-section {
    background: rgba(0, 255, 163, 0.05);
    border: 1px solid rgba(0, 255, 163, 0.15);
    border-radius: 10px;
    padding: 0.8rem;
    margin-bottom: 0.8rem;
}
.help-section strong {
    display: block;
    color: var(--primary) !important;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
}

.bookmarklet-btn {
    background: linear-gradient(135deg, rgba(0, 255, 163, 0.2), rgba(0, 255, 163, 0.1));
    border: 1px solid rgba(0, 255, 163, 0.4);
    border-radius: 8px;
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all 0.2s;
    margin: 0.5rem 0;
    width: 100%;
}
.bookmarklet-btn:hover { background: linear-gradient(135deg, rgba(0, 255, 163, 0.3), rgba(0, 255, 163, 0.15)); }

.help-divider {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin: 0.6rem 0;
    position: relative;
}
.help-divider::before, .help-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 35%;
    height: 1px;
    background: var(--glass-border);
}
.help-divider::before { left: 0; }
.help-divider::after { right: 0; }

.help-note {
    font-size: 0.75rem !important;
    color: rgba(148, 163, 184, 0.7) !important;
    font-style: italic;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── PIN / QR 공유 섹션 ── */
.share-section {
    margin-bottom: 1.2rem;
}

.share-toggle-btn {
    width: 100%;
    padding: 0.65rem 1rem;
    background: rgba(139, 92, 246, 0.1);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 12px;
    color: #a78bfa;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.share-toggle-btn:hover:not(:disabled) { background: rgba(139, 92, 246, 0.2); }
.share-toggle-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.share-box {
    margin-top: 0.8rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    padding: 1.2rem;
    text-align: center;
}

.share-pin-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}
.share-ttl {
    font-size: 0.72rem;
    opacity: 0.7;
}

.share-pin {
    font-size: 2.8rem;
    font-weight: 800;
    letter-spacing: 0.4em;
    color: var(--primary);
    font-family: 'Courier New', monospace;
    margin-bottom: 1rem;
    text-shadow: 0 0 20px var(--primary-glow);
}

.share-qr {
    display: inline-block;
    background: rgba(11, 14, 20, 0.8);
    border-radius: 12px;
    padding: 0.8rem;
    margin-bottom: 0.6rem;
}
.share-qr img {
    display: block;
    border-radius: 6px;
}
.share-qr-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

.share-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* PIN 입력 (모바일) */
.pin-input-row {
    display: flex;
    gap: 0.6rem;
    align-items: center;
}

.pin-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.8rem 1rem;
    color: white;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.25em;
    text-align: center;
    font-family: 'Courier New', monospace;
    transition: all 0.2s;
    width: 100%;
}
.pin-input:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.3);
}
.pin-input::placeholder {
    font-size: 0.85rem;
    letter-spacing: normal;
    font-weight: 400;
    font-family: 'Inter', sans-serif;
    color: var(--text-muted);
}

.pin-load-btn {
    padding: 0.8rem 1.2rem;
    background: linear-gradient(135deg, var(--secondary), #7c3aed);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}
.pin-load-btn:hover:not(:disabled) { filter: brightness(1.15); }
.pin-load-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.pin-error {
    margin-top: 0.5rem;
    font-size: 0.82rem;
    color: #f87171;
    text-align: center;
}

/* ── Mobile ── */
@media (max-width: 520px) {
    body {
        align-items: flex-start;
        padding: 0;
    }

    .container {
        padding: 1rem;
        max-width: 100%;
    }

    .glass-card {
        padding: 1.4rem 1.2rem;
        border-radius: 16px;
    }

    h1 { font-size: 1.9rem; }

    /* 쿠키 헤더: 두 줄로 감싸기 */
    .cookie-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .cookie-header > span {
        flex: 1 1 100%;
        font-size: 0.82rem;
    }
    .cookie-header-actions {
        flex: 1 1 100%;
        justify-content: flex-start;
    }
    .cookie-saved-badge {
        display: block;
        margin: 4px 0 0 0;
        width: fit-content;
    }

    /* 쿠키 입력: 1열로 */
    .cookie-inputs {
        grid-template-columns: 1fr;
    }
    .cookie-inputs .input-group { margin-bottom: 0.8rem; }
    .cookie-inputs .input-group:last-child { margin-bottom: 0; }

    /* 화질 선택: 1열로 */
    .options-row {
        grid-template-columns: 1fr;
    }

    /* 채널 입력: 버튼을 아래로 */
    .channel-input-row {
        flex-direction: column;
    }
    .load-btn {
        width: 100%;
        padding: 0.8rem;
    }

    /* 클립 썸네일 조금 작게 */
    .clip-thumb,
    .clip-thumb-placeholder {
        width: 64px;
        min-width: 64px;
        height: 36px;
    }

    /* 액션 버튼들 줄바꿈 허용 */
    .cookie-action-btn {
        font-size: 0.7rem;
        padding: 0.3rem 0.55rem;
    }

    input[type="text"],
    input[type="password"] {
        font-size: 0.95rem;
    }
}
