@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;700&family=Outfit:wght@400;700&display=swap");

:root {
  --primary-yellow: #ffd43b;
  --primary-blue: #4dabf7;
  --primary-red: #fa5252;
  --bg-dark: #0a0b0d;
  --dialog-bg: rgba(10, 11, 13, 0.9);
  --glass-border: rgba(255, 212, 59, 0.4);
  --text-main: #f8f9fa;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Outfit", "Noto Sans TC", sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 70px;
  transition: transform 3s cubic-bezier(0.19, 1, 0.22, 1);
  overflow: hidden;
}

.interior-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url("bg.png");
  background-size: cover;
  background-position: center;
  filter: brightness(0.6) blur(6px);
  transition: filter 2.5s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 0;
}

#app.zoomed {
  transform: scale(1.1);
}

#app.zoomed .interior-bg {
  filter: brightness(1) blur(0px);
}

#app::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    circle at center,
    transparent 45%,
    rgba(0, 0, 0, 0.4) 100%
  );
  pointer-events: none;
  z-index: 1;
}

/* Entry Gate */
.gate-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: flex;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  perspective: 1500px;
  background: #000;
  transition: background 2s cubic-bezier(0.4, 0, 0.2, 1);
}

.gate-overlay.open {
  background: transparent;
  pointer-events: none;
}

.gate-left,
.gate-right {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url("gate.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition:
    transform 2.8s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 2s ease-out;
  z-index: 105;
}

.gate-left {
  clip-path: inset(0 50% 0 0);
  border-right: 1px solid rgba(255, 212, 59, 0.2);
  transform-origin: 0% center;
}

.gate-right {
  clip-path: inset(0 0 0 50%);
  border-left: 1px solid rgba(255, 212, 59, 0.2);
  transform-origin: 100% center;
}

.gate-flare {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #fff;
  z-index: 104;
  opacity: 0;
  pointer-events: none;
}

.gate-overlay.open .gate-flare {
  animation: flashFade 1.5s cubic-bezier(0.19, 1, 0.22, 1) forwards;
}

@keyframes flashFade {
  0% {
    opacity: 0;
    background: #fff;
  }
  30% {
    opacity: 1;
    background: #fff;
    filter: brightness(1.5);
  }
  100% {
    opacity: 0;
    background: rgba(255, 212, 59, 0.2);
  }
}

.gate-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 110;
  transition: opacity 0.5s;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.6);
  padding: 30px 60px;
  border-radius: 60px;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 212, 59, 0.3);
}

.guild-emblem {
  font-size: 3.5rem;
  margin-bottom: 15px;
  filter: drop-shadow(0 0 20px var(--primary-yellow));
  animation: pulse 2s infinite;
}

.gate-text {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--primary-yellow);
  text-shadow: 0 0 10px rgba(255, 212, 59, 0.5);
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.1);
    opacity: 1;
  }
}

.gate-overlay.open .gate-left {
  transform: rotateY(-120deg) scale(1.1);
  opacity: 0;
}
.gate-overlay.open .gate-right {
  transform: rotateY(120deg) scale(1.1);
  opacity: 0;
}
.gate-overlay.open .gate-content {
  opacity: 0;
  pointer-events: none;
}
.gate-overlay.hidden {
  display: none;
}

/* Character Container */
.character-container {
  position: absolute;
  bottom: 25vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, 90vw, 70vh);
  height: auto;
  aspect-ratio: 1 / 1;
  z-index: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}

.mentor-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(2) contrast(1.1)
    drop-shadow(0 0 30px rgba(77, 171, 247, 0.4)) blur(10px);
  mix-blend-mode: screen;
  -webkit-mask-image: radial-gradient(circle, black 45%, transparent 90%);
  mask-image: radial-gradient(circle, black 45%, transparent 90%);
  opacity: 0;
  transform: scale(0) translateY(-50px);
  transition:
    opacity 1.2s ease-out,
    transform 1.8s cubic-bezier(0.19, 1, 0.22, 1),
    filter 1.5s ease-out;
}

.mentor-img.flying {
  opacity: 1;
  transform: scale(1) translateY(0);
  filter: brightness(1.2) contrast(1.1)
    drop-shadow(0 0 30px rgba(77, 171, 247, 0.4)) blur(0px);
}

.mentor-img.active {
  opacity: 1;
  transform: scale(1) translateY(0);
  filter: brightness(1.2) contrast(1.1)
    drop-shadow(0 0 30px rgba(77, 171, 247, 0.4)) blur(0px);
  animation: floating 4s ease-in-out infinite;
}

@keyframes floating {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-20px);
  }
}

/* Dialogue Box */
.dialogue-box {
  position: relative;
  width: 70%;
  max-width: min(800px, 92vw);
  min-height: clamp(140px, 20vh, 200px);
  background: var(--dialog-bg);
  backdrop-filter: blur(15px);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: clamp(15px, 3vw, 20px) clamp(20px, 5vw, 35px) clamp(20px, 4vw, 30px);
  z-index: 10;
  cursor: pointer;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.6s cubic-bezier(0.19, 1, 0.22, 1);
}

.dialogue-box.visible {
  opacity: 1;
  transform: translateY(0);
}

.speaker-name {
  position: absolute;
  top: -18px;
  left: 40px;
  background: var(--primary-yellow);
  color: #000;
  padding: 4px clamp(15px, 2vw, 20px);
  font-weight: 700;
  font-size: clamp(0.85rem, 1.5vw, 0.9rem);
  letter-spacing: 1px;
}

.dialogue-text {
  flex-grow: 1;
  font-size: clamp(1rem, 1.8vw, 1.1rem);
  line-height: 1.6;
  color: var(--text-main);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.dialogue-text b {
  color: var(--primary-yellow);
  font-weight: 700;
}

.dialogue-text a {
  color: var(--primary-blue);
  text-decoration: underline;
  text-underline-offset: 4px;
  font-weight: 700;
  transition: color 0.3s;
}

.dialogue-text a:hover {
  color: var(--primary-yellow);
}

.tavern-link {
  display: inline-block;
  margin-top: 10px;
  padding: 5px 15px;
  background: rgba(77, 171, 247, 0.1);
  border: 1px solid var(--primary-blue);
  border-radius: 4px;
  animation: glow 2s infinite alternate;
}

@keyframes glow {
  from {
    box-shadow: 0 0 5px rgba(77, 171, 247, 0.2);
  }
  to {
    box-shadow: 0 0 20px rgba(77, 171, 247, 0.5);
  }
}

/* Navigation */
.dialogue-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
}

.nav-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.6);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.3s;
  opacity: 0;
  pointer-events: none;
}

.nav-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

.nav-btn:hover {
  color: #fff;
  border-color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

.next-indicator {
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 12px solid var(--primary-yellow);
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(8px);
  }
}

/* End Controls */
.end-controls {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  z-index: 20;
  opacity: 0;
  visibility: hidden;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.end-controls.visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

.action-btn {
  padding: 15px 40px;
  font-size: 1.3rem;
  font-weight: 700;
  background: var(--primary-yellow);
  color: #000;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 0 30px rgba(255, 212, 59, 0.4);
  transition: all 0.3s;
}

.action-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 0 60px rgba(255, 212, 59, 0.7);
  background: #fff;
}

/* Scanline Effect */
.scanlines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0) 50%,
    rgba(0, 0, 0, 0.03) 50%
  );
  background-size: 100% 4px;
  pointer-events: none;
  z-index: 5;
}

/* Responsive Web Design (RWD) */
@media (max-width: 768px) {
  #app {
    padding-bottom: calc(120px + env(safe-area-inset-bottom, 20px));
  }

  .character-container {
    width: 90vw;
    height: 90vw;
    bottom: 220px;
  }

  .dialogue-box {
    width: 88% !important;
    margin: 0 auto;
    padding: 20px 25px;
    min-height: 140px;
    position: relative;
    left: auto !important;
    transform: translateY(0) !important;
    margin-bottom: max(10px, env(safe-area-inset-bottom, 20px));
  }

  .speaker-name {
    left: 15px;
    font-size: 0.9rem;
    padding: 3px 15px;
    top: -15px;
  }

  .dialogue-text {
    font-size: 1.1rem;
    line-height: 1.5;
    word-break: break-word;
  }

  .gate-content {
    padding: 20px 30px;
    width: 80%;
  }

  .guild-emblem {
    font-size: 2.5rem;
    margin-bottom: 15px;
  }

  .gate-text {
    font-size: 1.1rem;
    letter-spacing: 2px;
  }

  .action-btn {
    padding: 12px 30px;
    font-size: 1.1rem;
  }
}

@media (max-width: 480px) {
  .character-container {
    bottom: 240px;
  }

  .dialogue-text {
    font-size: 1.05rem;
  }
}
