:root {
    --surface: #faf7f2;
    --surface-warm: #f5f0e8;
    --parchment: #ede8de;
    --ink: #2a2520;
    --ink-light: #5c554d;
    --star: #d4a853;
    --star-glow: #f0d590;
    --star-dim: rgba(212, 168, 83, 0.15);
    --error: #c44d4d;
    --error-light: #fdf0ef;
    --error-glow: rgba(196, 77, 77, 0.12);
    --ok: #5a8f68;
    --ok-light: #edf6ef;
    --border-light: rgba(42, 37, 32, 0.08);
    --bg: #f4f5f7;
    --editor-focus: #fdfbf7;
    --dl-btn-bg: rgba(255, 255, 255, 0.7);
    --dl-btn-hover-bg: #fff;
    --primary-hover: #3a342d;
    --popup-shadow: rgba(0, 0, 0, 0.15);
    --suggestion-hover-color: #6b4f1d;
}

[data-theme="dark"] {
    --surface: #1e2030;
    --surface-warm: #171926;
    --parchment: #252840;
    --ink: #e0ddd8;
    --ink-light: #9a958e;
    --star: #d4a853;
    --star-glow: #f0d590;
    --star-dim: rgba(212, 168, 83, 0.12);
    --error: #e06060;
    --error-light: #2d1f1f;
    --error-glow: rgba(224, 96, 96, 0.15);
    --ok: #6fbf80;
    --ok-light: #1a2e1f;
    --border-light: rgba(255, 255, 255, 0.08);
    --bg: #13141f;
    --editor-focus: #222438;
    --dl-btn-bg: rgba(30, 32, 48, 0.7);
    --dl-btn-hover-bg: #252840;
    --primary-hover: #d0c8be;
    --popup-shadow: rgba(0, 0, 0, 0.4);
    --suggestion-hover-color: #f0d590;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* --- Skip Link --- */
.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: var(--surface);
    padding: 0.5rem 1.5rem;
    border-radius: 0 0 8px 8px;
    font-size: 0.85rem;
    text-decoration: none;
    z-index: 2000;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
}

/* --- Starfield Background --- */
.starfield {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.starfield::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(212, 168, 83, 0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 60%, rgba(212, 168, 83, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 100%, rgba(212, 168, 83, 0.05) 0%, transparent 40%);
}

.star-dot {
    position: absolute;
    border-radius: 50%;
    background: var(--star);
    animation: twinkle var(--dur, 4s) ease-in-out infinite alternate;
    animation-delay: var(--delay, 0s);
}

@keyframes twinkle {
    0%, 100% { opacity: var(--lo, 0.04); }
    50% { opacity: var(--hi, 0.15); }
}

/* --- Layout --- */
.page {
    position: relative;
    z-index: 1;
    max-width: 860px;
    margin: 0 auto;
    padding: 3rem 1.5rem 4rem;
}

/* --- Header Top (lang + theme) --- */
.header-top {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

/* --- Language Switcher --- */
.lang-switcher {
    display: flex;
    gap: 0.25rem;
}

.lang-btn {
    font-family: 'Outfit', sans-serif;
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 0.04em;
    padding: 0.25rem 0.6rem;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: transparent;
    color: var(--ink-light);
    cursor: pointer;
    transition: all 0.2s;
}

.lang-btn:hover {
    border-color: rgba(42, 37, 32, 0.2);
    color: var(--ink);
}

[data-theme="dark"] .lang-btn:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

.lang-btn.active {
    background: var(--ink);
    color: var(--surface);
    border-color: var(--ink);
}

/* --- Theme Toggle --- */
.theme-toggle {
    font-size: 1.1rem;
    padding: 0.2rem 0.45rem;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: transparent;
    color: var(--ink-light);
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}

.theme-toggle:hover {
    color: var(--star);
    border-color: var(--star-dim);
}

/* --- Header --- */
header {
    text-align: center;
    margin-bottom: 3rem;
    animation: fadeUp 0.8s ease-out both;
}

.brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.brand-wordmark {
    display: block;
    height: 52px;
    width: auto;
}


.tagline {
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    color: var(--ink);
    margin-top: 0.5rem;
    letter-spacing: 0.04em;
    opacity: 0.7;
}

/* --- Metrics Bar --- */
.metrics {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 2.5rem;
    animation: fadeUp 0.8s ease-out 0.15s both;
}

.metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}

.metric-value {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--star);
}

.metric-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(92, 85, 77, 0.7);
    font-weight: 400;
}

[data-theme="dark"] .metric-label {
    color: rgba(154, 149, 142, 0.7);
}

.metric-sep {
    width: 1px;
    height: 36px;
    background: linear-gradient(to bottom, transparent, rgba(212, 168, 83, 0.35), transparent);
    align-self: center;
}

/* --- Editor Card --- */
.editor-card {
    background: var(--surface);
    border-radius: 16px;
    overflow: hidden;
    box-shadow:
        0 0 0 1px rgba(212, 168, 83, 0.1),
        0 2px 12px rgba(42, 37, 32, 0.06),
        0 8px 32px rgba(42, 37, 32, 0.08);
    animation: fadeUp 0.8s ease-out 0.3s both;
    position: relative;
}

[data-theme="dark"] .editor-card {
    box-shadow:
        0 0 0 1px rgba(212, 168, 83, 0.08),
        0 2px 12px rgba(0, 0, 0, 0.2),
        0 8px 32px rgba(0, 0, 0, 0.3);
}

.editor-card::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 10%;
    right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--star-glow), transparent);
    opacity: 0.4;
}

/* --- Toolbar --- */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    background: var(--surface-warm);
    border-bottom: 1px solid var(--border-light);
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.stats {
    font-size: 0.8rem;
    color: var(--ink-light);
    font-weight: 400;
}

.stats .error-count {
    color: var(--error);
    font-weight: 600;
}

.stats .ok-count {
    color: var(--ok);
    font-weight: 600;
}

.char-count {
    font-size: 0.7rem;
    color: var(--ink-light);
    opacity: 0.6;
    font-variant-numeric: tabular-nums;
}

.char-count.over-limit {
    color: var(--error);
    opacity: 1;
    font-weight: 600;
}

.toolbar-actions {
    display: flex;
    gap: 0.4rem;
}

button {
    font-family: 'Outfit', sans-serif;
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    letter-spacing: 0.01em;
}

button:hover {
    background: var(--parchment);
    border-color: rgba(42, 37, 32, 0.15);
}

[data-theme="dark"] button:hover {
    border-color: rgba(255, 255, 255, 0.15);
}

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

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

/* --- Editor --- */
#editor {
    min-height: 280px;
    padding: 1.5rem 1.75rem;
    font-family: 'Literata', serif;
    font-size: 1.1rem;
    font-weight: 400;
    line-height: 2;
    color: var(--ink);
    outline: none;
    border: none;
    background: var(--surface);
    transition: background 0.3s;
    overflow-wrap: break-word;
    word-break: break-word;
}

#editor:focus {
    background: var(--editor-focus);
}

#editor::selection {
    background: var(--star-dim);
}

.misspelled {
    text-decoration-line: underline;
    text-decoration-style: wavy;
    text-decoration-color: var(--error);
    text-underline-offset: 4px;
    text-decoration-thickness: 1.5px;
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.15s;
}

.misspelled:hover {
    background: var(--error-glow);
}

/* --- Suggestion Popup --- */
.suggestion-popup {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    box-shadow:
        0 8px 40px var(--popup-shadow),
        0 0 0 1px rgba(0, 0, 0, 0.04);
    z-index: 1000;
    min-width: 180px;
    padding: 4px;
    animation: popIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popIn {
    from { opacity: 0; transform: translateY(-6px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.suggestion-popup .suggestion-item {
    padding: 0.45rem 0.75rem;
    cursor: pointer;
    border-radius: 8px;
    font-family: 'Literata', serif;
    font-size: 0.95rem;
    color: var(--ink);
    transition: all 0.12s;
}

.suggestion-popup .suggestion-item:hover,
.suggestion-popup .suggestion-item.focused {
    background: var(--star-dim);
    color: var(--suggestion-hover-color);
}

.suggestion-popup .no-suggestions {
    padding: 0.5rem 0.75rem;
    color: var(--ink-light);
    font-size: 0.85rem;
    font-style: italic;
}

/* --- Results Panel --- */
.results-panel {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border-light);
    background: var(--surface-warm);
}

.results-panel h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--ink-light);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.error-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.error-chip {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    background: var(--error-light);
    color: var(--error);
    border-radius: 5px;
    font-family: 'Literata', serif;
    font-size: 0.8rem;
    font-weight: 500;
}

/* --- Loading --- */
.loading {
    display: none;
    align-items: center;
    gap: 0.5rem;
    color: var(--ink-light);
    font-size: 0.8rem;
}

.loading.active { display: flex; }

.spinner {
    width: 14px;
    height: 14px;
    border: 1.5px solid var(--parchment);
    border-top-color: var(--ink);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* --- Downloads --- */
.downloads {
    margin-top: 2.5rem;
    animation: fadeUp 0.8s ease-out 0.45s both;
}

.downloads-label {
    text-align: center;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: rgba(92, 85, 77, 0.7);
    margin-bottom: 0.75rem;
}

[data-theme="dark"] .downloads-label {
    color: rgba(154, 149, 142, 0.7);
}

.downloads-row {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.dl-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1.1rem;
    border: 1px solid rgba(42, 37, 32, 0.1);
    border-radius: 10px;
    background: var(--dl-btn-bg);
    color: var(--ink-light);
    font-family: 'Outfit', sans-serif;
    font-size: 0.8rem;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.25s;
    text-decoration: none;
}

[data-theme="dark"] .dl-btn {
    border-color: rgba(255, 255, 255, 0.08);
}

.dl-btn:hover {
    background: var(--dl-btn-hover-bg);
    border-color: rgba(212, 168, 83, 0.35);
    color: var(--ink);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(42, 37, 32, 0.08);
}

[data-theme="dark"] .dl-btn:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.dl-btn .dl-icon {
    font-size: 0.9rem;
    opacity: 0.4;
}

.dl-btn .dl-ext {
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--star);
}

/* --- About Section --- */
.about {
    margin-top: 2rem;
    animation: fadeUp 0.8s ease-out 0.5s both;
}

.about-label {
    text-align: center;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: rgba(92, 85, 77, 0.7);
    margin-bottom: 0.5rem;
}

[data-theme="dark"] .about-label {
    color: rgba(154, 149, 142, 0.7);
}

.about-text {
    text-align: center;
    font-size: 0.85rem;
    color: var(--ink-light);
    max-width: 560px;
    margin: 0 auto;
    line-height: 1.7;
}

/* --- Footer --- */
footer {
    text-align: center;
    margin-top: 3rem;
    padding-bottom: 2rem;
    animation: fadeUp 0.8s ease-out 0.6s both;
}

.footer-line {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: rgba(92, 85, 77, 0.6);
    font-size: 0.75rem;
    letter-spacing: 0.03em;
}

[data-theme="dark"] .footer-line {
    color: rgba(154, 149, 142, 0.6);
}

.footer-dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: rgba(212, 168, 83, 0.4);
}

.footer-link {
    color: rgba(212, 168, 83, 0.6);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-link:hover {
    color: var(--star);
}

/* --- Animations --- */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Responsive --- */
@media (max-width: 640px) {
    .page { padding: 2rem 1rem 3rem; }
    .brand-wordmark { height: 38px; }
    .tagline { font-size: 1rem; }
    .metrics { gap: 1.2rem; }
    .metric-value { font-size: 1.2rem; }
    #editor {
        padding: 1.25rem;
        font-size: 1rem;
        min-height: 220px;
    }
    .toolbar {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .toolbar-actions {
        flex-wrap: wrap;
    }
}
