:root {
  --bg: #f6f7f5;
  --card: #ffffff;
  --text: #1f2a24;
  --muted: #66736b;
  --line: #e2e6e3;
  --accent: #2f855a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #3d4044;
    --card: #4a4e53;
    --text: #eceeef;
    --muted: #b9bec3;
    --line: #5d6268;
    --accent: #5fbf8a;
  }
}

* { box-sizing: border-box; }

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

.header {
  max-width: 960px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px 8px;
}
.header h1 { margin: 0; font-size: 1.25rem; }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 8px 16px calc(32px + env(safe-area-inset-bottom));
}

/* ---- カード一覧 ---- */
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.grid > li { display: flex; }

.card {
  /* ボタンは中身を上下中央に寄せるため、縦並び・上詰めにしてイラストの位置をそろえる */
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  flex: 1;
  width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: inherit;
  font: inherit;
  text-align: left;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s;
}
.card:active { transform: scale(0.97); }

.card-img,
.detail-img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--line);
}
.card-img.is-empty,
.detail-img.is-empty {
  display: grid;
  place-items: center;
  font-size: 3rem;
}

.card-text { padding: 10px 12px 12px; }
.card-name { font-weight: 700; line-height: 1.4; }
.meta-part { white-space: nowrap; }
.card-meta { margin-top: 2px; color: var(--muted); font-size: 0.8rem; }

.empty { grid-column: 1 / -1; padding: 32px 0; text-align: center; color: var(--muted); }

/* ---- 詳細 ---- */
/* 開いている間は裏側のページを動かさない */
.is-locked,
.is-locked body { overflow: hidden; }

.detail {
  width: min(560px, calc(100% - 32px));
  max-height: calc(100% - 48px);
  max-height: calc(100dvh - 48px);
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 20px;
  background: var(--card);
  color: var(--text);
}
.detail[open] { display: flex; flex-direction: column; }
.detail::backdrop { background: rgb(0 0 0 / 0.5); }
.detail-img { aspect-ratio: 16 / 10; }
.detail form { flex: none; background: var(--card); }

/* スクロールするのは詳細の中身だけ。端まで来ても裏側のページに伝えない */
.dialog-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  outline: none;
}
.detail-content { padding: 16px 20px 0; }
.detail-content h2 { margin: 0; font-size: 1.2rem; }
.detail-content h3 { margin: 16px 0 4px; font-size: 0.85rem; color: var(--muted); }
.detail-content ul,
.detail-content ol { margin: 0; padding-left: 1.3em; }
.detail-content p { margin: 0; }
.sub {
  margin-top: 16px;
  padding: 4px 14px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.detail-content .sub-title { margin-top: 8px; color: var(--accent); font-size: 0.95rem; }
.sub h4 { margin: 10px 0 2px; font-size: 0.8rem; color: var(--muted); }
.sub-note { margin-top: 8px !important; color: var(--muted); font-size: 0.85rem; }
.detail-note { margin-top: 4px !important; color: var(--muted); font-size: 0.8rem; }
.detail-meta { margin-top: 2px; color: var(--muted); font-size: 0.85rem; }

.close-btn {
  display: block;
  width: calc(100% - 40px);
  margin: 16px 20px;
  padding: 12px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
}

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