:root {
  --green: #6DAC44;
  --blue-green: #18555E;
  --dark-blue-green: #072B2E;
  --space-grey: #444444;
  --grey: #898989;
  --silver: #CCCCCC;
  --ice: #F8F8F8;
  --white: #FFFFFF;
  --cream: #FBF3E6;
  --cream-edge: #EAD9BF;
  /* The tan gradient behind the word cloud (and, on /display, the whole page). */
  --wall-bg: radial-gradient(ellipse at center, #FFF9EF 0%, var(--cream) 60%, #F5E6CF 100%);
  --danger: #9B2915;
  --font: "Avenir Next", "Gotham", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: var(--font);
  color: var(--space-grey);
  background: var(--ice);
  display: flex;
  flex-direction: column;
}

header {
  background: var(--dark-blue-green);
  color: var(--white);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}
header h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: 0.2px; }
header .leaf { font-size: 22px; }
header .spacer { flex: 1; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 24px 16px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
}

.btn {
  font-family: var(--font);
  background: var(--blue-green);
  color: var(--white);
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover { background: var(--dark-blue-green); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn.secondary { font-size: 12px; padding: 7px 16px; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #7A1F1F; }
.btn.ghost { background: transparent; color: var(--white); border: 1px solid rgba(255,255,255,0.5); }

/* ---------- Submit form ---------- */

.ask {
  display: flex;
  gap: 12px;
  align-items: center;
}
.ask label {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}
.ask input {
  flex: 1;
  min-width: 0;
  font-family: var(--font);
  font-size: 18px;
  padding: 13px 22px;
  border: 2px solid var(--silver);
  border-radius: 999px;
  background: var(--white);
  color: var(--space-grey);
  outline: none;
  transition: border-color 0.2s;
}
.ask input:focus { border-color: var(--blue-green); }
[hidden] { display: none !important; }

.closed-note {
  margin: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--blue-green);
}

.status {
  min-height: 22px;
  margin: -6px 0 0 22px;
  font-size: 15px;
  transition: opacity 0.3s;
}
.status.ok { color: var(--blue-green); }
.status.warn { color: var(--danger); }

/* ---------- Word cloud ---------- */

.cloud-wrap {
  position: relative;
  flex: 1;
  min-height: 420px;
  border-radius: 20px;
  background: var(--wall-bg);
  border: 1px solid var(--cream-edge);
  overflow: hidden;
}

#cloud { position: absolute; inset: 0; }

.shape-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}
.shape-bg.visible { opacity: 0.14; } /* faint enough that every word color stays readable on top */

/* Visually hidden, but still read by screen readers. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible { outline: 3px solid var(--blue-green); outline-offset: 2px; }

/* ---------- Full screen ---------- */

.fs-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10000;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: rgba(24, 85, 94, 0.85);
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.75;
  transition: opacity 0.2s, background 0.2s;
}
.fs-btn:hover, .fs-btn:focus-visible { opacity: 1; background: var(--blue-green); }
.fs-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.fs-btn .fs-exit { display: none; }

.fs-title { display: none; }

.cloud-wrap:fullscreen { border-radius: 0; border: none; }
.cloud-wrap:fullscreen .fs-btn .fs-enter { display: none; }
.cloud-wrap:fullscreen .fs-btn .fs-exit { display: block; }
.cloud-wrap:fullscreen .fs-btn { opacity: 0.35; }
.cloud-wrap:fullscreen .fs-btn:hover { opacity: 1; }
/* On the room display the button vanishes completely in full screen (Esc still exits). */
.display-root:fullscreen .fs-btn { display: none; }
.cloud-wrap:fullscreen .fs-title {
  display: block;
  position: absolute;
  top: 24px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(22px, 3vw, 40px);
  font-weight: 700;
  color: var(--dark-blue-green);
}
.cloud-wrap:fullscreen #cloud { top: clamp(70px, 9vh, 110px); }

.word {
  position: absolute;
  left: 50%;
  top: 50%;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  transform: translate(-50%, -50%);
  transition:
    transform 1.4s cubic-bezier(0.22, 1, 0.36, 1),
    font-size 1.4s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.9s ease,
    color 0.9s ease;
  will-change: transform, font-size;
}
.word.leaving { opacity: 0 !important; }
.word.pulse { animation: pulse 1.6s ease; }
@keyframes pulse {
  0%, 100% { filter: none; }
  35% { filter: drop-shadow(0 0 10px rgba(224, 122, 31, 0.75)); }
}

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--grey);
  font-size: 20px;
  transition: opacity 0.6s;
}
.empty.hidden { opacity: 0; pointer-events: none; }

/* ---------- Room display (/display) ---------- */

body.display { display: block; overflow: hidden; background: var(--cream); }

.display-root {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.5vh, 20px);
  padding: clamp(12px, 2vh, 28px) clamp(16px, 2.5vw, 40px);
  background: var(--wall-bg); /* the whole page is tan; only the QR card is white */
}

.display-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

/* Added by cloud.js when the QR card isn't showing. */
.display-header.centered { justify-content: center; align-items: center; text-align: center; }

.display-title {
  margin: 0;
  font-size: clamp(26px, 3.8vw, 76px);
  line-height: 1.05;
  font-weight: 700;
  color: var(--dark-blue-green);
}

/* QR code, top right. It sits above the cloud, so it never covers any words. */
.qr-card {
  display: flex;
  align-items: center;
  gap: clamp(10px, 1.4vw, 24px);
  flex-shrink: 0;
  background: var(--white);
  border: 1px solid var(--silver);
  border-radius: 20px;
  padding: clamp(8px, 1.2vh, 16px) clamp(12px, 1.4vw, 24px);
}
.qr-card img {
  display: block;
  width: clamp(110px, 21vh, 280px);
  height: clamp(110px, 21vh, 280px);
}
.qr-text {
  margin: 0;
  font-size: clamp(14px, 1.7vw, 30px);
  line-height: 1.25;
  color: var(--space-grey);
}
.qr-text strong {
  display: block;
  color: var(--blue-green);
  overflow-wrap: anywhere;
}

/* The cloud area has no box of its own here: the page behind it is already the tan gradient. */
.display-root .cloud-wrap { flex: 1; min-height: 0; background: none; border: none; border-radius: 0; }
.display-root:fullscreen { background: var(--wall-bg); }

@media (max-width: 640px) {
  .display-header { flex-direction: column; align-items: flex-start; }
}

footer {
  font-size: 12px;
  color: var(--grey);
  text-align: center;
  padding: 0 0 12px;
}
.live-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  margin-right: 6px;
  vertical-align: middle;
  animation: blink 2s infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }

@media (max-width: 640px) {
  header { padding: 12px 16px; }
  main { padding: 16px; }
  .ask { flex-direction: column; align-items: stretch; }
  .cloud-wrap { min-height: 360px; }
}

@media (prefers-reduced-motion: reduce) {
  .word { transition-duration: 0.01s; }
  .word.pulse, .live-dot { animation: none; }
}
