/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Noto Sans KR', 'Noto Sans JP', 'Noto Sans SC', sans-serif;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

/* ===== Game Container ===== */
#game-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#game-wrapper {
  position: relative;
  transition: transform 3s cubic-bezier(0.25, 0.1, 0.25, 1);
}

#game-canvas {
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

/* ===== Dialogue Overlay ===== */
#dialogue-overlay {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  padding: 24px 32px 36px;
  border-radius: 12px 12px 0 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.9) 25%);
  z-index: 10;
  pointer-events: none;
}

#dialogue-speaker {
  font-size: 14px;
  font-weight: 700;
  color: rgba(180, 200, 255, 0.8);
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}

#dialogue-text {
  font-size: 18px;
  font-weight: 300;
  color: #e8e8e8;
  line-height: 1.7;
  min-height: 54px;
  word-break: normal;
  overflow-wrap: break-word;
}

#dialogue-prompt {
  visibility: hidden;
  text-align: right;
  color: rgba(255,255,255,0.5);
  font-size: 14px;
  margin-top: 8px;
  animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ===== Speaker Colors ===== */
#dialogue-overlay[data-speaker="oracle"] #dialogue-speaker { color: rgba(180, 200, 255, 0.8); }
#dialogue-overlay[data-speaker="haeun"] #dialogue-speaker { color: rgba(255, 200, 180, 0.8); }
#dialogue-overlay[data-speaker="narrator"] #dialogue-speaker { color: rgba(180, 180, 180, 0.6); }
#dialogue-overlay[data-speaker="system"] #dialogue-speaker {
  color: rgba(255, 80, 80, 0.9);
  font-family: monospace;
}
#dialogue-overlay[data-speaker="system"] #dialogue-text {
  font-family: monospace;
  color: rgba(255, 80, 80, 0.8);
}

/* ===== Ending Layer ===== */
#ending-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  pointer-events: none;
}

/* ===== Perspective Container (3D) ===== */
#perspective-container {
  perspective: 800px;
  perspective-origin: 50% 40%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#phone-hand-unit {
  position: relative;
  transform-style: preserve-3d;
  will-change: transform;
}

#phone-hand-unit.picking-up {
  animation: phonePickup 4s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

@keyframes phonePickup {
  0%   { transform: rotateX(2deg) rotateY(-1deg) translateZ(10px); opacity: 1; }
  30%  { transform: rotateX(-35deg) rotateY(8deg) rotateZ(-3deg) translateZ(60px) translateY(-30px); opacity: 1; }
  45%  { transform: rotateX(-35deg) rotateY(8deg) rotateZ(-3deg) translateZ(60px) translateY(-30px); opacity: 1; }
  100% { transform: rotateX(-55deg) rotateY(12deg) rotateZ(-5deg) translateZ(-100px) translateY(120vh); opacity: 0; }
}

@keyframes handGripWobble {
  0%, 100% { transform: rotateX(0deg) rotateY(0deg); }
  25% { transform: rotateX(1.5deg) rotateY(-0.5deg); }
  50% { transform: rotateX(0.5deg) rotateY(0.5deg); }
  75% { transform: rotateX(2deg) rotateY(-1deg); }
}

/* ===== Hand Silhouette ===== */
#hand-silhouette {
  position: absolute;
  top: -10px;
  left: -15px;
  width: calc(100% + 30px);
  height: calc(100% + 20px);
  z-index: -1;
  opacity: 0;
  transition: opacity 1.5s ease;
  pointer-events: none;
}

#hand-silhouette.visible {
  opacity: 1;
}

/* ===== Phone Frame ===== */
#phone-frame {
  position: relative;
  width: 240px;
  height: 480px;
  background: #1a1a1a;
  border-radius: 28px;
  border: 3px solid #333;
  padding: 40px 8px 40px;
  box-shadow: 0 0 40px rgba(0,0,0,0.8), inset 0 0 2px rgba(255,255,255,0.05);
  opacity: 0;
  transition: opacity 1.5s ease;
}

#phone-frame::before {
  content: '';
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 6px;
  background: #222;
  border-radius: 3px;
}

#phone-screen {
  width: 100%;
  height: 100%;
  background: #0a0a0a;
  border-radius: 4px;
  overflow: hidden;
}

/* ===== Chat UI ===== */
#chat-ui {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #0a0a0a;
}

#chat-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 13px;
  color: #aaa;
}

.chat-avatar {
  color: #06cf68;
  font-size: 16px;
  margin-right: 8px;
}

#chat-messages {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.chat-msg {
  max-width: 85%;
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.5;
  word-break: normal;
  overflow-wrap: break-word;
  opacity: 0;
  animation: chatFadeIn 0.3s ease forwards;
}

.chat-msg.user {
  align-self: flex-end;
  background: #2a5298;
  color: #e8e8e8;
  border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: #1e1e1e;
  color: #ccc;
  border-bottom-left-radius: 4px;
}

@keyframes chatFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg.search {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  text-align: center;
  max-width: 100%;
  align-self: center;
}
.search-label { font-size: 10px; color: #888; margin-bottom: 6px; }
.search-sources { display: flex; justify-content: center; }
.search-icon + .search-icon { margin-left: 8px; }
.search-icon {
  width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: #fff;
}
.search-icon.grok { background: #000; border: 1px solid #555; }
.search-icon.claude { background: #d4845e; }
.search-icon.chatgpt { background: #10a37f; }
.search-icon.gemini { background: #4285f4; }

/* (Old #hand-svg removed — replaced by #hand-silhouette in phone-hand-unit) */

/* ===== Ending Text ===== */
#ending-text {
  position: fixed;
  bottom: 18%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  font-weight: 300;
  color: rgba(255,255,255,0.6);
  z-index: 25;
  opacity: 0;
  transition: opacity 1.5s ease;
  text-shadow: 0 0 30px rgba(0,0,0,1);
}

#ending-text.visible {
  opacity: 1;
}

/* ===== Title Card ===== */
#title-card {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 30;
  background: #000;
  opacity: 0;
  transition: opacity 2s ease;
}

#title-card.visible {
  opacity: 1;
}

#title-main {
  font-size: 28px;
  font-weight: 300;
  color: rgba(255,255,255,0.85);
  letter-spacing: 4px;
  margin-bottom: 16px;
}

#title-sub {
  font-size: 16px;
  font-weight: 300;
  color: rgba(255,255,255,0.35);
  letter-spacing: 2px;
}

#restart-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 35%;
  font-size: 14px;
  color: rgba(255,255,255,0.35);
  cursor: pointer;
  transition: opacity 1.5s ease, color 0.3s ease;
  opacity: 0;
}
#restart-btn.visible { opacity: 1; }
#restart-btn:hover { color: rgba(255,255,255,0.7); }

#credit {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 12%;
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  text-decoration: none;
  cursor: pointer;
  transition: opacity 1.5s ease, color 0.3s ease;
  opacity: 0;
  letter-spacing: 1px;
}
#credit.visible { opacity: 1; }
#credit:hover { color: rgba(255,255,255,0.7); }

/* ===== Language Select ===== */
#lang-select {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 60;
}

#lang-select button {
  margin: 10px 0;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-family: 'Noto Sans KR', 'Noto Sans JP', 'Noto Sans SC', sans-serif;
  font-size: 18px;
  font-weight: 300;
  padding: 8px 24px;
  cursor: pointer;
  transition: color 0.3s ease;
  letter-spacing: 1px;
}

#lang-select button:hover {
  color: rgba(255, 255, 255, 1);
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

/* ===== Fade Overlay ===== */
#fade-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  transition-property: opacity;
  transition-timing-function: ease;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 600px) {
  #dialogue-text {
    font-size: 16px;
  }

  #dialogue-speaker {
    font-size: 13px;
  }

  #dialogue-overlay {
    max-width: 100%;
    border-radius: 0;
    padding: 16px 20px 28px;
  }

  #phone-frame {
    width: 180px;
    height: 360px;
    border-radius: 22px;
    padding: 30px 6px 30px;
  }

  #title-main {
    font-size: 22px;
    letter-spacing: 2px;
  }

  #title-sub {
    font-size: 14px;
  }

  /* Mobile: reduced 3D rotation for smaller screens */
  @keyframes phonePickup {
    0%   { transform: rotateX(2deg) rotateY(-1deg) translateZ(8px); opacity: 1; }
    30%  { transform: rotateX(-28deg) rotateY(6deg) rotateZ(-2deg) translateZ(40px) translateY(-20px); opacity: 1; }
    45%  { transform: rotateX(-28deg) rotateY(6deg) rotateZ(-2deg) translateZ(40px) translateY(-20px); opacity: 1; }
    100% { transform: rotateX(-45deg) rotateY(10deg) rotateZ(-4deg) translateZ(-80px) translateY(120vh); opacity: 0; }
  }
}

@media (max-width: 400px) {
  #phone-frame {
    width: 140px;
    height: 280px;
  }
}

/* ===== Glitch animation helpers ===== */
@keyframes glitchShake {
  0% { transform: translate(0); }
  20% { transform: translate(-2px, 1px); }
  40% { transform: translate(2px, -1px); }
  60% { transform: translate(-1px, -2px); }
  80% { transform: translate(1px, 2px); }
  100% { transform: translate(0); }
}

.glitch-shake {
  animation: glitchShake 0.1s linear infinite;
}

/* (Old pocket-phase removed — replaced by 3D phonePickup animation) */
