/* Design tokens and themes */
:root {
	--font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
	--font-serif: 'Literata Variable', Georgia, serif;
	--font-sans: var(--font-ui);

	--bg: #fbfaf7;
	--surface: #ffffff;
	--surface-2: #f3f1ec;
	--text: #1d1b18;
	--muted: #6d6860;
	--faint: #a29d94;
	--border: #e7e3da;
	--accent: #2c55c0;
	--accent-soft: #e8eefc;
	--on-accent: #ffffff;
	--shadow: 0 1px 2px rgb(30 25 15 / 6%), 0 8px 24px rgb(30 25 15 / 8%);
	--shadow-lg: 0 2px 6px rgb(30 25 15 / 8%), 0 24px 60px rgb(30 25 15 / 18%);
	--scan-bg: #ece9e2;

	/* ProofreadPage quality levels */
	--q0: #b8b2a7;
	--q1: #e0705e;
	--q2: #8f7ff0;
	--q3: #e2b23c;
	--q4: #3fa56b;
	--q-none: #ebe7df;

	--radius: 14px;
	--radius-sm: 9px;
	--header-h: 56px;
	--measure: 38rem;
	--ease: cubic-bezier(0.2, 0.7, 0.2, 1);

	color-scheme: light;
}

[data-theme='sepia'] {
	--bg: #f4ecd8;
	--surface: #faf4e4;
	--surface-2: #ece2c8;
	--text: #3b2f20;
	--muted: #7a6a52;
	--faint: #a8977c;
	--border: #e2d6b8;
	--accent: #9a4f1c;
	--accent-soft: #f1dcc3;
	--scan-bg: #e9dfc6;
	--q-none: #e6dbbf;
}

[data-theme='dark'] {
	--bg: #16171a;
	--surface: #1e2024;
	--surface-2: #26282d;
	--text: #e7e5e0;
	--muted: #a19d95;
	--faint: #6f6c66;
	--border: #2f3137;
	--accent: #8eaaff;
	--accent-soft: #232c45;
	--on-accent: #0f1422;
	--shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%);
	--shadow-lg: 0 2px 6px rgb(0 0 0 / 40%), 0 24px 60px rgb(0 0 0 / 50%);
	--scan-bg: #232428;
	--q-none: #33353b;
	color-scheme: dark;
}

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

html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
	/* The reader compensates for content loading above the viewport itself. */
	overflow-anchor: none;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 16px/1.5 var(--font-ui);
	-webkit-font-smoothing: antialiased;
	-webkit-tap-highlight-color: transparent;
	transition: background-color 0.25s, color 0.25s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 0.18em; }
img { max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

@media (max-width: 719px) {
	.wide-only { display: none !important; }
}

/* Korean breaks lines between words, not between syllables. */
:lang(ko) { word-break: keep-all; }

.visually-hidden {
	position: absolute !important;
	width: 1px; height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

/* Layout */
.container {
	width: 100%;
	max-width: 1180px;
	margin: 0 auto;
	padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
}

.section { margin: 40px 0; }
.section-head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 14px;
}
.section-head h2 {
	font: 600 1.15rem/1.3 var(--font-ui);
	letter-spacing: -0.01em;
	margin: 0;
}
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

/* Buttons */
.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-height: 40px;
	padding: 0 16px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--surface);
	color: var(--text);
	font-weight: 500;
	font-size: 0.95rem;
	cursor: pointer;
	text-decoration: none !important;
	white-space: nowrap;
	transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { min-height: 32px; padding: 0 12px; font-size: 0.85rem; }

.icon-btn {
	display: inline-grid;
	place-items: center;
	width: 40px;
	height: 40px;
	flex: none;
	border: 0;
	border-radius: 999px;
	background: transparent;
	color: var(--text);
	cursor: pointer;
	transition: background-color 0.15s;
}
.icon-btn:hover, .icon-btn[aria-pressed='true'] { background: var(--surface-2); }
.icon-btn:focus-visible { outline-offset: -2px; border-radius: 999px; }
.icon-btn:disabled { opacity: 0.4; cursor: default; }

/* Chips */
.chips {
	display: flex;
	gap: 8px;
	overflow-x: auto;
	scrollbar-width: none;
	padding: 2px;
	margin: -2px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	flex: none;
	height: 34px;
	padding: 0 14px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--surface);
	color: var(--text);
	font-size: 0.875rem;
	cursor: pointer;
	white-space: nowrap;
	transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover { border-color: var(--faint); text-decoration: none; }
.chip[aria-pressed='true'], .chip.active { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip .count { opacity: 0.6; font-variant-numeric: tabular-nums; }

/* Form fields */
.field {
	width: 100%;
	height: 44px;
	padding: 0 14px;
	border: 1px solid var(--border);
	border-radius: 12px;
	background: var(--surface);
	color: var(--text);
	outline: none;
	transition: border-color 0.15s, box-shadow 0.15s;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
select.field { padding-right: 32px; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 19px, calc(100% - 13px) 19px; background-size: 5px 5px; background-repeat: no-repeat; }

.badge {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 1px 7px;
	border-radius: 6px;
	background: var(--surface-2);
	color: var(--muted);
	font-size: 0.72rem;
	font-weight: 600;
	letter-spacing: 0.02em;
	text-transform: uppercase;
	white-space: nowrap;
}

/* Horizontal shelves */
.shelf {
	display: grid;
	grid-auto-flow: column;
	grid-auto-columns: 132px;
	gap: 16px;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	scroll-padding: 16px;
	padding: 4px 16px 12px;
	margin: 0 -16px;
	scrollbar-width: none;
}
.shelf::-webkit-scrollbar { display: none; }
.shelf > * { scroll-snap-align: start; }
@media (min-width: 720px) {
	/* Wide screens: wrap into rows, so nothing hides off-screen. */
	.shelf {
		grid-auto-flow: row;
		grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
		gap: 28px 22px;
		overflow: visible;
		margin: 0;
		padding: 4px 0 0;
	}
}

.empty {
	padding: 48px 16px;
	text-align: center;
	color: var(--muted);
}

.skeleton {
	background: linear-gradient(90deg, var(--surface-2) 0%, var(--border) 50%, var(--surface-2) 100%);
	background-size: 200% 100%;
	animation: shimmer 1.4s infinite linear;
	border-radius: 8px;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 0.9s linear infinite; }

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