
    /* chat.css — チャットページ固有スタイル（共通スタイルはcommon.cssを参照） */

    html, body {
      height: 100%;
    }

    body {
      height: 100%;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

    /* chat.cssのnav-linkはborderあり・inline-flex・gap付き（共通と差異あり） */
    .nav-link {
      background: var(--card2);
      border: 1px solid var(--border);
      padding: 6px 14px;
      font-size: 12px;
      display: inline-flex;
      align-items: center;
      gap: 5px;
    }

    .nav-link:hover {
      border-color: var(--accent);
    }

    .nav-link.active {
      border-color: var(--accent);
      background: var(--accent-glow);
    }

    /* メインレイアウト */
    .chat-layout {
      display: flex;
      flex: 1;
      gap: 0;
      min-height: 0;
      overflow: hidden;
    }

    /* 左: キャラクターエリア */
    .character-panel {
      width: 340px;
      flex-shrink: 0;
      background: linear-gradient(180deg, #13101e 0%, #0f1117 100%);
      border-right: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 32px 24px;
      position: relative;
      overflow: hidden;
    }

    /* 背景グロー */
    .character-panel::before {
      content: '';
      position: absolute;
      bottom: -60px;
      left: 50%;
      transform: translateX(-50%);
      width: 300px;
      height: 300px;
      background: radial-gradient(circle, rgba(124, 58, 237, 0.15) 0%, transparent 70%);
      pointer-events: none;
    }

    .character-stage {
      position: relative;
      width: 220px;
      height: 220px;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    /* キャラクター画像またはプレースホルダー */
    .character-img {
      width: 200px;
      height: 200px;
      object-fit: contain;
      image-rendering: pixelated;
      filter: drop-shadow(0 0 24px rgba(124, 58, 237, 0.4));
      /* ボビングアニメーション */
      animation: bobbing 3s ease-in-out infinite;
    }

    /* 画像が存在しない場合のプレースホルダー */
    .character-placeholder {
      width: 200px;
      height: 200px;
      background: linear-gradient(135deg, var(--card2), #2a1f4a);
      border: 2px solid var(--border);
      border-radius: 50%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 12px;
      animation: bobbing 3s ease-in-out infinite;
      position: relative;
      overflow: hidden;
      box-shadow: 0 0 40px rgba(124, 58, 237, 0.2);
    }

    .character-placeholder::after {
      content: '';
      position: absolute;
      inset: 0;
      border-radius: 50%;
      border: 2px solid transparent;
      background: linear-gradient(135deg, rgba(124,58,237,0.4), transparent) border-box;
      -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
      -webkit-mask-composite: destination-out;
      mask-composite: exclude;
    }

    .char-face {
      font-size: 72px;
      line-height: 1;
      /* まばたきアニメーション */
      animation: blink 4s ease-in-out infinite;
    }

    .char-name-badge {
      font-size: 13px;
      font-weight: 700;
      color: var(--accent-light);
      letter-spacing: 0.5px;
    }

    @keyframes bobbing {
      0%, 100% { transform: translateY(0px); }
      50% { transform: translateY(-10px); }
    }

    @keyframes blink {
      0%, 90%, 100% { transform: scaleY(1); }
      95% { transform: scaleY(0.1); }
    }

    /* 感情表示バッジ */
    .emotion-badge {
      margin-top: 20px;
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 5px 14px;
      background: var(--accent-glow);
      border: 1px solid rgba(124, 58, 237, 0.3);
      border-radius: 20px;
      font-size: 12px;
      color: var(--accent-light);
      transition: all 0.4s ease;
    }

    .emotion-dot {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: var(--accent-light);
    }

    /* キャラ名 */
    .character-name {
      margin-top: 16px;
      font-size: 20px;
      font-weight: 700;
      color: var(--text);
      letter-spacing: 0.5px;
    }

    .character-tagline {
      font-size: 12px;
      color: var(--text-muted);
      margin-top: 4px;
      text-align: center;
    }

    /* 右: チャットエリア */
    .chat-panel {
      flex: 1;
      display: flex;
      flex-direction: column;
      min-width: 0;
    }

    /* チャットヘッダー */
    .chat-header {
      padding: 16px 24px;
      border-bottom: 1px solid var(--border);
      background: var(--card);
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-shrink: 0;
    }

    .chat-header-title {
      font-size: 14px;
      font-weight: 600;
      color: var(--text);
    }

    .chat-header-sub {
      font-size: 12px;
      color: var(--text-muted);
      margin-top: 1px;
    }

    .clear-btn {
      background: transparent;
      border: 1px solid var(--border);
      color: var(--text-muted);
      padding: 5px 12px;
      border-radius: var(--radius-sm);
      cursor: pointer;
      font-size: 12px;
      transition: all 0.2s;
    }

    .clear-btn:hover {
      border-color: var(--red);
      color: var(--red);
    }

    /* メッセージエリア */
    .messages-area {
      flex: 1;
      overflow-y: auto;
      padding: 24px;
      display: flex;
      flex-direction: column;
      gap: 16px;
      scroll-behavior: smooth;
    }

    .messages-area::-webkit-scrollbar {
      width: 6px;
    }

    .messages-area::-webkit-scrollbar-track {
      background: transparent;
    }

    .messages-area::-webkit-scrollbar-thumb {
      background: var(--border);
      border-radius: 3px;
    }

    /* システムメッセージ */
    .system-msg {
      text-align: center;
      font-size: 12px;
      color: var(--text-dim);
      padding: 8px 16px;
      background: var(--card2);
      border-radius: 20px;
      align-self: center;
      max-width: 80%;
    }

    /* メッセージバブル */
    .message-row {
      display: flex;
      gap: 10px;
      align-items: flex-end;
      max-width: 75%;
    }

    .message-row.user {
      align-self: flex-end;
      flex-direction: row-reverse;
    }

    .message-row.character {
      align-self: flex-start;
    }

    .msg-avatar {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      flex-shrink: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 16px;
    }

    .msg-avatar.char-avatar {
      background: linear-gradient(135deg, var(--accent), #a855f7);
      box-shadow: 0 0 10px var(--accent-glow);
    }

    .msg-avatar.user-avatar {
      background: var(--card2);
      border: 1px solid var(--border);
    }

    .msg-bubble {
      padding: 10px 14px;
      border-radius: 16px;
      font-size: 14px;
      line-height: 1.6;
      word-break: break-word;
      max-width: 100%;
    }

    .message-row.character .msg-bubble {
      background: var(--card);
      border: 1px solid var(--border);
      border-bottom-left-radius: 4px;
      color: var(--text);
    }

    .message-row.user .msg-bubble {
      background: linear-gradient(135deg, var(--accent), #6d28d9);
      border-bottom-right-radius: 4px;
      color: #fff;
    }

    .msg-meta {
      font-size: 10px;
      color: var(--text-dim);
      margin-top: 4px;
    }

    .message-row.user .msg-meta {
      text-align: right;
    }

    .msg-wrapper {
      display: flex;
      flex-direction: column;
    }

    /* ローディングインジケーター */
    .typing-indicator {
      display: flex;
      align-items: center;
      gap: 5px;
      padding: 12px 16px;
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 16px;
      border-bottom-left-radius: 4px;
    }

    .typing-dot {
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: var(--accent-light);
      animation: typing-bounce 1.2s ease-in-out infinite;
    }

    .typing-dot:nth-child(2) { animation-delay: 0.2s; }
    .typing-dot:nth-child(3) { animation-delay: 0.4s; }

    @keyframes typing-bounce {
      0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
      30% { transform: translateY(-6px); opacity: 1; }
    }

    /* エラーメッセージ */
    .error-bubble {
      padding: 10px 16px;
      background: rgba(239, 68, 68, 0.1);
      border: 1px solid rgba(239, 68, 68, 0.25);
      border-radius: var(--radius-sm);
      color: var(--red);
      font-size: 13px;
      align-self: center;
      max-width: 80%;
      text-align: center;
    }

    /* API状態バナー */
    .api-banner {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 8px 16px;
      background: rgba(234, 179, 8, 0.08);
      border-bottom: 1px solid rgba(234, 179, 8, 0.2);
      font-size: 12px;
      color: var(--yellow);
      flex-shrink: 0;
    }

    .api-banner.hidden { display: none; }

    /* 入力エリア */
    .input-area {
      padding: 16px 24px;
      padding-bottom: max(16px, env(safe-area-inset-bottom));
      border-top: 1px solid var(--border);
      background: var(--card);
      display: flex;
      gap: 10px;
      align-items: flex-end;
      flex-shrink: 0;
    }

    .input-wrapper {
      flex: 1;
      position: relative;
    }

    .chat-input {
      width: 100%;
      background: var(--card2);
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      padding: 10px 14px;
      color: var(--text);
      font-size: 14px;
      font-family: inherit;
      resize: none;
      outline: none;
      transition: border-color 0.2s;
      max-height: 120px;
      min-height: 44px;
      line-height: 1.5;
    }

    .chat-input:focus {
      border-color: var(--accent);
    }

    .chat-input::placeholder {
      color: var(--text-dim);
    }

    .char-counter {
      position: absolute;
      right: 10px;
      bottom: 8px;
      font-size: 10px;
      color: var(--text-dim);
    }

    .char-counter.warn { color: var(--yellow); }
    .char-counter.limit { color: var(--red); }

    .send-btn {
      width: 44px;
      height: 44px;
      background: linear-gradient(135deg, var(--accent), #6d28d9);
      border: none;
      border-radius: var(--radius-sm);
      color: #fff;
      cursor: pointer;
      font-size: 20px;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.2s;
      flex-shrink: 0;
      box-shadow: 0 2px 8px rgba(124, 58, 237, 0.4);
    }

    .send-btn:hover:not(:disabled) {
      transform: translateY(-1px);
      box-shadow: 0 4px 12px rgba(124, 58, 237, 0.5);
    }

    .send-btn:disabled {
      opacity: 0.5;
      cursor: not-allowed;
      transform: none;
    }

    .send-btn svg {
      width: 20px;
      height: 20px;
      fill: #fff;
    }

    /* スピナー */
    .spinner {
      width: 18px;
      height: 18px;
      border: 2px solid rgba(255,255,255,0.3);
      border-top-color: #fff;
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
    }

    /* レスポンシブ: スマホ縦並び */
    @media (max-width: 768px) {
      /* ヘッダー: 高さを抑え、ナビをコンパクトに */
      .header {
        height: auto;
        min-height: 52px;
        padding: 6px 12px;
        flex-wrap: wrap;
        gap: 6px;
      }

      .header-left {
        gap: 8px;
      }

      .header-icon {
        width: 28px;
        height: 28px;
        font-size: 14px;
      }

      .header-title {
        font-size: 14px;
      }

      .header-subtitle {
        font-size: 10px;
      }

      .header-right {
        gap: 4px;
        flex-wrap: wrap;
        justify-content: flex-end;
      }

      .status-badge {
        font-size: 10px;
      }

      .nav-link {
        padding: 4px 8px;
        font-size: 11px;
      }

      /* チャットレイアウト */
      .chat-layout {
        flex-direction: column;
        overflow: hidden;
      }

      /* キャラクターパネル: 横並びコンパクト表示 */
      .character-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 8px 12px;
        flex-direction: row;
        gap: 12px;
        justify-content: flex-start;
        min-height: auto;
        flex-shrink: 0;
        /* アニメーションはスマホでは不要なので軽量化 */
        overflow: visible;
      }

      .character-panel::before { display: none; }

      .character-stage {
        width: 56px;
        height: 56px;
        flex-shrink: 0;
      }

      .character-placeholder,
      .character-img {
        width: 52px;
        height: 52px;
      }

      /* ボビングアニメーションを控えめに */
      .character-placeholder,
      .character-img {
        animation: bobbing 4s ease-in-out infinite;
      }

      .char-face { font-size: 28px; }

      .char-name-badge { font-size: 10px; }

      .character-info-col {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        gap: 2px;
      }

      .character-name { margin-top: 0; font-size: 14px; }
      .character-tagline { font-size: 11px; text-align: left; }
      .emotion-badge { margin-top: 0; padding: 3px 10px; font-size: 11px; }

      /* チャットパネル: 残りスペースを全て使う */
      .chat-panel {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
      }

      /* チャットヘッダー */
      .chat-header {
        padding: 10px 12px;
        flex-shrink: 0;
      }

      .chat-header-title { font-size: 13px; }
      .chat-header-sub { font-size: 11px; }
      .clear-btn { padding: 4px 10px; font-size: 11px; }

      /* メッセージエリア */
      .messages-area {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 12px;
        gap: 12px;
      }

      .message-row {
        max-width: 88%;
      }

      .msg-bubble {
        font-size: 14px;
        padding: 9px 12px;
        /* 長い単語もはみ出さないよう強制折り返し */
        word-break: break-word;
        overflow-wrap: anywhere;
      }

      .msg-avatar {
        width: 28px;
        height: 28px;
        font-size: 14px;
      }

      /* 入力エリア: 画面下部に固定 */
      .input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        flex-shrink: 0;
        /* iOS Safari でキーボード表示時も追従させるため
           JS (visualViewport) で bottom を制御する */
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 50;
      }

      /* 入力エリアが fixed になる分、チャットパネルに下パディングを追加 */
      .chat-panel {
        padding-bottom: 70px; /* input-area の高さ分の余白 */
      }

      /* 送信ボタン: タップしやすいサイズ確保 */
      .send-btn {
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
        font-size: 22px;
      }

      .send-btn svg {
        width: 22px;
        height: 22px;
      }

      /* テキストエリア: iOS でズームしないよう font-size 16px 以上 */
      .chat-input {
        font-size: 16px;
        min-height: 48px;
      }
    }

    /* 超小型スマホ (iPhone SE 等) */
    @media (max-width: 375px) {
      .header-title { display: none; }
      .header-subtitle { display: none; }
      .nav-link { padding: 4px 6px; font-size: 10px; }
    }

    /* RVC声モデル選択 */
    .rvc-section {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
    }

    .rvc-label {
      font-size: 12px;
      color: var(--text-muted);
      white-space: nowrap;
    }

    .rvc-status-dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      flex-shrink: 0;
      background: var(--text-dim);
      transition: background 0.3s, box-shadow 0.3s;
    }

    .rvc-status-dot.connected {
      background: var(--green);
      box-shadow: 0 0 6px var(--green);
    }

    .rvc-status-dot.disconnected {
      background: var(--red);
      box-shadow: 0 0 6px var(--red);
    }

    .rvc-select {
      background: var(--card2);
      border: 1px solid var(--border);
      color: var(--text);
      padding: 4px 8px;
      border-radius: var(--radius-sm);
      font-size: 12px;
      font-family: inherit;
      cursor: pointer;
      outline: none;
      transition: border-color 0.2s;
      max-width: 180px;
    }

    .rvc-select:focus {
      border-color: var(--accent);
    }

    .rvc-select:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }

    .rvc-loading-text {
      font-size: 11px;
      color: var(--text-dim);
    }

    @media (max-width: 768px) {
      .rvc-section { gap: 6px; }
      .rvc-select { max-width: 130px; font-size: 11px; }
      .rvc-label { font-size: 11px; }
    }
  