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

:root {
    --bg: #0a0e0f;
    --surface: #10161a;
    --surface-2: #141b1f;
    --border: rgba(126, 200, 227, 0.14);
    --border-md: rgba(126, 200, 227, 0.28);
    --text: #d6e3e0;
    --muted: #7c9092;
    --hint: #4f6265;
    --accent: #63d4ff;
    --accent-bg: rgba(99, 212, 255, 0.08);
    --accent-dk: #2fa8d9;
    --green: #6be3a8;
    --green-bg: rgba(107, 227, 168, 0.08);
    --radius-sm: 3px;
    --radius-md: 4px;
    --radius-lg: 6px;
    --mono: "JetBrains Mono", "Fira Code", "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --glitch-blue: #4fd1e8;
    --glitch-purple: #a855f7;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--mono);
    background-color: var(--bg);
    background-image:
        linear-gradient(rgba(99, 212, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(99, 212, 255, 0.05) 1px, transparent 1px);
    background-size: 34px 34px;
    background-position: center top;
    color: var(--text);
    line-height: 1.7;
    min-height: 100vh;
    overflow-x: hidden; /* Evita scroll quando o Tux aparecer */
}

/* ── Navbar ─────────────────────────────────────── */
.navbar {
    background: var(--surface);
    border-bottom: 0.5px solid var(--border);
    height: 52px;
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(6px);
}

.navbar-inner {
    max-width: 900px;
    margin: 0 auto;
    height: 100%;
    padding: 0 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    letter-spacing: 0.02em;
}

.nav-brand .prompt {
    color: var(--accent);
    font-weight: 700;
}

.nav-links {
    display: flex;
    gap: 22px;
}

.nav-link {
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
    padding: 4px 0;
    text-decoration: none;
    transition: color 0.15s;
}

.nav-link:hover {
    color: var(--text);
}

.nav-link.active {
    color: var(--accent);
}

/* ── Main ─────────────────────────────────────── */
.main {
    max-width: 960px;
    margin: 0 auto;
    padding: 48px 32px 80px;
}

/* ── Layout com sidebar (TOC) ─────────────────── */
.page-layout {
    max-width: 1280px;
    margin: 0 auto;
    padding: 48px 32px 80px;
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr) 190px;
    gap: 48px;
    align-items: start;
}

.page-layout .main-col {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
}

.toc {
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: 68px;
}

.toc-label {
    font-size: 12px;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 14px;
}

.toc-label::before {
    content: "// ";
}

.toc nav {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.toc a {
    font-size: 12.5px;
    color: var(--muted);
    text-decoration: none;
    border-left: 2px solid transparent;
    padding-left: 10px;
    transition: color 0.15s, border-color 0.15s;
}

.toc a.toc-sub {
    padding-left: 22px;
}

.toc a:hover,
.toc a.active {
    color: var(--accent);
    border-left-color: var(--accent);
}

@media (max-width: 900px) {
    .toc {
        display: none;
    }
    .page-layout {
        display: block;
        max-width: 960px;
        padding: 32px 20px 60px;
    }
}

.breadcrumb {
    font-size: 12px;
    color: var(--hint);
    margin-bottom: 24px;
}

.breadcrumb::after {
    content: "▌";
    color: var(--accent);
    margin-left: 4px;
    animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

/* ── Tipografia ───────────────────────────────── */
.page-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 28px;
    color: var(--text);
}

.page-title::before {
    content: "# ";
    color: var(--accent);
}

.section-title {
    font-size: 15px;
    font-weight: 700;
    margin-top: 44px;
    margin-bottom: 14px;
    color: var(--accent);
}

.section-title::before {
    content: "## ";
    color: var(--hint);
}

.subsection-title {
    font-size: 12px;
    font-weight: 700;
    margin-top: 26px;
    margin-bottom: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.subsection-title::before {
    content: "### ";
    color: var(--hint);
}

.main p:not(.breadcrumb),
#content p:not(.breadcrumb) {
    font-size: 14.5px;
    line-height: 1.85;
    color: var(--text);
    margin-bottom: 20px;
}

.main p:last-child,
#content p:last-child {
    margin-bottom: 0;
}

#content em {
    font-style: italic;
    color: var(--muted);
}

#content a {
    color: var(--accent-dk);
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
    transition: color 0.15s;
}

#content a:hover {
    color: var(--accent);
}

.md-loading,
.md-error {
    font-size: 13px;
    color: var(--hint);
}

.md-error {
    color: #ff8a8a;
}

code {
    background: var(--surface-2);
    border: 0.5px solid var(--border);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--mono);
    font-size: 13px;
    color: var(--accent);
}

/* ── Progress ─────────────────────────────────── */
.progress-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 28px;
    margin-top: 4px;
}

.progress-label {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.progress-track {
    flex: 1;
    height: 4px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent);
    border-radius: 2px;
    transition: width 0.4s ease;
}

/* ── Seletores (Trilhas e Abas) ───────────────── */
.trilha-selector,
.unit-tabs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.trilha-btn,
.unit-tab {
    background: transparent;
    border: 1px solid #2a2f3a;
    color: #8a93a3;
    font-family: inherit;
    font-size: 0.85rem;
    padding: 0.4rem 0.9rem;
    border-radius: 4px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.trilha-btn:hover,
.unit-tab:hover {
    border-color: var(--glitch-blue);
    color: #e6e6e6;
}

.trilha-btn.active,
.unit-tab.active {
    border-color: var(--glitch-blue);
    color: var(--glitch-blue);
}

/* ── Days grid ────────────────────────────────── */
.days-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    margin-bottom: 28px;
}

.day-cell {
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    min-height: 78px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.day-cell:hover {
    border-color: var(--accent);
    background: var(--accent-bg);
}

.day-cell.active {
    border: 1px solid var(--accent);
    background: var(--accent-bg);
}

.day-cell.done {
    background: var(--surface-2);
}

.day-cell.locked {
    cursor: default;
    opacity: 0.4;
    pointer-events: none;
}

.dc-num {
    font-size: 11px;
    color: var(--hint);
}

.dc-num.done-mark::after {
    content: " ✓";
    color: var(--green);
}

.dc-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.3;
}

.day-cell.done .dc-label {
    color: var(--muted);
}

.day-cell.locked .dc-label {
    font-weight: 400;
}

/* ── Panel ────────────────────────────────────── */
.panel {
    display: none;
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.panel.visible {
    display: block;
}

/* ── Flashcards (Estrutura Básica) ────────────── */

.fc-wrap {
    position: relative;
    border-radius: var(--radius-lg);
    flex-direction: column;
    align-items: center;
    padding-top: 50px;
    padding-bottom: 20px;
    padding-left: 24px;
    padding-right: 24px;
    width: 100%;
    gap: 0;
}

.fc-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    width: 100%;
    position: relative;
    z-index: 10;
    margin-bottom: 25px;
    margin-top: 0;
}

.fc-nav button {
    background: var(--surface-2);
    border: 0.5px solid var(--border);
    color: var(--text);
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    font-size: 18px;
    font-family: var(--mono);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.fc-nav button:hover {
    border-color: var(--glitch-blue);
    color: var(--glitch-blue);
    background: rgba(79, 209, 232, 0.08);
    box-shadow: 0 0 8px rgba(79, 209, 232, 0.2);
}

.fc-nav button:active {
    transform: scale(0.92);
}

.fc-counter {
    font-size: 12px;
    color: var(--muted);
    min-width: 48px;
    text-align: center;
}

.fc-scene {
    width: min(92vw, 480px);
    height: 260px;
    perspective: 1200px;
    cursor: pointer;
    position: relative;
    z-index: 1;
    margin-bottom: 12px;
}

/* ── Glitch Logic (Cards e Botões) ────────────── */
.fc-card {
    width: 100%;
    height: 100%;
    position: relative;
    /* Restaura o eixo 3D e a transição suave de giro */
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}

.fc-card.flipped {
    transform: rotateY(180deg);
}

.fc-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    box-sizing: border-box;
    background: var(--surface);
    border: 0.5px solid var(--border);
    overflow: hidden;
    /* Restaura o backface para o giro 3D funcionar corretamente */
    backface-visibility: hidden;
}

.fc-face.fc-back {
    transform: rotateY(180deg);
}

/* Contador Hexadecimal Cyberpunk no Card */
.hex-counter {
    position: absolute;
    top: 14px;
    right: 18px;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--glitch-blue);
    text-shadow: 0 0 5px rgba(79, 209, 232, 0.4);
    letter-spacing: 0.05em;
    opacity: 0.8;
}

.fc-label {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 16px;
    color: var(--hint);
}

.fc-label::before {
    content: "// ";
}

.fc-text {
    font-size: 15.5px;
    font-weight: 500;
    color: var(--text);
    text-align: center;
    line-height: 1.6;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
}

.fc-text::-webkit-scrollbar,
.fc-text mjx-container::-webkit-scrollbar {
    display: none;
}

.fc-hint {
    font-size: 11px;
    color: var(--hint);
    margin-top: 20px;
}

/* Efeitos Visuais - Scanlines CRT */
.fc-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(79, 209, 232, 0.035) 0px,
    rgba(79, 209, 232, 0.035) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: screen;
}

.fc-scene.glitching,
.copy-btn.ok,
.copy-btn.error {
  animation: glitch-jitter 0.4s steps(6, end);
}

/* Aberração Cromática e Flash (Cards) */
.fc-scene.glitching .fc-text,
.fc-scene.glitching .fc-label,
.fc-scene.glitching .hex-counter {
  animation: glitch-rgb 0.4s steps(2, end);
}

/* Flash transversal durante o glitch no verso */
.fc-scene.glitching .fc-back::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(79, 209, 232, 0.15) 48%,
    rgba(168, 85, 247, 0.15) 52%,
    transparent 100%
  );
  animation: glitch-flash 0.4s steps(3, end);
  pointer-events: none;
}

.copy-btn.ok,
.copy-btn.error {
    animation: glitch-rgb-btn 0.4s steps(2, end), glitch-jitter 0.4s steps(6, end);
}

.copy-btn.ok {
    color: var(--green);
    border-color: var(--green);
}

.copy-btn.error {
    color: #ff8a8a;
    border-color: rgba(255, 138, 138, 0.5);
}

@keyframes glitch-jitter {
  0% { transform: translate(0, 0); }
  15% { transform: translate(-2px, 1px) skewX(1deg); }
  30% { transform: translate(2px, -1px) skewX(-1deg); }
  45% { transform: translate(-1px, 2px); }
  60% { transform: translate(1px, -2px) skewX(0.5deg); }
  75% { transform: translate(-2px, -1px); }
  100% { transform: translate(0, 0); }
}

@keyframes glitch-rgb {
  0%, 100% {
    text-shadow: 1px 0 var(--glitch-blue), -1px 0 var(--glitch-purple);
  }
  25% {
    text-shadow: -3px 0 var(--glitch-blue), 3px 0 var(--glitch-purple);
  }
  50% {
    text-shadow: 3px 0 var(--glitch-blue), -3px 0 var(--glitch-purple);
  }
  75% {
    text-shadow: -2px 0 var(--glitch-blue), 2px 0 var(--glitch-purple);
  }
}

/* Variável local para o RGB dos botões */
@keyframes glitch-rgb-btn {
  0%, 100% {
    text-shadow: 1px 0 currentColor, -1px 0 rgba(255,255,255,0.5);
  }
  25% {
    text-shadow: -3px 0 currentColor, 3px 0 rgba(255,255,255,0.5);
  }
  50% {
    text-shadow: 3px 0 currentColor, -3px 0 rgba(255,255,255,0.5);
  }
  75% {
    text-shadow: -2px 0 currentColor, 2px 0 rgba(255,255,255,0.5);
  }
}

@keyframes glitch-flash {
  0% { opacity: 0; transform: translateX(-100%); }
  40% { opacity: 1; }
  100% { opacity: 0; transform: translateX(100%); }
}

/* ── Copy Action Area ─────────────────────────── */

.fc-copy {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 12px;
    width: 100%;
    position: relative;
    z-index: 10;
    margin: 0 0 50px 0;
}

.copy-btn {
    background: var(--surface-2);
    border: 0.5px solid var(--border);
    color: var(--muted);
    font-size: 12px;
    font-family: var(--mono);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    position: relative;
}

.copy-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.copy-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

/* ── Tux Easter Egg ───────────────────────────── */
.tux-easter-egg {
    position: fixed;
    bottom: -150px;
    right: 40px;
    width: 90px;
    height: auto;
    z-index: 9999;
    pointer-events: none;
    filter: drop-shadow(0 0 10px rgba(79, 209, 232, 0.2));
    transition: bottom 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.tux-easter-egg.peek {
    bottom: -10px;
}

/* ── Anki tip ─────────────────────────────────── */
.anki-tip {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    max-width: 660px;
    margin: 48px auto 0;
    padding: 14px 16px;
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--muted);
    line-height: 1.6;
}

.anki-tip svg {
    flex-shrink: 0;
    margin-top: 2px;
    color: var(--accent);
}

.anki-tip code {
    background: var(--surface-2);
    color: var(--accent);
    border: 0.5px solid var(--border);
}

.anki-tip kbd {
    background: var(--surface-2);
    border: 0.5px solid var(--border-md);
    border-radius: var(--radius-sm);
    padding: 1px 5px;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text);
}

/* ── Empty state ──────────────────────────────── */
.empty-state {
    padding: 56px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    border: 0.5px dashed var(--border-md);
    border-radius: var(--radius-lg);
}

/* ── Footer ───────────────────────────────────── */
.site-footer {
    text-align: center;
    padding: 26px;
    font-size: 11px;
    color: var(--hint);
    border-top: 0.5px solid var(--border);
    margin-top: 48px;
}

.site-footer a {
    color: var(--accent-dk);
    text-decoration: none;
}

.site-footer a:hover {
    color: var(--accent);
}

/* ── MathJax overrides ────────────────────────── */
mjx-container {
    overflow-x: auto;
    max-width: 100%;
    color: var(--text);
}

/* ── Responsive ───────────────────────────────── */
@media (max-width: 860px) {
    .main {
        padding: 32px 20px 60px;
    }
    .days-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (max-width: 640px) {
    .main {
        padding: 24px 16px 48px;
    }
    .days-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .navbar-inner {
        padding: 0 20px;
    }
}

@media (max-width: 400px) {
    .days-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.trilha-selector,
.unit-tabs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.trilha-btn,
.unit-tab {
    background: transparent;
    border: 1px solid #2a2f3a;
    color: #8a93a3;
    font-family: inherit;
    font-size: 0.85rem;
    padding: 0.4rem 0.9rem;
    border-radius: 4px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.trilha-btn:hover,
.unit-tab:hover {
    border-color: #4fd1e8;
    color: #e6e6e6;
}

.trilha-btn.active,
.unit-tab.active {
    border-color: #4fd1e8;
    color: #4fd1e8;
}
