/*
 * Responsive Contest Details layout.
 * Desktop keeps the established contest presentation while mobile adds
 * reflowed result views and an interactive map-area view.
 */

.contest-details-responsive [hidden] {
  display: none !important;
}

.contest-details-responsive .prototype-desktop-overview::after {
  clear: both;
  content: '';
  display: block;
}

.contest-details-responsive .prototype-mobile-overview,
.contest-details-responsive .prototype-mobile-area-panel {
  display: none;
}

.contest-details-responsive #tooltip-span {
  overscroll-behavior: contain;
}

/* Keep the results header beside the accessible Close button, above the table. */
.contest-details-responsive #modalResults .modalTop {
  min-height: 0;
}

.contest-details-responsive #modalResultsHeader {
  box-sizing: border-box;
  min-height: 44px;
  overflow-wrap: anywhere;
  padding-right: 44px;
}

.contest-details-responsive #modalResultsHeading {
  font-weight: bold;
}

/* Reserve the wrapped error above its field, even while the live message is empty. */
.contest-details-responsive .map-area-selector {
  align-items: center;
  column-gap: 4px;
  display: grid;
  grid-template-columns: max-content minmax(0, max-content) max-content;
  justify-content: center;
}

.contest-details-responsive .map-area-selector > label {
  grid-column: 1;
  grid-row: 2;
}

.contest-details-responsive .map-area-selector > select,
.contest-details-responsive .map-area-selector > .filter-select-wrap {
  grid-column: 2;
  grid-row: 2;
}

.contest-details-responsive .map-area-selector > button {
  grid-column: 3;
  grid-row: 2;
}

.contest-details-responsive .area-validation-message {
  color: #b00020;
  display: grid;
  font-weight: bold;
  grid-column: 2 / -1;
  grid-row: 1;
  line-height: 1.3;
  /* Size the columns from the controls, then wrap the message within their span. */
  min-width: 100%;
  overflow-wrap: normal;
  text-align: left;
  width: 0;
}

.contest-details-responsive .area-validation-message > span {
  grid-area: 1 / 1;
  hyphens: none;
  min-width: 0;
  overflow-wrap: normal;
  word-break: normal;
}

.contest-details-responsive .area-validation-space {
  visibility: hidden;
}

/* Fit whole words when 400% mobile reflow leaves less than a phone's usual width. */
@media screen and (max-width: 192px) {
  .contest-details-responsive .area-validation-message {
    font-size: min(1em, 13.5vw);
  }
}

/* Keep the floating desktop summary visibly associated with its owning map region. */
@media all and (min-width: 801px) {
  .contest-details-responsive #svg path[data-tooltip-owner="true"]:not(:focus),
  .contest-details-responsive #svg path[data-tooltip-owner="true"][data-pointer-focus="true"]:focus {
    fill-opacity: 1;
    stroke: #ffff00;
    stroke-opacity: 1;
    stroke-width: calc(2px * var(--map-stroke-scale, 1));
  }
}

/* Avoid sticky touch-hover outlines while retaining hover feedback for a mouse. */
@media all and (max-width: 800px) and (hover: hover) and (pointer: fine) {
  .contest-details-responsive #mobileInteractiveSvg path[data-map-interaction-stroke="yellow"]:hover {
    stroke: #ffff00 !important;
  }

  .contest-details-responsive #mobileInteractiveSvg path[data-map-interaction-stroke="dark"]:hover {
    stroke: #003b5c !important;
  }

  .contest-details-responsive #mobileInteractiveSvg path[role="button"]:hover {
    stroke-width: calc(2px * var(--map-stroke-scale, 1));
  }
}

/* Match the legacy contest-heading wrap and rhythm without narrowing the stacked summary. */
@media screen and (min-width: 241px) and (max-width: 800px) {
  .contest-details-responsive .contest-summary-status > h2 {
    line-height: normal;
    text-wrap: balance;
  }
}

/* Keep the mobile title's legacy type size while reclaiming the subpixel wrap threshold. */
@media screen and (min-width: 241px) and (max-width: 500px) {
  .contest-details-responsive .contest-details-page > .site-header-title #lblHeader {
    letter-spacing: -0.005em;
  }
}

/* Keep the unzoomed iOS phone title on two lines without changing Android rendering. */
@supports (-webkit-touch-callout: none) {
  @media screen and (min-width: 241px) and (max-width: 500px) {
    html:not(.text-zoom-reflow-320) body.contest-details-responsive .contest-details-page > h1.site-header-title {
      font-size: clamp(1.15em, 4.2vw, 1.5em) !important;
      line-height: 1.3;
    }
  }
}

@media all and (max-width: 800px), handheld and (orientation: portrait) {
  html {
    scrollbar-gutter: stable;
  }

  .contest-details-responsive #contest-tabs {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .contest-details-responsive #contest-tabs > :where(.tab, .tabselected) {
    box-sizing: border-box;
    flex: 0 0 auto;
    max-width: 100%;
    padding-top: 0;
    width: 100%;
  }

  .contest-details-responsive #contest-tabs > :where(.tab, .tabselected)::before {
    border-radius: 0;
    top: 0;
  }

  .contest-details-responsive #contest-tabs > :where(.tab, .tabselected):first-child::before {
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
  }

  .contest-details-responsive #contest-tabs > .tabselected:not(:last-child)::before {
    border-bottom-color: gray;
  }

  .contest-details-responsive .prototype-desktop-overview {
    display: none !important;
  }

  .contest-details-responsive .prototype-mobile-overview:not([hidden]),
  .contest-details-responsive .prototype-mobile-area-panel:not([hidden]) {
    display: block;
  }

  .contest-details-responsive .prototype-mobile-map {
    box-sizing: border-box;
    margin: 0 auto 8px;
    max-width: 100%;
    width: 100%;
  }

  .contest-details-responsive #mobileInteractiveMap {
    scroll-margin-top: 1px;
    width: 100%;
  }

  .contest-details-responsive .prototype-mobile-map svg {
    display: block;
    height: auto;
    margin: 0 auto;
    max-width: 100%;
    width: 100%;
  }

  .contest-details-responsive #mobileStaticSvg {
    pointer-events: none;
  }

  .contest-details-responsive :where(#mobileStaticSvg, #mobileInteractiveSvg) path {
    fill-opacity: 1;
    stroke-opacity: 1;
    stroke-width: calc(1px * var(--map-stroke-scale, 1));
    vector-effect: none;
  }

  /* Keep selection and focus strokes from changing which county receives a tap. */
  .contest-details-responsive #mobileInteractiveSvg path[role="button"] {
    pointer-events: visibleFill;
  }

  .contest-details-responsive #mobileInteractiveSvg path[role="img"] {
    pointer-events: none;
  }

  .contest-details-responsive :where(#mobileStaticSvg, #mobileInteractiveSvg) path[data-map-contrast-stroke="#fff"] {
    stroke: #fff !important;
  }

  .contest-details-responsive :where(#mobileStaticSvg, #mobileInteractiveSvg) path[data-map-contrast-stroke="#000"] {
    stroke: #000 !important;
  }

  .contest-details-responsive #mobileInteractiveSvg path[data-map-interaction-stroke="yellow"]:focus {
    stroke: #ffff00 !important;
  }

  .contest-details-responsive #mobileInteractiveSvg path[data-map-interaction-stroke="dark"]:focus {
    stroke: #003b5c !important;
  }

  .contest-details-responsive #mobileInteractiveSvg path[data-map-interaction-stroke="yellow"][aria-pressed="true"] {
    stroke: #ffff00 !important;
    stroke-width: calc(3px * var(--map-stroke-scale, 1));
  }

  .contest-details-responsive #mobileInteractiveSvg path[data-map-interaction-stroke="dark"][aria-pressed="true"] {
    stroke: #003b5c !important;
    stroke-width: calc(3px * var(--map-stroke-scale, 1));
  }

  .contest-details-responsive #mobileInteractiveSvg path[role="button"]:focus {
    filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 1px #000);
    outline: none !important;
    stroke-width: calc(3px * var(--map-stroke-scale, 1));
  }

  .contest-details-responsive .prototype-inline-results {
    border: 1px solid gray;
    border-radius: 5px;
    box-sizing: border-box;
    margin: 0 0 8px;
    max-width: 100%;
    padding: 5px;
  }

  .contest-details-responsive .prototype-inline-results-heading {
    font-size: inherit;
    margin: 0 0 4px;
  }

  .contest-details-responsive .prototype-inline-results .modal-reporting-description {
    display: block;
    margin: 0 0 4px;
  }

  .contest-details-responsive .prototype-inline-results .table-scroll-region {
    max-height: none;
    overflow-y: visible;
  }

  .contest-details-responsive #mobileStaticLegendResults {
    box-sizing: border-box;
    max-width: 100%;
  }

  .contest-details-responsive .prototype-mobile-area-selector {
    align-items: center;
    display: grid;
    gap: 4px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    margin-top: 8px;
  }

  .contest-details-responsive .prototype-mobile-area-selector label {
    font-weight: bold;
  }

  .contest-details-responsive .prototype-mobile-area-selector select {
    display: block;
    min-width: 0;
    width: 100%;
  }
}

@media screen and (max-width: 479px) {
  .contest-details-responsive .prototype-mobile-area-selector {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .contest-details-responsive .prototype-mobile-area-selector button {
    grid-column: 1 / -1;
    grid-row: 3;
    justify-self: stretch;
    width: 100%;
  }
}

/* Match width-based mobile reflow when a browser applies text-only zoom. */
html.text-zoom-reflow-320 body.contest-details-responsive .map-area-selector {
  align-items: stretch;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  min-width: 0;
  width: 100%;
}

/* Use the whole row for the error and native controls when zoom retains layout width. */
html.text-zoom-reflow-320 body.contest-details-responsive .map-area-selector > :where(label, .area-validation-message, select, button) {
  box-sizing: border-box;
  max-width: 100%;
  min-width: 0;
  width: 100%;
}

html.text-zoom-reflow-240 body.contest-details-responsive h1.site-header-title {
  box-sizing: border-box;
  font-size: clamp(1.35rem, 12vw, 1.5em) !important;
  line-height: 1.3;
  max-width: 100%;
  padding-inline: 4px !important;
  width: 100%;
}

html.text-zoom-reflow-240 body.contest-details-responsive #lblHeader {
  overflow-wrap: anywhere;
  white-space: normal;
  word-break: normal;
}

html.text-zoom-reflow-240 body.contest-details-responsive #divTextSize {
  align-items: center;
  box-sizing: border-box;
  display: flex !important;
  flex-wrap: nowrap;
  font-size: clamp(0.9rem, 11vw, 1em);
  gap: 2px;
  justify-content: center;
  max-width: 100%;
  padding-left: 0;
  white-space: nowrap;
  width: 100%;
}

html.text-zoom-reflow-240 body.contest-details-responsive #divTextSize .link-button {
  align-items: center;
  flex: 0 0 44px;
  height: 44px;
  justify-content: center;
  line-height: 1;
  max-width: 44px;
  min-height: 44px;
  min-width: 44px;
  width: 44px;
}

html.text-zoom-reflow-240 body.contest-details-responsive #divTextSize .link-button:first-of-type {
  font-size: 0.85em !important;
}

html.text-zoom-reflow-240 body.contest-details-responsive #divTextSize .link-button:last-of-type {
  font-size: 1.15em !important;
}

html.text-zoom-reflow-240 body.contest-details-responsive .table-scroll-region {
  box-sizing: border-box;
  max-width: 100%;
  overflow-x: auto;
}

/* Mobile contest context, sticky views, and compact supporting information. */
.contest-details-responsive .prototype-general-instructions,
.contest-details-responsive .prototype-contact {
  display: contents;
}

@media all and (max-width: 800px), handheld and (orientation: portrait) {
  .contest-details-responsive #divtabs {
    overflow: visible;
  }

  .contest-details-responsive #contest-tabs {
    align-items: stretch;
    background: #fff;
    border-bottom: 2px solid #333;
    box-sizing: border-box;
    display: grid;
    flex-direction: initial;
    gap: 2px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 0;
    padding: 2px 0;
    position: sticky;
    top: 0;
    width: 100%;
    z-index: 20;
  }

  .contest-details-responsive #contest-tabs > :where(.tab, .tabselected) {
    box-sizing: border-box;
    flex: initial;
    font-size: 0.9rem;
    line-height: 1.2;
    margin: 0;
    max-width: none;
    min-height: 44px;
    min-width: 0;
    overflow-wrap: normal;
    padding: 4px;
    top: 0;
    white-space: normal;
    width: 100%;
    word-break: normal;
  }

  .contest-details-responsive #contest-tabs > :where(.tab, .tabselected)::before {
    border-radius: 4px;
    top: 0;
  }

  .contest-details-responsive #contest-tabs > :where(.tab, .tabselected):focus-visible {
    outline: 3px solid #000;
    outline-offset: -4px;
  }

  .contest-details-responsive #contest-tabs + .tabdiv,
  .contest-details-responsive .tabdiv,
  .contest-details-responsive .prototype-contact,
  .contest-details-responsive .contest-summary-layout {
    scroll-margin-top: calc(var(--contest-details-sticky-tabs-height, 0px) + 6px);
  }

  .contest-details-responsive .prototype-general-instructions,
  .contest-details-responsive .prototype-contact {
    display: block;
  }

  .contest-details-responsive .prototype-general-instructions br {
    display: none;
  }

  .contest-details-responsive .contest-summary-status > h2 + br {
    display: none;
  }

  .contest-details-responsive .contest-summary-status,
  .contest-details-responsive .contest-summary-note {
    line-height: 1.35;
  }

  .contest-details-responsive .prototype-contact {
    line-height: 1.35;
    margin-top: 6px;
  }

  .contest-details-responsive .prototype-contact a[href^="mailto:"] {
    overflow-wrap: anywhere;
    word-break: normal;
  }

  .contest-details-responsive #div-msg {
    box-sizing: border-box;
    max-width: 100%;
  }

  .contest-details-responsive #p-msg {
    margin: 4px 0;
  }

  .contest-details-responsive .contest-summary-layout {
    display: block;
    margin: 0;
  }

  .contest-details-responsive .contest-summary-status,
  .contest-details-responsive .contest-summary-note {
    margin: 0;
    max-width: none;
    width: 100%;
  }

  .contest-details-responsive #divtabs > .prototype-general-instructions {
    border-top: 2px solid #555;
    margin-top: 8px;
    padding: 8px 4px 0;
  }

  .contest-details-responsive #divtabs > .prototype-contact {
    margin: 6px 0 0;
    padding: 0 4px 2px;
  }
}

/* Stack tabs at zoom-created narrow widths so every label remains readable. */
@media screen and (max-width: 240px) {
  body.contest-details-responsive #contest-tabs {
    display: grid;
    flex-direction: initial;
    gap: 2px;
    grid-template-columns: minmax(0, 1fr);
    position: static;
  }

  body.contest-details-responsive #contest-tabs > :where(.tab, .tabselected) {
    flex: initial;
    font-size: 0.9rem;
    line-height: 1.2;
    min-height: 48px;
    padding: 4px;
    width: 100%;
  }
}

/* Safari text-only zoom can retain a wide layout viewport; mirror the same stack. */
html.text-zoom-reflow-240 body.contest-details-responsive.contest-details-responsive-mobile .contest-details-page #contest-tabs {
  display: grid;
  flex-direction: initial;
  gap: 2px;
  grid-template-columns: minmax(0, 1fr);
  position: static;
}

html.text-zoom-reflow-240 body.contest-details-responsive.contest-details-responsive-mobile .contest-details-page #contest-tabs > :where(.tab, .tabselected) {
  flex: initial;
  font-size: 0.9rem;
  line-height: 1.2;
  min-height: 48px;
  padding: 4px;
  width: 100%;
}

html.contest-details-responsive-active {
  scroll-padding-top: calc(var(--contest-details-sticky-tabs-height, 0px) + 6px);
}

@media (prefers-reduced-motion: reduce) {
  html.contest-details-responsive-active {
    scroll-behavior: auto;
  }
}

@media (forced-colors: active) {
  .contest-details-responsive #contest-tabs {
    border-bottom-color: CanvasText;
  }

  .contest-details-responsive #contest-tabs > :where(.tab, .tabselected):focus-visible {
    outline-color: Highlight;
  }
}
