/* 国語ことば辞典 — 社会ことば辞典（第4版）の画面を土台に、書体をクレー（Klee One）にした */
:root {
  --paper: #fbfaf7;
  --white: #ffffff;
  --ink: #20242b;
  --ink-soft: #5a6069;
  --line: #d9d6ce;
  --line-dark: #b9b5aa;
  --ai: #29527a;        /* 藍 = メイン */
  --ai-soft: #eef3f8;
  --shu: #c3502b;       /* 朱 = 強調（最小限） */
  --g1: #c3502b;
  --g2: #b7791f;
  --g3: #2f7a54;
  --g4: #29527a;
  --g5: #5b4a7a;
  --g6: #7a3548;
  --font: "Klee One", "Klee", "UD デジタル 教科書体 N-R", "UDDigiKyokashoN-R", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  font-family: var(--font);
  font-size: 17px;
}

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

[hidden] { display: none !important; }

.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;
}
.ja-phrase { word-break: auto-phrase; text-wrap: pretty; }

/* ふりがな */
ruby { ruby-align: center; }
rt { font-size: 0.5em; font-weight: 400; color: var(--ink-soft); letter-spacing: 0; }
body.no-ruby rt { display: none; }

/* ===== ヘッダー ===== */
.site-header {
  background: var(--white);
  border-bottom: 1px solid var(--line-dark);
}
.header-inner {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 26px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 24px;
  align-items: end;
}
.brand-line {
  grid-column: 1 / -1;
  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: 6px 0 4px;
  font-size: clamp(1.9rem, 5vw, 3rem);
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.25;
}
.site-header h1 .accent { color: var(--ai); }
.lead {
  font-size: 0.98rem;
  color: var(--ink-soft);
}
.lead strong { color: var(--ink); font-weight: 600; }
.page-nav {
  display: flex;
  gap: 6px;
  align-self: end;
}
.page-nav a {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--line-dark);
  border-radius: 3px;
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--white);
}
.page-nav a.current {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--white);
}

/* ===== 検索帯 ===== */
.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: 12px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
}
.search-box {
  flex: 1 1 280px;
  display: flex;
}
.search-box input {
  width: 100%;
  padding: 10px 16px;
  border: 1.5px solid var(--line-dark);
  border-radius: 4px;
  background: var(--paper);
  font-size: 1.05rem;
}
.search-box input:focus {
  outline: 2px solid var(--ai);
  outline-offset: -1px;
}
.grade-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 7px 13px;
  border: 1px solid var(--line-dark);
  border-radius: 3px;
  background: var(--white);
  font-size: 0.92rem;
  line-height: 1;
}
.chip:hover { border-color: var(--ink); }
.chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--white);
  font-weight: 600;
}
.ruby-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}
.ruby-toggle input { width: 18px; height: 18px; accent-color: var(--ai); }

/* ===== 本体レイアウト ===== */
.tool-layout {
  width: min(1120px, calc(100% - 40px));
  margin: 26px auto 60px;
  display: grid;
  grid-template-columns: 236px 1fr;
  gap: 34px;
  align-items: start;
}
.filters-panel {
  display: grid;
  gap: 4px;
  position: sticky;
  top: 74px;
  max-height: calc(100vh - 90px);
  overflow: auto;
}
.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.9rem;
  font-weight: 600;
  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(6, 1fr);
  gap: 5px;
}
.kana-grid .chip { padding: 7px 0; text-align: center; }
.tag-list { display: grid; gap: 3px; }
.tag-button {
  text-align: left;
  padding: 6px 8px;
  border-radius: 3px;
  font-size: 0.9rem;
  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 .count { margin-left: auto; font-size: 0.78rem; color: var(--ink-soft); }
.tag-button.active .count { color: var(--line); }

/* ===== 結果一覧 ===== */
.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: 600; 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(232px, 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: 2px;
  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.3rem;
  font-weight: 600;
  line-height: 1.6;
  padding-right: 34px;
  word-break: auto-phrase;
}
.term-card .reading { font-size: 0.8rem; color: var(--ink-soft); letter-spacing: 0.04em; }
.term-card .grade-label {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--grade-color, var(--ink-soft));
  letter-spacing: 0.06em;
}
.term-card .meaning {
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 4px;
}
.term-card .marks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.mark {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ai);
  border: 1px solid currentColor;
  border-radius: 2px;
  padding: 0 6px;
  letter-spacing: 0.06em;
  line-height: 1.6;
}
.mark.think { color: var(--shu); }
.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: 600;
  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);
  color: var(--ink);
}
.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: 40px;
  height: 40px;
  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.82rem;
  font-weight: 600;
  color: var(--grade-color, var(--ink-soft));
  letter-spacing: 0.08em;
}
.dialog-title h2 {
  font-size: 2.3rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.5;
  padding-right: 48px;
  word-break: auto-phrase;
}
.dialog-title .reading { font-size: 0.95rem; color: var(--ink-soft); letter-spacing: 0.06em; }
.dialog-title .note { margin-left: 12px; font-size: 0.85rem; color: var(--ink-soft); }
.senses { margin-top: 18px; display: grid; gap: 12px; counter-reset: sense; }
.sense {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: grid;
  grid-template-columns: 2em 1fr;
  gap: 2px 8px;
}
.sense .num {
  font-weight: 600;
  color: var(--ai);
  font-size: 1.05rem;
}
.sense .imi { font-size: 1.12rem; line-height: 1.9; }
.sense .rei {
  grid-column: 2;
  font-size: 1rem;
  color: var(--ink-soft);
  line-height: 1.9;
  padding-left: 1.2em;
  text-indent: -1.2em;
}
.sense .rei::before { content: "例 "; color: var(--ai); font-weight: 600; font-size: 0.85rem; letter-spacing: 0.1em; }
.term-detail {
  display: grid;
  grid-template-columns: 7em 1fr;
  gap: 10px 16px;
  margin-top: 18px;
}
.term-detail dt {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.1em;
  padding-top: 5px;
  border-top: 1px solid var(--line);
}
.term-detail dd {
  font-size: 0.98rem;
  border-top: 1px solid var(--line);
  padding-top: 4px;
}
.related-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.related-buttons button, .kanji-chip {
  border: 1px solid var(--line-dark);
  border-radius: 3px;
  padding: 3px 10px;
  font-size: 0.92rem;
  background: var(--white);
  text-decoration: none;
  color: var(--ink);
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}
.related-buttons button:hover, .kanji-chip:hover { border-color: var(--ai); color: var(--ai); }
.kanji-chip .k { font-size: 1.25rem; font-weight: 600; }
.kanji-chip .g { font-size: 0.72rem; color: var(--ink-soft); letter-spacing: 0.05em; }
.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: 600; letter-spacing: 0.12em; white-space: nowrap; }
.teacher-band p { font-size: 0.9rem; color: var(--ink-soft); margin-bottom: 6px; }
.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);
}

/* ===== 漢字表（付録） ===== */
.kanji-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  margin-bottom: 18px;
}
.kanji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}
.kanji-tile {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 4px 8px;
  display: grid;
  justify-items: center;
  gap: 2px;
  position: relative;
  transition: border-color 0.15s;
}
.kanji-tile::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--grade-color, var(--line-dark));
}
.kanji-tile:hover { border-color: var(--ink); }
.kanji-tile .k { font-size: 2.3rem; line-height: 1.2; font-weight: 400; }
.kanji-tile .y {
  font-size: 0.68rem;
  color: var(--ink-soft);
  line-height: 1.3;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.kanji-tile .s { font-size: 0.62rem; color: var(--ink-soft); letter-spacing: 0.05em; }
.kanji-hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 28px;
  align-items: start;
  margin-top: 6px;
}
.kanji-hero .big {
  font-size: 10rem;
  line-height: 1;
  font-weight: 400;
  width: 1.4em; height: 1.4em;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background-color: var(--paper);
  /* 十字は字の後ろ（背景）に引く */
  background-image: linear-gradient(var(--line-dark) 1px, transparent 1px), linear-gradient(90deg, var(--line-dark) 1px, transparent 1px);
  background-size: 50% 50%;
  background-position: -1px -1px;
  position: relative;
}
.kanji-hero .facts { display: grid; gap: 4px; font-size: 0.98rem; padding-top: 6px; }
.kanji-hero .facts .label { color: var(--ink-soft); font-size: 0.82rem; letter-spacing: 0.08em; margin-right: 8px; }
.kanji-hero .facts .yomi { font-size: 1.2rem; font-weight: 600; }
.kanji-hero .facts .hi { color: var(--ink-soft); font-size: 0.9rem; }
.tokubetsu-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px 14px;
  font-size: 1rem;
}
.tokubetsu-list li { border-bottom: 1px dotted var(--line-dark); padding: 4px 0; }
.tokubetsu-list rt { font-size: 0.55em; }
.section-title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 6px;
  margin: 34px 0 14px;
}

/* ===== レスポンシブ ===== */
@media (max-width: 860px) {
  .header-inner { grid-template-columns: 1fr; padding: 22px 0 18px; }
  .page-nav { justify-self: start; }
  .tool-layout { grid-template-columns: 1fr; gap: 10px; margin-top: 18px; }
  .filters-panel { position: static; max-height: none; border-bottom: 1px solid var(--line-dark); margin-bottom: 12px; }
  .dialog-body { padding: 22px 18px 18px; }
  .dialog-title h2 { font-size: 1.8rem; }
  .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; }
  .kanji-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
  .kanji-tile .k { font-size: 1.9rem; }
  .kanji-hero { grid-template-columns: 1fr; }
  .kanji-hero .big { font-size: 7rem; justify-self: start; }
}

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

@media print {
  .search-band, .filters-panel, .page-nav, .teacher-band, .show-more, .reset-button { display: none !important; }
  .tool-layout { grid-template-columns: 1fr; }
  .kanji-grid { grid-template-columns: repeat(10, 1fr); gap: 4px; }
  .kanji-tile { break-inside: avoid; }
}
