/* Symbolon theme: the one of Noctua and Phylax (Oxocarbon palette, dark, Cascadia Code), so that
   signing in feels like part of the same set of applications. The font comes from the device if
   installed, else from /fonts/ when [theme] lists it (as Phylax does), else the system monospace.
   The @font-face rules are in /static/fonts.css, written by symd from [theme]: empty without
   fonts, so that a browser never asks for a font that is not served. */

:root {
	color-scheme: dark;
	--font: "Cascadia Code", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
	--base: #161616;
	--mantle: #0f0f0f;
	--surface0: #262626;
	--surface1: #393939;
	--surface2: #525252;
	--muted: #8d8d8d;
	--subtext: #c6c6c6;
	--text: #dde1e6;
	--bright: #f2f4f8;
	--blue: #78a9ff;
	--cyan: #82cfff;
	--green: #42be65;
	--magenta: #ee5396;
	--purple: #be95ff;
	--yellow: #f1c21b;
}

* { box-sizing: border-box; }

/* Fluid text size: 15 px on phones, up to 18 px on large screens */
html { font-size: clamp(15px, 0.45vw + 9.5px, 18px); }

html, body {
	margin: 0;
	background: var(--base);
	color: var(--text);
	font-family: var(--font);
	line-height: 1.55;
}

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--cyan); text-decoration: underline; }
code { background: var(--mantle); border-radius: 4px; padding: 1px 5px; font-size: 0.9em; }

button {
	font: inherit;
	color: var(--text);
	background: var(--surface0);
	border: 1px solid var(--surface1);
	border-radius: 6px;
	padding: 4px 12px;
	cursor: pointer;
	transition: border-color 0.12s ease, color 0.12s ease, background-color 0.12s ease;
}
button:hover { border-color: var(--blue); color: var(--bright); }
button:disabled { opacity: 0.6; cursor: wait; }
button.danger { color: var(--magenta); }
button.danger:hover { border-color: var(--magenta); }
button.link { background: none; border: none; padding: 0; color: var(--muted); }
button.link:hover { color: var(--blue); text-decoration: underline; }
/* The main action of a page */
button.primary {
	display: block;
	width: 100%;
	padding: 12px 16px;
	border: none;
	border-radius: 8px;
	background: var(--blue);
	color: var(--base);
	font-weight: 700;
}
button.primary:hover { background: var(--cyan); color: var(--base); }
button.primary.inline { display: inline-block; width: auto; padding: 6px 16px; }
form { margin: 0; }
form.inline { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; max-width: 100%; }

input[type="text"], input[type="email"] {
	font: inherit;
	width: 100%;
	min-width: 0;
	color: var(--text);
	background: var(--mantle);
	border: 1px solid var(--surface1);
	border-radius: 6px;
	padding: 6px 10px;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="text"]:focus, input[type="email"]:focus {
	outline: none;
	border-color: var(--blue);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 22%, transparent);
}
input[type="file"] { font: inherit; font-size: 0.85rem; color: var(--subtext); max-width: 100%; }
input[type="file"]::file-selector-button {
	font: inherit;
	color: var(--text);
	background: var(--surface0);
	border: 1px solid var(--surface1);
	border-radius: 6px;
	padding: 4px 12px;
	margin-right: 10px;
	cursor: pointer;
}
label { display: block; margin: 10px 0 4px; color: var(--subtext); font-size: 0.85rem; }
/* The picture form: the file picker above its button, both centred */
.picture-upload { display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 100%; }
.picture-upload input[type="file"] { max-width: 14rem; }
.picture-actions { display: flex; gap: 8px; }

.small, .meta { color: var(--muted); font-size: 0.85rem; }
.error, #status { color: var(--magenta); }
#status:empty { display: none; }
.ok { color: var(--green); }
.warn { color: var(--yellow); }
/* Messages: a coloured bar on the left, like the Phylax summary */
.notice, .warning {
	margin: 0 0 20px;
	padding: 10px 14px;
	border: 1px solid var(--surface1);
	border-left-width: 4px;
	border-radius: 8px;
	background: var(--mantle);
	text-align: left;
}
.notice { border-left-color: var(--green); }
.warning { border-left-color: var(--yellow); }

/* ─── Header (account pages): brand on the left, profile menu on the right ─── */
.topbar {
	position: sticky;
	top: 0;
	z-index: 5;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 12px max(24px, calc((100% - 64rem) / 2 + 24px));
	border-bottom: 1px solid var(--surface1);
}
/* Lightly see-through, the page blurred behind it; the blur sits on a layer behind the bar so
   that the bar does not become the frame of the profile menu's fixed closing layer */
.topbar::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	background: color-mix(in srgb, var(--base) 72%, transparent);
	-webkit-backdrop-filter: blur(14px) saturate(140%);
	backdrop-filter: blur(14px) saturate(140%);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
	.topbar::before { background: var(--base); }
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--bright); font-size: 1.15rem; font-weight: 700; }
.brand:hover { text-decoration: none; color: var(--bright); }
.brand img { display: block; }

/* Profile menu: a native disclosure widget, no JavaScript */
.profile { position: relative; }
.profile summary {
	display: flex;
	align-items: center;
	gap: 10px;
	list-style: none;
	cursor: pointer;
	padding: 3px 8px 3px 3px;
	border-radius: 20px;
	transition: background-color 0.15s ease;
}
.profile summary::-webkit-details-marker { display: none; }
/* While the menu is open, a transparent layer covers the page: the first click anywhere else
   lands on the summary and closes the menu */
.profile[open] summary::before { content: ""; position: fixed; inset: 0; z-index: 25; cursor: default; }
.profile summary:hover, .profile[open] summary { background: var(--surface0); }
.profile[open] .profile-menu { animation: menu-in 0.16s ease-out; }
@keyframes menu-in {
	from { opacity: 0; transform: translateY(-4px) scale(0.98); }
	to { opacity: 1; transform: none; }
}
.username { color: var(--bright); font-weight: 600; max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-menu {
	position: absolute;
	right: 0;
	top: calc(100% + 8px);
	z-index: 30;
	min-width: 16rem;
	padding: 6px;
	background: var(--mantle);
	border: 1px solid var(--surface1);
	border-radius: 10px;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
	transform-origin: top right;
}
.profile-name { margin: 0 0 4px; padding: 8px 10px 10px; color: var(--bright); font-weight: 700; border-bottom: 1px solid var(--surface1); }
.profile-name .small { display: block; font-weight: 400; }
.menu-item {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	padding: 8px 10px;
	border: none;
	border-radius: 6px;
	background: none;
	color: var(--subtext);
	font: inherit;
	text-align: left;
	white-space: nowrap;
	cursor: pointer;
	transition: background-color 0.12s ease, color 0.12s ease;
}
.menu-item:hover { background: var(--surface0); color: var(--bright); text-decoration: none; }
.menu-item.signout:hover { color: var(--magenta); }
.menu-item svg { display: block; flex-shrink: 0; }

/* Picture, or initials on a disc; a picture that fails to load draws nothing over them */
.avatar { position: relative; display: block; width: 30px; height: 30px; flex-shrink: 0; }
.avatar .initial, .avatar img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; }
.avatar .initial {
	display: flex; align-items: center; justify-content: center;
	background: var(--surface1); color: var(--bright); font-weight: 700; font-size: 0.85rem;
}
.avatar img { object-fit: cover; color: transparent; font-size: 0; overflow: hidden; }
.avatar.large { width: 96px; height: 96px; }
.avatar.large .initial { font-size: 2rem; }

/* ─── Account pages ─── */
main.page { max-width: 64rem; margin: 0 auto; padding: 28px 24px 64px; }
main.page h1 { margin: 0 0 20px; font-size: 1.4rem; color: var(--bright); }
.panel { margin-bottom: 22px; padding: 16px 18px; border: 1px solid var(--surface0); border-radius: 10px; }
.panel h2 { margin: 0 0 10px; font-size: 1rem; color: var(--purple); }
.panel > p { margin: 0 0 12px; }
.panel > :last-child { margin-bottom: 0; }

/* Profile: the form on the left, the picture on the right (above it on phones) */
.profile-layout { display: grid; grid-template-columns: minmax(0, 1fr) 15rem; gap: 8px 32px; align-items: start; }
.profile-picture { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.profile-picture h3 { margin: 0; font-size: 0.85rem; font-weight: 400; color: var(--subtext); }
/* A field shown but not editable (the username) */
input[readonly] { color: var(--muted); background: transparent; border-style: dashed; cursor: default; }
input[readonly]:focus { border-color: var(--surface1); box-shadow: none; }
/* Two columns of at most 20rem: a field is as wide as what it holds, not as the page */
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 20rem)); gap: 0 16px; }
.fields .wide { grid-column: 1 / -1; }
.form-actions { margin-top: 14px; }

/* Rows of a list: passkeys, devices, applications */
.rows { list-style: none; margin: 0 0 14px; padding: 0; border: 1px solid var(--surface0); border-radius: 10px; }
.row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px 16px;
	padding: 10px 14px;
	border-bottom: 1px solid var(--surface0);
}
.row:last-child { border-bottom: none; }
.row:hover { background: var(--mantle); }
.row .main { flex: 1 1 16rem; min-width: 0; }
.row .main strong { color: var(--bright); font-weight: 600; }
.row .main .small { display: block; overflow-wrap: anywhere; }
.row .when { color: var(--subtext); font-size: 0.85rem; text-align: right; }
.row .when .small { display: block; }
.row form.inline input[type="text"] { width: auto; flex: 1 1 12rem; }

.tag { color: var(--base); background: var(--green); border-radius: 4px; padding: 0 6px; font-size: 0.75rem; margin-left: 6px; white-space: nowrap; }
.tag.synced { background: var(--purple); }
.tag.bound { background: var(--cyan); }

.panel .add button.primary { display: inline-block; width: auto; padding: 8px 18px; }
.panel .add #status { margin: 10px 0 0; }
/* Status badge (verified email…): tinted text on a tinted background, as in Noctua */
.badge {
	display: inline-block;
	margin-right: 6px;
	padding: 0 7px;
	border: 1px solid;
	border-radius: 4px;
	font-size: 0.78rem;
	line-height: 1.6;
	vertical-align: 1px;
}
.badge.ok { color: var(--green); border-color: color-mix(in srgb, var(--green) 45%, transparent); background: color-mix(in srgb, var(--green) 12%, transparent); }
.badge.warn { color: var(--yellow); border-color: color-mix(in srgb, var(--yellow) 45%, transparent); background: color-mix(in srgb, var(--yellow) 12%, transparent); }
/* A field and its badge on one line (the email and its state) */
.with-badge { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; max-width: calc(20rem + 8rem); }
.with-badge input { flex: 1 1 14rem; max-width: 20rem; }
.with-badge .badge { margin: 0; cursor: help; white-space: nowrap; }
.counter { font-size: 1.35rem; font-weight: 700; color: var(--bright); }
.counter.empty { color: var(--yellow); }

/* Recent activity */
.events { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.events th { text-align: left; color: var(--subtext); border-bottom: 1px solid var(--surface1); padding: 6px 8px; }
.events td { border-bottom: 1px solid var(--surface0); padding: 7px 8px; vertical-align: top; overflow-wrap: anywhere; }
.events tr:last-child td { border-bottom: none; }
.events td.refused { color: var(--magenta); }
.events td.ip { font-variant-numeric: tabular-nums; color: var(--subtext); white-space: nowrap; }

/* Recovery codes, shown once */
ol.codes { columns: 2; margin: 0 0 16px; padding-left: 2.2em; font-size: 1.05rem; }
ol.codes li { padding: 3px 0; }
ol.codes code { background: none; padding: 0; color: var(--bright); letter-spacing: 0.04em; }

/* Dialog over the page (identity confirmation), the page blurred behind */
dialog.dialog {
	width: min(28rem, calc(100% - 32px));
	padding: 24px 24px 18px;
	color: var(--text);
	background: var(--mantle);
	border: 1px solid var(--surface1);
	border-radius: 14px;
	box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
}
dialog.dialog::backdrop {
	background: color-mix(in srgb, var(--base) 45%, transparent);
	-webkit-backdrop-filter: blur(8px);
	backdrop-filter: blur(8px);
}
dialog.dialog h2 { margin: 0 0 8px; font-size: 1.1rem; color: var(--bright); }
dialog.dialog p { margin: 0 0 16px; color: var(--subtext); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
dialog.dialog .error:empty { display: none; }
dialog.dialog .error { margin: 12px 0 0; }

/* ─── Standalone pages: sign-in, consent, enrollment, recovery, errors ─── */
body.card {
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 24px;
}
.signin-card {
	width: 100%;
	max-width: 26rem;
	padding: 36px 32px;
	text-align: center;
	background: var(--mantle);
	border: 1px solid var(--surface1);
	border-radius: 16px;
}
.signin-card.wide { max-width: 36rem; }
.signin-logo { display: block; width: 6rem; height: 6rem; margin: 0 auto; }
.signin-card h1 { margin: 16px 0 6px; font-size: 1.6rem; color: var(--bright); }
.signin-tagline { margin: 0 0 24px; color: var(--muted); }
.signin-card p { margin: 0 0 16px; }
.signin-card .context { color: var(--subtext); }
.signin-card .context strong { color: var(--bright); }
.signin-card .error, .signin-card #status { margin: 14px 0 0; }
.signin-card form + form, .signin-card .choices { margin-top: 10px; }
.signin-card .choices { display: flex; gap: 10px; }
.signin-card .choices button { flex: 1; padding: 10px 12px; }
.signin-card .choices button.primary { width: auto; }
.signin-card label { text-align: left; }
.signin-card input[type="text"] { margin-bottom: 14px; }
/* The recovery code: centred and spaced, easier to compare with the paper */
.signin-card #code { text-align: center; letter-spacing: 0.08em; }
.signin-card .below { margin: 18px 0 0; font-size: 0.85rem; }
.signin-card ul.scopes { list-style: none; margin: 0 0 20px; padding: 0; text-align: left; border: 1px solid var(--surface0); border-radius: 10px; }
.signin-card ul.scopes li { padding: 8px 14px; border-bottom: 1px solid var(--surface0); }
.signin-card ul.scopes li:last-child { border-bottom: none; }
.signin-card ul.scopes li::before { content: "✓"; color: var(--green); margin-right: 10px; }
.signin-card .codes { text-align: left; }
.signin-card .account { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0 0 20px; color: var(--subtext); font-size: 0.9rem; }

/* Phones */
@media (max-width: 760px) {
	.topbar { padding: 10px 16px; }
	.username { display: none; }
	.profile summary { padding-right: 3px; }
	main.page { padding: 18px 14px 48px; }
	.panel { padding: 14px; }
	.row .when { text-align: left; }
	.fields { grid-template-columns: minmax(0, 1fr); }
	.profile-layout { grid-template-columns: minmax(0, 1fr); }
	.profile-picture { order: -1; }
	ol.codes { columns: 1; font-size: 0.9rem; padding-left: 1.8em; }
	/* A code never breaks in the middle: it is copied by hand */
	ol.codes code { white-space: nowrap; }
	/* Recent activity: one block per event, the event first, then date,
	   device and IP on small lines (four columns do not fit a phone) */
	.events thead { display: none; }
	.events tr { display: flex; flex-direction: column; padding: 9px 0; border-bottom: 1px solid var(--surface0); }
	.events tr:last-child { border-bottom: none; }
	.events td { padding: 0; border: none; }
	.events td:nth-child(2) { order: -1; color: var(--bright); }
	.events td:nth-child(2).refused { color: var(--magenta); }
	.events td:not(:nth-child(2)) { font-size: 0.8rem; color: var(--muted); }
	.events td.ip { overflow-wrap: anywhere; white-space: normal; }
	/* Dialog: buttons full width, the main one first */
	.dialog-actions { flex-direction: column; }
	.dialog-actions button { width: 100%; }
	body.card { padding: 14px; justify-content: flex-start; }
	.signin-card { padding: 28px 20px; }
}

/* Fewer movements when the system asks for it */
@media (prefers-reduced-motion: reduce) {
	button, input, .profile summary, .menu-item { transition: none; }
	.profile[open] .profile-menu { animation: none; }
}
