/* Wiki-Seite (wiki.html): Rahmenlayout samt Zurück-Knopf und Suche,
   Markdown-Formatierung und die Demo-Blöcke samt IO-Bedienfeldern und
   Tooltip. Grundfarben und Scrollbars kommen aus style.css. */

/* ------------------------------------------------------------------ Rahmen */

/* wiki.css wird nur von wiki.html geladen — html mit einfärben, damit
   unterhalb des Inhalts keine dunklere Fläche durchscheint */
html,
body.wiki {
	background: rgb(235, 235, 235);
}

#wiki-header {
	position: sticky;
	top: 0;
	z-index: 100;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 24px;
	background: #fff;
	border-bottom: 1px solid #ccc;
	box-shadow: 0 0 5px #00000020;
}

#wiki-header-left {
	display: flex;
	align-items: center;
	gap: 12px;
}

/* Zurück-Knopf: Das Wiki-Fenster öffnet oft ohne Browser-Menüleiste,
   der Knopf übernimmt dann den Zurück-Schritt der Historie */
#wiki-back {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	padding: 0;
	color: #222;
	background: #f0f0f0;
	border: 1px solid #ccc;
	border-radius: 6px;
	cursor: pointer;
}

#wiki-back img {
	display: block;
}

#wiki-back:hover {
	background: #e0e0e0;
	border-color: #999;
}

#wiki-back:active {
	background: #d0d0d0;
}

#wiki-title {
	font-size: 18px;
	font-weight: bold;
	color: #222;
	text-decoration: none;
}

#wiki-header-right {
	display: flex;
	align-items: center;
	gap: 10px;
}

/* Sprachwahl des Wikis: Flaggen-Knopf mit aufklappender Flaggenliste —
   bewusst ohne Text, damit die Auswahl selbst keine Übersetzung braucht */
#wiki-lang {
	position: relative;
}

#wiki-lang-current {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 32px;
	padding: 0;
	background: #f7f7f7;
	border: 1px solid #ccc;
	border-radius: 6px;
	cursor: pointer;
}

#wiki-lang-current:hover {
	background: #eee;
	border-color: #999;
}

.wiki-lang-flag {
	display: block;
	border-radius: 2px;
	/* feine Kontur, damit helle Flaggenteile nicht im Hintergrund verschwimmen */
	box-shadow: 0 0 0 1px #00000026;
}

/* die Liste dockt exakt in Knopfbreite direkt unter dem Knopf an */
#wiki-lang-options {
	position: absolute;
	top: calc(100% + 4px);
	left: 0;
	right: 0;
	box-sizing: border-box;
	z-index: 20;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	padding: 4px 0;
	background: #fff;
	border: 1px solid #ccc;
	border-radius: 6px;
	box-shadow: 0 4px 16px #00000030;
}

/* das display: flex darf das hidden-Attribut (Auf-/Zuklappen per wiki.js)
   nicht aushebeln */
#wiki-lang-options[hidden] {
	display: none;
}

#wiki-lang-options button {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 4px 5px;
	background: transparent;
	border: 0 none;
	border-radius: 4px;
	cursor: pointer;
}

#wiki-lang-options button:hover {
	background: #f2f8ff;
}

#wiki-lang-options button.active {
	background: #e8f2ff;
}

/* ------------------------------------------------------------- Wiki-Suche */

#wiki-search-box {
	position: relative;
}

#wiki-search {
	box-sizing: border-box;
	width: 260px;
	max-width: 40vw;
	padding: 6px 10px;
	font-size: 14px;
	color: #222;
	background: #f7f7f7;
	border: 1px solid #ccc;
	border-radius: 6px;
	outline: none;
}

#wiki-search:focus {
	background: #fff;
	border-color: #0080ff;
}

/* Treffer-Liste: klappt unter dem Suchfeld auf, rechtsbündig am Feld */
#wiki-search-results {
	position: absolute;
	top: calc(100% + 8px);
	right: 0;
	width: 420px;
	max-width: 90vw;
	max-height: min(60vh, 480px);
	overflow-y: auto;
	background: #fff;
	border: 1px solid #ccc;
	border-radius: 8px;
	box-shadow: 0 4px 16px #00000030;
}

.wiki-search-result {
	display: block;
	padding: 9px 14px;
	color: #222;
	text-decoration: none;
	border-bottom: 1px solid #eee;
}

.wiki-search-result:last-child {
	border-bottom: 0 none;
}

.wiki-search-result:hover {
	background: #f2f8ff;
}

.wiki-search-result-title {
	display: block;
	font-size: 14px;
	font-weight: bold;
	color: #0080ff;
}

.wiki-search-result-excerpt {
	display: block;
	margin-top: 2px;
	font-size: 12px;
	line-height: 1.45;
	color: #555;
}

.wiki-search-result-excerpt mark {
	background: #ffe9a8;
	border-radius: 2px;
	padding: 0 1px;
}

.wiki-search-message {
	padding: 12px 14px;
	font-size: 13px;
	color: #666;
}

#wiki-content {
	max-width: 860px;
	margin: 24px auto 60px auto;
	padding: 30px 40px;
	background: #fff;
	border: 1px solid #ccc;
	border-radius: 10px;
	box-shadow: 0 0 5px #00000020;
	color: #222;
	font-size: 15px;
	line-height: 1.6;
}

.wiki-error {
	padding: 15px 20px;
	background: #fdecea;
	border: 1px solid #e0b4b4;
	border-radius: 6px;
	color: #8b2e2e;
}

/* ------------------------------------------------------- Markdown-Inhalte */

#wiki-content h1,
#wiki-content h2,
#wiki-content h3,
#wiki-content h4 {
	line-height: 1.25;
	margin: 1.4em 0 0.5em 0;
}

#wiki-content h1:first-child {
	margin-top: 0;
}

#wiki-content h1 {
	font-size: 28px;
	padding-bottom: 8px;
	border-bottom: 1px solid #ddd;
}

#wiki-content h2 {
	font-size: 22px;
	padding-bottom: 5px;
	border-bottom: 1px solid #eee;
}

#wiki-content h3 {
	font-size: 18px;
}

#wiki-content h4 {
	font-size: 15px;
}

#wiki-content a {
	color: #0080ff;
	text-decoration: none;
}

#wiki-content a:hover {
	text-decoration: underline;
}

#wiki-content ul,
#wiki-content ol {
	padding-left: 28px;
}

#wiki-content li {
	margin: 3px 0;
}

#wiki-content blockquote {
	margin: 1em 0;
	padding: 2px 16px;
	border-left: 4px solid #0080ff40;
	background: #f6faff;
	color: #444;
}

#wiki-content hr {
	border: 0 none;
	border-top: 1px solid #ddd;
	margin: 2em 0;
}

#wiki-content img {
	max-width: 100%;
}

#wiki-content code {
	font-family: 'Courier New', Courier, monospace;
	font-size: 13px;
	background: #f0f0f0;
	border: 1px solid #e0e0e0;
	border-radius: 4px;
	padding: 1px 5px;
}

#wiki-content pre {
	background: #f6f6f6;
	border: 1px solid #ddd;
	border-radius: 6px;
	padding: 12px 16px;
	overflow: auto;
}

#wiki-content pre code {
	background: transparent;
	border: 0 none;
	padding: 0;
	font-size: 13px;
	line-height: 1.45;
}

#wiki-content table {
	border-collapse: collapse;
	margin: 1em 0;
}

#wiki-content th,
#wiki-content td {
	border: 1px solid #ccc;
	padding: 6px 12px;
	text-align: left;
}

#wiki-content th {
	background: #f0f0f0;
}

#wiki-content tr:nth-child(even) td {
	background: #fafafa;
}

/* ----------------------------------------------------------- Demo-Blöcke */

.operator-demo {
	display: flex;
	align-items: center;
	/* "safe" hält den linken Rand bei Demos erreichbar, die breiter als der Block sind */
	justify-content: safe center;
	gap: 20px;
	margin: 1.5em 0;
	padding: 15px;
	background: #f6f6f6;
	border: 1px solid #ccc;
	border-radius: 10px;
}

/* Scrollen übernimmt der Canvas-Wrap — so dürfen Tooltips seitlich aus dem
   Block herausragen, ohne dort einen Scrollbalken zu erzeugen */
.operator-demo-canvas {
	overflow-x: auto;
	max-width: 100%;
}

.operator-demo-canvas canvas {
	display: block;
	background: url(/gfx/grid-bg.png);
	border: 1px solid #ccc;
	border-radius: 6px;

	image-rendering: -moz-crisp-edges;
	image-rendering: -webkit-crisp-edges;
	image-rendering: pixelated;
	image-rendering: crisp-edges;
}

.operator-demo-error {
	padding: 10px 15px;
	background: #fdecea;
	border: 1px solid #e0b4b4;
	border-radius: 6px;
	color: #8b2e2e;
	font-size: 13px;
}

/* IO-Bedienfelder: unverdrahtete Eingänge links, Ausgänge rechts vom Canvas */

.operator-demo-ios {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.operator-demo-ios.inputs {
	align-items: flex-end;
}

.operator-demo-ios.outputs {
	align-items: flex-start;
}

.operator-demo-io {
	position: relative;
	display: flex;
	align-items: center;
	gap: 8px;
}

.operator-demo-io-label {
	font-size: 13px;
	white-space: nowrap;
}

/* Das Wert-Quadrat in den Statusfarben: rot = true (Haken), weiß = false
   (leer), blau = Bytewert (zweistelliger Hex-Code) */

.operator-demo-io-box {
	box-sizing: border-box;
	flex-shrink: 0;
	width: 20px;
	height: 20px;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 1px solid #333;
	border-radius: 4px;
	font-family: 'Courier New', Courier, monospace;
	font-size: 10px;
	font-weight: bold;
	line-height: 1;
	user-select: none;
}

.operator-demo-io-box.editable {
	cursor: pointer;
}

.operator-demo-io-box.editable:hover {
	border-color: #0080ff;
}

.operator-demo-io-box.io-false {
	background: #fff;
	color: #000;
}

.operator-demo-io-box.io-true {
	background: #f00;
	color: #fff;
	font-size: 13px;
}

.operator-demo-io-box.io-byte {
	background: #0080ff;
	color: #fff;
}

/* Aufgeklappter Regler eines Eingangs-Quadrats (-1 = false, 256 = true,
   dazwischen der Bytewert): legt sich als Rahmen auf Zeilenhöhe über die
   Zeile — Displayname, Regler und Quadrat nebeneinander. Fixed positioniert
   (op_demo.js richtet ihn am Quadrat aus), das Quadrat bleibt exakt an seinem
   Platz und der Rahmen klappt nach außen auf. */

.operator-demo-io-slider {
	position: fixed;
	z-index: 1000;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 5px 9px;
	background: #fff;
	border: 1px solid #999;
	border-radius: 6px;
	box-shadow: 0 2px 8px #00000040;
}

.operator-demo-io-slider input[type="range"] {
	display: block;
	width: 160px;
	margin: 0;
	accent-color: #0080ff;
}

/* Tooltip auf den IO-Zeilen: die Pin-Beschreibung aus data-tip — er öffnet
   seitlich nach außen, vom Canvas weg (Eingänge links, Ausgänge rechts) */

/* display: none im Ruhezustand — ein versteckter Tooltip hat keine Geometrie
   und kann darum nirgends Scroll-Überlauf erzeugen */
.operator-demo-io[data-tip]::after {
	content: attr(data-tip);
	display: none;
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	right: calc(100% + 18px);
	width: max-content;
	max-width: 240px;
	padding: 7px 11px;
	background: #333333cc;
	color: #fff;
	font-size: 12px;
	line-height: 1.4;
	white-space: normal;
	border-radius: 6px;
	box-shadow: 0 2px 8px #00000030;
	pointer-events: none;
	z-index: 10;
}

.operator-demo-io[data-tip]::before {
	content: "";
	display: none;
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	right: calc(100% + 12px);
	border: 6px solid transparent;
	border-left-color: #333333cc;
	border-right-width: 0;
	pointer-events: none;
	z-index: 10;
}

/* Ausgangszeilen: Tooltip nach rechts weg */
.operator-demo-ios.outputs .operator-demo-io[data-tip]::after {
	right: auto;
	left: calc(100% + 18px);
}

.operator-demo-ios.outputs .operator-demo-io[data-tip]::before {
	right: auto;
	left: calc(100% + 12px);
	border-left-color: transparent;
	border-left-width: 0;
	border-right: 6px solid #333333cc;
}

.operator-demo-io[data-tip]:hover::after,
.operator-demo-io[data-tip]:hover::before {
	display: block;
	animation: wiki-tip-fade 0.15s ease 0.25s backwards;
}

@keyframes wiki-tip-fade {
	from {
		opacity: 0;
	}
}
