:root {
	--bg: #f7f6f3;
	--card: #ffffff;
	--fg: #1c1b1a;
	--dim: #6b6862;
	--line: #dedbd4;
	--accent: #b5541c;
	--ok: #2f7d3a;
	--bad: #b3261e;
	--warn: #8a5a00;
	--chip: #efece6;
	--id-0: #b5541c;
	--id-1: #2f7d3a;
	--id-2: #2a64a8;
	--id-3: #7d3fa0;
	--id-4: #946a10;
	--id-5: #1b7f7f;
	--id-6: #a83565;
	--id-7: #5c6b1f;
	color-scheme: light;
}

/* dark when the system asks for it, unless the user picked light, or when
   the user picked dark (Station, Appearance) */
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #1c1b1a;
		--card: #262523;
		--fg: #ebe8e2;
		--dim: #a29e96;
		--line: #3b3936;
		--accent: #f08a4b;
		--ok: #7cc787;
		--bad: #f2867e;
		--warn: #e3b456;
		--chip: #33312e;
		--id-0: #f08a4b;
		--id-1: #7cc787;
		--id-2: #7fb2e6;
		--id-3: #c79be0;
		--id-4: #e3b456;
		--id-5: #6cc9c9;
		--id-6: #e88bb4;
		--id-7: #b5c46e;
		color-scheme: dark;
	}
}

:root[data-theme="dark"] {
	--bg: #1c1b1a;
	--card: #262523;
	--fg: #ebe8e2;
	--dim: #a29e96;
	--line: #3b3936;
	--accent: #f08a4b;
	--ok: #7cc787;
	--bad: #f2867e;
	--warn: #e3b456;
	--chip: #33312e;
	--id-0: #f08a4b;
	--id-1: #7cc787;
	--id-2: #7fb2e6;
	--id-3: #c79be0;
	--id-4: #e3b456;
	--id-5: #6cc9c9;
	--id-6: #e88bb4;
	--id-7: #b5c46e;
	color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
	margin: 0;
	background: var(--bg);
	color: var(--fg);
	font: 16px/1.4 system-ui, -apple-system, sans-serif;
	padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

/* scrolled to after decoding a recording, clear of the sticky header */
#log { scroll-margin-top: calc(64px + env(safe-area-inset-top)); }

header {
	position: sticky;
	top: 0;
	z-index: 1;
	display: flex;
	align-items: baseline;
	gap: 12px;
	padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
	background: var(--bg);
	border-bottom: 1px solid var(--line);
}

h1 { font-size: 18px; margin: 0; }
h2 { font-size: 16px; margin: 24px 0 8px; }
h2:first-child { margin-top: 8px; }

header #status {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	text-align: right;
	font-size: 14px;
}

main {
	max-width: 720px;
	margin: 0 auto;
	padding: 8px 16px 16px;
}

nav {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	background: var(--card);
	border-top: 1px solid var(--line);
	padding-bottom: env(safe-area-inset-bottom);
}

nav button {
	/* as wide as its label, the room left shared out evenly */
	flex: auto;
	height: 56px;
	border: 0;
	border-radius: 0;
	background: none;
	color: var(--dim);
	font: inherit;
	font-weight: 600;
	/* six tabs share a phone's width */
	font-size: min(15px, 3.9vw);
	padding: 0 2px;
	min-width: 0;
}

nav button[aria-selected="true"] { color: var(--accent); box-shadow: inset 0 3px var(--accent); }

button, select, input, .button {
	font: inherit;
	color: var(--fg);
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: 8px;
	padding: 8px 12px;
	min-height: 44px;
}

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.small { min-height: 32px; padding: 4px 8px; font-size: 14px; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
button:disabled { opacity: 0.5; }

.about img { display: block; width: 100%; max-width: 512px; height: auto; margin: 0 auto 8px; }
.about h3 { font-size: 14px; margin: 16px 0 4px; }
.about p { overflow-wrap: anywhere; }
.danger-zone { border: 1px solid var(--bad); border-radius: 10px; padding: 0 12px; }
.danger-zone input { flex: 1; min-width: 0; }

select { min-width: 0; flex: 1; }

/* the kind of post: one button group */
.segmented { display: flex; margin: 8px 0 12px; }
.segmented button { flex: 1; border-radius: 0; margin-left: -1px; }
.segmented button:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.segmented button:last-child { border-radius: 0 8px 8px 0; }
.segmented button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; color: var(--dim); font-size: 14px; }
.field[hidden] { display: none; }
.field input, .field textarea { color: var(--fg); font-size: 16px; }
.field.inline { flex: 1; min-width: 9em; margin: 0; }
textarea {
	font: inherit;
	color: var(--fg);
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: 8px;
	padding: 8px 12px;
	resize: vertical;
	min-height: 120px;
}
input:invalid { border-color: var(--bad); }

fieldset.choice { border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; padding: 8px 12px; }
fieldset.choice legend { color: var(--dim); font-size: 14px; padding: 0 4px; }
fieldset.choice label { display: flex; gap: 8px; align-items: baseline; padding: 6px 0; }
fieldset.choice input { min-height: 0; accent-color: var(--accent); }
fieldset.choice label:has(input:disabled) { color: var(--dim); }
fieldset.choice label.sub { padding-left: 24px; }
fieldset.choice label.sub[hidden] { display: none; }

/* the station's keys */
.key-card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0 0 8px; }
.key-card-head { display: flex; align-items: center; gap: 8px; }
.key-card-head strong { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.key-card .remove-confirm[hidden], .key-card .revoke-confirm[hidden] { display: none; }
#hex { font-family: ui-monospace, monospace; }
details#new-key { margin: 8px 0; }
details#new-key summary { cursor: pointer; color: var(--accent); min-height: 44px; display: flex; align-items: center; }

label.check { display: flex; gap: 8px; align-items: baseline; margin: 8px 0; min-height: 32px; overflow-wrap: anywhere; }
label.check[hidden] { display: none; }
label.check input { min-height: 0; accent-color: var(--accent); }

.post-actions { display: flex; justify-content: flex-end; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }

.file { display: inline-flex; align-items: center; cursor: pointer; }
.file input { display: none; }
.file[hidden] { display: none; }
label.file:not(.button) { color: var(--accent); text-decoration: underline; min-height: 44px; }

.meter { height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.meter div { height: 100%; width: 0; background: var(--ok); transition: width 0.1s; }
.meter div.hot { background: var(--bad); }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 4px 8px 4px 0; border-bottom: 1px solid var(--line); }
td input { width: 6em; min-height: 36px; padding: 4px 8px; }

.dim { color: var(--dim); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }

.entry {
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: 10px;
	padding: 10px 12px;
	margin: 0 0 8px;
	overflow-wrap: anywhere;
}

.entry.event { padding: 6px 12px; font-size: 14px; }

.entry-head { font-size: 14px; margin-bottom: 4px; }
.entry-head .time { color: var(--dim); }
.call { font-family: ui-monospace, monospace; font-weight: 600; }
.key, .hash { font-family: ui-monospace, monospace; font-size: 0.9em; color: var(--dim); }

.badge {
	float: right;
	font-size: 12px;
	padding: 1px 6px;
	border-radius: 6px;
	background: var(--chip);
	margin-left: 8px;
}

.box { border-left: 3px solid var(--line); padding-left: 10px; margin: 6px 0; }
.box-head { font-size: 14px; }

.post { margin: 6px 0; }
.post-head { font-size: 16px; }
.post .dim { font-size: 13px; }
.part { margin: 4px 0; white-space: pre-wrap; }
.dropped { opacity: 0.6; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.chip { font-size: 13px; padding: 2px 8px; border-radius: 10px; background: var(--chip); }

/* identicons, from the key: colour classes over the --id-* palette */
.identicon { background: var(--chip); border-radius: 6px; flex: none; vertical-align: middle; }
.id-0 { fill: var(--id-0); } .id-1 { fill: var(--id-1); } .id-2 { fill: var(--id-2); } .id-3 { fill: var(--id-3); }
.id-4 { fill: var(--id-4); } .id-5 { fill: var(--id-5); } .id-6 { fill: var(--id-6); } .id-7 { fill: var(--id-7); }
.face { display: inline-flex; flex: none; }
/* the whole avatar, fitted into its square, never cropped (SPEC.md, Avatar) */
.avatar { display: block; width: 32px; height: 32px; border-radius: 6px; object-fit: contain; }

.box-head.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.box-head.signer { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.who { flex: 1; min-width: 0; }
button.trust { flex: none; }
.chip.recipient { display: inline-flex; align-items: center; gap: 4px; }
.chip .identicon { border-radius: 3px; }
.chip.unverified { background: none; border: 1px dashed var(--line); color: var(--dim); }

.trust-dialog {
	max-width: min(420px, calc(100vw - 32px));
	background: var(--card);
	color: var(--fg);
	border: 1px solid var(--line);
	border-radius: 12px;
	padding: 16px;
}
.trust-dialog::backdrop { background: rgb(0 0 0 / 0.5); }
.trust-dialog h3 { margin: 0 0 12px; }
.trust-dialog p { overflow-wrap: anywhere; }
.level-row { align-items: flex-end; flex-wrap: nowrap; }
.level-row .field { flex: 1; min-width: 0; }
.level-row input[type=range] { accent-color: var(--accent); min-height: 32px; width: 100%; }
/* a fixed width, so the slider never moves as its value changes */
#output-level-value, #lead-value { flex: none; width: 4.5em; text-align: right; padding-bottom: 12px; font-variant-numeric: tabular-nums; }
.trust-dialog .row { justify-content: flex-end; }
.fingerprint { font-family: ui-monospace, monospace; font-size: 15px; letter-spacing: 0.02em; }
.fingerprint span { display: block; }

.picture { display: block; max-width: 100%; max-height: 320px; width: auto; height: auto; border-radius: 6px; }
.picture.opens, .opens .picture { cursor: zoom-in; }
/* a drawn picture on its own line, its Save under it */
.part > .animated { display: block; width: fit-content; margin-bottom: 4px; }
.part > img.picture { margin-bottom: 4px; }
.picture-dialog {
	max-width: calc(100vw - 16px);
	max-height: calc(100vh - 16px);
	background: var(--card);
	color: var(--fg);
	border: 1px solid var(--line);
	border-radius: 12px;
	padding: 8px;
}
.picture-dialog::backdrop { background: rgb(0 0 0 / 0.7); }
.picture-dialog .row { justify-content: space-between; align-items: center; margin: 0 0 8px; }
.picture-full { overflow: auto; max-width: calc(100vw - 34px); max-height: calc(100vh - 90px); }
.picture-natural { display: block; max-width: none; max-height: none; }
/* the avatar cropper: dragging moves the square, never the page */
.crop-area { position: relative; overflow: hidden; margin: 0 auto; touch-action: none; user-select: none; -webkit-user-select: none; cursor: move; }
.crop-area canvas { display: block; }
.crop-square { position: absolute; box-sizing: border-box; border: 2px solid var(--card); outline: 1px solid var(--fg); box-shadow: 0 0 0 100vmax rgb(0 0 0 / 0.5); }
.crop-square:focus-visible { border-color: var(--accent); }
/* corners to grab; the whole edge resizes too, the area takes the pointer */
.crop-handle { position: absolute; width: 14px; height: 14px; box-sizing: border-box; background: var(--card); border: 1px solid var(--fg); border-radius: 3px; pointer-events: none; }
/* inside the corners, so the picture's edge never cuts them off */
.crop-handle.nw { left: 0; top: 0; }
.crop-handle.ne { right: 0; top: 0; }
.crop-handle.sw { left: 0; bottom: 0; }
.crop-handle.se { right: 0; bottom: 0; }
.crop-hint { margin: 8px 0 0; }
.crop-dialog .field input[type=range] { accent-color: var(--accent); width: 100%; min-height: 32px; }
.crop-dialog .row { justify-content: flex-end; margin: 8px 0 0; }
.crop-info { min-height: 2.6em; margin: 4px 0 0; }
.animated { display: inline-block; max-width: 100%; -webkit-touch-callout: none; user-select: none; }

/* nothing moves where the system asks for less motion */
@media (prefers-reduced-motion: reduce) {
	* { transition: none !important; animation: none !important; }
}

a { color: var(--accent); }

/* inbox and boards */
.rows { display: flex; flex-direction: column; gap: 8px; }
.row-card {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	text-align: left;
	width: 100%;
	background: var(--card);
	color: var(--fg);
	border: 1px solid var(--line);
	border-radius: 10px;
	padding: 10px 12px;
	font: inherit;
	cursor: pointer;
	overflow-wrap: anywhere;
}
.row-card .dim, .row-card .ok, .row-card .warn { font-size: 14px; }
.row-text { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; flex: 1; }
.row-text .last { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); font-size: 14px; }
.faces { display: flex; flex-wrap: wrap; gap: 4px; }
#attachments { display: flex; flex-direction: column; gap: 8px; }
.attachment { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; }
.attachment .what { overflow-wrap: anywhere; }
#attach-info:empty { display: none; }
#outbox-groups { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
#outbox-groups .key-card { margin: 0; }
.outbox-post { display: flex; flex-direction: column; gap: 4px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; overflow-wrap: anywhere; }
.outbox-post .dim { font-size: 14px; }
.outbox-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
#drafts { display: flex; flex-direction: column; gap: 8px; }
.draft { display: flex; align-items: center; gap: 8px; }
.draft-line {
	display: flex;
	align-items: baseline;
	gap: 8px;
	flex: 1;
	min-width: 0;
	text-align: left;
	background: var(--card);
	color: var(--fg);
	border: 1px solid var(--line);
	border-radius: 10px;
	padding: 8px 12px;
	font: inherit;
	cursor: pointer;
	white-space: nowrap;
}
.draft-line > * { overflow: hidden; text-overflow: ellipsis; }
.draft-line strong { flex: 0 1 auto; max-width: 45%; }
.draft-line > span:not(.dim) { flex: 1 1 0; min-width: 0; }
.draft-line .dim { flex: 0 0 auto; margin-left: auto; font-size: 14px; }
#parked { margin-top: 24px; }
#parked-spots { display: flex; flex-direction: column; gap: 12px; }
#parked-spots .key-card { margin: 0; }
#parked-spots p.status:empty { display: none; }
#parked .parked-posts .outbox-post:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.thread-bar { margin: 4px 0 8px; }
.thread-subject { overflow-wrap: anywhere; }
.tree-node { margin: 0; }
.tree-node .tree-node { margin-left: 12px; padding-left: 8px; border-left: 2px solid var(--line); }
.tree-node.depth-4 .tree-node { margin-left: 0; padding-left: 0; border-left: none; }
.tree-post { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 8px 0; overflow-wrap: anywhere; }

/* kept revocations */
.relay-item { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; overflow-wrap: anywhere; }
.relay-item .identicon { flex: none; border-radius: 4px; }

/* an inbox conversation as a chat: own posts on the right */
.chat { display: flex; flex-direction: column; }
.chat-post { align-self: flex-start; max-width: 92%; min-width: 0; }
.chat-post.mine { align-self: flex-end; }
.chat-post.mine .tree-post { background: var(--chip); }

/* a post named by who wrote it and what it says (postRef in render.js),
   and the post it goes to when tapped */
button.replied {
	display: block;
	max-width: 100%;
	min-height: 0;
	padding: 0;
	border: none;
	background: none;
	color: var(--dim);
	font: inherit;
	font-size: 14px;
	text-align: left;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	cursor: pointer;
}
button.replied:hover { color: var(--fg); }
.post[data-post] { outline: none; border-radius: 6px; }
.post[data-post]:focus { outline: 2px solid var(--accent); outline-offset: 4px; }
#inbox-reply { border-top: 1px solid var(--line); margin-top: 12px; }
#inbox-reply-to { overflow-wrap: anywhere; }
#inbox-reply p:empty { display: none; }
