/* =========================================================================
   Abismo — estilos do site (mobile-first, alto contraste, leitura confortável)
   Edite as variáveis abaixo primeiro: cores, medida e espaçamento saem daqui.
   ========================================================================= */

:root {
    /* Cores — alto contraste (texto quase branco sobre fundo quase preto) */
    --bg:           #08090c;
    --bg-elev:      #0c0e13;   /* topbar, sidebar */
    --surface:      #13161d;   /* tabelas, citações, cartões */
    --text:         #e8e9ee;   /* corpo — contraste ~15:1 sobre --bg */
    --text-strong:  #ffffff;
    --text-muted:   #a9adb7;   /* itens de índice inativos, legendas */
    --accent:       #ff4d4d;
    --accent-soft:  rgba(255, 77, 77, 0.14);
    --accent-glow:  rgba(255, 77, 77, 0.45);
    --border:       rgba(255, 255, 255, 0.12);
    --border-soft:  rgba(255, 255, 255, 0.07);
    --mark:         #ffd24d;   /* destaque de busca */

    --font-body:    'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    --font-head:    'Cinzel', Georgia, serif;

    --topbar-h:     56px;
    --sidebar-w:    320px;
    --measure:      70ch;      /* largura de leitura */

    --radius:       10px;
    --shadow:       0 12px 30px rgba(0, 0, 0, 0.45);
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 12px); }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.75;
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

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

/* Foco visível para navegação por teclado */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* =========================== TOP BAR (sticky) =========================== */

.topbar {
    position: sticky;
    top: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: var(--topbar-h);
    padding: 0 0.75rem;
    padding-top: env(safe-area-inset-top, 0);
    background: rgba(12, 14, 19, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.topbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    flex-shrink: 0;
    height: 40px;
    padding: 0 0.8rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    font-size: 0.95rem;
    cursor: pointer;
}
.topbar-btn:hover { border-color: var(--accent); color: var(--text-strong); }
.topbar-btn-icon { font-size: 1.1rem; line-height: 1; }

.brand {
    flex-shrink: 0;
    font-family: var(--font-head);
    font-weight: 800;
    font-size: 1.4rem;
    letter-spacing: 0.14em;
    color: var(--accent);
    text-shadow: 0 0 14px var(--accent-glow);
}
.brand:hover { text-decoration: none; }

/* ---- Busca ---- */
.search {
    position: relative;
    margin-left: auto;
    flex: 1 1 auto;
    max-width: 360px;
}

.search-input {
    width: 100%;
    height: 40px;
    padding: 0 2.2rem 0 0.9rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    font-size: 0.95rem;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--accent); outline: none; }

.search-clear {
    position: absolute;
    top: 50%;
    right: 0.4rem;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    background: transparent;
    border: 0;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
}
.search-clear:hover { color: var(--text-strong); background: var(--border-soft); }

.search-results {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: min(92vw, 460px);
    max-height: min(70vh, 520px);
    overflow-y: auto;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.4rem;
    z-index: 320;
}

.search-result {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.6rem 0.7rem;
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    border: 0;
    background: transparent;
    font: inherit;
}
.search-result:hover,
.search-result.is-active { background: var(--accent-soft); }
.search-result .sr-title {
    display: block;
    font-weight: 600;
    color: var(--text-strong);
    font-size: 0.95rem;
}
.search-result .sr-crumb {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    margin-bottom: 0.15rem;
}
.search-result .sr-snippet {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 0.15rem;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.search-result mark,
.markdown-body mark.search-hit {
    background: var(--mark);
    color: #1a1200;
    padding: 0 2px;
    border-radius: 3px;
}
.search-empty {
    padding: 1rem 0.8rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Barrinha de progresso de leitura sob a topbar */
.reading-progress {
    position: sticky;
    top: var(--topbar-h);
    z-index: 290;
    height: 3px;
    width: 0;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
    transition: width 0.1s linear;
}

/* =============================== LAYOUT ================================= */

.layout { display: block; }

/* ---- Sidebar / Índice ---- */
.sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: min(86vw, var(--sidebar-w));
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 250;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    -webkit-overflow-scrolling: touch;
}
body.nav-open .sidebar { transform: translateX(0); }

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    z-index: 240;
}
body:not(.nav-open) .sidebar-overlay { display: none; }

.toc {
    padding: 1rem 0.9rem 3rem;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.toc-title {
    font-family: var(--font-head);
    font-size: 0.8rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.4rem 0.6rem 0.6rem;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 0.4rem;
}
.toc-item {
    display: block;
    color: var(--text-muted);
    font-size: 0.92rem;
    line-height: 1.4;
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    border-left: 2px solid transparent;
}
.toc-item:hover { color: var(--text-strong); background: var(--border-soft); text-decoration: none; }
.toc-item.active {
    color: var(--text-strong);
    background: var(--accent-soft);
    border-left-color: var(--accent);
}
.toc-item.lvl-2 { font-weight: 600; margin-top: 0.35rem; }
.toc-item.lvl-3 { padding-left: 1.4rem; font-size: 0.86rem; }
.toc-item.lvl-4 { padding-left: 2.1rem; font-size: 0.82rem; color: var(--text-muted); }

/* ---- Conteúdo ---- */
.content { min-width: 0; }

.hero {
    height: 34vh;
    min-height: 200px;
    background: url('images/armed-woman-in-the-ruined-cathedral.webp') center/cover no-repeat;
    position: relative;
}
.hero::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(8,9,12,0.15), var(--bg));
}

.markdown-body {
    max-width: var(--measure);
    margin: 0 auto;
    padding: 1.5rem 1.15rem 4rem;
    width: 100%;
}

.site-footer {
    text-align: center;
    padding: 2.5rem 1.15rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    background: var(--bg-elev);
}

/* =========================== TIPOGRAFIA ================================= */

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    font-family: var(--font-head);
    color: var(--text-strong);
    line-height: 1.2;
    scroll-margin-top: calc(var(--topbar-h) + 12px);
}

.markdown-body h1 {
    font-size: clamp(2.1rem, 8vw, 3.2rem);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    text-shadow: 0 0 22px var(--accent-glow);
    margin: 0.5rem 0 2rem;
}
.markdown-body h2 {
    font-size: clamp(1.6rem, 5vw, 2.1rem);
    margin: 3rem 0 1rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}
.markdown-body h3 {
    font-size: clamp(1.25rem, 4vw, 1.5rem);
    color: var(--text-strong);
    margin: 2.2rem 0 0.8rem;
}
.markdown-body h4 {
    font-size: 1.1rem;
    color: var(--accent);
    margin: 1.6rem 0 0.6rem;
    letter-spacing: 0.02em;
}

.markdown-body p { margin: 0 0 1.25rem; }
.markdown-body strong { color: var(--text-strong); font-weight: 700; }
.markdown-body em { color: var(--text); }

.markdown-body ul,
.markdown-body ol { margin: 0 0 1.25rem; padding-left: 1.5rem; }
.markdown-body li { margin-bottom: 0.5rem; }
.markdown-body li::marker { color: var(--accent); }
.markdown-body ul ul,
.markdown-body ol ol,
.markdown-body ul ol,
.markdown-body ol ul { margin: 0.5rem 0 0.5rem; }

.markdown-body blockquote {
    margin: 1.75rem 0;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border-left: 4px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text);
}
.markdown-body blockquote p:last-child { margin-bottom: 0; }

.markdown-body hr {
    border: 0;
    height: 1px;
    background: var(--border);
    margin: 2.5rem 0;
}

.markdown-body code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.9em;
    background: var(--surface);
    padding: 0.1em 0.4em;
    border-radius: 5px;
    border: 1px solid var(--border-soft);
}
.markdown-body pre {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
    margin: 0 0 1.25rem;
}
.markdown-body pre code { background: none; border: 0; padding: 0; }

/* ---- Tabelas (envolvidas por .table-wrap no JS para rolar no mobile) ---- */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1.75rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    font-size: 0.95rem;
}
.markdown-body th,
.markdown-body td {
    padding: 0.75rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: top;
}
.markdown-body th {
    background: var(--accent-soft);
    color: var(--accent);
    font-family: var(--font-head);
    font-weight: 600;
    white-space: nowrap;
}
.markdown-body tbody tr:last-child td { border-bottom: 0; }
.markdown-body tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }

/* ---- Imagens (estáticas do markdown e as inseridas pelo JS) ---- */
.markdown-body img,
.dynamic-img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    margin: 2rem auto;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-soft);
}
.dynamic-img {
    width: 100%;
    filter: grayscale(25%) contrast(105%);
    transition: filter 0.3s ease;
}
.dynamic-img:hover { filter: none; }

/* Alvo de rolagem em destaque momentâneo (busca / clique no índice) */
.flash-target { animation: flash 1.6s ease; }
@keyframes flash {
    0%, 15% { background: var(--accent-soft); box-shadow: 0 0 0 6px var(--accent-soft); }
    100%    { background: transparent; box-shadow: none; }
}

/* ---- Voltar ao topo ---- */
.to-top {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 260;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: 0;
    font-size: 1.3rem;
    cursor: pointer;
    box-shadow: var(--shadow);
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.to-top:hover { filter: brightness(1.1); }

/* ============================= DESKTOP ================================= */

@media (min-width: 900px) {
    body { font-size: 18px; }

    .layout { display: flex; align-items: flex-start; }

    /* Sidebar docada e visível por padrão; o botão Índice pode ocultá-la. */
    .sidebar {
        position: sticky;
        top: var(--topbar-h);
        height: calc(100vh - var(--topbar-h));
        transform: none;
        transition: none;
        flex: 0 0 var(--sidebar-w);
        width: var(--sidebar-w);
    }
    body:not(.nav-open) .sidebar { display: none; }
    .sidebar-overlay { display: none !important; }

    .content { flex: 1 1 auto; }
    .hero { height: 40vh; }
    .markdown-body { padding: 2.5rem 3rem 5rem; }

    /* Rótulo do botão sempre aparece no desktop */
    .topbar-btn-label { display: inline; }
}

/* Em telas estreitas, o botão fica mais compacto (só o ícone) */
@media (max-width: 480px) {
    .topbar { gap: 0.35rem; padding: 0 0.5rem; }
    .brand { font-size: 1.15rem; letter-spacing: 0.1em; }
    .topbar-btn { padding: 0 0.6rem; }
    .topbar-btn-label { display: none; }
    .search-input { font-size: 16px; } /* evita zoom automático no iOS */
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
