:root {
	--ink: #14213d;
	--ink-soft: #4a5672;
	--paper: #f5f7fa;
	--surface: #ffffff;
	--line: #dde3ec;
	--sea: #1f6fb2;
	--sea-strong: #175a92;
	--on-sea: #ffffff;
	--lemon: #f2c14e;
	--lemon-soft: #fbe7b0;
	--owed: #1e7f55;
	--owes: #b93a26;
	--focus: #1f6fb2;

	--font: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
	--step--1: 0.875rem;
	--step-0: 1rem;
	--step-1: 1.25rem;
	--step-2: 1.6rem;
	--step-3: 2.25rem;
	--radius-s: 6px;
	--radius-m: 12px;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--ink: #e8edf6;
		--ink-soft: #a5b0c6;
		--paper: #0f1a2e;
		--surface: #16233b;
		--line: #2a3a57;
		--sea: #5aa4e6;
		--sea-strong: #7db8ee;
		--on-sea: #0f1a2e;
		--lemon: #f2c14e;
		--lemon-soft: #3d3420;
		--owed: #5cc795;
		--owes: #f08a75;
		--focus: #7db8ee;
		color-scheme: dark;
	}
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

html {
	-webkit-text-size-adjust: 100%;
}

body {
	margin: 0;
	background: var(--paper);
	color: var(--ink);
	font-family: var(--font);
	font-size: var(--step-0);
	line-height: 1.5;
	font-optical-sizing: auto;
}

main {
	max-width: 640px;
	margin: 0 auto;
	padding: 8px 16px 120px;
	outline: none;
}

h1,
h2,
h3 {
	line-height: 1.15;
	margin: 0;
	text-wrap: balance;
}

h1 {
	font-size: var(--step-3);
	font-weight: 750;
	letter-spacing: -0.02em;
}

h2 {
	font-size: var(--step-1);
	font-weight: 650;
}

p {
	margin: 0;
}

a {
	color: var(--sea);
	text-underline-offset: 3px;
}

:focus-visible {
	outline: 3px solid var(--focus);
	outline-offset: 2px;
}

/* <main> is focused after each navigation for screen readers; it needs no visible ring. */
main:focus-visible {
	outline: none;
}

.muted {
	color: var(--ink-soft);
}

.small {
	font-size: var(--step--1);
}

.lede {
	color: var(--ink-soft);
	font-size: var(--step-1);
	line-height: 1.4;
}

/* Top bar ------------------------------------------------------------------ */

.topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	max-width: 640px;
	margin: 0 auto;
	padding: 14px 16px;
}

.brand {
	font-weight: 800;
	font-size: var(--step-1);
	color: var(--ink);
	text-decoration: none;
	display: inline-flex;
	align-items: center;
	gap: 8px;
}

.brand::before {
	content: "";
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: var(--lemon);
	box-shadow: inset 0 0 0 3px var(--ink);
}

.nav-user {
	color: var(--ink-soft);
	text-decoration: none;
	font-weight: 550;
}

.nav-user:hover {
	color: var(--ink);
}

/* Layout helpers ------------------------------------------------------------- */

.stack {
	display: grid;
	gap: 14px;
}

.stack-lg {
	display: grid;
	gap: 28px;
}

.row {
	display: flex;
	gap: 10px;
	align-items: center;
	flex-wrap: wrap;
}

.row.end {
	justify-content: flex-end;
}

.row.spread {
	justify-content: space-between;
}

.page-head {
	display: flex;
	justify-content: space-between;
	align-items: end;
	gap: 16px;
	flex-wrap: wrap;
	padding-top: 12px;
}

.pair {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 12px;
}

.crumb {
	font-size: var(--step--1);
	margin: 8px 0 6px;
}

.crumb a {
	color: var(--ink-soft);
}

.crumb a::before {
	content: "‹ ";
}

/* Forms ----------------------------------------------------------------------- */

.field {
	display: grid;
	gap: 6px;
}

.field-label {
	font-weight: 600;
	font-size: var(--step--1);
}

.hint {
	color: var(--ink-soft);
	font-size: var(--step--1);
}

input,
select {
	font: inherit;
	color: inherit;
	background: var(--surface);
	border: 1.5px solid var(--line);
	border-radius: var(--radius-s);
	padding: 10px 12px;
	min-height: 44px;
	width: 100%;
}

input:focus-visible,
select:focus-visible {
	border-color: var(--focus);
	outline-offset: 0;
}

input:user-invalid {
	border-color: var(--owes);
}

input.short {
	max-width: 9rem;
}

input.tiny {
	max-width: 5rem;
}

input[type="checkbox"] {
	width: 22px;
	height: 22px;
	min-height: 0;
	accent-color: var(--sea);
}

.amount-input {
	font-size: var(--step-1);
	font-weight: 650;
	font-variant-numeric: tabular-nums;
}

.code-input,
.code {
	letter-spacing: 0.12em;
	font-weight: 700;
}

.form-error {
	color: var(--owes);
	font-weight: 550;
}

.form-error:empty {
	display: none;
}

/* Buttons --------------------------------------------------------------------- */

button,
.button {
	font: inherit;
	font-weight: 600;
	color: var(--ink);
	background: var(--surface);
	border: 1.5px solid var(--line);
	border-radius: 999px;
	padding: 9px 18px;
	min-height: 44px;
	cursor: pointer;
	text-decoration: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

button:hover,
.button:hover {
	border-color: var(--ink-soft);
}

button:disabled {
	opacity: 0.6;
	cursor: progress;
}

.primary {
	background: var(--sea);
	border-color: var(--sea);
	color: var(--on-sea);
}

.primary:hover {
	background: var(--sea-strong);
	border-color: var(--sea-strong);
}

.danger {
	background: var(--owes);
	border-color: var(--owes);
	color: #fff;
}

.danger-link,
.link-button {
	background: none;
	border: none;
	padding: 8px 0;
	min-height: 0;
	justify-self: start;
	text-decoration: underline;
	text-underline-offset: 3px;
	font-weight: 550;
}

.danger-link {
	color: var(--owes);
}

.link-button {
	color: var(--sea);
}

.small-button {
	min-height: 36px;
	padding: 4px 14px;
	font-size: var(--step--1);
}

.icon-button {
	min-height: 36px;
	width: 36px;
	padding: 0;
	font-size: 1.3rem;
	line-height: 1;
	color: var(--ink-soft);
}

.big {
	padding: 14px 28px;
	font-size: var(--step-1);
	box-shadow: 0 6px 20px rgb(20 33 61 / 0.25);
}

/* Auth --------------------------------------------------------------------- */

.auth {
	display: grid;
	gap: 22px;
	padding-top: 6vh;
	max-width: 420px;
}

/* Lists ------------------------------------------------------------------------ */

.list {
	list-style: none;
	margin: 0;
	padding: 0;
	border-top: 1px solid var(--line);
}

.list > li {
	border-bottom: 1px solid var(--line);
}

.list-row {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 2px;
	color: inherit;
	text-decoration: none;
}

a.list-row:hover .row-title {
	text-decoration: underline;
	text-underline-offset: 3px;
}

.row-main {
	display: grid;
	flex: 1;
	min-width: 0;
}

.row-title {
	font-weight: 600;
	overflow-wrap: anywhere;
}

.amount {
	font-variant-numeric: tabular-nums;
	font-weight: 650;
	text-align: right;
	white-space: nowrap;
}

.amount .small {
	font-weight: 450;
}

.owed {
	color: var(--owed);
}

.owes {
	color: var(--owes);
}

.empty {
	display: grid;
	gap: 6px;
	padding: 28px 0;
}

.empty p:first-child {
	font-size: var(--step-1);
	font-weight: 650;
}

/* Project page --------------------------------------------------------------- */

.project h1 {
	margin-bottom: 18px;
}

/* The one bold element: the trip's balance, written as a sentence on a lemon band. */
.band {
	background: var(--lemon);
	color: #14213d;
	margin: 0 -16px;
	padding: 22px 16px 20px;
	display: grid;
	gap: 4px;
	position: relative;
}

.band::after {
	/* Torn ticket edge. */
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	bottom: -8px;
	height: 8px;
	background: radial-gradient(circle at 8px 0, var(--lemon) 6px, transparent 6.5px) 0 0 / 16px 8px repeat-x;
}

.band-sentence {
	font-size: clamp(2rem, 9vw, 3.2rem);
	font-weight: 800;
	line-height: 1.02;
	letter-spacing: -0.03em;
	font-variant-numeric: tabular-nums;
}

.band.is-owing .band-sentence {
	color: #8a2414;
}

.band-detail {
	font-weight: 500;
	opacity: 0.8;
}

@media (min-width: 672px) {
	.band {
		margin: 0;
		border-radius: var(--radius-m) var(--radius-m) 0 0;
	}
}

.tabs {
	display: flex;
	gap: 4px;
	margin: 30px 0 4px;
	border-bottom: 1.5px solid var(--line);
}

.tab {
	border: none;
	border-radius: 0;
	background: none;
	padding: 10px 14px;
	color: var(--ink-soft);
	border-bottom: 3px solid transparent;
	margin-bottom: -1.5px;
}

.tab[aria-selected="true"] {
	color: var(--ink);
	border-bottom-color: var(--ink);
}

.tab-panel {
	padding-top: 12px;
}

/* The tab bar already draws a rule; don't double it. */
.tab-panel > .stack-lg > .list:first-child {
	border-top: none;
}

.expense-page > h1 {
	margin-bottom: 20px;
}

.days {
	display: grid;
	gap: 22px;
}

.day {
	font-size: var(--step--1);
	font-weight: 600;
	color: var(--ink-soft);
	margin-bottom: 4px;
}

.payment .row-title {
	font-weight: 500;
	font-style: italic;
}

.balance-row {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 6px 12px;
	padding: 14px 2px;
}

.balance-detail {
	grid-column: 1 / -1;
	margin-top: -4px;
}

.meter {
	grid-column: 1 / -1;
	position: relative;
	height: 6px;
	background: var(--line);
	border-radius: 3px;
}

.meter::after {
	/* Centre line: left of it owes, right of it is owed. */
	content: "";
	position: absolute;
	left: 50%;
	top: -3px;
	bottom: -3px;
	width: 2px;
	background: var(--ink-soft);
}

.bar {
	position: absolute;
	top: 0;
	bottom: 0;
	border-radius: 3px;
}

.bar.plus {
	left: 50%;
	background: var(--owed);
}

.bar.minus {
	right: 50%;
	background: var(--owes);
}

.copy-row {
	display: flex;
	gap: 8px;
}

.copy-row input {
	flex: 1;
	min-width: 0;
}

.settings {
	padding-top: 24px;
	border-top: 1.5px solid var(--line);
}

.dock {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	justify-content: center;
	padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
	pointer-events: none;
}

.dock .button {
	pointer-events: auto;
}

/* Expense form ------------------------------------------------------------------ */

.split {
	border: none;
	padding: 0;
	margin: 0;
	display: grid;
	gap: 12px;
}

.split legend {
	font-weight: 650;
	font-size: var(--step-1);
	padding: 0;
	margin-bottom: 10px;
}

.segments {
	display: flex;
	border: 1.5px solid var(--line);
	border-radius: 999px;
	padding: 3px;
	background: var(--surface);
}

.segment {
	flex: 1;
	border: none;
	min-height: 38px;
	padding: 6px 10px;
	background: none;
	color: var(--ink-soft);
	font-size: var(--step--1);
}

.segment[aria-pressed="true"] {
	background: var(--ink);
	color: var(--paper);
}

.split-panel {
	border-top: 1px solid var(--line);
}

.split-row {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 8px 2px;
	border-bottom: 1px solid var(--line);
	min-height: 56px;
}

.split-row .row-title {
	flex: 1;
}

.split-row .amount {
	min-width: 5.5rem;
}

.stepper {
	display: inline-flex;
	align-items: center;
	border: 1.5px solid var(--line);
	border-radius: 999px;
	background: var(--surface);
}

.stepper button {
	border: none;
	background: none;
	min-height: 40px;
	width: 40px;
	padding: 0;
	font-size: 1.25rem;
	border-radius: 999px;
}

.stepper .stepper-value {
	border: none;
	min-height: 40px;
	width: 3rem;
	padding: 0;
	text-align: center;
	font-weight: 650;
	font-variant-numeric: tabular-nums;
	background: none;
	-moz-appearance: textfield;
	appearance: textfield;
}

.stepper .stepper-value::-webkit-inner-spin-button,
.stepper .stepper-value::-webkit-outer-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

.split-summary {
	font-weight: 550;
	color: var(--owed);
}

.split-summary.warn {
	color: var(--owes);
}

/* Loading ------------------------------------------------------------------------ */

body.is-loading main {
	opacity: 0.55;
	transition: opacity 0.2s;
}

body.is-loading::before {
	content: "";
	position: fixed;
	top: 0;
	left: 0;
	height: 3px;
	width: 35%;
	background: var(--sea);
	z-index: 20;
	animation: loading-bar 1.1s ease-in-out infinite;
}

@keyframes loading-bar {
	from {
		transform: translateX(-100%);
	}
	to {
		transform: translateX(300%);
	}
}

@media (prefers-reduced-motion: reduce) {
	body.is-loading::before {
		width: 100%;
		animation: none;
	}
}

/* Dialogs & toast -------------------------------------------------------------- */

dialog.sheet {
	border: none;
	border-radius: var(--radius-m);
	padding: 22px;
	width: min(440px, calc(100vw - 32px));
	background: var(--surface);
	color: var(--ink);
	box-shadow: 0 20px 60px rgb(0 0 0 / 0.3);
}

dialog.sheet::backdrop {
	background: rgb(20 33 61 / 0.45);
}

#toast {
	position: fixed;
	left: 50%;
	top: 16px;
	transform: translate(-50%, calc(-100% - 24px));
	visibility: hidden;
	background: var(--ink);
	color: var(--paper);
	padding: 10px 18px;
	border-radius: 999px;
	font-weight: 600;
	transition:
		transform 0.25s ease,
		visibility 0.25s;
	z-index: 10;
	max-width: calc(100vw - 32px);
}

#toast.visible {
	transform: translate(-50%, 0);
	visibility: visible;
}

@media (prefers-reduced-motion: reduce) {
	#toast {
		transition: none;
	}
}

@media (max-width: 420px) {
	.pair {
		grid-template-columns: 1fr;
	}

	.segment {
		padding: 6px 4px;
	}
}
