/* tinytyper · North-Sea paper, ink, and one brick-red accent */

:root {
	--paper: #f1f4f5;
	--panel: #fafcfc;
	--ink: #20262c;
	--slate: #8a97a0;
	--mist: #d7dee2;
	--brick: #a8402c;
	--brick-soft: #a8402c22;

	--cat-glow: none;

	--ui: "IBM Plex Sans", system-ui, sans-serif;
	--serif: "EB Garamond", Garamond, Georgia, serif;
	--mono: "APL385 Unicode", "IBM Plex Mono", ui-monospace, monospace;

	color-scheme: light;
}

/* Night watch: dusk over the Elbe rather than pitch black. */
:root[data-theme="dark"] {
	--paper: #14181c;
	--panel: #1b2127;
	--ink: #e3e8eb;
	--slate: #7e8b94;
	--mist: #333d45;
	--brick: #c8604a;
	--brick-soft: #c8604a2b;
	--cat-glow: drop-shadow(0 0 1.5px rgba(227, 232, 235, 0.6));
	color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
	:root[data-theme="auto"] {
		--paper: #14181c;
		--panel: #1b2127;
		--ink: #e3e8eb;
		--slate: #7e8b94;
		--mist: #333d45;
		--brick: #c8604a;
		--brick-soft: #c8604a2b;
		--cat-glow: drop-shadow(0 0 1.5px rgba(227, 232, 235, 0.6));
		color-scheme: dark;
	}
}

/* Janni stays a black cat in the dark; she just gets a faint halo. */
.cat, .logo-cat {
	filter: var(--cat-glow);
}

* {
	box-sizing: border-box;
}

html, body {
	margin: 0;
	background: var(--paper);
	color: var(--ink);
	font-family: var(--ui);
	font-size: 16px;
	line-height: 1.5;
}

main {
	max-width: 46rem;
	margin: 0 auto;
	padding: 0 1.25rem 3rem;
}

button {
	font: inherit;
	cursor: pointer;
}

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

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

/* Pinned to the viewport rather than sitting (absolutely) below the text
   panel, so focusing it — or the browser's own keep-the-focused-field-
   visible instinct while typing — never has anywhere to scroll to. The
   caret-follow in ./src/render.ts is the only thing that may move the
   page during practice. */
#key-input {
	position: fixed;
	top: 0;
	left: 0;
}

/* ---------- masthead ---------- */

.masthead {
	position: relative;
	text-align: center;
	padding: 2.5rem 1rem 1.5rem;
}

.settings-btn {
	position: absolute;
	top: 1rem;
	right: 1rem;
}

.logo-cat {
	width: 56px;
	height: 42px;
}

.wordmark {
	font-family: var(--serif);
	font-style: italic;
	font-weight: 500;
	font-size: 2.6rem;
	letter-spacing: 0.01em;
	margin: 0.25rem 0 0;
}

.tagline {
	color: var(--slate);
	margin: 0.35rem 0 0;
	font-size: 0.95rem;
}

/* ---------- setup ---------- */

.field {
	display: block;
	margin: 1.1rem 0;
}

.label {
	display: block;
	font-size: 0.8rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: lowercase;
	color: var(--slate);
	margin-bottom: 0.35rem;
}

#title-input, #text-input {
	width: 100%;
	border: 1px solid var(--mist);
	border-radius: 6px;
	background: var(--panel);
	color: var(--ink);
	padding: 0.6rem 0.75rem;
	font-family: var(--ui);
	font-size: 1rem;
}

#text-input {
	font-family: var(--mono);
	font-size: 0.95rem;
	resize: vertical;
	min-height: 10rem;
}

#title-input:focus, #text-input:focus {
	outline: none;
	border-color: var(--brick);
}

.setup-row {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	flex-wrap: wrap;
}

.samples {
	display: flex;
	gap: 0.5rem;
	flex-wrap: wrap;
	flex: 1;
}

.chip {
	border: 1px solid var(--mist);
	background: var(--panel);
	color: var(--ink);
	border-radius: 999px;
	padding: 0.3rem 0.85rem;
	font-size: 0.85rem;
}
.chip:hover {
	border-color: var(--brick);
	color: var(--brick);
}

.primary {
	border: none;
	background: var(--ink);
	color: var(--paper);
	border-radius: 6px;
	padding: 0.6rem 1.4rem;
	font-weight: 600;
}
.primary:hover {
	background: var(--brick);
}

/* epub import */

.epub-row {
	display: flex;
	align-items: center;
	gap: 1rem;
	flex-wrap: wrap;
	margin-top: 1.25rem;
	padding-top: 1.25rem;
	border-top: 1px solid var(--mist);
}

.file-btn {
	display: inline-block;
}
.file-btn:focus-within {
	outline: 2px solid var(--brick);
	outline-offset: 2px;
}

.check {
	display: flex;
	align-items: center;
	gap: 0.45rem;
	font-size: 0.85rem;
	color: var(--slate);
}
.check input {
	accent-color: var(--brick);
}

.import-error {
	color: var(--brick);
}

/* saved shelf */

.saved-row {
	display: flex;
	gap: 0.4rem;
	align-items: stretch;
	margin-bottom: 0.4rem;
}

.saved-open {
	flex: 1;
	display: flex;
	justify-content: space-between;
	gap: 1rem;
	border: 1px solid var(--mist);
	background: var(--panel);
	border-radius: 6px;
	padding: 0.55rem 0.85rem;
	text-align: left;
}
.saved-open:hover {
	border-color: var(--brick);
}
.saved-title {
	font-weight: 500;
}
.saved-meta {
	color: var(--slate);
	font-variant-numeric: tabular-nums;
}

.saved-delete {
	border: 1px solid var(--mist);
	background: var(--panel);
	color: var(--slate);
	border-radius: 6px;
	width: 2.4rem;
	font-size: 1.1rem;
}
.saved-delete:hover {
	color: var(--brick);
	border-color: var(--brick);
}

/* ---------- practice ---------- */

.toolbar {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	margin: 0.5rem 0 1rem;
	flex-wrap: wrap;
}

.doc-title {
	font-family: var(--serif);
	font-style: italic;
	font-size: 1.15rem;
}

.spacer {
	flex: 1;
}

.tool {
	border: 1px solid var(--mist);
	background: var(--panel);
	color: var(--ink);
	border-radius: 6px;
	padding: 0.3rem 0.7rem;
	font-size: 0.85rem;
}
.tool:hover {
	border-color: var(--brick);
	color: var(--brick);
}

.text-panel {
	--type-size: 22px;
	background: var(--panel);
	border: 1px solid var(--mist);
	border-radius: 8px;
	padding: 1.75rem 2rem;
	font-family: var(--serif);
	font-size: var(--type-size);
	line-height: 1.75;
	min-height: 12rem;
	overflow-wrap: anywhere;
	white-space: pre-wrap;
	cursor: text;
}

.text-panel.mono {
	font-family: var(--mono);
	line-height: 1.9;
}

.text-panel.unfocused {
	opacity: 0.55;
}
.text-panel.unfocused::after {
	content: "click to type";
	display: block;
	margin-top: 1rem;
	font-family: var(--ui);
	font-size: 0.8rem;
	color: var(--slate);
}

.g {
	white-space: pre-wrap;
}
.g.pending {
	color: var(--slate);
}
.g.correct {
	color: var(--ink);
}
.g.wrong {
	color: var(--brick);
	background: var(--brick-soft);
	text-decoration: underline;
	text-decoration-color: var(--brick);
	text-underline-offset: 0.2em;
	border-radius: 2px;
}

.g.nl {
	color: var(--mist);
	font-size: 0.7em;
	vertical-align: 0.15em;
}
.g.nl.correct {
	color: var(--slate);
}
.g.nl.wrong {
	color: var(--brick);
}

.g.caret {
	box-shadow: inset 2px 0 0 var(--brick);
	animation: caret-pulse 1.1s steps(2, jump-none) infinite;
}

@keyframes caret-pulse {
	50% {
		box-shadow: inset 2px 0 0 transparent;
	}
}

/* progress + cat */

.progress {
	position: relative;
	margin: 2.2rem 0 0.5rem;
	padding-top: 20px; /* headroom for the cat */
}

.bar {
	height: 6px;
	border-radius: 3px;
	background: var(--mist);
	overflow: hidden;
}

.bar-fill {
	height: 100%;
	width: 0%;
	background: var(--brick);
	border-radius: 3px;
	transition: width 200ms ease-out;
}

.cat {
	position: absolute;
	bottom: 4px;
	left: 0%;
	width: 34px;
	height: 26px;
	transform: translateX(-50%);
	transition: left 200ms ease-out;
}

.cat.oops {
	animation: stumble 450ms ease-out;
}

@keyframes stumble {
	0% {
		transform: translateX(-50%) rotate(0deg);
	}
	30% {
		transform: translateX(-50%) rotate(-24deg) translateY(-5px);
	}
	60% {
		transform: translateX(-50%) rotate(12deg);
	}
	100% {
		transform: translateX(-50%) rotate(0deg);
	}
}

/* hud */

.hud {
	display: flex;
	gap: 2.2rem;
	margin: 0.75rem 0 0;
	padding: 0;
}

.hud div {
	display: flex;
	flex-direction: column;
}

.hud dt {
	font-size: 0.72rem;
	letter-spacing: 0.08em;
	text-transform: lowercase;
	color: var(--slate);
}

.hud dd {
	margin: 0;
	font-size: 1.25rem;
	font-weight: 500;
	font-variant-numeric: tabular-nums;
}

/* ---------- done ---------- */

.done-heading {
	font-family: var(--serif);
	font-style: italic;
	font-weight: 500;
	font-size: 1.8rem;
	text-align: center;
	margin: 2.5rem 0 1.5rem;
}

.done-stats {
	display: grid;
	grid-template-columns: max-content max-content;
	gap: 0.4rem 2rem;
	justify-content: center;
	margin: 0 0 2rem;
}

.done-stats dt {
	color: var(--slate);
}
.done-stats dd {
	margin: 0;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	text-align: right;
}

.done-actions {
	display: flex;
	gap: 0.75rem;
	justify-content: center;
}

/* ---------- colophon ---------- */

.colophon {
	text-align: center;
	color: var(--slate);
	font-size: 0.8rem;
	padding: 1rem 0 2rem;
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
	.cat, .bar-fill {
		transition: none;
	}
	.cat.oops {
		animation: none;
	}
	.g.caret {
		animation: none;
	}
}

/* ---------- small screens ---------- */

/* the tabbed shelf */

.shelf {
	margin-top: 2.25rem;
}

.tabs {
	display: flex;
	gap: 0.25rem;
	border-bottom: 1px solid var(--mist);
}

/* Tabs sit *on* the rule rather than above it, so the selected one reads
   as continuous with the panel beneath. */
.tab {
	border: 1px solid transparent;
	border-bottom: none;
	background: none;
	color: var(--slate);
	border-radius: 6px 6px 0 0;
	padding: 0.45rem 0.9rem;
	margin-bottom: -1px;
	font-size: 0.85rem;
	font-weight: 600;
	letter-spacing: 0.02em;
}
.tab:hover {
	color: var(--brick);
}
.tab.on {
	border-color: var(--mist);
	background: var(--panel);
	color: var(--ink);
}

.shelf-body {
	padding-top: 0.75rem;
}

/* A table of contents can run to hundreds of rows; a flat shelf cannot,
   so only the drilled-in views get a ceiling and a scrollbar. */
.shelf-body.scrolling {
	max-height: 22rem;
	overflow-y: auto;
	padding-right: 0.25rem;
}

.shelf-empty {
	margin: 1.25rem 0;
	font-size: 0.9rem;
	color: var(--slate);
}

.shelf-head {
	display: flex;
	align-items: baseline;
	gap: 0.8rem;
	margin: 0.5rem 0 1rem;
}
.shelf-head h2 {
	margin: 0;
	font-family: var(--serif);
	font-style: italic;
	font-weight: 500;
	font-size: 1.3rem;
}

/* account: the masthead button and its dialog */

.account-btn {
	position: absolute;
	top: 1rem;
	left: 1rem;
}

.account-dialog {
	width: min(26rem, calc(100vw - 2rem));
	border: 1px solid var(--mist);
	border-radius: 10px;
	background: var(--panel);
	color: var(--ink);
	padding: 1.75rem;
	font-family: var(--ui);
}

.account-dialog::backdrop {
	background: rgb(0 0 0 / 45%);
	backdrop-filter: blur(2px);
}

.dialog-close {
	position: absolute;
	top: 0.5rem;
	right: 0.7rem;
	border: none;
	background: none;
	color: var(--slate);
	font-size: 1.4rem;
	line-height: 1;
	padding: 0.2rem 0.4rem;
}
.dialog-close:hover {
	color: var(--brick);
}

.dialog-heading {
	margin: 0 0 0.5rem;
	font-size: 1.05rem;
	font-weight: 600;
}

/* The sign-in / create-account switch. Two buttons behaving as one
   control, so the border belongs to the pair rather than to either. */
.segmented {
	display: flex;
	border: 1px solid var(--mist);
	border-radius: 6px;
	overflow: hidden;
	margin-bottom: 0.5rem;
}

.seg {
	flex: 1;
	border: none;
	background: var(--panel);
	color: var(--slate);
	padding: 0.5rem 0.6rem;
	font-size: 0.85rem;
	font-weight: 600;
}
.seg:hover {
	color: var(--brick);
}
.seg.on {
	background: var(--ink);
	color: var(--paper);
}

.account-dialog input[type="email"],
.account-dialog input[type="password"],
.account-dialog input[type="text"],
.danger-zone input[type="password"] {
	width: 100%;
	border: 1px solid var(--mist);
	border-radius: 6px;
	background: var(--paper);
	color: var(--ink);
	font: inherit;
	padding: 0.5rem 0.6rem;
}
.account-dialog input:focus-visible {
	outline: 2px solid var(--brick);
	outline-offset: 1px;
}

.dialog-actions {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 0.6rem;
	margin-top: 1.25rem;
}

/* Empty until something is said, and never laying out an empty line —
   ‘:empty’ keeps the gap from appearing before the first message. */
.dialog-note {
	margin: 0.9rem 0 0;
	font-size: 0.85rem;
	line-height: 1.45;
	color: var(--slate);
}
.dialog-note:empty {
	display: none;
}
.dialog-note.bad {
	color: var(--brick);
}

.dialog-rule {
	border: none;
	border-top: 1px solid var(--mist);
	margin: 1.5rem 0 0;
}

.account-line {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	margin: 0.75rem 0 0;
}

.account-email {
	font-weight: 600;
	overflow-wrap: anywhere;
}

.badge {
	flex: none;
	border-radius: 999px;
	padding: 0.15rem 0.55rem;
	font-size: 0.7rem;
	font-weight: 600;
	letter-spacing: 0.04em;
	background: var(--brick-soft);
	color: var(--brick);
}

.danger:hover {
	border-color: var(--brick);
	background: var(--brick);
	color: var(--paper);
}

/* ---------- settings & account pages ---------- */

.page-head {
	display: flex;
	align-items: baseline;
	gap: 0.8rem;
	margin: 0.5rem 0 1.5rem;
}
.page-head h2 {
	margin: 0;
	font-family: var(--serif);
	font-style: italic;
	font-weight: 500;
	font-size: 1.3rem;
}

/* One row per preference: name on the left, control on the right,
   wrapping under itself when a phone runs out of width. */
.setting {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.8rem 1.5rem;
	flex-wrap: wrap;
	margin: 0 0 1.1rem;
}
.setting-seg {
	flex: 0 1 17rem;
	margin-bottom: 0;
}

.size-row {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}
.size-out {
	min-width: 3.4rem;
	text-align: center;
	font-variant-numeric: tabular-nums;
	font-size: 0.9rem;
	color: var(--slate);
}

/* The preview borrows .text-panel wholesale — same variable, same mono
   class — and only shrinks it to a swatch rather than a page. Whitespace
   goes back to normal because the markup indents the sample text, and
   pre-wrap would faithfully render the formatter's tabs. */
.settings-preview {
	min-height: 0;
	padding: 1rem 1.25rem;
	margin-top: 0.4rem;
	cursor: default;
	white-space: normal;
}

.danger-zone {
	border: 1px solid var(--brick);
	border-radius: 8px;
	padding: 1rem 1.25rem 1.25rem;
	margin-top: 2.5rem;
}
.danger-zone h3 {
	margin: 0 0 0.5rem;
	font-size: 0.8rem;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--brick);
}
.danger-zone p {
	margin: 0 0 1rem;
	font-size: 0.9rem;
	line-height: 1.5;
	color: var(--slate);
}

@media (max-width: 540px) {
	.text-panel {
		padding: 1.1rem 1rem;
	}
	.hud {
		gap: 1.3rem;
	}
	.wordmark {
		font-size: 2rem;
	}
	/* Two absolutely-positioned buttons plus a wordmark is one thing too
	   many on a phone; the account button rejoins the flow underneath. */
	.account-btn {
		position: static;
		display: block;
		margin: 0 auto 1rem;
	}
}
