/* ===========================================================================
   Survey UI — built on the Telegram tokens in theme.css.

   Layout philosophy: the survey fills almost the whole screen, flows as one
   vertical list of "sections" (Telegram settings-card pattern), and is perfectly
   adapted to phones. There is no fixed header; the optional cover image is just
   the first element and scrolls away with the content.
   =========================================================================== */

/* ---- App shell ----------------------------------------------------------- */
.app {
  display: flex;
  flex-direction: column;
  height: var(--app-height);
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  position: relative;
}

/* The single scroll container — no nested scrolls. */
.scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-top: calc(var(--safe-top) + 12px);
  padding-bottom: 24px;
}

/* On phones the content goes edge to edge (Telegram's full-bleed sections). */
@media (max-width: 600px) {
  .app {
    max-width: 100%;
  }
}

/* ---- Cover (optional, first element only) -------------------------------- */
.cover {
  width: 100%;
  display: block;
  border-radius: var(--radius-big);
  overflow: hidden;
  margin-bottom: 16px;
}

.cover img,
.cover video {
  width: 100%;
  height: auto;
  display: block;
}

@media (max-width: 600px) {
  .cover {
    border-radius: 0;
    margin-bottom: 8px;
  }
}

/* ---- Survey intro -------------------------------------------------------- */
.intro {
  padding: 4px 16px 16px;
}

.intro__title {
  font-size: 20px;
  font-weight: var(--font-weight-bold);
  line-height: 1.25;
  margin: 0 0 6px;
  color: var(--primary-text-color);
  word-wrap: break-word;
}

.intro__desc {
  font-size: 15px;
  color: var(--secondary-text-color);
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ---- Section (a card; one per answerable block / structural group) -------- */
.section {
  background-color: var(--surface-color);
  border-radius: var(--section-radius);
  box-shadow: var(--section-shadow);
  margin: 0 12px 12px;
  padding: 16px;
  position: relative;
}

@media (max-width: 600px) {
  /* On phones questions flow directly on the page background — no per-question
     cards. Drop the card chrome (surface fill, shadow, radius) and separate
     consecutive questions with a thin divider instead. */
  .section {
    background-color: transparent;
    box-shadow: none;
    border-radius: 0;
    margin: 0;
    padding: 16px 16px 20px;
  }

  .section + .section {
    border-top: 1px solid var(--divider-color);
  }
}

.section__index {
  font-size: 13px;
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--primary-color);
  margin-bottom: 8px;
}

.section__title {
  font-size: 16px;
  font-weight: var(--font-weight-bold);
  line-height: 1.3;
  color: var(--primary-text-color);
  margin: 0 0 2px;
  word-wrap: break-word;
}

.section__title .req {
  color: var(--danger-color);
  margin-inline-start: 3px;
}

.section__hint {
  font-size: 14px;
  color: var(--secondary-text-color);
  margin: 0 0 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.section__body {
  margin-top: 12px;
}

/* Structural section-header block: just heading + text, no card chrome bloat. */
.section--header {
  background: transparent;
  box-shadow: none;
  padding-bottom: 0;
}

.section--header .section__title {
  font-size: 18px;
}

/* Per-question media (image / video / file) shown inside the section. */
.media {
  margin: 4px 0 12px;
  border-radius: var(--radius-medium);
  overflow: hidden;
}

.media img,
.media video {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-medium);
}

.media__file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-medium);
  color: var(--primary-text-color);
}

.media__file-icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--primary-color);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.media__file-name {
  font-size: 14px;
  word-break: break-all;
}

/* ===========================================================================
   Controls — replicated 1:1 from Telegram tweb.
   =========================================================================== */

/* ---- Ripple -------------------------------------------------------------- */
.rp {
  position: relative;
  overflow: hidden;
}

.ripple {
  position: absolute;
  border-radius: 50%;
  transform: scale(0);
  background-color: var(--ripple-color);
  pointer-events: none;
  animation: ripple-effect var(--ripple-duration) var(--easing) forwards;
}

@keyframes ripple-effect {
  to {
    transform: scale(2.2);
    opacity: 0;
  }
}

/* ---- Choice rows (single / multi) ---------------------------------------- */
.choice {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 3rem;
  padding: 8px 4px;
  cursor: pointer;
  border-radius: var(--radius-small);
  user-select: none;
}

.choice + .choice {
  border-top: 1px solid var(--divider-color);
  border-radius: 0;
}

.choice__control {
  flex: 0 0 auto;
}

.choice__label {
  flex: 1 1 auto;
  font-size: 16px;
  line-height: 1.3;
  word-wrap: break-word;
}

/* Radio (single_choice / dropdown-as-radio / yes_no) */
.radio {
  position: relative;
  width: 1.375rem;
  height: 1.375rem;
}

.radio::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid var(--secondary-text-color);
  border-radius: 50%;
  transition: border-color 0.1s ease;
}

.radio::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--primary-color);
  transform: scale(0);
  transition: transform 0.1s ease;
}

.choice.is-checked .radio::before {
  border-color: var(--primary-color);
}

.choice.is-checked .radio::after {
  transform: scale(1);
}

/* Checkbox (multi_choice) */
.checkbox {
  position: relative;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 0.3125rem;
  border: 2px solid #8d969c;
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.checkbox__fill {
  position: absolute;
  inset: -15%;
  background-color: var(--primary-color);
  border-radius: 50%;
  transform: scale(0);
  transition: transform 0.2s 0.05s ease-in-out;
}

.checkbox__check {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 13px;
  height: 13px;
  z-index: 1;
}

.checkbox__check path {
  fill: none;
  stroke: #fff;
  stroke-width: 3.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 0, 24.19;
  transition: stroke-dasharray 0.1s ease-in-out;
}

.choice.is-checked .checkbox {
  border-color: var(--primary-color);
}

.choice.is-checked .checkbox__fill {
  transform: scale(1);
}

.choice.is-checked .checkbox__check path {
  stroke-dasharray: 24.19, 24.19;
  transition: stroke-dasharray 0.1s 0.15s ease-in-out;
}

/* "Other" free-text option for choices */
.choice__other-input {
  flex: 1 1 auto;
  border: none;
  border-bottom: 1px solid var(--input-border-color);
  background: transparent;
  padding: 4px 0;
  outline: none;
}

.choice__other-input:focus {
  border-bottom-color: var(--primary-color);
}

/* ---- Text input field (Telegram floating-label) -------------------------- */
.field {
  position: relative;
  margin-top: 6px;
}

.field__input {
  width: 100%;
  min-height: var(--control-height);
  border: 1px solid var(--input-border-color);
  border-radius: var(--radius-medium);
  background-color: var(--surface-color);
  color: var(--primary-text-color);
  padding: 0.8125rem 1rem;
  outline: none;
  transition: border-color 0.2s ease;
  line-height: var(--line-height);
  resize: none;
}

.field__input::placeholder {
  color: var(--input-placeholder-color);
}

.field__input:focus {
  border-color: var(--primary-color);
  border-width: 2px;
  padding: calc(0.8125rem - 1px) calc(1rem - 1px);
}

.field__input.is-error {
  border-color: var(--danger-color);
}

textarea.field__input {
  min-height: 6rem;
}

/* ---- Number / date inputs share the field look --------------------------- */
.field__input[type='number'],
.field__input[type='date'] {
  -webkit-appearance: none;
  appearance: none;
}

/* ---- Scale (linear scale, Telegram-poll inspired) ------------------------ */
.scale {
  margin-top: 8px;
}

.scale__row {
  display: flex;
  gap: 6px;
  justify-content: space-between;
}

.scale__btn {
  flex: 1 1 0;
  min-width: 0;
  height: 2.75rem;
  border: 1.5px solid var(--input-border-color);
  border-radius: var(--radius-small);
  background: var(--surface-color);
  color: var(--primary-text-color);
  font-size: 15px;
  font-weight: var(--font-weight-bold);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    color 0.15s ease;
}

.scale__btn.is-selected {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
  color: #fff;
}

.scale__labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 13px;
  color: var(--secondary-text-color);
}

/* ---- Rating (stars / hearts / points) ------------------------------------ */
.rating {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.rating__star {
  font-size: 2rem;
  line-height: 1;
  color: var(--secondary-color);
  cursor: pointer;
  transition: color 0.12s ease, transform 0.12s ease;
}

.rating__star.is-active {
  color: #f5b400;
}

.rating__star:active {
  transform: scale(0.85);
}

/* ---- Dropdown ------------------------------------------------------------ */
.dropdown {
  position: relative;
  margin-top: 6px;
}

.dropdown__select {
  width: 100%;
  min-height: var(--control-height);
  border: 1px solid var(--input-border-color);
  border-radius: var(--radius-medium);
  background-color: var(--surface-color);
  color: var(--primary-text-color);
  padding: 0 2.5rem 0 1rem;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.dropdown__select:focus {
  border-color: var(--primary-color);
}

.dropdown__arrow {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--secondary-text-color);
  font-size: 20px;
}

/* ===========================================================================
   Submit footer / MainButton fallback.
   Inside Telegram we use the native MainButton; on the website we render this.
   =========================================================================== */
.footer {
  flex: 0 0 auto;
  padding: 12px 12px calc(12px + var(--safe-bottom));
  background-color: var(--background-color);
}

.btn-primary {
  width: 100%;
  height: var(--control-height);
  border: none;
  border-radius: var(--radius-medium);
  background-color: var(--primary-color);
  color: #fff;
  font-size: 15px;
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.02em;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background-color var(--transition-out), opacity 0.2s ease;
}

.btn-primary:hover {
  background-color: var(--dark-primary-color);
}

.btn-primary:disabled {
  opacity: var(--disabled-opacity);
  pointer-events: none;
}

/* Hidden when the Telegram MainButton is in use. */
.footer.is-hidden {
  display: none;
}

/* ===========================================================================
   States: loading skeleton, error, thank-you, landing.
   =========================================================================== */
.center {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  gap: 12px;
}

.center__icon {
  font-size: 56px;
  color: var(--primary-color);
}

.center__title {
  font-size: 20px;
  font-weight: var(--font-weight-bold);
}

.center__text {
  font-size: 15px;
  color: var(--secondary-text-color);
  max-width: 320px;
}

/* Loading skeleton bars */
.skeleton {
  padding: 16px;
}

.skeleton__bar {
  height: 16px;
  border-radius: 8px;
  background: var(--skeleton-color);
  margin-bottom: 12px;
  animation: skeleton-pulse 1.2s ease-in-out infinite;
}

.skeleton__bar.w-60 {
  width: 60%;
}
.skeleton__bar.w-40 {
  width: 40%;
}
.skeleton__bar.w-90 {
  width: 90%;
}

@keyframes skeleton-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

/* Validation error toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: var(--radius-big);
  box-shadow: var(--float-shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  max-width: 88%;
  text-align: center;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Landing page (open pool.webaweba.com with no slug) */
.landing {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  gap: 20px;
}

.landing__logo {
  width: 96px;
  height: 96px;
  border-radius: 28px;
  background: linear-gradient(135deg, #3390ec, #1d6fd0);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 52px;
  box-shadow: var(--float-shadow);
}

.landing__title {
  font-size: 26px;
  font-weight: var(--font-weight-bold);
  margin: 0;
}

.landing__text {
  font-size: 16px;
  color: var(--secondary-text-color);
  max-width: 360px;
  margin: 0;
}

.landing__cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: var(--control-height);
  padding: 0 24px;
  border-radius: var(--radius-medium);
  background-color: var(--primary-color);
  color: #fff;
  font-weight: var(--font-weight-bold);
  font-size: 16px;
}

.landing__cta:hover {
  background-color: var(--dark-primary-color);
}
