:root {
	--font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	--bg: #fbfbfa;
	--fg: #1a1a1a;
	--muted: #6b6b6b;
	--accent: #c2410c;
	--card: #ffffff;
	--border: #e7e5e0;
	--danger: #b91c1c;
	/* word marking: unknown = quiet dotted underline; learning = one amber hue
	   fading as familiarity grows; known = plain text */
	--mark-unknown: color-mix(in srgb, var(--accent) 42%, transparent);
	--mark-l1: rgba(245, 158, 11, 0.32);
	--mark-l2: rgba(245, 158, 11, 0.19);
	--mark-l3: rgba(245, 158, 11, 0.10);
	/* met/seen: tapped at least once — wash replaces the underline */
	--mark-met: color-mix(in srgb, var(--accent) 20%, transparent);
	--ok: #16a34a;
	--shadow-1: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
	--shadow-2: 0 12px 32px rgba(0, 0, 0, 0.16);
	--gap: 1rem;
	--pad: 1.5rem;
	--tabbar-h: 0px;
}

html.dark {
	--bg: #16161a;
	--fg: #eaeaea;
	--muted: #9a9a9a;
	--accent: #fb923c;
	--card: #1f1f25;
	--border: #2c2c33;
	--danger: #f87171;
	--mark-unknown: color-mix(in srgb, var(--accent) 52%, transparent);
	--mark-l1: rgba(251, 191, 36, 0.30);
	--mark-l2: rgba(251, 191, 36, 0.18);
	--mark-l3: rgba(251, 191, 36, 0.10);
	--mark-met: color-mix(in srgb, var(--accent) 26%, transparent);
	--ok: #4ade80;
	--shadow-1: none;
	--shadow-2: 0 12px 32px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

body {
	margin: 0;
	font-family: var(--font-sans);
	background: var(--bg);
	color: var(--fg);
	line-height: 1.6;
	transition: background 0.15s ease, color 0.15s ease;
}

.topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 1rem 1.5rem;
	border-bottom: 1px solid var(--border);
	gap: 1rem;
}

.brand {
	font-weight: 700;
	letter-spacing: 0;
	color: var(--fg);
	text-decoration: none;
}

.topnav {
	display: flex;
	align-items: center;
	gap: 0.85rem;
	flex-wrap: wrap;
	justify-content: flex-end;
}

.topnav a {
	color: var(--muted);
	text-decoration: none;
	font-size: 0.95rem;
}

.topnav a.active {
	color: var(--fg);
	font-weight: 650;
}

.tabbar {
	display: none;
}

.tabbar a {
	color: var(--muted);
	text-decoration: none;
}

.tabbar a.active {
	color: var(--accent);
	font-weight: 650;
}

.container {
	max-width: 1180px;
	margin: 0 auto;
	padding: 2.5rem var(--pad) calc(2.5rem + var(--tabbar-h) + env(safe-area-inset-bottom));
}

.hero h1 {
	font-size: 2.25rem;
	line-height: 1.15;
	letter-spacing: -0.03em;
	margin: 0 0 0.5rem;
}

.sub { color: var(--muted); font-size: 1.1rem; }

.cta { display: flex; gap: 0.75rem; margin-top: 1.5rem; }

.btn {
	display: inline-block;
	padding: 0.5rem 1rem;
	border-radius: 8px;
	background: var(--accent);
	color: #fff;
	text-decoration: none;
	border: none;
	font: inherit;
	cursor: pointer;
}

.btn.ghost {
	background: transparent;
	color: var(--fg);
	border: 1px solid var(--border);
}

.btn.small {
	padding: 0.3rem 0.55rem;
	font-size: 0.85rem;
}

.toggle {
	background: transparent;
	border: 1px solid var(--border);
	color: var(--fg);
	border-radius: 8px;
	padding: 0.35rem 0.7rem;
	cursor: pointer;
	font: inherit;
}

.demo {
	margin-top: 3rem;
	padding: 1.5rem;
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 8px;
}

.demo h2 { margin-top: 0; }

.counter {
	display: flex;
	align-items: center;
	gap: 1rem;
	font-size: 1.5rem;
	margin-top: 1rem;
}

.counter output {
	min-width: 2ch;
	text-align: center;
	font-variant-numeric: tabular-nums;
}

.form { max-width: 360px; }
.form label { display: block; font-size: 0.9rem; color: var(--muted); margin: 1rem 0 0.25rem; }
.form input,
.form select,
.form textarea,
.inline-form input {
	width: 100%;
	padding: 0.55rem 0.7rem;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--card);
	color: var(--fg);
	font: inherit;
}
.form textarea { resize: vertical; min-height: 12rem; }
.form .btn { margin-top: 1.5rem; }
.error { color: #dc2626; margin-top: 1rem; }

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

.page-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 1.5rem;
}

.page-head h1,
.reader-head h1 {
	margin: 0;
	line-height: 1.2;
}

.panel,
.empty,
.doc-row,
.word-panel {
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 8px;
}

.panel,
.empty {
	padding: 1.25rem;
}

.import-form {
	max-width: 680px;
}

.doc-list {
	display: grid;
	gap: 0.75rem;
}

.doc-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 1rem;
}

.doc-row h2 {
	margin: 0 0 0.25rem;
	font-size: 1.05rem;
}

.meta,
.breadcrumb,
.eyebrow {
	color: var(--muted);
	font-size: 0.9rem;
	margin: 0;
}

.row-actions,
.pager,
.page-actions,
.inline-form,
.chip-row {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	flex-wrap: wrap;
}

.row-actions form {
	margin: 0;
}

.btn.danger {
	background: transparent;
	color: var(--danger);
	border: 1px solid var(--border);
}

.reader-shell {
	max-width: 1120px;
	margin: 0 auto;
}

/* compact reader bar: back · title+meta · pager — the text should start fast */
.reader-bar {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	margin-bottom: 0.75rem;
	min-width: 0;
}

.reader-back {
	flex: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.2rem;
	height: 2.2rem;
	border: 1px solid var(--border);
	border-radius: 999px;
	color: var(--muted);
	background: var(--card);
	text-decoration: none;
	font-size: 1.3rem;
	line-height: 1;
}

.reader-title {
	min-width: 0;
	flex: 1;
}

.reader-title h1 {
	margin: 0;
	font-size: 1.05rem;
	font-weight: 650;
	line-height: 1.3;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.reader-meta {
	margin: 0;
	color: var(--muted);
	font-size: 0.8rem;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.reader-meta span + span::before {
	content: " · ";
}

.reader-pager {
	flex: none;
	gap: 0.35rem;
}

.pager-label {
	color: var(--muted);
	font-size: 0.85rem;
	font-variant-numeric: tabular-nums;
}

.pager-step {
	padding: 0.25rem 0.6rem;
	font-size: 1.05rem;
	line-height: 1;
}

.reader-controls {
	display: flex;
	justify-content: space-between;
	gap: 0.75rem;
	flex-wrap: wrap;
	margin: -0.35rem 0 1rem;
}

/* viewport-fitted reading: side page-turn buttons, column-sliced pages */
.reader-stage-wrap {
	min-width: 0;
}

.reader-stage {
	display: flex;
	justify-content: center;
	min-width: 0;
}

.reader-viewport {
	flex: 1;
	min-width: 0;
	overflow: hidden;
}

.reader-viewport .reader-text {
	column-fill: auto;
	transition: transform 0.18s ease;
}

/* a sentence and its translation page-turn together (sentence mode) */
.interlinear-unit {
	break-inside: avoid;
	-webkit-column-break-inside: avoid;
	page-break-inside: avoid;
}

/* true interlinear: word/gloss column pairs that wrap as units, so German
   and English lines alternate naturally and nothing splits across pages */
.reader-text.interlinear .reader-paragraph {
	margin-bottom: 1.6rem;
}

.il-word {
	display: inline-block;
	vertical-align: top;
	margin: 0 0.55em 0.7em 0;
	text-align: left;
}

.il-word .gloss {
	display: block;
	margin-top: 0.06em;
	font-family: var(--font-sans);
	font-size: 0.6em;
	line-height: 1.3;
	color: var(--muted);
	max-width: 18ch;
}

.il-sep {
	margin-right: 0.55em;
	margin-left: -0.4em;
}

.il-sep .il-text {
	display: block;
}

.sentence.il {
	margin-right: 0.2em;
}

.reader-viewport .reader-paragraph:first-child {
	margin-top: 0;
}

.fitted-nav {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 1rem;
	margin-top: 0.8rem;
	font-family: var(--font-sans);
}

.fitted-nav .sentence-step:disabled {
	opacity: 0.35;
	cursor: default;
}

.page-indicator {
	color: var(--muted);
	font-size: 0.9rem;
	font-variant-numeric: tabular-nums;
}

.reader-chapter {
	color: var(--accent);
	font-weight: 600;
}

.reader-toc {
	position: relative;
}

.reader-toc summary {
	list-style: none;
}

.reader-toc summary::-webkit-details-marker {
	display: none;
}

.toc-popover {
	position: absolute;
	left: 0;
	top: calc(100% + 0.45rem);
	z-index: 40;
	width: min(420px, calc(100vw - 2 * var(--pad)));
	max-height: min(62vh, 480px);
	overflow-y: auto;
	padding: 0.4rem;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--card);
	box-shadow: var(--shadow-2, 0 12px 32px rgba(0, 0, 0, 0.16));
}

.toc-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.toc-item {
	display: flex;
	align-items: baseline;
	gap: 0.6rem;
	padding: 0.5rem 0.65rem;
	border-radius: 6px;
	color: var(--fg);
	text-decoration: none;
}

.toc-item:hover {
	background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.toc-item.active {
	background: color-mix(in srgb, var(--accent) 12%, transparent);
	box-shadow: inset 3px 0 0 var(--accent);
}

.toc-no {
	min-width: 2.2ch;
	text-align: right;
	color: var(--muted);
	font-variant-numeric: tabular-nums;
	font-size: 0.85rem;
}

.toc-title {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.toc-item small {
	color: var(--muted);
	white-space: nowrap;
}

.toc-item.extra .toc-title {
	color: var(--muted);
	font-style: italic;
}

.chapter-continue {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	margin-top: 2.25rem;
	padding-top: 1.25rem;
	border-top: 1px solid var(--border);
}

.chapter-continue .btn {
	max-width: 48%;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.chapter-end {
	color: var(--muted);
	font-style: italic;
}

.check-row {
	display: flex;
	align-items: flex-start;
	gap: 0.5rem;
	margin: -0.35rem 0 0.9rem;
	color: var(--muted);
	font-size: 0.88rem;
}

.check-row input {
	width: auto;
	margin-top: 0.2rem;
	accent-color: var(--accent);
}

.reader-coverage,
.doc-progress {
	color: var(--muted);
	font-size: 0.9rem;
}

.reader-coverage {
	margin: -0.35rem 0 1rem;
}

.reader-grid {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 320px;
	gap: var(--gap);
	align-items: start;
}

.reader-text {
	max-width: var(--reader-measure, 760px);
	font-family: var(--reader-fam, ui-serif, Georgia, serif);
	font-size: calc(1.25rem * var(--reader-scale, 1));
	line-height: var(--reader-line, 1.85);
}

.reader-paragraph {
	margin: 0 0 1.35rem;
}

/* sentence mode is a focus mode: large, centered, with big nav targets */
.sentence-mode {
	font-size: calc(1.8rem * var(--reader-scale, 1));
	line-height: 1.75;
	max-width: 640px;
	margin: 0 auto;
	display: flex;
	flex-direction: column;
	justify-content: center;
	min-height: 52vh;
	text-align: left;
}

.sentence-mode .reader-paragraph {
	margin: 0;
}

.sentence-mode .translation-slot {
	margin-top: 1rem;
	font-size: 1.05rem;
}

.sentence-nav {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 1rem;
	margin-top: 2rem;
	font-family: var(--font-sans);
}

.sentence-step {
	min-height: 44px;
	display: inline-flex;
	align-items: center;
	padding: 0.5rem 1.1rem;
	font-size: 1rem;
}

.sentence {
	overflow-wrap: anywhere;
}

.translation-slot {
	margin: 0.35rem 0 0.85rem;
	padding-left: 0.75rem;
	border-left: 2px solid var(--border);
	font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif);
	font-size: 0.98rem;
	line-height: 1.55;
	color: var(--muted);
}

.translation-slot.loaded {
	color: var(--fg);
}

.translation-slot p,
.selection-popover p {
	margin: 0;
}

.translation-message {
	color: var(--muted);
	font-size: 0.92rem;
}

.w {
	border-radius: 0.15em;
	padding: 0 0.05em;
	cursor: pointer;
	transition: background 0.12s ease;
	box-decoration-break: clone;
	-webkit-box-decoration-break: clone;
}

.w:hover {
	outline: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
	outline-offset: 1px;
}

/* the tapped word keeps its hover outline while the lookup is open */
.w.sel {
	outline: 1px solid color-mix(in srgb, var(--accent) 70%, transparent);
	outline-offset: 1px;
	background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.panel-ignore {
	flex: none;
	color: var(--muted);
}

.panel-ignore:hover {
	color: var(--danger);
}

.panel-ai-loading {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	margin: 0;
	color: var(--muted);
}

.spinner {
	display: inline-block;
	width: 16px;
	height: 16px;
	vertical-align: -2px;
	flex: none;
	border-radius: 50%;
	border: 2px solid color-mix(in srgb, var(--accent) 25%, transparent);
	border-top-color: var(--accent);
	animation: kirk-spin 0.8s linear infinite;
}

@keyframes kirk-spin {
	to { transform: rotate(360deg); }
}

/* unknown: the page should read like a book — mark quietly, not loudly */
.w-0 {
	text-decoration: underline dotted var(--mark-unknown);
	text-decoration-thickness: 1.5px;
	text-underline-offset: 0.18em;
}

/* seen: tapped/looked up but not yet graded — the underline is reserved for
   words never touched, so the wash replaces it entirely */
.w-0.w-met {
	background: var(--mark-met);
	text-decoration: none;
}

/* ignored: out of tracking entirely — reads as plain text */
.w-ign {
	text-decoration: none;
	background: transparent;
}

/* learning: one hue, fading out as the word is acquired */
.w-1 { background: var(--mark-l1); }
.w-2 { background: var(--mark-l2); }
.w-3 { background: var(--mark-l3); }
.w-4 { background: transparent; }

.panel-shell {
	position: sticky;
	top: 1rem;
}

.word-panel {
	padding: 1rem;
}

.sheet-handle,
.scrim {
	display: none;
}

.reader-typo {
	position: relative;
	margin-left: auto;
}

.reader-typo summary {
	list-style: none;
}

.reader-typo summary::-webkit-details-marker {
	display: none;
}

.typo-popover {
	position: absolute;
	right: 0;
	top: calc(100% + 0.45rem);
	z-index: 30;
	min-width: 250px;
	padding: 0.85rem;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--card);
	box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
}

.typo-popover label {
	display: grid;
	gap: 0.25rem;
	margin-bottom: 0.7rem;
	color: var(--muted);
	font-size: 0.85rem;
}

.typo-popover label:last-child {
	margin-bottom: 0;
}

.typo-popover input,
.typo-popover select {
	width: 100%;
	accent-color: var(--accent);
}

.panel-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 0.75rem;
	padding-bottom: 0.65rem;
}

.panel-head h2 {
	margin: 0;
	font-size: 1.5rem;
	line-height: 1.2;
}

.headword-key {
	margin: 0.1rem 0 0;
	font-size: 0.85rem;
}

.panel-section {
	border-top: 1px solid var(--border);
	padding-top: 0.85rem;
	margin-top: 0.85rem;
}

.panel-section.first {
	margin-top: 0;
}

.hint {
	margin: 0.85rem 0 0;
	padding: 0.55rem 0.7rem;
	border: 1px dashed var(--border);
	border-radius: 8px;
	color: var(--muted);
	font-size: 0.88rem;
}

.panel-section h3 {
	font-size: 0.9rem;
	margin: 0 0 0.45rem;
	color: var(--muted);
	font-weight: 650;
}

.chip {
	border: 1px solid var(--border);
	border-radius: 999px;
	background: transparent;
	color: var(--fg);
	padding: 0.3rem 0.55rem;
	font: inherit;
	font-size: 0.85rem;
	text-decoration: none;
}

.chip {
	cursor: pointer;
}

.chip.active {
	border-color: var(--accent);
	color: var(--accent);
}

.selection-action-bar,
.selection-popover {
	position: absolute;
	z-index: 20;
	transform: translateX(-50%);
}

.selection-action-bar {
	display: flex;
	gap: 0.35rem;
}

.selection-translate-button {
	border: 1px solid var(--accent);
	border-radius: 999px;
	background: var(--accent);
	color: white;
	padding: 0.35rem 0.65rem;
	font: inherit;
	font-size: 0.86rem;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
	cursor: pointer;
}

.selection-translate-button.ghost {
	background: var(--card);
	color: var(--accent);
}

.selection-popover {
	max-width: min(360px, calc(100vw - 2rem));
	padding: 0.75rem 0.85rem;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--card);
	box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
	font-size: 0.95rem;
	line-height: 1.5;
}

.inline-form {
	align-items: stretch;
}

.inline-form input {
	min-width: 0;
	flex: 1;
}

.inline-form .btn {
	margin: 0;
}

.notice {
	margin-top: 0.85rem;
	padding: 0.7rem;
	border-radius: 8px;
	background: var(--mark-l2);
	color: var(--fg);
}

.notice.success {
	border: 1px solid color-mix(in srgb, var(--ok) 45%, transparent);
	background: color-mix(in srgb, var(--ok) 14%, transparent);
}

.notice.error {
	border: 1px solid var(--danger);
	background: transparent;
	color: var(--danger);
}

.context-sentence {
	font-family: ui-serif, Georgia, "Times New Roman", serif;
	line-height: 1.65;
}

.filter-form {
	display: grid;
	grid-template-columns: 1fr 130px 150px 150px auto;
	gap: 0.6rem;
	align-items: end;
	margin-bottom: 1rem;
}

.filter-form label {
	display: none;
}

.filter-form input,
.filter-form select,
.settings-form input,
.settings-form select {
	width: 100%;
	padding: 0.55rem 0.7rem;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--card);
	color: var(--fg);
	font: inherit;
}

.table-wrap {
	overflow-x: auto;
}

.vocab-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.95rem;
}

.vocab-table th,
.vocab-table td {
	padding: 0.65rem 0.5rem;
	border-bottom: 1px solid var(--border);
	text-align: left;
	vertical-align: middle;
}

.vocab-table th {
	color: var(--muted);
	font-size: 0.82rem;
	font-weight: 650;
}

.vocab-key {
	font-weight: 650;
}

.vocab-kind {
	color: var(--muted);
	text-transform: capitalize;
}

.chip-row.compact {
	gap: 0.3rem;
	flex-wrap: nowrap;
}

.inline-form.compact {
	min-width: 240px;
}

.vocab-due {
	white-space: nowrap;
}

.due-chip {
	display: inline-block;
	font-size: 0.78rem;
	color: var(--muted);
	border: 1px solid var(--border);
	border-radius: 999px;
	padding: 0.12rem 0.5rem;
}

.due-chip.hot {
	color: var(--accent);
	border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
	background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.due-chip.quiet {
	border-color: transparent;
	padding-left: 0;
}

.level-chip {
	font-size: 0.74rem;
	padding: 0.22rem 0.45rem;
}

.level-chip.active.lv-0 {
	border-color: var(--accent);
	color: var(--accent);
}

.level-chip.active.lv-1,
.level-chip.active.lv-2,
.level-chip.active.lv-3 {
	background: var(--mark-l2);
	border-color: color-mix(in srgb, #f59e0b 50%, var(--border));
	color: var(--fg);
}

.level-chip.active.lv-4 {
	background: color-mix(in srgb, var(--ok) 12%, transparent);
	border-color: color-mix(in srgb, var(--ok) 45%, var(--border));
	color: var(--fg);
}

/* inline edit: reads as text until focused, then shows its border + Save */
.inline-edit input {
	border: 1px solid transparent;
	border-radius: 8px;
	background: transparent;
	color: var(--fg);
	font: inherit;
	padding: 0.35rem 0.5rem;
	width: 100%;
}

.inline-edit input::placeholder {
	color: var(--muted);
	opacity: 1;
}

.inline-edit .btn {
	visibility: hidden;
}

.inline-edit:focus-within input {
	border-color: var(--border);
	background: var(--bg);
}

.inline-edit:focus-within .btn,
.inline-edit:hover .btn {
	visibility: visible;
}

.reset-btn {
	border: 0;
	background: transparent;
	color: var(--muted);
	font: inherit;
	font-size: 0.82rem;
	cursor: pointer;
	padding: 0.25rem 0.4rem;
	border-radius: 6px;
}

.reset-btn:hover {
	color: var(--danger);
	background: color-mix(in srgb, var(--danger) 8%, transparent);
}

.vocab-key .vocab-kind {
	display: block;
	font-size: 0.72rem;
}

.vocab-pager {
	justify-content: flex-end;
	margin-top: 1rem;
}

.stat-grid {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 0.75rem;
	margin-bottom: 1rem;
}

.stat-card,
.forecast-cell {
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 1rem;
}

.stat-card span,
.forecast-cell span,
.goal-head span,
.dist-row span {
	color: var(--muted);
	font-size: 0.9rem;
}

.stat-card strong,
.forecast-cell strong {
	display: block;
	font-size: 1.9rem;
	line-height: 1.2;
	margin-top: 0.25rem;
	font-variant-numeric: tabular-nums;
}

.stat-card small {
	display: block;
	color: var(--muted);
	font-size: 0.8rem;
	margin-top: 0.15rem;
}

.stat-hero {
	border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
	background: color-mix(in srgb, var(--accent) 5%, var(--card));
}

.stat-hero strong {
	font-size: 2.5rem;
	color: var(--accent);
}

.panel-title-row {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.75rem;
}

.panel-title-row h2 {
	margin: 0;
}

.milestone-note {
	margin: 0.5rem 0 0;
}

.footnote {
	margin-top: 1.5rem;
	font-size: 0.78rem;
	text-align: center;
}

.progress-grid,
.settings-grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 1rem;
	margin-bottom: 1rem;
}

.goal + .goal {
	margin-top: 1rem;
}

.goal-head,
.dist-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	margin-bottom: 0.35rem;
}

.dist-row {
	display: grid;
	grid-template-columns: 110px 1fr 48px;
}

.bar {
	height: 0.65rem;
	overflow: hidden;
	border-radius: 999px;
	background: color-mix(in srgb, var(--border) 70%, transparent);
}

.bar-fill {
	height: 100%;
	border-radius: inherit;
	background: var(--accent);
}

.level-fill {
	background: var(--mark-l1);
}

.bars {
	display: flex;
	align-items: end;
	gap: 0.22rem;
	height: 160px;
	padding-top: 0.5rem;
	border-bottom: 1px solid var(--border);
}

.bar-col {
	display: flex;
	align-items: end;
	flex: 1;
	height: 100%;
	min-width: 5px;
}

.bar-col-fill {
	width: 100%;
	border-radius: 4px 4px 0 0;
	background: var(--accent);
	opacity: 0.8;
}

.forecast {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 0.75rem;
}

/* review is a focus surface: one centered card, large type, keyboardable */
.review-stage {
	max-width: 620px;
	margin: 0 auto;
	padding-top: 1rem;
}

.review-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	margin-bottom: 1rem;
}

.review-activities {
	margin: 0;
}

.review-due-chip {
	flex: none;
	color: var(--muted);
	font-size: 0.85rem;
	font-variant-numeric: tabular-nums;
	border: 1px solid var(--border);
	border-radius: 999px;
	padding: 0.25rem 0.6rem;
}

.review-card {
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 14px;
	box-shadow: var(--shadow-1);
	padding: 2rem 1.75rem;
}

.review-card .review-example {
	font-family: ui-serif, Georgia, serif;
	font-size: 1.45rem;
	line-height: 1.7;
	margin: 0.25rem 0 0.75rem;
}

.review-card .review-word {
	font-family: ui-serif, Georgia, serif;
	font-size: 2.1rem;
	font-weight: 650;
	margin: 0.25rem 0 0.5rem;
}

.review-prompt-hint {
	color: var(--muted);
	font-size: 0.88rem;
	margin: 0 0 0.5rem;
}

.review-done {
	text-align: center;
	padding: 3rem 1.5rem;
}

.review-done-mark {
	margin: 0 auto 0.5rem;
	width: 3rem;
	height: 3rem;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 999px;
	background: color-mix(in srgb, var(--ok) 16%, transparent);
	color: var(--ok);
	font-size: 1.5rem;
}

.review-done h2 {
	margin: 0 0 0.25rem;
}

.review-done .btn {
	margin-top: 1rem;
	display: inline-block;
}

.choice-grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 0.5rem;
	margin-top: 0.75rem;
}

.choice-grid .choice {
	border-radius: 10px;
	text-align: left;
	padding: 0.7rem 0.85rem;
	font-size: 1rem;
}

.review-answer-prompt {
	font-size: 1.35rem;
	font-weight: 650;
	margin: 0.25rem 0 0.25rem;
}

.review-type-form {
	max-width: 420px;
	margin-top: 0.75rem;
}

.review-type-form input {
	font-size: 1.1rem;
	padding: 0.6rem 0.75rem;
	border: 1px solid var(--border);
	border-radius: 10px;
	background: var(--bg);
	color: var(--fg);
}

.review-example .blank {
	display: inline-block;
	min-width: 5rem;
	text-align: center;
}

.review-back {
	margin-top: 1.25rem;
}

.review-back summary {
	list-style: none;
}

.review-back summary::-webkit-details-marker {
	display: none;
}

.reveal-btn {
	display: flex;
	width: 100%;
	justify-content: center;
	gap: 0.5rem;
	cursor: pointer;
	font-size: 1rem;
	padding: 0.65rem 1rem;
}

.review-back[open] .reveal-btn {
	display: none;
}

kbd {
	font-family: var(--font-sans);
	font-size: 0.72rem;
	color: var(--muted);
	border: 1px solid var(--border);
	border-bottom-width: 2px;
	border-radius: 5px;
	padding: 0.05rem 0.35rem;
	background: var(--bg);
}

.reveal-btn kbd {
	color: color-mix(in srgb, white 75%, transparent);
	border-color: color-mix(in srgb, white 40%, transparent);
	background: transparent;
}

.review-answer {
	border-top: 1px solid var(--border);
	padding-top: 1rem;
}

.review-answer-word {
	margin: 0;
	font-family: ui-serif, Georgia, serif;
	font-size: 1.4rem;
	font-weight: 650;
}

.review-answer-back {
	margin: 0.15rem 0 1rem;
	font-size: 1.1rem;
	color: var(--muted);
}

.grade-row {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 0.5rem;
}

.grade {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.4rem;
	min-height: 44px;
	border-radius: 10px;
	border: 1px solid var(--border);
	background: transparent;
	color: var(--fg);
	font: inherit;
	font-size: 0.95rem;
	cursor: pointer;
}

.grade-again { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.grade-hard  { background: rgba(245, 158, 11, 0.12); border-color: color-mix(in srgb, #f59e0b 35%, var(--border)); }
.grade-good  { background: color-mix(in srgb, var(--ok) 10%, transparent); border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); }
.grade-easy  { background: rgba(59, 130, 246, 0.10); border-color: color-mix(in srgb, #3b82f6 35%, var(--border)); }

.settings-form {
	max-width: none;
	margin-bottom: 1.25rem;
}

.settings-form:last-child {
	margin-bottom: 0;
}

.install-panel {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 1rem;
}

.install-panel h2 {
	margin: 0 0 0.25rem;
}

.danger-zone {
	border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}

/* signed-in home dashboard */
.home-grid {
	display: grid;
	grid-template-columns: 2fr 1fr 1fr;
	gap: var(--gap);
	align-items: stretch;
}

.home-card {
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 14px;
	box-shadow: var(--shadow-1);
	padding: 1.25rem;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 0.35rem;
}

.home-card h2 {
	margin: 0;
	font-size: 1.3rem;
	line-height: 1.3;
}

.home-card .btn {
	margin-top: auto;
}

.home-card .sub span + span::before {
	content: " · ";
}

.home-big {
	margin: 0;
	font-size: 2.4rem;
	font-weight: 700;
	line-height: 1.1;
	font-variant-numeric: tabular-nums;
}

.home-bar {
	width: 100%;
	margin: 0.25rem 0 0.75rem;
}

@media (max-width: 860px) {
	.home-grid {
		grid-template-columns: 1fr 1fr;
	}

	.home-continue {
		grid-column: 1 / -1;
	}
}

@media (max-width: 1024px) {
	.reader-grid {
		grid-template-columns: 1fr;
	}

	.panel-shell {
		position: fixed;
		left: 0;
		right: 0;
		top: auto; /* the desktop sticky rule's top:1rem must not stretch the sheet */
		bottom: 0;
		z-index: 70; /* above the tab bar (50): an open sheet is modal */
		max-height: min(60vh, 100%);
		overflow-y: auto;
		padding: 0.5rem var(--pad) calc(0.75rem + env(safe-area-inset-bottom));
		border-top: 1px solid var(--border);
		border-top-left-radius: 16px;
		border-top-right-radius: 16px;
		background: var(--card);
		box-shadow: var(--shadow-2);
		transform: translateY(105%);
		visibility: hidden; /* belt and braces: never peek while closed */
		transition: transform 0.22s ease, visibility 0s linear 0.22s;
	}

	.panel-shell.open {
		transform: translateY(0);
		visibility: visible;
		transition: transform 0.22s ease;
	}

	.panel-shell .word-panel {
		border: 0;
		background: transparent;
		padding: 0 0 1rem;
	}

	.sheet-handle {
		display: block;
		margin: 0 auto 0.5rem;
		border: 0;
		border-radius: 999px;
		background: color-mix(in srgb, var(--border) 70%, transparent);
		color: var(--fg);
		padding: 0.25rem 0.75rem;
		font: inherit;
		cursor: pointer;
	}

	.scrim {
		display: block;
		position: fixed;
		inset: 0;
		z-index: 69;
		background: rgba(0, 0, 0, 0.4);
		opacity: 0;
		pointer-events: none;
		transition: opacity 0.18s ease;
	}

	.scrim.show {
		opacity: 1;
		pointer-events: auto;
	}

	.page-head,
	.doc-row,
	.install-panel {
		flex-direction: column;
		align-items: stretch;
	}

	.filter-form,
	.progress-grid,
	.settings-grid {
		grid-template-columns: 1fr;
	}

	.stat-grid,
	.forecast {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.chip-row.compact {
		flex-wrap: wrap;
	}

	.typo-popover {
		left: 0;
		right: auto;
	}
}

@media (max-width: 640px) {
	:root {
		--pad: 1rem;
		--tabbar-h: 58px;
	}

	.topbar {
		padding: 0.8rem var(--pad);
		align-items: flex-start;
	}

	.topnav {
		gap: 0.55rem;
	}

	.topnav a.top-primary {
		display: none;
	}

	.topnav a,
	.toggle {
		font-size: 0.86rem;
	}

	.container {
		padding-top: 1.4rem;
	}

	.tabbar {
		display: flex;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 50;
		justify-content: space-around;
		gap: 0.2rem;
		padding: 0.35rem 0.35rem calc(0.35rem + env(safe-area-inset-bottom));
		border-top: 1px solid var(--border);
		background: var(--card);
		box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.08);
	}

	.tabbar a {
		display: flex;
		align-items: center;
		justify-content: center;
		min-width: 44px;
		min-height: 44px;
		padding: 0.25rem 0.45rem;
		border-radius: 8px;
		font-size: 0.78rem;
	}

	.tabbar a.active {
		background: color-mix(in srgb, var(--accent) 12%, transparent);
	}

	.reader-controls {
		gap: 0.5rem;
	}

	.reader-controls .chip {
		font-size: 0.78rem;
		padding: 0.28rem 0.5rem;
	}

	.reader-meta {
		white-space: normal;
	}

	.typo-popover {
		right: 0;
		left: auto;
	}

	.toc-popover {
		position: fixed;
		left: 0;
		right: 0;
		top: auto;
		bottom: 0;
		width: auto;
		max-height: 70vh;
		border-radius: 14px 14px 0 0;
		border-bottom: none;
		padding-bottom: calc(0.4rem + env(safe-area-inset-bottom));
		z-index: 70;
	}

	.stat-grid,
	.forecast {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.filter-form {
		grid-template-columns: 1fr;
	}

	.choice-grid {
		grid-template-columns: 1fr;
	}

	.table-wrap {
		overflow: visible;
	}

	.vocab-table,
	.vocab-table thead,
	.vocab-table tbody,
	.vocab-table tr,
	.vocab-table td {
		display: block;
		width: 100%;
	}

	.vocab-table thead {
		display: none;
	}

	.vocab-row {
		margin-bottom: 0.75rem;
		padding: 0.75rem;
		border: 1px solid var(--border);
		border-radius: 8px;
		background: var(--card);
	}

	.vocab-table td {
		padding: 0.28rem 0;
		border-bottom: 0;
	}

	.vocab-key {
		font-size: 1.08rem;
	}

	.inline-form.compact {
		min-width: 0;
	}

	.selection-action-bar,
	.selection-popover {
		position: fixed;
		left: var(--pad);
		right: var(--pad);
		bottom: calc(var(--tabbar-h) + 0.75rem + env(safe-area-inset-bottom));
		top: auto;
		transform: none;
		max-width: none;
	}

	.selection-action-bar {
		justify-content: center;
	}
}

/* ---------- texture pass: icons, tiles, elevation, motion ---------- */

.icon {
	width: 1.15em;
	height: 1.15em;
	display: inline-block;
	vertical-align: -0.18em;
}

.toggle .icon {
	width: 1.05rem;
	height: 1.05rem;
	vertical-align: -0.22em;
}

.icon-sun { display: none; }
html.dark .icon-sun { display: inline; }
html.dark .icon-moon { display: none; }

.icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.1rem;
	height: 2.1rem;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: transparent;
	color: var(--muted);
	cursor: pointer;
}

.icon-btn:hover {
	color: var(--danger);
	border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
}

.panel,
.doc-row,
.stat-card,
.forecast-cell {
	box-shadow: var(--shadow-1);
}

.doc-tile {
	flex: none;
	width: 3.4rem;
	height: 4.4rem;
	border-radius: 8px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: ui-serif, Georgia, serif;
	font-size: 1.6rem;
	font-weight: 700;
	text-decoration: none;
	box-shadow: var(--shadow-1);
}

.tile-0 { background: #fde8d7; color: #9a3412; }
.tile-1 { background: #e0e7ff; color: #3730a3; }
.tile-2 { background: #d1fae5; color: #065f46; }
.tile-3 { background: #fce7f3; color: #9d174d; }
.tile-4 { background: #fef3c7; color: #92400e; }
.tile-5 { background: #e0f2fe; color: #075985; }

html.dark .tile-0 { background: #4a2511; color: #fdba74; }
html.dark .tile-1 { background: #272a52; color: #a5b4fc; }
html.dark .tile-2 { background: #0d3a2c; color: #6ee7b7; }
html.dark .tile-3 { background: #4a1230; color: #f9a8d4; }
html.dark .tile-4 { background: #45300a; color: #fcd34d; }
html.dark .tile-5 { background: #0c3349; color: #7dd3fc; }

.doc-main {
	flex: 1;
	min-width: 0;
}

.doc-main .meta span + span::before {
	content: " · ";
}

.doc-coverage {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	margin-top: 0.45rem;
}

.doc-bar {
	flex: 1;
	max-width: 220px;
	height: 0.45rem;
}

.doc-row h2 a {
	color: var(--fg);
	text-decoration: none;
}

.doc-row h2 a:hover {
	color: var(--accent);
}

.tabbar a {
	flex-direction: column;
	gap: 0.1rem;
}

.tabbar .icon {
	width: 1.25rem;
	height: 1.25rem;
	vertical-align: 0;
}

/* motion: SSE outer-replaces re-trigger these entrance animations */
@keyframes rise-in {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

#word-panel,
.review-card,
.selection-popover:not([hidden]) {
	animation: rise-in 0.18s ease both;
}

.btn:active,
.chip:active,
.grade:active {
	transform: scale(0.97);
}

@media (prefers-reduced-motion: reduce) {
	#word-panel,
	.review-card,
	.selection-popover:not([hidden]) {
		animation: none;
	}

	.panel-shell,
	.scrim,
	body {
		transition: none;
	}
}
