/* 永字八法 · 华文道「文字与印信」：基础、布局、纸面与 HUD */
:root {
	--ink: #0b0a08;
	--ink2: #12100d;
	--ink3: #1b1814;
	--paper: #f2ebde;
	--verm: #e2462b;
	--verm-d: #a8321f;
	--gold: #d9b36c;
	--gold-l: #f0d79c;
	--txt: #f2ebde;
	--txt2: rgba(242, 235, 222, .68);
	--txt3: rgba(242, 235, 222, .44);
	--line: rgba(242, 235, 222, .12);
	--line2: rgba(242, 235, 222, .24);
	--mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
	--serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "Noto Serif SC", "SimSun", serif;
	--sans: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
	--sat: env(safe-area-inset-top, 0px);
	--sab: env(safe-area-inset-bottom, 0px);
	--sal: env(safe-area-inset-left, 0px);
	--sar: env(safe-area-inset-right, 0px);
	--padT: 22px;
	--padB: 22px;
	--sheet: 560px;
	color-scheme: dark;
}
html.in-frame { --padT: 56px; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
	min-height: 100%;
	background: var(--ink);
	color: var(--txt);
	font: 15px/1.7 var(--sans);
	-webkit-font-smoothing: antialiased;
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
	overflow-x: hidden;
}
button, a { font: inherit; color: inherit; }
button { cursor: pointer; }
.mono { font-family: var(--mono); letter-spacing: .02em; }
[hidden] { display: none !important; }
kbd {
	font: 500 10px/1 var(--mono); letter-spacing: 0; color: var(--txt3);
	border: 1px solid var(--line2); border-radius: 3px; padding: 2px 4px; margin-left: 6px;
}
@media (hover: none) { kbd { display: none; } }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- 舞台 ---------- */
.yz {
	position: relative;
	min-height: 100vh;
	min-height: 100dvh;
	background:
		radial-gradient(70% 55% at 30% 45%, rgba(217, 179, 108, .08), transparent 70%),
		radial-gradient(120% 90% at 50% 120%, #1d140e 0%, var(--ink) 60%);
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	grid-template-areas: "head" "tabs" "stage" "panel";
	padding: calc(var(--padT) + var(--sat)) calc(16px + var(--sar)) calc(var(--padB) + var(--sab)) calc(16px + var(--sal));
	row-gap: 12px;
}
.yz::before {
	content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .55;
	background-image:
		linear-gradient(rgba(242, 235, 222, .026) 1px, transparent 1px),
		linear-gradient(90deg, rgba(242, 235, 222, .026) 1px, transparent 1px);
	background-size: 24px 24px;
	-webkit-mask-image: radial-gradient(80% 70% at 40% 45%, #000, transparent);
	mask-image: radial-gradient(80% 70% at 40% 45%, #000, transparent);
}
.yz > * { position: relative; z-index: 1; min-width: 0; }
.yz-head { grid-area: head; text-align: center; }
.yz-tabs { grid-area: tabs; }
.yz-stage { grid-area: stage; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.yz-panel { grid-area: panel; }

.yz-title {
	margin: 0; display: inline-flex; align-items: center; gap: 10px;
	font: 700 22px/1.2 var(--serif); letter-spacing: .14em;
}
.yz-seal {
	display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 3px;
	background: var(--verm-d); color: var(--paper); font: 700 16px/1 var(--serif); letter-spacing: 0;
	box-shadow: inset 0 0 0 1.5px rgba(242, 235, 222, .25);
}
.yz-sub { margin: 4px 0 0; font-size: 11px; letter-spacing: .32em; color: var(--txt3); }

/* ---------- 纸 ---------- */
.yz-sheet {
	position: relative;
	width: var(--sheet); height: var(--sheet);
	flex: none;
	box-shadow: 0 30px 60px -28px rgba(0, 0, 0, .9), 0 0 0 1px rgba(217, 179, 108, .16);
	background: var(--paper);
	touch-action: pan-y;
	-webkit-user-select: none; user-select: none;
	-webkit-touch-callout: none;
}
.yz-sheet canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.yz-sheet.is-writing, .yz-sheet.is-writing canvas { touch-action: none; cursor: crosshair; }
#cvGuide { mix-blend-mode: multiply; }
.yz-frame { position: absolute; inset: -9px; pointer-events: none; }
.yz-frame i { position: absolute; width: 16px; height: 16px; border: 0 solid var(--gold); opacity: .85; }
/* 刻度：纸边外侧的细刻线，八等分对应米字格 */
.yz-frame::before, .yz-frame::after {
	content: ""; position: absolute; top: 9px; bottom: 8px; width: 5px; opacity: .45;
	background: repeating-linear-gradient(to bottom, var(--gold) 0 1px, transparent 1px calc((100% - 1px) / 8));
	background-size: 100% calc(100% + 1px);
}
.yz-frame::before { left: -1px; }
.yz-frame::after { right: -1px; }
.yz-frame i:nth-child(1) { left: 0; top: 0; border-left-width: 1.5px; border-top-width: 1.5px; }
.yz-frame i:nth-child(2) { right: 0; top: 0; border-right-width: 1.5px; border-top-width: 1.5px; }
.yz-frame i:nth-child(3) { left: 0; bottom: 0; border-left-width: 1.5px; border-bottom-width: 1.5px; }
.yz-frame i:nth-child(4) { right: 0; bottom: 0; border-right-width: 1.5px; border-bottom-width: 1.5px; }

.yz-hud {
	position: absolute; top: -27px; font-size: 10.5px; line-height: 16px; letter-spacing: .14em;
	color: var(--txt3); white-space: nowrap; pointer-events: none;
}
.yz-hud--tl { left: 4px; }
.yz-hud--tr { right: 4px; color: var(--gold); }
.yz-hud--tr b { color: var(--txt); font: 700 12px/1 var(--serif); letter-spacing: .08em; margin-left: 6px; }
.yz-meter {
	position: absolute; left: 4px; bottom: -26px; display: flex; gap: 14px; font-size: 10px; line-height: 16px;
	letter-spacing: .1em; color: var(--txt3); pointer-events: none;
}
.yz-meter span { display: inline-flex; align-items: center; gap: 6px; }
.yz-meter b { display: inline-block; width: 46px; height: 3px; background: var(--line); position: relative; overflow: hidden; }
.yz-meter b i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--gold); transition: width .12s linear; }
.yz-meter b i#mI { background: var(--txt2); }

/* 笔画标签 */
.yz-tags { position: absolute; inset: 0; pointer-events: none; }
.yz-tag {
	position: absolute; transform: translate(-50%, -50%);
	display: inline-flex; align-items: baseline; gap: 6px;
	padding: 3px 9px 4px 7px; white-space: nowrap;
	background: rgba(11, 10, 8, .86); color: var(--txt);
	border: 1px solid rgba(226, 70, 43, .7);
	box-shadow: 0 6px 16px -8px rgba(0, 0, 0, .6);
	opacity: 0; transition: opacity .35s ease;
}
.yz-tag.on { opacity: 1; }
.yz-tag i { font: 500 9.5px/1 var(--mono); color: var(--gold); font-style: normal; letter-spacing: .04em; }
.yz-tag b { font: 700 16px/1 var(--serif); }
.yz-tag span { font-size: 11px; color: var(--txt2); }
.yz-tag.dim { border-color: rgba(217, 179, 108, .45); }

/* 评分徽记 */
.yz-badge {
	position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
	display: inline-flex; align-items: baseline; gap: 8px; padding: 4px 12px 5px;
	background: rgba(11, 10, 8, .86); color: var(--txt); border: 1px solid var(--gold);
	pointer-events: none; animation: yzPop .35s ease both;
}
.yz-badge b { font-size: 22px; line-height: 1; color: var(--gold-l); font-weight: 700; }
.yz-badge span { font: 700 14px/1 var(--serif); letter-spacing: .1em; }
.yz-hint {
	position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); margin: 0;
	max-width: calc(100% - 24px); padding: 4px 10px; text-align: center;
	font-size: 12.5px; line-height: 1.5; color: #3a2a1c; background: rgba(242, 235, 222, .9);
	border: 1px solid rgba(168, 50, 31, .35); pointer-events: none;
}
@keyframes yzPop { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) {
	.yz-badge { animation: none; }
	.yz-tag, .yz-meter b i { transition: none; }
}
