:root {
  --bg: #ffffff;
  --surface: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --code-bg: #f8fafc;
}
[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --code-bg: #162032;
}

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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  transition: background 0.2s, color 0.2s;
}

nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.nav-left { display: flex; align-items: center; gap: 2rem; }
.nav-brand { font-weight: 700; font-size: 1.25rem; text-decoration: none; color: var(--text); }
.nav-links {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2.5rem;
  align-items: center;
}
.nav-links a {
  text-decoration: none;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.nav-links a:hover, .nav-links a.active { color: var(--accent); }
#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 0.3rem;
  color: var(--text);
  cursor: pointer;
  padding: 0.25rem 0.6rem;
  font-size: 1.15rem;
  line-height: 1.4;
}

main { max-width: 800px; margin: 0 auto; padding: 2.5rem 1.5rem; }

section { margin-bottom: 3rem; }
h1 { font-size: 2rem; margin-bottom: 0.4rem; }
h2 {
  font-size: 1.25rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--accent);
  display: inline-block;
}

.tagline { color: var(--muted); margin-bottom: 0.9rem; }
.bio { margin-bottom: 1rem; }
.links { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.links a {
  color: var(--accent);
  text-decoration: none;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--accent);
  border-radius: 0.3rem;
  font-size: 0.875rem;
}
.links a:hover { background: var(--accent); color: #fff; }
.icon-link { display: inline-flex; align-items: center; gap: 0.4rem; }

/* Experience */
.entry {
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border-radius: 0.5rem;
  border-left: 3px solid var(--accent);
}
.entry-header { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.2rem; }
.date { color: var(--muted); font-size: 0.875rem; }
.company { color: var(--muted); font-size: 0.875rem; margin-bottom: 0.6rem; }
.points-list { padding-left: 1.2rem; }
.points-list li { font-size: 0.9rem; margin-bottom: 0.3rem; color: var(--text); }

/* CTF table */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.6rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--surface); font-weight: 600; }
tr:hover > td { background: var(--surface); }

/* Writeups — card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.ext-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  overflow: hidden;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ext-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.ext-thumb {
  position: relative;
  height: 130px;
  background: var(--border);
  overflow: hidden;
}
.ext-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.thumb-fallback {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.thumb-fallback.visible { display: flex; }

.ext-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  flex: 1;
}
.ext-body h3 {
  font-size: 0.9rem;
  line-height: 1.45;
  flex: 1;
}
.ext-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: 0.4rem;
}
.ext-icon { color: var(--accent); font-size: 1rem; font-weight: 700; }

/* Local .md list (future use) */
.writeup-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  margin-bottom: 0.65rem;
  cursor: pointer;
  background: var(--surface);
}
.writeup-item:hover { border-color: var(--accent); }
.writeup-item h3 { font-size: 0.95rem; margin-bottom: 0.3rem; }

.writeup-meta { color: var(--muted); font-size: 0.8rem; }
.tags { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.tag {
  font-size: 0.72rem;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  color: var(--muted);
}
.tag.source { color: var(--accent); border-color: var(--accent); }

/* Reader */
#back-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 0.3rem;
  color: var(--accent);
  cursor: pointer;
  padding: 0.35rem 0.9rem;
  margin-bottom: 1.75rem;
  font-size: 0.875rem;
}
#back-btn:hover { background: var(--surface); }

article { line-height: 1.8; }
article h1 { font-size: 1.75rem; margin-bottom: 1rem; }
article h2 { font-size: 1.2rem; display: block; margin: 1.75rem 0 0.65rem; padding-bottom: 0.3rem; border-bottom: 1px solid var(--border); }
article h3 { font-size: 1.05rem; margin: 1.25rem 0 0.5rem; }
article p { margin-bottom: 0.9rem; }
article ul, article ol { margin: 0.25rem 0 0.9rem 1.5rem; }
article li { margin-bottom: 0.2rem; }
article a { color: var(--accent); }
article blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.5rem 1rem;
  color: var(--muted);
  margin: 0.9rem 0;
  background: var(--surface);
  border-radius: 0 0.3rem 0.3rem 0;
}
article pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  margin: 0.9rem 0;
}
article code {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 0.15rem 0.35rem;
  border-radius: 0.2rem;
}
article pre > code { background: none; padding: 0; font-size: 0.85rem; }
article img { max-width: 100%; border-radius: 0.4rem; margin: 0.5rem 0; }
article hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
article table { margin: 0.9rem 0; }

footer {
  text-align: center;
  padding: 2rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.875rem;
}

@media (max-width: 600px) {
  nav { padding: 0.85rem 1rem; }
  main { padding: 1.5rem 1rem; }
  th, td { padding: 0.5rem 0.6rem; }
  .writeup-item { flex-direction: column; align-items: flex-start; gap: 0.4rem; }
}
