/* Darstellung. Die Zustandsfarben setzt app.js als --hintergrund/--vordergrund. */

:root {
  --hintergrund: #0000ff;
  --vordergrund: #ffffff;

  --panel: #ffffff;
  --panel-text: #1a1a1a;
  --panel-leise: #5c5c5c;
  --linie: #cfcfcf;
  --akzent: #1a1a1a;
  --fehler: #b00020;
  --fokus: #005fcc;

  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

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

html, body {
  margin: 0;
  height: 100%;
  min-height: 100lvh; /* groesster Viewport, auch bei eingefahrener Leiste */
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--hintergrund);
  color: var(--vordergrund);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* Uebergrosse Farbflaeche hinter allem: deckt auch Bereiche ab, die der
   Viewport nicht zuverlaessig erfasst (Home-Indikator, einfahrende
   Browserleisten, Gummiband-Scrollen). Sonst blitzt dort eine Fremdfarbe. */
body::before {
  content: "";
  position: fixed;
  inset: -50vh -50vw;
  z-index: -1;
  background: var(--hintergrund);
}

/* Hauptansicht: immer der ganze Viewport, inklusive Notch-Bereich. */
.flaeche {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(1.5rem, env(safe-area-inset-top))
    max(1.5rem, env(safe-area-inset-right))
    max(1.5rem, env(safe-area-inset-bottom))
    max(1.5rem, env(safe-area-inset-left));
  background: var(--hintergrund);
  user-select: none;
  -webkit-user-select: none;
}

.anzeigetext {
  margin: 0;
  max-width: 100%;
  font-size: clamp(2rem, 9vmin, 6rem);
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.restzeit {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  margin: 0;
  font-size: clamp(1.25rem, 5vmin, 2rem);
  font-variant-numeric: tabular-nums;
  text-align: center;
  opacity: 0.75;
}

.zahnrad {
  position: fixed;
  top: max(0.5rem, env(safe-area-inset-top));
  right: max(0.5rem, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--vordergrund);
  opacity: 0.4;
  cursor: pointer;
}

.zahnrad:hover { opacity: 0.75; }

.zahnrad:focus-visible {
  opacity: 1;
  outline: 2px solid var(--vordergrund);
  outline-offset: 2px;
}

/* Einstellungen */

.dialog {
  width: min(28rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  color: var(--panel-text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  overflow: auto;
  overscroll-behavior: contain;
}

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

.formular {
  padding: 1.25rem 1.25rem 1rem;
  font-size: 1rem;
}

.formular__titel {
  margin: 0 0 1rem;
  font-size: 1.2rem;
  font-weight: 600;
}

.gruppe {
  margin: 0 0 1rem;
  padding: 0.75rem 0.9rem 0.25rem;
  border: 1px solid var(--linie);
  border-radius: 8px;
}

.gruppe legend {
  padding: 0 0.35rem;
  font-weight: 600;
}

.gruppe label { display: block; margin-bottom: 0.3rem; }

.zeile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.zeile label { margin: 0; }

.zeile input[type="text"] { flex: 1; min-width: 0; }

input[type="text"] {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid #8a8a8a;
  border-radius: 6px;
  background: #fff;
  color: var(--panel-text);
  font: inherit;
  font-size: max(1rem, 16px); /* verhindert Zoom bei Fokus in iOS */
}

/* Farbwaehler */

.farbe {
  display: flex;
  gap: 0.5rem;
}

.farbe__muster {
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid #8a8a8a;
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px #fff;
  cursor: pointer;
  /* Schachbrett zeigt "keine gueltige Farbe" */
  background-image: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%);
  background-size: 12px 12px;
}

.farbe__muster:focus-visible {
  outline: 2px solid var(--fokus);
  outline-offset: 2px;
}

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

input.farbe__hex {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.waehler {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.6rem;
  padding: 0.75rem;
  border: 1px solid var(--linie);
  border-radius: 8px;
  background: #fafafa;
}

.waehler__feld {
  --farbton: hsl(240 100% 50%);
  position: relative;
  height: 9rem;
  border-radius: 6px;
  background:
    linear-gradient(to top, #000, transparent),
    linear-gradient(to right, #fff, var(--farbton));
  cursor: crosshair;
  touch-action: none;
}

.waehler__feld:focus-visible {
  outline: 2px solid var(--fokus);
  outline-offset: 2px;
}

.waehler__punkt {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.waehler__farbton {
  width: 100%;
  height: 14px;
  margin: 0;
  border-radius: 7px;
  background: linear-gradient(to right,
    #f00 0%, #ff0 16.7%, #0f0 33.3%, #0ff 50%, #00f 66.7%, #f0f 83.3%, #f00 100%);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.waehler__farbton::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
  -webkit-appearance: none;
}

.waehler__farbton::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}

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

.waehler__schnell {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.4rem;
}

.waehler__farbe {
  aspect-ratio: 1;
  min-height: 32px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  cursor: pointer;
}

.waehler__farbe[aria-pressed="true"] {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--akzent);
}

.waehler__farbe:focus-visible {
  outline: 2px solid var(--fokus);
  outline-offset: 2px;
}

input[aria-invalid="true"] {
  border-color: var(--fehler);
  box-shadow: 0 0 0 1px var(--fehler);
}

input:focus-visible,
.knopf:focus-visible {
  outline: 2px solid var(--fokus);
  outline-offset: 2px;
}

.gruppe .schalter {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.25rem 0 0.75rem;
  cursor: pointer;
}

.schalter input {
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  accent-color: var(--akzent);
}

.dauer {
  display: grid;
  grid-template-columns: 1fr 5.5rem 5.5rem;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.dauer__titel { font-weight: 500; }

.gruppe .dauer__feld {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
  color: var(--panel-leise);
  font-size: 0.9rem;
}

.dauer__feld input { text-align: right; }

.fehler {
  min-height: 1.1rem;
  margin: 0.2rem 0 0.5rem;
  color: var(--fehler);
  font-size: 0.85rem;
}

.hinweis {
  margin: 0 0 0.75rem;
  color: var(--panel-leise);
  font-size: 0.85rem;
  line-height: 1.4;
}

.hinweis--vorgabe {
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

/* Rollen: app.js setzt data-rolle / data-darf-aendern am Dialog. */
.dialog[data-rolle="user"] .nur-admin,
.dialog[data-darf-aendern="false"] .nur-bearbeiten,
.dialog[data-darf-aendern="true"] .nur-vorgabe {
  display: none !important;
}

.meldung {
  min-height: 1.1rem;
  margin: 0.4rem 0 0.75rem;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.fehler--speichern { min-height: 0; margin: 0 0 0.5rem; }

.aktionen {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.installieren {
  display: block;
  margin: 0.75rem auto 0;
  padding: 0.5rem;
  border: 0;
  background: none;
  color: var(--panel-leise);
  font: inherit;
  font-size: 0.9rem;
  text-decoration: underline;
  cursor: pointer;
}

.installieren:focus-visible {
  outline: 2px solid var(--fokus);
  outline-offset: 2px;
}

.knopf {
  min-height: 44px;
  padding: 0.55rem 1rem;
  border: 1px solid var(--akzent);
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}

.knopf--haupt { background: var(--akzent); color: #fff; }
.knopf--neben { background: #fff; color: var(--akzent); }
.knopf--neben:hover { background: #f0f0f0; }

@media (max-width: 360px) {
  .dauer { grid-template-columns: 1fr 1fr; }
  .dauer__titel { grid-column: 1 / -1; }
}
