@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500&display=swap');

/* Base styles */
body {
    font-family: 'Roboto', Arial, sans-serif;
    margin: 0;
    padding: 20px;
    background-color: #f8fafc;
    color: #333;
    line-height: 1.6;
}

/* Language-specific fonts */
.lang-ko { font-family: 'Noto Sans KR', 'Roboto', sans-serif; }
.lang-ja { font-family: 'Noto Sans JP', 'Roboto', sans-serif; }
.lang-zh-Hans { font-family: 'Noto Sans SC', 'Roboto', sans-serif; }
.lang-zh-Hant { font-family: 'Noto Sans TC', 'Roboto', sans-serif; }
.lang-ar { font-family: 'Noto Sans Arabic', 'Roboto', sans-serif; }
.lang-hi { font-family: 'Noto Sans Devanagari', 'Roboto', sans-serif; }

/* RTL support */
[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

[dir="rtl"] .input-container {
    flex-direction: row-reverse;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
header {
    margin-bottom: 20px;
}

.header-content {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    position: relative;
}

.language-selector-header {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

header h1 {
    font-size: 20px;
    font-weight: 700;
    color: #1f2937;
    margin: 0;
}

header h1 a {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

header h1 a:hover {
    color: #3b82f6;
}

.language-selector-header {
    display: flex;
    align-items: center;
}

.language-selector-header select {
    padding: 6px 10px;
    font-size: 14px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background-color: #fff;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.language-selector-header select:focus {
    outline: none;
    border-color: #3b82f6;
}

/* Input container */
.input-container {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    position: relative;
}

#youtube-url {
    flex-grow: 1;
    padding: 12px;
    font-size: 16px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    transition: border-color 0.3s ease;
}

#youtube-url:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#extract-btn {
    padding: 8px 16px;
    min-width: 100px;
    font-size: 16px;
    font-weight: 500;
    background: linear-gradient(135deg, #3b82f6, #1e40af);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease;
}

#extract-btn:hover {
    background: linear-gradient(135deg, #2563eb, #1e3a8a);
    transform: translateY(-1px);
}

#extract-btn:active {
    transform: translateY(0);
}

/* URL History Dropdown */
#url-history-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 110px;
    background-color: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
}

.url-history-item {
    display: flex;
    align-items: center;
    padding: 12px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.url-history-item:hover {
    background-color: #f3f4f6;
}

.history-title {
    flex-grow: 1;
    font-size: 14px;
    color: #374151;
}

.delete-history-btn {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 14px;
    margin-left: 8px;
    padding: 4px;
    border-radius: 4px;
}

.delete-history-btn:hover {
    color: #dc2626;
    background-color: #fef2f2;
}

/* Progress bar */
#progress-bar-container {
    width: 100%;
    height: 4px;
    background-color: #e5e7eb;
    margin-bottom: 20px;
    display: none;
    border-radius: 2px;
    overflow: hidden;
}

#progress-bar {
    width: 0%;
    height: 100%;
    background-color: #3b82f6;
    transition: width 0.3s ease;
}

/* Usage Guide */
#usage-guide {
    background-color: white;
    padding: 20px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 24px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

#usage-guide h2 {
    font-size: 18px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 20px;
    text-align: center;
}

#usage-guide h3 {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    margin: 16px 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid #e5e7eb;
}

#usage-guide h4 {
    font-size: 15px;
    font-weight: 600;
    color: #111827;
    margin: 12px 0 8px;
}

#usage-guide p {
    font-size: 14px;
    color: #111827;
    line-height: 1.5;
    margin: 12px 0;
}

#usage-guide ul {
    list-style: none;
    padding: 0;
    margin: 10px 0;
}

#usage-guide ul li {
    font-size: 14px;
    color: #111827;
    margin-bottom: 8px;
    position: relative;
    padding-left: 20px;
    line-height: 1.5;
}

#usage-guide ul li:before {
    content: '•';
    position: absolute;
    left: 8px;
    color: #3b82f6;
    font-weight: bold;
    font-size: 16px;
}

.method-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.method {
    background-color: #f8fafc;
    padding: 14px;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}

.problem-solution {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 0;
}

/* Results Container */
#results-container {
    display: none;
    grid-template-columns: 1fr 2fr;
    gap: 24px;
}

/* Video Info */
#video-info {
    background-color: white;
    padding: 20px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.thumbnail-container {
    position: relative;
    margin-bottom: 12px;
}

#video-thumbnail {
    width: 100%;
    max-width: 320px;
    border-radius: 8px;
    display: block;
}

.video-duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

#video-title {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 12px;
    color: #1f2937;
    text-decoration: none;
    display: block;
}

#video-title:hover {
    text-decoration: underline;
}

#video-channel, #video-views, #video-likes, #video-date {
    font-size: 14px;
    color: #6b7280;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
}

#video-channel i, #video-views i, #video-likes i, #video-date i {
    margin-right: 8px;
    color: #4b5563;
    font-size: 14px;
    width: 16px;
}

#video-channel a, #video-thumbnail-link {
    color: #3b82f6;
    text-decoration: none;
}

#video-channel a:hover, #video-thumbnail-link:hover {
    text-decoration: underline;
}

#video-description {
    font-size: 14px;
    color: #4b5563;
    margin-top: 12px;
    line-height: 1.5;
    max-height: 300px;
    overflow-y: auto;
    padding-right: 8px;
    max-width: 100%;
    word-break: break-word;
    word-wrap: break-word;
}

/* Subtitle Container */
#subtitle-container {
    background-color: white;
    padding: 20px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

#subtitle-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.subtitle-label {
    font-size: 16px;
    font-weight: 700;
    color: #1f2937;
}

.subtitle-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

#language-selector {
    padding: 8px;
    font-size: 14px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background-color: #fff;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

#language-selector:focus {
    outline: none;
    border-color: #3b82f6;
}

.action-buttons {
    display: flex;
    gap: 12px;
}

#copy-btn, #download-btn {
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

#copy-btn {
    background-color: #10b981;
    color: white;
}

#copy-btn:hover {
    background-color: #059669;
    transform: translateY(-1px);
}

#download-btn {
    background-color: #6b7280;
    color: white;
}

#download-btn:hover {
    background-color: #4b5563;
    transform: translateY(-1px);
}

#subtitle-content {
    width: 100%;
    box-sizing: border-box;
    max-height: 600px;
    overflow-y: auto;
    font-size: 15px;
    margin: 10px 0;
    padding: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background-color: #fafafa;
}

.subtitle-paragraph {
    margin: 0 0 5px 0;
    padding: 8px;
    line-height: 1.4;
    width: 100%;
    box-sizing: border-box;
    word-wrap: break-word;
    text-align: left;
    white-space: normal;
    background-color: white;
    border-radius: 4px;
    color: #000000;
}

.no-subtitles-message {
    color: #6b7280;
    font-style: italic;
    margin: 0;
    padding: 8px;
    text-align: center;
}

/* Recent Analyses Section */
.recent-analyses-section {
    background-color: white;
    padding: 20px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-top: 24px;
}

.recent-analyses-section h2 {
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 16px;
}

.recent-analyses-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.analyses-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.analysis-item {
    padding: 8px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background-color: #f9fafb;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}

.analysis-item:hover {
    background-color: #f3f4f6;
}

.analysis-date {
    color: #6b7280;
    min-width: 60px;
}

.analysis-title {
    flex: 2;
    font-weight: 500;
}

.analysis-title a {
    color: #1f2937;
    text-decoration: none;
}

.analysis-title a:hover {
    color: #3b82f6;
    text-decoration: underline;
}

.analysis-channel {
    flex: 1;
    color: #6b7280;
    text-align: center;
}

.analysis-video-date {
    color: #6b7280;
    min-width: 70px;
    text-align: center;
}

.analysis-duration {
    color: #6b7280;
    min-width: 50px;
    text-align: right;
}

.analysis-video-date {
    color: #6b7280;
    min-width: 70px;
    text-align: center;
}

.view-all-container {
    text-align: center;
}

.view-all-btn {
    display: inline-block;
    padding: 8px 16px;
    background-color: #3b82f6;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.3s ease;
}

.view-all-btn:hover {
    background-color: #2563eb;
}

/* History Page */
.history-container {
    background-color: white;
    padding: 20px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 24px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.history-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
}

.history-controls select {
    padding: 8px;
    font-size: 14px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background-color: #fff;
}

.history-table {
    display: flex;
    flex-direction: column;
}

.table-header, .table-row {
    display: grid;
    grid-template-columns: 1fr 3fr 1fr 1fr 2fr;
    gap: 12px;
    padding: 12px 0;
    align-items: center;
}

.table-header.show-all, .table-row.show-all {
    grid-template-columns: 1fr 3fr 1fr 1fr 2fr 1fr;
}

.table-header {
    font-weight: 600;
    color: #374151;
    border-bottom: 2px solid #e5e7eb;
}

.table-row {
    border-bottom: 1px solid #f3f4f6;
    transition: background-color 0.2s ease;
}

.table-row:hover {
    background-color: #f9fafb;
}

.col-title a {
    color: #1f2937;
    text-decoration: none;
}

.col-title a:hover {
    color: #3b82f6;
    text-decoration: underline;
}

.no-data {
    text-align: center;
    padding: 40px;
    color: #6b7280;
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    background-color: #374151;
    color: white;
    padding: 12px 24px;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 1000;
    max-width: 400px;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Footer */
footer {
    text-align: center;
    margin-top: 40px;
    padding: 20px;
    font-size: 12px;
    color: #6b7280;
    border-top: 1px solid #e5e7eb;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .header-content {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 12px;
    }
    
    .language-selector-header {
        position: static;
        transform: none;
    }
    
    #results-container {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .method-container,
    .problem-solution {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .subtitle-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .action-buttons {
        justify-content: stretch;
    }
    
    #copy-btn, #download-btn {
        flex: 1;
    }
    
    .analysis-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
    
    .analysis-date, .analysis-channel, .analysis-video-date, .analysis-duration {
        min-width: auto;
        text-align: left;
    }
    
    .table-header, .table-row {
        grid-template-columns: 1fr;
        gap: 8px;
        text-align: left;
    }
    
    .table-header > div, .table-row > div {
        padding: 4px 0;
    }
    
    .table-header > div:before {
        content: attr(data-label) ": ";
        font-weight: bold;
        display: inline-block;
        min-width: 80px;
    }
}

@media (max-width: 480px) {
    .input-container {
        flex-direction: column;
    }
    
    #extract-btn {
        width: 100%;
    }
    
    #url-history-dropdown {
        right: 0;
    }
}
