/* Rivo's case study: everything only this page uses (its chat demos, the
   sorting and security sections). The shared template is case-study/case-study.css. */

.chat-replay:focus-visible {
	outline: 2px solid var(--ink);
	outline-offset: 4px;
}

/* ---- the chat window ---- */

.chat {
	width: 25rem;
	height: 27.5rem;
	margin: 0;
	display: flex;
	flex-direction: column;
	border-radius: 1.5rem;
	/* no backdrop-filter: this element tilts with the pointer, and a
	   blurred backdrop would have to be recomputed on every frame */
	background: linear-gradient(160deg,
			rgba(52, 52, 52, 0.96) 0%,
			rgba(18, 18, 18, 0.98) 38%,
			rgba(6, 6, 6, 0.98));
	transform: perspective(1200px) rotateX(var(--tx, 0deg)) rotateY(var(--ty, 0deg));
}

.chat-top {
	display: flex;
	align-items: center;
	gap: 0.8rem;
	padding: 1rem 1.2rem;
	border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-avatar {
	width: 2.4rem;
	height: 2.4rem;
	flex: none;
	border-radius: 50%;
	display: grid;
	place-items: center;
	background: var(--accent);
	color: var(--accent-ink);
	font-size: 1.3rem;
	line-height: 1;
}

.chat-who {
	display: flex;
	flex-direction: column;
	line-height: 1.15;
}

.chat-name {
	font-size: 1.35rem;
}

.chat-status {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	font-family: "Poppins", sans-serif;
	font-size: 0.68rem;
	color: rgba(255, 255, 255, 0.6);
}

.chat-status::before {
	content: "";
	width: 0.45rem;
	height: 0.45rem;
	border-radius: 50%;
	background: var(--mint);
}

.chat-log {
	flex: 1;
	list-style: none;
	display: flex;
	flex-direction: column;
	justify-content: flex-end;
	gap: 0.55rem;
	padding: 1rem 1rem 0.5rem;
	overflow: hidden;
}

.msg-them {
	align-self: flex-start;
	background: rgba(255, 255, 255, 0.1);
	border-bottom-left-radius: 0.3rem;
}

.msg-me {
	align-self: flex-end;
	background: var(--accent);
	color: var(--accent-ink);
	border: 1px solid transparent;
	border-bottom-right-radius: 0.3rem;
}

.msg-tag {
	display: block;
	margin-bottom: 0.1rem;
	font-size: 0.62rem;
	opacity: 0.7;
}

/* stacked alternates: every state lives in the DOM, only one shows */

.msg-swap {
	display: grid;
}

.msg-swap>* {
	grid-area: 1 / 1;
	transition:
		opacity 0.5s var(--ease-out),
		filter 0.7s var(--ease-out),
		letter-spacing 0.7s var(--ease-out);
}

/* default = the finished state, so without JavaScript the
   conversation still reads correctly */

.once-sealed,
.once-body,
.capsule-lock {
	opacity: 0;
}

.msg-once[data-state="sealed"] .once-sealed,
.msg-once[data-state="open"] .once-body {
	opacity: 1;
}

.msg-once[data-state="sealed"] .once-gone,
.msg-once[data-state="open"] .once-gone {
	opacity: 0;
}

.msg-once[data-state="gone"] {
	background: transparent;
	border-color: color-mix(in srgb, var(--accent) 55%, transparent);
	border-style: dashed;
	color: rgba(255, 255, 255, 0.55);
}

.msg-once[data-state="gone"] .once-body {
	filter: blur(6px);
	letter-spacing: 0.3em;
}

.msg-capsule[data-state="locked"] {
	background: color-mix(in srgb, var(--accent) 16%, transparent);
	color: #fff;
	border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.msg-capsule[data-state="locked"] .capsule-lock {
	opacity: 1;
}

.msg-capsule[data-state="locked"] .capsule-body {
	opacity: 0;
}

.capsule-count {
	font-variant-numeric: tabular-nums;
	color: var(--accent);
}

.chat-typing {
	align-self: flex-start;
	margin: 0 1rem 1rem;
	padding: 0.55rem 0.8rem;
	display: flex;
	gap: 0.3rem;
	border-radius: 1rem;
	background: rgba(255, 255, 255, 0.1);
	opacity: 0;
	transition: opacity 0.3s ease;

	i {
		width: 0.38rem;
		height: 0.38rem;
		border-radius: 50%;
		background: rgba(255, 255, 255, 0.75);
	}
}

.chat.is-typing .chat-typing {
	opacity: 1;
}

.chat.is-typing .chat-typing i {
	animation: typing 1s ease-in-out infinite;
}

.chat.is-typing .chat-typing i:nth-child(2) {
	animation-delay: 0.15s;
}

.chat.is-typing .chat-typing i:nth-child(3) {
	animation-delay: 0.3s;
}

.chat-replay {
	margin-top: 1.6rem;
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.55rem 1rem;
	border: 1px solid rgba(0, 0, 0, 0.18);
	border-radius: 999px;
	background: transparent;
	font-family: "Poppins", sans-serif;
	font-size: 0.8rem;
	color: var(--ink-soft);
	cursor: pointer;
	visibility: hidden;
	opacity: 0;
	transition: opacity 0.4s ease, background-color 0.2s ease;
}

.chat-replay.is-ready {
	visibility: visible;
	opacity: 1;
}

.chat-replay:hover {
	background: rgba(0, 0, 0, 0.05);
}

/* =========================================================
   PROBLEM 1 — CHATS THAT SORT THEMSELVES
   A small, faithful replica of Rivo's home screen. The colours
   below are Rivo's own, not the portfolio's.
   ========================================================= */

.case-sorting {
	display: grid;
	grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
	gap: 2rem 4.5rem;
	align-items: center;
}

.sorting-copy p {
	max-width: 30rem;
	font-size: 1.05rem;
	line-height: 1.85;
	color: var(--ink-soft);
}

.sorting-copy p+p {
	margin-top: 1rem;
}

.sorting-stage {
	display: grid;
	justify-items: center;
	gap: 1.2rem;
}

.rv {
	--rv-bg: #e5ddd6;
	--rv-card: #f7f4f0;
	--rv-chip: #ece6df;
	--rv-label: #786859;
	--rv-bar: #292929;

	width: 100%;
	margin: 0;
	padding: 0.9rem;
	border-radius: 1.6rem;
	background: var(--rv-bg);
	border: 1px solid rgba(0, 0, 0, 0.06);
	box-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.6),
		0 2rem 4rem rgba(0, 0, 0, 0.14);
	font-family: "Poppins", sans-serif;
}

.rv-bar {
	height: 2.6rem;
	padding: 0 0.9rem;
	display: flex;
	align-items: center;
	justify-content: space-between;
	border-radius: 1rem;
	background: var(--rv-bar);

	i {
		width: 1.25rem;
		height: 1.25rem;
		border-radius: 50%;
		border: 1.5px solid rgba(255, 255, 255, 0.55);
	}
}

.rv-cols {
	margin-top: 0.9rem;
	display: grid;
	grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
	gap: 1rem;
	align-items: start;
}

.rv-label {
	display: block;
	margin: 0.15rem 0.3rem 0.6rem;
	font-size: 0.58rem;
	letter-spacing: 2.5px;
	color: var(--rv-label);
}

.rv-list {
	list-style: none;
}

/* a fixed floor for three pills, so the frame never changes height
   while conversations move between the columns */

.rv-active {
	display: flex;
	flex-direction: column;
	gap: 0.55rem;
	min-height: calc(3 * 3.4rem + 2 * 0.55rem);
}

.rv-contacts {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 0.55rem;
	align-content: start;
	min-height: calc(2 * 7.6rem + 0.55rem);
}

.rv-chat {
	position: relative;
}

.rv-av {
	flex: none;
	display: grid;
	place-items: center;
	border-radius: 50%;
	background: var(--av);
	color: #fff;
	font-family: "Roaheregular", serif;
	font-size: 1.1rem;
	line-height: 1;
}

.rv-body {
	min-width: 0;
	display: flex;
	flex-direction: column;
	line-height: 1.25;
}

.rv-name {
	font-size: 0.78rem;
}

.rv-msg {
	font-size: 0.64rem;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.rv-tick {
	margin-left: 0.15rem;
	letter-spacing: -0.2em;
	opacity: 0.9;
}

.rv-badge {
	position: absolute;
	min-width: 1.15rem;
	height: 1.15rem;
	padding: 0 0.3rem;
	display: grid;
	place-items: center;
	border-radius: 999px;
	background: #1d1d1d;
	color: #fff;
	font-size: 0.6rem;
	line-height: 1;
}

/* same element, two looks: the column decides which one */

.rv-active .rv-chat {
	height: 3.4rem;
	padding: 0 0.9rem 0 0.45rem;
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto;
	align-items: center;
	gap: 0.6rem;
	border-radius: 999px;
	background: var(--accent);
	color: #fff;
	box-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.25),
		0 0.6rem 1.2rem color-mix(in srgb, var(--accent) 28%, transparent);
	transition:
		background-color 0.7s ease,
		box-shadow 0.7s ease;

	.rv-av {
		width: 2.5rem;
		height: 2.5rem;
		box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
	}

	.rv-msg {
		opacity: 0.9;
	}

	.rv-time {
		align-self: start;
		margin-top: 0.75rem;
		font-size: 0.6rem;
		opacity: 0.85;
	}

	.rv-badge {
		right: 0.9rem;
		bottom: 0.6rem;
	}
}

/* a conversation that has gone quiet loses its colour first */

.rv-active .rv-chat.is-quiet {
	background: #c4b3a6;
	box-shadow: none;
}

.rv-contacts .rv-chat {
	min-height: 7.6rem;
	padding: 0.8rem 0.5rem 0.6rem;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.2rem;
	border-radius: 1rem;
	background: var(--rv-card);
	color: #1d1d1d;
	text-align: center;
	box-shadow: 0 0.4rem 1rem rgba(0, 0, 0, 0.06);
	transition: box-shadow 0.5s ease;

	.rv-av {
		width: 2.3rem;
		height: 2.3rem;
	}

	.rv-body {
		align-items: center;
		width: 100%;
	}

	.rv-msg {
		max-width: 100%;
		margin-top: 0.3rem;
		padding: 0.2rem 0.55rem;
		border-radius: 999px;
		background: var(--rv-chip);
		font-size: 0.58rem;
		color: #555;
	}

	.rv-time {
		font-size: 0.55rem;
		color: #8a7d70;
	}

	.rv-badge {
		top: 0.45rem;
		right: 0.45rem;
		background: var(--accent);
	}
}

/* a quiet contact that just received a message */

.rv-contacts .rv-chat.is-pinged {
	box-shadow:
		0 0 0 2px var(--accent),
		0 0.6rem 1.4rem color-mix(in srgb, var(--accent) 25%, transparent);
}

.rv-replay {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.55rem 1rem;
	border: 1px solid rgba(0, 0, 0, 0.18);
	border-radius: 999px;
	background: transparent;
	font-family: "Poppins", sans-serif;
	font-size: 0.8rem;
	color: var(--ink-soft);
	cursor: pointer;
	visibility: hidden;
	opacity: 0;
	transition: opacity 0.4s ease, background-color 0.2s ease;
}

.rv-replay.is-ready {
	visibility: visible;
	opacity: 1;
}

.rv-replay:hover {
	background: rgba(0, 0, 0, 0.05);
}

.rv-replay:focus-visible {
	outline: 2px solid var(--ink);
	outline-offset: 4px;
}

/* =========================================================
   PROBLEM 2 — MESSAGES WITH THEIR OWN RULES
   ========================================================= */

.rules-intro {
	max-width: 40rem;
	margin-bottom: 2.8rem;
	font-size: 1.05rem;
	line-height: 1.85;
	color: var(--ink-soft);
}

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

/* the same surface as the home-screen replica above: Rivo's own
   background, so every piece of Rivo UI on the page matches */

.rule-demo {
	/* tall enough for the settings panel, so all three titles line up */
	min-height: 9.6rem;
	margin-bottom: 1.4rem;
	padding: 1.4rem;
	display: flex;
	align-items: center;
	justify-content: flex-end;
	border-radius: 1.2rem;
	background: #e5ddd6;
	border: 1px solid rgba(0, 0, 0, 0.06);
	box-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.6),
		0 1.2rem 2.4rem rgba(0, 0, 0, 0.1);
	font-family: "Poppins", sans-serif;

	.msg {
		max-width: 85%;
	}

	/* bubbles were written for a dark window; on the light surface
	   their quiet states need dark text */
	.msg-once[data-state="gone"] {
		color: #6b5d51;
		border-color: color-mix(in srgb, var(--accent) 60%, transparent);
	}

	.msg-capsule[data-state="locked"] {
		background: color-mix(in srgb, var(--accent) 14%, #fff);
		border-color: color-mix(in srgb, var(--accent) 40%, transparent);
		color: #3b2416;
	}
}

.rule-demo-settings {
	flex-direction: column;
	align-items: stretch;
	justify-content: center;
	gap: 0.45rem;
}

.rs-label {
	margin: 0 0.25rem 0.1rem;
	font-size: 0.55rem;
	letter-spacing: 2.5px;
	color: #786859;
}

.rs-row {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	padding: 0.6rem 0.8rem;
	border-radius: 0.85rem;
	background: #f7f4f0;
	box-shadow: 0 0.3rem 0.8rem rgba(0, 0, 0, 0.05);
	font-size: 0.8rem;
	color: #1d1d1d;

	svg {
		flex: none;
	}
}

.rs-muted {
	opacity: 0.5;
	box-shadow: none;
}

.rs-icon {
	color: var(--accent);
}

.rs-count {
	margin-left: auto;
	min-width: 1.2rem;
	height: 1.2rem;
	padding: 0 0.3rem;
	display: grid;
	place-items: center;
	border-radius: 999px;
	background: var(--accent);
	color: #fff;
	font-size: 0.6rem;
	line-height: 1;
}

.rs-muted .rs-chev {
	margin-left: auto;
}

.rs-chev {
	color: #9a8b7e;
}

@media screen and (max-width: 1024px) {
	.rule-list {
		gap: 2.5rem 1.6rem;
	}

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

	.sorting-copy p {
		max-width: 40rem;
	}
}

/* =========================================================
   SECURITY — the pipeline is a real sequence, so it is numbered
   ========================================================= */

.security-intro p {
	max-width: 40rem;
	font-size: 1.05rem;
	line-height: 1.85;
	color: var(--ink-soft);
}

.stored {
	margin-top: 3.5rem;
	padding: 2rem 2.4rem;
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	gap: 1.2rem 3rem;
	align-items: end;

	figcaption {
		grid-column: 1 / -1;
		font-size: 0.8rem;
		color: rgba(255, 255, 255, 0.6);
	}

	dl div {
		display: flex;
		align-items: baseline;
		gap: 1.2rem;
		padding: 0.55rem 0;
		border-bottom: 1px solid rgba(255, 255, 255, 0.08);
	}

	dt {
		min-width: 5.5rem;
		font-family: "Poppins", sans-serif;
		font-size: 0.78rem;
		color: rgba(255, 255, 255, 0.55);
	}

	dd code {
		color: var(--accent);
		word-break: break-all;
	}

	>p {
		max-width: 17rem;
		font-size: 0.95rem;
		line-height: 1.6;
		color: rgba(255, 255, 255, 0.85);
	}
}

.js-motion .chat {
	animation: rise-in 1s var(--ease-out) 0.25s both;
}

.js-motion.motion-hold .chat {
	animation-play-state: paused;
}

/* ---- the chat demo ----
   Messages are hidden only while JS is in charge. If the script
   never arms the demo, a delayed keyframe reveals them anyway. */

.js-motion .chat .msg {
	opacity: 0;
	transform: translateY(0.6rem) scale(0.97);
	animation: msg-failsafe 0s linear 5s forwards;
}

.js-motion .chat.is-armed .msg {
	animation: none;
}

.js-motion .chat .msg.is-in {
	opacity: 1;
	transform: none;
}

@media screen and (max-width: 899px) {
	.chat {
		grid-column: 1 / -1;
	}
}

@media screen and (max-width: 767px) {
	.chat {
		width: min(21rem, 100%);
		height: 29rem;
	}

	.case-sorting,
	.rule-list {
		grid-template-columns: minmax(0, 1fr);
	}

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

	.stored {
		grid-template-columns: minmax(0, 1fr);
		padding: 1.6rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.chat,
	.chat-typing i {
		animation: none !important;
	}
}

.security-intro p + p {
	margin-top: 1rem;
}

/* =========================================================
   DELIVERY — nothing lost when the connection drops.
   The window reuses the hero's chat styles; these are only
   the parts that show a message's journey.
   ========================================================= */
.rivo-feature {
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
	gap: 2.5rem 4.5rem;
	align-items: center;
}

.rivo-copy p {
	max-width: 34rem;
	font-size: 1.05rem;
	line-height: 1.85;
	color: var(--ink-soft);
}

.rivo-copy p + p {
	margin-top: 1rem;
}

.rivo-copy code,
.rivo-proofs code {
	font-size: 0.88em;
	padding: 0.08em 0.35em;
	border-radius: 0.35em;
	background: rgba(0, 0, 0, 0.07);
}

.dl-demo {
	margin: 0;
	display: grid;
	gap: 0.9rem;
	justify-items: center;
}

.chat.dl-chat {
	width: min(25rem, 100%);
	height: 22rem;
	transform: none;
	color: #fff;
}

.dl-chat .chat-status {
	transition: color 0.3s;
}

.dl-chat .chat-status::before {
	transition: background-color 0.3s;
}

.dl-chat.is-offline .chat-status {
	color: #f2c879;
}

.dl-chat.is-offline .chat-status::before {
	background: #f2c879;
}

/* the phone asleep: the screen dims */
.dl-chat .chat-log {
	transition: opacity 0.5s;
}

.dl-chat.is-asleep .chat-log {
	opacity: 0.25;
}

.dl-msg {
	animation: dl-in 0.35s ease-out both;
}

.dl-tick {
	margin-left: 0.4rem;
	font-size: 0.68rem;
	opacity: 0.75;
	font-family: "Poppins", sans-serif;
}

.dl-edited {
	display: block;
	margin-top: 0.1rem;
	font-size: 0.6rem;
	opacity: 0.6;
}

.msg-them.is-updated {
	animation: dl-flash 1.2s ease-out;
}

@keyframes dl-in {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: none; }
}

@keyframes dl-flash {
	0% { box-shadow: 0 0 0 0 rgba(242, 200, 121, 0.8); }
	100% { box-shadow: 0 0 0 0.6rem rgba(242, 200, 121, 0); }
}

/* what happens behind the screen, line by line */
.dl-log {
	width: min(25rem, 100%);
	margin: 0;
	padding: 0.85rem 1rem;
	min-height: 9.6rem;
	list-style: none;
	border-radius: 1rem;
	background: #121212;
	color: rgba(255, 255, 255, 0.78);
	font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
	font-size: 0.68rem;
	line-height: 1.7;
}

.dl-log li {
	animation: dl-in 0.3s ease-out both;
}

.dl-log .is-server { color: #9ec5ff; }
.dl-log .is-warn { color: #f2c879; }
.dl-log .is-ok { color: var(--mint); }

.dl-verdict {
	min-height: 1.4rem;
	font-size: 0.9rem;
	color: var(--ink-soft);
	text-align: center;
	opacity: 0;
	transition: opacity 0.4s;
}

.dl-verdict.is-on {
	opacity: 1;
}

/* ---- built to be trusted: a checklist ---- */
.rivo-proofs {
	margin-top: 1.6rem;
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 1rem 2.5rem;
	padding: 0;
	list-style: none;
}

.rivo-proofs li {
	padding-left: 1.5rem;
	position: relative;
	line-height: 1.7;
	color: var(--ink-soft);
}

.rivo-proofs li::before {
	content: "";
	position: absolute;
	left: 0.2rem;
	top: 0.6em;
	width: 0.5rem;
	height: 0.5rem;
	border-radius: 50%;
	background: var(--accent);
}

.rivo-proofs b {
	color: var(--ink);
	font-weight: 600;
}

@media screen and (max-width: 1024px) {
	.rivo-feature {
		grid-template-columns: minmax(0, 1fr);
	}

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

@media (prefers-reduced-motion: reduce) {
	.dl-msg,
	.dl-log li,
	.msg-them.is-updated {
		animation: none;
	}
}

/* ---- gallery: the screenshots keep their own shape instead of being cropped to 16:10 ---- */
.shots .shot img {
	aspect-ratio: 1600 / 932;
}
