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

/* hidden-Attribut darf nicht von display:flex/grid Regeln ueberschrieben werden */
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  color-scheme: light dark;
}
html, body { margin: 0; padding: 0; min-height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans", sans-serif,
               "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  background: var(--bg);
  color: var(--text);
  transition: background-color .25s ease, color .25s ease;
}

img, video { display: block; max-width: 100%; }
img { height: auto; }

button {
  font: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
}
input, select {
  font: inherit;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ---------- Tokens ---------- */
:root {
  --bg:           #f7f5f0;
  --bg-elev:      #ffffff;
  --border:       #e4e0d6;
  --input-bg:     #ffffff;
  --text:         #0d1424;
  --text-muted:   #5a6175;
  --accent:       #8a7559;
  --accent-fg:    #ffffff;
  --accent-hover: #6f5d44;
  --danger:       #b3261e;
  --danger-bg:    #fde8e7;
  --focus-ring:   #8a7559;
  --preview-bg:   #1a1d27;
  --shadow-sm:    0 1px 2px rgba(13, 20, 36, .06);
  --shadow:       0 1px 2px rgba(13, 20, 36, .06),
                  0 8px 24px rgba(13, 20, 36, .08);
  --shadow-lg:    0 1px 2px rgba(13, 20, 36, .06),
                  0 24px 60px rgba(13, 20, 36, .18);
  --radius:       .85rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #0d1424;
    --bg-elev:      #141c30;
    --border:       #232c44;
    --input-bg:     #141c30;
    --text:         #e9e9ea;
    --text-muted:   #9aa3b8;
    --accent:       #b09e80;
    --accent-fg:    #0d1424;
    --accent-hover: #c4b393;
    --danger:       #f87171;
    --danger-bg:    rgba(248, 113, 113, .12);
    --focus-ring:   #b09e80;
    --preview-bg:   #050912;
    --shadow-sm:    0 1px 2px rgba(0, 0, 0, .35);
    --shadow:       0 1px 2px rgba(0, 0, 0, .35),
                    0 12px 32px rgba(0, 0, 0, .45);
    --shadow-lg:    0 1px 2px rgba(0, 0, 0, .35),
                    0 30px 80px rgba(0, 0, 0, .6);
  }
}

/* ---------- Layout ---------- */
main, .host-main {
  margin: 0 auto;
  padding: clamp(1.5rem, 5vh, 3rem) 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 100dvh;
  min-height: 100vh;
}

/* Gast-Seite: groessere Vorschau */
body.guest main { max-width: 760px; }

/* Host-Seite: kompakter fuer Forms */
body.host main { max-width: 560px; }

.brand {
  display: flex;
  justify-content: center;
  margin-bottom: clamp(1.25rem, 3vh, 2rem);
}
.logo {
  width: clamp(220px, 60vw, 300px);
  height: auto;
  image-rendering: -webkit-optimize-contrast;
}

/* ---------- Card ---------- */
.card {
  padding: 1.25rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.host-section { margin: 0; }
.host-section + .host-section { margin-top: 1rem; }
.host-h1 { font-size: 1.5rem; margin: 0 0 1rem; font-weight: 600; }
.host-h2 { font-size: 1.1rem; margin: 0 0 .5rem; font-weight: 600; }

.host-actions {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}
.text-link {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  text-decoration: underline;
  font-size: .9rem;
  padding: .25rem .5rem;
}
.text-link:hover { color: var(--text); }

/* Link-Display */
.link-result {
  margin-top: 1rem;
  padding: .85rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: .65rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
}
.link-display {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .9rem;
  word-break: break-all;
  color: var(--text);
}
.link-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.link-actions .cta, .link-actions .secondary {
  flex: 1 1 auto;
  text-align: center;
  text-decoration: none;
}

/* ---------- Invite-Required (minimal) ---------- */
.invite-required {
  display: flex;
  justify-content: center;
  padding: 2rem 1rem;
}
.invite-required p {
  margin: 0;
  color: var(--text-muted);
  font-size: 1rem;
  letter-spacing: .005em;
}

/* ---------- Meeting beendet ---------- */
.meeting-ended {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 3rem 1.5rem;
  gap: .75rem;
}
.meeting-ended h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 500;
  letter-spacing: -.005em;
}
.meeting-ended p {
  margin: 0;
  color: var(--text-muted);
  font-size: 1rem;
  max-width: 38ch;
}

/* ---------- Prejoin ---------- */
.prejoin {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.prejoin-header {
  min-height: 2.4rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

.greeting {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 500;
  letter-spacing: -.005em;
  text-align: center;
}

/* ---------- Vorschau ---------- */
.preview-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--preview-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  min-height: 200px;
}
@supports not (aspect-ratio: 16 / 9) {
  .preview-wrap::before { content: ""; display: block; padding-top: 56.25%; }
  .self-view, .preview-placeholder, .preview-controls { position: absolute; inset: 0; }
}

.self-view {
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: var(--preview-bg);
  transition: opacity .2s ease;
}
.self-view.is-hidden { opacity: 0; visibility: hidden; }

.preview-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: .5rem;
  color: rgba(255,255,255,.7);
  background: var(--preview-bg);
  font-size: .9rem;
  letter-spacing: .02em;
}

.preview-controls {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: .55rem;
  z-index: 2;
}

.icon-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.16);
  color: #fff;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background-color .15s ease, transform .05s ease;
  position: relative;
}
.icon-btn:hover { background: rgba(255,255,255,.26); }
.icon-btn:active { transform: scale(.96); }
.icon-btn .icon-off { display: none; }
.icon-btn.off       { background: #b3261e; color: #fff; }
.icon-btn.off:hover { background: #c8362e; }
.icon-btn.off .icon-on  { display: none; }
.icon-btn.off .icon-off { display: block; }

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ---------- Name-Input (Gast) ---------- */
.name-input {
  width: 100%;
  max-width: 360px;
  padding: .75rem 1rem;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: .65rem;
  font-size: 1rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease;
}
.name-input::placeholder { color: var(--text-muted); }
.name-input:hover { border-color: var(--accent); }
.name-input:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

/* ---------- Status / Auto-Join ---------- */
.status-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .65rem;
  text-align: center;
}
.status-banner {
  margin: 0;
  font-size: .95rem;
  color: var(--text-muted);
  transition: color .2s ease;
}
.status-banner.live {
  color: var(--accent);
  font-weight: 600;
  font-size: 1.05rem;
}

/* ---------- Modal (Settings) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.modal.open { opacity: 1; pointer-events: auto; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  transform: translateY(8px) scale(.98);
  transition: transform .2s ease;
  display: flex;
  flex-direction: column;
  gap: .85rem;
}
.modal.open .modal-card { transform: translateY(0) scale(1); }
.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -.005em;
}
.modal-close {
  position: absolute;
  top: .65rem;
  right: .65rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background-color .15s ease, color .15s ease;
}
.modal-close:hover {
  background: var(--bg);
  color: var(--text);
}

/* ---------- Forms ---------- */
.join-form { display: flex; flex-direction: column; gap: .65rem; }
.join-form input[type="text"],
.join-form input[type="password"] {
  width: 100%;
  padding: .85rem 1rem;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: .65rem;
  font-size: 1rem;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease;
}
.join-form input::placeholder { color: var(--text-muted); }
.join-form input:hover { border-color: var(--accent); }
.join-form input:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.field { display: flex; flex-direction: column; gap: .35rem; }
.field-label {
  font-size: .8rem;
  color: var(--text-muted);
  letter-spacing: .02em;
  padding-left: .15rem;
  font-weight: 500;
}
.field-hint {
  font-weight: 400;
  color: var(--text-muted);
  margin-left: .25rem;
}

.select {
  width: 100%;
  padding: .65rem 2rem .65rem .85rem;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: .55rem;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) 50%,
    calc(100% - 8px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  font-size: .95rem;
}

/* ---------- Buttons ---------- */
.cta {
  background: var(--accent);
  color: var(--accent-fg);
  padding: .95rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: .65rem;
  letter-spacing: .01em;
  box-shadow: var(--shadow);
  transition: background-color .15s ease, transform .05s ease, opacity .15s ease;
  margin-top: .35rem;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}
.cta:hover { background: var(--accent-hover); }
.cta:active { transform: translateY(1px); }
.cta:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }

.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: .75rem 1.1rem;
  font-size: .95rem;
  font-weight: 500;
  border-radius: .55rem;
  transition: background-color .15s ease, border-color .15s ease;
}
.secondary:hover {
  background: var(--bg);
  border-color: var(--accent);
}

/* ---------- Hint / Error ---------- */
.hint {
  font-size: .85rem;
  color: var(--text-muted);
  margin: 0 0 .85rem;
  line-height: 1.45;
}
.error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: .65rem .85rem;
  border-radius: .55rem;
  font-size: .9rem;
  text-align: center;
  margin: 0;
}

/* ---------- Footer ---------- */
.foot {
  margin-top: auto;
  padding-top: 2rem;
  text-align: center;
  font-size: .8rem;
  color: var(--text-muted);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translate(-50%, .5rem);
  padding: .65rem 1rem;
  background: var(--text);
  color: var(--bg);
  border-radius: .55rem;
  box-shadow: var(--shadow);
  font-size: .9rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 2000;
  max-width: calc(100% - 2rem);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Daily Iframe ---------- */
#call-container:empty { display: none; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  main, .host-main { padding-inline: 1rem; }
  .icon-btn { width: 44px; height: 44px; }
  .modal-card { padding: 1.25rem; }
}

/* ---------- Flatpickr Theming ---------- */
.flatpickr-calendar {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: .65rem;
  font-family: inherit;
}
.flatpickr-months .flatpickr-month,
.flatpickr-current-month,
.flatpickr-weekday {
  color: var(--text);
  fill: var(--text);
  background: transparent;
}
.flatpickr-day {
  color: var(--text);
  border-radius: .35rem;
}
.flatpickr-day:hover,
.flatpickr-day:focus {
  background: var(--bg);
  border-color: var(--accent);
}
.flatpickr-day.selected,
.flatpickr-day.selected:hover {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.flatpickr-day.today {
  border-color: var(--accent);
  color: var(--accent);
}
.flatpickr-day.today.selected { color: var(--accent-fg); }
.flatpickr-day.flatpickr-disabled,
.flatpickr-day.prevMonthDay,
.flatpickr-day.nextMonthDay {
  color: var(--text-muted);
}
.flatpickr-time input,
.flatpickr-time .flatpickr-am-pm {
  color: var(--text);
  background: var(--bg-elev);
}
.flatpickr-time input:hover,
.flatpickr-time input:focus,
.flatpickr-time .flatpickr-am-pm:hover,
.flatpickr-time .flatpickr-am-pm:focus {
  background: var(--bg);
}
.flatpickr-time .numInputWrapper span.arrowUp::after { border-bottom-color: var(--text); }
.flatpickr-time .numInputWrapper span.arrowDown::after { border-top-color: var(--text); }
.flatpickr-monthDropdown-months,
.flatpickr-monthDropdown-month {
  background: var(--bg-elev);
  color: var(--text);
}
.flatpickr-prev-month svg, .flatpickr-next-month svg { fill: var(--text); }
.flatpickr-prev-month:hover svg, .flatpickr-next-month:hover svg { fill: var(--accent); }
.flatpickr-calendar.arrowTop::before,
.flatpickr-calendar.arrowTop::after,
.flatpickr-calendar.arrowBottom::before,
.flatpickr-calendar.arrowBottom::after {
  border-bottom-color: var(--bg-elev);
  border-top-color: var(--bg-elev);
}

/* ---------- In-Call UI (Daily Call Object) ---------- */
.in-call {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #0b0e16;
  display: flex;
  flex-direction: column;
}

.tiles-grid {
  flex: 1;
  display: grid;
  gap: 4px;
  padding: 4px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  grid-auto-rows: 1fr;
  align-content: center;
  justify-content: center;
}

.tile {
  position: relative;
  background: #111623;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tile.is-local video { transform: scaleX(-1); }
.tile.cam-off video { display: none; }
.tile.cam-off::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 45%, #2a3146 0%, #131826 70%);
}
.tile-name {
  position: absolute;
  left: 10px;
  bottom: 8px;
  padding: 4px 10px;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .85rem;
  border-radius: 6px;
  letter-spacing: .01em;
}
.tile-name.is-muted::after {
  content: " 🔇";
  font-size: .85em;
}
.tile-initial {
  position: absolute;
  font-size: 4rem;
  color: rgba(255,255,255,.55);
  font-weight: 500;
  letter-spacing: -.02em;
  user-select: none;
}

.call-audio { display: none; }

.call-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 14px 16px env(safe-area-inset-bottom, 14px);
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(8px);
}

.icon-btn.round {
  width: 48px; height: 48px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  color: #fff;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}
.icon-btn.round:hover { background: rgba(255,255,255,.2); }
.icon-btn.round.off { background: #c2453d; }
.icon-btn.round.off:hover { background: #d35047; }
.icon-btn.round .icon-on  { display: inline-block; }
.icon-btn.round .icon-off { display: none; }
.icon-btn.round.off .icon-on  { display: none; }
.icon-btn.round.off .icon-off { display: inline-block; }
.icon-btn.round.active { background: var(--accent, #8a7559); }

.leave-btn {
  background: #c2453d;
  color: #fff;
  border: 0;
  padding: 0 18px;
  height: 48px;
  border-radius: 24px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: .01em;
  margin-left: 12px;
  transition: background .15s ease;
}
.leave-btn:hover { background: #d35047; }

@media (max-width: 520px) {
  .call-controls { gap: 8px; padding: 10px 10px env(safe-area-inset-bottom, 10px); }
  .leave-btn { padding: 0 14px; margin-left: 6px; font-size: .9rem; }
  .icon-btn.round { width: 44px; height: 44px; }
}
