/* Theme tokens / global overrides */
:root {
    --background: #11111b;
    --foreground: #c5c8ce;
    --accent: #a78bfa;

    --surface: rgba(255, 255, 255, 0.015);
    --surface-soft: rgba(255, 255, 255, 0.025);
    --surface-hover: rgba(255, 255, 255, 0.035);

    --border-subtle: #343943;
    --border-hover: #505762;

    --muted: #858b95;
    --muted-dim: #79808a;
    --foreground-strong: #d7d9df;

    --terminal-blue: #8192a8;
    --terminal-cyan: #82a3a6;
    --terminal-green: #91a58a;
    --terminal-purple: #978eaa;
    --terminal-red: #b67f84;
    --terminal-orange: #b3977b;

    --pwndbg-legend: #b8c0cc;
    --pwndbg-muted: #8b949e;
    --pwndbg-divider: #4c566a;
    --pwndbg-address: #8fbcbb;
    --pwndbg-execute: #bf616a;
    --pwndbg-bright: #eceff4;

    --placement-first: #b5a06e;
    --placement-second: #9ca3ad;
    --placement-third: #987c69;

    --syntax-background: #181a20;
    --syntax-yellow: #c2aa79;
    --syntax-green: #91a984;
    --syntax-cyan: #7fa3a7;
    --syntax-punctuation: #aab0b8;
}

html {
    overflow-y: scroll;
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
}

/* Utilities */

.text-accent {
    color: var(--accent);
}

.page-title {
    margin: 25px 0 2rem;
    color: var(--foreground);
    font-weight: 600;
}

.about-content {
    padding: 1.6rem 2rem;
    border: 1px solid var(--border-subtle);
    background: var(--surface);
}

.about-content :is(h2, h3, h4, h5, h6, b, strong) {
    font-weight: 600;
}

/* Shell header */

.shell-header {
    margin-bottom: 3rem;
    padding-top: 2rem;
    font-size: 0.95rem;
}

.shell-prompt {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.7rem;
}

.shell-home {
    color: var(--foreground);
    text-decoration: none;
}

.shell-user {
    color: var(--accent);
    font-weight: 700;
}

.shell-at,
.shell-sep,
.shell-dollar,
.shell-command {
    color: var(--foreground);
}

.shell-host {
    color: var(--terminal-green);
}

.shell-path,
.shell-nav a {
    color: var(--terminal-blue);
}

.shell-dollar,
.shell-command {
    margin-left: 0.15rem;
}

.shell-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: 0.45rem;
    padding-left: 0;
}

.shell-nav a {
    text-decoration: none;
}

.shell-nav a:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* Homepage / pwndbg */

.pwndbg-home {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.55;
}

.pwndbg-command {
    display: flex;
    gap: 0.7rem;
    margin-bottom: 0.25rem;
    color: var(--foreground);
}

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

.pwndbg-legend {
    margin-top: 0.85rem;
    margin-bottom: 0.5rem;
    color: var(--pwndbg-legend);
}

.legend-stack {
    color: var(--terminal-purple);
}

.legend-heap {
    color: var(--terminal-green);
}

.legend-code {
    color: var(--terminal-red);
}

.legend-data {
    color: var(--terminal-blue);
}

.legend-wx {
    color: var(--terminal-orange);
}

.legend-rodata {
    color: var(--terminal-cyan);
}

.pwndbg-scroll,
.vmmap {
    width: 100%;
}

.vmmap-row {
    display: grid;
    grid-template-columns: 15ch 15ch 5ch 7ch 7ch minmax(8ch, 1fr);
    column-gap: 0.7rem;
    padding: 0.08rem 0;
    color: var(--foreground);
    text-decoration: none;
    white-space: nowrap;
}

.vmmap-header {
    margin-bottom: 0.2rem;
    color: var(--muted-dim);
}

.vmmap-row:hover {
    background: var(--surface-hover);
}

a.vmmap-row:hover {
    color: inherit;
}

.vmmap-row span:first-child,
.vmmap-row span:nth-child(2) {
    color: var(--terminal-blue);
}

.vmmap-row.code span:nth-child(3) {
    color: var(--pwndbg-execute);
}

.vmmap-row.rodata span:nth-child(3) {
    color: var(--terminal-cyan);
}

.vmmap-row.stack span:nth-child(3) {
    color: var(--terminal-purple);
}

a.vmmap-row span:last-child {
    color: var(--accent);
}

a.vmmap-row:hover span:last-child {
    text-decoration: underline;
}

.muted-map {
    opacity: 0.55;
}

.pwndbg-section {
    margin-top: 1.2rem;
}

.pwndbg-registers {
    display: grid;
    gap: 0;
}

.pwndbg-registers > div {
    display: grid;
    grid-template-columns: 4rem auto;
}

.reg-name {
    display: inline-block;
    width: 3rem;
    color: var(--terminal-purple);
    font-weight: 700;
}

.reg-value {
    color: var(--foreground);
}

.pwndbg-registers a {
    color: var(--accent);
    text-decoration: none;
}

.pwndbg-registers a:hover {
    text-decoration: underline;
}

.pwndbg-recent {
    margin-top: 1.5rem;
}

.recent-row {
    display: grid;
    grid-template-columns: 110px 70px auto;
    gap: 0.5rem;
    padding: 0.1rem 0;
}

.recent-date {
    color: var(--muted-dim);
}

.recent-category {
    color: var(--terminal-purple);
}

.recent-row a {
    color: var(--foreground);
    text-decoration: none;
}

.recent-row a:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* Writeup list */

.writeups-page {
    width: 100%;
}

.writeup-card {
    margin-bottom: 1.5rem;
    padding: 1.4rem 1.5rem;
    border: 1px solid var(--border-subtle);
    background: var(--surface);
}

.writeup-card:hover {
    border-color: var(--border-hover);
}

.writeup-card-header h2 {
    margin: 0 0 0.45rem;
    font-size: 1.25rem;
    font-weight: 600;
}

.writeup-card-header h2 a {
    color: var(--foreground);
    text-decoration: none;
}

.writeup-card-header h2 a:hover {
    color: var(--accent);
}

.writeup-meta,
.writeup-tags {
    display: flex;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 0.85rem;
}

.writeup-meta {
    gap: 0.45rem;
}

.writeup-summary {
    margin: 1.2rem 0;
    color: var(--foreground);
    line-height: 1.6;
}

.writeup-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1.2rem;
}

.writeup-tags {
    gap: 0.55rem;
}

.writeup-read-more {
    flex-shrink: 0;
    color: var(--foreground);
    text-decoration: none;
}

.writeup-read-more:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* Writeup page */

.writeup-post > .post-title {
    font-weight: 600;
}

.writeup-single-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0;
    margin-top: 0.5rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.writeup-single-meta > *:not(:last-child)::after {
    content: " · ";
    margin: 0 0.55rem;
    color: var(--muted-dim);
}

.post-content {
    margin-top: 2rem;
    padding: 1.75rem 2rem;
    border: 1px solid var(--border-subtle);
    background: var(--surface);
}

.post-content :is(h2, h3, h4, h5, h6, b, strong) {
    font-weight: 600;
}

.post-content h2 {
    scroll-margin-top: 2rem;
}

.post-content > div > :first-child {
    margin-top: 0;
}

.post-content > div > :last-child {
    margin-bottom: 0;
}

/* TOC / scrollspy */

.writeup-body {
    position: relative;
}

.writeup-toc {
    display: none;
}

.writeup-toc nav > ul,
.writeup-toc-mobile nav > ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.writeup-toc li,
.writeup-toc-mobile nav li {
    margin: 0.35rem 0;
}

.writeup-toc a {
    position: relative;
    display: block;
    padding: 0.15rem 0 0.15rem 0.75rem;
    color: var(--muted);
    font-size: 0.85rem;
    line-height: 1.4;
    text-decoration: none;
    transition:
        color 0.15s ease,
        transform 0.15s ease;
}

.writeup-toc a::before {
    content: "";
    position: absolute;
    top: 0.25rem;
    bottom: 0.25rem;
    left: -1.05rem;
    width: 2px;
    background: transparent;
    transition: background 0.15s ease;
}

.writeup-toc a:hover {
    color: var(--accent);
    transform: translateX(3px);
}

.writeup-toc a.active {
    color: var(--accent);
    font-weight: 600;
    transform: translateX(4px);
}

.writeup-toc a.active::before {
    background: var(--accent);
}

.writeup-toc-mobile {
    margin: 1.5rem 0;
    padding: 0.8rem 1rem;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: var(--surface-soft);
}

.writeup-toc-mobile summary {
    color: var(--foreground);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.writeup-toc-mobile[open] summary {
    margin-bottom: 0.8rem;
}

.writeup-toc-mobile nav a {
    color: var(--muted);
    text-decoration: none;
}

.writeup-toc-mobile nav a:hover,
.writeup-toc-mobile a.active {
    color: var(--accent);
}

.writeup-toc-mobile a.active {
    font-weight: 600;
}

/* Writeup components */

.writeup-details {
    margin: 1.2rem 0;
    padding: 0.9rem 1rem;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: var(--surface-hover);
}

.writeup-details summary {
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.writeup-details summary:hover {
    opacity: 0.85;
}

.writeup-details[open] summary {
    margin-bottom: 0.8rem;
}

.writeup-image {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
    margin: 1.5rem auto;
    padding: 0;
    border: none;
    box-shadow: none;
}

.writeup-image-small {
    width: min(100%, clamp(220px, 30%, 340px));
}

.writeup-image-medium {
    width: 60%;
    max-width: 700px;
}

.writeup-image-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.writeup-image-row .writeup-image {
    width: 300px;
    margin: 0;
    object-fit: cover;
}

/* CTF page */

.ctfs-page {
    width: 100%;
}

.ctf-year {
    margin-bottom: 2.5rem;
}

.ctf-year h2 {
    margin-bottom: 1rem;
    font-weight: 600;
}

.ctf-table-wrapper {
    width: 100%;
    overflow-x: auto;
}

.ctf-table {
    width: 100%;
    min-width: 520px;
    table-layout: fixed;
}

.ctf-col-name {
    width: 38%;
}

.ctf-col-team {
    width: 22%;
}

.ctf-col-format {
    width: 23%;
}

.ctf-col-placement {
    width: 17%;
}

.ctf-table th,
.ctf-table td {
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--foreground);
    text-align: left;
    vertical-align: middle;
}

.ctf-table th {
    color: var(--foreground);
    font-weight: 700;
}

.ctf-table td {
    color: var(--foreground);
}

.ctf-table td:nth-child(2) {
    color: var(--accent);
}

.ctf-table tbody tr:hover {
    background: var(--surface-soft);
}

.ctf-link,
.ctf-link:visited,
.ctf-link:hover {
    color: inherit;
}

.ctf-link {
    text-decoration: none;
}

.ctf-link:hover {
    text-decoration: underline;
}

.ctf-placement {
    font-weight: 500;
}

.ctf-first,
.ctf-second,
.ctf-third {
    font-weight: 700;
}

.ctf-first {
    color: var(--placement-first);
}

.ctf-second {
    color: var(--placement-second);
}

.ctf-third {
    color: var(--placement-third);
}

/* 404 */

.pwndbg-404-body {
    min-height: 100vh;
    background: var(--background);
    color: var(--foreground-strong);
}

.pwndbg-404-page {
    padding: 1.2rem 1.4rem 2rem;
}

.pwndbg-404-shell {
    max-width: 1100px;
    margin: 0 auto;
    font-size: 0.95rem;
    line-height: 1.4;
}

.pwndbg-line {
    margin-bottom: 0.25rem;
}

.pwndbg-divider {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin: 0.7rem 0 0.45rem;
    color: var(--pwndbg-muted);
    font-size: 0.86rem;
    white-space: nowrap;
}

.pwndbg-divider::before,
.pwndbg-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--pwndbg-divider);
}

.crash-red,
.changed {
    color: var(--terminal-red);
}

.crash-address {
    color: var(--pwndbg-address);
}

.crash-function,
.current-arrow {
    color: var(--terminal-green);
}

.changed {
    display: inline-block;
    width: 0.8rem;
}

.pwndbg-regs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 2rem;
    row-gap: 0.15rem;
}

.pwndbg-regs > div {
    display: grid;
    grid-template-columns: 0.8rem 3rem auto;
    align-items: baseline;
    white-space: nowrap;
}

.pwndbg-disasm {
    display: grid;
    grid-template-columns: 1.2rem 7rem 11rem 4rem auto;
    align-items: baseline;
    column-gap: 0.7rem;
    white-space: nowrap;
}

.current-arrow,
.instr {
    font-weight: 700;
}

.instr {
    color: var(--pwndbg-bright);
}

.pwndbg-disasm-down {
    margin-left: 1.55rem;
    color: var(--pwndbg-muted);
}

.pwndbg-stack {
    display: flex;
    gap: 0.6rem;
    white-space: nowrap;
}

.stack-prefix {
    color: var(--terminal-purple);
}

.pwndbg-skipped {
    margin-top: 0.1rem;
    color: var(--pwndbg-muted);
}

.pwndbg-bt {
    display: grid;
    row-gap: 0.12rem;
}

.pwndbg-bt > div {
    display: grid;
    grid-template-columns: 1.2rem 1.5rem 12rem auto;
    align-items: baseline;
    column-gap: 0.6rem;
    white-space: nowrap;
}

.pwndbg-run {
    display: flex;
    align-items: baseline;
    gap: 0.7rem;
    margin-top: 0.2rem;
}

.pwndbg-run a {
    color: var(--foreground-strong);
    text-decoration: none;
}

.pwndbg-run a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.run-comment {
    color: var(--pwndbg-muted);
}

/* Footer */

.custom-footer {
    margin-top: 1.5rem;
    padding: 1rem 0 1.25rem;
    color: var(--muted-dim);
    font-size: 0.85rem;
    text-align: center;
}

.custom-footer span {
    white-space: nowrap;
}

/* Syntax highlighting */

/* Terminal marks the generic pre background as important. */
pre.chroma {
    background: var(--syntax-background) !important;
    color: var(--foreground-strong);
}

.chroma .k,
.chroma .kc,
.chroma .kd,
.chroma .kn,
.chroma .kp,
.chroma .kr,
.chroma .nf,
.chroma .fm {
    color: var(--syntax-yellow);
}

.chroma .kt,
.chroma .m,
.chroma .mb,
.chroma .mf,
.chroma .mh,
.chroma .mi,
.chroma .mo,
.chroma .il {
    color: var(--syntax-green);
}

.chroma .n,
.chroma .na,
.chroma .nb,
.chroma .nc,
.chroma .nd,
.chroma .ne,
.chroma .ni,
.chroma .nl,
.chroma .nn,
.chroma .no,
.chroma .nt,
.chroma .nv {
    color: var(--foreground-strong);
}

.chroma .s,
.chroma .s1,
.chroma .s2,
.chroma .sa,
.chroma .sb,
.chroma .sc,
.chroma .sd,
.chroma .se,
.chroma .sh,
.chroma .si,
.chroma .sx {
    color: var(--terminal-red);
}

.chroma .o,
.chroma .ow {
    color: var(--syntax-cyan);
}

.chroma .p {
    color: var(--syntax-punctuation);
}

.chroma .c,
.chroma .c1,
.chroma .ch,
.chroma .cm,
.chroma .cp,
.chroma .cpf,
.chroma .cs {
    color: var(--muted-dim);
    font-style: italic;
}

/* Responsive rules */

@media (min-width: 1350px) {
    .writeup-toc {
        position: absolute;
        top: 0;
        left: calc(100% + 32px);
        display: block;
        width: 230px;
        height: 100%;
    }

    .writeup-toc-inner {
        position: sticky;
        top: 2rem;
        padding-left: 1rem;
        border-left: 1px solid var(--border-subtle);
    }

    .writeup-toc-title {
        margin-bottom: 0.75rem;
        color: var(--muted);
        font-size: 0.8rem;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .writeup-toc-mobile {
        display: none;
    }
}

@media (max-width: 900px) {
    .pwndbg-404-shell {
        font-size: 0.88rem;
        overflow-wrap: anywhere;
    }

    .pwndbg-regs {
        grid-template-columns: 1fr;
        row-gap: 0.1rem;
    }

    .pwndbg-disasm,
    .pwndbg-bt > div,
    .pwndbg-stack {
        white-space: normal;
    }
}

@media (max-width: 800px) {
    .vmmap-row {
        grid-template-columns: 14ch 14ch 5ch 6ch 6ch minmax(8ch, 1fr);
        column-gap: 0.45rem;
    }
}

@media (max-width: 684px) {
    .shell-header {
        margin-bottom: 2rem;
        padding-top: 1.2rem;
        font-size: 0.85rem;
    }

    .shell-prompt {
        overflow-wrap: anywhere;
    }

    .shell-nav {
        gap: 1rem;
    }

    .pwndbg-home {
        font-size: 0.82rem;
    }

    .recent-row {
        grid-template-columns: 1fr;
        gap: 0;
        margin-bottom: 0.7rem;
    }

    .writeup-card {
        padding: 1rem;
    }

    .writeup-card-footer {
        flex-direction: column;
        align-items: flex-start;
    }

    .post-content {
        padding: 1.2rem;
    }

    .pwndbg-404-page {
        padding: 1rem;
    }

    .pwndbg-404-shell {
        font-size: 0.8rem;
        line-height: 1.35;
    }

    .pwndbg-divider {
        white-space: normal;
    }

    .pwndbg-disasm {
        grid-template-columns: 1rem 6rem 1fr;
    }

    .pwndbg-disasm .instr,
    .pwndbg-disasm .crash-red {
        grid-column: 2 / -1;
        margin-left: 1.7rem;
    }

    .pwndbg-bt > div {
        grid-template-columns: 1rem 1.3rem 1fr;
    }

    .pwndbg-bt > div span:last-child {
        grid-column: 2 / -1;
        margin-left: 1.9rem;
    }

    .pwndbg-stack {
        flex-direction: column;
        gap: 0.15rem;
    }

    .custom-footer {
        padding-bottom: 1rem;
        font-size: 0.78rem;
    }
}

@media (max-width: 600px) {
    .pwndbg-scroll {
        overflow-x: auto;
    }

    .vmmap {
        min-width: 700px;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}
