/* The Grid — daily Poker Squares (views/the-grid.pug, static/js/the-grid.js).
   Mobile first: at 375x667 the header, next card, grid and status line fit
   without scrolling; the board shrinks with the viewport height so short
   and desktop screens fit too. */

body.grid-page {
  gap: 0.55rem;
  padding-top: calc(0.7rem + env(safe-area-inset-top));
}

.grid-page .brand {
  width: min(30rem, 100%);
  gap: 0.55rem;
  margin: 0;
}
.grid-page .brand img {
  height: 32px;
}
.grid-page .brand .wordmark {
  font-size: 1.15rem;
}
.grid-page .brand .tagline {
  font-size: 0.52rem;
  margin-top: 0.2rem;
}

.grid-wrap {
  width: 100%;
  max-width: 30rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.grid-head {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
}
.grid-title {
  font-family: var(--serif);
  font-size: 1.7rem;
  line-height: 1.1;
  color: var(--cream);
  margin: 0;
}
.grid-badge {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted-2);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---------- playing cards ---------- */
/* Corner radius matches the geometry baked into the card art. */
.cc {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-family: var(--mono);
  font-weight: 700;
  background: linear-gradient(180deg, #faf5e8 0%, #ece1c8 100%);
  color: #232a24;
  border-radius: 8% / 6%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.cc.red {
  color: #c2404e;
}

/* ---------- next card ---------- */
.grid-next {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-height: 4.6rem;
}
.next-card {
  width: 3.3rem;
  height: 4.6rem;
  font-size: 1.35rem;
  gap: 3px;
  flex-shrink: 0;
}
.next-card.fresh {
  animation: grid-deal 0.3s ease both;
}
.next-main {
  flex: 1;
  min-width: 0;
}
.grid-next .grid-btn {
  flex-shrink: 0;
  min-width: 5.5rem;
}
.next-count {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}
.next-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.2rem 0 0;
  line-height: 1.35;
}
.grid-btn {
  padding: 0.65rem 1.1rem;
  border-radius: 11px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--cream);
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
.grid-btn.primary {
  background: var(--gold-grad);
  border: none;
  color: #241a08;
  font-weight: 800;
}
.grid-btn:disabled {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted-2);
  cursor: default;
}
.final-total {
  font-family: var(--serif);
  font-size: 1.6rem;
  color: var(--cream);
  line-height: 1.1;
}
.final-rating {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  margin-top: 0.2rem;
}

/* simple.css styles every <button> as a full-width gold CTA; none of
   that applies to the board or these buttons. */
.grid-page .grid-btn,
.grid-board button {
  width: auto;
  margin: 0;
  box-shadow: none;
  letter-spacing: normal;
}
.grid-page .grid-btn:hover,
.grid-board button:hover,
.grid-board button:active {
  transform: none;
  filter: none;
}
.grid-board .slot.filled,
.grid-board .slot.ghost {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
/* The ghost's face is dimmed (a dark wash over the card, brightness on
   the pips) rather than filtering the whole button, so the gold outline
   stays bright. */
.grid-board .slot.ghost,
.grid-board .slot.ghost:hover,
.grid-board .slot.ghost:focus {
  filter: none;
  background: linear-gradient(rgba(10, 20, 14, 0.4), rgba(10, 20, 14, 0.4)),
    linear-gradient(180deg, #faf5e8 0%, #ece1c8 100%);
  outline: 2.5px solid var(--gold);
  outline-offset: 1px;
}
.grid-board .slot.ghost > span {
  filter: brightness(0.62);
}

/* ---------- the board ---------- */
/* Five card columns plus a narrow score column; five card rows plus a
   score row. Width is capped by the viewport height so the whole board
   always fits on screen with the header and next card above it. */
.grid-board {
  --score-w: 2.35rem;
  --gap: 4px;
  /* Board height is about 1.36 x (width - 3.6rem) + 2.8rem; the rest of
     the play screen (header, next card, status) takes about 13rem. */
  width: min(100%, calc(73.5vh - 9rem));
  width: min(100%, calc(73.5dvh - 9rem));
  /* Keeps slots about 40px wide on a landscape phone, where the height
     cap above would make them too small to tap; that layout scrolls. */
  min-width: 16.5rem;
  align-self: center;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) var(--score-w);
  gap: var(--gap);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.grid-row {
  display: contents;
}

.slot {
  aspect-ratio: 5 / 6.8;
  min-width: 0;
  padding: 0;
  margin: 0;
  border-radius: 8% / 6%;
  font-size: clamp(0.85rem, 4.6vw, 1.2rem);
  gap: 2px;
  cursor: pointer;
  position: relative;
  touch-action: manipulation;
}
.slot .cc-suit {
  font-size: 1.05em;
}
.slot.empty {
  background: var(--inset);
  border: 1.5px dashed var(--line-strong);
  box-shadow: none;
  color: transparent;
}
.slot.empty:hover {
  border-color: var(--gold);
}
.slot.filled {
  border: none;
  cursor: default;
}
.slot.ghost {
  border: none;
  animation: grid-ghost 1.4s ease-in-out infinite;
}
.slot.placed {
  animation: grid-place 0.25s ease both;
}
.slot:focus {
  outline: none;
}
.slot:focus-visible {
  outline: 2.5px solid var(--cream);
  outline-offset: 1px;
}
.slot.ghost:focus-visible {
  outline-color: var(--gold);
}
/* A just-finished line pulses in its tier colour. */
.slot.flash {
  animation: grid-flash 1s ease both;
}
/* The finished board matches the share picture: a card some hand used
   keeps full brightness with a thin ring in that hand's tier colour, a
   card that scored nothing steps back (brightness, never opacity). */
.grid-board.done .slot.filled {
  cursor: default;
  transition: filter 0.45s ease, box-shadow 0.45s ease;
}
.grid-board.done .slot.scored {
  box-shadow: 0 0 0 2px var(--tier), 0 2px 6px rgba(0, 0, 0, 0.35);
}
.grid-board.done .slot.dead {
  filter: brightness(0.5);
  box-shadow: none;
}

.score {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted-2);
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(0.72rem, 3.4vw, 0.85rem);
  border-radius: 7px;
  cursor: default;
}
.score.row-score {
  justify-content: flex-start;
  padding-left: 2px;
  transform-origin: left center;
}
.score.col-score {
  height: 1.55rem;
}
.score.has {
  cursor: pointer;
}
.score.has:focus-visible {
  outline: 2px solid var(--cream);
}
.score.flash {
  animation: grid-pop 0.9s ease both;
}
.score.corner {
  justify-content: flex-start;
  padding-left: 2px;
  color: var(--gold);
  font-size: clamp(0.8rem, 3.6vw, 0.95rem);
}
.score.sel {
  background: var(--gold-soft);
}

/* Tier colours for the board and the payout table: none, then pairs up to
   quads and better. */
.t0 { --tier: #8a9483; }
.t1 { --tier: #e8cf5a; }
.t2 { --tier: #ec9a4c; }
.t3 { --tier: #54cf8c; }
.t4 { --tier: #5ea8ec; }
.t5 { --tier: #b682ea; }
.score.has {
  color: var(--tier);
}
.score.has.t0 {
  font-weight: 400;
}

.grid-status {
  margin: 0;
  min-height: 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}
.grid-status b {
  color: var(--cream);
}
.grid-status .tier {
  color: var(--tier);
  font-weight: 700;
}

/* ---------- result ---------- */
.grid-result {
  width: 100%;
  text-align: center;
  scroll-margin-top: 1rem;
  animation: grid-slide 0.4s ease both;
}
.grid-result h2 {
  font-family: var(--serif);
  font-size: 1.5rem;
  color: var(--cream);
  margin: 0 0 0.2rem;
}
.result-rating {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 0.8rem;
}
.result-stats {
  display: flex;
  justify-content: center;
  gap: 1.4rem;
  margin: 0 0 0.9rem;
}
.result-stats div {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.result-stats b {
  font-family: var(--serif);
  font-size: 1.35rem;
  color: var(--cream);
  font-weight: 400;
}
.result-stats span {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.result-next {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 0.9rem;
}
.result-next b {
  font-family: var(--mono);
  color: var(--cream);
}
.result-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
}

/* ---------- share dialog ---------- */
/* Built by the-grid.js on the first "Share result". Sized so the whole
   thing fits a 375x667 phone; anything taller scrolls inside it. */
.share-dialog {
  width: min(26rem, calc(100vw - 2rem));
  max-width: none;
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--felt-top) 0%, var(--felt-bot) 100%);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.share-dialog[open] {
  animation: share-in 0.18s ease both;
}
.share-dialog::backdrop {
  background: rgba(4, 10, 7, 0.72);
}
.share-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.9rem 1rem 1rem;
}
.share-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}
.share-head h2 {
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 400;
  line-height: 1.15;
  color: var(--cream);
  margin: 0;
}
.grid-page .share-close {
  flex-shrink: 0;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border-radius: 50%;
  font-size: 1.35rem;
  font-weight: 400;
  line-height: 1;
}
/* Square / Story: a two-way segmented switch. */
.share-formats {
  display: flex;
  align-self: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--inset);
}
.grid-page .share-format {
  padding: 0.4rem 1.1rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
}
.grid-page .share-format[aria-pressed="true"] {
  background: var(--gold-soft);
  color: var(--gold);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.share-preview {
  display: flex;
  justify-content: center;
}
.share-preview img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 50vh;
  max-height: 50dvh;
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
}
/* Square: no taller than the width so the actions stay on screen. */
.share-dialog:not(.story) .share-preview img {
  max-height: min(50dvh, 22rem);
}
/* The main action spans the row; the rest share one row beneath it, even
   at 375px wide. */
.share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.grid-page .share-actions .grid-btn {
  flex: 1 1 0;
  min-width: 5.5rem;
  padding: 0.65rem 0.4rem;
  font-size: 0.85rem;
}
.grid-page .share-actions .primary {
  flex-basis: 100%;
  font-size: 0.95rem;
}
.share-note {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted);
  text-align: center;
}

/* ---------- how to play ---------- */
.grid-help {
  font-size: 0.9rem;
  color: var(--muted);
}
.grid-help summary {
  cursor: pointer;
  color: var(--gold);
  font-weight: 600;
}
.grid-rules {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  line-height: 1.45;
}
/* "Confirm each card": opt-in two-tap placement. */
.grid-toggle {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin: 0 0 0.9rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--cream);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
}
.grid-toggle input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 0.05rem 0 0;
  accent-color: var(--gold);
  cursor: pointer;
}
.grid-toggle-note {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
}
.grid-payouts {
  border-collapse: collapse;
  font-size: 0.85rem;
  width: 100%;
  max-width: 18rem;
}
.grid-payouts td {
  padding: 0.2rem 0;
  border-top: 1px solid var(--line);
}
.grid-payouts td:last-child {
  text-align: right;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--tier);
}

/* ---------- promo ---------- */
.promo {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-top: 0.6rem;
}
.promo img {
  height: 4rem;
  width: auto;
  flex-shrink: 0;
}
.promo-main {
  flex: 1;
  min-width: 0;
}
.promo-title {
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--cream);
}
.promo-text {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
  margin: 0.15rem 0 0;
}
.promo-try {
  display: inline-block;
  margin-top: 0.4rem;
  color: var(--gold);
  font-weight: 700;
  font-size: 0.82rem;
  text-decoration: none;
}
.promo-try::after {
  content: " →";
}
/* After a finished grid: the same offer, under the result. */
.result-try {
  margin: 0.9rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  text-align: center;
}
.result-try a {
  color: var(--gold);
  font-weight: 700;
  text-decoration: none;
}
.promo-btn {
  flex-shrink: 0;
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  background: var(--gold-grad);
  color: #241a08;
  font-weight: 800;
  font-size: 0.82rem;
  text-decoration: none;
  white-space: nowrap;
}

@keyframes grid-deal {
  0% { transform: translateY(-8px) rotate(-4deg); filter: brightness(0.7); }
  100% { transform: none; filter: none; }
}
@keyframes grid-place {
  0% { transform: scale(0.9); }
  100% { transform: none; }
}
@keyframes grid-ghost {
  0%, 100% { outline-color: var(--gold); }
  50% { outline-color: #f6dca0; }
}
@keyframes grid-flash {
  0% { box-shadow: 0 0 0 0 var(--tier); transform: none; }
  25% { box-shadow: 0 0 0 3px var(--tier), 0 0 14px var(--tier); transform: scale(1.05); }
  100% { box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35); transform: none; }
}
@keyframes grid-pop {
  0% { transform: scale(0.4); }
  40% { transform: scale(1.35); }
  100% { transform: none; }
}
@keyframes share-in {
  0% { opacity: 0; transform: translateY(8px) scale(0.98); }
  100% { opacity: 1; transform: none; }
}
@keyframes grid-slide {
  0% { opacity: 0; transform: translateY(-6px); }
  100% { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .slot.ghost,
  .slot.flash,
  .slot.placed,
  .score.flash,
  .next-card.fresh,
  .grid-result,
  .share-dialog[open] {
    animation: none;
  }
  .grid-board.done .slot.filled {
    transition: none;
  }
}
