:root {
  --bg-dark: linear-gradient(135deg, #1e1e2f, #2b2b45);
  --bg-light: linear-gradient(135deg, #f0f0f0, #ffffff);
  --text-dark: #fff;
  --text-light: #000;
  --card-dark: #4cafef;
  --card-light: #e0e0e0;
  --status-dark: #00000050;
  --status-light: #ffffffaa;
  --brightness: 1;
  --speed: 0.3s;
}

html, body, .screen {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: sans-serif;
  overflow: hidden;
  transition: var(--speed);
}

body {
  background: var(--bg-dark);
  color: var(--text-dark);
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  font-size: 16px;
}

body.light {
  background: var(--bg-light);
  color: var(--text-light);
}

#bootscreen {
  position: fixed;
  inset: 0;
  background: black;
  z-index: 20000;
}

#bootscreen iframe {
  width: 100%;
  height: 100%;
  border: none;
}

#brightnessLayer {
  position: fixed;
  inset: 0;
  background: black;
  pointer-events: none;
  z-index: 5000;
  opacity: calc(1 - var(--brightness));
  transition: 0.2s;
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  position: relative;
  padding-bottom: 80px;
  box-sizing: border-box;
}

.status {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--status-dark);
  position: absolute;
  top: 0;
  z-index: 10;
  font-size: 0.9em;
  box-sizing: border-box;
}

body.light .status {
  background: var(--status-light);
}

/* FIX: Grid-Layout korrigiert */
.app-grid {
  margin-top: 60px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: min-content; /* Verhindert, dass Zeilen sich strecken */
  gap: 10px; /* Etwas mehr Platz zwischen den Apps */
  width: 100%;
  padding: 0 15px;
  box-sizing: border-box;
  overflow-y: auto;
  max-height: calc(100% - 100px);
  scrollbar-width: none;
}

.app-grid::-webkit-scrollbar {
  display: none;
}

/* FIX: .app-Klasse stabilisiert */
.app {
  width: 100%;
  aspect-ratio: 1 / 1; 
  height: auto; /* Wichtig: Überschreibt automatische Streckung */
  border-radius: 15px;
  background: var(--card-dark);
  color: black;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  font-size: 0.75em;
  overflow: hidden;
  padding: 5px;
  box-sizing: border-box; /* Padding wird in die Größe eingerechnet */
  transition: transform var(--speed), background var(--speed);
}

body.light .app {
  background: var(--card-light);
}

button, input, textarea, select {
  width: 80%;
  padding: 10px;
  margin: 6px;
  border: none;
  border-radius: 10px;
  user-select: auto;
  font-size: 1em;
}

textarea {
  height: 140px;
}

.message {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 10px 20px;
  border-radius: 10px;
  z-index: 10000;
  display: none;
  font-size: 16px;
  text-align: center;
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

.switch input {
  display: none;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ccc;
  transition: .4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background: #4cafef;
}

input:checked + .slider:before {
  transform: translateX(22px);
}

input:disabled + .slider {
  opacity: 0.5;
  cursor: not-allowed;
}

#homeButton {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 50px;
  height: 50px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  z-index: 999999;
  cursor: pointer;
  display: none;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(5px);
}

#homeButton::after {
  content: "";
  width: 18px;
  height: 18px;
  border: 2px solid white;
  border-radius: 4px;
}

.no-anim * {
  transition: none !important;
  animation: none !important;
}

iframe {
  background: #FFF;
}
/* Home Button Anpassung für den Light Mode */
body.light #homeButton {
    background: rgba(0, 0, 0, 0.1); /* Ein leichter dunkler Schleier */
    border-color: rgba(0, 0, 0, 0.3); /* Dunklerer Rand */
}

body.light #homeButton::after {
    border-color: #000; /* Das innere Quadrat wird schwarz */
}