/*
Theme Name: Cosmo AI
Theme URI: https://example.com/cosmo-ai
Author: April Fool Project
Description: エイプリルフール用 Cosmo AI PWA チャットアプリのWordPressテーマ
Version: 1.4.0
Requires at least: 6.0
Requires PHP: 7.4
License: MIT
Text Domain: cosmo-ai
*/

/* =============================================
   リセット & ベース
   ============================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --blue: #007AFF;
  --bubble-user: #007AFF;
  --bubble-ai: #E9E9EB;
  --bg: #F2F2F7;
  --header-bg: rgba(255,255,255,0.85);
  --input-bg: rgba(255,255,255,0.95);
  --text-primary: #1C1C1E;
  --text-secondary: #8E8E93;
  --font: -apple-system, "Helvetica Neue", Arial, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font);
  color: var(--text-primary);
}

/* =============================================
   アプリレイアウト
   ============================================= */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  position: relative;
}

/* =============================================
   ヘッダー
   ============================================= */
#chat-header {
  flex-shrink: 0;
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(0,0,0,0.1);
  padding: env(safe-area-inset-top, 12px) 16px 12px;
  padding-top: max(env(safe-area-inset-top), 12px);
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(90,103,216,0.35);
}

.avatar svg {
  width: 100%;
  height: 100%;
}

.status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  background: #34C759;
  border-radius: 50%;
  border: 2px solid white;
}

.header-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.header-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.header-status {
  font-size: 12px;
  color: var(--text-secondary);
}

/* =============================================
   メッセージリスト
   ============================================= */
#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  scroll-behavior: smooth;
}

#messages-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.date-divider {
  text-align: center;
  margin: 12px 0;
}

.date-divider span {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 2px 10px;
}

/* =============================================
   メッセージバブル
   ============================================= */
.message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 80%;
  animation: fadeSlideIn 0.25s ease;
}

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

.message.ai {
  align-self: flex-start;
}

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

.bubble-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.message.user .bubble-wrap {
  align-items: flex-end;
}

.message.ai .bubble-wrap {
  align-items: flex-start;
}

.message-bubble {
  padding: 10px 15px;
  border-radius: 20px;
  line-height: 1.5;
  font-size: 16px;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 100%;
}

.message.user .message-bubble {
  background: var(--bubble-user);
  color: white;
  border-bottom-right-radius: 5px;
}

.message.ai .message-bubble {
  background: var(--bubble-ai);
  color: var(--text-primary);
  border-bottom-left-radius: 5px;
}

.message-bubble p + p {
  margin-top: 6px;
}

.msg-time {
  font-size: 11px;
  color: var(--text-secondary);
  padding: 0 4px;
}

/* タイピングインジケーター */
.typing-indicator .message-bubble {
  padding: 14px 18px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: #8E8E93;
  border-radius: 50%;
  animation: typingBounce 1.2s ease infinite;
}

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

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* =============================================
   入力エリア
   ============================================= */
#input-area {
  flex-shrink: 0;
  background: var(--input-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(0,0,0,0.1);
  padding: 10px 12px;
  padding-bottom: max(env(safe-area-inset-bottom), 10px);
}

.input-inner {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: #EBEBF0;
  border-radius: 22px;
  padding: 8px 8px 8px 16px;
}

#message-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 16px;
  font-family: var(--font);
  color: var(--text-primary);
  resize: none;
  outline: none;
  max-height: 140px;
  line-height: 1.5;
  overflow-y: auto;
}

#message-input::placeholder {
  color: #C7C7CC;
}

#send-button {
  border: none;
  background: transparent;
  cursor: pointer;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  padding: 0;
  transition: transform 0.1s ease, opacity 0.15s ease;
  opacity: 0.35;
  pointer-events: none;
}

#send-button.active {
  opacity: 1;
  pointer-events: auto;
}

#send-button:active {
  transform: scale(0.88);
}

#send-button svg {
  width: 100%;
  height: 100%;
}

/* =============================================
   Turn 4: 赤点滅エフェクト
   ============================================= */
body.flash-red {
  animation: flashRed 0.4s ease-in-out infinite;
}

@keyframes flashRed {
  0%, 100% { background: var(--bg); }
  50%       { background: #FF3B30; }
}

/* Turn 4: 浮き上がりアニメーション */
.float-away {
  animation: floatAway var(--float-dur, 3s) ease-in var(--float-delay, 0s) forwards !important;
  pointer-events: none !important;
}

@keyframes floatAway {
  0%   { transform: translate(var(--fx, 0px), 0px) rotate(var(--fr, 0deg)); opacity: 1; }
  100% { transform: translate(var(--fx, 0px), -120vh) rotate(var(--fr2, 0deg)); opacity: 0; }
}

/* =============================================
   警告モーダル (Turn 4)
   ============================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: modalIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

.modal-box {
  background: white;
  border-radius: 20px;
  padding: 32px 28px;
  text-align: center;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.modal-icon {
  font-size: 56px;
  margin-bottom: 16px;
  animation: shake 0.5s ease infinite;
}

@keyframes shake {
  0%, 100% { transform: rotate(0deg); }
  25%       { transform: rotate(-8deg); }
  75%       { transform: rotate(8deg); }
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  color: #FF3B30;
  margin-bottom: 14px;
  letter-spacing: -0.3px;
}

.modal-body {
  font-size: 22px;
  font-weight: 700;
  color: #1C1C1E;
  margin-bottom: 10px;
  line-height: 1.4;
}

.modal-sub {
  font-size: 13px;
  color: #8E8E93;
  margin-bottom: 24px;
  line-height: 1.6;
}

.modal-btn {
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, #FF3B30, #FF6B35);
  color: white;
  border: none;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  box-shadow: 0 4px 15px rgba(255,59,48,0.4);
  transition: transform 0.1s ease;
}

.modal-btn:active {
  transform: scale(0.97);
}

/* =============================================
   スクロールバー
   ============================================= */
#messages-container::-webkit-scrollbar {
  width: 4px;
}

#messages-container::-webkit-scrollbar-track {
  background: transparent;
}

#messages-container::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: 2px;
}

/* =============================================
   ローディングオーバーレイ（システムダウン演出）
   ============================================= */
#error-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

/* =============================================
   AI応答 Markdownレンダリング用スタイル
   (.ai-chat-response 内にスコープ限定)
   ============================================= */
.ai-chat-response {
  font-size: 15px;
  line-height: 1.7;
  word-break: break-word;
}

/* white-space を上書き (Markdown HTML は pre-wrap 不要) */
.message.ai .message-bubble:has(.ai-chat-response) {
  white-space: normal;
}

/* 段落 */
.ai-chat-response p {
  margin: 0 0 8px 0;
}

.ai-chat-response p:last-child {
  margin-bottom: 0;
}

/* 見出し */
.ai-chat-response h1,
.ai-chat-response h2,
.ai-chat-response h3,
.ai-chat-response h4 {
  font-weight: 700;
  margin: 14px 0 6px 0;
  line-height: 1.3;
}

.ai-chat-response h1:first-child,
.ai-chat-response h2:first-child,
.ai-chat-response h3:first-child {
  margin-top: 0;
}

.ai-chat-response h1 { font-size: 1.15em; }
.ai-chat-response h2 {
  font-size: 1.05em;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.ai-chat-response h3 { font-size: 1em; }
.ai-chat-response h4 { font-size: 0.95em; }

/* 箇条書き・番号付きリスト */
.ai-chat-response ul,
.ai-chat-response ol {
  margin: 6px 0 10px 0;
  padding-left: 1.4em;
}

.ai-chat-response li {
  margin-bottom: 3px;
}

.ai-chat-response li > ul,
.ai-chat-response li > ol {
  margin: 2px 0 2px 0;
}

/* 強調 */
.ai-chat-response strong {
  font-weight: 700;
  color: #1a1a1a;
}

.ai-chat-response em {
  font-style: italic;
}

/* インラインコード */
.ai-chat-response code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 0.88em;
}

/* コードブロック */
.ai-chat-response pre {
  background: rgba(0,0,0,0.05);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.ai-chat-response pre code {
  background: transparent;
  padding: 0;
  font-size: 0.85em;
  line-height: 1.5;
}

/* 引用 */
.ai-chat-response blockquote {
  border-left: 3px solid rgba(0,0,0,0.15);
  margin: 8px 0;
  padding: 4px 0 4px 12px;
  color: #555;
  font-size: 0.95em;
}

/* 水平線 */
.ai-chat-response hr {
  border: none;
  border-top: 1px solid rgba(0,0,0,0.1);
  margin: 12px 0;
}

/* テーブル */
.ai-chat-response table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.9em;
}

.ai-chat-response th,
.ai-chat-response td {
  border: 1px solid rgba(0,0,0,0.1);
  padding: 6px 10px;
  text-align: left;
}

.ai-chat-response th {
  background: rgba(0,0,0,0.04);
  font-weight: 600;
}

/* リンク */
.ai-chat-response a {
  color: #007AFF;
  text-decoration: none;
}

.ai-chat-response a:hover {
  text-decoration: underline;
}

/* 取り消し線 */
.ai-chat-response del {
  text-decoration: line-through;
  color: #999;
}

/* =============================================
   請求金額ハイライト（[[AMOUNT:...]] からパース）
   ============================================= */
.highlight-billing {
  font-size: 1.4em;
  font-weight: 800;
  color: #d9534f;
  text-shadow: 0 0 4px rgba(217,83,79,0.3);
}

/* 請求通知ブロック全体の強調スタイル */
.billing-notice-block {
  background: linear-gradient(135deg, #FFF0F0, #FFE0E0);
  border: 2px solid #FF3B30;
  border-radius: 12px;
  padding: 14px 16px;
  margin: 12px 0 4px;
  font-size: 16px;
  font-weight: 600;
  color: #991B1B;
  line-height: 1.7;
}

.billing-notice-block p {
  margin: 0;
}

/* =============================================
   ⑥ Turn 4: 全画面警告画面
   ============================================= */
#warning-screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #0a0a0a;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* 赤い警告ランプ風の脈動エフェクト */
.warning-lamp {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, rgba(255,0,0,0.25) 0%, transparent 50%);
  animation: lampPulse 1.5s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes lampPulse {
  0%, 100% {
    opacity: 0.3;
    background: radial-gradient(circle at 50% 0%, rgba(255,0,0,0.2) 0%, transparent 50%);
  }
  50% {
    opacity: 1;
    background: radial-gradient(circle at 50% 0%, rgba(255,0,0,0.5) 0%, transparent 60%);
  }
}

/* 警察線テープ (横に流れるアニメーション) */
.police-tape {
  position: absolute;
  left: 0;
  width: 100%;
  height: 40px;
  background: repeating-linear-gradient(
    -45deg,
    #FFD700,
    #FFD700 20px,
    #111 20px,
    #111 40px
  );
  z-index: 2;
  overflow: hidden;
  display: flex;
  align-items: center;
  box-shadow: 0 0 20px rgba(255,215,0,0.3);
}

.police-tape span {
  display: inline-block;
  white-space: nowrap;
  font-family: "Impact", "Arial Black", sans-serif;
  font-size: 14px;
  font-weight: 900;
  color: #111;
  text-transform: uppercase;
  letter-spacing: 4px;
  animation: tapeScroll 12s linear infinite;
}

.tape-top {
  top: 60px;
  transform: rotate(-2deg);
}

.tape-bottom {
  bottom: 60px;
  transform: rotate(2deg);
}

.tape-top span {
  animation-direction: normal;
}

.tape-bottom span {
  animation-direction: reverse;
}

@keyframes tapeScroll {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* 警告モーダルコンテンツ */
.warning-modal-content {
  position: relative;
  z-index: 3;
  background: rgba(20,0,0,0.9);
  border: 2px solid #FF3B30;
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
  max-width: 380px;
  width: calc(100% - 40px);
  box-shadow:
    0 0 40px rgba(255,59,48,0.4),
    inset 0 0 40px rgba(255,0,0,0.05);
  animation: modalPulseIn 0.4s cubic-bezier(0.34,1.56,0.64,1);
  max-height: 80vh;
  overflow-y: auto;
}

@keyframes modalPulseIn {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

.warning-modal-content .modal-icon {
  font-size: 52px;
  margin-bottom: 12px;
  animation: alarmFlash 0.8s ease infinite;
}

@keyframes alarmFlash {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(1.15); }
}

.warning-modal-content .modal-title {
  font-size: 20px;
  font-weight: 800;
  color: #FF3B30;
  margin-bottom: 12px;
  letter-spacing: -0.3px;
  text-shadow: 0 0 10px rgba(255,59,48,0.5);
}

.warning-modal-content .modal-body {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
  line-height: 1.4;
  white-space: pre-line;
}

.warning-modal-content .modal-sub {
  font-size: 12px;
  color: #aaa;
  margin-bottom: 20px;
  line-height: 1.6;
}

.warning-modal-content .modal-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #FF3B30, #CC0000);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  box-shadow: 0 4px 20px rgba(255,59,48,0.5);
  transition: transform 0.1s ease;
  animation: btnGlow 2s ease infinite;
}

@keyframes btnGlow {
  0%, 100% { box-shadow: 0 4px 20px rgba(255,59,48,0.5); }
  50%      { box-shadow: 0 4px 30px rgba(255,59,48,0.8); }
}

.warning-modal-content .modal-btn:active {
  transform: scale(0.97);
}

/* 請求内訳テーブル */
#billing-breakdown {
  margin-top: 18px;
  text-align: left;
}

.breakdown-title {
  font-size: 14px;
  font-weight: 700;
  color: #FFD700;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255,215,0,0.3);
}

.breakdown-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  color: #ddd;
}

.breakdown-table thead th {
  color: #999;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  padding: 4px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  text-align: left;
}

.breakdown-table tbody td {
  padding: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.breakdown-amount {
  text-align: right;
  font-weight: 600;
  color: #FF6B6B;
}

.breakdown-total-label {
  text-align: right;
  font-weight: 700;
  color: #FFD700;
  padding: 8px 6px !important;
  border-top: 2px solid rgba(255,215,0,0.3);
}

.breakdown-total-amount {
  text-align: right;
  font-weight: 800;
  font-size: 16px;
  color: #FF3B30;
  padding: 8px 6px !important;
  border-top: 2px solid rgba(255,215,0,0.3);
}

/* =============================================
   エイプリルフール トースト通知
   ============================================= */
.april-fool-toast {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 99999;
  background: linear-gradient(135deg, #00C851, #007E33);
  color: white;
  padding: 20px 24px;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  line-height: 1.6;
  transform: translateY(-100%);
  transition: transform 0.5s cubic-bezier(0.34,1.56,0.64,1);
  box-shadow: 0 4px 20px rgba(0,200,81,0.4);
  font-family: var(--font);
}

.april-fool-toast.show {
  transform: translateY(0);
}

