/**
 * TSAI Plugin Styles
 * Modal, button, inline iframe, and CF7 styles
 */

/* -----------------------------------------------
   Modal
   ----------------------------------------------- */

html.tsai-modal-open,
body.tsai-modal-open {
  overflow: hidden;
  overscroll-behavior: contain;
}

#tsai-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s ease, visibility 0.6s ease;
  z-index: 9998;
}

#tsai-modal-backdrop.visible {
  opacity: 1;
  visibility: visible;
}

#tsai-modal-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  width: 600px;
  max-width: 95vw;
  height: 800px;
  max-height: 90dvh;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  overflow: visible;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s ease, visibility 0.6s ease, transform 0.6s ease;
  z-index: 9999;
}

#tsai-modal-container.visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

#tsai-modal-close {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  border: 2px solid #fff;
  color: #fff;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  z-index: 10;
  transition: background 0.3s ease, transform 0.2s ease;
}

#tsai-modal-close:hover {
  background: rgba(0, 0, 0, 0.9);
  transform: scale(1.1);
}

#tsai-modal-frame {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 8px;
  overscroll-behavior: contain;
}

/* -----------------------------------------------
   Trigger buttons (modal + newtab)
   ----------------------------------------------- */

.tsai-chat-buttons-wrapper {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.tsai-modal-trigger,
.tsai-newtab-link,
.tsai-quiz-reveal {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #1e3a8a;
  color: #fff !important;
  border: none;
  border-radius: 6px;
  font-weight: 500;
  text-decoration: none !important;
  transition: background 0.3s ease, transform 0.2s ease;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}

.tsai-modal-trigger:hover,
.tsai-newtab-link:hover,
.tsai-quiz-reveal:hover {
  background: #1a3166;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(30, 58, 138, 0.3);
}

.tsai-modal-trigger:active,
.tsai-newtab-link:active,
.tsai-quiz-reveal:active {
  transform: translateY(0);
}

/* Outer section spacing. The quiz sits below the post tags as its own block. */
.tsai-quiz {
  margin: 2rem 0;
}

/* Standout panel. The gradient brings its own background, so the section reads
   clearly on light or dark host themes; the faint border + shadow keep it
   separated even against a dark page. */
.tsai-quiz-card {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: #fff;
  border-radius: 12px;
  padding: 24px 28px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* On phones, trim the card's horizontal padding so the embedded player iframe
   gets as much width as possible. */
@media (max-width: 600px) {
  .tsai-quiz-card {
    padding: 18px 12px;
  }
}

.tsai-quiz-heading {
  margin: 0 0 6px;
  color: #fff;
  font-weight: 700;
  font-size: 1.4rem;
  letter-spacing: 0.3px;
}

.tsai-quiz-intro {
  margin: 0 0 18px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 15px;
  line-height: 1.5;
}

/* "Take the Quiz" call-to-action: Scike mascot + button as one group. */
.tsai-quiz-cta {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.tsai-quiz-mascot {
  width: 104px;
  height: auto;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.25));
  transition: transform 0.25s ease;
}

/* Hero button: larger, bold, white-on-blue so it pops against the gradient
   card. Scoped to .tsai-quiz-card so other .tsai-quiz-reveal usages keep the
   shared trigger styling. The transform-based hover/in-view/launch animations
   below are color-independent and still apply. */
.tsai-quiz-card .tsai-quiz-reveal {
  padding: 14px 28px;
  font-size: 16px;
  font-weight: 600;
  background: #fff;
  color: #1e3a8a !important;
}

.tsai-quiz-card .tsai-quiz-reveal::after {
  content: " \2192";
}

.tsai-quiz-card .tsai-quiz-reveal:hover {
  background: #f1f5f9;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.35);
}

/* Hover anywhere on the group (mascot or button) grows the button and gives
   the mascot a subtle lean toward it. */
.tsai-quiz-cta:hover .tsai-quiz-reveal {
  transform: scale(1.08);
}

.tsai-quiz-cta:hover .tsai-quiz-mascot {
  transform: rotate(-3deg) scale(1.03);
}

/* Plain text label shown in place of the button once the quiz has loaded.
   White so it stays legible on the gradient card. */
.tsai-quiz-loaded {
  font-weight: 600;
  font-size: 16px;
  color: #fff;
}

/* Explanation shown only after the reader has passed this quiz (server-side
   via is-passed for logged-in users, or client-side once detected). Styled
   for the gradient card: translucent white panel with white text. */
.tsai-quiz-note {
  display: none;
  margin: 16px 0 0;
  padding: 8px 12px;
  border-left: 3px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  color: #fff;
  font-size: 14px;
  line-height: 1.4;
}

.tsai-quiz.is-passed .tsai-quiz-note {
  display: block;
}

@media (prefers-reduced-motion: no-preference) {
  /* One-time attention grab when the CTA first scrolls into view. */
  .tsai-quiz-cta.in-view .tsai-quiz-reveal {
    animation: tsai-quiz-attention 0.7s ease 1;
  }

  /* Brief launch beat when the button is clicked, before the quiz reveals. */
  .tsai-quiz-cta.tsai-quiz-launching .tsai-quiz-reveal {
    animation: tsai-quiz-launch 0.4s ease 1;
  }
}

@keyframes tsai-quiz-attention {
  0% { transform: scale(1) rotate(0); }
  20% { transform: scale(1.12) rotate(-2deg); }
  40% { transform: scale(1.07) rotate(2deg); }
  60% { transform: scale(1.1) rotate(-1.5deg); }
  80% { transform: scale(1.03) rotate(1deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes tsai-quiz-launch {
  0% { transform: scale(1); }
  35% { transform: scale(0.92); }
  70% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.tsai-icon {
  font-size: 20px;
  line-height: 1;
}

/* -----------------------------------------------
   Contact Form 7 submit buttons
   ----------------------------------------------- */

.wpcf7-form input[type="submit"],
.wpcf7-submit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #1e3a8a;
  color: #fff !important;
  border: none;
  border-radius: 6px;
  font-weight: 500;
  text-decoration: none !important;
  transition: background 0.3s ease, transform 0.2s ease;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}

.wpcf7-form input[type="submit"]:hover,
.wpcf7-submit:hover {
  background: #1a3166;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(30, 58, 138, 0.3);
}

.wpcf7-form input[type="submit"]:active,
.wpcf7-submit:active {
  transform: translateY(0);
}

.wpcf7-form input[type="submit"]:disabled,
.wpcf7-submit:disabled {
  background: #9ca3af;
  cursor: not-allowed;
  transform: none;
}

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

@media (max-width: 768px) {
  #tsai-modal-container {
    width: 95vw;
    height: 82dvh;
  }

  #tsai-modal-close {
    top: max(8px, env(safe-area-inset-top));
    right: 8px;
    width: 32px;
    height: 32px;
    font-size: 20px;
  }
}

@media (max-width: 480px) {
  #tsai-modal-container {
    width: 98vw;
    height: 82dvh;
    border-radius: 6px;
  }

  #tsai-modal-close {
    top: max(8px, env(safe-area-inset-top));
    right: 8px;
    width: 30px;
    height: 30px;
    font-size: 18px;
  }

  #tsai-modal-frame {
    border-radius: 6px;
  }
}

/* -----------------------------------------------
   Character deep-link icon
   ----------------------------------------------- */

.tsai-character-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  margin-left: 0.4em;
  color: currentColor;
  text-decoration: none;
  vertical-align: middle;
}

.tsai-character-link:hover {
  opacity: 0.8;
}

.tsai-character-link__icon {
  display: inline-block;
}

/* -----------------------------------------------
   Sitewide status banner ([tsai_status])
   ----------------------------------------------- */

.tsai-status-banner {
  /* Break out to full viewport width even inside a constrained container. */
  width: 100vw;
  margin-left: calc(50% - 50vw);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.85em 1.25em;
  background: #f59e0b;
  color: #1f2937;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
}

.tsai-status-banner__icon {
  font-size: 1.25em;
  line-height: 1;
}


/* -----------------------------------------------
   Quiz leaderboard ([tsai_quiz_leaderboard])
   ----------------------------------------------- */

.tsai-leaderboard {
  margin: 1.5em 0;
}

.tsai-leaderboard__title {
  margin: 0 0 0.5em;
  font-size: 1.25rem;
  font-weight: 700;
}

.tsai-leaderboard__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
}

.tsai-leaderboard__table th,
.tsai-leaderboard__table td {
  padding: 0.6em 0.75em;
  text-align: left;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.tsai-leaderboard__table thead th {
  font-weight: 700;
  border-bottom: 2px solid rgba(0, 0, 0, 0.2);
}

/* Compound selectors (.table td.cell) so the numeric right-alignment beats a
   host theme's own `td` text-align rules — matching the headers, which already
   win via th:nth-child specificity. */
.tsai-leaderboard__table th:nth-child(3),
.tsai-leaderboard__table th:nth-child(4),
.tsai-leaderboard__table td.tsai-leaderboard__quizzes,
.tsai-leaderboard__table td.tsai-leaderboard__points {
  text-align: right;
  white-space: nowrap;
}

.tsai-leaderboard__rank {
  width: 2.5em;
}

.tsai-leaderboard__points {
  font-weight: 700;
}

.tsai-leaderboard__table tbody tr:nth-child(-n + 3) .tsai-leaderboard__rank {
  font-weight: 700;
}

.tsai-leaderboard__empty {
  font-style: italic;
  opacity: 0.8;
}

/* -----------------------------------------------
   Quiz ticker ([tsai_quiz_ticker])
   ----------------------------------------------- */

.tsai-ticker {
  margin: 1.5em 0;
  display: flex;
  align-items: center;
  gap: 0.75em;
  /* Gradient brings its own background so the ticker reads on light or dark
     host themes, matching the quiz card. */
  background: linear-gradient(135deg, #4a2fb8 0%, #b8246b 100%);
  color: #fff;
  border-radius: 999px;
  padding: 0.5em 1em;
  overflow: hidden;
}

.tsai-ticker__label {
  flex: 0 0 auto;
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  padding-right: 0.5em;
  border-right: 1px solid rgba(255, 255, 255, 0.4);
}

.tsai-ticker__viewport {
  flex: 1 1 auto;
  overflow: hidden;
}

.tsai-ticker__track {
  display: flex;
  width: max-content;
  /* Two identical runs sit side by side; translating the track by -50% lands on
     the start of the second run, which is pixel-identical to the first — so the
     loop is seamless. */
  animation: tsai-ticker-scroll 30s linear infinite;
}

.tsai-ticker:hover .tsai-ticker__track {
  animation-play-state: paused;
}

.tsai-ticker__run {
  display: flex;
  flex: 0 0 auto;
}

.tsai-ticker__item {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4em;
  padding: 0 1.25em;
  white-space: nowrap;
  font-size: 0.95rem;
  /* Items are anchors linking to /quiz-results — keep them looking like the
     plain ticker text. */
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.tsai-ticker__item:hover {
  text-decoration: none;
  color: inherit;
}

.tsai-ticker__rank {
  font-weight: 700;
  opacity: 0.85;
}

.tsai-ticker__name {
  font-weight: 600;
}

.tsai-ticker__points {
  font-weight: 700;
  opacity: 0.95;
}

/* Empty state (article scope, no scores yet): a static invitation instead of a
   scrolling marquee. The JS swaps this for live rows once a reader scores. */
.tsai-ticker--empty .tsai-ticker__track {
  animation: none;
  width: 100%;
}

.tsai-ticker__empty {
  flex: 1 1 auto;
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
}

@keyframes tsai-ticker-scroll {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-50%);
  }
}

/* Respect reduced-motion: don't animate; let the reader scroll horizontally. */
@media (prefers-reduced-motion: reduce) {
  .tsai-ticker__viewport {
    overflow-x: auto;
  }
  .tsai-ticker__track {
    animation: none;
  }
  /* The duplicate run is redundant without the scroll loop. */
  .tsai-ticker__run[aria-hidden="true"] {
    display: none;
  }
}

/* -------------------------------------------------------------------------
   Author posting schedule ([tsai_schedule] / /schedule page). Ports the
   Creator app's schedule-dialog.scss layout to a full-width page.
   ------------------------------------------------------------------------- */
.tsai-schedule {
  margin: 1.5em 0;
}

.tsai-schedule__heading {
  margin: 1em 0 0.5em;
  font-size: 1.25rem;
  font-weight: 700;
}

.tsai-schedule__calendar-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  margin: 0 0 1em;
}

.tsai-schedule__calendar-links a {
  display: inline-block;
  padding: 0.4em 0.9em;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
}

.tsai-schedule__subscribe {
  background: #1976d2;
  border-color: #1976d2 !important;
  color: #fff;
}

.tsai-schedule__download {
  color: inherit;
}

.tsai-schedule__divider {
  margin: 1.5em 0;
  border: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.tsai-schedule__day {
  margin-bottom: 0.75em;
}

.tsai-schedule__day h3 {
  margin: 0.5em 0 0.25em;
  font-size: 1.05rem;
  font-weight: 700;
}

.tsai-schedule__day ul,
.tsai-schedule__prob-list {
  margin: 0;
  padding-left: 1.25em;
}

.tsai-schedule__prob-list li {
  margin: 0.25em 0;
}

.tsai-schedule__type {
  font-style: italic;
  opacity: 0.75;
}

.tsai-schedule__hours,
.tsai-schedule__rates {
  opacity: 0.85;
}

.tsai-schedule__empty {
  font-style: italic;
  opacity: 0.7;
}
