.analytics-consent {
  position: relative;
}

.analytics-consent__notice {
  position: fixed;
  z-index: 1200;
  right: var(--space-4);
  bottom: var(--space-4);
  left: var(--space-4);
  display: grid;
  width: min(calc(100% - (2 * var(--space-4))), 44rem);
  margin-inline: auto;
  padding: var(--space-2) var(--space-3);
  border: var(--border-width-default) solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-card);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--font-size-xs);
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
}

/* Keep the notice reachable without covering a short or zoomed viewport. */
.analytics-consent__notice {
  bottom: max(var(--space-4), env(safe-area-inset-bottom, 0px));
  max-height: 50vh;
  max-height: 50dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.analytics-consent__notice[hidden] {
  display: none;
}

.analytics-consent__notice-title {
  font-size: inherit;
  overflow-wrap: anywhere;
}

.analytics-consent__notice-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.analytics-consent__notice-actions button {
  min-height: var(--space-11);
  padding: var(--space-2) var(--space-3);
  border: var(--border-width-default) solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font: inherit;
  font-weight: var(--font-weight-semibold);
}

.analytics-consent__notice-actions button[data-analytics-notice-settings] {
  background: var(--button-primary-bg);
  color: var(--button-primary-text);
}

.analytics-consent__notice-actions button[data-analytics-notice-close] {
  width: var(--space-11);
  padding: 0;
  border-radius: var(--radius-sm);
  font-size: inherit;
}

.analytics-consent__backdrop {
  position: fixed;
  z-index: 1200;
  display: grid;
  right: 0;
  bottom: 0;
  left: 0;
  padding: var(--space-4);
  pointer-events: none;
  place-items: end center;
}

.analytics-consent__backdrop[hidden] {
  display: none;
}

.analytics-consent__panel {
  position: relative;
  width: min(100%, 46rem);
  max-height: min(70dvh, 44rem);
  overflow-y: auto;
  padding: var(--space-7);
  border: var(--border-width-default) solid var(--border-strong);
  border-radius: var(--radius-xl);
  background: var(--surface-card);
  box-shadow: var(--shadow-xl);
  color: var(--text-primary);
  font-family: var(--font-body);
  pointer-events: auto;
}

.analytics-consent__eyebrow {
  margin: 0 0 var(--space-2);
  color: var(--surface-brand);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.analytics-consent__panel h2 {
  margin: 0;
  padding-right: var(--space-10);
  font-family: var(--font-display);
  font-size: clamp(var(--font-size-2xl), 6vw, var(--font-size-4xl));
  line-height: var(--line-height-heading);
}

.analytics-consent__panel > p:not(.analytics-consent__eyebrow) {
  margin: var(--space-4) 0 0;
  color: var(--text-secondary);
  line-height: var(--line-height-body);
}

.analytics-consent__panel a {
  color: var(--text-link);
  text-underline-offset: var(--space-1);
}

.analytics-consent__close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  display: inline-grid;
  width: var(--space-11);
  height: var(--space-11);
  padding: 0;
  border: var(--border-width-default) solid var(--border-default);
  border-radius: var(--radius-full);
  background: var(--surface-page);
  color: var(--text-primary);
  cursor: pointer;
  font: inherit;
  font-size: var(--font-size-2xl);
  place-items: center;
}

.analytics-consent__choices {
  display: grid;
  margin: var(--space-6) 0 0;
  padding: 0;
  border: 0;
  gap: var(--space-3);
}

.analytics-consent__choices legend {
  margin-bottom: var(--space-3);
  font-weight: var(--font-weight-semibold);
}

.analytics-consent__choices label {
  display: grid;
  padding: var(--space-4);
  border: var(--border-width-default) solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--surface-page);
  cursor: pointer;
  grid-template-columns: var(--space-6) 1fr;
  gap: var(--space-3);
}

.analytics-consent__choices input {
  width: var(--space-5);
  height: var(--space-5);
  margin: var(--space-1) 0 0;
  accent-color: var(--surface-brand);
}

.analytics-consent__choices span {
  display: grid;
  gap: var(--space-1);
}

.analytics-consent__choices small {
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-body);
}

.analytics-consent__actions {
  display: grid;
  margin-top: var(--space-6);
  gap: var(--space-2);
}

.analytics-consent__actions button {
  min-height: var(--space-12);
  padding: var(--space-3) var(--space-5);
  border: var(--border-width-default) solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--button-primary-bg);
  color: var(--button-primary-text);
  cursor: pointer;
  font: inherit;
  font-weight: var(--font-weight-semibold);
}

.analytics-consent__notice-actions button[data-analytics-notice-settings]:hover,
.analytics-consent__actions button:not([data-analytics-deny]):hover {
  background: var(--button-primary-bg-hover);
}

.analytics-consent__notice-actions button[data-analytics-notice-settings]:active,
.analytics-consent__actions button:not([data-analytics-deny]):active {
  background: var(--button-primary-bg-active);
}

.analytics-consent__actions button[data-analytics-deny] {
  background: transparent;
  color: var(--text-primary);
}

[data-theme="light"] .analytics-consent__panel {
  background: var(--surface-card);
  color: var(--text-primary);
}

[data-theme="dark"] .analytics-consent__panel {
  background: var(--surface-card);
  color: var(--text-primary);
}

.analytics-consent__close:focus-visible,
.analytics-consent__notice-actions button:focus-visible,
.analytics-consent__choices input:focus-visible,
.analytics-consent__actions button:focus-visible,
.analytics-consent__panel a:focus-visible {
  outline: var(--border-width-focus) solid var(--border-focus);
  outline-offset: var(--space-1);
}

/* R003: on phones the short notice stays one row (text + buttons) instead of a ~170 px block over the page. */
@media (max-width: 29.999rem) {
  .analytics-consent__notice { right: var(--space-2); left: var(--space-2); width: calc(100% - (2 * var(--space-2))); padding: var(--space-1) var(--space-2); }
  .analytics-consent__notice-actions { gap: var(--space-1); }
}

@media (min-width: 48rem) {
  .analytics-consent__notice {
    bottom: var(--space-8);
  }

  .analytics-consent__backdrop {
    padding: var(--space-8);
    place-items: end center;
  }

  .analytics-consent__actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .analytics-consent__actions button[data-analytics-deny] {
    grid-column: 1 / -1;
  }
}
