/**
 * Last Topic Cards – stylesheet
 *
 * Every colour and size is a custom property: override them in your own style,
 * e.g.  .topiccards { --tc-preview-bg: #f6e7d8; --tc-radius: 8px; }
 * Neutral colours use translucent greys so the cards blend into light AND dark styles.
 */

.topiccards {
	--tc-gap: 20px;
	--tc-radius: 14px;
	--tc-border: rgba(128, 128, 128, .22);
	--tc-muted: rgba(128, 128, 128, 1);
	--tc-accent: #105289;

	/* Preview area (links to the first post) */
	--tc-preview-bg: #dde8f5;
	--tc-preview-ratio: 16 / 10;
	--tc-paper-bg: #fff;
	--tc-paper-fg: #1f2933;
	--tc-paper-muted: #6b7682;
	--tc-paper-font: Georgia, "Times New Roman", serif;
	--tc-paper-shadow: 0 2px 10px rgba(16, 42, 67, .12);

	/* Unread label */
	--tc-badge-bg: #bc2a4d;
	--tc-badge-fg: #fff;

	/* Member line */
	--tc-avatar: 26px;

	/* "View more" buttons */
	--tc-button-bg: rgba(128, 128, 128, .12);
	--tc-button-hover: rgba(18, 163, 235, .18);
	--tc-shadow: 0 4px 12px rgba(0, 0, 0, .06);

	margin: 20px 0 24px;
}

.topiccards-top { margin-top: 10px; }

.topiccards .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;
}

/* ===== Grid ===== */

.tc-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
	gap: var(--tc-gap);
	transition: opacity .2s ease;
}

.tc-grid[aria-busy="true"] { opacity: .5; }

/* ===== Card ===== */

.tc-card {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

/* ===== Preview (first post) ===== */

.tc-preview {
	position: relative;
	display: block;
	aspect-ratio: var(--tc-preview-ratio);
	overflow: hidden;
	background: var(--tc-preview-bg);
	border: 1px solid var(--tc-border);
	border-radius: var(--tc-radius);
	text-decoration: none !important;
	isolation: isolate;
}

.tc-sheet {
	position: absolute;
	top: 14%;
	right: 11%;
	bottom: -12%;
	left: 11%;
	display: flex;
	flex-direction: column;
	gap: 5px;
	padding: 14px 16px;
	overflow: hidden;
	color: var(--tc-paper-fg);
	background: var(--tc-paper-bg);
	border-radius: 6px;
	box-shadow: var(--tc-paper-shadow);
	transition: transform .25s ease;
}

.tc-sheet-back {
	top: 10%;
	right: 8%;
	left: 15%;
	opacity: .55;
	transform: rotate(2deg);
	transform-origin: top right;
}

.tc-sheet-forum {
	overflow: hidden;
	color: var(--tc-accent);
	font-size: 9px;
	font-weight: 700;
	letter-spacing: .06em;
	text-transform: uppercase;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.tc-sheet-title {
	display: -webkit-box;
	overflow: hidden;
	font-family: var(--tc-paper-font);
	font-size: 15px;
	font-weight: 400;
	line-height: 1.2;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}

.tc-sheet-meta {
	overflow: hidden;
	color: var(--tc-paper-muted);
	font-size: 9px;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.tc-sheet-meta .icon { margin-right: 2px; }

.tc-sheet-text {
	display: -webkit-box;
	overflow: hidden;
	color: var(--tc-paper-muted);
	font-size: 10px;
	line-height: 1.45;
	-webkit-line-clamp: 4;
	-webkit-box-orient: vertical;
	overflow-wrap: anywhere;
}

.tc-image {
	position: absolute;
	inset: 0;
	z-index: 1;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
	transition: transform .35s ease;
}

.tc-image-ready .tc-sheet { visibility: hidden; }   /* see topiccards.js */

.tc-new {
	position: absolute;
	top: 10px;
	left: 10px;
	z-index: 2;
	padding: 2px 8px;
	color: var(--tc-badge-fg);
	background: var(--tc-badge-bg);
	border-radius: 20px;
	font-size: 10px;
	font-weight: 700;
	letter-spacing: .03em;
	text-transform: uppercase;
}

.tc-preview:hover .tc-sheet,
.tc-preview:focus .tc-sheet { transform: translateY(-4px); }

.tc-preview:hover .tc-sheet-back,
.tc-preview:focus .tc-sheet-back { transform: translateY(-2px) rotate(3.5deg); }

.tc-preview:hover .tc-image,
.tc-preview:focus .tc-image { transform: scale(1.04); }

/* ===== Title + date ===== */

.tc-text {
	display: flex;
	align-items: baseline;
	gap: 10px;
	min-width: 0;
	margin-top: 10px;
	color: inherit;
	text-decoration: none !important;
}

.topiccards .tc-title {
	flex: 1 1 auto;
	min-width: 0;
	margin: 0;
	padding: 0;
	overflow: hidden;
	border: 0;
	color: inherit;
	font-family: inherit;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.35;
	text-transform: none;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.tc-text:hover .tc-title,
.tc-text:focus .tc-title { text-decoration: underline; }

.tc-date {
	flex: 0 0 auto;
	color: var(--tc-muted);
	font-size: 12px;
	white-space: nowrap;
}

/* ===== Last poster ===== */

.tc-author {
	display: flex;
	align-items: center;
	gap: 7px;
	min-width: 0;
	margin-top: 6px;
	font-size: 12px;
}

.tc-avatar {
	display: flex;
	flex: 0 0 var(--tc-avatar);
	align-items: center;
	justify-content: center;
	width: var(--tc-avatar);
	height: var(--tc-avatar);
	overflow: hidden;
	border-radius: 50%;
	text-decoration: none !important;
}

.tc-avatar-letter { background-color: var(--tc-accent); }

.tc-avatar img {
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
}

a.tc-avatar:hover,
a.tc-avatar:focus { box-shadow: 0 0 0 2px var(--tc-accent); }

.tc-initial {
	color: #fff;
	font-size: 12px;
	font-weight: 700;
}

.tc-username {
	min-width: 0;
	overflow: hidden;
	font-weight: 600;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.tc-time {
	flex: 0 0 auto;
	color: var(--tc-muted);
	white-space: nowrap;
}

.tc-time::before {
	content: "·";
	margin-right: 7px;
}

.tc-read-more {
	flex: 0 0 auto;
	margin-left: 6px;
	color: var(--tc-accent);
	font-weight: 600;
	white-space: nowrap;
	text-decoration: none !important;
}

.tc-read-more .icon { margin-right: 2px; }

.tc-read-more:hover,
.tc-read-more:focus { text-decoration: underline !important; }

/* ===== View more / less ===== */

.tc-more {
	display: flex;
	gap: 10px;
	margin-top: 18px;
}

.tc-more-btn {
	flex: 1 1 0;
	min-width: 0;
	padding: 10px;
	border: 1px solid var(--tc-border);
	border-radius: 8px;
	color: inherit;
	background: var(--tc-button-bg);
	font-family: inherit;
	font-size: 13px;
	font-weight: 600;
	box-shadow: var(--tc-shadow);
	cursor: pointer;
}

.tc-more-btn:hover,
.tc-more-btn:focus { background: var(--tc-button-hover); }
.tc-more-btn[hidden] { display: none !important; }
.tc-more-btn:disabled { cursor: wait; opacity: .6; }

.tc-error {
	grid-column: 1 / -1;
	margin: 0;
}

/* ===== Dark styles (prosilver_dark & co) ===== */

html.phpbb-dark-mode .topiccards,
.prosilver_dark .topiccards {
	--tc-preview-bg: rgba(255, 255, 255, .06);
	--tc-paper-bg: #2b3138;
	--tc-paper-fg: #e4e8ec;
	--tc-paper-muted: #9aa5b1;
	--tc-paper-shadow: 0 2px 10px rgba(0, 0, 0, .45);
	--tc-shadow: 0 4px 12px rgba(0, 0, 0, .35);
	--tc-button-bg: rgba(255, 255, 255, .08);
	--tc-button-hover: rgba(255, 255, 255, .16);
	--tc-accent: #6f9bc4;
}

/* ===== Focus & motion ===== */

.topiccards a:focus-visible,
.tc-more-btn:focus-visible {
	outline: 2px solid var(--tc-accent);
	outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
	.tc-grid,
	.tc-sheet,
	.tc-image { transition: none; }

	.tc-preview:hover .tc-sheet,
	.tc-preview:focus .tc-sheet,
	.tc-preview:hover .tc-image,
	.tc-preview:focus .tc-image { transform: none; }

	.tc-preview:hover .tc-sheet-back,
	.tc-preview:focus .tc-sheet-back { transform: rotate(2deg); }
}

/* ===== Responsive ===== */

/* 6 cards: two rows of 3 instead of 4 + 2 */
@media (min-width: 901px) {
	.tc-grid[data-limit="6"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
	.tc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Phones */
@media (max-width: 560px) {
	.topiccards { --tc-gap: 18px; --tc-preview-ratio: 2 / 1; }

	.tc-grid { grid-template-columns: minmax(0, 1fr); }

	.tc-sheet { right: 14%; left: 14%; }
	.tc-sheet-back { right: 11%; left: 18%; }
	.tc-sheet-text { -webkit-line-clamp: 3; }
}

/* Phones in landscape */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
	.topiccards { --tc-preview-ratio: 2 / 1; }

	.tc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
	.tc-sheet-text { -webkit-line-clamp: 2; }
}
