/* ══════════════════════════════════════════════════════════
   正規表現テスター — スタイル
   テーマカラー: Indigo (#4f46e5)
   ══════════════════════════════════════════════════════════ */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #eef2ff;
  color: #1e1b4b;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── ヘッダー ── */
header {
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px;
  height: 52px;
  display: flex;
  align-items: center;
}
.logo { font-weight: 700; font-size: 1.1rem; color: #4f46e5; text-decoration: none; }
.logo:hover { color: #4338ca; }

/* ── メイン ── */
main {
  flex: 1;
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  width: 100%;
}

/* ── ヒーロー ── */
.hero { text-align: center; padding: 24px 0 20px; }
.hero-icon { font-size: 3rem; margin-bottom: 10px; }
.hero h1 { font-size: 1.65rem; font-weight: 700; color: #1e1b4b; margin-bottom: 6px; }
.description { color: #4f46e5; font-size: 0.9rem; line-height: 1.7; }

.hero-badges {
  display: flex; justify-content: center; flex-wrap: wrap;
  gap: .5rem; margin-top: .75rem;
}
.badge {
  display: inline-block;
  background: #eef2ff; color: #4f46e5;
  border: 1px solid #c7d2fe;
  border-radius: 999px;
  font-size: .78rem; font-weight: 600;
  padding: .2rem .75rem;
}

/* ══════════════════════════════
   正規表現入力カード
   ══════════════════════════════ */
.regex-input-card {
  background: #fff;
  border-radius: 18px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 16px rgba(79,70,229,.12);
}

.pattern-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.slash {
  font-size: 1.6rem;
  font-weight: 300;
  color: #a5b4fc;
  font-family: monospace;
  line-height: 1;
  flex-shrink: 0;
}

.pattern-input {
  flex: 1;
  min-width: 160px;
  padding: 10px 14px;
  border: 2px solid #c7d2fe;
  border-radius: 10px;
  font-size: 1.05rem;
  font-family: 'SFMono-Regular', 'Consolas', 'Courier New', monospace;
  color: #1e1b4b;
  background: #eef2ff;
  outline: none;
  transition: border-color .15s, background .15s;
}
.pattern-input:focus { border-color: #4f46e5; background: #fff; }
.pattern-input::placeholder { color: #a5b4fc; font-family: -apple-system, sans-serif; font-size: 0.9rem; }
.pattern-input.error { border-color: #f87171; background: #fef2f2; }

/* フラグボタン */
.flag-group { display: flex; gap: 4px; flex-shrink: 0; }
.flag-btn {
  width: 32px;
  height: 32px;
  border: 1.5px solid #c7d2fe;
  border-radius: 7px;
  background: #eef2ff;
  color: #818cf8;
  font-family: 'SFMono-Regular', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .14s;
  touch-action: manipulation;
}
.flag-btn:hover { border-color: #818cf8; background: #e0e7ff; }
.flag-btn.active {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #fff;
  box-shadow: 0 1px 6px rgba(79,70,229,.35);
}

.copy-regex-btn {
  width: 36px;
  height: 36px;
  border: 1.5px solid #c7d2fe;
  border-radius: 9px;
  background: #eef2ff;
  color: #4f46e5;
  font-size: 1rem;
  cursor: pointer;
  transition: all .14s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.copy-regex-btn:hover { background: #4f46e5; color: #fff; border-color: #4f46e5; }

/* エラー */
.regex-error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 10px;
  padding: 9px 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 9px;
  font-size: 0.82rem;
  color: #991b1b;
  font-family: monospace;
  line-height: 1.5;
}

/* 統計 */
.regex-stats { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.stat-badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.76rem;
  font-weight: 700;
}
.stat-badge.match-badge { background: #c7d2fe; color: #1e1b4b; }
.stat-badge.group-badge { background: #fde68a; color: #713f12; }
.stat-badge.flags-badge { background: #d1fae5; color: #065f46; font-family: monospace; }

/* ── モードタブ ── */
.mode-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.mode-tab {
  padding: 10px 22px;
  border: 2px solid #c7d2fe;
  border-radius: 12px;
  background: #eef2ff;
  color: #4f46e5;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .18s;
}
.mode-tab:hover { border-color: #818cf8; background: #e0e7ff; }
.mode-tab.active { background: #4f46e5; border-color: #4f46e5; color: #fff; box-shadow: 0 2px 10px rgba(79,70,229,.35); }

/* ── ツールラップ ── */
.tool-wrap {
  background: #fff;
  border-radius: 18px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 2px 16px rgba(79,70,229,.1);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── セクションラベル ── */
.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #4f46e5;
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── 小ボタン ── */
.sm-btn {
  padding: 5px 11px;
  border: 1.5px solid #c7d2fe;
  border-radius: 20px;
  background: #eef2ff;
  color: #4f46e5;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .14s;
  white-space: nowrap;
}
.sm-btn:hover { background: #4f46e5; color: #fff; border-color: #4f46e5; }
.sm-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── テスト文字列エリア ── */
.test-ta {
  width: 100%;
  height: 200px;
  padding: 12px;
  border: 1.5px solid #c7d2fe;
  border-radius: 12px;
  font-size: 0.875rem;
  font-family: 'SFMono-Regular', 'Consolas', monospace;
  color: #1e1b4b;
  background: #fafafa;
  resize: vertical;
  outline: none;
  line-height: 1.7;
  transition: border-color .15s;
}
.test-ta:focus { border-color: #4f46e5; background: #fff; }
.test-ta::placeholder { color: #9ca3af; font-family: -apple-system, sans-serif; }
.output-ta { background: #f8fafc; cursor: default; color: #374151; }

/* ══════════════════════════════
   ハイライト表示
   ══════════════════════════════ */
.highlight-body {
  border: 1.5px solid #c7d2fe;
  border-radius: 12px;
  background: #fafafa;
  overflow: auto;
  max-height: 300px;
}
.highlight-pre {
  padding: 12px;
  font-family: 'SFMono-Regular', 'Consolas', monospace;
  font-size: 0.875rem;
  line-height: 1.7;
  color: #1e1b4b;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
}
.ph-text { color: #9ca3af; font-family: -apple-system, sans-serif; }

/* マッチカラー（6色ローテーション） */
mark.mh { border-radius: 3px; padding: 0 1px; cursor: default; }
mark.mc0 { background: #fef08a; color: #713f12; outline: 1.5px solid #facc15; }
mark.mc1 { background: #bbf7d0; color: #14532d; outline: 1.5px solid #4ade80; }
mark.mc2 { background: #bfdbfe; color: #1e3a5f; outline: 1.5px solid #60a5fa; }
mark.mc3 { background: #fecdd3; color: #881337; outline: 1.5px solid #f87171; }
mark.mc4 { background: #ddd6fe; color: #3b0764; outline: 1.5px solid #a78bfa; }
mark.mc5 { background: #fed7aa; color: #7c2d12; outline: 1.5px solid #fb923c; }

/* カラー凡例 */
.color-legend { display: flex; gap: 6px; flex-wrap: wrap; }
.legend-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #6b7280;
}
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

/* ══════════════════════════════
   マッチテーブル
   ══════════════════════════════ */
.match-placeholder { color: #9ca3af; font-size: 0.875rem; text-align: center; padding: 20px; }

.match-table-wrap { overflow-x: auto; }
.match-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.match-table th {
  padding: 8px 12px;
  background: #eef2ff;
  color: #4f46e5;
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  border-bottom: 2px solid #c7d2fe;
}
.match-table td {
  padding: 7px 12px;
  border-bottom: 1px solid #e0e7ff;
  vertical-align: top;
}
.match-table tr:last-child td { border-bottom: none; }
.match-table tr:hover td { background: #f5f7ff; }

.td-num  { text-align: center; color: #6b7280; font-family: monospace; white-space: nowrap; }
.td-pos  { font-family: monospace; color: #4f46e5; font-size: 0.76rem; white-space: nowrap; }
.td-lc   { font-family: monospace; color: #6b7280; font-size: 0.72rem; white-space: nowrap; }

code.match-code {
  padding: 2px 6px;
  border-radius: 5px;
  font-family: 'SFMono-Regular', monospace;
  font-size: 0.82rem;
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
code.mc0 { background: #fef9c3; color: #713f12; }
code.mc1 { background: #dcfce7; color: #14532d; }
code.mc2 { background: #dbeafe; color: #1e3a5f; }
code.mc3 { background: #ffe4e6; color: #881337; }
code.mc4 { background: #ede9fe; color: #3b0764; }
code.mc5 { background: #ffedd5; color: #7c2d12; }

code.group-code {
  padding: 2px 6px;
  border-radius: 5px;
  background: #f3f4f6;
  color: #374151;
  font-family: 'SFMono-Regular', monospace;
  font-size: 0.8rem;
  display: inline-block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.undef { color: #9ca3af; font-style: italic; }

.more-matches {
  text-align: center;
  padding: 10px;
  font-size: 0.78rem;
  color: #9ca3af;
  border-top: 1px solid #e0e7ff;
}
.no-match {
  text-align: center;
  padding: 20px;
  font-size: 0.9rem;
  color: #9ca3af;
}

/* ══════════════════════════════
   置換モード
   ══════════════════════════════ */
.replace-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.replace-mid { display: flex; flex-direction: column; gap: 8px; }
.replace-hint { font-size: 0.72rem; color: #6b7280; font-weight: 500; text-transform: none; letter-spacing: 0; }

.replace-pattern-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid #c7d2fe;
  border-radius: 10px;
  font-size: 0.9rem;
  font-family: 'SFMono-Regular', monospace;
  color: #1e1b4b;
  background: #eef2ff;
  outline: none;
  transition: border-color .15s;
}
.replace-pattern-input:focus { border-color: #4f46e5; background: #fff; }
.replace-pattern-input::placeholder { color: #a5b4fc; }

.replace-btn {
  padding: 10px 24px;
  background: #4f46e5;
  color: #fff;
  border: none;
  border-radius: 50px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  box-shadow: 0 2px 8px rgba(79,70,229,.3);
  align-self: flex-start;
}
.replace-btn:hover { background: #4338ca; transform: translateY(-1px); }

.replace-stats {
  padding: 8px 14px;
  background: #eef2ff;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #4f46e5;
}

/* ══════════════════════════════
   よく使うパターン
   ══════════════════════════════ */
.card {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: 0 2px 12px rgba(79,70,229,.08);
}
.card h2 { font-size: 1.05rem; font-weight: 700; color: #1e1b4b; margin-bottom: 6px; }
.card-sub { font-size: 0.8rem; color: #9ca3af; margin-bottom: 16px; }

.patterns-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}
.pattern-chip {
  padding: 10px 14px;
  border: 1.5px solid #e0e7ff;
  border-radius: 12px;
  background: #f5f7ff;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.pattern-chip:hover { border-color: #4f46e5; background: #eef2ff; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(79,70,229,.15); }
.pattern-chip-name { font-size: 0.84rem; font-weight: 700; color: #1e1b4b; }
.pattern-chip-regex { font-size: 0.7rem; font-family: monospace; color: #4f46e5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pattern-chip-desc  { font-size: 0.68rem; color: #9ca3af; }

/* ══════════════════════════════
   チートシート
   ══════════════════════════════ */
.cheatsheet-card { padding: 0; overflow: hidden; }
.cheatsheet-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  cursor: pointer;
  user-select: none;
  list-style: none;
  font-size: 1.05rem;
  font-weight: 700;
  color: #1e1b4b;
}
.cheatsheet-summary::-webkit-details-marker { display: none; }
.cheatsheet-summary:hover { background: #f5f7ff; }
.cs-toggle-icon { color: #818cf8; transition: transform .2s; }
details[open] .cs-toggle-icon { transform: rotate(90deg); }

.cheatsheet-body { padding: 0 24px 24px; display: flex; flex-direction: column; gap: 20px; }
.cs-group-title {
  font-size: 0.76rem;
  font-weight: 700;
  color: #818cf8;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 8px;
}
.cs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px;
}
.cs-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 10px;
  background: #f5f7ff;
  border-radius: 8px;
  border: 1px solid #e0e7ff;
  cursor: pointer;
  transition: background .12s;
}
.cs-item:hover { background: #eef2ff; border-color: #c7d2fe; }
.cs-sym {
  font-family: 'SFMono-Regular', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: #4f46e5;
  background: #e0e7ff;
  padding: 2px 6px;
  border-radius: 5px;
  white-space: nowrap;
}
.cs-info { display: flex; flex-direction: column; gap: 1px; }
.cs-meaning { font-size: 0.78rem; font-weight: 600; color: #1e1b4b; }
.cs-example { font-size: 0.68rem; color: #6b7280; font-family: monospace; }

/* ── フッター ── */
footer {
  text-align: center;
  padding: 24px 16px;
  font-size: 0.8rem;
  color: #9ca3af;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}
footer a { color: #4f46e5; text-decoration: none; }
footer a:hover { text-decoration: underline; }
footer p + p { margin-top: 4px; }

.hidden { display: none !important; }

/* ══════════════════════════════
   レスポンシブ
   ══════════════════════════════ */
@media (max-width: 600px) {
  .hero h1 { font-size: 1.35rem; }
  .pattern-row { gap: 6px; }
  .pattern-input { font-size: 0.9rem; }
  .flag-btn { width: 28px; height: 28px; font-size: 0.78rem; }
  .tool-wrap { padding: 16px; }
  .patterns-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .cs-grid { grid-template-columns: 1fr; }
}

/* ━━━ Amazonおすすめ ━━━ */
.amazon-card h2 { margin-bottom: 0.25rem; }
.amazon-note { font-size: 0.82rem; color: #999; margin-bottom: 1rem; }
.amazon-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
.amazon-item {
  display: block;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 0.9rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.1s;
}
.amazon-item:hover {
  border-color: #FF9900;
  box-shadow: 0 2px 8px rgba(255,153,0,0.15);
  transform: translateY(-1px);
}
.amazon-item-icon { font-size: 1.7rem; margin-bottom: 0.35rem; }
.amazon-item-name { font-size: 0.88rem; font-weight: bold; margin-bottom: 0.2rem; }
.amazon-item-desc { font-size: 0.76rem; color: #888; line-height: 1.5; margin-bottom: 0.45rem; }
.amazon-item-link { font-size: 0.78rem; color: #FF9900; font-weight: bold; }

/* ─── Tips grid (rank-tracker 統一パターン) ──────── */
.tips-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.tip-item { display: flex; gap: .65rem; }
.tip-icon { font-size: 1.4rem; flex-shrink: 0; }
.tip-text strong { display: block; font-weight: 700; margin-bottom: .15rem; font-size: .88rem; }
.tip-text p { font-size: .8rem; color: #78716c; line-height: 1.55; }
@media (max-width: 600px) {
  .tips-grid { grid-template-columns: 1fr; }
}

.amazon-notice {
  font-size: 0.72rem;
  color: #bbb;
  margin-top: 0.2rem;
}

/* ━━━ FAQ ━━━ */
.faq-list { display: flex; flex-direction: column; }
.faq-item { padding: .9rem 0; border-bottom: 1px solid #f0f0f0; }
.faq-item:last-child { border-bottom: none; padding-bottom: 0; }
.faq-q { font-size: .9rem; font-weight: 700; color: #4f46e5; margin-bottom: .35rem; }
.faq-a { font-size: .85rem; color: #555; line-height: 1.75; }

/* ━━━ パターン早見表 ━━━ */
.table-wrap { overflow-x: auto; }
.table-note { font-size: .75rem; color: #bbb; margin-top: .5rem; }

.regex-ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  min-width: 520px;
}
.regex-ref-table th {
  background: #4f46e5;
  color: #fff;
  padding: .5rem .75rem;
  text-align: left;
  font-weight: 700;
  font-size: .76rem;
  white-space: nowrap;
}
.regex-ref-table td {
  padding: .45rem .75rem;
  border-bottom: 1px solid #e0e7ff;
  color: #1e1b4b;
  vertical-align: middle;
}
.regex-ref-table td code {
  font-family: 'SFMono-Regular', 'Consolas', monospace;
  font-size: .8rem;
  background: #eef2ff;
  color: #4f46e5;
  padding: .1rem .4rem;
  border-radius: 4px;
  white-space: nowrap;
}
.regex-ref-table tr:hover td { background: #f5f7ff; }
.hl-row td { background: #eef2ff !important; font-weight: 600; }

/* ━━━ 活用シーン ━━━ */
.scene-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .9rem; }
.scene-item { display: flex; gap: .65rem; align-items: flex-start; }
.scene-icon { font-size: 1.5rem; flex-shrink: 0; }
.scene-body strong { display: block; font-size: .88rem; font-weight: 700; margin-bottom: .15rem; color: #1e1b4b; }
.scene-body p { font-size: .8rem; color: #6b7280; line-height: 1.55; margin: 0; }

/* ━━━ 関連ツール ━━━ */
.related-tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem; }
.related-tool-item {
  display: flex; align-items: flex-start; gap: .75rem;
  padding: .85rem 1rem;
  border: 1.5px solid #e0e7ff; border-radius: 10px;
  text-decoration: none; color: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.related-tool-item:hover { border-color: #4f46e5; box-shadow: 0 2px 8px rgba(79,70,229,.12); }
.related-tool-icon { font-size: 1.6rem; flex-shrink: 0; }
.related-tool-item strong { display: block; font-size: .88rem; font-weight: 700; color: #4f46e5; margin-bottom: .2rem; }
.related-tool-item p { font-size: .76rem; color: #9ca3af; line-height: 1.5; margin: 0; }

@media (max-width: 560px) {
  .scene-grid { grid-template-columns: 1fr; }
}
