/* ballotreels phone UI: the videos' sketchbook look. Cream graph paper,
   graphite text, Caveat headings with an orange pencil underline,
   Patrick Hand body text, pencil-outlined boxes and taped paper scraps.
   One accent colour (the orange); nothing here carries a side's or a
   yes/no meaning (STANDARD rule 4.1). Fonts are self-hosted under
   fonts/ with their OFL licences. */

@font-face {
  font-family: "Caveat";
  src: url("fonts/Caveat-Variable.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
}

@font-face {
  font-family: "Patrick Hand";
  src: url("fonts/PatrickHand-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}

:root {
  --paper: #f3eedf;
  --desk: #e2d9c2;
  --grid: rgba(120, 108, 76, 0.14);
  --ink: #2e2b27;
  --ink-soft: #5f584e;
  --ink-faint: rgba(46, 43, 39, 0.35);
  --accent: #e07b33;
  --accent-soft: rgba(224, 123, 51, 0.35);
  --scrap: #fbf8ef;
  --tape: rgba(222, 204, 140, 0.65);
  --hand-radius: 255px 14px 225px 14px / 14px 225px 14px 255px;
  --box-radius: 3px 6px 4px 7px / 6px 3px 7px 4px;
  --heading: "Caveat", "Patrick Hand", cursive;
  --body: "Patrick Hand", "Comic Sans MS", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  overflow-x: hidden;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1.15rem;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

/* The notebook page: the full screen on a phone, a centred column with
   a little shadow on a desktop. */
.page {
  max-width: 540px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: 0 20px 24px;
  display: flex;
  flex-direction: column;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: -1px -1px;
}

@media (min-width: 600px) {
  .page {
    margin: 28px auto;
    min-height: calc(100vh - 56px);
    padding: 0 36px 28px;
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(60, 50, 30, 0.15),
                0 8px 30px rgba(60, 50, 30, 0.18);
  }
}

main {
  flex: 1;
}

/* -- header: the notebook's binding and the name ------------------- */

.site-header {
  position: relative;
  padding-top: 26px;
  margin: 0 -20px 4px;
  padding-left: 20px;
  padding-right: 20px;
}

@media (min-width: 600px) {
  .site-header {
    margin: 0 -36px 8px;
    padding-left: 36px;
    padding-right: 36px;
  }
}

/* A row of binding holes along the top edge, like the video's spiral. */
.site-header::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 8px;
  height: 12px;
  background-image: radial-gradient(circle at 50% 50%,
    var(--ink) 0, var(--ink) 4px, transparent 4.6px);
  background-size: 28px 12px;
  background-position: 6px 0;
  background-repeat: repeat-x;
  opacity: 0.85;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  font-family: var(--heading);
  font-weight: 700;
  font-size: 1.9rem;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 26px;
  height: 26px;
  flex: none;
}

/* -- type ----------------------------------------------------------- */

h1, h2 {
  font-family: var(--heading);
  font-weight: 700;
  line-height: 1.1;
  margin: 0.6rem 0 0.8rem;
}

h1 {
  font-size: 2.5rem;
}

h2 {
  font-size: 2rem;
}

h3 {
  font-family: var(--heading);
  font-weight: 700;
  font-size: 1.6rem;
  line-height: 1.15;
  margin: 1.6rem 0 0.5rem;
}

/* The video's hand-drawn orange pencil line under a heading. */
.scribble {
  display: inline;
  padding-bottom: 0.18em;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 12' preserveAspectRatio='none'%3E%3Cpath d='M3 7 C 60 4, 120 9, 180 6 S 270 5, 297 7' fill='none' stroke='%23e07b33' stroke-width='3' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3Cpath d='M12 9 C 80 7, 160 10, 230 8' fill='none' stroke='%23e07b33' stroke-opacity='0.45' stroke-width='1.5' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 100% 0.32em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

p {
  margin: 0 0 0.8rem;
}

.lead {
  font-size: 1.3rem;
  line-height: 1.35;
  margin-bottom: 1.2rem;
}

.muted {
  color: var(--ink-soft);
}

.small {
  font-size: 0.95rem;
}

a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

a:hover {
  text-decoration-thickness: 3px;
}

:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 3px;
}

/* -- pencil boxes and paper scraps --------------------------------- */

/* A pencil-outlined box: a firm line with a lighter second pass a
   hair off it, as the video draws its boxes. */
.box {
  position: relative;
  padding: 16px;
  margin: 0 0 14px;
  background: rgba(251, 248, 239, 0.55);
  border: 1.5px solid rgba(46, 43, 39, 0.78);
  border-radius: var(--box-radius);
}

.box::after {
  content: "";
  position: absolute;
  inset: -3px -2px -2px -3px;
  border: 1px solid var(--ink-faint);
  border-radius: var(--box-radius);
  transform: rotate(-0.35deg);
  pointer-events: none;
}

/* A paper scrap taped onto the page. */
.scrap {
  position: relative;
  padding: 22px 18px 16px;
  margin: 18px 4px 20px;
  background: var(--scrap);
  box-shadow: 0 1px 2px rgba(60, 50, 30, 0.12),
              0 4px 12px rgba(60, 50, 30, 0.1);
  transform: rotate(-0.4deg);
}

.scrap::before, .scrap::after {
  content: "";
  position: absolute;
  top: -10px;
  width: 64px;
  height: 22px;
  background: var(--tape);
}

.scrap::before {
  left: -8px;
  transform: rotate(-24deg);
}

.scrap::after {
  right: -8px;
  transform: rotate(22deg);
}

/* -- controls ------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 50px;
  padding: 0.4rem 1.3rem;
  font-family: var(--body);
  font-size: 1.3rem;
  line-height: 1.1;
  color: var(--ink);
  background: var(--scrap);
  border: 2px solid var(--ink);
  border-radius: var(--hand-radius);
  box-shadow: 2px 3px 0 var(--ink);
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}

.btn:hover {
  text-decoration: none;
}

.btn:active {
  transform: translate(2px, 2px);
  box-shadow: 0 1px 0 var(--ink);
}

.btn[disabled] {
  opacity: 0.55;
  cursor: default;
  transform: none;
  box-shadow: 2px 3px 0 var(--ink);
}

.btn-primary {
  background: var(--accent);
}

.btn-quiet {
  box-shadow: none;
  border-width: 1.5px;
  background: rgba(251, 248, 239, 0.7);
}

.btn-quiet:active {
  box-shadow: none;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}

.btn-row .btn {
  flex: 1 1 160px;
}

label, .label {
  display: block;
  font-size: 1.15rem;
  margin: 0 0 6px;
}

input[type="text"], input[type="search"] {
  display: block;
  width: 100%;
  min-height: 54px;
  padding: 0.45rem 0.9rem;
  font-family: var(--body);
  font-size: 1.35rem;
  color: var(--ink);
  background: #fffdf7;
  border: 2px solid var(--ink);
  border-radius: 6px 10px 7px 12px / 10px 6px 12px 7px;
  -webkit-appearance: none;
  appearance: none;
}

input::placeholder {
  color: rgba(46, 43, 39, 0.42);
}

input:focus {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}

input.zip-input {
  font-size: 2rem;
  letter-spacing: 0.3em;
  text-align: center;
  min-height: 64px;
}

input.zip-input::placeholder {
  font-size: 1.4rem;
  letter-spacing: normal;
}

.field-note {
  min-height: 1.5em;
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 1rem;
}

.back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 4px;
  font-size: 1.1rem;
  color: var(--ink-soft);
  text-decoration: none;
}

.back:hover {
  color: var(--ink);
}

.icon {
  display: inline-flex;
}

.icon svg {
  display: block;
  width: 1.15em;
  height: 1.15em;
}

/* -- home ----------------------------------------------------------- */

.hero h1 {
  margin-top: 0.4rem;
}

.or-rule {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 0 14px;
  color: var(--ink-soft);
}

.or-rule::before, .or-rule::after {
  content: "";
  flex: 1;
  border-top: 1.5px dashed var(--ink-faint);
}

.promise {
  list-style: none;
  padding: 0;
  margin: 0;
}

.promise li {
  position: relative;
  padding-left: 30px;
  margin: 0 0 6px;
}

/* A pencil tick, in graphite: it marks a promise, not a side. */
.promise li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.3em;
  width: 18px;
  height: 14px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 14'%3E%3Cpath d='M2 7.5 L7 12 L16.5 2' fill='none' stroke='%232e2b27' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat;
}

.promise-title {
  font-family: var(--heading);
  font-weight: 700;
  font-size: 1.5rem;
  margin: 0 0 6px;
}

/* -- loading -------------------------------------------------------- */

.loading {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 28px 0;
  color: var(--ink-soft);
  font-size: 1.2rem;
}

.pencil-spin {
  width: 26px;
  height: 26px;
  flex: none;
  border: 2.5px solid var(--ink-faint);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* -- notices: errors and empty states ------------------------------ */

.notice {
  margin-top: 8px;
}

.notice h2 {
  margin-top: 0;
  font-size: 1.8rem;
}

.notice-mark {
  display: block;
  width: 54px;
  height: 54px;
  margin: 0 0 6px;
}

.inline-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: rgba(251, 248, 239, 0.8);
}

/* -- district choice ------------------------------------------------ */

.map-container {
  position: relative;
  width: 100%;
  height: 300px;
  margin: 6px 0 18px;
  overflow: hidden;
  background: var(--scrap);
  border: 2px solid rgba(46, 43, 39, 0.8);
  border-radius: 14px 18px 12px 20px / 18px 12px 20px 14px;
  box-shadow: 3px 4px 0 rgba(46, 43, 39, 0.18);
}

.map-container .leaflet-container,
.map-container.leaflet-container {
  font-family: var(--body);
  background: var(--scrap);
}

.map-container svg {
  display: block;
}

/* Leaflet's own tiles a touch faded, so the pencil lines read first. */
.map-container .leaflet-tile-pane {
  filter: grayscale(0.85) sepia(0.25) contrast(0.9) brightness(1.04);
  opacity: 0.85;
}

.map-container .leaflet-control-attribution {
  font-family: var(--body);
  font-size: 0.75rem;
  background: rgba(251, 248, 239, 0.85);
}

.map-container .leaflet-control-zoom a {
  font-family: var(--body);
  color: var(--ink);
  background: var(--scrap);
}

/* The district's letter, pinned on the map and on its card: the
   districts are told apart by letter and line, not by colour. */
.district-label.leaflet-tooltip,
.district-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  font-family: var(--heading);
  font-weight: 700;
  font-size: 1.45rem;
  line-height: 1;
  color: var(--ink);
  background: var(--scrap);
  border: 2px solid var(--ink);
  border-radius: 50% 46% 52% 48% / 48% 52% 46% 50%;
  box-shadow: none;
}

.district-label.leaflet-tooltip::before {
  display: none;
}

.svg-label {
  font-family: "Caveat", cursive;
  font-weight: 700;
  font-size: 22px;
}

.map-note {
  margin: -8px 0 16px;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.choice-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.choice-list li {
  margin: 0 0 12px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 64px;
  margin: 0;
  padding: 12px 14px;
  font-family: var(--body);
  font-size: 1.25rem;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}

.choice:hover {
  background: var(--scrap);
}

.choice:active {
  transform: translate(1px, 1px);
}

.choice-name {
  flex: 1;
}

.chev {
  font-family: var(--heading);
  font-size: 1.8rem;
  line-height: 1;
  color: var(--ink-soft);
}

/* -- ballot --------------------------------------------------------- */

.matched {
  font-size: 1.05rem;
}

.matched strong {
  font-weight: 400;
  background: rgba(224, 123, 51, 0.16);
  padding: 0 3px;
}

.level-heading {
  margin: 1.6rem 0 0.7rem;
  font-family: var(--heading);
  font-weight: 700;
  font-size: 1.65rem;
  color: var(--ink);
}

.contest {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.contest-body {
  flex: 1;
  min-width: 0;
}

.contest-eyebrow {
  font-family: var(--heading);
  font-weight: 700;
  font-size: 1.55rem;
  line-height: 1.1;
  margin: 0 0 2px;
}

.contest-title {
  margin: 0 0 10px;
  font-family: var(--body);
  font-weight: 400;
  font-size: 1.15rem;
  line-height: 1.3;
}

.contest-title-only {
  font-family: var(--heading);
  font-weight: 700;
  font-size: 1.55rem;
  line-height: 1.15;
}

a.contest {
  text-decoration: none;
  color: var(--ink);
}

a.contest:hover {
  background: var(--scrap);
}

.thumb {
  flex: none;
  width: 72px;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  transform: rotate(-1.2deg);
  box-shadow: 2px 2px 0 rgba(46, 43, 39, 0.2);
}

.thumb-blank {
  display: flex;
  align-items: center;
  justify-content: center;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 10px 10px;
}

.thumb-blank svg {
  width: 30px;
  height: 30px;
}

.wait-note {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--ink-soft);
}

/* Not available (candidate races, for now): drawn but inert. */
.contest.inert {
  background: transparent;
  border-style: dashed;
  border-color: var(--ink-faint);
  color: var(--ink-soft);
}

.contest.inert::after {
  display: none;
}

.contest.inert .contest-title-only {
  color: var(--ink-soft);
}

.inert-note {
  margin: 4px 0 0;
  font-size: 1rem;
}

.empty-ballot {
  margin-top: 1rem;
}

/* -- progress (a video being made) --------------------------------- */

.progress {
  margin: 4px 0 0;
}

.progress-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  margin: 0 0 8px;
}

.progress-dot {
  width: 12px;
  height: 12px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.75); }
}

/* A pencil-hatched bar: the outline is the whole job, the hatching
   how far it has got. */
.progress-bar {
  position: relative;
  height: 16px;
  margin: 0 0 8px;
  border: 1.5px solid var(--ink);
  border-radius: 9px 7px 10px 6px / 7px 10px 6px 9px;
  overflow: hidden;
  background: rgba(251, 248, 239, 0.8);
}

.progress-fill {
  height: 100%;
  width: 4%;
  background: repeating-linear-gradient(-55deg,
    var(--accent) 0 3px, rgba(224, 123, 51, 0.45) 3px 7px);
  transition: width 0.8s ease;
}

.progress-meta {
  margin: 0;
  font-size: 1rem;
  color: var(--ink-soft);
}

.steps {
  list-style: none;
  padding: 0;
  margin: 14px 0 6px;
}

.steps li {
  position: relative;
  padding: 2px 0 2px 30px;
  color: var(--ink-soft);
  font-size: 1.05rem;
}

.steps li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.55em;
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--ink-faint);
  border-radius: 50%;
}

.steps li.done {
  color: var(--ink);
}

.steps li.done::before {
  border: 0;
  width: 16px;
  height: 13px;
  top: 0.45em;
  left: 2px;
  border-radius: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 14'%3E%3Cpath d='M2 7.5 L7 12 L16.5 2' fill='none' stroke='%232e2b27' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / contain;
}

.steps li.now {
  color: var(--ink);
  font-size: 1.15rem;
}

.steps li.now::before {
  border-color: var(--accent);
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

.progress-leave {
  margin: 10px 0 0;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

/* -- contest page --------------------------------------------------- */

.contest-page h1 {
  font-size: 1.85rem;
  margin-top: 0.2rem;
}

.contest-page .contest-eyebrow {
  font-size: 1.3rem;
  color: var(--ink-soft);
  margin-top: 0.4rem;
}

/* The 9:16 video, as tall as the screen allows. --above is the frame's
   distance from the page top, measured by app.js (fitVideo); the 16px
   keeps a little paper showing under it. */
.video-frame {
  position: relative;
  width: min(100%, calc((100svh - var(--above, 230px) - 16px) * 9 / 16));
  min-width: min(100%, 160px);
  aspect-ratio: 9 / 16;
  margin: 8px auto 20px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  overflow: hidden;
  background: var(--ink);
  box-shadow: 4px 5px 0 rgba(46, 43, 39, 0.2);
}

.video-frame video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--paper);
}

/* The same frame before a video exists: an empty page waiting, only
   as tall as what it holds. */
.video-frame.empty {
  width: 100%;
  aspect-ratio: auto;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 22px;
  background-color: var(--scrap);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 16px 16px;
}

.video-frame.empty h2 {
  font-size: 1.9rem;
  margin: 0 0 8px;
}

.sources {
  margin: 0 0 8px;
  padding: 0 0 0 1.6rem;
}

.sources li {
  margin: 0 0 10px;
  padding-left: 4px;
}

.sources li::marker {
  font-family: var(--heading);
  font-weight: 700;
  color: var(--ink-soft);
}

.sources a {
  overflow-wrap: anywhere;
}

.source-host {
  display: block;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.corrections {
  margin-top: 18px;
}

.corrections ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.corrections li {
  margin: 0 0 6px;
}

.corrections .date {
  color: var(--ink-soft);
}

.report {
  margin: 22px 0 6px;
}

.fine-print {
  margin: 18px 0 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

/* -- footer --------------------------------------------------------- */

.site-footer {
  margin-top: 36px;
  padding-top: 14px;
  border-top: 1.5px dashed var(--ink-faint);
  text-align: center;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.site-footer p {
  margin: 0 0 4px;
}

.site-footer a {
  color: var(--ink-soft);
  text-decoration-color: var(--ink-faint);
  text-decoration-thickness: 1px;
}

.site-footer .osm-note {
  font-size: 0.8rem;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

.contest-page .section-title {
  font-size: 1.7rem;
  margin: 1.4rem 0 0.7rem;
}
