:root {
  color-scheme: light; /* 既定はライト。右上のメニューで切り替える（app.js の applyTheme） */
  --bg: light-dark(#f5f6f8, #0e1014);
  --surface: light-dark(#ffffff, #16191f);
  --surface-2: light-dark(#f0f2f5, #1d2129);
  --line: light-dark(#e2e5ea, #2a2f39);
  --line-strong: light-dark(#c9ced6, #3a414e);
  --text: light-dark(#14171c, #e7e9ed);
  --muted: light-dark(#5d6573, #98a1b0);
  --accent: light-dark(#1d5bf0, #7ea6ff);
  --accent-tint: light-dark(#eaf0ff, #1b2540);
  --accent-ink: light-dark(#ffffff, #0a1020);
  --ok: light-dark(#13773a, #63d491);
  --danger: light-dark(#c2271a, #ff8f80);
  --stg: light-dark(#d97706, #f5a524);
  --serp-title: light-dark(#1a0dab, #8ab4f8);
  --radius: 14px;
  --shadow: 0 1px 2px light-dark(rgb(16 24 40 / .06), rgb(0 0 0 / .4));
  accent-color: var(--accent);
}
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="system"] { color-scheme: light dark; }
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font: 15px/1.6 "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button, input, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

/* ---------- バー ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
body[data-env="stg"] .bar { box-shadow: inset 0 3px 0 var(--stg); }
.brand { font-weight: 700; letter-spacing: .04em; color: var(--text); text-decoration: none; }
.site { color: var(--muted); font-size: 13px; }
.env {
  font-size: 12px; font-weight: 700; color: var(--stg);
  border: 1px solid currentColor; border-radius: 999px; padding: 1px 10px;
}
body:not([data-env]) .env { display: none; }
.me {
  margin-left: auto; width: 32px; height: 32px; border-radius: 50%; padding: 0;
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--line); cursor: pointer;
}
.me:hover, .me:has(+ .menu:popover-open) { border-color: var(--accent); color: var(--accent); }
.menu {
  /* 右上のボタンの下に出す。popover は既定で画面の中央なので、位置を決め直す */
  position: fixed; inset: 52px 16px auto auto; margin: 0;
  width: min(300px, calc(100vw - 32px)); padding: 14px 16px;
  display: none; gap: 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 28px light-dark(rgb(16 24 40 / .14), rgb(0 0 0 / .5));
}
.menu:popover-open { display: grid; }
.menu-who { margin: 0; display: grid; gap: 2px; font-size: 13px; overflow-wrap: anywhere; }
.menu-who span { color: var(--muted); font-size: 12px; }
.menu-theme { margin: 0; padding: 0; border: 0; display: grid; gap: 6px; }
.menu-theme legend { padding: 0; margin-bottom: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.menu-theme label { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.menu-out {
  justify-self: start; padding: 0; border: 0; background: none; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--danger);
}
.menu-out[hidden] { display: none; }
body[data-state="login"] :is(.me, .menu) { display: none; }

/* ---------- ログイン ---------- */
.login {
  width: min(400px, 100%); margin: 8vh auto 0; padding: 24px 20px;
  gap: 16px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.login h1 { margin: 0; font-size: 20px; }
.login-form { display: grid; gap: 10px; }
.login-form[hidden] { display: none; }
.login-form label { font-size: 13px; font-weight: 600; color: var(--muted); }
.login-form input {
  height: 44px; width: 100%; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
}
.login-form input[name="code"] { font-size: 20px; letter-spacing: .3em; text-align: center; }
.login-sent { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.login-sub { display: grid; gap: 8px; }
.login .primary:disabled { cursor: progress; filter: saturate(.6); }

main { container-type: inline-size; max-width: 1180px; margin: 0 auto; padding: 28px 24px 96px; }
main:focus { outline: none; }
[data-view] { display: none; }
body[data-state="home"] [data-view="home"],
body[data-state="login"] [data-view="login"],
body:not([data-state="home"], [data-state="boot"], [data-state="login"]) [data-view="job"] { display: grid; }

/* ---------- ホーム ---------- */
.home { gap: 40px; view-transition-name: stage; }
.drop {
  display: grid; place-items: center; align-content: center; gap: 14px;
  min-height: min(46vh, 420px);
  border: 2px dashed var(--line-strong); border-radius: 22px;
  background: var(--surface);
  color: var(--muted); cursor: pointer;
  transition: border-color .15s, background-color .15s, color .15s;
}
.drop:hover, .drop.is-over { border-color: var(--accent); background: var(--accent-tint); color: var(--accent); }
.drop:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 4px; }
.drop svg { width: 56px; height: 56px; }
.drop strong { font-size: 18px; color: var(--text); font-weight: 600; }

.history-head { display: flex; align-items: center; gap: 16px; margin: 0 0 8px; }
.history h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0; letter-spacing: .04em; }
.history-q {
  margin-left: auto; width: min(320px, 100%); height: 36px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); font-size: 14px;
}
.runs-empty { margin: 16px 4px; color: var(--muted); font-size: 14px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 12px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pager .ghost { width: auto; height: 36px; padding: 0 16px; }
.pager .ghost:disabled { opacity: .4; cursor: default; border-color: var(--line-strong); color: inherit; }
.pager[hidden], .runs-empty[hidden] { display: none; }
.runs { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.runs a {
  display: grid; grid-template-columns: 88px minmax(0, 1fr) auto auto; align-items: center; gap: 16px;
  padding: 12px 4px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none;
}
.runs a:hover { background: var(--surface); }
.runs .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.runs time, .runs .who { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.state { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.state.ok { color: var(--ok); }
.state.ng { color: var(--danger); }
.state.run { color: var(--accent); }

/* ---------- 確認 ---------- */
.job {
  grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start;
  view-transition-name: stage;
}
@container (max-width: 880px) {
  .job { grid-template-columns: minmax(0, 1fr); }
}
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

.doc { padding: 24px 28px 28px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }
@container (max-width: 560px) { .doc { padding: 18px 16px 22px; } }
.eyecatch {
  margin: 0; grid-area: thumb; align-self: start; width: 120px; aspect-ratio: 3 / 2; border-radius: 10px; overflow: hidden;
  background:
    radial-gradient(120% 140% at 0% 0%, light-dark(#dbe7ff, #22325a) 0%, transparent 60%),
    radial-gradient(120% 140% at 100% 100%, light-dark(#fde7d6, #4a2b1f) 0%, transparent 55%),
    var(--surface);
  display: grid; place-items: center; color: light-dark(#93a3c4, #5d6c8f);
}
.eyecatch svg { width: 36px; height: 36px; opacity: .8; }

.kw {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line-strong); border-radius: 12px; padding: 4px 6px 4px 6px;
  background: var(--surface);
}
/* フォーカスの輪は outline で描く（box-shadow は強制カラーモードで消える） */
.kw:has(input:focus-visible) { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 2px; }
.kw label {
  font-size: 12px; font-weight: 700; letter-spacing: .06em;
  background: var(--text); color: var(--surface); border-radius: 8px; padding: 4px 9px;
}
.kw input { flex: 1; border: 0; background: none; padding: 8px 4px; font-size: 16px; font-weight: 600; }
.kw input:focus-visible { outline: none; } /* 輪は外枠 .kw に出す */
.kw-hint { flex: none; font-size: 12px; color: var(--accent); font-weight: 600; padding-right: 6px; }
.kw-hint[hidden] { display: none; }

/* 検索結果の見た目で、タイトル・URL・メタを並べる */
.serp {
  display: grid; column-gap: 16px; row-gap: 2px; padding: 16px 18px; border-radius: 12px; background: var(--surface-2);
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "url thumb" "title thumb" "meta thumb" "err err";
}
.serp-url { grid-area: url; display: flex; align-items: baseline; font-size: 13px; color: var(--muted); min-width: 0; }
.serp-url span { flex: none; white-space: nowrap; }
.serp-url input { flex: 1; border: 0; background: none; padding: 0 0 0 4px; color: var(--text); min-width: 0; }
.serp-title {
  grid-area: title; border: 0; background: none; padding: 2px 0; width: 100%; resize: none; field-sizing: content;
  font-size: 20px; line-height: 1.4; color: var(--serp-title); font-weight: 500;
}
.serp .meta-box { grid-area: meta; }
.serp .err { grid-area: err; }
@container (max-width: 560px) {
  .serp { grid-template-areas: "thumb" "url" "title" "meta" "err"; grid-template-columns: minmax(0, 1fr); }
  .eyecatch { width: 100%; aspect-ratio: 3 / 1; margin-bottom: 8px; }
}
.meta-box textarea {
  border: 0; background: none; resize: none; padding: 2px 0; width: 100%;
  color: var(--muted); font-size: 14px; line-height: 1.6; field-sizing: content; min-height: 3.2em;
}
.serp :is(input, textarea) { border-radius: 4px; }
.serp :is(input, textarea):hover { background: color-mix(in srgb, var(--surface) 60%, transparent); }
.serp :is(input, textarea):focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; background: var(--surface); }
.serp :user-invalid { outline: 2px solid var(--danger) !important; outline-offset: 1px; }
.err { display: none; margin: 4px 0 0; font-size: 13px; color: var(--danger); font-weight: 600; }
.serp:has(:user-invalid) .err { display: block; }
.skel {
  height: 3.2em; border-radius: 6px;
  background: linear-gradient(90deg, var(--line) 0 30%, color-mix(in srgb, var(--line) 40%, transparent) 50%, var(--line) 70% 100%) 0 0 / 300% 100%;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { to { background-position: -150% 0; } }
body[data-convert="running"] .serp .meta-box textarea { display: none; }
body:not([data-convert="running"]) .meta-box .skel { display: none; }
body:not([data-permalink="running"]) .skel-slug { display: none; }
body[data-permalink="running"] .serp-url input { display: none; }
.skel-slug { flex: 1; height: 1.2em; margin-left: 4px; }
body:not([data-classify="running"]) .group .skel { display: none; }
body[data-classify="running"] .group .chips { display: none; }

/* 構成と CTA の位置 */
.outline { list-style: none; margin: 0; padding: 0 0 0 18px; position: relative; }
.outline::before { content: ""; position: absolute; left: 5px; top: 10px; bottom: 10px; width: 2px; background: var(--line); border-radius: 2px; }
.sec { position: relative; padding: 10px 0; }
.sec::before { content: ""; position: absolute; left: -17px; top: 19px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line-strong); }
.sec-head { display: flex; align-items: baseline; gap: 12px; }
.sec-head h3 { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.45; flex: 1; }
.imgs { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.imgs svg { width: 15px; height: 15px; }
.sec ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 2px; }
.sec li { font-size: 13.5px; color: var(--muted); padding-left: 14px; position: relative; }
.sec li::before { content: ""; position: absolute; left: 0; top: .8em; width: 6px; height: 1px; background: var(--line-strong); }

.slot { position: relative; }
.slot-add {
  display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%;
  height: 22px; margin: 0; padding: 0; border: 0; background: none; cursor: pointer;
  color: transparent; font-size: 12px; font-weight: 600;
}
.slot-add::before, .slot-add::after { content: ""; flex: 1; height: 0; border-top: 1px dashed transparent; }
.slot-add:is(:hover, :focus-visible) { color: var(--accent); }
.slot-add:is(:hover, :focus-visible)::before, .slot-add:is(:hover, :focus-visible)::after { border-color: var(--accent); }
.slot.is-on .slot-add { display: none; }
.slot:not(.is-on) .cta { display: none; }

.cta {
  display: flex; align-items: center; gap: 10px; margin: 4px 0;
  padding: 8px; border: 1px dashed var(--accent); border-radius: 12px; background: var(--accent-tint);
}
.cta-mark { font-size: 11px; font-weight: 800; letter-spacing: .08em; color: var(--accent); writing-mode: vertical-rl; padding: 0 2px; }
.cta-body { display: grid; gap: 4px; flex: 1; min-width: 0; }
.cta-sub { font-size: 12px; color: var(--muted); line-height: 1.4; overflow-wrap: anywhere; }
.cta-select, .btn-row select { width: 100%; max-width: 100%; font: inherit; font-size: 14px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text); }
.btn-mark { margin-left: 8px; padding: 1px 6px; font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-tint); border-radius: 6px; }
.btn-rows { display: grid; gap: 10px; margin-top: 12px; }
.btn-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; align-items: start; font-size: 13.5px; font-weight: 600; }
.btn-row > div { display: grid; gap: 4px; min-width: 0; }
.x {
  margin-left: auto; align-self: flex-start; width: 28px; height: 28px; border-radius: 8px; border: 0;
  background: none; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1;
}
.x:hover { background: var(--surface); color: var(--text); }
.slot.is-end .x { display: none; }

/* ---------- 決めること ---------- */
.decide {
  position: sticky; top: 76px; max-height: calc(100dvh - 92px); overflow: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
  padding: 20px 20px 0; display: grid; gap: 20px; align-content: start;
}
@container (max-width: 880px) {
  .decide { position: static; max-height: none; overflow: visible; }
}
.group { border: 0; margin: 0; padding: 0; min-width: 0; }
.group legend { padding: 0; margin-bottom: 8px; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .06em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none;
  padding: 6px 12px; border-radius: 999px; font-size: 14px;
  border: 1px solid var(--line-strong); background: var(--surface);
  transition: background-color .12s, border-color .12s, color .12s;
}
.chip:hover { border-color: var(--accent); }
.chip:has(:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip:has(:checked)::before { content: "✓"; font-size: 12px; }
.chip:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip[hidden] { display: none; }
.tag-more { margin-top: 8px; }
.tag-more[hidden], body[data-classify="running"] .tag-more { display: none; }
.tag-more summary {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; list-style: none;
  padding: 6px 12px; border-radius: 999px; font-size: 14px; color: var(--muted);
  border: 1px dashed var(--line-strong);
}
.tag-more summary::-webkit-details-marker { display: none; }
.tag-more summary::before { content: "＋"; font-size: 12px; }
.tag-more[open] summary::before { content: "－"; }
.tag-more summary:hover { border-color: var(--accent); color: var(--text); }
.tag-more summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tag-q {
  display: block; width: 100%; margin: 8px 0; padding: 6px 12px; font-size: 14px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text);
}
.tag-q:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
#tag-rest { max-height: 260px; overflow-y: auto; padding: 2px; }
.tag-none { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

.types { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type { cursor: pointer; border-radius: 10px; overflow: hidden; border: 2px solid var(--line); background: var(--surface); }
.type:hover { border-color: var(--line-strong); }
.type:has(:checked) { border-color: var(--accent); }
.type:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.type img { aspect-ratio: 682 / 461; object-fit: cover; width: 100%; }
.type span { display: block; padding: 6px 8px; font-size: 12.5px; font-weight: 600; line-height: 1.35; }
.type input { position: absolute; opacity: 0; pointer-events: none; }

.go {
  position: sticky; bottom: 0; display: grid; gap: 8px;
  margin: 0 -20px; padding: 12px 20px 20px;
  background: linear-gradient(to bottom, transparent, var(--surface) 14px);
}
/* 文字（警告・失敗）を載せるときは透かさない。透けると下のチップと重なって読めない */
.go:has(.issues li, .fail:not([hidden])) {
  background: var(--surface); box-shadow: 0 -1px 0 var(--line);
  border-bottom-left-radius: inherit; border-bottom-right-radius: inherit;
}
body[data-state="failed"] .go:has(.fail) { position: static; box-shadow: none; }
.primary {
  height: 50px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-size: 16px; font-weight: 700;
}
.primary:hover { filter: brightness(1.06); }
.primary[aria-disabled="true"] { cursor: progress; filter: saturate(.6); }
progress {
  appearance: none; width: 100%; height: 6px; border: 0; border-radius: 999px; overflow: hidden;
  background: var(--surface-2); color: var(--accent);
}
progress::-webkit-progress-bar { background: var(--surface-2); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; transition: inline-size .3s; }
progress::-moz-progress-bar { background: var(--accent); }
.meter { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meter progress { flex: 1; }
body[data-state="ready"] .meter, body[data-state="done"] .meter, body[data-state="failed"] .meter { display: none; }
body[data-state="failed"] .primary { display: none; }
body[data-state="failed"][data-nodoc="1"] :is(.doc, .decide .group) { display: none; }
body[data-state="publishing"] .primary { display: none; }

.result { display: none; text-align: center; gap: 14px; padding: 8px 0 4px; justify-items: center; }
body[data-state="done"] .result { display: grid; }
body[data-state="done"] .decide > :not(.result) { display: none; }
:is(.doc, .decide fieldset)[inert] { opacity: .55; filter: saturate(.4); transition: opacity .2s; }
.result .mark { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.result .mark svg { width: 28px; height: 28px; }
.result h2 { margin: 0; font-size: 18px; }
.result .id { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.result a.primary { display: grid; place-items: center; width: 100%; text-decoration: none; }
.issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: 13px; color: var(--stg); }
.issues:empty, .fail[hidden] { display: none; }
.fail { display: grid; gap: 8px; }
.fail p { margin: 0; color: var(--danger); font-weight: 600; font-size: 14px; }
.drop-err { margin: 0; font-size: 13px; color: var(--danger); font-weight: 600; }
.drop-err:empty { display: none; }
.ghost { height: 44px; width: 100%; border-radius: 12px; border: 1px solid var(--line-strong); background: none; cursor: pointer; font-weight: 600; }
.ghost:hover { border-color: var(--accent); color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  .skel { animation: none; }
}
.eyecatch img { width: 100%; height: 100%; object-fit: cover; }
