:root {
  --background-color: #333;
  --text-color: #fff;
  --sidebar-width: 250px;
  --header-height: 43px;
}

@media (prefers-color-scheme: light) {
  :root {
    --background-color: #fff;
    --text-color: #111;
  }
}

html, body {
  font-family: "Roboto", sans-serif;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--background-color);
  color: var(--text-color);
}

h1, h2, h3, h4, h5, h6 {
  font-family: "Roboto", sans-serif;
  margin: 0;
  padding: 0.5em 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

pre {
  overflow-x: auto;
  white-space: pre;
  max-width: 100%;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS Safari */
}

/* Code inside pre blocks must preserve whitespace for ASCII art */
pre code {
  white-space: pre;
  word-wrap: normal;
  overflow-wrap: normal;
}

/* Inline code can wrap */
code {
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-width: 100%;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

table {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.w3-sidebar { 
  z-index: 3;
  width: var(--sidebar-width);
  top: var(--header-height); /* Adjust if header height changes */
  bottom: 0;
  height: inherit; 
}

.w3-main.shifted-by-sidebar { 
  margin-left: var(--sidebar-width);
}

.container {
  padding: 20px;
  max-width: 100%; 
  box-sizing: border-box;
  overflow-wrap: break-word;
}

.image-gallery {
  overflow: auto; 
  margin-left: -1%; 
  padding: 0; 
  list-style: none;
}

.image-gallery li {
  float: left;
  display: block;
  margin: 0 0 1% 1%; 
  width: 19%;
  box-sizing: border-box;
}

.image-gallery li a {
  display: block; /* Makes the whole area clickable */
  text-align: center;
  text-decoration: none; 
  color: #777;
}

.image-gallery li a span { 
  display: block;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  padding: 3px 0;
}

.image-gallery li a img {
  width: 100%;
  display: block; 
}

.post-tag {
  background-color: #555;
  color: #fff;
  padding: 0.2em 0.5em;
  border-radius: 3px;
  text-decoration: none;
  font-size: 0.9em;
  white-space: nowrap;
  margin-right: 5px;
}
.post-tag:hover {
  background-color: #777;
}


.no-wrap {
  white-space: nowrap;
}



@media screen and (max-width: 768px) {
  .w3-sidebar {
    display: none; 
    position: fixed;
    width: 100%; 
    height: 100%; 
    top: 0; 
    left: 0;
    background-color: var(--background-color);
  }

  .w3-main.shifted-by-sidebar {
    margin-left: 0; 
  }

  .container {
    margin-left: 0; 
    padding: 15px;
    width: 100%; 
  }

  h1, h2, h3, h4, h5, h6 {
    margin-left: 0;
    padding-left: 0;
  }

  .image-gallery {
    margin-left: -1%;
  }

  .image-gallery li {
    width: 48%; 
  }
}

/* Dracula Theme for Rouge Syntax Highlighting */
.highlight {
  background: #282a36;
  border-radius: 4px;
  margin: 20px 0;
}

.highlight pre {
  padding: 15px;
  color: #f8f8f2;
  overflow-x: auto;
  border-radius: 4px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre;
}

.highlight pre code {
  white-space: pre;
  word-wrap: normal;
  overflow-wrap: normal;
}

.highlight .hll { background-color: #282a36 }
.highlight .c { color: #6272a4 } /* Comment */
.highlight .err { color: #ff5555 } /* Error */
.highlight .k { color: #ff79c6 } /* Keyword */
.highlight .l { color: #bd93f9 } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #ff79c6 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .cm { color: #6272a4 } /* Comment.Multiline */
.highlight .cp { color: #6272a4 } /* Comment.Preproc */
.highlight .c1 { color: #6272a4 } /* Comment.Single */
.highlight .cs { color: #6272a4 } /* Comment.Special */
.highlight .gd { color: #ff5555 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #50fa7b } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #8be9fd } /* Generic.Subheading */
.highlight .kc { color: #ff79c6 } /* Keyword.Constant */
.highlight .kd { color: #ff79c6 } /* Keyword.Declaration */
.highlight .kn { color: #ff79c6 } /* Keyword.Namespace */
.highlight .kp { color: #ff79c6 } /* Keyword.Pseudo */
.highlight .kr { color: #ff79c6 } /* Keyword.Reserved */
.highlight .kt { color: #8be9fd } /* Keyword.Type */
.highlight .m { color: #bd93f9 } /* Literal.Number */
.highlight .s { color: #f1fa8c } /* Literal.String */
.highlight .na { color: #50fa7b } /* Name.Attribute */
.highlight .nb { color: #8be9fd } /* Name.Builtin */
.highlight .nc { color: #50fa7b } /* Name.Class */
.highlight .no { color: #ff5555 } /* Name.Constant */
.highlight .nd { color: #50fa7b } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #ff5555 } /* Name.Exception */
.highlight .nf { color: #50fa7b } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #50fa7b } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #ff79c6 } /* Name.Tag */
.highlight .nv { color: #8be9fd } /* Name.Variable */
.highlight .ow { color: #ff79c6 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mf { color: #bd93f9 } /* Literal.Number.Float */
.highlight .mh { color: #bd93f9 } /* Literal.Number.Hex */
.highlight .mi { color: #bd93f9 } /* Literal.Number.Integer */
.highlight .mo { color: #bd93f9 } /* Literal.Number.Oct */
.highlight .sb { color: #f1fa8c } /* Literal.String.Backtick */
.highlight .sc { color: #f1fa8c } /* Literal.String.Char */
.highlight .sd { color: #f1fa8c } /* Literal.String.Doc */
.highlight .s2 { color: #f1fa8c } /* Literal.String.Double */
.highlight .se { color: #f1fa8c } /* Literal.String.Escape */
.highlight .sh { color: #f1fa8c } /* Literal.String.Heredoc */
.highlight .si { color: #f1fa8c } /* Literal.String.Interpol */
.highlight .sx { color: #f1fa8c } /* Literal.String.Other */
.highlight .sr { color: #f1fa8c } /* Literal.String.Regex */
.highlight .s1 { color: #f1fa8c } /* Literal.String.Single */
.highlight .ss { color: #f1fa8c } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #8be9fd } /* Name.Variable.Class */
.highlight .vg { color: #8be9fd } /* Name.Variable.Global */
.highlight .vi { color: #8be9fd } /* Name.Variable.Instance */
.highlight .il { color: #bd93f9 } /* Literal.Number.Integer.Long */

/* Additional styling for inline code */
code.highlighter-rouge {
  background-color: #44475a;
  color: #f8f8f2;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: 'Courier New', Courier, monospace;
}

/* Responsive tables */
table {
  width: 100%;
  margin: 20px 0;
  border-collapse: collapse;
  border: 1px solid #555;
}

th, td {
  padding: 8px 12px;
  text-align: left;
  border: 1px solid #555;
}

th {
  background-color: #444;
}

/* Mobile table styles - horizontal scrolling */
@media screen and (max-width: 768px) {
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* Mobile code block styles - preserve ASCII art */
  pre {
    font-size: 12px;
    padding: 12px;
    border-radius: 4px;
  }

  .highlight pre {
    font-size: 12px;
  }
}

/* ===========================
   Post Meta (date, reading time, tags)
   =========================== */
.post-meta {
  color: #999;
  font-size: 0.9em;
  margin-bottom: 1.5em;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5em;
}

.post-date {
  margin-right: 0.5em;
}

.post-reading-time {
  background: #444;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.85em;
}

.post-tags {
  margin-left: 0.5em;
}

/* ===========================
   Table of Contents
   =========================== */
.toc {
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 1em;
  margin: 1.5em 0;
  max-width: 400px;
}

.toc details summary {
  cursor: pointer;
  user-select: none;
  padding: 0.25em 0;
}

.toc details summary:hover {
  color: #0af;
}

.toc-list {
  list-style: none;
  padding-left: 0;
  margin: 0.75em 0 0 0;
}

.toc-list li {
  padding: 0.25em 0;
  border-bottom: 1px solid #333;
}

.toc-list li:last-child {
  border-bottom: none;
}

.toc-list a {
  color: #ccc;
  text-decoration: none;
  transition: color 0.2s;
}

.toc-list a:hover {
  color: #0af;
}

.toc-h2 {
  font-weight: 500;
}

.toc-h3 {
  padding-left: 1em;
  font-size: 0.9em;
  color: #888;
}

/* ===========================
   Back to Top Button
   =========================== */
.back-to-top {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 50px;
  height: 50px;
  background: #444;
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s, background 0.3s;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  background: #0af;
}

.back-to-top svg {
  width: 24px;
  height: 24px;
}

/* Mobile adjustments */
@media screen and (max-width: 768px) {
  .post-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3em;
  }

  .post-tags {
    margin-left: 0;
  }

  .toc {
    max-width: 100%;
  }

  .back-to-top {
    bottom: 20px;
    right: 20px;
    width: 45px;
    height: 45px;
  }
}
