*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip {
  position: absolute; left: -9999px; top: 0; z-index: 20;
  background: var(--accent); color: var(--accent-ink); padding: 12px 16px;
}
.skip:focus { left: 0; }

#main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 64px; }

h1, h2, h3 { line-height: 1.15; letter-spacing: -0.02em; margin: 0; }
h1 { font-size: clamp(26px, 5vw, 38px); font-weight: 800; }
h2 { font-size: clamp(20px, 3.4vw, 26px); font-weight: 750; }
p { line-height: 1.5; margin: 0; }
.muted { color: var(--ink-soft); }
.stack-gap > * + * { margin-top: 14px; }
.stack-gap-lg > * + * { margin-top: 26px; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 12px 20px; border-radius: var(--r-md);
  font: inherit; font-weight: 650; font-size: 16px; cursor: pointer;
  border: 1.5px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  transition: transform 80ms ease;
}
.btn:active { transform: translateY(1px); }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn--wide { width: 100%; }
.btn--big { min-height: 60px; font-size: 19px; }
.btn[disabled] { opacity: 0.42; cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible {
  outline: 3px solid var(--blue); outline-offset: 2px;
}

.icon-btn {
  display: grid; place-items: center;
  width: var(--tap); height: var(--tap); flex: none;
  border-radius: var(--r-sm); border: 0; cursor: pointer;
  background: rgba(255, 255, 255, 0.16); color: currentColor;
}
.icon-btn:active { transform: translateY(1px); }
.icon-btn[disabled] { opacity: 0.28; cursor: not-allowed; }
.icon-btn svg { width: 22px; height: 22px; }

.field { display: block; }
.field span { display: block; font-weight: 650; margin-bottom: 6px; font-size: 15px; }
input[type="text"] {
  width: 100%; min-height: var(--tap); padding: 12px 14px; font: inherit; font-size: 17px;
  border-radius: var(--r-md); border: 1.5px solid var(--line);
  background: var(--card); color: var(--ink);
}
input.code-input {
  font-size: 30px; font-weight: 800; letter-spacing: 0.28em;
  text-align: center; text-transform: uppercase; min-height: 64px;
}

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 20px;
}

.error {
  border-left: 4px solid var(--red); background: var(--card);
  padding: 12px 14px; border-radius: var(--r-sm); font-size: 15px;
}

/* ---------- the bricks ---------- */
/* Geometry is defined once in app.js (BRICK: W 220, H 96, D 36, PAD 12). The
   percentages here derive from it: box 256 x 144, front face from 33.33% down,
   85.94% wide; the brick above overlaps by 18.75% of the width so it sits on
   this one's studs. Text scales with the brick via container units. */

.tower { list-style: none; margin: 0; padding: 0; }
.tower--edit { padding-right: 56px; }

.block {
  position: relative;
  container-type: inline-size;
  aspect-ratio: 256 / 144;
  color: var(--ink-on-block);
}
.block + .block { margin-top: -18.75%; }

.block__brick {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  filter: drop-shadow(0 2px 3px var(--shadow));
}
.block__face {
  position: absolute; left: 0; top: 33.33%; width: 85.94%; height: 66.67%;
  display: flex; flex-direction: column; justify-content: center;
  padding: 3cqi 5cqi 3.5cqi 5cqi;
  text-align: center;
  pointer-events: none; /* text only — pointer hits fall through to the handle */
}
/* Ranked bricks carry the handle at the left. Padding it symmetrically keeps
   the text centred on the brick face rather than on the space beside it. */
.block--ranked .block__face { padding-left: 12cqi; padding-right: 12cqi; }
.block__name { font-weight: 800; font-size: 7.3cqi; line-height: 1.08; letter-spacing: -0.012em; text-shadow: 0 1px 0 rgba(0,0,0,0.12); }
.block__prompt { font-size: 4.9cqi; line-height: 1.2; margin-top: 1.5cqi; }
.block__traits { display: none; font-size: 3.6cqi; line-height: 1.25; margin-top: 1.7cqi; }
.tower--roomy .block__traits { display: block; }
.tower--mini .block__prompt, .tower--mini .block__traits { display: none; }
.tower--mini .block__name { font-size: 8.5cqi; }

/* The handle: rank number over a grip, down the left of the front face. It is
   the only part of a brick that captures touch, so the rest of it scrolls. */
.block__handle {
  position: absolute; left: 0; top: 33.33%; width: 11cqi; height: 66.67%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.5cqi;
  color: inherit;
}
.block__rank { font-weight: 800; font-size: 5.2cqi; line-height: 1; font-variant-numeric: tabular-nums; }
.block__grip { display: none; width: 4.5cqi; height: 4.5cqi; }
/* The handle drags with any pointer — finger, pen or mouse. `touch-action:
   none` is confined to it so a touch anywhere else on a brick still scrolls
   the page. A finger needs a bigger target than a cursor, so the handle widens
   on a coarse pointer; it grows under the face's left padding, which is
   pointer-transparent, so the centred text does not move. */
.tower--edit .block__grip { display: block; }
.tower--edit .block__handle { touch-action: none; cursor: grab; }
.tower--edit .block.is-dragging .block__handle { cursor: grabbing; }
@media (pointer: coarse) {
  /* 15cqi clears 44px only from about 383px of viewport; below that the floor
     does the work, and the face's padding follows so the number never sits on
     the text. */
  /* The floor grows the handle under the face's pointer-transparent padding,
     so the target reaches 44px without narrowing the centred text. */
  .tower--edit .block__handle { width: 15cqi; min-width: 44px; }
}

.block--blue   { --ink-on-block: var(--blue-ink); }
.block--green  { --ink-on-block: var(--green-ink); }
.block--yellow { --ink-on-block: var(--yellow-ink); }
.block--red    { --ink-on-block: var(--red-ink); }
.block--yellow .block__name { text-shadow: none; }

.block__moves {
  position: absolute; right: -56px; top: 66.67%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 4px;
}
.block__moves .icon-btn { background: var(--card); color: var(--ink); border: 1px solid var(--line); }

.block.is-dragging { z-index: 40 !important; }
.block.is-dragging .block__brick { filter: drop-shadow(0 16px 24px var(--shadow)); }
.block.is-settling { transition: transform 160ms ease; }
@media (prefers-reduced-motion: reduce) { .block.is-settling { transition: none; } }

.tower-hint { text-align: center; font-size: 14px; margin-top: 18px; }

/* ---------- host screen ---------- */

.host-grid { display: grid; gap: 24px; }
@media (min-width: 900px) { .host-grid { grid-template-columns: minmax(0, 340px) minmax(0, 1fr); align-items: start; } }

.joinbox { text-align: center; }
.joinbox__code {
  font-size: clamp(52px, 12vw, 78px); font-weight: 850; letter-spacing: 0.12em;
  line-height: 1; margin: 6px 0 4px; font-variant-numeric: tabular-nums;
}
.joinbox__url { font-size: 15px; word-break: break-all; }
.qr { width: min(260px, 70vw); height: auto; margin: 14px auto 0; display: block; background: var(--qr-bg); padding: 10px; border-radius: var(--r-md); }
.qr svg { display: block; width: 100%; height: auto; }

.roster { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.roster li {
  display: flex; align-items: center; gap: 10px; min-height: var(--tap);
  padding: 8px 14px; border-radius: var(--r-md);
  background: var(--card); border: 1px solid var(--line); font-size: 16px;
}
.roster .tick { flex: none; width: 22px; height: 22px; color: var(--green); }
.roster .waiting { flex: none; width: 22px; height: 22px; color: var(--ink-soft); }
.roster li[data-locked="0"] { opacity: 0.62; }
.roster__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

.tally { display: flex; align-items: baseline; gap: 10px; }
.tally strong { font-size: 34px; font-weight: 850; font-variant-numeric: tabular-nums; }

/* ---------- reveal board ---------- */

.board { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
@media (max-width: 480px) { .board { grid-template-columns: 1fr 1fr; gap: 12px; } }
.board__person { min-width: 0; }
.board__name {
  font-weight: 750; font-size: 16px; margin-bottom: 8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.dist { display: grid; gap: 10px; }
.dist__row { display: grid; grid-template-columns: 130px 1fr 44px; align-items: center; gap: 12px; }
.dist__label { font-weight: 700; font-size: 14px; }
.dist__bar { height: 26px; background: var(--paper); border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--line); }
.dist__fill { display: block; height: 100%; }
.dist__fill.blue { background: var(--blue); }
.dist__fill.green { background: var(--green); }
.dist__fill.yellow { background: var(--yellow); }
.dist__fill.red { background: var(--red); }
.dist__n { font-weight: 750; font-variant-numeric: tabular-nums; text-align: right; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; }
.toolbar .btn { flex: 1 1 auto; }

/* ---------- role picker ---------- */

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; border-radius: var(--r-md); background: var(--paper); border: 1px solid var(--line); }
.seg__opt { position: relative; display: block; }
.seg__opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg__opt span {
  display: flex; align-items: center; justify-content: center; min-height: var(--tap);
  padding: 10px 12px; border-radius: 9px; font-weight: 650; font-size: 15.5px; text-align: center;
  color: var(--ink-soft); transition: background 120ms ease, color 120ms ease;
}
.seg__opt input:checked + span { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px var(--shadow); }
.seg__opt input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }
