:root {
	--bg: #f5f7fa;
	--surface: #ffffff;
	--surface-2: #f1f4f8;
	--border: #e2e8f0;
	--text: #1a202c;
	--muted: #718096;
	--blue: #2783de;
	--blue-2: #1c6fc1;
	--blue-soft: #ebf4fd;
	--green: #2f8f62;
	--green-soft: #e8f6ef;
	--orange: #d69e2e;
	--orange-soft: #fff7e6;
	--red: #e53e3e;
	--red-soft: #fff0f0;
	--purple: #805ad5;
	--shadow: 0 2px 4px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
	--radius: 16px;
	--radius-sm: 10px;
	--safe-bottom: env(safe-area-inset-bottom, 0px);
	--safe-top: env(safe-area-inset-top, 0px);
}

* {
	box-sizing: border-box;
	-webkit-tap-highlight-color: transparent;
}

html, body {
	margin: 0;
	padding: 0;
	background: var(--bg);
	color: var(--text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 16px;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

body {
	min-height: 100vh;
	padding-top: var(--safe-top);
	padding-bottom: var(--safe-bottom);
}

button, input, select, textarea {
	font: inherit;
	color: inherit;
}

h1, h2, h3, p { margin: 0; }

.hidden { display: none !important; }

#app {
	max-width: 860px;
	margin: 0 auto;
	padding: 16px;
}

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

.brand {
	display: flex;
	align-items: center;
	gap: 12px;
}

.brand-icon {
	width: 42px;
	height: 42px;
	border-radius: 12px;
	background: var(--blue-soft);
	padding: 6px;
	box-shadow: var(--shadow);
}

.brand h1 {
	font-size: 20px;
	font-weight: 800;
	letter-spacing: -0.3px;
}

.brand p {
	font-size: 13px;
	color: var(--muted);
	margin-top: 2px;
}

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	border: 1px solid var(--border);
	background: var(--surface);
	border-radius: var(--radius-sm);
	padding: 11px 16px;
	font-size: 15px;
	font-weight: 600;
	cursor: pointer;
	min-height: 46px;
	transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:active { transform: scale(0.97); }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
	background: var(--blue);
	border-color: var(--blue);
	color: white;
}
.btn-primary:hover { background: var(--blue-2); }

.btn-secondary { background: transparent; }

.btn-ghost {
	background: transparent;
	border-color: transparent;
	color: var(--muted);
}

.btn-danger {
	color: var(--red);
	border-color: var(--red-soft);
	background: var(--red-soft);
}
.btn-danger:hover { background: #ffe5e5; }

.btn-icon {
	width: 46px;
	padding: 0;
	border-radius: 50%;
}

.btn-add {
	background: var(--blue-soft);
	color: var(--blue);
	border-color: var(--blue-soft);
	font-size: 22px;
	font-weight: 400;
	line-height: 1;
}

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

.upload-section {
	padding: 16px;
	margin-bottom: 20px;
}

.subject-row {
	display: flex;
	gap: 8px;
	margin-bottom: 14px;
	flex-wrap: nowrap;
}

.subject-row select,
.subject-row input,
.subject-row .btn-add {
	min-height: 46px;
}

.subject-row select {
	flex: 1 1 35%;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface);
	padding: 0 10px;
	font-size: 15px;
	min-width: 120px;
}

.subject-row input {
	flex: 1 1 45%;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: 0 12px;
	font-size: 15px;
	min-width: 100px;
}

.dropzone {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 8px;
	text-align: center;
	padding: 28px 20px;
	border: 2px dashed var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface-2);
	cursor: pointer;
	transition: 0.15s ease;
}

.dropzone:hover,
.dropzone.dragover {
	border-color: var(--blue);
	background: var(--blue-soft);
}

.dropzone-icon { color: var(--blue); }

.dropzone-title {
	font-weight: 700;
	font-size: 16px;
}

.dropzone-sub {
	font-size: 13px;
	color: var(--muted);
}

.filter-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 14px;
	flex-wrap: wrap;
}

.filter-bar h2 {
	font-size: 18px;
	font-weight: 700;
}

.status-chips {
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
}

.chip {
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--muted);
	padding: 7px 12px;
	border-radius: 999px;
	font-size: 13px;
	font-weight: 700;
	cursor: pointer;
}

.chip.active {
	background: var(--blue);
	border-color: var(--blue);
	color: white;
}

.homework-list {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.hw-card {
	padding: 16px;
}

.hw-header {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-bottom: 14px;
}

.hw-thumb {
	width: 64px;
	height: 64px;
	border-radius: 12px;
	object-fit: cover;
	background: var(--surface-2);
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 26px;
	overflow: hidden;
}

.hw-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.hw-info {
	flex: 1;
	min-width: 0;
}

.hw-name {
	font-weight: 700;
	font-size: 15px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.hw-subject {
	font-size: 12px;
	color: var(--blue);
	font-weight: 700;
	margin-top: 2px;
}

.hw-status {
	font-size: 11px;
	font-weight: 800;
	padding: 4px 9px;
	border-radius: 999px;
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

.status-processing { background: var(--orange-soft); color: var(--orange); }
.status-ready { background: var(--surface-2); color: var(--muted); }
.status-solving { background: var(--blue-soft); color: var(--blue); }
.status-done { background: var(--green-soft); color: var(--green); }
.status-error { background: var(--red-soft); color: var(--red); }

.hw-body textarea {
	width: 100%;
	min-height: 90px;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: 12px;
	font-size: 15px;
	resize: vertical;
	background: var(--surface-2);
	margin-bottom: 12px;
}

.hw-body textarea:focus {
	outline: none;
	border-color: var(--blue);
	background: var(--surface);
}

.hw-note {
	font-size: 13px;
	color: var(--muted);
	margin-bottom: 10px;
}

.hw-actions {
	display: flex;
	gap: 10px;
	flex-wrap: wrap;
	margin-bottom: 12px;
}

.hw-actions .btn {
	flex: 1 1 auto;
}

.hw-actions .btn-danger {
	flex: 0 0 auto;
}

.hw-answer {
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: 14px;
	font-size: 15px;
	line-height: 1.6;
	max-height: 320px;
	overflow: auto;
}

.hw-answer h3, .hw-answer h4, .hw-answer h2 {
	margin-top: 12px;
	margin-bottom: 6px;
	font-size: 16px;
}

.hw-answer p, .hw-answer ul, .hw-answer ol {
	margin-bottom: 10px;
}

.hw-answer ul, .hw-answer ol {
	padding-left: 22px;
}

.hw-answer strong { color: var(--text); }

.hw-error {
	color: var(--red);
	font-size: 14px;
	background: var(--red-soft);
	border-radius: var(--radius-sm);
	padding: 10px 12px;
	margin-bottom: 12px;
}

.empty-state {
	text-align: center;
	padding: 44px 24px;
	color: var(--muted);
}

.empty-icon {
	font-size: 48px;
	margin-bottom: 12px;
}

.modal {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.45);
	display: grid;
	place-items: center;
	padding: 16px;
	z-index: 100;
}

.modal-card {
	width: 100%;
	max-width: 440px;
	padding: 20px;
}

.modal-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 14px;
}

.modal-header h2 {
	font-size: 20px;
	font-weight: 800;
}

.field-label {
	display: block;
	font-size: 14px;
	font-weight: 700;
	margin-bottom: 6px;
	margin-top: 12px;
}

.field-hint {
	font-size: 13px;
	color: var(--muted);
	margin: 4px 0 10px;
}

.modal input, .modal select {
	width: 100%;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: 12px;
	font-size: 15px;
	background: var(--surface-2);
}

.modal-actions {
	display: flex;
	gap: 10px;
	margin-top: 18px;
}

.modal-actions .btn {
	flex: 1;
}

.toast, .install-toast {
	position: fixed;
	left: 50%;
	bottom: 20px;
	transform: translateX(-50%);
	background: var(--text);
	color: white;
	padding: 12px 16px;
	border-radius: var(--radius-sm);
	font-size: 14px;
	box-shadow: var(--shadow);
	z-index: 200;
	display: flex;
	align-items: center;
	gap: 12px;
	white-space: nowrap;
	max-width: calc(100vw - 32px);
}

.install-toast {
	bottom: 28px;
}

@media (max-width: 560px) {
	#app { padding: 12px; }

	.brand h1 { font-size: 18px; }
	.brand p { font-size: 12px; }
	.brand-icon { width: 38px; height: 38px; }

	.subject-row {
		flex-wrap: wrap;
	}

	.subject-row select,
	.subject-row input {
		flex: 1 1 100%;
		min-width: 0;
	}

	.subject-row .btn-add {
		width: 46px;
	}

	.dropzone { padding: 22px 16px; }
	.dropzone-title { font-size: 15px; }
	.dropzone-sub { font-size: 12px; }

	.filter-bar { flex-direction: column; align-items: flex-start; }
	.status-chips { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
	.chip { white-space: nowrap; }

	.hw-actions .btn {
		flex: 1 1 100%;
	}
	.hw-actions .btn-danger {
		flex: 0 0 auto;
	}

	.modal { padding: 12px; }
	.modal-card { padding: 16px; }
}
