:root {
  --paper: #fbfaf7;
  --white: #ffffff;
  --ink: #20242b;
  --ink-soft: #5a6069;
  --line: #d9d6ce;
  --line-dark: #b9b5aa;
  --ai: #29527a;        /* 藍 = メイン */
  --ai-soft: #eef3f8;
  --shu: #c3502b;       /* 朱 = 強調（最小限） */
  --g3: #2f7a54;
  --g4: #29527a;
  --g5: #8a5a2a;
  --g6: #7a3548;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.8;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }
a { color: var(--ai); }
h1, h2, h3, p, dl, dd, figure { margin: 0; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); border: 0;
}

.inner {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
}

/* ===== ヘッダー：辞典の扉 ===== */
.site-header {
  background: var(--white);
  border-bottom: 1px solid var(--line-dark);
}
.header-inner {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 40px 0 34px;
}
.brand-line {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}
.brand-line .edition {
  border: 1px solid var(--line-dark);
  padding: 1px 10px;
  letter-spacing: 0.1em;
}
.site-header h1 {
  margin: 10px 0 6px;
  font-size: clamp(1.9rem, 5vw, 3rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.2;
}
.site-header h1 .accent {
  color: var(--ai);
}
.lead {
  font-size: 0.98rem;
  color: var(--ink-soft);
}
.lead strong {
  color: var(--ink);
  font-weight: 600;
}

/* ===== 検索帯 ===== */
.search-band {
  background: var(--white);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.search-inner {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 14px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
}
.search-box {
  flex: 1 1 300px;
  display: flex;
}
.search-box input {
  width: 100%;
  padding: 10px 16px;
  border: 1.5px solid var(--line-dark);
  border-radius: 4px;
  background: var(--paper);
}
.search-box input:focus {
  outline: 2px solid var(--ai);
  outline-offset: -1px;
}
.grade-chips {
  display: flex;
  gap: 6px;
}
.chip {
  padding: 7px 14px;
  border: 1px solid var(--line-dark);
  border-radius: 3px;
  background: var(--white);
  font-size: 0.9rem;
  line-height: 1;
}
.chip:hover { border-color: var(--ink); }
.chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--white);
  font-weight: 600;
}

/* ===== 本体レイアウト ===== */
.tool-layout {
  width: min(1120px, calc(100% - 40px));
  margin: 26px auto 60px;
  display: grid;
  grid-template-columns: 232px 1fr;
  gap: 34px;
  align-items: start;
}

/* --- フィルタ列 --- */
.filters-panel {
  display: grid;
  gap: 4px;
  position: sticky;
  top: 76px;
}
.panel-block {
  border-top: 1px solid var(--line-dark);
  padding: 2px 0 14px;
}
.panel-block summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 0 6px;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-block summary::-webkit-details-marker { display: none; }
.panel-block summary::after {
  content: "＋";
  color: var(--ink-soft);
  font-weight: 400;
}
.panel-block[open] summary::after { content: "−"; }
.kana-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}
.kana-grid .chip {
  padding: 7px 0;
  text-align: center;
}
.tag-list {
  display: grid;
  gap: 4px;
}
.tag-button {
  text-align: left;
  padding: 6px 8px;
  border-radius: 3px;
  font-size: 0.88rem;
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tag-button:hover { background: var(--ai-soft); }
.tag-button.active {
  background: var(--ink);
  color: var(--white);
  font-weight: 600;
}
.tag-button .swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex: none;
  background: var(--tag-color, var(--line-dark));
}
.unit-group-label {
  margin-top: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
}

/* --- 結果一覧 --- */
.results-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 8px;
  margin-bottom: 18px;
}
.results-head .count {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.results-head .count small {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-left: 2px;
}
.reset-button {
  font-size: 0.85rem;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.reset-button:hover { color: var(--shu); }

.term-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(228px, 1fr));
  gap: 14px;
}
.term-card {
  position: relative;
  text-align: left;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px 16px 12px 19px;
  display: grid;
  gap: 4px;
  align-content: start;
  transition: border-color 0.15s;
}
.term-card::before {
  content: "";
  position: absolute;
  inset: -1px auto -1px -1px;
  width: 4px;
  border-radius: 4px 0 0 4px;
  background: var(--grade-color, var(--line-dark));
}
.term-card:hover {
  border-color: var(--ink);
}
.term-card .term-name {
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.4;
}
.term-card .reading {
  font-size: 0.78rem;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}
.term-card .grade-label {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--grade-color, var(--ink-soft));
  letter-spacing: 0.06em;
}
.term-card .meaning {
  font-size: 0.86rem;
  color: var(--ink-soft);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.term-card .zukai-mark {
  justify-self: start;
  margin-top: 3px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ai);
  border: 1px solid currentColor;
  border-radius: 2px;
  padding: 0 6px;
  letter-spacing: 0.08em;
}
.show-more {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 13px 0;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--white);
  font-weight: 700;
  letter-spacing: 0.06em;
}
.show-more:hover {
  background: var(--ink);
  color: var(--white);
}
.empty-state {
  padding: 40px 0;
  color: var(--ink-soft);
  text-align: center;
}

/* ===== 用語ダイアログ ===== */
.term-dialog {
  width: min(720px, calc(100% - 32px));
  border: none;
  border-radius: 6px;
  padding: 0;
  background: var(--white);
  box-shadow: 0 24px 60px rgba(32, 36, 43, 0.25);
}
.term-dialog::backdrop {
  background: rgba(32, 36, 43, 0.45);
}
.dialog-body {
  padding: 30px 34px 26px;
  position: relative;
}
.close-button {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-dark);
  border-radius: 3px;
  background: var(--white);
  font-size: 1.1rem;
  line-height: 1;
  z-index: 2;
}
.close-button:hover { border-color: var(--ink); }
.dialog-meta {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--grade-color, var(--ink-soft));
  letter-spacing: 0.08em;
}
.dialog-title h2 {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.3;
  padding-right: 44px;
}
.dialog-title .reading {
  font-size: 0.9rem;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
}
.person-box {
  margin: 18px 0 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--white);
  text-align: center;
}
.person-box img {
  max-width: 100%;
  max-height: 300px;
  display: inline-block;
}
.person-box + .zukai-box {
  margin-top: 10px;
}
.zukai-box {
  margin: 18px 0 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--white);
  overflow: hidden;
}
.zukai-box svg {
  display: block;
  width: 100%;
  height: auto;
}
.zukai-box svg text {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", sans-serif;
}
.term-detail {
  display: grid;
  grid-template-columns: 6.6em 1fr;
  gap: 10px 16px;
  margin-top: 16px;
}
.term-detail dt {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.1em;
  padding-top: 3px;
  border-top: 1px solid var(--line);
}
.term-detail dd {
  font-size: 0.98rem;
  border-top: 1px solid var(--line);
  padding-top: 3px;
}
.en-text {
  font-family: Georgia, "Times New Roman", "Hiragino Sans", serif;
  color: var(--ink-soft);
  line-height: 1.6;
}
.en-text strong {
  color: var(--ink);
}
.related-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.related-buttons button {
  border: 1px solid var(--line-dark);
  border-radius: 3px;
  padding: 3px 10px;
  font-size: 0.86rem;
  background: var(--white);
}
.related-buttons button:hover {
  border-color: var(--ai);
  color: var(--ai);
}
.thinking-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.thinking-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--tag-color, var(--ink));
  border: 1px solid currentColor;
  border-radius: 2px;
  padding: 1px 8px;
}
.thinking-pill .swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: currentColor;
}
.dialog-foot {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--ink-soft);
}
.dialog-foot a {
  color: var(--ink-soft);
  text-underline-offset: 3px;
}
.dialog-foot a:hover { color: var(--shu); }

/* ===== 先生・おうちの方へ ===== */
.teacher-band {
  background: var(--white);
  border-top: 1px solid var(--line-dark);
}
.teacher-inner {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 36px 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 40px;
  align-items: baseline;
}
.teacher-band h2 {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  white-space: nowrap;
}
.teacher-band p {
  font-size: 0.88rem;
  color: var(--ink-soft);
}
.teacher-band .form-links {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.teacher-band .form-links a {
  font-size: 0.88rem;
  font-weight: 600;
  text-underline-offset: 3px;
}

/* ===== フッター ===== */
.site-footer {
  border-top: 1px solid var(--line-dark);
  background: var(--paper);
}
.site-footer .inner {
  padding: 20px 0 28px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* ===== レスポンシブ ===== */
@media (max-width: 860px) {
  .tool-layout {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 18px;
  }
  .filters-panel {
    position: static;
    border-bottom: 1px solid var(--line-dark);
    margin-bottom: 12px;
  }
  .header-inner { padding: 26px 0 22px; }
  .dialog-body { padding: 22px 18px 18px; }
  .term-detail { grid-template-columns: 1fr; gap: 2px; }
  .term-detail dt { border-top: 1px solid var(--line); margin-top: 10px; }
  .term-detail dd { border-top: none; padding-top: 0; }
  .teacher-inner { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .term-card { transition: none; }
}
