:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --text: #22252a;
  --muted: #6b7078;
  --line: #e3e0d8;
  --accent: #e4572e;
  --accent-ink: #ffffff;
  --chip: #f1eee7;
  --icon: #8a8f97;
  --accent-soft: #fff1ec;
  --hover: #e2ddd2;
  --inverse-bg: #22252a;
  --inverse-fg: #ffffff;
  --link: #2e6fab;
  --radius: 14px;
  --header-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181b; --card: #212328; --text: #ecebe7; --muted: #a2a6ad; --line: #33363c;
    --chip: #2c2f35; --icon: #9aa0a8; --accent-soft: #3a2620; --hover: #3a3d44;
    --inverse-bg: #ecebe7; --inverse-fg: #17181b; --link: #7fb2e5; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17181b; --card: #212328; --text: #ecebe7; --muted: #a2a6ad; --line: #33363c;
  --chip: #2c2f35; --icon: #9aa0a8; --accent-soft: #3a2620; --hover: #3a3d44;
  --inverse-bg: #ecebe7; --inverse-fg: #17181b; --link: #7fb2e5; color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.6;
}

a { color: var(--link); }
h2 { font-size: 18px; margin: 0 0 10px; }

/* ヘッダー: タイトルも1行に収めて、アプリ部分に高さを回す */
.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.logo { flex: none; font-weight: 800; font-size: 18px; color: var(--accent); text-decoration: none; }
.lang-switch {
  flex: none; margin-left: auto; padding: 3px 10px; border: 1px solid var(--line); border-radius: 999px;
  color: var(--text); font-size: 13px; text-decoration: none; background: var(--card);
}
.lang-switch:hover { background: var(--chip); }
.lang-suggest {
  display: block; padding: 6px 16px; background: var(--accent-soft); color: var(--text);
  font-size: 13px; text-align: center; text-decoration: none;
}
.lang-suggest[hidden] { display: none; }
.site-header h1 {
  margin: 0; font-size: 15px; font-weight: 700; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* アプリ本体: 画面の高さちょうどに収める */
.app {
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  min-height: 460px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 12px;
  padding: 12px;
}

.stage-pane, .picker-pane {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.modes {
  display: flex; gap: 2px; padding: 3px; margin-bottom: 8px;
  background: var(--chip); border-radius: 999px; align-self: flex-start;
}
.modes button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 4px 16px; border-radius: 999px; font-size: 14px; font-weight: 700;
}
.modes button[aria-selected="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

.toolbar { display: flex; align-items: center; gap: 8px 12px; margin-bottom: 8px; min-height: 30px; }
.chips {
  flex: 1; min-width: 0;
  display: flex; gap: 6px;
  overflow-x: auto; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 4px 2px 10px;
  border-radius: 999px;
  background: var(--chip);
  font-size: 13px; white-space: nowrap;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.chip button {
  border: 0; background: transparent; cursor: pointer;
  width: 22px; height: 22px; border-radius: 50%;
  color: var(--muted); font-size: 15px; line-height: 1;
}
.chip button:hover { background: var(--hover); color: var(--text); }

.me-input { flex: none; display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.me-input[hidden] { display: none; }
.me-input input {
  background: var(--card); color: var(--text);
  width: 64px; padding: 3px 6px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px;
}

.stage { flex: 1; min-height: 0; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.stage svg { display: block; width: 100%; height: 100%; }

.stage-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.ratio {
  flex: 1; min-width: 0; margin: 0; font-size: 13px; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ratio b { color: var(--text); }
.actions { flex: none; display: flex; gap: 6px; }
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn:hover { filter: brightness(0.97); }
.toast {
  position: absolute; left: 50%; top: 52px; transform: translateX(-50%);
  background: var(--inverse-bg); color: var(--inverse-fg); font-size: 13px; padding: 4px 12px; border-radius: 999px;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

.guide {
  display: flex; align-items: flex-start; gap: 6px;
  margin: 0 0 8px; padding: 6px 4px 6px 10px; border-radius: 8px;
  background: var(--accent-soft); color: var(--text); font-size: 13px; line-height: 1.5;
}
.guide[hidden] { display: none; }
.guide p { flex: 1; margin: 0; }
.guide button {
  flex: none; width: 24px; height: 24px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer;
}
.guide button:hover { background: var(--hover); color: var(--text); }
.search {
  background: var(--card); color: var(--text);
  width: 100%; padding: 8px 10px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px;
}
.cats { display: flex; gap: 6px; margin-bottom: 8px; overflow-x: auto; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.cats button {
  flex: none;
  border: 1px solid var(--line); background: var(--card); padding: 3px 11px;
  border-radius: 999px; font-size: 13px; cursor: pointer; color: var(--text);
}
.cats button[aria-pressed="true"] { background: var(--inverse-bg); color: var(--inverse-fg); border-color: var(--inverse-bg); }

.grid {
  flex: 1; min-height: 0; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  align-content: start; gap: 6px;
}
.grid button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 8px 4px; border: 1px solid var(--line); background: var(--card);
  border-radius: 10px; cursor: pointer; font-size: 12px; line-height: 1.25; color: var(--text);
}
.grid button svg { width: 40px; height: 30px; fill: var(--icon); color: var(--icon); }
.grid button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.grid button[aria-pressed="true"] svg { fill: var(--accent); color: var(--accent); }

/* スマホ: 上に比較図、下に選択肢 */
@media (max-width: 760px) {
  :root { --header-h: 46px; }
  .site-header { gap: 10px; padding: 0 12px; }
  .logo { font-size: 16px; }
  .site-header h1 { font-size: 13px; }
  .app { display: flex; flex-direction: column; gap: 8px; padding: 8px; min-height: 520px; }
  .stage-pane { flex: 0 0 56%; padding: 8px; }
  .picker-pane { flex: 1; padding: 8px; }
  .search { padding: 6px 10px; margin-bottom: 6px; }
  .cats { margin-bottom: 6px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); }
  .grid button { padding: 6px 2px; font-size: 11px; }
  .grid button svg { width: 32px; height: 24px; }
  .stage-foot { margin-top: 6px; flex-wrap: wrap; gap: 4px 6px; }
  .stage-foot .ratio { flex-basis: 100%; }
  .actions { margin-left: auto; }
  .ratio { font-size: 12px; }
}

/* ここから下はスクロールした先の詳しい情報 */
.wrap { max-width: 980px; margin: 0 auto; padding: 16px; }
.lead { color: var(--muted); margin: 8px 0 16px; }

.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-bottom: 16px; }
.item-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; font-size: 14px; }
.item-card h3 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.item-card h3 .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.item-card dl { display: grid; grid-template-columns: auto 1fr; gap: 0 10px; margin: 0 0 4px; }
.item-card dt { color: var(--muted); }
.item-card dd { margin: 0; font-weight: 700; }
.item-card p { margin: 0; color: var(--muted); font-size: 13px; }
.badge {
  margin-left: 4px; padding: 0 6px; border-radius: 999px;
  background: var(--chip); color: var(--muted); font-size: 11px; font-weight: 700;
}
.grid button small { display: block; color: var(--muted); font-size: 10px; }
.item-card dd small { font-weight: 400; color: var(--muted); font-size: 12px; }
.item-card .source { margin-top: 6px; font-size: 12px; line-height: 1.5; }

.article { margin: 8px 0 24px; }
.article table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; font-size: 15px; }
.article th, .article td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.article th { background: var(--chip); font-weight: 700; }

.related ul { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; }
.related a {
  display: inline-block; padding: 6px 12px; background: var(--card);
  border: 1px solid var(--line); border-radius: 999px; text-decoration: none; font-size: 14px;
}

.site-footer { max-width: 980px; margin: 0 auto; padding: 16px; color: var(--muted); font-size: 12px; }

/* 共有ページで「画像を保存」を押したときの画像表示 */
.image-overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: rgba(0, 0, 0, .6);
}
.image-dialog {
  max-width: 900px; width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: var(--card); color: var(--text);
  border-radius: var(--radius); padding: 14px;
}
.image-dialog img { width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--line); }
.image-dialog p { margin: 0; font-size: 14px; color: var(--muted); text-align: center; }

/* このサイトについて・プライバシーポリシーなどの文章ページ */
.doc { max-width: 760px; }
.doc h2 { margin-top: 28px; }
.doc p, .doc li { line-height: 1.9; }
.site-footer a { color: var(--muted); }
