:root {
	--nest-quiz-page-width: min(1120px, calc(100vw - 96px));
	--nest-quiz-primary: var(--wp--preset--color--primary, #2563eb);
	--nest-quiz-primary-hover: #1d4ed8;
	--nest-quiz-border: var(--wp--preset--color--contrast-3, #e0e0e0);
	--nest-quiz-soft: var(--wp--preset--color--base-2, #f8f8f8);
	--nest-quiz-muted: #666;
	--nest-quiz-text: var(--wp--preset--color--contrast, #1f2937);
}

.nest-quiz-page .entry-content,
.nest-quiz-page .wp-block-post-content,
.nest-quiz-page main .wp-block-group,
.nest-quiz-page main .wp-block-group__inner-container {
	max-width: none;
}

.nest-quiz-library,
.nest-quiz-builder,
.nest-quiz-viewer {
	box-sizing: border-box;
	width: var(--nest-quiz-page-width);
	max-width: none;
	margin-right: auto;
	margin-left: auto;
	color: var(--nest-quiz-text);
}

.lesson-right .nest-quiz-viewer {
	width: 100%;
}

.nest-quiz-library *,
.nest-quiz-builder *,
.nest-quiz-viewer *,
.nest-modal * {
	box-sizing: border-box;
}

/* Shared modal styles */
.nest-modal {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 9999;
	align-items: center;
	justify-content: center;
	padding: 24px;
	background: rgba(0, 0, 0, 0.5);
}

.nest-modal-content {
	position: relative;
	width: min(90vw, 860px);
	max-height: 90vh;
	overflow-y: auto;
	padding: 28px;
	border-radius: 8px;
	background: #fff;
}

.nest-close {
	position: absolute;
	top: 12px;
	right: 14px;
	border: 0;
	background: none;
	cursor: pointer;
	font-size: 1.5rem;
	line-height: 1;
}

/* Shared button styles */
.nest-button {
	display: inline-block;
	padding: 7px 14px;
	border: 1px solid #ccc;
	border-radius: 4px;
	background: #f8f8f8;
	color: inherit;
	cursor: pointer;
	font-size: 0.9em;
	text-decoration: none;
}

.nest-button:hover {
	background: #eee;
}

.nest-button-primary {
	border-color: var(--nest-quiz-primary);
	background: var(--nest-quiz-primary);
	color: #fff;
}

.nest-button-primary:hover {
	background: var(--nest-quiz-primary-hover);
	color: #fff;
}

.nest-button-link {
	padding: 0;
	border: 0;
	background: none;
	color: #c00;
	cursor: pointer;
}

/* Quiz library */
.nest-quiz-library-header {
	display: flex;
	flex-wrap: wrap;
	gap: 16px;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 1.25rem;
}

.nest-quiz-library-header h2 {
	margin: 0;
}

.nest-quiz-library-table-wrap {
	width: 100%;
	overflow-x: auto;
}

.nest-quiz-library-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.9em;
}

.nest-quiz-library-table th,
.nest-quiz-library-table td {
	padding: 9px 12px;
	border-bottom: 1px solid var(--nest-quiz-border);
	text-align: left;
	vertical-align: middle;
}

.nest-quiz-library-table th {
	background: var(--nest-quiz-soft);
	font-weight: 600;
	white-space: nowrap;
}

.nest-quiz-library-table th:first-child,
.nest-quiz-library-table td:first-child {
	width: 42%;
}

.nest-quiz-lib-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.nest-quiz-responses-modal-content {
	max-width: 980px;
}

.nest-quiz-resp-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.88em;
}

.nest-quiz-resp-table th,
.nest-quiz-resp-table td {
	padding: 7px 10px;
	border-bottom: 1px solid #e8e8e8;
	text-align: left;
}

.nest-quiz-resp-table th {
	font-weight: 600;
}

.nest-quiz-picker-filters {
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(170px, 220px);
	gap: 10px;
	margin-bottom: 14px;
}

.nest-quiz-picker-filters input,
.nest-quiz-picker-filters select {
	width: 100%;
	min-height: 38px;
}

.nest-quiz-picker-item {
	display: flex;
	width: 100%;
	gap: 12px;
	align-items: center;
	justify-content: space-between;
	padding: 10px 0;
	border: 0;
	border-bottom: 1px solid var(--nest-quiz-border);
	background: transparent;
	color: inherit;
	cursor: pointer;
	text-align: left;
}

.nest-quiz-picker-item:hover {
	color: var(--nest-quiz-primary);
}

.nest-quiz-picker-item small {
	flex: 0 0 auto;
	color: var(--nest-quiz-muted);
}

/* Quiz builder */
.nest-quiz-meta-panel {
	margin-bottom: 1.5rem;
	padding: 20px;
	border: 1px solid var(--nest-quiz-border);
	border-radius: 8px;
	background: var(--nest-quiz-soft);
}

.nest-quiz-options-row {
	display: flex;
	flex-wrap: wrap;
	gap: 16px;
	align-items: flex-end;
	margin-top: 1rem;
}

.nest-quiz-options-row .nest-field {
	margin-bottom: 0;
}

.nest-quiz-options-row label {
	display: flex;
	gap: 6px;
	align-items: center;
}

.nest-quiz-questions-wrap h3 {
	margin-bottom: 0.75rem;
}

.nest-quiz-save-row {
	display: flex;
	gap: 12px;
	align-items: center;
	margin-top: 1.5rem;
}

#nqb-save-msg {
	font-size: 0.9em;
}

/* Question blocks */
.nqb-question-block {
	margin-bottom: 1rem;
	border: 1px solid #ddd;
	border-radius: 6px;
	background: #fff;
}

.nqb-question-block[draggable="true"] {
	cursor: grab;
}

.nqb-question-header {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	align-items: center;
	padding: 10px 14px;
	border-radius: 6px 6px 0 0;
	background: #f4f4f4;
}

.nqb-question-drag {
	color: #aaa;
	cursor: grab;
	font-size: 1.2em;
}

.nqb-question-type {
	padding: 4px 8px;
	border: 1px solid #ccc;
	border-radius: 4px;
}

.nqb-question-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	align-items: center;
	margin-left: auto;
}

.nqb-question-meta label {
	display: flex;
	gap: 4px;
	align-items: center;
	font-size: 0.85em;
}

.nqb-question-body {
	padding: 14px 16px;
}

.nqb-question-body label {
	display: block;
	margin-bottom: 4px;
	font-weight: 600;
}

.nqb-question-text {
	width: 100%;
	padding: 8px;
	border: 1px solid #ccc;
	border-radius: 4px;
	font-size: 1rem;
}

/* Answer rows */
.nqb-answer-list {
	margin: 10px 0;
}

.nqb-answer-row {
	display: flex;
	gap: 8px;
	align-items: center;
	margin-bottom: 6px;
}

.nqb-answer-text {
	flex: 1;
	padding: 5px 8px;
	border: 1px solid #ccc;
	border-radius: 4px;
}

.nqb-fill-answer {
	width: 100%;
	padding: 6px 10px;
	border: 1px solid #ccc;
	border-radius: 4px;
}

.nqb-type-section {
	margin: 10px 0;
}

.nqb-type-section .description {
	margin: 4px 0 10px;
	color: var(--nest-quiz-muted);
	font-size: 0.85em;
}

/* Matching */
.nqb-matching-columns {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 16px;
}

.nqb-matching-left h5,
.nqb-matching-right h5 {
	margin: 0 0 8px;
	font-size: 0.9em;
	font-weight: 600;
}

.nqb-match-item-row,
.nqb-match-target-row {
	display: flex;
	gap: 6px;
	align-items: center;
	margin-bottom: 6px;
}

.nqb-match-item-text,
.nqb-match-target-text {
	flex: 1;
	padding: 5px 8px;
	border: 1px solid #ccc;
	border-radius: 4px;
}

.nqb-match-target-select {
	flex: 1;
	padding: 5px 6px;
	border: 1px solid #ccc;
	border-radius: 4px;
}

/* Quiz viewer */
.nest-quiz-title {
	margin-bottom: 0.5rem;
}

.nest-quiz-instructions {
	margin-bottom: 1.5rem;
	padding: 12px 16px;
	border-left: 4px solid var(--nest-quiz-primary);
	border-radius: 0 6px 6px 0;
	background: var(--nest-quiz-soft);
	font-size: 0.95em;
}

.nest-quiz-start-screen {
	padding: 2rem 1rem;
	text-align: center;
}

.nest-quiz-attempts-info,
.nest-quiz-timer-info {
	margin-bottom: 0.5rem;
	color: #555;
	font-size: 0.95em;
}

/* Questions */
.nest-quiz-question {
	margin-bottom: 1.25rem;
	padding: 18px 20px;
	border: 1px solid var(--nest-quiz-border);
	border-radius: 8px;
}

.nest-quiz-question-header {
	display: flex;
	gap: 10px;
	align-items: flex-start;
	margin-bottom: 1rem;
}

.nest-quiz-q-number {
	flex-shrink: 0;
	font-size: 1.05em;
	font-weight: 700;
}

.nest-quiz-q-text {
	flex: 1;
}

.nest-quiz-q-timer {
	flex-shrink: 0;
	padding: 2px 8px;
	border-radius: 4px;
	background: #fef9c3;
	font-size: 0.8em;
	font-weight: 600;
}

.nest-quiz-q-timer.nest-quiz-timer-warning {
	background: #fee2e2;
	color: #991b1b;
}

.nest-quiz-q-timer.nest-quiz-timer-expired {
	background: #e5e7eb;
	color: #6b7280;
}

/* Answer options */
.nest-quiz-answer-label {
	display: flex;
	gap: 10px;
	align-items: center;
	margin-bottom: 6px;
	padding: 9px 12px;
	border: 1px solid var(--nest-quiz-border);
	border-radius: 6px;
	cursor: pointer;
}

.nest-quiz-answer-label:hover {
	background: #f5f5f5;
}

.nest-quiz-answer-label input {
	flex-shrink: 0;
}

.nest-quiz-text-input {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid #ccc;
	border-radius: 4px;
	font-size: 1rem;
}

.nest-quiz-textarea {
	width: 100%;
	padding: 10px;
	border: 1px solid #ccc;
	border-radius: 4px;
	font-size: 1rem;
	resize: vertical;
}

/* Matching */
.nest-quiz-matching {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.nest-quiz-match-row {
	display: flex;
	gap: 10px;
	align-items: center;
}

.nest-quiz-match-item {
	min-width: 160px;
	font-weight: 500;
}

.nest-quiz-match-select {
	flex: 1;
	padding: 7px 8px;
	border: 1px solid #ccc;
	border-radius: 4px;
}

/* Global timer */
.nest-quiz-global-timer {
	position: sticky;
	top: 0;
	z-index: 100;
	margin-bottom: 1rem;
	padding: 8px;
	border-radius: 6px;
	background: #fef9c3;
	font-size: 1.1em;
	font-weight: 700;
	text-align: center;
}

.nest-quiz-global-timer.nest-quiz-timer-warning {
	background: #fee2e2;
	color: #991b1b;
}

/* Submit row */
.nest-quiz-submit-row {
	display: flex;
	gap: 12px;
	align-items: center;
	margin-top: 1.5rem;
}

#nest-quiz-submit-msg {
	font-size: 0.9em;
}

/* Results */
.nest-quiz-results {
	margin-top: 1rem;
}

.nest-quiz-score-summary {
	margin-bottom: 1.5rem;
	padding: 14px 18px;
	border-radius: 8px;
	background: #f0fdf4;
	font-size: 1.3em;
	font-weight: 700;
}

.nest-quiz-pending-manual {
	margin-left: 10px;
	color: #92400e;
	font-size: 0.75em;
	font-weight: normal;
}

.nest-quiz-result-item {
	margin-bottom: 0.75rem;
	padding: 14px 16px;
	border: 1px solid var(--nest-quiz-border);
	border-radius: 8px;
}

.nest-quiz-result-correct { border-left: 4px solid #16a34a; }
.nest-quiz-result-incorrect { border-left: 4px solid #dc2626; }
.nest-quiz-result-pending { border-left: 4px solid #f59e0b; }

.nest-quiz-result-q {
	display: flex;
	justify-content: space-between;
	margin-bottom: 0.75rem;
	font-weight: 500;
}

.nest-quiz-result-pts {
	margin-left: 10px;
	color: #555;
	font-size: 0.85em;
	font-weight: normal;
	white-space: nowrap;
}

.nest-quiz-result-option {
	margin-bottom: 4px;
	padding: 6px 10px;
	border-radius: 4px;
}

.nest-quiz-result-option.selected { background: #dbeafe; }
.nest-quiz-result-option.correct-answer { background: #dcfce7; }
.nest-quiz-result-option.selected.correct-answer { background: #bbf7d0; font-weight: 600; }

.correct-tick {
	margin-left: 6px;
	color: #16a34a;
}

.nest-quiz-text-response {
	padding: 8px 10px;
	border-radius: 4px;
	background: #f3f4f6;
	font-size: 0.95em;
}

.nest-quiz-correct-answer {
	margin-top: 4px;
	color: #15803d;
	font-size: 0.85em;
}

.nest-quiz-pending-note {
	color: #92400e;
	font-size: 0.85em;
	font-style: italic;
}

.nest-quiz-match-result {
	display: flex;
	gap: 8px;
	align-items: center;
	margin-bottom: 4px;
	padding: 5px 8px;
	border-radius: 4px;
}

.nest-quiz-match-result.correct { background: #dcfce7; }
.nest-quiz-match-result.incorrect { background: #fee2e2; }
.nest-quiz-match-arrow { color: #888; }
.nest-quiz-correct-match { margin-left: 4px; color: #15803d; font-size: 0.8em; }

.nest-quiz-pending-results {
	padding: 16px 20px;
	border-radius: 8px;
	background: #fef9c3;
}

.nest-quiz-limit {
	color: #dc2626;
}

/* Field utility */
.nest-field {
	margin-bottom: 1rem;
}

.nest-field label {
	display: block;
	margin-bottom: 4px;
	font-weight: 600;
}

.nest-field input[type="text"],
.nest-field input[type="number"],
.nest-field select,
.nest-field textarea {
	width: 100%;
	max-width: 100%;
	padding: 7px 10px;
	border: 1px solid #ccc;
	border-radius: 4px;
	font-size: 1rem;
}

.nest-field .description {
	margin: 4px 0 0;
	color: var(--nest-quiz-muted);
	font-size: 0.85em;
}

.required {
	color: #c00;
}

@media (min-width: 900px) {
	.nest-quiz-meta-panel {
		display: grid;
		grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
		gap: 16px 20px;
	}

	.nest-quiz-meta-panel > .nest-field:first-child,
	.nest-quiz-meta-panel > .nest-quiz-options-row {
		grid-column: 1 / -1;
	}

	.nest-quiz-meta-panel > .nest-field:first-child input {
		max-width: 520px;
	}
}

@media (max-width: 640px) {
	:root {
		--nest-quiz-page-width: calc(100vw - 32px);
	}

	.nest-quiz-library-table {
		min-width: 720px;
	}

	.nest-quiz-picker-filters {
		grid-template-columns: 1fr;
	}

	.nest-quiz-question-header,
	.nest-quiz-result-q,
	.nest-quiz-submit-row,
	.nest-quiz-match-row,
	.nqb-answer-row {
		flex-wrap: wrap;
	}

	.nqb-matching-columns {
		grid-template-columns: 1fr;
	}
}
