@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600;700&display=swap");

@tailwind base;
@tailwind components;
@tailwind utilities;

@keyframes shimmer {
	0% {
		background-position: -200% 0;
	}
	100% {
		background-position: 200% 0;
	}
}

.animate-shimmer {
	animation: shimmer 2s ease-in-out infinite;
}

@keyframes sidebar-bg-fade-in {
	from {
		background-color: hsl(var(--background));
	}
	to {
		background-color: hsl(var(--sidebar-background));
	}
}

.sidebar-fade-in {
	animation: sidebar-bg-fade-in 300ms ease-out forwards;
}

@layer base {
	:root {
		--otto-font-family: "IBM Plex Mono", monospace;
		--background: 220 25% 95%;
		--foreground: 220 10% 15%;
		--card: 220 25% 98%;
		--card-foreground: 220 10% 15%;
		--popover: 220 25% 98%;
		--popover-foreground: 220 10% 15%;
		--primary: 222.2 47.4% 11.2%;
		--primary-foreground: 210 40% 98%;
		--secondary: 220 18% 88%;
		--secondary-foreground: 222.2 35% 25%;
		--muted: 220 18% 88%;
		--muted-foreground: 220 15% 40%;
		--accent: 220 20% 86%;
		--accent-foreground: 222.2 35% 25%;
		--destructive: 0 90% 65%;
		--destructive-foreground: 210 40% 98%;
		--border: 220 15% 89%;
		--input: 220 15% 89%;
		--ring: 222.2 84% 4.9%;
		--chart-1: 222.2 47.4% 41.2%;
		--chart-2: 173 58% 39%;
		--chart-3: 197 37% 24%;
		--chart-4: 43 74% 66%;
		--chart-5: 27 87% 67%;
		--radius: 0.5rem;
		--sidebar-background: 220 25% 91%;
		--sidebar-foreground: 220 20% 15%;
		--sidebar-primary: 222 50% 25%;
		--sidebar-primary-foreground: 210 40% 98%;
		--sidebar-accent: 220 35% 88%;
		--sidebar-accent-foreground: 222 35% 20%;
		--sidebar-border: 220 30% 87%;
		--sidebar-ring: 222 60% 30%;
		--sidebar-muted-foreground: 220 20% 45%;
		--code-background: hsl(220 25% 93%);
		--code-foreground: hsl(220 10% 10%);
		--code-keyword: hsl(300 85% 42%);
		--code-class: hsl(120 60% 35%);
		--code-function: hsl(220 95% 45%);
		--code-string: hsl(120 60% 35%);
		--code-comment: hsl(220 15% 35%);
		--code-operator: hsl(180 85% 30%);
		--code-punctuation: hsl(220 15% 20%);
		color-scheme: light;
	}

	.dark {
		--background: 240 10% 8%;
		--foreground: 0 0% 98%;
		--card: 240 10% 10%;
		--card-foreground: 0 0% 98%;
		--popover: 240 10% 10%;
		--popover-foreground: 0 0% 98%;
		--primary: 0 0% 98%;
		--primary-foreground: 240 5.9% 10%;
		--secondary: 240 3.7% 15.9%;
		--secondary-foreground: 0 0% 98%;
		--muted: 240 3.7% 15.9%;
		--muted-foreground: 240 5% 64.9%;
		--accent: 240 3.7% 15.9%;
		--accent-foreground: 0 0% 98%;
		--destructive: 0 75% 45%;
		--destructive-foreground: 0 0% 98%;
		--border: 240 3.7% 15.9%;
		--input: 240 3.7% 15.9%;
		--ring: 240 4.9% 83.9%;
		--chart-1: 220 70% 50%;
		--chart-2: 160 60% 45%;
		--chart-3: 30 80% 55%;
		--chart-4: 280 65% 60%;
		--chart-5: 340 75% 55%;
		--radius: 0.5rem;
		--sidebar-background: 240 10% 5%;
		--sidebar-foreground: 0 0% 92%;
		--sidebar-primary: 0 0% 92%;
		--sidebar-primary-foreground: 240 10% 5%;
		--sidebar-accent: 240 10% 7%;
		--sidebar-accent-foreground: 0 0% 95%;
		--sidebar-border: 240 6% 10%;
		--sidebar-ring: 240 4.9% 83.9%;
		--sidebar-muted-foreground: 240 5% 50%;
		--code-background: hsl(240 10% 10%);
		--code-foreground: hsl(0 0% 98%);
		--code-keyword: #c678dd;
		--code-class: #98c379;
		--code-function: #61afef;
		--code-string: #98c379;
		--code-comment: hsl(240 5% 64.9%);
		--code-operator: #56b6c2;
		--code-punctuation: hsl(240 5% 64.9%);
		color-scheme: dark;
	}
}

body {
	margin: 0;
	font-family: var(--otto-font-family);
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	background-color: hsl(var(--background));
	color: hsl(var(--foreground));
	overflow: hidden;
	position: fixed;
	width: 100%;
	height: 100%;
	-webkit-overflow-scrolling: touch;
}

html {
	--app-height: 100dvh;
	--mobile-safe-area-top: env(safe-area-inset-top);
	--visual-viewport-offset-bottom: 0px;
	--mobile-keyboard-offset-bottom: 0px;
	overflow: hidden;
	position: fixed;
	width: 100%;
	height: 100%;
	font-size: 15px;
}

@media (display-mode: standalone) {
	html {
		--mobile-safe-area-top: max(env(safe-area-inset-top), 24px);
	}
}

code {
	font-family: var(--otto-font-family);
	color: var(--code-foreground);
}

/* Remove button outline and focus ring on click/focus */
button:focus,
button:focus-visible {
	outline: none;
	box-shadow: none;
}

/* Hide scrollbar utility */
.scrollbar-hide {
	-ms-overflow-style: none; /* IE and Edge */
	scrollbar-width: none; /* Firefox */
}

.scrollbar-hide::-webkit-scrollbar {
	display: none; /* Chrome, Safari and Opera */
}

/* macOS-style overlay scrollbars: only visible while scrolling */
* {
	scrollbar-width: thin;
	scrollbar-color: transparent transparent;
}

.is-scrolling {
	scrollbar-color: rgba(155, 155, 155, 0.5) transparent;
}

::-webkit-scrollbar {
	width: 10px;
	height: 10px;
	background: transparent;
}

::-webkit-scrollbar-track,
::-webkit-scrollbar-track-piece {
	background: transparent;
	border: none;
}

::-webkit-scrollbar-thumb {
	background-color: transparent;
	border-radius: 10px;
	border: 2px solid transparent;
	background-clip: padding-box;
	min-height: 24px;
	transition: background-color 400ms ease;
}

.is-scrolling::-webkit-scrollbar-thumb {
	background-color: rgba(155, 155, 155, 0.5);
	background-clip: padding-box;
	transition: background-color 80ms ease;
}

.is-scrolling::-webkit-scrollbar-thumb:hover {
	background-color: rgba(155, 155, 155, 0.7);
	background-clip: padding-box;
}

.is-scrolling::-webkit-scrollbar-thumb:active {
	background-color: rgba(155, 155, 155, 0.85);
	background-clip: padding-box;
}

::-webkit-scrollbar-corner,
::-webkit-scrollbar-button {
	background: transparent;
	display: none;
}

.markdown-content {
	max-width: 100%;
	overflow-wrap: break-word;
	word-wrap: break-word;
	word-break: break-word;

	h1 {
		font-size: 1.875rem;
		font-weight: 700;
		margin-top: 1.5rem;
		margin-bottom: 1rem;
		line-height: 1.2;
	}
	h2 {
		font-size: 1.5rem;
		font-weight: 600;
		margin-top: 1.5rem;
		margin-bottom: 0.75rem;
		line-height: 1.3;
	}
	h3 {
		font-size: 1.25rem;
		font-weight: 600;
		margin-top: 1.25rem;
		margin-bottom: 0.5rem;
		line-height: 1.4;
	}
	h4 {
		font-size: 1.125rem;
		font-weight: 600;
		margin-top: 1rem;
		margin-bottom: 0.5rem;
		line-height: 1.4;
	}
	p {
		margin-top: 0.75rem;
		margin-bottom: 0.75rem;
	}
	ul,
	ol {
		margin-top: 0.75rem;
		margin-bottom: 0.75rem;
		padding-left: 1.5rem;
	}
	li {
		margin-top: 0.25rem;
		margin-bottom: 0.25rem;
	}
	pre {
		background-color: var(--code-background);
		border: 1px solid hsl(var(--border));
		border-radius: 0.5rem;
		padding: 1rem;
		margin-top: 0.75rem;
		margin-bottom: 0.75rem;
		overflow-x: auto;
		color: var(--code-foreground);
		max-width: 100%;
	}
	code {
		background-color: var(--code-background);
		border: 1px solid hsl(var(--border));
		border-radius: 0.25rem;
		padding: 0.125rem 0.375rem;
		font-size: 0.875rem;
		color: var(--code-foreground);
		word-break: break-all;
	}
	pre code {
		background-color: transparent;
		border: none;
		padding: 0;
		font-size: 0.875rem;
		color: inherit;
		word-break: normal;
		overflow-wrap: normal;
	}
	blockquote {
		border-left: 4px solid hsl(var(--border));
		padding-left: 1rem;
		margin-top: 0.75rem;
		margin-bottom: 0.75rem;
		color: hsl(var(--muted-foreground));
		font-style: italic;
	}
	a {
		color: hsl(var(--primary));
		text-decoration: underline;
		word-break: break-word;
	}
	a:hover {
		color: hsl(var(--primary) / 0.85);
	}
	strong,
	b {
		font-weight: 600;
	}
	em,
	i {
		font-style: italic;
	}
	hr {
		border: none;
		border-top: 1px solid hsl(var(--border));
		margin-top: 1.5rem;
		margin-bottom: 1.5rem;
	}
	table {
		border-collapse: collapse;
		margin-top: 0.75rem;
		margin-bottom: 0.75rem;
		width: max-content;
		min-width: 100%;
	}
	th,
	td {
		border: 1px solid hsl(var(--border));
		padding: 0.5rem 0.75rem;
		text-align: left;
		word-wrap: break-word;
		overflow-wrap: break-word;
		max-width: 32rem;
	}
	th {
		white-space: nowrap;
	}
	th {
		background-color: hsl(var(--muted));
		font-weight: 600;
	}
	& > *:first-child {
		margin-top: 0;
	}
	& > *:last-child {
		margin-bottom: 0;
	}
	& > p:first-child,
	& > ul:first-child,
	& > ol:first-child,
	& > pre:first-child,
	& > blockquote:first-child {
		margin-top: 0;
	}
	& > p:last-child,
	& > ul:last-child,
	& > ol:last-child,
	& > pre:last-child,
	& > blockquote:last-child {
		margin-bottom: 0;
	}
}

@layer utilities {
	.touch-manipulation {
		touch-action: manipulation;
	}

	.safe-area-inset-top {
		padding-top: env(safe-area-inset-top);
	}

	.safe-area-inset-bottom {
		padding-bottom: env(safe-area-inset-bottom);
	}

	.safe-area-inset-left {
		padding-left: env(safe-area-inset-left);
	}

	.safe-area-inset-right {
		padding-right: env(safe-area-inset-right);
	}
}

/* Research panel messages - smaller text for distinction */
.research-messages .markdown-content {
	font-size: 0.8125rem;
	line-height: 1.5;
}

.research-messages .markdown-content h1 {
	font-size: 1.25rem;
	margin-top: 1rem;
	margin-bottom: 0.5rem;
}

.research-messages .markdown-content h2 {
	font-size: 1.125rem;
	margin-top: 0.875rem;
	margin-bottom: 0.375rem;
}

.research-messages .markdown-content h3 {
	font-size: 1rem;
	margin-top: 0.75rem;
	margin-bottom: 0.25rem;
}

.research-messages .markdown-content pre {
	padding: 0.625rem;
	font-size: 0.75rem;
}

.research-messages .markdown-content code {
	font-size: 0.75rem;
	padding: 0.0625rem 0.25rem;
}

/* Non-selectable line numbers using CSS counters + ::before pseudo-elements */
.code-with-line-numbers {
	counter-reset: line-number;
}

.code-with-line-numbers .code-line {
	counter-increment: line-number;
	/* biome-ignore lint/complexity/noImportantStyles: override react-syntax-highlighter inline style */
	display: flex !important;
	align-items: flex-start;
}

.code-with-line-numbers .code-line::before {
	content: counter(line-number);
	min-width: 3em;
	padding-right: 1em;
	text-align: right;
	color: hsl(var(--muted-foreground) / 0.5);
	font-size: 0.7rem;
	flex-shrink: 0;
	user-select: none;
	pointer-events: none;
}
