:root {
  --ink: #1f2933;
  --muted: #52606d;
  --line: #d9dee3;
  --paper: #ffffff;
  --accent: #2b6cb0;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  font-family: system-ui, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.6;
}

a {
  color: var(--accent);
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}

header h1 {
  margin: 0;
  font-size: 1.1rem;
}

header h1 a {
  color: inherit;
  text-decoration: none;
}

footer {
  padding: 4px 16px;
  border-top: 1px solid var(--line);
  font-size: 0.75rem;
  color: var(--muted);
}

footer p {
  margin: 4px 0;
  overflow-wrap: anywhere;
}

.maplibregl-popup-content {
  font-size: 0.875rem;
}

.maplibregl-popup-content code {
  color: var(--muted);
}

/* 地点の詳細ページ */
.detail {
  max-width: 48rem;
  margin: 0 auto;
  padding: 16px;
}

.detail hgroup h2 {
  margin: 0;
  font-size: 1.5rem;
}

.detail hgroup p {
  margin: 0;
  color: var(--muted);
}

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
}

.facts dt {
  color: var(--muted);
}

.facts dt + dd ~ dd {
  grid-column: 2;
}

.facts dd {
  margin: 0;
}

.facts dd a {
  margin-left: 8px;
}

/* 広告である旨の表示。商品の並びのすぐ下に出す */
.ad-notice {
  margin: 8px 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.detail h3 {
  margin: 24px 0 8px;
  font-size: 1.1rem;
}

.markup {
  overflow-wrap: anywhere;
}

.works,
.references {
  padding-left: 1.25rem;
}

.works .certainty,
.works .captions {
  margin-left: 8px;
  font-size: 0.875rem;
  color: var(--muted);
}

.references a {
  overflow-wrap: anywhere;
}

/* 作品のページ: 見出しの階層は字下げで表す。番号は階層をまたいで通しになるので付けない */
.caption-list {
  padding-left: 0;
  list-style: none;
}

.caption-list .depth-1 {
  margin-left: 1.25rem;
}

.caption-list .depth-2 {
  margin-left: 2.5rem;
}

.caption-list .caption-remarks {
  font-size: 0.875rem;
  color: var(--muted);
}

.sites {
  margin: 0 0 8px;
  padding-left: 1.25rem;
}

.sites .certainty,
.identifier,
.series-works .volume {
  margin-left: 8px;
  font-size: 0.875rem;
  color: var(--muted);
}

.series-works .volume {
  margin: 0 8px 0 0;
}

/* シリーズのページ: 巻の数を前に出すので、並びの印は付けない */
.series-works {
  padding-left: 0;
  list-style: none;
}

/* 帯の検索欄。帯の右に寄せ、狭い画面では次の行に回る */
header .search {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

header .search input {
  width: 14rem;
  max-width: 60vw;
  padding: 4px 8px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 4px;
}

header .search button {
  padding: 4px 12px;
  font: inherit;
  color: var(--paper);
  background: var(--accent);
  border: 0;
  border-radius: 4px;
}

/* 入稿と、ログインしている編集者・ログアウト。検索欄の右に並べる */
header .editor {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--muted);
}

header .editor form {
  margin: 0;
}

header .editor button {
  padding: 2px 8px;
  font: inherit;
  color: var(--accent);
  background: none;
  border: 1px solid var(--line);
  border-radius: 4px;
}

/* 検索のページ */
.hits {
  padding-left: 1.25rem;
}

.hits .kana,
.hits .district,
.note {
  margin-left: 8px;
  font-size: 0.875rem;
  color: var(--muted);
}

.note {
  margin-left: 0;
}

/* 入稿の画面 */
.error {
  padding: 8px 12px;
  color: #9b1c1c;
  background: #fdecec;
  border: 1px solid #f5c2c2;
  border-radius: 4px;
}

.code .export,
.code .position {
  margin-left: 8px;
  font-size: 0.875rem;
}

.manuscript-form {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin: 8px 0;
}

.manuscript-form input[type="text"],
.manuscript-form input[type="url"] {
  padding: 4px 8px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.manuscript-form button {
  padding: 4px 12px;
  font: inherit;
  color: var(--paper);
  background: var(--accent);
  border: 0;
  border-radius: 4px;
}

.plan-counts,
.plan-diagnostics {
  border-collapse: collapse;
  font-size: 0.875rem;
}

.plan-counts th,
.plan-counts td,
.plan-diagnostics th,
.plan-diagnostics td {
  padding: 2px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.plan-counts td,
.plan-diagnostics td:first-child {
  text-align: right;
}

.plan-diagnostics tr.error td,
.plan-diagnostics tr.fatal td {
  color: #9b1c1c;
}

.plan-changes {
  padding-left: 0;
  list-style: none;
  font-size: 0.875rem;
}

.plan-changes .mark {
  display: inline-block;
  width: 1.25rem;
  font-family: ui-monospace, monospace;
  color: var(--muted);
}

.plan-changes .delete {
  color: #9b1c1c;
}

/* 地点の位置の画面（#121） */
.position-map {
  height: 480px;
  margin: 16px 0;
  border: 1px solid var(--line);
}

.position-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 8px 0;
}

/* 形の画面の道具（#122）。押しているものを塗る */
.shape-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 0;
}

.shape-tools button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--paper);
}

/* 位置の根拠の長い URL を折り返す（#124） */
.position-source dd {
  min-width: 0;
  overflow-wrap: anywhere;
}

.position-source dd a {
  margin-left: 0;
}

.position-source-form label {
  flex: 1 1 24rem;
  display: flex;
  gap: 8px;
}

.position-source-form input[type="url"] {
  flex: 1;
  min-width: 0;
}

.done {
  padding: 8px 12px;
  color: #1c5e2e;
  background: #e9f7ee;
  border: 1px solid #b8e2c6;
  border-radius: 4px;
}

.notices {
  padding-left: 1.25rem;
}

.notices code {
  margin-left: 8px;
  color: var(--muted);
}

/* 問い合わせのフォーム（#120）。罠の欄は人に見せない（display: none だと機械も読み飛ばすので、画面の外へ出す） */
.contact-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 40rem;
}

.contact-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.contact-form .trap {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.contact-form button {
  align-self: flex-start;
}

/* 問い合わせの一覧。本文の改行をそのまま出す */
.inquiry-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* 公開文書（#120）の表。セルを上で揃え、罫線で区切る */
.policy table {
  border-collapse: collapse;
  margin: 8px 0;
}

.policy th,
.policy td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

/*
 * 閲覧の地図（#155・#158）。全画面の地図に、検索の帯とパネルを重ねる。見た目は地図帳の趣で、管理画面に広げないよう body.shell の下に閉じる。
 * 朱は地点と現況の印にだけ使い、リンクは藍にする。色を変えるときは map.js の COLORS も直す
 */
body.shell {
  --ink: #2b2a26;
  --muted: #68665d;
  --line: #d9d4bf;
  --paper: #f5f2e4;
  --accent: #274c77;
  --shu: #c2331f;
  --usuzumi: #8a8880;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", serif;
  --panel-width: min(400px, calc(100vw - 16px));
  position: relative;
  height: 100dvh;
  overflow: hidden;
  font-family: "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif;
}

body.shell :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body.shell #map {
  position: absolute;
  inset: 0;
}

/* 左の 1 枚の紙。検索の帯とパネルがつながる */
.shell-side {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 8px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  width: var(--panel-width);
  pointer-events: none;
  filter: drop-shadow(0 1px 3px rgb(43 42 38 / 25%));
}

body.shell .shell-bar {
  flex: none;
  padding: 8px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  pointer-events: auto;
}

body.shell .shell-bar h1 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: 0.04em;
}

body.shell .shell-bar .search {
  flex: 1;
  margin-left: 0;
}

body.shell .shell-bar .search input {
  flex: 1;
  width: auto;
  min-width: 0;
  background: transparent;
  border-width: 0 0 1px;
  border-radius: 0;
}

body.shell .shell-bar .search button {
  border-radius: 2px;
}

#view-list {
  padding: 0;
  font: inherit;
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: underline;
  background: none;
  border: 0;
  cursor: pointer;
}

#status {
  flex: 1;
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

/* 右上の拡大・縮小の操作を避ける */
.shell-editor {
  position: absolute;
  top: 8px;
  right: 56px;
  z-index: 3;
  max-width: calc(100vw - var(--panel-width) - 80px);
  padding: 4px 8px;
  font-size: 0.875rem;
  background: var(--paper);
  border: 1px solid var(--line);
}

.shell-editor .editor {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  color: var(--muted);
}

.shell-editor form {
  margin: 0;
}

.panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-top: 0;
  pointer-events: auto;
}

.panel[hidden] {
  display: none;
}

.panel-bar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
}

.panel-bar button {
  min-width: 32px;
  min-height: 32px;
  font: inherit;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}

.panel-bar button:hover {
  color: var(--ink);
}

.panel-bar button[hidden] {
  display: none;
}

#panel-close {
  margin-left: auto;
}

/* 持ち手は狭い画面でだけ使う */
#panel-handle {
  display: none;
}

#panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* パネルの中身 */
.panel-page {
  max-width: none;
  margin: 0;
  padding: 0 20px 24px;
  font-size: 0.9375rem;
}

.panel-page h2:focus {
  outline: none;
}

.panel-page h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.35;
}

.panel-page h3 {
  margin: 24px 0 8px;
  padding-bottom: 2px;
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}

.panel-page h4 {
  margin: 16px 0 4px;
  font-size: 0.875rem;
}

.panel-page .note,
.panel-page .empty {
  font-size: 0.875rem;
  color: var(--muted);
}

/* 判子。一番目立たせるのはここだけで、ほかは罫線と余白で静かに置く */
.panel-head {
  position: relative;
  display: block;
  min-height: 3rem;
  padding: 0;
  border: 0;
}

.panel-head h2,
.panel-head .kana,
.panel-head .place {
  padding-right: 4rem;
}

.panel-head:not(:has(.stamp)) h2,
.panel-head:not(:has(.stamp)) .kana,
.panel-head:not(:has(.stamp)) .place {
  padding-right: 0;
}

.panel-head .kana {
  margin: 2px 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.panel-head .place {
  margin: 2px 0 0;
  font-size: 0.875rem;
}

.stamp {
  display: inline-block;
  padding: 0 4px;
  font-family: var(--serif);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--shu);
  border: 1px solid currentColor;
  border-radius: 2px;
}

.panel-head > .stamp {
  position: absolute;
  top: 2px;
  right: 0;
  padding: 2px 8px;
  font-size: 1rem;
  letter-spacing: 0.1em;
  border-width: 2px;
  border-radius: 3px;
  transform: rotate(-5deg);
}

.stamp-card {
  flex: none;
  transform: rotate(-3deg);
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 12px 0 0;
  padding: 0;
  font-size: 0.8125rem;
  list-style: none;
}

.panel-actions button {
  padding: 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  background: none;
  border: 0;
  cursor: pointer;
}

.panel-page .works,
.panel-page .hits,
.panel-page .series-works,
.panel-page .products {
  margin: 0;
  padding: 0;
  list-style: none;
}

.panel-page .works li,
.panel-page .hits li,
.panel-page .series-works li,
.panel-page .products li {
  padding: 6px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent);
}

.panel-page .works li:last-child,
.panel-page .hits li:last-child,
.panel-page .series-works li:last-child,
.panel-page .products li:last-child {
  border-bottom: 0;
}

.panel-page .works .work-name {
  font-weight: 600;
}

.panel-page .works .captions {
  display: block;
  margin-left: 0;
  font-size: 0.8125rem;
}

.panel-page .works .certainty {
  margin-left: 0;
}

.panel-page .hits .kana,
.panel-page .hits .district {
  display: block;
  margin-left: 0;
  font-size: 0.75rem;
}

/* 見出しの目次。最上位ごとに畳む */
.chapter {
  border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent);
}

.chapter summary {
  display: list-item;
  padding: 4px 0;
  cursor: pointer;
}

.chapter summary .caption-name {
  font-weight: 600;
}

.chapter-count {
  margin-left: 8px;
  white-space: nowrap;
  font-size: 0.75rem;
  color: var(--muted);
}

.panel-page .caption-list {
  margin: 0 0 4px;
}

.panel-page .caption-list .depth-1 {
  margin-left: 1rem;
}

.panel-page .caption-list .depth-2 {
  margin-left: 2rem;
}

.panel-page .sites {
  margin: 0 0 4px;
  padding-left: 1rem;
  font-size: 0.875rem;
  list-style: "・";
}

.panel-page .sites li::marker {
  color: var(--shu);
}

.panel-page .sites .stamp {
  margin-left: 4px;
}

.panel-page .identifier {
  font-size: 0.8125rem;
}

/* 公開文書の表は幅が足りないので、中で折り返す */
.panel-page.policy table {
  font-size: 0.8125rem;
}

.panel-page.policy td {
  overflow-wrap: anywhere;
}

.panel-page .contact-form select,
.panel-page .contact-form textarea {
  font: inherit;
  background: #fbf9f0;
  border: 1px solid var(--line);
}

/* 記録は奥付のように小さく */
.panel-notes {
  font-size: 0.8125rem;
  color: var(--muted);
}

.panel-notes .facts {
  margin: 0;
}

.panel-notes .facts dd a {
  margin-left: 0;
}

.panel-notes .references {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
}

.panel-notes .code {
  font-size: 0.75rem;
}

.panel-notes .export {
  margin-left: 8px;
}

/* 右下の凡例と出典 */
.map-notes {
  position: absolute;
  right: 8px;
  bottom: 28px;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  max-width: min(32rem, calc(100vw - 16px));
}

.map-legend {
  margin: 0;
  padding: 2px 8px;
  font-size: 0.6875rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
}

.pin-mark {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin: 0 4px 0 2px;
  background: var(--shu);
  border-radius: 50%;
}

.pin-mark-changed {
  margin-left: 8px;
  background: var(--usuzumi);
}

.attribution {
  max-height: 50dvh;
  padding: 2px 8px;
  overflow-y: auto;
  font-size: 0.6875rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
}

.attribution summary {
  cursor: pointer;
}

.attribution p {
  margin: 4px 0;
  overflow-wrap: anywhere;
}

/* ピンのカード（#157） */
body.shell .hover-card .maplibregl-popup-content {
  padding: 10px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0;
  box-shadow: 0 1px 4px rgb(43 42 38 / 30%);
}

body.shell .hover-card.maplibregl-popup-anchor-bottom .maplibregl-popup-tip {
  border-top-color: var(--paper);
}

body.shell .hover-card.maplibregl-popup-anchor-top .maplibregl-popup-tip {
  border-bottom-color: var(--paper);
}

body.shell .hover-card.maplibregl-popup-anchor-left .maplibregl-popup-tip {
  border-right-color: var(--paper);
}

body.shell .hover-card.maplibregl-popup-anchor-right .maplibregl-popup-tip {
  border-left-color: var(--paper);
}

.card {
  display: block;
  width: 100%;
  padding: 0;
  font: inherit;
  color: var(--ink);
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-name {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.card-sub {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.card-works {
  display: block;
  margin-top: 6px;
  padding-top: 6px;
  font-size: 0.8125rem;
  border-top: 1px solid var(--line);
}

.card-work {
  display: block;
  padding-left: 0.75rem;
  overflow-wrap: anywhere;
}

.card-excerpt {
  display: block;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.card-action {
  display: block;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--accent);
  text-align: right;
}

.card-choices {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.card-choices button {
  display: block;
  width: 100%;
  padding: 3px 0;
  font: inherit;
  font-size: 0.8125rem;
  color: var(--accent);
  text-align: left;
  background: none;
  border: 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

/* パネルを開いたとわかるように、短く滑らせる */
@media (prefers-reduced-motion: no-preference) {
  .panel:not([hidden]) {
    animation: panel-open 160ms ease-out;
  }

  @keyframes panel-open {
    from {
      opacity: 0;
      transform: translateY(-6px);
    }
  }
}

/* 狭い画面: パネルは下からのシート。検索の帯は上に残す */
@media (max-width: 767px) {
  .shell-side {
    bottom: auto;
  }

  .shell-editor {
    top: auto;
    right: auto;
    bottom: 28px;
    left: 8px;
    max-width: calc(100vw - 16px);
  }

  .panel {
    --sheet-height: 55dvh;
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 4;
    height: var(--sheet-height);
    border-width: 1px 0 0;
    border-radius: 8px 8px 0 0;
  }

  .panel-page {
    padding: 0 16px 16px;
  }

  #panel-handle {
    display: block;
    flex: 1;
    align-self: stretch;
    touch-action: none;
    cursor: grab;
  }

  #panel-handle::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    margin: 0 auto;
    background: var(--line);
    border-radius: 2px;
  }

  #panel-close {
    margin-left: 0;
  }
}

/* filter の中では fixed が効かないので、狭い画面では影を外す */
@media (max-width: 767px) {
  .shell-side {
    z-index: 4;
    filter: none;
  }
}

/* Font Awesome のアイコン（#167）。色は文字に合わせ、幅の違う字形も 1em の枠の中央に置く */
.icon {
  display: inline-block;
  flex: none;
  width: 1em;
  height: 1em;
  margin-right: 0.35em;
  vertical-align: -0.125em;
  fill: currentColor;
}

/* 文字の無いボタンと、文字の後ろに置く矢印 */
#panel-back .icon,
#panel-close .icon {
  margin-right: 0;
}

.card-action .icon {
  margin: 0 0 0 0.25em;
}

/* 編集者だけが見るタグ（#171） */
.tag-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  margin: 12px 0;
}
.tag-form input[type="text"],
.tag-form select {
  max-width: 100%;
}
.tag-table {
  border-collapse: collapse;
}
.tag-table th,
.tag-table td {
  padding: 4px 16px 4px 0;
  text-align: left;
}
.tag-table .count {
  text-align: right;
}
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 0;
  list-style: none;
}
.tagged {
  padding: 0;
  list-style: none;
}
.tagged li {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: center;
  margin: 4px 0;
}
.tag-remove {
  display: inline;
}
