/*
 * Elwood Braid Customizer
 *
 * Everything is scoped under .ebc-* so the theme's header, navigation and
 * footer are untouched. The app has no height cap and no internal scroll
 * container: it sits in the page flow and the page scrolls normally.
 */

.ebc-app,
.ebc-app *,
.ebc-modal-overlay,
.ebc-modal-overlay * {
	box-sizing: border-box;
}

.ebc-app {
	--ebc-bg: #0f1115;
	--ebc-panel: #15181f;
	--ebc-sunken: #1c202a;
	--ebc-line: #282f3d;
	--ebc-line-soft: #222731;
	--ebc-text: #f3f4f6;
	--ebc-muted: #9ca3af;
	--ebc-accent: #2563eb;
	--ebc-accent-hover: #1d4ed8;

	/*
	 * The cord stands vertically, so the preview only needs a narrow column.
	 * Everything else goes to the control panel, which is the part with real
	 * content in it.
	 */
	display: grid;
	grid-template-columns: clamp(300px, 26vw, 420px) minmax(0, 1fr);
	align-items: stretch;

	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 15px;
	line-height: 1.5;
	color: var(--ebc-text);
	background: var(--ebc-bg);

	width: 100%;
	margin: 0 0 32px;
	border: 1px solid var(--ebc-line-soft);
	border-radius: 14px;
	overflow: hidden;
}

/*
 * Full bleed: escape whatever container the theme wraps the page content in.
 *
 * --ebc-sbw is the scrollbar width, set by the script. Without it, 50vw
 * overshoots the content area by the scrollbar and the page gains a spurious
 * horizontal scrollbar; with it the breakout lands exactly on the edges.
 */
.ebc-app--full {
	width: auto;
	max-width: none;
	margin-left: calc(50% - 50vw + (var(--ebc-sbw, 0px) / 2));
	margin-right: calc(50% - 50vw + (var(--ebc-sbw, 0px) / 2));
	border-radius: 0;
	border-left: 0;
	border-right: 0;
}

/* ---------------------------------------------------------------
   Viewport
   --------------------------------------------------------------- */

.ebc-viewport {
	position: relative;
	min-width: 0;
	display: flex;
	flex-direction: column;
	background: radial-gradient(circle at center, #1a1d24 0%, #0f1115 100%);
}

.ebc-view {
	flex: 0 0 auto;
	width: 100%;
	/* A canvas needs an explicit height; it just must not be a viewport lock. */
	height: clamp(400px, 58vh, 660px);
	cursor: grab;
	touch-action: pan-y;
}

.ebc-view.is-dragging {
	cursor: grabbing;
}

.ebc-view canvas {
	display: block;
	max-width: 100%;
}

/*
 * In flow, not floating. A vertical cord runs through the middle of the pane,
 * so an overlaid caption sits right on top of the model.
 */
.ebc-viewport__header {
	flex: 0 0 auto;
	padding: 22px 20px 12px;
}

.ebc-viewport__title {
	margin: 0;
	padding: 0;
	font-size: 22px;
	font-weight: 700;
	letter-spacing: -0.02em;
	line-height: 1.2;
	color: #fff;
}

.ebc-viewport__sub {
	margin: 4px 0 0;
	padding: 0;
	font-size: 13px;
	color: var(--ebc-muted);
}



/*
 * The pattern map sits below the cord in normal flow rather than floating over
 * it — in a narrow column an overlay would cover most of the preview.
 */
.ebc-map {
	flex: 0 0 auto;
	margin: 0 20px 20px;
	padding: 12px;
	background: rgba(21, 23, 30, 0.85);
	border: 1px solid rgba(255, 255, 255, 0.08);
	border-radius: 12px;
	box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.ebc-map__label {
	margin-bottom: 8px;
	font-size: 10px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--ebc-muted);
}

#ebc-flat-canvas {
	display: block;
	width: 100%;
	height: auto;
	border: 1px solid rgba(255, 255, 255, 0.05);
	border-radius: 6px;
}

/* ---------------------------------------------------------------
   Control panel — flows with the page, never scrolls internally
   --------------------------------------------------------------- */

.ebc-controls {
	min-width: 0;
	padding: 28px;
	background: var(--ebc-panel);
	border-left: 1px solid var(--ebc-line-soft);

	/*
	 * The panel sizes its own contents off its own width, not the window's.
	 * That is what lets the matrix go to a single 16-wide row whenever there
	 * is room, whether the layout is side-by-side or stacked.
	 */
	container-type: inline-size;
	container-name: ebc-panel;
}

.ebc-product-title {
	margin: 0 0 4px;
	padding: 0;
	font-size: 24px;
	font-weight: 700;
	line-height: 1.25;
	letter-spacing: -0.02em;
	color: #fff;
}

.ebc-pricing {
	display: flex;
	align-items: baseline;
	flex-wrap: wrap;
	gap: 8px;
	margin: 12px 0 24px;
}

.ebc-price {
	font-size: 28px;
	font-weight: 700;
	color: #fff;
}

.ebc-price__note {
	font-size: 13px;
	color: var(--ebc-muted);
}

.ebc-price__total {
	font-size: 15px;
	font-weight: 600;
	color: #93c5fd;
}

.ebc-price__total:empty {
	display: none;
}

/* Form */

.ebc-field {
	margin-bottom: 22px;
}

.ebc-label {
	display: block;
	margin-bottom: 8px;
	font-size: 12px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--ebc-muted);
}

.ebc-label span {
	margin-left: 2px;
	color: #ef4444;
}

.ebc-hint {
	margin: -2px 0 10px;
	font-size: 12px;
	color: #6b7280;
}

.ebc-hint--spool {
	margin: 8px 0 0;
	line-height: 1.45;
}

/* Two fields side by side once the panel is wide enough to hold them. */
.ebc-grid-2 {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 0 20px;
}

@container ebc-panel (min-width: 520px) {
	.ebc-grid-2 {
		grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
	}
}

/* Quantity */

.ebc-app .ebc-qty {
	display: block;
	width: 100%;
	max-width: 160px;
	height: auto;
	margin: 0;
	padding: 12px;
	font-family: inherit;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.4;
	color: var(--ebc-text);
	background: var(--ebc-sunken);
	border: 1px solid var(--ebc-line);
	border-radius: 8px;
	outline: none;
}

.ebc-app .ebc-qty:focus-visible {
	border-color: #6b7280;
	box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.35);
}

.ebc-app .ebc-select {
	display: block;
	width: 100%;
	max-width: 100%;
	height: auto;
	margin: 0;
	padding: 12px;
	font-family: inherit;
	font-size: 14px;
	font-weight: 500;
	line-height: 1.4;
	color: var(--ebc-text);
	background: var(--ebc-sunken);
	border: 1px solid var(--ebc-line);
	border-radius: 8px;
	outline: none;
	cursor: pointer;
	appearance: none;
	background-image: linear-gradient(45deg, transparent 50%, #9ca3af 50%), linear-gradient(135deg, #9ca3af 50%, transparent 50%);
	background-position: calc(100% - 18px) calc(50% + 2px), calc(100% - 13px) calc(50% + 2px);
	background-size: 5px 5px, 5px 5px;
	background-repeat: no-repeat;
}

.ebc-app .ebc-select:focus-visible {
	border-color: #6b7280;
	box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.35);
}

.ebc-app .ebc-select option {
	color: #111;
	background: #fff;
}

/* Strand rows */

.ebc-strand-box {
	margin-bottom: 12px;
	padding: 12px;
	background: var(--ebc-sunken);
	border: 1px solid var(--ebc-line);
	border-radius: 10px;
}

.ebc-strand-box__meta {
	display: flex;
	justify-content: space-between;
	margin-bottom: 8px;
	font-size: 11px;
	font-weight: 600;
	color: var(--ebc-muted);
}

.ebc-bobbins {
	display: grid;
	grid-template-columns: repeat(8, minmax(0, 1fr));
	gap: 4px;
}

/*
 * A wide panel fits all 16 strands on one line, which halves the height of
 * the matrix and is closer to how the row is actually loaded.
 */
@container ebc-panel (min-width: 560px) {
	.ebc-bobbins {
		grid-template-columns: repeat(16, minmax(0, 1fr));
	}
}

.ebc-app .ebc-bobbin {
	display: flex;
	align-items: center;
	justify-content: center;
	aspect-ratio: 1;
	width: 100%;
	min-width: 0;
	padding: 0;
	font-family: inherit;
	font-size: 10px;
	font-weight: 700;
	line-height: 1;
	border: 1px solid rgba(255, 255, 255, 0.1);
	border-radius: 6px;
	cursor: pointer;
	user-select: none;
	transition: transform 0.1s ease, border-color 0.1s ease;
}

.ebc-app .ebc-bobbin:hover,
.ebc-app .ebc-bobbin:focus-visible {
	z-index: 2;
	border-color: #fff;
	transform: scale(1.08);
	outline: none;
}

/* Buttons */

.ebc-actions {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
	margin-bottom: 12px;
}

.ebc-app .ebc-btn-ghost {
	padding: 10px;
	font-family: inherit;
	font-size: 11px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.02em;
	color: var(--ebc-muted);
	background: transparent;
	border: 1px solid var(--ebc-line);
	border-radius: 8px;
	cursor: pointer;
	transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.ebc-app .ebc-btn-ghost:hover,
.ebc-app .ebc-btn-ghost:focus-visible {
	color: #fff;
	border-color: #4b5563;
	background: rgba(255, 255, 255, 0.02);
	outline: none;
}

.ebc-app .ebc-btn-cart {
	display: block;
	width: 100%;
	padding: 15px;
	font-family: inherit;
	font-size: 14px;
	font-weight: 700;
	color: #fff;
	background: var(--ebc-accent);
	border: none;
	border-radius: 8px;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.15s ease;
}

.ebc-app .ebc-btn-cart:hover:not(:disabled) {
	background: var(--ebc-accent-hover);
	transform: translateY(-1px);
}

.ebc-app .ebc-btn-cart:disabled {
	opacity: 0.6;
	cursor: default;
	transform: none;
}

/* Feedback */

.ebc-feedback {
	margin-top: 12px;
	font-size: 13px;
}

.ebc-feedback:empty {
	margin-top: 0;
}

.ebc-feedback--error {
	color: #fca5a5;
}

.ebc-feedback--success {
	color: #86efac;
}

.ebc-feedback a {
	color: #93c5fd;
	text-decoration: underline;
}

.ebc-feedback a + a {
	margin-left: 12px;
}

/* Info block */

.ebc-info {
	margin-top: 28px;
	padding-top: 20px;
	border-top: 1px solid var(--ebc-line-soft);
}

.ebc-info__title {
	margin: 0 0 8px;
	padding: 0;
	font-size: 15px;
	font-weight: 600;
	color: #fff;
}

.ebc-info__p {
	margin: 0 0 12px;
	font-size: 13px;
	line-height: 1.55;
	color: var(--ebc-muted);
}

.ebc-app .ebc-steps {
	margin: 0 0 16px;
	padding: 0;
	list-style: none;
}

.ebc-app .ebc-steps li {
	position: relative;
	margin-bottom: 10px;
	padding-left: 20px;
	font-size: 13px;
	line-height: 1.45;
	color: var(--ebc-muted);
}

.ebc-app .ebc-steps li::before {
	content: "\2022";
	position: absolute;
	left: 0;
	font-weight: 700;
	color: #3b82f6;
}

.ebc-app .ebc-steps li strong {
	color: #e5e7eb;
}

/* Use the extra width instead of making the panel taller. */
@container ebc-panel (min-width: 620px) {
	.ebc-app .ebc-steps {
		columns: 2;
		column-gap: 28px;
	}

	.ebc-app .ebc-steps li {
		break-inside: avoid;
	}

	.ebc-actions {
		max-width: 420px;
	}

	.ebc-app .ebc-btn-cart {
		max-width: 420px;
	}
}

.ebc-legal {
	margin: 0;
	padding-top: 12px;
	font-size: 11px;
	font-style: italic;
	line-height: 1.45;
	color: #6b7280;
	border-top: 1px solid var(--ebc-line-soft);
}

/* ---------------------------------------------------------------
   Colour picker modal
   --------------------------------------------------------------- */

.ebc-modal-overlay {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
	background: rgba(7, 8, 10, 0.6);
	backdrop-filter: blur(8px);

	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	color: #f3f4f6;
}

.ebc-modal-overlay[hidden] {
	display: none;
}

.ebc-modal {
	display: flex;
	flex-direction: column;
	width: min(92vw, 560px);
	max-height: min(80vh, 700px);
	padding: 24px;
	background: #15181f;
	border: 1px solid #282f3d;
	border-radius: 16px;
	box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.ebc-modal h3 {
	margin: 0 0 2px;
	padding: 0;
	font-size: 18px;
	font-weight: 700;
	color: #fff;
}

.ebc-modal__sub {
	margin-bottom: 16px;
	font-size: 12px;
	color: #9ca3af;
}

/* The one place an internal scroller is right: a modal with 70 swatches. */
.ebc-modal__scroll {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	padding-right: 6px;
}

.ebc-library-group {
	margin-bottom: 18px;
}

.ebc-library-group__title {
	margin-bottom: 8px;
	padding-bottom: 4px;
	font-size: 11px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: #6b7280;
	border-bottom: 1px solid #222731;
}

.ebc-swatches {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
	gap: 8px;
}

.ebc-modal .ebc-swatch {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 6px;
	font-family: inherit;
	background: #1c202a;
	border: 1px solid #282f3d;
	border-radius: 8px;
	cursor: pointer;
	transition: transform 0.15s ease, border-color 0.15s ease;
}

.ebc-modal .ebc-swatch:hover,
.ebc-modal .ebc-swatch:focus-visible {
	border-color: #fff;
	transform: translateY(-2px);
	outline: none;
}

.ebc-swatch__circle {
	width: 32px;
	height: 32px;
	margin-bottom: 4px;
	border: 1px solid rgba(255, 255, 255, 0.1);
	border-radius: 50%;
}

.ebc-swatch__name {
	width: 100%;
	overflow: hidden;
	font-size: 10px;
	line-height: 1.3;
	text-align: center;
	text-overflow: ellipsis;
	white-space: nowrap;
	color: #e5e7eb;
}

.ebc-modal .ebc-modal__close {
	flex: 0 0 auto;
	width: 100%;
	margin-top: 16px;
	padding: 12px;
	font-family: inherit;
	font-size: 12px;
	font-weight: 600;
	color: #9ca3af;
	background: #1c202a;
	border: 1px solid #282f3d;
	border-radius: 8px;
	cursor: pointer;
}

.ebc-modal .ebc-modal__close:hover {
	color: #fff;
	background: #242a38;
}

/* Scrollbar (modal only) */

.ebc-modal__scroll::-webkit-scrollbar {
	width: 6px;
}

.ebc-modal__scroll::-webkit-scrollbar-track {
	background: transparent;
}

.ebc-modal__scroll::-webkit-scrollbar-thumb {
	background: #282f3d;
	border-radius: 3px;
}

/* ---------------------------------------------------------------
   Admin-only notice
   --------------------------------------------------------------- */

.ebc-notice--admin {
	padding: 16px 20px;
	margin: 0 0 24px;
	font-size: 14px;
	color: #78350f;
	background: #fef3c7;
	border-left: 4px solid #d97706;
	border-radius: 4px;
}

/* ---------------------------------------------------------------
   Responsive
   --------------------------------------------------------------- */

@media (min-width: 1500px) {
	.ebc-controls {
		padding: 36px;
	}
}

@media (max-width: 1100px) {
	.ebc-controls {
		padding: 22px;
	}
}

/* Below this the two-column split stops working, so stack it. */
@media (max-width: 900px) {
	.ebc-app {
		grid-template-columns: minmax(0, 1fr);
	}

	.ebc-view {
		height: clamp(360px, 54vh, 520px);
	}

	.ebc-map {
		margin: 0 16px 16px;
	}

	.ebc-controls {
		padding: 24px 20px;
		border-left: none;
		border-top: 1px solid var(--ebc-line-soft);
	}

	.ebc-viewport__header {
		padding: 18px 16px 10px;
	}

	.ebc-viewport__title {
		font-size: 19px;
	}
}

@media (max-width: 560px) {
	.ebc-app {
		margin-bottom: 20px;
	}

	.ebc-controls {
		padding: 20px 16px;
	}

	.ebc-product-title {
		font-size: 20px;
	}

	.ebc-price {
		font-size: 24px;
	}

	.ebc-map {
		margin: 0 12px 12px;
	}

	.ebc-view {
		height: clamp(320px, 46vh, 420px);
	}

	.ebc-app .ebc-qty {
		max-width: none;
	}

	.ebc-app .ebc-bobbin {
		font-size: 11px;
		border-radius: 5px;
	}

	.ebc-actions {
		grid-template-columns: 1fr;
	}

	.ebc-app .ebc-btn-cart {
		padding: 16px;
		font-size: 15px;
	}

	.ebc-modal {
		width: 100%;
		max-height: 88vh;
		padding: 18px 16px;
		border-radius: 14px;
	}

	.ebc-swatches {
		grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
	}
}

/* Very narrow phones: one bobbin row of eight is still readable. */
@media (max-width: 360px) {
	.ebc-controls {
		padding: 16px 12px;
	}

	.ebc-swatches {
		grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
	}
}

@media (prefers-reduced-motion: reduce) {
	.ebc-app *,
	.ebc-modal-overlay * {
		transition: none !important;
	}
}
