:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.container {
    background-color: var(--surface);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 100%;
    /* max-width: 500px; */
    border: 1px solid var(--border);
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.language-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text);
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 1rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.tab-btn:hover {
    background-color: var(--surface);
}

.tab-btn.active {
    background-color: var(--primary);
    color: white;
}

.tab-content {
    display: none;
    flex-direction: column;
    gap: 1rem;
}

.tab-content.active {
    display: flex;
}

.select-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

select {
    width: 100%;
    background-color: #0f172a;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    outline: none;
    appearance: none;
    /* Remove default arrow */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1.5em;
}

select:focus {
    border-color: var(--primary);
}

textarea {
    width: 100%;
    background-color: #0f172a;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    transition: border-color 0.2s;
    outline: none;
}

textarea:focus {
    border-color: var(--primary);
}

.controls {
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
}

button {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    width: 100%;
}

button:hover {
    background-color: var(--primary-hover);
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.pdf-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1.5rem;
    margin-bottom: 1rem;
}

#pdfViewerContainer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    background-color: #000;
    padding: 1rem;
    border-radius: 8px;
    width: 100%;
}

#pdfWrapper {
    position: relative;
    display: inline-block;
}

/* Ensure text layer matches canvas size and position */
.textLayer {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    pointer-events: none;
    /* Allow clicks to pass through the container */
}

.textLayer>span {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
    pointer-events: auto;
    /* Enable text selection on the spans */
}

/* Fix for text selection highlight */
::selection {
    background: rgba(99, 102, 241, 0.3);
}

.pdf-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text);
}

.action-buttons {
    display: flex;
    gap: 1rem;
}

.extracted-text-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.extracted-text-container label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

#pdfExtractedText {
    width: 100%;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    color: var(--text);
    font-family: inherit;
    resize: vertical;
    font-size: 0.9rem;
}

#pdfExtractedText:focus {
    outline: none;
    border-color: var(--primary);
}

.icon-btn {
    background-color: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover:not(:disabled) {
    background-color: var(--primary);
    border-color: var(--primary);
}

.icon-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#pdfCanvas {
    max-width: 100%;
    height: auto;
    border: 1px solid #333;
}

.primary-btn {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    width: auto;
}

.primary-btn:hover {
    background-color: var(--primary-hover);
}

.text-controls {
    display: flex;
    justify-content: center;
}

.secondary-btn {
    background-color: var(--surface);
    border: 1px solid var(--primary);
    color: var(--primary);
    width: auto;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.secondary-btn:hover {
    background-color: rgba(99, 102, 241, 0.1);
    color: var(--primary-hover);
}

#audioContainer {
    margin-top: 1.5rem;
    animation: fadeIn 0.3s ease-in-out;
}

audio {
    width: 100%;
    border-radius: 8px;
}

.hidden {
    display: none;
}

#loading {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--text-muted);
    display: none;
    /* Explicitly hidden initially */
}

#loading.flex {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}