:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #1e293b;
  --sub: #64748b;
  --line: #e7ecf3;
  --accent: #4f7cff;
  --accent-soft: #eef3ff;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 14px rgba(15, 23, 42, 0.05);
  --shadow-hover: 0 2px 4px rgba(15, 23, 42, 0.05), 0 10px 24px rgba(79, 124, 255, 0.14);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 400px at 10% -10%, #e3ecff 0%, transparent 60%),
    radial-gradient(900px 360px at 100% 0%, #e6f7f4 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: "Inter", system-ui, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 16px 80px;
}

header h1 {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  margin: 0 0 6px;
}

/* パンくず */
.breadcrumb {
  font-size: 0.88rem;
  color: var(--sub);
  margin-bottom: 24px;
  min-height: 1.2em;
}
.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.breadcrumb a:hover { text-decoration: underline; }

/* 科目・単元のリスト */
.list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 12px;
}
.list a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 600;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.list a:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: #cfdcff;
}
.count {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
  margin-left: 12px;
}

/* 検索欄 */
.search {
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(79, 124, 255, 0.15);
}

/* 用語カード */
.term {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  overflow: hidden;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.term:hover { border-color: #cfdcff; }
.term[open] {
  border-color: #cfdcff;
  box-shadow: var(--shadow-hover);
}
.term summary {
  font-size: 1.05rem;
  font-weight: 700;
  padding: 16px 20px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: baseline;
}
.term summary::-webkit-details-marker { display: none; }
.term summary::before {
  content: "›";
  display: inline-block;
  width: 1.2em;
  color: var(--accent);
  font-weight: 800;
  transition: transform 0.2s;
}
.term[open] summary::before { transform: rotate(90deg); }
.term .reading {
  font-size: 0.78rem;
  color: var(--sub);
  font-weight: 500;
  margin-left: 10px;
}
.term .body {
  padding: 14px 20px 16px calc(20px + 1.2em);
  background: #fafcff;
  border-top: 1px solid var(--line);
}
.term .body > p {
  margin: 0;
  white-space: pre-wrap;
}

/* 入れ子カード */
.children { margin-top: 14px; }
.children .term {
  box-shadow: none;
  border-radius: 10px;
  margin-bottom: 8px;
}
.children .term summary { font-size: 0.98rem; padding: 12px 16px; }
.children .term .body { padding: 12px 16px 14px calc(16px + 1.2em); background: #f6f9ff; }

/* 図 */
.figure {
  margin-top: 16px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.figure .fig-title { margin: 0 0 8px; font-weight: 700; }
.figure .fig-note { margin: 12px 0 0; }
.figure .fig-steps { margin: 12px 0; padding-left: 1.4em; }

.tree {
  display: block;
  width: 100%;
  max-width: 420px;
  height: auto;
  margin: 0 auto;
  font-family: inherit;
}
.tree text { text-anchor: middle; font-size: 14px; }
.tree .edge line { stroke: #b8c4d6; stroke-width: 2; }
.tree .bit text { fill: var(--accent); font-weight: 800; font-size: 15px; }
.tree .inner circle { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; }
.tree .inner text { fill: var(--accent); font-weight: 700; font-size: 13px; }
.tree .leaf rect { fill: #e9f8f3; stroke: #3bb58f; stroke-width: 1.5; }
.tree .leaf text { fill: var(--text); font-weight: 800; }
.tree .leaf text.p { font-size: 11px; font-weight: 500; fill: var(--sub); }
.tree .code text { fill: #e0567a; font-weight: 800; font-family: ui-monospace, Consolas, monospace; }

.rle { display: flex; flex-wrap: wrap; gap: 6px; }
.rle .run {
  padding: 6px 12px;
  border-radius: 8px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.15em;
}
.rle .r1 { background: #e6eeff; color: #3b63d9; }
.rle .r2 { background: #e9f8f3; color: #23946f; }
.rle .r3 { background: #fff3e0; color: #c97a12; }
.rle .r4 { background: #fdeaf0; color: #c9436a; }
.rle-arrow { margin: 8px 0; color: var(--sub); font-size: 0.9rem; }

.fig-table {
  border-collapse: collapse;
  font-size: 0.92rem;
}
.fig-table th, .fig-table td {
  border: 1px solid var(--line);
  padding: 4px 14px;
  text-align: center;
}
.fig-table th { background: var(--accent-soft); }
.fig-table .mono { font-family: ui-monospace, Consolas, monospace; white-space: nowrap; }
.fig-table b { color: #e0567a; }
/* 横に長い表はカード内で横スクロール */
.figure { overflow-x: auto; }

.empty {
  color: var(--sub);
  text-align: center;
  padding: 48px 0;
  background: rgba(255, 255, 255, 0.6);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
