/* Spielesammlung - Stylesheet
 *
 * Mobile-first: Die Grundregeln gelten fürs Handy, ab 768px (Tablet hochkant) kommt die Seitenleiste mit den
 * Filtern dazu, ab 1100px wird es nur noch luftiger. Hell/dunkel folgt der Einstellung des Geräts.
 * Ein- und Ausblenden über das hidden-Attribut (siehe Regel ganz unten), nicht über Klassen. */

:root {
	--bg:              #f4f1ea;
	--surface:         #ffffff;
	--surface-2:       #ebe6db;
	--text:            #1f2328;
	--text-muted:      #5d6470;
	--line:            #d9d2c3;
	--accent:          #2f6b55;
	--accent-strong:   #24543f;
	--accent-contrast: #ffffff;
	--accent-soft:     #dcebe4;
	--danger:          #b3261e;
	--danger-soft:     #fbe3e1;
	--shadow:          0 1px 2px rgba(31, 35, 40, 0.06), 0 2px 10px rgba(31, 35, 40, 0.06);
	--shadow-raised:   0 6px 24px rgba(31, 35, 40, 0.18);

	--radius:          14px;
	--radius-small:    10px;
	/* Mindestgröße für alles, was man antippt (Apple: 44pt) */
	--touch:           44px;
	--gutter:          16px;

	color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg:              #121417;
		--surface:         #1c1f24;
		--surface-2:       #272b32;
		--text:            #e8e6e1;
		--text-muted:      #a0a6b0;
		--line:            #353a43;
		--accent:          #6cc4a1;
		--accent-strong:   #8ad6b7;
		--accent-contrast: #0d1f18;
		--accent-soft:     #1f3a30;
		--danger:          #ff8a80;
		--danger-soft:     #3b1d1b;
		--shadow:          0 1px 2px rgba(0, 0, 0, 0.4);
		--shadow-raised:   0 6px 24px rgba(0, 0, 0, 0.6);
	}
}

/* Grundlagen --------------------------------------------------------------------------------------------- */

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

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

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	-webkit-tap-highlight-color: transparent;
	min-height: 100dvh;
}

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

button {
	cursor: pointer;
}

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

:focus-visible {
	outline: 3px solid var(--accent);
	outline-offset: 2px;
}

fieldset {
	margin: 0;
	padding: 0;
	border: 0;
	min-width: 0;
}

legend {
	padding: 0;
}

/* Kopfzeile ---------------------------------------------------------------------------------------------- */

.appHeader {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: calc(6px + env(safe-area-inset-top)) var(--gutter) 6px;
	min-height: 56px;
}

.brand {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	color: var(--text);
	text-decoration: none;
	font-size: 1.25rem;
	font-weight: 700;
	letter-spacing: -0.01em;
}

.brand i {
	color: var(--accent);
	font-size: 1.6rem;
}

.headerActions {
	display: flex;
	align-items: center;
	gap: 4px;
}

.headerActions form {
	margin: 0;
}

.iconBtn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--touch);
	height: var(--touch);
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--text-muted);
	font-size: 1.35rem;
	text-decoration: none;
}

.iconBtn:active {
	background: var(--surface-2);
}

/* Filterleiste ------------------------------------------------------------------------------------------- */

.filterBar {
	position: sticky;
	top: 0;
	z-index: 10;
	padding: 8px var(--gutter) 10px;
	background: var(--bg);
	border-bottom: 1px solid var(--line);
}

.filterQuick {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.searchField {
	display: flex;
	align-items: center;
	gap: 8px;
	height: var(--touch);
	padding: 0 12px;
	border: 1px solid var(--line);
	border-radius: var(--radius-small);
	background: var(--surface);
}

.searchField:focus-within {
	border-color: var(--accent);
	box-shadow: 0 0 0 2px var(--accent-soft);
}

.searchField i {
	color: var(--text-muted);
	font-size: 1.15rem;
}

.searchField input {
	flex: 1;
	min-width: 0;
	height: 100%;
	border: 0;
	outline: 0;
	background: transparent;
}

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

/* Spielerzahl: der wichtigste Filter am Spieleabend, deshalb groß und immer sichtbar */
.stepper {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: var(--touch);
	border: 1px solid var(--line);
	border-radius: 999px;
	background: var(--surface);
}

.stepBtn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--touch);
	height: calc(var(--touch) - 2px);
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--accent);
	font-size: 1.2rem;
}

.stepBtn:active {
	background: var(--accent-soft);
}

.stepBtn:disabled {
	color: var(--line);
	cursor: default;
}

.stepValue {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-weight: 600;
	white-space: nowrap;
}

.stepValue i {
	color: var(--text-muted);
}

.stepper.active {
	border-color: var(--accent);
	background: var(--accent-soft);
}

.filterToggle {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	height: var(--touch);
	padding: 0 14px;
	border: 1px solid var(--line);
	border-radius: 999px;
	background: var(--surface);
	font-weight: 600;
}

.filterToggle[aria-expanded="true"] {
	border-color: var(--accent);
	color: var(--accent);
}

.badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	height: 20px;
	padding: 0 6px;
	border-radius: 999px;
	background: var(--accent);
	color: var(--accent-contrast);
	font-size: 0.75rem;
	font-weight: 700;
}

/* Auf dem Handy zugeklappt; aufgeklappt scrollt der Bereich in sich, damit die Leiste nie den ganzen
   Bildschirm verdeckt. */
.filterMore {
	display: none;
}

.filterBar.open .filterMore {
	display: flex;
	flex-direction: column;
	gap: 16px;
	max-height: calc(100dvh - 150px);
	overflow-y: auto;
	padding: 14px 2px 4px;
	overscroll-behavior: contain;
}

.filterGroup legend {
	margin-bottom: 8px;
	color: var(--text-muted);
	font-size: 0.8rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

/* Chips (Auswahlknöpfe) ---------------------------------------------------------------------------------- */

/* Das eigentliche Eingabeelement bleibt für Tastatur und Screenreader erreichbar, sichtbar ist das Label */
.chipInput {
	position: absolute;
	opacity: 0;
	width: 1px;
	height: 1px;
	pointer-events: none;
}

.chipRow {
	position: relative;
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 40px;
	padding: 0 14px;
	border: 1px solid var(--line);
	border-radius: 999px;
	background: var(--surface);
	cursor: pointer;
	user-select: none;
	white-space: nowrap;
}

.chip.small {
	min-height: 36px;
	padding: 0 12px;
	font-size: 0.9rem;
}

.chip i {
	font-size: 1.1rem;
}

.chipInput:checked + .chip {
	border-color: var(--accent);
	background: var(--accent);
	color: var(--accent-contrast);
}

.chipInput:focus-visible + .chip,
.chipInput:focus-visible + label {
	outline: 3px solid var(--accent);
	outline-offset: 2px;
}

/* Zwei Hälften, genau eine aktiv: UND/ODER der Arten */
.segmented {
	position: relative;
	display: flex;
	margin-top: 10px;
	padding: 3px;
	border-radius: 999px;
	background: var(--surface-2);
}

.segmented label {
	flex: 1;
	padding: 8px 4px;
	border-radius: 999px;
	color: var(--text-muted);
	font-size: 0.85rem;
	white-space: nowrap;
	text-align: center;
	cursor: pointer;
	user-select: none;
}

.segmented .chipInput:checked + label {
	background: var(--accent-soft);
	color: var(--accent-strong);
	font-weight: 600;
	box-shadow: var(--shadow);
}

.textBtn {
	display: inline-flex;
	align-items: center;
	align-self: flex-start;
	gap: 6px;
	min-height: var(--touch);
	padding: 0 4px;
	border: 0;
	background: transparent;
	color: var(--accent);
	font-weight: 600;
	text-decoration: none;
}

/* Ergebnisse --------------------------------------------------------------------------------------------- */

.results {
	padding: 12px var(--gutter) calc(110px + env(safe-area-inset-bottom));
}

.resultInfo {
	margin: 0 0 10px;
	color: var(--text-muted);
	font-size: 0.9rem;
}

.gameGrid {
	display: grid;
	grid-template-columns: 1fr;
	gap: 10px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.gameCard {
	min-width: 0;
}

.cardBody {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 8px;
	width: 100%;
	height: 100%;
	padding: 14px 16px;
	border: 1px solid transparent;
	border-radius: var(--radius);
	background: var(--surface);
	box-shadow: var(--shadow);
	text-align: left;
}

button.cardBody {
	padding-right: 44px;
}

button.cardBody:active {
	border-color: var(--accent);
}

.gameName {
	font-size: 1.1rem;
	font-weight: 700;
	line-height: 1.25;
	overflow-wrap: anywhere;
}

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

.typeTag {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 2px 8px;
	border-radius: 999px;
	background: var(--accent-soft);
	color: var(--accent-strong);
	font-size: 0.8rem;
	font-weight: 600;
}

.gameMeta {
	display: flex;
	flex-wrap: wrap;
	gap: 4px 16px;
	color: var(--text-muted);
	font-size: 0.95rem;
}

.metaItem {
	display: inline-flex;
	align-items: center;
	gap: 6px;
}

.editHint {
	position: absolute;
	top: 14px;
	right: 14px;
	color: var(--text-muted);
	font-size: 1.1rem;
}

.emptyState {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	padding: 48px 16px;
	color: var(--text-muted);
	text-align: center;
}

.emptyState > i {
	font-size: 2.5rem;
	color: var(--line);
}

.emptyState p {
	margin: 8px 0;
}

.emptyState .textBtn {
	align-self: center;
}

/* Hinzufügen-Knopf --------------------------------------------------------------------------------------- */

.fab {
	position: fixed;
	right: calc(20px + env(safe-area-inset-right));
	bottom: calc(20px + env(safe-area-inset-bottom));
	z-index: 20;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 60px;
	height: 60px;
	border: 0;
	border-radius: 50%;
	background: var(--accent);
	color: var(--accent-contrast);
	font-size: 1.8rem;
	box-shadow: var(--shadow-raised);
}

.fab:active {
	background: var(--accent-strong);
}

/* Formular-Dialog ---------------------------------------------------------------------------------------- */

/* Auf dem Handy ein Blatt, das von unten kommt und die volle Breite nutzt */
.gameDialog {
	width: 100%;
	max-width: 100%;
	max-height: 94dvh;
	margin: auto 0 0;
	padding: 0;
	border: 0;
	border-radius: 18px 18px 0 0;
	background: var(--surface);
	color: var(--text);
	box-shadow: var(--shadow-raised);
}

.gameDialog::backdrop {
	background: rgba(0, 0, 0, 0.45);
}

.gameDialog form {
	display: flex;
	flex-direction: column;
	max-height: 94dvh;
}

.dialogHeader {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 8px 4px 20px;
}

.dialogHeader h2 {
	margin: 0;
	font-size: 1.2rem;
}

.dialogBody {
	display: flex;
	flex-direction: column;
	gap: 18px;
	padding: 8px 20px 16px;
	overflow-y: auto;
}

.dialogFooter {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
	border-top: 1px solid var(--line);
}

.footerSpacer {
	flex: 1;
}

/* Die Hauptaktion steht rechts, im HTML aber vorn (siehe inc/gameForm.html) */
.dialogFooter .btn.primary {
	order: 1;
}

.field {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.fieldLabel {
	font-weight: 600;
}

.fieldHint {
	margin: 0;
	color: var(--text-muted);
	font-size: 0.85rem;
	font-weight: 400;
}

.field input[type="text"],
.field input[type="password"] {
	width: 100%;
	height: var(--touch);
	padding: 0 12px;
	border: 1px solid var(--line);
	border-radius: var(--radius-small);
	background: var(--bg);
	/* 16px verhindert, dass iOS beim Antippen in das Feld hineinzoomt */
	font-size: 16px;
}

.field input:focus {
	border-color: var(--accent);
	outline: 0;
	box-shadow: 0 0 0 2px var(--accent-soft);
}

.rangeRow {
	position: relative;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
}

.field .rangeRow input[type="text"] {
	width: 5.5em;
	text-align: center;
}

.field .rangeRow input:disabled {
	opacity: 0.4;
}

.rangeDash {
	color: var(--text-muted);
}

.formError {
	margin: 0;
	padding: 10px 12px;
	border-radius: var(--radius-small);
	background: var(--danger-soft);
	color: var(--danger);
	font-weight: 600;
}

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	min-height: var(--touch);
	padding: 0 18px;
	border: 1px solid var(--line);
	border-radius: 999px;
	background: var(--surface);
	font-weight: 600;
	white-space: nowrap;
}

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

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

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

.btn.wide {
	width: 100%;
}

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

/* Hinweis unten ------------------------------------------------------------------------------------------ */

.toast {
	position: fixed;
	left: 50%;
	bottom: calc(96px + env(safe-area-inset-bottom));
	z-index: 30;
	max-width: calc(100% - 32px);
	padding: 10px 18px;
	border-radius: 999px;
	background: var(--text);
	color: var(--bg);
	font-weight: 600;
	box-shadow: var(--shadow-raised);
	transform: translateX(-50%);
}

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

/* Anmelden / Einrichtung --------------------------------------------------------------------------------- */

.authBox {
	display: flex;
	flex-direction: column;
	gap: 16px;
	max-width: 420px;
	margin: 0 auto;
	padding: 16px var(--gutter) 48px;
}

.authBox h1 {
	margin: 0;
	font-size: 1.6rem;
}

.authIntro {
	margin: 0;
	color: var(--text-muted);
}

.authForm {
	display: flex;
	flex-direction: column;
	gap: 16px;
	padding: 20px;
	border-radius: var(--radius);
	background: var(--surface);
	box-shadow: var(--shadow);
}

/* Tablet und größer -------------------------------------------------------------------------------------- */

@media (min-width: 768px) {
	:root {
		--gutter: 24px;
	}

	.layout {
		display: grid;
		grid-template-columns: 280px minmax(0, 1fr);
		gap: 20px;
		max-width: 1440px;
		margin: 0 auto;
		padding: 0 var(--gutter);
	}

	/* Die Filter stehen dauerhaft als Seitenleiste; sie klebt beim Scrollen und scrollt bei Bedarf in sich */
	.filterBar {
		align-self: start;
		max-height: 100dvh;
		overflow-y: auto;
		padding: 12px 4px 24px 0;
		border-bottom: 0;
	}

	.filterToggle {
		display: none;
	}

	.filterMore,
	.filterBar.open .filterMore {
		display: flex;
		flex-direction: column;
		gap: 20px;
		max-height: none;
		overflow: visible;
		padding: 20px 0 0;
	}

	.results {
		padding: 12px 0 calc(110px + env(safe-area-inset-bottom));
	}

	.gameGrid {
		/* 190px: Auf dem Tablet hochkant passen damit neben der Seitenleiste zwei Spalten */
		grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
		gap: 14px;
	}

	.gameDialog {
		max-width: 560px;
		margin: auto;
		border-radius: 18px;
	}

	.gameDialog form {
		max-height: 90dvh;
	}
}

@media (min-width: 1100px) {
	.layout {
		grid-template-columns: 330px minmax(0, 1fr);
		gap: 32px;
	}

	.gameGrid {
		grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
	}
}

/* Muss gegen die display-Angaben oben gewinnen */
[hidden] {
	display: none !important;
}
