/* QR Risk Radar。色はトークンにまとめ、文字と背景の組み合わせのコントラスト比は test/html.test.js が確かめる */
:root {
  color-scheme: light dark;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #4b5563;
  --border: #d1d5db;
  --code-bg: #f3f4f6;
  --accent: #4c51bf;
  --accent-text: #ffffff;
  --focus: #2563eb;
  --header-1: #4c51bf;
  --header-2: #6b46c1;
  --header-text: #ffffff;
  --high-bg: #fde8e8;
  --high-fg: #9b1c1c;
  --medium-bg: #fef3c7;
  --medium-fg: #92400e;
  --low-bg: #e0f2fe;
  --low-fg: #075985;
  --trusted-bg: #dcfce7;
  --trusted-fg: #166534;
  --none-bg: #e5e7eb;
  --none-fg: #1f2937;
  --error: #b91c1c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #334155;
    --code-bg: #0f172a;
    --accent: #818cf8;
    --accent-text: #0f172a;
    --focus: #93c5fd;
    --header-1: #312e81;
    --header-2: #4c1d95;
    --header-text: #ffffff;
    --high-bg: #450a0a;
    --high-fg: #fecaca;
    --medium-bg: #451a03;
    --medium-fg: #fde68a;
    --low-bg: #082f49;
    --low-fg: #bae6fd;
    --trusted-bg: #052e16;
    --trusted-fg: #bbf7d0;
    --none-bg: #334155;
    --none-fg: #f1f5f9;
    --error: #fca5a5;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  line-height: 1.7;
}

code { font-family: ui-monospace, "SFMono-Regular", Consolas, "BIZ UDGothic", monospace; word-break: break-all; }

.site-header {
  background: linear-gradient(135deg, var(--header-1), var(--header-2));
  color: var(--header-text);
  padding: 1.5rem 1rem;
  text-align: center;
}
.site-header h1 { margin: 0; font-size: 1.9rem; }
.tagline { margin: 0.4rem 0 0; }
.lang-btn {
  min-height: 44px;
  min-width: 44px;
  margin-top: 0.6rem;
  padding: 0.3rem 0.9rem;
  border: 1px solid var(--header-text);
  border-radius: 8px;
  background: transparent;
  color: var(--header-text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.lang-btn:focus-visible { outline-color: var(--header-text); }
/* 広い画面では題名を中央に、言語のボタンを右端に置く */
@media (min-width: 769px) {
  .site-header { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; }
  .header-text { grid-column: 2; }
  .lang-btn { grid-column: 3; justify-self: end; margin-top: 0; }
}

main { max-width: 760px; margin: 0 auto; padding: 1.5rem 1rem 2rem; }

.notice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 0 0 1.5rem;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ボタン（押せる大きさは44px以上） */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 44px; min-width: 44px; padding: 0.5rem 1.1rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.small { padding: 0.3rem 0.8rem; font-size: 0.9rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.button-bar { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0.75rem 0; }
.file-btn { position: relative; }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }

/* タブ */
.tabs { display: flex; gap: 0.5rem; border-bottom: 2px solid var(--border); margin-bottom: 1rem; }
.tab {
  flex: 1; min-height: 48px; padding: 0.5rem 1rem;
  background: transparent; color: var(--muted);
  border: 0; border-bottom: 3px solid transparent; margin-bottom: -2px;
  font: inherit; font-weight: 600; cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); background: var(--surface); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.1rem; }
.field-label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
textarea, input[type="text"] {
  width: 100%; padding: 0.6rem 0.75rem; min-height: 44px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { font-family: ui-monospace, Consolas, monospace; resize: vertical; }

.hint { color: var(--muted); font-size: 0.92rem; margin: 0.4rem 0; }
.muted { color: var(--muted); }
.status { min-height: 1.5em; margin: 0.25rem 0; }
.status.error { color: var(--error); font-weight: 600; }
.section-title { font-size: 1.15rem; margin: 1.5rem 0 0.4rem; }

/* サンプル */
.sample-group { border: 1px solid var(--border); border-radius: 8px; margin: 0.5rem 0; }
.sample-group summary { cursor: pointer; padding: 0.6rem 0.8rem; font-weight: 600; min-height: 44px; }
.sample-group ul {
  list-style: none;
  margin: 0;
  padding: 0 0.6rem 0.6rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
}
.sample {
  width: 100%; height: 100%; text-align: left; min-height: 44px;
  display: flex; flex-direction: column; gap: 0.2rem;
  padding: 0.6rem 0.7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit; cursor: pointer;
}
.sample-title { font-weight: 600; }
.sample-note { color: var(--muted); font-size: 0.85rem; }

/* 判定の印 */
.badge { display: inline-block; padding: 0.1rem 0.6rem; border-radius: 999px; font-size: 0.85rem; font-weight: 700; white-space: nowrap; }
.level-high { background: var(--high-bg); color: var(--high-fg); }
.level-medium { background: var(--medium-bg); color: var(--medium-fg); }
.level-low { background: var(--low-bg); color: var(--low-fg); }
.level-trusted { background: var(--trusted-bg); color: var(--trusted-fg); }
.level-other, .level-text { background: var(--none-bg); color: var(--none-fg); }

/* 結果 */
.result {
  overflow-wrap: anywhere;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin-top: 1.25rem;
}
.result-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
.result-head h2 { margin: 0; font-size: 1.3rem; }
.result-head .badge { font-size: 1rem; }
.total { color: var(--muted); }
.level-note { margin: 0.6rem 0; }
.input-echo { background: var(--code-bg); border-radius: 6px; padding: 0.4rem 0.6rem; }
.owner { margin: 0.8rem 0 0.2rem; }
.host-line { font-family: ui-monospace, Consolas, monospace; font-size: 1.05rem; margin: 0 0 0.6rem; word-break: break-all; }
.host-sub { color: var(--muted); }
.host-reg { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.parts-box summary { cursor: pointer; min-height: 44px; padding: 0.5rem 0; }
.parts { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.parts th, .parts td { border-top: 1px solid var(--border); padding: 0.35rem 0.4rem; text-align: left; vertical-align: top; }
.parts th { width: 34%; font-weight: 600; }
.result h3 { font-size: 1.05rem; margin: 1rem 0 0.4rem; }
.signals { list-style: none; padding: 0; margin: 0; }
.signals li { display: flex; gap: 0.6rem; padding: 0.45rem 0; border-top: 1px solid var(--border); }
.signals .pts {
  flex: 0 0 2.6rem;
  text-align: center;
  font-weight: 700;
  border-radius: 6px;
  background: var(--none-bg);
  color: var(--none-fg);
  height: fit-content;
}
.signals .hit .pts { background: var(--high-bg); color: var(--high-fg); }
.signal-text { flex: 1; }
.follow { margin-left: 0.5rem; }
.qr-make { margin-top: 1rem; }
.qr-out { margin-top: 0.75rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.qr-out img { background: #fff; border: 1px solid var(--border); border-radius: 6px; image-rendering: pixelated; }
.qr-out .hint { flex-basis: 100%; }

/* QR を読む（貼り付け・ドロップ） */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  margin: 0.75rem 0;
  text-align: center;
  color: var(--muted);
}
body.dragging .drop-zone { border-color: var(--accent); background: var(--low-bg); color: var(--low-fg); }
body.dragging main { outline: 3px dashed var(--accent); outline-offset: 4px; }

/* 生の中身は並び順どおりに表示し、向きを変える文字・見えない文字は印にする */
.logical { unicode-bidi: bidi-override; direction: ltr; }
.ctrl {
  display: inline-block;
  margin: 0 0.15em;
  padding: 0 0.3em;
  border-radius: 4px;
  background: var(--high-bg);
  color: var(--high-fg);
  font-size: 0.85em;
  white-space: nowrap;
}
.inspect { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0.5rem 0; }
.inspect .hint { margin: 0; }

/* 中身の種類 */
.payload h3 { font-size: 1.05rem; margin: 1rem 0 0.4rem; }
.payload h4 { font-size: 0.95rem; margin: 0.8rem 0 0.3rem; }
.notes {
  margin: 0.6rem 0;
  padding: 0.5rem 0.75rem 0.5rem 1.6rem;
  border-radius: 6px;
  background: var(--medium-bg);
  color: var(--medium-fg);
}
.notes li { margin: 0.2rem 0; }
.payload-urls { list-style: none; padding: 0; margin: 0; }
.payload-urls li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; padding: 0.35rem 0; border-top: 1px solid var(--border); }

/* QR を読む */
.camera-box { position: relative; margin: 0.75rem 0; border-radius: 8px; overflow: hidden; background: #000; }
.camera-box video { display: block; width: 100%; max-height: 60vh; object-fit: contain; }
.scan-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: #e9b213;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.image-box { margin: 0.75rem 0; }
.image-box img { max-width: 100%; max-height: 260px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.image-box figcaption { color: var(--muted); font-size: 0.9rem; }

/* 信頼するドメイン */
.samples-section, .trust, .accuracy { margin-top: 1.5rem; }
.trust-controls { display: flex; gap: 0.5rem; align-items: center; }
.trust-controls input { flex: 1; min-width: 0; }
.trust-controls .btn { flex: none; }
.trust-list { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.trust-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.3rem 0; border-top: 1px solid var(--border); }
.trust-list li.empty { color: var(--muted); border: 0; }

/* 確かさの表 */
.table-wrap { overflow-x: auto; }
.table-title { font-size: 1rem; margin: 0.9rem 0 0.3rem; }
.accuracy-table { border-collapse: collapse; width: 100%; font-size: 0.9rem; background: var(--surface); }
.accuracy-table th, .accuracy-table td { border: 1px solid var(--border); padding: 0.4rem 0.5rem; text-align: left; }
.accuracy-table td { text-align: right; white-space: nowrap; }

.site-footer { text-align: center; padding: 1.5rem 1rem 2rem; }
.site-footer a { color: var(--text); min-height: 44px; display: inline-flex; align-items: center; }

@media (max-width: 480px) {
  .site-header h1 { font-size: 1.5rem; }
  .trust-controls { flex-direction: column; }
  .signals li { flex-direction: column; gap: 0.2rem; }
  .signals .pts { flex-basis: auto; width: 2.6rem; }
}
