:root {
  /* 4x3 & NYT Games Canvas + Ink */
  --bg-cream: #f2f0e8;
  --card-white: #ffffff;
  --card-border: #dad6ca;
  --ink-black: #1a1a1a;
  --ink-body: #4a4843;
  --ink-muted: #78756d;

  /* NYT Connections Default Tile */
  --tile-bg: #efefe6;
  --tile-border: #dfddd2;
  --tile-hover-border: #b8b5a8;

  /* COP31 Antalya Brand Accents (used for Happened tiles, pastel bars & promo art) */
  --cop-green: #64b680;
  --cop-green-fill: #e3f4e8;
  --cop-green-ink: #1b5230;
  --cop-blue: #3874b6;
  --cop-cobalt: #244c9e;
  --cop-blue-bar: #e5eef9;
  --cop-crimson: #d6362a;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Components set their own display values, which would otherwise beat [hidden] */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-cream);
  color: var(--ink-black);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page-wrap {
  min-height: 100vh;
  max-width: 1140px;
  margin: 0 auto;
  padding: 16px 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* =========================================================
   MOBILE TOP AD BANNER (Hidden on Desktop, Top on Mobile)
   ========================================================= */
.ad-mobile {
  display: none;
  width: 100%;
  max-width: 620px;
  margin-bottom: 12px;
}

.ad-mobile-inner {
  background: #e7eef6;
  border: 1px solid #d3cfe0;
  border-radius: 12px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-black);
}

.ad-mobile-text {
  font-weight: 500;
}

/* "Buy me a coffee" pill, cobalt to match the Results button */
.coffee-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  padding: 9px 14px;
  border-radius: 999px;
  background-color: var(--cop-cobalt);
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 700;
  text-decoration: none;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.coffee-btn:hover {
  background-color: #183e9a;
}

.coffee-btn:active {
  transform: scale(0.98);
}

.coffee-btn-small {
  align-self: auto;
  padding: 5px 12px;
  font-size: 11.5px;
}

/* =========================================================
   4x3-STYLE HEADER: LOGO + UNBOXED SUBTITLE ON CREAM CANVAS
   ========================================================= */
.game-header {
  max-width: 580px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 12px;
}

.game-logo {
  height: 92px;
  width: auto;
  max-width: min(92vw, 460px);
  object-fit: contain;
  margin-bottom: 6px;
  user-select: none;
}

.game-subtitle {
  margin: 0 0 4px;
  font-size: 13.5px;
  line-height: 1.45;
  font-weight: 400;
  color: var(--ink-body);
  max-width: 540px;
}

/* =========================================================
   CENTER STAGE: WHITE CARD + FLOATING RIGHT AD PANEL
   ========================================================= */
.stage-row {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.game-card {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 620px;
  background-color: var(--card-white);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 20px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* COP31 brand stripe: cobalt, cerulean, emerald, tulip crimson */
.game-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(
    90deg,
    var(--cop-cobalt) 0 30%,
    var(--cop-blue) 30% 60%,
    var(--cop-green) 60% 90%,
    var(--cop-crimson) 90% 100%
  );
}

/* Top Bar Inside Card: NYT / 4x3 Pill Buttons + Dot Counter */
.card-top-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.action-pills {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.nyt-btn {
  appearance: none;
  border-radius: 8px;
  padding: 8px 20px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.1s ease, background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.nyt-btn:active {
  transform: scale(0.98);
}

/* Solid Black Pill Button (exact match to 4x3 "Results" & NYT "Share Your Results") */
.nyt-btn-solid {
  background-color: var(--cop-cobalt);
  color: #ffffff;
  border: 1.5px solid var(--cop-cobalt);
}

.nyt-btn-solid:hover {
  background-color: #183e9a;
  border-color: #183e9a;
}

.nyt-btn-solid[aria-pressed='true'] {
  background-color: #2f7d4a;
  border-color: #2f7d4a;
  color: #ffffff;
}

/* Outlined Black Pill Button (exact match to 4x3 "<- Back" & NYT secondary buttons) */
.nyt-btn-outline {
  background-color: #ffffff;
  color: var(--cop-cobalt);
  border: 1.5px solid var(--cop-cobalt);
}

.nyt-btn-outline:hover {
  background-color: var(--cop-blue-bar);
}

/* =========================================================
   4x3-STYLE PASTEL CATEGORY BAR FOR THE 75-DIGIT SEED
   ========================================================= */
.seed-strip-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.seed-strip {
  width: 100%;
  background-color: var(--cop-blue-bar);
  border-radius: 8px;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.seed-strip-tag {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cop-blue);
  white-space: nowrap;
  user-select: none;
}

.seed-strip-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  padding: 3px 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-black);
  border-bottom: 1px dashed rgba(56, 116, 182, 0.45);
}

.seed-strip-input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 4px;
  border-bottom-Style: solid;
  border-bottom-color: var(--cop-cobalt);
}

.seed-strip-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.seed-chip-btn {
  appearance: none;
  background: rgba(255, 255, 255, 0.85);
  color: var(--cop-cobalt);
  border: 1px solid rgba(56, 116, 182, 0.3);
  border-radius: 999px;
  padding: 3px 9px;
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.seed-chip-btn:hover {
  background: #ffffff;
  border-color: var(--cop-cobalt);
}

.seed-feedback {
  margin: 0;
  font-size: 11.5px;
  font-weight: 600;
  text-align: center;
}

.seed-feedback:empty {
  display: none;
}

.seed-feedback.is-error {
  color: var(--cop-crimson);
}

.seed-feedback.is-success {
  color: var(--cop-green-ink);
}

/* Pastel Status Bar (when Results are revealed) */
.bingo-bars {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.bingo-bars[hidden] {
  display: none;
}

.bingo-bar {
  width: 100%;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.03em;
}

.bingo-bar.is-progress {
  background-color: var(--cop-blue-bar);
  color: var(--cop-cobalt);
}

.bingo-bar.is-win {
  background-color: var(--cop-green-fill);
  border: 1px solid var(--cop-green);
  color: var(--cop-green-ink);
}

/* =========================================================
   5x5 BINGO GRID & TILES (NYT Connections + 4x3 Feel)
   ========================================================= */
.bingo-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  perspective: 900px;
}

.bingo-tile {
  position: relative;
  min-height: 108px;
  background-color: var(--tile-bg);
  border: 1.5px solid var(--tile-border);
  border-radius: 12px;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: background-color 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}

.bingo-tile:hover {
  border-color: var(--cop-blue);
  background-color: #eef2f5;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(36, 76, 158, 0.08);
}

/* Placeholder tiles shown while the sheet is loading */
.bingo-tile.tile-skeleton {
  pointer-events: none;
  overflow: hidden;
  gap: 7px;
}

.bingo-tile.tile-skeleton:hover {
  border-color: var(--tile-border);
  background-color: var(--tile-bg);
  transform: none;
  box-shadow: none;
}

.skeleton-key,
.skeleton-line {
  display: block;
  border-radius: 999px;
  background: linear-gradient(100deg, #e4e1d4 30%, #f7f5ee 48%, #e4e1d4 66%);
  background-size: 220% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  animation-delay: calc(var(--i) * 45ms);
}

.skeleton-key {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 7px;
}

.skeleton-line {
  height: 9px;
  width: 74%;
}

.skeleton-line:nth-child(3) {
  width: 52%;
}

.skeleton-line:nth-child(4) {
  width: 38%;
}

.tile-skeleton:nth-child(odd) .skeleton-line:nth-child(2) {
  width: 86%;
}

.tile-skeleton:nth-child(3n) .skeleton-line:nth-child(3) {
  width: 40%;
}

@keyframes skeleton-shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -20% 0;
  }
}

.nyt-btn:disabled,
.seed-chip-btn:disabled,
.footer-link:disabled {
  opacity: 0.4;
  cursor: default;
}

.seed-strip-input:disabled {
  opacity: 0.55;
}

.bingo-tile.is-happened-revealed:hover {
  border-color: var(--cop-green-ink);
  background-color: var(--cop-green-fill);
}

.tile-key {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 9px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--ink-muted);
  opacity: 0.55;
  pointer-events: none;
}

.bingo-tile.is-happened-revealed .tile-key {
  color: var(--cop-green-ink);
}

.tile-title {
  margin: 0;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.24;
  color: inherit;
  letter-spacing: -0.01em;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Happened / Green Tile State (matches 4x3 REDSTONE/LAPIS + pastel card inspo) */
.bingo-tile.is-happened-revealed {
  background-color: var(--cop-green-fill);
  border-color: var(--cop-green);
}

.bingo-tile.is-happened-revealed {
  color: var(--cop-green-ink);
}

/* Winning 5-in-a-row line highlight */
.bingo-tile.is-bingo-line {
  border-width: 2px;
  border-color: var(--cop-green-ink);
  box-shadow: inset 0 0 0 1px var(--cop-green);
}

/* Bottom White Pill inside Green Tile (matches white pills on green card in reference #3) */
.tile-source-wrap {
  margin-top: 6px;
  display: flex;
  justify-content: center;
  width: 100%;
}

.tile-source-link,
.tile-source-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 9.5px;
  font-weight: 700;
  line-height: 1.15;
  background-color: #ffffff;
  color: var(--ink-black);
  border: 1px solid rgba(100, 182, 128, 0.55);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-source-badge {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  padding: 0;
  background: none;
  border: none;
  box-shadow: none;
  border-radius: 0;
  white-space: normal;
  font-size: 9.5px;
  font-weight: 500;
  font-style: italic;
  color: var(--cop-green-ink);
  opacity: 0.85;
}

.tile-source-link:hover {
  background-color: var(--ink-black);
  color: #ffffff;
  border-color: var(--ink-black);
}

/* =========================================================
   4x3-STYLE RIGHT-HAND FLOATING PROMO / AD CARD
   ========================================================= */
.ad-sidebar {
  position: absolute;
  left: calc(50% + 332px);
  top: 50%;
  transform: translateY(-50%);
  width: 205px;
}

.ad-promo-card {
  background: #e7eef6;
  border: 1px solid #d5cfe4;
  border-radius: 16px;
  padding: 18px 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 12px;
}

.ad-promo-art {
  align-self: center;
  width: 126px;
  background: linear-gradient(145deg, var(--cop-cobalt) 0%, var(--cop-blue) 52%, var(--cop-green) 100%);
  color: #ffffff;
  border-radius: 8px;
  padding: 16px 12px;
  box-shadow: 4px 6px 14px rgba(24, 62, 154, 0.22);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.ad-promo-eyebrow {
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  opacity: 0.9;
}

.ad-promo-Headline {
  font-family: var(--font-sans);
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}

.ad-promo-pill {
  font-size: 9.5px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.22);
  padding: 2px 8px;
  border-radius: 999px;
}

.card-credit {
  max-width: 540px;
  margin: 16px 0 0;
  text-align: center;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--ink-body);
}

.card-credit a {
  color: var(--cop-cobalt);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.card-credit a:hover {
  color: var(--cop-blue);
}

/* Error Banner */
.error-banner {
  background: #fdeceb;
  border: 1px solid var(--cop-crimson);
  color: #7f1d1d;
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  font-size: 13px;
}

.error-banner p {
  margin: 6px 0 10px;
}

/* =========================================================
   4x3-STYLE BOTTOM UNDERLINED LINKS
   ========================================================= */
.game-footer {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.footer-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 18px;
}

.footer-link {
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--ink-muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.footer-link:hover {
  color: var(--cop-cobalt);
}

.footer-credit {
  margin: 0;
  font-size: 11.5px;
  color: var(--ink-muted);
}

/* Share-results sheet, in the style of the NYT end-of-game dialog */
.share-dialog {
  position: relative;
  border: none;
  border-radius: 16px;
  padding: 28px 22px 16px;
  width: min(320px, calc(100vw - 32px));
  background: var(--card-white);
  color: var(--ink-black);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  text-align: center;
  overflow: hidden;
}

.share-dialog::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(
    90deg,
    var(--cop-cobalt) 0 30%,
    var(--cop-blue) 30% 60%,
    var(--cop-green) 60% 90%,
    var(--cop-crimson) 90% 100%
  );
}

.share-dialog::backdrop {
  background: rgba(26, 26, 26, 0.5);
}

.share-dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-sans);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.share-dialog-close:hover {
  background: var(--bg-cream);
  color: var(--ink-black);
}

.share-dialog-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.share-dialog-grid {
  margin: 14px 0 12px;
  font-family: var(--font-sans);
  font-size: 28px;
  line-height: 1.2;
  letter-spacing: 2px;
  white-space: pre;
}

.share-dialog-score {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 700;
}

.share-dialog-site {
  margin: 0 0 16px;
  font-size: 12px;
  color: var(--ink-muted);
}

.share-dialog-copy {
  width: 100%;
}

.share-dialog-note {
  min-height: 1.2em;
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--ink-muted);
}

/* =========================================================
   STAMP + GAME-FEEL ANIMATIONS
   ========================================================= */
.tile-stamp {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 3px solid var(--cop-green);
  color: var(--cop-green);
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.28;
  transform: translate(calc(-50% + var(--sx, 0px)), calc(-50% + var(--sy, 0px)))
    rotate(-14deg);
  pointer-events: none;
  z-index: 0;
}

.tile-title,
.tile-source-wrap {
  position: relative;
  z-index: 1;
}

.bingo-tile.is-dealing {
  animation: tile-deal 0.42s cubic-bezier(0.2, 0.8, 0.3, 1.15) backwards;
  animation-delay: calc(var(--i) * 22ms);
}

.bingo-tile.is-flipping {
  animation: tile-flip 0.6s linear backwards;
  animation-delay: calc(var(--r) * 140ms);
}

.bingo-tile.is-flipping .tile-source-wrap {
  animation: back-face 0.6s linear backwards;
  animation-delay: calc(var(--r) * 140ms);
}

.bingo-tile.is-flipping .tile-stamp {
  animation: stamp-in 0.32s cubic-bezier(0.3, 1.6, 0.5, 1) backwards;
  animation-delay: calc(var(--r) * 140ms + 0.55s);
}

.bingo-tile.is-flipping.is-celebrating {
  animation:
    tile-flip 0.6s linear backwards,
    tile-jump 0.45s ease-out;
  animation-delay: calc(var(--r) * 140ms), var(--jd);
}

.bingo-bar.is-popping {
  animation: win-pop 0.5s cubic-bezier(0.3, 1.5, 0.5, 1) backwards;
  animation-delay: var(--jd, 0.6s);
}

@keyframes tile-deal {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Rotates one way only: the plain face turns away edge-on, then the green
   face arrives from the opposite side (-90deg), so it reads as a real flip */
@keyframes tile-flip {
  0% {
    transform: rotateX(0deg);
    background-color: var(--tile-bg);
    border-color: var(--tile-border);
    color: var(--ink-black);
    animation-timing-function: ease-in;
  }
  49.99% {
    transform: rotateX(90deg);
    background-color: var(--tile-bg);
    border-color: var(--tile-border);
    color: var(--ink-black);
  }
  50% {
    transform: rotateX(-90deg);
    background-color: var(--cop-green-fill);
    border-color: var(--cop-green);
    color: var(--cop-green-ink);
    animation-timing-function: ease-out;
  }
  100% {
    transform: rotateX(0deg);
    background-color: var(--cop-green-fill);
    border-color: var(--cop-green);
    color: var(--cop-green-ink);
  }
}

@keyframes back-face {
  0%,
  49.99% {
    opacity: 0;
  }
  50%,
  100% {
    opacity: 1;
  }
}

@keyframes stamp-in {
  from {
    opacity: 0;
    transform: translate(calc(-50% + var(--sx, 0px)), calc(-50% + var(--sy, 0px)))
      rotate(-14deg) scale(2.2);
  }
  to {
    opacity: 0.28;
    transform: translate(calc(-50% + var(--sx, 0px)), calc(-50% + var(--sy, 0px)))
      rotate(-14deg) scale(1);
  }
}

@keyframes tile-jump {
  0%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-8px);
  }
}

@keyframes win-pop {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bingo-tile,
  .bingo-tile .tile-stamp,
  .bingo-bar,
  .skeleton-key,
  .skeleton-line {
    animation: none !important;
    transition: none !important;
  }

  .bingo-tile:hover {
    transform: none;
  }
}

/* =========================================================
   RESPONSIVE BREAKPOINTS
   ========================================================= */
@media (max-width: 1080px) {
  .ad-sidebar {
    display: none;
  }

  .ad-mobile {
    display: block;
  }
}

@media (max-width: 640px) {
  .page-wrap {
    padding: 10px 10px 28px;
  }

  .game-logo {
    height: 64px;
  }

  .game-card {
    padding: 10px;
    border-radius: 14px;
  }

  .bingo-grid {
    gap: 6px;
  }

  .bingo-tile {
    min-height: 92px;
    padding: 10px 5px;
    border-radius: 10px;
  }

  .tile-title {
    font-size: 10px;
    line-height: 1.2;
  }

  .tile-key {
    top: 4px;
    right: 5px;
    font-size: 7.5px;
  }

  .skeleton-key {
    top: 6px;
    right: 6px;
    width: 14px;
    height: 6px;
  }

  .skeleton-line {
    height: 8px;
  }

  .tile-stamp {
    width: 44px;
    height: 44px;
    font-size: 24px;
    border-width: 2.5px;
  }

  .tile-source-link,
  .tile-source-badge {
    font-size: 8.5px;
    padding: 2px 6px;
  }
}
