:root {
  --bg: #0d0e14;
  --surface: #141620;
  --surface-2: #1a1d29;
  --ink: #ececf4;
  --muted: #a5a7b5;
  --line: #2b2f3d;
  --accent: #9b7bff;
  --accent-soft: rgba(155, 123, 255, .13);
  --accent-bright: #c6b6ff;
  --code: #0a0b10;
  --green: #4ade80;
  --excel-grid: #d8dce4;
  --excel-head: #eef0f3;
  --excel-text: #252834;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 78% 7%, rgba(118, 84, 210, .11), transparent 28rem),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Yu Gothic UI", "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 17px;
  line-height: 1.85;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }

button { font: inherit; }

.site-header {
  height: 68px;
  padding: 0 clamp(20px, 4vw, 64px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(13, 14, 20, .88);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
  font-size: .88rem;
  letter-spacing: .18em;
}

.brand strong { color: var(--accent-bright); }

.brand-mark {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 0 10px rgba(199, 203, 215, .18));
}

.section-name {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: .78rem;
  letter-spacing: .08em;
}

.reading-progress {
  position: fixed;
  top: 68px;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 30;
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #6d4ed0, var(--accent-bright));
}

.page-shell {
  width: min(1200px, calc(100% - 40px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 190px minmax(0, 780px);
  gap: clamp(44px, 7vw, 92px);
  justify-content: center;
  padding: 70px 0 110px;
}

.home-shell {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: clamp(64px, 9vw, 116px) 0 110px;
}

.home-hero {
  min-height: 430px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 360px);
  align-items: center;
  gap: clamp(50px, 8vw, 110px);
  border-bottom: 1px solid var(--line);
}

.hero-copy { padding-bottom: 44px; }

.hero-copy h1 {
  max-width: 760px;
  margin: 18px 0 24px;
  font-size: clamp(2.55rem, 6vw, 4.9rem);
  line-height: 1.2;
}

.hero-copy > p:last-child {
  max-width: 640px;
  color: #bfc1cc;
  font-size: 1.02rem;
}

.hero-symbol {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  position: relative;
}

.hero-symbol::before {
  content: "";
  position: absolute;
  inset: 8%;
  border: 1px solid #292c38;
  border-radius: 50%;
  box-shadow: 0 0 90px rgba(155, 123, 255, .09);
}

.hero-symbol img { width: 76%; position: relative; }

.article-index { padding-top: 72px; }
.index-heading { max-width: 680px; margin-bottom: 34px; }
.index-heading h2 { margin: 12px 0 14px; }
.index-heading > p:last-child { color: var(--muted); }

.article-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.article-card {
  min-height: 310px;
  padding: 30px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 17px;
  color: var(--ink);
  background:
    linear-gradient(145deg, rgba(255,255,255,.035), rgba(255,255,255,.008)),
    var(--surface);
  text-decoration: none;
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}

.article-card:hover {
  transform: translateY(-4px);
  border-color: #5c4e7f;
  box-shadow: 0 24px 60px rgba(0,0,0,.22);
}

.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: #858896;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: .72rem;
}

.card-meta span { color: var(--accent-bright); }
.article-card h3 { margin: 28px 0 14px; font-size: 1.35rem; }
.article-card p { margin: 0 0 28px; color: #aeb0bd; font-size: .9rem; }
.card-link { margin-top: auto; color: var(--accent-bright); font-size: .82rem; }

.site-footer {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 30px 0 44px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 14px;
}

.site-footer strong { font-size: .85rem; letter-spacing: .08em; }
.site-footer p { margin: 1px 0 0; color: #767988; font-size: .74rem; }

.toc {
  position: sticky;
  top: 112px;
  align-self: start;
  border-left: 1px solid var(--line);
  padding-left: 20px;
}

.toc-label,
.section-kicker {
  color: var(--accent);
  font-size: .7rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: .18em;
}

.toc nav { display: grid; gap: 7px; }

.toc a {
  color: #878a99;
  text-decoration: none;
  font-size: .8rem;
  line-height: 1.55;
  transition: color .2s ease, transform .2s ease;
}

.toc a:hover,
.toc a.is-current { color: var(--accent-bright); transform: translateX(3px); }

.article { min-width: 0; }

.breadcrumb {
  margin: 0 0 24px;
  display: flex;
  gap: 9px;
  color: #777a89;
  font-size: .74rem;
}

.breadcrumb a { color: #aaaebe; text-decoration: none; }
.breadcrumb a:hover { color: var(--accent-bright); }

.article-header { padding: 14px 0 60px; }

.eyebrow { display: flex; gap: 9px; margin-bottom: 22px; }

.eyebrow span {
  border: 1px solid #443a62;
  border-radius: 999px;
  padding: 3px 11px;
  color: var(--accent-bright);
  background: var(--accent-soft);
  font-size: .72rem;
  line-height: 1.6;
}

h1, h2, h3 { margin-top: 0; line-height: 1.38; letter-spacing: .01em; }

h1 {
  margin-bottom: 24px;
  font-size: clamp(2.15rem, 5vw, 3.65rem);
  font-weight: 700;
  letter-spacing: -.035em;
}

h2 { margin-bottom: 24px; font-size: clamp(1.55rem, 3vw, 2.05rem); }
h3 { margin-top: 42px; margin-bottom: 16px; font-size: 1.2rem; }

.lead { max-width: 700px; color: #bcbecb; font-size: 1.08rem; line-height: 1.9; }

.article-meta {
  display: flex;
  gap: 18px;
  margin-top: 28px;
  color: #747786;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: .76rem;
}

.article > section {
  padding: 64px 0;
  border-top: 1px solid var(--line);
  scroll-margin-top: 90px;
}

.article p { color: #c5c7d1; }
.article p code, .choice-row code, .summary-list code { color: #d7cbff; }

.process-list {
  margin: 34px 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  list-style: none;
}

.process-list li {
  min-height: 106px;
  display: flex;
  align-items: flex-start;
  gap: 15px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(255,255,255,.025), rgba(255,255,255,.008));
}

.process-list > li > span {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: .72rem;
}

.process-list strong { display: block; font-size: .93rem; }
.process-list small { display: block; margin-top: 4px; color: var(--muted); font-size: .78rem; line-height: 1.55; }

.note, .warning {
  margin: 34px 0;
  display: flex;
  gap: 14px;
  padding: 18px 20px;
  border: 1px solid #3b3450;
  border-radius: 12px;
  background: var(--accent-soft);
}

.note p, .warning p { margin: 0; font-size: .88rem; }

.note-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #17121f;
  background: var(--accent-bright);
  font: 700 .75rem Georgia, serif;
}

.sheet-card {
  margin: 34px 0;
  overflow: hidden;
  border: 1px solid #313544;
  border-radius: 16px;
  background: #10121a;
  box-shadow: 0 28px 70px rgba(0,0,0,.22);
}

.sheet-toolbar {
  min-height: 49px;
  padding: 10px 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #303442;
  color: #d7d8e0;
  font-size: .8rem;
}

.sheet-dots { display: flex; gap: 6px; }
.sheet-dots span { width: 8px; height: 8px; border-radius: 50%; background: #444856; }
.sheet-dots span:first-child { background: #8062dd; }
.sheet-hint { margin-left: auto; color: #777b8a; font-size: .7rem; }
.sheet-scroll { overflow-x: auto; background: white; }

.excel-sheet {
  width: 100%;
  min-width: 700px;
  border-collapse: collapse;
  table-layout: fixed;
  color: var(--excel-text);
  background: white;
  font-family: Calibri, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.25;
}

.excel-sheet th, .excel-sheet td {
  height: 28px;
  padding: 5px 7px;
  border-right: 1px solid var(--excel-grid);
  border-bottom: 1px solid var(--excel-grid);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.excel-sheet thead th,
.excel-sheet tbody th { background: var(--excel-head); color: #656976; text-align: center; font-weight: 500; }
.excel-sheet .corner, .excel-sheet tbody th { width: 38px; }
.excel-sheet .source-header td { background: #d9e5f6; font-weight: 700; }
.excel-sheet .blank-row td { height: 21px; background: #fafafa; }
.excel-sheet .filter-row td { height: 25px; padding: 2px 5px; background: #f5f0ff; border-bottom: 2px solid #8c6ee1; text-align: right; }
.filter-cell { display: inline-grid; width: 18px; height: 17px; place-items: center; border: 1px solid #bbb4d1; border-radius: 2px; color: #555064; background: #fff; font-size: 8px; }
.excel-sheet tr.is-filtered-out { display: none; }
.excel-sheet tr.is-gray td { background: #d9d9d9; }
.excel-sheet tr.is-gray th { background: #c9cbd0; }

.demo-controls {
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  border-top: 1px solid #282b38;
}

.demo-button {
  border: 1px solid #3b3f50;
  border-radius: 8px;
  padding: 8px 12px;
  color: #b8bac5;
  background: #191b25;
  cursor: pointer;
  font-size: .78rem;
  transition: border-color .2s ease, color .2s ease, background .2s ease;
}

.demo-button:hover { color: white; border-color: #70628f; }
.demo-button.is-active { color: white; border-color: #8d70e2; background: #332650; }
.demo-caption { min-height: 47px; margin: 0; padding: 0 16px 16px; color: #9699a8 !important; font-size: .8rem; }

.code-block {
  margin: 28px 0;
  overflow: hidden;
  border: 1px solid #2a2d38;
  border-radius: 13px;
  background: var(--code);
}

.code-head {
  min-height: 42px;
  padding: 7px 12px 7px 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #252832;
  color: #817f8c;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: .68rem;
  letter-spacing: .12em;
}

.copy-button {
  border: 1px solid #343743;
  border-radius: 6px;
  padding: 4px 9px;
  color: #aaa8b3;
  background: #161820;
  cursor: pointer;
  font-size: .68rem;
}

.copy-button:hover { color: white; border-color: #5c4e7f; }

.code-block.code-warning {
  border-color: #b98a2e;
  background: #11100d;
  box-shadow: inset 3px 0 0 #e1ad42;
}

.code-warning .code-head {
  border-bottom-color: #6d5325;
  color: #f2c96f;
  background: #241c0d;
}

.warning-badge {
  border: 1px solid #a87c25;
  border-radius: 999px;
  padding: 4px 9px;
  color: #ffdc8a;
  background: #3a2a0c;
  font-family: "Noto Sans JP", sans-serif;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .05em;
}

pre {
  margin: 0;
  padding: 22px;
  overflow-x: auto;
  color: #d9d7e2;
  font: .82rem/1.75 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  tab-size: 4;
}

.large pre { max-height: 680px; }

.explain-grid {
  margin: 30px 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--line);
}

.explain-grid > div { padding: 20px; background: var(--surface); }
.explain-grid code { color: var(--accent-bright); font-weight: 700; }
.explain-grid p { margin: 8px 0 0; color: var(--muted); font-size: .82rem; line-height: 1.65; }

blockquote {
  margin: 38px 0 0;
  padding: 2px 0 2px 24px;
  border-left: 3px solid var(--accent);
}

blockquote p { margin: 0; color: #ded6f7 !important; font-size: 1.05rem; }

.choice-row { margin: 30px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice-row > div { padding: 18px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.choice-row strong { display: block; margin-bottom: 8px; font-size: .86rem; }
.choice-row code { display: block; overflow-wrap: anywhere; font-size: .75rem; }

.comparison-grid {
  margin: 30px 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.comparison-grid > div {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}

.comparison-label {
  display: block;
  margin-bottom: 12px;
  color: var(--accent-bright);
  font: .72rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.comparison-grid strong { display: block; font-size: .95rem; }
.comparison-grid p { margin: 7px 0 0; color: var(--muted); font-size: .82rem; line-height: 1.65; }

.key-flow {
  margin: 32px 0;
  padding: 22px;
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1.6fr;
  align-items: stretch;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.key-flow > div {
  min-height: 86px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid #303442;
  border-radius: 10px;
  background: var(--surface-2);
}

.key-flow > span { align-self: center; color: #757988; }
.key-flow small { color: #848796; font-size: .7rem; }
.key-flow strong { margin-top: 4px; font-size: .85rem; }
.key-flow .key-result { border-color: #584a7d; background: var(--accent-soft); }
.key-flow .key-result strong { color: var(--accent-bright); }

.aggregation-demo {
  margin: 34px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.data-panel {
  overflow: hidden;
  border: 1px solid #313544;
  border-radius: 14px;
  background: #10121a;
}

.data-panel-head {
  min-height: 46px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #d6d8e0;
  font-size: .8rem;
}

.data-panel-head small { color: #7d808e; font-size: .68rem; }
.result-panel { border-color: #51446f; }
.aggregate-arrow { color: var(--accent-bright); font-size: 1.25rem; }

.mini-sheet {
  width: 100%;
  min-width: 300px;
  border-collapse: collapse;
  color: var(--excel-text);
  background: #fff;
  font: 13px/1.3 Calibri, "Segoe UI", sans-serif;
}

.mini-sheet th, .mini-sheet td { padding: 9px 11px; border: 1px solid var(--excel-grid); text-align: left; }
.mini-sheet th { background: #e9ecf2; font-weight: 600; }
.mini-sheet td:last-child, .mini-sheet th:last-child { text-align: right; }
.mini-sheet .duplicate-row td { background: #eee9ff; }

.next-article {
  margin-top: 10px;
  padding: 22px 24px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 20px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  background: var(--surface);
  text-decoration: none;
  transition: border-color 0.2s ease,
              background-color 0.2s ease,
              transform 0.2s ease;
}

.next-article > span:first-child { grid-column: 1; color: #858896; font-size: .72rem; }
.next-article strong { grid-column: 1; font-size: .92rem; }
.next-article > span:last-child { grid-column: 2; grid-row: 1 / 3; align-self: center; color: var(--accent-bright); }
.next-article:hover {
  border-color: #6f5d99;
  background-color: #181922;
  transform: translateY(-2px);
}

a[target="_blank"] {
  color: #66b3ff;
  text-decoration: underline;
  text-underline-offset: 3px;
}

a[target="_blank"]:hover {
  color: #9dceff;
}

.warning { display: block; border-color: #59462b; background: rgba(231, 170, 78, .08); }
.warning strong { display: block; margin-bottom: 4px; color: #efc57d; font-size: .88rem; }

.summary-list { margin: 28px 0 34px; padding: 0; list-style: none; }
.summary-list li { position: relative; padding: 12px 0 12px 30px; border-bottom: 1px solid var(--line); color: #c5c7d1; }
.summary-list li::before { content: ""; position: absolute; left: 3px; top: 24px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px rgba(155,123,255,.5); }

.article-footer {
  margin-top: 58px;
  padding-top: 30px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 15px;
}

.code-comment {
  color: #6a9955;
}

.article-footer .brand-mark { width: 38px; height: 38px; }
.article-footer strong { font-size: .88rem; letter-spacing: .08em; }
.article-footer p { margin: 1px 0 0; color: #767988; font-size: .75rem; }

@media (max-width: 940px) {
  .page-shell { grid-template-columns: minmax(0, 780px); padding-top: 45px; }
  .toc { display: none; }
  .home-hero { grid-template-columns: minmax(0, 1fr) 260px; }
}

@media (max-width: 620px) {
  body { font-size: 16px; }
  .site-header { height: 60px; padding: 0 18px; }
  .reading-progress { top: 60px; }
  .section-name { font-size: .68rem; }
  .page-shell { width: min(100% - 32px, 780px); padding: 32px 0 72px; }
  .home-shell { width: min(100% - 32px, 780px); padding: 48px 0 72px; }
  .home-hero { min-height: auto; grid-template-columns: 1fr; gap: 8px; }
  .hero-copy { padding-bottom: 10px; }
  .hero-copy h1 { font-size: 2.35rem; }
  .hero-symbol { width: 210px; margin: 0 auto 46px; }
  .article-index { padding-top: 50px; }
  .article-grid { grid-template-columns: 1fr; }
  .article-card { min-height: 280px; padding: 24px; }
  .article-header { padding-bottom: 42px; }
  h1 { font-size: 2.05rem; }
  .lead { font-size: 1rem; }
  .article > section { padding: 48px 0; scroll-margin-top: 70px; }
  .process-list, .explain-grid, .choice-row, .comparison-grid { grid-template-columns: 1fr; }
  .process-list li { min-height: auto; }
  .key-flow { grid-template-columns: 1fr; }
  .key-flow > span { transform: rotate(90deg); }
  .aggregation-demo { grid-template-columns: 1fr; }
  .aggregate-arrow { justify-self: center; transform: rotate(90deg); }
  .sheet-hint { display: none; }
  .demo-controls { display: grid; }
  .demo-button { width: 100%; text-align: left; }
  pre { padding: 18px; font-size: .76rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}
