/**
 * ThemeFour Shamsi — [shamsi_clock] widget.
 *
 * One widget, four skins: an analog tile face, a flip clock, a minimal glass
 * panel and a ceremonial sunburst frame. All four share the same wrapper, the
 * same data attributes and the same date/meta block, so the shortcode has a
 * single rendering path and a single script.
 *
 * Colors arrive as inline CSS variables from the shortcode and default to the
 * brand palette (turquoise #0e9c9c, saffron #e8a93d). Logical properties are
 * used throughout so the widget stays correct in both RTL and LTR contexts,
 * and every animation is disabled under prefers-reduced-motion.
 */

.tfk-clock {
	--tfk-accent: #0e9c9c;
	--tfk-gold: #e8a93d;
	--tfk-radius: 22px;

	/* Dark is the default surface; .tfk-theme-light overrides these four. */
	--tfk-surface: #0f1b2e;
	--tfk-surface-2: #16263f;
	--tfk-ink: #ffffff;
	--tfk-muted: rgba(255, 255, 255, 0.62);
	--tfk-line: rgba(255, 255, 255, 0.16);

	box-sizing: border-box;
	inline-size: 100%;
	max-inline-size: 420px;
	margin-inline: auto;
	font-family: inherit;
	line-height: 1.6;
	color: var(--tfk-ink);
	direction: rtl;

	/* The widget must react to the column it is dropped into, not to the
	   viewport: sidebars and Elementor columns are narrow on wide screens. */
	container-type: inline-size;
	container-name: tfk;
}

.tfk-clock *,
.tfk-clock *::before,
.tfk-clock *::after {
	box-sizing: border-box;
}

.tfk-clock.tfk-theme-light {
	--tfk-surface: #ffffff;
	--tfk-surface-2: #f4f8f8;
	--tfk-ink: #16242c;
	--tfk-muted: rgba(22, 36, 44, 0.62);
	--tfk-line: rgba(22, 36, 44, 0.12);
}

/* ---------- Shared shell ---------- */
.tfk-body {
	position: relative;
	overflow: hidden;
	padding: 30px 24px 26px;
	border-radius: var(--tfk-radius);
	background: linear-gradient(160deg, var(--tfk-surface) 0%, var(--tfk-surface-2) 100%);
	border: 1px solid var(--tfk-line);
	box-shadow: 0 20px 45px -22px rgba(7, 64, 63, 0.55);
	text-align: center;
}

/* ---------- Shared date / meta block ---------- */
.tfk-meta {
	position: relative;
	z-index: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 3px;
	margin-block-start: 18px;
}

.tfk-date {
	font-size: 1.05em;
	font-weight: 700;
	letter-spacing: 0.01em;
}

.tfk-weekday {
	font-size: 0.82em;
	font-weight: 600;
	color: var(--tfk-accent);
}

.tfk-theme-dark .tfk-weekday {
	color: color-mix(in srgb, var(--tfk-accent) 55%, #ffffff);
}

.tfk-greg,
.tfk-hijri {
	font-size: 0.78em;
	color: var(--tfk-muted);
}

/* Each meta line is its own paragraph, and each decides its own direction.
 *
 * The Gregorian line was pinned to `direction: ltr`, which reads as a sensible
 * default only while the month is a Latin word. It is not: the month name comes
 * from WordPress's locale, so on a Persian site the line is "۱۳ آگوست ۲۰۲۶",
 * with an Arabic-script run in the middle. Under a left-to-right paragraph the
 * bidirectional algorithm keeps that run and the number after it together and
 * lays them out right to left, which put the year in front of the month and
 * left the day stranded at the far edge. The line came out as
 * "آگوست ۲۰۲۶ ۱۳".
 *
 * `plaintext` takes the direction from the first strong character of the line
 * itself, so a Persian month gives a right-to-left line and an English one
 * gives a left-to-right line, with no locale test anywhere. It is applied to
 * all four lines rather than only the one that was reported, because the Jalali
 * and weekday lines have exactly the same shape and would fail the same way the
 * moment the widget sits in a left-to-right container. */
.tfk-date,
.tfk-weekday,
.tfk-greg,
.tfk-hijri {
	unicode-bidi: plaintext;
}

.tfk-caption {
	margin-block-start: 12px;
	font-size: 0.76em;
	color: var(--tfk-muted);
	text-align: center;
}

/* Skins that draw the time graphically still carry it as text for screen
   readers. Clipped rather than display:none, which would remove it from the
   accessibility tree along with the pixels. */
.tfk-sr-only {
	position: absolute;
	inline-size: 1px;
	block-size: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/* Clock digits never reflow: tabular figures keep the width constant so the
   card does not twitch once per second. */
.tfk-time,
.tfk-flip-face {
	font-variant-numeric: tabular-nums;
}

/* The seconds hand, the seconds card and the AM/PM marker are always in the
   markup and hidden here instead of being omitted. That is what lets the
   control panel's builder toggle them live, and it costs three empty elements. */
.tfk-clock[data-seconds="0"] .tfk-ss,
.tfk-clock[data-seconds="0"] .tfk-only-seconds,
.tfk-clock[data-hour12="0"] .tfk-ampm {
	display: none;
}

/* ================= Skin: analog ================= */
.tfk-face {
	position: relative;
	inline-size: 230px;
	block-size: 230px;
	max-inline-size: 100%;
	aspect-ratio: 1;
	margin-inline: auto;
	border-radius: 50%;
	border: 2px solid var(--tfk-gold);
	/* A size container so the numeral ring can be placed in cqmin units and
	   scale with the face instead of hard-coded pixel coordinates. */
	container-type: size;
	container-name: tfkface;
	background:
		conic-gradient(from 0deg,
			color-mix(in srgb, var(--tfk-gold) 16%, transparent) 0 8.3333%,
			transparent 8.3333% 16.6666%);
	box-shadow:
		inset 0 0 0 8px color-mix(in srgb, var(--tfk-accent) 22%, transparent),
		0 0 34px color-mix(in srgb, var(--tfk-accent) 28%, transparent);
}

/* Hour numerals are placed by rotation rather than by hard-coded offsets, so
   the face scales with its container without recomputing any coordinates. */
/* Deliberately physical (top/left) rather than logical: a clock face is a
   round dial, not a text flow. Logical offsets would mirror the numeral ring
   and the hands inside a dir="rtl" container and put 3 o'clock on the left. */
.tfk-num {
	position: absolute;
	top: 50%;
	left: 50%;
	inline-size: 22px;
	block-size: 22px;
	margin: -11px 0 0 -11px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.8em;
	font-weight: 700;
	color: color-mix(in srgb, var(--tfk-gold) 78%, #ffffff);
	transform:
		rotate(calc(var(--tfk-i) * 30deg))
		translateY(-41cqmin)
		rotate(calc(var(--tfk-i) * -30deg));
}

.tfk-theme-light .tfk-num {
	color: color-mix(in srgb, var(--tfk-gold) 70%, #000000);
}

.tfk-hand {
	position: absolute;
	left: 50%;
	bottom: 50%;
	transform-origin: bottom center;
	border-radius: 6px;
	background: var(--tfk-ink);
	/* Rotation is written as a CSS variable by the script, so one custom
	   property write per tick replaces rebuilding the whole transform. */
	transform: translateX(-50%) rotate(var(--tfk-deg, 0deg));
}

.tfk-hh {
	inline-size: 5px;
	block-size: 27%;
	background: var(--tfk-gold);
}

.tfk-mm {
	inline-size: 3.5px;
	block-size: 37%;
}

.tfk-ss {
	inline-size: 2px;
	block-size: 42%;
	background: color-mix(in srgb, var(--tfk-accent) 65%, #ff7a59);
	transition: transform 0.12s cubic-bezier(0.4, 2.1, 0.6, 1);
}

.tfk-hub {
	position: absolute;
	top: 50%;
	left: 50%;
	inline-size: 12px;
	block-size: 12px;
	margin: -6px 0 0 -6px;
	border-radius: 50%;
	background: var(--tfk-gold);
}

/* ================= Skin: flip ================= */
.tfk-skin-flip .tfk-body {
	background: linear-gradient(160deg, #fffdf8 0%, #f1e7d6 100%);
	color: #241c15;
	border-color: rgba(36, 28, 21, 0.1);
}

.tfk-skin-flip .tfk-weekday {
	color: color-mix(in srgb, var(--tfk-accent) 82%, #000000);
}

.tfk-skin-flip .tfk-greg,
.tfk-skin-flip .tfk-hijri,
.tfk-skin-flip .tfk-caption {
	color: rgba(36, 28, 21, 0.6);
}

.tfk-flip-row {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 8px;
	direction: ltr;
}

.tfk-flip-card {
	position: relative;
	inline-size: 60px;
	block-size: 76px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 11px;
	background: linear-gradient(180deg, #1d3050 0%, #14223a 100%);
	color: #fff;
	font-size: 1.9em;
	font-weight: 800;
	box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
}

/* The hairline across the middle is what reads as "a card that flips". */
.tfk-flip-card::after {
	content: "";
	position: absolute;
	inset-inline: 0;
	inset-block-start: 50%;
	block-size: 1px;
	background: rgba(0, 0, 0, 0.4);
}

/* Added by the script only on the digit that actually changed, so the other
   two cards never repaint. */
.tfk-flip-card.is-flipping {
	animation: tfk-flip 0.42s ease;
}

@keyframes tfk-flip {
	0% { transform: perspective(320px) rotateX(0deg); }
	45% { transform: perspective(320px) rotateX(-78deg); }
	100% { transform: perspective(320px) rotateX(0deg); }
}

.tfk-flip-colon {
	font-size: 1.4em;
	font-weight: 800;
	opacity: 0.45;
	color: #14223a;
}

.tfk-skin-flip .tfk-divider {
	inline-size: 62px;
	block-size: 3px;
	margin: 16px auto 0;
	border-radius: 3px;
	background: var(--tfk-gold);
}

.tfk-skin-flip .tfk-meta {
	margin-block-start: 12px;
}

/* ================= Skin: glass ================= */
.tfk-skin-glass .tfk-body {
	padding-block: 44px;
	background: linear-gradient(160deg,
		color-mix(in srgb, var(--tfk-surface) 92%, var(--tfk-accent)) 0%,
		var(--tfk-surface-2) 100%);
}

/* The frosted plate. backdrop-filter is progressive: without support the
   translucent background alone still reads as a glass panel. */
.tfk-glass-plate {
	position: relative;
	z-index: 1;
	padding: 28px 20px;
	border-radius: calc(var(--tfk-radius) - 6px);
	border: 1px solid var(--tfk-line);
	background: color-mix(in srgb, var(--tfk-ink) 7%, transparent);
	backdrop-filter: blur(14px);
}

/* The AM/PM marker and the digits share one baseline row, so the marker never
   drops onto a line of its own when the container narrows. */
.tfk-bigtime {
	display: flex;
	align-items: baseline;
	justify-content: center;
	gap: 0.4em;
}

.tfk-skin-glass .tfk-time {
	font-size: 2.9em;
	font-weight: 800;
	letter-spacing: 0.04em;
	direction: ltr;
}

.tfk-ampm {
	font-size: 1em;
	font-weight: 700;
	color: var(--tfk-gold);
}

.tfk-thin {
	inline-size: 38px;
	block-size: 2px;
	margin: 18px auto 0;
	background: var(--tfk-line);
}

/* ================= Skin: sunburst ================= */
.tfk-skin-sunburst .tfk-body {
	padding-block-start: 48px;
	background:
		radial-gradient(circle at 50% 18%, color-mix(in srgb, var(--tfk-gold) 26%, transparent), transparent 62%),
		linear-gradient(160deg, #241c15 0%, var(--tfk-surface) 100%);
	border-color: color-mix(in srgb, var(--tfk-gold) 30%, transparent);
	color: #fff;
}

.tfk-sunburst {
	position: absolute;
	top: -90px;
	left: 50%;
	inline-size: 290px;
	block-size: 290px;
	margin-left: -145px;
	border-radius: 50%;
	pointer-events: none;
	background: repeating-conic-gradient(
		color-mix(in srgb, var(--tfk-gold) 16%, transparent) 0deg 4deg,
		transparent 4deg 12deg);
	animation: tfk-spin 60s linear infinite;
}

@keyframes tfk-spin {
	to { transform: rotate(360deg); }
}

.tfk-skin-sunburst .tfk-time {
	position: relative;
	z-index: 1;
	display: block;
	font-size: 2.5em;
	font-weight: 800;
	letter-spacing: 0.08em;
	color: color-mix(in srgb, var(--tfk-gold) 55%, #ffffff);
	direction: ltr;
}

.tfk-ornament {
	position: relative;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	margin-block-start: 16px;
	color: var(--tfk-gold);
}

.tfk-ornament i {
	inline-size: 36px;
	block-size: 1px;
	background: currentColor;
	opacity: 0.6;
}

/* ---------- Fallback for engines without color-mix() ---------- */
@supports not (background: color-mix(in srgb, red 10%, white)) {
	.tfk-face {
		background: transparent;
		box-shadow: inset 0 0 0 8px rgba(14, 156, 156, 0.22);
	}

	.tfk-num {
		color: var(--tfk-gold);
	}

	.tfk-glass-plate {
		background: rgba(255, 255, 255, 0.08);
	}

	.tfk-sunburst {
		background: repeating-conic-gradient(rgba(232, 169, 61, 0.16) 0deg 4deg, transparent 4deg 12deg);
	}
}

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
	.tfk-sunburst {
		animation: none;
	}

	.tfk-flip-card.is-flipping {
		animation: none;
	}

	.tfk-ss {
		transition: none;
	}
}

/* ---------- Narrow containers ---------- */
@container tfk (max-width: 340px) {
	.tfk-body { padding: 22px 16px 20px; }
	.tfk-face { inline-size: 178px; block-size: 178px; }
	.tfk-flip-card { inline-size: 48px; block-size: 62px; font-size: 1.5em; }
	.tfk-skin-glass .tfk-time { font-size: 2.2em; }
	.tfk-skin-sunburst .tfk-time { font-size: 1.9em; }
	.tfk-sunburst { inline-size: 220px; block-size: 220px; margin-left: -110px; }
}

/* Fallback for browsers without container queries. */
@supports not (container-type: inline-size) {
	@media (max-width: 340px) {
		.tfk-body { padding: 22px 16px 20px; }
		.tfk-face { inline-size: 178px; block-size: 178px; }
		.tfk-flip-card { inline-size: 48px; block-size: 62px; font-size: 1.5em; }
		.tfk-skin-glass .tfk-time { font-size: 2.2em; }
		.tfk-skin-sunburst .tfk-time { font-size: 1.9em; }
	}
}

/* Without container-size support the numeral ring loses its cqmin radius, so
   fall back to a fixed one that matches the default 230px face. */
@supports not (container-type: size) {
	.tfk-num {
		transform:
			rotate(calc(var(--tfk-i) * 30deg))
			translateY(-94px)
			rotate(calc(var(--tfk-i) * -30deg));
	}
}
