/* ============================================================
   FF Scorigami – v0.1.1
   Helles Design, Barlow Condensed, Accent #e07645
   Defensiv gegen Theme-Reset.css (eigene Variablen, keine Erbung)
   ============================================================ */

.ff-scorigami {
	--ffs-bg:          #ffffff;
	--ffs-bg-elev:     #f7f7f5;
	--ffs-bg-soft:     #fafaf8;
	--ffs-border:      #e4e2dd;
	--ffs-border-soft: #efede8;
	--ffs-text:        #1f1f1f;
	--ffs-text-mid:    #555;
	--ffs-text-dim:    #8a8a8a;
	--ffs-accent:      #e07645;
	--ffs-accent-soft: #fbe8dd;
	--ffs-empty:       #f1efe9;
	--ffs-diag:        #fdf1e8;

	font-family: 'Barlow Condensed', 'Barlow', -apple-system, BlinkMacSystemFont, sans-serif;
	color: var(--ffs-text);
	background: var(--ffs-bg);
	padding: 22px;
	border: 1px solid var(--ffs-border);
	border-radius: 8px;
	box-shadow: 0 1px 3px rgba(0,0,0,0.04);
	max-width: 100%;
	box-sizing: border-box;
}
.ff-scorigami *, .ff-scorigami *::before, .ff-scorigami *::after { box-sizing: border-box; }

/* --- Debug-Box --- */
.ffs-debug {
	background: #fff8e1;
	border: 1px solid #f0d48a;
	border-left: 3px solid #d9a200;
	padding: 12px 16px;
	margin-bottom: 16px;
	font-size: 13px;
	color: #4a3a00;
	border-radius: 4px;
}
.ffs-debug strong { font-size: 14px; letter-spacing: 0.5px; }
.ffs-debug ul { margin: 8px 0 0 0; padding-left: 18px; }
.ffs-debug ul ul { margin-top: 2px; }
.ffs-debug code {
	background: rgba(0,0,0,0.06);
	padding: 1px 5px;
	border-radius: 3px;
	font-size: 12px;
}
.ffs-debug pre {
	background: rgba(0,0,0,0.04);
	padding: 6px 10px;
	margin: 6px 0 0;
	font-size: 12px;
	border-radius: 3px;
	white-space: pre-wrap;
}

/* --- Empty State --- */
.ffs-empty-state {
	text-align: center;
	padding: 40px 20px;
	background: var(--ffs-bg-soft);
	border: 1px dashed var(--ffs-border);
	border-radius: 6px;
	color: var(--ffs-text-mid);
}
.ffs-empty-state p { margin: 0 0 8px; }
.ffs-empty-state code {
	background: #fff;
	padding: 2px 6px;
	border: 1px solid var(--ffs-border);
	border-radius: 3px;
	font-size: 13px;
}

/* --- Controls (Switcher + Forfait-Toggle) --- */
.ffs-controls {
	display: flex;
	flex-wrap: wrap;
	align-items: stretch;
	gap: 14px 16px;
	margin-bottom: 18px;
	border-bottom: 1px solid var(--ffs-border);
	padding-bottom: 14px;
}
.ffs-forfait-toggle {
	flex: 0 0 auto;
	align-self: center;
}

/* --- Side-Controls: Saison + Forfait-Toggle rechts gruppiert --- */
.ffs-side-controls {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 14px;
	flex: 0 0 auto;
	align-self: center;
}

/* --- Modus-Selector (Endstand | 1./2./3. Drittel) --- */
.ffs-mode-switcher {
	display: inline-flex;
	align-items: stretch;
	gap: 0;
	border: 1px solid var(--ffs-border);
	border-radius: 4px;
	overflow: hidden;
	background: #fff;
}
.ffs-mode {
	background: #fff;
	color: var(--ffs-text-mid);
	border: none;
	border-right: 1px solid var(--ffs-border);
	padding: 6px 12px;
	font-family: inherit;
	font-size: 12px;
	font-weight: 500;
	letter-spacing: 0.3px;
	cursor: pointer;
	transition: all 0.15s ease;
	line-height: 1.2;
	white-space: nowrap;
}
.ffs-mode:last-child { border-right: none; }
.ffs-mode:hover {
	background: var(--ffs-accent-soft);
	color: var(--ffs-text);
}
.ffs-mode.is-active {
	background: var(--ffs-accent);
	color: #fff;
}

/* --- Sekundärer Score (Endstand in Perioden-Detail) --- */
.ffs-games-score--secondary {
	color: var(--ffs-text-dim);
	font-weight: 500;
}

/* --- Saison-Dropdown --- */
.ffs-season-control {
	display: inline-flex;
	align-items: center;
	gap: 8px;
}
.ffs-season-label {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.8px;
	color: var(--ffs-text-dim);
	font-weight: 500;
}
.ffs-season-select {
	font-family: inherit;
	font-size: 13px;
	font-weight: 500;
	color: var(--ffs-text);
	background: #fff;
	border: 1px solid var(--ffs-border);
	border-radius: 4px;
	padding: 6px 28px 6px 10px;
	cursor: pointer;
	line-height: 1.2;
	appearance: none;
	-webkit-appearance: none;
	background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%238a8a8a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 9px center;
	background-size: 10px;
	transition: border-color 0.15s ease;
	min-width: 150px;
}
.ffs-season-select:hover,
.ffs-season-select:focus {
	border-color: var(--ffs-accent);
	outline: none;
}

/* --- Switcher (horizontale Kachelleiste) --- */
.ffs-switcher {
	display: flex;
	flex-wrap: nowrap;
	gap: 8px;
	margin: 0;
	padding: 2px 2px 8px 2px;
	border: none;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	scroll-snap-type: x proximity;
	scroll-padding-left: 2px;
	scrollbar-width: thin;
	scrollbar-color: var(--ffs-border) transparent;
	/* fade-mask am Rand für Scroll-Andeutung */
	mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
	-webkit-mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
	flex: 1 1 auto;
	min-width: 0;
}
.ffs-switcher::-webkit-scrollbar { height: 6px; }
.ffs-switcher::-webkit-scrollbar-thumb { background: var(--ffs-border); border-radius: 3px; }

.ffs-tab {
	flex: 0 0 auto;
	width: 90px;
	height: 82px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 8px 6px;
	background: #fff;
	color: var(--ffs-text-mid);
	border: 1px solid var(--ffs-border);
	border-radius: 6px;
	font-family: inherit;
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.4px;
	text-transform: uppercase;
	cursor: pointer;
	transition: all 0.15s ease;
	line-height: 1.15;
	scroll-snap-align: start;
}
.ffs-tab:hover {
	color: var(--ffs-text);
	border-color: var(--ffs-accent);
	background: var(--ffs-accent-soft);
	transform: translateY(-1px);
}
.ffs-tab.is-active {
	background: var(--ffs-accent);
	border-color: var(--ffs-accent);
	color: #fff;
	box-shadow: 0 2px 6px rgba(224,118,69,0.35);
}
.ffs-tab-logo {
	width: 36px;
	height: 36px;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}
.ffs-tab-logo img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
	filter: none;
	transition: filter 0.15s ease;
}
.ffs-tab.is-active .ffs-tab-logo img {
	/* weißes Logo auf orangem Background: invertieren hilft bei dunklen Logos */
	filter: brightness(0) invert(1);
}
.ffs-tab-logo--placeholder {
	background: var(--ffs-bg-soft);
	border-radius: 50%;
	font-size: 12px;
	font-weight: 700;
	color: var(--ffs-text-dim);
	letter-spacing: 0;
}
.ffs-tab.is-active .ffs-tab-logo--placeholder {
	background: rgba(255,255,255,0.2);
	color: #fff;
}
.ffs-tab-logo--all {
	color: var(--ffs-text-dim);
}
.ffs-tab.is-active .ffs-tab-logo--all {
	color: #fff;
}
.ffs-tab-name {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 100%;
}

/* --- Forfait-Toggle (Pill-Switch) --- */
.ffs-forfait-toggle {
	display: inline-flex;
	align-items: center;
	gap: 8px;
}
.ffs-toggle-label {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.8px;
	color: var(--ffs-text-dim);
	font-weight: 500;
}
.ffs-forfait-toggle .ffs-toggle {
	background: #fff;
	color: var(--ffs-text-mid);
	border: 1px solid var(--ffs-border);
	padding: 6px 14px;
	font-family: inherit;
	font-size: 13px;
	font-weight: 500;
	letter-spacing: 0.4px;
	text-transform: lowercase;
	cursor: pointer;
	transition: all 0.15s ease;
	line-height: 1.2;
}
.ffs-forfait-toggle .ffs-toggle:first-of-type {
	border-radius: 4px 0 0 4px;
	border-right-width: 0;
}
.ffs-forfait-toggle .ffs-toggle:last-of-type {
	border-radius: 0 4px 4px 0;
}
.ffs-forfait-toggle .ffs-toggle:hover {
	color: var(--ffs-text);
	background: var(--ffs-accent-soft);
}
.ffs-forfait-toggle .ffs-toggle.is-active {
	background: var(--ffs-accent);
	border-color: var(--ffs-accent);
	color: #fff;
}

/* --- Fun-Facts-Box --- */
.ffs-filter-note {
	display: inline-block;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.8px;
	color: var(--ffs-accent);
	background: var(--ffs-accent-soft);
	padding: 3px 10px;
	border-radius: 3px;
	margin-bottom: 10px;
	font-weight: 600;
}
.ffs-facts {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
	gap: 10px;
	margin-bottom: 20px;
}
.ffs-fact {
	background: var(--ffs-bg-elev);
	border: 1px solid var(--ffs-border-soft);
	border-left: 3px solid var(--ffs-accent);
	padding: 10px 14px;
	border-radius: 4px;
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}
.ffs-fact-label {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 1px;
	color: var(--ffs-text-dim);
	font-weight: 500;
}
.ffs-fact-value {
	font-size: 21px;
	font-weight: 600;
	color: var(--ffs-text);
	line-height: 1.2;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.ffs-fact-value small {
	font-size: 12px;
	color: var(--ffs-text-dim);
	font-weight: 400;
	margin-left: 4px;
	letter-spacing: 0;
}
.ffs-fact-value.ffs-missing { color: var(--ffs-accent); }

/* --- Grid --- */
@keyframes ffsGridFade {
	from { opacity: 0; transform: translateY(6px); }
	to   { opacity: 1; transform: translateY(0); }
}
@keyframes ffsCellPop {
	0%   { opacity: 0; transform: scale(0.4); }
	60%  { opacity: 1; transform: scale(1.06); }
	100% { opacity: 1; transform: scale(1); }
}

.ffs-grid-wrap {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	padding-bottom: 4px;
	animation: ffsGridFade 0.35s ease both;
}

/* --- Torverteilungs-Histogramm ---
 * Echter Breiten-Cap mit höherer Specificity (.ff-scorigami-Präfix schlägt
 * die meisten Theme-Overrides). box-sizing: border-box stellt sicher, dass
 * Padding innerhalb der 1000px bleibt.
 */
.ff-scorigami .ffs-histogram {
	margin-top: 18px;
	margin-left: auto;
	margin-right: auto;
	max-width: 1000px;
	box-sizing: border-box;
	padding: 14px 16px 12px;
	background: var(--ffs-bg-soft);
	border: 1px solid var(--ffs-border-soft);
	border-radius: 6px;
	animation: ffsGridFade 0.4s ease 0.1s both;
}
.ffs-histo-header {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 10px;
	flex-wrap: wrap;
}
.ffs-histo-title {
	font-size: 13px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.8px;
	color: var(--ffs-text-mid);
}
.ffs-histo-hint {
	font-size: 11px;
	color: var(--ffs-text-dim);
	letter-spacing: 0.3px;
}
.ffs-histo-bars {
	display: flex;
	align-items: flex-end;
	gap: 3px;
	height: 110px;
	position: relative;
}
.ffs-histo-col {
	flex: 1 1 0;
	min-width: 0;  /* ← beim Cap auf 1000px müssen Balken schrumpfen dürfen,
	                  sonst sprengen min-width-Werte × Anzahl den Container */
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-end;
	height: 100%;
	position: relative;
	cursor: default;
}
.ffs-histo-bar {
	width: 100%;
	height: var(--h, 0%);
	min-height: 1px;
	background: linear-gradient(to top, var(--ffs-accent), rgba(224,118,69,0.55));
	border-radius: 2px 2px 0 0;
	transition: background 0.15s ease, transform 0.15s ease;
	transform-origin: bottom;
}
.ffs-histo-col:hover .ffs-histo-bar {
	background: var(--ffs-accent);
	transform: scaleY(1.03);
}
.ffs-histo-col.is-peak .ffs-histo-bar {
	background: linear-gradient(to top, #d6541d, var(--ffs-accent));
	box-shadow: 0 0 0 1px rgba(214,84,29,0.3);
}
.ffs-histo-xlabel {
	font-size: 10px;
	color: var(--ffs-text-dim);
	margin-top: 3px;
	font-weight: 500;
}

/* --- Actions-Leiste + Save-Button ---
 * justify-content: flex-start sorgt dafür, dass der Button links sitzt.
 * (Vorher flex-end: Wenn ein breiteres Kind-Element – z.B. ein altes Histogramm –
 * den Viewport aufgeblasen hat, wurde der Button nach rechts aus dem sichtbaren
 * Bereich gepusht und war faktisch verschwunden.)
 */
.ffs-actions {
	display: flex;
	justify-content: flex-start;
	gap: 8px;
	margin-top: 14px;
	max-width: 1000px;
	margin-left: auto;
	margin-right: auto;
}
.ffs-save-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	background: #fff;
	color: var(--ffs-text-mid);
	border: 1px solid var(--ffs-border);
	border-radius: 4px;
	padding: 7px 14px;
	font-family: inherit;
	font-size: 13px;
	font-weight: 500;
	letter-spacing: 0.3px;
	cursor: pointer;
	transition: all 0.15s ease;
	line-height: 1.2;
}
.ffs-save-btn:hover {
	color: var(--ffs-text);
	border-color: var(--ffs-accent);
	background: var(--ffs-accent-soft);
}
.ffs-save-btn:disabled {
	opacity: 0.6;
	cursor: wait;
}
.ffs-save-btn svg {
	flex-shrink: 0;
}
.ffs-grid {
	display: grid;
	grid-template-columns: minmax(140px, auto) repeat(var(--ffs-size), minmax(34px, 1fr));
	gap: 2px;
	min-width: max-content;
	background: var(--ffs-bg-soft);
	padding: 10px;
	border-radius: 6px;
	border: 1px solid var(--ffs-border-soft);
}
.ffs-corner {
	font-size: 10px;
	color: var(--ffs-text-dim);
	text-transform: uppercase;
	letter-spacing: 0.5px;
	padding: 4px 8px;
	align-self: end;
	line-height: 1.3;
	font-weight: 500;
}
.ffs-col-head,
.ffs-row-head {
	font-size: 12px;
	font-weight: 600;
	color: var(--ffs-text-mid);
	text-align: center;
	padding: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
}
.ffs-row-head {
	justify-content: flex-end;
	padding-right: 10px;
}

/* --- Cells --- */
.ffs-cell {
	aspect-ratio: 1 / 1;
	min-height: 34px;
	background: var(--ffs-empty);
	border: 1px solid transparent;
	border-radius: 2px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 11px;
	font-weight: 700;
	cursor: default;
	position: relative;
	transition: transform 0.1s ease, box-shadow 0.1s ease;
	color: var(--ffs-text);
}
.ffs-cell--disabled {
	background: transparent;
	pointer-events: none;
	border-color: transparent;
}
.ffs-cell--empty {
	background: var(--ffs-empty);
	color: transparent;
}
.ffs-cell--filled {
	background: rgba(224, 118, 69, var(--ffs-intensity, 0.3));
	cursor: pointer;
	color: var(--ffs-text);
	animation: ffsCellPop 0.32s ease both;
	animation-delay: calc(var(--ffs-anim-index, 0) * 18ms);
}
.ffs-cell--filled:hover {
	transform: scale(1.18);
	box-shadow: 0 2px 6px rgba(0,0,0,0.12), 0 0 0 2px var(--ffs-accent);
	z-index: 2;
	animation: none; /* Hover übersteuert den pop */
}

/* Reduced motion respektieren */
@media (prefers-reduced-motion: reduce) {
	.ffs-grid-wrap { animation: none; }
	.ffs-cell--filled { animation: none; }
}
.ffs-cell--diag.ffs-cell--empty { background: var(--ffs-diag); }
.ffs-cell-count {
	pointer-events: none;
	color: #1f1f1f;
}

/* Erst-Ergebnis-Markierung: goldener Rand + Stern */
.ffs-cell--first {
	box-shadow: 0 0 0 2px #f2c94c, 0 1px 4px rgba(242,201,76,0.3);
	z-index: 1;
}
.ffs-cell--first::after {
	content: "★";
	position: absolute;
	top: -4px;
	right: -3px;
	font-size: 10px;
	line-height: 1;
	color: #f2c94c;
	text-shadow: 0 0 2px rgba(0,0,0,0.4);
	pointer-events: none;
}
.ffs-cell--first.ffs-cell--empty {
	/* Selten: leere Zelle + first (wäre theoretisch unmöglich), trotzdem absichern */
	background: rgba(242,201,76,0.15);
}
.ffs-cell--first:hover {
	box-shadow: 0 2px 8px rgba(0,0,0,0.15), 0 0 0 3px #f2c94c;
}

/* Fact-Kachel für Firsts — goldener Akzent statt Orange */
.ffs-fact--first {
	border-left-color: #f2c94c;
}
.ffs-fact--first .ffs-star {
	color: #f2c94c;
	margin-left: 4px;
	font-size: 10px;
}
.ffs-fact-examples {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	margin-top: 6px;
}
.ffs-chip {
	display: inline-block;
	padding: 2px 7px;
	background: #fff7e0;
	border: 1px solid #f0d48a;
	border-radius: 3px;
	font-size: 11px;
	font-weight: 600;
	color: #6a4a1a;
	letter-spacing: 0.3px;
}
.ffs-chip--more {
	background: transparent;
	border-style: dashed;
	color: #b08a3a;
}
/* Bei hoher Intensität weißen Text + Schatten für Lesbarkeit */
.ffs-cell--filled[data-intensity-high="1"] .ffs-cell-count {
	color: #fff;
	text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}

/* --- Modal --- */
.ffs-modal {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(30,30,30,0.55);
	z-index: 99999;
	align-items: center;
	justify-content: center;
	padding: 20px;
}
.ffs-modal.is-open { display: flex; }
.ffs-modal-inner {
	background: #fff;
	border: 1px solid var(--ffs-border);
	border-radius: 8px;
	padding: 24px;
	max-width: 900px;
	width: 100%;
	max-height: 85vh;
	overflow-y: auto;
	position: relative;
	font-family: 'Barlow Condensed', 'Barlow', sans-serif;
	color: var(--ffs-text);
	box-shadow: 0 10px 40px rgba(0,0,0,0.18);
}
.ffs-modal-close {
	position: absolute;
	top: 8px;
	right: 12px;
	background: transparent;
	color: var(--ffs-text-dim);
	border: none;
	font-size: 28px;
	line-height: 1;
	cursor: pointer;
	padding: 4px 10px;
}
.ffs-modal-close:hover { color: var(--ffs-accent); }
.ffs-modal-title {
	margin: 0 0 4px;
	font-size: 24px;
	font-weight: 600;
	color: var(--ffs-accent);
	line-height: 1.2;
}
.ffs-modal-title small {
	font-size: 14px;
	color: var(--ffs-text-dim);
	font-weight: 400;
	margin-left: 8px;
}
.ffs-modal-meta {
	margin: 0 0 16px;
	font-size: 12px;
	color: var(--ffs-text-dim);
	text-transform: uppercase;
	letter-spacing: 0.6px;
}
.ffs-modal-empty {
	padding: 24px;
	text-align: center;
	color: var(--ffs-text-dim);
	font-style: italic;
	background: var(--ffs-bg-soft);
	border-radius: 4px;
}

/* --- Games Table --- */
.ffs-games {
	width: 100%;
	border-collapse: collapse;
	font-size: 14px;
	color: var(--ffs-text);
}
.ffs-games th,
.ffs-games td {
	padding: 8px 10px;
	border-bottom: 1px solid var(--ffs-border-soft);
	text-align: left;
}
.ffs-games thead th {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--ffs-text-dim);
	font-weight: 600;
	border-bottom: 1px solid var(--ffs-border);
	background: var(--ffs-bg-soft);
}
.ffs-games tbody tr:hover { background: var(--ffs-bg-soft); }
.ffs-games-score {
	font-weight: 700;
	color: var(--ffs-accent);
	text-align: center;
	white-space: nowrap;
}
.ffs-badge-forfait {
	display: inline-block;
	margin-left: 6px;
	padding: 1px 6px;
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	background: #efe7db;
	color: #6a4a1a;
	border-radius: 3px;
	font-weight: 600;
	vertical-align: middle;
}

/* Loading */
.ffs-viewport.is-loading { opacity: 0.5; pointer-events: none; }

/* .ffs-savable.is-capturing wurde in 0.1.20 entfernt – nativer Canvas-Export,
 * keine Pre-Render-CSS-Manipulation mehr nötig. */
