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

:root {
    --bg: #0d0a06;
    --surface: #1a1008;
    --surface-light: #231a0e;
    --border: #3d2e1a;
    --text: #d4c5a0;
    --text-dim: #8a7a5a;
    --accent: #c8a830;
    --accent-hover: #d4b840;
    --gold: #c8a830;
    --positive: #7a9a40;
    --negative: #8b2500;
    --input-bg: #1a1008;
    --radius: 4px;
    --font-title: 'Uncial Antiqua', cursive;
    --font-body: 'Cormorant Garamond', serif;
    --font-ui: 'Old Standard TT', serif;
}

body {
    font-family: var(--font-body);
    font-size: 16px;
    background-color: var(--bg);
    background-image:
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 20px,
            rgba(30, 20, 10, 0.3) 20px,
            rgba(30, 20, 10, 0.3) 21px
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 40px,
            rgba(20, 14, 6, 0.2) 40px,
            rgba(20, 14, 6, 0.2) 41px
        ),
        repeating-linear-gradient(
            87deg,
            transparent,
            transparent 60px,
            rgba(40, 28, 14, 0.15) 60px,
            rgba(40, 28, 14, 0.15) 62px
        );
    color: var(--text);
    min-height: 100vh;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 60px 24px 40px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 48px;
}

h1 {
    font-family: var(--font-title);
    font-size: 2.4rem;
    font-weight: 400;
    letter-spacing: 0.04em;
    color: var(--gold);
    text-shadow:
        0 0 20px rgba(200, 168, 48, 0.3),
        0 2px 0 #1a1008,
        0 3px 0 #0d0a06;
    margin-bottom: 8px;
}

.subtitle {
    font-family: var(--font-ui);
    color: var(--text-dim);
    font-size: 0.95rem;
    font-style: italic;
}

/* Ornamental dividers */
.ornament {
    text-align: center;
    line-height: 1;
    color: var(--gold);
    font-size: 0.85rem;
    letter-spacing: 0.3em;
    user-select: none;
    position: relative;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
}

.ornament::before,
.ornament::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent,
        var(--gold) 30%,
        var(--gold) 70%,
        transparent
    );
    opacity: 0.4;
}

.ornament-top {
    margin-bottom: 16px;
}

.ornament-bottom {
    margin-top: 16px;
}

/* Scroll panel wrapper */
.scroll-panel {
    background:
        radial-gradient(ellipse at 50% 0%, rgba(35, 26, 14, 0.8) 0%, transparent 70%),
        var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 24px;
    box-shadow:
        inset 0 1px 0 rgba(200, 168, 48, 0.05),
        0 4px 20px rgba(0, 0, 0, 0.4);
    border-top: 3px solid transparent;
    border-image: repeating-linear-gradient(
        90deg,
        var(--gold) 0px,
        var(--gold) 8px,
        transparent 8px,
        transparent 16px
    ) 3;
    margin-bottom: 32px;
}

/* Form */
#cognate-form {
    margin-bottom: 0;
}

.input-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

.input-group {
    flex: 1;
    position: relative;
}

.input-group label {
    display: block;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
}

.input-with-lang {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background:
        radial-gradient(ellipse at 50% 50%, rgba(35, 26, 14, 0.4) 0%, transparent 80%),
        var(--input-bg);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-with-lang:focus-within {
    border-color: var(--gold);
    box-shadow: 0 0 12px rgba(200, 168, 48, 0.15);
}

.input-with-lang input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 14px;
    font-family: var(--font-body);
    font-size: 1.05rem;
    color: var(--text);
    outline: none;
    min-width: 0;
}

.input-with-lang input::placeholder {
    color: var(--text-dim);
    opacity: 0.6;
}

.input-with-lang select {
    background: var(--surface-light);
    border: none;
    border-left: 1px solid var(--border);
    padding: 10px 12px;
    font-family: var(--font-ui);
    font-size: 0.85rem;
    color: var(--text-dim);
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a7a5a'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 24px;
}

/* Button */
button[type="submit"] {
    padding: 10px 28px;
    background: linear-gradient(180deg, #3d2e1a 0%, #2a1e10 50%, #1a1008 100%);
    color: var(--gold);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-ui);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    height: fit-content;
    text-transform: uppercase;
    box-shadow:
        inset 0 1px 0 rgba(200, 168, 48, 0.15),
        inset 0 -1px 0 rgba(0, 0, 0, 0.3),
        0 2px 6px rgba(0, 0, 0, 0.3);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

button[type="submit"]:hover {
    background: linear-gradient(180deg, #4a3820 0%, #3d2e1a 50%, #231a0e 100%);
    border-color: var(--gold);
    box-shadow:
        inset 0 1px 0 rgba(200, 168, 48, 0.2),
        inset 0 -1px 0 rgba(0, 0, 0, 0.3),
        0 2px 10px rgba(200, 168, 48, 0.1);
}

button[type="submit"]:active {
    background: linear-gradient(180deg, #1a1008 0%, #231a0e 50%, #2a1e10 100%);
    box-shadow:
        inset 0 2px 4px rgba(0, 0, 0, 0.5),
        inset 0 -1px 0 rgba(200, 168, 48, 0.05);
    transform: translateY(1px);
}

button[type="submit"]:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Suggestions dropdown */
.suggestions {
    list-style: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 10;
    display: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.suggestions.active {
    display: block;
}

.suggestions li {
    padding: 8px 14px;
    font-family: var(--font-body);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    color: var(--text);
    border-bottom: 1px solid rgba(61, 46, 26, 0.4);
}

.suggestions li:last-child {
    border-bottom: none;
}

.suggestions li:hover {
    background: var(--surface);
    color: var(--gold);
}

.suggestions li span.lang-tag {
    color: var(--text-dim);
    font-family: var(--font-ui);
    font-size: 0.75rem;
    margin-left: 8px;
}

/* Result */
.result {
    text-align: center;
    padding: 20px;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 1.1rem;
    margin-bottom: 32px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.result.hidden {
    display: none;
}

.result.cognate {
    border-color: var(--positive);
    color: var(--positive);
    background: linear-gradient(180deg, rgba(122, 154, 64, 0.08) 0%, var(--surface) 100%);
}

.result.not-cognate {
    border-color: #8b6530;
    color: #c8a060;
    background: linear-gradient(180deg, rgba(139, 101, 48, 0.08) 0%, var(--surface) 100%);
}

.result .ancestor-detail {
    color: var(--gold);
    font-size: 0.95rem;
    margin-top: 6px;
    font-style: italic;
}

/* Graph */
#graph-container {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background:
        radial-gradient(ellipse at 50% 50%, rgba(26, 16, 8, 0.9) 0%, var(--surface) 100%);
    overflow: hidden;
    display: none;
}

#graph-container.active {
    display: block;
}

#graph {
    width: 100%;
    height: 500px;
}

/* Graph elements */
.node-label {
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    fill: var(--text);
    text-anchor: middle;
    pointer-events: none;
}

.lang-label {
    font-family: var(--font-ui);
    font-size: 9px;
    fill: var(--text-dim);
    text-anchor: middle;
    pointer-events: none;
}

.link-label {
    font-family: var(--font-ui);
    font-size: 8px;
    fill: var(--text-dim);
    text-anchor: middle;
}

.translation-label {
    font-family: var(--font-body);
    font-size: 8px;
    fill: var(--gold);
    text-anchor: middle;
    font-style: italic;
    pointer-events: none;
    opacity: 0.8;
}

.link {
    stroke: var(--border);
    stroke-width: 1.5;
    fill: none;
    marker-end: url(#arrowhead);
}

/* Loading */
.loading {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

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

/* Responsive */
/* Examples section */
.examples-section {
    text-align: center;
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.example-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.example-chip {
    display: inline-block;
    padding: 6px 14px;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.example-chip:hover {
    border-color: var(--gold);
    color: var(--gold);
    background: rgba(200, 168, 48, 0.08);
}

.random-btn {
    padding: 6px 16px;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 20px;
    color: var(--text-dim);
    font-family: var(--font-ui);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.random-btn:hover {
    border-color: var(--gold);
    color: var(--gold);
}

/* Fun fact */
.fun-fact {
    margin-bottom: 24px;
    padding: 12px 16px 12px 20px;
    border-left: 3px solid var(--gold);
    background: rgba(200, 168, 48, 0.04);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-style: italic;
    color: var(--text-dim);
    line-height: 1.5;
    transition: opacity 0.3s;
}

.fun-fact:hover {
    color: var(--text);
}

/* Summary banner */
.summary-banner {
    font-size: 1.1rem;
    line-height: 1.5;
    margin-bottom: 4px;
}

/* Confidence badge */
.confidence-badge {
    font-size: 0.75rem;
    letter-spacing: 2px;
    margin-right: 6px;
    vertical-align: middle;
}

.confidence-high {
    color: var(--positive);
}

.confidence-medium {
    color: var(--gold);
}

.confidence-low {
    color: var(--text-dim);
}

/* Not-cognate improvements */
.not-cognate-explanation {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-top: 8px;
    font-style: italic;
}

.try-instead {
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* Tooltip */
.graph-tooltip {
    display: none;
    position: absolute;
    z-index: 100;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    max-width: 280px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--text);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    line-height: 1.4;
}

.graph-tooltip .tooltip-lang {
    color: var(--text-dim);
    font-size: 0.8rem;
}

.graph-tooltip .tooltip-desc {
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--text-dim);
    font-style: italic;
}

.graph-tooltip .tooltip-trans {
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--gold);
}

/* Legend */
.graph-legend {
    margin-top: 16px;
    padding: 16px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.graph-legend.hidden {
    display: none;
}

.legend-title {
    font-family: var(--font-ui);
    font-size: 0.85rem;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 12px;
}

.legend-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.legend-section h4 {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.legend-item svg {
    flex-shrink: 0;
}

/* How to read this */
.how-to-read {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.how-to-read.hidden {
    display: none;
}

.how-to-read summary {
    padding: 12px 20px;
    font-family: var(--font-ui);
    font-size: 0.85rem;
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
    list-style: none;
}

.how-to-read summary::before {
    content: "\25B6  ";
    font-size: 0.65rem;
    transition: transform 0.2s;
    display: inline-block;
}

.how-to-read[open] summary::before {
    transform: rotate(90deg);
}

.how-to-read summary::-webkit-details-marker {
    display: none;
}

.how-to-read-content {
    padding: 0 20px 16px;
    font-size: 0.85rem;
    color: var(--text-dim);
    line-height: 1.6;
}

.how-to-read-content p {
    margin-bottom: 10px;
}

.how-to-read-content strong {
    color: var(--text);
}

.how-to-read-content em {
    color: var(--gold);
    font-style: italic;
}

/* Timeline */
.timeline-bar {
    display: flex;
    margin-top: 16px;
    border-radius: var(--radius);
    overflow: hidden;
    height: 48px;
}

.timeline-era {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    color: #0d0a06;
    font-family: var(--font-ui);
}

.timeline-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.2;
}

.timeline-date {
    font-size: 0.6rem;
    opacity: 0.7;
}

/* Responsive */
@media (max-width: 600px) {
    .input-row {
        flex-direction: column;
    }

    .container {
        padding: 32px 16px 24px;
    }

    h1 {
        font-size: 1.8rem;
    }

    .scroll-panel {
        padding: 20px 16px;
    }

    .legend-grid {
        grid-template-columns: 1fr;
    }

    .timeline-bar {
        flex-direction: column;
        height: auto;
    }

    .timeline-era {
        padding: 8px;
        flex-direction: row;
        gap: 8px;
    }

    .examples-section {
        gap: 6px;
    }

    .example-chip {
        font-size: 0.8rem;
        padding: 4px 10px;
    }
}
