/* ==========================================================================
   Cheatbox styling: a terminal-flavoured skin on top of the Flex theme.
   Colours are tokens so light/dark mode only has to swap variables.
   ========================================================================== */

:root {
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Source Code Pro', ui-monospace, 'SFMono-Regular', Consolas, monospace;

  --accent: #1f8a43;
  --accent-strong: #166b33;
  --accent-soft: rgba(31, 138, 67, .1);
  --gold: #b7860b;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2128;
  --muted: #5d6875;
  --border: #e2e6eb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --shadow-hover: 0 2px 4px rgba(16, 24, 40, .06), 0 12px 28px rgba(16, 24, 40, .1);
  --inline-code-bg: #eef3ef;
  --inline-code-text: #17602f;

  /* Code blocks and the sidebar stay dark in both themes: it's a terminal. */
  --term-bg: #16191d;
  --term-bar: #22262c;
  --term-border: #2c3138;
  --sidebar-bg: #121518;

  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  body:not(.light-theme) {
    --accent: #5fd37f;
    --accent-strong: #8ae3a2;
    --accent-soft: rgba(95, 211, 127, .12);
    --gold: #ffd54a;
    --bg: #0f1215;
    --surface: #171b20;
    --text: #e4e8ed;
    --muted: #96a1ae;
    --border: #262c33;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-hover: 0 8px 24px rgba(0, 0, 0, .45);
    --inline-code-bg: #1e2a22;
    --inline-code-text: #8ae3a2;
    --term-bg: #0b0d0f;
    --term-bar: #15181c;
    --term-border: #262c33;
    --sidebar-bg: #0b0d0f;
  }
}

body.dark-theme {
  --accent: #5fd37f;
  --accent-strong: #8ae3a2;
  --accent-soft: rgba(95, 211, 127, .12);
  --gold: #ffd54a;
  --bg: #0f1215;
  --surface: #171b20;
  --text: #e4e8ed;
  --muted: #96a1ae;
  --border: #262c33;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-hover: 0 8px 24px rgba(0, 0, 0, .45);
  --inline-code-bg: #1e2a22;
  --inline-code-text: #8ae3a2;
  --term-bg: #0b0d0f;
  --term-bar: #15181c;
  --term-border: #262c33;
  --sidebar-bg: #0b0d0f;
}

/* ---------- Base ---------- */

html { scroll-behavior: smooth; scroll-padding-top: 24px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--accent-strong); }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

::selection { background: rgba(95, 211, 127, .3); }

h1, h2, h3, h4 { font-family: var(--font-sans); letter-spacing: -.02em; line-height: 1.25; color: var(--text); }

code, kbd, samp, pre, main article code, main article pre { font-family: var(--font-mono); }

hr { border: 0; height: 1px; background: var(--border); }

/* ---------- Sidebar ---------- */

aside {
  background:
    radial-gradient(ellipse at top, rgba(95, 211, 127, .10), transparent 60%),
    linear-gradient(180deg, var(--sidebar-bg), #0d1013);
  border-right: 1px solid rgba(255, 255, 255, .04);
}

body.dark-theme aside { background: radial-gradient(ellipse at top, rgba(95, 211, 127, .08), transparent 60%), var(--sidebar-bg); }

aside > div:first-child { padding-bottom: 8px; }

aside div img {
  width: 128px;
  height: 128px;
  object-fit: cover;
  padding: 4px;
  background: linear-gradient(135deg, #5fd37f, #ffd54a);
  box-shadow: 0 0 0 4px #121518, 0 0 36px rgba(95, 211, 127, .25);
  transition: transform .3s ease, box-shadow .3s ease;
}
aside div a:hover img { transform: rotate(-4deg) scale(1.03); box-shadow: 0 0 0 4px #121518, 0 0 44px rgba(95, 211, 127, .4); }

aside h1 { font-size: 1.6em; font-weight: 800; letter-spacing: -.02em; }
aside h1 a, aside h1 a:hover { color: #fff; }
aside h1 a::before { content: '~/'; color: #5fd37f; font-family: var(--font-mono); font-weight: 500; margin-right: 2px; }
aside h1 a::after {
  content: '';
  display: inline-block;
  width: .5em;
  height: 1em;
  margin-left: 4px;
  vertical-align: -.12em;
  background: #5fd37f;
  animation: blink 1.1s steps(1) infinite;
}

aside div p { color: #aab4bf; font-size: .95em; letter-spacing: .02em; }

aside nav ul.list li, aside nav ul.list li span {
  font-family: var(--font-mono);
  font-size: 12px;
  color: #7f8b98;
  text-transform: none;
}

ul.social a {
  background: rgba(255, 255, 255, .06) !important;
  border: 1px solid rgba(255, 255, 255, .08);
  color: #e4e8ed;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
ul.social a:hover { background: rgba(95, 211, 127, .15) !important; border-color: rgba(95, 211, 127, .5); color: #fff; }
ul.social li + li { margin-left: 6px; }

/* Search + widgets: align with the new type */
.site-search input { font-family: var(--font-mono); font-size: 13px; background: rgba(0, 0, 0, .35); border-color: rgba(255, 255, 255, .12); }
aside .widgets-container .widget { font-family: var(--font-sans); background: rgba(255, 255, 255, .03); border-color: rgba(255, 255, 255, .08); box-shadow: none; width: 170px; }
aside .widgets-container .row { background: rgba(0, 0, 0, .3); }
.widget .value, aside .widgets-container .update-time { font-family: var(--font-mono); }
.widget .value { font-size: 19px; }

@media screen and (min-width: 768px) {
  aside {
    overflow-y: auto;          /* the sidebar is fixed at 100vh: let it scroll on short screens */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .15) transparent;
    width: 300px;
  }
  main { padding-left: 300px; }
}

@media screen and (min-width: 1400px) {
  aside { width: 340px; }
  main { padding-left: 340px; }
}

/* ---------- Main column ---------- */

main { background: var(--bg); min-height: 100vh; height: auto !important; }
main article, main .hero, main .listing-header, main .post-list, main .pagination {
  max-width: 820px;
  margin-left: auto !important;
  margin-right: auto !important;
  padding-left: 32px;
  padding-right: 32px;
  box-sizing: border-box;
}

@media (max-width: 600px) {
  main article, main .hero, main .listing-header, main .post-list { padding-left: 16px; padding-right: 16px; }
}

/* ---------- Home hero ---------- */

.hero { padding-top: 56px; padding-bottom: 24px; }
.hero h1 { font-size: clamp(1.9rem, 4vw, 2.7rem); font-weight: 800; margin: 28px 0 8px; }
.hero h1::after {
  content: '';
  display: block;
  width: 64px;
  height: 4px;
  margin-top: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
}
.hero .lead { color: var(--muted); font-size: 1.1em; margin: 0 0 22px; max-width: 60ch; }

.terminal {
  background: var(--term-bg);
  border: 1px solid var(--term-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  max-width: 520px;
}
.terminal-bar, .code-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  background: var(--term-bar);
  border-bottom: 1px solid var(--term-border);
}
.terminal-bar span, .code-bar .dots span {
  width: 11px; height: 11px; border-radius: 50%; background: #ff5f57; display: inline-block;
}
.terminal-bar span:nth-child(2), .code-bar .dots span:nth-child(2) { background: #febc2e; }
.terminal-bar span:nth-child(3), .code-bar .dots span:nth-child(3) { background: #28c840; }
.terminal-bar em { margin-left: 8px; color: #7f8b98; font: 12px var(--font-mono); font-style: normal; }
.terminal pre {
  margin: 0;
  padding: 16px 18px 18px;
  color: #d7dde4;
  font: 14px/1.7 var(--font-mono);
  background: transparent !important;
  border: 0 !important;
  white-space: pre-wrap;
}
.t-prompt { color: #5fd37f; font-weight: 700; }
.t-out { color: #ffd54a; }
.t-cursor {
  display: inline-block; width: .55em; height: 1.1em; vertical-align: -.2em;
  background: #d7dde4; animation: blink 1.1s steps(1) infinite;
}

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

/* Live typing (driven by custom.js; without JS every line is simply shown) */
.t-line { display: block; min-height: 1.7em; }
.t-out a { color: #ffd54a; text-decoration: underline; text-decoration-color: rgba(255, 213, 74, .4); text-underline-offset: 3px; }
.t-out a:hover { color: #fff; text-decoration-color: #fff; }
.terminal.is-typing .t-line.t-pending { display: none; }
.terminal.is-typing .t-cursor.t-busy { animation: none; }       /* solid while typing, blinks when idle */
.t-out.t-reveal { animation: t-reveal .25s ease-out; }
@keyframes t-reveal { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

/* Interactive shell */
.terminal.is-interactive { cursor: text; }
.terminal.is-interactive .t-screen { max-height: 340px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #3a414a transparent; }
.t-prompt-line { display: flex; align-items: center; gap: .55em; }
.t-input {
  flex: 1;
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: #e4e8ed;
  caret-color: #5fd37f;
  font: inherit;
}
.t-input::placeholder { color: #5d6670; }
.t-input:disabled { opacity: .6; }
.t-out.t-shell { color: #d7dde4; }
.t-dim { color: #7f8b98; }
.t-ok { color: #5fd37f; font-weight: 700; }
.t-gold { color: #ffd54a; }
@media (max-width: 600px) { .t-input { font-size: 16px; } }   /* stop iOS zooming on focus */

.tag-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-strip a {
  font: 500 13px var(--font-mono);
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  transition: border-color .15s ease, color .15s ease, transform .15s ease;
}
.tag-strip a span { color: var(--muted); margin-left: 2px; }
.tag-strip a:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.tag-strip a.more { border-style: dashed; color: var(--muted); }

/* ---------- Listing header (tag / category / author pages) ---------- */

.listing-header { padding-top: 56px; padding-bottom: 8px; }
.listing-header h1 { font-size: 2.2rem; margin: 4px 0; font-weight: 800; }
.listing-header p { color: var(--muted); margin: 0; }
.listing-header .eyebrow, .eyebrow {
  font: 600 12px var(--font-mono); text-transform: uppercase; letter-spacing: .12em; color: var(--accent);
}

/* ---------- Post cards ---------- */

.post-list { display: grid; gap: 14px; padding-top: 12px; padding-bottom: 40px; }

main article.post-card {
  position: relative;
  margin: 0 !important;
  padding: 20px 22px;
  max-width: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
main article.post-card::before {
  content: '';
  position: absolute; left: -1px; top: 18px; bottom: 18px; width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  opacity: 0;
  transition: opacity .18s ease;
}
main article.post-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
main article.post-card:hover::before { opacity: 1; }

.post-card h2 { font-size: 1.2rem; font-weight: 700; margin: 0 0 6px; }
.post-card h2 a { color: var(--text); }
/* Make the whole card clickable while keeping tag links usable. */
.post-card h2 a::after { content: ''; position: absolute; inset: 0; border-radius: var(--radius); }
.post-card:hover h2 a { color: var(--accent); }

.post-meta { color: var(--muted); font-size: .88rem; margin: 0; }
.post-tags { display: inline-flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; position: relative; z-index: 1; }
.post-meta .post-tags { margin: 0; vertical-align: middle; }
.post-tags a {
  font: 500 12px var(--font-mono);
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}
.post-tags a:hover { background: var(--accent); color: var(--surface); }

/* ---------- Single article ---------- */

main article.single { padding-top: 48px; padding-bottom: 24px; }
main article.single header h1 { font-size: clamp(1.7rem, 3.4vw, 2.35rem); font-weight: 800; margin: 0 0 12px; }
main article.single header p.post-meta { font-size: .9rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
main article.single header { padding-bottom: 20px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }

.article-body { font-size: 1.02rem; }
.article-body p, .article-body li { line-height: 1.75; }
.article-body h2, .article-body h3 { position: relative; margin: 2.2em 0 .7em; }
.article-body h2 { font-size: 1.4rem; font-weight: 700; }
.article-body h3 { font-size: 1.15rem; font-weight: 700; }
.article-body h2::before {
  content: '#';
  font-family: var(--font-mono);
  color: var(--accent);
  margin-right: .4em;
  opacity: .8;
}
.article-body .headerlink {
  margin-left: .4em;
  font-size: .8em;
  color: var(--muted);
  opacity: 0;
  transition: opacity .15s ease;
}
.article-body h2:hover .headerlink, .article-body h3:hover .headerlink, .article-body .headerlink:focus { opacity: 1; }

.article-body img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 18px 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

main article blockquote {
  margin: 1.5em 0;
  padding: 14px 18px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  border-left: 4px solid var(--accent) !important;
  border-radius: 10px;
  background: var(--accent-soft);
  font-size: .97rem;
  font-weight: 400;
}
main article blockquote p { margin: 0; }

/* Inline code */
main article *:not(pre) > code {
  font-size: .86em;
  white-space: normal;
  color: var(--inline-code-text);
  background: var(--inline-code-bg);
  border: 0;
  border-radius: 5px;
  padding: .15em .4em;
}

/* Code blocks: a terminal window with a copy button (bar is added by custom.js) */
main article div.highlight, main article .code-window {
  margin: 1.2em 0 1.6em;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--term-border);
  background: var(--term-bg);
  box-shadow: var(--shadow);
}
main article .code-window div.highlight { margin: 0; border: 0; border-radius: 0; box-shadow: none; }
main article div.highlight pre {
  margin: 0;
  padding: 16px 18px;
  border: 0;
  border-radius: 0;
  background: var(--term-bg) !important;
  font-size: 13.5px;
  line-height: 1.65;
  tab-size: 4;
  scrollbar-width: thin;
  scrollbar-color: #3a414a transparent;
}
main article .highlight, main article .highlight pre { background: var(--term-bg) !important; }
main article div.highlight pre, main article div.highlight pre .w { color: #e4e8ed; }

.code-bar { justify-content: space-between; padding: 7px 10px 7px 12px; }
.code-bar .dots { display: inline-flex; gap: 7px; }
.code-bar .lang { font: 11px var(--font-mono); color: #7f8b98; text-transform: lowercase; margin-left: 10px; margin-right: auto; }
.copy-btn {
  font: 500 12px var(--font-mono);
  color: #c4ccd5;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 6px;
  padding: 3px 9px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.copy-btn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.copy-btn.copied { color: #5fd37f; border-color: rgba(95, 211, 127, .5); }

/* Prev / next */
.post-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 48px 0 8px; }
.post-nav a {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s ease, transform .15s ease;
}
.post-nav a:hover { border-color: var(--accent); transform: translateY(-1px); }
.post-nav small { display: block; color: var(--muted); font: 12px var(--font-mono); margin-bottom: 4px; }
.post-nav span { font-weight: 600; line-height: 1.4; }
.post-nav .older { grid-column: 2; text-align: right; }
@media (max-width: 600px) {
  .post-nav { grid-template-columns: 1fr; }
  .post-nav .older { grid-column: 1; }
}

/* Archives & tags pages */
main article.single dl dt { margin-top: 1em; font: 600 13px var(--font-mono); color: var(--muted); }
main article.single dl dd { margin: 4px 0 0; }
main article.single ul.list li { display: inline-block; margin: 0 6px 8px 0; padding: 0; }
main article.single ul.list li a {
  font: 500 13px var(--font-mono);
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
main article.single ul.list li a:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Footer ---------- */

main footer {
  max-width: 820px;
  margin: 24px auto 0;
  padding: 24px 32px 40px;
  box-sizing: border-box;
  border-top: 1px solid var(--border) !important;
}
main footer p { color: var(--muted); font-size: 12.5px; padding: 0; line-height: 1.8; }
main footer a { color: var(--muted); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
main footer a:hover { color: var(--accent); }

/* ---------- Floating controls ---------- */

.reading-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 2000;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transform-origin: 0 50%;
  transform: scaleX(0);
  display: none;
}
body.page-article .reading-progress { display: block; }

.theme-toggle, .to-top {
  position: fixed;
  z-index: 1500;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, color .15s ease, opacity .2s ease;
}
.theme-toggle:hover, .to-top:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.theme-toggle { top: 16px; right: 16px; }
.to-top { right: 16px; bottom: 16px; opacity: 0; pointer-events: none; }
.to-top.visible { opacity: 1; pointer-events: auto; }

.theme-toggle .fa-sun { display: none; }
body.dark-theme .theme-toggle .fa-sun { display: inline-block; }
body.dark-theme .theme-toggle .fa-moon { display: none; }
@media (prefers-color-scheme: dark) {
  body:not(.light-theme) .theme-toggle .fa-sun { display: inline-block; }
  body:not(.light-theme) .theme-toggle .fa-moon { display: none; }
}

@media (max-width: 767px) {
  .theme-toggle { position: absolute; }
}

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