:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1f2630;
  --border: #2d3540;
  --text: #e6edf3;
  --muted: #8b949e;
  --dim: #565e68;
  --accent: #3fb950;
  --accent-ink: #04130a;
  --link: #58a6ff;
  --danger: #f85149;
  --warn: #d29922;
  --radius: 8px;
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --c-web: #58a6ff; --c-pwn: #f85149; --c-rev: #d2a8ff; --c-crypto: #e3b341;
  --c-forensics: #3fb950; --c-misc: #8b949e; --c-osint: #39c5cf; --c-stego: #ff7b72;
  --c-blockchain: #a371f7; --c-hardware: #ffa657; --c-mobile: #7ee787;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa; --surface: #ffffff; --surface-2: #eef1f4; --border: #d0d7de;
    --text: #1f2328; --muted: #59636e; --accent: #1a7f37; --accent-ink: #ffffff;
    --dim: #a0a8b0;
    --link: #0969da; --danger: #cf222e; --warn: #9a6700;
    --c-web: #0969da; --c-pwn: #cf222e; --c-rev: #8250df; --c-crypto: #9a6700;
    --c-forensics: #1a7f37; --c-misc: #59636e; --c-osint: #1b7c83; --c-stego: #bc4c00;
    --c-blockchain: #6639ba; --c-hardware: #bc4c00; --c-mobile: #2da44e;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .hash { font-family: var(--mono); font-size: .88em; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; overflow-x: auto; }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 1.2rem 0 .6rem; }
h2 { font-size: 1.2rem; margin: 2rem 0 .75rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.lead { color: var(--muted); font-size: 1.05rem; max-width: 70ch; }
.empty { color: var(--muted); padding: 1rem 0; }
.inline { display: inline; margin: 0; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { font-family: var(--mono); font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand .prompt { color: var(--accent); }
.nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.nav a, .linklike { color: var(--text); font-size: .95rem; }
.linklike { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; }
.linklike:hover { text-decoration: underline; }
.pill { background: var(--warn); color: #000; border-radius: 999px; padding: 0 7px; font-size: .75rem; font-weight: 700; }

/* buttons */
.btn { display: inline-block; background: var(--accent); color: var(--accent-ink) !important; border: 1px solid transparent; border-radius: var(--radius);
  padding: 8px 14px; font: 600 .95rem var(--sans); cursor: pointer; text-decoration: none !important; text-align: center; }
.btn:hover { filter: brightness(1.1); }
.btn-sm { padding: 4px 10px; font-size: .88rem; }
.btn-ghost { background: transparent; color: var(--text) !important; border-color: var(--border); }
.btn-block { display: block; width: 100%; margin-top: 8px; }

/* messages */
.messages { list-style: none; padding: 0; margin: 16px 0 0; }
.msg { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 8px; border: 1px solid var(--border); background: var(--surface); }
.msg-success { border-color: var(--accent); }
.msg-error { border-color: var(--danger); color: var(--danger); }

/* hero */
.hero { padding: 2.5rem 0 1rem; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.5rem); max-width: 22ch; }
.search { display: flex; gap: 8px; margin: 1.25rem 0; max-width: 720px; }
.search input { flex: 1; min-width: 0; }
.stats { display: flex; gap: 32px; flex-wrap: wrap; margin-top: 1.5rem; }
.stats div { display: flex; flex-direction: column; }
.stats b { font: 700 1.6rem var(--mono); }
.stats span { color: var(--muted); font-size: .85rem; }

.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.section-head h1, .section-head h2 { margin-bottom: .6rem; }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.cat-card { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid currentColor; border-radius: var(--radius); font-weight: 600; }
.cat-card b { font-family: var(--mono); color: var(--text); }
.cat-card:hover { background: var(--surface-2); text-decoration: none; }

.card-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }

/* tables */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.num { text-align: right !important; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.has span { font: .75rem var(--mono); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; margin-right: 3px; color: var(--muted); white-space: nowrap; }
.matrix th a { color: inherit; }
.leaderboard .rank { color: var(--muted); width: 2.5rem; }
.leaderboard .handle { font-family: var(--mono); font-weight: 600; }
.leaderboard tr.top-1 .rank, .leaderboard tr.top-2 .rank, .leaderboard tr.top-3 .rank { font-size: 0; }
.leaderboard tr.top-1 .rank::before { content: "🥇"; font-size: 1rem; }
.leaderboard tr.top-2 .rank::before { content: "🥈"; font-size: 1rem; }
.leaderboard tr.top-3 .rank::before { content: "🥉"; font-size: 1rem; }

/* difficulty voting + likes */
.ratings { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: center; margin: 10px 0; }
.rating { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rating-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.vote-form { display: inline-flex; gap: 4px; margin-left: 4px; }
.vote-chip { font: .78rem var(--mono); padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--muted); cursor: pointer; }
.vote-chip:hover { color: var(--text); border-color: var(--text); }
.vote-chip.active { background: var(--accent, #2563eb); border-color: var(--accent, #2563eb); color: #fff; }
.like-btn { cursor: pointer; }
.like-btn.liked { color: #e0245e; border-color: #e0245e; }
.table th .sort-link { color: inherit; text-decoration: none; }
.table th .sort-link:hover, .table th .sort-link.active { color: var(--text); }

/* category / difficulty / status chips */
.cat { font-weight: 600; white-space: nowrap; }
.cat-web { color: var(--c-web); } .cat-pwn { color: var(--c-pwn); } .cat-rev { color: var(--c-rev); }
.cat-crypto { color: var(--c-crypto); } .cat-forensics { color: var(--c-forensics); } .cat-misc { color: var(--c-misc); }
.cat-osint { color: var(--c-osint); } .cat-stego { color: var(--c-stego); } .cat-blockchain { color: var(--c-blockchain); }
.cat-hardware { color: var(--c-hardware); } .cat-mobile { color: var(--c-mobile); }
.cat-bg-web { background: var(--c-web); } .cat-bg-pwn { background: var(--c-pwn); } .cat-bg-rev { background: var(--c-rev); }
.cat-bg-crypto { background: var(--c-crypto); } .cat-bg-forensics { background: var(--c-forensics); } .cat-bg-misc { background: var(--c-misc); }
.cat-bg-osint { background: var(--c-osint); } .cat-bg-stego { background: var(--c-stego); } .cat-bg-blockchain { background: var(--c-blockchain); }
.cat-bg-hardware { background: var(--c-hardware); } .cat-bg-mobile { background: var(--c-mobile); }

/* ctf category share bar */
.share-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; gap: 2px; background: var(--surface-2); }
.share-legend { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 10px 0 0; font-size: .9rem; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }

.diff { font-size: .85rem; white-space: nowrap; }
.diff::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: currentColor; }
.diff-1 { color: var(--c-osint); } .diff-2 { color: var(--accent); } .diff-3 { color: var(--warn); }
.diff-4 { color: var(--c-hardware); } .diff-5 { color: var(--danger); }

.status { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; border-radius: 4px; padding: 1px 6px; margin-left: 6px; border: 1px solid currentColor; vertical-align: middle; }
.status-pending { color: var(--warn); } .status-approved { color: var(--accent); } .status-rejected { color: var(--danger); }

.chip, .tag { display: inline-block; font-size: .82rem; border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; background: var(--surface); color: var(--text); }
.tag { color: var(--muted); text-decoration: none; }
.tag:hover { border-color: var(--text); color: var(--text); }
.tag-sm { font-size: .72rem; padding: 1px 7px; }
.row-tags { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tag-cloud .tag { font-size: .9rem; }
.tag-family { border-color: var(--accent, #6ea8fe); color: var(--text); font-weight: 600; }
.tag-family:hover { border-color: var(--text); }
.tag-sub { font-size: .8rem; }
.tags-families-h { font-size: 1rem; margin: 20px 0 0; }
.tags-families-h .muted { font-weight: 400; font-size: .82rem; }
.family-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.family-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 2px 0 2px 14px; }
.domain-list { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.domain-block { padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.tag-domain { border-color: var(--accent, #6ea8fe); background: var(--surface); font-weight: 700; font-size: .95rem; margin-bottom: 4px; }
.tag-domain:hover { border-color: var(--text); }
.see-also { font-size: .78rem; margin-left: 4px; }
.see-also a { color: var(--muted); }
.see-also a:hover { color: var(--text); }
.domain-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: baseline; margin-bottom: 6px; }
.small { font-size: .78rem; }
details.family { margin: 2px 0 2px 10px; }
details.family > summary { cursor: pointer; list-style: none; padding: 3px 0; display: inline-flex; align-items: baseline; gap: 6px; }
details.family > summary::-webkit-details-marker { display: none; }
details.family > summary .tag-family { cursor: pointer; }
details.family[open] > summary .tag-family { border-color: var(--text); color: var(--text); }
.family-body { padding: 4px 0 8px 18px; display: flex; flex-direction: column; gap: 6px; }
.family-body .rollup { display: inline-block; }
.sub-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.sub-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; min-width: 90px; }


.crumbs { margin-top: 1.25rem; color: var(--muted); font-size: .9rem; }
.meta { color: var(--muted); }
.dots > * + *::before { content: "·"; color: var(--muted); margin: 0 .5em; display: inline-block; }
.weight { font-family: var(--mono); color: var(--text); }
.prose { max-width: 75ch; }
.prose img { max-width: 100%; }

/* challenge page */
.challenge-head h1 { margin-bottom: .5rem; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.layout-2 { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 32px; margin-top: 1rem; }
.files { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 16px 16px; align-self: start; position: sticky; top: 72px; }
.files h2 { margin-top: 1rem; }
.file-list { list-style: none; padding: 0; margin: 0; }
.file-list li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; word-break: break-all; }
.file-list li:last-child { border-bottom: 0; }
.hash { color: var(--muted); font-size: .75rem; }
.writeup { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 10px; }
.writeup header { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.writeup p { margin: .5rem 0 0; word-break: break-all; }
details summary { cursor: pointer; }
.writeup-form { margin-top: 1rem; }
.writeup-form summary { list-style: none; display: inline-block; }
.writeup-form summary::-webkit-details-marker { display: none; }

/* browse */
.browse { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 24px; align-items: start; }
.filters { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow-y: auto; }
.filters fieldset { border: 0; padding: 0; margin: 0 0 14px; }
.filters legend { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; padding: 0; }
.check { display: flex; align-items: center; gap: 8px; padding: 2px 0; cursor: pointer; font-size: .92rem; }
.range { display: flex; align-items: center; gap: 6px; }
.range input { width: 100%; min-width: 0; }
.pager { display: flex; gap: 16px; justify-content: center; padding: 16px; }

/* forms */
input:not([type=checkbox]):not([type=radio]), select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; font: inherit; width: 100%; }
input[type=file] { padding: 6px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--link); outline-offset: -1px; }
.form { margin-top: 1rem; }
.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 4px; }
.field label { font-weight: 600; font-size: .92rem; }
.help { color: var(--muted); font-size: .82rem; }
.help ul { margin: 4px 0; padding-left: 18px; }
.error { color: var(--danger); font-size: .85rem; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.req { color: var(--danger); }
.narrow { max-width: 680px; }
.auth { max-width: 420px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.note { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--link); border-radius: var(--radius); padding: 10px 14px; margin: 1rem 0; }
.note p { margin: .4rem 0 0; }
.note-warn { border-left-color: var(--warn); }
.plain { list-style: none; padding: 0; margin: .4rem 0 0; }
.plain code, .note code { word-break: break-all; }
.ext { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.ext span { font: 400 .78rem var(--mono); opacity: .85; }

.flag { font-size: 1.05em; line-height: 1; font-family: "Noto Color Emoji", "Twemoji Mozilla", "Segoe UI Emoji", "Apple Color Emoji", sans-serif; font-style: normal; }

.footer { color: var(--muted); font-size: .85rem; padding-top: 3rem; padding-bottom: 2rem; border-top: 1px solid var(--border); margin-top: 3rem; }
.footer-credit { text-align: center; color: var(--muted); font-size: .85rem; margin: 1.5rem 0 0; }

@media (max-width: 860px) {
  .layout-2, .browse { grid-template-columns: 1fr; }
  .files, .filters { position: static; max-height: none; }
}

/* Footer: top-countries ranking (uses theme vars so text stays readable in both modes) */
.footer-rank h3 { color: var(--text); font-size: .95rem; margin: 0 0 .7rem; }
.rank-global { margin-left: .6rem; font-size: .85rem; font-weight: 500; color: var(--accent); }
.rank-list { list-style: none; margin: 0 0 1.4rem; padding: 0; display: grid;
  grid-template-columns: repeat(2, 1fr); gap: .35rem .9rem; }
@media (max-width: 640px) {
  .rank-list { grid-template-columns: 1fr; }
  /* Tighter top bar so the nav doesn't eat the screen */
  .topbar-inner { gap: 8px 12px; padding-top: 8px; padding-bottom: 8px; }
  .nav { gap: 10px 12px; }
  .nav a, .linklike { font-size: .9rem; }
  .wrap { padding: 0 14px; }
  /* Denser tables: smaller padding/font so more fits before scrolling */
  .table th, .table td { padding: 6px 9px; font-size: .9rem; }
  .table th { font-size: .72rem; }
  /* Scroll hint: let the viewer know a wide table pans sideways */
  .table-scroll { -webkit-overflow-scrolling: touch; }
  /* Full-width action buttons read better under the thumb */
  .btn { display: inline-block; }
}
.rank-list li a { display: flex; align-items: center; gap: .55rem; padding: .32rem .55rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  text-decoration: none; }
.rank-list li a:hover { border-color: var(--accent); }
.rank-pos { width: 1.4rem; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-list .flag { font-size: 1.05rem; }
.rank-name { flex: 1; min-width: 0; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-n { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; }

/* Country ranking: rank column + medals */
.rank-col { width: 2.2rem; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.medal { font-size: 1.15rem; }

/* FAQ */
.faq { max-width: 760px; }
.faq h2 { margin: 1.8rem 0 .6rem; font-size: 1.05rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; }
.faq-item { border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); margin-bottom: .5rem; }
.faq-item > summary { cursor: pointer; padding: .7rem .9rem; font-weight: 600; color: var(--text);
  list-style: none; display: flex; justify-content: space-between; align-items: center; }
.faq-item > summary::after { content: "+"; color: var(--muted); font-weight: 400; margin-left: 1rem; }
.faq-item[open] > summary::after { content: "–"; }
.faq-item > summary:hover { color: var(--accent); }
.faq-item > .prose { padding: 0 .9rem .9rem; color: var(--text); }
.faq-item > .prose p:first-child { margin-top: 0; }

/* Team ranking: year archive tabs + filters */
.year-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: .4rem 0 0; }
.year-tabs .chip { font-family: var(--mono); }
.year-tabs .chip:hover { border-color: var(--accent); text-decoration: none; }
.year-tabs .chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.team-filters { flex-wrap: wrap; }
.team-filters select { flex: 1 1 180px; width: auto; }

/* Inactive CTFs (no challenges yet) — dimmed to recede from active ones */
tr.ctf-inactive td, tr.ctf-inactive a { color: var(--dim); }

/* CTF flag format chip */
.flag-format { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; font-family: var(--mono); font-size: .85em; color: var(--text); }
