/* ===== リセット ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ui-safe-top: max(10px, env(safe-area-inset-top));
  --ui-safe-right: max(10px, env(safe-area-inset-right));
  --ui-safe-bottom: max(10px, env(safe-area-inset-bottom));
  --ui-safe-left: max(10px, env(safe-area-inset-left));
}

body {
  background: #000;
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Noto Sans JP', 'Hiragino Sans', 'Yu Gothic', sans-serif;
  overflow: hidden;
}

/* ===== ゲームコンテナ ===== */
#game-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #111;
  overflow: hidden;
  user-select: none;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  isolation: isolate;
}

#game-container.layout-responsive {
  width: min(100vw, calc(100dvh * (16 / 9)));
  height: min(100dvh, calc(100vw * (9 / 16)));
  max-width: 100vw;
  max-height: 100dvh;
  aspect-ratio: var(--game-aspect, 16 / 9);
}

@media (orientation: portrait) {
  #game-container.layout-responsive {
    width: 100vw;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100dvh;
    aspect-ratio: auto;
  }
}

/* ===== 背景レイヤー ===== */
#bg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.5s ease;
  z-index: 1;
}

#bg-video-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.5s ease;
  z-index: 1;
}

/* ===== スプライトステージ ===== */
#sprite-stage {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}

.sprite {
  position: absolute;
  bottom: 0;
  max-height: 90%;
  width: auto;
  transform: translateX(-50%);
  transition: opacity 0.4s ease, left 0.5s ease;
  opacity: 0;
}

.sprite--visible {
  opacity: 1;
}

/* ===== テキストボックス ===== */
#text-box {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: clamp(188px, 34%, 290px);
  background: linear-gradient(180deg, rgba(2, 6, 12, 0.18) 0%, rgba(3, 8, 18, 0.88) 10%, rgba(2, 6, 12, 0.96) 100%);
  border-top: 1px solid rgba(150, 198, 255, 0.24);
  padding: clamp(16px, 2.2vmin, 24px) clamp(18px, 3vmin, 34px) clamp(18px, 2.4vmin, 28px);
  z-index: 10;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(10px);
}

#speaker-name {
  color: #ffd166;
  font-size: clamp(17px, 2.2vmin, 24px);
  font-weight: bold;
  margin-bottom: clamp(8px, 1.2vmin, 12px);
  min-height: clamp(26px, 3.1vmin, 34px);
  letter-spacing: 0.04em;
}

#text-content {
  color: #fff;
  font-size: clamp(18px, 2.15vmin, 24px);
  line-height: 1.82;
  letter-spacing: 0.02em;
  flex: 1;
  overflow-y: auto;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

/* ===== 選択肢 ===== */
#choice-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  flex-direction: column;
  justify-content: safe center;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: rgba(0, 0, 0, 0.5);
  z-index: 15;
}

#choice-container.story-menu-container {
  justify-content: center;
  align-items: center;
  gap: clamp(8px, 1.6vmin, 14px);
  padding: clamp(56px, 9vmin, 76px) clamp(18px, 4vmin, 42px) clamp(28px, 5vmin, 48px);
  background:
    linear-gradient(180deg, rgba(3, 12, 14, 0.96) 0%, rgba(5, 18, 20, 0.9) 42%, rgba(3, 10, 12, 0.94) 100%);
  backdrop-filter: blur(1px);
}

#choice-container.choice-card-mode {
  justify-content: center;
  gap: clamp(8px, 1.6vmin, 14px);
  padding: clamp(56px, 9vmin, 72px) clamp(16px, 4vmin, 36px) clamp(28px, 5vmin, 46px);
  background:
    linear-gradient(180deg, rgba(5, 14, 24, 0.96) 0%, rgba(8, 24, 40, 0.9) 42%, rgba(4, 10, 18, 0.94) 100%);
  backdrop-filter: blur(1px);
}

#choice-container::before,
#choice-container::after {
  content: '';
  flex: 1 0 0px;
}

#choice-container.story-menu-container::before,
#choice-container.story-menu-container::after {
  flex: 0 0 0px;
}

#choice-container.choice-card-mode::before,
#choice-container.choice-card-mode::after {
  flex: 0 0 0px;
}

.choice-card-list {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: min(860px, 88%);
  max-height: 100%;
  gap: clamp(8px, 1.8vmin, 14px);
  justify-content: flex-start;
  overflow: visible;
}

.choice-btn {
  flex-shrink: 0;
  padding: clamp(10px, 2vmin, 14px) clamp(20px, 5vmin, 40px);
  min-width: clamp(200px, 60vw, 280px);
  min-height: 52px;
  font-size: clamp(16px, 2vmin, 18px);
  font-family: inherit;
  color: #fff;
  background: linear-gradient(180deg, rgba(17, 33, 70, 0.92) 0%, rgba(11, 24, 54, 0.98) 100%);
  border: 1px solid rgba(116, 177, 255, 0.45);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, transform 0.12s, border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.22);
}

.choice-btn:hover {
  background: linear-gradient(180deg, rgba(31, 58, 115, 0.96) 0%, rgba(14, 34, 79, 1) 100%);
  border-color: rgba(141, 198, 255, 0.78);
  transform: translateY(-2px);
}

.choice-btn:active {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

.choice-btn:focus-visible {
  outline: 2px solid rgba(173, 220, 255, 0.7);
  outline-offset: 2px;
}

.choice-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(10px, 2vmin, 16px);
  width: min(760px, 100%);
  max-width: 760px;
  min-height: clamp(72px, 10vmin, 92px);
  padding: clamp(12px, 1.9vmin, 18px) clamp(16px, 3.2vmin, 26px);
  text-align: left;
  border-radius: 14px;
  border-width: 1.5px;
  border-left-width: 6px;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.32);
  touch-action: manipulation;
  white-space: normal;
  hyphens: auto;
}

.choice-card:active {
  transform: translateY(-1px);
  background: linear-gradient(180deg, rgba(27, 53, 105, 0.96) 0%, rgba(9, 28, 62, 1) 100%);
  border-color: rgba(167, 214, 255, 0.82);
}

.choice-card-title {
  flex: 1;
  min-width: 0;
  font-size: clamp(17px, 2.1vmin, 21px);
  line-height: 1.25;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-wrap: pretty;
  hyphens: auto;
}

.choice-card-arrow {
  flex-shrink: 0;
  font-size: clamp(18px, 2.4vmin, 22px);
  opacity: 0.84;
  color: #9ad0ff;
  transition: transform 0.12s;
  flex-basis: 24px;
}

.choice-card:hover .choice-card-arrow {
  transform: translateX(2px);
}

/* ===== メニューバー ===== */
#menu-bar {
  position: absolute;
  top: var(--ui-safe-top);
  right: var(--ui-safe-right);
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: clamp(6px, 0.8vmin, 10px);
  z-index: 20;
  max-width: calc(100% - var(--ui-safe-left) - var(--ui-safe-right));
}

.menu-btn {
  position: relative;
  padding: 0 clamp(10px, 1.2vmin, 14px);
  font-size: clamp(12px, 1.35vmin, 14px);
  min-height: clamp(40px, 4.6vmin, 52px);
  min-width: clamp(72px, 7.2vmin, 92px);
  font-family: inherit;
  color: #ccc;
  background: linear-gradient(180deg, rgba(8, 15, 30, 0.78) 0%, rgba(3, 8, 18, 0.9) 100%);
  border: 1px solid rgba(140, 194, 255, 0.24);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.12s;
  touch-action: manipulation;
  backdrop-filter: blur(8px);
}

.menu-btn:hover {
  background: linear-gradient(180deg, rgba(19, 34, 64, 0.88) 0%, rgba(8, 20, 42, 0.96) 100%);
  color: #fff;
  border-color: rgba(140, 194, 255, 0.5);
  transform: translateY(-1px);
}

@media (max-width: 700px), (orientation: portrait) {
  #menu-bar {
    top: max(4px, env(safe-area-inset-top));
    right: max(4px, env(safe-area-inset-right));
    gap: 4px;
  }

  .menu-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 0;
    border-radius: 6px;
  }

  .menu-btn::before {
    font-size: 18px;
    line-height: 1;
  }

  #btn-auto::before { content: 'A'; }
  #btn-save::before { content: 'S'; }
  #btn-load::before { content: 'L'; }
  #btn-log::before { content: 'Log'; font-size: 12px; }
  #btn-config::before { content: '⚙'; }

  #text-box {
    height: 38%;
    min-height: 112px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  #overlay-content {
    min-width: 0;
    width: min(92vw, 520px);
    max-height: 82dvh;
  }
}

.menu-btn-active {
  background: rgba(100, 180, 255, 0.5);
  color: #fff;
  border-color: rgba(100, 180, 255, 0.6);
}

/* ===== タイトル画面 ===== */
#title-screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 20px;
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  z-index: 50;
}

#title-name {
  color: #fff;
  font-size: 32px;
  font-weight: bold;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  margin-bottom: 40px;
}

.title-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 50px;
  min-width: 200px;
  min-height: 44px;
  line-height: 1.2;
  font-size: 18px;
  font-family: inherit;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.title-btn:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* ===== タイトルバナー ===== */
.title-banner {
  position: absolute;
  cursor: pointer;
  z-index: 51;
  line-height: 0;
}

.title-banner img {
  display: block;
}

/* ===== オーバーレイ ===== */
#overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
}

#overlay-content {
  background: #1e1e2e;
  color: #fff;
  padding: 24px;
  border-radius: 8px;
  max-width: 90%;
  max-height: 85%;
  overflow-y: auto;
  min-width: 320px;
}

#overlay-content h2 {
  margin-bottom: 16px;
  font-size: 20px;
  color: #ffd700;
}

.save-slots {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.save-slot-btn {
  padding: 8px 16px;
  font-size: 14px;
  font-family: inherit;
  color: #ddd;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
  transition: background 0.2s;
}

.save-slot-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
}

.save-slot-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.overlay-close-btn {
  padding: 8px 24px;
  font-size: 14px;
  font-family: inherit;
  color: #fff;
  background: rgba(100, 100, 100, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  cursor: pointer;
}

.overlay-close-btn:hover {
  background: rgba(100, 100, 100, 0.7);
}

/* ===== バックログ ===== */
.backlog {
  max-height: 60vh;
  overflow-y: auto;
  margin-bottom: 16px;
  padding-right: 8px;
  scrollbar-width: thin;
  scrollbar-color: #666 #222;
}

.backlog p {
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.5;
  color: #ccc;
}

.backlog p strong {
  color: #ffd700;
}

/* ===== 設定パネル ===== */
.config-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.config-panel label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  color: #ccc;
}

.config-panel input[type="range"] {
  width: 100%;
}

/* ===== ステータスパネル ===== */
#status-panel {
  position: absolute;
  top: 28px;
  right: 0;
  min-width: 120px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-top: none;
  border-right: none;
  border-bottom-left-radius: 6px;
  z-index: 18;
  font-size: 12px;
  color: #ccc;
  pointer-events: none;
}

.char-container {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}

.char-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex-shrink: 0;
}

.param-info {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
}

.param-label {
  color: #aaa;
  flex-shrink: 0;
}

.param-value {
  color: #fff;
  font-weight: bold;
  min-width: 28px;
  text-align: right;
  margin-left: auto;
}

/* ===== 座標配置モード（positioned-mode） ===== */
#status-panel.positioned-mode {
  top: 0;
  left: 0;
  right: auto;
  width: 100%;
  height: 100%;
  min-width: auto;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
}

#status-panel.positioned-mode .char-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(3, 10, 14, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  padding: 5px;
  gap: 2px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.32);
}

#status-panel.positioned-mode .char-icon {
  width: clamp(58px, 7.2vmin, 86px);
  height: clamp(58px, 7.2vmin, 86px);
}

#status-panel.positioned-mode .param-value {
  margin-left: 0;
  text-align: center;
}

#status-panel.positioned-mode .param-info {
  width: 100%;
  gap: 6px;
  font-size: clamp(10px, 1.35vmin, 12px);
  line-height: 1.1;
}

#status-panel.positioned-mode .param-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: clamp(48px, 6vmin, 68px);
}

/* 選択肢表示中はステータスアイコン（収集ログ等）を一時的に隠す
   choice-card-mode で choice-container が前面オーバーレイとなり、
   アイコンと選択肢ボタンが視覚的に重なるのを避けるため。
   選択完了でクラスが除去され、即座に再表示される。
   media query 内の positioned-mode 上書きに勝つため !important 指定。 */
#status-panel.choice-active,
#status-panel.choice-active.positioned-mode,
#status-panel.choice-active.positioned-mode .char-container {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transition: opacity 0.18s ease !important;
}

/* パラメータ変化アニメーション（色+スケールはJSで制御 — @char_color 対応） */

/* パラメータ変化フローティング通知（ポップアップ表示中も前面に表示） */
.param-notification {
  position: absolute;
  left: 50%;
  bottom: 40%;
  transform: translateX(-50%);
  font-size: 18px;
  font-weight: bold;
  pointer-events: none;
  z-index: 90;
  white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  animation: paramNotifFloat 1.5s ease-out forwards;
}


@keyframes paramNotifFloat {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0); }
  70%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-40px); }
}

/* ===== トロープ獲得通知 ===== */
/* ポップアップ表示中でも前面に表示するため popup-overlay(80) より高い z-index */
.trope-notification {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  font-weight: bold;
  color: #ffd700;
  text-shadow: 0 0 12px rgba(255, 215, 0, 0.6), 0 2px 4px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 90;
  /* 長いトロープ名（英語）でも画面からはみ出さないよう折り返し可・幅制限・中央寄せ */
  white-space: normal;
  max-width: min(90%, 620px);
  text-align: center;
  line-height: 1.3;
  animation: tropeNotifAppear 2.5s ease-out forwards;
}

/* ラベルとトロープ名をそれぞれ独立した行に（label=1行目 / name=2行目） */
.trope-notification .trope-notif-line {
  display: block;
}
/* ラベル行は常に1行（折り返さない）→ ボックス幅がラベル分確保され、短い名前でもラベルが割れない */
.trope-notification .trope-notif-line:not(.trope-notif-nameline) {
  white-space: nowrap;
}
/* 名前行（名前＋装飾＋回数）はまとめて1行で表示し、ラベル行とあわせて常に2行に収める */
.trope-notification .trope-notif-nameline,
.trope-notification .trope-notif-name {
  white-space: nowrap;
}

.trope-notification--duplicate {
  opacity: 0.7;
}

/* ===== ストーリーメニュー ===== */
.story-menu-btn {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.6vmin, 14px);
  width: min(760px, 78%);
  min-width: min(360px, 92%);
  max-width: 760px;
  min-height: clamp(72px, 10vmin, 92px);
  padding: clamp(9px, 1.8vmin, 14px) clamp(14px, 3vmin, 24px);
  background: rgba(22, 48, 94, 0.92);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  touch-action: manipulation;
}

.story-menu-btn:focus-visible {
  outline: 2px solid rgba(173, 220, 255, 0.7);
  outline-offset: 2px;
}

.story-menu-thumb {
  width: clamp(56px, 8vmin, 76px);
  height: clamp(56px, 8vmin, 76px);
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.24);
  flex-shrink: 0;
}

.story-menu-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.story-menu-btn--cleared {
  border-color: rgba(255, 215, 0, 0.4);
}

.story-menu-btn--new {
  border-color: rgba(255, 68, 68, 0.5);
  background: rgba(60, 30, 30, 0.85);
}

.story-menu-title {
  flex: 1;
  text-align: left;
  font-size: clamp(15px, 2vmin, 18px);
  line-height: 1.25;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.story-menu-age {
  color: rgba(255, 220, 170, 0.9);
  font-size: clamp(11px, 1.45vmin, 13px);
  text-align: left;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.story-menu-profile {
  color: rgba(255, 255, 255, 0.74);
  font-size: clamp(11px, 1.55vmin, 13px);
  line-height: 1.4;
  text-align: left;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.story-badge {
  font-size: 0.8em;
  font-weight: bold;
  flex-shrink: 0;
}

.story-badge--cleared {
  color: #ffd700;
}

.story-badge--new {
  color: #ff4444;
}

.story-trope-progress {
  font-size: clamp(12px, 1.7vmin, 15px);
  opacity: 0.7;
  flex-shrink: 0;
  min-width: 44px;
  text-align: right;
}

.story-menu-pagination {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 4px;
}

.story-menu-page-btn {
  padding: 6px 16px;
  min-width: auto;
  font-size: 14px;
}

.story-menu-page-label {
  color: #ccc;
  font-size: 14px;
  min-width: 50px;
  text-align: center;
}

.story-menu-gallery-btn {
  margin-top: clamp(8px, 1.8vmin, 14px);
  border-top: 1px solid rgba(255,255,255,0.15);
  padding-top: clamp(10px, 1.8vmin, 14px);
  opacity: 0.85;
  font-size: 0.9em;
}

@media (max-width: 700px), (orientation: portrait) {
  #choice-container.choice-card-mode {
    justify-content: flex-start;
    align-items: center;
    padding:
      calc(58px + env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      calc(18px + env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .choice-card-list {
    width: min(100%, 680px);
  }

  .choice-card {
    min-width: 0;
    min-height: 88px;
    padding: 12px 14px;
  }

  .choice-card-title {
    font-size: clamp(16px, 4.2vw, 19px);
  }

  .choice-card-arrow {
    font-size: 20px;
  }

  #choice-container.story-menu-container {
    justify-content: flex-start;
    padding: calc(58px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .story-menu-btn {
    width: min(100%, 520px);
    min-width: 0;
    min-height: 76px;
  }

  .story-menu-profile {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  #status-panel.positioned-mode .char-container {
    left: max(8px, env(safe-area-inset-left)) !important;
    top: calc(54px + env(safe-area-inset-top)) !important;
  }

  #status-panel.positioned-mode.story-menu-active {
    display: none !important;
  }
}

@keyframes tropeNotifAppear {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  25%  { transform: translate(-50%, -50%) scale(1.0); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) translateY(-20px); }
}

/* NEW! バッジ */
.trope-new-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ff4444;
  color: #fff;
  font-size: 9px;
  font-weight: bold;
  padding: 1px 4px;
  border-radius: 4px;
  z-index: 1;
  text-shadow: none;
}

/* ===== 動画レイヤー ===== */
#video-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 5;
  cursor: pointer;
  background: #000;
}

/* ===== ポップアップ ===== */
#popup-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  background: transparent;
  z-index: 80;
  pointer-events: none;
}

/* メニューバー下〜テキストボックス上の上下中央に配置（オート・セーブ・ロードと重ならないように） */
#popup-content {
  position: absolute;
  left: 50%;
  top: calc(28px + (65% - 28px) / 2);
  transform: translate(-50%, -50%);
  /* 固定サイズを使わず画像の自然なアスペクト比に従う */
  max-width: 90%;
  max-height: calc(65% - 28px - 16px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#popup-content img,
#popup-content video {
  max-width: 90vmin;
  max-height: calc(65vh - 28px - 16px);
  width: auto;
  height: auto;
  object-fit: contain;
  border: 1px solid rgba(136, 136, 136, 0.5);
  border-radius: 4px;
  image-rendering: auto;
  image-rendering: -webkit-optimize-contrast;
  animation: popup-fade-in 0.25s ease-out;
}

@keyframes popup-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

#popup-content.popup-fading-out img,
#popup-content.popup-fading-out video {
  animation: popup-fade-out 0.15s ease-in forwards;
}

@keyframes popup-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ===== カード選択システム ===== */
#card-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 24px;
  background: rgba(0, 0, 0, 0.6);
  z-index: 15;
}

.card {
  width: clamp(100px, 20vmin, 140px);
  height: clamp(150px, 30vmin, 210px);
  perspective: 800px;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.card:hover {
  transform: translateY(-8px);
}

.card.fade-out {
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s ease;
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card.flipped {
  cursor: default;
}

.card-back,
.card-front {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* カード色変数定義 */
.card-pink   { --card-rgb: 255,105,180; --card-dark: #c71585; --card-darkest: #8b0045; --card-light-rgb: 255,105,180; }
.card-red    { --card-rgb: 255,68,68;   --card-dark: #cc0000; --card-darkest: #8b0000; --card-light-rgb: 255,68,68; }
.card-purple { --card-rgb: 155,89,182;  --card-dark: #6a0dad; --card-darkest: #3d0066; --card-light-rgb: 155,89,182; }
.card-blue   { --card-rgb: 79,195,247;  --card-dark: #0277bd; --card-darkest: #01579b; --card-light-rgb: 79,195,247; }
.card-gold   { --card-rgb: 255,215,0;   --card-dark: #b8860b; --card-darkest: #8b6914; --card-light-rgb: 255,215,0; }
.card-silver { --card-rgb: 192,192,192; --card-dark: #808080; --card-darkest: #585858; --card-light-rgb: 192,192,192; }
.card-bronze { --card-rgb: 205,127,50;  --card-dark: #8b4513; --card-darkest: #5c2e0a; --card-light-rgb: 205,127,50; }
.card-green  { --card-rgb: 102,187,106; --card-dark: #2e7d32; --card-darkest: #1b5e20; --card-light-rgb: 102,187,106; }

/* カード裏面 — 色でカード種類を示す */
.card-back {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  background: linear-gradient(135deg, rgb(var(--card-rgb)) 0%, var(--card-dark) 50%, var(--card-darkest) 100%);
  border-color: rgba(var(--card-light-rgb), 0.5);
}

.card-mystery .card-back {
  background: linear-gradient(135deg, #2a1f3d 0%, #1a1028 100%);
  border: 1px solid rgba(200, 150, 255, 0.3);
}

.card-symbol {
  font-size: 48px;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* カードopenモード — 表面を見せて選択 */
.card-open-select {
  cursor: pointer;
  border: 2px solid rgba(255, 215, 0, 0.5);
  border-radius: 10px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.card-open-select:hover {
  transform: translateY(-8px) scale(1.05);
  box-shadow: 0 8px 24px rgba(255, 215, 0, 0.4);
  border-color: rgba(255, 215, 0, 0.9);
}

.card-selected {
  border: 3px solid #ffd700;
  border-radius: 10px;
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

/* openモード — 色クラス別ボーダー（CSS変数で統一） */
.card-open-select {
  border-color: rgba(var(--card-light-rgb), 0.5);
}
.card-open-select:hover {
  box-shadow: 0 8px 24px rgba(var(--card-light-rgb), 0.4);
  border-color: rgba(var(--card-light-rgb), 0.9);
}
.card-selected {
  border-color: rgb(var(--card-light-rgb));
  box-shadow: 0 0 20px rgba(var(--card-light-rgb), 0.6);
}

/* カード表面 — 名前・説明 */
.card-front {
  transform: rotateY(180deg);
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
  padding: 16px 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* カード表面 — 色クラス別背景（openモード用、CSS変数で統一） */
[class*="card-"] .card-front {
  border-color: rgba(var(--card-light-rgb), 0.3);
}

.card-name {
  color: #ffd700;
  font-size: 15px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 12px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.card-desc {
  color: #ccc;
  font-size: 11px;
  line-height: 1.6;
  text-align: center;
}

/* ===== トロープカード表示 ===== */
#trophy-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  /* タイトルがビューポート上部寄りに見えるよう flex-start + padding-top で位置調整。
     menu-bar との重なりを避けつつ、画面中央付近にコンテンツの主要部が来るように設定。 */
  justify-content: flex-start;
  background: rgba(0, 0, 0, 0.85);
  z-index: 15;
  padding: clamp(40px, 8vh, 90px) 16px clamp(20px, 4vh, 40px) 16px;
  overflow-y: auto;
}

.trophy-title {
  color: #ffd700;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 16px;
  text-shadow: 0 2px 8px rgba(255, 215, 0, 0.4);
  letter-spacing: 2px;
}

.trophy-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 600px;
  max-height: 340px;
  overflow-y: auto;
  padding: 4px;
}

.trophy-card {
  width: 110px;
  height: 80px;
  border-radius: 6px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  animation: trophyAppear 0.4s ease-out both;
  cursor: default;
  transition: transform 0.2s ease;
}

.trophy-card:hover {
  transform: scale(1.08);
  z-index: 2;
}

@keyframes trophyAppear {
  from {
    opacity: 0;
    transform: scale(0.5) rotateY(90deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotateY(0deg);
  }
}

/* Color variations */
.trophy-gold {
  background: linear-gradient(135deg, #ffd700 0%, #b8860b 50%, #8b6914 100%);
  border: 2px solid rgba(255, 215, 0, 0.6);
}

.trophy-silver {
  background: linear-gradient(135deg, #c0c0c0 0%, #808080 50%, #585858 100%);
  border: 2px solid rgba(192, 192, 192, 0.6);
}

.trophy-bronze {
  background: linear-gradient(135deg, #cd7f32 0%, #8b4513 50%, #5c2e0a 100%);
  border: 2px solid rgba(205, 127, 50, 0.6);
}

.trophy-pink {
  background: linear-gradient(135deg, #ff69b4 0%, #c71585 50%, #8b0045 100%);
  border: 2px solid rgba(255, 105, 180, 0.5);
}

.trophy-blue {
  background: linear-gradient(135deg, #4fc3f7 0%, #0277bd 50%, #01579b 100%);
  border: 2px solid rgba(79, 195, 247, 0.5);
}

.trophy-green {
  background: linear-gradient(135deg, #66bb6a 0%, #2e7d32 50%, #1b5e20 100%);
  border: 2px solid rgba(102, 187, 106, 0.5);
}

.trophy-purple {
  background: linear-gradient(135deg, #9b59b6 0%, #6a0dad 50%, #3d0066 100%);
  border: 2px solid rgba(155, 89, 182, 0.5);
}

.trophy-red {
  background: linear-gradient(135deg, #ff4444 0%, #cc0000 50%, #8b0000 100%);
  border: 2px solid rgba(255, 68, 68, 0.5);
}

.trophy-card-name {
  color: #fff;
  font-size: 11px;
  font-weight: bold;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  line-height: 1.3;
  margin-top: 2px;
}

.trophy-card-desc {
  color: rgba(255, 255, 255, 0.75);
  font-size: 9px;
  text-align: center;
  line-height: 1.2;
  margin-top: 2px;
}

.trophy-card-stars {
  font-size: 10px;
  line-height: 1;
}

.trophy-star-filled {
  color: #ffd700;
  text-shadow: 0 0 4px rgba(255, 215, 0, 0.6);
}

.trophy-star-empty {
  color: rgba(255, 255, 255, 0.3);
}

.trophy-close {
  color: rgba(255, 255, 255, 0.5);
  font-size: 12px;
  margin-top: 12px;
  cursor: pointer;
}

.trophy-close:hover {
  color: rgba(255, 255, 255, 0.8);
}

/* ===== ゲージバー ===== */
#gauge-container {
  position: absolute;
  left: 50%;
  bottom: 40%;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 16;
}

.gauge-bar {
  position: relative;
  width: 300px;
  height: 24px;
  background: rgba(30, 30, 50, 0.9);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
}

.gauge-success-zone {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(76, 175, 80, 0.4);
  border-left: 1px solid rgba(76, 175, 80, 0.6);
  border-right: 1px solid rgba(76, 175, 80, 0.6);
}

.gauge-cursor {
  position: absolute;
  top: -2px;
  width: 4px;
  height: calc(100% + 4px);
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
  transform: translateX(-50%);
}

.gauge-label {
  color: #ffd700;
  font-size: 14px;
  font-weight: bold;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  animation: gaugePulse 1s ease-in-out infinite;
}

@keyframes gaugePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ゲージ結果フラッシュ */
.gauge-result-success {
  background: rgba(76, 175, 80, 0.6) !important;
  transition: background 0.3s ease;
}

.gauge-result-fail {
  background: rgba(244, 67, 54, 0.6) !important;
  transition: background 0.3s ease;
}

/* ===== TTCV2 Responsive UI Override ===== */

#menu-bar {
  top: var(--ui-safe-top);
  right: var(--ui-safe-right);
  flex-wrap: nowrap;
  gap: clamp(6px, 0.8vmin, 10px);
  max-width: calc(100% - var(--ui-safe-left) - var(--ui-safe-right));
}

.menu-btn {
  position: relative;
  padding: 0 clamp(10px, 1.2vmin, 14px);
  font-size: clamp(12px, 1.35vmin, 14px);
  min-height: clamp(40px, 4.6vmin, 52px);
  min-width: clamp(72px, 7.2vmin, 92px);
  background: linear-gradient(180deg, rgba(8, 15, 30, 0.78) 0%, rgba(3, 8, 18, 0.9) 100%);
  border: 1px solid rgba(140, 194, 255, 0.24);
  border-radius: 10px;
  transition: background 0.2s, border-color 0.2s, transform 0.12s;
  backdrop-filter: blur(8px);
}

.menu-btn:hover {
  background: linear-gradient(180deg, rgba(19, 34, 64, 0.88) 0%, rgba(8, 20, 42, 0.96) 100%);
  border-color: rgba(140, 194, 255, 0.5);
  transform: translateY(-1px);
}

.menu-btn.has-label-image,
.title-btn.has-label-image {
  color: transparent;
}

.menu-btn.has-label-image::after,
.title-btn.has-label-image::after {
  content: '';
  position: absolute;
  inset: 8px;
  background-image: var(--label-image);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  pointer-events: none;
}

#text-box {
  height: clamp(188px, 34%, 290px);
  background: linear-gradient(180deg, rgba(2, 6, 12, 0.18) 0%, rgba(3, 8, 18, 0.88) 10%, rgba(2, 6, 12, 0.96) 100%);
  border-top: 1px solid rgba(150, 198, 255, 0.24);
  padding: clamp(16px, 2.2vmin, 24px) clamp(18px, 3vmin, 34px) clamp(18px, 2.4vmin, 28px);
  backdrop-filter: blur(10px);
}

#speaker-name {
  color: #ffd166;
  font-size: clamp(17px, 2.2vmin, 24px);
  margin-bottom: clamp(8px, 1.2vmin, 12px);
  min-height: clamp(26px, 3.1vmin, 34px);
  letter-spacing: 0.04em;
}

#text-content {
  font-size: clamp(18px, 2.15vmin, 24px);
  line-height: 1.82;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

#title-screen {
  justify-content: flex-end;
  gap: clamp(12px, 2vmin, 20px);
  padding: clamp(20px, 4vmin, 36px);
  padding-bottom: clamp(28px, 7vmin, 54px);
}

#title-screen.title-screen--has-art::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(2, 5, 12, 0.26) 0%, rgba(5, 9, 16, 0.1) 32%, rgba(4, 8, 18, 0.62) 72%, rgba(3, 7, 14, 0.88) 100%);
  z-index: -1;
}

.title-btn {
  position: relative;
  width: min(420px, 58vw);
  min-width: 240px;
  min-height: 64px;
  padding: 12px 28px;
  font-size: 20px;
  background: linear-gradient(180deg, rgba(8, 15, 30, 0.54) 0%, rgba(5, 11, 24, 0.78) 100%);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  transition: background 0.2s, transform 0.12s, border-color 0.2s;
  backdrop-filter: blur(8px);
}

.title-btn:hover {
  background: linear-gradient(180deg, rgba(16, 28, 58, 0.78) 0%, rgba(6, 16, 33, 0.9) 100%);
  border-color: rgba(255, 255, 255, 0.42);
  transform: translateY(-2px);
}

#status-panel {
  top: var(--ui-safe-top);
  left: var(--ui-safe-left);
  right: auto;
  min-width: 0;
  padding: 0;
  background: none;
  border: none;
}

#status-panel.positioned-mode .char-container {
  background: linear-gradient(180deg, rgba(3, 10, 18, 0.78) 0%, rgba(3, 8, 15, 0.9) 100%);
  border: 1px solid rgba(140, 194, 255, 0.26);
  border-radius: 14px;
  padding: 8px 8px 6px;
  gap: 6px;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.32);
  transform: translate(-50%, 0);
}

#status-panel.positioned-mode .char-icon {
  width: clamp(52px, 7vmin, 82px);
  height: clamp(52px, 7vmin, 82px);
  border-radius: 10px;
}

#status-panel.positioned-mode .param-info {
  width: 100%;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(118, 176, 255, 0.12);
}

#status-panel.positioned-mode .param-label {
  color: rgba(219, 233, 255, 0.82);
}

#status-panel.positioned-mode .param-value {
  margin-left: 0;
  min-width: 0;
  text-align: center;
  font-size: clamp(15px, 1.9vmin, 20px);
  line-height: 1;
}

#popup-content {
  top: 35%;
  width: min(68vh, 64vw, 660px);
  height: min(68vh, 64vw, 660px);
  max-width: none;
  max-height: none;
  padding: 12px;
  background: linear-gradient(180deg, rgba(7, 14, 26, 0.92) 0%, rgba(3, 9, 18, 0.98) 100%);
  border: 1px solid rgba(140, 194, 255, 0.24);
  border-radius: 24px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}

#popup-content img,
#popup-content video {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: contain;
  border-radius: 16px;
}

.story-menu-btn {
  width: min(860px, 88%);
  min-width: min(380px, 94%);
  min-height: clamp(92px, 12vmin, 116px);
  border-radius: 14px;
}

.story-menu-thumb {
  width: clamp(72px, 9vmin, 94px);
  height: clamp(72px, 9vmin, 94px);
  border-radius: 10px;
}

.story-menu-title {
  font-size: clamp(18px, 2.05vmin, 22px);
}

.story-menu-age,
.story-menu-profile {
  font-size: clamp(13px, 1.55vmin, 15px);
}

@media (max-width: 700px), (orientation: portrait) {
  #menu-bar {
    left: var(--ui-safe-left);
    right: var(--ui-safe-right);
    justify-content: space-between;
    gap: 6px;
  }

  .menu-btn {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    height: 52px;
    min-height: 52px;
    padding: 0;
    font-size: 11px;
  }

  #title-screen {
    padding: 18px 18px calc(28px + env(safe-area-inset-bottom));
    background-position: center top;
  }

  .title-btn {
    width: min(100%, 320px);
    min-width: 0;
    min-height: 58px;
  }

  #text-box {
    height: clamp(228px, 39%, 328px);
    padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
  }

  #speaker-name {
    font-size: clamp(18px, 4.8vw, 22px);
  }

  #text-content {
    font-size: clamp(17px, 4.5vw, 21px);
    line-height: 1.78;
  }

  #status-panel.positioned-mode .char-container {
    transform: none;
    padding: 6px;
    border-radius: 12px;
  }

  #status-panel.positioned-mode .char-icon {
    width: 48px;
    height: 48px;
  }

  #status-panel.positioned-mode .param-label {
    display: none;
  }

  #status-panel.positioned-mode .param-info {
    justify-content: center;
    min-width: 48px;
  }

  #popup-content {
    top: 31%;
    width: min(84vw, calc(100dvh - 340px), 420px);
    height: min(84vw, calc(100dvh - 340px), 420px);
    padding: 10px;
    border-radius: 20px;
  }

  .story-menu-btn {
    width: min(100%, 560px);
    min-width: 0;
    min-height: 96px;
    padding: 12px;
  }

  .story-menu-title {
    font-size: clamp(16px, 4.3vw, 19px);
  }

  .story-menu-age,
  .story-menu-profile {
    font-size: clamp(12px, 3.3vw, 14px);
  }
}

/* ===== TTCV2 VN Layout Override ===== */

#game-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: var(--scene-image);
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  filter: blur(24px) brightness(0.42) saturate(0.72);
  transform: scale(1.08);
  z-index: 0;
  pointer-events: none;
}

#bg-layer,
#bg-video-layer {
  object-fit: contain;
}

#title-screen.title-screen--has-art {
  background-size: contain !important;
}

/* タイトルのシャープな絵柄は #title-screen の background-image（contain）で前面に表示する。
   ::before にぼかし版（var(--title-image)）を重ねると、要素背景より前面(z-index:-1でも背景の上)に
   描画され、シャープな絵柄を覆ってしまう（全面ぼかし表示になる）バグがあったため撤去。
   余白のぼかしフィルは別レイヤー(<img>)を持つシーン背景側(--scene-image)でのみ使用する。 */

#text-box {
  align-items: center;
}

#speaker-name,
#text-content {
  width: min(100%, 1120px);
}

#speaker-name {
  font-size: clamp(20px, 2.35vmin, 28px);
}

#text-content {
  font-size: clamp(22px, 2.5vmin, 30px);
  line-height: 1.9;
}

#popup-content {
  top: auto;
  bottom: calc(clamp(188px, 34%, 290px) + 28px);
  width: min(78vh, 52vw, 800px);
  height: min(78vh, 52vw, 800px);
  transform: translateX(-50%);
}

#status-panel.positioned-mode .char-container {
  padding: 12px 12px 10px;
  gap: 8px;
}

#status-panel.positioned-mode .char-icon {
  width: clamp(84px, 9.5vmin, 118px);
  height: clamp(84px, 9.5vmin, 118px);
}

#status-panel.positioned-mode .param-info {
  padding: 6px 12px;
}

#status-panel.positioned-mode .param-label {
  font-size: clamp(13px, 1.5vmin, 16px);
}

#status-panel.positioned-mode .param-value {
  font-size: clamp(22px, 2.6vmin, 30px);
}

@media (max-width: 700px), (orientation: portrait) {
  #game-container::before {
    filter: blur(18px) brightness(0.45) saturate(0.82);
    transform: scale(1.04);
  }

  #bg-layer,
  #bg-video-layer {
    object-position: center 18%;
  }

  #title-screen.title-screen--has-art {
    background-size: contain !important;
    background-position: center 18%;
  }

  #title-screen {
    justify-content: flex-end;
  }

  #speaker-name,
  #text-content {
    width: 100%;
  }

  #speaker-name {
    font-size: clamp(20px, 5.5vw, 24px);
  }

  #text-content {
    font-size: clamp(19px, 5.2vw, 23px);
    line-height: 1.82;
  }

  #popup-content {
    bottom: calc(clamp(228px, 39%, 328px) + 18px);
    width: min(62vw, 320px);
    height: min(62vw, 320px);
    top: auto;
  }

  #status-panel.positioned-mode .char-container {
    padding: 8px 8px 6px;
  }

  #status-panel.positioned-mode .char-icon {
    width: 64px;
    height: 64px;
  }

  #status-panel.positioned-mode .param-value {
    font-size: 26px;
  }
}

/* ===== Final HUD Placement Override ===== */

#status-panel {
  top: auto !important;
  left: auto !important;
  right: var(--ui-safe-right) !important;
  bottom: calc(clamp(188px, 34%, 290px) + 22px) !important;
  width: auto !important;
  height: auto !important;
}

#status-panel.positioned-mode .char-container {
  position: static !important;
  left: auto !important;
  top: auto !important;
  width: 148px;
  transform: none !important;
  background: linear-gradient(180deg, rgba(3, 10, 18, 0.84) 0%, rgba(3, 8, 15, 0.94) 100%) !important;
  border-radius: 18px;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.34);
}

#status-panel.positioned-mode .char-icon {
  width: 96px !important;
  height: 96px !important;
}

#status-panel.positioned-mode .param-label {
  display: none !important;
}

#status-panel.positioned-mode .param-info {
  justify-content: center !important;
}

#status-panel.positioned-mode .param-value {
  font-size: 34px !important;
  font-weight: 800;
}

#status-panel.popup-active {
  bottom: 18px !important;
}

@media (max-width: 700px), (orientation: portrait) {
  #status-panel {
    right: 10px !important;
    bottom: calc(clamp(228px, 39%, 328px) + 12px) !important;
  }

  #status-panel.positioned-mode .char-container {
    width: 96px;
    padding: 8px 8px 6px;
    border-radius: 14px;
  }

  #status-panel.positioned-mode .char-icon {
    width: 64px !important;
    height: 64px !important;
  }

  #status-panel.positioned-mode .param-value {
    font-size: 26px !important;
  }
}

/* ===== Canonical ADV Stage ===== */

#game-container.layout-responsive {
  width: min(100vw, calc(100dvh * (16 / 9))) !important;
  height: auto !important;
  max-width: 100vw !important;
  max-height: 100dvh !important;
  aspect-ratio: var(--game-aspect, 16 / 9) !important;
}

@media (orientation: portrait) {
  #game-container.layout-responsive {
    width: min(100vw, calc(100dvh * (16 / 9))) !important;
    height: auto !important;
    max-width: 100vw !important;
    max-height: 100dvh !important;
    aspect-ratio: var(--game-aspect, 16 / 9) !important;
  }
}

#game-container::before {
  background-size: contain !important;
  filter: blur(28px) brightness(0.36) saturate(0.72) !important;
  transform: scale(1.12) !important;
}

#bg-layer,
#bg-video-layer {
  object-fit: contain !important;
  object-position: center center !important;
}

#title-screen.title-screen--has-art {
  background-size: contain !important;
  background-position: center center !important;
}

#title-screen.title-screen--has-art::before {
  background-size: cover, contain !important;
  background-position: center center, center center !important;
}

#text-box {
  align-items: center;
}

#speaker-name,
#text-content {
  width: min(100%, 1120px);
}

#speaker-name {
  font-size: clamp(20px, 2.2vmin, 28px);
}

#text-content {
  font-size: clamp(22px, 2.4vmin, 30px);
  line-height: 1.9;
}

#popup-content {
  left: 50% !important;
  right: auto !important;
  top: auto !important;
  bottom: calc(clamp(188px, 34%, 290px) + 28px) !important;
  transform: translateX(-50%) !important;
  width: min(74vh, 46vw, 760px) !important;
  height: min(74vh, 46vw, 760px) !important;
}

#status-panel,
#status-panel.popup-active {
  top: auto !important;
  left: auto !important;
  right: 18px !important;
  bottom: calc(clamp(188px, 34%, 290px) + 22px) !important;
  width: auto !important;
  height: auto !important;
}

#status-panel.positioned-mode .char-container {
  position: static !important;
  left: auto !important;
  top: auto !important;
  width: 148px !important;
  transform: none !important;
  background: linear-gradient(180deg, rgba(3, 10, 18, 0.84) 0%, rgba(3, 8, 15, 0.94) 100%) !important;
  border-radius: 18px !important;
  padding: 12px 12px 10px !important;
  gap: 8px !important;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.34) !important;
}

#status-panel.positioned-mode .char-icon {
  width: 96px !important;
  height: 96px !important;
}

#status-panel.positioned-mode .param-label {
  display: none !important;
}

#status-panel.positioned-mode .param-info {
  justify-content: center !important;
  min-width: 0 !important;
  padding: 7px 12px !important;
}

#status-panel.positioned-mode .param-value {
  font-size: 34px !important;
  font-weight: 800 !important;
}

@media (max-width: 700px), (orientation: portrait) {
  #game-container::before {
    filter: blur(22px) brightness(0.38) saturate(0.78) !important;
    transform: scale(1.08) !important;
  }

  #title-screen {
    justify-content: flex-end;
  }

  #speaker-name,
  #text-content {
    width: min(100%, 360px);
  }

  #speaker-name {
    font-size: clamp(19px, 4.8vw, 22px);
  }

  #text-content {
    font-size: clamp(18px, 4.9vw, 21px);
    line-height: 1.82;
  }

  #popup-content {
    bottom: calc(clamp(228px, 39%, 328px) + 18px) !important;
    width: min(52vw, 250px) !important;
    height: min(52vw, 250px) !important;
  }

  #status-panel,
  #status-panel.popup-active {
    right: 12px !important;
    bottom: calc(clamp(228px, 39%, 328px) + 14px) !important;
  }

  #status-panel.positioned-mode .char-container {
    width: 96px !important;
    padding: 8px 8px 6px !important;
    border-radius: 14px !important;
  }

  #status-panel.positioned-mode .char-icon {
    width: 64px !important;
    height: 64px !important;
  }

  #status-panel.positioned-mode .param-value {
    font-size: 26px !important;
  }
}

/* ===== TTCV2 Canonical 4:3 ADV Layout ===== */

:root {
  --ttcv2-stage-ratio: 3 / 4;
  --ttcv2-stage-padding: clamp(10px, 1.6vmin, 18px);
  --ttcv2-stage-radius: clamp(12px, 1.8vmin, 20px);
  --ttcv2-menu-gap: clamp(8px, 1vmin, 12px);
  --ttcv2-menu-size: clamp(44px, 5.8vmin, 58px);
  --ttcv2-textbox-bottom: clamp(14px, 1.8vmin, 24px);
  --ttcv2-textbox-side: clamp(14px, 1.8vmin, 24px);
  --ttcv2-textbox-height: clamp(168px, 31%, 232px);
  --ttcv2-popup-size: min(75vw, 52vh, 480px);
}

body {
  display: grid;
  place-items: center;
  padding: 0;
  background:
    radial-gradient(circle at top, rgba(20, 40, 76, 0.32), transparent 52%),
    linear-gradient(180deg, #05070d 0%, #02040a 100%);
}

#game-container {
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.55);
}

#game-container.layout-responsive {
  width: min(calc(100dvw - (var(--ttcv2-stage-padding) * 2)), calc((100dvh - (var(--ttcv2-stage-padding) * 2)) * (3 / 4))) !important;
  height: auto !important;
  max-width: calc(100dvw - (var(--ttcv2-stage-padding) * 2)) !important;
  max-height: calc(100dvh - (var(--ttcv2-stage-padding) * 2)) !important;
  aspect-ratio: var(--ttcv2-stage-ratio) !important;
  border-radius: var(--ttcv2-stage-radius);
}

#game-container::before {
  background-size: cover !important;
  filter: blur(26px) brightness(0.34) saturate(0.74) !important;
  transform: scale(1.08) !important;
}

#bg-layer,
#bg-video-layer {
  object-fit: cover !important;
  object-position: center center !important;
  background: #05070d;
}

#bg-layer[src=""] {
  display: none;
}

#title-screen {
  justify-content: flex-end !important;
  align-items: center !important;
  overflow: hidden !important;
  padding: clamp(18px, 3.2vmin, 32px) clamp(16px, 2.4vmin, 28px) clamp(26px, 6vmin, 56px) !important;
  gap: clamp(10px, 1.8vmin, 18px) !important;
}

#title-screen.title-screen--has-art {
  background-size: cover !important;
  background-position: center center !important;
}

#title-screen.title-screen--has-art::before {
  content: '' !important;
  position: absolute !important;
  inset: 0 !important;
  background-size: cover, cover !important;
  background-position: center center, center center !important;
  z-index: 0 !important;
}

#title-screen > * {
  position: relative;
  z-index: 1;
}

.title-btn {
  width: min(46%, 360px) !important;
  min-width: 220px !important;
  min-height: 62px !important;
}

#menu-bar {
  top: clamp(14px, 1.9vmin, 22px) !important;
  right: clamp(14px, 1.9vmin, 22px) !important;
  left: auto !important;
  gap: var(--ttcv2-menu-gap) !important;
}

.menu-btn {
  width: var(--ttcv2-menu-size) !important;
  min-width: var(--ttcv2-menu-size) !important;
  height: var(--ttcv2-menu-size) !important;
  padding: 0 !important;
  border-radius: 14px !important;
}

#text-box {
  left: var(--ttcv2-textbox-side) !important;
  right: var(--ttcv2-textbox-side) !important;
  bottom: var(--ttcv2-textbox-bottom) !important;
  height: var(--ttcv2-textbox-height) !important;
  border: 1px solid rgba(154, 202, 255, 0.22) !important;
  border-top: 1px solid rgba(154, 202, 255, 0.26) !important;
  border-radius: 24px 24px 18px 18px !important;
  background: linear-gradient(180deg, rgba(6, 10, 18, 0.36) 0%, rgba(4, 8, 16, 0.92) 14%, rgba(3, 7, 14, 0.97) 100%) !important;
  padding: clamp(16px, 2.2vmin, 24px) clamp(18px, 2.6vmin, 28px) clamp(18px, 2.4vmin, 24px) !important;
  backdrop-filter: blur(12px) !important;
  align-items: stretch !important;
}

#speaker-name,
#text-content {
  width: 100% !important;
  max-width: none !important;
}

#speaker-name {
  font-size: clamp(18px, 2.3vmin, 26px) !important;
  margin-bottom: clamp(8px, 1.1vmin, 12px) !important;
}

#text-content {
  font-size: clamp(18px, 2.35vmin, 28px) !important;
  line-height: 1.8 !important;
}

#status-panel,
#status-panel.popup-active {
  top: auto !important;
  left: var(--ttcv2-textbox-side) !important;
  right: auto !important;
  bottom: calc(var(--ttcv2-textbox-bottom) + var(--ttcv2-textbox-height) + clamp(10px, 1.4vmin, 16px)) !important;
  width: auto !important;
  height: auto !important;
  min-width: 0 !important;
  padding: 0 !important;
  background: none !important;
  border: none !important;
}

#status-panel.positioned-mode {
  width: auto !important;
  height: auto !important;
}

#status-panel.positioned-mode .char-container {
  position: static !important;
  left: auto !important;
  top: auto !important;
  transform: none !important;
  width: clamp(92px, 11vmin, 132px) !important;
  padding: clamp(8px, 1.1vmin, 12px) !important;
  gap: clamp(5px, 0.8vmin, 8px) !important;
  border-radius: 16px !important;
  background: linear-gradient(180deg, rgba(6, 12, 20, 0.88) 0%, rgba(3, 7, 14, 0.96) 100%) !important;
  border: 1px solid rgba(150, 200, 255, 0.26) !important;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.36) !important;
}

#status-panel.positioned-mode .char-icon {
  width: clamp(58px, 7.2vmin, 88px) !important;
  height: clamp(58px, 7.2vmin, 88px) !important;
  border-radius: 12px !important;
}

#status-panel.positioned-mode .param-label {
  display: none !important;
}

#status-panel.positioned-mode .param-info {
  justify-content: center !important;
  min-width: 0 !important;
  padding: 6px 10px !important;
  border-radius: 999px !important;
  background: rgba(117, 176, 255, 0.12) !important;
}

#status-panel.positioned-mode .param-value {
  font-size: clamp(22px, 2.6vmin, 30px) !important;
  font-weight: 800 !important;
}

#popup-content {
  left: 50% !important;
  right: auto !important;
  top: auto !important;
  bottom: calc(var(--ttcv2-textbox-bottom) + var(--ttcv2-textbox-height) + clamp(10px, 1.6vmin, 18px)) !important;
  transform: translateX(-50%) !important;
  width: var(--ttcv2-popup-size) !important;
  height: var(--ttcv2-popup-size) !important;
  max-width: none !important;
  max-height: none !important;
  padding: clamp(8px, 1.1vmin, 12px) !important;
  border-radius: 24px !important;
  background: linear-gradient(180deg, rgba(7, 14, 26, 0.92) 0%, rgba(3, 9, 18, 0.98) 100%) !important;
  border: 1px solid rgba(140, 194, 255, 0.24) !important;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45) !important;
}

#popup-content img,
#popup-content video {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: contain !important;
  border-radius: 16px !important;
}

@media (orientation: portrait) {
  :root {
    --ttcv2-stage-padding: 8px;
    --ttcv2-textbox-side: 10px;
    --ttcv2-textbox-bottom: 10px;
    --ttcv2-textbox-height: clamp(148px, 36%, 190px);
    --ttcv2-popup-size: min(82vw, 48vh, 380px);
  }

  #game-container.layout-responsive {
    width: min(calc(100dvw - 16px), calc((100dvh - 16px) * (3 / 4))) !important;
    max-width: calc(100dvw - 16px) !important;
    max-height: calc(100dvh - 16px) !important;
  }

  .title-btn {
    width: min(72%, 280px) !important;
    min-width: 0 !important;
    min-height: 56px !important;
  }

  #menu-bar {
    top: 10px !important;
    right: 10px !important;
  }

  .menu-btn {
    border-radius: 12px !important;
  }

  #speaker-name {
    font-size: clamp(17px, 3.8vw, 21px) !important;
  }

  #text-content {
    font-size: clamp(16px, 4.05vw, 20px) !important;
    line-height: 1.72 !important;
  }

  #status-panel.positioned-mode .char-container {
    width: 88px !important;
    padding: 7px !important;
    border-radius: 14px !important;
  }

  #status-panel.positioned-mode .char-icon {
    width: 52px !important;
    height: 52px !important;
  }

  #status-panel.positioned-mode .param-info {
    padding: 5px 8px !important;
  }

  #status-panel.positioned-mode .param-value {
    font-size: 22px !important;
  }
}

/* ===== TTCV2 Final Layout Reset ===== */

:root {
  --ttcv2-shell-pad: clamp(10px, 1.6vmin, 18px);
  --ttcv2-gap: clamp(10px, 1.4vmin, 16px);
  --ttcv2-text-height: clamp(170px, 23dvh, 230px);
  --ttcv2-scene-width: min(
    calc(100vw - (var(--ttcv2-shell-pad) * 2)),
    calc((100dvh - (var(--ttcv2-shell-pad) * 2) - var(--ttcv2-text-height) - var(--ttcv2-gap)) * (4 / 3)),
    1180px
  );
  --ttcv2-scene-height: calc(var(--ttcv2-scene-width) * 3 / 4);
  --ttcv2-popup-size-final: min(calc(var(--ttcv2-scene-width) * 0.62), calc(var(--ttcv2-scene-height) * 0.95), 560px);
}

body {
  display: block !important;
  background:
    radial-gradient(circle at top, rgba(20, 40, 76, 0.28), transparent 48%),
    linear-gradient(180deg, #05070d 0%, #02040a 100%) !important;
}

#game-container,
#game-container.layout-responsive {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: none !important;
  aspect-ratio: auto !important;
  transform: none !important;
  left: 0 !important;
  top: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

#game-container::before {
  inset: 0 !important;
  background-size: cover !important;
  filter: blur(30px) brightness(0.3) saturate(0.7) !important;
  transform: scale(1.08) !important;
}

#bg-layer,
#bg-video-layer,
#sprite-stage {
  position: absolute !important;
  left: 50% !important;
  top: var(--ttcv2-shell-pad) !important;
  width: var(--ttcv2-scene-width) !important;
  height: var(--ttcv2-scene-height) !important;
  transform: translateX(-50%) !important;
}

#bg-layer,
#bg-video-layer {
  object-fit: cover !important;
  object-position: center center !important;
  border-radius: 28px !important;
  background: #05070d !important;
  box-shadow: 0 20px 54px rgba(0, 0, 0, 0.42) !important;
}

#title-screen {
  position: absolute !important;
  left: 50% !important;
  top: var(--ttcv2-shell-pad) !important;
  width: var(--ttcv2-scene-width) !important;
  height: calc(var(--ttcv2-scene-height) + var(--ttcv2-text-height) + var(--ttcv2-gap)) !important;
  transform: translateX(-50%) !important;
  justify-content: flex-end !important;
  align-items: center !important;
  padding: clamp(16px, 2.2vmin, 26px) !important;
  padding-bottom: clamp(18px, 2.6vmin, 30px) !important;
  gap: clamp(10px, 1.5vmin, 16px) !important;
  background-position: center top !important;
  border-radius: 28px !important;
  overflow: hidden !important;
}

#title-screen.title-screen--has-art {
  background-size: cover !important;
}

#title-screen.title-screen--has-art::before {
  content: '' !important;
  position: absolute !important;
  inset: 0 !important;
  background-size: cover, cover !important;
  background-position: center center, center center !important;
  z-index: 0 !important;
}

#title-screen > * {
  position: relative !important;
  z-index: 1 !important;
}

.title-btn {
  width: min(58%, 420px) !important;
  min-width: 240px !important;
  min-height: 64px !important;
}

#menu-bar {
  position: absolute !important;
  left: 50% !important;
  top: calc(var(--ttcv2-shell-pad) + clamp(12px, 1.8vmin, 18px)) !important;
  width: var(--ttcv2-scene-width) !important;
  transform: translateX(-50%) !important;
  display: flex !important;
  justify-content: flex-end !important;
  gap: clamp(8px, 1vmin, 12px) !important;
  padding-right: clamp(12px, 1.8vmin, 18px) !important;
}

.menu-btn {
  width: clamp(48px, 5.2vmin, 58px) !important;
  min-width: clamp(48px, 5.2vmin, 58px) !important;
  height: clamp(48px, 5.2vmin, 58px) !important;
  min-height: clamp(48px, 5.2vmin, 58px) !important;
  padding: 0 !important;
  border-radius: 14px !important;
}

#text-box {
  position: absolute !important;
  left: 50% !important;
  top: calc(var(--ttcv2-shell-pad) + var(--ttcv2-scene-height) + var(--ttcv2-gap)) !important;
  width: var(--ttcv2-scene-width) !important;
  height: var(--ttcv2-text-height) !important;
  transform: translateX(-50%) !important;
  border-radius: 24px !important;
  border: 1px solid rgba(154, 202, 255, 0.22) !important;
  background: linear-gradient(180deg, rgba(6, 10, 18, 0.42) 0%, rgba(4, 8, 16, 0.93) 14%, rgba(3, 7, 14, 0.98) 100%) !important;
  padding: clamp(16px, 2.2vmin, 24px) clamp(18px, 2.6vmin, 28px) !important;
  align-items: stretch !important;
}

#speaker-name,
#text-content {
  width: 100% !important;
  max-width: none !important;
}

#speaker-name {
  font-size: clamp(18px, 2vmin, 24px) !important;
}

#text-content {
  font-size: clamp(19px, 2.15vmin, 26px) !important;
  line-height: 1.76 !important;
}

#status-panel,
#status-panel.popup-active {
  position: absolute !important;
  left: 50% !important;
  top: calc(var(--ttcv2-shell-pad) + var(--ttcv2-scene-height) - 132px) !important;
  width: var(--ttcv2-scene-width) !important;
  height: 0 !important;
  transform: translateX(-50%) !important;
  padding: 0 !important;
  background: none !important;
  border: none !important;
}

#status-panel.positioned-mode {
  width: var(--ttcv2-scene-width) !important;
  height: 0 !important;
}

#status-panel.positioned-mode .char-container {
  position: absolute !important;
  left: clamp(10px, 1.6vmin, 18px) !important;
  top: 0 !important;
  transform: none !important;
  width: clamp(90px, 10vmin, 122px) !important;
  padding: 8px 8px 6px !important;
  gap: 6px !important;
  border-radius: 16px !important;
  background: linear-gradient(180deg, rgba(6, 12, 20, 0.9) 0%, rgba(3, 7, 14, 0.96) 100%) !important;
  border: 1px solid rgba(150, 200, 255, 0.26) !important;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.36) !important;
}

#status-panel.positioned-mode .char-icon {
  width: clamp(54px, 6.8vmin, 78px) !important;
  height: clamp(54px, 6.8vmin, 78px) !important;
}

#status-panel.positioned-mode .param-label {
  display: none !important;
}

#status-panel.positioned-mode .param-info {
  justify-content: center !important;
  min-width: 0 !important;
  padding: 5px 8px !important;
  border-radius: 999px !important;
}

#status-panel.positioned-mode .param-value {
  font-size: clamp(20px, 2.4vmin, 28px) !important;
  font-weight: 800 !important;
}

#popup-content {
  left: 50% !important;
  top: calc(var(--ttcv2-shell-pad) + (var(--ttcv2-scene-height) / 2)) !important;
  bottom: auto !important;
  width: var(--ttcv2-popup-size-final) !important;
  height: var(--ttcv2-popup-size-final) !important;
  transform: translate(-50%, -50%) !important;
  padding: 10px !important;
  border-radius: 24px !important;
}

#popup-content img,
#popup-content video {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
}

@media (orientation: portrait) {
  :root {
    --ttcv2-shell-pad: 8px;
    --ttcv2-gap: 10px;
    --ttcv2-text-height: clamp(180px, 26dvh, 240px);
    --ttcv2-scene-width: calc(100vw - 16px);
    --ttcv2-scene-height: calc(var(--ttcv2-scene-width) * 3 / 4);
    --ttcv2-popup-size-final: min(calc(var(--ttcv2-scene-width) * 0.78), calc(var(--ttcv2-scene-height) * 0.96), 400px);
  }

  .title-btn {
    width: min(76%, 320px) !important;
    min-width: 0 !important;
    min-height: 56px !important;
  }

  #menu-bar {
    padding-right: 10px !important;
    gap: 6px !important;
  }

  .menu-btn {
    width: 46px !important;
    min-width: 46px !important;
    height: 46px !important;
    min-height: 46px !important;
    border-radius: 12px !important;
  }

  #speaker-name {
    font-size: clamp(17px, 4vw, 21px) !important;
  }

  #text-content {
    font-size: clamp(18px, 4.3vw, 21px) !important;
    line-height: 1.72 !important;
  }

  #status-panel,
  #status-panel.popup-active {
    top: calc(var(--ttcv2-shell-pad) + var(--ttcv2-scene-height) - 118px) !important;
  }

  #status-panel.positioned-mode .char-container {
    width: 88px !important;
  }

  #status-panel.positioned-mode .char-icon {
    width: 50px !important;
    height: 50px !important;
  }

  #status-panel.positioned-mode .param-value {
    font-size: 20px !important;
  }
}

/* ============================================================ */
/* Title Screen Customization (re-applied after restore)        */
/* ============================================================ */

/* タイトルボタン：プライマリ「はじめから」、セカンダリ「つづきから」 */
#btn-start.title-btn {
  background: linear-gradient(180deg, rgba(120, 165, 255, 0.32) 0%, rgba(68, 110, 200, 0.55) 100%);
  border-color: rgba(180, 210, 255, 0.55);
  color: #ffffff;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  box-shadow: 0 8px 22px rgba(60, 110, 200, 0.32), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
}

#btn-start.title-btn:hover {
  background: linear-gradient(180deg, rgba(150, 195, 255, 0.5) 0%, rgba(82, 130, 220, 0.78) 100%);
  border-color: rgba(220, 235, 255, 0.78);
  box-shadow: 0 12px 28px rgba(80, 140, 230, 0.46), 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

#btn-title-load.title-btn {
  font-weight: 400;
  color: rgba(225, 232, 245, 0.88);
}

/* セーブデータがあるときは「つづきから」も「はじめから」と同じく点灯表示にする */
#btn-title-load.title-btn.has-save {
  background: linear-gradient(180deg, rgba(120, 165, 255, 0.32) 0%, rgba(68, 110, 200, 0.55) 100%);
  border-color: rgba(180, 210, 255, 0.55);
  color: #ffffff;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  box-shadow: 0 8px 22px rgba(60, 110, 200, 0.32), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
}

#btn-title-load.title-btn.has-save:hover {
  background: linear-gradient(180deg, rgba(150, 195, 255, 0.5) 0%, rgba(82, 130, 220, 0.78) 100%);
  border-color: rgba(220, 235, 255, 0.78);
  box-shadow: 0 12px 28px rgba(80, 140, 230, 0.46), 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

/* バナー：絶対配置→フレックス配下のレイアウト要素に変換 */
.title-banner {
  position: relative !important;
  left: auto !important;
  top: auto !important;
  display: block;
  width: min(58%, 304px) !important;
  margin: 4px 0 0;
  border-radius: 10px;
  overflow: hidden;
  z-index: 52 !important;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.title-banner:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
}

.title-banner img {
  display: block;
  width: 100%;
  height: auto;
}

/* スマホ portrait：画像直下にボタン・バナーを縦配置 */
@media (orientation: portrait), (max-width: 700px) {
  /* TTCV2 Final Layout Reset の cover を contain に上書き（画像見切れ防止） */
  #title-screen.title-screen--has-art {
    background-size: 85% auto !important;
    background-position: center top !important;
    background-repeat: no-repeat !important;
  }

  /* ぼかしバックドロップの拡大を抑える */
  #title-screen.title-screen--has-art::before {
    transform: scale(1.02) !important;
  }

  /* title-screen：高さ自動。padding-top で画像ぶんを予約 → 直下に content 並べる */
  #title-screen {
    height: auto !important;
    min-height: 0 !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: center !important;
    padding: calc(var(--ttcv2-scene-width) * 0.6375 + 24px) 16px calc(20px + env(safe-area-inset-bottom)) !important;
    gap: 12px !important;
  }

  /* スマホ用バナー：横幅大きめでタップしやすく */
  .title-banner {
    width: min(78%, 300px) !important;
    margin: 4px 0 0 !important;
    border-radius: 8px !important;
  }
}

/* ============================================================ */
/* Mobile portrait: menu-bar を背景画像の上（viewport 最上部）に分離配置 */
/* ============================================================ */
@media (orientation: portrait), (max-width: 700px) {
  /* shell-pad を増やして scene 全体を下げる
     これで scene-bg・title・status-panel・text-box すべてが menu-bar 分下に動く */
  :root {
    --ttcv2-shell-pad: 60px;
  }

  /* menu-bar 自身は viewport 最上部に固定（safe-area inset 対応） */
  #menu-bar {
    top: max(8px, env(safe-area-inset-top, 0px)) !important;
  }
}

/* ============================================================ */
/* Mobile tap highlight suppression（テキスト送り時のフラッシュ抑制） */
/* ============================================================ */

/* iOS/Android のタップ時の半透明オーバーレイを完全無効化 */
* {
  -webkit-tap-highlight-color: transparent !important;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0) !important;
}

/* テキストボックスとメニューバー領域は focus 時にも outline を出さない */
#text-box,
#text-box:focus,
#text-box:focus-visible,
#text-box:active,
.menu-btn:focus,
.menu-btn:focus-visible,
.choice-btn:focus,
.choice-btn:focus-visible {
  outline: none !important;
}

/* iOS Safari の :active スタイルが暗くなる挙動を抑える（textbox のみ） */
#text-box:active {
  background-color: transparent;
}

/* ============================================================ */
/* Mobile portrait: メッセージ枠を少し広げ＋フォント微調整         */
/* （1メッセージ 40字目安、最大 50字でも見切れない設計）            */
/* ============================================================ */
@media (orientation: portrait), (max-width: 700px) {
  :root {
    --ttcv2-text-height: clamp(200px, 30dvh, 270px);
  }

  /* テキスト本文：少し小さめにして1行あたりの収納を増やす */
  #text-content {
    font-size: clamp(16px, 4.1vw, 19px) !important;
    line-height: 1.78 !important;
  }
}

/* ============================================================ */
/* Video layer：BG と同じシーン枠サイズで表示、最前面（popup/icon より上）*/
/* ============================================================ */
#video-layer {
  position: absolute !important;
  left: 50% !important;
  top: var(--ttcv2-shell-pad) !important;
  width: var(--ttcv2-scene-width) !important;
  height: var(--ttcv2-scene-height) !important;
  transform: translateX(-50%) !important;
  object-fit: cover !important;
  border-radius: 28px !important;
  background: #05070d !important;
  z-index: 200 !important;     /* popup-overlay(80) / status-panel(18) より上 */
  cursor: pointer;
}

/* スマホ portrait はシーン枠の角丸を控えめ */
@media (orientation: portrait), (max-width: 700px) {
  #video-layer {
    border-radius: 16px !important;
  }
}

/* ============================================================ */
/* Story menu: ストーリー選択中は status-panel を非表示（全画面共通） */
/* ============================================================ */
#status-panel.story-menu-active,
#status-panel.positioned-mode.story-menu-active {
  display: none !important;
}

/* ソートトグル UI */
.story-menu-sort {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  width: min(100%, 680px);
  margin: 0 0 4px;
}

.story-menu-sort-btn {
  background: rgba(8, 14, 28, 0.55);
  border: 1px solid rgba(180, 210, 255, 0.32);
  color: rgba(220, 232, 245, 0.85);
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.story-menu-sort-btn:hover {
  background: rgba(20, 35, 60, 0.85);
  border-color: rgba(220, 235, 255, 0.55);
}

.story-menu-sort-btn.active {
  background: linear-gradient(180deg, rgba(120, 165, 255, 0.32), rgba(68, 110, 200, 0.55));
  border-color: rgba(180, 210, 255, 0.65);
  color: #fff;
  font-weight: 500;
}

/* ============================================================ */
/* Story menu: status-panel を強制非表示＋カード幅を中央寄せ          */
/* ============================================================ */

/* 強制非表示：visibility と pointer-events も併用してCSS優先度を確実化 */
#status-panel.story-menu-active,
#status-panel.story-menu-active.positioned-mode,
body #status-panel.story-menu-active {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  opacity: 0 !important;
}

/* :has() ベースのフォールバック — クラス付与のタイミング問題に依存せず、
   choice-container が story-menu モードのとき必ず status-panel を隠す。
   親（game-container / body）から選択肢コンテナを見て、
   兄弟の status-panel を強制非表示。 */
#game-container:has(#choice-container.story-menu-container) #status-panel,
body:has(#choice-container.story-menu-container) #status-panel,
#game-container:has(#choice-container.choice-card-mode) #status-panel,
body:has(#choice-container.choice-card-mode) #status-panel {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  opacity: 0 !important;
}

/* ストーリーメニューのカードリストを中央寄せ＋最大幅制限
   左右にアイコン用のスペースが空くようにする */
#choice-container.story-menu-container {
  align-items: center !important;
  justify-content: center !important;
}

#choice-container.story-menu-container .choice-card-list {
  width: min(720px, 90%) !important;
  max-width: 720px !important;
  margin: 0 auto !important;
}

#choice-container.story-menu-container .story-menu-sort {
  width: min(720px, 90%) !important;
  max-width: 720px !important;
  margin: 0 auto 8px !important;
}

#choice-container.story-menu-container .story-menu-pagination {
  width: min(720px, 90%) !important;
  max-width: 720px !important;
  margin: 8px auto 0 !important;
}

/* ============================================================ */
/* トロープ獲得時の黄色通知を大きく表示                              */
/* ============================================================ */
.trope-notification {
  font-size: clamp(28px, 5vmin, 44px) !important;
  font-weight: 800 !important;
  text-shadow:
    0 0 20px rgba(255, 215, 0, 0.85),
    0 0 40px rgba(255, 215, 0, 0.5),
    0 3px 8px rgba(0, 0, 0, 0.9) !important;
  letter-spacing: 0.06em !important;
  z-index: 95 !important;
}

/* スマホ portrait はやや控えめ（長いトロープ名でも2行で収まるよう少し小さめ） */
@media (orientation: portrait), (max-width: 700px) {
  .trope-notification {
    font-size: clamp(20px, 5.4vw, 30px) !important;
  }
}
