/* =========================================================
 * Simple Text Copy – 共通スタイル（エディタ/フロント）
 * 変更点：
 *  - 親の block-gap を差し引いた margin-bottom で間隔を統一（A案）
 *  - 見出し・段落の margin-top は 0 にし、ボタン側の margin-bottom のみで決定
 *  - Group/Columns 内の見出しにも対応
 * ========================================================= */

/* 外側ブロック：ユーザーの margin が最優先。既定は少なめ */
.wp-block-clipboard-button{
  display:block !important;
  width:100% !important;
  float:none !important;
  padding:0 !important;

  /* ▼ここをいじると「ボタンと次ブロックの基本距離（公開/エディタ共通）」が変わります */
  --cbw-default-gap: 3.0rem;

  /* ▼親の block-gap を差し引いて“見かけの間隔”を一定にする */
  margin: 0 0 calc(var(--cbw-default-gap) - var(--wp--style--block-gap, 0px)) 0;
}

/* =========================================================
 * 【重要】ボタン直後の "block-gap"（WordPressの自動ブロック間余白）を無効化
 * └ ここを入れないと、テーマやコアの --wp--style--block-gap が上に乗り、
 *    見出しだけ広く見える等の不一致の原因になります。
 * ========================================================= */
:is(.is-layout-flow, .wp-block-post-content, .entry-content)
  > .wp-block-clipboard-button + * {
  margin-block-start: 0 !important; /* (= margin-top) */
}

/* =========================================================
 * ボタン直後が見出し または 段落の場合：上マージンを 0 に
 * └ ここをいじると「ボタン＋見出し/段落」の間隔を“見出し/段落だけ”微調整できます
 * ========================================================= */

/* 見出し（h1～h6）および 見出しラッパ（.wp-block-heading） */
.wp-block-clipboard-button + :is(h1,h2,h3,h4,h5,h6,.wp-block-heading){
  margin-top: 0 !important;  /* ←ここを -0.25rem 等にすると見出しだけさらに詰まる */
  /* ▼公開画面で“装飾（padding-top/border-top/ライン）”が距離を作っている場合だけ、必要なら下の2行を外して使う
     padding-top: 0 !important;
     border-top: none !important; */
}

/* 段落（p） */
.wp-block-clipboard-button + p{
  margin-top: 0 !important;  /* ←段落の上マージンをゼロ（ボタン側の --cbw-default-gap のみが効く） */
}

/* =========================================================
 * ボタン直後が Group/Columns で、その最初の子が見出し/見出しラッパのときのケア
 * └ Gutenbergでは「見出しが .wp-block-group 内に入る」事が多い。
 *    直後は h2 ではなく .wp-block-group になるので、ここで合わせて潰す。
 * ========================================================= */
.wp-block-clipboard-button + :is(.wp-block-group, .wp-block-columns){
  margin-top: 0 !important; /* ←コンテナ自体の上マージンもゼロに */
}

.wp-block-clipboard-button + :is(.wp-block-group, .wp-block-columns)
  > :first-child:is(h1,h2,h3,h4,h5,h6,.wp-block-heading){
  margin-top: 0 !important;  /* ←コンテナ直下の最初の見出しの上マージンもゼロに */
  /* 必要に応じ、公開画面でのみ装飾を外す（コメント解除は慎重に）
     padding-top: 0 !important;
     border-top: none !important; */
}

/* --- ここまで“間隔”に関する修正。以下は元の内部構造/ボタン見た目 --- */

/* 内部構造 */
.cbw-wrapper{
  position: relative;
  display: flow-root; /* 内部だけ margin-collapsing 防止 */
  width: 100%;
  max-width: 100%;
}

.cbw-inner{ display:flex; width:100%; }
.cbw-pos-left   .cbw-inner{ justify-content:flex-start; }
.cbw-pos-center .cbw-inner{ justify-content:center; }
.cbw-pos-right  .cbw-inner{ justify-content:flex-end; }

/* 全幅モード */
.cbw-length-full .cbw-inner{ display:block; text-align:center; }
.cbw-length-full .cbw-button{
  width:100%; display:inline-flex; justify-content:center;
}

/* ボタン */
.cbw-button{
  --cbw-border: var(--cbw-bg,#000);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--cbw-font, inherit);
  font-size: var(--cbw-font-size, 14px);
  line-height: 1;
  padding: 10px 16px;
  border: none;
  box-shadow: 0 0 0 1px var(--cbw-border);
  background: var(--cbw-bg, var(--wp--preset--color--base, #fff));
  color: var(--cbw-fg, #111);
  background-clip: padding-box;
  cursor: pointer;
  border-radius: 8px;
  transition: transform .02s ease, background .2s ease, box-shadow .2s ease, color .2s ease;
  width: var(--cbw-w, auto);
  height: var(--cbw-h, auto);
  min-height: calc(var(--cbw-h, 0px));
  box-sizing: border-box;
  text-align: center;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transform: translateZ(0);
  backface-visibility: hidden;
  will-change: transform;
}
.cbw-label{
  line-height: 1.4;
  word-break: break-word;
  white-space: normal;
  font-weight: var(--cbw-font-weight, 400);
}
.cbw-button:hover{
  /* ▼括弧の数を修正済み */
  background: var(--cbw-bg-hover, var(--cbw-bg, var(--wp--preset--color--base, #fff)));
  color: var(--cbw-fg-hover, var(--cbw-fg, inherit));
  box-shadow: 0 0 0 1px var(--cbw-bg-hover, var(--cbw-border));
}
.cbw-button:active{ transform: scale(0.98); }

/* 形状 */
.cbw-shape-square  .cbw-button{ border-radius: 0; }
.cbw-shape-rounded .cbw-button{ border-radius: 8px; }
.cbw-shape-pill    .cbw-button{ border-radius: 9999px; }

/* 影 */
.cbw-shadow .cbw-button{
  box-shadow:
    0 0 0 1px var(--cbw-border),
    0 8px 22px rgba(0,0,0,.18) !important;
}

/* アイコン */
.cbw-button .dashicons{
  line-height: 1;
  font-size: var(--cbw-icon, 32px);
  width: var(--cbw-icon, 32px);
  height: var(--cbw-icon, 32px);
}
.cbw-button svg,
.cbw-button img{
  display: inline-block;
  vertical-align: middle;
  width: var(--cbw-icon, 32px);
  height: var(--cbw-icon, 32px);
  object-fit: contain;
}

/* 画像アイコンの単色化（mask） */
.cbw-img-mask{
  display:inline-block;
  width:var(--cbw-icon,32px);
  height:var(--cbw-icon,32px);
  background-color:var(--cbw-fg,currentColor);
  -webkit-mask-image:var(--cbw-icon-url);
  -webkit-mask-repeat:no-repeat;
  -webkit-mask-position:center;
  -webkit-mask-size:contain;
          mask-image:var(--cbw-icon-url);
          mask-repeat:no-repeat;
          mask-position:center;
          mask-size:contain;
}
.cbw-img-fallback{ display:none; }
.cbw-img-fallback img{
  width:var(--cbw-icon,32px);
  height:var(--cbw-icon,32px);
  object-fit:contain;
}
@supports not (-webkit-mask-image: url("")) and not (mask-image: url("")){
  .cbw-img-mask{ display:none !important; }
  .cbw-img-fallback{ display:inline-block !important; }
}

/* 注釈（※エディタ専用。フロントでは出力しない） */
.cbw-copy-note{
  margin-top: .5rem;
  font-size: .875rem;
  line-height: 1.4;
  min-height: calc(.875rem * 1.4);
  color: #555;
  opacity: 1;
  visibility: visible;
  transition: opacity .15s ease;
  text-align: inherit;
}
.cbw-pos-left   .cbw-copy-note{ text-align: left; }
.cbw-pos-center .cbw-copy-note{ text-align: center; }
.cbw-pos-right  .cbw-copy-note{ text-align: right; }
.cbw-copy-note.is-hidden{ opacity:0; visibility:hidden; }

/* トースト */
.cbw-toast{
  position: absolute;
  top: -35px; left: 50%; transform: translateX(-50%);
  background: #333; color: #fff;
  padding: 6px 12px; border-radius: 4px;
  font-size: 12px; white-space: nowrap;
  opacity: 0; visibility: hidden;
  transition: all .3s; pointer-events: none;
  z-index: 10000;
}
.cbw-toast.show{ opacity:1; visibility:visible; }

/* エディタUI */
.cbw-radio-hidden{ position:absolute; opacity:0; pointer-events:none; }
.cbw-icon-grid{
  display:grid;
  grid-template-columns: repeat(6, minmax(0,1fr));
  gap: 8px;
}
@media (max-width: 680px){
  .cbw-icon-grid{ grid-template-columns: repeat(4, minmax(0,1fr)); }
}
@media (max-width: 420px){
  .cbw-icon-grid{ grid-template-columns: repeat(3, minmax(0,1fr)); }
}
.cbw-icon-card{
  display:flex; align-items:center; justify-content:center;
  height:42px; border-radius:8px; background:#fff; cursor:pointer; user-select:none;
  box-shadow: 0 0 0 1px #e5e7eb;
  transition: box-shadow .15s ease, background .15s ease;
  overflow:hidden;
}
.cbw-icon-card.is-active{ box-shadow: 0 0 0 2px rgba(37,99,235,.45); }
.cbw-icon-card .dashicons{ font-size:20px; width:20px; height:20px; }
.cbw-icon-card .cbw-svg-wrap svg{ width:20px; height:20px; shape-rendering:geometricPrecision; }
.cbw-icon-card .cbw-img-wrap img{ width:22px; height:22px; object-fit:contain; }
