:root {
  --bg-deep: #090710;
  --bg-panel: rgba(18, 14, 30, 0.78);
  --bg-panel-border: rgba(168, 85, 247, 0.35);
  --accent-purple: #a855f7;
  --accent-light-purple: #c084fc;
  --accent-neon: #d946ef;
  --accent-cyan: #38bdf8;
  --text-main: #f8fafc;
  --text-sub: #cbd5e1;
  --text-muted: #94a3b8;
  --font-main: "M PLUS Rounded 1c", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-en: "Outfit", sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-deep);
  font-family: var(--font-main);
  color: var(--text-main);
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
  overflow: hidden;
  background: #000;
  display: flex;
  flex-direction: column;
}

/* 背景レイヤー */
.bg-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: background-image 0.8s ease-in-out, filter 0.5s ease;
  z-index: 1;
}

.ambient-overlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 40%, rgba(168, 85, 247, 0.12), rgba(9, 7, 16, 0.85) 85%);
  pointer-events: none;
  z-index: 2;
}

.flash-overlay {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out;
  z-index: 50;
}

.flash-overlay.active {
  opacity: 0.8;
}

/* 画面共通 */
.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.screen.active {
  display: flex;
  opacity: 1;
}

/* ==========================================================
   タイトル画面
   ========================================================== */
#title-screen {
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  background: radial-gradient(circle at 50% 40%, rgba(30, 20, 50, 0.85), #06040a 90%), url('assets/bg_bugfeed_alley.png') center/cover;
}

.title-content {
  position: relative;
  z-index: 12;
  padding: 40px;
  background: rgba(14, 10, 26, 0.72);
  border: 1px solid rgba(168, 85, 247, 0.35);
  border-radius: 28px;
  backdrop-filter: blur(20px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), 0 0 35px rgba(168, 85, 247, 0.25);
  max-width: 640px;
  width: 90%;
  animation: floatCard 6s ease-in-out infinite;
}

@keyframes floatCard {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.title-badges {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}

.badge-tag {
  font-family: var(--font-en);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent-light-purple);
  background: rgba(168, 85, 247, 0.18);
  border: 1px solid rgba(168, 85, 247, 0.4);
  padding: 4px 14px;
  border-radius: 100px;
}

.badge-cat {
  font-size: 14px;
  filter: drop-shadow(0 0 8px var(--accent-neon));
}

.main-title {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #ffffff 20%, #e9d5ff 60%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 20px rgba(168, 85, 247, 0.4);
  margin-bottom: 8px;
}

.sub-title {
  font-family: var(--font-en);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 3px;
  color: var(--accent-cyan);
  text-transform: uppercase;
  margin-bottom: 32px;
  opacity: 0.9;
}

.title-menu {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}

/* ボタン共通 */
button {
  cursor: pointer;
  border: none;
  outline: none;
  font-family: var(--font-main);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-primary {
  background: linear-gradient(135deg, #9333ea, #7c3aed);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  padding: 14px 24px;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(147, 51, 234, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-primary:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 8px 25px rgba(168, 85, 247, 0.65);
  background: linear-gradient(135deg, #a855f7, #9333ea);
}

.btn-secondary {
  background: rgba(30, 20, 50, 0.6);
  color: var(--text-main);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid rgba(168, 85, 247, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-secondary:hover {
  background: rgba(168, 85, 247, 0.25);
  border-color: rgba(168, 85, 247, 0.6);
  transform: translateY(-2px);
}

.title-credit {
  position: absolute;
  bottom: 20px;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 1px;
}

/* ==========================================================
   名前入力画面
   ========================================================== */
#name-screen {
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(30, 20, 50, 0.85), #06040a 90%), url('assets/bg_bugfeed_cafe.png') center/cover;
}

.name-entry-container {
  position: relative;
  z-index: 12;
  width: 90%;
  max-width: 520px;
}

.name-entry-card {
  background: rgba(14, 10, 26, 0.82);
  border: 1.5px solid rgba(168, 85, 247, 0.45);
  border-radius: 28px;
  padding: 44px 48px 40px;
  backdrop-filter: blur(22px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), 0 0 40px rgba(168, 85, 247, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  animation: floatCard 6s ease-in-out infinite;
}

.name-entry-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.name-entry-icon {
  font-size: 40px;
  filter: drop-shadow(0 0 12px rgba(168, 85, 247, 0.8));
  animation: heartBeat 1.4s ease-in-out infinite;
}

.name-entry-title {
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(135deg, #fff 20%, #e9d5ff 60%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.name-entry-sub {
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.name-input-wrap {
  width: 100%;
  position: relative;
}

.name-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-main);
  font-size: 32px;
  font-weight: 800;
  color: #fff;
  text-align: center;
  padding: 8px 0 12px;
  letter-spacing: 4px;
  caret-color: var(--accent-light-purple);
}

.name-input::placeholder {
  color: rgba(255, 255, 255, 0.2);
  letter-spacing: 2px;
}

.name-input-underline {
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-purple), var(--accent-neon), var(--accent-purple), transparent);
  border-radius: 2px;
  background-size: 200% 100%;
  animation: shimmer 2s linear infinite;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.name-suggestions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.suggest-label {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.suggest-btn {
  background: rgba(168, 85, 247, 0.15);
  border: 1px solid rgba(168, 85, 247, 0.35);
  border-radius: 20px;
  color: var(--accent-light-purple);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  padding: 5px 16px;
  transition: all 0.2s ease;
}

.suggest-btn:hover {
  background: rgba(168, 85, 247, 0.4);
  border-color: var(--accent-light-purple);
  color: #fff;
  transform: translateY(-1px);
}

.name-confirm-btn {
  width: 100%;
  font-size: 18px;
  padding: 16px;
}

/* ==========================================================
   ノベルゲーム本編画面
   ========================================================== */
#novel-screen {
  flex-direction: column;
  justify-content: space-between;
  padding: 20px 40px 30px;
}

/* ヘッダー・クイックナビ */
.game-header {
  position: relative;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.chapter-badge {
  font-size: 14px;
  font-weight: 700;
  color: #f1f5f9;
  background: rgba(18, 14, 30, 0.75);
  border: 1px solid rgba(168, 85, 247, 0.4);
  padding: 8px 18px;
  border-radius: 20px;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.quick-nav {
  display: flex;
  gap: 8px;
}

.nav-btn {
  background: rgba(18, 14, 30, 0.65);
  color: var(--text-sub);
  font-family: var(--font-en);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid rgba(168, 85, 247, 0.25);
  backdrop-filter: blur(10px);
}

.nav-btn:hover {
  background: rgba(168, 85, 247, 0.35);
  color: #fff;
  border-color: var(--accent-light-purple);
}

.nav-btn.active {
  background: var(--accent-purple);
  color: #fff;
  box-shadow: 0 0 12px var(--accent-purple);
}

/* 立ち絵ステージ */
.characters-stage {
  position: absolute;
  inset: 0;
  bottom: 80px;
  z-index: 5;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  pointer-events: none;
}

.sprite-wrap {
  position: absolute;
  bottom: 0;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  opacity: 0;
  transform: translateY(20px) scale(0.96);
}

.sprite-wrap.active {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.sprite-wrap.girl {
  right: 26%;
  animation: breathing 4s ease-in-out infinite;
}

.sprite-wrap.boy {
  left: 20%;
  animation: breathing 4.2s ease-in-out infinite 0.5s;
}

@keyframes breathing {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.character-sprite {
  height: 600px;
  width: auto;
  border-radius: 0;
  filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.9)) drop-shadow(0 0 25px rgba(168, 85, 247, 0.4));
  transition: opacity 0.2s ease, transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: center bottom;
}

.sprite-wrap[data-framing="bust"] .character-sprite {
  transform: scale(1.28);
  transform-origin: center top;
}

.sprite-wrap[data-framing="close"] .character-sprite {
  transform: scale(1.52);
  transform-origin: center top;
}

/* 全画面イベントCGモーダル */
.event-cg-layer {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: opacity 0.4s ease;
}

.event-cg-layer.hidden {
  display: none;
  opacity: 0;
}

.event-cg-layer img {
  max-width: 94%;
  max-height: 85%;
  border-radius: 18px;
  box-shadow: 0 10px 40px rgba(168, 85, 247, 0.4), 0 0 80px rgba(0, 0, 0, 0.9);
  border: 2px solid rgba(192, 132, 252, 0.4);
  animation: cgZoomIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes cgZoomIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.cg-caption {
  margin-top: 16px;
  font-size: 18px;
  font-weight: 700;
  color: #f3e8ff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

.cg-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  animation: blink 1.2s infinite;
}

/* 選択肢ボックス */
.choices-container {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 35;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 90%;
  max-width: 520px;
}

.choices-container.hidden {
  display: none;
}

.choice-btn {
  background: rgba(22, 16, 38, 0.88);
  border: 1.5px solid rgba(168, 85, 247, 0.45);
  border-radius: 16px;
  padding: 16px 24px;
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  text-align: left;
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6), 0 0 20px rgba(168, 85, 247, 0.2);
  display: flex;
  align-items: center;
  gap: 14px;
  animation: slideChoice 0.35s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

@keyframes slideChoice {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.choice-btn:hover {
  background: linear-gradient(135deg, rgba(147, 51, 234, 0.6), rgba(168, 85, 247, 0.4));
  border-color: #c084fc;
  transform: translateX(6px) scale(1.02);
  box-shadow: 0 10px 35px rgba(168, 85, 247, 0.5);
}

.choice-num {
  font-family: var(--font-en);
  font-size: 13px;
  color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.15);
  padding: 2px 8px;
  border-radius: 6px;
}

/* メッセージウィンドウ */
.dialogue-box {
  position: relative;
  z-index: 30;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  min-height: 180px;
  background: var(--bg-panel);
  border: 1.5px solid var(--bg-panel-border);
  border-radius: 22px;
  backdrop-filter: blur(20px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.75), 0 0 30px rgba(168, 85, 247, 0.15);
  padding: 22px 28px;
  display: flex;
  gap: 22px;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.dialogue-box:hover {
  border-color: rgba(192, 132, 252, 0.6);
}

.dialogue-avatar-wrap {
  position: relative;
  width: 90px;
  height: 90px;
  flex-shrink: 0;
}

.dialogue-avatar {
  width: 100%;
  height: 100%;
  border-radius: 18px;
  background: #1a162b;
  background-size: 300% 200%;
  background-position: 0% 0%;
  background-repeat: no-repeat;
  overflow: hidden;
  border: 2px solid rgba(168, 85, 247, 0.5);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
}

.dialogue-avatar[data-emotion="smile"] { background-position: 50% 0%; }
.dialogue-avatar[data-emotion="joy"] { background-position: 100% 0%; }
.dialogue-avatar[data-emotion="serious"] { background-position: 0% 100%; }
.dialogue-avatar[data-emotion="surprise"] { background-position: 50% 100%; }
.dialogue-avatar[data-emotion="troubled"] { background-position: 100% 100%; }

.avatar-glow {
  position: absolute;
  inset: -3px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent-purple), transparent, var(--accent-cyan));
  z-index: -1;
  opacity: 0.6;
  filter: blur(4px);
}

.dialogue-body {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.speaker-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.speaker-name {
  font-size: 19px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 10px rgba(168, 85, 247, 0.5);
}

.emotion-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-light-purple);
  background: rgba(168, 85, 247, 0.2);
  border: 1px solid rgba(168, 85, 247, 0.35);
  padding: 2px 10px;
  border-radius: 100px;
}

.heart-pulse {
  font-size: 16px;
  color: var(--accent-neon);
  animation: heartBeat 1.4s ease-in-out infinite;
}

@keyframes heartBeat {
  0%, 100% { transform: scale(1); }
  15% { transform: scale(1.3); }
  30% { transform: scale(1); }
  45% { transform: scale(1.2); }
}

.dialogue-text {
  font-size: 18px;
  line-height: 1.7;
  color: #f1f5f9;
  min-height: 60px;
  word-break: break-word;
}

.click-indicator {
  position: absolute;
  bottom: 14px;
  right: 20px;
  color: var(--accent-light-purple);
  font-size: 13px;
  animation: bounceDown 1s infinite alternate ease-in-out;
}

@keyframes bounceDown {
  from { transform: translateY(0); opacity: 0.4; }
  to { transform: translateY(4px); opacity: 1; }
}

/* ==========================================================
   モーダル（バックログ・CGギャラリー・設定）
   ========================================================== */
.modal-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: rgba(6, 4, 10, 0.85);
  backdrop-filter: blur(16px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: rgba(18, 14, 30, 0.95);
  border: 1.5px solid rgba(168, 85, 247, 0.4);
  border-radius: 24px;
  width: 100%;
  max-width: 680px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(168, 85, 247, 0.2);
}

.modal-card.modal-large {
  max-width: 900px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
  border-bottom: 1px solid rgba(168, 85, 247, 0.2);
}

.modal-header h3 {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
}

.modal-close-btn {
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  padding: 6px 12px;
  border-radius: 8px;
}

.modal-close-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.modal-body {
  padding: 24px 28px;
  overflow-y: auto;
}

/* バックログ */
.log-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.log-item {
  padding: 12px 16px;
  background: rgba(30, 20, 50, 0.4);
  border-left: 3px solid var(--accent-purple);
  border-radius: 8px;
}

.log-speaker {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-light-purple);
  margin-bottom: 4px;
}

.log-text {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-main);
}

/* CGギャラリー */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}

.gallery-card {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(168, 85, 247, 0.3);
  background: #0d0918;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.gallery-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent-light-purple);
}

.gallery-card img {
  width: 100%;
  aspect-ratio: 16/10;
  object-fit: cover;
  display: block;
}

.gallery-card.locked img {
  filter: grayscale(1) blur(4px) brightness(0.3);
}

.gallery-lock-text {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 700;
  color: var(--text-muted);
}

.gallery-card-title {
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
}

/* 設定フォーム */
.config-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.config-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.config-row label {
  font-size: 16px;
  font-weight: 600;
}

.config-row input[type="range"] {
  width: 220px;
  accent-color: var(--accent-purple);
}

/* トースト通知 */
.toast-notify {
  position: absolute;
  top: 24px;
  right: 24px;
  z-index: 60;
  background: rgba(18, 14, 30, 0.9);
  border: 1px solid var(--accent-purple);
  padding: 12px 20px;
  border-radius: 12px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: all 0.3s ease;
}

.toast-notify.active {
  opacity: 1;
  transform: translateY(0);
}

/* bug feed #211: cyber-subculture visual direction */
:root {
  --bg-deep: #08070b;
  --bg-panel: rgba(10, 9, 14, 0.88);
  --bg-panel-border: rgba(229, 54, 143, 0.48);
  --accent-purple: #9a74ff;
  --accent-light-purple: #c5b4ff;
  --accent-neon: #f04a9b;
  --accent-cyan: #62d5e8;
  --text-sub: #e0dce5;
  --text-muted: #a7a2af;
}

html,
body {
  min-height: 100dvh;
  background: #08070b;
}

#game-container {
  width: 100%;
  height: 100dvh;
  min-height: 560px;
  background: #08070b;
}

.bg-layer {
  filter: saturate(0.78) brightness(0.65);
  transform: scale(1.025);
}

.ambient-overlay {
  background:
    linear-gradient(180deg, rgba(8, 7, 11, 0.12), rgba(8, 7, 11, 0.18) 46%, rgba(8, 7, 11, 0.88)),
    linear-gradient(90deg, rgba(8, 7, 11, 0.56), transparent 48%, rgba(8, 7, 11, 0.2));
}

#title-screen {
  justify-content: flex-start;
  align-items: flex-start;
  text-align: left;
  background:
    linear-gradient(90deg, rgba(7, 6, 10, 0.94) 0%, rgba(7, 6, 10, 0.78) 36%, rgba(7, 6, 10, 0.08) 100%),
    linear-gradient(0deg, rgba(7, 6, 10, 0.72), transparent 50%),
    url("assets/cg211_title_v2.png") 57% 42% / cover no-repeat,
    #08070b;
}

.title-content {
  align-self: flex-start;
  margin: 0 0 3vh clamp(28px, 5vw, 72px);
  padding: clamp(26px, 4vw, 56px) 0;
  width: min(620px, 58vw);
  max-width: 620px;
  background: transparent;
  border: 0;
  border-radius: 0;
  backdrop-filter: none;
  box-shadow: none;
  animation: none;
}

.title-badges {
  justify-content: flex-start;
  gap: 10px;
  margin-bottom: 28px;
}

.badge-tag,
.badge-cat {
  border-radius: 2px;
  padding: 6px 10px;
  color: #e9e3f4;
  background: rgba(9, 8, 12, 0.58);
  border: 1px solid rgba(240, 74, 155, 0.56);
  font-family: var(--font-en), monospace;
  font-size: 10px;
  letter-spacing: 1.4px;
  filter: none;
}

.main-title {
  margin: 0;
  font-family: var(--font-en), "Courier New", monospace;
  font-size: clamp(46px, 7vw, 88px);
  font-weight: 800;
  letter-spacing: -0.075em;
  line-height: 0.92;
  color: #f8f5fb;
  background: none;
  -webkit-text-fill-color: currentColor;
  text-shadow: 3px 0 rgba(240, 74, 155, 0.55), -3px 0 rgba(98, 213, 232, 0.38);
}

.main-title span {
  color: #f04a9b;
}

.sub-title {
  margin: 14px 0 34px;
  color: #ded8e7;
  font-size: clamp(15px, 2vw, 20px);
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: none;
}

.title-menu {
  align-items: flex-start;
  max-width: 340px;
  margin: 0;
  gap: 9px;
}

.title-menu button {
  justify-content: flex-start;
  width: 100%;
  min-height: 46px;
  padding: 11px 16px;
  border-radius: 2px;
  font-family: var(--font-en), var(--font-main);
  letter-spacing: 0.04em;
  backdrop-filter: blur(12px);
}

.btn-primary {
  color: #fff;
  background: #d73583;
  box-shadow: 0 6px 28px rgba(215, 53, 131, 0.25);
}

.btn-primary:hover {
  background: #f04a9b;
  box-shadow: 0 8px 32px rgba(240, 74, 155, 0.35);
}

.btn-secondary {
  color: #eee9f3;
  background: rgba(10, 9, 14, 0.74);
  border: 1px solid rgba(221, 213, 230, 0.2);
}

.btn-secondary:hover {
  background: rgba(240, 74, 155, 0.16);
  border-color: rgba(240, 74, 155, 0.65);
}

.title-credit {
  right: 28px;
  bottom: 22px;
  left: 28px;
  text-align: right;
  font-family: var(--font-en), monospace;
  font-size: 10px;
  letter-spacing: 1.8px;
  color: rgba(239, 232, 245, 0.64);
}

#name-screen {
  background:
    linear-gradient(90deg, rgba(7, 6, 10, 0.9), rgba(7, 6, 10, 0.55)),
    url("assets/bg_bugfeed_alley.png") center / cover no-repeat,
    #08070b;
}

.name-entry-card {
  border-radius: 3px;
  background: rgba(9, 8, 12, 0.88);
  border: 1px solid rgba(240, 74, 155, 0.42);
  box-shadow: 0 18px 65px rgba(0, 0, 0, 0.55);
  animation: none;
}

.name-entry-icon {
  font-family: var(--font-en), monospace;
  color: #f04a9b;
  font-size: 18px;
  letter-spacing: 0.22em;
  filter: none;
  animation: none;
}

.name-entry-title {
  background: none;
  color: #f7f2fa;
  -webkit-text-fill-color: currentColor;
}

.name-input {
  caret-color: #f04a9b;
}

.name-input-underline {
  background: linear-gradient(90deg, transparent, #62d5e8, #f04a9b, transparent);
  animation: none;
}

.suggest-btn {
  border-radius: 2px;
  color: #ded4ee;
  background: rgba(240, 74, 155, 0.1);
  border-color: rgba(240, 74, 155, 0.34);
}

#novel-screen {
  padding: 22px clamp(18px, 4vw, 62px) 28px;
}

.chapter-badge,
.nav-btn {
  color: #f4edf7;
  border-radius: 2px;
  background: rgba(9, 8, 12, 0.72);
  border-color: rgba(222, 212, 230, 0.22);
}

.chapter-badge {
  border-left: 2px solid #f04a9b;
  letter-spacing: 0.08em;
}

.nav-btn.active {
  background: #b72b6d;
  box-shadow: 0 0 15px rgba(240, 74, 155, 0.35);
}

.sprite-wrap.girl {
  right: auto;
  left: clamp(7%, calc(50% - 460px), 24%);
  animation: breathing 4s ease-in-out infinite;
}

.sprite-wrap.boy {
  right: clamp(7%, calc(50% - 460px), 24%);
  left: auto;
  animation: breathing 4.2s ease-in-out infinite 0.5s;
}

.character-sprite {
  height: min(84vh, 860px);
  max-width: min(46vw, 600px);
  object-fit: contain;
  filter: drop-shadow(0 18px 36px rgba(0, 0, 0, 0.8));
}

.sprite-wrap[data-framing="bust"] .character-sprite {
  transform: scale(1.42);
  transform-origin: center 6%;
}

.sprite-wrap[data-framing="close"] .character-sprite {
  transform: scale(1.68);
  transform-origin: center 6%;
}

.dialogue-box {
  max-width: 1060px;
  min-height: 160px;
  padding: 22px 26px;
  border-radius: 3px;
  border: 1px solid rgba(240, 74, 155, 0.52);
  background: linear-gradient(120deg, rgba(8, 7, 11, 0.94), rgba(17, 12, 20, 0.84));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}

.dialogue-avatar {
  border-radius: 2px;
  border-color: rgba(240, 74, 155, 0.45);
}

.avatar-glow {
  background: linear-gradient(135deg, #f04a9b, transparent 65%, #62d5e8);
}

.speaker-name {
  font-family: var(--font-en), var(--font-main);
  text-shadow: none;
}

.emotion-tag {
  color: #ffd5e8;
  border-radius: 2px;
  background: rgba(240, 74, 155, 0.12);
  border-color: rgba(240, 74, 155, 0.36);
}

.heart-pulse,
.click-indicator {
  color: #f04a9b;
}

.choices-container {
  top: 43%;
  max-width: 650px;
}

.choice-btn {
  border-radius: 2px;
  border-color: rgba(240, 74, 155, 0.55);
  background: rgba(10, 9, 14, 0.94);
}

.choice-btn:hover {
  background: rgba(139, 31, 83, 0.94);
  border-color: #ff83bd;
  box-shadow: 0 8px 28px rgba(240, 74, 155, 0.2);
}

.choice-num {
  color: #62d5e8;
  border-radius: 2px;
  background: rgba(98, 213, 232, 0.1);
}

.event-cg-layer {
  background: rgba(4, 4, 7, 0.96);
}

.event-cg-layer img {
  max-width: min(98%, 1500px);
  max-height: min(84vh, 920px);
  object-fit: contain;
  border-radius: 2px;
  border: 1px solid rgba(240, 74, 155, 0.5);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.7);
}

.cg-caption {
  color: #f7eaf3;
  font-family: var(--font-en), var(--font-main);
  letter-spacing: 0.05em;
}

.system-alert {
  position: absolute;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(3, 3, 7, 0.58);
  backdrop-filter: blur(3px);
}

.system-alert.hidden {
  display: none;
}

.system-alert-window {
  width: min(440px, 100%);
  padding: 0 22px 22px;
  color: #f7f2fa;
  background: #100d15;
  border: 1px solid rgba(240, 74, 155, 0.8);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.72), 0 0 34px rgba(240, 74, 155, 0.16);
  animation: alertAppear 180ms ease-out both;
}

.system-alert-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 38px;
  margin: 0 -22px 20px;
  padding: 0 14px;
  color: #efc5da;
  background: rgba(240, 74, 155, 0.12);
  border-bottom: 1px solid rgba(240, 74, 155, 0.28);
  font: 11px var(--font-en), monospace;
  letter-spacing: 0.16em;
}

.system-alert-bar button {
  color: #e9dbe5;
  background: transparent;
  font-size: 22px;
}

.system-alert-content {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.system-alert-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  flex: 0 0 auto;
  color: #100d15;
  background: #f04a9b;
  border-radius: 50%;
  font: 800 20px var(--font-en), sans-serif;
}

.system-alert-content h2 {
  margin: 1px 0 8px;
  font-size: 17px;
}

.system-alert-content p {
  color: #c9c1ce;
  font-size: 14px;
  line-height: 1.7;
}

.system-alert-confirm {
  display: block;
  min-width: 130px;
  margin: 20px 0 0 auto;
  padding: 9px 16px;
  color: #fff;
  background: #bd2f72;
  border: 1px solid #f04a9b;
  border-radius: 2px;
}

.system-alert-confirm:hover {
  background: #e23e8a;
}

@keyframes alertAppear {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

body.glitching #game-container::after {
  position: absolute;
  inset: 0;
  z-index: 45;
  content: "";
  pointer-events: none;
  opacity: 0.42;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(217, 227, 255, 0.075) 4px, transparent 5px 8px);
  mix-blend-mode: screen;
  animation: scanJitter 1.8s steps(2, end) infinite;
}

body.glitching .bg-layer {
  filter: saturate(1.15) brightness(0.62) hue-rotate(-8deg);
  animation: backgroundGlitch 5s steps(1, end) infinite;
}

body.glitching .character-sprite {
  filter: drop-shadow(3px 0 rgba(240, 74, 155, 0.56)) drop-shadow(-3px 0 rgba(98, 213, 232, 0.4));
}

body[data-scene="rain-deck"] .ambient-overlay {
  background:
    repeating-linear-gradient(104deg, transparent 0 31px, rgba(192, 218, 255, 0.09) 32px, transparent 33px 64px),
    linear-gradient(180deg, rgba(13, 17, 30, 0.15), rgba(9, 11, 20, 0.55) 58%, rgba(7, 8, 13, 0.94));
}

.modal-card {
  border-radius: 3px;
  background: rgba(11, 9, 14, 0.97);
  border-color: rgba(240, 74, 155, 0.38);
}

.modal-header {
  border-bottom-color: rgba(240, 74, 155, 0.22);
}

.gallery-card {
  border-radius: 2px;
  border-color: rgba(240, 74, 155, 0.3);
}

.gallery-card:hover {
  border-color: #f04a9b;
}

.toast-notify {
  border-color: rgba(240, 74, 155, 0.7);
  border-radius: 2px;
  background: rgba(12, 9, 15, 0.95);
}

@keyframes scanJitter {
  0%, 86%, 100% { transform: translateX(0); }
  88% { transform: translateX(3px); }
  91% { transform: translateX(-2px); }
  95% { transform: translateX(1px); }
}

@keyframes backgroundGlitch {
  0%, 90%, 94%, 100% { transform: scale(1.025); }
  91% { transform: translateX(3px) scale(1.025); }
  92% { transform: translateX(-2px) scale(1.025); }
}

@media (max-width: 760px) {
  #game-container {
    min-height: 520px;
  }

  #title-screen {
    background-position: 59% center;
  }

  .title-content {
    align-self: flex-end;
    width: calc(100% - 38px);
    margin: 0 19px 7vh;
    padding: 20px 0;
  }

  .title-badges {
    flex-wrap: wrap;
    margin-bottom: 17px;
  }

  .badge-tag,
  .badge-cat {
    font-size: 8px;
    letter-spacing: 1px;
  }

  .main-title {
    font-size: clamp(48px, 15vw, 76px);
  }

  .title-menu {
    max-width: 100%;
  }

  .title-credit {
    right: 14px;
    bottom: 10px;
    left: 14px;
    font-size: 8px;
  }

  #novel-screen {
    padding: 12px 12px 14px;
  }

  .game-header {
    align-items: flex-start;
    gap: 8px;
  }

  .chapter-badge {
    max-width: 43vw;
    padding: 7px 9px;
    font-size: 10px;
    line-height: 1.35;
  }

  .quick-nav {
    max-width: 55vw;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 4px;
  }

  .nav-btn {
    padding: 6px 8px;
    font-size: 9px;
  }

  .characters-stage {
    bottom: 116px;
  }

  .sprite-wrap.girl {
    left: 2%;
  }

  .sprite-wrap.boy {
    right: 2%;
  }

  .character-sprite {
    height: min(64vh, 520px);
    max-width: 68vw;
  }

  .sprite-wrap[data-framing="bust"] .character-sprite {
    transform: scale(1.3);
    transform-origin: center 6%;
  }

  .sprite-wrap[data-framing="close"] .character-sprite {
    transform: scale(1.48);
    transform-origin: center 6%;
  }

  .dialogue-box {
    min-height: 146px;
    gap: 12px;
    padding: 14px 13px 20px;
  }

  .dialogue-avatar-wrap {
    width: 54px;
    height: 54px;
  }

  .speaker-name {
    font-size: 15px;
  }

  .emotion-tag {
    font-size: 9px;
  }

  .dialogue-text {
    font-size: 15px;
    line-height: 1.58;
  }

  .choices-container {
    top: 46%;
    width: calc(100% - 26px);
    gap: 8px;
  }

  .choice-btn {
    padding: 12px 13px;
    font-size: 14px;
    line-height: 1.5;
  }

  .event-cg-layer img {
    max-width: 98%;
    max-height: 76vh;
  }

  .cg-caption {
    max-width: 92%;
    text-align: center;
    font-size: 14px;
  }

  .name-entry-card {
    padding: 34px 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* 新脚本版: CGの間も台詞を読み、会話の進行に合わせて構図を戻す。 */
html, body, #game-container, .screen { overflow: clip; }
.event-cg-layer.story-cg {
  z-index: 12;
  padding: 0;
  background: #08070b;
  overflow: hidden;
  isolation: isolate;
}
.event-cg-layer.story-cg img,
.event-cg-layer.gallery-cg img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
  max-width: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  object-fit: cover;
  object-position: center;
  animation: none;
}
.event-cg-layer.story-cg .cg-caption,
.event-cg-layer.story-cg .cg-hint { display: none; }
.event-cg-layer.gallery-cg {
  z-index: 80;
  padding: 0;
  overflow: hidden;
  isolation: isolate;
  background: #08070b;
}
.event-cg-layer.gallery-cg .cg-caption,
.event-cg-layer.gallery-cg .cg-hint {
  position: absolute;
  z-index: 2;
  left: 20px;
  right: 20px;
  max-width: none;
  margin: 0;
  text-align: center;
  text-shadow: 0 2px 12px #000;
}
.event-cg-layer.gallery-cg .cg-caption { bottom: 52px; }
.event-cg-layer.gallery-cg .cg-hint { bottom: 24px; }
.event-cg-layer.gallery-cg::after {
  content: '';
  position: absolute;
  inset: 65% 0 0;
  pointer-events: none;
  background: linear-gradient(transparent, #08070bc7);
}
/* 縦長ではふたりを切らず、画面の端まで同じCGの色を敷く。 */
@media (max-aspect-ratio: 1/1) {
  .event-cg-layer.story-cg::before,
  .event-cg-layer.gallery-cg::before {
    content: '';
    position: absolute;
    inset: -20px;
    background: var(--cg-backdrop) center / cover no-repeat;
    filter: blur(16px);
    opacity: .4;
    pointer-events: none;
  }
  .event-cg-layer.story-cg img,
  .event-cg-layer.gallery-cg img { object-fit: contain; }
}

/* エンディングの回想: 顔を切らず、曲とともに画像を重ねる。 */
.memory-reel {
  position: absolute;
  inset: 0;
  z-index: 70;
  background: #08070b;
  opacity: 1;
  transition: opacity 1.8s cubic-bezier(.32,.72,0,1);
}
.memory-reel.hidden { display: none; }
.memory-reel.leaving { opacity: 0; pointer-events: none; }
.memory-images { position: absolute; inset: 68px 18px 110px; overflow: hidden; }
.memory-image { position: absolute; width: 100%; height: 100%; object-fit: contain; opacity: 0; }
.memory-heading {
  position: absolute; top: 24px; left: 32px; right: 32px;
  display: flex; justify-content: space-between; gap: 20px;
  font-size: 12px; letter-spacing: .14em; color: #a8a0b2;
}
.memory-heading span:first-child { color: #e3dbe8; }
.memory-footer {
  position: absolute; bottom: 24px; left: 32px; right: 32px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 24px;
}
.memory-caption { margin: 0 0 9px; color: #eee6ef; font-size: 14px; line-height: 1.7; }
.memory-count { color: #938999; font-size: 10px; letter-spacing: .2em; }
.memory-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.memory-controls button {
  color: #d7cdda; background: #17121c; border: 1px solid #443448;
  padding: 10px 14px; font: inherit; font-size: 11px; cursor: pointer;
  transition: background .3s cubic-bezier(.32,.72,0,1);
}
.memory-controls button:hover, .memory-controls button:focus-visible {
  background: #352039; outline: 1px solid #ac719e; outline-offset: 3px;
}
body.recollecting .game-header, body.recollecting .characters-stage,
body.recollecting .dialogue-box, body.recollecting .choices-container,
body.recollecting #toast-notify { visibility: hidden; }
@media (max-width: 760px) {
  .memory-heading { top: 20px; left: 18px; right: 18px; font-size: 10px; }
  .memory-images { inset: 54px 6px 156px; }
  .memory-footer { left: 18px; right: 18px; bottom: 22px; flex-direction: column; align-items: flex-start; gap: 16px; }
  .memory-caption { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .memory-image { transform: none !important; }
}
body[data-scene="dawn"] .bg-layer {
  background: linear-gradient(115deg, #28232f 0%, #686070 48%, #dad0c8 100%);
  filter: none;
}
body[data-scene="dawn"] .ambient-overlay {
  background: linear-gradient(180deg, rgba(240,218,200,.12), rgba(18,15,23,.68));
}
.dialogue-text { max-height: 24vh; overflow-y: auto; }
@media (max-width: 760px) {
  .event-cg-layer.story-cg { padding: 0; }
  .chapter-badge { max-width: 100%; white-space: normal; line-height: 1.4; }
  .choices-container { top: 24%; }
}
@media (prefers-reduced-motion: reduce) {
  .event-cg-layer img { animation: none; }
}

/* 地の文にはキャラクターの顔や表情ラベルを付けない。 */
.dialogue-box:is([data-speaker-kind="narration"], [data-speaker-kind="system"]) .dialogue-avatar-wrap,
.dialogue-box:is([data-speaker-kind="narration"], [data-speaker-kind="system"]) .emotion-tag,
.dialogue-box:is([data-speaker-kind="narration"], [data-speaker-kind="system"]) .heart-pulse,
.dialogue-box[data-speaker-kind="narration"] .speaker-row { display: none; }
.dialogue-box[data-speaker-kind="system"] .speaker-name { color: #c9c4da; }
