/* 大螢幕開票頁。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(--bg);
}

body.idle {
  cursor: none;
}

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

/* Masthead */
.mast {
  grid-area: mast;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(var(--u) * 2);
  padding-left: calc(var(--u) * 1.2);
  border-left: calc(var(--u) * 0.45) solid var(--gold);
}

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

.kicker {
  margin: 0;
  color: var(--ink-2);
  font-size: calc(var(--u) * 1.15);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--u) * 1);
  margin: calc(var(--u) * 0.2) 0 0;
  font-size: calc(var(--u) * 2.9);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.tag {
  padding: 0.22em 0.7em;
  border-radius: 0.4em;
  background: var(--brand);
  color: #fff;
  font-size: 0.56em;
  font-weight: 700;
  white-space: nowrap;
}

.status {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.6em;
  margin: 0;
  padding: 0.5em 1.1em;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: calc(var(--u) * 1.4);
  font-weight: 700;
  white-space: nowrap;
}

.dot {
  width: 0.62em;
  height: 0.62em;
  border-radius: 50%;
  background: var(--line-strong);
}

[data-status='open'] .status {
  border-color: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

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

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

[data-status='closed'] .dot {
  background: var(--gold);
}

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

/* Left panel: how to get a ballot. */
.join {
  grid-area: join;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: calc(var(--u) * 1.5);
  border-radius: calc(var(--u) * 1);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.qr {
  display: block;
  width: 100%;
  margin: 0;
  padding: calc(var(--u) * 0.7);
  border: 1px solid var(--line);
  border-radius: calc(var(--u) * 0.6);
  background: #fff;
  cursor: zoom-in;
}

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

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

.join-how {
  margin: calc(var(--u) * 1.2) 0 0;
  font-size: calc(var(--u) * 2.1);
  font-weight: 800;
  line-height: 1.2;
}

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

.join-url {
  margin: calc(var(--u) * 0.7) 0 0;
  color: var(--brand);
  font-size: calc(var(--u) * 1);
  font-weight: 600;
  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: 1px solid var(--line);
  color: var(--ink-2);
  font-size: calc(var(--u) * 1.3);
  font-weight: 600;
}

.count .odo {
  color: var(--brand);
  font-family: var(--num);
  font-size: calc(var(--u) * 4.4);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

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

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

[data-status='closed'] .seal {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 0 calc(var(--u) * 0.4);
  padding: calc(var(--u) * 3.4) 0;
  border-radius: calc(var(--u) * 0.6);
  background: var(--brand);
  color: #fff;
  font-size: calc(var(--u) * 3);
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1;
  box-shadow: inset 0 calc(var(--u) * -0.45) 0 var(--gold);
}

.seal.pressed {
  animation: seal 0.5s ease-out 0.2s both;
}

@keyframes seal {
  from {
    opacity: 0;
    transform: scale(0.94);
  }
  to {
    opacity: 1;
    transform: 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 results board */
.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;
  padding: calc(var(--u) * 1) calc(var(--u) * 0.8) calc(var(--u) * 0.6);
  border-radius: calc(var(--u) * 1);
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.cols {
  padding-bottom: calc(var(--u) * 0.6);
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
  font-size: calc(var(--u) * 0.9);
  font-weight: 600;
}

.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(--line);
  border-radius: calc(var(--u) * 0.5);
  background: var(--surface);
  transition: transform 0.85s cubic-bezier(0.3, 0.9, 0.3, 1), background-color 0.6s;
}

.row[data-rank='1'] {
  border-bottom-color: transparent;
  background: var(--gold-tint);
}

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

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

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

.rank {
  width: calc(var(--s) * 0.66);
  height: calc(var(--s) * 0.66);
  border-radius: 50%;
  color: var(--ink-2);
  font-size: calc(var(--s) * 0.4);
}

.row[data-rank='1'] .rank,
.row[data-rank='2'] .rank,
.row[data-rank='3'] .rank {
  color: 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-radius: calc(var(--s) * 0.12);
  background: var(--bg);
  color: var(--ink-2);
  font-size: calc(var(--s) * 0.3);
}

.row[data-rank='1'] .no {
  background: #fff;
}

.who {
  min-width: 0;
}

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

.name {
  font-size: calc(var(--s) * 0.4);
  font-weight: 700;
  line-height: 1.25;
}

.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.5);
}

/* One bar per team, as long as its share of the leader's votes. */
.tally {
  display: flex;
  align-items: center;
  min-width: 0;
  height: calc(var(--s) * 0.24);
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg);
}

.row[data-rank='1'] .tally {
  background: rgba(247, 168, 27, 0.22);
}

.bar {
  width: calc(var(--v, 0) / var(--max, 1) * 100%);
  height: 100%;
  border-radius: 999px;
  background: var(--brand);
  transition: width 0.7s cubic-bezier(0.2, 0.85, 0.25, 1);
}

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

.score {
  position: relative;
  justify-self: end;
  font-family: var(--num);
  font-size: calc(var(--s) * 0.6);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}

.plus {
  position: absolute;
  right: 100%;
  bottom: 50%;
  margin-right: 0.3em;
  color: var(--brand);
  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) * 5);
  padding: calc(var(--u) * 2);
  background: var(--brand);
  color: #fff;
  cursor: zoom-out;
}

.zoom img {
  flex: none;
  width: calc(var(--u) * 48);
  height: calc(var(--u) * 48);
  padding: calc(var(--u) * 1.2);
  border-radius: calc(var(--u) * 1.4);
  background: #fff;
}

.zoom-how {
  margin: 0;
  font-size: calc(var(--u) * 5);
  font-weight: 800;
  line-height: 1.2;
}

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

.zoom-url {
  margin: calc(var(--u) * 2.2) 0 0;
  padding-top: calc(var(--u) * 1.4);
  border-top: calc(var(--u) * 0.3) solid var(--gold);
  font-size: calc(var(--u) * 1.7);
  font-weight: 600;
  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.45);
  z-index: 30;
  margin: 0;
  font-size: calc(var(--u) * 0.8);
}

.net {
  right: calc(var(--u) * 0.6);
  padding: 0.4em 0.9em;
  border-radius: 999px;
  background: var(--live);
  color: #fff;
  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-left: 12px;
    border-left-width: 4px;
  }

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

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

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

  .status {
    display: inline-flex;
    margin-top: 12px;
    font-size: 15px;
  }

  .join {
    display: block;
    margin-top: 14px;
    padding: 14px;
    border-radius: var(--radius);
  }

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

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

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

  .count {
    margin-top: 12px;
    padding-top: 10px;
    font-size: 15px;
  }

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

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

  .board {
    display: block;
    margin-top: 14px;
    padding: 4px 6px;
    border-radius: var(--radius);
  }

  .cols {
    display: none;
  }

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

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

  .name {
    font-size: 18px;
  }

  .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;
  }

  .bar {
    transition: none;
  }
}
