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

:root {
    --bg: #faf8f0;
    --surface: #ffffff;
    --primary: #b45309;
    --primary-hover: #92400e;
    --text: #1c1917;
    --text-muted: #78716c;
    --border: #e7e5e4;
    --accent: #fed7aa;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
    font-family: 'Noto Sans Devanagari', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    padding: 2rem 1rem 1rem;
    background: linear-gradient(135deg, #fef3c7, #fed7aa);
    border-bottom: 2px solid var(--primary);
}

header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 0.02em;
}

header .subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

main {
    max-width: 720px;
    width: 100%;
    margin: 2rem auto;
    padding: 0 1rem;
    flex: 1;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.5rem;
}

.tab {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-muted);
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--text);
    background: var(--accent);
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* Tab panels */
.tab-panel {
    display: none;
}

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

/* Textarea */
textarea {
    width: 100%;
    padding: 1rem;
    font-family: 'Noto Sans Devanagari', monospace;
    font-size: 1.1rem;
    line-height: 1.8;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    resize: vertical;
    transition: border-color 0.2s;
}

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

textarea[readonly] {
    background: #fefce8;
}

/* Drop zone */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--surface);
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary);
    background: #fef3c7;
}

.drop-zone p {
    color: var(--text-muted);
}

.drop-zone .hint {
    font-size: 0.8rem;
    margin-top: 0.5rem;
}

/* Image preview */
#image-preview-container {
    margin-top: 1rem;
    text-align: center;
}

#image-preview {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

#pdf-filename {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: var(--accent);
    border-radius: var(--radius);
    font-weight: 600;
}

/* Extracted text section */
#extracted-text-section {
    margin-top: 1.5rem;
}

#extracted-text-section h3 {
    font-size: 1rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

/* Controls */
.controls {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.control-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.control-row:last-child {
    margin-bottom: 0;
}

.control-row label {
    min-width: 100px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
}

select, input[type="range"] {
    flex: 1;
}

select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--surface);
}

input[type="range"] {
    accent-color: var(--primary);
}

.buttons {
    justify-content: flex-start;
    gap: 0.75rem;
}

button {
    padding: 0.6rem 1.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--surface);
    color: var(--text);
}

button:hover:not(:disabled) {
    background: #f5f5f4;
}

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

button.primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

button.primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

/* Status & spinner */
#status {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
}

#status.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

#status.success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

#spinner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    color: var(--primary);
    font-size: 0.9rem;
}

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

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

/* Hidden utility */
.hidden {
    display: none !important;
}

/* ── Reading display with word highlighting ── */
#reading-display-section {
    margin-top: 1.5rem;
}

#reading-display-section h3 {
    font-size: 1rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

#reading-display {
    padding: 1.25rem;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-family: 'Noto Sans Devanagari', sans-serif;
    font-size: 1.3rem;
    line-height: 2.2;
    max-height: 350px;
    overflow-y: auto;
    word-wrap: break-word;
}

#reading-display .word {
    display: inline;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background-color 0.15s, color 0.15s;
    cursor: default;
}

#reading-display .word-active {
    background-color: var(--primary);
    color: #fff;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(180, 83, 9, 0.35);
}

/* ── PDF page navigation ── */
#page-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

#page-indicator {
    font-weight: 600;
    color: var(--primary);
    min-width: 100px;
    text-align: center;
}

/* Footer */
footer {
    text-align: center;
    padding: 1.5rem 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}

/* Responsive */
@media (max-width: 600px) {
    header h1 {
        font-size: 1.6rem;
    }

    .tab {
        font-size: 0.82rem;
        padding: 0.6rem 0.5rem;
    }

    .control-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .control-row label {
        min-width: auto;
    }
}
