:root {
	/* Every colour is a light-dark(light, dark) pair; color-scheme below picks the side. */
	--ink: light-dark(#14213d, #e8edf6);
	--ink-soft: light-dark(#4a5672, #a5b0c6);
	--paper: light-dark(#f5f7fa, #0f1a2e);
	--surface: light-dark(#ffffff, #16233b);
	--line: light-dark(#dde3ec, #2a3a57);
	--sea: light-dark(#1f6fb2, #5aa4e6);
	--sea-strong: light-dark(#175a92, #7db8ee);
	--on-sea: light-dark(#ffffff, #0f1a2e);
	--owed: light-dark(#1e7f55, #5cc795);
	--owes: light-dark(#b93a26, #f08a75);
	--focus: light-dark(#1f6fb2, #7db8ee);

	--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;

	/* "system" (no data-theme): follow the device. */
	color-scheme: light dark;
}

:root[data-theme="light"] {
	color-scheme: light;
}

:root[data-theme="dark"] {
	color-scheme: dark;
}

/*
 * Accent colours, chosen per user. They colour the balance band on the trip page, the logo
 * dot and notices. --accent-ink is the text colour on top of --accent (at least 7:1 contrast).
 * Defined on any [data-accent] element so settings swatches can show each one.
 */
:root,
[data-accent="yellow"] {
	--accent: #f2c14e;
	--accent-ink: #14213d;
	--accent-soft: light-dark(#fbe7b0, #3d3420);
}

[data-accent="rose"] {
	--accent: #f5a8c2;
	--accent-ink: #3b0f24;
	--accent-soft: light-dark(#fde2ec, #46202f);
}

[data-accent="blue"] {
	--accent: #8fc4f2;
	--accent-ink: #0b2440;
	--accent-soft: light-dark(#dcebfb, #1b2d44);
}

[data-accent="green"] {
	--accent: #95d6a9;
	--accent-ink: #0d321d;
	--accent-soft: light-dark(#dcf3e3, #173a26);
}

[data-accent="red"] {
	--accent: #f2897b;
	--accent-ink: #3d0b05;
	--accent-soft: light-dark(#fde0db, #4a1f19);
}

*,
*::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;
	min-height: 44px;
}

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

/* Account button: an initial in a circle plus the name, sized as a full 44px touch target. */
.nav-user {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: 44px;
	padding: 0 14px 0 4px;
	border: 1.5px solid var(--line);
	border-radius: 999px;
	background: var(--surface);
	color: var(--ink);
	text-decoration: none;
	font-weight: 600;
}

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

.avatar {
	display: inline-grid;
	place-items: center;
	width: 34px;
	height: 34px;
	border-radius: 50%;
	background: var(--ink);
	color: var(--paper);
	font-weight: 700;
	font-size: var(--step--1);
}

.nav-user-name {
	max-width: 10rem;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* 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: 0;
}

.crumb a {
	color: var(--ink-soft);
	display: inline-flex;
	align-items: center;
	min-height: 44px;
}

.crumb a::before {
	/* A margin, not a trailing space: flex layout drops whitespace at the end of ::before. */
	content: "‹";
	margin-right: 0.3em;
}

/* 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;
}

.notice {
	background: var(--accent-soft);
	border-left: 4px solid var(--accent);
	padding: 12px 14px;
	border-radius: var(--radius-s);
	font-weight: 550;
}

.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 band in the user's accent. */
.band {
	background: var(--accent);
	color: var(--accent-ink);
	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(--accent) 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-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.pending {
	color: var(--ink-soft);
}

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

/* Appearance settings ---------------------------------------------------------- */

.choice-group {
	border: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 8px;
}

.choice-group legend {
	padding: 0;
	margin-bottom: 8px;
}

.swatches {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.swatch {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: 44px;
	padding: 4px 14px 4px 6px;
	border: 1.5px solid var(--line);
	border-radius: 999px;
	background: var(--surface);
	font-weight: 550;
	cursor: pointer;
}

.swatch-dot {
	width: 30px;
	height: 30px;
	border-radius: 50%;
	background: var(--accent);
	box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.12);
}

.swatch:has(input:checked) {
	border-color: var(--ink);
	box-shadow: inset 0 0 0 1px var(--ink);
}

.swatch:has(input:focus-visible),
.segments label:has(input:focus-visible) {
	outline: 3px solid var(--focus);
	outline-offset: 2px;
}

/* Radio-based segmented control (the button-based one uses aria-pressed). */
.segments label {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	font-weight: 600;
	border-radius: 999px;
}

.segments label:has(input:checked) {
	background: var(--ink);
	color: var(--paper);
}

.band-preview {
	margin: 0;
	border-radius: var(--radius-m) var(--radius-m) 0 0;
	padding: 16px;
}

.band-preview .band-sentence {
	font-size: var(--step-2);
}

/* 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;
	}
}
