:root {
	color-scheme: light;
	font-family: "STKaiti", "KaiTi", "Noto Serif SC", serif;
	--paper: #d8d0bb;
	--paper-strong: rgba(224, 216, 195, 0.94);
	--ink: #292821;
	--ink-soft: #665f51;
	--line: rgba(41, 40, 33, 0.36);
	--red: #8f352a;
	--shadow: 0 8px 28px rgba(31, 29, 24, 0.2);
}

* { box-sizing: border-box; }

html, body {
	width: 100%;
	height: 100%;
	margin: 0;
	overflow: hidden;
	background: var(--paper);
	color: var(--ink);
}

button, a { font: inherit; }

button {
	min-width: 44px;
	min-height: 44px;
	border: 1px solid var(--line);
	background: rgba(231, 224, 206, 0.9);
	color: var(--ink);
	cursor: pointer;
	transition: background 140ms ease, color 140ms ease, transform 140ms ease;
}

button:hover { background: #eee6d1; }
button:active { transform: translateY(1px); }
button.active, button[aria-pressed="true"] { background: #49493f; color: #f1ead8; }
button:focus-visible, a:focus-visible { outline: 3px solid rgba(143, 53, 42, 0.55); outline-offset: 2px; }

a { color: #67483b; text-decoration-thickness: 1px; text-underline-offset: 3px; }

#san11-canvas {
	display: block;
	width: 100vw;
	height: 100vh;
	touch-action: none;
	cursor: grab;
}

#san11-canvas:active { cursor: grabbing; }

.paper-panel {
	position: fixed;
	z-index: 10;
	background:
		linear-gradient(110deg, rgba(255,255,255,0.08), transparent 42%),
		var(--paper-strong);
	border: 1px solid var(--line);
	box-shadow: var(--shadow);
	backdrop-filter: blur(6px);
}

#loading {
	position: fixed;
	inset: 0;
	z-index: 100;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 18px;
	background: #d8d0bb;
	letter-spacing: 0.12em;
	transition: opacity 420ms ease, visibility 420ms ease;
}

#loading.done { opacity: 0; visibility: hidden; }
#loading.failed { color: #7c2f29; }
#loading strong { display: block; font-size: 21px; margin-bottom: 5px; }
#loading span { display: block; color: var(--ink-soft); font-size: 13px; }

.loading-seal {
	width: 58px;
	height: 58px;
	display: grid;
	place-items: center;
	border: 2px solid var(--red);
	color: var(--red);
	font-weight: 700;
	font-size: 18px;
	line-height: 1.05;
	transform: rotate(-3deg);
}

#brand-panel {
	top: max(14px, env(safe-area-inset-top));
	left: max(14px, env(safe-area-inset-left));
	width: 286px;
	padding: 12px 15px 11px;
}

.brand-kicker, .info-kicker {
	font-family: Georgia, serif;
	font-size: 9px;
	letter-spacing: 0.18em;
	text-transform: uppercase;
	color: var(--ink-soft);
}

#brand-panel h1 {
	margin: 3px 0 1px;
	font-size: 24px;
	letter-spacing: 0.12em;
	font-weight: 700;
}

.brand-sub { font-size: 12px; color: var(--ink-soft); }
.brand-links { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; }
.text-button { min-width: 0; min-height: 0; padding: 0; border: 0; background: transparent; text-decoration: underline; }

#map-toolbar {
	top: max(14px, env(safe-area-inset-top));
	right: max(14px, env(safe-area-inset-right));
	display: flex;
	padding: 5px;
	gap: 4px;
}

#map-toolbar button { padding: 0 12px; }
#btn-rotate-left, #btn-rotate-right { font-size: 20px; padding: 0; }

#view-rail {
	left: max(14px, env(safe-area-inset-left));
	top: 50%;
	transform: translateY(-38%);
	display: flex;
	flex-direction: column;
	padding: 5px;
	gap: 3px;
}

#view-rail button { min-height: 38px; padding: 0 11px; font-size: 12px; }

#map-info {
	top: 82px;
	right: max(14px, env(safe-area-inset-right));
	width: min(340px, calc(100vw - 28px));
	padding: 19px 18px 15px;
	opacity: 0;
	pointer-events: none;
	transform: translateX(calc(100% + 28px));
	transition: transform 240ms ease, opacity 200ms ease;
}

#map-info.open { opacity: 1; pointer-events: auto; transform: translateX(0); }
#map-info h2 { margin: 3px 32px 2px 0; font-size: 25px; letter-spacing: 0.08em; }
#info-meta { color: var(--red); font-size: 12px; line-height: 1.5; }
#info-body { margin: 12px 0; font-size: 14px; line-height: 1.7; }

.panel-close {
	position: absolute;
	top: 7px;
	right: 7px;
	width: 44px;
	padding: 0;
	border: 0;
	background: transparent;
	font: 28px/1 Arial, sans-serif;
}

.info-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.info-actions button { padding: 7px 8px; }

#route-banner {
	position: fixed;
	left: 50%;
	bottom: calc(54px + env(safe-area-inset-bottom));
	z-index: 12;
	max-width: min(680px, calc(100vw - 30px));
	padding: 8px 14px;
	background: rgba(68, 64, 54, 0.94);
	color: #f1ead8;
	border: 1px solid rgba(241, 234, 216, 0.35);
	box-shadow: var(--shadow);
	font-size: 13px;
	opacity: 0;
	pointer-events: none;
	transform: translate(-50%, 12px);
	transition: opacity 180ms ease, transform 180ms ease;
}

#route-banner.visible { opacity: 1; transform: translate(-50%, 0); }

#map-status {
	left: 50%;
	bottom: max(10px, env(safe-area-inset-bottom));
	transform: translateX(-50%);
	width: min(660px, calc(100vw - 28px));
	min-height: 34px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 18px;
	padding: 6px 11px;
	font-size: 12px;
	pointer-events: none;
}

#hover-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#view-level { color: var(--ink-soft); white-space: nowrap; }

.paper-dialog {
	width: min(500px, calc(100vw - 28px));
	max-height: calc(100vh - 36px);
	padding: 22px 24px 18px;
	border: 1px solid var(--line);
	background: #e2dac5;
	color: var(--ink);
	box-shadow: 0 20px 70px rgba(20, 18, 14, 0.36);
}

.paper-dialog::backdrop { background: rgba(35, 34, 29, 0.52); backdrop-filter: blur(2px); }
.paper-dialog h2 { margin: 0 38px 12px 0; font-size: 25px; }
.paper-dialog ul { padding-left: 1.25em; line-height: 1.8; }
.paper-dialog p { line-height: 1.7; }

#update-banner {
	position: fixed;
	left: 50%;
	bottom: max(9px, env(safe-area-inset-bottom));
	z-index: 80;
	display: flex;
	align-items: center;
	gap: 10px;
	transform: translateX(-50%);
	padding: 7px 8px 7px 14px;
	background: #38372f;
	color: #f2ecd9;
	box-shadow: var(--shadow);
}

#update-banner button { min-height: 36px; padding: 0 12px; }
#update-banner .banner-close { min-width: 36px; padding: 0; }

@media (max-width: 720px) {
	#brand-panel { width: 210px; padding: 9px 11px; }
	#brand-panel h1 { font-size: 19px; }
	.brand-kicker { display: none; }
	#map-toolbar { top: auto; bottom: calc(62px + env(safe-area-inset-bottom)); right: 8px; flex-direction: column; }
	#map-toolbar button { width: 48px; padding: 0; font-size: 11px; }
	#view-rail {
		top: auto;
		left: max(8px, env(safe-area-inset-left));
		right: 72px;
		bottom: calc(62px + env(safe-area-inset-bottom));
		transform: none;
		flex-direction: row;
		overflow-x: auto;
		scrollbar-width: none;
		box-shadow: var(--shadow);
	}
	#view-rail::-webkit-scrollbar { display: none; }
	#view-rail button { flex: 0 0 auto; min-width: 49px; min-height: 44px; padding: 0 7px; }
	#map-info {
		top: auto;
		left: 8px;
		right: 8px;
		bottom: calc(138px + env(safe-area-inset-bottom));
		width: auto;
		transform: translateY(calc(100% + 130px));
	}
	#map-info.open { transform: translateY(0); }
	#map-info h2 { font-size: 22px; }
	#info-body { margin: 8px 0; }
	#map-status { bottom: max(7px, env(safe-area-inset-bottom)); width: calc(100vw - 16px); }
	#hover-status { max-width: 70vw; }
	#route-banner { bottom: calc(136px + env(safe-area-inset-bottom)); }
}

@media (max-width: 430px) {
	.brand-sub { display: none; }
	.brand-links { margin-top: 4px; }
	#brand-panel { width: 184px; }
	#hover-status { max-width: 62vw; }
}

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
