:root {
  --paper: #f5f1e8;
  --paper-deep: #ebe4d6;
  --ink: #24201c;
  --muted: #6d655c;
  --line: #d8cfc0;
  --accent: #963d31;
  --accent-soft: #ead5cc;
  --serif: "Shippori Mincho", "Yu Mincho", "Hiragino Mincho ProN", serif;
  --sans: "Noto Sans JP", "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.9;
  text-rendering: optimizeLegibility;
}

body::selection {
  background: var(--accent-soft);
}

a {
  color: var(--accent);
  text-underline-offset: 0.18em;
}

a:hover {
  color: #6f2b24;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 3px solid #bd6b58;
  outline-offset: 3px;
}

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

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 0 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--ink);
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  text-decoration: none;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 20px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--accent);
}

.breadcrumb {
  margin: 34px 0 18px;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.05em;
}

.breadcrumb span {
  margin: 0 0.55em;
  color: #a89d8f;
}

.breadcrumb a {
  color: inherit;
}

.hero {
  max-width: 900px;
  padding: 34px 0 58px;
}

.kicker {
  margin: 0 0 18px;
  color: var(--accent);
  font-family: var(--display);
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.35;
}

h1 {
  max-width: 930px;
  margin: 0;
  font-size: clamp(2.15rem, 5vw, 4.7rem);
}

h2 {
  margin: 0 0 24px;
  font-size: clamp(1.55rem, 3vw, 2.35rem);
}

h3 {
  margin: 0 0 10px;
  font-size: 1.2rem;
}

.lede {
  max-width: 760px;
  margin: 26px 0 0;
  color: #4d463f;
  font-family: var(--serif);
  font-size: clamp(1.08rem, 2vw, 1.35rem);
  line-height: 1.85;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 24px;
  color: var(--muted);
  font-size: 0.78rem;
}

.hero-meta strong {
  color: var(--ink);
  font-weight: 500;
}

.article-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: clamp(38px, 8vw, 110px);
  align-items: start;
}

.article-body {
  min-width: 0;
}

.article-body > section {
  padding: 58px 0;
  border-top: 1px solid var(--line);
}

.article-body > section:first-child {
  padding-top: 0;
  border-top: 0;
}

.article-body p {
  max-width: 760px;
  margin: 0 0 1.3em;
}

.article-body ul,
.article-body ol {
  max-width: 760px;
  padding-left: 1.5em;
}

.article-body li + li {
  margin-top: 0.55em;
}

.article-body strong {
  font-weight: 700;
}

.article-body em {
  color: #5c3028;
}

.article-body blockquote {
  max-width: 760px;
  margin: 28px 0;
  padding: 18px 24px;
  border-left: 3px solid var(--accent);
  background: rgba(255, 255, 255, 0.3);
  color: #4f463d;
  font-family: var(--serif);
  font-size: 1.05rem;
}

.section-index {
  position: sticky;
  top: 24px;
  padding: 22px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.section-index small {
  display: block;
  margin-bottom: 12px;
  color: var(--accent);
  font-family: var(--display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.section-index a {
  display: block;
  padding: 5px 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-decoration: none;
}

.section-index a:hover {
  color: var(--accent);
}

.callout {
  max-width: 760px;
  margin: 28px 0;
  padding: 24px 26px;
  background: var(--paper-deep);
  border: 1px solid var(--line);
}

.callout p:last-child,
.source-card p:last-child,
.card p:last-child {
  margin-bottom: 0;
}

.callout-label {
  display: block;
  margin-bottom: 9px;
  color: var(--accent);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.three-up,
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 30px 0;
}

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

.lens-card {
  min-height: 100%;
  padding: 22px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.22);
}

.lens-card--future {
  border-color: #bcae9d;
  background: #eee5d7;
}

.lens-card--falsifier {
  border-color: var(--accent);
  background: rgba(234, 213, 204, 0.42);
}

.lens-card .eyebrow {
  margin-bottom: 12px;
  color: var(--accent);
  font-family: var(--display);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
}

.lens-card p:last-child {
  margin-bottom: 0;
}

.card {
  padding: 22px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.22);
}

.card p {
  color: #5e574e;
  font-size: 0.9rem;
}

.card .eyebrow {
  margin-bottom: 12px;
  color: var(--accent);
  font-family: var(--display);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
}

.source-card {
  max-width: 760px;
  margin: 24px 0;
  padding: 22px 24px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.34);
}

.source-card .source-meta {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.78rem;
}

.source-card h3 {
  font-size: 1.2rem;
}

.source-card a {
  font-size: 0.88rem;
}

.table-wrap {
  max-width: 100%;
  margin: 28px 0;
  overflow-x: auto;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  min-width: 660px;
  border-collapse: collapse;
  font-size: 0.86rem;
}

th,
td {
  padding: 14px 15px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--paper-deep);
  color: #4d443b;
  font-size: 0.77rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

tr:last-child td {
  border-bottom: 0;
}

.formula {
  max-width: 760px;
  margin: 26px 0;
  padding: 18px 22px;
  overflow-x: auto;
  background: #2d2823;
  color: #f5f1e8;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.7;
}

.small-note,
.method-note {
  color: var(--muted);
  font-size: 0.82rem;
}

.tool-panel {
  max-width: 920px;
  margin: 32px 0;
  padding: clamp(20px, 4vw, 32px);
  border: 1px solid #bcae9d;
  background: rgba(255, 255, 255, 0.38);
}

.tool-panel h3 {
  margin-bottom: 8px;
}

.tool-table {
  min-width: 860px;
}

.tool-table th,
.tool-table td {
  padding: 10px 8px;
  text-align: center;
}

.tool-table th:first-child,
.tool-table td:first-child {
  min-width: 118px;
  text-align: left;
}

.confidence-input {
  width: 70px;
  padding: 7px 6px;
  border: 1px solid #b9ab9a;
  border-radius: 0;
  background: #fffdf7;
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
  text-align: center;
}

.correct-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.68rem;
  white-space: nowrap;
}

.correct-input {
  accent-color: var(--accent);
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
}

.button {
  display: inline-block;
  padding: 10px 17px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fffaf2;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  letter-spacing: 0.05em;
}

.button:hover {
  background: #713027;
}

.tool-status {
  color: var(--muted);
  font-size: 0.78rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 24px;
}

.metric {
  padding: 15px;
  border-top: 2px solid var(--accent);
  background: var(--paper-deep);
}

.metric strong {
  display: block;
  color: var(--accent);
  font-family: var(--display);
  font-size: 1.35rem;
  line-height: 1.2;
}

.metric span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.5;
}

.result-table {
  min-width: 500px;
  margin-top: 18px;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 20px 0;
}

.preset-button {
  padding: 7px 11px;
  border: 1px solid #bcae9d;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.76rem;
}

.preset-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chart-shell {
  margin-top: 24px;
  padding: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.28);
}

.chart-shell svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 230px;
}

.chart-shell text {
  fill: var(--muted);
  font-family: var(--sans);
  font-size: 11px;
}

.chart-shell .grid-line {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-shell .perfect-line {
  stroke: #9e9489;
  stroke-dasharray: 5 5;
  stroke-width: 1.5;
}

.chart-shell .confidence-bar {
  fill: rgba(36, 32, 28, 0.22);
}

.chart-shell .accuracy-bar {
  fill: var(--accent);
}

.chart-shell .legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.73rem;
}

.chart-shell .legend span::before {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 5px;
  content: "";
  background: var(--accent);
}

.chart-shell .legend span:first-child::before {
  background: rgba(36, 32, 28, 0.32);
}

.decision-table td:first-child {
  min-width: 110px;
  color: var(--accent);
  font-weight: 700;
}

.score-highlight {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.82rem;
}

.data-label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 700;
}

.data-input {
  display: block;
  width: 100%;
  min-height: 190px;
  padding: 14px;
  border: 1px solid #b9ab9a;
  border-radius: 0;
  background: #fffdf7;
  color: var(--ink);
  font: 0.82rem/1.6 "SFMono-Regular", Consolas, monospace;
  resize: vertical;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.control-grid label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
}

.control-grid select {
  min-height: 38px;
  padding: 7px 9px;
  border: 1px solid #b9ab9a;
  border-radius: 0;
  background: #fffdf7;
  color: var(--ink);
  font: inherit;
}

.control-grid input[type="range"] {
  width: 100%;
  margin: 8px 0 2px;
  accent-color: var(--accent);
}

.range-value {
  color: var(--accent);
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 700;
}

.metric-grid.five-up {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.metric-grid.four-up {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.output-block {
  margin-top: 24px;
}

.output-block h3 {
  margin-bottom: 8px;
}

.group-table {
  min-width: 1040px;
}

.coverage-table {
  min-width: 900px;
}

.split-table {
  min-width: 1160px;
}

.interval-cell {
  white-space: nowrap;
}

.bin-table td:not(:first-child),
.bin-table th:not(:first-child) {
  text-align: right;
}

.related {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 28px;
}

.related a {
  display: block;
  height: 100%;
  padding: 18px;
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.related a:hover {
  border-color: var(--accent);
}

.related small {
  display: block;
  margin-bottom: 7px;
  color: var(--accent);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
}

.footer {
  margin-top: 80px;
  padding: 30px 0 50px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
}

.footer p {
  margin: 0 0 8px;
}

@media (max-width: 820px) {
  .article-layout {
    grid-template-columns: 1fr;
  }

  .section-index {
    position: static;
    order: -1;
    display: flex;
    flex-wrap: wrap;
    gap: 3px 14px;
  }

  .section-index small {
    width: 100%;
  }

  .section-index a {
    padding: 2px 0;
  }

  .three-up,
  .card-grid,
  .related {
    grid-template-columns: 1fr;
  }

  .lens-grid {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-grid.five-up {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric-grid.four-up {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .page-shell {
    width: min(100% - 28px, 1120px);
  }

  .site-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .site-nav {
    justify-content: flex-start;
  }

  .hero {
    padding: 24px 0 42px;
  }

  .article-body > section {
    padding: 42px 0;
  }

  .callout,
  .source-card,
  .tool-panel {
    padding: 18px;
  }

  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }

  .metric-grid.five-up {
    grid-template-columns: 1fr 1fr;
  }

  .metric-grid.four-up {
    grid-template-columns: 1fr 1fr;
  }

  .control-grid {
    grid-template-columns: 1fr;
  }

}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
