:root {
  text-autospace: normal;
  --bg: #fffdff;
  --text: #5f4350;
  --text-secondary: #8d6878;
  --text-muted: #b08a99;
  --accent: #FF82B2;
  --accent-soft: #ffe3ee;
  --accent-deep: #FF5E9B;
  --strong: #4a3440;
  --code-bg: #fff1f7;
  --code-text: #7a3f59;
  --chroma-bg: #fff6fa;
  --border: #f2c8d8;
  --em-bg: #ffe8f1;
  --em-border: #ffb3cf;
  --gallery-frame-bg: #ffffff;
  --gallery-frame-border: #00adef;
  --gallery-frame-shadow: rgba(0, 0, 0, 0.08);
  --gallery-index-color: #8b82b3;
  --gallery-overlay: rgba(5, 8, 16, 0.9);
  --gallery-control-bg: rgba(22, 26, 37, 0.78);
  --gallery-control-bg-hover: rgba(22, 26, 37, 0.94);
  --gallery-control-icon: #ffffff;
  --gallery-control-shadow: rgba(0, 0, 0, 0.32);
}

/* System dark mode fallback (no-JS) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #1a1a1a;
    --text: #d4d4d4;
    --text-secondary: #aaa;
    --text-muted: #888;
    --accent: #3cb371;
    --strong: #e0e0e0;
    --code-bg: rgba(42, 42, 42, 0.8);
    --code-text: #d4d4d4;
    --chroma-bg: #282c34;
    --border: #444;
    --em-bg: #3d3a20;
    --em-border: #665e10;
    --gallery-frame-bg: #ffffff;
    --gallery-frame-border: #ffffff;
    --gallery-frame-shadow: rgba(0, 0, 0, 0.32);
    --gallery-index-color: #a9a3c8;
    --gallery-overlay: rgba(5, 8, 16, 0.9);
    --gallery-control-bg: rgba(22, 26, 37, 0.78);
    --gallery-control-bg-hover: rgba(22, 26, 37, 0.94);
    --gallery-control-icon: #ffffff;
    --gallery-control-shadow: rgba(0, 0, 0, 0.5);
  }
}

/* Explicit dark mode (JS toggle) */
:root[data-theme="dark"] {
  --bg: #1a1a1a;
  --text: #d4d4d4;
  --text-secondary: #aaa;
  --text-muted: #888;
  --accent: #3cb371;
  --strong: #e0e0e0;
  --code-bg: rgba(42, 42, 42, 0.8);
  --code-text: #d4d4d4;
  --chroma-bg: #282c34;
  --border: #444;
  --em-bg: #3d3a20;
  --em-border: #665e10;
  --gallery-frame-bg: #ffffff;
  --gallery-frame-border: #ffffff;
  --gallery-frame-shadow: rgba(0, 0, 0, 0.32);
  --gallery-index-color: #a9a3c8;
  --gallery-overlay: rgba(5, 8, 16, 0.9);
  --gallery-control-bg: rgba(22, 26, 37, 0.78);
  --gallery-control-bg-hover: rgba(22, 26, 37, 0.94);
  --gallery-control-icon: #ffffff;
  --gallery-control-shadow: rgba(0, 0, 0, 0.5);
}

body {
  margin: 0 auto;
  padding: 1em;
  line-height: 1.8;
  background: var(--bg);
  color: var(--text);
  max-width: 80ch;
  text-align: justify;
  text-justify: inter-ideograph;
}

h1,h2,h3,h4,h5,h6 {
  text-align: left;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

.site-title {
  color: var(--accent);
}

.lastmod {
  color: var(--accent);
}

.initpost {
  color: var(--accent);
}

.date {
  margin-top: -0.5em;
  color: var(--text-muted);
}

ul {
  padding-left: 1.5em;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-deep);
}

main a::before {
  content: "[";
  font-size: 1em;
}

main a::after {
  content: "]";
  font-size: 1em;
}

.no-tag::after {
  content: none;
}

.no-tag::before {
  content: none;
}

.inspire a::after {
  content: none;
}

.inspire a::before {
  content: none;
}

.inspire ul {
  list-style: none;
  counter-reset: inspire-counter;
  padding: 0;
}

.inspire li {
  padding-left: 0;
  margin-bottom: 0.2em;
}

.inspire li:before {
  content: "[" counter(inspire-counter) "]   ";
  counter-increment: inspire-counter;
}

ol {
    margin-left: 1em;
    padding-left: 0;
}

img {
  max-width: 100%;
  display: block;
  margin: 1em auto;
  border-radius: 4px;
}

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

th,
td {
  padding: 5px 10px;
  border-bottom: 2px solid var(--border);
}

/* header and footer areas */
.menu {
  padding: 0;
}

.menu li {
  display: inline-block;
}

.article-meta,
.menu a {
  text-decoration: none;
  padding: 5px;
}

.title {
  font-size: 1.1em;
}

footer a {
  text-decoration: none;
}

hr {
  border-style: dashed;
  color: var(--border);
}

.page-list {
  list-style-type: decimal-leading-zero;
}

.page-list li {
  padding: 5px;
}

.highlight pre {
  margin: 0;
}

.chroma {
  overflow-x: auto;
  border-radius: 10px;
  padding: 0.8em 1em;
  background: var(--chroma-bg);
  border: 1px solid var(--border);
}

.highlight code {
  background: transparent;
  color: inherit;
  padding: 0;
  border-radius: 0;
}

blockquote {
  border-left: 3px solid var(--accent);
  padding: 0 0 0 1em;
  color: var(--text-secondary);
  margin: 0 0 0 3px;
  background: linear-gradient(to right, var(--accent-soft), transparent 70%);
  quotes: "\201C" "\201D" "\2018" "\2019";
}

#content {
  position: relative;
}

.btw {
  width: 25%;
  right: 100%;
  text-align: justify;
  position: absolute;
  padding-right: 1em;
  color: var(--text-muted);
}

.btw>p {
  padding-top: 1px;
  margin-top: 0px;
  font-size: 80%;
}

@media screen and (max-width: 80ch) {
  .btw {
    font-size: 80%;
    position: relative;
    margin: 0.5em 0 0.5em auto;
    padding: 0.2em 0.2em;
    right: 0;
    text-align: left;
    width: initial;
    max-width: 75%;
  }

  .btw>p {
    border-top: 1px solid;
    border-bottom: 1px solid;
  }
}

em {
  font-style: normal;
  background-color: var(--em-bg);
  color: var(--text);
  border-bottom: 1px solid var(--em-border);
}

strong {
  font-weight: bold;
  color: var(--strong);
}

code {
  font-family: "Monaco", "Consolas", monospace;
  font-size: 80%;
  background-color: var(--code-bg);
  color: var(--code-text);
  border-radius: 0.2em;
  padding: 0.15em 0.4em;
}

::selection {
  background: var(--accent);
  color: #fff;
}

nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

nav .menu {
  flex: 1;
}

nav hr {
  width: 100%;
}

.theme-toggle {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
  padding: 5px;
}

.theme-toggle:hover {
  color: var(--accent-deep);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px 26px;
  width: min(1380px, calc(100vw - 48px));
  max-width: none;
  margin: 1.75em 0;
  margin-left: 50%;
  transform: translateX(-50%);
}

.gallery-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-decoration: none;
}

.gallery-frame {
  display: block;
  overflow: hidden;
  border: 1px solid var(--gallery-frame-border);
  padding: 8px;
  background: var(--gallery-frame-bg);
  box-shadow: 0 16px 34px var(--gallery-frame-shadow);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.gallery-index {
  color: var(--gallery-index-color);
  font-size: 0.92rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.gallery-card img {
  width: 100%;
  height: auto;
  margin: 0;
  border: 0;
  border-radius: 0;
  transition: transform 0.22s ease;
}

.gallery-card:hover .gallery-frame {
  transform: translateY(-4px);
  box-shadow: 0 24px 42px var(--gallery-frame-shadow);
}

.gallery-card:hover img {
  transform: scale(1.025);
}

body.gallery-open {
  overflow: hidden;
}

.gallery-lightbox[hidden] {
  display: none;
}

.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 999;
}

.gallery-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: var(--gallery-overlay);
  backdrop-filter: blur(2px);
}

.gallery-lightbox-shell {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.gallery-lightbox-stage {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 36px 110px;
  pointer-events: none;
}

.gallery-lightbox-image {
  max-width: min(86vw, 1450px);
  max-height: 88vh;
  width: auto;
  height: auto;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.48);
  pointer-events: auto;
}

.gallery-lightbox-nav,
.gallery-lightbox-download,
.gallery-lightbox-close {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  background: var(--gallery-control-bg);
  box-shadow: 0 16px 34px var(--gallery-control-shadow);
  color: transparent;
  cursor: pointer;
  padding: 0;
  pointer-events: auto;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.gallery-lightbox-nav {
  position: absolute;
  top: 50%;
  width: 62px;
  height: 62px;
  transform: translateY(-50%);
}

.gallery-lightbox-actions {
  position: absolute;
  top: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
}

.gallery-lightbox-download,
.gallery-lightbox-close {
  width: 48px;
  height: 48px;
}

.gallery-lightbox-prev {
  left: 34px;
}

.gallery-lightbox-next {
  right: 34px;
}

.gallery-lightbox-nav::before {
  content: "";
  width: 14px;
  height: 14px;
  border-top: 3px solid var(--gallery-control-icon);
  border-right: 3px solid var(--gallery-control-icon);
}

.gallery-lightbox-prev::before {
  transform: rotate(-135deg);
  margin-left: 6px;
}

.gallery-lightbox-next::before {
  transform: rotate(45deg);
  margin-right: 6px;
}

.gallery-lightbox-download::before {
  content: "";
  position: absolute;
  width: 3px;
  height: 16px;
  background: var(--gallery-control-icon);
  border-radius: 999px;
  transform: translateY(-4px);
}

.gallery-lightbox-download::after {
  content: "";
  position: absolute;
  width: 11px;
  height: 11px;
  border-right: 3px solid var(--gallery-control-icon);
  border-bottom: 3px solid var(--gallery-control-icon);
  transform: translateY(5px) rotate(45deg);
}

.gallery-lightbox-close::before,
.gallery-lightbox-close::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 2.5px;
  background: var(--gallery-control-icon);
  border-radius: 999px;
}

.gallery-lightbox-close::before {
  transform: rotate(45deg);
}

.gallery-lightbox-close::after {
  transform: rotate(-45deg);
}

.gallery-lightbox-nav:hover {
  background: var(--gallery-control-bg-hover);
  box-shadow: 0 22px 36px var(--gallery-control-shadow);
  transform: translateY(-50%) scale(1.04);
}

.gallery-lightbox-download:hover,
.gallery-lightbox-close:hover {
  background: var(--gallery-control-bg-hover);
  box-shadow: 0 22px 36px var(--gallery-control-shadow);
  transform: scale(1.04);
}

.gallery-lightbox-nav:active {
  transform: translateY(-50%) scale(0.97);
}

.gallery-lightbox-download:active,
.gallery-lightbox-close:active {
  transform: scale(0.97);
}

.gallery-lightbox-nav:focus-visible,
.gallery-lightbox-download:focus-visible,
.gallery-lightbox-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

@media screen and (max-width: 900px) {
  .gallery-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px 18px;
    width: 100%;
    margin-left: 0;
    transform: none;
  }
}

@media screen and (max-width: 720px) {
  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 14px;
  }
}

@media screen and (max-width: 560px) {
  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 12px;
  }

  .gallery-frame {
    padding: 5px;
  }

  .gallery-index {
    font-size: 0.82rem;
  }

  .gallery-lightbox-shell {
    pointer-events: none;
  }

  .gallery-lightbox-image {
    max-width: calc(100vw - 32px);
    max-height: 82vh;
  }

  .gallery-lightbox-stage {
    padding: 22px 18px;
  }

  .gallery-lightbox-close {
    width: 42px;
    height: 42px;
  }

  .gallery-lightbox-actions {
    top: 12px;
    right: 12px;
    gap: 10px;
  }

  .gallery-lightbox-download,
  .gallery-lightbox-close {
    width: 42px;
    height: 42px;
  }

  .gallery-lightbox-nav {
    width: 52px;
    height: 52px;
  }

  .gallery-lightbox-prev {
    left: 10px;
  }

  .gallery-lightbox-next {
    right: 10px;
  }
}
