/**
 * TBT Drag & Drop — the playable exercise surface.
 *
 * The design tokens this file consumes are NOT defined here. They come from the
 * shared 'tbt-tokens' handle, which TBT-Hub owns and this plugin declares as a
 * dependency, falling back to assets/vendor/tbt/tbt-tokens.css when Hub is
 * inactive. See that directory's README.txt for why the tokens are a :root
 * default inside a cascade layer rather than a self-referencing var() fallback.
 *
 * The var() calls below deliberately carry no fallback value. 'tbt-tokens' is a
 * hard dependency, so a fallback would hide a broken enqueue instead of
 * surfacing it.
 *
 * Desktop only, by decision: HTML5 drag plus click-to-place, no touch fallback.
 */

/* ---------- Shell ---------- */

.tbtdd-standalone {
	background: var(--tbt-canvas);
}

.tbtdd-standalone__inner {
	width: min(1000px, 100% - 48px);
	margin: 0 auto;
	padding: 32px 0 96px;
}

.tbtdd-exercise {
	width: 100%;
	margin: 0 auto;
	color: var(--tbt-ink);
	font-family: var(--tbt-font-ui);
	font-size: 16px;
	line-height: 1.55;
}

/* Zero-specificity reset so a Divi theme's typography stops at the exercise. */
:where(.tbtdd-exercise), :where(.tbtdd-exercise *), :where(.tbtdd-exercise *::before), :where(.tbtdd-exercise *::after) {
	box-sizing: border-box;
}

:where(.tbtdd-exercise p, .tbtdd-exercise h1, .tbtdd-exercise h2) {
	margin: 0;
	padding: 0;
}

:where(.tbtdd-exercise button) {
	font: inherit;
	color: inherit;
	background: none;
	border: 0;
	cursor: pointer;
}

/* Divi sets display on many elements, which beats [hidden]'s default. */
:where(.tbtdd-exercise) [hidden] {
	display: none !important;
}

.tbtdd-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	white-space: nowrap;
	border: 0;
	clip-path: inset(50%);
}

/* ---------- Hero (Style Book §6B) ---------- */

.tbtdd-hero {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	gap: clamp(20px, 4vw, 52px);
	align-items: center;
	padding: 26px 28px;
	border-radius: var(--tbt-radius-panel);
	/* Blue holds to 65%, white by 95%. The mark sits in the pale end, where the
	   leaves land on TBT blue at the end of their bloom. Style Book §6B still
	   describes the old 135deg blue-to-navy hero; both shipped tools moved to
	   this fade and the shipped version wins. */
	background: linear-gradient(
		92deg,
		var(--tbt-blue) 0%,
		var(--tbt-blue) 65%,
		#FFFFFF 95%
	);
	box-shadow: var(--tbt-shadow-raised);
	color: #FFFFFF;
	overflow: hidden;
}

/* Every piece of copy has to stay left of the 65% stop, or white text lands
   on white. */
.tbtdd-hero__content {
	min-width: 0;
	max-width: 62%;
}

.tbtdd-hero__eyebrow {
	margin: 0 0 6px;
	font-family: var(--tbt-font-ui);
	font-size: 12px;
	font-weight: 700;
	letter-spacing: .08em;
	line-height: 1.3;
	text-transform: uppercase;
	color: #CFE0FB;
}

.tbtdd-hero__title {
	margin: 0;
	color: #FFFFFF;
	font-family: var(--tbt-font-identity);
	font-size: 34px;
	font-weight: 700;
	line-height: 1.1;
	text-transform: uppercase;
}

.tbtdd-hero__support {
	max-width: 60ch;
	margin: 10px 0 0;
	font-family: var(--tbt-font-ui);
	font-size: 16px;
	line-height: 1.5;
	color: #DBE8FC;
}

/* Hub's [tbt_tree] sets its own inline width; this is the PNG fallback. */
.tbtdd-hero .tbt-tree-host {
	justify-self: end;
}

.tbtdd-hero__logo {
	display: block;
	width: clamp(120px, 16vw, 180px);
	max-height: 96px;
	height: auto;
	object-fit: contain;
}

/* ---------- Embedded heading (compact, inside a lesson) ---------- */

.tbtdd-embedded-title {
	margin: 0 0 8px;
	color: var(--tbt-ink);
	font-family: var(--tbt-font-content);
	font-size: 22px;
	font-weight: 700;
	line-height: 1.3;
}

.tbtdd-embedded-instructions {
	margin: 0 0 24px;
	color: var(--tbt-muted);
	font-family: var(--tbt-font-ui);
	font-size: 14px;
}

/* ---------- Token bank ---------- */

.tbtdd-bank {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	/* Deep enough that an emptied bank keeps its shape instead of collapsing
	   and shunting the reading panel up the page mid-exercise. */
	min-height: 78px;
	margin-top: 48px;
	padding: 20px;
	border: 1px solid var(--tbt-border);
	border-radius: var(--tbt-radius-card);
	background: var(--tbt-surface);
	box-shadow: var(--tbt-shadow);
}

.tbtdd-exercise--compact .tbtdd-bank {
	margin-top: 0;
}

/* ---------- Token ----------
   A rectangle with the control radius, not the legacy 999px pill: a token is a
   piece of the text on its way into a sentence, and it has to read like the
   words around it rather than like a chip. */
.tbtdd-token {
	display: inline-flex;
	align-items: center;
	padding: 8px 16px;
	border: 1px solid var(--tbt-border);
	border-radius: var(--tbt-radius-control);
	background: var(--tbt-surface);
	box-shadow: var(--tbt-shadow);
	color: var(--tbt-ink);
	font-family: var(--tbt-font-content);
	font-size: 17px;
	font-weight: 500;
	line-height: 1.3;
	cursor: grab;
	transition: border-color .16s var(--tbt-ease), background-color .16s var(--tbt-ease), box-shadow .16s var(--tbt-ease);
}

.tbtdd-token:hover {
	border-color: var(--tbt-blue);
	background: var(--tbt-selected-bg);
}

.tbtdd-token:active {
	cursor: grabbing;
}

.tbtdd-token:focus-visible {
	border-color: var(--tbt-blue);
	box-shadow: var(--tbt-focus-ring);
	outline: none;
}

.tbtdd-token.is-dragging {
	opacity: .4;
}

/* Picked up by click and waiting for a gap. */
.tbtdd-token.is-picked {
	border-color: var(--tbt-blue);
	background: var(--tbt-selected-bg);
	box-shadow: var(--tbt-focus-ring);
}

.tbtdd-token.is-correct {
	border-color: var(--tbt-success);
	background: var(--tbt-success-bg);
	color: var(--tbt-success);
}

.tbtdd-token.is-wrong {
	border-color: var(--tbt-error);
	background: var(--tbt-error-bg);
	color: var(--tbt-error);
}

/* ---------- Reading panel ---------- */

.tbtdd-reading {
	margin-top: 32px;
	padding: 40px;
	border: 1px solid var(--tbt-border);
	border-radius: var(--tbt-radius-panel);
	background: var(--tbt-surface);
	box-shadow: var(--tbt-shadow);
	color: var(--tbt-ink);
	font-family: var(--tbt-font-content);
	font-size: 18px;
	/* Loose enough that a 44px slot sits inside a line rather than pushing the
	   lines around it apart. */
	line-height: 2.6;
}

/* ---------- Slot ---------- */

.tbtdd-slot {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 130px;
	min-height: 44px;
	margin: 0 4px;
	padding: 2px 6px;
	border: 1px dashed var(--tbt-border);
	border-radius: var(--tbt-radius-control);
	background: var(--tbt-input);
	vertical-align: middle;
	cursor: pointer;
	transition: border-color .16s var(--tbt-ease), background-color .16s var(--tbt-ease), box-shadow .16s var(--tbt-ease);
}

.tbtdd-slot:focus-visible {
	border-color: var(--tbt-blue);
	box-shadow: var(--tbt-focus-ring);
	outline: none;
}

.tbtdd-slot.is-over {
	border-style: solid;
	border-color: var(--tbt-blue);
	background: var(--tbt-selected-bg);
	box-shadow: var(--tbt-focus-ring);
}

.tbtdd-slot.is-filled {
	border-style: solid;
	background: var(--tbt-surface);
}

.tbtdd-slot.is-correct {
	border-style: solid;
	border-color: var(--tbt-success);
	background: var(--tbt-success-bg);
}

.tbtdd-slot.is-wrong {
	border-style: solid;
	border-color: var(--tbt-error);
	background: var(--tbt-error-bg);
}

/* The slot keeps the frame; a token inside it gives up its own, or the two
   borders sit one inside the other. A token in the bank is unchanged. */
.tbtdd-slot .tbtdd-token {
	padding: 6px 12px;
	border-color: transparent;
	background: transparent;
	box-shadow: none;
}

/* After checking, the slot carries the verdict. The token contributes only its
   text colour, which the .is-correct / .is-wrong rules already set. */
.tbtdd-slot .tbtdd-token.is-correct,
.tbtdd-slot .tbtdd-token.is-wrong {
	border-color: transparent;
	background: transparent;
}

/* ---------- Actions ---------- */

.tbtdd-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	align-items: center;
	margin-top: 32px;
}

.tbtdd-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 0 20px;
	border: 1px solid var(--tbt-border);
	border-radius: var(--tbt-radius-control);
	background: var(--tbt-surface);
	color: var(--tbt-blue-dark);
	font-family: var(--tbt-font-ui);
	font-size: 15px;
	font-weight: 600;
	line-height: 1.2;
	/* Sentence case: Show correct and Redo are interface operations beside the
	   one uppercase call to action, not calls to action themselves. */
	text-transform: none;
	white-space: nowrap;
	transition: transform .16s var(--tbt-ease), border-color .16s var(--tbt-ease), background-color .16s var(--tbt-ease), box-shadow .16s var(--tbt-ease);
}

.tbtdd-button:hover {
	border-color: var(--tbt-blue);
	background: var(--tbt-selected-bg);
}

.tbtdd-button:focus-visible {
	border-color: var(--tbt-blue);
	box-shadow: var(--tbt-focus-ring);
	outline: none;
}

/*
 * Filled but sentence case. Redo only appears after Check, and a row of one
 * white button reads as unfinished; uppercase stays reserved for Check, which
 * is the only call to action here.
 */
.tbtdd-button--primary {
	border-color: var(--tbt-blue);
	background: var(--tbt-blue);
	color: #FFFFFF;
	box-shadow: var(--tbt-shadow-action);
}

.tbtdd-button--primary:hover {
	border-color: var(--tbt-blue-dark);
	background: var(--tbt-blue-dark);
	color: #FFFFFF;
	transform: translateY(-1px);
	box-shadow: var(--tbt-shadow-raised);
}

/* The single call to action on the page. */
.tbtdd-button--cta {
	min-height: 48px;
	padding: 0 28px;
	border-color: var(--tbt-blue);
	background: var(--tbt-blue);
	color: #FFFFFF;
	font-weight: 700;
	letter-spacing: .04em;
	text-transform: uppercase;
	box-shadow: var(--tbt-shadow-action);
}

.tbtdd-button--cta:hover {
	border-color: var(--tbt-blue-dark);
	background: var(--tbt-blue-dark);
	color: #FFFFFF;
	transform: translateY(-1px);
	box-shadow: var(--tbt-shadow-raised);
}

.tbtdd-score {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	padding: 8px 18px;
	border-radius: var(--tbt-radius-pill);
	background: var(--tbt-selected-bg);
	color: var(--tbt-blue-dark);
	font-family: var(--tbt-font-ui);
	font-size: 16px;
	font-weight: 700;
}

.tbtdd-score.is-perfect {
	background: var(--tbt-success-bg);
	color: var(--tbt-success);
}

/* Shown to editors in place of an exercise that cannot render. */
.tbtdd-admin-error {
	padding: 12px 16px;
	border-radius: var(--tbt-radius-control);
	background: var(--tbt-error-bg);
	color: var(--tbt-error);
	font-family: var(--tbt-font-ui);
	font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
	.tbtdd-token,
	.tbtdd-slot,
	.tbtdd-button {
		transition: none;
	}

	.tbtdd-button--cta:hover,
	.tbtdd-button--primary:hover {
		transform: none;
	}
}
