/* Daily Puzzle: learn by doing. The board answers; the rail only keeps the record. */

.puzzle-day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 6px;
}

.puzzle-day-kicker {
  margin: 0 0 4px;
  color: #f1c75b;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.puzzle-day-head h1 {
  margin: 0;
  color: #f7f1e6;
  font-size: clamp(1.5rem, 3.2vw, 2.1rem);
  font-weight: 850;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.puzzle-prize {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  color: rgba(247, 241, 230, 0.72);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
}

.puzzle-prize-tile {
  width: 46px;
  aspect-ratio: 3 / 4;
  border-radius: 7px;
  overflow: hidden;
  box-shadow: 0 0 0 2px rgba(241, 199, 91, 0.6), 0 6px 18px rgba(0, 0, 0, 0.45);
  filter: grayscale(0.85) brightness(0.7);
  transform: rotate(-4deg);
}

.puzzle-prize-tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.puzzle-live[data-phase="solved"] ~ * .puzzle-prize-tile,
body:has(.puzzle-live[data-phase="solved"]) .puzzle-prize-tile {
  filter: none;
  animation: puzzle-prize-win 700ms cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

@keyframes puzzle-prize-win {
  from { transform: rotate(-4deg) scale(0.6); }
  to { transform: rotate(-4deg) scale(1); }
}

/* The rail: a row of controls, then the record. */
.puzzle-live .puzzle-rail {
  gap: 0.6rem;
}

.puzzle-live .puzzle-foot {
  flex-direction: row;
  margin-top: 0;
}

.puzzle-live .puzzle-hint,
.puzzle-live .puzzle-next,
.puzzle-live .puzzle-restart {
  width: auto;
  flex: 1 1 0;
  min-height: 2.6rem;
  transition: transform 120ms ease, background 120ms ease;
}

.puzzle-live .puzzle-hint {
  background: #f1c75b;
  color: #2b1d05;
}

.puzzle-live .puzzle-hint:disabled {
  background: #2a2622;
  color: rgba(244, 239, 228, 0.4);
  cursor: default;
}

.puzzle-live .puzzle-hint:not(:disabled):hover,
.puzzle-live .puzzle-restart:hover {
  transform: translateY(-1px);
}

.puzzle-live .puzzle-step {
  margin: 0.2rem 0 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.puzzle-live .puzzle-bubble {
  max-width: 22rem;
  padding: 0.5rem 0.7rem;
  font-size: 0.88rem;
}

/* The board invites a tap. */
.puzzle-live[data-phase="choose"] #south-tiles .mj-tile[data-legal="true"] .mj-tile-body {
  animation: puzzle-breathe 2.4s ease-in-out infinite;
}

.puzzle-live[data-phase="choose"] #south-tiles .mj-tile[data-legal="true"]:nth-child(2n) .mj-tile-body { animation-delay: 0.3s; }
.puzzle-live[data-phase="choose"] #south-tiles .mj-tile[data-legal="true"]:nth-child(3n) .mj-tile-body { animation-delay: 0.6s; }

.puzzle-live[data-phase="choose"] #south-tiles .mj-tile[data-legal="true"]:hover .mj-tile-body {
  animation: none;
  transform: translateY(-14%);
}

@keyframes puzzle-breathe {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4%); }
}

.puzzle-live[data-phase="opening"] .action-stage {
  cursor: pointer;
  pointer-events: auto;
}

/* A wrong tile shakes and is crossed out; it can be tried again. */
.puzzle-live .mj-tile.is-missed {
  position: relative;
}

.puzzle-live .mj-tile.is-missed .mj-tile-body {
  animation: puzzle-shake 420ms cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
  filter: saturate(0.4) brightness(0.8);
}

.puzzle-live .mj-tile.is-missed::after {
  content: "✕";
  position: absolute;
  top: -0.55em;
  right: -0.35em;
  display: grid;
  place-items: center;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  background: #e0533d;
  color: #fff;
  font-size: clamp(10px, 1.6cqw, 15px);
  font-weight: 900;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  animation: puzzle-stamp 320ms cubic-bezier(0.3, 1.6, 0.5, 1) both;
  pointer-events: none;
}

@keyframes puzzle-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px) rotate(-3deg); }
  40%, 60% { transform: translateX(6px) rotate(3deg); }
}

@keyframes puzzle-stamp {
  from { transform: scale(2.2) rotate(-20deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

/* The hint glows; the right tile lifts out in gold. */
.puzzle-live .mj-tile.is-hinted .mj-tile-body {
  outline: 3px solid #f1c75b;
  outline-offset: 2px;
  animation: puzzle-hint-glow 1.2s ease-in-out infinite;
}

@keyframes puzzle-hint-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(241, 199, 91, 0.0); transform: translateY(-6%); }
  50% { box-shadow: 0 0 22px 6px rgba(241, 199, 91, 0.55); transform: translateY(-12%); }
}

.puzzle-live .mj-tile.is-accepted {
  position: relative;
  z-index: 3;
}

.puzzle-live .mj-tile.is-accepted .mj-tile-body {
  outline: 3px solid #f1c75b;
  outline-offset: 2px;
  animation: puzzle-lift 640ms cubic-bezier(0.3, 1.6, 0.5, 1) both;
  box-shadow: 0 0 28px 8px rgba(241, 199, 91, 0.6);
}

.puzzle-live .mj-tile.is-accepted::after {
  content: "✓";
  position: absolute;
  top: -0.6em;
  right: -0.4em;
  display: grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  border-radius: 50%;
  background: linear-gradient(180deg, #f8d779, #d9a93a);
  color: #3d2a08;
  font-size: clamp(11px, 1.7cqw, 16px);
  font-weight: 900;
  box-shadow: 0 2px 0 #9a6a10, 0 4px 10px rgba(0, 0, 0, 0.4);
  animation: puzzle-stamp 360ms 200ms cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

@keyframes puzzle-lift {
  0% { transform: translateY(0) scale(1); }
  60% { transform: translateY(-34%) scale(1.18); }
  100% { transform: translateY(-24%) scale(1.1); }
}

/* The stage speaks in a word or two, and bumps when it does. */
.puzzle-live .action-stage.is-bumped {
  animation: puzzle-bump 380ms cubic-bezier(0.3, 1.6, 0.5, 1);
}

.puzzle-live .action-stage[data-tone="incorrect"] .action-stage-name { color: #ff9a86; }
.puzzle-live .action-stage[data-tone="correct"] .action-stage-name { color: #f8d779; font-size: 1.4em; }
.puzzle-live .action-stage[data-tone="hint"] .action-stage-name { color: #f1c75b; }

@keyframes puzzle-bump {
  0% { transform: scale(0.85); }
  100% { transform: scale(1); }
}

/* Solved: a card over the board with the day's tile. */
.puzzle-live .play-stage {
  position: relative;
}

.puzzle-win {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(circle at 50% 45%, rgba(18, 40, 30, 0.55), rgba(8, 14, 11, 0.86));
  backdrop-filter: blur(2px);
}

.puzzle-win[hidden] {
  display: none;
}

.puzzle-win-card {
  position: relative;
  width: min(360px, 100%);
  padding: 26px 22px 18px;
  border-radius: 22px;
  background: linear-gradient(180deg, #fbf5e8, #f1e6cf);
  color: #2b1d0d;
  text-align: center;
  box-shadow: 0 2px 0 #c9b48a, 0 30px 60px rgba(0, 0, 0, 0.5);
  /* The rays turn inside the card, behind its contents, and stop at its edge. */
  isolation: isolate;
  overflow: hidden;
}

.puzzle-win.is-in .puzzle-win-card {
  animation: puzzle-card-in 520ms cubic-bezier(0.3, 1.5, 0.5, 1) both;
}

.puzzle-win-card::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 22%;
  width: 640px;
  height: 640px;
  margin: -320px 0 0 -320px;
  z-index: -1;
  border-radius: 50%;
  background: repeating-conic-gradient(rgba(248, 215, 121, 0.28) 0 9deg, transparent 9deg 18deg);
  mask-image: radial-gradient(circle, #000 0 28%, transparent 62%);
  animation: puzzle-spin 18s linear infinite;
  pointer-events: none;
}

@keyframes puzzle-card-in {
  from { transform: translateY(30px) scale(0.85); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes puzzle-spin {
  to { transform: rotate(360deg); }
}

.puzzle-win-stamp {
  display: inline-block;
  margin: 0;
  padding: 4px 18px 6px;
  border-radius: 12px;
  background: linear-gradient(180deg, #f8d779, #d9a93a);
  color: #3d2a08;
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  box-shadow: 0 3px 0 #9a6a10, 0 8px 20px rgba(154, 106, 16, 0.35);
  transform: rotate(-3deg);
}

.puzzle-win.is-in .puzzle-win-stamp {
  animation: puzzle-stamp 420ms 160ms cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

.puzzle-win-streak {
  margin: 12px 0 0;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #2f7a4a;
}

.puzzle-win-tile {
  width: 92px;
  margin: 14px auto 2px;
  aspect-ratio: 3 / 4;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 0 3px #f1c75b, 0 14px 28px rgba(0, 0, 0, 0.35);
}

.puzzle-win.is-in .puzzle-win-tile {
  animation: puzzle-flip 700ms 380ms cubic-bezier(0.3, 1.4, 0.5, 1) both;
}

.puzzle-win-tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@keyframes puzzle-flip {
  from { transform: perspective(500px) rotateY(180deg) scale(0.6); opacity: 0; }
  to { transform: perspective(500px) rotateY(0) scale(1); opacity: 1; }
}

.puzzle-win-why {
  margin: 12px 0 16px;
  font-size: 0.92rem;
  line-height: 1.35;
  color: #5a4a35;
}

.puzzle-win-actions {
  display: flex;
  gap: 8px;
}

.puzzle-win-share,
.puzzle-win-play {
  flex: 1 1 0;
  display: grid;
  place-items: center;
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.puzzle-win-share {
  background: #2f7a4a;
  color: #fff;
  box-shadow: 0 3px 0 #1d5432;
}

.puzzle-win-play {
  background: #2b1d0d;
  color: #fbf5e8;
  box-shadow: 0 3px 0 #000;
}

.puzzle-win-share:active,
.puzzle-win-play:active {
  transform: translateY(2px);
  box-shadow: none;
}

.puzzle-win-look {
  margin-top: 10px;
  border: 0;
  background: none;
  color: #7a6748;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .puzzle-live *,
  .puzzle-win *,
  .puzzle-win-card::before {
    animation: none !important;
  }
}

@media (max-width: 600px) {
  .puzzle-day-head h1 { font-size: 1.35rem; }
  .puzzle-prize figcaption { display: none; }
}

/* Wide screens: the board on the left, the chat beside it on the right. */
@media (min-width: 1100px) {
  .puzzle-live.play-app {
    grid-template-columns: minmax(0, 1fr) minmax(17rem, 22rem);
    grid-template-rows: auto;
    grid-template-areas: "stage rail";
    gap: 1.25rem 3.25rem;
    align-items: start;
  }

  .puzzle-live .play-stage {
    width: 100%;
    margin: 0;
    max-height: calc(100svh - 9rem);
  }

  .puzzle-live .play-meta.puzzle-rail {
    position: sticky;
    top: 1rem;
    /* Start below the seat names so East never runs under the chat. */
    margin-top: 4.25rem;
    max-height: calc(100svh - 9rem);
    padding: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    background: linear-gradient(180deg, #1f2a23, #18201b);
  }

  .puzzle-live .puzzle-timeline {
    flex: 1 1 auto;
  }

  .puzzle-live .puzzle-bubble {
    max-width: 100%;
  }
}

/* The table's line wraps inside the felt instead of running off it. */
.puzzle-live .action-stage {
  max-width: min(80%, 19rem);
}

.puzzle-live .action-stage-who,
.puzzle-live .action-stage[data-state="decision"] .action-stage-who {
  align-items: flex-start;
  width: min(72cqw, 19rem);
  max-width: 19rem;
}

.puzzle-live .action-stage-copy {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
  white-space: normal;
  text-align: left;
  text-wrap: balance;
}

.puzzle-live .action-stage-text {
  font-size: 0.86em;
  line-height: 1.3;
  white-space: normal;
}

/* Phones and tablets: the chat is part of the page, not its own scroll box,
   so a swipe anywhere scrolls the page. */
@media (max-width: 1099px) {
  .puzzle-live .play-meta.puzzle-rail,
  .puzzle-live .play-meta {
    max-height: none;
    overflow: visible;
  }

  .puzzle-live .puzzle-timeline {
    max-height: none;
    overflow: visible;
  }
}

/* The rail as a scorecard: Goal, Your tries, Hint, Why it works. */
.puzzle-live .puzzle-step {
  display: none;
}

.puzzle-live .puzzle-timeline {
  gap: 0.6rem;
}

.puzzle-live .puzzle-panel {
  display: grid;
  gap: 0.4rem;
  padding: 0.75rem 0.85rem;
  border-radius: 0.9rem;
  background: rgba(255, 255, 255, 0.05);
  animation: puzzle-panel-in 320ms cubic-bezier(0.3, 1.4, 0.5, 1) both;
}

@keyframes puzzle-panel-in {
  from { transform: translateY(8px) scale(0.97); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.puzzle-live .puzzle-panel-label {
  margin: 0;
  color: rgba(244, 239, 228, 0.55);
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.puzzle-live .puzzle-panel p:not(.puzzle-panel-label) {
  margin: 0;
  color: #f4efe4;
  font-size: 0.92rem;
  line-height: 1.35;
}

.puzzle-live .puzzle-panel-goal {
  font-size: 1.02rem !important;
  font-weight: 800;
}

.puzzle-live .puzzle-tries {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 2.4rem;
  align-items: center;
}

.puzzle-live .puzzle-tries-empty {
  color: rgba(244, 239, 228, 0.5);
  font-size: 0.85rem;
}

.puzzle-live .puzzle-try {
  position: relative;
  display: inline-grid;
  place-items: center;
  animation: puzzle-try-in 360ms cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

@keyframes puzzle-try-in {
  from { transform: translateY(-10px) scale(0.6) rotate(-8deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.puzzle-live .puzzle-try .mj-tile {
  width: 1.9rem;
}

.puzzle-live .puzzle-try.is-wrong .mj-tile {
  filter: saturate(0.4) brightness(0.8);
}

.puzzle-live .puzzle-try-word {
  padding: 0.35rem 0.6rem;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.82rem;
  font-weight: 800;
}

.puzzle-live .puzzle-try-mark {
  position: absolute;
  top: -0.45rem;
  right: -0.45rem;
  display: grid;
  place-items: center;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: #e0533d;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 900;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
}

.puzzle-live .puzzle-try.is-right .puzzle-try-mark {
  background: linear-gradient(180deg, #f8d779, #d9a93a);
  color: #3d2a08;
}

.puzzle-live .puzzle-panel.is-hint {
  background: rgba(241, 199, 91, 0.12);
  box-shadow: inset 0 0 0 1px rgba(241, 199, 91, 0.35);
}

.puzzle-live .puzzle-panel.is-hint .puzzle-panel-label {
  color: #f1c75b;
}

.puzzle-live .puzzle-panel.is-why {
  background: rgba(79, 179, 108, 0.14);
  box-shadow: inset 0 0 0 1px rgba(79, 179, 108, 0.4);
}

.puzzle-live .puzzle-panel.is-why .puzzle-panel-label {
  color: #7fd39a;
}

/* Once a board is passed, every tile shows its grade: a gold star on the best, a green tick on a
   good one, and the misses dim back, so the whole decision reads at a glance. */
.puzzle-live .mj-tile.is-grade-best,
.puzzle-live .mj-tile.is-grade-good {
  position: relative;
}

.puzzle-live .mj-tile.is-grade-best::before,
.puzzle-live .mj-tile.is-grade-good::before {
  position: absolute;
  top: -0.55em;
  left: -0.35em;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 1.35em;
  height: 1.35em;
  border-radius: 50%;
  font-size: clamp(10px, 1.5cqw, 14px);
  font-weight: 900;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  animation: puzzle-stamp 320ms 260ms cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

.puzzle-live .mj-tile.is-grade-best::before {
  content: "★";
  background: linear-gradient(180deg, #f8d779, #d9a93a);
  color: #3d2a08;
}

.puzzle-live .mj-tile.is-grade-good::before {
  content: "✓";
  background: linear-gradient(180deg, #7fd49a, #3f9f63);
  color: #0f3a1f;
}

.puzzle-live .mj-tile.is-grade-miss .mj-tile-body {
  filter: saturate(0.55) brightness(0.82);
  transition: filter 300ms ease;
}

.puzzle-live .puzzle-panel-scale {
  margin-top: 0.35rem;
  color: rgba(244, 239, 228, 0.6);
  font-size: 0.78rem;
  font-weight: 700;
}

.puzzle-live .puzzle-try.is-good .puzzle-try-mark,
.puzzle-live .puzzle-try.is-right:not(.is-best) .puzzle-try-mark {
  background: linear-gradient(180deg, #7fd49a, #3f9f63);
  color: #0f3a1f;
}

/* The Daily Puzzle by email, on the solved card (puzzle_email.js). */
.puzzle-win .puzzle-email {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
  font-size: 0.88rem;
  color: #5a4a35;
}

.puzzle-win .puzzle-email[hidden] {
  display: none;
}

.puzzle-win .puzzle-email p {
  margin: 0;
}

.puzzle-email-toggle {
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  background: #36905b;
  color: #fffaf0;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.puzzle-email.is-on .puzzle-email-toggle {
  background: transparent;
  color: inherit;
  box-shadow: inset 0 0 0 1px rgba(43, 29, 13, 0.24);
}

/* Island Card boards: Pick your hand offers hands on the card as chips; Chase it names its hand. */
.action-chip.puzzle-pick {
  display: grid;
  gap: 2px;
  justify-items: start;
  text-align: left;
}

.action-chip.puzzle-pick small {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  opacity: 0.75;
}

.puzzle-panel-target {
  margin: 4px 0 0;
  font-weight: 800;
  color: #a8436a;
}

/* Four hands do not fit side by side on the table: stack them, centred under the stage. */
.action-stage[data-state="decision"] .action-stage-actions:has(.puzzle-pick) {
  flex-direction: column;
  align-items: stretch;
  width: min(20rem, calc(100vw - 48px));
  gap: 6px;
}

.action-chip.puzzle-pick small {
  white-space: normal;
  word-break: break-word;
}
