:root {
  --fg: #111;
  --muted: #666;
  --bg: #fff;
  --accent: #2cfc03;
  --border: #000;
  --max: 980px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: monospace;
  font-size: 16px;
  line-height: 1.55;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.site-header {
  max-width: var(--max);
  width: 100%;
  margin: 2rem auto 0;
  padding: 0 1.25rem;
  text-align: center;
}

.ascii-logo {
  display: inline-block;
  margin: 0 auto;
  font-family: monospace;
  font-size: clamp(0.45rem, 1.6vw, 0.95rem);
  line-height: 1.05;
  white-space: pre;
  overflow: hidden;
  text-align: left;
  max-width: 100%;
}

.site-nav {
  margin: 1.5rem 0 2rem;
}

.site-nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0;
  padding: 0;
  margin: 0;
  border: 2px solid var(--border);
}

.site-nav li { flex: 0 0 auto; }

.site-nav a {
  display: block;
  padding: 0.9rem 2.5rem;
  color: var(--fg);
  text-decoration: none;
  border: 3px solid transparent;
  font-weight: 500;
}

.site-nav a:hover { background: #f5f5f5; }

.site-nav a.active {
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.site-nav li.has-dropdown { position: relative; }

.site-nav .dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  min-width: 100%;
  background: var(--bg);
  border: 2px solid var(--border);
  list-style: none;
  margin: 0;
  padding: 0;
  z-index: 10;
}

.site-nav li.has-dropdown:hover > .dropdown,
.site-nav li.has-dropdown:focus-within > .dropdown {
  display: block;
}

.site-nav .dropdown a {
  display: block;
  padding: 0.6rem 1.25rem;
  white-space: nowrap;
  border: 3px solid transparent;
}

.subsection-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.subsection-list li {
  padding: 0.9rem 0;
  border-bottom: 1px dashed #ccc;
}
.subsection-list a {
  display: block;
  color: var(--fg);
  text-decoration: none;
  font-weight: 700;
}
.subsection-list a:hover { color: #2a8f12; }

.subsection-heading {
  font-weight: 400;
  color: var(--muted);
}

.content {
  flex: 1;
  max-width: var(--max);
  width: 100%;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
}

.content h1 {
  margin-top: 0;
  font-size: 1.6rem;
  border-bottom: 1px solid var(--fg);
  padding-bottom: 0.25rem;
}

.article-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.article-list li {
  padding: 1rem 0;
  border-bottom: 1px dashed #ccc;
}

.article-link {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 1.25rem;
  align-items: start;
  color: var(--fg);
  text-decoration: none;
}

.article-thumb {
  width: 140px;
  height: 100px;
  object-fit: cover;
  border: 1px solid #ddd;
  background: #f3f3f3;
  display: block;
}

.article-thumb.placeholder {
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%) 0 0/16px 16px,
    linear-gradient(-45deg, #eee 25%, transparent 25%) 0 0/16px 16px,
    #f8f8f8;
}

.article-meta { display: flex; flex-direction: column; gap: 0.25rem; }

.article-link:hover .article-title { color: #2a8f12; }

.article-title { font-weight: 700; }
.article-date { color: var(--muted); font-size: 0.9rem; }
.article-summary { color: var(--muted); }

@media (max-width: 520px) {
  .article-link { grid-template-columns: 90px 1fr; gap: 0.75rem; }
  .article-thumb { width: 90px; height: 70px; }
}

.post-body img {
  max-width: 240px;
  float: right;
  margin: 0 0 1rem 1.5rem;
  border: 1px solid #ddd;
}

.post-body img.full,
.post-body p > img:only-child {
  float: none;
  display: block;
  margin: 1.5rem auto;
  max-width: 100%;
}

.post-body p { margin: 0 0 1rem; text-align: justify; }
.post-body h2 { margin-top: 2rem; }
.post-body code {
  background: #f3f3f3;
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.post-body pre {
  background: #f3f3f3;
  padding: 1rem;
  overflow-x: auto;
}

.back { margin-top: 2rem; }
.back a { color: var(--muted); text-decoration: none; }
.back a:hover { color: var(--fg); }

.site-footer {
  max-width: var(--max);
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
  text-align: right;
  border-top: 1px solid #ddd;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  .ascii-logo { font-size: clamp(0.35rem, 2.2vw, 0.7rem); }
  .site-nav { font-size: 0.9rem; }
  .site-nav a { padding: 0.6rem 0.9rem; }
  .site-nav .dropdown a { padding: 0.45rem 0.7rem; }
  .post-body img { float: none; display: block; margin: 1rem auto; max-width: 100%; }
}

/* On touch / narrow screens, flatten the dropdown: subsection items are
   always visible inline beneath their parent rather than hidden behind a
   hover that doesn't translate to touch. */
@media (max-width: 520px) {
  .site-nav ul { gap: 0.15rem 0; }
  .site-nav li.has-dropdown {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }
  /* Keep the dropdown inline (horizontal) regardless of hover/focus state,
     overriding the desktop popup behavior on touch screens. */
  .site-nav .dropdown,
  .site-nav li.has-dropdown:hover > .dropdown,
  .site-nav li.has-dropdown:focus-within > .dropdown {
    display: flex;
    position: static;
    transform: none;
    border: none;
    background: none;
    min-width: 0;
  }
  .site-nav .dropdown a {
    padding: 0.4rem 0.6rem;
    font-size: 0.85em;
    color: var(--muted);
  }
  .site-nav .dropdown a.active { color: var(--accent); }
}
