/**
 * Cookie consent bar.
 *
 * Same treatment as the reference site (zhihuilu.com/en/): the notice is a
 * strip at the very top of the document, above the site header, in normal
 * flow. It pushes the page down instead of floating over it, so nothing is
 * ever covered and no bottom padding has to be faked. Once a choice is made
 * the strip is removed and the page closes the gap.
 *
 * Loaded on every page and never deferred: it has to be paintable before the
 * visitor starts reading. Nothing here loads an external font or image.
 */

/* The gate in the head puts `cm-ck-pending` on <html> only when no choice is
   stored yet, so the strip never flashes for a returning visitor. */
.cm-ck {
  position: relative;
  z-index: 60;
  display: none;
  background: var(--cm-surface-2);
  border-bottom: 1px solid var(--cm-line);
  color: var(--cm-ink);
  font-size: var(--cm-fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
html.cm-ck-pending .cm-ck { display: block; }

.cm-ck__in {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  width: 100%;
  max-width: var(--cm-container, 1440px);
  min-height: 68px;
  margin-inline: auto;
  padding: 14px var(--cm-gutter, 24px);
  box-sizing: border-box;
}

/* Two lines at 720px on a desktop. Centred, because it is a notice, not a
   paragraph of the page. */
.cm-ck__text {
  flex: 0 1 720px;
  max-width: 720px;
  margin: 0;
  color: var(--cm-ink);
  font-size: var(--cm-fs-base);
  line-height: 1.5;
  text-align: center;
  text-wrap: pretty;
}
.cm-ck__policy {
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  white-space: nowrap;
}
.cm-ck__policy:hover,
.cm-ck__policy:focus-visible {
  color: var(--cm-navy);
  text-decoration-thickness: 2px;
  outline: none;
}

.cm-ck__acts {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.cm-ck__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  height: 36px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--cm-r, 8px);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease;
}
.cm-ck__btn--yes {
  background: var(--cm-ink);
  border-color: var(--cm-ink);
  color: var(--cm-on-dark);
}
.cm-ck__btn--yes:hover,
.cm-ck__btn--yes:focus-visible {
  background: var(--cm-navy);
  border-color: var(--cm-navy);
  outline: none;
}
.cm-ck__btn--no {
  background: var(--cm-surface);
  border-color: var(--cm-line-strong);
  color: var(--cm-ink);
}
.cm-ck__btn--no:hover,
.cm-ck__btn--no:focus-visible {
  background: var(--cm-surface);
  border-color: var(--cm-ink-3);
  outline: none;
}

/* Settings is a link, not a third decision — it must not compete with the
   two answers. */
.cm-ck__link {
  padding: 0;
  margin-inline-end: 6px;
  border: 0;
  background: none;
  color: var(--cm-ink-3);
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: nowrap;
  cursor: pointer;
}
.cm-ck__link:hover,
.cm-ck__link:focus-visible {
  color: var(--cm-ink);
  outline: none;
  text-decoration-thickness: 2px;
}
.cm-ck__link[aria-expanded="true"] { color: var(--cm-ink); }

/* --------------------------------------------------------------------------
   Preferences — opens under the strip, also in flow
   -------------------------------------------------------------------------- */
.cm-ck__prefs {
  border-top: 1px solid var(--cm-line);
  background: var(--cm-surface-3);
}
.cm-ck__prefs[hidden] { display: none; }

.cm-ck__prefs-in {
  max-width: var(--cm-container, 1440px);
  margin-inline: auto;
  padding: 18px var(--cm-gutter, 24px) 20px;
  box-sizing: border-box;
  display: grid;
  gap: 16px;
}

.cm-ck__row { max-width: 720px; }

.cm-ck__rowt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--cm-ink);
  font-size: var(--cm-fs-base);
  line-height: 1.4;
}
.cm-ck__rowt strong { font-weight: 700; }
label.cm-ck__rowt { cursor: pointer; }

.cm-ck__rowd {
  margin: 3px 0 0;
  color: var(--cm-ink-3);
  font-size: 13px;
  line-height: 1.55;
}

.cm-ck__fixed {
  flex: 0 0 auto;
  color: var(--cm-ink-3);
  font-size: var(--cm-fs-sm);
  letter-spacing: .02em;
}

/* Toggle — 38×22, the size of the reference switch. */
.cm-ck__sw {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  width: 38px;
  height: 22px;
}
.cm-ck__sw input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.cm-ck__sw i {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--cm-r-pill, 999px);
  background: var(--cm-line-strong);
  transition: background-color .18s ease;
  pointer-events: none;
}
.cm-ck__sw i::after {
  content: "";
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cm-surface);
  box-shadow: 0 1px 2px rgba(18, 26, 34, .2);
  transition: transform .18s ease;
}
.cm-ck__sw input:checked + i { background: var(--cm-ink); }
.cm-ck__sw input:checked + i::after { transform: translateX(16px); }
.cm-ck__sw input:focus-visible + i {
  outline: 2px solid var(--cm-ink);
  outline-offset: 2px;
}

.cm-ck__save {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.cm-ck__saved {
  color: var(--cm-success);
  font-size: 13px;
  font-weight: 600;
}
.cm-ck__saved[hidden] { display: none; }

/* --------------------------------------------------------------------------
   Footer trigger — reads as one more legal link
   -------------------------------------------------------------------------- */
.cm-footer__ck {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
}
.cm-footer__ck:hover { color: var(--cm-on-dark); text-decoration: underline; }
.cm-footer__ck:focus-visible { outline: 2px solid var(--cm-primary); outline-offset: 2px; }

/* --------------------------------------------------------------------------
   Responsive — the strip stacks, the two answers stay side by side
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .cm-ck { font-size: var(--cm-fs-sm); line-height: 1.55; }
  .cm-ck__in {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    min-height: 0;
    max-width: none;
    padding: 14px var(--cm-sp-4, 16px) 16px;
  }
  /* Left-aligned once it wraps: centred text over four lines is hard to
     find the start of. */
  .cm-ck__text {
    flex: none;
    max-width: none;
    font-size: var(--cm-fs-sm);
    line-height: 1.55;
    text-align: start;
  }
  .cm-ck__acts { gap: 8px; }
  .cm-ck__link { flex: 0 0 auto; margin-inline-end: 4px; padding: 0 2px; font-size: var(--cm-fs-sm); }
  /* Both answers get the same width and height — no nudging one into being
     the easier target. */
  .cm-ck__btn { flex: 1 1 0; min-width: 0; height: 40px; padding: 0 10px; font-size: 13px; }
  .cm-ck__prefs-in { padding: 16px; gap: 14px; }
  .cm-ck__rowt { font-size: 13px; }
  .cm-ck__rowd { font-size: var(--cm-fs-sm); }
  .cm-ck__save .cm-ck__btn { flex: 0 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .cm-ck__btn,
  .cm-ck__sw i,
  .cm-ck__sw i::after { transition: none; }
}
