/* ==========================================================================
   基本レイアウト & フォント設定
   ========================================================================== */
* { margin:0; padding:0; box-sizing:border-box; }
html, body { 
  width:100%; 
  height:100%; 
  background:#050A15;
  overflow:hidden;
  font-family:'Klee One', serif;
}

#clock,
#botbar b {
  font-family:'Share Tech Mono', monospace;
  font-weight:400;
}
  
body.custom-cursor-active,
body.custom-cursor-active * { cursor: none !important; }
body.hide-cursor { cursor: none; }

#cursor-dot {
  pointer-events: none;
  position: fixed;
  z-index: 200;
  width: 20px;
  height: 24px;
  filter: drop-shadow(0 0 6px rgba(56,189,248,0.5));
  display: none;
}
#wrap { position:fixed; inset:0; display:flex; flex-direction:column; background:#060b14; }
#topbar {
  height:32px; flex-shrink:0; display:flex; justify-content:space-between; align-items:center;
  padding:0 20px; border-bottom:1px solid rgba(56, 189, 248, 0.08);
  font-size:14px; color:#384f6b; letter-spacing:3px;
}
#homeBtn {
  color:rgba(56, 189, 248, 0.5); text-decoration:none; letter-spacing:2px; font-size:15px;
  transition: color 0.15s, text-shadow 0.15s;
  font-weight: 600;
}
#homeBtn:hover { color:#7dd3fc; text-shadow: 0 0 8px rgba(56,189,248,0.6); }

/* ── ゲーム領域の固定 ── */
#canvasWrap {
  flex:1; 
  overflow:hidden;
  display:flex; 
  align-items:center; 
  justify-content:center; 
  background: #060b14;
  border-top: 1px solid rgba(56, 189, 248, 0.03);
  border-bottom: 1px solid rgba(56, 189, 248, 0.03);
  width: 100%;
}

#gameArea {
  position:relative;
  width: 100%;
  max-width: 800px; 
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: 1px solid rgba(56, 189, 248, 0.08);
}

#ideoLink {
  margin-top:16px; padding:12px 36px;
  border:1px solid rgba(56, 189, 248, 0.2); color:rgba(125, 211, 252, 0.7);
  background:transparent; font-family:'Klee One', sans-serif;
  font-size:13px; letter-spacing:4px; cursor:pointer;
  text-decoration:none;
  transition: all 0.2s;
}
#ideoLink:hover { background:rgba(56, 189, 248, 0.05); border-color:rgba(56, 189, 248, 0.5); color:#fff; }

#botbar {
  height:28px; flex-shrink:0; display:flex; justify-content:space-between; align-items:center;
  padding:0 24px; border-top:1px solid rgba(56, 189, 248, 0.08);
  font-size:14px; color:#384f6b; letter-spacing:3px;
}
#botbar span { display: flex; align-items: center; gap: 6px; }
#botbar b { font-family: 'Share Tech Mono', monospace; color: #7dd3fc; font-weight: normal; text-shadow: 0 0 4px rgba(56,189,248,0.3); }

canvas { display:block; position:absolute; }

#scanlines {
  position:absolute; inset:0; pointer-events:none; z-index:5;
  background:repeating-linear-gradient(0deg,transparent,transparent 4px,rgba(56,189,248,0.015) 4px,rgba(56,189,248,0.015) 5px);
}

#overlay, #pauseOverlay {
  position:absolute; inset:0; z-index:20;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  background:rgba(6, 11, 20, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#pauseOverlay { z-index:21; display:none; }
#pauseOverlay .glitch { font-size:clamp(18px,4vw,36px); color:#7dd3fc; text-shadow: 0 0 10px rgba(56,189,248,0.5); }

.pause-btn {
  margin-top:12px; padding:12px 36px;
  border:1px solid rgba(56, 189, 248, 0.2); color:rgba(125, 211, 252, 0.7);
  background:transparent; font-family:'Klee One', sans-serif;
  font-size:15px; letter-spacing:4px; cursor:pointer;
  text-decoration:none; display:block; text-align:center;
  transition: all 0.2s;
}
.pause-btn:hover { background:rgba(56, 189, 248, 0.05); border-color:rgba(56, 189, 248, 0.5); color:#fff; }

.glitch {
  font-family:'Klee One', sans-serif;
  font-weight: 400;
  font-size:clamp(20px,4vw,36px); color:#bae6fd;
  letter-spacing:10px; text-transform:uppercase;
  opacity: 0.9; margin-bottom:14px;
  text-shadow: 0 0 12px rgba(56,189,248,0.4);
}
.tagline { font-size:14px; color:rgba(56, 189, 248, 0.5); letter-spacing:4px; margin:4px 0; }
.hint { font-size:15px; color:#384f6b; letter-spacing:2px; margin:3px 0; }

#startBtn,
#collectionBtn,
#closeCollection,
#resetDataBtn {
  margin-top:32px;
  padding:12px 40px;
  border:1px solid rgba(56,189,248,0.25);
  color:#7dd3fc;
  background:transparent;
  font-family:'Klee One', sans-serif;
  font-size:15px;
  letter-spacing:4px;
  cursor:pointer;
  transition:all .2s;
  text-shadow:0 0 4px rgba(56,189,248,.3);
}

#startBtn:hover,
#collectionBtn:hover,
#closeCollection:hover,
#resetDataBtn:hover {
  background:rgba(56,189,248,.05);
  border-color:rgba(56,189,248,.6);
  color:#fff;
  box-shadow:0 0 10px rgba(56,189,248,.2);
}

/* ==========================================================================
   硝子片集（コレクション一覧）外枠・スクロール設定
   ========================================================================== */
#collectionView {
  position: absolute;
  inset: 0;
  background: rgba(5, 10, 21, 0.98);
  z-index: 50 !important; 
  padding: 40px 20px;
  display: none; 
  flex-direction: column !important;
  align-items: center !important;
  justify-content: flex-start;
  pointer-events: auto !important;
  overflow-y: auto !important; /* 全体スクロールを有効化 */
  -webkit-overflow-scrolling: touch;
}

/* スクロールバー装飾 */
#collectionView::-webkit-scrollbar { width: 4px; }
#collectionView::-webkit-scrollbar-track { background: rgba(56, 189, 248, 0.02); }
#collectionView::-webkit-scrollbar-thumb { background: rgba(56, 189, 248, 0.15); border-radius: 2px; }

/* 決定論的セクション構造用ラッパー */
#collectionSectionsContainer {
  width: 100%;
  max-width: 800px;
  margin: 24px 0;
}

/* ── 【追加】左上戻るボタンの装飾 ── */
.collection-back-btn-wrap {
  width: 100%;
  max-width: 800px;
  display: flex;
  justify-content: flex-start;
  padding: 10px 0 10px 0;
  box-sizing: border-box;
}

.collection-top-back-btn {
  background: rgba(40, 40, 40, 0.6);
  color: #d4c4a8;
  border: 1px solid #5a4f43;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-radius: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.collection-top-back-btn:hover {
  background: rgba(70, 60, 50, 0.8);
  border-color: #98846e;
  color: #fff;
  box-shadow: 0 0 8px rgba(152, 132, 110, 0.3);
}

.collection-top-back-btn span {
  font-size: 12px;
}

.collection-section {
  width: 100%;
  margin-bottom: 32px;
}

/* セクションヘッダー（レア度名 ＆ 進捗） */
.collection-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(56, 189, 248, 0.15);
  padding-bottom: 6px;
  margin-bottom: 14px;
  color: #bae6fd;
  font-size: 15px;
  letter-spacing: 2px;
}

.collection-section-progress {
  font-family: 'Share Tech Mono', monospace;
  color: #384f6b;
  font-size: 14px;
  letter-spacing: 0px;
}

/* 新規グリッドシステム（SPEC完全準拠） */
.collection-grid-wrap {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) !important;
  gap: 12px;
  width: 100%;
}

/* 各アイテムの基本カード枠 */
.collection-item-box {
  position: relative !important;
  overflow: hidden;
  border: 1px solid rgba(125, 211, 252, 0.3) !important;
  background: rgba(6, 11, 20, 0.7) !important;
  padding: 10px 6px !important;
  text-align: center;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start !important;
  box-sizing: border-box;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
  min-height: 120px;
  pointer-events: auto !important;
}

/* ── 獲得済み（item-obtained）のインタラクション ── */
.item-obtained:hover {
  background: rgba(56, 189, 248, 0.05) !important;
  border-color: rgba(56, 189, 248, 0.8) !important;
}
.item-obtained img {
  width: 44px !important;
  height: 44px !important;
  object-fit: contain;
  display: block;
  opacity: 1.0 !important;
  filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.6)) !important; /* icon.glow = blue */
}

/* ── 未観測（item-unobtained）の減光・透過ルール ── */
.item-unobtained {
  border-color: rgba(56, 189, 248, 0.05) !important;
  background: rgba(6, 11, 20, 0.3) !important;
}
.item-unobtained .unknown {
  opacity: 0.35 !important; /* icon.opacity = 0.35 */
  filter: none !important;   /* icon.glow = none */
}
.item-unobtained .rarity-badge {
  opacity: 0.25 !important; /* rarity.label.opacity = 0.25 */
}
.item-unobtained h3 {
  color: rgba(56, 189, 248, 0.3) !important;
  text-shadow: none !important;
}

/* 未観測用（？）アセット代替表示 */
.unknown {
  width: 44px !important;
  height: 44px !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: rgba(56, 189, 248, 0.2) !important;
  text-shadow: 0 0 8px rgba(56, 189, 248, 0.1);
  background: rgba(56, 189, 248, 0.02);
  border: 1px dashed rgba(56, 189, 248, 0.15);
  border-radius: 4px;
}

/* コレクション内のテキスト調整 */
.collection-item-box h3 {
  color: #ffffff;
  font-size: 12px;
  letter-spacing: 1px;
  margin-top: 10px;
  text-shadow: 0 0 6px rgba(125, 211, 252, 0.3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

/* ==========================================================================
   完全同期・世界観調和カラーバッジ仕様（和風泥沼発光）
   ========================================================================== */
.rarity-badge {
  position: absolute !important;
  top: 4px !important;
  left: 4px !important;
  font-size: 10px !important;
  line-height: 1 !important;
  padding: 3px 6px !important;
  border-radius: 3px !important;
  font-weight: bold !important;
  letter-spacing: 1px !important;
  z-index: 10 !important;
  font-family: 'Klee One', serif;
}

/* ── 【常触 / C】：灰青 ── */
.rarity-badge.rarity-c {
  background: rgba(95, 112, 134, 0.15) !important;
  color: #5F7086 !important;
  border: 1px solid rgba(95, 112, 134, 0.4) !important;
}
.rarity-border-c { border-color: rgba(95, 112, 134, 0.3) !important; }
.rarity-text-c {
  color: #5F7086 !important;
  text-shadow: 0 0 6px rgba(95, 112, 134, 0.35) !important;
}

/* ── 【希有 / R】：深群青 ── */
.rarity-badge.rarity-r {
  background: rgba(57, 108, 255, 0.15) !important;
  color: #396CFF !important;
  border: 1px solid rgba(57, 108, 255, 0.5) !important;
}
.rarity-border-r {
  border-color: rgba(57, 108, 255, 0.4) !important;
  box-shadow: 0 0 8px rgba(57, 108, 255, 0.2), inset 0 0 4px rgba(57, 108, 255, 0.1) !important;
}
.rarity-text-r {
  color: #396CFF !important;
  text-shadow: 0 0 10px rgba(57, 108, 255, 0.55) !important;
}

/* ── 【幻晶 / L】：氷晶白 ── */
.rarity-badge.rarity-l {
  background: rgba(234, 253, 255, 0.2) !important;
  color: #EAFDFF !important;
  border: 1px solid rgba(234, 253, 255, 0.7) !important;
  text-shadow: 0 0 8px rgba(234, 253, 255, 0.6);
}
.rarity-border-l { animation: glassPulse 3s infinite alternate ease-in-out !important; }
.rarity-text-l {
  color: #EAFDFF !important;
  text-shadow: 0 0 14px rgba(234, 253, 255, 0.8), 0 0 6px rgba(234, 253, 255, 0.4) !important;
}

@keyframes glassPulse {
  0% {
    border-color: rgba(234, 253, 255, 0.3) !important;
    box-shadow: 0 0 8px rgba(234, 253, 255, 0.15), inset 0 0 4px rgba(234, 253, 255, 0.1) !important;
  }
  50% {
    border-color: rgba(234, 253, 255, 0.7) !important;
    box-shadow: 0 0 16px rgba(234, 253, 255, 0.45), inset 0 0 10px rgba(234, 253, 255, 0.25) !important;
  }
  100% {
    border-color: rgba(200, 240, 255, 0.4) !important;
    box-shadow: 0 0 10px rgba(200, 240, 255, 0.2), inset 0 0 6px rgba(200, 240, 255, 0.15) !important;
  }
}

/* ==========================================================================
   詳細ポップアップ（モーダル）
   ========================================================================== */
.popup-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 16, 0.85); 
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100 !important; 
  display: none; 
  align-items: center;
  justify-content: center;
}

.popup-content {
  background: rgba(10, 18, 32, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.3);
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.15);
  border-radius: 8px;
  width: 85%;
  max-width: 340px;
  padding: 24px;
  text-align: center;
  animation: popupFadeIn 0.2s ease-out;
  position: relative;
  pointer-events: auto !important;
}

@keyframes popupFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

#popupImageWrap img {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.4));
}

#popupName {
  font-size: 18px;
  color: #bae6fd;
  letter-spacing: 2px;
  margin-bottom: 12px;
  font-weight: 600;
}

#popupDesc {
  font-size: 13px;
  color: rgba(175, 219, 245, 0.8);
  line-height: 1.6;
  text-align: center;
  margin-bottom: 20px;
  white-space: normal;
}

.popup-stats table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  border-top: 1px solid rgba(56, 189, 248, 0.1);
}

.popup-stats td {
  padding: 6px 4px;
  font-size: 12px;
  border-bottom: 1px solid rgba(56, 189, 248, 0.1);
}

.popup-stats td:first-child {
  color: #384f6b; 
  text-align: left;
  letter-spacing: 2px;
}

.popup-stats td:last-child {
  color: #7dd3fc; 
  text-align: right;
  font-family: 'Share Tech Mono', monospace;
}

.popup-hint {
  display: block;
  font-size: 11px;
  color: #384f6b;
  margin-top: 16px;
  letter-spacing: 1px;
}

/* ==========================================================================
   スマートフォン環境最適化（1080px以下レスポンシブ）
   ========================================================================== */
@media screen and (max-width: 1080px) {
  html, body, #wrap {
    height: 100% !important;
    overflow: hidden !important; 
    position: relative;
  }

  #topbar, #botbar {
    font-size: 13px;
    letter-spacing: 1px;
    padding: 0 12px;
    height: 32px !important; 
  }

  #canvasWrap {
    height: calc(100% - 64px) !important; 
    overflow: hidden;
  }
  #gameArea{
    flex:none;
    max-width: 100%;
  }

  #collectionView {
    position: absolute;
    inset: 0 !important;
    padding: 16px 12px !important;
    display: none;
    flex-direction: column !important;
    justify-content: flex-start !important;
    background: rgba(5,10,21,.98) !important;
    z-index: 60 !important; 
  }

  /* セクション内スマホグリッド上書き */
  .collection-grid-wrap {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)) !important;
    gap: 8px !important;
  }

  .collection-item-box {
    min-height: 105px !important;
    padding: 8px 4px !important;
    justify-content: flex-start !important;
  }

  .collection-item-box img, .unknown {
    width: 36px !important; 
    height: 36px !important;
    margin-bottom: 4px !important;
  }

  .popup-content {
    max-width: 90% !important;
    max-height: 85% !important; 
    overflow-y: auto; 
    padding: 20px 10px;
  }

  #popupName { font-size: 18px; letter-spacing: 2px; }
  #popupDesc { font-size: 14px; line-height: 1.6; }
  .popup-stats table { font-size: 13px; }

  .glitch {
    font-size: 26px !important; 
    letter-spacing: 6px;
    margin-bottom: 20px;
  }

  .tagline, .hint {
    font-size: 14px !important; 
    letter-spacing: 1px;
    line-height: 1.6;
  }

  #startBtn, #collectionBtn, #resetDataBtn {
    position: relative;
    z-index: 40 !important; 
    padding: 14px 32px;
    font-size: 16px;
    width: 80%; 
    max-width: 240px;
    pointer-events: auto !important;
  }

  #closeCollection {
    display: block !important;
    width: 90% !important;
    max-width: 300px !important;
    margin: 16px auto 10px auto !important; 
    padding: 16px !important;
    font-size: 18px !important;
    flex-shrink: 0; 
    z-index: 70 !important; 
    pointer-events: auto !important;
  }
}
