/* ==========================================================================
   qv-phone.css - the live Quick Vote replica inside the phone frame.

   The frame itself (.phone, .stage, the pinned pane) comes from schedule.css.
   This file only styles what js/qv-phone.js builds inside it.

   Sizing: the app is laid out at a true device width, DEV_W = 360px, inside
   .qv-dev. js/qv-phone.js then sets two custom properties on it through the
   CSSOM (the CSP forbids style="" attributes, but CSSOM calls are allowed):
     --k      the scale, frame width / 360
     --dev-h  the device height, frame height / --k
   so every size below is in px at the 360px device scale and the whole app
   shrinks as one piece to fit whatever width the frame has.

   Theme: the replica copies the live app's single light theme (cream field
   with a guilloche texture, ballot-paper cards, oxblood ink). There is no
   theme switch.
   ========================================================================== */

/* --- Fallback screenshots, until the script replaces them ---------------- */

.phone--live[data-qv] { position: relative; }

.qv-shot {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  border-radius: 27px;
}

/* --- Palette -------------------------------------------------------------- */

/* Field tokens first: what sits straight on the cream page. Cards (.qv-card)
   re-declare the ink-on-paper set further down, the way the live app does. */
.qv {
  --q-bg: #ece6da;
  --q-bar-bg: #e3dcce;
  --q-glow: rgba(255, 255, 255, .45);
  --q-texture: url('/assets/textures/guilloche-light.svg');
  --q-paper: #fbf9f4;
  --q-card: #fbf9f4;
  --q-surface: rgba(255, 255, 255, .4);
  --q-track: rgba(36, 27, 26, .08);
  --q-text: #241b1a;
  --q-text-2: #5f5450;
  --q-text-3: #5f5450;
  --q-divider: rgba(36, 27, 26, .12);
  --q-hairline: rgba(36, 27, 26, .1);
  --q-hairline-strong: rgba(36, 27, 26, .18);
  --q-accent: #241b1a;
  --q-accent-text: #5a1f1c;
  --q-accent-on: #fbf9f4;
  --q-accent-muted: rgba(36, 27, 26, .08);
  --q-oxblood: #7a2e2a;
  --q-serial: #5a1f1c;
  --q-focus: #7a2e2a;
  --q-btn-bg: #241b1a;
  --q-btn-fg: #fbf9f4;
  --q-btn-hover: #3a2c2a;
  --q-btn2-border: rgba(36, 27, 26, .4);
  --q-btn2-hover: rgba(36, 27, 26, .06);
  --q-input-bg: rgba(255, 255, 255, .6);
  --q-input-border: rgba(36, 27, 26, .7);
  --q-bar-lead: #241b1a;
  --q-bar-other: #8e8498;
  --q-waiting: #7a6a64;
  --q-shadow-card: inset 0 0 0 6px #fbf9f4, inset 0 0 0 7px rgba(122, 46, 42, .35), 0 18px 32px -18px rgba(70, 50, 30, .28), 0 1px 3px rgba(70, 50, 30, .18);
  --q-check-img: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 26 26' fill='none' stroke='%237A2E2A' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.5 6.5L20.5 19.5'/%3E%3Cpath d='M20 5.5L6 20.5'/%3E%3C/svg%3E");
  --q-md: 3px;
  --q-btn: 4px;
  --q-paper-r: 3px;
  --q-pill: 999px;
  --q-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --q-ui: 'Source Serif 4', Georgia, 'Times New Roman', serif;
}

/* --- Viewport and scaled device ------------------------------------------ */

.qv-vp {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 27px;
  isolation: isolate;
  background: var(--q-bg);
}

.qv-dev {
  position: absolute;
  top: 0;
  left: 0;
  width: 360px;
  height: var(--dev-h, 760px);
  transform: scale(var(--k, .8));
  transform-origin: 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: var(--q-serif);
  font-size: 16px;
  line-height: 1.4;
  text-align: left;
  letter-spacing: 0;
  color: var(--q-text);
  background-color: var(--q-bg);
  background-image:
    radial-gradient(120% 55% at 50% 0, var(--q-glow), transparent 70%),
    var(--q-texture);
  background-size: auto, 240px 120px;
  background-repeat: no-repeat, repeat;
}

/* --- Reset: keep the host page's rules out of the app ---------------------- */

.qv-dev,
.qv-dev * { box-sizing: border-box; }

.qv-dev ul,
.qv-dev li {
  list-style: none;
  margin: 0;
  padding: 0;
}

.qv-dev ul { display: block; }

.qv-dev [hidden] { display: none !important; }

/* :where() keeps the reset at element specificity, so any class below wins. */
:where(.qv-dev) button,
:where(.qv-dev) input {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  -webkit-appearance: none;
  appearance: none;
  text-align: inherit;
}

:where(.qv-dev) button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:where(.qv-dev) button:disabled { cursor: default; }

.qv-dev svg { display: block; max-width: none; flex: none; }

.qv-dev :focus-visible {
  outline: 3px solid var(--q-focus);
  outline-offset: 2px;
}

.qv-dev [tabindex="-1"]:focus { outline: none; }

.qv-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --- Icons ---------------------------------------------------------------- */

.qv-ic {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.qv-ic--chk { stroke-width: 3; }

/* --- Top bar ---------------------------------------------------------------- */

.qv-bar {
  flex: none;
  height: 63px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--q-hairline);
  background: var(--q-bar-bg);
  font-family: var(--q-ui);
}

.qv-brand {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-family: var(--q-serif);
  font-weight: 600;
  font-size: 16px;
  color: var(--q-text);
  white-space: nowrap;
}

.qv-mark {
  flex: none;
  width: 28px;
  height: 28px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--q-hairline-strong);
  border-radius: var(--q-btn);
  color: var(--q-accent);
}

.qv-mark__svg { width: 16px; height: 16px; display: block; }

/* The Voter/Admin slider: two squared options, the picked one filled with ink. */
.qv-seg {
  margin-left: auto;
  display: inline-flex;
  gap: 0;
  padding: 4px;
  border: 1px solid var(--q-hairline-strong);
  border-radius: var(--q-btn);
  background: transparent;
}

.qv-seg__b {
  width: 52px;
  height: 34px;
  padding: 0 2px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  color: var(--q-text-2);
  transition: background-color .3s, color .3s;
}

.qv-seg__b.is-on {
  background: var(--q-btn-bg);
  color: var(--q-btn-fg);
}

/* --- Page area ---------------------------------------------------------------- */

.qv-page {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
}

/* Only when the page is wheel-stepped: otherwise a scrolled-to-the-end screen
   should hand the scroll back to the page. */
html.is-segmented .qv-page { overscroll-behavior: contain; }

.qv-page::-webkit-scrollbar { display: none; }

.qv-pad { padding: 22px 20px 28px; }

.qv-screen { animation: qv-in .28s cubic-bezier(.16, 1, .3, 1) both; }

@keyframes qv-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* --- Type ----------------------------------------------------------------------- */

.qv-h1 {
  margin: 0 0 12px;
  font-family: var(--q-serif);
  font-size: 34px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -.01em;
}

.qv-h2 {
  margin: 0 0 6px;
  font-family: var(--q-serif);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
}

.qv-h3 {
  margin: 0;
  font-family: var(--q-serif);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
}

.qv-lead {
  margin: 0 0 22px;
  color: var(--q-text-2);
  font-size: 16px;
  line-height: 1.5;
}

.qv-text {
  color: var(--q-text-2);
  font-size: 15px;
  line-height: 1.45;
}

.qv-note {
  margin-top: 8px;
  color: var(--q-text-3);
  font-family: var(--q-ui);
  font-size: 13px;
  line-height: 1.4;
}

/* Printed form labels: small caps, tracked out. */
.qv-label {
  margin-bottom: 6px;
  color: var(--q-text-3);
  font-family: var(--q-ui);
  font-size: 15px;
  font-weight: 600;
  font-variant-caps: all-small-caps;
  letter-spacing: .06em;
  line-height: 1.2;
}

.qv-label--gap { margin-top: 18px; }

.qv-q {
  margin-top: 4px;
  color: var(--q-text-2);
  font-size: 16px;
  line-height: 1.4;
}

.qv-q--left { margin: 0; color: var(--q-text); font-size: 17px; font-weight: 600; }

/* --- Cards: sheets of ballot paper ----------------------------------------------- */

.qv-card {
  /* ink-on-paper tokens, as the live app's .paper declares them */
  --q-surface: #f3f0ea;
  --q-track: #f1e6e2;
  --q-text: #241b1a;
  --q-text-2: #4d4240;
  --q-text-3: #6b5f5b;
  --q-divider: #e0d6cf;
  --q-hairline: rgba(36, 27, 26, .12);
  --q-hairline-strong: rgba(36, 27, 26, .22);
  --q-accent: #241b1a;
  --q-accent-text: #7a2e2a;
  --q-accent-on: #fbf9f4;
  --q-accent-muted: rgba(122, 46, 42, .08);
  --q-focus: #7a2e2a;
  --q-input-bg: #fff;
  --q-bar-lead: #7a2e2a;
  --q-bar-other: #7a6a64;

  margin: 0 0 14px;
  padding: 20px;
  border: 1px solid rgba(122, 46, 42, .45);
  border-radius: var(--q-paper-r);
  background: var(--q-paper);
  box-shadow: var(--q-shadow-card);
  color: var(--q-text);
  caret-color: var(--q-oxblood);
}

.qv-card ::selection {
  background: var(--q-oxblood);
  color: #f2f0eb;
}

.qv-card__h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 32px;
}

.qv-center { text-align: center; }

/* "Vote recorded": an oxblood rubber stamp */
.qv-badge {
  width: 64px;
  height: 64px;
  margin: 2px auto 14px;
  display: grid;
  place-items: center;
  border: 2.5px solid var(--q-oxblood);
  border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 4px var(--q-paper), inset 0 0 0 5px rgba(122, 46, 42, .6);
  color: var(--q-oxblood);
  transform: rotate(-8deg);
  animation: qv-pop .4s cubic-bezier(.16, 1, .3, 1) both;
}

.qv-badge__ic { width: 28px; height: 28px; stroke-width: 2.5; }

@keyframes qv-pop {
  from { transform: rotate(-8deg) scale(.8); opacity: 0; }
  to { transform: rotate(-8deg) scale(1); opacity: 1; }
}

/* --- Join ------------------------------------------------------------------------- */

.qv-pills {
  display: grid;
  gap: 8px;
  max-width: 260px;
  margin-bottom: 24px;
}

.qv-pill {
  display: block;
  height: 14px;
  border-radius: 1px;
  background: var(--q-accent);
  opacity: .45;
  transform-origin: left center;
}

.qv-pill--a { width: 61%; }
.qv-pill--b { width: 100%; opacity: 1; }
.qv-pill--c { width: 45%; }

@media (prefers-reduced-motion: no-preference) {
  .qv-pill { animation: qv-bar-grow .9s cubic-bezier(.16, 1, .3, 1) both; }
  .qv-pill--b { animation-delay: 90ms; }
  .qv-pill--c { animation-delay: 180ms; }
}

@keyframes qv-bar-grow {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.qv-pin { position: relative; }

.qv-cells {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.qv-cell {
  height: 52px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--q-text);
  border-radius: 2px;
  background: #fff;
  color: var(--q-serial);
  font-family: var(--q-ui);
  font-size: 28px;
  font-weight: 600;
  font-variant-numeric: tabular-nums lining-nums;
}

.qv-cell.is-filled {
  box-shadow: inset 0 0 0 1px rgba(122, 46, 42, .25);
}

.qv-cell.is-empty {
  color: var(--q-text-3);
  font-weight: 400;
  opacity: .6;
}

/* The real input sits over the cells, invisible but focusable. */
.qv-dev .qv-pin__in {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  color: transparent;
  caret-color: transparent;
  background: transparent;
  font-family: var(--q-ui);
  font-size: 16px;
  letter-spacing: 40px;
  border-radius: 2px;
  cursor: text;
}

.qv-pin__in::selection { background: transparent; color: transparent; }

.qv-dev .qv-input {
  display: block;
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border: 1.5px solid var(--q-input-border);
  border-radius: var(--q-md);
  background: var(--q-input-bg);
  color: var(--q-text);
  font-family: var(--q-ui);
  font-size: 16px;
  transition: border-color .2s;
}

.qv-dev .qv-input:focus { border-color: var(--q-focus); }

.qv-input::placeholder { color: var(--q-text-3); opacity: 1; }

/* Primary button: ink fill, paper text, a 4px rectangle. */
.qv-dev .qv-btn {
  display: block;
  width: 100%;
  height: 48px;
  margin-top: 20px;
  border: 1px solid transparent;
  border-radius: var(--q-btn);
  background: var(--q-btn-bg);
  color: var(--q-btn-fg);
  font-family: var(--q-ui);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .01em;
  text-align: center;
  transition: background-color .15s, opacity .2s, transform .12s;
}

.qv-dev .qv-btn:hover:not(:disabled) { background: var(--q-btn-hover); }
.qv-btn:disabled { opacity: .45; }
.qv-btn:not(:disabled):active { transform: scale(.98); }

/* Waiting for the host */
.qv-wait { text-align: center; padding-block: 26px; }
.qv-wait .qv-h2 { margin-bottom: 8px; }

.qv-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

.qv-dots i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--q-waiting);
  animation: qv-dot 1s ease-in-out infinite;
}

.qv-dots i:nth-child(2) { animation-delay: .15s; }
.qv-dots i:nth-child(3) { animation-delay: .3s; }

@keyframes qv-dot {
  0%, 100% { opacity: .3; transform: scale(.8); }
  50% { opacity: 1; transform: scale(1); }
}

/* --- Ballot: ruled rows, a box on the right, marked with a hand-drawn cross ------- */

.qv-opts {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 12px;
}

.qv-dev .qv-opt {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 56px;
  padding: 10px 4px;
  border: 0;
  border-bottom: 1px solid var(--q-divider);
  border-radius: 0;
  background: transparent;
  color: var(--q-text);
  font-family: var(--q-serif);
  font-size: 17px;
  line-height: 1.3;
  transition: background-color .15s;
}

.qv-dev .qv-opt:first-child { border-top: 1px solid var(--q-divider); }
.qv-dev .qv-opt:not(.is-on):hover { background: rgba(122, 46, 42, .04); }

.qv-opt__t { flex: 1 1 auto; order: 1; min-width: 0; }

.qv-ring {
  flex: none;
  order: 2;
  display: block;
  width: 26px;
  height: 26px;
  border: 1.5px solid var(--q-text);
  border-radius: 2px;
  background-color: #fff;
  background-image: none;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100%;
}

.qv-opt.is-on .qv-ring {
  background-image: var(--q-check-img);
  animation: qv-cross .2s ease-out;
}

/* The cross is the background image; the script's tick icon stays unused. */
.qv-dev .qv-ring .qv-ring__ic { display: none; }

@keyframes qv-cross {
  from { background-size: 45%; opacity: .4; }
  to { background-size: 100%; opacity: 1; }
}

/* --- Results bars: square-ended --------------------------------------------------- */

/* .qv-dev prefix: the reset's `.qv-dev ul { display: block; margin: 0 }` would
   otherwise beat these single-class rules and drop the row gap. */
.qv-dev .qv-rows {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 14px;
}

.qv-dev .qv-h3 + .qv-rows { margin-top: 18px; }

.qv-row__h {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.qv-row__n {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 16px;
  line-height: 1.3;
}

.qv-row__v {
  flex: none;
  color: var(--q-text-2);
  font-family: var(--q-ui);
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums lining-nums;
}

.qv-row.is-lead .qv-row__v { color: var(--q-serial); }

/* "Your vote" mark: an oxblood-edged circle with a tick. */
.qv-tag {
  flex: none;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  border: 1px solid rgba(122, 46, 42, .45);
  color: var(--q-oxblood);
}

.qv-tag__ic { width: 14px; height: 14px; stroke-width: 2.5; }

.qv-track {
  height: 26px;
  border-radius: 2px;
  background: var(--q-track);
  box-shadow: inset 0 0 0 1px var(--q-hairline);
  overflow: hidden;
}

.qv-fill {
  width: var(--w, 0%);
  height: 100%;
  border-radius: 2px;
  background: var(--q-bar-other);
  transition: width .6s cubic-bezier(.16, 1, .3, 1), background-color .3s;
}

.qv-row.is-lead .qv-fill { background: var(--q-bar-lead); }

.qv-dev .qv-link {
  padding: 8px 4px;
  color: var(--q-accent-text);
  font-family: var(--q-ui);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}

.qv-link:disabled { color: var(--q-text-3); opacity: .6; }
.qv-link--center { display: block; margin: 2px auto 0; }

/* --- Host ------------------------------------------------------------------------- */

.qv-bigpin {
  margin-top: 2px;
  color: var(--q-serial);
  font-family: var(--q-ui);
  font-size: 40px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: .06em;
  font-variant-numeric: tabular-nums lining-nums;
}

.qv-dev .qv-queue { margin: 10px 0 0; }

.qv-dev .qv-person {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--q-divider);
}

.qv-person:first-child { border-top: 0; }
.qv-person__n { font-size: 16px; }

/* Small secondary button: a hairline-edged 4px rectangle. */
.qv-dev .qv-pillbtn {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--q-btn2-border);
  border-radius: var(--q-btn);
  background: transparent;
  color: var(--q-text);
  font-family: var(--q-ui);
  font-size: 15px;
  font-weight: 600;
  transition: background-color .15s;
}

.qv-dev .qv-pillbtn:hover:not(:disabled) { background: var(--q-btn2-hover); }

.qv-queue + .qv-text { margin-top: 6px; }

.qv-inroom {
  margin: 0 4px 14px;
  color: var(--q-text-2);
  font-family: var(--q-ui);
  font-size: 13px;
  font-weight: 500;
}

.qv-switchlabel {
  font-family: var(--q-ui);
  font-size: 15px;
  font-weight: 600;
}

.qv-dev .qv-switch {
  position: relative;
  flex: none;
  width: 52px;
  height: 30px;
  border-radius: var(--q-pill);
  background: var(--q-input-bg);
  border: 1.5px solid var(--q-input-border);
  transition: background-color .2s, border-color .2s;
}

.qv-switch__knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--q-text-2);
  transition: transform .2s cubic-bezier(.16, 1, .3, 1), background-color .2s;
}

.qv-switch.is-on { background: var(--q-accent); border-color: var(--q-accent); }
.qv-switch.is-on .qv-switch__knob { transform: translateX(22px); background: var(--q-accent-on); }

/* --- Motion and contrast preferences ------------------------------------------------------ */

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

@media (forced-colors: active) {
  .qv-dev .qv-cell,
  .qv-dev .qv-cell.is-filled,
  .qv-dev .qv-cell.is-empty {
    forced-color-adjust: none;
    background: Canvas;
    color: CanvasText;
    border-color: CanvasText;
  }

  .qv-dev .qv-cell.is-filled { border-width: 2px; }

  /* The real input sits over the cells; keep its own text and caret out of sight. */
  .qv-dev .qv-pin__in,
  .qv-dev .qv-pin__in::selection {
    forced-color-adjust: none;
    color: transparent;
    caret-color: transparent;
    background: transparent;
  }

  .qv-dev .qv-track { border: 1px solid CanvasText; }

  .qv-dev .qv-fill {
    forced-color-adjust: none;
    background: CanvasText;
  }

  .qv-dev .qv-row.is-lead .qv-fill { background: Highlight; }

  /* The cross is a background image, which forced colours drop: fill the box instead. */
  .qv-dev .qv-opt.is-on .qv-ring {
    forced-color-adjust: none;
    background-color: Highlight;
    border-color: CanvasText;
  }

  .qv-dev .qv-switch__knob {
    forced-color-adjust: none;
    background: ButtonText;
  }

  .qv-dev .qv-switch.is-on {
    forced-color-adjust: none;
    background: Highlight;
  }

  .qv-dev .qv-switch.is-on .qv-switch__knob { background: HighlightText; }

  .qv-dev .qv-seg__b.is-on {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }
}
