.layout {
  --layout-max-width: 1320px;
  --layout-side-width: 240px;
  display: grid;
  grid-template-columns: var(--layout-side-width) 1fr;
  grid-template-areas: "side main";
  gap: 40px;
  width: 100%;
  max-width: var(--layout-max-width);
  margin: 0 auto;
  align-items: start;
}

.layout-side {
  grid-area: side;
  position: sticky;
  top: 20px;
  align-self: start;
  margin-top: var(--layout-side-offset, 0px);
}

.layout-main {
  grid-area: main;
  min-width: 0;
  color: #333;
  font-size: 15px;
  line-height: 1.7;
}

.layout-main > p,
.layout-main .wp-block-paragraph {
  margin: 0 0 16px;
  color: #444;
}

.layout-main > p:last-child,
.layout-main .wp-block-paragraph:last-child {
  margin-bottom: 0;
}

.layout-main > h2.wp-block-heading,
.layout-main h2.wp-block-heading:not(.tool-title) {
  scroll-margin-top: 80px;
  margin: 32px 0 16px;
  padding: 14px 16px;
  padding-left: 20px;
  font-size: clamp(1rem, 2.2vw, 1.25rem);
  font-weight: 700;
  line-height: 1.4;
  color: #333;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.04);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
  position: relative;
}

.layout-main > h2.wp-block-heading::before,
.layout-main h2.wp-block-heading:not(.tool-title)::before {
  content: "";
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  background: #2d8a4e;
  border-radius: 2px;
}

.layout-main > h2.wp-block-heading:first-child,
.layout-main h2.wp-block-heading:not(.tool-title):first-child {
  margin-top: 0;
}

.layout-main > ul.wp-block-list,
.layout-main > ol.wp-block-list {
  margin: 0 0 24px;
  padding: 16px 16px 16px calc(16px + 1em);
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.04);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
}

.layout-main > ul.wp-block-list:last-child,
.layout-main > ol.wp-block-list:last-child {
  margin-bottom: 0;
}

.layout-main > ul.wp-block-list li,
.layout-main > ol.wp-block-list li {
  margin-bottom: 8px;
  line-height: 1.6;
}

.layout-main > ul.wp-block-list li:last-child,
.layout-main > ol.wp-block-list li:last-child {
  margin-bottom: 0;
}

.side-ad {
  margin-top: 24px;
  padding: 12px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
  text-align: center;
}

.bottom-ad {
  margin-top: 32px;
  padding: 12px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
  text-align: center;
}

.side-ad:not(:has(*)),
.bottom-ad:not(:has(*)) {
  display: none;
}

.side-ad .wp-block-image,
.bottom-ad .wp-block-image {
  margin: 0;
}

.side-ad .wp-block-image img,
.bottom-ad .wp-block-image img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

/* Tablet以下: 1カラム（目次 → メイン） */
@media (max-width: 1023px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "side"
      "main";
    gap: 32px;
    overflow-x: clip;
  }

  .layout-side {
    position: relative;
    top: auto;
    width: 100%;
    margin-top: 0;
  }
}

/* Tablet */
@media (max-width: 1023px) and (min-width: 768px) {
  .layout {
    padding-left: 20px;
    padding-right: 20px;
    box-sizing: border-box;
  }
}

/* Mobile: LP風（solarpunk_mobile_layout_sample 準拠） */
@media (max-width: 767px) {
  body.has-custom-layout {
    --layout-page-bg: linear-gradient(180deg, #effcff 0%, #f6fff5 50%, #fff8e8 100%);
  }

  body.has-custom-layout.has-hero-page-bg {
    background: var(--hero-page-bg) !important;
  }

  body.has-custom-layout:not(.has-hero-page-bg) {
    background: var(--layout-page-bg);
  }

  body.has-custom-layout .entry-content,
  .entry-content:has(.layout) {
    overflow-x: clip;
  }

  .entry-content > .wp-block-custom-hero.hero + .wp-block-custom-layout.layout,
  .entry-content > .hero.wp-block-custom-hero + .layout {
    position: relative;
    z-index: 3;
  }

  .layout {
    width: min(calc(100% - 28px), 560px);
    margin: -42px auto 52px;
    padding: 0;
    gap: 18px;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    overflow-x: clip;
  }

  .layout-side {
    margin-bottom: 0;
  }

  .layout-main {
    font-size: 14px;
    display: grid;
    gap: 18px;
  }

  .layout-main > h2.wp-block-heading,
  .layout-main h2.wp-block-heading:not(.tool-title) {
    margin: 0;
    padding: 18px;
    font-size: 1.25rem;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(213, 233, 230, 0.9);
    border-radius: 22px;
    box-shadow: 0 18px 45px rgba(30, 76, 92, 0.13);
  }

  .layout-main > ul.wp-block-list,
  .layout-main > ol.wp-block-list {
    padding: 18px 18px 18px calc(18px + 1em);
    margin-bottom: 0;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(213, 233, 230, 0.9);
    border-radius: 22px;
    box-shadow: 0 18px 45px rgba(30, 76, 92, 0.13);
  }

  .layout-main .tool-row,
  .layout-main .text-card,
  .layout-main .chart-card,
  .layout-main .hub-card {
    margin: 0;
  }

  .side-ad,
  .bottom-ad {
    margin-top: 0;
    padding: 18px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(213, 233, 230, 0.9);
    border-radius: 22px;
    box-shadow: 0 18px 45px rgba(30, 76, 92, 0.13);
  }
}

/* ゲーム別背景（767px以下のみ body に適用） */
@media (max-width: 767px) {
  body.layout-game-solarpunk-post {
    --layout-page-bg: linear-gradient(180deg, #effcff 0%, #f6fff5 50%, #fff8e8 100%);
  }
}
