/* ═══════════════════════════════════════════════════════════
   Theseus — Base Stylesheet
   Reset, custom properties, typography, utility classes
   ═══════════════════════════════════════════════════════════ */

/* ── Reset ─────────────────────────────────────────────── */
*,
*::before,
*::after {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}
html {
	font-size: 16px;
	scroll-behavior: smooth;
	-webkit-text-size-adjust: 100%;
}
body {
	min-height: 100vh;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}
img,
picture,
video,
svg {
	display: block;
	max-width: 100%;
}
input,
button,
textarea,
select {
	font: inherit;
}
a {
	color: inherit;
	text-decoration: none;
}
ul,
ol {
	list-style: none;
}

/* ── Scrollbar Styling ────────────────────────────────── */

/* Firefox */
* {
	scrollbar-width: thin;
	scrollbar-color: var(--scrollbar-thumb, rgba(0, 0, 0, 0.2)) transparent;
}

/* Chrome, Safari, Edge */
::-webkit-scrollbar {
	width: 8px;
	height: 8px;
}

::-webkit-scrollbar-track {
	background: transparent;
}

::-webkit-scrollbar-thumb {
	background: var(--scrollbar-thumb, rgba(0, 0, 0, 0.2));
	border-radius: 4px;
	border: 2px solid transparent;
	background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
	background: var(--scrollbar-thumb-hover, rgba(0, 0, 0, 0.35));
	border: 2px solid transparent;
	background-clip: content-box;
}

/* ── Custom Properties ─────────────────────────────────── */
:root {
	/* Colors — Primary */
	--color-ink: #1a1a2e;
	--color-parchment: #faf6f1;
	--color-ember: #c2553a;
	--color-sage: #7c9a82;
	--color-mist: #e8e4df;
	--color-slate: #4a5568;

	/* Colors — Extended */
	--color-deep: #0f0f1a;
	--color-sepia: #f0e6d3;
	--color-cloud: #f5f1ec;
	--color-warm-gray: #736b66;
	--color-amber: #d4a853;
	--color-error: #b83a3a;

	/* Semantic — Text */
	--text-primary: var(--color-ink);
	--text-secondary: var(--color-slate);
	--text-muted: var(--color-warm-gray);
	--text-inverse: var(--color-parchment);

	/* Semantic — Backgrounds */
	--bg-page: var(--color-parchment);
	--bg-card: var(--color-cloud);
	--bg-elevated: white;
	--bg-inset: var(--color-mist);
	--surface: #eae5df;
	--surface-hover: #e0dbd4;

	/* Semantic — Interactive */
	--accent: var(--color-ember);
	--accent-hover: #a84832;
	--accent-active: #8f3d2b;
	--success: var(--color-sage);
	--warning: var(--color-amber);
	--error: var(--color-error);

	/* Semantic — Structure */
	--border: var(--color-mist);
	--border-subtle: rgba(26, 26, 46, 0.06);
	--divider: var(--color-mist);

	/* Shadows */
	--shadow-color: rgba(0, 0, 0, 0.08);
	--shadow-lg: rgba(0, 0, 0, 0.06);
	--focus-ring: rgba(194, 85, 58, 0.2);

	/* Scrollbar */
	--scrollbar-thumb: rgba(0, 0, 0, 0.15);
	--scrollbar-thumb-hover: rgba(0, 0, 0, 0.3);

	/* Typography */
	--font-reading: Georgia, "Times New Roman", serif;
	--font-ui: "Helvetica Neue", Arial, sans-serif;
	--font-mono: "SF Mono", Consolas, "Fira Code", monospace;

	/* Type Scale (major third — 1.25) */
	--text-xs: 0.64rem;
	--text-sm: 0.8rem;
	--text-base: 1rem;
	--text-md: 1.125rem;
	--text-lg: 1.25rem;
	--text-xl: 1.563rem;
	--text-2xl: 1.953rem;
	--text-3xl: 2.441rem;
	--text-4xl: 3.052rem;

	/* Spacing (4px grid) */
	--space-1: 0.25rem;
	--space-2: 0.5rem;
	--space-3: 0.75rem;
	--space-4: 1rem;
	--space-5: 1.25rem;
	--space-6: 1.5rem;
	--space-8: 2rem;
	--space-10: 2.5rem;
	--space-12: 3rem;
	--space-16: 4rem;
	--space-20: 5rem;
	--space-24: 6rem;

	/* Layout */
	--max-width-reading: 38rem;
	--max-width-social: 30rem;
	--max-width-content: 56rem;
	--max-width-page: 80rem;
	--sidebar-width: 16rem;
	--sidebar-width-collapsed: 3.5rem;
	--max-width-wide: 96rem;

	/* Motion */
	--duration-fast: 150ms;
	--duration-normal: 250ms;
	--duration-slow: 400ms;
	--ease-out: cubic-bezier(0.16, 1, 0.3, 1);
	--ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

	/* Radius */
	--radius-sm: 4px;
	--radius-md: 6px;
	--radius-lg: 12px;
	--radius-full: 100px;
}

/* ── Base Typography ───────────────────────────────────── */
body {
	font-family: var(--font-reading);
	color: var(--text-primary);
	background: var(--bg-page);
	line-height: 1.6;
}

h1,
h2,
h3,
h4,
h5,
h6 {
	font-family: var(--font-reading);
	font-weight: 400;
	line-height: 1.2;
	letter-spacing: -0.02em;
}

/* ── Typography Utilities ──────────────────────────────── */
.t-page-title {
	font-size: var(--text-2xl);
}
.t-section-title {
	font-size: var(--text-xl);
}
.t-card-title {
	font-size: var(--text-lg);
	letter-spacing: -0.02em;
	line-height: 1.3;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}
.t-body {
	font-size: var(--text-base);
	line-height: 1.6;
}
.t-label {
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.15em;
	color: var(--text-secondary);
}
.t-meta {
	font-family: var(--font-ui);
	font-size: var(--text-sm);
	color: var(--text-secondary);
}
.t-tag {
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	font-weight: 500;
	letter-spacing: 0.02em;
}
.t-body-reading {
	font-family: var(--font-reading);
	font-size: var(--text-md);
	line-height: 1.7;
}
.t-card-excerpt,
.t-card-description {
	display: -webkit-box;
	-webkit-line-clamp: 4;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
	display: inline-flex;
	align-items: center;
	gap: var(--space-2);
	padding: var(--space-2) var(--space-5);
	font-family: var(--font-ui);
	font-size: var(--text-sm);
	font-weight: 500;
	border-radius: var(--radius-md);
	cursor: pointer;
	transition:
		background var(--duration-fast) ease,
		color var(--duration-fast) ease;
	border: none;
	line-height: 1.4;
}
.btn-primary {
	background: var(--accent);
	color: var(--text-inverse);
}
.btn-primary:hover {
	background: var(--accent-hover);
}
.btn-primary:active {
	background: var(--accent-active);
}
.btn-secondary {
	background: transparent;
	color: var(--text-primary);
	border: 1px solid var(--border);
}
.btn-secondary:hover {
	background: var(--bg-inset);
}
.btn-ghost {
	background: transparent;
	color: var(--text-secondary);
	padding: var(--space-1) var(--space-2);
}
.btn-ghost:hover {
	color: var(--text-primary);
}

/* ── Tag Pills ─────────────────────────────────────────── */
.tag-pill {
	display: inline-flex;
	align-items: center;
	padding: var(--space-1) var(--space-2);
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	font-weight: 500;
	color: var(--text-secondary);
	background: var(--bg-inset);
	border-radius: var(--radius-full);
	letter-spacing: 0.02em;
	line-height: 1.6;
	white-space: nowrap;
}
.tag-pill-link {
	text-decoration: none;
}
.tag-pill-link:hover {
	background: var(--accent);
	color: var(--text-inverse);
}

/* ── Form Elements ─────────────────────────────────────── */
.input {
	width: 100%;
	padding: var(--space-2) var(--space-3);
	font-family: var(--font-ui);
	font-size: var(--text-base);
	color: var(--text-primary);
	background: var(--bg-elevated);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	transition: border-color var(--duration-fast) ease;
}
.input:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--focus-ring);
}
.input::placeholder {
	color: var(--text-muted);
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
	background: var(--bg-card);
	border: 1px solid var(--border-subtle);
	border-radius: var(--radius-lg);
	overflow: hidden;
	display: flex;
	flex-direction: column;
	cursor: pointer;
	transition:
		transform var(--duration-fast) var(--ease-out),
		box-shadow var(--duration-fast) var(--ease-out);
}
.card:hover {
	transform: translateY(-2px);
	box-shadow: 0 8px 24px var(--shadow-lg);
}
.card-image {
	width: 100%;
	aspect-ratio: 40 / 21;
	object-fit: cover;
}
/* <picture> wrapper in card flex column: fill card width */
picture:has(> .card-image) {
	width: 100%;
}

/* ── Card Type Placeholders ───────────────────────────── */
.card-placeholder {
	width: 100%;
	aspect-ratio: 40 / 21;
	display: flex;
	align-items: center;
	justify-content: center;
	background: linear-gradient(135deg, var(--bg-inset) 0%, var(--bg-card) 100%);
	color: var(--text-muted);
	opacity: 0.6;
}
.card-placeholder svg {
	width: 48px;
	height: 48px;
}
.card-placeholder-article {
	color: var(--color-sage);
}
.card-placeholder-link {
	color: var(--color-slate);
}
.card-placeholder-quote {
	color: var(--color-ember);
}
.card-placeholder-product {
	color: var(--color-amber, var(--color-ember));
}
.card-placeholder-note {
	color: var(--color-sage);
}
.card-placeholder-snippet {
	color: var(--color-slate);
}
.card-placeholder-image {
	color: var(--text-muted);
}
.card-placeholder-social {
	color: var(--color-ember);
}
.card-placeholder-video {
	color: var(--color-slate);
}
.card-placeholder-list {
	color: var(--color-sage);
}

/* ── List Card Progress ──────────────────────────────── */
.card-list-meta {
	display: flex;
	flex-direction: column;
	gap: var(--space-1);
	padding: 0 var(--space-4);
	margin-bottom: var(--space-2);
}
.card-list-count {
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	color: var(--text-muted);
}
.card-list-bar {
	width: 100%;
	height: 4px;
	background: var(--bg-inset);
	border-radius: var(--radius-full);
	overflow: hidden;
}
.card-list-bar-fill {
	height: 100%;
	background: var(--accent);
	border-radius: var(--radius-full);
}
.card-list-preview {
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	color: var(--text-muted);
	padding: 0 var(--space-4);
	margin-bottom: var(--space-2);
	display: -webkit-box;
	-webkit-line-clamp: 1;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

/* ── Video Card Overlay ──────────────────────────────── */
.card-video-wrap {
	position: relative;
	overflow: hidden;
}
.card-video-wrap > img,
.card-video-wrap > picture {
	display: block;
	width: 100%;
	height: 100%;
}
.card-video-wrap > img,
.card-video-wrap > picture > img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}
.card-video-overlay {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	pointer-events: none;
}
.card-play-indicator {
	width: 44px;
	height: 44px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: color-mix(in srgb, var(--color-ink) 60%, transparent);
	backdrop-filter: blur(4px);
	border-radius: var(--radius-full);
	opacity: 0;
	transition: opacity var(--duration-fast) var(--ease-out);
}
.card-play-indicator svg {
	transform: translate(1px, 0);
}
.card:hover .card-play-indicator,
.card:has(a:focus-visible) .card-play-indicator {
	opacity: 1;
}
@media (hover: none) {
	.card-play-indicator {
		opacity: 1;
	}
}
.card-duration-badge {
	position: absolute;
	bottom: var(--space-2);
	right: var(--space-2);
	background: color-mix(in srgb, var(--color-ink) 75%, transparent);
	backdrop-filter: blur(4px);
	border-radius: var(--radius-sm);
	padding: 2px var(--space-1);
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	font-weight: 500;
	font-variant-numeric: tabular-nums;
	color: var(--color-parchment);
	letter-spacing: 0.02em;
	line-height: 1;
	pointer-events: none;
}
/* Hide progress bar on video cards (future-proofing) */
.card[data-card-type="video"] .card-progress {
	display: none;
}
.card-body {
	padding: var(--space-4);
	flex: 1;
}
.card-body .t-label {
	margin-bottom: var(--space-1);
}
.card-body .t-card-title {
	margin-bottom: var(--space-2);
}
.card-body .t-meta {
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	margin-bottom: var(--space-3);
}
.card-tags {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-1);
	overflow: hidden;
	/* ~2 rows of pills: (font-size × line-height + padding×2) × 2 + gap */
	max-height: calc(2 * (0.7rem * 1.6 + 4px * 2) + 4px);
}
.tag-pill-overflow {
	display: inline-flex;
	align-items: center;
	padding: var(--space-1) var(--space-2);
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	font-weight: 500;
	color: var(--text-muted);
	background: var(--bg-inset);
	border-radius: var(--radius-full);
	letter-spacing: 0.02em;
	line-height: 1.6;
	white-space: nowrap;
	border: none;
	cursor: pointer;
}
.tag-pill-overflow:hover {
	background: var(--border);
}

/* ── Card Hover Expand ────────────────────────────────── */
/* Expansion is driven by JS (lib/card-hover-expand.ts) which adds
   .card--expanded after a 600 ms loiter delay.  The card's height is
   locked via an inline style so the grid row never reflows.            */
.card--expanded {
	overflow: visible;
	z-index: 2;
	position: relative;
}
.card--expanded .tc-link-wrap {
	overflow: visible;
}
.card--expanded .t-card-title,
.card--expanded .t-meta,
.card--expanded .t-card-excerpt,
.card--expanded .t-card-description {
	-webkit-line-clamp: unset;
}

/* Pull the body out of flow so it can grow without changing the
   card's in-flow height.  Background + shadow keep it readable.       */
.card--expanded .card-body,
.card--expanded .tc-article-body,
.card--expanded .tc-product-body,
.card--expanded .tc-video-body,
.card--expanded .tc-note-body {
	position: absolute;
	inset-inline: 0;
	background: var(--bg-card);
	border-radius: 0 0 var(--radius-lg) var(--radius-lg);
	box-shadow: 0 8px 24px var(--shadow-lg);
}

/* Hide tags / actions while expanded — they sit behind the overlay   */
.card--expanded .tc-card-tags,
.card--expanded .tc-card-actions,
.card--expanded .card-footer {
	opacity: 0;
	pointer-events: none;
}

.card-footer {
	padding: var(--space-2) var(--space-4);
	border-top: 1px solid var(--border-subtle);
	display: flex;
	justify-content: space-between;
	align-items: center;
}

/* ── Social Embed ──────────────────────────────────────── */
.social-embed-container {
	border-radius: var(--radius-md);
	overflow: hidden;
}
.social-fallback-card {
	background: var(--bg-elevated);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: var(--space-4);
	border-left: 3px solid var(--color-ember);
}
.social-fallback-header {
	font-size: var(--text-sm);
	font-weight: 600;
	color: var(--text-secondary);
	margin-bottom: var(--space-2);
}
.social-fallback-body {
	font-size: var(--text-base);
	line-height: 1.5;
	color: var(--text-primary);
	white-space: pre-wrap;
}
.social-fallback-footer {
	font-size: var(--text-xs);
	color: var(--text-muted);
	margin-top: var(--space-3);
}
.card-list-item-thumb-placeholder {
	width: 64px;
	height: 64px;
	border-radius: var(--radius-sm);
	background: var(--bg-inset);
	flex-shrink: 0;
}

/* ── Empty State ───────────────────────────────────────── */
.empty-state {
	text-align: center;
	padding: var(--space-16) var(--space-8);
	color: var(--text-muted);
}
.empty-state .icon {
	font-size: 3rem;
	margin-bottom: var(--space-4);
}
.empty-state h3 {
	font-size: var(--text-lg);
	color: var(--text-secondary);
	margin-bottom: var(--space-2);
}
.empty-state p {
	font-size: var(--text-base);
	margin-bottom: var(--space-6);
}

/* ── Toast ─────────────────────────────────────────────── */
.toast-container {
	position: fixed;
	bottom: var(--space-6);
	right: var(--space-6);
	z-index: 1000;
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
}
.toast {
	padding: var(--space-3) var(--space-5);
	background: var(--color-ink);
	color: var(--color-parchment);
	border-radius: var(--radius-md);
	font-family: var(--font-ui);
	font-size: var(--text-sm);
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
	display: flex;
	align-items: center;
	gap: var(--space-3);
	animation: toast-in var(--duration-normal) var(--ease-out);
}
.toast a {
	color: var(--accent);
	text-decoration: underline;
	cursor: pointer;
}
@keyframes toast-in {
	from {
		opacity: 0;
		transform: translateY(8px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ── View Transitions ──────────────────────────────────── */
@view-transition {
	navigation: auto;
}

::view-transition-old(root) {
	animation: fade-out var(--duration-fast) var(--ease-out);
}
::view-transition-new(root) {
	animation: fade-in var(--duration-fast) var(--ease-out);
}

/*
 * Card transitions — browser auto-morphs matching view-transition-names.
 * Individual card-{id} names are set inline; the browser morphs automatically
 * when the same view-transition-name appears on the old and new page.
 * No wildcard rules needed — the default morph animation handles it.
 */

/*
 * Page-level transitions — sidebar stays in place, main content cross-fades.
 * The sidebar has the same content across pages so the morph makes it stable.
 * Main content and page header cross-fade between old and new pages.
 */
::view-transition-old(main-content) {
	animation: fade-out var(--duration-fast) var(--ease-out);
}
::view-transition-new(main-content) {
	animation: fade-in var(--duration-fast) var(--ease-out);
}
::view-transition-old(page-header) {
	animation: fade-out var(--duration-fast) var(--ease-out);
}
::view-transition-new(page-header) {
	animation: fade-in var(--duration-fast) var(--ease-out);
}
@keyframes fade-out {
	from {
		opacity: 1;
	}
	to {
		opacity: 0;
	}
}
@keyframes fade-in {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

/*
 * Stable chrome — these elements should never animate during page transitions.
 * They are layout landmarks (nav, sidebar, FAB) that must stay rock-solid.
 * Giving them a view-transition-name extracts them from the root group;
 * setting animation: none prevents any morph/fade during transitions.
 */
::view-transition-old(mobile-nav),
::view-transition-new(mobile-nav),
::view-transition-old(save-fab),
::view-transition-new(save-fab) {
	animation: none;
}

/* biome-ignore lint/correctness/noUnknownTypeSelector: view-transition-name identifiers, not type selectors */
::view-transition-old(sidebar),
/* biome-ignore lint/correctness/noUnknownTypeSelector: view-transition-name identifiers, not type selectors */
	::view-transition-new(sidebar) {
	animation: none;
}

/* ── Offline Banner ───────────────────────────────────── */
.offline-banner {
	background: var(--warning);
	color: var(--color-ink);
	text-align: center;
	padding: var(--space-2);
	font-family: var(--font-ui);
	font-size: var(--text-sm);
}

/* ── Skeleton Loading States ───────────────────────────── */
@keyframes skeleton-pulse {
	0% {
		opacity: 0.6;
	}
	50% {
		opacity: 0.3;
	}
	100% {
		opacity: 0.6;
	}
}

.skeleton {
	background: var(--border);
	border-radius: var(--radius-sm);
	animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-text {
	height: 1em;
	margin-bottom: 0.5em;
	background: var(--border);
	border-radius: var(--radius-sm);
	animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-text:last-child {
	width: 60%;
}

.skeleton-card {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	padding: var(--space-4);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
}

.skeleton-card-image {
	height: 160px;
	background: var(--border);
	border-radius: var(--radius-sm);
	animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-card-title {
	height: 1.25em;
	width: 80%;
	background: var(--border);
	border-radius: var(--radius-sm);
	animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-card-body {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
}

/* ── Reduced Motion ────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		/* biome-ignore lint/complexity/noImportantStyles: required for a11y reduced-motion override */
		animation-duration: 0.01ms !important;
		/* biome-ignore lint/complexity/noImportantStyles: required for a11y reduced-motion override */
		transition-duration: 0.01ms !important;
	}
	::view-transition-group(*),
	::view-transition-old(*),
	::view-transition-new(*) {
		/* biome-ignore lint/complexity/noImportantStyles: required for a11y reduced-motion override */
		animation: none !important;
	}
}

/* ── Focus Styles ──────────────────────────────────────── */
:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}
/* Remove default outline for mouse users */
:focus:not(:focus-visible) {
	outline: none;
}

/* ── Button States ─────────────────────────────────────── */
.btn:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
	box-shadow: 0 0 0 4px var(--focus-ring);
}
.btn:disabled,
.btn[aria-disabled="true"] {
	opacity: 0.5;
	cursor: not-allowed;
}

/* ── Card Focus ────────────────────────────────────────── */
.card:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
	box-shadow: 0 0 0 4px var(--focus-ring);
}

/* ── Display Utilities ─────────────────────────────────── */
.hidden,
[hidden] {
	/* biome-ignore lint/complexity/noImportantStyles: utility class must override component display values */
	display: none !important;
}

/* ── Accessibility Utilities ──────────────────────────── */
.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}
