/* ==========================================================================
   Live vertaling — design system
   Warm, kalm, liturgisch: perkament & inkt, amber-goud accent.
   ========================================================================== */

@font-face {
  font-family: "Fraunces";
  src: url("/assets/fonts/fraunces-latin.woff2") format("woff2");
  font-weight: 500 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #faf5ec;
  --paper-2: #f2ead9;
  --paper-3: #e9dfc9;
  --ink: #241c11;
  --ink-soft: #6d6151;
  --ink-faint: #a3968232;
  --gold: #a06a1b;
  --gold-bright: #c58a2a;
  --wine: #8c3a2e;
  --live: #b23a2c;
  --ok: #4a7c59;
  --ring: #a06a1b2e;
  --shadow: 0 18px 50px -18px #4a3a1f38, 0 2px 10px -4px #4a3a1f24;
  --radius: 20px;
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji";
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171209;
    --paper-2: #201a0f;
    --paper-3: #2b2315;
    --ink: #f0e7d6;
    --ink-soft: #a2937c;
    --ink-faint: #a2937c2e;
    --gold: #d9a441;
    --gold-bright: #e8b954;
    --wine: #d07b6c;
    --live: #e05e4c;
    --ok: #7cb08d;
    --ring: #d9a44133;
    --shadow: 0 18px 50px -18px #00000080, 0 2px 10px -4px #00000060;
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  min-height: 100dvh;
  line-height: 1.5;
  /* subtle parchment grain */
  background-image: radial-gradient(
      circle at 15% 8%,
      #ffffff0d 0%,
      transparent 45%
    ),
    radial-gradient(circle at 85% 92%, #0000000a 0%, transparent 45%),
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 3px,
      #00000003 3px,
      #00000003 4px
    );
}

.shell {
  max-width: 480px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px
    max(28px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.shell--wide {
  max-width: 760px;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */

.masthead {
  text-align: center;
  padding: 26px 0 10px;
}

.masthead .rule {
  width: 54px;
  height: 2px;
  margin: 0 auto 18px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.masthead h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(26px, 7vw, 34px);
  letter-spacing: 0.01em;
  line-height: 1.15;
}

.masthead .subtitle {
  margin-top: 6px;
  color: var(--ink-soft);
  font-size: 15px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 6px 14px;
  border: 1px solid var(--ink-faint);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: var(--paper-2);
}

.status-pill .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-faint);
}

.status-pill.is-live {
  color: var(--live);
  border-color: color-mix(in srgb, var(--live) 35%, transparent);
}

.status-pill.is-live .dot {
  background: var(--live);
  animation: livePulse 1.6s ease-in-out infinite;
}

@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 45%, transparent); }
  55% { box-shadow: 0 0 0 7px transparent; }
}

/* --------------------------------------------------------------------------
   Language grid (listener, first screen)
   -------------------------------------------------------------------------- */

.choose-title {
  font-family: var(--serif);
  font-weight: 500;
  text-align: center;
  font-size: 18px;
  color: var(--ink-soft);
  margin: 26px 0 16px;
}

.lang-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  animation: rise 0.5s ease both;
}

.lang-card {
  appearance: none;
  border: 1px solid var(--ink-faint);
  background: var(--paper-2);
  border-radius: var(--radius);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.lang-card:active {
  transform: scale(0.97);
}

.lang-card:hover,
.lang-card:focus-visible {
  border-color: var(--gold);
  background: var(--paper-3);
  outline: none;
}

.lang-card .flag {
  font-size: 30px;
  line-height: 1;
}

.lang-card .native {
  font-weight: 650;
  font-size: 17px;
}

.lang-card .en {
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* --------------------------------------------------------------------------
   Listening screen
   -------------------------------------------------------------------------- */

.listen-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  padding: 26px 0;
}

.halo-wrap {
  position: relative;
  width: 196px;
  height: 196px;
  display: grid;
  place-items: center;
}

.halo-wrap .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--ring);
  opacity: 0;
  pointer-events: none;
}

.is-playing .halo-wrap .ring {
  animation: halo 2.8s ease-out infinite;
}

.is-playing .halo-wrap .ring:nth-child(2) { animation-delay: 0.9s; }
.is-playing .halo-wrap .ring:nth-child(3) { animation-delay: 1.8s; }

@keyframes halo {
  0% { transform: scale(0.82); opacity: 0; }
  18% { opacity: 1; }
  100% { transform: scale(1.5); opacity: 0; }
}

.play-btn {
  appearance: none;
  width: 152px;
  height: 152px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--gold) 55%, transparent);
  background: radial-gradient(
    circle at 32% 28%,
    color-mix(in srgb, var(--gold-bright) 26%, var(--paper-2)),
    var(--paper-2) 70%
  );
  box-shadow: var(--shadow);
  color: var(--gold);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.play-btn:active { transform: scale(0.96); }
.play-btn svg { width: 52px; height: 52px; display: block; }

.listen-hint {
  color: var(--ink-soft);
  font-size: 14.5px;
  text-align: center;
  max-width: 300px;
  min-height: 1.4em;
}

/* Captions / scrollable transcript */
.captions {
  min-height: 96px;
  width: 100%;
  border-top: 1px solid var(--ink-faint);
  padding: 18px 6px 0;
  text-align: center;
  position: relative;
}

.captions .label {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.transcript {
  max-height: 34vh;
  min-height: 72px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  padding: 2px 4px 10px;
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 18px);
  mask-image: linear-gradient(to bottom, transparent, black 18px);
}

.transcript .line-final {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink-soft);
  margin: 0 0 10px;
}

.transcript .line-current {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 19px;
  line-height: 1.5;
  color: var(--ink);
  min-height: 1.4em;
}

.captions #followBtn {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: var(--shadow);
}

/* Listen code entry */
.code-form input {
  text-align: center;
  font-size: 26px;
  letter-spacing: 0.18em;
  font-weight: 650;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--ink-faint);
  background: var(--paper-2);
  color: var(--ink);
  width: 100%;
}

.code-form input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.code-form .btn {
  margin-top: 14px;
}

/* Language search (all supported languages) */
.lang-search {
  margin-top: 14px;
}

.lang-search input[type="search"] {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--ink-faint);
  background: var(--paper-2);
  color: var(--ink);
}

.lang-search input[type="search"]:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.lang-search .lang-grid {
  margin-top: 12px;
}

/* Current language chip + switcher */
.lang-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chip {
  appearance: none;
  font-family: inherit;
  border: 1px solid var(--ink-faint);
  background: var(--paper-2);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.12s ease;
}

.chip:hover { border-color: var(--gold); }
.chip.ghost { color: var(--ink-soft); font-weight: 500; }

.volume {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(280px, 80%);
  color: var(--ink-soft);
}

.volume input[type="range"] {
  flex: 1;
  accent-color: var(--gold);
}

/* --------------------------------------------------------------------------
   Shared: cards, buttons, forms (broadcast page)
   -------------------------------------------------------------------------- */

.card {
  background: var(--paper-2);
  border: 1px solid var(--ink-faint);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 16px; }

.card h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 19px;
  margin-bottom: 12px;
}

.btn {
  appearance: none;
  font-family: inherit;
  font-size: 16px;
  font-weight: 650;
  border-radius: 14px;
  padding: 13px 22px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: var(--gold);
  color: var(--paper);
  border-color: var(--gold);
}

.btn--danger {
  background: var(--wine);
  color: var(--paper);
  border-color: var(--wine);
}

.btn--ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--ink-faint);
}

.btn--block { width: 100%; display: block; }

label.field {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 14px 0 6px;
}

input[type="password"],
input[type="text"],
select {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--ink-faint);
  background: var(--paper);
  color: var(--ink);
}

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

.error-text {
  color: var(--wine);
  font-size: 14px;
  margin-top: 10px;
  min-height: 1.3em;
}

/* Level meter */
.meter {
  height: 14px;
  border-radius: 999px;
  background: var(--paper-3);
  overflow: hidden;
  border: 1px solid var(--ink-faint);
}

.meter .fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--ok), var(--gold-bright) 75%, var(--wine));
  transition: width 90ms linear;
}

/* Language stats table (broadcast) */
.lang-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.lang-stat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--paper);
  border: 1px solid var(--ink-faint);
  font-size: 14.5px;
}

.lang-stat .flag { font-size: 18px; }
.lang-stat .name { flex: 1; font-weight: 600; }
.lang-stat .count { color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.lang-stat .state {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-faint);
}

.lang-stat .state.active { background: var(--ok); }
.lang-stat .state.connecting { background: var(--gold-bright); animation: livePulse 1.2s infinite; }
.lang-stat .state.error { background: var(--wine); }

.muted { color: var(--ink-soft); font-size: 14px; }
.mono { font-variant-numeric: tabular-nums; }

/* QR fullscreen overlay */
.qr-overlay {
  position: fixed;
  inset: 0;
  background: #fdfaf3;
  color: #241c11;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  z-index: 50;
  text-align: center;
  padding: 40px;
}

.qr-overlay.open { display: flex; }

.qr-overlay h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(28px, 4.5vw, 44px);
}

.qr-overlay img {
  width: min(58vh, 78vw);
  border-radius: 24px;
  border: 1px solid #241c1120;
}

.qr-overlay .url {
  font-size: clamp(18px, 2.6vw, 26px);
  font-weight: 650;
  color: #8a5a16;
}

/* --------------------------------------------------------------------------
   Landing / 404
   -------------------------------------------------------------------------- */

.center-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 40px 0;
}

.center-page h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(30px, 8vw, 42px);
}

.center-page p {
  color: var(--ink-soft);
  max-width: 320px;
}

footer.colophon {
  text-align: center;
  color: var(--ink-soft);
  font-size: 12.5px;
  padding-top: 26px;
  opacity: 0.8;
}

/* QR scanner overlay (landing page) */
.scan-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 60;
}

.scan-overlay.open { display: flex; }

.scan-overlay video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.9;
}

.scan-frame {
  position: relative;
  width: min(62vw, 300px);
  aspect-ratio: 1;
  border-radius: 24px;
  border: 3px solid #ffffffd9;
  box-shadow: 0 0 0 100vmax #00000073;
  pointer-events: none;
}

.scan-hint {
  position: relative;
  color: #fff;
  font-size: 15px;
  text-align: center;
  padding: 0 30px;
  text-shadow: 0 1px 6px #000;
}

.scan-overlay .chip {
  position: relative;
  background: #ffffffe6;
  color: #1c1c1c;
  border: none;
  padding: 10px 22px;
}

/* Admin panel */
.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

@media (max-width: 560px) {
  .admin-grid { grid-template-columns: 1fr; }
}

.pw-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

input[type="color"] {
  width: 52px;
  height: 40px;
  padding: 2px;
  border: 1px solid var(--ink-faint);
  border-radius: 10px;
  background: var(--paper);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.church-card .urls a { color: var(--gold); }

.hidden { display: none !important; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
