/* Tall Order. A cutting mat, tape-measure yellow and paper tags.
   Every screen is laid out to fit the window: the page itself never scrolls
   unless the window is too small for the smallest version of a screen. */

:root {
  --mat: #12564a;
  --mat-deep: #0c3f36;
  --grid: rgba(255, 255, 255, 0.055);
  --grid-strong: rgba(255, 255, 255, 0.1);
  --tape: #ffd23f;
  --tape-edge: #d9a90f;
  --ink: #10201b;
  --chalk: #f3f7f1;
  --soft: #a8c9bd;
  --red: #e8412f;
  --display: 'Big Shoulders Display', 'Arial Narrow', Impact, sans-serif;
  --body: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --gap: clamp(8px, 1.9vh, 20px);
  --control: clamp(44px, 6.4vh, 52px);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  color: var(--chalk);
  font: 400 1.0625rem/1.45 var(--body);
  background-color: var(--mat);
  background-image:
    linear-gradient(var(--grid-strong) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-strong) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
}

h1, h2, h3, p { margin: 0; }

button, input { font: inherit; color: inherit; }

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

.noscript { padding: 24px; text-align: center; }

/* ---- top bar ---- */

.bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: clamp(8px, 1.4vh, 14px) 16px;
}

.wordmark {
  font: 900 1.5rem/1 var(--display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--tape);
  text-decoration: none;
}

.bar-right { display: flex; align-items: center; gap: 12px; }

.conn { display: none; font-size: 0.875rem; color: var(--tape); }
body.offline .conn { display: inline; }

.code-chip {
  font: 800 1.125rem/1 var(--display);
  letter-spacing: 0.14em;
  padding: 6px 10px;
  border: 1.5px dashed var(--soft);
  border-radius: 4px;
}

.units { display: flex; border: 1.5px solid var(--soft); border-radius: 4px; overflow: hidden; flex: none; }
.units button {
  background: none;
  border: 0;
  padding: 5px 10px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--soft);
  cursor: pointer;
  white-space: nowrap;
}
.units button[aria-pressed='true'] { background: var(--chalk); color: var(--ink); }
.units button:focus-visible { outline-offset: -3px; outline-color: var(--tape); }
body.at-home .bar .units { display: none; }

/* ---- page frame ---- */

#root { flex: 1; min-height: 0; overflow: auto; }

.screen {
  height: 100%;
  max-width: 580px;
  margin: 0 auto;
  padding: 4px 16px 16px;
  display: flex;
  flex-direction: column;
}
.screen > *, .col > * { flex: none; }
.col { display: contents; }

/* A part that gives up height when the window is short. */
.screen .shrink, .col .shrink { flex: 0 1 auto; min-height: 0; }

@media (min-width: 880px) {
  .screen.split {
    max-width: 1020px;
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 0 56px;
  }
  .screen.split .col { display: flex; flex-direction: column; min-height: 0; }
  .screen.split .col + .col { padding-top: 26px; }
}

/* ---- shared pieces ---- */

.eyebrow {
  font: 800 1rem/1 var(--display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--soft);
}

.title {
  font: 900 clamp(1.9rem, min(9vw, 7vh), 3.5rem)/0.92 var(--display);
  text-transform: uppercase;
  margin: 6px 0 8px;
  overflow-wrap: anywhere;
}
.title em { font-style: normal; color: var(--tape); }

.lede { color: var(--soft); max-width: 48ch; }
.lede strong { color: var(--chalk); font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control);
  padding: 8px 22px;
  border: 0;
  border-radius: 4px;
  background: var(--tape);
  color: var(--ink);
  font: 800 1.3125rem/1 var(--display);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--tape-edge);
  transition: transform 80ms, box-shadow 80ms;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--tape-edge); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn.wide { width: 100%; }
.btn.ghost { background: transparent; color: var(--chalk); box-shadow: inset 0 0 0 1.5px var(--soft); }
.btn.ghost:active { box-shadow: inset 0 0 0 1.5px var(--chalk); }
.btn.small { min-height: 44px; font-size: 1.125rem; padding: 8px 16px; }

.link {
  background: none;
  border: 0;
  padding: 4px 0;
  color: var(--soft);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:hover { color: var(--chalk); }

.field { display: grid; gap: 5px; margin-top: var(--gap); }
.field label, .join-row label { font-weight: 600; }
.hint { font-size: 0.9375rem; font-weight: 400; color: var(--soft); }

input[type='text'], input[type='number'] {
  width: 100%;
  min-height: var(--control);
  padding: 8px 14px;
  border: 2px solid transparent;
  border-radius: 4px;
  background: var(--chalk);
  color: var(--ink);
  font-size: 1.125rem;
}
input::placeholder { color: #7d8f88; }
input:focus-visible { outline: 3px solid var(--tape); outline-offset: 2px; }
input[disabled] { opacity: 0.5; }

.hrow { display: flex; align-items: center; gap: 10px; }
.hrow input { max-width: 96px; }
.hrow .suffix { color: var(--soft); font-weight: 500; }
.hrow .units { margin-left: auto; }
.hrow .units button { padding: 9px 13px; font-size: 1rem; }

.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; color: var(--soft); font-weight: 400; margin-top: 4px; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--tape); flex: none; }

.error { color: #ffc9c0; font-weight: 500; margin-top: 8px; }
.error:empty { display: none; }

.section { margin-top: var(--gap); display: flex; flex-direction: column; }
.section > h2 {
  flex: none;
  font: 800 1.0625rem/1 var(--display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--soft);
  margin-bottom: 10px;
}
.actions { margin-top: var(--gap); display: grid; gap: 10px; }

/* paper tag */
.tag {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 12px 5px 22px;
  background: var(--chalk);
  color: var(--ink);
  font-weight: 600;
  line-height: 1.25;
  clip-path: polygon(11px 0, 100% 0, 100% 100%, 11px 100%, 0 50%);
  position: relative;
  white-space: nowrap;
}
.tag::before {
  content: '';
  position: absolute;
  left: 9px;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: var(--mat);
}
.tag small { font-weight: 500; font-size: 0.8125rem; color: #4b625a; }
.tag small:empty { display: none; }
.tag.off { opacity: 0.5; }
.tag.me { background: var(--tape); }

.tags { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 8px 10px; overflow: auto; }

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

.home {
  min-height: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
}
.hero-title {
  font: 900 clamp(2.5rem, min(13vw, 10.5vh), 6.75rem)/0.84 var(--display);
  text-transform: uppercase;
  margin: 8px 0 clamp(8px, 1.6vh, 18px);
}
.hero-title em { font-style: normal; color: var(--tape); }
.home .lede { font-size: clamp(1rem, 2.2vh, 1.1875rem); }
.join-card { max-width: 460px; }
.cta { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: var(--gap); }
.join-row { display: flex; align-items: center; gap: 10px; margin-top: var(--gap); }
.join-row input { text-transform: uppercase; letter-spacing: 0.2em; font-weight: 600; max-width: 112px; min-height: 44px; }
.footer { margin-top: var(--gap); font-size: 0.875rem; color: var(--soft); }

.showcase { display: none; }

@media (min-width: 880px) {
  .home { grid-template-columns: minmax(0, 1fr) 380px; gap: 56px; align-content: safe center; align-items: center; }
  .showcase { display: flex; flex-direction: column; gap: 12px; }
  .showcase .lineup { height: min(46vh, 380px); }
  .showcase p { color: var(--soft); font-size: 0.9375rem; }
}

@media (max-height: 640px) {
  :root { --gap: 6px; --control: 42px; }
  .home .footer, .home .eyebrow { display: none; }
}

/* ---- lobby ---- */

.invite { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; margin: 6px 0; }
.big-code { font: 900 clamp(3rem, min(20vw, 12vh), 6.5rem)/0.85 var(--display); letter-spacing: 0.08em; color: var(--tape); }

/* ---- countdown ---- */

.timer { display: flex; align-items: center; gap: 12px; margin: 4px 0 6px; }
.timer-num { font: 900 1.75rem/1 var(--display); min-width: 2ch; font-variant-numeric: tabular-nums; }
.timer-track { flex: 1; height: 8px; background: rgba(12, 63, 54, 0.8); border-radius: 4px; overflow: hidden; }
.timer-track i { display: block; height: 100%; width: 100%; background: var(--tape); transform-origin: left; }
.timer.low .timer-num { color: var(--red); }
.timer.low .timer-track i { background: var(--red); }

/* ---- putting the team in order ---- */

.ends { font: 800 0.875rem/1 var(--display); letter-spacing: 0.14em; text-transform: uppercase; color: var(--soft); margin: 8px 0 6px; }
.sortable {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-auto-rows: minmax(28px, 54px);
  gap: 5px;
  overflow: auto;
}
.sortable li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 0 14px;
  min-height: 0;
  background: var(--chalk);
  color: var(--ink);
  border-radius: 4px;
  font-weight: 600;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.sortable li.dragging { background: var(--tape); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35); cursor: grabbing; }
.sortable .grip { color: #7d8f88; letter-spacing: 2px; }
.sortable .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sortable button {
  align-self: stretch;
  width: 42px;
  max-height: 42px;
  margin: 3px 0;
  border: 0;
  border-radius: 4px;
  background: rgba(16, 32, 27, 0.08);
  color: var(--ink);
  font-size: 0.9375rem;
  line-height: 1;
  cursor: pointer;
}
.sortable button:focus-visible { outline-color: var(--mat); outline-offset: 0; }

.status { color: var(--soft); margin-top: 8px; }
.status strong { color: var(--chalk); font-weight: 600; }

/* ---- the line-up of bars ---- */

.lineup {
  display: flex;
  align-items: flex-end;
  justify-content: safe center;
  gap: 8px;
  overflow-x: auto;
  border-bottom: 3px solid var(--chalk);
}
.screen .lineup { flex: 0 4 320px; min-height: 92px; margin-top: var(--gap); }
.person { flex: 1 1 0; min-width: 0; max-width: 84px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-height: 0; }
.person .cm { font: 800 1rem/1 var(--display); margin-bottom: 5px; white-space: nowrap; animation: fade 300ms both; }
.person .bar-fill {
  width: 100%;
  background-color: var(--tape);
  background-image: repeating-linear-gradient(0deg, transparent 0 9px, rgba(16, 32, 27, 0.55) 9px 10px);
  background-size: 34% 100%;
  background-repeat: no-repeat;
  background-position: right;
  border-radius: 3px 3px 0 0;
  transform-origin: bottom;
  animation: grow 700ms cubic-bezier(0.16, 0.84, 0.3, 1) both;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
}
.person .bar-fill span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  color: var(--ink);
  font: 800 1rem/1 var(--display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 0;
  white-space: nowrap;
  max-height: 100%;
  overflow: hidden;
  margin-right: 30%;
}
.person.me .bar-fill { background-color: var(--chalk); }

/* Nine or more people: slimmer bars, shorter labels. */
.lineup.dense { gap: 4px; }
.lineup.dense .cm { font-size: 0.75rem; letter-spacing: -0.01em; }
.lineup.dense .bar-fill { background-image: none; }
.lineup.dense .bar-fill span { font-size: 0.8125rem; margin-right: 0; padding: 6px 0; }

@keyframes grow { from { transform: scaleY(0); } }
@keyframes fade { from { opacity: 0; } }

/* ---- results ---- */

.rank {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-auto-rows: minmax(24px, 44px);
  gap: 5px;
  overflow: auto;
}
.rank li { display: flex; align-items: center; gap: 12px; padding: 0 14px; min-height: 0; background: rgba(12, 63, 54, 0.75); border-radius: 4px; }
.rank li .pos { font: 900 1.375rem/1 var(--display); color: var(--soft); min-width: 1.4ch; }
.rank li .who { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank li .val { color: var(--soft); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rank li:first-child { background: var(--tape); color: var(--ink); }
.rank li:first-child .pos, .rank li:first-child .val { color: var(--ink); }
.rank li.me { box-shadow: inset 0 0 0 2px var(--chalk); }

.awards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-top: var(--gap); }
.awards:empty { display: none; }
.award { font-size: 0.9375rem; padding: 9px 12px 10px 24px; background: var(--chalk); color: var(--ink); line-height: 1.3; clip-path: polygon(13px 0, 100% 0, 100% 100%, 13px 100%, 0 50%); }
.award b { display: block; font: 800 0.875rem/1 var(--display); letter-spacing: 0.06em; white-space: nowrap; text-transform: uppercase; color: #3d6b5d; margin-bottom: 3px; }
.award strong { font-weight: 600; }

/* Big teams: tighter type so the whole list still fits. */
.screen.many .title { font-size: 1.5rem; margin: 2px 0 4px; }
.screen.many .ends { margin: 4px 0 3px; }
.screen.many .sortable { grid-auto-rows: minmax(24px, 54px); gap: 4px; }
.screen.many .sortable button { margin: 2px 0; }
.screen.many .status { margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.screen.many .lede.optional { display: none; }
@media (max-width: 879px) {
  .rank.cols2 { grid-template-columns: 1fr 1fr; }
  .rank.cols2 li { padding: 0 10px; gap: 8px; }
}

/* ---- toast ---- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 20px);
  max-width: min(92vw, 460px);
  padding: 12px 18px;
  background: var(--ink);
  color: var(--chalk);
  border-radius: 4px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms, transform 200ms;
  z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 700px) {
  .optional { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; transition-delay: 0ms !important; }
}
