/* iPhone等の自動文字サイズ調整による崩れを防止 */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  background-color: #0a0a0a;
  color: #f0f0f0;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Meiryo", sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

/* 全体のコンテナ（前のサイズ感） */
#game-container {
  width: 100%;
  max-width: 680px;
  height: 94vh;
  background: #141414;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.85);
  overflow: hidden;
  position: relative;
  border: 1px solid #333;
}

/* =========================================
   上部エリア（左：余白なしの絵 ／ 右：目的パネル）
   ========================================= */
#top-stage {
  display: flex;
  flex-direction: row;
  height: 54%;
  min-height: 260px;
  border-bottom: 2px solid #2c2c2c;
  background: #000;
}

/* 左側：絵が余白なくピタッと埋まる領域 */
#visual-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
}

#char-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;          /* 余白を一切作らず枠いっぱいに埋める */
  object-position: center top; /* 人物の顔〜上半身が綺麗に入るよう上中央基準 */
}

#char-name-plate {
  position: absolute;
  bottom: 8px;
  left: 10px;
  background: rgba(15, 15, 15, 0.85);
  color: #f39c12;
  border: 1px solid #f39c12;
  padding: 3px 12px;
  border-radius: 14px;
  font-size: 0.78rem;
  font-weight: bold;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

/* 右側：タイトル＆目的（クエスト）パネル */
#side-panel {
  width: 210px;
  background: #1b1b1b;
  border-left: 1px solid #333;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
  overflow-y: auto;
}

.header-top {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #333;
}

h1 {
  margin: 0;
  font-size: 0.95rem;
  color: #fff;
  line-height: 1.3;
}

.header-buttons {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

#api-btn, #char-btn {
  flex: 1;
  background: #2b2b2b;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 5px 6px;
  font-size: 0.72rem;
  cursor: pointer;
  white-space: nowrap;
}

#char-btn:hover, #api-btn:hover {
  background: #444;
}

/* 右側の目的表示パネル */
.quest-panel {
  flex: 1;
  background: #121212;
  border-left: 3px solid #f1c40f;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quest-title {
  color: #fff;
  line-height: 1.45;
}

.quest-icon {
  color: #f1c40f;
  font-weight: bold;
  display: block;
  margin-bottom: 4px;
  font-size: 0.82rem;
}

#quest-text {
  font-weight: bold;
  font-size: 0.8rem;
}

.quest-flags {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}

.flag-badge {
  background: #222;
  color: #aaa;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.74rem;
  border: 1px solid #444;
  transition: all 0.3s ease;
}

.flag-badge.cleared {
  background: rgba(46, 204, 113, 0.2);
  color: #2ecc71;
  border-color: #2ecc71;
  font-weight: bold;
}

/* =========================================
   下部エリア：文字が出るところ（チャット＆ストーリー）
   ========================================= */
main#screen {
  flex: 1;
  padding: 12px 16px;
  overflow-y: auto;
  background: #141414;
  line-height: 1.65;
  font-size: 0.94rem;
  display: flex;
  flex-direction: column;
}

#text-display {
  margin-top: auto;
}

/* 地の文・ストーリーブロック */
.story-block {
  margin-bottom: 12px;
  padding: 10px 14px;
  background: #1f1f1f;
  border-radius: 6px;
  border: 1px solid #333;
  white-space: pre-wrap;
  color: #f0f0f0;
}

/* チャット吹き出し */
.chat-entry {
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  line-height: 1.55;
  animation: fadeIn 0.25s ease;
}

.chat-player {
  background: #1a3a54;
  color: #e8f4fc;
  margin-left: 16%;
  border: 1px solid #2e6da4;
  border-bottom-right-radius: 2px;
}

.chat-npc {
  background: #222222;
  color: #ffffff;
  margin-right: 6%;
  border-left: 4px solid #e67e22;
  border-top: 1px solid #333;
  border-right: 1px solid #333;
  border-bottom: 1px solid #333;
  border-bottom-left-radius: 2px;
}

.speaker-name {
  font-size: 0.78rem;
  font-weight: bold;
  color: #f39c12;
  margin-bottom: 4px;
  display: block;
}

.chat-player .speaker-name {
  color: #5dade2;
}

/* フッター・操作エリア */
footer#controls {
  padding: 10px 14px;
  background: #1c1c1c;
  border-top: 1px solid #333;
}

#system-msg {
  font-size: 0.8rem;
  color: #f1c40f;
  margin-bottom: 6px;
  min-height: 1.2em;
}

#command-box {
  display: flex;
  justify-content: center;
}

#start-btn {
  width: 100%;
  padding: 11px;
  font-size: 1rem;
  background: #3498db;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}

/* チャット入力欄 */
#chat-box {
  display: flex;
  gap: 8px;
  width: 100%;
}

#user-input {
  flex: 1;
  padding: 9px 12px;
  font-size: 0.95rem;
  border-radius: 4px;
  border: 1px solid #555;
  background: #111;
  color: #fff;
  outline: none;
}

#user-input:focus {
  border-color: #3498db;
}

#send-btn {
  padding: 9px 18px;
  font-size: 0.9rem;
  background: #e67e22;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  white-space: nowrap;
}

#send-btn:disabled, #user-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 条件クリア時の次へ進むボタン */
#next-action-box {
  margin-top: 8px;
  animation: popUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#next-stage-btn {
  width: 100%;
  padding: 11px;
  font-size: 0.98rem;
  background: linear-gradient(90deg, #27ae60, #2ecc71);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
}

@keyframes popUp {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* モーダル・エンディングパネル */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 20px;
  box-sizing: border-box;
}

.modal-content {
  background: #222;
  border: 2px solid #3498db;
  border-radius: 8px;
  padding: 20px;
  color: #fff;
  text-align: left;
  line-height: 1.6;
  width: 100%;
  max-width: 460px;
}

.modal-content h2 {
  margin-top: 0;
  color: #3498db;
  font-size: 1.2rem;
  text-align: center;
}

.api-input {
  width: 100%;
  padding: 10px;
  box-sizing: border-box;
  background: #111;
  border: 1px solid #555;
  color: #fff;
  border-radius: 4px;
}

.btn-modal-start {
  width: 100%;
  padding: 12px;
  margin-top: 16px;
  font-size: 1rem;
  background: #2ecc71;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}

#ending-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 82%;
  background: rgba(25, 25, 25, 0.96);
  border: 2px solid #2ecc71;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  z-index: 10;
  box-shadow: 0 8px 30px rgba(0,0,0,0.9);
}

#ending-title { margin-top: 0; color: #2ecc71; }
#ending-msg { font-size: 0.92rem; line-height: 1.6; white-space: pre-wrap; }

.btn-retry {
  padding: 10px 20px;
  background: #3498db;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  margin-top: 10px;
  font-weight: bold;
}

/* スマホなど横幅が狭い画面でも見やすいよう右パネル幅を自動調整 */
@media (max-width: 480px) {
  #side-panel {
    width: 155px;
    padding: 8px;
  }
  h1 {
    font-size: 0.85rem;
  }
}