/* No build step and no third-party stylesheet: the CSP allows neither an external sheet nor a style
   attribute, so every rule a screen needs is a class here. Colours follow Telegram's theme where the
   client publishes one and fall back to the mockup's palette where it does not. */

:root {
  --surface: var(--tg-theme-bg-color, #ffffff);
  --surface-1: var(--tg-theme-secondary-bg-color, #f3f4f6);
  --border: rgba(0, 0, 0, 0.1);
  --border-strong: rgba(0, 0, 0, 0.22);

  --text-primary: var(--tg-theme-text-color, #101114);
  --text-secondary: var(--tg-theme-subtitle-text-color, #6b7280);
  --text-muted: var(--tg-theme-hint-color, #9ca3af);

  --text-accent: var(--tg-theme-link-color, #2481cc);
  --fill-accent: var(--tg-theme-button-color, #2481cc);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --bg-accent: #e6f1fa;
  --border-accent: #a5cdec;

  --text-success: #17734a;
  --bg-success: #e2f3e9;
  --fill-success: #2ea36a;
  --text-warning: #8a5a00;
  --bg-warning: #fcf0da;
  --fill-warning: #dd9c33;
  --text-danger: var(--tg-theme-destructive-text-color, #c0392b);
  --bg-danger: #fbe9e7;
  --border-danger: rgba(192, 57, 43, 0.42);

  --radius: 10px;
  --radius-lg: 12px;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-voice: Georgia, "Times New Roman", serif;
}

/* Two selectors on purpose: Telegram reports its own scheme, a plain browser reports the system's. */
@media (prefers-color-scheme: dark) {
  :root {
    --surface: var(--tg-theme-bg-color, #1e2126);
    --surface-1: var(--tg-theme-secondary-bg-color, #282c33);
    --border: rgba(255, 255, 255, 0.12);
    --border-strong: rgba(255, 255, 255, 0.26);
    --text-primary: var(--tg-theme-text-color, #eceef1);
    --text-secondary: var(--tg-theme-subtitle-text-color, #9aa2ad);
    --text-muted: var(--tg-theme-hint-color, #767e89);
    --text-accent: var(--tg-theme-link-color, #6ab3f3);
    --fill-accent: var(--tg-theme-button-color, #3d8ecc);
    --bg-accent: #1d3143;
    --border-accent: #35597a;
    --text-success: #7ed6a6;
    --bg-success: #1b3329;
    --fill-success: #3aa876;
    --text-warning: #e8bb70;
    --bg-warning: #362b16;
    --fill-warning: #c9903a;
    --text-danger: var(--tg-theme-destructive-text-color, #ef8b7f);
    --bg-danger: #361f1d;
    --border-danger: rgba(239, 139, 127, 0.42);
  }
}

[data-theme="dark"] {
  --bg-accent: #1d3143;
  --border-accent: #35597a;
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.26);
  --text-success: #7ed6a6;
  --bg-success: #1b3329;
  --fill-success: #3aa876;
  --text-warning: #e8bb70;
  --bg-warning: #362b16;
  --fill-warning: #c9903a;
  --bg-danger: #361f1d;
  --border-danger: rgba(239, 139, 127, 0.42);
}

* {
  box-sizing: border-box;
}

/* The class on a hidden element would otherwise set display and win on specificity. */
[hidden] {
  display: none !important;
}

/* Keeps a control's space in the layout: the header would shift under the title without it. */
.invisible {
  visibility: hidden;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.sprite {
  display: none;
}

p {
  margin: 0;
}

/* ---------------------------------------------------------------- shell */

.shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  min-height: 54px;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
}

.bar-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-action,
.bar-right {
  flex: none;
  min-width: 56px;
  display: flex;
  align-items: center;
  gap: 4px;
  font: inherit;
  font-size: 14px;
  color: var(--text-accent);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.bar-right {
  justify-content: flex-end;
}

.screen {
  flex: 1;
  padding: 16px;
}

.footer {
  padding: 0 16px 20px;
}

.footer:empty {
  padding: 0;
}

/* ---------------------------------------------------------------- type */

.title {
  font-size: 17px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.title-lg {
  font-size: 22px;
  font-weight: 500;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.section {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.hint {
  font-size: 13px;
  color: var(--text-secondary);
}

.note {
  font-size: 12px;
  color: var(--text-muted);
}

.center {
  text-align: center;
}

.gap-top {
  margin-top: 14px;
}

.gap-bottom {
  margin-bottom: 14px;
}

.mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ---------------------------------------------------------------- icons */

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-lg {
  width: 20px;
  height: 20px;
}

.icon-xl {
  width: 32px;
  height: 32px;
  stroke-width: 1.5;
}

/* ---------------------------------------------------------------- controls */

button {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--fill-accent);
  outline-offset: 1px;
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

input,
textarea {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0 10px;
  height: 36px;
  width: 100%;
}

textarea {
  padding: 8px 10px;
  height: auto;
  min-height: 84px;
  line-height: 1.4;
  resize: vertical;
}

::placeholder {
  color: var(--text-muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--fill-accent);
  color: var(--on-accent);
  border: 0;
  min-height: 44px;
  font-size: 15px;
  font-weight: 500;
}

.btn-danger {
  color: var(--text-danger);
  border-color: var(--border-danger);
}

.btn-quiet {
  border: 0;
  background: none;
  color: var(--text-accent);
  min-height: 30px;
  padding: 4px 0;
  font-size: 13px;
}

.btn-icon {
  border: 0;
  background: none;
  color: var(--text-muted);
  min-height: 32px;
  width: 32px;
  padding: 0;
  flex: none;
}

.btn-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.btn-span {
  grid-column: span 2;
}

/* ---------------------------------------------------------------- pills and tabs */

.pills {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
}

.pill {
  flex: none;
  min-height: 30px;
  padding: 0 12px;
  font-size: 12px;
  border-radius: 15px;
  color: var(--text-secondary);
}

.pill[aria-pressed="true"],
.tab[aria-pressed="true"],
.type[aria-pressed="true"] {
  background: var(--bg-accent);
  color: var(--text-accent);
  border: 0.5px solid var(--border-accent);
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  min-height: 34px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ---------------------------------------------------------------- cards and rows */

.card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px;
  margin-bottom: 8px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.card-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.card-title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

.card-meta span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.card-meta .icon {
  width: 14px;
  height: 14px;
}

.push {
  margin-left: auto;
  color: var(--text-muted);
}

.badge {
  flex: none;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 10px;
  background: var(--surface-1);
  color: var(--text-secondary);
}

.badge-live {
  background: var(--bg-success);
  color: var(--text-success);
}

.badge-draft {
  background: var(--bg-warning);
  color: var(--text-warning);
}

.rows {
  margin-top: 4px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 0.5px solid var(--border);
  font-size: 14px;
}

.row-key {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
}

.row-value {
  text-align: right;
  overflow-wrap: anywhere;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px;
  margin-bottom: 8px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.list-row-body {
  flex: 1;
  min-width: 0;
}

.list-row-title {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-row-sub {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.metric {
  background: var(--surface-1);
  border-radius: var(--radius);
  padding: 12px;
}

.metric-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.metric-value {
  font-size: 20px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.metric-value-sm {
  font-size: 15px;
}

.span-2 {
  grid-column: span 2;
}

/* ---------------------------------------------------------------- avatars */

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  background: var(--bg-accent);
  color: var(--text-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
}

.avatar-lg {
  width: 52px;
  height: 52px;
  font-size: 17px;
}

.identity {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.identity-name {
  font-size: 16px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------- banners */

.banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
  margin-bottom: 16px;
  background: var(--surface-1);
  color: var(--text-secondary);
}

.banner-ok {
  background: var(--bg-success);
  color: var(--text-success);
}

.banner-warn {
  background: var(--bg-warning);
  color: var(--text-warning);
}

.banner-error {
  background: var(--bg-danger);
  color: var(--text-danger);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: 360px;
  width: calc(100% - 32px);
  z-index: 20;
  margin: 0;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}

.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}

.empty-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  margin: 10px 0 4px;
}

.empty-text {
  font-size: 13px;
  color: var(--text-secondary);
}

.loading {
  text-align: center;
  padding: 40px 16px;
  font-size: 13px;
  color: var(--text-muted);
}

/* The app replaces this whole screen as soon as it runs, so the hint is only ever seen when it did not.
   On a timer in CSS because the failure it explains is the script itself never starting. */
.boot-hint {
  opacity: 0;
  padding-top: 0;
  animation: boot-hint 0.3s linear 6s forwards;
}

@keyframes boot-hint {
  to {
    opacity: 1;
  }
}

/* ---------------------------------------------------------------- share block */

.share {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-1);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 14px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.share-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share button {
  flex: none;
  min-height: 28px;
  font-size: 12px;
  padding: 0 10px;
}

/* ---------------------------------------------------------------- builder */

.field {
  margin-bottom: 12px;
}

/* A checkbox the whole row is the label for, so the tap target is the sentence rather than the box. */
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  padding: 4px 0;
  margin-bottom: 4px;
  cursor: pointer;
}

.toggle-box {
  width: 18px;
  height: 18px;
  accent-color: var(--fill-accent);
  flex: none;
}

.field-title {
  font-size: 17px;
  font-weight: 500;
  border: 0;
  background: transparent;
  padding: 4px 0;
}

.qcard {
  background: var(--surface-1);
  border-radius: var(--radius-lg);
  padding: 12px;
  margin-bottom: 12px;
}

.qcard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.qcard-label {
  font-size: 12px;
  color: var(--text-muted);
}

.qcard input,
.qcard textarea {
  background: var(--surface);
}

.qcard-title {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 10px;
}

.types {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.type {
  flex: 1;
  min-width: 0;
  min-height: 32px;
  padding: 0 4px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-secondary);
}

.type .icon {
  width: 14px;
  height: 14px;
}

.opt {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.opt-icon {
  color: var(--text-muted);
}

.opt input[type="text"] {
  flex: 1;
  min-width: 0;
  height: 34px;
  font-size: 14px;
}

.opt-weight {
  width: 58px;
  flex: none;
  height: 34px;
  font-size: 13px;
  text-align: center;
  padding: 0 4px;
}

.opt-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* The score bands under the questions: a heading for the section, and the sentence each band shows. */
.section-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.band-message {
  width: 100%;
  height: 34px;
  font-size: 13px;
}

.placeholder {
  border: 0.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------------------------------------------------------------- result bars */

.stat {
  margin-bottom: 10px;
}

.stat-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 4px;
}

.stat-label {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.stat-value {
  flex: none;
  color: var(--text-secondary);
}

.stat-track {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-1);
  overflow: hidden;
}

.stat-fill {
  height: 100%;
  width: 0;
  background: var(--fill-accent);
}

.stat-fill-success {
  background: var(--fill-success);
}

.stat-fill-warning {
  background: var(--fill-warning);
}

.qblock {
  border-top: 0.5px solid var(--border);
  padding-top: 14px;
  margin-bottom: 18px;
}

.qblock-title {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  overflow-wrap: anywhere;
}

.qblock-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.quote {
  border-left: 2px solid var(--border-strong);
  padding: 2px 0 2px 10px;
  margin-bottom: 10px;
}

.quote-text {
  font-family: var(--font-voice);
  font-size: 13px;
  margin-bottom: 2px;
  overflow-wrap: anywhere;
}

.quote-who {
  font-size: 11px;
  color: var(--text-muted);
}

.weight-tag {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 6px;
}

/* ---------------------------------------------------------------- respondent flow */

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface-1);
  border-radius: 14px;
  padding: 5px 10px;
}

.chip .icon {
  width: 14px;
  height: 14px;
}

.facts {
  border-top: 0.5px solid var(--border);
  padding-top: 14px;
}

.fact {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

.fact .icon {
  color: var(--text-muted);
  margin-top: 2px;
}

.resume {
  background: var(--bg-accent);
  border-radius: var(--radius-lg);
  padding: 12px;
  margin-bottom: 16px;
}

.resume-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-accent);
}

.ticks {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

.tick {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
}

.tick-on {
  background: var(--fill-accent);
}

.question {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.question-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px;
  margin-bottom: 8px;
  font-size: 14px;
  min-height: 44px;
  overflow-wrap: anywhere;
}

.choice[aria-pressed="true"] {
  background: var(--bg-accent);
  color: var(--text-accent);
  border: 0.5px solid var(--border-accent);
}

.choice .icon {
  width: 18px;
  height: 18px;
}

.score-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--bg-accent);
  color: var(--text-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  font-size: 20px;
  font-weight: 500;
}

.state-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface-1);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
}

.state-icon-danger {
  background: var(--bg-danger);
  color: var(--text-danger);
}

.sheet-answer {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  padding: 6px 0;
  color: var(--text-secondary);
}

.sheet-answer-picked {
  color: var(--text-primary);
  font-weight: 500;
}
