@font-face {
  font-family: "Inter Fallback";
  src: local("Arial");
  size-adjust: 106%;
  ascent-override: 91%;
  descent-override: 22%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Fraunces Fallback";
  src: local("Georgia");
  size-adjust: 94%;
  ascent-override: 92%;
  descent-override: 24%;
  line-gap-override: 0%;
}

:root {
  color-scheme: dark;
  --felt: #0e1512;
  --felt-2: #1c1a12;
  --panel: rgba(20, 25, 22, 0.78);
  --panel-solid: #151b18;
  --hairline: rgba(212, 166, 74, 0.28);
  --text: #f3efe6;
  --muted: #b9b3a6;
  --brass: #d4a64a;
  --brass-dark: #20180a;
  --danger: #e46773;
  --serif: Fraunces, "Fraunces Fallback", Georgia, serif;
  --sans: Inter, "Inter Fallback", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 4%, rgba(28, 26, 18, 0.95), transparent 38%),
    #0e1512;
  color: var(--text);
  font-family: var(--sans);
}

button,
input {
  min-height: 44px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  font: inherit;
}

button {
  padding: 0 16px;
  background: var(--brass);
  color: var(--brass-dark);
  font-weight: 600;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
}

button:not(.carousel-card):not(.tap-zone):not(.howto-play):not(.jigsaw-picture-button):active { transform: translateY(1px); }

button.ghost,
.secondary-action {
  background: rgba(243, 239, 230, 0.06);
  color: var(--text);
}

input {
  width: 100%;
  padding: 0 14px;
  background: rgba(243, 239, 230, 0.08);
  color: var(--text);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

p {
  color: var(--muted);
  line-height: 1.35;
}

.screen {
  position: absolute;
  inset: 0;
  min-height: 100dvh;
}

#listScreen {
  overflow: hidden;
  padding: max(16px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% 0%, rgba(28, 26, 18, 0.96), transparent 42%),
    radial-gradient(circle at 18% 100%, rgba(92, 57, 31, 0.12), transparent 34%),
    var(--felt);
}

.lobby-topbar {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100%, 1100px);
  margin: 0 auto;
}

.lobby-topbar h1 {
  font-family: var(--serif);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.player-avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: rgba(212, 166, 74, 0.1);
  color: var(--brass);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.lobby-shell {
  width: 100%;
  height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(18px, env(safe-area-inset-bottom)) - 38px);
}

.lobby {
  display: grid;
  grid-template-rows: auto minmax(315px, 1fr) auto;
  align-items: center;
  width: min(100%, 1100px);
  height: 100%;
  margin: 0 auto;
  padding: 26px 0 0;
}

.lobby-eyebrow {
  align-self: end;
  color: rgba(185, 179, 166, 0.82);
  font-size: 13px;
  font-weight: 500;
}

.picture-carousel {
  position: relative;
  width: 100%;
  height: min(46dvh, 390px);
  min-height: 315px;
  perspective: 1200px;
  outline: none;
  touch-action: pan-y;
}

.carousel-stage {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.carousel-card {
  position: absolute;
  top: 50%;
  left: 50%;
  width: clamp(192px, 54vw, 236px);
  aspect-ratio: 3 / 4;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: #101310;
  box-shadow:
    0 calc(18px + var(--abs) * 8px) calc(34px + var(--abs) * 10px) rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(243, 239, 230, 0.08);
  opacity: var(--opacity);
  overflow: hidden;
  transform:
    translate3d(calc(-50% + var(--x)), -50%, var(--z))
    rotateY(var(--rotate))
    scale(var(--scale));
  transform-style: preserve-3d;
  transition:
    transform 320ms ease-out,
    opacity 320ms ease-out,
    box-shadow 320ms ease-out;
}

.carousel-card.is-focused {
  box-shadow:
    0 24px 56px rgba(0, 0, 0, 0.52),
    0 0 0 1px var(--brass);
}

.carousel-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.tap-zone {
  position: absolute;
  top: 10%;
  bottom: 10%;
  display: none;
  width: 28%;
  min-height: 0;
  border: 0;
  background: transparent;
  color: transparent;
  z-index: 30;
}

.tap-zone-left { left: 0; }
.tap-zone-right { right: 0; }

.lobby-detail {
  display: grid;
  justify-items: center;
  gap: 13px;
  width: min(100%, 420px);
  margin: 0 auto;
  padding-bottom: 2px;
  text-align: center;
}

.picture-title {
  min-height: 82px;
  color: var(--text);
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.01em;
  transition: opacity 180ms ease-out, transform 180ms ease-out;
}

.picture-title.is-swapping {
  opacity: 0;
  transform: translateY(5px);
}

.piece-chooser-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 40px;
  color: var(--brass);
}

.piece-chooser {
  display: inline-flex;
  gap: 8px;
}

.piece-pill {
  min-width: 58px;
  min-height: 38px;
  padding: 0 13px;
  border-color: var(--brass);
  background: transparent;
  color: var(--brass);
  font-size: 15px;
  font-weight: 700;
}

.piece-pill[aria-pressed="true"] {
  background: var(--brass);
  color: var(--brass-dark);
}

.pieces-word,
.time-estimate {
  color: var(--muted);
  font-size: 14px;
}

.rotate-toggle-row {
  display: inline-grid;
  grid-template-columns: auto auto auto;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 34px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.rotate-toggle-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 1px;
  opacity: 0;
  pointer-events: none;
}

.rotate-switch {
  position: relative;
  width: 42px;
  height: 24px;
  border: 1px solid rgba(212, 166, 74, 0.48);
  border-radius: 999px;
  background: rgba(243, 239, 230, 0.08);
}

.rotate-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: var(--muted);
  transition: transform 180ms ease-out, background 180ms ease-out;
}

.rotate-toggle-row input:checked + .rotate-switch {
  background: var(--brass);
}

.rotate-toggle-row input:checked + .rotate-switch::after {
  background: var(--brass-dark);
  transform: translateX(18px);
}

.rotate-toggle-row input:focus-visible + .rotate-switch {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
}

.rotate-toggle-row.is-disabled {
  color: rgba(185, 179, 166, 0.58);
}

.rotate-toggle-row.is-disabled .rotate-switch {
  border-color: rgba(185, 179, 166, 0.22);
  background: rgba(243, 239, 230, 0.04);
}

.rotate-toggle-row.is-disabled .rotate-switch::after {
  background: rgba(185, 179, 166, 0.44);
}

.rotate-hint {
  grid-column: 1 / -1;
  color: rgba(185, 179, 166, 0.66);
  font-size: 12px;
}

.lobby-actions {
  display: grid;
  gap: 8px;
  width: 100%;
  padding-top: 3px;
}

.primary-action,
.secondary-action {
  width: 100%;
  min-height: 52px;
  font-size: 17px;
  font-weight: 500;
}

.primary-action {
  border-color: rgba(255, 227, 157, 0.52);
  background: var(--brass);
  color: var(--brass-dark);
}

.secondary-action {
  border-color: rgba(212, 166, 74, 0.42);
}

.code-link {
  justify-self: center;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.lobby-empty {
  margin: 80px auto 0;
  max-width: 320px;
  text-align: center;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  align-items: end;
  background: rgba(3, 6, 5, 0);
  pointer-events: none;
  transition: background 260ms ease-out;
  z-index: 20;
}

.sheet-backdrop.is-open {
  background: rgba(3, 6, 5, 0.58);
  pointer-events: auto;
}

.join-sheet {
  position: relative;
  display: grid;
  gap: 14px;
  width: min(100%, 460px);
  margin: 0 auto;
  padding: 12px 18px max(18px, env(safe-area-inset-bottom));
  border: 1px solid var(--hairline);
  border-radius: 16px 16px 0 0;
  background: #121814;
  box-shadow: 0 -22px 52px rgba(0, 0, 0, 0.48);
  transform: translateY(105%);
  transition: transform 260ms ease-out;
}

.sheet-backdrop.is-open .join-sheet {
  transform: translateY(0);
}

.join-sheet h2 {
  font-family: var(--serif);
  font-size: 27px;
  line-height: 1;
}

.sheet-grip {
  justify-self: center;
  width: 44px;
  height: 4px;
  border-radius: 999px;
  background: rgba(185, 179, 166, 0.32);
}

.sheet-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 42px;
  min-height: 42px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0;
}

.sheet-close::before {
  content: "X";
  font-size: 15px;
}

.join-sheet.is-invalid input {
  border-color: var(--danger);
  animation: shake 180ms linear;
}

.howto-sheet {
  gap: 12px;
}

.howto-video-wrap {
  position: relative;
  width: min(100%, 315px);
  aspect-ratio: 9 / 16;
  max-height: min(58dvh, 560px);
  justify-self: center;
  overflow: hidden;
  border: 1px solid rgba(212, 166, 74, 0.28);
  border-radius: 8px;
  background: #050706;
}

.howto-video-wrap video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.howto-play {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  min-height: 82px;
  padding: 0;
  border-color: rgba(255, 227, 157, 0.72);
  border-radius: 999px;
  background: var(--brass);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.45);
  color: var(--brass-dark);
  font-size: 0;
  transform: translate(-50%, -50%);
}

.howto-play::before {
  content: "";
  width: 0;
  height: 0;
  margin-left: 6px;
  border-top: 17px solid transparent;
  border-bottom: 17px solid transparent;
  border-left: 25px solid currentColor;
}

.howto-play:active {
  transform: translate(-50%, calc(-50% + 1px));
}

.howto-caption {
  text-align: center;
}

#board {
  display: block;
  width: 100%;
  height: 100dvh;
  background: var(--felt);
  touch-action: none;
}

.hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 8px 10px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: rgba(14, 21, 18, 0.76);
  backdrop-filter: blur(14px);
  z-index: 3;
}

.hud div {
  display: grid;
  gap: 2px;
}

.hud strong {
  color: var(--brass);
  letter-spacing: 0.08em;
}

.hud span {
  color: var(--muted);
  font-size: 13px;
}

.controls {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: rgba(14, 21, 18, 0.82);
  backdrop-filter: blur(14px);
  z-index: 4;
}

.controls button {
  padding: 0 8px;
}

.controls.jigsaw-hold-controls {
  left: 0;
  right: 0;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: block;
  width: auto;
  height: 60px;
  padding: 0 16px;
  border: 0;
  border-radius: 0;
  background: transparent;
  backdrop-filter: none;
  pointer-events: none;
}

.controls.jigsaw-hold-controls button {
  pointer-events: auto;
}

.jigsaw-picture-button {
  position: absolute;
  left: 50%;
  bottom: 6px;
  min-height: 46px;
  transform: translateX(-50%);
}

.jigsaw-picture-button:active {
  transform: translate(-50%, 1px);
}

.jigsaw-rotate-button {
  position: absolute;
  bottom: 2px;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  min-height: 56px;
  padding: 0;
  border-color: rgba(255, 227, 157, 0.6);
  border-radius: 999px;
  background: var(--brass);
  color: var(--brass-dark);
  font-size: 31px;
  font-weight: 500;
  line-height: 1;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.38);
}

.jigsaw-rotate-left {
  left: max(16px, env(safe-area-inset-left));
}

.jigsaw-rotate-right {
  right: max(16px, env(safe-area-inset-right));
}

.toast {
  position: fixed;
  top: 78px;
  left: 50%;
  max-width: calc(100vw - 28px);
  transform: translateX(-50%);
  padding: 9px 12px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--text);
  z-index: 5;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 6, 5, 0.68);
  overflow: hidden;
  z-index: 10;
}

.modal.solved-modal::before {
  content: "";
  position: absolute;
  inset: -28px;
  background-image: var(--modal-image);
  background-position: center;
  background-size: cover;
  filter: blur(18px);
  opacity: 0.38;
  transform: scale(1.04);
}

.modal-body {
  position: relative;
  width: min(420px, 100%);
  padding: 24px 22px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: rgba(18, 24, 20, 0.92);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
  text-align: center;
}

.modal-body h2 {
  font-family: var(--serif);
  font-size: clamp(30px, 9vw, 48px);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.01em;
}

.code-modal .modal-body h2 {
  color: var(--brass);
  font-family: var(--sans);
  letter-spacing: 0.14em;
}

.modal-body p {
  margin: 10px 0 18px;
  white-space: pre-line;
}

.hidden {
  display: none !important;
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform:
      translate3d(calc(-50% + var(--x)), calc(-50% + 24px), var(--z))
      rotateY(var(--rotate))
      scale(var(--scale));
  }
  to {
    opacity: var(--opacity);
    transform:
      translate3d(calc(-50% + var(--x)), -50%, var(--z))
      rotateY(var(--rotate))
      scale(var(--scale));
  }
}

.lobby.is-entering .carousel-card.is-visible {
  animation: cardIn 500ms ease-out both;
  animation-delay: var(--enter-delay);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  33% { transform: translateX(-5px); }
  66% { transform: translateX(5px); }
}

@media (min-width: 760px) {
  #listScreen {
    padding-inline: 30px;
  }

  .lobby {
    grid-template-rows: auto minmax(390px, 1fr) auto;
    padding-top: 34px;
  }

  .picture-carousel {
    height: min(52dvh, 490px);
    min-height: 390px;
  }

  .carousel-card {
    width: clamp(230px, 28vw, 294px);
  }

  .tap-zone {
    display: block;
  }

  .lobby-detail {
    width: 430px;
  }

  .picture-title {
    min-height: 72px;
    font-size: 38px;
  }

  .controls {
    left: 50%;
    right: auto;
    width: 620px;
    transform: translateX(-50%);
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .hud {
    left: 50%;
    right: auto;
    width: min(760px, calc(100vw - 24px));
    transform: translateX(-50%);
  }

  .controls.jigsaw-hold-controls {
    left: 0;
    right: 0;
    width: auto;
    transform: none;
    grid-template-columns: none;
  }
}

@media (min-width: 1100px) {
  .lobby-topbar h1 {
    font-size: 29px;
  }

  .picture-title {
    font-size: 42px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  .carousel-card,
  .picture-title,
  .sheet-backdrop,
  .join-sheet {
    transition-duration: 120ms !important;
    transition-timing-function: linear !important;
  }

  .lobby.is-entering .carousel-card.is-visible {
    animation-duration: 120ms;
    animation-timing-function: linear;
  }
}
