/* ダークモード（デフォルト） */
:root{
  --bg: #0b0d12;
  --card: #121621;
  --text: #e8eefc;
  --muted: #a7b1c2;
  --accent: #4da3ff;
  --accent-strong: #2d8fff;
  --border: #1e2533;
  --ghost: #2a3245;
  --shadow: 0 10px 30px rgba(0,0,0,0.45);
  --radius: 16px;
  --radius-sm: 10px;
  --textarea-bg: #0f1320;
  --modal-overlay: rgba(0,0,0,0.8);
  --warn-bg: #2a2010;
  --warn-border: #b3831f;
  --warn-text: #ffd479;
  --report-note: #c3cbd9;
  /* 見出し下の説明は青い地の上に載るので、--muted では 3.89 しかない */
  --subtitle: #ccd4e0;
  /* 白文字を載せるボタンの地色。--accent のままだと 2.63〜2.92 */
  --btn-bg: #175fb5;
  --btn-bg-strong: #12539e;
}

/* ライトモード */
[data-theme="light"] {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1a202c;
  --muted: #636f7f;
  --accent: #2b6cb0;
  --accent-strong: #2c5282;
  --border: #e2e8f0;
  --ghost: #edf2f7;
  --shadow: 0 10px 30px rgba(0,0,0,0.1);
  --textarea-bg: #f7fafc;
  --modal-overlay: rgba(0,0,0,0.5);
  --warn-bg: #fff8e6;
  --warn-border: #b3831f;
  --warn-text: #7a4f00;
  --report-note: #4a5568;
  --subtitle: #636f7f;
  --btn-bg: #2b6cb0;
  --btn-bg-strong: #2c5282;
}

/* 背景グラデーションの調整 */
body{
  background: radial-gradient(1200px 700px at 20% -10%, var(--accent-strong) 0%, var(--bg) 60%) fixed;
}

[data-theme="light"] body{
  background: radial-gradient(1200px 700px at 20% -10%, #e6f2ff 0%, var(--bg) 60%) fixed;
}

* { box-sizing: border-box; }

body{
  margin: 0;
  padding-bottom: 80px;
  min-height: 100vh;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", "Meiryo", sans-serif;
  color: var(--text);
  transition: background-color 0.3s ease, color 0.3s ease;
}

.site-header{
  padding: 32px 20px 10px;
  text-align: center;
}
.site-header h1{
  margin: 0;
  font-weight: 800;
  letter-spacing: .3px;
  font-size: 32px;
}
.subtitle{
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.container{
  max-width: 920px;
  margin: 0 auto;
  padding: 18px 20px 30px;
}

.card{
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.015)) , var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card h2{
  margin: 4px 0 14px;
  font-size: 20px;
  letter-spacing: .2px;
}

.form-row{
  margin: 14px 0;
}
.label{
  display: inline-block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.label-with-button{
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.textarea{
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--textarea-bg);
  color: var(--text);
  padding: 12px 14px;
  line-height: 1.5;
  outline: none;
  resize: vertical;
  min-height: 120px;
}

.textarea:focus{
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(77,163,255,0.15);
}

.btn-copy-output{
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--ghost);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: background .2s ease, transform .1s ease, color .2s ease;
}

.btn-copy-output:hover{
  background: rgba(77,163,255,0.2);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-copy-output:active{
  transform: scale(0.95);
}

.btn-copy-output.copied{
  background: rgba(77,255,163,0.2);
  border-color: rgba(77,255,163,0.5);
  color: #4dffa3;
}

/* Toast */
.toast{
  position: fixed;
  top: -100px;
  right: 20px;
  background: var(--card);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 2000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  max-width: 300px;
}

.toast.show{
  top: 20px;
  opacity: 1;
}

.toast.success{
  background: #1e3a2e;
  border-color: #28a745;
  color: #7dff99;
}

.toast.error {
  background: #3a1e26;
  border-color: #dc3545;
  color: #ff6b7a;
}

.toast.info {
  background: #1e2a3a;
  border-color: #17a2b8;
  color: #7dd3fc;
}

/* ライトモード用Toast */
[data-theme="light"] .toast {
  background: var(--card);
  color: var(--text);
  border-color: var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

[data-theme="light"] .toast.success {
  background: #d4edda;
  border-color: #c3e6cb;
  color: #155724;
}

[data-theme="light"] .toast.error {
  background: #f8d7da;
  border-color: #f5c6cb;
  color: #721c24;
}

[data-theme="light"] .toast.info {
  background: #d1ecf1;
  border-color: #bee5eb;
  color: #0c5460;
}

/* 統計表示 */
.stats {
  margin-top: 16px;
  padding: 16px;
  background: rgba(255,255,255,0.02);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.stats-grid {
  display: grid;
  /* 中身の最小幅で押し広げられないよう、下限を画面幅に合わせる */
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 120px), 1fr));
  gap: 12px;
}

.stat-item {
  text-align: center;
  padding: 12px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
}

.stat-item.error {
  background: rgba(220,53,69,0.1);
  border-color: rgba(220,53,69,0.2);
}

.stat-value {
  display: block;
  font-size: 24px;
  font-weight: bold;
  color: var(--accent);
  line-height: 1;
}

.stat-item.error .stat-value {
  color: #ff4d6d;
}

.stat-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  font-weight: 500;
}

/* ライトモード用統計スタイル */
[data-theme="light"] .stats {
  background: rgba(0,0,0,0.03);
  border-color: rgba(0,0,0,0.08);
}

[data-theme="light"] .stat-item {
  background: rgba(0,0,0,0.02);
  border-color: rgba(0,0,0,0.05);
}

[data-theme="light"] .stat-item.error {
  background: rgba(220,53,69,0.05);
  border-color: rgba(220,53,69,0.15);
}

/* URLプレビュー */
.url-preview {
  margin-top: 8px;
  padding: 12px;
  background: rgba(77,163,255,0.05);
  border: 1px solid rgba(77,163,255,0.15);
  border-radius: var(--radius-sm);
  font-size: 12px;
  display: none;
}

.preview-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.preview-title {
  color: var(--accent);
  font-weight: 600;
}

.preview-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preview-item {
  padding: 4px 8px;
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
  color: var(--muted);
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 11px;
  word-break: break-all;
}

.preview-more {
  padding: 4px 8px;
  color: var(--accent);
  font-style: italic;
  font-size: 11px;
}

/* ライトモード用プレビュースタイル */
[data-theme="light"] .url-preview {
  background: rgba(43,108,176,0.03);
  border-color: rgba(43,108,176,0.1);
}

[data-theme="light"] .preview-item {
  background: rgba(0,0,0,0.03);
}

/* ローディングオーバーレイ */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.8);
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.loading-overlay.show {
  opacity: 1;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(77,163,255,0.2);
  border-top: 4px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.options{
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 12px 0 8px;
}
.checkbox{
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 14px;
}
.checkbox input[type="checkbox"]{
  width: 18px;
  height: 18px;
}

.buttons{
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0 6px;
}

.btn{
  border: 1px solid var(--border);
  background: var(--ghost);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  transition: transform .03s ease, box-shadow .2s ease, background .2s ease;
  user-select: none;
}
.btn:hover{
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}
.btn:active{
  transform: translateY(1px);
}

.btn.primary{
  background: linear-gradient(180deg, var(--btn-bg), var(--btn-bg-strong));
  border-color: transparent;
  color: white;
  font-weight: 700;
}

.btn.ghost{
  background: transparent;
}

.details{
  margin-top: 8px;
  color: var(--muted);
}
.details summary{
  cursor: pointer;
  color: var(--text);
}
.details ul{
  margin-top: 10px;
  padding-left: 18px;
}

footer{
  margin: 20px 0 0;
  text-align: center;
}
.footer{
  display: inline-block;
  padding: 8px 14px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 14px;
}
.footer a{
  color: var(--text);
  text-decoration: underline;
}

/* テーマ切り替えボタン */
.btn-theme{
  position: fixed;
  top: 32px;
  right: calc(50% - 460px + 66px);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ghost);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform .1s ease, box-shadow .2s ease, background .3s ease;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-icon-light,
.theme-icon-dark{
  position: absolute;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.theme-icon-dark{
  opacity: 0;
  transform: rotate(180deg);
}
.theme-icon-light{
  opacity: 1;
  transform: rotate(0deg);
}

[data-theme="light"] .theme-icon-dark{
  opacity: 1;
  transform: rotate(0deg);
}
[data-theme="light"] .theme-icon-light{
  opacity: 0;
  transform: rotate(180deg);
}

@media (max-width: 960px) {
  .btn-theme{
    right: 66px;
  }
}
.btn-theme:hover{
  transform: scale(1.1);
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-theme:active{
  transform: scale(0.95);
}

/* ヘルプボタン */
.site-header{
  position: relative;
}
.btn-help{
  position: fixed;
  top: 32px;
  right: calc(50% - 460px + 20px);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--btn-bg);
  color: white;
  border: none;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s ease, box-shadow .2s ease;
  z-index: 100;
}
@media (max-width: 960px) {
  .btn-help{
    right: 20px;
  }
}
.btn-help:hover{
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(77,163,255,0.4);
}
.btn-help:active{
  transform: scale(0.95);
}

/* モーダル */
.modal{
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--modal-overlay);
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}
.modal.show{
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

.modal-header{
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2{
  margin: 0;
  font-size: 24px;
}

.modal-close{
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 28px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s ease;
}
.modal-close:hover{
  color: var(--text);
}

.modal-body{
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-body section{
  margin-bottom: 24px;
}
.modal-body h3{
  margin: 0 0 12px;
  font-size: 18px;
  color: var(--text);
}
.modal-body h4{
  margin: 12px 0 8px;
  font-size: 15px;
  color: var(--muted);
}
.modal-body p{
  line-height: 1.6;
  color: var(--muted);
}
.modal-body ul, .modal-body ol{
  line-height: 1.8;
  color: var(--muted);
}
.modal-body li{
  margin-bottom: 4px;
}
.modal-body code{
  background: rgba(77,163,255,0.15);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.9em;
}
.modal-body strong{
  color: var(--text);
}

/* アニメーション */
@keyframes fadeIn{
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp{
  from { 
    opacity: 0;
    transform: translateY(20px);
  }
  to { 
    opacity: 1;
    transform: translateY(0);
  }
}

/* レスポンシブ対応 */
@media (max-width: 600px) {
  .btn-theme{
    position: fixed;
    bottom: 76px;
    right: 20px;
    top: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  }
  .btn-help{
    position: fixed;
    bottom: 20px;
    right: 20px;
    top: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  }
  .modal-content{
    max-height: 100vh;
    border-radius: 0;
  }
}

/* 消したものと、貼る前に見ておきたい点 */
.report-panel{
  margin-top: 1rem;
  padding: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.report-panel.risk-panel{
  border-color: var(--warn-border);
  background: var(--warn-bg);
}

.report-title{
  margin: 0 0 .6rem;
  font-size: 1rem;
  color: var(--text);
}

.report-list{
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: .5rem;
}

.report-item{
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .4rem .6rem;
  min-width: 0;
}

.report-name{
  padding: .1rem .4rem;
  background: var(--textarea-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
}

.report-note,
.risk-body{
  color: var(--report-note);
  font-size: .92rem;
  overflow-wrap: anywhere;
}

.report-where,
.report-count{
  color: var(--report-note);
  font-size: .85rem;
}

.risk-item{
  display: grid;
  gap: .2rem;
}

.risk-label{
  color: var(--warn-text);
}

.risk-detail{
  padding: .1rem .4rem;
  background: var(--textarea-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
  justify-self: start;
  max-width: 100%;
}

/* 操作要素の当たり判定をそろえる（指で触れる大きさにする） */
.btn,
.btn-copy-output,
.btn-theme,
.btn-help,
.modal-close{
  min-width: 44px;
  min-height: 44px;
}

/* チェックボックスは見た目を変えず、ラベルごと触れる範囲を広げる */
.checkbox,
label:has(> input[type="checkbox"]){
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  min-height: 44px;
}

input[type="checkbox"]{
  width: 1.15rem;
  height: 1.15rem;
}

/* hidden 属性で出し入れする（style属性を使うとCSPのstyle-src-attrに触れる） */
[hidden]{
  display: none !important;
}

/* ヘルプ内の補足ブロック（以前はstyle属性で書かれていた） */
.help-callout{
  padding: 12px;
  margin: 10px 0;
  border-radius: 8px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
}

/* 見出し下の説明は、青い地の上に載るので専用の色にする */
.subtitle{
  color: var(--subtitle);
}

/* 言語切り替え */
.btn-lang{
  position: fixed;
  top: 32px;
  right: calc(50% - 460px + 72px);
  min-height: 44px;
  padding: .4rem .9rem;
  border-radius: 999px;
  background: var(--ghost);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: .9rem;
  cursor: pointer;
  z-index: 5;
}

.btn-lang:hover,
.btn-lang:focus-visible{
  border-color: var(--accent);
}

@media (max-width: 1000px){
  .btn-lang{
    position: static;
    display: block;
    margin: .5rem auto 0;
  }
}

/* フッターも青い地の上に載るので、説明文と同じ色にする */
.footer{
  color: var(--subtitle);
}

/* ヘッダー右上の操作をまとめて並べる。
   以前は3つとも position: fixed で右端からの距離を個別に指定していたため、
   言語ボタンを足したときに重なって文字が切れていた。 */
.header-actions{
  position: fixed;
  top: 24px;
  right: max(20px, calc(50% - 460px + 20px));
  display: flex;
  align-items: center;
  gap: .5rem;
  z-index: 100;
}

.header-actions .btn-theme,
.header-actions .btn-help,
.header-actions .btn-lang{
  position: static;
  right: auto;
  top: auto;
  margin: 0;
}

.header-actions .btn-lang{
  white-space: nowrap;
}

@media (max-width: 1000px){
  .header-actions{
    position: static;
    justify-content: center;
    margin: .75rem auto 0;
  }

  .header-actions .btn-lang{
    display: inline-block;
    margin: 0;
  }
}

/* トーストは画面下へ出す。
   右上のままだと、ヘッダーのボタン（テーマ・言語・ヘルプ）に重なる。 */
.toast{
  top: auto;
  bottom: -100px;
  right: 20px;
  left: auto;
}

.toast.show{
  top: auto;
  bottom: 20px;
}

@media (max-width: 600px){
  .toast{
    right: 12px;
    left: 12px;
    max-width: none;
  }
}

/* 連れているURL自体の問題 */
.risk-target-note{
  color: var(--warn-text);
  font-size: .9rem;
}

/* 自分で消したい名前 */
.custom-rules{
  margin-top: .5rem;
}

.custom-rules .input{
  width: 100%;
  min-height: 44px;
  padding: .6rem .8rem;
  background: var(--textarea-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .95rem;
}

.custom-rules-note{
  margin: .3rem 0 0;
  color: var(--report-note);
  font-size: .85rem;
}

/* URLの部品 */
.structure-list{
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  gap: .35rem .8rem;
  margin: 0;
}

.structure-key{
  color: var(--report-note);
  font-size: .9rem;
}

.structure-key.structure-warn{
  color: var(--warn-text);
  font-weight: 700;
}

.structure-value{
  margin: 0;
  min-width: 0;
}

.structure-value code{
  overflow-wrap: anywhere;
}

.structure-note{
  margin-left: .5rem;
  color: var(--report-note);
  font-size: .85rem;
}

@media (max-width: 600px){
  .structure-list{
    grid-template-columns: minmax(0, 1fr);
    gap: .1rem;
  }

  .structure-value{
    margin-bottom: .5rem;
  }
}
