/* Marketing Tarot widget. Everything is scoped under .mt-widget so it can sit
   inside a Squarespace code block without fighting the theme.

   Colours and fonts match merlinitemarketing.com, specifically the teal "reading"
   arch on the Marketing Tarot landing page the widget is embedded in: teal
   background, cream text, clay buttons, gold card edges, Playfair Display headings,
   Inter body text and Caveat for the little script accents. Change the values below
   and everything (including the print styles) follows. */

:root {
  --mt-bg: #264349;                    /* teal: the arch the widget sits in */
  --mt-bg-deep: #1e373c;               /* card backs */
  --mt-panel: rgba(30, 55, 60, 0.5);   /* boxes on the teal */
  --mt-line: rgba(230, 207, 182, 0.28);
  --mt-ink: #f4f1eb;                   /* cream */
  --mt-ink-soft: #d9e2df;
  --mt-sand: #e6cfb6;                  /* script accents and small labels */
  --mt-gold: #c9a27e;                  /* card edges and the moon */
  --mt-clay: #93603c;                  /* buttons (the site's "Let's talk" clay) */
  --mt-clay-dark: #7e5234;
  --mt-clay-light: #a8744f;            /* card fronts */
  --mt-field: #fbf9f5;                 /* the dropdown */
  --mt-field-ink: #264349;
  --mt-error: #f5c6b2;
  --mt-radius: 24px;
  --mt-card-ratio: 11 / 19;
  --mt-serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --mt-sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mt-script: Caveat, "Segoe Script", "Bradley Hand", cursive;
}

/* standalone-only */
html, body {
  margin: 0;
  padding: 0;
  background: var(--mt-bg);
}

/* Set by app.js once the host page's embed script has acknowledged a height message:
   the iframe is being resized to fit, so the frame document needs no scrollbar. */
html.mt-embedded {
  overflow: hidden;
}
/* /standalone-only */

.mt-widget,
.mt-widget * {
  box-sizing: border-box;
}

.mt-widget {
  font-family: var(--mt-sans);
  color: var(--mt-ink);
  line-height: 1.55;
  max-width: 920px;
  margin: 0 auto;
  padding: 8px 16px 32px;
  -webkit-font-smoothing: antialiased;
}

.mt-widget h1,
.mt-widget h2,
.mt-widget h3 {
  font-family: var(--mt-serif);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0;
  margin: 0;
  color: var(--mt-ink);
}

.mt-widget p {
  margin: 0;
}

.mt-widget a {
  color: var(--mt-sand);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.mt-widget a:hover {
  color: var(--mt-ink);
}

.mt-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Header (standalone page only; the host page has its own heading) ---------- */

.mt-header {
  text-align: center;
  padding-top: 24px;
  margin-bottom: 28px;
}

.mt-header h1 {
  font-size: clamp(32px, 4.5vw, 46px);
}

.mt-header__sub {
  color: var(--mt-ink-soft);
  margin: 10px auto 0;
  max-width: 560px;
  font-size: 17px;
  line-height: 1.6;
}

/* ---------- Controls ---------- */

.mt-controls {
  background: var(--mt-panel);
  border: 1px solid var(--mt-line);
  border-radius: var(--mt-radius);
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 14px;
  align-items: end;
}

.mt-controls__field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.mt-controls label {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--mt-sand);
}

.mt-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  color: var(--mt-field-ink);
  background: var(--mt-field) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%23264349' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 18px center;
  border: 1.5px solid var(--mt-gold);
  border-radius: 999px;
  padding: 12px 46px 12px 20px;
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.mt-select:focus-visible,
.mt-button:focus-visible {
  outline: 3px solid var(--mt-sand);
  outline-offset: 3px;
}

.mt-button {
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--mt-clay);
  border: 2px solid var(--mt-ink);
  border-radius: 999px;
  padding: 13px 28px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.mt-button:hover {
  background: var(--mt-clay-dark);
  transform: translateY(-2px);
}

.mt-button:active {
  transform: translateY(0);
}

.mt-button[disabled] {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}

/* Outline button, like the chips on the site's dark sections. */
.mt-button--ghost {
  background: transparent;
  color: var(--mt-ink);
  border: 1.5px solid var(--mt-ink);
  padding: 13.5px 28px;
}

.mt-button--ghost:hover {
  background: var(--mt-ink);
  color: var(--mt-bg);
}

/* ---------- Reading ---------- */

.mt-reading {
  margin-top: 32px;
}

.mt-reading[hidden] {
  display: none;
}

.mt-reading__question {
  text-align: center;
  font-size: clamp(24px, 3vw, 32px);
  margin-bottom: 8px;
  border-radius: 6px;
}

/* Focus moves here after a pull. Mouse users see nothing; keyboard users get the sand ring. */
.mt-reading__question:focus {
  outline: none;
}

.mt-reading__question:focus-visible {
  outline: 3px solid var(--mt-sand);
  outline-offset: 6px;
}

.mt-reading__hint {
  text-align: center;
  color: var(--mt-ink-soft);
  font-size: 15px;
  margin-bottom: 6px;
}

/* Shown while any card is still face down, in the site's handwritten accent style. */
.mt-reading__flip-hint {
  text-align: center;
  font-family: var(--mt-script);
  font-weight: 500;
  font-size: 24px;
  line-height: 1.2;
  color: var(--mt-sand);
  margin-bottom: 4px;
}

.mt-widget [hidden] {
  display: none !important;
}

.mt-cards {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.mt-card {
  background: var(--mt-panel);
  border: 1px solid var(--mt-line);
  border-radius: var(--mt-radius);
  padding: 18px 16px 20px;
  display: grid;
  grid-template-areas:
    "position"
    "image"
    "name"
    "classic"
    "marketing";
  grid-template-rows: auto auto auto auto 1fr;
  gap: 10px;
  min-width: 0;
}

/* "1  WHERE YOU ARE": an italic serif number, then the position in small spaced caps. */
.mt-card__position {
  grid-area: position;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1.35;
  color: var(--mt-sand);
}

.mt-card__position-num {
  display: inline-block;
  font-family: var(--mt-serif);
  font-style: italic;
  font-weight: 500;
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
  vertical-align: -3px;
  margin-right: 8px;
  color: var(--mt-sand);
}

.mt-card__figure {
  grid-area: image;
  position: relative;
  margin: 0;
  justify-self: center;
  width: 100%;
  max-width: 190px;
  perspective: 1200px;
}

.mt-card__flip {
  position: relative;
  width: 100%;
  aspect-ratio: var(--mt-card-ratio);
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.mt-card.is-facedown .mt-card__flip {
  transform: rotateY(180deg);
}

/* Browsers without aspect-ratio support (Safari before 15, 2020-era Android) get the
   classic padding trick instead, so the card still has a size and can be tapped. */
@supports not (aspect-ratio: 11 / 19) {
  .mt-card__flip {
    height: 0;
    padding-bottom: 172.73%; /* 19 / 11 */
  }
}

.mt-card__face {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  border-radius: 12px;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 14px 30px rgba(20, 40, 44, 0.28);
}

/* Card back: deep teal, gold edge, the site's crescent moon, and a thin inner frame. */
.mt-card__face--back {
  transform: rotateY(180deg);
  background: var(--mt-bg-deep) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='30' fill='none' stroke='%23C9A27E' stroke-width='1.5'/%3E%3Cpath d='M58 32 A20 20 0 1 0 58 68 A16 16 0 1 1 58 32 Z' fill='%23C9A27E'/%3E%3C/svg%3E") no-repeat center 42% / 48% auto;
  border: 2px solid var(--mt-gold);
}

.mt-card__face--back::before {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  bottom: 8px;
  left: 8px;
  border: 1px solid rgba(201, 162, 126, 0.6);
  border-radius: 8px;
  pointer-events: none;
}

.mt-card__face--front {
  background: var(--mt-field);
  border: 2px solid var(--mt-clay-light);
}

.mt-card__face--front img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--mt-field);
}

/* Placeholder used when a card image is missing or still loading. */
.mt-card__placeholder {
  display: none;
  width: 100%;
  height: 100%;
  padding: 12px;
  background: var(--mt-field);
  color: var(--mt-field-ink);
  font-family: var(--mt-serif);
  text-align: center;
  align-items: center;
  justify-content: center;
}

.mt-card__face--front.is-missing img {
  display: none;
}

.mt-card__face--front.is-missing .mt-card__placeholder {
  display: flex;
}

.mt-card__name {
  grid-area: name;
  font-size: 21px;
}

.mt-card__name h3 {
  font-size: inherit;
}

.mt-card__classic {
  grid-area: classic;
  font-size: 14px;
  color: var(--mt-ink-soft);
}

.mt-card__classic strong {
  color: var(--mt-ink);
  font-weight: 600;
}

.mt-card__marketing {
  grid-area: marketing;
  font-size: 15px;
}

/* A face-down card is compact: label, card back, "tap to flip". The text joins the layout
   when the card is turned, fading in once the flip is half-way round. */
@keyframes mt-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.mt-card__text {
  animation: mt-fade-in 0.45s ease 0.25s both;
}

.mt-card.is-facedown .mt-card__text {
  display: none;
}

/* "tap to flip" button: an invisible button covering the whole face-down picture, with
   the handwritten label along the bottom edge, as on the site's own card illustration.
   Removed once the card is turned. */
.mt-card__turn {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 12px 18px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  font: inherit;
}

.mt-card__turn span {
  display: inline-block;
  font-family: var(--mt-script);
  font-weight: 500;
  font-size: 20px;
  line-height: 1;
  color: var(--mt-sand);
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: color 0.2s ease, opacity 0.3s ease;
}

/* Two rules rather than one list: an old browser that doesn't know :focus-visible would
   otherwise throw the hover style away with it. */
.mt-card__turn:hover span {
  color: #fff;
}

.mt-card__turn:focus-visible span {
  color: #fff;
}

.mt-card__turn:focus-visible {
  outline: 3px solid var(--mt-sand);
  outline-offset: 4px;
}

.mt-card__turn:disabled {
  cursor: default;
}

.mt-card__turn:disabled span {
  opacity: 0;
}

.mt-card:not(.is-facedown) .mt-card__turn {
  display: none;
}

/* A face-down card lifts slightly under the pointer. */
.mt-card.is-facedown .mt-card__figure:hover .mt-card__flip {
  transform: rotateY(180deg) translateY(-6px);
}

/* Focus lands on the name after a turn; the card appearing is the feedback, no ring needed. */
.mt-card__name h3:focus {
  outline: none;
}

/* Small shimmy while "shuffling". */
@keyframes mt-shuffle {
  0%   { transform: translateY(0) rotate(0deg); }
  25%  { transform: translateY(-6px) rotate(-2deg); }
  50%  { transform: translateY(0) rotate(0deg); }
  75%  { transform: translateY(-6px) rotate(2deg); }
  100% { transform: translateY(0) rotate(0deg); }
}

.mt-reading.is-shuffling .mt-card__figure {
  animation: mt-shuffle 0.5s ease-in-out infinite;
}

.mt-reading.is-shuffling .mt-card:nth-child(2) .mt-card__figure { animation-delay: 0.08s; }
.mt-reading.is-shuffling .mt-card:nth-child(3) .mt-card__figure { animation-delay: 0.16s; }
.mt-reading.is-shuffling .mt-card:nth-child(4) .mt-card__figure { animation-delay: 0.24s; }

.mt-reading__footer {
  margin-top: 24px;
  text-align: center;
  color: var(--mt-ink-soft);
  font-size: 15px;
  line-height: 1.6;
  padding: 18px 8px 0;
  border-top: 1px solid var(--mt-line);
}

/* ---------- Reading actions + PDF ---------- */

.mt-reading__actions {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.mt-reading__pdf-status {
  text-align: center;
  font-size: 14px;
  color: var(--mt-ink-soft);
  min-height: 1.4em;
  margin-top: 8px;
}

.mt-reading__pdf-status.is-error {
  color: var(--mt-error);
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .mt-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .mt-widget {
    padding: 4px 12px 28px;
  }

  .mt-controls {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .mt-controls .mt-button {
    width: 100%;
  }

  .mt-cards {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* On a phone: label on top, image beside the name and classic line,
     marketing meaning full width underneath. Keeps each card short. */
  .mt-card {
    grid-template-areas:
      "position position"
      "image name"
      "image classic"
      "marketing marketing";
    grid-template-columns: 104px 1fr;
    grid-template-rows: auto auto 1fr auto;
    column-gap: 14px;
    row-gap: 6px;
    padding: 14px;
  }

  .mt-card__figure {
    justify-self: start;
    max-width: 104px;
  }

  /* While face down there is no text yet, so drop the empty right-hand column and sit
     the card back in the middle; it moves to the left as it turns and the text appears. */
  .mt-card.is-facedown {
    grid-template-areas:
      "position"
      "image";
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .mt-card.is-facedown .mt-card__figure {
    justify-self: center;
    max-width: 150px;
  }

  .mt-card__face--back {
    background-size: 44% auto;
  }

  .mt-card__turn {
    padding: 10px 8px 12px;
  }

  .mt-card__turn span {
    font-size: 18px;
  }

  .mt-card__name {
    font-size: 19px;
    align-self: end;
  }

  .mt-card__classic {
    align-self: start;
  }

  .mt-reading__actions .mt-button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mt-card__flip,
  .mt-card__turn span,
  .mt-button {
    transition: none;
  }

  .mt-button:hover {
    transform: none;
  }

  .mt-card__text {
    animation: none;
  }

  .mt-card.is-facedown .mt-card__figure:hover .mt-card__flip {
    transform: rotateY(180deg);
  }

  .mt-reading.is-shuffling .mt-card__figure {
    animation: none;
  }
}

/* ---------- Print (Ctrl+P / Save as PDF) ---------- */

@media print {
  /* Dark ink on white paper: every colour above is a variable, so swapping them is enough. */
  :root {
    --mt-bg: #fff;
    --mt-bg-deep: #fff;
    --mt-panel: transparent;
    --mt-line: #cfcac0;
    --mt-ink: #264349;
    --mt-ink-soft: #3b5a60;
    --mt-sand: #8a5a38;
    --mt-field: #fff;
  }

  html, body {
    background: #fff;
  }

  .mt-header__sub,
  .mt-controls,
  .mt-reading__actions,
  .mt-reading__pdf-status,
  .mt-reading__hint,
  .mt-reading__flip-hint,
  .mt-card__turn {
    display: none !important;
  }

  .mt-widget {
    padding: 0;
    max-width: none;
  }

  .mt-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .mt-card {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .mt-card__flip {
    transform: none !important;
    transition: none;
  }

  .mt-card__face {
    box-shadow: none;
  }

  .mt-card__face--back {
    display: none;
  }

  .mt-card__text {
    display: block !important;
    opacity: 1 !important;
    animation: none !important;
  }

  .mt-reading__footer a {
    color: inherit;
    text-decoration: underline;
  }
}
