/* Myth Widget Revamp: Flat, Modern, Elegant */
#myth-widget {
  text-align: center;
  font-family: 'Inter', 'Acumin Pro', Arial, sans-serif;
  position: relative;
  /* max-width: 700px; */
  margin-left: 0;
  margin-right: 0;
  border: none;
  padding-bottom: 3.5em;
  padding-left: 0;
  padding-right: 0;
}

/* Remove horizontal padding from .container for edge-to-edge effect */
.container {
  padding-left: 0 !important;
  padding-right: 0 !important;
}

/* Ensure postcard is edge-to-edge inside widget */
.postcard {
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.myth-btn, .thinker-btn {
  background: #fff;
  border: 0.5px solid #e5e5e5;
  cursor: pointer;
  transition: border 0.19s, background 0.19s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(24vw, 120px);
  height: min(24vw, 120px);
  min-width: 56px;
  min-height: 56px;
  aspect-ratio: 1/1;
  position: relative;
  overflow: hidden;
  padding: 0; /* Remove any padding for perfect image fit */
}
.thinker-btn {
  border-radius: 50% !important;
}

.myth-btn:focus-visible, .thinker-btn:focus-visible {
  outline: 2.5px solid var(--hurricane-red);
  outline-offset: 2px;
}
.myth-btn:disabled, .thinker-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  filter: grayscale(0.8);
}
.myth-btn.active, .thinker-btn.active {
  border: 2.5px solid var(--old-gold);
  background: #fffbe8;
  box-shadow: 0 0 0 4px #ffe07555, 0 0 16px 2px #ffe07599;
  z-index: 2;
}
.myth-btn:hover, .thinker-btn:hover,
.myth-btn:focus-visible, .thinker-btn:focus-visible {
  border-color: #1a1a1a;
  background: #f2f2f2;
  color: #111;
  text-decoration: underline;
}
.myth-btn.active, .thinker-btn.active {
  border: 2px solid #111;
  background: #eaeaea;
  color: #111;
  z-index: 2;
}
.myth-btn:disabled, .thinker-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  filter: grayscale(0.8);
}

.myth-btn:hover, .thinker-btn:hover,
.myth-btn:focus-visible, .thinker-btn:focus-visible {
  border-color: var(--old-gold);
  background: #f8f1e3;
}

.myth-btn:disabled, .thinker-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  filter: grayscale(0.8);
}
/* Avatar images fill button, no margin for perfect alignment & image quality */
.myth-avatar, .thinker-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  box-shadow: none !important;
  background: #fff;
  display: block;
  pointer-events: none;
  transition: filter 0.18s, border-color 0.18s;
  border: none;
  /* Removed margin to eliminate uneven padding */
  image-rendering: auto;
  image-rendering: -webkit-optimize-contrast;
}
.myth-avatar {
  border-radius: 0 !important;
}
.thinker-avatar {
  border-radius: 50% !important;
}
.myth-btn.active .myth-avatar, .thinker-btn.active .thinker-avatar {
  filter: none;
  outline: 1px solid var(--old-gold);
  outline-offset: -1px;
}

#gen-btn {
  margin: 1em 0 1.2em 0;
  padding: 0.6em 2.2em;
  font-size: 1.07rem;
  border-radius: 0 !important;
  border: 2px solid #232323;
  background: #fff;
  color: #232323;
  font-weight: 700;
  box-shadow: none !important;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border 0.2s;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
#gen-btn:hover, #gen-btn:focus-visible {
  background: #f2f2f2;
  color: #111;
  border-color: #111;
  text-decoration: underline;
}
#gen-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.postcard {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 3/2;
  margin: 2.5em 0 0 0;
  perspective: 1600px;
  position: relative;
  border-radius: 0 !important;
  box-shadow: 0 8px 32px #e5d8b733, 0 1.5px 16px #fff8;
  border: none;
  background: #fff;
  overflow: visible;
  transition: box-shadow 0.4s cubic-bezier(.22,1,.36,1), transform 0.8s cubic-bezier(.7,1.6,.23,.99);
  transform-style: preserve-3d;
  cursor: pointer;
  display: flex;
  will-change: transform;
}

.postcard:focus {
  outline: 2.5px solid #003595;
  outline-offset: 3px;
}

.postcard:hover, .postcard:active {
  box-shadow: 0 16px 40px #e5d8b799, 0 2.5px 22px #fff8, 0 0 0 4px #00359522;
  transform: scale(1.025) rotateX(2deg) rotateZ(-0.2deg);
  z-index: 10;
}

.postcard.flipped {
  transform: rotateY(180deg) scale(1.025) rotateX(2deg) rotateZ(-0.2deg);
  box-shadow: 0 24px 56px #e5d8b7cc, 0 4px 32px #fff8, 0 0 0 4px #00359522;
  z-index: 12;
}

/* Only parent animates; remove transition from .face */
.postcard .face {
  position: absolute;
  width: 100%;
  backface-visibility: hidden;
  border-radius: 0 !important;
  overflow: hidden;
  transition: transform 0.8s cubic-bezier(.7,1.6,.23,.99);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  will-change: transform;
}

.postcard .front {
  background: #fff;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
}
#myth-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: #fff;
  display: block;
  border: none;
}
.postcard .back {
  transform: rotateY(180deg);
  padding: 2.2em 2.4em 1.7em 2.4em;
  box-sizing: border-box;
  display: grid;
  gap: 1.2em;
  border-radius: 0 !important;
  border: none;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  z-index: 1;
}
#myth-text {
  font-size: 1.2rem;
  color: #232323;
  margin: 0 0 1.2em 0;
  line-height: 1.7;
  text-align: left;
  background: none;
  border-radius: 0 !important;
  padding: 0.1em 0 0.1em 0.1em;
  box-shadow: none !important;
  min-height: 90px;
  letter-spacing: 0.02em;
  word-break: break-word;
  font-family: var(--myth-handwritten, 'Caveat', 'Indie Flower', 'Patrick Hand', 'Shadows Into Light', cursive, Arial, sans-serif);
  visibility: visible;
}
#myth-widget .back #myth-text,
.postcard .back #myth-text {
  background: none;
  color: #003595;
  border-radius: 0;
  box-shadow: none;
  min-height: 60px;
  text-align: left;
  margin: 0.2em 0 1em 0;
  border: none;
  word-break: break-word;
  font-family: 'Caveat', 'Indie Flower', 'Patrick Hand', 'Shadows Into Light', cursive;
  letter-spacing: 0.01em;
  font-weight: 400;
  transition: font-size 0.2s, padding 0.2s, color 0.2s;
}
#myth-widget .back #myth-text:empty,
.postcard .back #myth-text:empty {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
}

.spinner-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.76);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 0 !important;
  transition: opacity 0.3s;
}
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--old-gold);
  border-top: 4px solid var(--tu-blue);
  border-radius: 0 !important;
  animation: myth-spin 1.1s linear infinite;
  box-shadow: none !important;
}
@keyframes myth-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
.postcard.flipped {
  transform: rotateY(180deg);
}

.myth-grid, .thinker-grid {
  display: grid;
  gap: 0.75em;
  margin: auto auto 1.5em auto;
  justify-content: center;
  grid-template-columns: repeat(6, 1fr); max-width: 700px;
}
.myth-btn:focus-visible, .thinker-btn:focus-visible {
  outline: 2.5px solid var(--hurricane-red);
  outline-offset: 2px;
}
.myth-btn:disabled, .thinker-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  filter: grayscale(0.8);
}

.myth-btn.active .myth-avatar, .thinker-btn.active .thinker-avatar {
  filter: drop-shadow(0 0 7px #ffe075aa) brightness(1.08) saturate(1.12);
}

#gen-btn {
  margin: 1.2em 0 1.7em 0;
  padding: 0.85em 2.2em;
  font-size: 1.13rem;
  border-radius: 0 !important;
  border: none;
  color: #003595;
  font-weight: 700;
  box-shadow: none !important;
  cursor: pointer;
  transition: background 0.3s, color 0.2s;
}
#gen-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.postcard {
  aspect-ratio: 3/2;
  margin: 2.7em auto 0 auto;
  perspective: 1600px;
  position: relative;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: #f8f1e3;
  overflow: visible;
  transition: box-shadow 0.3s, transform 0.8s cubic-bezier(.7,1.6,.23,.99); /* Animate transform for 3D flip both ways */
  cursor: pointer;
}

.postcard.flipped {
  transform: rotateY(180deg) scale(1.025) rotateX(2deg) rotateZ(-0.2deg);
  box-shadow: 0 24px 56px #e5d8b7cc, 0 4px 32px #fff8, 0 0 0 4px #00359522;
  z-index: 12;
}

/* Only parent animates; remove transition from .face */
.postcard .face {
  position: absolute;
  width: 100%;
  backface-visibility: hidden;
  border-radius: 0 !important;
  overflow: hidden;
  transition: transform 0.8s cubic-bezier(.7,1.6,.23,.99);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  will-change: transform;
}

.postcard .front {
  background: #fff;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
}
#myth-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: #fff;
  display: block;
}
.postcard .back {
  transform: rotateY(180deg);
  padding: 2.1em 2.2em 1.6em 2.2em;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 1.2em;
}
#thinker-signature {
  font-family: 'Shadows Into Light', 'Caveat', 'Indie Flower', 'Patrick Hand', cursive;
  font-size: 1.25rem;
  color: #003595;
  margin-top: -0.5em;
  align-self: flex-end;
  letter-spacing: 0.07em;
  opacity: 0.96;
  text-shadow: 0 2.5px 12px #00359522, 0 1px 0 #ffe07544;
  border-bottom: 2.5px solid #d0b78744;
  padding-right: 0.12em;
  background: none;
  letter-spacing: 0.04em;
}
.spinner-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.76);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 0 !important;
  transition: opacity 0.3s;
}
.spinner {
  width: 54px;
  height: 54px;
  border: 6px solid #ffe075;
  border-top: 6px solid #003595;
  border-radius: 0 !important;
  animation: myth-spin 1.1s linear infinite;
  box-shadow: none !important;
}
@keyframes myth-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

#myth-widget select, #myth-widget button {
  margin: 0.25em 0.25em 0.25em 0.25em;
  border: 2.5px solid #e5e5e5;
  color: #222;
  cursor: pointer;
  transition: background 0.3s, color 0.2s;
}
#myth-widget button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
#myth-widget .card {
  width: 360px;
  min-height: 540px;
  max-width: 95vw;
  margin: 2em auto 0 auto;
  perspective: 1200px;
  position: relative;
  border-radius: 0 !important;
  box-shadow: none !important;
  overflow: visible;
  transition: box-shadow 0.3s;
}
#myth-widget .card:hover {
  box-shadow: none !important;
}
#myth-widget .face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 0 !important;
  overflow: hidden;
  transition: transform 0.7s cubic-bezier(.22,1,.36,1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#myth-widget .front {
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.2rem;
  letter-spacing: 0.03em;
  font-family: 'Anton', 'Acumin Pro', sans-serif;
  position: relative;
}
#myth-widget .front .backdrop {
  font-size: 5.5rem;
  filter: blur(0.5px) drop-shadow(0 2px 8px #ffe07588);
  opacity: 0.7;
}
#myth-widget .back {
  /* No font-size or font-family overrides here; allow postcard-back.css to control */
  transform: rotateY(180deg);
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  gap: 0.01em;
}
#myth-widget .card.flipped .front { transform: rotateY(-180deg); }
#myth-widget .card.flipped .back { transform: rotateY(0deg); }
#myth-widget #myth-img {
  object-fit: cover;
  min-height: 220px;
}
#myth-widget .spinner-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.76);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 0 !important;
  transition: opacity 0.3s;
}
#myth-widget .spinner {
  width: 54px;
  height: 54px;
  border: 6px solid #ffe075;
  border-top: 6px solid #003595;
  border-radius: 0 !important;
  animation: myth-spin 1.1s linear infinite;
  box-shadow: none !important;
}
@keyframes myth-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
#myth-widget .card {
  animation: floaty-card 3.2s ease-in-out infinite alternate;
}
@keyframes floaty-card {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-10px) scale(1.02); }
}

/* --- Canonical mobile override for postcard back and text (do not duplicate below) --- */
@media (max-width: 700px) {
  #myth-text, 
  .postcard .back #myth-text {
    font-size: 0.85rem;
    line-height: 1.1;
  }
  .postcard {
    width: 100%;
    min-width: 0;
    min-height: 0;
    aspect-ratio: 3/2;
  }
  .myth-grid, .thinker-grid { 
    grid-template-columns: repeat(3, 1fr); 
    max-width: 99vw; 
  }
  #myth-img { 
    min-height: 100%; 
  }
  .postcard .back { 
    padding: 0em 0em 0em 0em; 
  }
  #myth-widget .card {
    width: 98vw;
    min-height: 420px;
    max-width: 99vw;
  }
  #myth-widget #myth-img {
    max-width: 96vw;
    min-height: 160px;
  }
  .myth-btn, .thinker-btn {
    width: min(24vw, 120px);
    height: min(24vw, 120px);
    min-width: 44px;
    min-height: 44px;
  }
}

/* Styles for loading overlay to prevent flipping and ensure correct positioning */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  transform-style: flat;
  backface-visibility: hidden;
}

/* Counter flip transform when card is flipped */
.postcard.flipped .loading-overlay {
  transform: rotateY(0deg) !important;
}

/* Progress bar container styles */
.progress-bar-container {
  width: 80%;
  height: 20px;
  background-color: #e0e0e0;
  border-radius: 10px;
  overflow: hidden;
}

/* Animated striped progress bar */
.progress-bar {
  width: 0%;
  height: 100%;
  background: repeating-linear-gradient(45deg, #FFE075, #FFE075 10px, #003595 10px, #003595 20px);
  background-size: 200% 100%;
  animation: stripe-slide 30s linear infinite;  
  box-shadow: 0 2px 12px #00359522, 0 1px 0 #ffe07544;
}

@keyframes stripe-slide {
  0% { background-position: 0 0; }
  100% { background-position: 200px 0; }  
}

/* Microcopy text styles */
.microcopy-text {
  color: #fff;
  margin-top: 20px;
  font-size: 1.2em;
  text-align: center;
}
