/* Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background-color: #09070f;
  color: #f3f4f6;
  font-family: 'Outfit', 'Noto Sans JP', sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* Game Main Container - 16:9 Aspect Ratio */
.game-container {
  position: relative;
  width: 100vw;
  height: 56.25vw; /* 16:9 */
  max-width: 1280px;
  max-height: 720px;
  background: #000;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(147, 51, 234, 0.2);
  border-radius: 8px;
  overflow: hidden;
}

@media (max-aspect-ratio: 16/9) {
  .game-container {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }
}

/* Background Layer */
.bg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#bg-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 1.2s cubic-bezier(0.25, 1, 0.5, 1), filter 0.8s ease;
}

/* Background Overlays */
.sunlight-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 85% 30%, rgba(255, 230, 180, 0.3) 0%, rgba(255, 190, 120, 0.1) 40%, transparent 70%);
  mix-blend-mode: screen;
  pointer-events: none;
  transition: opacity 1s ease;
}

.vignette-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, transparent 40%, rgba(10, 5, 20, 0.75) 100%);
  pointer-events: none;
}

.horror-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, rgba(139, 0, 0, 0.25) 0%, rgba(15, 0, 10, 0.85) 100%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 1s ease;
  z-index: 2;
}

.horror-active .horror-overlay {
  opacity: 1;
  animation: horrorPulse 4s infinite alternate ease-in-out;
}

@keyframes horrorPulse {
  0% { opacity: 0.6; }
  100% { opacity: 0.9; }
}

/* Floating Dust Particles */
.dust-particles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(2px 2px at 20px 30px, rgba(255, 255, 255, 0.4), rgba(0,0,0,0)),
                    radial-gradient(3px 3px at 40px 70px, rgba(255, 240, 200, 0.3), rgba(0,0,0,0)),
                    radial-gradient(2px 2px at 90px 40px, rgba(255, 255, 255, 0.5), rgba(0,0,0,0)),
                    radial-gradient(3px 3px at 160px 120px, rgba(255, 210, 160, 0.4), rgba(0,0,0,0));
  background-repeat: repeat;
  background-size: 250px 250px;
  animation: particleFloat 20s linear infinite;
  pointer-events: none;
  opacity: 0.7;
}

@keyframes particleFloat {
  0% { background-position: 0 0; }
  100% { background-position: 250px 500px; }
}

/* Academy Header Top Left */
.academy-header {
  position: absolute;
  top: 20px;
  left: 24px;
  z-index: 10;
  background: rgba(15, 11, 28, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-left: 3px solid #c084fc;
  padding: 8px 16px;
  border-radius: 0 6px 6px 0;
  pointer-events: none;
}

.academy-kanji {
  font-family: 'Cinzel', 'Noto Sans JP', serif;
  font-size: 0.75rem;
  color: #c084fc;
  letter-spacing: 3px;
}

.academy-name {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: #ffffff;
  letter-spacing: 1px;
}

.scene-tag {
  font-size: 0.75rem;
  color: #9ca3af;
  margin-top: 2px;
}

/* UI Toolbar Top Right */
.ui-toolbar {
  position: absolute;
  top: 20px;
  right: 24px;
  z-index: 10;
  display: flex;
  gap: 10px;
}

.ui-btn {
  background: rgba(20, 15, 35, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(192, 132, 252, 0.3);
  color: #e5e7eb;
  padding: 8px 14px;
  border-radius: 20px;
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.25s ease;
}

.ui-btn:hover {
  background: rgba(147, 51, 234, 0.5);
  border-color: #c084fc;
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(147, 51, 234, 0.4);
}

.ui-btn.btn-active {
  background: #9333ea;
  border-color: #e9d5ff;
  color: #fff;
  box-shadow: 0 0 12px rgba(192, 132, 252, 0.6);
}

/* Character Sprite Stage Layer & Depth Planes */
.sprite-stage {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
}

.character-sprite {
  position: absolute;
  bottom: 0px;
  height: 86%;
  max-width: 48%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  transform-origin: bottom center;
  transition: left 0.75s cubic-bezier(0.25, 1, 0.5, 1),
              right 0.75s cubic-bezier(0.25, 1, 0.5, 1),
              bottom 0.75s cubic-bezier(0.25, 1, 0.5, 1),
              transform 0.75s cubic-bezier(0.25, 1, 0.5, 1),
              filter 0.6s ease,
              opacity 0.6s ease;
  opacity: 1;
}

.character-sprite img {
  height: 100%;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 15px 25px rgba(0, 0, 0, 0.65));
  transition: filter 0.5s ease;
}

/* Realistic Ground Contact Shadow */
.sprite-shadow {
  position: absolute;
  bottom: -6px;
  width: 75%;
  height: 22px;
  background: radial-gradient(ellipse at center, rgba(10, 5, 20, 0.85) 0%, rgba(10, 5, 20, 0.4) 45%, transparent 70%);
  border-radius: 50%;
  filter: blur(4px);
  pointer-events: none;
  z-index: -1;
  transition: transform 0.6s ease, opacity 0.6s ease;
}

/* Spatial Position Anchors (Grounded in Classroom) */
.pos-window {
  left: 10%;
  right: auto;
}

.pos-left-center {
  left: 26%;
  right: auto;
}

.pos-center {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

.pos-right-center {
  right: 24%;
  left: auto;
}

.pos-door {
  right: 8%;
  left: auto;
}

/* Depth Layers (Perspective & Scale) */
.depth-bg {
  z-index: 4;
  transform: scale(0.74);
  bottom: 8%;
  filter: brightness(0.72) contrast(0.92);
}
.depth-bg .sprite-shadow {
  transform: scale(0.7);
  opacity: 0.6;
}

.depth-mg {
  z-index: 6;
  transform: scale(0.90);
  bottom: 1%;
  filter: brightness(0.92);
}
.depth-mg .sprite-shadow {
  transform: scale(0.95);
  opacity: 0.85;
}

.depth-fg {
  z-index: 8;
  transform: scale(1.06);
  bottom: -4%;
  filter: brightness(1.05);
}
.depth-fg .sprite-shadow {
  transform: scale(1.2);
  opacity: 0.95;
}

/* Natural Micro-Animations (Discreet, Organic, Slow) */

/* 1. Breathing Idle Animation */
.character-sprite.state-idle img,
.character-sprite.state-waiting img {
  animation: naturalBreathing 5s infinite ease-in-out;
}

@keyframes naturalBreathing {
  0%, 100% {
    transform: translateY(0px) scale(1, 1);
  }
  50% {
    transform: translateY(-2px) scale(1.004, 1.008);
  }
}

/* 2. Speaking Body Sway (Subtle micro tilt and speech rhythm) */
.character-sprite.state-speaking img {
  animation: speakingSway 3.6s infinite ease-in-out;
  filter: drop-shadow(0 0 20px rgba(192, 132, 252, 0.45)) drop-shadow(0 15px 25px rgba(0,0,0,0.7));
}

#sprite-haru.state-speaking img {
  filter: drop-shadow(0 0 20px rgba(59, 130, 246, 0.45)) drop-shadow(0 15px 25px rgba(0,0,0,0.7));
}

@keyframes speakingSway {
  0%, 100% {
    transform: translateY(0px) rotate(0deg) scale(1.01, 1.01);
  }
  33% {
    transform: translateY(-2.5px) rotate(0.4deg) scale(1.012, 1.015);
  }
  66% {
    transform: translateY(-1px) rotate(-0.3deg) scale(1.01, 1.012);
  }
}

/* 3. Surprised State */
.character-sprite.state-surprised img {
  animation: naturalSurprise 0.5s ease-out;
}

@keyframes naturalSurprise {
  0% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-8px) scale(1.02, 1.03); }
  100% { transform: translateY(-2px) scale(1.01, 1.01); }
}

/* 4. Nervous / Quiver State */
.character-sprite.state-nervous img {
  animation: nervousQuiver 2s infinite ease-in-out;
}

@keyframes nervousQuiver {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-1px) translateY(-1px); }
  50% { transform: translateX(1px) translateY(0); }
  75% { transform: translateX(-0.5px) translateY(-1px); }
}

/* 5. Ominous Darkened Tint State (Haru sinister dialogue) */
.character-sprite.state-ominous {
  filter: brightness(0.7) contrast(1.2) drop-shadow(0 0 25px rgba(180, 0, 0, 0.5));
}
.character-sprite.state-ominous img {
  animation: ominousPulse 4s infinite alternate ease-in-out;
}

@keyframes ominousPulse {
  0% { transform: translateY(0) scale(1.02); }
  100% { transform: translateY(-3px) scale(1.025); }
}

/* Sprite States */
.character-sprite.sprite-active {
  z-index: 9;
}

.character-sprite.sprite-hidden {
  opacity: 0;
  transform: translateY(30px) scale(0.85);
  pointer-events: none;
}

/* Sprite Animations */
.anim-bounce {
  animation: spriteBounce 0.5s ease;
}

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

.anim-shake {
  animation: spriteShake 0.4s ease;
}

@keyframes spriteShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-12px); }
  40%, 80% { transform: translateX(12px); }
}

.anim-enter-right {
  animation: slideRightIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideRightIn {
  from { transform: translateX(100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Dialogue Box */
.dialogue-box {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 1100px;
  min-height: 145px;
  background: rgba(13, 10, 25, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(192, 132, 252, 0.35);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 24px 30px 20px 30px;
  z-index: 10;
  cursor: pointer;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.dialogue-box:hover {
  border-color: rgba(192, 132, 252, 0.6);
  box-shadow: 0 15px 40px rgba(147, 51, 234, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* Speaker Badge */
.speaker-badge {
  position: absolute;
  top: -18px;
  left: 36px;
  padding: 6px 22px;
  border-radius: 20px;
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
}

.narration-badge {
  background: linear-gradient(135deg, #4b5563 0%, #1f2937 100%);
  border: 1px solid #9ca3af;
  color: #f3f4f6;
}

.yui-badge {
  background: linear-gradient(135deg, #a855f7 0%, #7e22ce 100%);
  border: 1px solid #f0abfc;
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(168, 85, 247, 0.5);
}

.haru-badge {
  background: linear-gradient(135deg, #2563eb 0%, #1e3a8a 100%);
  border: 1px solid #93c5fd;
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.5);
}

.speaker-sub {
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.85;
}

/* Dialogue Content & Text */
.dialogue-content {
  margin-top: 6px;
  font-size: 1.15rem;
  line-height: 1.65;
  color: #f9fafb;
  min-height: 70px;
  word-wrap: break-word;
  font-family: 'Outfit', sans-serif;
}

#dialogue-text {
  white-space: pre-line;
}

/* Click to Continue Arrow Indicator */
.next-indicator {
  position: absolute;
  bottom: 12px;
  right: 24px;
  color: #c084fc;
  font-size: 1rem;
  animation: arrowBounce 1.2s infinite ease-in-out;
  opacity: 0.9;
}

@keyframes arrowBounce {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50% { transform: translateY(6px); opacity: 1; }
}

/* Modals */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(6, 4, 14, 0.85);
  backdrop-filter: blur(10px);
  z-index: 50;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.modal-hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background: rgba(18, 14, 32, 0.95);
  border: 1px solid #c084fc;
  box-shadow: 0 0 40px rgba(147, 51, 234, 0.4);
  border-radius: 16px;
  padding: 32px 36px;
  width: 90%;
  max-width: 480px;
  text-align: center;
  animation: modalScaleUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScaleUp {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-kanji {
  font-family: 'Cinzel', 'Noto Sans JP', serif;
  color: #c084fc;
  font-size: 0.9rem;
  letter-spacing: 4px;
  margin-bottom: 4px;
}

.modal-header h3 {
  font-family: 'Sora', sans-serif;
  font-size: 1.4rem;
  color: #ffffff;
  margin-bottom: 8px;
}

.modal-sub {
  color: #9ca3af;
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group input {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(192, 132, 252, 0.4);
  border-radius: 8px;
  padding: 14px 18px;
  font-size: 1.1rem;
  color: #ffffff;
  font-family: 'Outfit', sans-serif;
  text-align: center;
  outline: none;
  transition: all 0.25s ease;
}

.input-group input:focus {
  border-color: #c084fc;
  box-shadow: 0 0 15px rgba(192, 132, 252, 0.5);
  background: rgba(255, 255, 255, 0.14);
}

/* Primary Button */
.primary-btn {
  background: linear-gradient(135deg, #9333ea 0%, #6b21a8 100%);
  border: 1px solid #e9d5ff;
  color: #ffffff;
  padding: 14px 28px;
  border-radius: 8px;
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 4px 15px rgba(147, 51, 234, 0.4);
}

.primary-btn:hover {
  background: linear-gradient(135deg, #a855f7 0%, #7e22ce 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.6);
}

/* Log Modal Drawer */
.log-card {
  max-width: 720px;
  width: 95%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  text-align: left;
}

.log-card .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 16px;
  margin-bottom: 16px;
}

.close-btn {
  background: transparent;
  border: none;
  color: #9ca3af;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
}

.close-btn:hover {
  color: #fff;
}

.log-list {
  overflow-y: auto;
  max-height: 55vh;
  padding-right: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.log-entry {
  background: rgba(255, 255, 255, 0.04);
  border-left: 3px solid #9ca3af;
  padding: 10px 14px;
  border-radius: 0 6px 6px 0;
}

.log-entry.log-yui {
  border-left-color: #a855f7;
}

.log-entry.log-haru {
  border-left-color: #3b82f6;
}

.log-speaker {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.log-speaker.yui { color: #c084fc; }
.log-speaker.haru { color: #60a5fa; }
.log-speaker.narrator { color: #9ca3af; }

.log-text {
  font-size: 0.95rem;
  color: #e5e7eb;
  line-height: 1.5;
}

/* End Screen */
.end-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, #150a26 0%, #05020c 100%);
  z-index: 60;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  transition: opacity 1s ease;
}

.screen-hidden {
  opacity: 0;
  pointer-events: none;
}

.end-title {
  font-family: 'Cinzel', serif;
  font-size: 2.8rem;
  color: #c084fc;
  letter-spacing: 4px;
  margin-bottom: 8px;
  text-shadow: 0 0 25px rgba(192, 132, 252, 0.6);
}

.end-subtitle {
  font-family: 'Sora', sans-serif;
  font-size: 1.5rem;
  color: #e5e7eb;
  letter-spacing: 3px;
  margin-bottom: 12px;
}

.end-credits {
  color: #9ca3af;
  font-size: 0.95rem;
  margin-bottom: 36px;
}

.end-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 14px 24px;
  border-radius: 8px;
  font-family: 'Sora', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.25s ease;
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.pulse-btn {
  animation: pulseGlow 2s infinite alternate;
}

@keyframes pulseGlow {
  0% { box-shadow: 0 0 15px rgba(147, 51, 234, 0.4); }
  100% { box-shadow: 0 0 30px rgba(192, 132, 252, 0.8); }
}

/* Start Overlay */
.start-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(7, 4, 16, 0.94);
  backdrop-filter: blur(12px);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.start-card {
  max-width: 500px;
  padding: 40px;
}

.start-title-kanji {
  font-family: 'Cinzel', 'Noto Sans JP', serif;
  color: #c084fc;
  font-size: 1.6rem;
  letter-spacing: 8px;
  margin-bottom: 6px;
}

.start-title {
  font-family: 'Cinzel', sans-serif;
  font-size: 2.4rem;
  color: #ffffff;
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.start-scene {
  color: #a855f7;
  font-size: 0.95rem;
  letter-spacing: 2px;
  margin-bottom: 32px;
}

.start-btn {
  background: linear-gradient(135deg, #a855f7 0%, #7e22ce 100%);
  border: 1px solid #f0abfc;
  color: #ffffff;
  padding: 16px 36px;
  border-radius: 30px;
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
  letter-spacing: 1px;
  box-shadow: 0 10px 30px rgba(168, 85, 247, 0.5);
  transition: all 0.3s ease;
}

.start-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 35px rgba(192, 132, 252, 0.8);
}
