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

:root {
    --font-deva: "Noto Sans Devanagari", sans-serif;
    --font-ui: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
    --bg: #fafaf9;
    --surface: #ffffff;
    --border: #e5e5e5;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --accent: #b45309;
    --accent-hover: #92400e;
    --error-bg: #fef2f2;
    --error-text: #991b1b;
    --link: #1d4ed8;
    --link-hover: #1e40af;
    --radius: 6px;
}

body {
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1.25rem;
}

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

header h1 {
    font-family: var(--font-deva);
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

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

/* Input */
.input-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.25rem;
}

#sanskrit-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.75rem;
    font-family: var(--font-deva);
    font-size: 1.15rem;
    line-height: 1.8;
    resize: vertical;
    color: var(--text);
    background: var(--bg);
}

#sanskrit-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}

#sanskrit-input::placeholder {
    font-family: var(--font-ui);
    font-size: 0.9rem;
    color: var(--text-muted);
}

.input-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.75rem;
    gap: 0.75rem;
}

.script-selectors {
    display: flex;
    gap: 1rem;
    margin-top: 0.75rem;
}

.selector-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex: 1;
}

.selector-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
}

.selector-group select {
    flex: 1;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    color: var(--text);
    background: var(--bg);
    cursor: pointer;
}

.selector-group select:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}

.script-badge {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

#analyze-btn {
    padding: 0.5rem 1.5rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-family: var(--font-ui);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}

#analyze-btn:hover {
    background: var(--accent-hover);
}

#analyze-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem;
    color: var(--text-muted);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* Error */
.error {
    background: var(--error-bg);
    color: var(--error-text);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}

/* Results */
.results {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.result-section h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.5rem;
}

.result-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    font-family: var(--font-deva);
    font-size: 1.1rem;
    line-height: 1.8;
    word-break: break-word;
}

/* Table */
#result-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

#result-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

#result-table th,
#result-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
    vertical-align: top;
}

#result-table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    white-space: nowrap;
}

#result-table td {
    font-family: var(--font-deva);
    line-height: 1.7;
}

#result-table tr:last-child td {
    border-bottom: none;
}

.col-num {
    width: 2.5rem;
    text-align: center;
}

.col-word {
    min-width: 100px;
}

.col-lemma {
    min-width: 80px;
}

.col-tags {
    min-width: 120px;
    font-family: var(--font-ui);
}

#result-table td a {
    color: var(--link);
    text-decoration: none;
}

#result-table td a:hover {
    text-decoration: underline;
    color: var(--link-hover);
}

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

/* Footer */
footer {
    margin-top: 3rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.8;
}

footer a {
    color: var(--text-muted);
    text-decoration: underline;
    text-decoration-color: var(--border);
}

footer a:hover {
    color: var(--accent);
    text-decoration-color: var(--accent);
}

/* Responsive */
@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }
    header h1 {
        font-size: 1.5rem;
    }
    #sanskrit-input {
        font-size: 1rem;
    }
    .input-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .script-selectors {
        flex-direction: column;
        gap: 0.5rem;
    }
    #analyze-btn {
        align-self: flex-end;
    }
}
