:root {
    --ink: #26343b;
    --muted: #68777b;
    --paper: #eee9df;
    --paper-light: #f8f5ee;
    --panel: #fffdf8;
    --line: #c9c0ae;
    --blue: #2c5d76;
    --blue-deep: #1f4357;
    --rust: #a34734;
    --green: #557762;
    --shadow: 0 8px 24px rgba(31, 46, 52, 0.09);
}

* { box-sizing: border-box; }

body {
    min-width: 320px;
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
    line-height: 1.55;
}

button, input, select { font: inherit; }
button, select, input[type="range"] { cursor: pointer; }
a { color: var(--blue); }

.site-header {
    display: flex;
    justify-content: space-between;
    gap: 28px;
    padding: 28px clamp(20px, 5vw, 72px) 24px;
    color: #f9f6ed;
    background: #213944;
    border-bottom: 4px solid var(--rust);
}

.site-header h1 { margin: 0; font-size: clamp(1.7rem, 3vw, 2.7rem); letter-spacing: 0.07em; }
.subtitle { max-width: 780px; margin: 6px 0 0; color: #c9d6d8; overflow-wrap: anywhere; }
.eyebrow { margin: 0 0 5px; color: var(--rust); font: 700 0.68rem/1.2 Consolas, monospace; letter-spacing: 0.16em; }
.site-header .eyebrow { color: #abc6ce; }
.header-actions { display: grid; gap: 8px; align-self: center; }
.header-stamp { align-self: center; min-width: 145px; padding: 10px 12px; color: #cad8da; border: 1px solid #718b93; text-align: center; font: 700 0.67rem/1.45 Consolas, monospace; letter-spacing: 0.12em; }
.header-stamp span, .header-stamp small { display: block; }
.help-button { min-height: 32px; color: #f7f3e9; background: transparent; border-color: #91a7ad; font-size: 0.75rem; font-weight: 700; }
.help-button:hover { background: rgba(255, 255, 255, 0.1); }

.app-shell {
    display: grid;
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    gap: 22px;
    width: min(1680px, calc(100% - 32px));
    margin: 20px auto;
    align-items: start;
}

.control-panel { position: sticky; top: 12px; overflow: hidden; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.panel-section { padding: 17px 18px; border-bottom: 1px solid var(--line); }
.panel-section:last-child { border-bottom: 0; }
.section-heading { display: flex; align-items: baseline; gap: 9px; margin-bottom: 13px; }
.section-heading span { color: var(--rust); font: 700 0.7rem Consolas, monospace; }
.section-heading h2 { margin: 0; font-size: 0.95rem; letter-spacing: 0.06em; }

label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 0.75rem; font-weight: 700; }
output { float: right; color: var(--blue); font: 700 0.76rem Consolas, monospace; }
input[type="range"] { width: 100%; }
input[type="search"], select { width: 100%; min-height: 39px; padding: 7px 9px; color: var(--ink); background: #fff; border: 1px solid #a9b0af; border-radius: 2px; }
button { min-height: 38px; padding: 7px 11px; color: var(--blue-deep); background: #f8faf9; border: 1px solid #7c9299; border-radius: 2px; }
button:hover { background: #e8f0f1; }
button:focus-visible, input:focus-visible, select:focus-visible, canvas:focus-visible { box-shadow: 0 0 0 3px rgba(44, 93, 118, 0.35); }
.primary-button { color: #fff; background: var(--blue); border-color: var(--blue); font-weight: 700; }
.primary-button:hover { background: var(--blue-deep); }
.secondary-button { background: transparent; }
.text-button { min-height: 30px; color: var(--rust); background: transparent; border-color: transparent; }
.button-stack { display: grid; gap: 8px; margin-top: 14px; }
.field-note { margin: 8px 0 0; color: var(--muted); font-size: 0.72rem; }

.year-fields { display: grid; gap: 3px; }
.year-fields input + label { margin-top: 7px; }
.preset-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 12px; }
.preset-row button { min-height: 28px; padding: 3px 7px; font: 700 0.66rem Consolas, monospace; }

.layer-controls { display: grid; gap: 12px; }
.layer-row { display: grid; grid-template-columns: 1fr 35px; gap: 3px 8px; align-items: center; }
.layer-row > input[type="range"] { grid-column: 1 / -1; }
.layer-toggle { display: flex; gap: 7px; align-items: center; margin: 0; color: var(--ink); font-size: 0.78rem; }
.layer-toggle input:disabled ~ span { color: #8b9391; opacity: 0.7; }
.layer-row input:disabled + .layer-swatch { opacity: 0.4; }
.layer-row input[type="range"]:disabled { cursor: not-allowed; opacity: 0.45; }
.layer-swatch { width: 10px; height: 10px; background: #3b6f8f; border-radius: 50%; }
.check-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; color: var(--ink); font-size: 0.78rem; }
.removal-controls { display: grid; gap: 8px; background: #f0ebe1; }
.removal-controls .section-heading { margin-bottom: 4px; }

.workspace { display: grid; min-width: 0; gap: 17px; }
.overview-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.overview-strip div { padding: 11px 14px; border-right: 1px solid var(--line); }
.overview-strip div:last-child { border-right: 0; }
.overview-strip span { display: block; color: var(--muted); font-size: 0.68rem; }
.overview-strip strong { color: var(--blue-deep); font: 700 1.2rem Consolas, monospace; }

.graph-card, .timeline-card, .list-card, .ranking-card, .detail-card, .method-card, .removal-card { background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.graph-heading, .card-heading { display: flex; justify-content: space-between; gap: 16px; align-items: end; padding: 12px 15px; border-bottom: 1px solid var(--line); }
.graph-heading h2, .card-heading h2 { margin: 0; font-size: 1rem; letter-spacing: 0.04em; }
.graph-heading .eyebrow { margin-bottom: 2px; }
.graph-status, .card-heading span { margin: 0; color: var(--muted); text-align: right; font-size: 0.7rem; }
.canvas-wrap { position: relative; overflow: hidden; background: var(--paper-light); }
#networkCanvas { display: block; width: 100%; height: clamp(480px, 62vh, 720px); touch-action: none; }
.canvas-help { position: absolute; right: 8px; bottom: 8px; padding: 4px 7px; color: #607074; background: rgba(255, 253, 248, 0.88); border: 1px solid rgba(132, 137, 131, 0.5); font-size: 0.64rem; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 17px; padding: 9px 14px; color: var(--muted); border-top: 1px solid var(--line); font-size: 0.68rem; }
.legend span { display: flex; gap: 6px; align-items: center; }
.legend i { display: inline-block; width: 16px; height: 3px; background: #3b6f8f; }
.legend .uncertain-line { background: repeating-linear-gradient(90deg, #667 0 4px, transparent 4px 7px); }

.timeline-card { overflow: hidden; }
.year-histogram { display: grid; grid-template-columns: repeat(61, minmax(3px, 1fr)); gap: 1px; height: 116px; padding: 12px 13px 7px; align-items: end; }
.year-bar { display: grid; height: 100%; grid-template-rows: 1fr 15px; align-items: end; }
.year-bar i { width: 100%; height: 2%; min-height: 2px; background: #bac2be; transition: height 0.2s ease, background 0.2s ease; }
.year-bar.active i { background: var(--blue); }
.year-bar small { overflow: visible; color: var(--muted); font: 0.52rem Consolas, monospace; transform: translateX(-4px); }

.information-grid { display: grid; grid-template-columns: minmax(220px, 0.8fr) minmax(230px, 0.9fr) minmax(330px, 1.5fr); gap: 17px; align-items: start; }
.list-card, .ranking-card, .detail-card { min-width: 0; }
.search-label { padding: 11px 13px 0; }
.list-card input[type="search"] { width: calc(100% - 26px); margin: 0 13px 10px; }
.person-list { max-height: 420px; overflow: auto; border-top: 1px solid #ded8cc; }
.person-list button { display: flex; width: 100%; min-height: 34px; justify-content: space-between; gap: 10px; padding: 7px 12px; text-align: left; background: transparent; border: 0; border-bottom: 1px solid #e7e1d6; }
.person-list button[aria-selected="true"] { color: #fff; background: var(--blue); }
.person-list small { flex: 0 0 auto; font: 0.68rem Consolas, monospace; }

.ranking-list { margin: 0; padding: 0; list-style: none; }
.ranking-list button { display: grid; width: 100%; min-height: 37px; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; padding: 7px 12px; text-align: left; background: transparent; border: 0; border-bottom: 1px solid #e7e1d6; }
.rank-number { color: var(--rust); font: 700 0.68rem Consolas, monospace; }
.ranking-list strong { color: var(--blue); font: 700 0.7rem Consolas, monospace; }

.detail-panel { padding: 15px 16px 18px; }
.detail-panel h3, .detail-panel h4, .detail-panel p { margin-top: 0; }
.detail-panel h4 { margin: 18px 0 8px; font-size: 0.8rem; letter-spacing: 0.05em; }
.person-title { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.person-title h3 { margin-bottom: 2px; font-size: 1.15rem; }
.person-title span, .latin-name, .selection-note { color: var(--muted); font-size: 0.72rem; }
.latin-name { margin-bottom: 12px; font-family: Georgia, serif; font-style: italic; }
.person-description { margin: 11px 0 8px; padding: 10px 12px; color: var(--ink); background: #f0ebe1; border-left: 3px solid var(--blue); font-size: 0.82rem; }
.source-links { font-size: 0.74rem; }
.metric-table { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 12px 0; border: 1px solid var(--line); }
.metric-table div { padding: 8px 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.metric-table div:nth-child(2n) { border-right: 0; }
.metric-table div:nth-last-child(-n+2) { border-bottom: 0; }
.metric-table dt { color: var(--muted); font-size: 0.66rem; }
.metric-table dd { margin: 2px 0 0; color: var(--blue); font: 700 0.9rem Consolas, monospace; }
.connection-list { display: grid; gap: 5px; }
.connection-list button { display: flex; justify-content: space-between; gap: 9px; min-height: 31px; padding: 5px 8px; text-align: left; }
.connection-list strong { font: 700 0.7rem Consolas, monospace; }
.relation-title { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 12px; }
.relation-title button { font-weight: 700; }
.weight-table { width: 100%; border-collapse: collapse; font-size: 0.7rem; }
.weight-table th, .weight-table td { padding: 5px 6px; border: 1px solid var(--line); text-align: right; }
.weight-table th:first-child { text-align: left; }
.source-list { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.source-list li { padding: 7px 8px; background: #f4f1e9; border-left: 3px solid var(--blue); font-size: 0.72rem; }
.source-list span, .source-list small { display: block; }
.source-list small { margin-top: 3px; color: var(--muted); }
.empty-state { margin: 12px; color: var(--muted); font-size: 0.76rem; }

.removal-card { overflow: hidden; border-color: #b78c7f; }
.comparison-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.comparison-grid div { padding: 12px 14px; border-right: 1px solid var(--line); }
.comparison-grid div:last-child { border-right: 0; }
.comparison-grid span { display: block; color: var(--muted); font-size: 0.66rem; }
.comparison-grid strong { color: var(--rust); font: 700 1rem Consolas, monospace; }
.removal-card > p { margin: 0; padding: 0 14px 12px; color: var(--muted); font-size: 0.72rem; }

.method-card { padding: 0; }
.method-card summary { cursor: pointer; padding: 13px 15px; color: var(--blue-deep); font-weight: 700; }
.method-content { padding: 0 17px 17px; color: #4d5d61; font-size: 0.76rem; }
.research-paper summary { border-top: 2px solid var(--rust); }
.paper-content { max-width: 1040px; font-size: 0.79rem; line-height: 1.75; }
.paper-content header { padding-bottom: 9px; border-bottom: 1px solid var(--line); }
.paper-content h2 { margin: 3px 0 12px; color: var(--blue-deep); font-size: 1.15rem; line-height: 1.45; }
.paper-content h3 { margin: 22px 0 7px; padding-bottom: 4px; color: var(--blue-deep); border-bottom: 1px solid var(--line); font-size: 0.92rem; }
.paper-content p { margin: 8px 0; }
.paper-content .formula { margin: 12px 0; padding: 9px 12px; color: var(--ink); background: #f0ebe1; border-left: 3px solid var(--rust); font-family: Georgia, serif; font-size: 0.92rem; text-align: center; }
.paper-references { margin: 7px 0 0; padding-left: 24px; }
.paper-references li { margin: 6px 0; }
.audit-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); margin: 13px 0; border: 1px solid var(--line); }
.audit-grid div { padding: 7px; border-right: 1px solid var(--line); text-align: center; }
.audit-grid div:last-child { border-right: 0; }
.audit-grid span, .audit-grid strong { display: block; }
.audit-grid span { color: var(--muted); font-size: 0.63rem; }
.audit-grid strong { font: 700 0.85rem Consolas, monospace; }
.license-note { padding: 8px 10px; background: #f0ebe1; border-left: 3px solid var(--rust); }

.help-dialog { width: min(680px, calc(100% - 28px)); max-height: calc(100vh - 40px); padding: 0; overflow: auto; color: var(--ink); background: var(--panel); border: 1px solid var(--line); box-shadow: 0 18px 60px rgba(20, 34, 40, 0.3); }
.help-dialog::backdrop { background: rgba(25, 38, 44, 0.66); }
.help-dialog form { margin: 0; }
.help-heading { display: flex; justify-content: space-between; gap: 18px; align-items: start; padding: 17px 19px 14px; color: #f8f4eb; background: #213944; border-bottom: 3px solid var(--rust); }
.help-heading h2 { margin: 0; font-size: 1.2rem; }
.help-heading button { min-height: 31px; color: #fff; background: transparent; border-color: #91a7ad; }
.help-steps { display: grid; gap: 12px; margin: 0; padding: 19px 28px 17px 47px; }
.help-steps li { padding-left: 3px; font-size: 0.82rem; }
.help-steps strong { display: block; color: var(--blue-deep); }
.help-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 15px; margin: 0 19px; padding: 13px 15px; background: #f0ece3; border: 1px solid var(--line); font-size: 0.72rem; }
.help-controls kbd { display: inline-block; min-width: 62px; margin-right: 4px; padding: 2px 5px; color: var(--blue-deep); background: #fff; border: 1px solid #aab2b0; border-radius: 2px; text-align: center; font: 700 0.68rem Consolas, monospace; }
.help-caveat { margin: 15px 19px 19px; padding: 9px 11px; color: var(--muted); background: #f8f1e9; border-left: 3px solid var(--rust); font-size: 0.72rem; }

.site-footer { display: flex; justify-content: space-between; gap: 20px; width: min(1680px, calc(100% - 32px)); margin: 0 auto; padding: 4px 0 25px; color: var(--muted); font-size: 0.7rem; }
.back-link { font-weight: 700; }

@media (max-width: 1180px) {
    .information-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .detail-card { grid-column: 1 / -1; }
    .comparison-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .comparison-grid div { border-bottom: 1px solid var(--line); }
}

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; width: min(100% - 20px, 780px); margin-top: 10px; }
    .control-panel { position: static; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .panel-section { border-right: 1px solid var(--line); }
    .overview-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .overview-strip div { border-bottom: 1px solid var(--line); }
    #networkCanvas { height: min(70vh, 620px); }
    .audit-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .audit-grid div { border-bottom: 1px solid var(--line); }
}

@media (max-width: 620px) {
    .site-header { flex-wrap: wrap; padding: 22px 16px 18px; }
    .header-stamp, .canvas-help { display: none; }
    .header-actions { width: 100%; align-self: start; justify-items: start; }
    .help-button { min-width: 72px; }
    .control-panel, .information-grid { grid-template-columns: 1fr; }
    .panel-section { border-right: 0; }
    .detail-card { grid-column: auto; }
    .overview-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .overview-strip div:nth-child(2n) { border-right: 0; }
    .graph-heading, .card-heading { align-items: start; }
    #networkCanvas { height: 520px; }
    .comparison-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric-table { grid-template-columns: 1fr; }
    .metric-table div { border-right: 0; }
    .metric-table div:nth-last-child(2) { border-bottom: 1px solid var(--line); }
    .site-footer { display: block; width: calc(100% - 20px); }
    .site-footer span { display: block; margin-top: 6px; }
    .help-controls { grid-template-columns: 1fr; }
}
