/**
 * AI Language Tutor — frontend styles (mobile-first).
 */

.alt-app {
	--alt-accent: #4f46e5;
	--alt-accent-contrast: #ffffff;
	--alt-bg: #ffffff;
	--alt-bg-soft: #f4f4f8;
	--alt-text: #1e1e24;
	--alt-text-soft: #5c5c66;
	--alt-border: #e2e2ea;
	--alt-good: #15803d;
	--alt-bad: #dc2626;
	--alt-ok: #b45309;
	--alt-radius: 12px;
	--alt-shadow: 0 2px 8px rgba(20, 20, 40, 0.08);

	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
	color: var(--alt-text);
	background: var(--alt-bg);
	line-height: 1.55;
	width: 100%;
	max-width: 1080px;
	margin: 0 auto;
	padding: 16px;
	box-sizing: border-box;
	container-type: inline-size;
}

.alt-app *,
.alt-app *::before,
.alt-app *::after {
	box-sizing: border-box;
}

/* The hidden attribute must always win over display rules below
   (otherwise the flashcard overlay, skeleton, etc. show on page load). */
@media screen {
	.alt-app [hidden] {
		display: none !important;
	}
}

@media (prefers-color-scheme: dark) {
	.alt-app {
		--alt-bg: #16161d;
		--alt-bg-soft: #1f1f28;
		--alt-text: #e8e8ef;
		--alt-text-soft: #a2a2b0;
		--alt-border: #33333f;
		--alt-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
	}
}

/* ---------- header ---------- */

.alt-title {
	margin: 0 0 8px;
	font-size: 1.5rem;
}

.alt-hint {
	background: var(--alt-bg-soft);
	border-left: 3px solid var(--alt-accent);
	border-radius: 6px;
	padding: 8px 12px;
	font-size: 0.9rem;
	color: var(--alt-text-soft);
}

/* ---------- layout ---------- */

.alt-layout {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

@container (min-width: 860px) {
	.alt-layout {
		flex-direction: row;
		align-items: flex-start;
	}
	.alt-main {
		flex: 1 1 auto;
		min-width: 0;
	}
	.alt-history {
		flex: 0 0 260px;
		position: sticky;
		top: 16px;
	}
}

/* ---------- history panel ---------- */

.alt-history {
	background: var(--alt-bg-soft);
	border: 1px solid var(--alt-border);
	border-radius: var(--alt-radius);
	padding: 12px;
}

.alt-history-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.alt-history-header h3 {
	margin: 0;
	font-size: 1rem;
}

.alt-history-note {
	font-size: 0.78rem;
	color: var(--alt-text-soft);
	margin: 4px 0 10px;
}

.alt-history-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.alt-history-item {
	display: flex;
	align-items: center;
	gap: 6px;
	background: var(--alt-bg);
	border: 1px solid var(--alt-border);
	border-radius: 8px;
	padding: 6px 8px;
}

.alt-history-load {
	flex: 1 1 auto;
	min-width: 0;
	background: none;
	border: 0;
	padding: 6px 4px;
	text-align: left;
	cursor: pointer;
	color: var(--alt-text);
	min-height: 44px;
}

.alt-history-name {
	display: block;
	font-weight: 600;
	font-size: 0.9rem;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.alt-history-meta {
	display: block;
	font-size: 0.75rem;
	color: var(--alt-text-soft);
}

.alt-history-actions {
	display: flex;
	gap: 2px;
}

.alt-history-empty {
	font-size: 0.85rem;
	color: var(--alt-text-soft);
}

@container (max-width: 859px) {
	.alt-history.collapsed .alt-history-list,
	.alt-history.collapsed .alt-history-empty,
	.alt-history.collapsed .alt-history-note {
		display: none;
	}
}

/* ---------- form ---------- */

.alt-form {
	background: var(--alt-bg-soft);
	border: 1px solid var(--alt-border);
	border-radius: var(--alt-radius);
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.alt-form-row {
	display: grid;
	grid-template-columns: 1fr;
	gap: 14px;
}

@container (min-width: 600px) {
	.alt-form-row {
		grid-template-columns: repeat(3, 1fr);
	}
}

.alt-field {
	display: flex;
	flex-direction: column;
	gap: 4px;
	position: relative;
}

.alt-field label {
	font-weight: 600;
	font-size: 0.9rem;
}

.alt-field input,
.alt-field select {
	width: 100%;
	padding: 10px 12px;
	border: 1px solid var(--alt-border);
	border-radius: 8px;
	background: var(--alt-bg);
	color: var(--alt-text);
	font-size: 1rem;
	min-height: 44px;
}

.alt-field input:focus,
.alt-field select:focus {
	outline: 2px solid var(--alt-accent);
	outline-offset: 1px;
}

.alt-char-counter {
	position: absolute;
	right: 8px;
	bottom: -18px;
	font-size: 0.75rem;
	color: var(--alt-text-soft);
}

.alt-field-topic {
	margin-bottom: 14px;
}

/* ---------- buttons ---------- */

.alt-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 10px 18px;
	border-radius: 8px;
	border: 1px solid transparent;
	font-size: 1rem;
	font-weight: 600;
	cursor: pointer;
	min-height: 44px;
	transition: filter 0.15s ease;
}

.alt-btn:disabled {
	opacity: 0.55;
	cursor: not-allowed;
}

.alt-btn-primary {
	background: var(--alt-accent);
	color: var(--alt-accent-contrast);
}

.alt-btn-secondary {
	background: var(--alt-bg);
	color: var(--alt-text);
	border-color: var(--alt-border);
}

.alt-btn-success {
	background: var(--alt-good);
	color: #fff;
}

.alt-btn-danger {
	background: var(--alt-bad);
	color: #fff;
}

.alt-icon-btn {
	background: none;
	border: 0;
	cursor: pointer;
	font-size: 1.1rem;
	padding: 8px;
	min-width: 44px;
	min-height: 44px;
	border-radius: 8px;
	color: var(--alt-text);
}

.alt-icon-btn.recording {
	background: var(--alt-bad);
	color: #fff;
	animation: alt-pulse 1s infinite;
}

@keyframes alt-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.6; }
}

/* ---------- error ---------- */

.alt-error {
	background: #fdecec;
	border: 1px solid var(--alt-bad);
	color: var(--alt-bad);
	border-radius: 8px;
	padding: 10px 14px;
	margin: 14px 0;
}

@media (prefers-color-scheme: dark) {
	.alt-error {
		background: #3a1d1d;
	}
}

/* ---------- loading skeleton ---------- */

.alt-skeleton {
	margin-top: 18px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.alt-skel {
	border-radius: 8px;
	background: linear-gradient(90deg, var(--alt-bg-soft) 25%, var(--alt-border) 50%, var(--alt-bg-soft) 75%);
	background-size: 200% 100%;
	animation: alt-shimmer 1.4s infinite;
}

.alt-skel-title { height: 28px; width: 55%; }
.alt-skel-line { height: 16px; width: 90%; }
.alt-skel-line.short { width: 60%; }
.alt-skel-card { height: 120px; width: 100%; }

@keyframes alt-shimmer {
	0% { background-position: 200% 0; }
	100% { background-position: -200% 0; }
}

/* ---------- lesson ---------- */

.alt-lesson {
	margin-top: 20px;
	display: flex;
	flex-direction: column;
	gap: 14px;
	padding-bottom: 76px; /* room for sticky bar */
}

@container (min-width: 860px) {
	.alt-lesson {
		padding-bottom: 0;
	}
}

.alt-lesson-title {
	margin: 0;
	font-size: 1.35rem;
}

.alt-lesson-meta {
	color: var(--alt-text-soft);
	font-size: 0.85rem;
	margin: 4px 0;
}

.alt-lesson-intro {
	margin: 8px 0 0;
}

.alt-lesson-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 10px;
}

/* ---------- cards ---------- */

.alt-card {
	background: var(--alt-bg);
	border: 1px solid var(--alt-border);
	border-radius: var(--alt-radius);
	box-shadow: var(--alt-shadow);
	overflow: hidden;
}

.alt-card-header {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	background: var(--alt-bg-soft);
	border: 0;
	padding: 12px 16px;
	font-size: 1rem;
	font-weight: 700;
	cursor: pointer;
	color: var(--alt-text);
	min-height: 44px;
	text-align: left;
}

.alt-card-chevron {
	transition: transform 0.2s ease;
}

.alt-card.open .alt-card-chevron {
	transform: rotate(180deg);
}

.alt-card-body {
	padding: 14px 16px;
}

/* ---------- vocabulary table ---------- */

.alt-vocab-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.92rem;
}

.alt-vocab-table th,
.alt-vocab-table td {
	padding: 8px 10px;
	border-bottom: 1px solid var(--alt-border);
	text-align: left;
	vertical-align: top;
}

.alt-vocab-table th {
	font-size: 0.8rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--alt-text-soft);
}

.alt-vocab-term {
	font-weight: 700;
}

.alt-vocab-example {
	font-style: italic;
	color: var(--alt-text-soft);
}

.alt-vocab-actions {
	white-space: nowrap;
}

/* Stacked cards on small screens */
@container (max-width: 640px) {
	.alt-vocab-table thead {
		display: none;
	}
	.alt-vocab-table,
	.alt-vocab-table tbody,
	.alt-vocab-table tr,
	.alt-vocab-table td {
		display: block;
		width: 100%;
	}
	.alt-vocab-table tr {
		border: 1px solid var(--alt-border);
		border-radius: 8px;
		margin-bottom: 10px;
		padding: 6px;
	}
	.alt-vocab-table td {
		border-bottom: 0;
		padding: 4px 8px;
	}
	.alt-vocab-table td::before {
		content: attr(data-label);
		display: block;
		font-size: 0.7rem;
		text-transform: uppercase;
		color: var(--alt-text-soft);
	}
	.alt-vocab-actions::before {
		display: none;
	}
}

/* ---------- ASR result ---------- */

.alt-asr-result {
	font-size: 0.85rem;
	color: var(--alt-text-soft);
	margin-top: 4px;
	white-space: normal;
}

.alt-asr-result.alt-good { color: var(--alt-good); }
.alt-asr-result.alt-ok { color: var(--alt-ok); }
.alt-asr-result.alt-bad { color: var(--alt-bad); }

/* ---------- phrases / grammar ---------- */

.alt-phrase-list,
.alt-grammar-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.alt-phrase-item {
	border-bottom: 1px solid var(--alt-border);
	padding-bottom: 10px;
}

.alt-phrase-item:last-child {
	border-bottom: 0;
}

.alt-phrase-top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
}

.alt-phrase-translation {
	color: var(--alt-text-soft);
}

.alt-phrase-note {
	font-size: 0.85rem;
	color: var(--alt-text-soft);
	font-style: italic;
}

.alt-grammar-list p {
	margin: 4px 0 0;
	color: var(--alt-text-soft);
}

/* ---------- dialogue ---------- */

.alt-dialogue {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.alt-dialogue-line {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	flex-wrap: wrap;
}

.alt-dialogue-bubble {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	gap: 8px;
	background: var(--alt-bg-soft);
	border: 1px solid var(--alt-border);
	border-radius: 10px;
	padding: 10px 12px;
}

.alt-dialogue-speaker {
	font-weight: 700;
	white-space: nowrap;
}

.alt-dialogue-translation {
	font-size: 0.85rem;
	color: var(--alt-text-soft);
	font-style: italic;
}

.alt-dialogue-actions {
	display: flex;
}

/* ---------- quiz ---------- */

.alt-quiz-score {
	font-weight: 700;
	margin-bottom: 10px;
}

.alt-quiz-item {
	border: 1px solid var(--alt-border);
	border-radius: 8px;
	padding: 12px;
	margin-bottom: 12px;
}

.alt-quiz-question {
	margin: 0 0 10px;
	font-weight: 600;
}

.alt-quiz-options {
	display: grid;
	grid-template-columns: 1fr;
	gap: 8px;
}

@container (min-width: 600px) {
	.alt-quiz-options {
		grid-template-columns: 1fr 1fr;
	}
}

.alt-quiz-option {
	padding: 10px 12px;
	border: 1px solid var(--alt-border);
	border-radius: 8px;
	background: var(--alt-bg);
	color: var(--alt-text);
	cursor: pointer;
	text-align: left;
	font-size: 0.95rem;
	min-height: 44px;
}

.alt-quiz-option.alt-good {
	border-color: var(--alt-good);
	background: rgba(21, 128, 61, 0.12);
}

.alt-quiz-option.alt-bad {
	border-color: var(--alt-bad);
	background: rgba(220, 38, 38, 0.1);
}

.alt-quiz-fill {
	display: flex;
	gap: 8px;
}

.alt-quiz-fill input {
	flex: 1 1 auto;
	padding: 10px 12px;
	border: 1px solid var(--alt-border);
	border-radius: 8px;
	background: var(--alt-bg);
	color: var(--alt-text);
	font-size: 1rem;
	min-height: 44px;
}

.alt-quiz-feedback {
	margin-top: 10px;
	font-size: 0.9rem;
}

.alt-quiz-feedback.alt-good { color: var(--alt-good); }
.alt-quiz-feedback.alt-bad { color: var(--alt-bad); }

/* ---------- flashcards ---------- */

.alt-flashcards {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.55);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 99999;
	padding: 16px;
}

.alt-flashcards-inner {
	background: var(--alt-bg);
	border-radius: var(--alt-radius);
	padding: 16px;
	width: 100%;
	max-width: 480px;
}

.alt-flashcards-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin-bottom: 12px;
}

.alt-flashcards-header h3 {
	margin: 0;
}

.alt-flashcard {
	position: relative;
	height: 220px;
	cursor: pointer;
	perspective: 800px;
	border-radius: var(--alt-radius);
}

.alt-flashcard-face {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: 20px;
	font-size: 1.3rem;
	font-weight: 600;
	border: 1px solid var(--alt-border);
	border-radius: var(--alt-radius);
	background: var(--alt-bg-soft);
	backface-visibility: hidden;
	transition: transform 0.4s ease;
	white-space: pre-line;
}

.alt-flashcard-back {
	transform: rotateY(180deg);
	font-weight: 400;
	font-size: 1.05rem;
}

.alt-flashcard.flipped .alt-flashcard-front { transform: rotateY(180deg); }
.alt-flashcard.flipped .alt-flashcard-back { transform: rotateY(360deg); }

.alt-fc-flip-hint {
	text-align: center;
	font-size: 0.8rem;
	color: var(--alt-text-soft);
}

.alt-flashcards-actions {
	display: flex;
	gap: 10px;
}

.alt-flashcards-actions .alt-btn {
	flex: 1 1 0;
}

.alt-no-scroll {
	overflow: hidden;
}

/* ---------- toast ---------- */

.alt-toast {
	position: fixed;
	left: 50%;
	bottom: 90px;
	transform: translateX(-50%) translateY(10px);
	background: var(--alt-text);
	color: var(--alt-bg);
	padding: 10px 18px;
	border-radius: 999px;
	font-size: 0.9rem;
	opacity: 0;
	transition: opacity 0.3s ease, transform 0.3s ease;
	z-index: 100000;
	pointer-events: none;
}

.alt-toast.visible {
	opacity: 1;
	transform: translateX(-50%) translateY(0);
}

/* ---------- sticky bottom action bar (mobile) ---------- */

.alt-sticky-bar {
	display: none;
}



/* ---------- print ---------- */

@media print {
	.alt-form,
	.alt-history,
	.alt-sticky-bar,
	.alt-flashcards,
	.alt-lesson-actions,
	.alt-card-chevron,
	.alt-mic-btn,
	.alt-tts-btn,
	.alt-hint {
		display: none !important;
	}
	.alt-card-body {
		display: block !important;
	}
	.alt-card,
	.alt-quiz-item {
		box-shadow: none;
		border: 1px solid #ccc;
		break-inside: avoid;
	}
	.alt-app {
		max-width: none;
		padding: 0;
	}
}
