* { box-sizing: border-box; }

/* Round colours. Discussion 1 is cerulean blue, discussion 2 is hunter
   green. clock.js sets data-round on <html> from the server's round number,
   so every screen (buttons, bubbles, backgrounds, timer) follows. */
:root {
  --accent: #007BA7;        /* cerulean blue */
  --accent-strong: #00698f;
  --bg: #e6f2f8;            /* page / waiting-room background */
  --bg-chat: #f1f8fb;       /* thread background */
  --accent-soft: #cfe6f0;   /* borders, composer line */
  --theirs: #ffffff;        /* other people's bubbles */
}
:root[data-round="2"] {
  --accent: #355E3B;        /* hunter green */
  --accent-strong: #2a4b2f;
  --bg: #e8f0e9;
  --bg-chat: #f2f7f2;
  --accent-soft: #cfdfd1;
  --theirs: #ffffff;
}

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  background: #fff;
  color: #000;
}

.screen { height: 100%; }
/* !important so the per-screen #id { display: flex } rules below cannot win. */
.screen[hidden] { display: none !important; }
.question[hidden] { display: none; }

/* Landing / waiting room */
#landing {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}

.join-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.join-card h1 { margin: 0 0 8px; font-size: 28px; text-align: center; }
.join-card label { font-size: 15px; color: #6e6e73; }

/* Landing page: everything larger than the rest of the app. The splash
   and the finished screen share these sizes so their headings land on the
   same spot as "Welcome!". */
#landing .join-card, #splash .join-card, #done .join-card { max-width: 680px; gap: 20px; }
#landing h1, #splash h1, #done h1 {
  font-family: "Cinzel", "Times New Roman", Georgia, serif;
  font-weight: 700;
  font-size: clamp(64px, 11vw, 120px);
  line-height: 1.1;
  letter-spacing: 0.02em;
  margin-bottom: 20px;
}
#landing label, #splash label { font-size: 34px; color: #3a3a3c; }
#landing input, #splash input, #done input { font-size: 32px; height: 84px; padding: 0 22px; border-radius: 18px; }
#landing .primary, #splash .primary, #done .primary { font-size: 32px; height: 84px; border-radius: 18px; }
#landing .error { font-size: 24px; }

/* Splash: white "Welcome!" over a slowly drifting cerulean-to-hunter-green
   glow. Sits on top of the landing page and fades out to reveal it. */
.splash {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
  cursor: none; /* no mouse pointer over the splash */
  color: #fff;
  background: linear-gradient(135deg, #007BA7 0%, #0a8c9a 25%, #1f7f6f 50%, #2e6e4e 75%, #355E3B 100%);
  background-size: 400% 400%;
  animation: splash-drift 18s ease-in-out infinite;
  /* Long, gentle cross-fade into the landing page beneath. */
  transition: opacity 5s cubic-bezier(0.45, 0, 0.3, 1);
}
.splash.fade { opacity: 0; pointer-events: none; }
.splash[hidden] { display: none; }
.splash .join-card { position: relative; z-index: 1; }
.splash h1 { color: #fff; text-shadow: 0 0 24px rgba(255, 255, 255, 0.45); }
.splash .ghost { visibility: hidden; }

/* Two soft blurred blobs of the end colours that wander across the screen. */
.glow {
  position: absolute;
  width: 70vmax;
  height: 70vmax;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.7;
  pointer-events: none;
}
.glow-a {
  top: -25vmax; left: -20vmax;
  background: radial-gradient(circle, rgba(0, 150, 200, 0.9) 0%, rgba(0, 123, 167, 0) 70%);
  animation: glow-a 22s ease-in-out infinite alternate;
}
.glow-b {
  bottom: -25vmax; right: -20vmax;
  background: radial-gradient(circle, rgba(70, 130, 90, 0.9) 0%, rgba(53, 94, 59, 0) 70%);
  animation: glow-b 26s ease-in-out infinite alternate;
}
.splash-hint {
  position: absolute;
  bottom: calc(40px + env(safe-area-inset-bottom));
  left: 0; right: 0;
  margin: 0;
  text-align: center;
  font-size: 18px;
  color: rgba(255, 255, 255, 0.85);
  animation: hint-pulse 2.4s ease-in-out infinite;
}
.splash-hint[hidden] { display: none; }

@keyframes splash-drift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
@keyframes glow-a {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(45vw, 35vh) scale(1.25); }
}
@keyframes glow-b {
  from { transform: translate(0, 0) scale(1.1); }
  to { transform: translate(-45vw, -35vh) scale(0.9); }
}
@keyframes hint-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .splash, .glow, .splash-hint { animation: none; }
}

.join-card input {
  font: inherit;
  padding: 0 14px;
  height: 48px;
  border: 1px solid #c7c7cc;
  border-radius: 12px;
  background: #fff;
}

.primary {
  font: inherit;
  font-weight: 600;
  height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.error { margin: 0; color: #ff3b30; font-size: 15px; }

/* Chat */
#chat {
  display: flex;
  flex-direction: column;
  position: relative;
}

.thread {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-chat);
  padding: 12px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg { display: flex; flex-direction: column; max-width: 75%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }

.sender { font-size: 12px; color: #6e6e73; margin: 0 12px 2px; }

.bubble {
  padding: 8px 14px;
  border-radius: 18px;
  line-height: 1.3;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.mine .bubble { background: var(--accent); color: #fff; }
.theirs .bubble { background: var(--theirs); color: #000; box-shadow: 0 0 0 1px var(--accent-soft) inset; }

.system {
  align-self: center;
  font-size: 13px;
  color: #6e6e73;
  padding: 2px 0;
}

/* Coloured header bar: which discussion this is, plus the session timer. */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  position: relative;
  z-index: 5;
  padding: 10px 14px calc(10px);
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--accent);
  color: #fff;
}

.timer {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: #fff;
  background: rgba(255, 255, 255, 0.22);
  user-select: none;
}
.timer.ending { background: #ff3b30; }

/* "Click here to see the topic" button (top-left of the chat header) and the
   panel that pops up with the topic while the pointer hovers over it. The
   popover also opens on keyboard focus and on tap (the .open class), since
   phones have no hover. */
.topic-peek { position: relative; min-width: 0; }
.topic-peek-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(255, 255, 255, 0.22);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.topic-peek-btn:hover,
.topic-peek.open .topic-peek-btn { background: rgba(255, 255, 255, 0.34); }
.topic-peek-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.topic-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 520px;
  max-width: calc(100vw - 28px);
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  box-sizing: border-box;
  border-radius: 14px;
  background: #fff;
  color: #000;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25), 0 0 0 1px var(--accent-soft) inset;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  pointer-events: none;
}
.topic-popover::before {        /* little arrow pointing up at the button */
  content: "";
  position: absolute;
  top: -6px;
  left: 22px;
  width: 12px;
  height: 12px;
  background: #fff;
  transform: rotate(45deg);
  border-radius: 2px;
}
.topic-popover .eyebrow { margin: 0; color: var(--accent); font-size: 12px; }
.topic-popover-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  font-weight: 500;
  text-align: left;
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.topic-peek:hover .topic-popover,
.topic-peek:focus-within .topic-popover,
.topic-peek.open .topic-popover {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}
.timer.done { background: #ff3b30; }

.jump {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom));
  font: inherit;
  font-size: 14px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}
.jump[hidden] { display: none; }

/* Composer */
.composer {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
  align-items: end;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--accent-soft);
  background: #fff;
}

.composer textarea {
  font: inherit;
  min-height: 44px;
  max-height: 140px;
  padding: 11px 14px;
  border: 1px solid #c7c7cc;
  border-radius: 22px;
  resize: none;
  line-height: 1.3;
}

.send {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
}
.send:disabled { background: #c7c7cc; cursor: default; }

.hint {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 12px;
  color: #8e8e93;
  text-align: center;
}

/* Instructions between the rounds */
#instructions {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 24px 16px;
  background: var(--bg);
  text-align: center;
}
.instructions-text { margin: 0; font-size: 24px; line-height: 1.35; font-weight: 600; }
.topic-text.small-topic { font-size: 17px; }

/* Topic screen */
#topic {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 24px 16px;
  background: var(--bg);
  text-align: center;
}

.topic-card {
  width: 100%;
  max-width: 640px;
  margin: auto;            /* centres vertically, scrolls instead of clipping when tall */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.eyebrow {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.topic-text {
  margin: 0;
  font-size: 18px;
  line-height: 1.5;
  font-weight: 500;
  text-align: left;
  white-space: pre-line;   /* blank lines in the topic become paragraph breaks */
}

.primary.big {
  width: 100%;
  max-width: 360px;
  height: 56px;
  font-size: 19px;
}
.primary:disabled { background: #c7c7cc; cursor: default; }
.primary:not(:disabled):hover { background: var(--accent-strong); }

/* Pre-participation questionnaire (right after the name) and the topic
   rating (right after the topic screen) */
#survey, #rating {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
}

.survey-card {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.survey-card h1 { margin: 0; font-size: 26px; }

.topic-reminder {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: #fff;
  font-size: 14px;
  line-height: 1.4;
  color: #3a3a3c;
}

.question {
  margin: 0;
  padding: 14px;
  border: 0;
  border-radius: 14px;
  background: #fff;
}

.question legend {
  float: left; /* keeps the legend inside the fieldset's padding/radius */
  width: 100%;
  margin: 0 0 12px;
  padding: 0;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
}

.scale {
  clear: both;
  display: grid;
  grid-template-columns: repeat(var(--steps, 5), 1fr);
  gap: 6px;
}

.scale-btn {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 72px;
  padding: 8px 4px;
  border: 1px solid #c7c7cc;
  border-radius: 12px;
  background: #fff;
  color: #000;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.scale-btn .num { font-size: 20px; font-weight: 700; line-height: 1; }
.scale-btn .lab {
  font-size: 12px;
  line-height: 1.2;
  color: #6e6e73;
  text-align: center;
  overflow-wrap: anywhere;
}
.scale-btn:hover { border-color: var(--accent); }
.scale-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.scale-btn[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.scale-btn[aria-checked="true"] .lab { color: #fff; }

.survey-card .primary.big { align-self: center; }
.center { text-align: center; }

/* A section of an exported form: heading, description, then its questions. */
.q-section { display: flex; flex-direction: column; gap: 16px; }
.q-section h2 {
  margin: 10px 0 -4px;
  font-size: 20px;
  line-height: 1.25;
  color: var(--accent);
}
.req { color: #ff3b30; font-weight: 700; }
.question .help {
  clear: both;
  margin: -4px 0 12px;
  font-size: 14px;
  line-height: 1.35;
  color: #6e6e73;
}

/* Multiple choice: a stacked list of options, one per button. */
.choices {
  clear: both;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.choice-btn {
  font: inherit;
  text-align: left;
  padding: 10px 14px;
  border: 1px solid #c7c7cc;
  border-radius: 12px;
  background: #fff;
  color: #000;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.choice-btn:hover { border-color: var(--accent); }
.choice-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice-btn[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Free text: a single-line input or a textarea. */
.answer-text {
  clear: both;
  display: block;
  width: 100%;
  font: inherit;
  padding: 10px 14px;
  border: 1px solid #c7c7cc;
  border-radius: 12px;
  background: #fff;
  color: #000;
  line-height: 1.3;
  resize: vertical;
}
.answer-text:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

/* The facilitator's name in the post questionnaire. NAME in the JSON is
   shown as CANDIDE after round 1 and ROBERT after round 2 (chat.js), and
   highlighted in that round's colour: cerulean blue, then hunter green. */
.sysname {
  background: var(--accent);
  color: #fff;
  padding: 0 0.35em;
  border-radius: 5px;
  font-weight: 700;
}

/* Scales with more than five points stack vertically on narrow screens. */
@media (max-width: 520px) {
  .scale.scale-wide { grid-template-columns: 1fr; gap: 4px; }
  .scale.scale-wide .scale-btn {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    min-height: 44px;
    padding: 8px 12px;
  }
  .scale.scale-wide .scale-btn .lab { font-size: 14px; text-align: left; }
}

/* Consensus screen and post-discussion questionnaire: same layout as the pre-survey. */
#consensus, #post {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
}

/* Finished: the landing page's layout and heading, with the subtitle in
   the slot the "What is your name?" label had, and the invisible input and
   button below it (the .ghost rule above) so the heading is centred the
   same way. */
#done {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
  text-align: center;
}
#done .join-card { max-width: 1100px; }
#done .ghost { visibility: hidden; }
#done .done-sub {
  margin: 0;
  font-size: 34px;
  line-height: 1.3;
  color: #3a3a3c;
}
@media (max-width: 700px) {
  #done .done-sub { font-size: 24px; }
}

@media (max-width: 420px) {
  .topic-peek-btn { font-size: 12px; padding: 3px 8px; }
  .scale-btn { min-height: 80px; padding: 8px 2px; }
  .scale-btn .lab { font-size: 11px; }
  .topic-text { font-size: 16px; }
}

/* Waiting room */
#waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
  text-align: center;
}

.waiting-card {
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.waiting-card h1 { margin: 4px 0 0; font-size: 24px; }

.pulse {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(0.7); opacity: 0.4; }
  50% { transform: scale(1.15); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .pulse { animation: none; }
}

.muted { margin: 0; color: #6e6e73; font-size: 15px; }
.small { font-size: 13px; }
.starts { margin: 0; font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Host controls (/admin) */
#admin {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}

.admin-card .status {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: #fff;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.admin-card .status.running { color: #1b7f3b; }
.admin-card .status.ended { color: #ff3b30; }

.admin-card .row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.secondary {
  font: inherit;
  font-weight: 600;
  height: 48px;
  padding: 0 16px;
  border: 1px solid #c7c7cc;
  border-radius: 12px;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
}
.secondary.danger { color: #ff3b30; }

.ok { margin: 0; color: #1b7f3b; }
.admin-card a { color: var(--accent); }
