/* 大螢幕開票表。Everything is sized in --u (1% of a 16:9 frame) so one layout fits any projector;
   rows are sized in --rh (the height of one row), which display.js measures. */

:root {
  --u: 1vw;
  --u: min(1vw, 1.7778vh);
}

html,
body {
  height: 100%;
}

body {
  overflow: hidden;
  background: var(--sheet);
}

body.idle {
  cursor: none;
}

.stage {
  display: grid;
  grid-template-columns: calc(var(--u) * 24) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    'mast mast'
    'join board';
  column-gap: calc(var(--u) * 2);
  row-gap: calc(var(--u) * 1.4);
  height: 100vh;
  height: 100dvh;
  padding: calc(var(--u) * 1.7) calc(var(--u) * 2.2) calc(var(--u) * 1.8);
}

/* Masthead */
.mast {
  grid-area: mast;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: calc(var(--u) * 2);
  padding-bottom: calc(var(--u) * 1.1);
  border-bottom: calc(var(--u) * 0.24) solid var(--ink);
}

.mast-name {
  min-width: 0;
}

.kicker {
  margin: 0;
  font-size: calc(var(--u) * 1.15);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--u) * 1.1);
  margin: calc(var(--u) * 0.3) 0 0;
  font-family: var(--kai);
  font-size: calc(var(--u) * 3.1);
  font-weight: 700;
  line-height: 1.15;
}

.tag {
  padding: 0.12em 0.5em 0.16em;
  background: var(--ink);
  color: #fff;
  font-size: 0.68em;
  white-space: nowrap;
}

.status {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.55em;
  margin: 0;
  padding: 0.36em 0.95em;
  border: calc(var(--u) * 0.16) solid var(--ink);
  border-radius: 999px;
  font-size: calc(var(--u) * 1.5);
  font-weight: 700;
  white-space: nowrap;
}

.dot {
  width: 0.62em;
  height: 0.62em;
  border: 0.13em solid currentColor;
  border-radius: 50%;
}

[data-status='open'] .status {
  border-color: var(--seal);
  background: var(--seal);
  color: #fff;
}

[data-status='open'] .dot {
  background: currentColor;
  animation: pulse 1.5s ease-in-out infinite;
}

[data-status='closed'] .status {
  background: var(--ink);
  color: #fff;
}

[data-status='closed'] .dot {
  background: currentColor;
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

/* Left panel: how to get a ballot. Yellow because the ballot itself is yellow. */
.join {
  grid-area: join;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: calc(var(--u) * 1.3);
  border: calc(var(--u) * 0.16) solid var(--ink);
  background: var(--ballot);
}

.qr {
  display: block;
  width: 100%;
  margin: 0;
  padding: calc(var(--u) * 0.5);
  border: calc(var(--u) * 0.16) solid var(--ink);
  border-radius: 0;
  background: #fff;
  cursor: zoom-in;
}

.qr img {
  display: block;
  width: 100%;
  height: auto;
}

.qr:focus-visible {
  outline: calc(var(--u) * 0.25) solid var(--seal);
  outline-offset: calc(var(--u) * 0.2);
}

.join-how {
  margin: calc(var(--u) * 1.1) 0 0;
  font-family: var(--kai);
  font-size: calc(var(--u) * 2.2);
  font-weight: 700;
  line-height: 1.2;
}

.join-rule {
  margin: calc(var(--u) * 0.35) 0 0;
  font-size: calc(var(--u) * 1.35);
  line-height: 1.35;
}

.join-url {
  margin: calc(var(--u) * 0.6) 0 0;
  color: var(--ink-2);
  font-size: calc(var(--u) * 1);
  line-height: 1.3;
  word-break: break-all;
}

.join-link {
  display: none;
}

.count {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
  margin: auto 0 0;
  padding-top: calc(var(--u) * 0.9);
  border-top: calc(var(--u) * 0.16) solid var(--ink);
  font-size: calc(var(--u) * 1.35);
  font-weight: 700;
}

.count .odo {
  font-family: var(--num);
  font-size: calc(var(--u) * 4.8);
  font-weight: 800;
}

[data-status='closed'] .qr,
[data-status='closed'] .join-url {
  display: none;
}

/* Once voting closes the QR code gives way to a seal: the count is final. */
.seal {
  display: none;
}

[data-status='closed'] .seal {
  display: grid;
  grid-template-columns: 1fr 1fr;
  place-items: center;
  align-self: center;
  width: calc(var(--u) * 15);
  height: calc(var(--u) * 15);
  margin: calc(var(--u) * 1.6) 0 calc(var(--u) * 1.4);
  padding: calc(var(--u) * 0.7);
  border: calc(var(--u) * 0.8) solid var(--seal);
  color: var(--seal);
  font-family: var(--kai);
  font-size: calc(var(--u) * 5.2);
  font-weight: 700;
  line-height: 1;
  transform: rotate(-7deg);
}

.seal.pressed {
  animation: seal 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2) 0.25s both;
}

@keyframes seal {
  from {
    opacity: 0;
    transform: rotate(-7deg) scale(1.9);
  }
  60% {
    opacity: 1;
    transform: rotate(-7deg) scale(0.94);
  }
  to {
    transform: rotate(-7deg) scale(1);
  }
}

/* Rolling digits */
.odo {
  display: inline-flex;
  line-height: 1;
}

.odo-col {
  display: block;
  height: 1em;
  overflow: hidden;
}

.odo-strip {
  display: block;
  line-height: 1;
  text-align: center;
  white-space: pre;
  transition: transform 0.7s cubic-bezier(0.2, 0.85, 0.25, 1);
}

/* The tally sheet */
.board {
  --c-rank: calc(var(--u) * 4.2);
  --c-no: calc(var(--u) * 3.2);
  --c-score: calc(var(--u) * 6.2);
  grid-area: board;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.cols,
.row {
  display: grid;
  grid-template-columns: var(--c-rank) var(--c-no) minmax(0, 0.36fr) minmax(0, 0.64fr) var(--c-score);
  column-gap: calc(var(--u) * 0.9);
  align-items: center;
  padding: 0 calc(var(--u) * 0.7);
}

.cols {
  padding-bottom: calc(var(--u) * 0.45);
  border-bottom: calc(var(--u) * 0.16) solid var(--ink);
  color: var(--ink-2);
  font-size: calc(var(--u) * 0.95);
  font-weight: 700;
}

.cols span:nth-child(-n + 2) {
  text-align: center;
}

.cols span:last-child {
  text-align: right;
}

.rows {
  /* --s sizes what sits inside a row: the row height, but never more than the width can carry
     (on a 4:3 projector rows are tall and narrow, and names would otherwise be cut off). */
  --s: min(var(--rh, 80px), calc(var(--u) * 4.6));
  position: relative;
  flex: 1;
  min-height: 0;
}

.row {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 1;
  height: var(--rh, 10%);
  border-bottom: 1px solid var(--ink-3);
  background: var(--sheet);
  transition: transform 0.85s cubic-bezier(0.3, 0.9, 0.3, 1), background-color 0.6s;
}

.row[data-rank='1'] {
  background: var(--ballot);
}

.row.rise {
  animation: rise 1.6s ease-out;
}

@keyframes rise {
  from {
    background-color: var(--ballot-deep);
  }
}

.rank,
.no {
  display: flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
  font-family: var(--num);
  font-weight: 800;
  line-height: 1;
}

.rank {
  width: calc(var(--s) * 0.74);
  height: calc(var(--s) * 0.74);
  border-radius: 50%;
  font-size: calc(var(--s) * 0.56);
}

.row[data-rank='1'] .rank,
.row[data-rank='2'] .rank,
.row[data-rank='3'] .rank {
  box-shadow: inset 0 0 0 calc(var(--s) * 0.035) var(--ink);
}

.row[data-rank='1'] .rank {
  background: var(--gold);
}

.row[data-rank='2'] .rank {
  background: var(--silver);
}

.row[data-rank='3'] .rank {
  background: var(--bronze);
}

.no {
  width: calc(var(--s) * 0.56);
  height: calc(var(--s) * 0.56);
  border: calc(var(--s) * 0.03) solid var(--ink);
  background: var(--sheet);
  font-size: calc(var(--s) * 0.4);
}

.who {
  min-width: 0;
}

.name,
.topic {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name {
  font-family: var(--kai);
  font-size: calc(var(--s) * 0.43);
  font-weight: 700;
  line-height: 1.2;
}

.topic {
  margin-top: calc(var(--s) * 0.01);
  color: var(--ink-2);
  font-size: calc(var(--s) * 0.23);
  line-height: 1.3;
}

.rows[data-dense] .topic {
  display: none;
}

.rows[data-dense] .name {
  font-size: calc(var(--s) * 0.52);
}

/* 正 marks: five strokes per character, one stroke per vote. */
.tally {
  display: flex;
  align-items: center;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

.zheng {
  flex: none;
  width: var(--g, 2vw);
  height: var(--g, 2vw);
  margin-right: calc(var(--g, 2vw) * 0.2);
  overflow: visible;
}

.zheng path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 1 2;
  stroke-dashoffset: 1;
  opacity: 0;
  transition: stroke 1s ease;
}

.zheng path.on {
  stroke-dashoffset: 0;
  opacity: 1;
}

.zheng path.fresh {
  stroke: var(--seal);
  animation: draw 0.42s ease-out both;
}

@keyframes draw {
  from {
    stroke-dashoffset: 1;
  }
  to {
    stroke-dashoffset: 0;
  }
}

.score {
  position: relative;
  justify-self: end;
  font-family: var(--num);
  font-size: calc(var(--s) * 0.74);
  font-weight: 800;
  line-height: 1;
}

.plus {
  position: absolute;
  right: 100%;
  bottom: 50%;
  margin-right: 0.25em;
  color: var(--seal);
  font-size: 0.5em;
  white-space: nowrap;
  animation: plus 1.4s ease-out forwards;
}

@keyframes plus {
  from {
    opacity: 0;
    transform: translateY(60%);
  }
  18% {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translateY(-70%);
  }
}

/* Full-screen QR code for the back rows */
.zoom {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--u) * 4);
  padding: calc(var(--u) * 2);
  background: var(--ballot);
  cursor: zoom-out;
}

.zoom img {
  flex: none;
  width: calc(var(--u) * 50);
  height: calc(var(--u) * 50);
  border: calc(var(--u) * 0.24) solid var(--ink);
  background: #fff;
}

.zoom-how {
  margin: 0;
  font-family: var(--kai);
  font-size: calc(var(--u) * 5.4);
  font-weight: 700;
  line-height: 1.2;
}

.zoom-rule {
  margin: calc(var(--u) * 0.8) 0 0;
  font-size: calc(var(--u) * 2.8);
}

.zoom-url {
  margin: calc(var(--u) * 2) 0 0;
  color: var(--ink-2);
  font-size: calc(var(--u) * 1.7);
  word-break: break-all;
}

.slips {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 15;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.net,
.keys {
  position: fixed;
  bottom: calc(var(--u) * 0.5);
  z-index: 30;
  margin: 0;
  font-size: calc(var(--u) * 0.85);
}

.net {
  right: calc(var(--u) * 0.6);
  padding: 0.35em 0.8em;
  border: 2px solid var(--seal);
  background: #fff;
  color: var(--seal);
  font-weight: 700;
}

.keys {
  left: calc(var(--u) * 2.2);
  color: var(--ink-2);
  animation: leave 1s 7s forwards;
}

@keyframes leave {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

/* Opened on a phone: a plain ranked list, with a way over to the ballot. */
@media (max-width: 820px) {
  :root {
    --u: 8px;
  }

  body {
    overflow: auto;
  }

  .stage {
    display: block;
    height: auto;
    padding: 16px 12px 28px;
  }

  .mast {
    display: block;
    padding-bottom: 12px;
    border-bottom-width: 3px;
  }

  .kicker {
    font-size: 13px;
    letter-spacing: 0;
  }

  .title {
    gap: 8px;
    line-height: 1.3;
  }

  .status {
    display: inline-flex;
    margin-top: 12px;
    border-width: 2px;
    font-size: 16px;
  }

  .join {
    display: block;
    margin-top: 14px;
    padding: 14px;
    border-width: 2px;
  }

  .qr,
  .join-how,
  .join-rule,
  .join-url,
  [data-status='closed'] .seal {
    display: none;
  }

  .join-link {
    display: block;
    padding: 12px;
    border-radius: 8px;
    background: var(--ink);
    color: #fff;
    font-size: 19px;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
  }

  [data-status='closed'] .join-link {
    display: none;
  }

  .count {
    margin-top: 12px;
    padding-top: 10px;
    border-top-width: 2px;
    font-size: 16px;
  }

  [data-status='closed'] .count {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }

  .count .odo {
    font-size: 40px;
  }

  .board {
    display: block;
    margin-top: 16px;
    border-top: 3px solid var(--ink);
  }

  .cols {
    display: none;
  }

  .row {
    grid-template-columns: 44px 34px minmax(0, 1fr) 58px;
    column-gap: 8px;
    padding: 0 4px;
  }

  .rows {
    --s: 46px;
    height: calc(var(--n, 10) * 64px);
  }

  .title {
    font-size: 21px;
  }

  .title span:first-child {
    text-wrap: balance;
  }

  .name {
    font-size: 19px;
  }

  .topic {
    font-size: 13px;
  }

  .tally,
  .keys {
    display: none;
  }

  .net {
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  [data-status='open'] .dot,
  .row.rise,
  .seal.pressed,
  .plus {
    animation: none;
  }

  .plus {
    display: none;
  }
}
