/* Opening Screen Styles */

.opening-screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 3rem 4rem;
  overflow: hidden;
  background: 
    radial-gradient(ellipse at 15% 70%, rgba(246, 214, 196, 0.4) 0%, transparent 60%),
    radial-gradient(ellipse at 85% 15%, rgba(224, 236, 225, 0.5) 0%, transparent 55%),
    linear-gradient(135deg, #FFF9F5 0%, var(--palette-peach-light) 65%, var(--palette-peach) 100%);
}

/* Background Ambient Elements */
.opening-screen::before {
  content: '';
  position: absolute;
  top: -10vw;
  right: -5vw;
  width: 45vw;
  height: 45vw;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.7) 0%, rgba(246, 214, 196, 0.1) 70%, transparent 100%);
  pointer-events: none;
  z-index: 1;
}

/* Title at Top */
.opening-title-container {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 900px;
  margin: 0 auto 1.5rem auto;
  text-align: center;
  animation: titleDropIn 0.9s var(--ease-out-expo) forwards;
}

.opening-title-badge {
  display: inline-block;
  padding: 0.35rem 1rem;
  margin-bottom: 0.75rem;
  background: var(--palette-sage-light);
  color: var(--palette-brown-dark);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(107, 142, 109, 0.25);
}

.opening-title {
  font-family: var(--font-family-display);
  font-size: clamp(2rem, 3.8vw, 3.6rem);
  font-weight: 800;
  line-height: 1.15;
  color: var(--palette-brown-dark);
  letter-spacing: -0.02em;
  text-shadow: 0 2px 10px rgba(56, 36, 24, 0.05);
}

.opening-title .subtitle-part {
  display: block;
  font-size: clamp(1.2rem, 2.2vw, 2rem);
  font-weight: 500;
  color: var(--palette-brown-med);
  margin-top: 0.4rem;
  font-family: var(--font-family-body);
  letter-spacing: -0.01em;
}

/* Main Content Area */
.opening-body {
  position: relative;
  z-index: 5;
  flex: 1;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  pointer-events: none;
}

/* Characters Container - Positioned off-center in the left third */
.characters-container {
  position: absolute;
  left: 3%;
  bottom: 6%;
  width: 38%;
  max-width: 540px;
  min-width: 320px;
  height: 64vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  pointer-events: auto;
  animation: charactersFadeIn 1.1s var(--ease-out-expo) 0.2s backwards;
}

.character-card {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  border-radius: var(--radius-2xl);
  overflow: hidden;
  box-shadow: 
    0 20px 40px -10px rgba(56, 36, 24, 0.12),
    0 2px 10px rgba(56, 36, 24, 0.04);
  border: 4px solid var(--palette-warm-white);
  background: var(--palette-warm-white);
}

.character-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center bottom;
  display: block;
  transition: transform 0.6s var(--ease-out-expo);
}

.character-card:hover .character-image {
  transform: scale(1.02);
}

.character-label-pill {
  position: absolute;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-family-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--palette-brown-dark);
  box-shadow: 0 4px 15px rgba(56, 36, 24, 0.1);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.character-label-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--palette-sage);
}

/* Lower Right Continue Button */
.continue-btn-container {
  position: absolute;
  right: 4rem;
  bottom: 3.5rem;
  z-index: 20;
  pointer-events: auto;
  display: flex;
  gap: 0.75rem;
}

.resume-btn {
  background: transparent;
  color: var(--palette-teal-dark);
  border: 2px solid var(--palette-teal-dark);
  font-family: var(--font-family-display);
  font-size: 1.25rem;
  font-weight: 700;
  padding: 1.1rem 2.6rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transition: 
    opacity var(--dur-slow) var(--ease-out-expo),
    transform var(--dur-slow) var(--ease-out-expo),
    background-color var(--dur-fast) ease,
    color var(--dur-fast) ease;
}

.resume-btn.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.resume-btn:hover,
.resume-btn:focus-visible {
  background-color: var(--palette-teal-dark);
  color: var(--text-inverse);
}

.resume-btn:active {
  transform: translateY(1px) scale(0.99);
}

.resume-btn:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-on-light);
  outline-offset: var(--focus-ring-offset);
}

.continue-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.1rem 2.6rem;
  font-family: var(--font-family-display);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--palette-warm-white);
  background-color: var(--palette-teal);
  border: 2px solid transparent;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: 
    0 10px 25px -4px rgba(54, 107, 119, 0.35),
    0 4px 10px -2px rgba(54, 107, 119, 0.2);
  
  /* Initial state: Hidden until 1.5 seconds pass */
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transition: 
    opacity var(--dur-slow) var(--ease-out-expo),
    transform var(--dur-slow) var(--ease-out-expo),
    background-color var(--dur-fast) ease,
    border-color var(--dur-fast) ease,
    box-shadow var(--dur-fast) ease;
  user-select: none;
  -webkit-user-select: none;
}

/* Visible class triggered after ~1.5 seconds */
.continue-btn.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.continue-btn .continue-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transform-origin: center center;
  transition: transform var(--dur-fast) var(--ease-out-expo), text-decoration var(--dur-fast) ease;
  text-decoration: none;
}

.continue-btn .continue-arrow {
  position: absolute;
  right: 1.1rem;
  top: 50%;
  transform: translateY(-50%) translateX(-6px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  opacity: 0;
  pointer-events: none;
  transition: 
    opacity var(--dur-fast) var(--ease-out-expo),
    transform var(--dur-fast) var(--ease-out-expo);
}

.continue-btn .continue-arrow svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
  display: block;
}

/* HOVER STATE REQUIREMENTS:
   1. Button's color changes
   2. Arrow fades in next to the word "continue"
   3. The word "continue" becomes underlined and increases slightly in size, remaining centered
*/
.continue-btn:hover {
  background-color: var(--palette-brown-dark);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 
    0 14px 30px -4px rgba(56, 36, 24, 0.4),
    0 6px 14px -2px rgba(56, 36, 24, 0.25);
  transform: translateY(-2px) scale(1.02);
}

/* Keyboard users get the same affordance as mouse users: every :hover rule
   above is mirrored on :focus-visible. */
.continue-btn:focus-visible {
  background-color: var(--palette-brown-dark);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow:
    0 14px 30px -4px rgba(56, 36, 24, 0.4),
    0 6px 14px -2px rgba(56, 36, 24, 0.25);
}

.continue-btn:hover .continue-text,
.continue-btn:focus-visible .continue-text {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
  transform: scale(1.05);
}

.continue-btn:hover .continue-arrow,
.continue-btn:focus-visible .continue-arrow {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.continue-btn:active {
  transform: translateY(1px) scale(0.99);
}

.continue-btn:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-on-light);
  outline-offset: 4px;
}

/* Blurb - right side, across from the illustration: a broad overview of the story before the
   learner starts. Sits clear of the Continue button below it. */
.opening-blurb {
  position: absolute;
  left: 45%;
  right: 3%;
  top: 0;
  bottom: 5.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  pointer-events: auto;
  animation: charactersFadeIn 1.1s var(--ease-out-expo) 0.35s backwards;
}

/* Plain text, no card. Sized between body copy and the subtitle (clamp(1.2rem, 2.2vw, 2rem)),
   never larger, in the title's colour. */
.opening-blurb-text {
  margin: 0;
  font-family: var(--font-family-body);
  font-size: clamp(1.1rem, 1.75vw, 1.6rem);
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: -0.005em;
  color: var(--palette-brown-dark);
  text-wrap: pretty;
}

/* Keyframe Animations */
@keyframes titleDropIn {
  0% {
    opacity: 0;
    transform: translateY(-24px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes charactersFadeIn {
  0% {
    opacity: 0;
    transform: translateY(30px) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ==========================================================
   REDUCED MOTION
   Entrances are shortened rather than removed — the continue button's reveal
   is a real state change (it becomes clickable), so it must still happen.
   ========================================================== */

@media (prefers-reduced-motion: reduce) {
  .opening-title-container,
  .characters-container,
  .opening-blurb {
    animation-duration: 0.01s;
    animation-delay: 0s;
  }

  .continue-btn, .resume-btn {
    transition: opacity 0.01s linear, background-color var(--dur-fast) ease;
    transform: none;
  }

  .continue-btn.is-visible, .resume-btn.is-visible {
    transform: none;
  }

  .continue-btn:hover,
  .continue-btn:focus-visible,
  .continue-btn:active,
  .resume-btn:hover,
  .resume-btn:focus-visible,
  .resume-btn:active {
    transform: none;
  }

  .continue-btn .continue-text,
  .continue-btn .continue-arrow,
  .character-image {
    transition: none;
  }

  .continue-btn:hover .continue-text,
  .continue-btn:focus-visible .continue-text {
    transform: none;
  }

  .character-card:hover .character-image {
    transform: none;
  }
}

/* ==========================================================
   RESPONSIVE BREAKPOINTS
   ========================================================== */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
  .opening-screen {
    padding: 2.5rem 2.5rem;
  }

  .characters-container {
    width: 44%;
    height: 58vh;
    left: 2%;
    bottom: 5%;
  }

  .continue-btn-container {
    right: 2.5rem;
    bottom: 2.5rem;
  }

  .opening-blurb {
    left: 49%;
    right: 1%;
  }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
  .opening-screen {
    padding: 1.25rem 1rem max(5.5rem, calc(4.5rem + env(safe-area-inset-bottom, 0px))) 1rem;
    justify-content: flex-start;
    gap: 1rem;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .opening-title-container {
    margin-bottom: 0.25rem;
  }

  .opening-title-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    margin-bottom: 0.35rem;
  }

  .opening-title {
    font-size: clamp(1.5rem, 5.5vw, 2.2rem);
    line-height: 1.18;
  }

  .opening-title .subtitle-part {
    font-size: clamp(0.95rem, 3.8vw, 1.35rem);
    margin-top: 0.25rem;
  }

  .opening-body {
    flex: none;
    position: relative;
    width: 100%;
    height: auto;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: auto 0;
  }

  .characters-container {
    position: relative;
    left: auto;
    bottom: auto;
    width: 100%;
    max-width: 380px;
    height: clamp(230px, 45vh, 380px);
    min-height: 220px;
  }

  .character-card {
    border-radius: var(--radius-lg);
    border-width: 3px;
  }

  .opening-body {
    flex-direction: column;
    gap: 1rem;
  }

  .opening-blurb {
    position: relative;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
    width: 100%;
    max-width: 480px;
  }

  .character-label-pill {
    bottom: 0.75rem;
    font-size: 0.88rem;
    padding: 0.35rem 0.95rem;
  }

  .continue-btn-container {
    position: fixed;
    right: 1.25rem;
    bottom: max(1.25rem, env(safe-area-inset-bottom, 1.25rem));
    left: 1.25rem;
    display: flex;
    justify-content: flex-end;
    pointer-events: none;
    z-index: 50;
  }

  .continue-btn, .resume-btn {
    width: 100%;
    max-width: 300px;
    min-height: 48px;
    justify-content: center;
    padding: 0.9rem 1.6rem;
    font-size: 1.12rem;
    touch-action: manipulation;
  }
}

/* Small mobile devices (<= 480px) */
@media (max-width: 480px) {
  .opening-screen {
    padding-top: max(1rem, env(safe-area-inset-top, 1rem));
  }

  .opening-title {
    font-size: 1.55rem;
  }

  .characters-container {
    height: clamp(200px, 42vh, 320px);
  }

  .continue-btn, .resume-btn {
    max-width: 100%;
  }
}

/* Returning learner: Resume is the primary (right, filled), Start over the secondary (outline).
   Tab order stays Resume first, which is also the likelier choice. */
.continue-btn-container.has-resume {
  flex-direction: row-reverse;
}

.has-resume .resume-btn {
  background-color: var(--palette-teal);
  color: var(--palette-warm-white);
  border-color: transparent;
  box-shadow:
    0 10px 25px -4px rgba(54, 107, 119, 0.35),
    0 4px 10px -2px rgba(54, 107, 119, 0.2);
}

.has-resume .resume-btn:hover,
.has-resume .resume-btn:focus-visible {
  background-color: var(--palette-brown-dark);
  color: var(--palette-warm-white);
}

.has-resume .continue-btn {
  background-color: transparent;
  color: var(--palette-teal-dark);
  border-color: var(--palette-teal-dark);
  box-shadow: none;
}

.has-resume .continue-btn:hover,
.has-resume .continue-btn:focus-visible {
  background-color: var(--palette-teal-dark);
  color: var(--palette-warm-white);
}

.has-resume .continue-btn .continue-arrow {
  display: none;
}

/* Short landscape screens (a phone turned sideways): the illustration and the blurb sit side by
   side in the flow and the screen scrolls, with Continue pinned to the lower right. */
@media (max-height: 600px) and (min-width: 769px) {
  .opening-screen {
    justify-content: flex-start;
    padding: 1rem 1.5rem 5.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .opening-title-container {
    margin-bottom: 0.75rem;
  }

  .opening-title-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.75rem;
    margin-bottom: 0.3rem;
  }

  .opening-title {
    font-size: clamp(1.4rem, 3.4vw, 2rem);
  }

  .opening-title .subtitle-part {
    font-size: clamp(0.95rem, 2vw, 1.25rem);
    margin-top: 0.15rem;
  }

  .opening-body {
    flex: none;
    height: auto;
    align-items: flex-start;
    gap: 1.5rem;
  }

  .characters-container {
    position: sticky;
    top: 0;
    left: auto;
    bottom: auto;
    width: 36%;
    min-width: 0;
    height: min(62vh, 320px);
    flex-shrink: 0;
  }

  .opening-blurb {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    width: auto;
    flex: 1;
    align-self: center;
    justify-content: flex-start;
  }

  .continue-btn-container {
    position: fixed;
    right: 1.25rem;
    bottom: max(1rem, env(safe-area-inset-bottom, 1rem));
  }

  .continue-btn, .resume-btn {
    padding: 0.8rem 1.8rem;
    font-size: 1.05rem;
  }
}
