:root {
	--bg-primary: #0a0a0a;
	--bg-secondary: #141414;
	--bg-surface: #1f1f1f;
	--text-primary: #f0f0f0;
	--text-secondary: #a0a0a0;
	--accent: #22c55e;
	--accent-hover: #16a34a;
	--border: #333333;
	--grid-line: #333333;
}

* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

body {
	font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
	background: var(--grid-line);
	/* Color of the gaps */
	color: var(--text-primary);
	line-height: 1.5;
	height: 100vh;
	width: 100vw;
	overflow: hidden;
	display: grid;
	grid-template-columns: 600px 1fr 1fr 1fr;
	grid-template-rows: auto 240px 1fr;
	grid-template-areas:
		"authors header header header"
		"authors distribution classes schools"
		"authors spells spells spells";
	gap: 1px;
}

/* Global Reset for Rounded Corners */
* {
	border-radius: 0 !important;
}

/* Regions */
.region {
	background: var(--bg-primary);
	overflow: auto;
	display: flex;
	flex-direction: column;
	position: relative;
	padding: 1rem;
}

header {
	grid-area: header;
	background: var(--bg-secondary);
	padding: 1rem 1.5rem;
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 1px solid var(--border);
}

#region-authors {
	grid-area: authors;
	border-right: 1px solid var(--border);
	overflow: hidden;
	padding: 0;
}

#region-distribution {
	grid-area: distribution;
}

#region-classes {
	padding: 0px;
	grid-area: classes;
}

#region-schools {
	padding: 0px;
	grid-area: schools;
}

#region-spells {
	grid-area: spells;
}

/* Typography */
h1 {
	font-size: 1.5rem;
	font-weight: 400;
	letter-spacing: -0.02em;
	color: var(--text-primary);
}

#overview {
	font-size: 0.9rem;
	color: var(--text-secondary);
}

/* Charts */
.chart-container {
	flex: 1;
	min-height: 200px;
	position: relative;
}

canvas {
	width: 100% !important;
	height: auto !important;
}

/* Tables */
table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.85rem;
	table-layout: fixed;
	/* Ensure consistent column sizing */
}

th,
td {
	padding: 0.75rem 1rem;
	text-align: left;
	border-bottom: 1px solid var(--border);
}

th {
	background: var(--bg-surface);
	color: var(--text-secondary);
	font-weight: 600;
	text-transform: uppercase;
	font-size: 0.75rem;
	letter-spacing: 0.05em;
	position: sticky;
	top: 0;
	z-index: 10;
	cursor: pointer;
	user-select: none;
}

/* Removed old spellsTable column sizing as we are using inline styles and canvas now */

tr:hover td {
	background: rgba(255, 255, 255, 0.03);
}

/* Inputs & Controls */
.controls {
	display: flex;
	gap: 0.5rem;
	margin-bottom: 1rem;
	padding-bottom: 1rem;
	border-bottom: 1px solid var(--border);
}

input,
button,
select {
	background: var(--bg-surface);
	border: 1px solid var(--border);
	color: var(--text-primary);
	padding: 0.5rem 1rem;
	font-family: inherit;
	font-size: 0.85rem;
}

input:focus,
button:focus,
select:focus {
	outline: 1px solid var(--accent);
	border-color: var(--accent);
}

button {
	cursor: pointer;
	background: var(--bg-secondary);
}

button:hover {
	background: var(--bg-surface);
	color: var(--accent);
}

/* Specific Adjustments */


/* Scrollbar Styling */
::-webkit-scrollbar {
	width: 8px;
	height: 8px;
}

::-webkit-scrollbar-track {
	background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
	background: var(--border);
}

::-webkit-scrollbar-thumb:hover {
	background: #555;
}

/* Filters in Spells Table */
.filters th input,
.filters th select {
	width: 100%;
	margin: 0;
	border: none;
	background: transparent;
	padding: 0.25rem 0;
	border-bottom: 1px solid transparent;
	color: var(--text-primary);
}

.filters th select option {
	background: var(--bg-surface);
	color: var(--text-primary);
}

.filters th input:focus,
.filters th select:focus {
	border-bottom-color: var(--accent);
}

aside {
	padding: 1rem;
	border-bottom: 1px solid var(--border);
	margin-bottom: 1rem;
	background: var(--bg-secondary);
}

/* Tooltip */
#tooltip {
	position: fixed;
	/* Fixed to viewport as regions scroll */
	background: var(--bg-surface);
	border: 1px solid var(--border);
	padding: 0.5rem;
	font-size: 0.8rem;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
	z-index: 1000;
	pointer-events: none;
	display: none;
}

/* Modal */
.modal-overlay {
	display: none;
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.7);
	z-index: 2000;
	justify-content: center;
	align-items: center;
}

.modal-content {
	background: var(--bg-surface);
	padding: 2rem;
	width: 95%;
	/* Increased width for 3 columns */
	max-width: 1600px;
	max-height: 95vh;
	overflow-y: auto;
	position: relative;
	border: 1px solid var(--border);
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
}

.close-modal {
	position: absolute;
	top: 1rem;
	right: 1.5rem;
	font-size: 2rem;
	cursor: pointer;
	color: var(--text-secondary);
}

.close-modal:hover {
	color: var(--text-primary);
}

.spells-header {
	background: var(--bg-surface);
	z-index: 10;
}

/* Ensure canvas aligns */
#spellsCanvas {
	display: block;
	width: 100%;
	height: 100%;
}

#region-spells {
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.spells-list-container {
	flex: 1;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

#spellsCanvasContainer {
	flex: 1;
	position: relative;
	overflow: hidden;
}

/* Similar Spells in Modal */
.spell-modal-grid {
	display: grid;
	grid-template-columns: 1fr;
	gap: 1.5rem;
}

.spell-modal-grid.has-similar {
	grid-template-columns: 1fr 280px 1fr;
	/* 3 Columns: Details, Similar List, Comparison */
}

.spell-card h2 {
	margin-bottom: 1rem;
	color: var(--text-primary);
	font-size: 1.5rem;
}

.spell-meta {
	background: var(--bg-secondary);
	padding: 1rem;
	margin-bottom: 1rem;
	border: 1px solid var(--border);
}

.meta-row {
	display: flex;
	padding: 0.4rem 0;
	border-bottom: 1px solid var(--border);
}

.meta-row:last-child {
	border-bottom: none;
}

/* Highlight differences in comparative spell card */
.field-diff {
	background: rgba(180, 60, 60, 0.3);
	border-radius: 3px;
	margin: 0 -0.5rem;
	padding-left: 0.5rem;
	padding-right: 0.5rem;
}

.spell-description.field-diff {
	border: 2px solid rgba(180, 60, 60, 0.5);
	background: rgba(180, 60, 60, 0.15);
}

.meta-label {
	font-weight: 600;
	color: var(--text-secondary);
	min-width: 80px;
	margin-right: 0.5rem;
}

.meta-value {
	color: var(--text-primary);
}

/* Property tags in spell card */
.prop-tag {
	display: inline-block;
	padding: 0.15rem 0.4rem;
	margin-right: 0.25rem;
	font-size: 0.75rem;
	font-weight: 600;
	background: var(--bg-surface);
	border: 1px solid var(--border);
	color: var(--text-secondary);
	cursor: help;
	transition: border-color 0.15s ease;
}

.prop-tag:hover {
	border-color: var(--accent);
}

.prop-tag.tick-guaranteed {
	background: rgba(59, 130, 246, 0.2);
	border-color: rgba(59, 130, 246, 0.5);
	color: #60a5fa;
}

.prop-tag.tick-conditional {
	background: rgba(251, 146, 60, 0.2);
	border-color: rgba(251, 146, 60, 0.5);
	color: #fb923c;
}

.prop-tag.tick-activated {
	background: rgba(168, 85, 247, 0.2);
	border-color: rgba(168, 85, 247, 0.5);
	color: #a855f7;
}

.spell-description {
	background: var(--bg-secondary);
	padding: 1rem;
	border: 1px solid var(--border);
}

.spell-description h3 {
	margin-bottom: 0.75rem;
	color: var(--accent);
	font-size: 1rem;
}

.spell-description p {
	line-height: 1.6;
	color: var(--text-primary);
}

.spell-higher-levels {
	background: var(--bg-secondary);
	padding: 1rem;
	border: 1px solid var(--border);
	margin-top: 1rem;
}

.spell-higher-levels h3 {
	margin-bottom: 0.75rem;
	color: #a855f7;
	font-size: 1rem;
}

.spell-higher-levels p {
	line-height: 1.6;
	color: var(--text-primary);
}

.prop-tag-none {
	color: var(--text-secondary);
	font-style: italic;
	font-size: 0.85rem;
}

.similar-spells-panel {
	background: var(--bg-secondary);
	padding: 1rem;
	border: 1px solid var(--border);
	height: fit-content;
}

.similar-spells-panel h3 {
	margin-bottom: 0.75rem;
	color: var(--accent);
	font-size: 1rem;
}

.similar-spells-list {
	list-style: none;
	padding: 0;
	margin: 0;
}

.similar-spells-list li {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0.25rem 0;
	border-bottom: 1px solid var(--border);
	line-height: 1.2;
}

.similar-spells-list li:last-child {
	border-bottom: none;
}

.similar-spell-link {
	color: var(--accent);
	text-decoration: none;
	cursor: pointer;
	flex: 1;
}

.similar-spell-link:hover {
	color: var(--accent-hover);
	text-decoration: underline;
}

.similarity-pct {
	color: var(--text-secondary);
	font-size: 0.85rem;
	margin-left: 0.5rem;
	min-width: 40px;
	text-align: right;
}

.similar-meta {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	text-align: right;
}

.similar-author {
	font-size: 0.75rem;
	color: var(--text-secondary);
	opacity: 0.8;
}

.ddb-link {
	color: var(--accent);
	text-decoration: none;
}

.ddb-link:hover {
	text-decoration: underline;
}

/* Comparative Detail Card */
.comparative-card {
	border-left: 1px solid var(--border);
	padding-left: 1.5rem;
	background: rgba(34, 197, 94, 0.02);
	/* Very subtle accent tint */
}

@media (max-width: 1200px) {
	.spell-modal-grid.has-similar {
		grid-template-columns: 1fr 280px;
	}

	.comparative-card {
		grid-column: span 2;
		border-left: none;
		border-top: 1px solid var(--border);
		padding-left: 0;
		padding-top: 1.5rem;
	}
}