/*
 * Calhou.me! create-draw wizard (UI v2). Loaded only by /criar, after app.css and motion.css.
 * Without JS every .step is a plain expanded card; create.js adds .is-wizard to the form
 * and sets data-state="current|done|locked" on each step.
 */

html:not(.js) .js-only {
  display: none !important;
}

.hint-block {
  margin: -4px 0 16px;
  color: var(--muted);
  font-size: 1rem;
}

/* Contact channel per participant: radios styled as pills. */
.channel {
  margin: 0 0 10px;
  padding: 0;
  border: 0;
  min-width: 0;
}

.channel legend {
  margin-bottom: 6px;
  padding: 0;
  font-weight: 700;
}

.channel-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.channel-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 6px 14px;
  background: var(--stage);
  border: 2px solid var(--edge);
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.channel-pill input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.channel-pill:hover {
  border-color: var(--muted);
}

.channel-pill:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--deep);
}

.channel-pill:has(input:focus-visible) {
  outline: 4px solid #ffffff;
  outline-offset: 3px;
}

/* Narrow phones: the three options as one equal-width segmented row, icon over label. */
@media (max-width: 27rem) {
  .channel-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .channel-pill {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: 60px;
    padding: 6px 4px;
    border-radius: 12px;
    font-size: 0.9375rem;
    line-height: 1.2;
    text-align: center;
    white-space: normal;
  }

  .budget-options {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .budget-pill {
    min-width: 0;
    min-height: 48px;
  }
}

/* Budget presets reuse the channel pills; "Outro" reveals the number input. */
.budget {
  margin-bottom: 18px;
}

.budget-options {
  gap: 6px;
}

.budget-pill {
  justify-content: center;
  padding: 6px 12px;
}

.budget-custom {
  position: relative;
  max-width: 12rem;
  margin: 10px 0 0;
}

.budget-custom input {
  padding-right: 40px;
}

.budget-unit {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--deep);
  font-weight: 700;
  pointer-events: none;
}

.contact-hand {
  margin: 0 0 14px;
  font-size: 1rem;
  color: var(--muted);
}

/* ---------- Level 2: how everyone gets the link ---------- */

.send-default {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.send-options {
  display: grid;
  gap: 10px;
}

.send-choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 12px 14px;
  background: var(--stage-2);
  box-shadow: inset 0 0 0 3px var(--edge), 0 4px 0 0 var(--deep);
  cursor: pointer;
  transition: box-shadow var(--dur-fast) steps(2, end), transform var(--dur-fast) steps(2, end);
}

.send-choice input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.send-choice:hover {
  box-shadow: inset 0 0 0 3px var(--muted), 0 4px 0 0 var(--deep);
}

.send-choice:active {
  transform: translateY(2px);
}

.send-choice:has(input:checked) {
  box-shadow: inset 0 0 0 3px var(--accent), 0 4px 0 0 var(--accent-dark);
}

.send-choice:has(input:focus-visible) {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.send-icon {
  display: inline-flex;
  flex: none;
  line-height: 0;
}

.send-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.send-title {
  font-weight: 700;
  font-size: 1.0625rem;
}

.send-desc {
  font-size: 0.9375rem;
  color: var(--muted);
}

/* A square pixel radio on the right. */
.send-radio {
  flex: none;
  width: 20px;
  height: 20px;
  margin-left: auto;
  box-shadow: inset 0 0 0 3px var(--edge);
}

.send-choice:has(input:checked) .send-radio {
  background: var(--accent);
  box-shadow: inset 0 0 0 3px var(--accent), inset 0 0 0 7px var(--stage-2);
}

.send-hint {
  display: block;
  margin: 14px 0 0;
  font-size: 0.9375rem;
  color: var(--muted);
}

/* ---------- Level 4: the discreet switch inside each contact field ---------- */

/* As tall as an input; holds the input, the switch button and, when open, the other ways. */
.contact-box {
  position: relative;
}

.contact-box:has(.switch-in) input {
  padding-right: 150px;
}

.switch-in {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  padding: 6px 8px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: #5a6694;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur-fast) steps(2, end), color var(--dur-fast) steps(2, end);
}

.switch-in:hover,
.switch-in:focus-visible {
  background: var(--accent);
  color: var(--deep);
}

.switch-in:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* "Eu entrego": a box the size of an input, the text on the left and the switch on the right. */
.field-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
}

/* Exactly an input's height (one 1.6em line + 20px padding + 6px border), whatever the text does. */
.hand-box {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 10px;
  height: calc(1.6em + 26px);
  padding: 2px 8px 2px 14px;
  border: 3px dashed var(--edge);
  border-radius: 4px;
  overflow: hidden;
}

.hand-box .contact-hand {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.875rem;
  line-height: 1.25;
}

.hand-box .switch-in {
  position: static;
  transform: none;
  flex: none;
  color: var(--muted);
}

.hand-box .switch-in:hover,
.hand-box .switch-in:focus-visible {
  color: var(--deep);
}

/* Open: the other ways cover the input, same height, so the row does not grow. */
.contact-box.is-switching input,
.contact-box.is-switching .contact-hand {
  visibility: hidden;
}

.switch-over {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px;
  background: var(--stage-2);
}

.switch-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 12px;
  border: 0;
  background: var(--stage);
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: inset 0 0 0 2px var(--edge), 0 3px 0 0 var(--deep);
  cursor: pointer;
}

.switch-chip:hover,
.switch-chip:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent), 0 3px 0 0 var(--deep);
}

.switch-chip:active {
  transform: translateY(2px);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.switch-chip .icon {
  width: 20px;
  height: 20px;
}

/* The subtle way back ("Afinal tem email"): text on wide screens, a small × on narrow ones. */
.switch-keep {
  margin-left: auto;
  padding: 6px 4px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: nowrap;
  cursor: pointer;
}

.switch-keep:hover,
.switch-keep:focus-visible {
  color: var(--accent);
}

.switch-keep-x {
  display: none;
}

@media (max-width: 30rem) {
  .switch-chip {
    padding: 0 10px;
    font-size: 0.875rem;
  }

  .switch-keep {
    width: 40px;
    height: 40px;
    padding: 0;
    text-decoration: none;
    font-size: 1.5rem;
    line-height: 1;
  }

  .switch-keep-text {
    display: none;
  }

  .switch-keep-x {
    display: inline;
  }

  .contact-box:has(.switch-in) input {
    padding-right: 130px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .switch-over {
    animation: calhou-blip-in var(--dur) var(--ease-pixel) both;
  }
}

.participants {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: grid;
  gap: 16px;
}

.participant {
  min-width: 0;
  padding: 12px 14px 0;
  background: var(--stage-2);
}

.participant-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  margin-bottom: 4px;
}

.participant-n {
  font-weight: 800;
  color: var(--accent);
}

.participant .field {
  margin-bottom: 14px;
}

.participant-self .participant-head {
  justify-content: flex-start;
}

/* "Tu": a quiet tag, same row style as everyone else. */
.badge-self {
  padding: 2px 10px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--stage);
  border-color: var(--edge);
}

.self-fields {
  margin: 0;
}

.self-fields dt {
  margin-bottom: 6px;
  font-weight: 700;
}

/* Read-only values never wrap: one line, ellipsis, the full value in the title attribute. */
.self-fields dd {
  display: block;
  min-height: 52px;
  margin: 0;
  padding: 10px 14px;
  line-height: 26px;
  background: var(--stage);
  border: 3px dashed var(--edge);
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.self-fields dd.is-empty {
  color: var(--muted);
  font-style: italic;
}

.self-fields .field {
  min-width: 0;
}

.self-hint {
  margin: 0 0 14px;
  font-size: 1rem;
  color: var(--muted);
}

.self-toggle {
  margin-bottom: 4px;
}

.btn-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 2px;
}

.btn-add {
  width: 100%;
  background: transparent;
  color: var(--accent);
  border: 3px dashed var(--accent);
}

.btn-add:hover {
  background: rgba(247, 208, 70, 0.1);
}

.groups {
  display: grid;
  gap: 16px;
}

.groups:not(:empty) {
  margin-bottom: 16px;
}

.group {
  margin: 0;
  padding: 12px 14px 14px;
  background: var(--stage-2);
  border: 0;
}

.group legend {
  float: left;
  width: 100%;
  margin-bottom: 8px;
  padding: 0;
  font-weight: 800;
  color: var(--accent);
}

.group-options {
  clear: both;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.groups-empty {
  margin: 0 0 16px;
}

@media (min-width: 40rem) {
  .self-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
    gap: 0 12px;
  }

  .details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
  }

  .btn-add {
    width: auto;
  }
}

.name-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (min-width: 640px) {
  .name-row {
    flex-direction: row;
    align-items: stretch;
  }
  .name-row .btn-add {
    white-space: nowrap;
  }
}


/* ---------- Level bar (HUD) ---------- */

.levelbar {
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  gap: 4px 14px;
  margin: 0 0 24px;
  /* No box: just the level nodes, their links and names. */
  padding: 4px 0 0;
}

.lvl-track {
  display: flex;
  justify-content: space-between;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Level 1 sits on the left edge of the cards, level 5 on the right edge, the rest equidistant:
   every level but the last takes an equal share and starts with its node; the last is node-wide. */
.lvl {
  position: relative;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

.lvl:last-child {
  flex: 0 0 48px;
  align-items: flex-end;
}

/* Pixel connector between nodes: fills green (in steps) once the previous level is done. */
.lvl:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 21px;
  left: 48px;
  right: 0;
  height: 6px;
  background-color: var(--edge);
  background-image: linear-gradient(var(--ok), var(--ok));
  background-repeat: no-repeat;
  background-size: 0% 100%;
  transition: background-size var(--dur-slow) steps(5, end);
}

.lvl.is-done:not(:last-child)::after {
  background-size: 100% 100%;
}

.lvl-node {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  color: var(--muted);
  background: var(--stage-2);
  font-family: var(--pixel-font);
  font-size: 0.875rem;
  line-height: 1;
  text-decoration: none;
  box-shadow:
    4px 0 0 0 var(--edge),
    -4px 0 0 0 var(--edge),
    0 4px 0 0 var(--edge),
    0 -4px 0 0 var(--edge);
  transition: background-color var(--dur) steps(3, end), color var(--dur) steps(3, end);
}

.lvl-node:hover {
  color: var(--text);
}

.lvl-node .lvl-check {
  display: none;
}

.lvl.is-current .lvl-node {
  color: var(--deep);
  background: var(--accent);
  box-shadow:
    4px 0 0 0 var(--accent-dark),
    -4px 0 0 0 var(--accent-dark),
    0 4px 0 0 var(--accent-dark),
    0 -4px 0 0 var(--accent-dark),
    0 0 18px 6px rgba(247, 208, 70, 0.45);
}

.lvl.is-done .lvl-node {
  background: #1f5e3a;
  box-shadow:
    4px 0 0 0 var(--ok),
    -4px 0 0 0 var(--ok),
    0 4px 0 0 var(--ok),
    0 -4px 0 0 var(--ok);
  cursor: pointer;
}

.lvl.is-done .lvl-num {
  display: none;
}

.lvl.is-done .lvl-check {
  display: block;
}

.lvl.is-locked .lvl-node {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Visited but after the current level: its number, no check, still clickable. */
.lvl.is-ahead .lvl-node {
  color: var(--text);
  cursor: pointer;
}

.lvl.is-error .lvl-node {
  background: var(--error-bg);
  color: var(--error);
  box-shadow:
    4px 0 0 0 var(--error-edge),
    -4px 0 0 0 var(--error-edge),
    0 4px 0 0 var(--error-edge),
    0 -4px 0 0 var(--error-edge);
}

.lvl.is-error .lvl-num {
  display: block;
}

.lvl.is-error .lvl-check {
  display: none;
}

.lvl:first-child .lvl-name {
  justify-content: flex-start;
}

.lvl:last-child .lvl-name {
  justify-content: flex-end;
}

.lvl-name {
  /* Centred under its node; the first hugs the left edge and the last the right edge. */
  display: flex;
  justify-content: center;
  width: 48px;
  margin-top: 10px;
  overflow: visible;
  white-space: nowrap;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--muted);
}

.lvl.is-current .lvl-name {
  color: var(--accent);
}

.lvl.is-done .lvl-name {
  color: var(--ok);
}

.lvl-label {
  grid-column: 1 / -1;
  margin: 10px 0 0;
  font-family: var(--pixel-font);
  font-size: 0.6875rem;
  line-height: 1.6;
  color: var(--accent);
  text-align: center;
}

html:not(.js) .lvl-label {
  display: none;
}

@media (prefers-reduced-motion: no-preference) {
  .lvl.is-current .lvl-node {
    animation: lvl-glow 1.4s steps(4, end) infinite alternate;
  }

  .lvl-node.lvl-up {
    animation: lvl-up 520ms steps(6, end);
  }
}

@keyframes lvl-glow {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.18);
  }
}

@keyframes lvl-up {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.4) translateY(-6px);
  }
  70% {
    transform: scale(0.9);
  }
  100% {
    transform: scale(1);
  }
}

/* ---------- Particle bursts (level up stars, poof dust) ---------- */

.burst {
  position: absolute;
  z-index: 60;
  width: 0;
  height: 0;
  pointer-events: none;
}

.burst i {
  position: absolute;
  left: -4px;
  top: -4px;
  width: 8px;
  height: 8px;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dark);
  animation: burst-fly 600ms steps(6, end) forwards;
}

.burst-star i:nth-child(2n) {
  background: #ffffff;
  width: 6px;
  height: 6px;
}

.burst-dust i {
  width: 10px;
  height: 10px;
  background: var(--muted);
  box-shadow: none;
  border-radius: 0;
}

.burst-dust i:nth-child(3n) {
  background: #8a94a6;
}

@keyframes burst-fly {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    transform: translate(var(--dx), var(--dy)) scale(0.4);
    opacity: 0;
  }
}

/* ---------- Steps (wizard cards) ---------- */

.step {
  position: relative;
  padding: 0;
  margin: 0 0 26px;
  border: 0;
  border-radius: 0;
  background: var(--stage);
  box-shadow:
    4px 0 0 0 var(--edge),
    -4px 0 0 0 var(--edge),
    0 4px 0 0 var(--edge),
    0 -4px 0 0 var(--edge),
    0 10px 0 0 var(--deep);
  scroll-margin-top: 16px;
  transition: opacity var(--dur) steps(3, end), background-color var(--dur) steps(3, end);
}

.step-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 4px;
}

.step-head h2 {
  /* No growing: the "Opcional" tag sits right after the title, not pushed to the far right. */
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 1.25rem;
}

.step-head h2:focus {
  outline: none;
}

/* The wizard moves focus to the level title (screen readers announce it); a title is not a
   control, so no visible frame. */
.step-head h2:focus-visible {
  outline: none;
}

.step-badge {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  font-family: var(--pixel-font);
  font-size: 0.875rem;
  color: var(--deep);
  background: var(--accent);
  box-shadow: inset -4px -4px 0 0 var(--accent-dark);
}

.step-badge .step-badge-check,
.step-badge .step-badge-lock {
  display: none;
}

.tag-opt {
  flex: none;
  align-self: center;
  padding: 4px 8px;
  font-family: var(--pixel-font);
  font-size: 0.5625rem;
  line-height: 1.4;
  color: var(--muted);
  border: 2px dashed var(--muted);
  text-transform: uppercase;
}

.step-body {
  padding: 12px 16px 16px;
}

.step-inner > :last-child {
  margin-bottom: 0;
}

.step-errors:empty {
  display: none;
}

.step-errors {
  margin: 16px 0 0;
  box-shadow: 4px 4px 0 0 var(--deep);
}

.step-errors:focus {
  outline: none;
}

.step-errors p {
  margin: 0 0 6px;
}

.step-errors ul {
  margin: 0;
  padding-left: 1.25em;
}

/* Inline field error: a red pixel tag under the field. */
.field-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 8px 0 0;
  padding: 6px 10px;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--error);
  background: var(--error-bg);
  border-left: 4px solid var(--error-edge);
}

.field-error::before {
  content: "!";
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  font-family: var(--pixel-font);
  font-size: 0.625rem;
  color: var(--deep);
  background: var(--error-edge);
}

@media (prefers-reduced-motion: no-preference) {
  .field-error {
    animation: calhou-slide-up var(--dur) steps(3, end) both;
  }
}

.channel-pill input[aria-invalid="true"] + * {
  color: var(--error);
}

/* Step navigation. */
.step-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

.step-nav .step-next {
  margin-left: auto;
}

.step-nav .btn-pixel {
  min-height: 52px;
  font-size: 1.0625rem;
}

/* ---------- Wizard states (only with JS) ---------- */

/* Before create.js starts, only level 1 is open (avoids a flash of the long form). */
html.js .create:not(.is-wizard) .step:not(#step-1) .step-body {
  display: none;
}

.is-wizard .step[data-state="done"] .step-body,
.is-wizard .step[data-state="ahead"] .step-body,
.is-wizard .step[data-state="locked"] .step-body {
  display: none;
}

.is-wizard .step.is-collapsing .step-body {
  display: block;
}

.is-wizard .step[data-state="current"] {
  box-shadow:
    4px 0 0 0 var(--accent),
    -4px 0 0 0 var(--accent),
    0 4px 0 0 var(--accent),
    0 -4px 0 0 var(--accent),
    0 10px 0 0 var(--accent-dark),
    0 0 32px 4px rgba(247, 208, 70, 0.18);
}

.is-wizard .step[data-state="current"] .step-head {
  padding-top: 18px;
}

/* Done: a compact summary card; the whole card opens it again. */
.is-wizard .step[data-state="done"] {
  background: #1a2a3a;
  box-shadow:
    4px 0 0 0 #2f6b48,
    -4px 0 0 0 #2f6b48,
    0 4px 0 0 #2f6b48,
    0 -4px 0 0 #2f6b48,
    0 8px 0 0 var(--deep);
}

.is-wizard .step[data-state="done"] .step-head {
  padding: 12px 14px 0;
}

.is-wizard .step[data-state="done"] .step-head h2 {
  font-size: 1.0625rem;
  color: var(--ok);
}

.is-wizard .step[data-state="done"] .step-badge {
  width: 36px;
  height: 36px;
  background: #1f5e3a;
  box-shadow: inset -4px -4px 0 0 #164a2c;
}

.is-wizard .step[data-state="done"] .step-badge-num {
  display: none;
}

.is-wizard .step[data-state="done"] .step-badge-check {
  display: block;
}

.is-wizard .step[data-state="done"] .tag-opt {
  display: none;
}

.step-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 4px 14px 12px 62px;
  color: var(--text);
  background: none;
  border: 0;
  font: inherit;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
}

/* The summary button covers the whole card: tap anywhere to edit. */
.step-summary::before {
  content: "";
  position: absolute;
  inset: 0;
}

.step-summary:focus-visible {
  outline: none;
}

.step-summary:focus-visible::before {
  outline: 3px solid var(--accent);
  outline-offset: 6px;
}

.summary-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.summary-edit {
  flex: none;
  padding: 6px 10px;
  font-family: var(--pixel-font);
  font-size: 0.625rem;
  color: var(--deep);
  background: var(--ok);
  box-shadow: 0 3px 0 0 #2f6b48;
  transition: transform var(--dur-fast) steps(2, end);
}

.is-wizard .step[data-state="done"]:hover .summary-edit {
  transform: translateY(-2px);
}

.is-wizard .step[data-state="done"]:hover {
  background: #1e3245;
}

/* Ahead: visited, after the current level. A compact summary card like "done", in neutral colours. */
.is-wizard .step[data-state="ahead"] {
  background: var(--stage);
  box-shadow:
    4px 0 0 0 var(--edge),
    -4px 0 0 0 var(--edge),
    0 4px 0 0 var(--edge),
    0 -4px 0 0 var(--edge),
    0 8px 0 0 var(--deep);
}

.is-wizard .step[data-state="ahead"] .step-head {
  padding: 12px 14px 0;
}

.is-wizard .step[data-state="ahead"] .step-head h2 {
  font-size: 1.0625rem;
  color: var(--text);
}

.is-wizard .step[data-state="ahead"] .step-badge {
  width: 36px;
  height: 36px;
  color: var(--text);
  background: var(--stage-2);
  box-shadow: inset -4px -4px 0 0 var(--deep);
}

.is-wizard .step[data-state="ahead"] .tag-opt {
  display: none;
}

.is-wizard .step[data-state="ahead"] .summary-edit {
  color: var(--text);
  background: var(--stage-2);
  box-shadow: 0 3px 0 0 var(--deep);
}

.is-wizard .step[data-state="ahead"]:hover {
  background: var(--stage-2);
}

.is-wizard .step[data-state="ahead"]:hover .summary-edit {
  transform: translateY(-2px);
}

/* Locked: dim card with a padlock; optional ones keep their tag. */
.is-wizard .step[data-state="locked"] {
  opacity: 0.55;
  background: var(--bg);
  box-shadow:
    4px 0 0 0 var(--edge),
    -4px 0 0 0 var(--edge),
    0 4px 0 0 var(--edge),
    0 -4px 0 0 var(--edge);
}

.is-wizard .step[data-state="locked"] .step-head {
  padding: 12px 14px;
}

.is-wizard .step[data-state="locked"] .step-head h2 {
  font-size: 1.0625rem;
  color: var(--muted);
}

.is-wizard .step[data-state="locked"] .step-badge {
  width: 36px;
  height: 36px;
  background: var(--stage-2);
  box-shadow: inset -4px -4px 0 0 var(--deep);
}

.is-wizard .step[data-state="locked"] .step-badge-num {
  display: none;
}

.is-wizard .step[data-state="locked"] .step-badge-lock {
  display: block;
}

/* Incoming step: pixel slide + pop. */
@media (prefers-reduced-motion: no-preference) {
  .step.step-in .step-inner {
    animation: step-in 360ms steps(5, end) both;
  }

  .step.step-in-back .step-inner {
    animation: step-in-back 360ms steps(5, end) both;
  }

  .step.step-in .step-badge,
  .step.step-in-back .step-badge {
    animation: calhou-pop 420ms steps(5, end) both;
  }

  .shake {
    animation: shake 360ms steps(6, end);
  }
}

@keyframes step-in {
  from {
    opacity: 0;
    transform: translateX(32px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes step-in-back {
  from {
    opacity: 0;
    transform: translateX(-32px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(4px);
  }
}

/* ---------- Participant rows: trash button, enter and leave ---------- */

.participant {
  position: relative;
  padding: 10px 14px 0;
  background: var(--stage-2);
}

.participant-head {
  margin-bottom: 2px;
}

.btn-trash {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 48px;
  height: 48px;
  margin-bottom: 4px;
  padding: 0;
  color: var(--text);
  background: var(--stage);
  border: 3px solid var(--edge);
  border-radius: 2px;
  box-shadow: 0 4px 0 0 var(--deep);
  cursor: pointer;
  transition:
    transform var(--dur-fast) steps(2, end),
    box-shadow var(--dur-fast) steps(2, end),
    background-color var(--dur-fast) linear,
    border-color var(--dur-fast) linear;
}

.btn-trash:hover {
  background: var(--error-bg);
  border-color: var(--error-edge);
}

.btn-trash:active {
  transform: translateY(4px);
  background: #5a1f2c;
  border-color: var(--error-edge);
  box-shadow: 0 0 0 0 var(--deep);
}

.btn-trash:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: no-preference) {
  .btn-trash:hover .icon {
    animation: trash-wiggle 400ms steps(4, end) infinite;
  }

  .participant.is-entering,
  .group.is-entering {
    animation: row-in 420ms steps(6, end) both;
  }

  /* jump-start: the revealed field is never fully invisible, even on the first frame. */
  .is-entering:not(.participant):not(.group) {
    animation: calhou-slide-up 300ms steps(4, jump-start) both;
  }
}

@keyframes trash-wiggle {
  0%,
  100% {
    transform: rotate(0);
  }
  25% {
    transform: rotate(-10deg);
  }
  75% {
    transform: rotate(10deg);
  }
}

@keyframes row-in {
  0% {
    opacity: 0;
    transform: translateX(-28px);
  }
  70% {
    opacity: 1;
    transform: translateX(4px);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}

.participant.is-leaving {
  pointer-events: none;
  overflow: hidden;
}

.group-head {
  position: absolute;
  top: 8px;
  right: 10px;
}

.group {
  position: relative;
  padding-right: 70px;
}

/* ---------- Pills ---------- */

.channel-pill {
  border-radius: 2px;
  border-width: 3px;
  box-shadow: 0 3px 0 0 var(--deep);
  transition:
    background-color var(--dur-fast) steps(2, end),
    color var(--dur-fast) steps(2, end),
    border-color var(--dur-fast) steps(2, end),
    transform var(--dur-fast) steps(2, end),
    box-shadow var(--dur-fast) steps(2, end);
}

.channel-pill:active {
  transform: translateY(3px);
  box-shadow: none;
}

.channel-pill:has(input:checked) {
  box-shadow: 0 3px 0 0 var(--accent-dark);
}

.pill-icon {
  width: 24px;
  height: 24px;
}

.channel-pill:has(input:checked) .pill-icon {
  filter: drop-shadow(2px 2px 0 var(--deep));
}

@media (prefers-reduced-motion: no-preference) {
  .is-ready .channel-pill:has(input:checked) {
    animation: pill-pick 260ms steps(4, end);
  }
}

@keyframes pill-pick {
  0% {
    transform: scale(0.9);
  }
  60% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

/* ---------- Draw name + dice ---------- */

.btn-dice {
  gap: 10px;
}

.btn-dice .dice-icon {
  width: 28px;
  height: 28px;
}

@media (prefers-reduced-motion: no-preference) {
  .btn-dice:hover .dice-icon {
    animation: dice-wobble 500ms steps(4, end) infinite;
  }

  .btn-dice.is-rolling .dice-icon {
    animation: dice-roll 480ms steps(4, end);
  }

  .field input.is-flash {
    animation: input-flash 480ms steps(3, end);
  }
}

@keyframes dice-wobble {
  0%,
  100% {
    transform: rotate(0);
  }
  50% {
    transform: rotate(-12deg);
  }
}

@keyframes dice-roll {
  0% {
    transform: rotate(0) translateY(0);
  }
  50% {
    transform: rotate(180deg) translateY(-8px);
  }
  100% {
    transform: rotate(360deg) translateY(0);
  }
}

@keyframes input-flash {
  0% {
    background: #fff3b0;
  }
  100% {
    background: #ffffff;
  }
}

/* ---------- Final level: Turnstile + big Sortear! ---------- */

.submit-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin: 20px -16px 0;
  padding: 16px 0 0;
  border-top: 4px dashed var(--edge);
}

/* The widget only shows when Cloudflare needs a click (interaction-only), so no space is reserved
   for it: empty, the container is 0 px tall and Turnstile grows it when it has to ask. */

.step-nav-final {
  width: 100%;
  margin-top: 0;
  padding: 0 16px;
  justify-content: center;
}

.btn-sortear {
  flex: 1 1 auto;
  min-height: 68px;
  font-size: 1.125rem;
  margin-bottom: 10px;
}

.sortear-dice {
  display: inline-flex;
  line-height: 0;
}

.btn-sortear.is-sending {
  opacity: 1;
  cursor: progress;
}

@media (prefers-reduced-motion: no-preference) {
  .btn-sortear:not(:disabled):hover .sortear-dice {
    animation: dice-wobble 500ms steps(4, end) infinite;
  }

  .btn-sortear.is-sending .sortear-dice {
    animation: dice-roll 480ms steps(4, end) infinite;
  }
}

/* "A sortear…" overlay: two pixel dice tumbling. */
.rolling {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(8, 11, 26, 0.82);
  background-image: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.03) 0 2px, transparent 2px 4px);
}

.rolling-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 28px 32px;
  background: var(--stage);
  box-shadow:
    4px 0 0 0 var(--accent),
    -4px 0 0 0 var(--accent),
    0 4px 0 0 var(--accent),
    0 -4px 0 0 var(--accent),
    0 12px 0 0 var(--deep);
}

.rolling-dice {
  display: flex;
  gap: 18px;
}

.rolling-die .icon {
  width: 64px;
  height: 64px;
}

.rolling-text {
  margin: 0;
  font-family: var(--pixel-font);
  font-size: 1rem;
  color: var(--accent);
  text-shadow: 2px 2px 0 var(--deep);
}

@media (prefers-reduced-motion: no-preference) {
  .rolling {
    animation: calhou-fade var(--dur) steps(3, end) both;
  }

  .rolling-box {
    animation: calhou-blip-in var(--dur-slow) var(--ease-pixel) both;
  }

  .rolling-die {
    animation: die-tumble 520ms steps(4, end) infinite;
  }

  .rolling-die + .rolling-die {
    animation-delay: 130ms;
  }

  .rolling-text {
    animation: blink 900ms steps(2, end) infinite;
  }
}

@keyframes die-tumble {
  0% {
    transform: translateY(0) rotate(0);
  }
  25% {
    transform: translateY(-18px) rotate(90deg);
  }
  50% {
    transform: translateY(0) rotate(180deg);
  }
  75% {
    transform: translateY(-10px) rotate(270deg);
  }
  100% {
    transform: translateY(0) rotate(360deg);
  }
}

@keyframes blink {
  50% {
    opacity: 0.55;
  }
}

/* ---------- Phones ---------- */

@media (max-width: 40rem) {
  .levelbar {
    grid-template-columns: 1fr;
    padding: 4px 0 0;
  }

  .lvl-name {
    display: none;
  }

  .lvl:not(:last-child)::after {
    top: 21px;
  }

  .step-head {
    padding: 14px 14px 4px;
  }

  .step-body {
    padding: 10px 14px 14px;
  }

  .submit-area {
    margin-left: -14px;
    margin-right: -14px;
  }

  .step-nav-final {
    padding: 0 14px;
  }

  /* Keyboard focus and scrollIntoView keep fields clear of the sticky bar below. */
  html:has(.is-wizard) {
    scroll-padding-bottom: 112px;
  }

  /* Sticky bottom action bar for the current level. */
  .is-wizard .step[data-state="current"] .step-nav:not(.step-nav-final) {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 20px -14px -14px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    background: var(--stage);
    border-top: 4px solid var(--edge);
    box-shadow: 0 -8px 16px rgba(8, 11, 26, 0.5);
  }

  .step-nav .step-next {
    flex: 1 1 auto;
  }

  .step-nav-final .step-prev {
    flex: none;
    padding-left: 12px;
    padding-right: 12px;
  }

  .step-nav-final .step-prev span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .step-nav-final .step-prev {
    min-width: 56px;
  }

  .btn-sortear {
    font-size: 1rem;
    padding: 12px 14px;
  }

  .summary-edit {
    font-size: 0.5625rem;
  }

  .step-summary {
    padding-left: 14px;
  }
}

@media (max-width: 22.5rem) {
  .tag-opt {
    font-size: 0.5rem;
    padding: 3px 5px;
  }
}
