*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Keep layout rules (flex/grid) from overriding application visibility. */
[hidden] {
  display: none !important;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: var(--line-height-base);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0 0 var(--space-3);
}

h1,
h2,
h3 {
  line-height: var(--line-height-tight);
  font-weight: 700;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--color-accent);
}

button,
input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* Accessible focus ring, visible for keyboard users on every interactive element */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  padding: var(--space-2) var(--space-4);
  z-index: 1000;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus {
  left: 0;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: var(--space-3) var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--font-size-base);
  background: var(--color-surface-alt);
  color: var(--color-text);
  transition: background var(--transition-fast), transform var(--transition-fast), border-color var(--transition-fast);
  text-decoration: none;
}
.btn:hover {
  color: var(--color-primary-contrast);
  background: var(--color-border);
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
}
.btn-primary:hover {
  background: var(--color-primary-dark);
  color: var(--color-primary-contrast);
}
.btn-accent {
  background: var(--color-accent);
  color: var(--color-primary-contrast);
}
.btn-accent:hover {
  background: var(--bmg-diamond);
  color: var(--color-primary-contrast);
}
.btn-outline {
  background: transparent;
  border-color: var(--color-border);
}
.btn-outline:hover {
  border-color: var(--color-primary);
}
.btn-danger-outline {
  background: transparent;
  border-color: var(--color-danger);
  color: var(--color-danger);
}
.btn-danger-outline:hover {
  color: var(--color-danger);
  background: rgba(242, 99, 123, 0.12);
}
.btn-sm {
  min-height: 36px;
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-sm);
}
.btn-block {
  width: 100%;
}

/* ---- Cards ---- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-md);
}

/* ---- Forms ---- */
.field {
  margin-bottom: var(--space-4);
}
.field label {
  display: block;
  font-weight: 600;
  margin-bottom: var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}
.field input[type='text'],
.field input[type='number'],
.field textarea,
.field select {
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-3);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}
.field textarea {
  resize: vertical;
  min-height: 88px;
}
.field-error {
  color: var(--color-danger);
  font-size: var(--font-size-sm);
  margin-top: var(--space-1);
}
.field-hint {
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  margin-top: var(--space-1);
}
.char-count {
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  text-align: right;
}

/* ---- Result bars (used for polls, friction meter, myth votes) ---- */
.result-bar-row {
  margin-bottom: var(--space-3);
}
.result-bar-label {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-1);
}
.result-bar-track {
  background: var(--color-bg-elevated);
  border-radius: 999px;
  height: 20px;
  overflow: hidden;
  border: 1px solid var(--color-border);
}
.result-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  border-radius: 999px;
  transition: width var(--transition-base);
  min-width: 4px;
}
.result-bar-row.is-preferred .result-bar-fill {
  background: linear-gradient(90deg, var(--color-success), #7be8b0);
}
.result-bar-row.is-preferred .result-bar-label::after {
  content: '✓ Preferred';
  color: var(--color-success);
  font-weight: 700;
  font-size: var(--font-size-xs);
}

@media (prefers-reduced-motion: reduce) {
  .result-bar-fill {
    transition: none;
  }
}

/* ---- Badges / status pills ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: var(--font-size-xs);
  font-weight: 700;
  border: 1px solid var(--color-border);
}
.badge::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.badge-open {
  color: var(--color-success);
  border-color: var(--color-success);
}
.badge-closed {
  color: var(--color-warning);
  border-color: var(--color-warning);
}
.badge-idle {
  color: var(--color-text-muted);
}

/* ---- Progress ---- */
.progress-track {
  height: 8px;
  background: var(--color-bg-elevated);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--color-border);
}
.progress-fill {
  height: 100%;
  background: var(--color-primary);
  transition: width var(--transition-base);
}
@media (prefers-reduced-motion: reduce) {
  .progress-fill {
    transition: none;
  }
}

/* ---- Layout helpers ---- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding-inline: var(--space-5);
}
.visually-hidden-focusable:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.banner-warning {
  background: rgba(245, 181, 68, 0.14);
  border: 1px solid var(--color-warning);
  color: var(--color-warning);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
}

.toast {
  position: fixed;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  max-width: min(90vw, 420px);
}
/* Class display rules (e.g. .setup-screen { display: flex }) otherwise override the hidden attribute */
[hidden] {
  display: none !important;
}

/* Static voting feedback: no motion or color-only timing cues. */
.voting-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  font-size: var(--font-size-sm);
}
.voting-pill {
  display: inline-block;
  max-width: 100%;
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-accent);
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
}
.voting-participation {
  color: var(--color-text);
}

.scene-intro {
  max-width: 65ch;
  flex-shrink: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-base);
  margin-bottom: var(--space-4);
  overflow-wrap: anywhere;
}

.pillar-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: var(--radius-md);
  background: var(--color-surface-alt);
  color: var(--color-accent);
}
.pillar-icon svg {
  display: block;
  width: 24px;
  height: 24px;
}

/* Presentation-style brand lockup on the opening scene. */
.welcome-scene {
  width: 100%;
  text-align: center;
}
.welcome-logo {
  display: block;
  width: clamp(136px, 18vw, 204px);
  max-width: 100%;
  height: auto;
  margin: 0 auto clamp(20px, 3vh, 36px);
}
.welcome-scene .scene-body-text,
.welcome-scene .p-body-text {
  margin-inline: auto;
}

/* Shared scene branding: a reserved lower-right strip, never behind content.
   The transparent source artwork is cropped by this box, not stretched. */
.stage:has(> .scene-brand),
.p-stage:has(> .scene-brand) {
  display: flex;
  flex-direction: column;
}
.scene-brand {
  --brand-size: clamp(240px, 30vw, 440px);
  --brand-bottom-crop: 48px;
  order: 100;
  flex: 0 0 auto;
  /* Match the square asset's visible height so its top curve is never cut. */
  height: calc(var(--brand-size) - var(--brand-bottom-crop));
  margin-top: auto;
  width: 100%;
  margin-bottom: calc(-1 * var(--space-6));
  overflow: hidden;
  pointer-events: none;
  background: url('/images/bmg_lowerslide.png') no-repeat;
  background-size: var(--brand-size) auto;
  background-position: right -24px bottom calc(-1 * var(--brand-bottom-crop));
  opacity: 0.4;
}
.stage:has(> .scene-brand) > :not(.scene-brand) {
  flex-shrink: 0;
}
.p-stage > .scene-brand {
  margin-bottom: calc(-1 * var(--space-8));
}
@media (max-width: 600px), (max-height: 600px) {
  .scene-brand {
    --brand-size: 148px;
    --brand-bottom-crop: 60px;
    opacity: 0.3;
  }
}
