:root {
	color-scheme: light;
	--paper: #f3efe5;
	--paper-deep: #e7e0d1;
	--surface: #fbf9f3;
	--surface-strong: #ffffff;
	--ink: #24211d;
	--ink-soft: #686159;
	--line: #d8d0c1;
	--line-strong: #aaa092;
	--red: #8f2f2c;
	--red-dark: #6f211f;
	--red-soft: #f2dfda;
	--saffron: #b76f25;
	--saffron-soft: #f2e3c8;
	--blue: #315f70;
	--blue-soft: #dce9eb;
	--focus: #166a88;
	--shadow: 0 18px 50px rgba(52, 42, 30, .08);
	--shadow-small: 0 7px 20px rgba(52, 42, 30, .07);
	--radius: 6px;
	--radius-large: 12px;
	--serif: Iowan Old Style, Baskerville, 'Songti SC', SimSun, Georgia, serif;
	--sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans Tibetan', 'Microsoft YaHei', sans-serif;
}

:root[data-theme='dark'] {
	color-scheme: dark;
	--paper: #191816;
	--paper-deep: #22201d;
	--surface: #24221f;
	--surface-strong: #2b2925;
	--ink: #f2ede3;
	--ink-soft: #bdb5aa;
	--line: #48433c;
	--line-strong: #746c62;
	--red: #d77a72;
	--red-dark: #ef9a90;
	--red-soft: #4b2926;
	--saffron: #dda25d;
	--saffron-soft: #493720;
	--blue: #82b9c7;
	--blue-soft: #203e46;
	--focus: #71c6df;
	--shadow: 0 18px 50px rgba(0, 0, 0, .25);
	--shadow-small: 0 7px 20px rgba(0, 0, 0, .2);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
	margin: 0;
	background: var(--paper);
	color: var(--ink);
	font-family: var(--sans);
	line-height: 1.55;
	min-height: 100vh;
	overflow-x: hidden;
	overflow-x: clip;
}

button, select, input { font: inherit; }
button, a, select, input { -webkit-tap-highlight-color: transparent; }
button, select { color: inherit; }
a { color: var(--red); text-underline-offset: 3px; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible {
	outline: 3px solid var(--focus);
	outline-offset: 3px;
}

.skip-link {
	position: fixed;
	top: 8px;
	left: 8px;
	padding: 10px 14px;
	background: var(--ink);
	color: var(--paper);
	z-index: 2000;
	transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }
.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.site-shell { width: min(1240px, calc(100% - 40px)); margin: 0 auto; }
.site-header {
	min-height: 82px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 24px;
	border-bottom: 1px solid var(--line);
}
.brand {
	display: inline-flex;
	align-items: center;
	gap: 12px;
	color: inherit;
	text-decoration: none;
}
.brand-mark {
	width: 44px;
	height: 44px;
	display: grid;
	place-items: center;
	border: 1px solid var(--red);
	color: var(--red);
	font-family: var(--serif);
	font-size: 1.15rem;
}
.brand strong, .brand small { display: block; }
.brand strong { font-family: var(--serif); font-size: 1.05rem; letter-spacing: .04em; }
.brand small { color: var(--ink-soft); font-size: .73rem; text-transform: uppercase; letter-spacing: .12em; }
.header-actions, .button-group { display: flex; align-items: center; gap: 9px; }
.header-actions { flex-wrap: nowrap; }
.button-group { flex-wrap: wrap; }
.quiet-select, .text-button, .icon-button, .secondary-button, .primary-button, .step-button, .inline-link {
	min-height: 44px;
	border: 1px solid var(--line);
	background: var(--surface);
	border-radius: var(--radius);
	transition: border-color .16s ease, background-color .16s ease, color .16s ease, transform .16s ease;
}
.quiet-select { padding: 0 34px 0 12px; }
.text-button, .secondary-button, .primary-button { padding: 10px 15px; font-weight: 650; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.icon-button { width: 44px; padding: 0; display: grid; place-items: center; font-size: 1.25rem; }
.primary-button { background: var(--red); color: #fff; border-color: var(--red); }
.primary-button:hover { background: var(--red-dark); border-color: var(--red-dark); }
.secondary-button:hover, .text-button:hover, .icon-button:hover, .step-button:hover { border-color: var(--red); color: var(--red); background: var(--surface-strong); }

main { padding: 42px 0 28px; }
.hero {
	display: grid;
	grid-template-columns: minmax(0, 1.45fr) minmax(290px, .75fr);
	column-gap: clamp(18px, 3vw, 36px);
	row-gap: 16px;
	align-items: stretch;
	margin-bottom: 44px;
}
.hero-copy {
	grid-column: 1 / -1;
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 20px;
	padding-bottom: 12px;
	border-bottom: 1px solid var(--line);
}
.eyebrow, .section-kicker, .period-title p {
	margin: 0 0 9px;
	color: var(--red);
	font-size: .75rem;
	font-weight: 800;
	letter-spacing: .13em;
	text-transform: uppercase;
}
.hero h1 {
	margin: 0;
	font-family: var(--serif);
	font-size: clamp(1.65rem, 2.6vw, 2.4rem);
	line-height: 1.1;
	font-weight: 600;
	letter-spacing: -.02em;
}
.hero-copy .eyebrow { margin: 0; color: var(--ink-soft); white-space: nowrap; }
.beta-badge {
	display: inline-block;
	vertical-align: top;
	margin: 6px 0 0 7px;
	padding: 3px 7px;
	border: 1px solid var(--red);
	font: 700 .7rem/1 var(--sans);
	letter-spacing: .08em;
	color: var(--red);
}
.basis-button {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: 44px;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	text-align: left;
	color: var(--ink-soft);
}
.basis-button span { font-size: .78rem; }
.basis-button strong { color: var(--ink); font-size: .82rem; font-weight: 650; }
.basis-button::after { content: '›'; color: var(--red); font-size: 1.05rem; }
.basis-button:hover strong { color: var(--red); }
.hero-context {
	grid-column: 1 / -1;
	display: flex;
	align-items: center;
	gap: 18px;
	min-height: 44px;
}
.date-notice {
	margin: 0;
	max-width: 680px;
	padding-left: 12px;
	border-left: 2px solid var(--saffron);
	color: var(--ink-soft);
	font-size: .8rem;
}
.today-card, .next-card {
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius-large);
	padding: 24px;
	box-shadow: var(--shadow-small);
}
.today-card { position: relative; overflow: hidden; padding: clamp(26px, 3.5vw, 44px); }
.today-card::after {
	content: '';
	position: absolute;
	top: 0;
	right: 0;
	width: 5px;
	height: 100%;
	background: var(--red);
}
.gregorian-date { margin: 14px 0 0; color: var(--ink-soft); font-size: 1rem; }
.tibetan-date {
	margin: 0;
	color: var(--red);
	font-family: var(--serif);
	font-size: clamp(2.2rem, 4.7vw, 4.3rem);
	font-weight: 600;
	letter-spacing: -.035em;
	line-height: 1.12;
}
.selected-event { margin: 13px 0 0; font-weight: 700; }
.selected-multiplier { margin: 3px 0 0; color: var(--ink-soft); font-size: .88rem; }
.next-card { background: var(--ink); color: #f3efe5; }
:root[data-theme='dark'] .next-card { background: #11110f; }
.next-card .section-kicker { color: #e7a098; }
.next-card h2 { margin: 0 0 5px; font-family: var(--serif); font-size: 1.3rem; font-weight: 560; }
.next-card p { margin: 2px 0; }
.next-card .muted { color: #c7beb2; font-size: .86rem; }
.inline-link { min-height: 44px; margin-top: 8px; padding: 5px 0; border: 0; color: #f5d2cc; background: transparent; font-weight: 700; }
.skeleton-line { width: 70%; height: 16px; background: color-mix(in srgb, currentColor 14%, transparent); }

.calendar-workspace {
	scroll-margin-top: 18px;
	background: var(--surface-strong);
	border: 1px solid var(--line);
	border-radius: var(--radius-large);
	box-shadow: var(--shadow);
	overflow: hidden;
}
.calendar-toolbar {
	min-height: 96px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 20px;
	padding: 20px 24px;
	border-bottom: 1px solid var(--line);
}
.period-controls { display: flex; align-items: center; gap: 8px; }
.period-title { min-width: clamp(150px, 20vw, 245px); text-align: center; }
.period-title p { margin-bottom: 2px; }
.period-title h2 { margin: 0; font-family: var(--serif); font-size: clamp(1.35rem, 2vw, 1.9rem); font-weight: 560; }
.step-button { width: 44px; height: 44px; padding: 0; font-size: 1.15rem; }
.secondary-step { color: var(--ink-soft); font-size: .75rem; }
.calendar-scroll { overflow-x: auto; }
.calendar-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.calendar-table th {
	height: 42px;
	padding: 8px 5px;
	border-bottom: 1px solid var(--line-strong);
	color: var(--ink-soft);
	font-size: .72rem;
	font-weight: 750;
	letter-spacing: .06em;
	text-transform: uppercase;
}
.calendar-table td {
	position: relative;
	height: 116px;
	padding: 11px 9px;
	border-right: 1px solid var(--line);
	border-bottom: 1px solid var(--line);
	vertical-align: top;
	background: var(--surface-strong);
	cursor: pointer;
	transition: background-color .14s ease;
}
.calendar-table td:last-child { border-right: 0; }
.calendar-table tr:last-child td { border-bottom: 0; }
.calendar-table td[role='button']:hover { background: var(--paper); }
.calendar-table td[role='button']:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; z-index: 2; }
.calendar-table td.empty-cell { cursor: default; background: color-mix(in srgb, var(--paper) 68%, var(--surface)); }
.calendar-table td.out-of-range { cursor: not-allowed; color: var(--ink-soft); opacity: .42; background: var(--paper); }
.calendar-table td.today { box-shadow: inset 0 0 0 2px var(--red); }
.calendar-table td.today::after {
	content: '';
	position: absolute;
	top: 0;
	right: 0;
	border-top: 14px solid var(--red);
	border-left: 14px solid transparent;
}
.day-number { display: block; font: 620 1.12rem/1 var(--serif); }
.lunar-date { display: block; margin-top: 8px; color: var(--red); font-size: .86rem; font-weight: 720; }
.cell-event {
	margin-top: 12px;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
	font-size: .72rem;
	line-height: 1.3;
	color: var(--ink-soft);
}
.cell-markers { display: flex; gap: 4px; position: absolute; left: 9px; bottom: 8px; }
.cell-markers i, .legend-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.festival-marker, .festival-dot { background: var(--red); }
.multiplier-marker, .multiplier-dot { background: var(--saffron); }
.eclipse-marker, .eclipse-dot { background: var(--blue); }
.calendar-legend { display: flex; gap: 20px; margin: 0; padding: 13px 24px; border-top: 1px solid var(--line); color: var(--ink-soft); font-size: .75rem; }
.calendar-legend span { display: flex; align-items: center; gap: 7px; }

.tools { margin-top: 30px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-large); overflow: hidden; }
.tool-tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tool-tab {
	position: relative;
	min-height: 54px;
	padding: 0 22px;
	border: 0;
	background: transparent;
	font-weight: 700;
	color: var(--ink-soft);
	white-space: nowrap;
}
.tool-tab::after { content: ''; position: absolute; left: 20px; right: 20px; bottom: -1px; height: 3px; background: transparent; }
.tool-tab.active { color: var(--red); }
.tool-tab.active::after { background: var(--red); }
.tool-panel { padding: 24px; }
.panel-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 18px; }
.panel-toolbar select, .reverse-form select {
	min-height: 44px;
	padding: 8px 34px 8px 12px;
	border: 1px solid var(--line-strong);
	background: var(--surface-strong);
	border-radius: var(--radius);
}
.panel-summary, .panel-intro { margin: 0 0 16px; color: var(--ink-soft); }
.event-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.event-row button {
	width: 100%;
	min-height: 78px;
	display: grid;
	grid-template-columns: minmax(105px, .32fr) minmax(0, 1fr) 20px;
	align-items: center;
	gap: 18px;
	padding: 13px 5px;
	border: 0;
	border-bottom: 1px solid var(--line);
	background: transparent;
	text-align: left;
}
.event-row button:hover { background: color-mix(in srgb, var(--paper) 60%, transparent); }
.event-row time strong, .event-row time span, .event-copy > strong, .event-copy > span { display: block; }
.event-row time span { color: var(--ink-soft); font-size: .76rem; }
.event-copy > strong { font-family: var(--serif); font-size: 1.02rem; }
.type-pill { display: inline-block; margin: 5px 6px 0 0; padding: 2px 7px; border-radius: 999px; font-style: normal; font-size: .66rem; font-weight: 700; }
.type-pill.festival { color: var(--red); background: var(--red-soft); }
.type-pill.multiplier { color: var(--saffron); background: var(--saffron-soft); }
.type-pill.eclipse { color: var(--blue); background: var(--blue-soft); }
.empty-state { padding: 28px 0; color: var(--ink-soft); }

.reverse-form { display: grid; grid-template-columns: repeat(3, minmax(120px, 1fr)) auto auto; gap: 14px; align-items: end; }
.reverse-form label:not(.check-field) { display: grid; gap: 6px; font-size: .78rem; font-weight: 700; color: var(--ink-soft); }
.check-field { min-height: 44px; display: flex; align-items: center; gap: 8px; }
.check-field input { width: 18px; height: 18px; accent-color: var(--red); }
.reverse-results { margin-top: 22px; }
.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.result-grid button { min-height: 78px; padding: 13px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-strong); text-align: left; }
.result-grid button span { display: block; margin-top: 3px; color: var(--ink-soft); font-size: .8rem; }
.result-grid button i { display: inline-block; margin-top: 7px; color: var(--red); font-size: .7rem; }
#aboutPanel h2 { margin-top: 0; font: 560 1.6rem/1.2 var(--serif); }
#aboutPanel p { max-width: 850px; }
.source-links { margin-top: 18px; }

.install-card { margin-top: 30px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 24px; border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }
.install-card p { margin: 0; }
.install-card .section-kicker { margin-bottom: 5px; }
footer { padding: 27px 0 44px; color: var(--ink-soft); font-size: .75rem; }
.noscript { padding: 18px; border: 1px solid var(--red); }

#detailMask {
	position: fixed;
	inset: 0;
	display: none;
	background: rgba(15, 13, 11, .56);
	backdrop-filter: blur(3px);
	z-index: 900;
}
#detailDialog {
	position: fixed;
	top: 50%;
	left: 50%;
	width: min(560px, calc(100% - 32px));
	max-height: min(82vh, 760px);
	overflow-y: auto;
	padding: 27px;
	transform: translate(-50%, -48%);
	opacity: 0;
	display: none;
	background: var(--surface-strong);
	border: 1px solid var(--line);
	border-radius: var(--radius-large);
	box-shadow: 0 28px 80px rgba(0, 0, 0, .3);
	z-index: 901;
	transition: opacity .16s ease, transform .16s ease;
}
#detailDialog.active { opacity: 1; transform: translate(-50%, -50%); }
#detailDialog .dialog-header { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 5px; }
#detailDialog h2 { margin: 0 0 20px; padding-right: 38px; font: 560 clamp(1.5rem, 4vw, 2.1rem)/1.15 var(--serif); }
.detail-section { padding: 16px 0; border-top: 1px solid var(--line); }
.detail-section h3 { margin: 0 0 8px; color: var(--ink-soft); font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; }
.detail-section p { margin: 4px 0; }
.detail-tibetan, .detail-event { font-family: var(--serif); font-size: 1.15rem; font-weight: 600; }
.accent-section { border-top-color: var(--red); }
.accent-section .detail-event { color: var(--red); }
.eclipse-section { border-top-color: var(--blue); }
.status-row { display: flex; gap: 7px; margin-top: 9px; }
.status-row span { padding: 3px 8px; border: 1px solid var(--saffron); color: var(--saffron); font-size: .7rem; }
.time-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.time-grid div { padding: 10px; background: var(--blue-soft); }
.time-grid dt { color: var(--blue); font-size: .7rem; font-weight: 700; }
.time-grid dd { margin: 2px 0 0; font-size: .82rem; }
.fine-print, .source-section { color: var(--ink-soft); font-size: .78rem; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 9px; padding-top: 18px; border-top: 1px solid var(--line); }

.settings-dialog {
	width: min(540px, calc(100% - 32px));
	padding: 25px;
	border: 1px solid var(--line);
	border-radius: var(--radius-large);
	background: var(--surface-strong);
	color: var(--ink);
	box-shadow: 0 28px 80px rgba(0, 0, 0, .3);
}
.settings-dialog::backdrop { background: rgba(15, 13, 11, .56); backdrop-filter: blur(3px); }
.dialog-title-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.dialog-title-row h2 { margin: 0; font: 560 1.5rem var(--serif); }
.settings-dialog fieldset { display: grid; gap: 10px; margin: 22px 0; padding: 0; border: 0; }
.choice-card { display: flex; gap: 12px; padding: 15px; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.choice-card:has(input:checked) { border-color: var(--red); background: var(--red-soft); }
.choice-card input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--red); }
.choice-card strong, .choice-card small { display: block; }
.choice-card small { margin-top: 3px; color: var(--ink-soft); }
.dialog-done { width: 100%; }

.toast {
	position: fixed;
	left: 50%;
	bottom: 22px;
	max-width: calc(100% - 32px);
	padding: 10px 15px;
	transform: translate(-50%, 12px);
	opacity: 0;
	background: var(--ink);
	color: var(--paper);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	z-index: 2200;
	transition: opacity .18s ease, transform .18s ease;
}
.toast.active { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
	.hero { grid-template-columns: 1fr 1fr; }
	.reverse-form { grid-template-columns: repeat(2, 1fr); }
	.reverse-form .primary-button { align-self: end; }
}

@media (max-width: 720px) {
	.site-shell { width: min(calc(100% - 32px), 620px); }
	.site-header { min-height: 70px; }
	.brand small, .header-actions .text-button { display: none; }
	.header-actions { gap: 6px; }
	.quiet-select { max-width: 106px; }
	main { padding-top: 26px; }
	.hero { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 24px; }
	.hero-copy { grid-column: auto; padding: 0 0 10px; }
	.hero h1 { font-size: 1.65rem; }
	.hero-context { grid-column: auto; align-items: flex-start; flex-direction: column; gap: 0; }
	.today-card, .next-card { padding: 19px; }
	.tibetan-date { font-size: clamp(2.25rem, 10vw, 3.5rem); }
	.calendar-toolbar { min-height: auto; padding: 14px; flex-wrap: wrap; }
	.period-controls { width: 100%; justify-content: space-between; }
	.period-title { min-width: 0; flex: 1; }
	.calendar-toolbar > .primary-button { width: 100%; }
	.secondary-step { display: none; }
	.calendar-table td { height: 76px; padding: 8px 5px; }
	.calendar-table th { font-size: .65rem; }
	.day-number { font-size: 1rem; }
	.lunar-date { margin-top: 7px; font-size: .7rem; }
	.cell-event { display: none; }
	.cell-markers { left: 5px; bottom: 6px; }
	.calendar-legend { padding: 11px 14px; gap: 14px; overflow-x: auto; white-space: nowrap; }
	.tool-panel { padding: 18px 14px; }
	.tool-tab { padding: 0 15px; }
	.tool-tab::after { left: 14px; right: 14px; }
	.panel-toolbar { align-items: stretch; flex-direction: column; }
	.panel-toolbar select { width: 100%; }
	.button-group > * { flex: 1 1 auto; }
	.event-row button { grid-template-columns: 92px minmax(0, 1fr) 15px; gap: 10px; }
	.event-copy > strong { font-size: .93rem; }
	.reverse-form { grid-template-columns: 1fr 1fr; }
	.reverse-form .primary-button { grid-column: 1 / 3; }
	.result-grid { grid-template-columns: 1fr; }
	.install-card { align-items: stretch; flex-direction: column; }
	#detailDialog.bottom-sheet {
		top: auto;
		left: 0;
		right: 0;
		bottom: 0;
		width: 100%;
		max-height: 88vh;
		border-radius: 14px 14px 0 0;
		transform: translateY(100%);
	}
	#detailDialog.bottom-sheet.active { transform: translateY(0); }
	.dialog-footer { position: sticky; bottom: -27px; margin: 0 -27px -27px; padding: 14px 27px calc(14px + env(safe-area-inset-bottom)); background: var(--surface-strong); }
}

@media (max-width: 430px) {
	.brand-mark { width: 40px; height: 40px; }
	.brand strong { font-size: .92rem; }
	.hero h1 { font-size: 1.5rem; }
	.hero-copy .eyebrow { font-size: .62rem; letter-spacing: .08em; }
	.calendar-table td { height: 70px; }
	.calendar-table th { font-size: .56rem; letter-spacing: 0; }
	.lunar-date { font-size: .64rem; }
	.calendar-legend { font-size: .68rem; }
	.event-row button { grid-template-columns: 78px minmax(0, 1fr) 12px; }
	.reverse-form { grid-template-columns: 1fr; }
	.reverse-form .primary-button { grid-column: auto; }
	.time-grid { grid-template-columns: 1fr; }
	.dialog-footer { flex-direction: column; }
}

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

@media print {
	.site-header, .hero-copy, .next-card, .tools, .install-card, footer, .calendar-toolbar button, .calendar-legend { display: none !important; }
	body, .site-shell, .calendar-workspace { background: white; color: black; width: 100%; box-shadow: none; border: 0; }
	main { padding: 0; }
	.hero { display: block; margin: 0 0 12px; }
	.today-card { box-shadow: none; border: 1px solid #999; }
	.calendar-table td { height: 90px; }
}
