:root {
  --wood-1: #9a5d2c;
  --wood-2: #7a4720;
  --wood-3: #582f16;
  --wood-4: #3c1f0f;
  --panel: #1c1108;
  --panel-2: #241708;
  --brass-1: #e3bd63;
  --brass-2: #a9772a;
  --cream: #f4e9ce;
  --cream-2: #e9dab3;
  --ink: #241a10;
  --amber: #e0a53d;
  --coral: #e2664b;
  --teal: #3fa093;
  --indigo: #5271b8;
  --piece: clamp(80px, 12vw, 150px);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  min-height: 100vh;
  background:
    radial-gradient(
      ellipse 900px 500px at 50% -10%,
      rgba(227, 189, 99, 0.08),
      transparent 60%
    ),
    #120b06;
  font-family: "Manrope", sans-serif;
  color: var(--cream);
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 1120px;
  padding: 0 0 40px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px clamp(16px, 4vw, 36px) 16px;
  border-bottom: 1px solid rgba(227, 189, 99, 0.18);
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  color: var(--brass-1);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
}
.brand-mark svg {
  width: 100%;
  height: 100%;
}
.brand h1 {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-weight: 600;
  font-size: clamp(21px, 2.6vw, 29px);
  margin: 0;
  color: var(--brass-1);
  letter-spacing: 0.01em;
}
.brand .tagline {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: rgba(244, 233, 206, 0.55);
  letter-spacing: 0.02em;
}
.status {
  display: flex;
  align-items: center;
  gap: 10px;
}
.timer-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 13.5px;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(227, 189, 99, 0.25);
  padding: 8px 12px;
  border-radius: 999px;
  min-width: 96px;
}
.timer-chip svg {
  width: 14px;
  height: 14px;
  color: var(--brass-1);
  flex: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: "Manrope", sans-serif;
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: 0.02em;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid rgba(227, 189, 99, 0.5);
  background: linear-gradient(
    180deg,
    rgba(227, 189, 99, 0.16),
    rgba(227, 189, 99, 0.04)
  );
  color: var(--brass-1);
  cursor: pointer;
  transition:
    transform 0.15s ease,
    background 0.2s ease,
    box-shadow 0.2s ease;
}
.btn svg {
  width: 14px;
  height: 14px;
}
.btn:hover {
  background: linear-gradient(
    180deg,
    rgba(227, 189, 99, 0.28),
    rgba(227, 189, 99, 0.08)
  );
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0px) scale(0.97);
}
.btn-primary {
  background: linear-gradient(180deg, var(--brass-1), var(--brass-2));
  color: var(--ink);
  border-color: transparent;
  box-shadow: 0 8px 18px -6px rgba(227, 189, 99, 0.55);
}
.btn-primary:hover {
  filter: brightness(1.06);
}

/* ---------- Hint row ---------- */
.hint-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 16px clamp(16px, 4vw, 36px) 4px;
}
.hint {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: rgba(244, 233, 206, 0.75);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(227, 189, 99, 0.14);
  padding: 7px 12px;
  border-radius: 999px;
}
.hint svg {
  width: 14px;
  height: 14px;
  color: var(--brass-1);
  flex: none;
}

/* ---------- Difficulty switch ---------- */
.tier-switch {
  display: flex;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(227, 189, 99, 0.22);
}
.tier-btn {
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: rgba(244, 233, 206, 0.6);
  font-family: "Manrope", sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition:
    background 0.18s ease,
    color 0.18s ease;
}
.tier-btn:hover {
  color: var(--cream);
  background: rgba(255, 255, 255, 0.05);
}
.tier-btn.is-on {
  color: #2a1c0c;
  background: linear-gradient(160deg, var(--brass-1), var(--brass-2));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.tier-btn:focus-visible {
  outline: 2px solid var(--brass-1);
  outline-offset: 2px;
}

/* ---------- Seed chip ---------- */
.seed-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(227, 189, 99, 0.28);
  cursor: text;
}
.seed-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(227, 189, 99, 0.6);
}
.seed-input {
  width: 8ch;
  padding: 0;
  border: 0;
  background: none;
  color: var(--cream);
  font-family: "IBM Plex Mono", monospace;
  font-size: 13.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.seed-input:focus {
  outline: none;
  color: var(--brass-1);
}

/* ---------- Keyboard legend ---------- */
.keys-row {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 10px clamp(16px, 4vw, 36px) 0;
  font-size: 11.5px;
  color: rgba(244, 233, 206, 0.5);
}
.keys-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(227, 189, 99, 0.55);
}
.key-group {
  display: flex;
  align-items: center;
  gap: 5px;
}
kbd {
  display: inline-block;
  min-width: 19px;
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(227, 189, 99, 0.22);
  border-bottom-width: 2px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 10.5px;
  line-height: 1.25;
  text-align: center;
  color: var(--cream-2);
}

/* A control the current difficulty doesn't use. */
.is-off {
  opacity: 0.3;
}

/* ---------- Stage (the table) ---------- */
/* The board's color only — the grain itself is drawn once into
   #tableGrain by buildTableGrain(), so nothing here tiles or repeats. */
.stage {
  position: relative;
  width: min(94vw, 1040px);
  height: clamp(500px, 58vw, 640px);
  margin: 22px auto 8px;
  border-radius: 26px;
  isolation: isolate;
  background:
    radial-gradient(
      ellipse 70% 55% at 24% 18%,
      rgba(255, 216, 163, 0.1),
      transparent 70%
    ),
    radial-gradient(
      ellipse 55% 45% at 78% 74%,
      rgba(46, 22, 8, 0.22),
      transparent 72%
    ),
    radial-gradient(
      ellipse 40% 70% at 92% 20%,
      rgba(255, 226, 180, 0.05),
      transparent 70%
    ),
    linear-gradient(
      158deg,
      var(--wood-1) 0%,
      var(--wood-2) 45%,
      var(--wood-3) 78%,
      var(--wood-4) 100%
    );
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.35),
    inset 0 0 90px rgba(0, 0, 0, 0.45),
    0 30px 60px -20px rgba(0, 0, 0, 0.65);
  border: 10px solid var(--panel-2);
  outline: 1px solid rgba(227, 189, 99, 0.25);
  outline-offset: -11px;
  overflow: hidden;
  touch-action: none;
}
/* Hard plays on a 7x7 board — the cards and the target card grow so the
   dots keep roughly the size they have at 5x5. */
.stage.grid-7 {
  --piece: clamp(104px, 15vw, 196px);
}
.stage.grid-7 .target-card {
  width: clamp(104px, 12.5vw, 150px);
}
body.grid-7 .target-card-big {
  width: min(72vw, 52vh, 400px);
}

.table-grain {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}
/* Satin finish: a broad sheen across the boards, over the grain. */
.table-sheen {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(
      104deg,
      rgba(255, 236, 205, 0.09) 0%,
      rgba(255, 236, 205, 0) 26%,
      rgba(0, 0, 0, 0.05) 55%,
      rgba(255, 236, 205, 0.05) 78%,
      rgba(0, 0, 0, 0.08) 100%
    ),
    radial-gradient(
      ellipse 120% 90% at 50% 50%,
      transparent 45%,
      rgba(24, 11, 4, 0.35) 100%
    );
}

/* ---------- Target card mount ---------- */
.target-mount {
  position: absolute;
  left: 50%;
  top: 12%;
  transform: translate(-50%, -50%) rotate(-2deg);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 6;
  pointer-events: none;
}
.target-card {
  position: relative;
  display: block;
  width: clamp(88px, 10.5vw, 124px);
  aspect-ratio: 1;
  background: linear-gradient(160deg, #f7ecd2, #e8d8ae);
  border: 0;
  border-radius: 9px;
  padding: 12%;
  box-shadow:
    0 12px 22px -6px rgba(0, 0, 0, 0.55),
    inset 0 0 0 1px rgba(0, 0, 0, 0.07);
}
/* The mount ignores the pointer so it never blocks a drag; the card itself
   takes it back, because clicking it opens the enlarged view. */
button.target-card {
  pointer-events: auto;
  cursor: zoom-in;
  transition: transform 0.2s ease;
}
button.target-card:hover {
  transform: scale(1.06);
}
button.target-card:focus-visible {
  outline: 2px solid var(--brass-1);
  outline-offset: 3px;
}
.target-pin {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f3d27a, var(--brass-2));
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.45);
}
.target-label {
  margin-top: 9px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--brass-1);
  text-transform: uppercase;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* ---------- Slot ---------- */
.slot {
  position: absolute;
  left: 50%;
  top: 58%;
  width: var(--piece);
  height: var(--piece);
  transform: translate(-50%, -50%);
  border-radius: 16px;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.05) 0,
      rgba(255, 255, 255, 0.05) 1px,
      transparent 1px,
      transparent 20%
    ),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.05) 0,
      rgba(255, 255, 255, 0.05) 1px,
      transparent 1px,
      transparent 20%
    ),
    linear-gradient(160deg, var(--wood-3), var(--wood-4));
  box-shadow:
    inset 0 8px 16px rgba(0, 0, 0, 0.55),
    inset 0 -2px 3px rgba(255, 255, 255, 0.05);
  border: 3px solid var(--brass-2);
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.slot-hint {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(227, 189, 99, 0.4);
  transition: opacity 0.25s ease;
  pointer-events: none;
  text-align: center;
}
.slot.filled-any .slot-hint {
  opacity: 0;
}

/* ---------- Pieces ---------- */
.piece-wrapper {
  position: absolute;
  width: var(--piece);
  height: var(--piece);
  transform: translate(-50%, -50%);
  transition: transform 0.2s ease;
  cursor: grab;
  z-index: 2;
  touch-action: none;
  outline: none;
}
.piece-wrapper.dragging {
  cursor: grabbing;
  transform: translate(-50%, -50%) scale(1.08);
}
.piece-wrapper.settle {
  animation: settlePulse 0.32s ease;
}
@keyframes settlePulse {
  0% {
    transform: translate(-50%, -50%) scale(1);
  }
  40% {
    transform: translate(-50%, -50%) scale(1.09);
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
  }
}
.piece-wrapper:focus-visible .piece,
.piece-wrapper.is-selected .piece {
  box-shadow:
    0 0 0 3px var(--brass-1),
    0 10px 22px -6px rgba(0, 0, 0, 0.55);
}

.piece {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  transition: transform 0.32s cubic-bezier(0.34, 1.5, 0.62, 1);
  will-change: transform;
  box-shadow:
    0 8px 18px -8px rgba(15, 8, 3, 0.4),
    0 1px 3px rgba(15, 8, 3, 0.22);
}
/* Faint sheen only — the card must stay see-through so the dots of the
   cards underneath read through it. */
.piece::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.12),
    rgba(255, 255, 255, 0) 42%
  );
  pointer-events: none;
}
/* The tint identifies the card; it is NOT the color of its dots. */
.piece-amber {
  background: rgba(224, 165, 61, 0.08);
  border: 2px solid rgba(224, 165, 61, 0.5);
}
.piece-coral {
  background: rgba(226, 102, 75, 0.08);
  border: 2px solid rgba(226, 102, 75, 0.5);
}
.piece-teal {
  background: rgba(63, 160, 147, 0.08);
  border: 2px solid rgba(63, 160, 147, 0.5);
}
.piece-indigo {
  background: rgba(82, 113, 184, 0.08);
  border: 2px solid rgba(82, 113, 184, 0.5);
}
.flip-mark {
  position: absolute;
  left: 6px;
  bottom: 2px;
  font-size: 12px;
  line-height: 1;
  color: rgba(227, 189, 99, 0.75);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.piece-wrapper.is-flipped .flip-mark {
  opacity: 1;
}
.card-no {
  position: absolute;
  right: 5px;
  bottom: 3px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  line-height: 1;
  color: rgba(244, 233, 206, 0.45);
  pointer-events: none;
}

/* ---------- Dot grids ---------- */
.dot-grid {
  position: absolute;
  inset: 14%;
  display: grid;
  /* grid-template-columns/rows are set in buildDotGrid — the board is 5x5
     or 7x7 depending on the difficulty tier. */
}
.dot-grid .cell {
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Dots are fully opaque: a dot on an upper card hides the dot of any
   card below it. That overlay is the whole puzzle. */
.dot-grid .cell.filled::after {
  content: "";
  width: 58%;
  height: 58%;
  border-radius: 50%;
  background: radial-gradient(
    circle at 34% 28%,
    var(--dot-a),
    var(--dot-b) 78%
  );
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.3),
    0 0 0 1.5px rgba(26, 16, 7, 0.6),
    0 1px 2px rgba(0, 0, 0, 0.4);
}
.dot-amber {
  --dot-a: #f4cd74;
  --dot-b: #b8791b;
}
.dot-coral {
  --dot-a: #f28d6d;
  --dot-b: #b23c24;
}
.dot-teal {
  --dot-a: #6ac9b9;
  --dot-b: #1c7365;
}
.dot-indigo {
  --dot-a: #8ba7e4;
  --dot-b: #2c4790;
}
.target-card .dot-grid {
  inset: 12%;
}

/* ---------- Stack order tray ---------- */
.stack-tray {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.34);
  border: 1px solid rgba(227, 189, 99, 0.18);
  font-family: "IBM Plex Mono", monospace;
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(227, 189, 99, 0.6);
  white-space: nowrap;
  z-index: 7;
  pointer-events: none;
}
.stack-chips {
  display: flex;
  align-items: center;
  gap: 5px;
}
.stack-chip {
  width: 19px;
  height: 19px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 0;
  color: var(--cream);
  border: 1.5px solid currentColor;
}
.stack-chip.empty {
  border-style: dashed;
  border-color: rgba(227, 189, 99, 0.28);
  color: rgba(227, 189, 99, 0.28);
}
.stack-chip.chip-amber {
  border-color: var(--amber);
  background: rgba(224, 165, 61, 0.16);
}
.stack-chip.chip-coral {
  border-color: var(--coral);
  background: rgba(226, 102, 75, 0.16);
}
.stack-chip.chip-teal {
  border-color: var(--teal);
  background: rgba(63, 160, 147, 0.16);
}
.stack-chip.chip-indigo {
  border-color: var(--indigo);
  background: rgba(82, 113, 184, 0.16);
}

/* ---------- Snap ring + confetti ---------- */
.snap-ring {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid var(--brass-1);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: ringPulse 0.5s ease-out forwards;
  z-index: 400;
}
@keyframes ringPulse {
  0% {
    width: 16px;
    height: 16px;
    opacity: 0.95;
  }
  100% {
    width: 190px;
    height: 190px;
    opacity: 0;
  }
}
.confetti-bit {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: confettiFly 0.95s ease-out forwards;
  z-index: 500;
}
@keyframes confettiFly {
  0% {
    transform: translate(-50%, -50%) translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) translate(var(--dx), var(--dy))
      rotate(320deg);
    opacity: 0;
  }
}

/* ---------- Enlarged target ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 6, 3, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.modal.show {
  opacity: 1;
}
/* An author `display` beats the UA's [hidden] rule, so restore it by hand —
   without this the overlay keeps painting after it is hidden. */
.modal[hidden] {
  display: none;
}
.modal-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 26px 30px 24px;
  border-radius: 18px;
  background: linear-gradient(160deg, #221507, #170e05);
  border: 1px solid rgba(227, 189, 99, 0.28);
  box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.7);
  transform: scale(0.96);
  transition: transform 0.25s cubic-bezier(0.34, 1.5, 0.62, 1);
}
.modal.show .modal-card {
  transform: scale(1);
}
.modal-heading {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--brass-1);
}
.target-card-big {
  width: min(64vw, 46vh, 340px);
  cursor: default;
}
.target-card-big .dot-grid {
  inset: 12%;
}
.modal-note {
  margin: 0;
  max-width: 34ch;
  text-align: center;
  font-size: 12.5px;
  color: rgba(244, 233, 206, 0.6);
}
.modal-card kbd {
  margin-left: 6px;
}

/* ---------- Win overlay ---------- */
.win-overlay {
  position: absolute;
  inset: 0;
  background: rgba(18, 11, 6, 0.74);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 1000;
}
.win-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.win-overlay[hidden] {
  display: none;
}
.win-card {
  background: linear-gradient(160deg, #f7ecd2, #e9dab3);
  color: var(--ink);
  padding: 34px 40px;
  border-radius: 18px;
  text-align: center;
  box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.6);
  transform: translateY(8px) scale(0.96);
  transition: transform 0.35s cubic-bezier(0.34, 1.5, 0.62, 1);
  max-width: 86%;
}
.win-overlay.show .win-card {
  transform: translateY(0) scale(1);
}
.win-badge {
  width: 46px;
  height: 46px;
  margin: 0 auto 10px;
  color: var(--brass-2);
}
.win-badge svg {
  width: 100%;
  height: 100%;
}
.win-card h2 {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-weight: 600;
  font-size: clamp(24px, 3.4vw, 32px);
  margin: 0 0 6px;
}
.win-time {
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  color: #5a4a30;
  margin: 0 0 20px;
  letter-spacing: 0.03em;
}

/* ---------- Multiplayer ---------- */

/* The room dialog reuses .modal / .modal-card wholesale — including the
   explicit [hidden] rule that beats the UA stylesheet — and swaps one of
   three views inside it. */
.room-card {
  width: min(420px, calc(100vw - 36px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}
.room-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}
.room-view[hidden] {
  display: none;
}

.room-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}
.room-field span {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(244, 233, 206, 0.5);
}
.room-field input,
.code-input {
  font-family: "Manrope", sans-serif;
  font-size: 15px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(227, 189, 99, 0.28);
  background: rgba(0, 0, 0, 0.28);
  color: var(--cream);
  width: 100%;
}
.room-field input:focus,
.code-input:focus,
.limit-input:focus {
  outline: none;
  border-color: rgba(227, 189, 99, 0.7);
  box-shadow: 0 0 0 3px rgba(227, 189, 99, 0.16);
}
.code-input {
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  text-align: center;
}

.room-error {
  margin: 0;
  width: 100%;
  font-size: 13px;
  font-weight: 600;
  color: #f2a08a;
  text-align: center;
}
.room-error.is-status {
  color: rgba(244, 233, 206, 0.55);
  font-weight: 600;
}
.room-error[hidden] {
  display: none;
}

.room-or {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  font-size: 12px;
  color: rgba(244, 233, 206, 0.4);
}
.room-or::before,
.room-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(227, 189, 99, 0.18);
}
.room-join {
  display: flex;
  gap: 8px;
  width: 100%;
}
.room-join .code-input {
  flex: 1;
}

/* The code is the thing people read aloud, so it is the biggest text in
   the dialog and set in the mono face the seeds use. */
.room-code {
  font-family: "IBM Plex Mono", monospace;
  font-size: 42px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  color: var(--brass-1);
  text-shadow: 0 2px 10px rgba(227, 189, 99, 0.25);
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(227, 189, 99, 0.07);
  border: 1px solid rgba(227, 189, 99, 0.14);
  font-size: 14px;
  font-weight: 600;
  color: var(--cream);
}
.player-list li.is-you {
  border-color: rgba(227, 189, 99, 0.45);
}
.player-list li.is-gone {
  opacity: 0.45;
}
.player-tag {
  margin-left: auto;
  font-family: "IBM Plex Mono", monospace;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(244, 233, 206, 0.5);
}

.host-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}
.host-controls[hidden] {
  display: none;
}
.lobby-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.lobby-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(244, 233, 206, 0.5);
  flex: none;
  width: 84px;
}
.limit-fields {
  display: flex;
  align-items: center;
  gap: 6px;
}
.limit-input {
  width: 46px;
  text-align: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 15px;
  padding: 7px 4px;
  border-radius: 10px;
  border: 1px solid rgba(227, 189, 99, 0.28);
  background: rgba(0, 0, 0, 0.28);
  color: var(--cream);
}
.limit-unit {
  font-size: 12px;
  color: rgba(244, 233, 206, 0.5);
}
.btn-quiet {
  border-color: rgba(227, 189, 99, 0.22);
  background: none;
  font-weight: 600;
  color: rgba(244, 233, 206, 0.65);
}
.btn-quiet:hover {
  color: var(--brass-1);
}

.standings {
  list-style: none;
  counter-reset: place;
  margin: 0;
  padding: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.standings li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 13px;
  border-radius: 10px;
  background: rgba(227, 189, 99, 0.07);
  border: 1px solid rgba(227, 189, 99, 0.14);
  font-size: 14px;
  font-weight: 600;
  color: var(--cream);
}
.standings li.is-winner {
  background: linear-gradient(
    100deg,
    rgba(227, 189, 99, 0.22),
    rgba(227, 189, 99, 0.06)
  );
  border-color: rgba(227, 189, 99, 0.5);
}
.standings li.is-failed {
  opacity: 0.55;
}
.standings .place {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--brass-1);
  width: 26px;
  flex: none;
}
.standings .result {
  margin-left: auto;
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  color: rgba(244, 233, 206, 0.75);
}
.standings .flagged {
  font-size: 11px;
  color: #f2a08a;
}

/* The race strip replaces the solo controls while a race is on. */
/* Inset to match the topbar's own horizontal padding, and held clear of
   its bottom border — full-bleed and flush, the bar's top edge collided
   with that border and read as a doubled line. */
.race-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin: 14px clamp(16px, 4vw, 36px) 0;
  padding: 9px 14px;
  border-radius: 12px;
  background: rgba(227, 189, 99, 0.08);
  border: 1px solid rgba(227, 189, 99, 0.22);
}

/* A finish is announced on the bar itself, so it registers even if the
   player is staring at their own cards. First blood glows brass and hard;
   every finish after it gets the same shape, quieter — the ranking is
   legible from the brightness alone. */
.race-bar.glow-strong {
  animation: raceGlowStrong 1.9s ease-out;
}
.race-bar.glow-soft {
  animation: raceGlowSoft 1.5s ease-out;
}
@keyframes raceGlowStrong {
  0% {
    box-shadow: 0 0 0 0 rgba(227, 189, 99, 0);
  }
  16% {
    background: rgba(227, 189, 99, 0.22);
    border-color: rgba(227, 189, 99, 0.95);
    box-shadow:
      0 0 30px 5px rgba(227, 189, 99, 0.5),
      inset 0 0 18px rgba(227, 189, 99, 0.2);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(227, 189, 99, 0);
  }
}
@keyframes raceGlowSoft {
  0% {
    box-shadow: 0 0 0 0 rgba(227, 189, 99, 0);
  }
  20% {
    background: rgba(227, 189, 99, 0.14);
    border-color: rgba(227, 189, 99, 0.5);
    box-shadow: 0 0 16px 2px rgba(227, 189, 99, 0.22);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(227, 189, 99, 0);
  }
}
.race-bar[hidden] {
  display: none;
}
.race-room {
  font-size: 12px;
  color: rgba(244, 233, 206, 0.6);
}
.race-room b {
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.18em;
  color: var(--brass-1);
}
.race-clock {
  font-family: "IBM Plex Mono", monospace;
  font-size: 20px;
  font-weight: 600;
  color: var(--cream);
}
.race-clock.is-low {
  color: #f2a08a;
}
.race-standings {
  flex: 1;
  min-width: 160px;
  font-size: 12.5px;
  color: rgba(244, 233, 206, 0.7);
}
.race-bar .btn {
  margin-left: auto;
}

/* Anything that would desync a race is hidden for its duration. */
body.racing .tier-switch:not(#lobbyTiers),
body.racing .seed-chip,
body.racing #newPuzzleBtn,
body.racing #multiplayerBtn {
  display: none;
}

/* Solo, the win card lives inside the stage, where the player is already
   looking. In a race the finish can land while they are scrolled or on a
   short window, and it has to be unmissable — so it covers the viewport
   instead. Below .modal (2000), so the standings still replace it. */
body.racing .win-overlay {
  position: fixed;
}

/* An author `display` beats the UA's [hidden] rule — see the modal note.
   The win card's two buttons swap by `hidden`, so they need this. */
.btn[hidden],
.win-note[hidden] {
  display: none;
}

/* First to finish. The card keeps its shape and gains a brass frame and a
   glow, so the difference reads instantly without a second layout. */
.win-card.is-first {
  border: 1px solid rgba(169, 119, 42, 0.55);
  box-shadow:
    0 30px 60px -12px rgba(0, 0, 0, 0.6),
    0 0 0 4px rgba(227, 189, 99, 0.28),
    0 0 46px rgba(227, 189, 99, 0.4);
  animation: firstGlow 2.4s ease-in-out 2;
}
.win-card.is-first h2 {
  font-size: clamp(27px, 4vw, 38px);
}
.win-note {
  font-family: "Manrope", sans-serif;
  font-size: 13.5px;
  font-weight: 600;
  color: rgba(58, 42, 20, 0.72);
  margin: 0 0 14px;
}
/* Pulses the frame, never the transform — .win-card's entrance is a
   transform transition, and an animation on the same property would fight
   it and make the card jump on open. */
@keyframes firstGlow {
  0%,
  100% {
    box-shadow:
      0 30px 60px -12px rgba(0, 0, 0, 0.6),
      0 0 0 4px rgba(227, 189, 99, 0.28),
      0 0 46px rgba(227, 189, 99, 0.4);
  }
  50% {
    box-shadow:
      0 30px 60px -12px rgba(0, 0, 0, 0.6),
      0 0 0 7px rgba(227, 189, 99, 0.42),
      0 0 66px rgba(227, 189, 99, 0.62);
  }
}

.countdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(12, 8, 4, 0.82);
}
.countdown-overlay[hidden] {
  display: none;
}
.countdown-num {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-size: clamp(80px, 18vw, 180px);
  line-height: 1;
  color: var(--brass-1);
  animation: countPop 1s ease-out;
}
.countdown-note {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(244, 233, 206, 0.55);
}
@keyframes countPop {
  0% {
    transform: scale(1.5);
    opacity: 0;
  }
  30% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal,
  .modal-card,
  button.target-card,
  .piece-wrapper,
  .piece,
  .snap-ring,
  .confetti-bit,
  .win-card,
  .win-overlay,
  .countdown-num,
  .race-bar {
    animation: none !important;
    transition-duration: 0.01s !important;
  }
}

@media (max-width: 560px) {
  .status {
    width: 100%;
    justify-content: space-between;
  }
  .hint-row {
    gap: 8px;
  }
}
