@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
	--bg-primary: #fdfbf7;
	--bg-secondary: #ffffff;
	--bg-tertiary: #f8f6f0;
	--accent-color: #ea580c;
	--accent-hover: #c2410c;
	--accent-light: rgba(234, 88, 12, 0.08);

	--text-primary: #1e1b18;
	--text-secondary: #4a443f;
	--text-muted: #8f8178;

	--border-color: #ebdcd2;
	--border-strong: #dcc8b9;
	--border-focus: #fb923c;

	--success-color: #059669;
	--error-color: #be123c;

	--font-title: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
	--font-body: "Outfit", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;

	--shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
	--shadow-md: 0 4px 10px -2px rgba(15, 23, 42, 0.08);
	--shadow-lg: 0 12px 24px -6px rgba(15, 23, 42, 0.16);

	--radius-sm: 10px;
	--radius-md: 12px;
	--radius-pill: 999px;
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	font-family: var(--font-body);
	background: linear-gradient(180deg, #fffaf2 0%, var(--bg-primary) 100%);
	color: var(--text-secondary);
	line-height: 1.6;
	-webkit-font-smoothing: antialiased;
}

a,
a:visited {
	color: var(--accent-color);
}

a:hover,
a:focus-visible {
	color: var(--border-focus);
}

.page-shell {
	width: 100%;
	margin: 0;
	padding: 1rem 1.25rem 1.5rem;
}

.landing-shell {
	max-width: 960px;
	margin: 0 auto;
}

.landing-hero {
	margin-bottom: 1.5rem;
}

.eyebrow {
	margin: 0 0 0.5rem;
	font-size: 0.8rem;
	font-weight: 700;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--accent-color);
}

.hero-copy {
	margin: 0.8rem 0 0;
	font-size: 1.05rem;
	max-width: 42rem;
}

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

.landing-card {
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
	padding: 1.25rem;
	background: linear-gradient(180deg, #ffffff 0%, #fffaf5 100%);
	border: 1px solid var(--border-color);
	border-radius: var(--radius-md);
	box-shadow: var(--shadow-sm);
	text-decoration: none;
	color: var(--text-primary);
	transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.landing-card:hover,
.landing-card:focus-visible {
	transform: translateY(-2px);
	border-color: var(--border-focus);
	box-shadow: var(--shadow-md);
}

.card-kicker {
	font-size: 0.72rem;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	font-weight: 700;
	color: var(--accent-color);
}

.landing-card h2 {
	margin: 0;
	font-family: var(--font-title);
	font-size: clamp(1.5rem, 2vw, 2rem);
	color: var(--accent-color);
	transition: color 0.2s ease;
}

.landing-card:hover h2,
.landing-card:focus-visible h2 {
	color: var(--accent-hover);
}

.landing-card p {
	margin: 0;
	color: var(--text-secondary);
}

.card-link {
	margin-top: auto;
	font-weight: 700;
	color: var(--accent-color);
}

.subnav {
	display: flex;
	gap: 0.75rem;
	flex-wrap: wrap;
	margin: 0 0 1rem;
}

.explore-placeholder {
	padding: 1rem 0;
	color: var(--text-secondary);
}

.hero h1 {
	margin: 0 0 1rem;
	font-size: clamp(1.6rem, 2vw, 2.2rem);
	font-family: var(--font-title);
	font-weight: 700;
	letter-spacing: -0.02em;
	background: linear-gradient(to right, var(--accent-color), #f59e0b);
	-webkit-background-clip: text;
	-webkit-text-fill-color: transparent;
}

.panel {
	background: transparent;
	border: 0;
	border-radius: 0;
	padding: 0;
	box-shadow: none;
}

.panel-header h2 {
	margin: 0;
	font-family: var(--font-title);
	font-weight: 600;
	color: var(--text-primary);
}

.panel-header p {
	margin: 0.4rem 0 1rem;
	color: var(--text-secondary);
}

.search-form {
	display: grid;
	gap: 0.75rem;
}

.compare-grid {
	display: grid;
	gap: 0.75rem;
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
	display: grid;
	gap: 0.35rem;
}

.field-picker {
	position: relative;
}

.field span {
	font-size: 0.9rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--text-secondary);
}

.field input {
	width: 100%;
	border: 1px solid var(--border-color);
	background: var(--bg-primary);
	color: var(--text-primary);
	border-radius: var(--radius-sm);
	padding: 0.65rem 0.75rem;
	font-size: 0.95rem;
	font-family: var(--font-body);
	transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.field input:focus {
	outline: none;
	border-color: var(--border-focus);
	box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.15);
}

.picker-menu {
	position: absolute;
	left: 0;
	right: 0;
	top: calc(100% + 0.2rem);
	background: linear-gradient(180deg, #ffffff 0%, #fffaf5 100%);
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-md);
	box-shadow: var(--shadow-lg);
	max-height: 240px;
	overflow: auto;
	z-index: 30;
	display: none;
	opacity: 0;
	transform: translateY(-2px);
	transition: opacity 120ms ease, transform 120ms ease;
}

.picker-menu.is-open {
	display: block;
	opacity: 1;
	transform: translateY(0);
}

.picker-option {
	width: 100%;
	border: 0;
	background: transparent;
	text-align: left;
	padding: 0.62rem 0.78rem;
	font-size: 0.9rem;
	font-family: inherit;
	color: var(--text-primary);
	cursor: pointer;
	border-bottom: 1px solid var(--border-color);
}

.picker-option:last-child {
	border-bottom: 0;
}

.picker-option:hover,
.picker-option.is-active {
	background: var(--accent-light);
}

.picker-message {
	padding: 0.62rem 0.78rem;
	font-size: 0.86rem;
	color: var(--text-muted);
}

.picker-message.is-error {
	color: var(--error-color);
}

.actions {
	display: flex;
	gap: 0.6rem;
	flex-wrap: wrap;
}

.button {
	border: 1px solid var(--accent-color);
	background: var(--accent-color);
	color: #ffffff;
	border-radius: var(--radius-pill);
	padding: 0.55rem 1rem;
	cursor: pointer;
	font-family: var(--font-body);
	font-weight: 600;
	transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.button:hover:not(:disabled) {
	background: var(--accent-hover);
	transform: translateY(-1px);
	box-shadow: var(--shadow-sm);
}

.button-secondary {
	background: var(--bg-secondary);
	color: var(--text-primary);
	border-color: var(--border-color);
}

.button-secondary:hover:not(:disabled) {
	background: var(--bg-tertiary);
	border-color: var(--text-muted);
}

.status {
	min-height: 1.2rem;
	margin: 0.65rem 0;
	font-size: 0.92rem;
	color: var(--text-secondary);
}

.results-grid {
	display: grid;
	gap: 1rem;
	grid-template-columns: 1fr;
}

.results-card {
	background: transparent;
	border: 0;
	border-radius: 0;
	padding: 0;
	min-width: 0;
}

.results-card-header h3 {
	margin: 0;
	font-family: var(--font-title);
	font-weight: 600;
	color: var(--text-primary);
}

.results-card-header p {
	margin: 0.35rem 0 0.7rem;
	color: var(--text-secondary);
}

.statistics-output {
	width: 100%;
}

.statistics-grid {
	display: grid;
	gap: 0.75rem;
	grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
	grid-auto-rows: 180px;
}

.stat-box {
	background: linear-gradient(180deg, #ffffff 0%, #fffaf5 100%);
	border: 1px solid var(--border-color);
	border-radius: var(--radius-md);
	padding: 0.9rem;
	height: 100%;
	min-height: 0;
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: 0.35rem;
	overflow: hidden;
	box-shadow: var(--shadow-sm);
}

.stat-box-value {
	font-size: clamp(1.75rem, 3vw, 2.2rem);
	font-weight: 700;
	line-height: 1.05;
	color: var(--text-primary);
}

.stat-box-subtitle {
	font-size: 0.9rem;
	color: var(--text-secondary);
	line-height: 1.3;
	overflow: hidden;
}

.stat-box-title {
	font-size: 0.92rem;
	font-weight: 700;
	color: var(--text-primary);
}

.provenance-output {
	display: flex;
	flex-wrap: wrap;
	gap: 0.8rem;
	width: 100%;
	min-height: 160px;
	max-height: none;
	overflow: visible;
	align-items: start;
}

.provenance-output > * {
	flex: 1 1 320px;
}

#provenance-output .ranking-section {
	flex: 1 1 100%;
	max-height: none;
	overflow: visible;
}

.shared-owner-pair-layout {
	display: grid;
	grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
	gap: 1rem;
	align-items: start;
	width: 100%;
}

.shared-owner-sankey-panel,
.shared-owner-list-panel {
	min-width: 0;
}

.shared-owner-list-panel {
	max-height: 800px;
	overflow-y: auto;
}

.shared-owner-sankey-panel {
	display: flex;
	flex-direction: column;
	gap: 0.45rem;
}

.shared-owner-sankey-chart-wrapper {
	min-height: 700px;
	width: 100%;
}

#owner-lists-output {
	min-height: 120px;
}

.owner-list-section,
.ranking-section {
	background: var(--bg-secondary);
	border: 1px solid var(--border-color);
	border-radius: var(--radius-md);
	padding: 0.75rem;
	min-width: 0;
	max-height: none;
	overflow: visible;
	box-shadow: var(--shadow-sm);
}

.owner-list-title,
.ranking-title {
	margin: 0 0 0.35rem;
}

.owner-list-subtitle,
.comparison-summary {
	margin: 0 0 0.55rem;
	color: var(--text-muted);
	font-size: 0.88rem;
}

.ranking-controls {
	margin: 0 0 0.65rem;
}

.ranking-sort-label {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	font-size: 0.9rem;
	color: var(--text-secondary);
}

.ranking-sort-select {
	border: 1px solid var(--border-color);
	border-radius: 8px;
	padding: 0.35rem 0.5rem;
	font-size: 0.88rem;
	background: var(--bg-primary);
	color: var(--text-primary);
}

.owner-list,
.shared-owner-list {
	margin: 0;
	padding-left: 1.1rem;
	display: grid;
	gap: 0.45rem;
	list-style-position: inside;
	max-height: 800px;
	overflow-y: auto;
}

.owner-list-item,
.shared-owner-item {
	position: relative;
	padding: 0.5rem;
	border: 1px solid var(--border-color);
	border-radius: 8px;
	background: linear-gradient(180deg, #ffffff 0%, #fffcf8 100%);
}

.owner-list-bookids-hint {
	margin-top: 0.25rem;
	font-size: 0.82rem;
	color: var(--text-secondary);
	text-decoration: underline;
	text-decoration-style: dotted;
	cursor: pointer;
}

.bookids-popup {
	display: none;
	position: absolute;
	left: 0.45rem;
	right: 0.45rem;
	top: calc(100% + 0.35rem);
	z-index: 50;
	border: 1px solid rgba(245, 158, 11, 0.25);
	border-radius: 10px;
	background: rgba(43, 27, 16, 0.98);
	box-shadow: var(--shadow-lg);
	padding: 0.55rem;
	color: #faf7f5;
}

.bookids-popup.is-open {
	display: block;
}

.bookids-popup-title {
	font-size: 0.82rem;
	font-weight: 700;
	margin-bottom: 0.25rem;
	color: #fb923c;
}

.bookids-popup-body {
	font-size: 0.8rem;
	line-height: 1.35;
	color: #ffedd5;
	white-space: pre-wrap;
	max-height: 10rem;
	overflow: auto;
	word-break: break-word;
}

.owner-list-heading,
.shared-owner-title {
	font-weight: 600;
	margin-bottom: 0.25rem;
	color: var(--accent-color);
}

.owner-list-row,
.shared-owner-row {
	font-size: 0.9rem;
	color: var(--text-secondary);
}

.comparison-pair {
	margin: 0.75rem 0 0.35rem;
	color: var(--text-primary);
}

.ranking-output {
	margin: 0;
	white-space: pre-wrap;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
	color: var(--text-primary);
}

.sankey-tooltip,
.stats-tooltip {
	--tooltip-surface: rgba(43, 27, 16, 0.98);
	--tooltip-text: #faf7f5;
	--tooltip-accent: #fb923c;
	--tooltip-highlight: #fbbf24;
}

.sankey-tooltip {
	position: fixed;
	left: 0;
	top: 0;
	z-index: 1200;
	max-width: 320px;
	padding: 0.5rem 0.6rem;
	border: 1px solid rgba(245, 158, 11, 0.25);
	border-radius: var(--radius-sm);
	background: var(--tooltip-surface);
	box-shadow: var(--shadow-lg);
	color: var(--tooltip-text);
	font-size: 0.82rem;
	line-height: 1.3;
	pointer-events: none;
	opacity: 0;
	transform: translate3d(0, 0, 0);
	transition: opacity 120ms ease;
}

.sankey-tooltip .t-val {
  margin-top: 0.2rem;
  color: var(--tooltip-highlight);
  font-weight: 600;
}

.sankey-tooltip .tooltip-formula,
.stats-tooltip .tooltip-formula {
	font-family: monospace;
	background: rgba(255, 255, 255, 0.08);
	padding: 0.4rem 0.6rem;
	border-radius: 6px;
	margin: 0.5rem 0;
	color: var(--tooltip-accent);
	font-size: 0.825rem;
	line-height: 1.4;
	word-break: normal;
	word-wrap: break-word;
	white-space: pre-wrap;
	border-left: 3px solid var(--tooltip-accent);
}

.sankey-tooltip .tooltip-highlight,
.stats-tooltip .tooltip-highlight {
	color: var(--tooltip-highlight);
	font-weight: 600;
}

.sankey-tooltip .tooltip-section-title,
.stats-tooltip .tooltip-section-title {
	font-weight: 700;
	color: var(--tooltip-accent);
	font-size: 1.05rem;
	margin-bottom: 0.4rem;
	border-bottom: 1px solid rgba(245, 158, 11, 0.25);
	padding-bottom: 0.3rem;
}

.bookids-popup .tooltip-highlight {
	color: #fbbf24;
	font-weight: 600;
}

@media (max-width: 980px) {
	.results-grid {
		grid-template-columns: 1fr;
	}

	.shared-owner-pair-layout {
		grid-template-columns: 1fr;
	}

	.provenance-output {
		max-height: none;
	}

	.owner-list-section,
	.ranking-section {
		max-height: none;
	}
}

@media (max-width: 700px) {
	.compare-grid,
	.landing-grid {
		grid-template-columns: 1fr;
	}
}