:root {
  --green: #1d6b45;
  --green-dark: #14512f;
  --green-pale: #e8f3ec;
  --ink: #22302a;
  --muted: #6b7a72;
  --line: #dce6e0;
  --bg: #f6f8f6;
  --card: #ffffff;
  --accent: #c98a2d;
  --danger: #b04a3a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}
.container { max-width: 1080px; margin: 0 auto; padding: 0 16px; }

.site-header {
  background:
    linear-gradient(90deg, rgba(246,248,246,.82) 0%, rgba(246,248,246,.35) 38%, rgba(246,248,246,0) 60%),
    url('assets/header.webp') right center / cover no-repeat,
    linear-gradient(135deg, #eef5ee, #dcebdf);
  color: var(--green-dark);
  padding: 44px 0 30px;
  border-bottom: 1px solid var(--line);
}
.logo {
  margin: 0; font-size: 2.1rem; letter-spacing: .06em; font-weight: 800;
  text-shadow: 0 1px 0 rgba(255,255,255,.8);
}
.tagline { margin: 8px 0 0; font-size: .92rem; color: #3c5a48; text-shadow: 0 1px 0 rgba(255,255,255,.7); }
.stats { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
.stat-chip {
  background: rgba(255,255,255,.75);
  border: 1px solid rgba(29,107,69,.3);
  border-radius: 999px;
  padding: 3px 14px;
  font-size: .82rem;
  color: var(--green-dark);
}
.stat-chip b { font-size: 1rem; }
@media (max-width: 760px) {
  .site-header {
    background:
      linear-gradient(90deg, rgba(246,248,246,.88) 0%, rgba(246,248,246,.5) 55%, rgba(246,248,246,.12) 100%),
      url('assets/header.webp') 72% center / cover no-repeat,
      linear-gradient(135deg, #eef5ee, #dcebdf);
    padding: 30px 0 22px;
  }
  .logo { font-size: 1.6rem; }
}

.controls { margin: 20px 0 12px; display: flex; flex-direction: column; gap: 10px; }
#q {
  width: 100%;
  padding: 11px 16px;
  font-size: 1rem;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
#q:focus { outline: 2px solid var(--green); border-color: transparent; }
.selects { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.selects select {
  padding: 7px 10px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: .85rem;
  color: var(--ink);
  max-width: 220px;
}
.checkbox { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 4px; }

.horse-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.loading { text-align: center; color: var(--muted); padding: 48px 0; }
.empty { text-align: center; color: var(--muted); padding: 48px 0; }

.horse-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 18px;
  cursor: pointer;
  transition: box-shadow .15s, transform .15s;
  display: grid;
  grid-template-columns: minmax(180px, 1.1fr) minmax(160px, 1fr) minmax(150px, .9fr) minmax(200px, 1.3fr);
  gap: 6px 18px;
  align-items: center;
}
.horse-card:hover { box-shadow: 0 4px 16px rgba(20,81,47,.12); transform: translateY(-1px); }
.horse-card.retired { opacity: .6; }

.h-name { font-weight: 700; font-size: 1.05rem; }
.h-name .badges { margin-left: 6px; }
.badge {
  display: inline-block;
  font-size: .68rem;
  padding: 1px 7px;
  border-radius: 999px;
  vertical-align: 2px;
  font-weight: 600;
}
.badge.sex-牡 { background: #e3edf8; color: #2a5b8f; }
.badge.sex-牝 { background: #fbe9ee; color: #a8455f; }
.badge.sex-セ { background: #eee9f8; color: #6a4f9e; }
.badge.unraced { background: #fdf3e0; color: #9a6b14; }
.badge.retired-badge { background: #f1e3e0; color: var(--danger); }
.badge.graduated-badge { background: #e2f3d9; color: #3a7a1e; }
.badge.coat { background: #efece5; color: #6e6354; }
.horse-card.graduated { background: #fbfff8; }

.races-table { width: 100%; border-collapse: collapse; font-size: .8rem; margin: 8px 0 20px; }
.races-table th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: .72rem;
  padding: 4px 6px; border-bottom: 1.5px solid var(--line);
}
.races-table td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.races-table small { color: var(--muted); }
.races-table .pos { font-weight: 700; white-space: nowrap; }
.races-table .pos.win { color: var(--accent); }
.h-sub { color: var(--muted); font-size: .78rem; }

.h-pedigree { font-size: .85rem; }
.h-pedigree .lbl { color: var(--muted); font-size: .72rem; margin-right: 3px; }

.h-stable { font-size: .85rem; }
.area-tag {
  display: inline-block; font-size: .7rem; font-weight: 700;
  padding: 1px 8px; border-radius: 4px; margin-right: 5px;
}
.area-美浦 { background: #e3f0fa; color: #1f6293; }
.area-栗東 { background: #f8efe0; color: #8a5d12; }

.h-latest { font-size: .82rem; min-width: 0; }
.kind {
  display: inline-block; font-size: .68rem; font-weight: 700;
  padding: 1px 8px; border-radius: 4px; margin-right: 6px;
}
.kind-race { background: var(--green-pale); color: var(--green); }
.kind-training { background: #e9f0fb; color: #355e9e; }
.kind-transport { background: #f3eafa; color: #74479e; }
.kind-twitter { background: #e8e8e8; color: #333; }
.kind-news { background: #fdf0e3; color: #a06515; }
.kind-stable_comment { background: #f0f5e6; color: #5d7a23; }
.h-latest .title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-latest .date { color: var(--muted); font-size: .72rem; }
.h-record { font-size: .8rem; color: var(--muted); }

.pager { display: flex; gap: 8px; justify-content: center; margin: 8px 0 32px; }
.pager button {
  padding: 7px 18px; border: 1.5px solid var(--line); background: var(--card);
  border-radius: 8px; cursor: pointer; font-size: .85rem;
}
.pager button:disabled { opacity: .4; cursor: default; }
.pager .page-info { align-self: center; color: var(--muted); font-size: .85rem; }

/* 詳細モーダル（背後に一覧が見える。外側タップで閉じる） */
.drawer {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 30, 25, .5);
  overflow-y: auto;
  padding: 36px 16px 64px;
  cursor: pointer;
}
.drawer-inner {
  max-width: 860px; margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 26px 30px 36px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, .3);
  cursor: auto;
}
.drawer .close-btn {
  position: fixed; top: 14px; right: 18px; z-index: 51;
  border: 1px solid var(--line); background: var(--card);
  width: 40px; height: 40px; border-radius: 50%;
  font-size: 1.2rem; cursor: pointer; color: var(--muted);
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
}
.chart-wrap { margin: 18px 0 6px; }
.chart-wrap h3 { font-size: 1rem; border-bottom: 2px solid var(--green); padding-bottom: 6px; }
.chart-panel { margin: 10px 0 2px; }
.chart-panel .panel-label { font-size: .78rem; font-weight: 700; color: var(--green-dark); }
.chart-panel svg { width: 100%; height: auto; display: block; }
.drawer h2 { margin: 4px 0 2px; font-size: 1.5rem; }
.drawer .kana { color: var(--muted); font-size: .8rem; }
.profile-table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: .88rem; }
.profile-table th {
  text-align: left; color: var(--muted); font-weight: 600;
  padding: 6px 10px 6px 0; width: 6.5em; vertical-align: top; font-size: .8rem;
}
.profile-table td { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.ext-links { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 4px; }
.ext-links a {
  font-size: .8rem; text-decoration: none; color: var(--green);
  border: 1.5px solid var(--green); border-radius: 999px; padding: 4px 14px;
}
.ext-links a:hover { background: var(--green-pale); }
.timeline { margin-top: 18px; }
.timeline h3 { font-size: 1rem; border-bottom: 2px solid var(--green); padding-bottom: 6px; }
.tl-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.tl-item .tl-head { display: flex; align-items: center; gap: 8px; }
.tl-item .tl-date { color: var(--muted); font-size: .75rem; }
.tl-item .tl-title { font-weight: 600; font-size: .9rem; margin: 2px 0; }
.tl-item .tl-body { font-size: .83rem; color: #41504a; }
.tl-item .tl-src { font-size: .72rem; color: var(--muted); }
.tl-item .tl-src a { color: var(--green); }

.note-box {
  background: var(--green-pale); border-radius: 8px; padding: 8px 14px;
  font-size: .83rem; margin-top: 10px;
}

.site-footer {
  border-top: 1px solid var(--line);
  padding: 20px 0 28px; color: var(--muted); font-size: .76rem;
  background: #eef2ef;
}
.site-footer p { margin: 2px 0; }

@media (max-width: 760px) {
  .horse-card { grid-template-columns: 1fr 1fr; }
  .h-latest { grid-column: 1 / -1; }
}
@media (max-width: 480px) {
  .horse-card { grid-template-columns: 1fr; }
}
