/* ===== リセット & フォント ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f5f5f5;
  min-height: 100vh;
  overflow: hidden;
}

/* ===== メインコンテナ ===== */
.container {
  display: grid;
  grid-template-columns: 400px 1fr;
  height: 100vh;
  padding: 16px;
  gap: 16px;
}

/* ===== チャットパネル（左） ===== */
.chat-panel {
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.chat-header {
  background: white;
  color: #1d1d1f;
  padding: 20px;
  border-bottom: 1px solid #e5e5e5;
}

.chat-header h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header p {
  font-size: 13px;
  color: #6e6e73;
  font-weight: 400;
}

/* API キー入力セクション */
.api-key-section {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e5e5e5;
}

.api-key-section input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #d1d1d6;
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
}

.api-key-section input:focus {
  outline: none;
  border-color: #4A90E2;
}

.api-key-section button {
  padding: 8px 16px;
  background: #4A90E2;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.api-key-section button:hover {
  background: #357ABD;
}

#apiKeyStatus {
  font-size: 12px;
  white-space: nowrap;
}

.chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: white;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: slideIn 0.3s ease-out;
}

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

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  background: #f5f5f5;
}

.message.user .message-avatar {
  background: #4A90E2;
  color: white;
}

.message.bot .message-avatar {
  background: #f5f5f5;
}

.message-content {
  flex: 1;
  padding: 10px 14px;
  border-radius: 12px;
  max-width: 80%;
}

.message.user .message-content {
  background: #4A90E2;
  color: white;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}

.message.bot .message-content {
  background: #f5f5f5;
  color: #1d1d1f;
  border-bottom-left-radius: 4px;
}

.message-text {
  font-size: 14px;
  line-height: 1.5;
}

.chat-input-container {
  padding: 12px 16px;
  background: white;
  border-top: 1px solid #e5e5e5;
}

.chat-input-wrapper {
  display: flex;
  gap: 10px;
  align-items: center;
}

#userInput {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #d1d1d6;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: white;
}

#userInput:focus {
  outline: none;
  border-color: #4A90E2;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

#userInput::placeholder {
  color: #86868b;
}

#sendButton {
  padding: 10px 20px;
  background: #4A90E2;
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

#sendButton:hover {
  background: #357ABD;
}

#sendButton:active {
  transform: scale(0.98);
}

#sendButton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ===== タブ付きパネル ===== */
.tabbed-panel {
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

/* タブヘッダー */
.tab-header {
  display: flex;
  background: #f5f5f5;
  border-bottom: 2px solid #e5e5e5;
  padding: 0;
}

.tab-button {
  flex: 1;
  padding: 16px;
  background: transparent;
  border: none;
  font-size: 16px;
  font-weight: 600;
  color: #6e6e73;
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 3px solid transparent;
}

.tab-button:hover {
  background: #ebebeb;
}

.tab-button.active {
  color: #4A90E2;
  background: white;
  border-bottom-color: #4A90E2;
}

/* タブコンテンツ */
.tab-content {
  display: none;
  flex: 1;
  overflow: hidden;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
}

/* コードパネル（タブ内） */
.code-panel-inner {
  display: flex;
  flex-direction: column;
  background: #1e1e1e;
  height: 100%;
  overflow: hidden;
}

.code-header {
  background: #252526;
  color: #d4d4d4;
  padding: 16px 20px;
  border-bottom: 1px solid #3e3e42;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.code-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: #d4d4d4;
}

#copyCodeButton {
  padding: 6px 14px;
  background: #0e639c;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

#copyCodeButton:hover {
  background: #1177bb;
}

.code-content {
  flex: 1;
  position: relative;
  overflow: auto;
  background: #1e1e1e;
}

.code-content pre {
  margin: 0;
  padding: 16px;
  overflow: visible;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #d4d4d4;
}

.code-content code {
  font-family: inherit;
  white-space: pre-wrap;
  word-break: break-all;
}

/* カーソル点滅アニメーション */
.code-content.streaming code::after {
  content: '█';
  animation: blink 1s infinite;
  color: #d4d4d4;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.code-placeholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #86868b;
}

.code-placeholder-icon {
  font-size: 56px;
  margin-bottom: 12px;
  opacity: 0.6;
}

.code-placeholder p {
  font-size: 15px;
  font-weight: 500;
}

/* プレビューパネル（タブ内） */
.preview-panel-inner {
  display: flex;
  flex-direction: column;
  background: white;
  height: 100%;
  overflow: hidden;
}

.preview-header {
  background: white;
  color: #1d1d1f;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e5e5e5;
}

.preview-header h2 {
  font-size: 16px;
  font-weight: 600;
}

#clearButton {
  padding: 6px 14px;
  background: white;
  color: #4A90E2;
  border: 1px solid #d1d1d6;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

#clearButton:hover {
  background: #f5f5f5;
  border-color: #4A90E2;
}

#clearButton:active {
  transform: scale(0.98);
}

.preview-buttons {
  display: flex;
  gap: 8px;
}

#reloadButton {
  padding: 6px 14px;
  background: #4A90E2;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#reloadButton:hover {
  background: #357ABD;
}

#reloadButton:active {
  transform: scale(0.98);
}

.preview-content {
  flex: 1;
  position: relative;
  background: #fafafa;
}

#gamePreview {
  width: 100%;
  height: 100%;
  border: none;
  background: white;
}

.preview-placeholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #86868b;
}

.preview-placeholder-icon {
  font-size: 56px;
  margin-bottom: 12px;
  opacity: 0.6;
}

.preview-placeholder p {
  font-size: 15px;
  font-weight: 500;
}

/* ===== ローディングアニメーション ===== */
.loading {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.loading-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: bounce 1.4s infinite ease-in-out;
}

.loading-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce {
  0%, 80%, 100% {
    transform: scale(0);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ===== スクロールバーのカスタマイズ ===== */
.chat-messages::-webkit-scrollbar,
.code-content::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.chat-messages::-webkit-scrollbar-track,
.code-content::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #d1d1d6;
  border-radius: 4px;
}

.code-content::-webkit-scrollbar-thumb {
  background: #3e3e42;
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.code-content::-webkit-scrollbar-thumb:hover {
  background: #aeaeb2;
}

/* ===== レスポンシブデザイン（iPad対応） ===== */
/* iPadサイズ: 左右2カラム + タブ切り替え */
@media (max-width: 1024px) {
  .container {
    grid-template-columns: 1fr;
    grid-template-rows: 45vh 1fr;
    gap: 12px;
  }

  .chat-panel {
    max-height: none;
  }

  .tab-button {
    font-size: 15px;
    padding: 14px;
  }

  .code-header h2,
  .preview-header h2 {
    font-size: 15px;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 10px;
    gap: 10px;
  }

  .chat-header h1 {
    font-size: 18px;
  }

  .chat-input-wrapper {
    flex-direction: column;
  }

  #sendButton {
    width: 100%;
  }
}

/* ===== タッチデバイス用の調整 ===== */
@media (hover: none) and (pointer: coarse) {
  #userInput,
  #sendButton,
  #clearButton,
  #copyCodeButton {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  /* タッチターゲットを大きく */
  #sendButton,
  #clearButton,
  #copyCodeButton {
    min-height: 44px;
min-width: 44px;
  }
}
