/* Base styles on top of tokens.css. No components here. */

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

html {
	font-size: 100%;
	/* an app, not a page: no pinch or double-tap zoom (text size comes from Dynamic Type), no grey
	   flash on a tap, and the document itself never scrolls or bounces (kozo-native pins it; each
	   screen scrolls in its own container, with the system's momentum and edge bounce) */
	touch-action: pan-x pan-y;
	-webkit-tap-highlight-color: transparent;
	overscroll-behavior: none;
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
	font-synthesis: none; /* small caps (and faux bold/italic) are never synthesized */
}

/* iOS: Dynamic Type reaches the page only through this keyword. The touch-callout
   query is true on iOS/iPadOS WebKit only, so desktop Safari keeps 100%. */
@supports (font: -apple-system-body) and (-webkit-touch-callout: none) {
	html {
		font: -apple-system-body;
	}
}

body {
	margin: 0;
	min-height: 100dvh;
	background: var(--bg);
	color: var(--ink);
	font-family: var(--serif);
	font-size: 1rem;
	line-height: 1.45;
	font-optical-sizing: auto; /* Newsreader's opsz axis follows the size */
	font-variant-numeric: lining-nums;
	-webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
	font: inherit;
	color: inherit;
}

/* chrome is not text: a long press on a button, a link or a label doesn't select it or open the
   link menu; what the person wrote (notes, fields, documents) stays selectable */
button,
a,
label,
summary,
[role='button'],
.label {
	-webkit-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
}
input,
textarea,
[contenteditable] {
	-webkit-user-select: text;
	user-select: text;
}

/* The single centred column: at most 640px, 16px gutter (24px from 480px),
   kept clear of the notch in landscape. */
.col {
	max-width: var(--col);
	margin-inline: auto;
	padding-inline: max(var(--gutter), env(safe-area-inset-left))
		max(var(--gutter), env(safe-area-inset-right));
}

h1 {
	font-weight: 500;
	font-size: calc(2rem * var(--half));
	line-height: 1.15;
	margin: 0.15rem 0 0.35rem;
	overflow-wrap: anywhere;
	text-wrap: balance;
}

/* Dates, times, counts and numbers. */
.mono {
	font-family: var(--mono);
	font-size: 0.8125rem;
	line-height: 1.3;
	letter-spacing: 0.02em;
	font-variant-numeric: lining-nums tabular-nums;
}

/* Labels: real capitals, never synthesized small caps. */
.label {
	font-family: var(--serif);
	text-transform: uppercase;
	font-weight: 500;
	font-size: 0.75rem;
	letter-spacing: 0.08em;
	line-height: 1.25;
	color: var(--muted);
	margin: 0;
}

a {
	color: inherit;
	text-decoration: underline;
}

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

/* a ring follows the keyboard, never a tap: WebKit marks focus returned to an opener after a tap as
   focus-visible, so the last input kind (set on <html> by Home's layout) decides */
html[data-input='pointer'] :focus-visible,
html[data-input='pointer'] :focus-visible::after {
	outline: none !important;
}

@media (forced-colors: active) {
	:focus-visible {
		outline-color: CanvasText;
	}
}

/* ---- shared controls (the prototype's vocabulary: DESIGN-DNA §1 Look) ---- */

.sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}
[hidden] {
	display: none !important;
}
[tabindex='-1']:focus {
	outline: none;
}
.muted {
	color: var(--muted);
}
.label .sr {
	text-transform: none;
}

/* a label heading that ends in a printer's rule running to the right edge */
.sec {
	display: flex;
	align-items: center;
	gap: 10px;
}
.sec::after {
	content: '';
	flex: 1;
	border-top: var(--hair) solid var(--rule);
}

/* ---- controls: the one definition (app/src/lib/ui: Button, IconButton, Row, Toggle, SheetHead
   render these classes; markup that predates them uses the classes directly). One height, one
   glyph size, one hairline, one press: an iPhone dims what is pressed and keeps no hover. ---- */

/* icon button: a 44×44 hit, the glyph at --glyph in a 1.5px stroke, ink */
.ib {
	min-width: var(--tap);
	min-height: var(--tap);
	border: 0;
	background: transparent;
	border-radius: var(--r-control);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0 10px;
	cursor: pointer;
	color: var(--ink);
	flex: none;
}
.ib svg {
	width: var(--glyph);
	height: var(--glyph);
}

/* text button: italic accent (DESIGN-DNA: text buttons are italic accent) */
.tb {
	white-space: nowrap;
	min-height: var(--tap);
	min-width: var(--tap);
	border: 0;
	background: transparent;
	padding: 0 6px;
	cursor: pointer;
	color: var(--accent);
	font-family: var(--serif);
	font-style: italic;
	font-weight: 500;
	font-size: var(--t-body);
	border-radius: var(--r-control);
	overflow-wrap: normal;
	text-align: start;
}

/* buttons: one height, one radius. Filled is ink on paper (the one primary); "ghost" (outlined in
   the component) is a quiet sunk fill with no drawn border, as the system's grey buttons are; the
   transparent hairline is its edge in forced colours */
.btn {
	min-height: var(--btn-h);
	border-radius: var(--r-control);
	border: var(--hair) solid var(--btn);
	background: var(--btn);
	color: var(--btn-ink);
	padding: var(--sp-2) var(--sp-5);
	cursor: pointer;
	font-size: var(--t-body);
	font-weight: 500;
	line-height: 1.25;
	overflow-wrap: anywhere;
	text-align: center;
}
.btn.ghost {
	background: var(--sunk);
	color: var(--ink);
	border-color: transparent;
}
.btn:disabled {
	background: transparent;
	color: var(--muted);
	border-color: var(--rule);
	cursor: default;
}

/* pressed: dims at once, comes back over a moment (the system's feel); no hover on a phone */
.ib,
.tb,
.btn {
	transition: opacity var(--dur-fast) var(--ease-out);
	-webkit-user-select: none;
	user-select: none;
}
.ib:active:not(:disabled),
.tb:active:not(:disabled) {
	opacity: 0.4;
	transition: none;
}
.btn:active:not(:disabled) {
	opacity: 0.7;
	transition: none;
}
@media (hover: hover) {
	.ib:hover:not(:disabled) {
		background: var(--sunk);
	}
	.tb:hover:not(:disabled) {
		text-decoration: underline;
		text-underline-offset: 3px;
	}
}

/* a row that opens something: pressed, one sunk tint fills the row's own box without moving (no
   spread shadow: a 100vmax one repaints the screen on every touch-down and stalled scrolling); its
   own separator gives way to the tint. One selector strong enough that no row's
   `background: none` (library.css, a sheet's scoped styles) leaves its middle untinted (owner
   screenshot: a page-coloured band between two dark strips). A grouped row tints inside its card. */
:is(.press, .mrow, .morerow, .shrow, :is(button, a).row):active:not(:disabled) {
	border-bottom-color: transparent;
	background: var(--sunk);
}
.press,
.mrow,
.morerow,
.shrow,
.row {
	-webkit-user-select: none;
	user-select: none;
}

/* drawn checkbox (20px, half-rate scaling) */
.box {
	--box: calc(20px * (1 + (var(--ts) - 1) * 0.5));
	appearance: none;
	-webkit-appearance: none;
	margin: 0;
	padding: 0;
	color: inherit;
	font: inherit;
	flex: none;
	width: var(--box);
	height: var(--box);
	border: 1.5px solid var(--field);
	border-radius: 4px;
	background: var(--surface);
	display: inline-grid;
	place-content: center;
	cursor: pointer;
}
.box[data-state='checked'] {
	background: var(--accent);
	border-color: var(--accent);
}
.box[data-state='checked']::before {
	content: '';
	width: calc(var(--box) * 0.6);
	height: calc(var(--box) * 0.6);
	background: var(--bg);
	clip-path: polygon(14% 52%, 0 66%, 38% 100%, 100% 22%, 86% 8%, 38% 72%);
}
.box[role='radio'] {
	border-radius: 50%;
}
.box[role='radio'][data-state='checked'] {
	background: var(--surface);
}
.box[role='radio'][data-state='checked']::before {
	width: calc(var(--box) * 0.5);
	height: calc(var(--box) * 0.5);
	border-radius: 50%;
	background: var(--accent);
	clip-path: none;
}
.box:focus-visible {
	outline-offset: 3px;
}

@media (forced-colors: active) {
	.box[data-state='checked']::before {
		forced-color-adjust: none;
		background: CanvasText;
	}
	.box[data-state='checked'] {
		border-color: CanvasText;
	}
	.tb {
		text-decoration: underline;
	}
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		transition: none !important;
		animation: none !important;
		scroll-behavior: auto !important;
	}
}

/* hanging punctuation on prose, where the engine supports it (WebKit): quotes and stops sit outside
   the measure (DESIGN-DNA luxury list 16) */
.tx,
.full,
.booklet,
.rt,
.pv {
	hanging-punctuation: first allow-end;
}

/* ---- the primitives' parts (app/src/lib/ui) ---- */

/* the text button, upright: a bar's or heading's plain action */
.tb.up {
	font-style: normal;
}

/* a sheet's heading row (SheetHead.svelte): the × centres on the heading's first line */
.shead {
	/* it stays at the top of a long sheet: its × in reach however far the sheet has scrolled (device QA:
	   a Move sheet scrolled to its shelf left Close above the screen) */
	position: sticky;
	top: calc(-1 * var(--sp-2));
	z-index: 2;
	background: var(--surface);
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: var(--sp-2);
	color: var(--ink);
	font-style: normal;
}
.shead h2 {
	flex: 1 1 auto;
	min-width: 0;
	font-weight: 500;
	font-size: var(--t-head);
	line-height: 1.25;
	margin: var(--sp-3) 0 var(--sp-1);
	overflow-wrap: break-word;
	text-wrap: balance;
}
.shead > .ib {
	margin-top: calc(var(--sp-3) + (var(--t-head) * 1.25 - var(--tap)) / 2);
	flex: none;
}
.shead > .ib:last-child {
	margin-inline-end: -10px;
}
/* the room under a sheet's last line: the home indicator's inset and one step of air */
.pad {
	height: calc(var(--sp-4) + env(safe-area-inset-bottom, 0px));
}

/* a row (Row.svelte, SwitchRow.svelte): name over a one-line hint, a value and a chevron at the right */
.urow {
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	width: 100%;
	min-height: max(52px, 3.25rem);
	padding: var(--sp-2) 0;
	border: 0;
	border-bottom: var(--hair) solid var(--rule);
	background: none;
	color: var(--ink);
	text-align: start;
	text-decoration: none;
	cursor: pointer;
	font-size: var(--t-row);
	line-height: 1.3;
}
.urow:focus-visible {
	outline-offset: -2px;
}
.urow .rt {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 2px;
}
.urow .rh {
	color: var(--muted);
	font-size: var(--t-sub);
	font-style: italic;
}
.urow .rv {
	flex: none;
	color: var(--muted);
}
/* name and value: one line while they fit, else the value wraps under the name, as iOS does at large text */
.urow .rmain {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	column-gap: var(--sp-3);
	row-gap: 2px;
}
.urow .rmain > .rt {
	flex: 1 1 auto;
	min-width: min-content;
}
.urow .ri,
.urow .rc {
	flex: none;
	display: inline-flex;
	color: var(--muted);
}
.urow .ri svg {
	width: var(--glyph);
	height: var(--glyph);
}
.urow .rc svg {
	width: max(16px, 1rem);
	height: max(16px, 1rem);
}

/* a grouped list (Settings): rows on a surface card, hairlines inset to the text, as the system's
   grouped tables are; pressed, a row tints to the card's rounded edge */
.grp {
	list-style: none;
	margin: 0;
	padding: 0;
	background: var(--surface);
	border-radius: var(--r-group);
	overflow: hidden;
}
.grp .urow {
	position: relative;
	padding-inline: var(--sp-4);
	border-bottom: 0;
}
.grp > li + li > .urow::before,
.grp > li + li.urow::before {
	content: '';
	position: absolute;
	top: 0;
	inset-inline: var(--sp-4) 0;
	border-top: var(--hair) solid var(--rule);
}
.grp .urow.press:active {
	box-shadow: none;
	clip-path: none;
}
@media (forced-colors: active) {
	.grp {
		border: 1px solid CanvasText;
	}
}
/* a group's one-line footnote */
.grpnote {
	margin: var(--sp-2) var(--sp-4) 0;
	color: var(--muted);
	font-size: var(--t-sub);
	font-style: italic;
	text-wrap: pretty;
}

/* a field (Field.svelte): surface, a hairline in the field colour, the accent edge when focused */
.inp {
	width: 100%;
	min-height: var(--tap);
	padding: 10px var(--sp-3);
	border: var(--hair) solid var(--field);
	border-radius: var(--r-control);
	background: var(--surface);
	color: var(--ink);
	font-size: var(--t-row);
	line-height: 1.4;
	resize: none;
}
.inp:focus-visible,
.inp:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 var(--hair) var(--accent);
}
.inp[aria-invalid='true'] {
	border-color: var(--error);
}
@media (forced-colors: active) {
	.inp:focus {
		outline: 2px solid CanvasText;
	}
}

/* a closing sheet's still copy, sinking over its fading scrim (motion.ts sink) */
.sheet-ghost {
	position: fixed;
	inset: 0;
	z-index: 2147483000;
	pointer-events: none;
	overflow: hidden;
}
.sheet-ghost-scrim {
	position: absolute;
	inset: 0;
	background: var(--scrim);
}

/* the old page's still copy during a push or pop (lib/ui/push.ts) */
.page-ghost {
	position: fixed;
	inset: 0;
	background: var(--bg);
	pointer-events: none;
	overflow: hidden;
}
/* as the system does, a page takes no taps while it is pushed or popped: quick taps can't land on
   whatever is arriving under the finger (device QA: five taps on Library opened a note) */
:root[data-nav] .lib,
:root[data-nav] .home {
	pointer-events: none;
}
/* but Back always works, mid-push too: it cancels the push and goes back (device QA, shelf then Back) */
:root[data-nav] .lib .back {
	pointer-events: auto;
}
/* a modal's scrim fades in (a CSS animation: WebKit can't animate ::backdrop from script, and a
   scrim drawn at once flashed the screen dark for a frame, device QA) */
dialog[open]::backdrop {
	animation: kz-scrim-in 160ms ease-out backwards; /* nothing held once it has played */
}
@keyframes kz-scrim-in {
	from {
		opacity: 0;
	}
}
@media (prefers-reduced-motion: reduce) {
	dialog[open]::backdrop {
		animation: none;
	}
}

/* the moving sheet (rising, or the sinking copy) is its own compositor layer for the length of the
   motion, so its shadow is rasterised once and only the transform animates; a layer kept only while
   it moves (data-arriving is removed when the rise ends) */
dialog[data-arriving] .sheet,
.sheet-ghost > :not(.sheet-ghost-scrim) {
	will-change: transform;
}
.sheet-ghost > :not(.sheet-ghost-scrim) {
	contain: paint;
}
