* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/*
 * Scales the whole rem-based layout uniformly to fit any viewport,
 * preserving the 402x874 reference aspect ratio — every rem value in
 * the app (positions, sizes, the .frame itself) shrinks or grows with
 * this. Capped at 16px so the app never grows past its reference size
 * on large screens. Uses svh (not dvh) for the height term so mobile
 * browser chrome showing/hiding during scroll never triggers a resize
 * — svh is fixed to the smallest possible viewport, unlike dvh.
 */
html {
  font-size: min(16px, calc(100vw * 16 / 402), calc(100svh * 16 / 874));
}

html,
body {
  height: 100%;
}

body {
  background: #0c0c0c;
  font-family: "Replica LL", sans-serif;
  color: #fff;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  display: flex;
  align-items: center;
  justify-content: center;
}

#bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* ---------- frame (iPhone 17, 402x874 reference) ---------- */

.frame {
  position: relative;
  z-index: 1;
  width: 25.125rem;
  height: 54.625rem;
}

/*
 * Fills the whole viewport (not just .frame) with black while a
 * screen like Settings is open, so the letterbox margins around the
 * frame go black too instead of showing the animated #bg canvas. The
 * frame has no transform, so this fixed element still resolves against
 * the real viewport despite living inside .frame.
 *
 * z-index:1 is required, not decorative: the floating intro cards are
 * never clipped (they intentionally drift above/below the stage, see
 * shuffle.js), so they can render outside .frame's own box. .screen-main
 * has no z-index of its own (auto), and an auto-stacked element always
 * paints above an equally-unstacked EARLIER sibling — without an
 * explicit z-index here those overflowing cards would paint over this
 * backdrop instead of being covered by it. 1 is still below
 * .screen-settings' z-index:2, so the panel itself stays on top.
 */
.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: #0c0c0c;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.45s ease;
}

.settings-backdrop.open {
  opacity: 1;
  visibility: visible;
}
/* 
* {
  outline: 1px solid red;
} */

/* ---------- title ---------- */

.title {
  position: absolute;
  top: 4.5rem;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 2rem;
  font-weight: 400;
  line-height: 1.2;
  z-index: 2;
}

/* ---------- shuffle intro (floating cards) ---------- */

.shuffle-stage {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  cursor: pointer;
}

/* grid is the end state — hidden during the intro/gather phases */
.screen-main.intro .grid,
.screen-main.gathered .grid {
  display: none;
}

/* end state: grid visible, floating stage gone */
.screen-main.done .shuffle-stage {
  display: none;
}

/* deal-card = a flippable card (back = dice PNG, front = grid card) */
.deal-card {
  position: absolute;
  top: 0;
  left: 0;
  width: 6.9375rem;
  height: 8rem;
  will-change: transform;
  perspective: 56.25rem;
}

.deal-card .flip {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}

.deal-card.flipped .flip {
  transform: rotateY(180deg);
}

.deal-card .face {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 0.375rem;
  overflow: hidden;
}

.deal-card .face-back img {
  width: 100%;
  height: 100%;
  display: block;
}

.deal-card .face-front {
  transform: rotateY(180deg);
}

.deal-card .face-front .card {
  width: 100%;
  height: 100%;
}

/* hand prompt shown on the presented card during dealing */
.deal-hand {
  position: absolute;
  z-index: 120;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: opacity 0.3s ease;
}

.deal-hand.show {
  opacity: 1;
}

/* soft glow behind the prompt, fades out on gather */
.shuffle-glow {
  position: absolute;
  top: 25.625rem;
  left: 50%;
  width: min(22.5rem, 90vw);
  height: min(22.5rem, 90vw);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.14) 0%,
    rgba(255, 255, 255, 0.06) 35%,
    transparent 68%
  );
  z-index: 1;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.screen-main.gathered .shuffle-glow {
  opacity: 0;
}

.shuffle-prompt {
  position: absolute;
  top: 20.625rem;
  left: 0;
  width: 100%;
  text-align: center;
  z-index: 2;
  transition: opacity 0.35s ease;
}

.screen-main.gathered .shuffle-prompt {
  opacity: 0;
  pointer-events: none;
}

.shuffle-text {
  font-size: 1.75rem;
  font-weight: 300;
  line-height: 1.25;
}

span.shuffle-hand {
  margin-top: 1rem;
  color: #fff;
  font-size: 3rem;
  transform: rotate(35deg);
  display: inline-block;
}

/* ---------- card grid ---------- */

.grid {
  position: absolute;
  top: 9.625rem;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(3, 6.9375rem);
  column-gap: 1.0625rem;
  row-gap: 0.84375rem;
}

/*
 * Card internals are positioned absolutely, calibrated against the
 * Figma export (pages_pngs/Flow_4_Anfang.png) using the font metrics
 * of Replica LL (ascent 950, cap height 700 per 1000 upm):
 * name cap top 19.5px, icon glyph center 74px, duty cap top 100.5px.
 */
.card {
  position: relative;
  width: 6.9375rem;
  height: 8rem;
  background: #fff;
  border-radius: 0.375rem;
  color: #000;
}

.grid .card {
  cursor: pointer;
  transition: transform 0.15s ease;
}

.grid .card:hover {
  transform: scale(1.04);
}

.card-name,
.card-duty {
  position: absolute;
  left: 0;
  width: 100%;
  text-align: center;
  line-height: 1.2;
}

.card-name {
  top: 1rem;
  font-size: 0.875rem;
  font-weight: 400;
}

/*
 * No per-icon --dx/--dy nudges here anymore: those were measured for
 * the old inline-SVG icons and only applied to the static grid, not
 * the animated deal-card faces — so every icon visibly jumped the
 * moment the two got swapped after the flip. Font glyphs are centred
 * by the flex box instead; re-measure against Figma only if needed.
 */
.card-icon {
  position: absolute;
  top: 4.625rem;
  left: 50%;
  width: 2rem;
  height: 2rem;
  display: flex;
  justify-content: center;
  align-items: center;
  transform: translate(-50%, -50%);
}

.card-duty {
  top: 6.109375rem;
  font-size: 0.6875rem;
  font-weight: 400;
}

/* ---------- screens ---------- */

.screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/*
 * Settings panel slides in from the left over the main screen.
 * All coordinates below are calibrated against the Figma export
 * pages_pngs/Einstellungen.png (content column x 52.5..348.5).
 */
.screen-settings {
  z-index: 2;
  background: #0c0c0c;
  transform: translateX(calc(-100% - 1.5rem));
  transition: transform 0.45s cubic-bezier(0.32, 0.72, 0, 1);
  visibility: hidden;
}

.screen-settings.open {
  transform: none;
  visibility: visible;
}

.screen-settings.no-anim {
  transition: none;
}

/* keep it visible while sliding out */
.screen-settings.closing {
  visibility: visible;
}

/* ---------- settings: headings ---------- */

.section-heading {
  position: absolute;
  left: 3.25rem;
  display: flex;
  align-items: baseline;
  gap: 0.5625rem;
  font-size: 1.5rem;
  font-weight: 400;
  line-height: 1.2;
}

.section-heading img {
  align-self: flex-end;
  margin-bottom: 0.375rem; /* image bottom sits on the text baseline */
}

.section-heading .count {
  font-size: 1rem;
  font-weight: 300;
}

/* ---------- settings: rows ---------- */

.freikarte-row {
  position: absolute;
  top: 7.9375rem;
  left: 3.25rem;
  width: 18.5rem;
  height: 2.625rem;
  border: 0.0625rem solid #fff;
  border-radius: 1.34375rem 0.375rem 0.375rem 1.34375rem;
  box-sizing: border-box;
}

/*
 * The fill overlaps the container border on the left end (white on
 * white) so there is a single clean edge — no hairline gap.
 */
.freikarte-fill {
  position: absolute;
  top: -0.0625rem;
  bottom: -0.0625rem;
  left: -0.0625rem;
  width: 15.9375rem;
  background: #fff;
  border-radius: 1.3125rem 0 0 1.3125rem;
  color: #000;
}

/* 40px icon, glyph optically centered on the semicircle center (21,21) */
.freikarte-balloon {
  position: absolute;
  left: 0.125rem;
  top: 0.3rem;
  font-size: 1.75rem;
}

.freikarte-label {
  position: absolute;
  left: 2.625rem;
  right: 2.625rem;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 300;
  color: #000;
}

.info-btn {
  color: #fff;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 2.5625rem;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.info-btn [class^="icon-"] {
  font-size: 3rem;
}

.list-viewport {
  position: absolute;
  left: 3.25rem;
  width: 18.5rem;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  scroll-snap-type: y proximity;
  scroll-behavior: smooth;
}

.list-viewport::-webkit-scrollbar {
  display: none;
}

.list-viewport.duties {
  top: 11.25rem;
  height: 9.375rem;
}

.list-viewport.names {
  top: 28.25rem;
  height: 12.4375rem;
}

.list-viewport.icons {
  top: 34.125rem;
  left: 1.75rem;
  width: 21.525rem;
  height: 12.28125rem;
}

.item-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5625rem;
}

.item {
  position: relative;
  height: 2.6875rem;
  flex: none;
  scroll-snap-align: start;
}

.row {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 15.375rem;
  border: 0.0625rem solid #fff;
  border-radius: 0.375rem;
  box-sizing: border-box;
  cursor: pointer;
}

.row.duty {
  border-radius: 1.34375rem 0.375rem 0.375rem 1.34375rem; /* 21.5 = h/2, true semicircle end */
}

/*
 * Concentric with the row's semicircular left end, with an even
 * ~1.5px dark gap between the circle and the 1px border lines.
 */
.badge {
  position: absolute;
  left: 0.125rem;
  top: 0.125rem;
  width: 2.3125rem;
  height: 2.3125rem;
  border-radius: 50%;
  background: #fff;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.row-label {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 300;
  white-space: nowrap;
}

/* name rows are directly-editable inputs, not plain labels */
input.row-label {
  border: 0;
  background: transparent;
  color: #fff;
  font-family: "Replica LL", sans-serif;
  outline: none;
  padding: 0 0.75rem;
  text-align: center;
}

input.row-label::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

/* centered between the badge circle and the row's right edge */
.row.duty .row-label {
  left: 2.625rem;
}

.x-btn {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 2.625rem;
  border: 0.0625rem solid #fff;
  border-radius: 0.375rem;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-sizing: border-box;
}

.x-btn [class^="icon-"] {
  font-size: 1.625rem;
}

/* ---------- settings: scrollbars ---------- */

.track {
  position: absolute;
  left: 22.5rem;
  width: 0.0625rem;
  background: rgba(255, 255, 255, 0.4);
  pointer-events: none;
}

.track.icons {
  left: 24.025rem;
}

.thumb.icons {
  left: 23.9rem;
}

.thumb {
  position: absolute;
  left: 22.375rem;
  width: 0.3125rem;
  height: 0.3125rem;
  border-radius: 50%;
  background: #fff;
  pointer-events: none;
}

/* ---------- settings: buttons ---------- */

.plus-btn {
  color: #fff;
  position: absolute;
  left: 3.25rem;
  width: 18.5rem;
  height: 2.625rem;
  border: 0.0625rem solid #fff;
  border-radius: 0.375rem;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* .action-btn.check-btn — higher specificity so the 168x52 size wins
   over the base .action-btn 48x48 (which is declared later in the file) */
.action-btn.check-btn {
  position: absolute;
  left: 50%;
  top: 47.5rem;
  transform: translateX(-50%);
  width: 10.5rem;
  height: 3.25rem;
}

/* ---------- Ämtli erfassen screen ---------- */

/*
 * Full-screen form that slides up from the bottom over the settings
 * panel. Calibrated against pages_pngs/Ämtli erfassen.png.
 */
.screen-erfassen {
  z-index: 3;
  background: #0c0c0c;
  color: #fff;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  visibility: hidden;
}

.screen-erfassen.open {
  transform: none;
  visibility: visible;
}

.screen-erfassen.closing {
  visibility: visible;
}

.erfassen-header {
  position: absolute;
  top: 3.0625rem;
  left: 1.25rem;
  right: 1.25rem;
  height: 2.625rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hdr-btn {
  width: 2.625rem;
  height: 2.625rem;
  flex: none;
  border: 0.0625rem solid #fff;
  border-radius: 0.375rem;
  background: transparent;
  color: #fff;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hdr-btn [class^="icon-"] {
  font-size: 1.25rem;
}

.erfassen-title {
  font-size: 1.5rem;
  font-weight: 400;
}

.erfassen-preview {
  position: absolute;
  top: 7.6875rem;
  left: 50%;
  transform: translateX(-50%);
  width: 7.875rem;
  height: 7.875rem;
  border-radius: 50%;
  background: #fff;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.erfassen-preview [class^="icon-"] {
  font-size: 6.25rem;
}

.erfassen-input,
.erfassen-desc {
  position: absolute;
  left: 1.9375rem;
  width: min(21.25rem, 90vw);
  border: 0.0625rem solid #fff;
  border-radius: 0.375rem;
  background: transparent;
  color: #fff;
  font-family: "Replica LL", sans-serif;
  font-size: 1rem;
  font-weight: 300;
  box-sizing: border-box;
  outline: none;
}

.erfassen-input {
  top: 18rem;
  height: 3.4375rem;
  padding: 0 1.5rem;
}

.erfassen-desc {
  top: 22.875rem;
  height: 9.9375rem;
  padding: 1.125rem 1.5rem;
  resize: none;
  line-height: 1.4;
}

.erfassen-input::placeholder,
.erfassen-desc::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(7, 2.625rem);
  column-gap: 0.525rem;
  row-gap: 0.59375rem;
}

.icon-cell {
  width: 2.625rem;
  height: 2.625rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: start;
}

.icon-cell [class^="icon-"] {
  font-size: 1.375rem;
}

.icon-cell.selected {
  background: #fff;
  color: #000;
}

/* ---------- bottom action buttons ---------- */

.actions {
  position: absolute;
  bottom: 4.5rem;
  left: 4rem;
  right: 4rem;
  display: flex;
  justify-content: space-between;
  z-index: 2;
}

/* solid fill so floating cards don't show through behind the buttons */
.actions .action-btn {
  background: transparent;
}

.action-btn {
  width: 3rem;
  height: 3rem;
  border: 0.0625rem solid #fff;
  border-radius: 0.375rem;
  background: transparent;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.action-btn [class^="icon-"] {
  font-size: 1.75rem;
}

.plus-btn:disabled,
.x-btn:disabled,
.hdr-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* shuffle button only reshuffles once a round has been revealed */
#btn-shuffle {
  opacity: 0.5;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.screen-main.done #btn-shuffle {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- generic info popup ---------- */

.popup-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.popup-overlay.open {
  opacity: 1;
  visibility: visible;
}

.popup-card {
  width: 100%;
  max-width: 21.125rem;
  border: 0.0625rem solid #fff;
  border-radius: 0.375rem;
  background: #0c0c0c;
  padding: 2.5rem 2rem 2rem;
  text-align: center;
}

.popup-title {
  font-size: 1.75rem;
  font-weight: 400;
  text-transform: uppercase;
  margin-bottom: 1.5rem;
}

.popup-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  font-size: 1rem;
  font-weight: 300;
  line-height: 1.4;
  margin-bottom: 2rem;
}

/* Replica LL only ships weight 300/400 — use 400 for emphasis instead
   of a synthesized bold, consistent with the rest of the app. */
.popup-body strong {
  font-weight: 400;
}

.popup-confirm {
  margin: 0 auto;
  width: 10.5rem;
  height: 3.25rem;
}

/* ---------- discard-changes alert (two text buttons) ---------- */

.popup-actions {
  display: flex;
  gap: 0.75rem;
}

.text-btn {
  flex: 1;
  height: 3.25rem;
  border: 0.0625rem solid #fff;
  border-radius: 0.375rem;
  background: transparent;
  color: #fff;
  font-family: "Replica LL", sans-serif;
  font-size: 1rem;
  font-weight: 300;
  cursor: pointer;
}

.text-btn-primary {
  background: #fff;
  color: #000;
}

/* ---------- light per-card detail popup ---------- */

.popup-card.light {
  background: #fff;
  color: #000;
  border-color: #000;
  aspect-ratio: 350.23 / 542.65;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.action-btn.light {
  color: #000;
  border-color: #000;
}

.card-popup-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}

.card-popup-icon [class^="icon-"] {
  font-size: 4.5rem;
}

.card-popup-title {
  font-size: 2.25rem;
  font-weight: 400;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.card-popup-name {
  font-size: 1.5rem;
  font-weight: 300;
  margin-bottom: 1.5rem;
}
