/* style.css — フレンズ・パラドックス・シミュレータ */
:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --chart-surface: #fcfcfb;
  --text-1: #0b0b0b;
  --text-2: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --edge: rgba(11, 11, 11, 0.13);
  --c-friend: #2a78d6;
  --c-self: #eb6834;
  --c-tie: #898781;
  --c-3: #1baf7a;
  --c-4: #eda100;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 16px rgba(0, 0, 0, 0.05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --chart-surface: #1a1a19;
    --text-1: #f0efec;
    --text-2: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --edge: rgba(255, 255, 255, 0.16);
    --c-friend: #3987e5;
    --c-self: #d95926;
    --c-3: #199e70;
    --c-4: #c98500;
    --accent: #3987e5;
    --shadow: none;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --chart-surface: #1a1a19;
  --text-1: #f0efec;
  --text-2: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --edge: rgba(255, 255, 255, 0.16);
  --c-friend: #3987e5;
  --c-self: #d95926;
  --c-3: #199e70;
  --c-4: #c98500;
  --accent: #3987e5;
  --shadow: none;
}

* {
  box-sizing: border-box;
}
html {
  scroll-behavior: smooth;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-1);
  font-family: system-ui, -apple-system, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', 'Noto Sans CJK JP', 'Yu Gothic UI', Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}
a {
  color: var(--accent);
}
.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 16px;
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
strong {
  font-weight: 700;
}
h1,
h2,
h3 {
  line-height: 1.35;
  letter-spacing: 0.01em;
}
h2 {
  font-size: 1.35rem;
  margin: 0 0 12px;
  padding-top: 8px;
}
h3 {
  font-size: 1.05rem;
  margin: 18px 0 6px;
}
p {
  margin: 0 0 10px;
}
button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-1);
  padding: 6px 12px;
  transition: background 0.15s, transform 0.05s;
}
button:hover {
  background: var(--surface-2);
}
button:active {
  transform: translateY(1px);
}
button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
}
button.primary:hover {
  filter: brightness(1.08);
  background: var(--accent);
}
button.ghost {
  background: transparent;
}

/* ---------------- ヘッダー */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 0 14px;
}
.site-header h1 {
  margin: 0;
  font-size: 1.5rem;
}
.site-header .tagline {
  margin: 4px 0 10px;
  color: var(--text-2);
}
.site-header nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  align-items: center;
  font-size: 0.92rem;
}
.site-header nav a {
  text-decoration: none;
}
.site-header nav a:hover {
  text-decoration: underline;
}
#theme-toggle {
  margin-left: auto;
  font-size: 0.85rem;
  padding: 4px 10px;
}

/* ---------------- シミュレータ領域 */
.sim {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 20px;
  margin: 20px auto 28px;
  align-items: start;
}
.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
}
.controls h2 {
  font-size: 1.05rem;
  margin: 0 0 10px;
  padding: 0;
}
.controls .field {
  margin-bottom: 12px;
}
.controls label {
  display: block;
  font-size: 0.86rem;
  color: var(--text-2);
  margin-bottom: 2px;
}
.controls label .val {
  float: right;
  color: var(--text-1);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.controls select,
.controls input[type='number'] {
  width: 100%;
  font: inherit;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-1);
}
.controls input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}
.controls .hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 2px 0 0;
  line-height: 1.5;
}
.controls .type-desc {
  font-size: 0.84rem;
  color: var(--text-2);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 6px 0 12px;
  line-height: 1.6;
}
.controls .seed-row {
  display: flex;
  gap: 6px;
}
.controls .seed-row input {
  flex: 1;
}
.controls .btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}
.controls .btn-row .primary {
  flex: 1 1 100%;
}
.controls .checks label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-1);
  font-size: 0.86rem;
  margin: 4px 0;
}
.controls .checks input {
  accent-color: var(--accent);
}
.controls hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}
#share-status {
  font-size: 0.78rem;
  color: var(--text-2);
  word-break: break-all;
  min-height: 1.2em;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.verdict {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 1.02rem;
  box-shadow: var(--shadow);
}
.verdict strong {
  color: var(--accent);
}
.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.card .label {
  font-size: 0.78rem;
  color: var(--text-2);
  line-height: 1.4;
}
.card .value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 4px 0 2px;
  font-variant-numeric: tabular-nums;
}
.card .sub {
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.card.accent-friend .value {
  color: var(--c-friend);
}
.card.accent-self .value {
  color: var(--c-self);
}
.extra {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0 4px;
}

.canvas-wrap {
  position: relative;
  background: var(--chart-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
#net {
  display: block;
  width: 100%;
  height: 520px;
  touch-action: none;
}
.legend {
  position: absolute;
  left: 10px;
  top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 0.8rem;
  color: var(--text-2);
  background: color-mix(in srgb, var(--chart-surface) 80%, transparent);
  padding: 4px 8px;
  border-radius: 8px;
  pointer-events: none;
}
.legend .sw {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -1px;
}
.sw-friend {
  background: var(--c-friend);
}
.sw-self {
  background: var(--c-self);
}
.sw-tie {
  background: var(--c-tie);
}
.canvas-help {
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-size: 0.76rem;
  color: var(--text-muted);
  pointer-events: none;
}
.ego {
  position: absolute;
  right: 10px;
  top: 10px;
  max-width: min(340px, 70%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.86rem;
  line-height: 1.6;
  box-shadow: var(--shadow);
}
.ego-head {
  margin-bottom: 4px;
}
.ego-actions {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.ego-actions button {
  font-size: 0.8rem;
  padding: 4px 8px;
}
.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  margin-left: 4px;
}
.pill-friend {
  background: var(--c-friend);
}
.pill-self {
  background: var(--c-self);
}
.pill-tie {
  background: var(--c-tie);
}

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}
.charts figure,
.panel {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.charts figcaption,
.panel h3 {
  font-weight: 700;
  font-size: 0.98rem;
  margin: 0 0 4px;
}
.charts .caption-sub,
.panel .lead {
  font-size: 0.82rem;
  color: var(--text-2);
  margin: 0 0 8px;
  line-height: 1.55;
}
.charts canvas,
.panel canvas {
  display: block;
  width: 100%;
  height: 280px;
}
.panel .row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
}
.panel .row label {
  font-size: 0.86rem;
  color: var(--text-2);
}
.panel .row input[type='range'] {
  accent-color: var(--accent);
}
.panel .row label strong {
  font-variant-numeric: tabular-nums;
}
.panel .verdict {
  margin: 8px 0;
  padding: 8px 12px;
  box-shadow: none;
}
.panel .row input[type='number'] {
  width: 72px;
  font: inherit;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-1);
}
.status {
  font-size: 0.82rem;
  color: var(--text-2);
  margin: 6px 0;
}
.fs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin: 6px 0 8px;
}
.fs-grid div {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text-2);
  line-height: 1.4;
}
.fs-grid strong {
  display: block;
  font-size: 1.2rem;
  color: var(--text-1);
  font-variant-numeric: tabular-nums;
}
table.stats {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  margin: 6px 0;
}
table.stats th,
table.stats td {
  text-align: right;
  padding: 5px 8px;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}
table.stats th[scope='row'] {
  text-align: left;
  font-weight: 500;
  color: var(--text-2);
}
table.stats thead th {
  color: var(--text-muted);
  font-weight: 600;
}
table.stats thead th:first-child {
  text-align: left;
}
.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
}
.two-col canvas {
  height: 260px;
}

/* ---------------- 解説セクション */
.prose {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 0 auto 22px;
  box-shadow: var(--shadow);
  max-width: 980px;
}
.prose h2 {
  border-bottom: 2px solid var(--grid);
  padding-bottom: 6px;
}
.prose ul,
.prose ol {
  padding-left: 1.4em;
  margin: 4px 0 10px;
}
.prose li {
  margin: 2px 0;
}
.callout {
  background: var(--surface-2);
  border-left: 4px solid var(--c-3);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 12px 0;
  font-size: 0.95rem;
}
.callout.warn {
  border-left-color: var(--c-4);
}
.formula {
  text-align: center;
  font-size: 1.1rem;
  margin: 10px 0;
  font-family: 'STIX Two Math', 'Cambria Math', 'Latin Modern Math', 'Times New Roman', serif;
}
.formula .frac {
  display: inline-block;
  vertical-align: middle;
  text-align: center;
}
.formula .frac span {
  display: block;
  padding: 0 4px;
}
.formula .frac span:first-child {
  border-bottom: 1px solid currentColor;
}
table.mini {
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 8px 0 12px;
}
table.mini th,
table.mini td {
  border: 1px solid var(--grid);
  padding: 4px 10px;
  text-align: center;
}
table.mini th {
  background: var(--surface-2);
  font-weight: 600;
}
.metric-list dt {
  font-weight: 700;
  margin-top: 8px;
}
.metric-list dd {
  margin: 0 0 4px 0;
  color: var(--text-2);
}
.presets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin: 12px 0;
}
.preset-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.preset-card h3 {
  margin: 0;
  font-size: 0.98rem;
}
.preset-card p {
  font-size: 0.86rem;
  color: var(--text-2);
  margin: 0;
  flex: 1;
}
.preset-card button {
  align-self: flex-start;
}
.model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin: 10px 0;
}
.model-grid div {
  border: 1px solid var(--grid);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.88rem;
}
.model-grid strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.95rem;
}
.model-grid em {
  font-style: normal;
  font-weight: 600;
  color: var(--text-2);
}
.model-grid div {
  line-height: 1.6;
}
.site-footer {
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 10px 0 30px;
  text-align: center;
}

/* ---------------- ツールチップ */
.tooltip {
  position: fixed;
  z-index: 50;
  background: var(--text-1);
  color: var(--bg);
  font-size: 0.8rem;
  line-height: 1.5;
  padding: 6px 10px;
  border-radius: 8px;
  pointer-events: none;
  max-width: 260px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}
.tooltip .tip-status {
  opacity: 0.85;
}

/* ---------------- レスポンシブ */
@media (max-width: 920px) {
  .sim {
    grid-template-columns: 1fr;
  }
  .controls {
    position: static;
    max-height: none;
  }
  #net {
    height: 420px;
  }
}
@media (max-width: 520px) {
  body {
    font-size: 14px;
  }
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .card .value {
    font-size: 1.3rem;
  }
  #net {
    height: 360px;
  }
  .charts canvas,
  .panel canvas {
    height: 240px;
  }
  .prose {
    padding: 14px 16px;
  }
  .ego {
    max-width: 85%;
  }
}
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
