/*
 * Senior Word Search — front-end styles (v1.1 redesign).
 *
 * Design direction — "the puzzle-book page": a warm paper surface with deep
 * slate ink and a friendly serif display face, the grid presented as a raised
 * puzzle board, amber for in-progress selection and deep teal for found words.
 * Found words also get a strikethrough and a check, so state is never colour
 * alone. The signature element is the oversized Easy/Medium/Hard switcher with
 * ● / ●● / ●●● dots — the dot count itself encodes the difficulty.
 *
 * Accessibility floor: 48px+ targets, visible focus rings, keyboard operable,
 * reduced motion respected, responsive to small screens, print-friendly.
 *
 * Colours and base size are injected as CSS custom properties on .sws-game.
 */

.sws-game {
	/* Fallbacks; overridden by inline custom properties from settings. */
	--sws-font-size: 22px;
	--sws-color-text: #2b3445;
	--sws-color-cell: #ffffff;
	--sws-color-grid: #ded6c6;
	--sws-color-sel: #ffc552;
	--sws-color-found: #2e7d6b;

	/* Fixed design tokens. */
	--sws-paper: #f8f4eb;
	--sws-paper-2: #efe9dc;
	--sws-ink-soft: #5b6472;
	--sws-denim: #3a5a83;
	--sws-denim-dark: #2c4666;
	--sws-cell: calc(var(--sws-font-size) * 2);
	--sws-gap: 4px;
	--sws-grid-pad: 10px;
	--sws-grid-border: 3px;
	--sws-display: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, Georgia, serif;
	--sws-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

	box-sizing: border-box;
	max-width: 100%;
	margin: 1.5rem auto;
	padding: clamp(1.1rem, 2.5vw, 2rem);
	background: var(--sws-paper);
	border: 1px solid var(--sws-paper-2);
	border-radius: 18px;
	box-shadow: 0 1px 2px rgba(43, 52, 69, 0.06);
	color: var(--sws-color-text);
	font-family: var(--sws-body);
	line-height: 1.45;
}

.sws-game *,
.sws-game *::before,
.sws-game *::after {
	box-sizing: border-box;
}

/* --------------------------------------------------------------------- */
/* Header */
/* --------------------------------------------------------------------- */

.sws-eyebrow {
	margin: 0 0 0.2rem;
	font-size: 0.85rem;
	font-weight: 700;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--sws-ink-soft);
}

.sws-title {
	margin: 0 0 0.35rem;
	font-family: var(--sws-display);
	font-size: clamp(1.7rem, 1.2rem + 2vw, 2.4rem);
	font-weight: 700;
	letter-spacing: 0.005em;
	color: var(--sws-color-text);
}

.sws-instructions {
	margin: 0 0 1.1rem;
	max-width: 46em;
	font-size: 1.1rem;
	color: var(--sws-ink-soft);
}

/* --------------------------------------------------------------------- */
/* Level switcher — the signature element. Dots encode the difficulty.    */
/* --------------------------------------------------------------------- */

.sws-levels {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin-bottom: 1rem;
}

.sws-level {
	appearance: none;
	display: inline-flex;
	flex-direction: column;
	align-items: center;
	gap: 0.1rem;
	min-width: 108px;
	min-height: 56px;
	padding: 0.5rem 1.3rem;
	font-family: inherit;
	font-size: 1.15rem;
	font-weight: 700;
	color: var(--sws-color-text);
	background: #ffffff;
	border: 2px solid var(--sws-paper-2);
	border-radius: 14px;
	cursor: pointer;
}

.sws-level:hover {
	border-color: var(--sws-denim);
}

.sws-level .sws-level-dots {
	font-size: 0.7rem;
	letter-spacing: 0.25em;
	color: var(--sws-ink-soft);
}

.sws-level.is-active {
	color: #ffffff;
	background: var(--sws-denim);
	border-color: var(--sws-denim);
}

.sws-level.is-active .sws-level-dots {
	color: rgba(255, 255, 255, 0.85);
}

.sws-level:disabled {
	opacity: 0.6;
	cursor: default;
}

/* --------------------------------------------------------------------- */
/* Toolbar */
/* --------------------------------------------------------------------- */

.sws-toolbar {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	align-items: center;
	margin-bottom: 1.25rem;
	padding-bottom: 1.25rem;
	border-bottom: 1px solid var(--sws-paper-2);
}

.sws-theme-label {
	font-size: 1.05rem;
	font-weight: 700;
}

.sws-theme-select {
	min-height: 48px;
	padding: 0.4rem 0.75rem;
	font-family: inherit;
	font-size: 1.05rem;
	color: var(--sws-color-text);
	background: #ffffff;
	border: 2px solid var(--sws-paper-2);
	border-radius: 10px;
	max-width: 100%;
}

.sws-btn {
	appearance: none;
	min-height: 48px;
	padding: 0.55rem 1.2rem;
	font-family: inherit;
	font-size: 1.05rem;
	font-weight: 600;
	color: #ffffff;
	background: var(--sws-denim);
	border: 2px solid transparent;
	border-radius: 999px;
	cursor: pointer;
}

.sws-btn:hover {
	background: var(--sws-denim-dark);
}

.sws-btn:disabled {
	opacity: 0.6;
	cursor: default;
}

.sws-btn-quiet {
	color: var(--sws-color-text);
	background: #ffffff;
	border-color: var(--sws-paper-2);
}

.sws-btn-quiet:hover {
	background: var(--sws-paper-2);
}

.sws-text-size {
	display: inline-flex;
	gap: 0.35rem;
	margin-left: auto;
}

.sws-text-size .sws-btn {
	min-width: 48px;
	padding: 0.55rem 0.6rem;
}

.sws-timer {
	margin-left: 0.5rem;
	padding: 0.45rem 0.9rem;
	font-variant-numeric: tabular-nums;
	font-size: 1.1rem;
	font-weight: 700;
	background: #ffffff;
	border: 2px solid var(--sws-paper-2);
	border-radius: 999px;
}

/* --------------------------------------------------------------------- */
/* Layout: grid + sidebar */
/* --------------------------------------------------------------------- */

.sws-body {
	display: flex;
	flex-wrap: wrap;
	gap: clamp(1.25rem, 3vw, 2.25rem);
	align-items: flex-start;
}

.sws-grid-area {
	position: relative;
	max-width: 100%;
}

.sws-grid-wrap {
	max-width: 100%;
	overflow-x: auto; /* Only when zoomed past the fitted size, or on dense grids. */
	-webkit-overflow-scrolling: touch;
	padding: 4px;
}

/* Right-edge fade signals there is more puzzle to the side. */
.sws-grid-area.is-scrollable::after {
	content: "";
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	width: 34px;
	background: linear-gradient(to left, var(--sws-paper), rgba(248, 244, 235, 0));
	pointer-events: none;
	border-radius: 0 14px 14px 0;
}

.sws-scroll-hint {
	margin: 0.5rem 0 0;
	font-size: 1rem;
	font-weight: 600;
	color: var(--sws-ink-soft);
	text-align: center;
}

/* Compact mode (small fitted cells): tighter board chrome, applied by JS. */
.sws-game.sws-compact {
	--sws-gap: 3px;
	--sws-grid-pad: 8px;
	--sws-grid-border: 2px;
}

.sws-game.sws-compact .sws-cell {
	border-radius: 5px;
}

/* The raised "puzzle board".
 * Fluid by default: 1fr columns mean the board can NEVER be wider than its
 * container, on any screen — the browser guarantees the fit, not a script.
 * Width is capped so desktop cells stop growing at the comfortable size. */
.sws-grid {
	--sws-size: 8;
	display: grid;
	grid-template-columns: repeat(var(--sws-size), minmax(0, 1fr));
	gap: var(--sws-gap);
	padding: var(--sws-grid-pad);
	background: var(--sws-color-grid);
	border: var(--sws-grid-border) solid rgba(43, 52, 69, 0.12);
	border-radius: 14px;
	box-shadow: 0 3px 10px rgba(43, 52, 69, 0.12);
	width: 100%;
	max-width: calc(
		var(--sws-size) * var(--sws-cell) +
		(var(--sws-size) - 1) * var(--sws-gap) +
		2 * var(--sws-grid-pad) +
		2 * var(--sws-grid-border)
	);
	touch-action: manipulation;
}

/* Zoomed mode (player pressed A+): fixed-size cells that may exceed the
 * screen; the board then slides sideways with the hint and edge fade. */
.sws-game.sws-zoomed .sws-grid {
	grid-template-columns: repeat(var(--sws-size), var(--sws-cell));
	width: max-content;
	max-width: none;
}

.sws-game.sws-zoomed .sws-cell {
	width: var(--sws-cell);
	height: var(--sws-cell);
	aspect-ratio: auto;
	font-size: var(--sws-font-size);
}

/* Rows stay in the accessibility tree but do not affect grid layout. */
.sws-row {
	display: contents;
}

.sws-cell {
	appearance: none;
	width: 100%;
	min-width: 0;
	height: auto;
	aspect-ratio: 1 / 1;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: inherit;
	font-size: var(--sws-letter, var(--sws-font-size));
	font-weight: 700;
	text-transform: uppercase;
	color: var(--sws-color-text);
	background: var(--sws-color-cell);
	border: none;
	border-radius: 8px;
	cursor: pointer;
	user-select: none;
	padding: 0;
}

.sws-cell:hover {
	background: #eef2f6;
}

.sws-cell.sws-anchor {
	background: var(--sws-color-sel);
	color: #1a1a1a;
	box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.3);
}

.sws-cell.sws-preview {
	background: var(--sws-color-sel);
	color: #1a1a1a;
}

.sws-cell.sws-found {
	background: var(--sws-color-found);
	color: #ffffff;
}

.sws-cell.sws-hint {
	outline: 4px dashed var(--sws-denim);
	outline-offset: -4px;
}

.sws-cell.sws-invalid {
	background: #f2c8c2;
}

/* Very old browsers without aspect-ratio support: fixed cell height. */
@supports not (aspect-ratio: 1 / 1) {
	.sws-cell {
		height: var(--sws-cell);
	}
}

/* --------------------------------------------------------------------- */
/* Word bank */
/* --------------------------------------------------------------------- */

.sws-sidebar {
	flex: 1 1 220px;
	min-width: 190px;
}

.sws-wordbank-title {
	margin: 0 0 0.7rem;
	font-family: var(--sws-display);
	font-size: 1.35rem;
	font-weight: 700;
}

.sws-wordbank {
	list-style: none;
	margin: 0 0 1rem;
	padding: 0;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
	gap: 0.45rem 0.75rem;
}

.sws-word {
	display: flex;
	align-items: center;
	gap: 0.45rem;
	padding: 0.35rem 0.6rem;
	font-size: 1.15rem;
	font-weight: 600;
	letter-spacing: 0.03em;
	background: #ffffff;
	border: 1px solid var(--sws-paper-2);
	border-radius: 10px;
}

.sws-word-check {
	display: inline-flex;
	width: 1.3rem;
	justify-content: center;
	color: var(--sws-color-found);
	font-weight: 800;
}

.sws-word.is-found {
	background: var(--sws-paper-2);
}

.sws-word.is-found .sws-word-text {
	text-decoration: line-through;
	text-decoration-thickness: 2px;
	color: var(--sws-ink-soft);
}

/* Progress bar + caption */

.sws-progressbar {
	height: 12px;
	background: var(--sws-paper-2);
	border-radius: 999px;
	overflow: hidden;
}

.sws-progressfill {
	height: 100%;
	width: 0;
	background: var(--sws-color-found);
	border-radius: 999px;
}

.sws-progress {
	margin: 0.5rem 0 0;
	font-size: 1.05rem;
	font-weight: 600;
	color: var(--sws-ink-soft);
}

/* --------------------------------------------------------------------- */
/* Status / completion */
/* --------------------------------------------------------------------- */

.sws-status {
	margin: 1rem 0 0;
	min-height: 1.5rem;
	font-size: 1.15rem;
	font-weight: 700;
	color: var(--sws-color-found);
}

.sws-complete {
	margin-top: 1.25rem;
	padding: 1.5rem;
	text-align: center;
	background: #ffffff;
	border: 3px solid var(--sws-color-found);
	border-radius: 16px;
}

.sws-complete-badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 3rem;
	height: 3rem;
	margin-bottom: 0.5rem;
	font-size: 1.6rem;
	font-weight: 800;
	color: #ffffff;
	background: var(--sws-color-found);
	border-radius: 50%;
}

.sws-complete-message {
	margin: 0 0 1rem;
	font-family: var(--sws-display);
	font-size: 1.5rem;
	font-weight: 700;
}

/* --------------------------------------------------------------------- */
/* Notice (empty/error states) */
/* --------------------------------------------------------------------- */

.sws-notice {
	margin: 1.5rem auto;
	padding: 1.25rem 1.5rem;
	background: #fff8e6;
	border: 1px solid #f0d98a;
	border-radius: 12px;
	font-size: 1.1rem;
	color: #5c4b1a;
}

/* --------------------------------------------------------------------- */
/* Focus visibility (accessibility floor) */
/* --------------------------------------------------------------------- */

.sws-game .sws-btn:focus-visible,
.sws-game .sws-cell:focus-visible,
.sws-game .sws-level:focus-visible,
.sws-game .sws-theme-select:focus-visible {
	outline: 3px solid #1d4ed8;
	outline-offset: 2px;
	z-index: 1;
}

/* --------------------------------------------------------------------- */
/* Small screens */
/* --------------------------------------------------------------------- */

@media (max-width: 640px) {
	.sws-game {
		margin: 0.75rem auto;
		padding: 12px;
		border-radius: 14px;
	}

	.sws-text-size {
		margin-left: 0;
	}

	.sws-level {
		flex: 1 1 auto;
		min-width: 0;
	}

	.sws-theme-label {
		flex: 0 0 auto;
	}

	.sws-theme-select {
		flex: 1 1 auto;
		min-width: 0;
	}

	.sws-body {
		flex-direction: column;
		gap: 1rem;
	}

	.sws-grid-area {
		width: 100%;
	}

	.sws-grid-wrap {
		padding: 2px;
	}

	.sws-sidebar {
		width: 100%;
	}

	.sws-wordbank {
		grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
	}
}

/* --------------------------------------------------------------------- */
/* Motion: only add transitions when the user allows motion */
/* --------------------------------------------------------------------- */

@media (prefers-reduced-motion: no-preference) {
	.sws-cell {
		transition: background-color 120ms ease, color 120ms ease;
	}

	.sws-btn,
	.sws-level {
		transition: background-color 120ms ease, border-color 120ms ease;
	}

	.sws-progressfill {
		transition: width 300ms ease;
	}
}

/* --------------------------------------------------------------------- */
/* Print: show a clean, solvable-on-paper puzzle; hide interactive chrome */
/* --------------------------------------------------------------------- */

@media print {
	.sws-toolbar,
	.sws-levels,
	.sws-status,
	.sws-complete,
	.sws-instructions,
	.sws-progressbar,
	.sws-progress,
	.sws-scroll-hint {
		display: none !important;
	}

	.sws-grid-area.is-scrollable::after {
		display: none !important;
	}

	.sws-grid-wrap {
		overflow: visible !important;
	}

	.sws-game {
		border: none;
		box-shadow: none;
		background: #ffffff;
		margin: 0;
		padding: 0;
	}

	.sws-grid {
		background: #ffffff;
		gap: 0;
		border: 2px solid #000000;
		box-shadow: none;
		grid-template-columns: repeat(var(--sws-size), var(--sws-cell));
		width: max-content;
		max-width: none;
	}

	.sws-cell {
		border: 1px solid #000000;
		border-radius: 0;
		color: #000000 !important;
		background: #ffffff !important;
		width: var(--sws-cell);
		height: var(--sws-cell);
		aspect-ratio: auto;
		font-size: var(--sws-font-size);
	}

	.sws-word {
		border: none;
		background: none;
	}

	.sws-word.is-found .sws-word-text {
		text-decoration: none;
		color: #000000;
	}

	.sws-word-check {
		display: none;
	}
}
