/* Interaktive Bauanleitung - Optik an gedruckte LEGO-Anleitungen angelehnt */

:root {
  --dark:  #26292f;
  --gray:  #74787e;
  --light: #e0e3e6;
  --accent:#cc1a1a;
  --note:  #8c6b0d;
  --box:   #f7f7fa;
  --hl:    #ffcd00;   /* Markierungsfarbe wie im PDF */
  --sel:   #33aaff;   /* Auswahl aus der Teileleiste (hellblau) */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #ffffff;
  color: var(--dark);
  font-family: "Segoe UI", Tahoma, Verdana, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#gl {
  position: fixed;
  left: 0; top: 0;
  width: 100%; height: 100%;
  display: block;
  z-index: 0;
}

#ui {
  position: fixed;
  left: 0; top: 0; right: 0; bottom: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

/* ------------------------------------------------------------- Kopfzeile */
#header { flex: 0 0 auto; }

.hdr {
  background: var(--dark);
  color: #fff;
  height: 46px;
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 14px;
}
.hdr-title {
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hdr-sub {
  margin-left: auto;
  font-size: 13px;
  font-weight: 400;
  opacity: .8;
  white-space: nowrap;
}
.badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  border-radius: 6px;
  padding: 4px 14px;
  white-space: nowrap;
}
.hdr-cover { height: 70px; }
.hdr-cover .hdr-title { font-size: 28px; }

/* --------------------------------------------------------------- Inhalt */
#content {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 10px 22px 4px 22px;
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;   /* Touch-Gesten macht app.js (drehen/zoomen/tippen) */
}
.stage.dragging { cursor: grabbing; }

.pagetitle {
  font-size: 20px;
  font-weight: 700;
  margin: 6px 0 10px 2px;
}

/* Schrittnummer + Callout */
.steprow {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.stepno {
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
  padding-top: 16px;
  min-width: 50px;
  text-align: right;
  color: var(--dark);
}
/* Die Callout-Box darf KEINEN deckenden Hintergrund haben: die Bauteile
 * darin werden live auf dem darunterliegenden Canvas gezeichnet. */
.callout {
  flex: 1 1 auto;
  background: none;
  border: 1px solid var(--light);
  border-radius: 7px;
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;      /* nie nach rechts clippen: Zellen brechen um */
  align-items: flex-start;
  gap: 6px;
  min-height: 124px;
  overflow: hidden;
}
.co-item {
  flex: 0 1 176px;
  min-width: 92px;
  text-align: center;
  font-size: 13px;
  color: var(--gray);
  line-height: 1.2;
  /* die ganze Zelle ist anklickbar (markiert die Teile im Bild) */
  pointer-events: auto;
  cursor: pointer;
  border-radius: 4px;
}
.co-item:hover { outline: 2px solid rgba(51, 170, 255, .45); outline-offset: 2px; }
/* drehbare 3D-Flaeche einer Callout-Zelle (Scissor-Rendering) */
.co-view {
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
}
.co-view:active { cursor: grabbing; }
.co-item .co-view {
  display: block;
  width: 100%;
  height: 104px;
  margin: 0 auto 2px auto;
}
.co-item .cnt {
  font-size: 15px;
  font-weight: 700;
  color: var(--dark);
}
.co-sub {
  display: flex;
  align-items: center;
  gap: 18px;
  flex: 0 0 auto;
  padding-right: 20px;
  margin-right: 12px;
  border-right: 1px solid var(--light);
}
.co-sub .co-view {
  flex: 0 0 auto;
  width: 236px;
  height: 148px;
}
.co-sub .cnt { font-size: 17px; font-weight: 700; }
.co-sub .subno { font-size: 19px; font-weight: 700; color: var(--dark); }
.co-sub .lnk {
  font-size: 19px;
  font-weight: 700;
  color: var(--dark);
  text-decoration: none;
  border-bottom: 1px dotted var(--gray);
  cursor: pointer;
  pointer-events: auto;
}
.co-sub .lnk:hover { color: var(--accent); border-color: var(--accent); }
.co-sub .nm { font-size: 14px; color: var(--gray); }

/* Im Bild angeklicktes Bauteil: outline statt border, damit nichts umbricht */
.co-hl {
  outline: 3px solid var(--hl);
  outline-offset: 2px;
  border-radius: 4px;
  background: rgba(255, 205, 0, .16);
}
/* In der Teileleiste ausgewaehltes Bauteil (im Bild hellblau umrandet).
 * Steht bewusst NACH .co-hl: die Auswahl gewinnt, wenn beides zutrifft. */
.co-sel {
  outline: 3px solid var(--sel);
  outline-offset: 2px;
  border-radius: 4px;
  background: rgba(51, 170, 255, .16);
}
.co-sel .cnt { color: #0a72c4; }

/* Farbfeld + Farbname (Teileleiste und Baugruppen-Teilelisten) */
.col-tag {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 12px;
  color: var(--gray);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-tag i {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  border: 1px solid rgba(0, 0, 0, .35);
  border-radius: 2px;
}

/* Hinweistext bewusst gross: doppelte Groesse der urspruenglichen 12px */
.note {
  flex: 0 0 auto;
  color: var(--note);
  font-style: italic;
  font-size: 24px;
  line-height: 1.25;
  margin: 8px 0 0 62px;
}

/* ------------------------------------------------------- Uebersichtsraster */
.grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  gap: 8px;
}
/* WICHTIG: Kacheln duerfen KEINEN Hintergrund haben - sie liegen ueber dem
 * Canvas, ein opaker Hintergrund wuerde die 3D-Darstellung verdecken.
 * Rueckmeldung beim Ueberfahren daher nur ueber die Rahmenfarbe. */
.tile {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 2px;
}
.tile:hover { border-color: var(--accent); }
.tile:hover .tile-lbl { color: var(--accent); }
.tileview {
  flex: 1 1 auto;
  min-height: 0;
  pointer-events: auto;
  cursor: pointer;
  touch-action: none;
}
.tile-lbl {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: auto;
  cursor: pointer;
}
.tile-sub {
  flex: 0 0 auto;
  font-size: 10px;
  color: var(--gray);
}

/* --------------------------------------------- Startseite einer Baugruppe */
.chaprow {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 16px;
}
.chapleft, .chapright {
  flex: 1 1 50%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.chapright { flex: 1 1 52%; }
.chaphint {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--gray);
  margin-bottom: 4px;
}

/* Raster der Bauteil-Zellen (Startseite und Folgeseiten) */
.plgrid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  gap: 8px;
}
.pl-cell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  text-align: center;
  border: 1px solid var(--light);
  border-radius: 6px;
  padding: 3px;
}
/* live gerenderte, dreh- und zoombare 3D-Flaeche der Zelle */
.pl-view {
  flex: 1 1 auto;
  min-height: 0;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
}
.pl-view:active { cursor: grabbing; }
.pl-cnt {
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 700;
}
.pl-cnt span { font-weight: 400; color: var(--gray); font-size: 11px; margin-left: 6px; }
.pl-desc {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--gray);
  line-height: 1.15;
  max-height: 26px;
  overflow: hidden;
}

/* Zellen fuer Baugruppen, die vorher gebaut werden muessen: abgesetzt vom
 * Rest der Liste, Name und Bild fuehren zu ihrer eigenen Seite.
 * ACHTUNG: kein Hintergrund - die Zellen sind durchsichtig, das 3D-Bild
 * kommt vom Canvas DAHINTER. Ein Hintergrund wuerde es verdecken. */
.pl-sub {
  border: 2px solid var(--dark);
}
.pl-sub .pl-desc { color: var(--dark); font-weight: 700; }
.pl-link { cursor: pointer; pointer-events: auto; }
.pl-link:hover { text-decoration: underline; }
.pl-note {
  flex: 0 0 auto;
  font-size: 10px;
  color: var(--accent);
  line-height: 1.3;
}

/* Teileliste */
.bom-cell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.bom-cell img {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  object-fit: contain;
  background: #fff;
}
.bom-cnt { font-size: 12px; font-weight: 700; }
.bom-cnt span { font-weight: 400; color: var(--gray); font-size: 10px; margin-left: 6px; }
.bom-desc {
  font-size: 10px;
  color: var(--gray);
  line-height: 1.15;
  max-height: 24px;
  overflow: hidden;
}
.bom-cell .col-tag { font-size: 10px; justify-content: flex-start; }
.bom-cell .col-tag i { width: 9px; height: 9px; }

/* (Teilezahl und Baugruppen stehen in der Kopfzeile der Startseite.) */

/* ------------------------------------------------------ Navigationsleiste */
/* Sitzt direkt unter der Kopfzeile; alles auf EINER Zeile, vertikal zentriert */
#navbar {
  flex: 0 0 auto;
  height: auto;
  min-height: 60px;
  display: flex;
  flex-wrap: wrap;      /* schmales Fenster: umbrechen statt abschneiden */
  align-items: center;
  padding: 6px 18px;
  font-size: 14px;
  color: var(--gray);
  gap: 4px 14px;
  border-bottom: 1px solid var(--light);
}
.nav-left, .nav-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nav-right { margin-left: auto; }  /* auch in einer eigenen Zeile rechtsbuendig */
.nav-mid { flex: 1 1 auto; text-align: center; }
.nav-right { justify-content: flex-end; }
.nav-info {
  font-size: 13px;
  color: var(--gray);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.navbtn {
  pointer-events: auto;
  width: 42px; height: 36px;
  border: 1px solid var(--light);
  background: #fff;
  color: var(--dark);
  border-radius: 6px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.navbtn:hover { background: var(--dark); color: #fff; }
.txtbtn {
  pointer-events: auto;
  border: 1px solid var(--light);
  background: #fff;
  color: var(--dark);
  border-radius: 6px;
  font-size: 14px;
  padding: 8px 14px;
  cursor: pointer;
}
.txtbtn:hover { background: var(--dark); color: #fff; }
#jump {
  pointer-events: auto;
  max-width: 320px;
  min-width: 0;
  flex: 0 1 auto;       /* darf schrumpfen, statt die Zeile zu sprengen */
  font-size: 14px;
  border: 1px solid var(--light);
  border-radius: 6px;
  background: #fff;
  color: var(--dark);
  padding: 6px 8px;
}

/* Bei schmalen Fenstern hat der Bedienhinweis die geringste Prioritaet.
 * Unter ~1260px reicht der Platz in der Mitte nicht mehr fuer den ganzen
 * Text, dann lieber ganz weg als abgeschnitten. */
@media (max-width: 1300px) {
  #nav-hint { display: none; }
}

#splash {
  position: fixed;
  left: 0; top: 0; right: 0; bottom: 0;
  z-index: 5;
  background: #fff;
  color: var(--gray);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}
#splash.hidden { display: none; }

.err {
  padding: 40px;
  font-size: 15px;
  color: var(--accent);
}

/* ------------------------------------------------------------- Mobil
 * Schmale Fenster (Telefon): die Teileleiste oben so dicht wie moeglich,
 * kleinere Kopf- und Navigationszeile. Am Seitenmodell aendert sich
 * nichts - nur Groessen und Abstaende. */
@media (max-width: 720px) {
  #content { padding: 4px 8px 2px 8px; }
  .steprow { gap: 6px; }
  .stepno { font-size: 22px; min-width: 26px; padding-top: 6px; }
  .callout { padding: 4px 6px; gap: 4px; min-height: 0; }
  .co-item { flex: 0 1 96px; min-width: 68px; font-size: 11px; }
  .co-item .co-view { height: 64px; }
  .co-item .cnt { font-size: 13px; }
  .col-tag { font-size: 10px; }
  .co-sub { gap: 8px; padding-right: 8px; margin-right: 4px; }
  .co-sub .co-view { width: 130px; height: 86px; }
  .co-sub .cnt { font-size: 14px; }
  .co-sub .lnk { font-size: 15px; }
  .co-sub .nm { font-size: 11px; }
  .note { font-size: 15px; margin: 4px 0 0 8px; }
  .pagetitle { font-size: 16px; margin: 4px 0 6px 2px; }
  .hdr { height: 40px; padding: 0 10px; gap: 8px; }
  .hdr-title { font-size: 14px; }
  .hdr-sub { font-size: 11px; }
  .badge { font-size: 13px; padding: 3px 10px; }
  .hdr-cover { height: 54px; }
  .hdr-cover .hdr-title { font-size: 20px; }
  #navbar { padding: 4px 8px; gap: 4px 8px; min-height: 0; }
  .navbtn { width: 36px; height: 32px; font-size: 18px; }
  .txtbtn { font-size: 12px; padding: 6px 8px; }
  #jump { max-width: 42vw; font-size: 12px; padding: 4px 6px; }
  .nav-info { font-size: 11px; }
}
