:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #5d636b;
  --line: #dcd9d1;
  --accent: #1f4e5f;
  --accent-soft: #e6eef1;
  --ok: #2f6b3a;
  --ok-soft: #e8f1e9;
  --wait: #8a5a00;
  --wait-soft: #fbf1dc;
  --human: #47506a;
  --human-soft: #eceef4;
  --no: #6b6f75;
  --no-soft: #f0f0ee;
  --bad: #a3322a;
  --bad-soft: #f9e6e4;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 15px; line-height: 1.7; word-break: normal; overflow-wrap: anywhere;
}
a { color: var(--accent); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.err { color: var(--bad); min-height: 1.5em; }

/* 上の帯 */
.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.top-inner { max-width: 1120px; margin: 0 auto; padding: 10px 20px 0; }
.brand { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.title { font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 4px; padding: 0 6px; vertical-align: 2px; }
.maker { font-size: 11px; color: var(--muted); white-space: nowrap; }
.tabs { display: flex; gap: 4px; margin-top: 6px; overflow-x: auto; }
.tabs a { flex: 0 0 auto; text-decoration: none; color: var(--muted); padding: 8px 12px; border-bottom: 3px solid transparent; font-weight: 600; font-size: 14px; }
.tabs a .n { display: inline-block; width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 50%; background: var(--line); color: var(--ink); font-size: 12px; margin-right: 6px; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a.on .n { background: var(--accent); color: #fff; }

main.wrap { padding-top: 20px; padding-bottom: 28px; }
h1 { font-size: 21px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0; }
.lead { margin: 0 0 16px; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.card > h2:first-child { margin-top: 0; }

/* 入力 */
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.req { color: var(--bad); font-size: 12px; margin-left: 6px; font-weight: 600; }
.opt { color: var(--muted); font-size: 12px; margin-left: 6px; font-weight: 400; }
input[type=text], input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: #fff;
  border: 1px solid #c9c5bb; border-radius: 8px; padding: 9px 11px; min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.unit { position: relative; }
.unit input { padding-right: 48px; }
.unit span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 16px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
details.more { margin-top: 12px; }
details.more summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.examples { display: flex; gap: 8px; flex-wrap: wrap; }

.btn { font: inherit; font-size: 15px; font-weight: 600; border-radius: 8px; border: 1px solid #b9b5ab; background: #fff; color: var(--ink); padding: 10px 16px; min-height: 44px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; text-align: center; line-height: 1.4; }
.btn:hover { background: #faf9f6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #18404e; }
.btn.danger { color: var(--bad); border-color: #d8b0ab; }
.btn.small { font-size: 13px; padding: 6px 10px; min-height: 36px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .55; cursor: progress; }

.notice { border-radius: 8px; padding: 10px 14px; margin: 0 0 14px; font-size: 14px; }
.notice.info { background: var(--accent-soft); }
.notice.warn { background: var(--wait-soft); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.choose { background: #fff; border: 2px solid var(--accent); font-weight: 600; font-size: 15px; }

.loading { display: flex; align-items: center; gap: 12px; padding: 18px; }
.spin { width: 22px; height: 22px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; flex: 0 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 結果の1枚 */
.sheet-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.sheet-head .addr { font-size: 19px; font-weight: 700; line-height: 1.4; }
.sheet-head .meta { font-size: 13px; color: var(--muted); }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pubgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border-top: 1px solid var(--line); border-left: 1px solid var(--line); margin-top: 14px; }
.pubcell { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 10px 12px; min-width: 0; }
/* 最後の行が1つだけのときは、その行の幅いっぱいに広げる */
.pubcell:last-child:nth-child(3n+1) { grid-column: span 3; }
.pubcell:last-child:nth-child(3n+2) { grid-column: span 2; }
.pubcell .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.pubcell .v { font-size: 16px; font-weight: 700; line-height: 1.45; margin: 2px 0 4px; }
.pubcell .v.failed { color: var(--muted); font-weight: 600; }
.pubcell .note { font-size: 12px; color: var(--muted); line-height: 1.55; }
.pubcell .src { font-size: 11px; color: #7b8087; margin-top: 4px; line-height: 1.5; }
.mapbox { position: relative; width: 300px; max-width: 100%; height: 170px; overflow: hidden; border-radius: 8px; border: 1px solid var(--line); background: #e9e7e1; flex: 0 0 auto; }
.mapbox .tiles { position: absolute; width: 768px; height: 768px; }
.mapbox .tiles img { position: absolute; width: 256px; height: 256px; }
.mapbox .pin { position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; background: #c0392b; border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.mapbox .attr { position: absolute; right: 0; bottom: 0; font-size: 10px; background: rgba(255,255,255,.85); padding: 0 4px; color: #444; }
.sub { margin-top: 14px; }
table.plain { width: 100%; border-collapse: collapse; font-size: 13px; }
table.plain th, table.plain td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.plain th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.tablewrap { overflow-x: auto; }

.calc { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.calc .box { background: #faf9f6; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.calc .box .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.calc .box .v { font-size: 16px; font-weight: 700; }
.calc .box .how { font-size: 12px; color: var(--muted); line-height: 1.5; }
.inputs-list { font-size: 13px; color: var(--muted); margin: 0 0 12px; }

.group { margin-top: 18px; }
.group-title { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.count { font-size: 13px; color: var(--muted); font-weight: 400; }
.cands { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.cand { border: 1px solid var(--line); border-left: 5px solid var(--ok); border-radius: 8px; padding: 12px 14px; background: #fff; min-width: 0; }
.cand.pending { border-left-color: #d49a2a; }
.cand-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.cand-head .id { font-size: 12px; color: var(--muted); }
.chip { display: inline-block; font-size: 11px; font-weight: 600; border-radius: 4px; padding: 0 6px; background: var(--accent-soft); color: var(--accent); }
.cand h3, .cand-head h3 { width: 100%; font-size: 16px; margin-top: 2px; }
.reasons { margin: 6px 0 8px; padding: 0; list-style: none; font-size: 13px; }
.reasons li { padding: 3px 0 3px 22px; position: relative; line-height: 1.55; }
.reasons li::before { position: absolute; left: 2px; top: 3px; font-weight: 700; }
.reasons li.t::before { content: "○"; color: var(--ok); }
.reasons li.u::before { content: "？"; color: var(--wait); }
.reasons li.f::before { content: "×"; color: var(--no); }
.reasons .val { color: var(--muted); }
.kv { font-size: 13px; margin-top: 6px; }
.kv b { display: block; font-size: 12px; color: var(--muted); }
.check { background: var(--human-soft); border-radius: 6px; padding: 6px 10px; margin-top: 8px; font-size: 13px; }
.check b { color: var(--human); display: block; font-size: 12px; }
.need { background: var(--wait-soft); border-radius: 6px; padding: 6px 10px; margin-top: 6px; font-size: 13px; }
details.fold { border: 1px solid var(--line); border-radius: 8px; background: #fff; margin-top: 10px; }
details.fold > summary { cursor: pointer; padding: 10px 14px; font-weight: 600; }
details.fold .inner { padding: 0 14px 12px; }
.mini { list-style: none; margin: 0; padding: 0; }
.mini li { border-top: 1px solid var(--line); padding: 8px 0; font-size: 13px; }
.mini li:first-child { border-top: 0; }
.mini .nm { font-weight: 600; font-size: 14px; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }

/* 一覧 */
.list-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
table.kiri { width: 100%; border-collapse: collapse; background: #fff; font-size: 13px; }
table.kiri th, table.kiri td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
table.kiri th { background: #faf9f6; color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
table.kiri td.nm { font-weight: 600; font-size: 14px; min-width: 160px; }
table.kiri td.id, table.kiri td.th { white-space: nowrap; }
table.kiri td.cond { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; min-width: 220px; }
table.kiri td.ops { white-space: nowrap; }
table.kiri tr.flash td { background: #fff7d6; transition: background 1.2s; }
.st { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 4px; padding: 1px 7px; white-space: nowrap; }
.st.match { background: var(--ok-soft); color: var(--ok); }
.st.pending { background: var(--wait-soft); color: var(--wait); }
.st.human { background: var(--human-soft); color: var(--human); }
.st.no { background: var(--no-soft); color: var(--no); }
.st.invalid { background: var(--bad-soft); color: var(--bad); }
.rowcards { display: none; }
.rowcard { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.rowcard .cond { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #faf9f6; border-radius: 6px; padding: 6px 8px; margin: 6px 0; }
.rowcard .ops { display: flex; gap: 8px; margin-top: 8px; }

/* 書き換えの窓 */
dialog.editor { border: 0; border-radius: 12px; padding: 0; width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog.editor::backdrop { background: rgba(20, 24, 28, .45); }
.ed-head { padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
.ed-body { padding: 14px 18px; }
.ed-body .field { margin-bottom: 12px; }
.ed-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; position: sticky; bottom: 0; background: #fff; }
.builder { background: #faf9f6; border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-top: 8px; }
.builder .bgrid { display: grid; grid-template-columns: 1.3fr 1fr 1.3fr auto; gap: 8px; align-items: end; }
.parsed { font-size: 13px; margin-top: 6px; }
.parsed.ok { color: var(--ok); }
.parsed.bad { color: var(--bad); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #1f2328; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 50; max-width: calc(100vw - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.25); }

/* 出典の表示 */
.credit { font-size: 12px; color: var(--muted); padding-top: 10px; padding-bottom: 40px; line-height: 1.7; }
.credit .box { border-top: 1px solid var(--line); padding-top: 12px; }
.credit p { margin: 0 0 6px; }
.credit .maker-line { margin-top: 10px; text-align: right; }

/* 合言葉の画面 */
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 420px; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.login-card form { margin-top: 12px; display: grid; gap: 10px; }
.login-card .maker { margin-top: 14px; text-align: right; }

@media (max-width: 900px) {
  .pubgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pubcell:last-child:nth-child(3n+1), .pubcell:last-child:nth-child(3n+2) { grid-column: auto; }
  .pubcell:last-child:nth-child(2n+1) { grid-column: span 2; }
  .calc { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cands { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .wrap { padding: 0 14px; }
  .top-inner { padding: 8px 14px 0; }
  .title { font-size: 14px; white-space: nowrap; }
  .brand { align-items: center; }
  .maker { font-size: 10px; }
  .tabs a { padding: 7px 8px; font-size: 13px; }
  .tabs a .n { margin-right: 4px; width: 18px; height: 18px; line-height: 18px; }
  h1 { font-size: 19px; }
  .card { padding: 14px; }
  .pubgrid { grid-template-columns: minmax(0, 1fr); }
  .pubcell:last-child:nth-child(n) { grid-column: auto; }
  .calc { grid-template-columns: minmax(0, 1fr); }
  .mapbox { width: 100%; height: 150px; }
  .sheet-head .addr { font-size: 17px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  table.kiri { display: none; }
  .rowcards { display: block; }
  .builder .bgrid { grid-template-columns: minmax(0, 1fr); }
  .sheet-actions .btn { flex: 1 1 auto; }
}
@media print {
  .top, .sheet-actions, .noprint, .toast { display: none !important; }
  body { background: #fff; }
  .card { border: 0; padding: 0; }
}
