@layer reset, theme, page;

@import url("./_reset.css") layer(reset);
@import url("./_theme.css") layer(theme);

@layer page {
  body {
    width: 100%;
    min-height: 100vh;

    padding-top: 8em;
    padding-bottom: 2em;

    background: 
      linear-gradient(
        to bottom,
        rgba(255 255 255 / 0%) 0,
        rgba(255 255 255 / 0%) 20vh,
        rgba(255 255 255 / 100%) 30vh,
        rgba(255 255 255 / 100%) calc(100% - 50vh),
        rgba(255 255 255 / 0%) calc(100% - 20vh)
      ),
      var(--pattern-bg);

    background-size: 100% 100%;
    background-repeat: no-repeat;

    @media (width < 500px) {
      padding-inline: 2em;
      padding-block: 4em;
    }
  }

  article {
    margin: 0 auto;
    width: min(80vw, 120em);

    & > * + * {
      margin-top: 40px;
    }

    @media (width <= 800px) {
      width: 75vw;
    }

    @media (width <= 600px) {
      width: 85vw;
    }
  }

  header {
    display: flex;
    flex-direction: column;
    width: 100%;

    gap: 0.5rem;

    padding-bottom: 0.75em;

    @media (width <= 850px) {
      gap: 1.25rem;
    }

    a.back-to-list {
      display: flex;
      align-items: start;
      justify-items: start;
      gap: 1em;
      text-decoration: none;
      color: var(--primary);

      &:hover .intention, &:focus .intention {
        text-decoration: underline;
      }
    }

    hgroup.header {
      display: flex;
      flex-direction: column;
      align-items: start;
    }

    h2.site-name {
      font-size: 1.2em;
      line-height: 100%;
      color: var(--primary);
    }

    .intention {
      font-size: 0.9em;
    }

    hr {
      height: 1.5em;
      margin-top: 2px;
      border: none;
      border-left: 2px solid var(--primary);
      margin-left: 3px;

      @media (width <= 500px) {
        height: 1.0em;
      }
    }

    h2.article-type {
      font-size: 1.8em;
      line-height: 100%;
      color: var(--primary);

      @media (width <= 500px) {
        font-size: 1.2rem;
        letter-spacing: -2px;
      }
    }

    hgroup.title {
      display: flex;
      flex-direction: column;
      gap: 0.7em;
      width: 100%;

      h1 {
        color: var(--text-emphasized);

        font-size: 2.5em;
        line-height: 110%;
        letter-spacing: -1px;

        margin-bottom: -6px;

        @media (width <= 800px) {
          font-size: 1.75em;
          margin-bottom: 0px;
        }
      }
    }

    date {
      font-size: 1em;
      font-weight: 300;

      color: var(--typed-primary);

      @media screen and (max-width: 500px) {
        font-size: 0.8em;
      }
    }
  }

  aside.metas {
    section {
      border-left: 2px solid var(--typed-primary);

      h3 {
        padding-left: 32px;
        padding-right: 24px;
        background-color: var(--typed-primary);
        color: white;
        width: fit-content;
      }

      div.content {
        padding: 16px 0px 16px 32px;
      }
    }
  }

  main.content {
    margin: 0 auto;
    width: min(100%, 60rem);

    color: var(--text);
    font-size: 1.1em;
    line-height: 170%;

    margin-top: 3em;
    padding-bottom: 3em;

    overflow-wrap: anywhere;

    img.emoji {
      width: 1em;
      aspect-ratio: 1 / 1;
      vertical-align: middle;
      margin-bottom: 3px;
    }

    aside:not(.footnote-def) {
      &.disclaimer {
        color: var(--typed-primary);
        padding: 0 2em;
        margin: 3em auto;
        width: 75%;

        line-height: 110%;
        text-align: center;

        border: 0px solid var(--typed-primary);
        border-width: 0px 1px 0px 1px;

        @media screen and (max-width: 500px) {
          width: 100%;
          margin: 3em 0;
          padding: 0 2em;
          font-size: 0.9em;
        }
      }

      &:not(.disclaimer) {
        margin: 1em 0em;
        padding: 1em 1.5em;

        border: 2px solid rgb(from var(--typed-primary) r g b / 20%);
      }
    }

    a.fnref-anchor {
      position: absolute;
      transform: translateY(-50vh);
    }

    p {
      letter-spacing: -0.5px;
      text-wrap: pretty;
    }

    strong {
      color: var(--text-emphasized);
    }

    *:is(p, code.block) + *:not(h1, h2, h3, h4, h5, h6) {
      margin-top: 1.3em;
    }
    *:not(h1, h2, h3, h4, h5, h6) + *:is(p, code.block) {
      margin-top: 1.3em;
    }

    h1, h2, h3, h4, h5, h6 {
      margin-top: 1.8em;
      margin-bottom: 0.25em;
      letter-spacing: 1px;
      font-weight: bold;
      color: var(--typed-primary);
      line-height: 120%;
      text-wrap: pretty;
    }

    h1:first-child, h2:first-child, h3:first-child,
    h4:first-child, h5:first-child, h6:first-child {
      margin-top: 0;
    }

    h1 { font-size: 2rem; margin-top: 2em; margin-bottom: 0.5em; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1rem; }
    h5 { font-size: 1rem; }
    h6 { font-size: 1rem; }

    ul > li {
      list-style: disc;
    }

    ol > li {
      list-style: decimal;
    }

    li {
      margin-left: 1.2em;
      padding-left: 0.1em;
      margin-top: 0.5em;
    }

    *:not(pre) > code {
      font-family: PlemolJP Console NF, monospace;
      background-color: rgb(from var(--typed-primary) r g b / 10%);
      font-size: 0.9em;
      padding: 0.05em 0.25em;
      border-radius: 3px;
    }

    code.block {
      display: block;

      font-family: PlemolJP Console NF, monospace;
      line-height: 105%;

      pre {
        padding: 1em 1.5em;
        width: 100%;
        overflow-x: auto;
        border-radius: 4px;
      }
    }

    img {
      margin-inline: 0;
    }

    p:has(> img:not(.emoji)) {
      width: 100%;

      img {
        text-align: center;
        margin: 0 20%;
        width: 60%;
      }
    }

    sup {
      line-height: 0;
    }

    aside.footnote-def {
      margin-top: 4em;
      border-top: 1px solid rgb(from var(--typed-primary) r g b / 30%);
      border-bottom: 1px solid rgb(from var(--typed-primary) r g b / 30%);
      font-size: 0.9em;
      line-height: 150%;
      padding: 1em;

      h1 {
        font-size: 1.25em;
        letter-spacing: 0px;
        color: color-mix(in hsl, var(--typed-primary), black 20%);
      }

      & ol > li:first-child {
        margin-top: 0em;
      }
      & ol > li:not(:first-child) {
        margin-top: 1em;
      }
    }
  }

  hr.footer-hr {
    margin: 0 auto;
    width: min(100%, 60rem);
    margin-top: 6em;
    margin-bottom: 1em;
  }

  footer {
    margin: 0 auto;
    width: min(100%, 60rem);
    padding: 1.5em 2em;

    background-color: hsl(from var(--typed-primary) h calc(s - 35) calc(l - 10));
    color: white;
    margin-bottom: 20vh;

    & > * + * { margin-top: 0.7em; }

    .eoc {
      font-style: italic;
      font-size: 0.9em;
      letter-spacing: -0.5px;
    }

    .eoc-notice {
      & > * + * { margin-top: 0.3em; }
    }

    .title {
      font-size: 1.5em;
      line-height: 110%;

      @media (width <= 800px) {
        font-size: 1.2em;
        margin-bottom: 0px;
      }
    }

    nav.actions a {
      color: white;
    }
  }
}
