:root {
	--bg: #16120f;
	--surface: #221c17;
	--surface-2: #2d251e;
	--text: #f3ebe0;
	--muted: #a8998a;
	--accent: #e0452f;
	--accent-text: #fff;
	--box: rgba(255, 196, 92, 0.9);
	--box-fill: rgba(255, 196, 92, 0.12);
	--selected: #ff6a4d;
	--selected-fill: rgba(255, 106, 77, 0.2);
	--border: #3a3028;
	--shadow: rgba(0, 0, 0, 0.4);
	--overlay-bg: rgba(22, 18, 15, 0.75);
	color-scheme: dark;
}

@media (prefers-color-scheme: light) {
	:root {
		--bg: #f7f1e8;
		--surface: #fffaf3;
		--surface-2: #f0e7da;
		--text: #2a211b;
		--muted: #7a6b5d;
		--accent: #c7351f;
		--box: rgba(199, 53, 31, 0.85);
		--box-fill: rgba(199, 53, 31, 0.08);
		--selected: #1f6fc7;
		--selected-fill: rgba(31, 111, 199, 0.15);
		--border: #e3d7c6;
		--shadow: rgba(60, 40, 20, 0.12);
		--overlay-bg: rgba(255, 250, 243, 0.85);
		color-scheme: light;
	}
}

* {
	box-sizing: border-box;
}

html {
	touch-action: pan-x pan-y;
	-webkit-text-size-adjust: 100%;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
	line-height: 1.5;
	padding-bottom: env(safe-area-inset-bottom);
}

header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	padding-top: max(12px, env(safe-area-inset-top));
	border-bottom: 1px solid var(--border);
	position: sticky;
	top: 0;
	background: var(--bg);
	z-index: 10;
}

h1 {
	font-size: 18px;
	margin: 0;
	display: flex;
	align-items: center;
	gap: 8px;
}

.logo {
	display: inline-grid;
	place-items: center;
	width: 30px;
	height: 30px;
	border-radius: 8px;
	background: var(--accent);
	color: var(--accent-text);
	font-size: 18px;
}

.toggle {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 15px;
	color: var(--muted);
}

.toggle input {
	width: 18px;
	height: 18px;
	accent-color: var(--accent);
}

#status {
	position: fixed;
	top: var(--header-height, 55px);
	left: 0;
	right: 0;
	z-index: 9;
	padding: 10px 16px;
	background: var(--surface-2);
	font-size: 14px;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

#status[hidden] {
	display: none;
}

progress {
	width: 100%;
	height: 4px;
	accent-color: var(--accent);
}

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

#intro {
	text-align: center;
	padding: 32px 0;
	min-height: calc(100dvh - var(--header-height, 55px));
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.lantern {
	font-size: 64px;
	margin: 0 0 8px;
	line-height: 1.6;
}

.lantern rt {
	font-size: 0.3em;
	color: var(--muted);
}

.lead {
	font-size: 18px;
	margin: 0 auto 28px;
	max-width: 22em;
}

.note {
	color: var(--muted);
	font-size: 14px;
	margin-top: 24px;
}

.actions {
	display: flex;
	gap: 12px;
	justify-content: center;
	flex-wrap: wrap;
}

.button {
	appearance: none;
	font: inherit;
	font-size: 17px;
	font-weight: 600;
	padding: 14px 24px;
	border-radius: 999px;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	cursor: pointer;
	min-width: 140px;
	text-align: center;
}

.button.primary {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--accent-text);
}

#viewer[hidden], #intro[hidden] {
	display: none;
}

.box {
	fill: var(--box-fill);
	stroke: var(--box);
	stroke-width: 2;
	vector-effect: non-scaling-stroke;
	cursor: pointer;
	transition: fill 0.15s;
}

.box.selected {
	stroke: var(--selected);
	stroke-width: 3;
	fill: var(--selected-fill);
}

.line {
	display: flex;
	align-items: center;
	gap: 12px;
}

.ja {
	flex: 1;
	min-width: 0;
	font-size: 28px;
	margin: 0;
	line-height: 1.9;
	overflow-wrap: anywhere;
}

.ja rt {
	font-size: 0.5em;
	color: var(--accent);
}

.romaji {
	margin: 0;
	color: var(--muted);
	font-size: 15px;
}

.hide-romaji .romaji {
	display: none;
}

.speak {
	flex: none;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	border: 1px solid var(--border);
	background: var(--surface-2);
	color: var(--text);
	display: grid;
	place-items: center;
	cursor: pointer;
}

.toggles {
	display: flex;
	gap: 14px;
}

.meanings {
	list-style: none;
	padding: 8px 0 0;
	margin: 8px 0 0;
	border-top: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	gap: 4px;
	font-size: 15px;
}

.meaning {
	display: flex;
	gap: 10px;
	align-items: baseline;
}

.meaning .word {
	flex: none;
	font-weight: 600;
	min-width: 3em;
}

.meaning .details {
	min-width: 0;
	color: var(--muted);
}

.alternatives {
	display: block;
	font-size: 14px;
	margin-top: 2px;
}

.alternative {
	appearance: none;
	font: inherit;
	font-size: 15px;
	color: var(--accent);
	background: none;
	border: none;
	padding: 2px 0;
	cursor: pointer;
	text-decoration: underline;
	text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
	text-underline-offset: 3px;
}

.meaning .sense {
	display: block;
}

.meaning .sense b {
	color: var(--accent);
	font-weight: 600;
}

.meaning:not(.expanded) .sense:not(:first-child) {
	display: none;
}

.meaning:not(.expanded) .sense:first-child b {
	display: none;
}

.meaning:not(.expanded) .sense:first-child:not(:last-child)::after {
	content: " …";
}

.hide-english .senses,
.hide-english .meaning:not(:has(.alternatives)) {
	display: none;
}

.hide-english .meanings:not(:has(.alternatives)) {
	display: none;
}

.credits {
	color: var(--muted);
	font-size: 12px;
	margin-top: 32px;
}

.credits a,
.source a {
	color: inherit;
}

.source {
	color: var(--muted);
	font-size: 12px;
	margin-top: 8px;
}

#sheet {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 20;
	max-width: 720px;
	margin: 0 auto;
	max-height: 55vh;
	display: flex;
	flex-direction: column;
	background: var(--surface);
	border: 1px solid var(--border);
	border-bottom: none;
	border-radius: 18px 18px 0 0;
	box-shadow: 0 -8px 32px var(--shadow);
	padding-bottom: env(safe-area-inset-bottom);
	animation: sheet-in 0.2s ease-out;
}

#sheet[hidden] {
	display: none;
}

@keyframes sheet-in {
	from {
		transform: translateY(24px);
		opacity: 0;
	}
}

.sheet-nav {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 8px 8px 0;
}

#position {
	flex: 1;
	text-align: center;
	font-size: 13px;
	color: var(--muted);
	font-variant-numeric: tabular-nums;
}

.icon-button {
	appearance: none;
	width: 40px;
	height: 40px;
	border: none;
	border-radius: 50%;
	background: transparent;
	color: var(--text);
	display: grid;
	place-items: center;
	cursor: pointer;
}

.icon-button:active {
	background: var(--surface-2);
}

#card {
	overflow-y: auto;
	padding: 4px 16px 16px;
	overscroll-behavior: contain;
}

/* Photo viewer: fills the screen below the header, with its own zoom. */

.viewing {
	overflow: hidden;
}

#viewer {
	position: fixed;
	top: var(--header-height, 55px);
	left: 0;
	right: 0;
	bottom: 0;
}

.photo {
	position: absolute;
	inset: 0;
	overflow: hidden;
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
	background: var(--bg);
}

#stage {
	position: absolute;
	top: 0;
	left: 0;
	transform-origin: 0 0;
	will-change: transform;
}

#photo {
	display: block;
	width: 100%;
	height: 100%;
}

#overlay {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
}

#summary {
	position: absolute;
	top: 10px;
	left: 50%;
	transform: translateX(-50%);
	max-width: calc(100% - 32px);
	margin: 0;
	padding: 6px 14px;
	border-radius: 999px;
	background: var(--overlay-bg);
	color: var(--text);
	font-size: 13px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	pointer-events: none;
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
}

#summary:empty {
	display: none;
}

.actions.floating {
	position: absolute;
	left: 16px;
	right: 16px;
	bottom: max(16px, env(safe-area-inset-bottom));
	pointer-events: none;
}

.actions.floating > * {
	pointer-events: auto;
	box-shadow: 0 4px 16px var(--shadow);
}

.sheet-open .actions.floating {
	display: none;
}

/* Start screen: offline and install status. */

#offline-status {
	font-size: 14px;
	color: var(--muted);
	margin: 8px 0 0;
}

#offline-status::before {
	content: "";
	display: inline-block;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	margin-right: 8px;
	vertical-align: 1px;
	background: var(--muted);
}

#offline-status[data-state="saving"]::before {
	background: #e0a32f;
	animation: pulse 1s ease-in-out infinite alternate;
}

#offline-status[data-state="ready"]::before {
	background: #3fb56b;
}

@keyframes pulse {
	to {
		opacity: 0.3;
	}
}

.install {
	font-size: 14px;
	color: var(--muted);
	margin-top: 16px;
}

.install a {
	color: var(--accent);
	font-weight: 600;
}
