/*
 * Mobile-first styles for the recipe app. Light and dark via
 * prefers-color-scheme, large touch targets, safe-area aware.
 */

:root {
	--bg: #f6f1e7;
	--bg-card: #fffdf8;
	--fg: #1c1a17;
	--fg-muted: #6b655c;
	--line: #ddd5c6;
	--accent: #c2410c;
	--accent-fg: #ffffff;
	--danger: #b42318;
	--star: #d97706;
	--shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
	--radius: 12px;
	--touch: 48px;
	--gap: 12px;
	--font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
		"Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #1c1a17;
		--bg-card: #2a2622;
		--fg: #f1ece2;
		--fg-muted: #a39b8e;
		--line: #3d3731;
		--accent: #f97316;
		--accent-fg: #1c1a17;
		--danger: #f87171;
		--star: #fbbf24;
		--shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
	}
}

* {
	box-sizing: border-box;
}

html {
	font-size: 112.5%;
	-webkit-text-size-adjust: 100%;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--fg);
	font-family: var(--font);
	line-height: 1.5;
	padding-bottom: env(safe-area-inset-bottom);
}

a {
	color: var(--accent);
	word-break: break-word;
}

h1, h2, h3 {
	line-height: 1.25;
	margin: 0 0 var(--gap);
}

h1 {
	font-size: 1.5rem;
}

h2 {
	font-size: 1.2rem;
	margin-top: calc(var(--gap) * 2);
}

p {
	margin: 0 0 var(--gap);
}

.loading, .empty {
	color: var(--fg-muted);
	text-align: center;
	padding: calc(var(--gap) * 3) var(--gap);
}

/* Top bar */
.topbar {
	position: sticky;
	top: 0;
	z-index: 10;
	display: flex;
	align-items: center;
	gap: 8px;
	min-height: calc(var(--touch) + 12px + env(safe-area-inset-top));
	padding: calc(6px + env(safe-area-inset-top)) var(--gap) 6px;
	background: var(--bg);
	border-bottom: 1px solid var(--line);
}

.topbar h1 {
	flex: 1;
	margin: 0;
	font-size: 1.25rem;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

main {
	padding: var(--gap);
	padding-left: max(var(--gap), env(safe-area-inset-left));
	padding-right: max(var(--gap), env(safe-area-inset-right));
	max-width: 760px;
	margin: 0 auto;
}

/* Buttons */
button, .btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	text-decoration: none;
	font: inherit;
	min-height: var(--touch);
	min-width: var(--touch);
	padding: 0 16px;
	border: 1px solid var(--line);
	border-radius: var(--radius);
	background: var(--bg-card);
	color: var(--fg);
	cursor: pointer;
	touch-action: manipulation;
}

button:active {
	filter: brightness(0.92);
}

.btn-primary {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--accent-fg);
	font-weight: 600;
}

.btn-danger {
	color: var(--danger);
}

.btn-icon {
	padding: 0;
	font-size: 1.25rem;
	line-height: 1;
}

.btn-link {
	border: none;
	background: none;
	color: var(--accent);
	padding: 0 8px;
}

.actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: calc(var(--gap) * 2) 0;
}

.actions > * {
	flex: 1 1 auto;
}

/* Forms */
label {
	display: block;
	margin-bottom: var(--gap);
}

.field {
	margin-bottom: var(--gap);
}

label > span, legend, .field-label {
	display: block;
	font-size: 0.9rem;
	color: var(--fg-muted);
	margin-bottom: 4px;
}

input, select, textarea {
	font: inherit;
	width: 100%;
	min-height: var(--touch);
	padding: 10px 12px;
	border: 1px solid var(--line);
	border-radius: var(--radius);
	background: var(--bg-card);
	color: var(--fg);
}

input:focus, select:focus, textarea:focus, button:focus-visible {
	outline: 3px solid var(--accent);
	outline-offset: 1px;
}

textarea {
	resize: vertical;
	min-height: calc(var(--touch) * 2);
}

input[type="checkbox"], input[type="radio"] {
	width: 28px;
	height: 28px;
	min-height: 0;
	margin: 0 8px 0 0;
	vertical-align: middle;
	accent-color: var(--accent);
}

.check {
	display: flex;
	align-items: center;
	min-height: var(--touch);
}

.check > span {
	margin: 0;
	font-size: 1rem;
	color: var(--fg);
}

fieldset {
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: var(--gap);
	margin: 0 0 var(--gap);
}

.radio-row {
	display: flex;
	flex-wrap: wrap;
	gap: var(--gap);
}

.radio-row label {
	margin: 0;
}

.row {
	display: flex;
	gap: 8px;
	align-items: flex-start;
	margin-bottom: 8px;
}

.row > * {
	flex: 1 1 0;
	min-width: 0;
}

.row > .narrow {
	flex: 0 0 4.5rem;
}

.row > .wide {
	flex: 2 1 0;
}

.row.bottom {
	align-items: flex-end;
}

.row > .ctl {
	flex: 0 0 auto;
	display: flex;
	gap: 4px;
}

.row > .ctl button {
	min-width: 40px;
	padding: 0;
}

.hidden {
	display: none !important;
}

.btn-row {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-bottom: 8px;
}

/* Pasted ingredient lines */
.paste {
	margin-bottom: var(--gap);
}

.paste textarea {
	margin-bottom: 8px;
}

/* Filters */
.filters {
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin-bottom: var(--gap);
}

.filters .row {
	margin: 0;
}

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

.chip {
	min-height: 40px;
	padding: 0 14px;
	border-radius: 20px;
	font-size: 0.95rem;
}

.chip[aria-pressed="true"] {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--accent-fg);
}

/* Cards */
.cards {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.card {
	display: flex;
	gap: 12px;
	align-items: center;
	width: 100%;
	text-align: left;
	padding: 12px 16px;
	background: var(--bg-card);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	color: inherit;
	text-decoration: none;
}

.card .title {
	font-size: 1.1rem;
	font-weight: 600;
	display: flex;
	gap: 8px;
	align-items: baseline;
}

.card .title .star {
	color: var(--star);
}

.card .meta {
	color: var(--fg-muted);
	font-size: 0.9rem;
}

.card .body {
	flex: 1 1 auto;
	min-width: 0;
}

.card .thumb {
	flex: 0 0 auto;
	width: 64px;
	height: 64px;
	object-fit: cover;
	border-radius: 8px;
	background: var(--line);
}

/* Overflow menu */
.menu {
	position: relative;
}

.menu summary {
	list-style: none;
}

.menu summary::-webkit-details-marker {
	display: none;
}

.menu-list {
	position: absolute;
	right: 0;
	top: calc(100% + 4px);
	min-width: 10rem;
	display: flex;
	flex-direction: column;
	background: var(--bg-card);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	overflow: hidden;
	z-index: 20;
}

.menu-list > * {
	justify-content: flex-start;
	border: none;
	border-radius: 0;
	padding: 0 16px;
	min-height: var(--touch);
	display: flex;
	align-items: center;
	color: var(--fg);
	text-decoration: none;
	background: none;
}

.menu-list > * + * {
	border-top: 1px solid var(--line);
}

/* Detail */
.meta-line {
	color: var(--fg-muted);
	margin-bottom: var(--gap);
}

.ingredients {
	list-style: none;
	padding: 0;
	margin: 0;
}

.ingredients li {
	display: flex;
	gap: 10px;
	padding: 10px 0;
	border-bottom: 1px solid var(--line);
}

.ingredients .amount {
	flex: 0 0 5.5rem;
	text-align: right;
	font-variant-numeric: tabular-nums;
	color: var(--fg-muted);
}

.ingredients .note {
	color: var(--fg-muted);
}

.steps {
	padding-left: 1.6rem;
	margin: 0;
}

.steps li {
	padding: 8px 0;
	font-size: 1.05rem;
}

.steps li::marker {
	color: var(--accent);
	font-weight: 700;
}

.intro {
	white-space: pre-wrap;
}

/* Portion stepper */
.stepper {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 8px;
}

.stepper button {
	padding: 0;
	font-size: 1.4rem;
	line-height: 1;
}

.stepper-value {
	min-width: 7.5rem;
	text-align: center;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

/* Nutrition in the form */
details.nutrition {
	margin-bottom: var(--gap);
}

details.nutrition summary {
	cursor: pointer;
	min-height: var(--touch);
	display: flex;
	align-items: center;
	color: var(--fg-muted);
}

details.nutrition summary::before {
	content: "▸";
	margin-right: 8px;
}

details.nutrition[open] summary::before {
	content: "▾";
}

details.nutrition .row label {
	margin-bottom: 4px;
}

/* Favorite star in the top bar */
.fav {
	font-size: 1.5rem;
	color: var(--fg-muted);
}

.fav[aria-pressed="true"] {
	color: var(--star);
}

/* Photos */
.photos {
	display: flex;
	gap: 8px;
	overflow-x: auto;
	scroll-snap-type: x proximity;
	-webkit-overflow-scrolling: touch;
	padding-bottom: 4px;
	margin-bottom: 8px;
}

.photo {
	position: relative;
	flex: 0 0 auto;
	margin: 0;
	scroll-snap-align: start;
}

.thumb-btn {
	padding: 0;
	border: none;
	background: var(--line);
	border-radius: var(--radius);
	overflow: hidden;
	width: 128px;
	height: 128px;
}

.thumb-btn img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.photo .badge {
	position: absolute;
	left: 6px;
	bottom: 6px;
	padding: 2px 8px;
	border-radius: 10px;
	font-size: 0.7rem;
	white-space: nowrap;
	background: var(--accent);
	color: var(--accent-fg);
	pointer-events: none;
}

.del {
	min-width: 36px;
	min-height: 36px;
	padding: 0;
	font-size: 0.9rem;
	line-height: 1;
}

.photo .del {
	position: absolute;
	top: 4px;
	right: 4px;
	background: var(--bg-card);
}

.upload {
	display: flex;
	align-items: center;
	gap: var(--gap);
}

.upload .check {
	margin: 0;
}

.overlay {
	position: fixed;
	inset: 0;
	z-index: 50;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(0, 0, 0, 0.92);
}

.overlay img {
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
}

.overlay .close {
	position: absolute;
	top: calc(8px + env(safe-area-inset-top));
	right: calc(8px + env(safe-area-inset-right));
	background: rgba(255, 255, 255, 0.9);
	color: #000;
	border: none;
}

/* Cook log and notes */
.section-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin-top: calc(var(--gap) * 2);
}

.section-head h2 {
	margin: 0;
}

.entries {
	list-style: none;
	margin: 0 0 var(--gap);
	padding: 0;
}

.entry {
	padding: 10px 0;
	border-bottom: 1px solid var(--line);
}

.entry-head {
	display: flex;
	align-items: center;
	gap: 10px;
}

.entry-head .date {
	color: var(--fg-muted);
	font-variant-numeric: tabular-nums;
}

.entry-head .rating {
	color: var(--star);
	letter-spacing: 2px;
}

.entry-head .del {
	margin-left: auto;
}

.entry .comment {
	margin: 4px 0 0;
	white-space: pre-wrap;
}

.entry-form {
	margin-top: var(--gap);
}

.entry-form .actions {
	margin-top: 0;
}

.stars {
	display: flex;
	gap: 2px;
}

.stars button {
	min-width: 44px;
	padding: 0;
	border: none;
	background: none;
	font-size: 1.6rem;
	color: var(--fg-muted);
}

.stars button[aria-pressed="true"] {
	color: var(--star);
}

/* Cooking mode */
.cook {
	font-size: 125%;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
}

.cook main {
	flex: 1 1 auto;
	width: 100%;
}

.cook .checks {
	list-style: none;
	margin: 0 0 var(--gap);
	padding: 0;
}

.cook .checks li {
	border-bottom: 1px solid var(--line);
}

.cook .checks .check {
	min-height: 56px;
	margin: 0;
	padding: 6px 0;
}

.cook .checks input[type="checkbox"] {
	width: 32px;
	height: 32px;
	margin-right: 14px;
	flex: 0 0 auto;
}

.cook .checks .done span {
	color: var(--fg-muted);
	text-decoration: line-through;
}

.cook .step {
	margin: calc(var(--gap) * 2) 0;
	padding: var(--gap);
	background: var(--bg-card);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
}

.cook .counter {
	margin: 0 0 8px;
	color: var(--accent);
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.cook .step-text {
	margin: 0;
	font-size: 1.4rem;
	line-height: 1.4;
	white-space: pre-wrap;
}

.cook .all-steps li {
	font-size: 0.85rem;
	color: var(--fg-muted);
	padding: 6px 8px;
	border-radius: 8px;
	cursor: pointer;
}

.cook .all-steps li.current {
	color: var(--fg);
	background: var(--bg-card);
	font-weight: 600;
}

.cook .stepper {
	margin-bottom: var(--gap);
}

/* Timers */
.timerbar {
	position: sticky;
	top: calc(var(--touch) + 12px + env(safe-area-inset-top));
	z-index: 9;
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding: 6px var(--gap);
	background: var(--bg);
	border-bottom: 1px solid var(--line);
}

.timer {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 4px 4px 4px 12px;
	background: var(--bg-card);
	border: 1px solid var(--line);
	border-radius: var(--radius);
}

.timer-label {
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-size: 0.9rem;
	color: var(--fg-muted);
}

.timer-time {
	font-size: 1.3rem;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.timer button {
	min-height: 40px;
	padding: 0 12px;
}

.timer.done {
	background: var(--danger);
	border-color: var(--danger);
	color: #fff;
}

.timer.done .timer-label {
	color: #fff;
}

.timer.done button {
	background: rgba(255, 255, 255, 0.9);
	color: #000;
	border: none;
}

.timers {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
}

.timers:not(:empty) {
	margin-top: var(--gap);
}

.timers-label {
	font-size: 0.9rem;
	color: var(--fg-muted);
}

.btn-timer {
	min-height: 40px;
	padding: 0 14px;
	border-radius: 20px;
	border-color: var(--accent);
	color: var(--accent);
	font-weight: 600;
}

.btn-timer:disabled {
	opacity: 0.5;
	cursor: default;
}

.cookbar {
	position: sticky;
	bottom: 0;
	z-index: 10;
	display: flex;
	gap: 8px;
	padding: 8px var(--gap)
		 calc(8px + env(safe-area-inset-bottom));
	background: var(--bg);
	border-top: 1px solid var(--line);
}

.cookbar .btn-step {
	flex: 1 1 0;
	min-height: 56px;
	font-size: 1.1rem;
}

/* Import */
.import-form .row {
	align-items: flex-end;
}

.import-form .row > button {
	flex: 0 0 auto;
}

.import-form label {
	margin: 0;
}

.spinner {
	display: inline-block;
	width: 1em;
	height: 1em;
	margin-right: 8px;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

.preview-head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 4px 10px;
	color: var(--fg-muted);
	margin: var(--gap) 0 8px;
}

.preview-head .method {
	font-weight: 600;
	color: var(--fg);
}

.warnings {
	margin: 0 0 var(--gap);
	padding-left: 1.2rem;
	color: var(--fg-muted);
	font-size: 0.9rem;
}

.warnings li {
	padding: 2px 0;
}

.preview-img {
	margin: 0 0 var(--gap);
}

.preview-img img {
	display: block;
	width: 100%;
	max-height: 200px;
	object-fit: cover;
	border-radius: var(--radius);
	background: var(--line);
}

.preview-img .check {
	margin-top: 4px;
}

.import-photo {
	display: flex;
	align-items: center;
	gap: var(--gap);
	margin-bottom: var(--gap);
}

.import-photo .field-label {
	margin: 0;
}

/* Shopping list and pantry */
.shop {
	list-style: none;
	margin: 0 0 var(--gap);
	padding: 0;
}

.shop .item {
	display: flex;
	align-items: center;
	gap: 8px;
	min-height: 56px;
	border-bottom: 1px solid var(--line);
}

.shop .check {
	flex: 1 1 auto;
	min-width: 0;
	margin: 0;
	padding: 6px 0;
	cursor: pointer;
}

.shop .check input[type="checkbox"] {
	width: 32px;
	height: 32px;
	margin-right: 14px;
	flex: 0 0 auto;
}

.shop .text {
	flex: 1 1 auto;
	min-width: 0;
	font-size: 1.05rem;
	overflow-wrap: anywhere;
}

.shop .qty {
	color: var(--fg-muted);
	font-variant-numeric: tabular-nums;
}

.shop .note {
	color: var(--fg-muted);
	font-size: 0.85rem;
}

.shop .done .text {
	color: var(--fg-muted);
	text-decoration: line-through;
}

.shop .del {
	flex: 0 0 auto;
	margin-right: 4px;
}

.shop .empty {
	border: none;
}

.pantry .text {
	padding: 10px 0;
}

.shop-add .row {
	align-items: center;
	margin-bottom: 8px;
}

.shop-add .row > .btn-link {
	flex: 0 0 auto;
}

.shop-add .add {
	flex: 0 0 var(--touch);
	padding: 0;
	font-size: 1.4rem;
}

.hint {
	align-self: center;
	color: var(--fg-muted);
	font-size: 0.9rem;
}

button[aria-disabled="true"] {
	opacity: 0.5;
}

/* Bottom sheet */
.sheet-bg {
	position: fixed;
	inset: 0;
	z-index: 50;
	display: flex;
	align-items: flex-end;
	background: rgba(0, 0, 0, 0.5);
}

.sheet {
	width: 100%;
	max-width: 760px;
	margin: 0 auto;
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: var(--gap) var(--gap)
		 calc(var(--gap) + env(safe-area-inset-bottom));
	background: var(--bg);
	border-radius: var(--radius) var(--radius) 0 0;
	box-shadow: var(--shadow);
}

.sheet button {
	min-height: 56px;
}

/* Public recipe page */
.photos-full .photo img {
	display: block;
	height: 220px;
	max-width: 85vw;
	border-radius: var(--radius);
	background: var(--line);
}

.foot {
	margin-top: calc(var(--gap) * 3);
	padding: var(--gap) 0;
	border-top: 1px solid var(--line);
	color: var(--fg-muted);
	font-size: 0.9rem;
	text-align: center;
}

/* Login */
.login {
	max-width: 400px;
	margin: 10vh auto 0;
}

/* Toast */
#toast {
	position: fixed;
	left: 50%;
	bottom: calc(24px + env(safe-area-inset-bottom));
	transform: translateX(-50%);
	max-width: calc(100vw - 2 * var(--gap));
	padding: 12px 18px;
	border-radius: var(--radius);
	background: var(--fg);
	color: var(--bg);
	box-shadow: var(--shadow);
	z-index: 100;
}

#toast.error {
	background: var(--danger);
	color: #fff;
}

#toast[hidden] {
	display: none;
}

@media (min-width: 600px) {
	.filters {
		flex-direction: row;
		flex-wrap: wrap;
	}

	.filters > * {
		flex: 1 1 45%;
	}

	.filters .chips {
		flex-basis: 100%;
	}
}
