/* CSSセレクタ辞典 スタイル
   デモ内部のスタイルは js/selectors.js の DEMO_HTML 側に持たせている（iframe隔離のため） */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  font-size: 16px;
  line-height: 1.7;
}

/* ============ ヘッダー（薄型バー） ============ */
.header {
  background: linear-gradient(135deg, #1e293b 0%, #3730a3 100%);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 16px;
}
.header h1 {
  font-size: clamp(1.05rem, 0.95rem + 0.5vw, 1.3rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.header p {
  color: #c7d2fe;
  font-size: 1rem;
}

/* ============ レイアウト ============
   ≥1400px: 一覧 / コード / デモ の3カラム。3つとも画面高に収めて内側スクロール
   1000-1399px: 一覧 ＋ 右にコード→デモ の2カラム
   <1000px: 1カラム（一覧 → コード → デモ）
*/
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 20px 56px;
}
.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  grid-template-areas:
    "list detail"
    "list demo";
  gap: 20px;
  align-items: start;
}
.sidebar {
  grid-area: list;
}
.demo-panel {
  grid-area: demo;
}
.detail-panel {
  grid-area: detail;
}

/* ============ 一覧（サイドバー）・絞り込みコントロール ============ */
.sidebar {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fff;
  border: 1px solid #e2e8f0;
  padding: 16px;
}
.sidebar h2 {
  font-size: 1.05rem;
}
/* 検索・カテゴリチップのアコーディオン。コード列のサンプルCSSの下に置き、既定は開いておく */
.detail-controls {
  flex-shrink: 0;
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid #cbd5e1;
}
.detail-controls > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  list-style: none;
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 4px 2px;
}
.detail-controls > summary::-webkit-details-marker {
  display: none;
}
.detail-controls > summary::before {
  content: "▸";
  color: #6366f1;
  transition: transform 0.15s;
}
.detail-controls[open] > summary::before {
  transform: rotate(90deg);
}
.detail-controls > summary > span:first-of-type {
  margin-right: auto;
}
.detail-controls > summary:hover {
  background: #f8fafc;
}
.controls-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
}
.search-box {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
}
.search-box:focus {
  outline: 2px solid #6366f1;
  outline-offset: 1px;
  background: #fff;
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  font-family: inherit;
  font-size: 1rem;
  padding: 5px 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.chip:hover {
  border-color: #6366f1;
  color: #4f46e5;
}
.chip.is-active {
  background: #6366f1;
  border-color: #6366f1;
  color: #fff;
}
.list-count {
  font-size: 1rem;
  font-weight: 400;
  color: #64748b;
}
.sel-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}
.sel-btn {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  border: 1px solid #e2e8f0;
  background: #fff;
  padding: 9px 12px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.sel-btn:hover {
  border-color: #6366f1;
  background: #eef2ff;
}
.sel-btn.is-active {
  border-color: #6366f1;
  background: #eef2ff;
  box-shadow: inset 3px 0 0 #6366f1;
}
.sel-code {
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 1rem;
  color: #4f46e5;
  word-break: break-all;
}
.sel-label {
  font-size: 1rem;
  color: #64748b;
  line-height: 1.4;
}
.empty-msg {
  color: #64748b;
  padding: 12px 4px;
}

/* ============ パネル ============ */
.panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  padding: 20px;
}
/* コード列は薄い水色。一覧・デモの白と塗り分けて列の切り替わりを分かりやすくする */
.detail-panel {
  background: #e0f2fe;
}
.detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.detail-name {
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: clamp(1.1rem, 1rem + 0.8vw, 1.5rem);
  color: #1e293b;
  word-break: break-all;
}
.hit-badge {
  flex-shrink: 0;
  font-size: 1rem;
  color: #475569;
  background: #fff;
  padding: 4px 14px;
}
.hit-badge strong {
  color: #4f46e5;
  font-size: 1.1rem;
}
.detail-desc {
  margin-top: 10px;
  color: #334155;
}
.detail-note {
  margin-top: 10px;
  padding: 10px 14px;
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
  color: #78350f;
  font-size: 1rem;
}

/* コード */
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 8px;
}
.code-head h2 {
  font-size: 1.05rem;
}
.copy-btn {
  border: none;
  background: #6366f1;
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 8px 18px;
  cursor: pointer;
  transition: background 0.2s;
}
.copy-btn:hover {
  background: #4f46e5;
}
.copy-btn:disabled {
  background: #cbd5e1;
  cursor: default;
}
.code-box {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  font-size: 1rem;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
  min-height: 76px;
}

/* デモ。パネルの高さを画面に合わせ、iframeが残りを埋めて内側でスクロールする
   （JSで高さを測らないので「縮まない」問題が起きない） */
.demo-panel {
  display: flex;
  flex-direction: column;
  padding: 0;
}
.demo-frame {
  width: 100%;
  flex: 1;
  min-height: 320px;
  /* パネルの余白を無くしたぶん、枠線はカラムの区切り線に任せる（2重線の防止） */
  border: none;
  background: #f8fafc;
  display: block;
}

/* 解説セクション */
.about {
  margin-top: 20px;
}
.about h2 {
  font-size: 1.2rem;
  margin-bottom: 10px;
}
.about h3 {
  font-size: 1.05rem;
  margin: 18px 0 6px;
}
.about p,
.about li {
  color: #334155;
}
.about ul {
  padding-left: 1.4em;
}

/* ============ トースト ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(12px);
  background: #1e293b;
  color: #fff;
  padding: 10px 20px;
  font-size: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============ フッター ============ */
footer {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  padding: 24px 40px;
  color: #64748b;
  font-size: 1rem;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}
footer a {
  color: #1e293b;
  text-decoration: none;
  transition: color 0.2s;
}
footer a:hover {
  color: #4f46e5;
}
.footer-links {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.footer-links a {
  border: 1px solid #e2e8f0;
  padding: 8px 16px;
  font-size: 1rem;
  transition: all 0.2s;
}
.footer-links a:hover {
  border-color: #6366f1;
  color: #4f46e5;
}

/* ============ 広告（右下フローティングカード320×100・薄型透明枠＋×閉じ） ============ */
.footer-ad {
  position: fixed;
  right: 0;
  bottom: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0;
  width: 320px;
  overflow: hidden;
  background: transparent;
  border: none;
  box-shadow: none;
}
.footer-ad.is-closed {
  display: none;
}
.ad-widget__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  position: relative;
  z-index: 1;
}
.ad-widget__label {
  color: #64748b;
  font-size: 12px;
  letter-spacing: 0.04em;
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: 999px;
}
.ad-widget__close {
  appearance: none;
  border: none;
  background: #f1f5f9;
  color: #64748b;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.ad-widget__close:hover {
  background: #e2e8f0;
  color: #1e293b;
}
.footer-ad ins.adsbygoogle {
  display: block;
  width: 320px;
  height: 100px;
}

/* ============ レスポンシブ ============ */

/* 画面高に収める（3カラム時と2カラム時）。各列が内側でスクロールする。
   カラム同士は余白と角丸をやめ、1本のボーダーで区切る */
@media (min-width: 1000px) {
  .container {
    max-width: none;
    padding: 0 0 40px;
  }
  .layout {
    height: calc(100vh - var(--header-h, 56px));
    min-height: 520px;
    align-items: stretch; /* デモ列を列いっぱいに伸ばす */
    gap: 0;
    background: #fff;
  }
  .sidebar,
  .demo-panel,
  .detail-panel {
    border: none;
  }
  /* コード列だけは薄い水色を残す */
  .sidebar,
  .demo-panel {
    background: #fff;
  }
  .sidebar {
    border-right: 1px solid #e2e8f0;
  }
  .detail-panel {
    border-left: 1px solid #e2e8f0;
  }
  .about {
    width: min(1000px, calc(100% - 40px));
    margin: 32px auto 0;
  }
  .sidebar,
  .demo-panel,
  .detail-panel {
    max-height: 100%;
    min-height: 0;
  }
  /* コードは中身の高さのまま。余白で間延びさせない */
  .detail-panel {
    align-self: start;
    overflow-y: auto;
  }
}

/* 2カラム時は右列をコード→デモの縦積みにする。
   コードは中身の高さ（auto）、デモが残りを取る。%指定にするとコード側が潰れる */
@media (min-width: 1000px) and (max-width: 1399px) {
  .layout {
    grid-template-rows: auto minmax(280px, 1fr);
  }
  .detail-panel {
    max-height: none;
    overflow-y: visible;
    border-bottom: 1px solid #e2e8f0;
  }
  .demo-panel {
    border-left: 1px solid #e2e8f0;
  }
}

/* 3カラム（一覧 / コード / デモ）。一覧とコードを左に並べ、デモに残り全部を渡す。
   共通ブロックの border / align-self を上書きするので、この位置（後ろ）に置く */
@media (min-width: 1400px) {
  .container {
    max-width: 1980px;
  }
  .layout {
    grid-template-columns: 300px 300px minmax(0, 1fr);
    grid-template-areas: "list detail demo";
  }
  .detail-panel {
    padding: 16px;
    /* 中央列になるので区切り線は右側。デモ列との境目が途切れないよう縦いっぱいに伸ばす */
    border-left: none;
    border-right: 1px solid #e2e8f0;
    align-self: stretch;
  }
}

@media (max-width: 999px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "list"
      "detail"
      "demo";
  }
  .sidebar {
    position: static;
    max-height: none;
  }
  .sel-list {
    max-height: 300px;
  }
  .demo-panel {
    height: 70vh;
    min-height: 420px;
  }
}
@media screen and (max-width: 768px) {
  footer {
    flex-direction: column;
    gap: 16px;
    padding: 24px 16px;
    text-align: center;
  }
  .footer-links {
    justify-content: center;
  }
  .footer-ad {
    position: static;
    align-self: center;
    margin: 24px auto 0;
    gap: 0;
    padding: 0;
    background: none;
    border: none;
    box-shadow: none;
    z-index: auto;
  }
  .footer-ad.is-closed {
    display: flex;
  }
  .ad-widget__head {
    display: none;
  }
  .footer-ad ins.adsbygoogle {
    width: 320px;
    height: 100px;
  }
}
@media (max-width: 600px) {
  .header {
    padding: 28px 16px;
  }
  .container {
    padding: 20px 14px 48px;
  }
  .panel {
    padding: 16px;
  }
}
