/* =============================================================================
 * ballot-ceremony.css — Heisman 3-card flip/zoom/fog ballot ceremony (W3-W5)
 *
 * Scoped entirely to .hbc-* — zero leakage.
 * Palette mirrors heisman.css tokens (inline so this file is standalone).
 *
 *   --hm-bronze:    #C7884A
 *   --hm-gold-leaf: #E8C77A
 *   --hm-wood:      #241910
 *   --hm-ivory:     #F4ECD8
 *
 * 3D-card tilt: Aceternity "3D Card" pattern, vanilla-ported.
 * Focus Cards: blur+dim non-focused cards.
 * Card Stack: staggered starting deal.
 * Lens/Expand: CSS scale+translate zoom on the focused card.
 * ============================================================================= */

/* ── Table / felt surface ─────────────────────────────────────────────────── */
.hbc-wrap {
  position: relative;
  width: 100%;
  padding: 28px 12px 36px;
  /* Felt surface */
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, rgba(36,25,16,.95) 0%, #120c06 100%);
  border-radius: 20px;
  border: 1px solid rgba(199,136,74,.22);
  /* NOTE: overflow:hidden removed — combined with isolation:isolate it caused Chromium
     to exclude child elements from hit-testing (elementFromPoint returned the mount
     instead of cards), making cards unclickable. Pseudo-elements are inset:0 so they
     don't overflow; the picker z-stack manages its own overflow. */
  overflow: visible;
  /* isolate stacking contexts */
  isolation: isolate;
}

/* Felt texture overlay */
.hbc-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  /* Fine cross-hatch felt */
  background-image:
    repeating-linear-gradient(
      45deg,
      rgba(199,136,74,.03) 0px, rgba(199,136,74,.03) 1px,
      transparent 1px, transparent 8px
    ),
    repeating-linear-gradient(
      -45deg,
      rgba(199,136,74,.02) 0px, rgba(199,136,74,.02) 1px,
      transparent 1px, transparent 8px
    );
  border-radius: inherit;
}

/* Corner gold rule accents */
.hbc-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(135deg, rgba(232,199,122,.06) 0%, transparent 30%),
    linear-gradient(315deg, rgba(199,136,74,.04) 0%, transparent 30%);
  border-radius: inherit;
}

/* ── Caption / instruction text ──────────────────────────────────────────── */
.hbc-caption {
  position: relative;
  z-index: 2;
  text-align: center;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(244,236,216,.55);
  margin-bottom: 24px;
  min-height: 1.4em;
  transition: opacity 0.3s;
}

/* ── Card stage ───────────────────────────────────────────────────────────── */
/* The stage is a relative-positioned container; individual card wrappers
   inside are positioned by JS translate to pan between cards. */
.hbc-stage {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(10px, 3vw, 20px);
  padding: 8px 4px 16px;
  /* perspective for the 3D tilt effect */
  perspective: 1200px;
  /* allow overflow for the zoom-scale effect */
  overflow: visible;
  min-height: 280px;
}

/* ── Per-card wrapper (handles transform: focus zoom + 3D tilt) ───────────── */
.hbc-card-wrap {
  position: relative;
  flex-shrink: 0;
  /* Tilt is applied via JS mousemove CSS vars */
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.34,1.56,0.64,1),
              filter 0.35s ease,
              opacity 0.35s ease,
              z-index 0s;
  z-index: 1;
  will-change: transform;
  /* cursor affordance */
  cursor: pointer;
}

/* Tilt via CSS vars (set by JS) — 3D Card Effect (Aceternity port) */
.hbc-card-wrap {
  --tilt-x: 0deg;
  --tilt-y: 0deg;
}

/* Card size: three cards fit across without overflow on 390px mobile */
.hbc-card-wrap .heis-card {
  --heis-w: clamp(100px, 26vw, 190px);
}

/* ── Focus state: zoom + center + dim others ──────────────────────────────── */
.hbc-stage.is-focused .hbc-card-wrap:not(.is-focused) {
  opacity: 0.28;
  filter: blur(3px);
  pointer-events: none;
}

/* Focused card: scale up and raise z */
.hbc-stage.is-focused .hbc-card-wrap.is-focused {
  transform: scale(1.48) !important;
  z-index: 20;
  cursor: default;
  filter: none;
  opacity: 1;
}

/* ── Deal animation (ported from showdown.js runDealAnimation) ───────────── */
@keyframes hbcDealFly {
  0% {
    opacity: 0;
    transform:
      translateX(var(--deal-dx, 0px))
      translateY(var(--deal-dy, 240px))
      scale(0.78)
      rotate(var(--deal-rot, 3deg));
  }
  35% {
    opacity: 1;
    transform:
      translateX(calc(var(--deal-dx, 0px) * 0.3))
      translateY(calc(var(--deal-dy, 240px) * 0.3))
      scale(0.92)
      rotate(calc(var(--deal-rot, 3deg) * 0.4));
  }
  100% {
    opacity: 1;
    transform: translateX(0) translateY(0) scale(1) rotate(0deg);
  }
}

.hbc-card-wrap.hbc-dealing {
  opacity: 0;
  transform: translateX(var(--deal-dx, 0px)) translateY(var(--deal-dy, 240px)) scale(0.78) rotate(var(--deal-rot, 3deg));
}

.hbc-card-wrap.hbc-dealt {
  animation: hbcDealFly 480ms cubic-bezier(0.34,1.56,0.64,1) both;
}

/* Set state (filled, awaiting OK confirmation) */
.hbc-card-wrap.is-set {
  /* gentle gold glow on set cards */
  filter: drop-shadow(0 0 12px rgba(232,199,122,.35));
}

/* Locked state (submitted) */
.hbc-card-wrap.is-locked {
  filter: drop-shadow(0 0 16px rgba(199,136,74,.5));
  cursor: default;
  pointer-events: none;
}

/* ── FOG FX panel (shown while focus is active, before OK) ───────────────── */
.hbc-fog {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
  /* Wispy fog gradients layered */
  background:
    radial-gradient(ellipse 70% 40% at 30% 60%, rgba(199,136,74,.12) 0%, transparent 65%),
    radial-gradient(ellipse 50% 50% at 70% 30%, rgba(232,199,122,.08) 0%, transparent 60%),
    radial-gradient(ellipse 80% 60% at 50% 80%, rgba(140,80,30,.14) 0%, transparent 70%);
  /* noise texture via SVG filter */
  filter: blur(18px);
}

.hbc-fog.is-visible {
  opacity: 1;
}

/* ── PICKER panel (fixed overlay, positioned by JS) ──────────────────────── */
/* Position:fixed is set inline by openPicker() using getBoundingClientRect
   so the picker escapes all stacking contexts (isolation:isolate on .hbc-wrap,
   overflow:hidden on .ht-panel, etc.) and never overlaps adjacent panels.
   CSS only provides appearance + z-index. */
.hbc-picker {
  /* position is always set by JS to fixed */
  position: fixed;
  z-index: 9999;
  background: #1a1005;
  border: 1px solid rgba(199,136,74,.45);
  border-radius: 14px;
  box-shadow:
    0 24px 60px rgba(0,0,0,.8),
    inset 0 0 0 1px rgba(232,199,122,.08);
  padding: 16px;
  display: none;
  /* Clamp height in case viewport is short */
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
}

.hbc-picker.is-open {
  display: block;
  animation: hbcPickerIn 0.28s cubic-bezier(0.34,1.4,0.64,1) both;
}

@keyframes hbcPickerIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.hbc-picker-head {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(199,136,74,.8);
  margin-bottom: 10px;
}

/* Chip grid for top10 suggestions */
.hbc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.hbc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(199,136,74,.12);
  border: 1px solid rgba(199,136,74,.35);
  cursor: pointer;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.68rem;
  font-weight: 600;
  color: rgba(244,236,216,.85);
  transition: background 0.15s, border-color 0.15s;
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
}

.hbc-chip:hover,
.hbc-chip:focus-visible {
  background: rgba(199,136,74,.22);
  border-color: rgba(232,199,122,.6);
  outline: none;
}

.hbc-chip-school {
  font-size: 0.58rem;
  color: rgba(199,136,74,.65);
  font-weight: 500;
  font-style: italic;
}

/* Search box */
.hbc-search-wrap {
  position: relative;
  margin-bottom: 10px;
}

.hbc-search {
  width: 100%;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(199,136,74,.35);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.78rem;
  color: #F4ECD8;
  outline: none;
  transition: border-color 0.15s;
  box-sizing: border-box;
}

.hbc-search::placeholder { color: rgba(244,236,216,.3); }

.hbc-search:focus {
  border-color: rgba(232,199,122,.6);
}

/* Search results list */
.hbc-results {
  max-height: 180px;
  overflow-y: auto;
  border-radius: 8px;
  margin-bottom: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(199,136,74,.4) transparent;
}

.hbc-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 6px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.72rem;
  color: rgba(244,236,216,.85);
  transition: background 0.12s;
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
}

.hbc-result-item:hover,
.hbc-result-item:focus-visible {
  background: rgba(199,136,74,.18);
  outline: none;
}

.hbc-result-school {
  font-size: 0.6rem;
  color: rgba(199,136,74,.6);
  margin-left: 4px;
}

/* Write-in toggle + input */
.hbc-writein-toggle {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.62rem;
  color: rgba(199,136,74,.7);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  background: none;
  border: none;
  padding: 0;
  margin-bottom: 8px;
  display: block;
  min-height: 28px;
  -webkit-tap-highlight-color: transparent;
}

.hbc-writein-input {
  width: 100%;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(199,136,74,.35);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.78rem;
  color: #F4ECD8;
  outline: none;
  margin-bottom: 10px;
  display: none;
  box-sizing: border-box;
}

.hbc-writein-input.is-open {
  display: block;
  animation: hbcFadeIn 0.2s ease both;
}

/* Picker error */
.hbc-picker-err {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.65rem;
  color: #e05252;
  margin-bottom: 8px;
  display: none;
  min-height: 1.2em;
}

.hbc-picker-err.is-visible { display: block; }

/* OK / confirm button */
.hbc-ok-btn {
  width: 100%;
  padding: 11px 20px;
  background: linear-gradient(135deg, #C7884A 0%, #E8C77A 60%, #C7884A 100%);
  border: none;
  border-radius: 8px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #1a0e04;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.12s;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.hbc-ok-btn:hover { opacity: 0.92; transform: translateY(-1px); }
.hbc-ok-btn:active { transform: translateY(0); }
.hbc-ok-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── Cast button row ──────────────────────────────────────────────────────── */
.hbc-cast-row {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 28px;
}

.hbc-cast-btn {
  padding: 14px 36px;
  background: linear-gradient(135deg, #8A5A2B 0%, #C7884A 35%, #E8C77A 65%, #C7884A 100%);
  border: none;
  border-radius: 10px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #1a0e04;
  cursor: pointer;
  min-height: 52px;
  min-width: 220px;
  transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(199,136,74,.35);
  -webkit-tap-highlight-color: transparent;
}

.hbc-cast-btn:hover:not(:disabled) {
  opacity: 0.92;
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(199,136,74,.5);
}

.hbc-cast-btn:active:not(:disabled) { transform: translateY(0); }

.hbc-cast-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.hbc-error-msg {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.68rem;
  color: #e05252;
  text-align: center;
  display: none;
  min-height: 1.2em;
}

.hbc-error-msg.is-visible { display: block; }

/* ── Distinct-pick warning (block same player on 2 cards) ─────────────────── */
.hbc-dup-warning {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.62rem;
  color: #E8C77A;
  text-align: center;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(232,199,122,.1);
  border: 1px solid rgba(232,199,122,.3);
  display: none;
}
.hbc-dup-warning.is-visible { display: block; }

/* ── Status panels (closed ballot / locked ballot) ───────────────────────── */
.hbc-status-panel {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 32px 20px;
  font-family: 'Inter', system-ui, sans-serif;
}

.hbc-status-icon {
  font-size: 2.2rem;
  margin-bottom: 12px;
  display: block;
}

.hbc-status-title {
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--hm-gold-leaf, #E8C77A);
  margin-bottom: 8px;
}

.hbc-status-sub {
  font-size: 0.75rem;
  color: rgba(244,236,216,.55);
  line-height: 1.6;
  max-width: 320px;
  margin: 0 auto;
}

/* ── Cast success flourish ────────────────────────────────────────────────── */
@keyframes hbcSeal {
  0%   { transform: scale(0.5) rotate(-20deg); opacity: 0; }
  60%  { transform: scale(1.15) rotate(4deg);  opacity: 1; }
  100% { transform: scale(1) rotate(0deg);    opacity: 1; }
}

.hbc-cast-sealed .hbc-card-wrap.is-locked .heis-card__seal {
  animation: hbcSeal 0.55s cubic-bezier(0.34,1.4,0.64,1) both;
}

/* ── 409 / 403 states ─────────────────────────────────────────────────────── */
.hbc-alert {
  position: relative;
  z-index: 2;
  padding: 14px 18px;
  border-radius: 10px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.72rem;
  color: rgba(244,236,216,.85);
  line-height: 1.55;
  border: 1px solid rgba(199,136,74,.4);
  background: rgba(199,136,74,.1);
  text-align: center;
  margin-top: 12px;
}

.hbc-alert--error {
  border-color: rgba(224,82,82,.5);
  background: rgba(224,82,82,.1);
  color: rgba(244,200,200,.9);
}

/* ── Loading shimmer ──────────────────────────────────────────────────────── */
.hbc-loading {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
  color: rgba(199,136,74,.5);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

@keyframes hbcFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Guest gate: Cast Ballot button prompt ────────────────────────────────── */
.hbc-login-gate {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding: 16px;
  border-radius: 10px;
  background: rgba(199,136,74,.08);
  border: 1px solid rgba(199,136,74,.3);
  text-align: center;
}

.hbc-login-gate p {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.72rem;
  color: rgba(244,236,216,.65);
  margin: 0;
  line-height: 1.5;
}

.hbc-login-gate a {
  display: inline-block;
  padding: 10px 22px;
  background: linear-gradient(135deg, #C7884A, #E8C77A);
  border-radius: 8px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #1a0e04;
  text-decoration: none;
  min-height: 44px;
  display: flex;
  align-items: center;
  transition: opacity 0.15s;
}

.hbc-login-gate a:hover { opacity: 0.88; }

/* ── Locked read-only three-card display ──────────────────────────────────── */
.hbc-locked-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.hbc-locked-header {
  position: relative;
  z-index: 2;
  text-align: center;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(232,199,122,.7);
  padding-bottom: 12px;
}

/* ── prefers-reduced-motion overrides ────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .hbc-card-wrap {
    transition: opacity 0.15s ease, filter 0.15s ease !important;
  }

  .hbc-card-wrap.hbc-dealing {
    opacity: 1 !important;
    transform: none !important;
  }

  .hbc-card-wrap.hbc-dealt {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }

  .hbc-stage.is-focused .hbc-card-wrap.is-focused {
    /* instant focus, no spring scale */
    transition: none !important;
  }

  .hbc-picker.is-open {
    animation: none !important;
  }

  .hbc-cast-sealed .hbc-card-wrap.is-locked .heis-card__seal {
    animation: none !important;
  }

  .hbc-fog { display: none !important; }
}

/* ── Mobile: table + zoomed card fit within 100dvh ───────────────────────── */
@media (max-width: 480px) {
  .hbc-wrap {
    padding: 20px 8px 24px;
    border-radius: 12px;
  }

  .hbc-card-wrap .heis-card {
    --heis-w: clamp(88px, 24vw, 110px);
  }

  /* On mobile, zoom is less aggressive to stay within viewport */
  .hbc-stage.is-focused .hbc-card-wrap.is-focused {
    transform: scale(1.28) !important;
  }

  .hbc-picker {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    transform: none;
    width: 100%;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-radius: 16px 16px 0 0;
    max-height: 65dvh;
    overflow-y: auto;
    z-index: 200;
  }

  .hbc-picker.is-open {
    animation: hbcSlideUp 0.3s cubic-bezier(0.34,1.2,0.64,1) both;
  }

  @keyframes hbcSlideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }

  /* Mobile picker backdrop */
  .hbc-picker-backdrop {
    display: block !important;
  }
}

/* Mobile picker backdrop (hidden on desktop) */
.hbc-picker-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 199;
  -webkit-backdrop-filter: blur(2px);
          backdrop-filter: blur(2px);
}

/* ── Horizontal overflow guard ────────────────────────────────────────────── */
.hbc-stage {
  max-width: 100%;
}

/* ── Card slot number indicator (above each card) ────────────────────────── */
.hbc-slot-label {
  display: block;
  text-align: center;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(199,136,74,.55);
  margin-bottom: 4px;
}

/* Highlight active slot */
.hbc-card-wrap.is-active-slot .hbc-slot-label {
  color: rgba(232,199,122,.85);
}
