/*
 * Oberfläche von xzeit. Bootstrap 5.3 liefert Formulare, Menü und Dialoge,
 * hier steht nur, was die Uhr selbst braucht.
 */

:root {
  --xz-bg: #000;
  --xz-fg: #fff;
  --xz-muted: rgba(255, 255, 255, 0.66);
  --xz-pause: #ffc107;
  --xz-message: #ffe08a;
  --xz-focus: #ffd54f;
  --xz-clock-font: Arial, Helvetica, "Liberation Sans", "Nimbus Sans", sans-serif;
  /*
   * Oben und unten derselbe Abstand, auch wenn das iPhone oben mehr Platz für
   * die Kamera braucht als unten: Nur so liegt die Uhr exakt in der Mitte.
   */
  --xz-safe-x: max(env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  --xz-safe-y: max(env(safe-area-inset-top, 0px), env(safe-area-inset-bottom, 0px));
  --xz-bar-h: clamp(4rem, 7vmin, 7rem);
  --bs-body-bg: var(--xz-bg);
  --bs-body-color: var(--xz-fg);
}

html,
body {
  background: var(--xz-bg);
  color: var(--xz-fg);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Bootstrap ersetzt den Fokusrahmen durch einen Schatten, der auf Schwarz kaum auffällt. */
:focus-visible,
.btn:focus-visible,
.btn-close:focus-visible,
.form-control:focus-visible,
.form-check-input:focus-visible,
.btn-check:focus-visible + .btn {
  outline: 3px solid var(--xz-focus);
  outline-offset: 2px;
}

.noscript {
  margin: 2rem auto;
  max-width: 40rem;
  padding: 1rem;
  border: 1px solid var(--xz-message);
  color: var(--xz-message);
  text-align: center;
}

/* Startseite */

.start-view {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(var(--xz-safe-y) + 1.5rem) calc(var(--xz-safe-x) + 1rem) calc(var(--xz-safe-y) + 0.5rem);
}

.start-inner {
  width: 100%;
  max-width: 26rem;
  margin: auto;
  text-align: center;
}

.start-title {
  font-size: clamp(1.6rem, 3.5vw, 2rem);
  font-weight: 400;
  margin-bottom: 1.25rem;
}

.start-title:focus {
  outline: none;
}

.start-alert {
  text-align: left;
}

/*
 * Eine schmale Spalte: oben die Wahl Übungszeit oder X-Zeit, darunter nur
 * die Felder, die dazu passen, dann der Code.
 */
.start-form {
  display: grid;
  gap: 0.75rem;
  text-align: left;
}

.start-kind {
  width: 100%;
  margin-bottom: 0.25rem;
}

.start-kind > .btn {
  flex: 1 1 0;
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
  font-size: 1.1rem;
}

.start-fields {
  display: grid;
  gap: 0.5rem;
}

.start-fields[hidden] {
  display: none;
}

.start-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.5rem;
}

/* Das Format ist Beiwerk: gedämpft und etwas kleiner (der Schalter selbst nicht, wegen iOS). */
.start-dtg {
  display: flex;
  align-items: center;
  gap: 0.5em;
  min-height: 2rem;
  margin: 0;
  color: var(--xz-muted);
}

.start-dtg .form-check-input {
  margin-top: 0;
}

.start-dtg .form-check-label {
  font-size: 0.9375rem;
}

.start-help {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  padding: 0;
  font-size: 0.9375rem;
  text-decoration: none;
  color: var(--xz-muted);
}

.start-help:hover,
.start-help:focus-visible {
  color: var(--xz-fg);
}

/* Eine leere Fehlerzeile darf keinen zweiten Abstand erzeugen. */
.start-form > .form-error {
  margin: 0;
}

.start-form > .form-error:empty {
  display: none;
}

.start-form.start-join {
  gap: 0.5rem;
  margin-top: 2rem;
}

.start-promo {
  margin-top: 2.5rem;
}

.start-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.25rem;
  margin-top: 1.5rem;
  color: var(--xz-muted);
}

/* iOS zoomt beim Fokus in Felder unter 16 px hinein und verschiebt dabei die Seite. */
.form-control,
.form-select {
  font-size: max(1rem, 16px);
}

/*
 * Alte Browser ohne Zeitfeld bekommen ein Textfeld mit Muster als Platzhalter
 * (siehe prepareInputs). Bootstrap blendet Platzhalter in Floating-Feldern aus,
 * beim Tippen soll das Muster aber zu sehen sein.
 */
.form-floating > .form-control:focus::placeholder {
  color: var(--bs-secondary-color);
}

/* Ein schwebendes Label endet am Rand seines Feldes, notfalls mit Auslassungspunkten. */
.form-floating > label {
  max-width: 100%;
}

.form-floating > .form-control:focus ~ label,
.form-floating > .form-control:not(:placeholder-shown) ~ label {
  /* Bootstrap verkleinert das Label auf 85 % und schiebt es um 0,15rem nach rechts. */
  max-width: calc(100% / 0.85 - 0.15rem);
}

.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  letter-spacing: 0.2em;
  text-transform: lowercase;
}

.form-error {
  min-height: 1.5em;
  margin: 0.25rem 0 0.75rem;
  color: #ff8a80;
}

.form-error:empty {
  min-height: 0;
  margin: 0;
}

/* Uhransicht */

.clock-view {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--xz-bar-h) minmax(0, 1fr) var(--xz-band-h, 0px) var(--xz-bar-h);
  padding: var(--xz-safe-y) var(--xz-safe-x);
  overflow: hidden;
  background: var(--xz-bg);
  color: var(--xz-fg);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.clock-view:focus {
  outline: none;
}

.clock-view.has-message {
  --xz-band-h: clamp(4.5rem, 30%, 45vh);
}

.clock-view.controls-hidden {
  cursor: none;
}

.bar {
  display: grid;
  align-items: center;
  gap: 0.25rem 0.75rem;
  min-width: 0;
  padding: 0 clamp(0.75rem, 2vw, 2.5rem);
}

/* Die Statusanzeige bekommt den Platz zwischen Echtzeit und Knöpfen und bricht notfalls um. */
.bar-top {
  grid-row: 1;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "realtime status controls";
}

.bar-bottom {
  grid-row: 4;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "share legal";
}

.realtime {
  grid-area: realtime;
  display: flex;
  flex-direction: column;
  justify-self: start;
  line-height: 1.1;
  font-family: var(--xz-clock-font);
  white-space: nowrap;
}

.realtime-label {
  font-size: clamp(0.8rem, 1.4vmin, 1.1rem);
  color: var(--xz-muted);
}

.realtime-value {
  font-size: clamp(1.1rem, 3.2vmin, 2.6rem);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.status {
  grid-area: status;
  justify-self: center;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.25rem 0.5rem;
  max-width: 100%;
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  background: rgba(255, 193, 7, 0.16);
  border: 1px solid rgba(255, 193, 7, 0.6);
  color: #ffe08a;
  font-size: 0.9rem;
  line-height: 1.3;
  text-align: center;
}

.status[data-kind="connecting"] {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.35);
  color: var(--xz-fg);
}

.status[data-kind="not_found"] {
  background: rgba(220, 53, 69, 0.2);
  border-color: rgba(255, 138, 128, 0.8);
  color: #ffd0cc;
}

.status-actions {
  display: inline-flex;
  gap: 0.5rem;
}

.status-actions .btn {
  --bs-btn-padding-y: 0.1rem;
  --bs-btn-padding-x: 0.5rem;
  --bs-btn-font-size: 0.8125rem;
}

.controls {
  grid-area: controls;
  justify-self: end;
  display: flex;
  gap: 0.5rem;
}

.icon-btn {
  width: 2.75rem;
  height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1.2rem;
}

/* Wie die Echtzeit oben: kleine Beschriftung, darunter der Wert. */
.share {
  grid-area: share;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-self: start;
  min-width: 0;
  line-height: 1.1;
}

.share-label {
  font-size: clamp(0.8rem, 1.4vmin, 1.1rem);
  color: var(--xz-muted);
  white-space: nowrap;
}

.share-value {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.code-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: clamp(1.25rem, 2.6vmin, 2rem);
  letter-spacing: 0.15em;
}

.copy-btn {
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1.35rem;
  color: var(--xz-muted);
}

.copy-btn:hover,
.copy-btn:focus-visible {
  color: var(--xz-fg);
}

.legal {
  grid-area: legal;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--xz-muted);
}

.legal .btn-link,
.start-footer .btn-link {
  padding: 0.25rem;
  font-size: 0.9rem;
}

/* Die Bedienelemente blenden aus, nehmen aber weiter ihren Platz ein: Nichts verschiebt die Uhr. */
.auto-hide {
  transition: opacity 0.2s ease, visibility 0s linear 0s;
}

.clock-view.controls-hidden .auto-hide {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s ease, visibility 0s linear 0.6s;
}

.stage {
  grid-row: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/*
 * Die Uhr. --xz-clock-size setzt js/ui/clock-display.js passend zur Fläche.
 * Beschriftung oben und Zeile unten hängen absolut am Zeitblock, damit allein
 * der Zeitblock zentriert wird.
 */
.display {
  --xz-clock-size: 12vmin;
  --xz-gap: calc(var(--xz-clock-size) * 0.1);
  position: relative;
  font-family: var(--xz-clock-font);
  font-size: var(--xz-clock-size);
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  font-kerning: none;
}

/*
 * Der Kasten der Zeit ist so hoch wie die Ziffern selbst (Werte aus der
 * Schriftvermessung). So sitzen die sichtbaren Ziffern mittig und nicht die
 * Zeilenbox mit Ober- und Unterlänge.
 */
.time {
  height: calc(var(--xz-glyph-h, 1) * 1em);
}

.time-inner {
  position: relative;
  top: calc(var(--xz-glyph-top, 0) * -1em);
  display: block;
  line-height: 1;
}

.time-small {
  font-size: 0.5em;
}

/* Sitzt auf der Grundlinie, daraus ergibt sich die Lage der Ziffern. */
.baseline-probe {
  display: inline-block;
  width: 0;
  height: 0;
  vertical-align: baseline;
}

.display-caption,
.display-sub {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  line-height: 1.2;
  white-space: nowrap;
  text-align: center;
}

.display-caption {
  bottom: calc(100% + var(--xz-gap));
  font-size: max(0.85rem, 0.1em);
  color: var(--xz-muted);
}

.display-sub {
  top: calc(100% + var(--xz-gap));
  min-height: 1.2em;
  font-size: max(1rem, 0.17em);
}

/* Unter der X-Zeit nur bei sehr großen Werten eine dezente Notiz ("2 Tage 03:15 h nach X"). */
.display-sub.is-note {
  font-size: max(0.8rem, 0.07em);
  color: var(--xz-muted);
}

.display-caption .bi {
  margin-right: 0.3em;
}

.clock-view.is-paused .display-caption {
  color: var(--xz-pause);
}

@media (prefers-reduced-motion: reduce) {
  .auto-hide,
  .clock-view.controls-hidden .auto-hide {
    transition: none;
  }
}

.clock-view.is-stale .time {
  opacity: 0.5;
}

/* Noch kein Zustand vom Server: Platzhalter nur angedeutet. */
.clock-view.is-empty .time {
  opacity: 0.3;
}

.message-band {
  grid-row: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  padding: 0.5rem clamp(0.75rem, 3vw, 3rem);
  border-top: 1px solid rgba(255, 224, 138, 0.35);
  overflow: hidden;
}

.message-band.is-overflowing {
  align-items: flex-start;
  overflow-y: auto;
}

.message-text {
  max-width: 100%;
  margin: 0;
  font-size: var(--xz-message-size, 2rem);
  line-height: 1.2;
  color: var(--xz-message);
  text-align: center;
  white-space: pre-line;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.app-toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--xz-safe-y) + var(--xz-bar-h) + 0.5rem);
  transform: translateX(-50%);
  max-width: min(36rem, calc(100% - 2rem));
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  background: #2b1a1a;
  border: 1px solid #ff8a80;
  color: #ffd0cc;
  text-align: center;
  z-index: 10;
}

/* Schmal: kürzere Beschriftung und kleinere Statusanzeige, damit die Leisten reichen. */
@media (max-width: 899.98px) {
  .share-label-long {
    display: none;
  }

  .status {
    font-size: 0.8125rem;
    padding: 0.15rem 0.5rem;
  }
}

/*
 * Handy hochkant: Leisten zweizeilig, damit die Statusanzeige Platz hat. Quer
 * bleibt es einzeilig, sonst bliebe für die Uhr kaum Höhe übrig.
 */
@media (max-width: 599.98px) and (min-height: 500px) {
  .clock-view {
    --xz-bar-h: 7.5rem;
  }

  .bar-top {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "realtime controls"
      "status status";
    align-content: center;
  }

  .status {
    justify-self: center;
  }

  .bar-bottom {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "share"
      "legal";
    align-content: center;
    justify-items: center;
  }

  .share {
    justify-self: center;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
  }
}

/*
 * Menü: ein schmales Panel am Zahnrad statt einer Leiste über die ganze
 * Höhe. Technisch bleibt es ein Bootstrap-Offcanvas (Fokus bleibt im Menü,
 * Escape und Tipp daneben schließen). Es wird nur so hoch wie sein Inhalt
 * und scrollt, wenn der Platz nicht reicht, etwa auf dem Handy quer.
 */
.menu.offcanvas-end {
  --bs-offcanvas-width: min(22.5rem, calc(100vw - 1rem));
  --bs-offcanvas-bg: #17191c;
  --xz-menu-gap: 0.5rem;
  top: calc(env(safe-area-inset-top, 0px) + 0.5rem);
  right: calc(env(safe-area-inset-right, 0px) + 0.5rem);
  bottom: auto;
  height: auto;
  max-height: calc(100vh - 1rem);
  max-height: calc(100dvh - 1rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 0.75rem;
  box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, 0.6);
  transform: translateX(calc(100% + 1rem + env(safe-area-inset-right, 0px)));
}

.menu.offcanvas-end.showing,
.menu.offcanvas-end.show:not(.hiding) {
  transform: none;
}

.menu .offcanvas-body {
  padding: 0.75rem 1rem;
  overscroll-behavior: contain;
}

.offcanvas-backdrop.show {
  opacity: 0.3;
}

.menu-section {
  display: grid;
  gap: var(--xz-menu-gap);
  padding: 0.625rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.menu-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.menu-section:last-child {
  padding-bottom: 0;
}

.menu-line {
  display: flex;
  align-items: stretch;
  gap: var(--xz-menu-gap);
  min-width: 0;
}

.menu-line > .btn {
  flex: 0 0 auto;
  padding-left: 0.6rem;
  padding-right: 0.6rem;
}

/* Etwas weniger Innenabstand als sonst, damit die Labels in die schmalen Felder passen. */
.menu .form-floating > .form-control,
.menu .form-floating > label {
  padding-left: 0.625rem;
  padding-right: 0.625rem;
}

.menu-line > .menu-grow {
  flex: 1 1 0;
  min-width: 0;
}

/*
 * Die Dreierwahl der Darstellung wirkt wie Registerkarten: Darunter stehen
 * nur die Felder, die zur gewählten Darstellung gehören.
 */
.menu-panel {
  display: grid;
  gap: var(--xz-menu-gap);
}

/* Auf sehr schmalen Handys darf eine Registerkarte umbrechen. */
.mode-group {
  width: 100%;
}

.mode-group > .btn {
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.4rem;
  font-size: 0.9375rem;
  line-height: 1.2;
}

.menu-help,
.menu-line > .menu-help {
  width: 2.5rem;
  height: 2.5rem;
  align-self: center;
  padding: 0;
  font-size: 1.2rem;
  color: var(--xz-muted);
}

.menu-help:hover,
.menu-help:focus-visible {
  color: var(--xz-fg);
}

.pause-btn {
  height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.menu-head .btn-close {
  align-self: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  background-size: 0.9rem;
}

/* Einzeilig wie ein Feld; wer mehr schreibt, zieht es größer (Umschalt+Enter macht eine neue Zeile). */
.form-floating > .form-control.message-input {
  resize: vertical;
}

.menu-icon {
  font-size: 1.15rem;
}

.xtime-sign > .btn {
  display: inline-flex;
  align-items: center;
  padding-left: 0.55rem;
  padding-right: 0.55rem;
  font-family: var(--xz-clock-font);
  font-size: 1.1rem;
}

.menu-line > .xtime-minutes {
  min-width: 3.25rem;
}

.xtime-seconds {
  flex: 0 0 3.5rem;
}

.form-floating > .xtime-field {
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  font-family: var(--xz-clock-font);
  font-variant-numeric: tabular-nums;
}

.form-floating > .xtime-field ~ label {
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.xtime-colon {
  align-self: center;
  font-size: 1.3rem;
}

/* Sehr schmale Handys: etwas enger, damit jede Zeile in die Breite passt. */
@media (max-width: 359.98px) {
  .menu.offcanvas-end {
    --xz-menu-gap: 0.375rem;
  }

  .menu .offcanvas-body {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .menu-line > .btn {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .xtime-sign > .btn {
    padding-left: 0.4rem;
    padding-right: 0.4rem;
  }

  .menu-line > .xtime-minutes {
    min-width: 2.75rem;
  }

  .xtime-seconds {
    flex-basis: 3rem;
  }
}

.leave-btn {
  font-size: 1.25rem;
  padding-top: 0.2rem;
  padding-bottom: 0.2rem;
}

/* Zeichenzähler und Hinweis zum Bildschirm erscheinen nur, wenn sie etwas zu sagen haben. */
.menu-count,
.menu-note {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--xz-muted);
}

.menu-count {
  margin-top: -0.25rem;
  text-align: right;
}

.menu-count.is-over {
  color: #ff8a80;
}

.menu-feedback {
  margin: 0;
  font-size: 0.875rem;
}

.menu-feedback:empty {
  display: none;
}

.menu-feedback.is-error {
  color: #ff8a80;
}

/*
 * Erfolg zeigt der Knopf selbst (kurz grün, Symbole werden zum Haken). Die
 * Meldung bleibt für Screenreader im Dokument, nimmt aber keinen Platz ein.
 */
.menu-feedback.is-ok {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.btn.is-done {
  background-color: var(--bs-success);
  border-color: var(--bs-success);
  color: #fff;
}

.btn.is-done .bi::before {
  content: "\f633";
}

.copy-btn.is-done {
  background-color: transparent;
  border-color: transparent;
  color: #9be7a5;
}

.btn.is-busy {
  cursor: progress;
  opacity: 0.7;
}

.modal-content {
  background: #16181b;
}
