/*
 * Schedule grid.
 *
 * Every length here is design pixels times --u, the site's own fluid unit: the section the
 * shortcode sits in declares --u as 100cqi / 1440, so the grid grows and shrinks with the page
 * exactly like every other section. Without it the calendar stayed 1320px wide while the rest
 * of the site stretched, and the mismatch shows the moment the window is not 1440.
 *
 * The design numbers themselves still change per breakpoint (the room column is 145 units on
 * desktop, 179 on tablet, 125 on mobile) — that is the designer's decision, not scaling.
 * Below the desktop width the seven days no longer fit, so the grid scrolls sideways with the
 * room column pinned by position:sticky.
 *
 * --u falls back to 1px, so the grid still renders if the shortcode is used outside a section.
 */

.tsch {
	/*
	 * The site's unit, but never below 0.8: at 1440 the tile caption is already 10px, so a
	 * viewport of 993 would shrink it to 6.9px and nobody can read that. Past the floor the
	 * grid stops shrinking and starts scrolling instead — the same answer the design gives
	 * for tablets.
	 */
	--tsch-u: max(0.8px, var(--u, 1px));

	--tsch-rooms-width: calc(145 * var(--tsch-u));
	--tsch-rooms-gutter: calc(20 * var(--tsch-u));
	--tsch-day-width: calc(165 * var(--tsch-u));
	--tsch-day-gap: 0px;
	--tsch-week-gap: calc(20 * var(--tsch-u));
	--tsch-head-gap: calc(10 * var(--tsch-u));
	--tsch-card-height: calc(194 * var(--tsch-u));
	--tsch-head-height: calc(34 * var(--tsch-u));
	--tsch-lot-width: calc(52 * var(--tsch-u));
	--tsch-lot-height: calc(22 * var(--tsch-u));
	--tsch-row-gap: calc(5 * var(--tsch-u));
	--tsch-hairline: calc(1 * var(--tsch-u));

	--tsch-paper: #fffdf7;
	--tsch-ink: #3c3c3c;
	--tsch-red: #7e2422;
	--tsch-red-dark: #551414;
	--tsch-star: #eaeaea;
	--tsch-month: #d9d9d9;

	position: relative;
	color: var(--tsch-paper);
}

/* ------------------------------------------------------------------ top bar ---- */

.tsch__bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: calc(20 * var(--tsch-u));
	margin-bottom: calc(20 * var(--tsch-u));
}

.tsch__picker {
	position: relative;
	display: flex;
	align-items: center;
	gap: calc(10 * var(--tsch-u));
	width: calc(176 * var(--tsch-u));
	min-height: calc(41 * var(--tsch-u));
	padding: calc(10 * var(--tsch-u)) calc(12 * var(--tsch-u));
	border: var(--tsch-hairline) solid var(--tsch-red);
	border-radius: calc(10 * var(--tsch-u));
	background: #000;
}

.tsch__picker-icon {
	display: flex;
	flex: 0 0 calc(18 * var(--tsch-u));
	width: calc(18 * var(--tsch-u));
	color: var(--tsch-red);
}

.tsch__picker-icon svg {
	width: 100%;
	height: auto;
	fill: currentColor;
}

.tsch__picker select {
	width: 100%;
	padding: 0 calc(14 * var(--tsch-u)) 0 0;
	border: 0;
	background: transparent;
	color: var(--tsch-paper);
	font-size: calc(14 * var(--tsch-u));
	font-weight: 500;
	letter-spacing: -0.02em;
	line-height: 1.5;
	appearance: none;
	cursor: pointer;
}

.tsch__picker select option {
	color: #111;
}

/* The triangle of the design, drawn rather than shipped as an asset. */
.tsch__picker::after {
	position: absolute;
	right: calc(12 * var(--tsch-u));
	width: calc(10 * var(--tsch-u));
	height: calc(8 * var(--tsch-u));
	background: var(--tsch-red);
	clip-path: polygon(0 0, 100% 0, 50% 100%);
	content: "";
	pointer-events: none;
}

.tsch__nav {
	display: flex;
	align-items: center;
	gap: calc(14 * var(--tsch-u));
}

.tsch__month {
	color: var(--tsch-month);
	font-family: var(--tsch-font-display, "Carol Gothic", serif);
	font-size: calc(32 * var(--tsch-u));
	line-height: 0.76;
	text-transform: lowercase;
}

.tsch__arrow {
	display: block;
	width: calc(12 * var(--tsch-u));
	height: calc(14 * var(--tsch-u));
	background: var(--tsch-month);
	clip-path: polygon(100% 0, 100% 100%, 0 50%);
	text-decoration: none;
}

.tsch__arrow--next {
	clip-path: polygon(0 0, 0 100%, 100% 50%);
}

.tsch__arrow.is-off {
	opacity: 0.3;
}

/* -------------------------------------------------------------------- grid ---- */

.tsch__scroll {
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-behavior: smooth;
	scroll-snap-type: x proximity;
	/* The sticky room column travels with the content, so the scroll padding matches it
	   instead of the row carrying a left inset of its own. */
	scroll-padding-left: calc(var(--tsch-rooms-width) + var(--tsch-rooms-gutter));
}

/*
 * The room column carries its own gutter inside the track, so the pill keeps the width the
 * design gives it and the first day still starts one gutter further right.
 *
 * Row rhythm: the grid gap is half the distance between weeks and every week cell adds the
 * other half as a margin. That way the header sits one head gap above the first week, exactly
 * as the design draws it, without a negative margin.
 */
.tsch__grid {
	display: grid;
	grid-template-columns: calc(var(--tsch-rooms-width) + var(--tsch-rooms-gutter)) repeat(7, var(--tsch-day-width));
	column-gap: var(--tsch-day-gap);
	row-gap: calc(var(--tsch-week-gap) / 2);
	width: max-content;
}

.tsch__cell,
.tsch__rooms {
	margin-bottom: calc(var(--tsch-week-gap) / 2);
}

.tsch__grid > .tsch__corner,
.tsch__grid > .tsch__rooms {
	position: sticky;
	left: 0;
	z-index: 2;
	padding-right: var(--tsch-rooms-gutter);
}

/*
 * The pinned column needs an opaque backing, or day cards show through the gaps between room
 * pills as they scroll past. But an opaque strip also hides the page's own background art, so
 * it is only painted while the grid actually scrolls — the script sets the class.
 */
.tsch.is-scrollable .tsch__corner,
.tsch.is-scrollable .tsch__rooms {
	background: var(--tsch-page-background, #141313);
}

.tsch__corner,
.tsch__dayhead {
	display: flex;
	align-items: center;
	min-height: var(--tsch-head-height);
	margin-bottom: calc(var(--tsch-head-gap) - var(--tsch-week-gap) / 2);
}

.tsch__tag {
	display: flex;
	flex: 1 1 auto;
	align-items: center;
	justify-content: center;
	min-height: var(--tsch-head-height);
	padding: calc(8 * var(--tsch-u)) calc(20 * var(--tsch-u));
	border-radius: 500px;
	font-size: calc(14 * var(--tsch-u));
	font-weight: 500;
	letter-spacing: -0.02em;
	line-height: calc(18 * var(--tsch-u));
	text-align: center;
}

.tsch__tag--room {
	padding: calc(8 * var(--tsch-u)) calc(40 * var(--tsch-u));
	background: var(--tsch-red-dark);
}

.tsch__tag--weekday {
	background: var(--tsch-ink);
}

.tsch__dayhead {
	width: var(--tsch-day-width);
}

/* Room labels line up with the tile rows of every card, so they share the row rhythm. */
.tsch__rooms {
	display: flex;
	flex-direction: column;
	gap: var(--tsch-row-gap);
	padding-top: calc(32 * var(--tsch-u));
}

.tsch__room {
	display: flex;
	align-items: center;
	justify-content: center;
	height: var(--tsch-lot-height);
	padding: 0 calc(12 * var(--tsch-u));
	overflow: hidden;
	border-radius: 500px;
	background: var(--tsch-red-dark);
	font-size: calc(12 * var(--tsch-u));
	font-weight: 500;
	letter-spacing: -0.02em;
	line-height: 1.3;
	text-align: center;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.tsch__cell {
	width: var(--tsch-day-width);
	scroll-snap-align: start;
}

/*
 * Fixed height, not min-height: the design's 194 units are the row rhythm of the whole
 * calendar, and the date and band captions are positioned rather than stacked so the first
 * tile row always starts exactly 32 units down whatever the captions do.
 */
.tsch__card {
	position: relative;
	box-sizing: border-box;
	height: var(--tsch-card-height);
	border: var(--tsch-hairline) solid var(--tsch-ink);
	border-radius: calc(10 * var(--tsch-u));
	background-color: var(--tsch-paper);
	/* Relative to this file, so the texture travels with the plugin and needs no upload. */
	background-image: var(--tsch-texture, url("paper.png"));
	background-position: center;
	background-size: cover;
	color: var(--tsch-ink);
}

.tsch__date {
	position: absolute;
	top: calc(5 * var(--tsch-u));
	left: calc(8 * var(--tsch-u));
	font-size: calc(14 * var(--tsch-u));
	font-weight: 500;
	letter-spacing: -0.02em;
	line-height: 1.2;
}

.tsch__bands {
	/* Pushed right of the date so the two never collide, then spread over the rest of the
	   card: the design places these captions by eye, not above the tile columns. */
	position: absolute;
	top: calc(15 * var(--tsch-u));
	right: calc(2 * var(--tsch-u));
	left: calc(20 * var(--tsch-u));
	display: grid;
	grid-template-columns: repeat(3, 1fr);
}

.tsch__band {
	font-size: calc(12 * var(--tsch-u));
	font-weight: 500;
	letter-spacing: -0.02em;
	line-height: 1.2;
	text-align: center;
	text-transform: lowercase;
}

/* Rows are rooms, columns are bands: the same order the room labels are printed in. */
.tsch__slots {
	display: grid;
	grid-template-columns: repeat(3, var(--tsch-lot-width));
	row-gap: var(--tsch-row-gap);
	/* One unit less than the design offset on every side: the card border is inside the box. */
	margin: calc(31 * var(--tsch-u)) calc(4 * var(--tsch-u)) calc(4 * var(--tsch-u));
}

.tsch__lot {
	display: flex;
	align-items: center;
	justify-content: center;
	height: var(--tsch-lot-height);
	border-radius: 500px;
	font-size: calc(10 * var(--tsch-u));
	font-weight: 500;
	letter-spacing: -0.02em;
	line-height: 1.2;
	text-align: center;
	text-decoration: none;
}

.tsch__lot.is-free {
	background: var(--tsch-red);
}

/* The free-slot star is drawn here, not shipped as inline SVG in every one of the ~500 tiles. */
.tsch__lot.is-free::after {
	width: calc(10 * var(--tsch-u));
	height: calc(10 * var(--tsch-u));
	background: var(--tsch-star);
	mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'><path d='M5 0c.4 2.5 2.1 4.2 5 4.6v.8C7.1 5.8 5.4 7.5 5 10c-.4-2.5-2.1-4.2-5-4.6v-.8C2.9 4.2 4.6 2.5 5 0z'/></svg>") center / contain no-repeat;
	content: "";
}

.tsch__lot.is-busy {
	border: var(--tsch-hairline) solid var(--tsch-ink);
	color: var(--tsch-ink);
}

a.tsch__lot.is-busy:hover,
a.tsch__lot.is-busy:focus-visible {
	background: var(--tsch-ink);
	color: var(--tsch-paper);
}

.tsch__lot.is-closed {
	background: var(--tsch-ink);
}

/* A slot that has already happened stays visible but stops inviting a click. Grey rather
   than merely faint: a washed-out red still reads as an offer. */
.tsch__lot.is-past {
	opacity: 0.4;
	filter: grayscale(1);
}

.tsch__cell.is-empty {
	height: var(--tsch-card-height);
}

/* -------------------------------------------------------------------- dots ---- */

.tsch__dots {
	display: none;
	gap: calc(8 * var(--tsch-u));
	justify-content: center;
	margin-top: calc(16 * var(--tsch-u));
}

.tsch__dot {
	width: calc(8 * var(--tsch-u));
	height: calc(8 * var(--tsch-u));
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--tsch-ink);
	cursor: pointer;
}

.tsch__dot.is-current {
	background: var(--tsch-paper);
}

/* ------------------------------------------------------------- breakpoints ---- */

/*
 * Only the design numbers change here. The unit does not: the site redefines --u at the same
 * two widths, so the grid keeps scaling with the page inside each band.
 */
@media (max-width: 991px) {
	.tsch {
		--tsch-rooms-width: calc(179 * var(--tsch-u));
		--tsch-day-gap: calc(20 * var(--tsch-u));
	}
}

@media (max-width: 600px) {
	.tsch {
		--tsch-rooms-width: calc(125 * var(--tsch-u));
		--tsch-rooms-gutter: calc(10 * var(--tsch-u));
		--tsch-day-gap: calc(10 * var(--tsch-u));
		--tsch-week-gap: calc(10 * var(--tsch-u));
		--tsch-head-gap: calc(12 * var(--tsch-u));
		--tsch-head-height: calc(32 * var(--tsch-u));
	}

	.tsch__bar {
		flex-wrap: wrap;
	}

	.tsch__picker {
		width: 100%;
		justify-content: center;
	}

	.tsch__picker select {
		flex: 0 1 auto;
		text-align: center;
	}

	.tsch__nav {
		flex: 1 1 100%;
		justify-content: space-between;
	}

	.tsch__scroll {
		scroll-snap-type: x mandatory;
	}

	.tsch__tag {
		padding: calc(8 * var(--tsch-u)) calc(12 * var(--tsch-u));
		line-height: calc(16 * var(--tsch-u));
	}

	.tsch__tag--room {
		padding: calc(8 * var(--tsch-u)) calc(16 * var(--tsch-u));
	}

	.tsch__dots {
		display: flex;
	}
}
