/*
 * 外枠: スマホ幅の 1 列 (.phone) をそのままサイトにする。
 * PC では列を画面の真ん中に置き、左 (.side-left) に絵、右 (.side-right) にメニューを固定で出す。
 * 本文の見た目は style.css のまま。
 */
:root {
  --col: 430px; /* 真ん中の列の幅 */
  --side: calc((100vw - var(--col)) / 2);
}

body {
  background: var(--bg);
}

/* 背景 (PC のときだけ出す) */
.backdrop {
  display: none;
}

.phone {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
}

/* 中身が短いページでも、フッターを列のいちばん下に置く */
.phone > main {
  flex: 1 0 auto;
}

.phone .inner {
  width: 100%;
}

/* ---------------------------------------------------------------- スマホのヘッダーとメニュー */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 96%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.site-header .inner {
  flex-wrap: nowrap;
}

.menu-button {
  display: grid;
  gap: 5px;
  width: 40px;
  height: 40px;
  margin: -8px -8px -8px 0;
  padding: 11px 9px;
  border: 0;
  background: none;
  cursor: pointer;
}

.menu-button span {
  display: block;
  height: 2px;
  border-radius: 1px;
  background: var(--text);
  transition: transform 0.2s, opacity 0.2s;
}

.menu-button[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.menu-button[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}

.menu-button[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ≡ のメニューは本文の上に重ねて出し、うしろを暗くする (本文を押し下げない) */
.site-header .phone-menu {
  display: block;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: calc(100vh - var(--header-h, 57px));
  overflow-y: auto;
  border-top: 1px solid var(--line);
  background: var(--bg);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

.site-header .phone-menu[hidden] {
  display: none;
}

.menu-dim {
  position: fixed;
  inset: 0;
  z-index: 9; /* ヘッダー (10) のすぐ下 */
  background: rgba(0, 0, 0, 0.35);
}

.menu-dim[hidden] {
  display: none;
}

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

.phone-menu .menu a {
  display: block;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.phone-menu .menu li:last-child a {
  border-bottom: 0;
}

.phone-menu .current-menu-item > a {
  color: var(--accent-text);
}

/* ---------------------------------------------------------------- 本文の中で足したもの */

/* 作品ページのタイトル画像は、枠を付けず列の端から端まで (本文の上と左右の余白を打ち消す) */
.doc .hero {
  margin: -32px -16px 16px;
  border-radius: 0;
}

/* エレメンタルストーリーズ: 1 ドット = 列の幅の 1/240。下の白い空と本文の境目に線を引く */
.hero.light {
  --dot: calc(min(100vw, var(--col)) / 240);
  box-shadow: inset 0 -1px 0 var(--line);
}

.hero .edition {
  font-size: clamp(14px, calc(min(100vw, var(--col)) * 0.04), 18px);
}

.hero.space .bg {
  height: min(60vw, 300px);
}

.chapters {
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

/* トップ: 月ごとの絵 */
/* 列の端から端まで (本文の上と左右の余白を打ち消す) */
.doc .main-visual {
  margin: -32px -16px 16px;
}

.main-visual img {
  display: block;
  width: 100%;
}

/* トップ: 各ページへのメニュー (2 列のタイル) */
.top-menu {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 16px 0;
  padding: 0;
  list-style: none;
}

.top-menu a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 100%;
  min-height: 72px;
  padding: 14px 10px;
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
}

.top-menu img {
  width: 60px;
  height: 60px;
  border-radius: 14px;
}

.top-menu .sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

/* 絵のない項目は 1 行に 2 つ並べ、少し低く */
.top-menu .text a {
  min-height: 56px;
  border: 1px solid var(--line);
  background: none;
}

/* 列のヘッダーのロゴ */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.brand img {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

/* ページのいちばん上ではロゴと名前を隠し、影も付けない (menu.js が .at-top を付け外しする) */
.site-header {
  transition: box-shadow 0.2s;
}

.site-header .brand {
  transition: opacity 0.2s, transform 0.2s, visibility 0s;
}

.site-header.at-top {
  box-shadow: none;
}

/* ヘッダーは本文に重ね、いちばん上では透明にする。
   --header-h は menu.js が入れる (JavaScript が動かないときは重ねない) */
.site-header {
  margin-bottom: calc(-1 * var(--header-h, 0px));
  transition: box-shadow 0.2s, background-color 0.2s;
}

.site-header.at-top {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* 絵のないページは、見出しを ≡ と同じ行に置く (スマホでは見出しの右を ≡ の分あける) */
.phone > main.inner {
  padding-top: 8px;
}

@media (max-width: 767px) {
  .doc > h1:first-child:not(.main-visual) {
    padding-right: 48px;
  }
}

/* PC は ≡ がないので、列の上端に少し余白を残す */
@media (min-width: 768px) {
  .phone > main.inner {
    padding-top: 24px;
  }
}

/* 絵で始まるページ (トップ・作品ページ) は、絵をヘッダーの裏まで詰める (絵は本文の上の余白 32px を打ち消している) */
.phone:has(.doc > .main-visual:first-child, .doc > .hero:first-child) > main.inner {
  padding-top: 32px;
}

/* いちばん上では、絵の上でも見えるよう ≡ を白い台に載せる (どのページも同じ見た目にする) */
.site-header.at-top .menu-button {
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.menu-button {
  transition: background-color 0.2s, box-shadow 0.2s;
}

.site-header.at-top .brand {
  opacity: 0;
  transform: translateY(-4px);
  visibility: hidden;
  transition: opacity 0.2s, transform 0.2s, visibility 0s 0.2s;
}

/* X へのリンク (マーク＋@rapljp) */
.x-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  text-decoration: none;
}

.site-footer .x-link {
  padding: 6px 14px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
}

.side-x {
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.side-x .x-link {
  color: #565656;
  font-size: 14px;
}

/* お知らせ */
.news-list {
  margin: 16px 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

/* 見出しのすぐ下に並べるときは、見出しの下線と重ならないよう上の線をなくす */
.doc h2 + .news-list {
  margin-top: 0;
  border-top: 0;
}

.news-list a {
  display: block;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}

.news-list time {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

.news-list .title {
  font-weight: 700;
}

.news-article h1 {
  margin-top: 0;
}

.news-article .meta {
  margin-bottom: 4px;
}

.news-cat {
  margin-left: 8px;
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--panel);
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
}

.news-thumb img {
  display: block;
  border-radius: 14px;
}

.doc .more {
  text-align: right;
  font-size: 14px;
}

.doc .back {
  margin-top: 40px;
  font-size: 14px;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
}

.nav-links .page-numbers {
  padding: 4px 12px;
  border-radius: 8px;
  background: var(--panel);
  text-decoration: none;
}

.nav-links .current {
  background: var(--accent);
  color: #fff;
}

.screen-reader-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ブロックエディターで入れた画像・区切り線など */
.doc figure {
  margin: 16px 0;
}

.doc figure img {
  border-radius: 12px;
}

.doc figcaption {
  font-size: 13px;
  color: var(--muted);
}

.doc hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 32px 0;
}

.aligncenter {
  display: block;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

/* ---------------------------------------------------------------- PC: 真ん中に列、左右は固定 */

.side {
  display: none;
}

@media (min-width: 768px) {
  .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    /* www.rapl.jp と同じ緑の斜めの縞 */
    background: #80b232 url("img/rapljp/back.gif") repeat;
  }

  .phone {
    width: var(--col);
    margin: 0 auto;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15), 0 10px 40px rgba(40, 70, 0, 0.45);
  }

  /* 左にロゴ、右にメニューがあるので、列のヘッダーは出さない */
  .site-header,
  .menu-dim {
    display: none !important;
  }

  .side {
    position: fixed;
    top: 0;
    bottom: 0;
    width: var(--side);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    overflow-y: auto;
  }

  .side-left {
    left: 0;
    display: none;
  }

  .side-right {
    right: 0;
  }

  .side-inner {
    width: 100%;
    max-width: 320px;
    text-align: center;
  }

  /* 右: www.rapl.jp の白い箱のように、白地にメニュー */
  .side-right .side-inner {
    padding: 28px 24px 32px;
    border-radius: 24px;
    background: #fff;
    color: #565656;
    box-shadow: 0 8px 30px rgba(40, 70, 0, 0.3);
  }

  .side-right .menu li + li {
    margin-top: 6px;
  }

  .side-right .menu a {
    display: inline-block;
    padding: 6px 4px;
    color: #565656;
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
    transition: color 0.15s;
  }

  .side-right .menu a:hover,
  .side-right .menu .current-menu-item > a,
  .side-right .menu .current_page_parent > a {
    color: #4d8a12;
  }

  .side-right .menu .current-menu-item > a::before,
  .side-right .menu .current_page_parent > a::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    margin: 0 8px 2px 0;
    border-radius: 50%;
    background: var(--accent);
    vertical-align: middle;
  }

  .side-buttons {
    display: grid;
    gap: 10px;
    margin-top: 24px;
  }

  .side-button {
    display: block;
    padding: 12px 16px;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 35%, transparent);
  }

  .side-button.soon {
    background: var(--panel);
    color: #6d8f45;
    box-shadow: none;
  }
}

/* 左の絵を出さない幅では、列を少し左に寄せて右のメニューの幅をとる */
@media (min-width: 768px) and (max-width: 1023px) {
  :root {
    --gap: calc((100vw - var(--col) - 280px) / 2);
  }

  .phone {
    margin-left: var(--gap);
  }

  .side-right {
    width: calc(100vw - var(--col) - var(--gap));
  }
}

/* 左のロゴは広い画面のときだけ */
@media (min-width: 1024px) {
  .side-left {
    display: flex;
  }

  /* ロゴ (トップへのリンク) */
  .side-logo {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: #4d8a12;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-decoration: none;
  }

  .side-logo img {
    width: 180px;
    border-radius: 36px;
    box-shadow: 0 6px 16px rgba(40, 70, 0, 0.35);
  }

  .side-logo span {
    padding: 2px 14px;
    border-radius: 999px;
    background: #fff;
  }
}
