/* ==========================================================================
   Koharu — Article content typography
   Ported from astro-koharu src/styles/theme/markdown.css.
   ========================================================================== */

.entry-content {
  width: 100%;
  max-width: var(--reader-measure, none);
  margin-inline: auto;
  font-size: var(--reader-font-size, 1rem);
  line-height: var(--reader-line-height, 1.8);
  overflow-wrap: anywhere;
  word-break: auto-phrase;
  line-break: strict;
}

/* --------------------------------------------------------------------------
   Flow
   -------------------------------------------------------------------------- */
.entry-content > * + * {
  margin-top: 1.25em;
}

.entry-content h1 + *,
.entry-content h2 + *,
.entry-content h3 + *,
.entry-content h4 + * {
  margin-top: 0;
}

/* --------------------------------------------------------------------------
   Links
   -------------------------------------------------------------------------- */
.entry-content a {
  color: hsl(var(--primary));
  text-decoration: none;
  transition: color var(--duration-ui) var(--ease-out);
}

.entry-content a:hover {
  color: hsl(var(--shoka-blue));
  text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Headings
   -------------------------------------------------------------------------- */
.entry-content h1,
.entry-content h2,
.entry-content h3,
.entry-content h4,
.entry-content h5,
.entry-content h6 {
  position: relative;
  font-weight: 700;
  line-height: 1.3;
  scroll-margin-top: 4rem;
}

.entry-content h1 {
  font-size: 2.25em;
}

.entry-content h2 {
  margin-top: 2em;
  margin-bottom: 1em;
  font-size: 1.5em;
}

.entry-content h3 {
  margin-top: 1.6em;
  margin-bottom: 0.6em;
  font-size: 1.25em;
}

.entry-content h4 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-size: 1em;
}

.entry-content h5,
.entry-content h6 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-size: 0.875em;
}

/* Level label in the left margin (H1, H2 …). */
.entry-content :is(h1, h2, h3, h4, h5, h6)::before {
  content: attr(data-level);
  position: absolute;
  left: -1.5em;
  bottom: 0;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.75rem;
  font-weight: 400;
  color: hsl(var(--muted-foreground));
  opacity: 0.5;
  transition: opacity var(--duration-ui) var(--ease-out);
}

.entry-content :is(h1, h2, h3, h4, h5, h6):hover::before {
  opacity: 0.8;
}

/* Anchor link revealed on hover. */
.heading-anchor {
  margin-left: 0.5rem;
  opacity: 0;
  color: hsl(var(--muted-foreground));
  transition: opacity var(--duration-ui) var(--ease-out);
}

.entry-content :is(h1, h2, h3, h4, h5, h6):hover .heading-anchor {
  opacity: 1;
}

.heading-anchor::before {
  content: "#";
}

/* --------------------------------------------------------------------------
   Paragraphs, lists
   -------------------------------------------------------------------------- */
.entry-content p {
  margin: 0;
}

.entry-content strong {
  font-weight: 600;
}

.entry-content ul,
.entry-content ol {
  margin-block: 1rem;
  padding-left: 0;
  list-style: none;
}

.entry-content li {
  position: relative;
  margin-block: 0.5em;
  border-radius: 0.375rem;
  transition: background var(--duration-ui) var(--ease-out);
}

.entry-content li:hover {
  background: hsl(var(--primary) / 0.05);
}

.dark .entry-content li:hover {
  background: hsl(var(--primary) / 0.1);
}

.entry-content ul > li {
  padding-left: 1.75rem;
}

.entry-content ul > li::before {
  content: "";
  position: absolute;
  left: 0.5rem;
  top: 0.625em;
  height: 0.375rem;
  width: 0.375rem;
  border-radius: 50%;
  background: hsl(var(--primary));
  opacity: 0.7;
}

.entry-content ul ul {
  margin-block: 0.5rem;
  padding-left: 1rem;
}

.entry-content ul ul > li::before {
  background: transparent;
  border: 1.5px solid hsl(var(--primary));
  opacity: 0.6;
}

.entry-content ol {
  counter-reset: koharu-list;
}

.entry-content ol > li {
  counter-increment: koharu-list;
  padding: 0.25rem 0.5rem 0.25rem 2.5rem;
}

.entry-content ol > li::before {
  content: counter(koharu-list);
  position: absolute;
  left: 0.5rem;
  top: 0.5em;
  display: flex;
  min-width: 1.5rem;
  height: 1.5rem;
  padding-inline: 0.25rem;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  background: hsl(var(--primary) / 0.1);
  color: hsl(var(--primary));
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
}

.entry-content ol ol {
  counter-reset: koharu-list-2;
}

.entry-content ol ol > li {
  counter-increment: koharu-list-2;
}

.entry-content ol ol > li::before {
  content: counter(koharu-list-2, lower-alpha);
  min-width: 1.35rem;
  height: 1.35rem;
  border-radius: 0.3rem;
  background: hsl(var(--primary) / 0.12);
  font-size: 0.75rem;
}

.entry-content ol ol ol {
  counter-reset: koharu-list-3;
}

.entry-content ol ol ol > li {
  counter-increment: koharu-list-3;
}

.entry-content ol ol ol > li::before {
  content: counter(koharu-list-3, lower-roman);
  min-width: 1.25rem;
  height: 1.25rem;
  border-radius: 0.25rem;
  background: hsl(var(--primary) / 0.08);
  color: hsl(var(--primary) / 0.8);
  font-size: 0.7rem;
  font-weight: 500;
}

.entry-content li > p {
  margin: 0;
}

.entry-content dl dt {
  font-weight: 600;
}

.entry-content dl dd {
  margin-left: 1.5rem;
}

/* --------------------------------------------------------------------------
   Blockquote
   -------------------------------------------------------------------------- */
.entry-content blockquote {
  margin-block: 1.5em;
  padding-left: 1.25em;
  border-left: 0.25rem solid hsl(var(--border));
  font-style: italic;
  color: hsl(var(--muted-foreground));
}

.entry-content blockquote p:first-of-type::before,
.entry-content blockquote p:last-of-type::after {
  content: "";
}

.entry-content blockquote cite {
  display: block;
  margin-top: 0.5em;
  font-size: 0.875em;
  font-style: normal;
}

/* --------------------------------------------------------------------------
   Inline code
   -------------------------------------------------------------------------- */
.entry-content :not(pre) > code {
  padding: 0.15rem 0.375rem;
  border-radius: 0.375rem;
  background: hsl(var(--primary) / 0.08);
  box-shadow: 0 1px 2px 0 hsl(var(--primary) / 0.05);
  color: hsl(var(--primary) / 0.8);
  font-size: 0.9em;
  font-weight: 500;
  transition: background var(--duration-ui) var(--ease-out), box-shadow var(--duration-ui) var(--ease-out);
}

.entry-content :not(pre) > code:hover {
  background: hsl(var(--primary) / 0.12);
  box-shadow: 0 2px 4px 0 hsl(var(--primary) / 0.1);
}

.dark .entry-content :not(pre) > code {
  background: hsl(var(--background) / 0.8);
}

/* --------------------------------------------------------------------------
   Code blocks — macOS window chrome
   -------------------------------------------------------------------------- */
.code-block {
  margin-block: 1.5em;
  overflow: hidden;
  border: 1px solid hsl(var(--border));
  border-radius: 0.75rem;
  background: hsl(var(--card));
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

.code-block-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  padding-right: 0.5rem;
  padding-left: 1rem;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.5);
  backdrop-filter: blur(4px);
}

.dark .code-block-toolbar {
  background: hsl(var(--muted) / 0.3);
}

.code-block-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-block: 0.5rem;
}

.traffic-lights {
  display: flex;
  gap: 0.5rem;
}

.traffic-lights i {
  display: block;
  height: 0.75rem;
  width: 0.75rem;
  border-radius: 9999px;
}

.traffic-lights i:nth-child(1) { background: #ff5f56; }
.traffic-lights i:nth-child(2) { background: #ffbd2e; }
.traffic-lights i:nth-child(3) { background: #27c93f; }

.code-block-lang {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
}

.code-block-actions {
  display: flex;
  margin-left: auto;
  align-items: center;
  padding-block: 0.25rem;
}

.code-copy {
  display: flex;
  height: 2rem;
  width: 2rem;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0.375rem;
  background: none;
  color: hsl(var(--muted-foreground));
  /* `transform` is in the list because the press shrinks the button —
     `CopyButton.tsx:30` carries `active:scale-95`. */
  transition: background var(--duration-ui) var(--ease-out), color var(--duration-ui) var(--ease-out),
    transform var(--duration-tween) var(--ease-out);
}

.code-copy:active {
  transform: scale(0.95);
}

.code-copy:hover {
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.code-copy.is-copied {
  color: hsl(var(--primary));
}

.code-copy svg {
  height: 1rem;
  width: 1rem;
}

.code-block pre {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: transparent;
  font-size: 0.875em;
}

.code-block pre code {
  display: block;
  padding: 1rem 1.5rem;
  overflow-x: auto;
  background: transparent;
  line-height: 1.7;
}

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.entry-content table {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 0.875em;
  line-height: 1.7;
}

.entry-content th {
  padding: 0 0.75em 0.75em;
  text-align: left;
  font-weight: 600;
}

.entry-content td {
  padding: 0.75em;
  border-top: 1px solid hsl(var(--border));
}

.entry-content thead th {
  border-bottom: 1px solid hsl(var(--border));
}

/* --------------------------------------------------------------------------
   Media
   -------------------------------------------------------------------------- */
.entry-content img {
  margin-inline: auto;
  border-radius: 0.5rem;
}

.entry-content figure {
  margin-block: 1.5rem;
}

.entry-content figcaption {
  margin-top: 0.5rem;
  text-align: center;
  font-size: 0.8rem;
  line-height: 1.4;
  color: hsl(var(--muted-foreground));
}

.entry-content .wp-caption-text,
.entry-content .wp-element-caption {
  margin-top: 0.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: hsl(var(--muted-foreground));
}

.entry-content .aligncenter {
  margin-inline: auto;
}

.entry-content .alignleft {
  float: left;
  margin-right: 1.5rem;
}

.entry-content .alignright {
  float: right;
  margin-left: 1.5rem;
}

.entry-content .alignwide,
.entry-content .alignfull {
  max-width: 100%;
}

.entry-content .gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.75rem;
}

.entry-content .wp-block-button__link {
  display: inline-flex;
  padding: 0.625rem 1.25rem;
  border-radius: 0.5rem;
  background: var(--gradient-shoka-button);
  color: #fff;
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   Misc
   -------------------------------------------------------------------------- */
.entry-content hr {
  margin-block: 3em;
  border-color: hsl(var(--border));
}

.entry-content kbd {
  font-size: 0.8em;
}

.entry-content .wp-block-quote {
  border-left-width: 0.25rem;
}

/* --------------------------------------------------------------------------
   Reader display preferences

   Hooks the Settings Center drawer toggles on <html>. Each one is also
   rendered server-side from 主题设置, so a visitor without JavaScript gets the
   site's defaults and a visitor with it gets the script's inline overrides,
   which win because they sit on the element rather than in a stylesheet.

   The matching `wave-off` rule lives in pages.css, beside the wave it hides,
   and `.motion-off` / `.scroll-progress-off` in base.css and layout.css.

   Font presets: `round` has no rule on purpose — it is the theme's own
   `--font-sans`, so it falls through. `system` keeps the rounded face on
   Japanese pages, as the original does.
   -------------------------------------------------------------------------- */
html[data-font-preset="system"]:not(:lang(ja)) .entry-content,
html[data-font-preset="system"]:not(:lang(ja)) .entry-content :is(h1, h2, h3, h4, h5, h6) {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

html[data-font-preset="serif"] .entry-content,
html[data-font-preset="serif"] .entry-content :is(h1, h2, h3, h4, h5, h6) {
  font-family: "Songti SC", "Noto Serif CJK SC", "Noto Serif SC", "Source Han Serif SC", serif;
}

html[data-font-preset="wenkai"] .entry-content,
html[data-font-preset="wenkai"] .entry-content :is(h1, h2, h3, h4, h5, h6) {
  font-family: "LXGW WenKai", "LXGW WenKai Screen", "寒蝉全圆体", serif;
}

html[data-reader-font="local"]:not(:lang(ja)) .entry-content,
html[data-reader-font="local"]:not(:lang(ja)) .entry-content :is(h1, h2, h3, h4, h5, h6) {
  font-family: var(--reader-font-family), "寒蝉全圆体", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

html[data-reader-font="local"]:lang(ja) .entry-content,
html[data-reader-font="local"]:lang(ja) .entry-content :is(h1, h2, h3, h4, h5, h6) {
  font-family: var(--reader-font-family), "Gen Jyuu Gothic P", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

html.reader-justify .entry-content {
  text-align: justify;
}
