/* ==========================================================================
   2D Multiplayer Virtual Office — Temple Aesthetics & Animal Crossing Theme
   規格依據: Specification Section 2 (Frontend HTML5 Wrapper & Temple-Styled Overlays)
   ========================================================================== */

:root {
  /* 神殿風古典與動森療癒自定義色彩變數 (Custom CSS Variables) */
  --temple-gold: #FFD166;
  --temple-gold-dark: #B38300;
  --temple-crimson: #E63946;
  --temple-crimson-dark: #9D0208;
  --temple-sand: #F7EAD0;
  --temple-sand-border: #D8C3A5;
  --temple-teal: #78C0A8;
  --temple-teal-dark: #2D6A4F;
  --temple-slate: #2B2D42;
  --temple-glass-bg: rgba(255, 252, 245, 0.68);
  --temple-glass-border: rgba(255, 255, 255, 0.75);
  --temple-shadow: 0 10px 30px -4px rgba(43, 45, 66, 0.18);
  --temple-glow: 0 0 16px rgba(255, 209, 102, 0.7);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body, html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #B8E1D9;
  font-family: 'Nunito', 'Quicksand', system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  color: var(--temple-slate);
}

/* ==========================================================================
   1. DOM 階層核心容器 (DOM Hierarchy Setup)
   ========================================================================== */

/* #game-container: 全螢幕畫布容器 */
#game-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
  touch-action: none;
}

/* #youtube-player-layer: 懸浮在 Canvas 之上的多媒體串流專屬層 */
#youtube-player-layer {
  position: absolute;
  top: 70px;
  right: 16px;
  width: 320px;
  height: 180px;
  border-radius: 1.25rem;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.3), inset 0 2px 4px rgba(255, 255, 255, 0.4);
  background: #000000;
  z-index: 25;
  pointer-events: auto;
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

/* 收縮摺疊狀態: 縮小為透明隱藏，但保留 DOM 內的 iframe 讓音樂持續無縫播送不中斷 */
#youtube-player-layer.is-collapsed {
  transform: scale(0.01) translate(400px, -200px) !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* 懸浮播放器頂部控制列 (Draggable Header Bar) */
#youtube-header-bar {
  opacity: 0.88;
  transition: opacity 0.2s ease;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
#youtube-header-bar:active {
  cursor: grabbing;
}
#youtube-player-layer:hover #youtube-header-bar {
  opacity: 1;
}

#youtube-floating-icon {
  cursor: grab;
  user-select: none;
  touch-action: none;
}
#youtube-floating-icon:active {
  cursor: grabbing;
}

/* #chat-overlay: 左下象限懸浮滾動聊天系統 */
#chat-overlay {
  position: absolute;
  bottom: 16px;
  left: 16px;
  width: 340px;
  max-width: calc(100vw - 140px);
  z-index: 30;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* #mobile-action-hud: 右下象限神殿風格控制台 */
#mobile-action-hud {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 30;
  pointer-events: auto;
}

/* ==========================================================================
   2. 神殿美學毛玻璃視覺樣式 (Temple Aesthetics & Frosted Glass)
   ========================================================================== */
.temple-glass-card {
  background: var(--temple-glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid var(--temple-glass-border);
  border-radius: 1.25rem;
  box-shadow: var(--temple-shadow);
  color: var(--temple-slate);
}

/* 聊天滾動日誌視窗 (Scrolling Message History Log) */
.chat-history-window {
  height: 160px;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 192, 168, 0.6) transparent;
}
.chat-history-window::-webkit-scrollbar {
  width: 4px;
}
.chat-history-window::-webkit-scrollbar-thumb {
  background: rgba(120, 192, 168, 0.6);
  border-radius: 4px;
}

.chat-bubble-log {
  background: rgba(255, 255, 255, 0.85);
  border: 1.5px solid rgba(120, 192, 168, 0.4);
  border-radius: 0.85rem;
  padding: 4px 8px;
  font-size: 11px;
  line-height: 1.35;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  animation: fadeInLog 0.2s ease-out;
}

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

/* ==========================================================================
   3. 神殿透明懸浮動作按鈕 (Temple Action Overlays & Scaling)
   ========================================================================== */
.temple-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255, 253, 245, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2.5px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 8px 20px rgba(43, 45, 66, 0.16), inset 0 2px 4px rgba(255, 255, 255, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--temple-slate);
  cursor: pointer;
  touch-action: none;
  transition: transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.15s ease, opacity 0.2s ease;
  user-select: none;
  padding: 6px;
}

/* 點擊主動縮放 (tap active scaling state: transform: scale(0.95)) */
.temple-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.65);
}

.temple-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(43, 45, 66, 0.22);
}

.temple-btn-icon {
  font-size: 22px;
  line-height: 1;
}

.temple-btn-text {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.5px;
  margin-top: 2px;
  color: #1E293B;
}

/* 特殊按鈕色彩樣式 */
.btn-gold {
  background: rgba(255, 209, 102, 0.4);
  border-color: var(--temple-gold);
}
.btn-crimson {
  background: rgba(230, 57, 70, 0.35);
  border-color: var(--temple-crimson);
}
.btn-club-active {
  background: rgba(168, 85, 247, 0.5) !important;
  border-color: #C084FC !important;
  box-shadow: 0 0 20px #A855F7, 0 8px 24px rgba(0, 0, 0, 0.3) !important;
  animation: pulseNeon 1s infinite alternate;
}

@keyframes pulseNeon {
  from { filter: drop-shadow(0 0 4px #A855F7); }
  to { filter: drop-shadow(0 0 14px #EC4899); }
}

/* ==========================================================================
   4. 虛擬搖桿底盤 (Virtual Joystick)
   ========================================================================== */
#joystick-touch-zone {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 44vw;
  height: 44vh;
  z-index: 20;
  pointer-events: auto;
  touch-action: none;
}

#virtual-joystick-base {
  position: absolute;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(8px);
  border: 3px solid rgba(255, 255, 255, 0.65);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  transform: translate(-50%, -50%);
  display: none;
  pointer-events: none;
}

#virtual-joystick-thumb {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46px;
  height: 46px;
  margin-top: -23px;
  margin-left: -23px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #52B788, #2D6A4F);
  border: 2px solid #FFFFFF;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

/* ==========================================================================
   5. 🪩 夜店派對模式全域動態濾鏡覆蓋 (Club Disco Overlay)
   ========================================================================== */
#club-disco-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.8s ease;
  background: radial-gradient(circle at 50% 30%, rgba(168, 85, 247, 0.25), rgba(236, 72, 153, 0.2), rgba(15, 23, 42, 0.4));
  mix-blend-mode: color-burn;
}

#club-disco-overlay.active {
  opacity: 1;
  animation: discoFlicker 3s infinite alternate ease-in-out;
}

@keyframes discoFlicker {
  0% { filter: hue-rotate(0deg); }
  50% { filter: hue-rotate(180deg); }
  100% { filter: hue-rotate(360deg); }
}

/* ==========================================================================
   6. 嵌入式貪吃蛇街機視窗 (Snake Arcade Modal)
   ========================================================================== */
.snake-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

.snake-arcade-box {
  width: 380px;
  background: #FFFDF9;
  border: 4px solid var(--temple-gold);
  border-radius: 1.5rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.snake-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px dashed #E2E8F0;
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
}

.snake-close-btn {
  background: #FEE2E2;
  color: #DC2626;
  border: 2px solid #FCA5A5;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.snake-hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0 0.5rem 0.5rem 0.5rem;
}

.snake-canvas-container {
  position: relative;
  border: 4px solid #1E293B;
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.5);
}

.snake-game-over {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.snake-footer {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
}

.snake-action-btn {
  background: #FEF3C7;
  border: 2px solid var(--temple-gold);
  color: #92400E;
  font-weight: 800;
  padding: 0.35rem 0.75rem;
  border-radius: 0.75rem;
  cursor: pointer;
  font-size: 12px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1.0); }
}

/* ==========================================================================
   7. 移動端專屬整潔排版與 1 行聊天室折疊 (Mobile-Only Tidy View & 1-Line Chat Collapse)
   嚴格限定在 @media (max-width: 639px)，保證桌面版 (>=640px) 佈局 100% 不受任何影響
   ========================================================================== */
@media (max-width: 639px) {
  /* 0. 移動端懸浮 YouTube 播放器與收起圖標適配 (Mobile Floating Player & Icon) */
  #youtube-player-layer {
    top: 52px;
    right: 8px;
    width: 210px;
    height: 118px;
    border-radius: 0.85rem;
    border-width: 2px;
    z-index: 28;
  }

  #youtube-header-bar {
    height: 22px;
    padding: 0 4px;
  }

  #youtube-header-bar #youtube-header-title {
    max-width: 80px;
    font-size: 9px;
  }

  #youtube-header-bar button {
    padding: 1px 4px;
    font-size: 9px;
  }

  #youtube-floating-icon {
    top: 52px !important;
    right: 8px !important;
    padding: 4px 8px !important;
    border-radius: 0.85rem !important;
  }

  /* 1. 移動端聊天懸浮層直接位於左下角 (Directly at bottom-left corner) */
  #chat-overlay {
    bottom: 12px;
    left: 12px;
    width: 250px;
    max-width: calc(100vw - 120px);
    gap: 5px;
    z-index: 35;
    transition: all 0.2s ease-out;
  }

  /* 折疊狀態: 消息框只保留 1 行 (Collapse until 1 line of chat only)，直接釘在左下角 */
  #chat-overlay.is-mobile-collapsed {
    gap: 0;
  }
  #chat-overlay.is-mobile-collapsed #mobile-chat-toggle-bar {
    display: none !important;
  }
  #chat-overlay.is-mobile-collapsed .chat-history-window {
    height: 32px !important;
    min-height: 32px !important;
    max-height: 32px !important;
    overflow: hidden !important;
    padding: 3px 32px 3px 8px !important;
    border-radius: 0.85rem !important;
    display: flex !important;
    align-items: center !important;
    cursor: pointer !important;
    position: relative !important;
  }

  /* 單行聊天右側顯著展開指示圖示 [▲] */
  #chat-overlay.is-mobile-collapsed .chat-history-window::after {
    content: '▲';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    font-weight: 900;
    background: rgba(254, 243, 199, 0.95);
    padding: 1px 5px;
    border-radius: 6px;
    color: #78350F;
    border: 1px solid rgba(245, 158, 11, 0.4);
    pointer-events: none;
  }

  /* 只顯示最新的一條聊天訊息，超出部分以單行省略號截斷 */
  #chat-overlay.is-mobile-collapsed .chat-history-window .chat-bubble-log:not(:last-child) {
    display: none !important;
  }
  #chat-overlay.is-mobile-collapsed .chat-history-window .chat-bubble-log:last-child {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    padding: 2px 4px !important;
    margin: 0 !important;
    font-size: 11px !important;
    line-height: 22px !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
  }

  /* 折疊時隱藏快捷表情列與輸入列，釋放手機遊戲視野，僅呈現極簡 1 行 */
  #chat-overlay.is-mobile-collapsed #chat-quick-emotes {
    display: none !important;
  }
  #chat-overlay.is-mobile-collapsed #chat-form {
    display: none !important;
  }

  /* 移動端展開狀態: 向上展開，適當高度與滾動 */
  #chat-overlay:not(.is-mobile-collapsed) .chat-history-window {
    height: 125px;
    max-height: 135px;
  }

  /* 移動端輸入框輕量化 */
  #chat-overlay #chat-input {
    padding: 6px 10px;
    font-size: 11px;
  }
  #chat-overlay form button {
    width: 34px !important;
    height: 34px !important;
  }

  /* 2. 移動端右下象限控制台整齊緊湊網格佈局 (Tidy Mobile Action HUD) */
  #mobile-action-hud {
    bottom: 12px;
    right: 12px;
    display: grid;
    grid-template-columns: repeat(2, 46px);
    gap: 6px;
  }
  #mobile-action-hud .temple-btn {
    width: 46px;
    height: 46px;
    padding: 2px;
    border-width: 2px;
  }
  #mobile-action-hud .temple-btn-icon {
    font-size: 18px;
    line-height: 1;
  }
  #mobile-action-hud .temple-btn-text {
    font-size: 7px;
    letter-spacing: 0;
    margin-top: 1px;
  }

  /* 3. 移動端左側虛擬搖桿感應區域 (左半部觸控感應，不干擾左下角單行聊天點擊) */
  #joystick-touch-zone {
    bottom: 0;
    left: 0;
    width: 50vw;
    height: 50vh;
  }
  #virtual-joystick-base {
    width: 86px;
    height: 86px;
  }
  #virtual-joystick-thumb {
    width: 38px;
    height: 38px;
  }

  /* 4. 移動端頂部導覽列緊湊整潔 */
  header {
    top: 8px;
    left: 8px;
    right: 8px;
  }
  header .temple-glass-card {
    padding: 4px 8px;
    gap: 6px;
  }
  header .temple-glass-card .w-10 {
    width: 28px;
    height: 28px;
    font-size: 16px;
  }
}
