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

body {
  background: #050505;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 40px 16px;
}

#game {
  font-family: 'Noto Serif JP', serif;
  background: #0a0a0a;
  color: #c8c0b0;
  width: 100%;
  max-width: 480px;
  min-height: 600px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  border: 0.5px solid #1a1a1a;
}

#silhouette-area {
  height: 220px;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  transition: filter 2s ease;
}

#silhouette-area::before {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0; height: 60px;
  background: linear-gradient(transparent, #0a0a0a);
  z-index: 2;
}

.room-bg { position: absolute; inset: 0; }

.room-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  transition: all 2s ease;
}

#story-area { padding: 24px 28px 16px; flex: 1; }

#phase-label {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: #777;
  margin-bottom: 16px;
  text-transform: uppercase;
  transition: color 1s ease;
}

#scene-text {
  font-size: 14px;
  line-height: 2;
  color: #b8b0a0;
  min-height: 100px;
  margin-bottom: 24px;
}

#scene-text.typing::after {
  content: '▋';
  animation: blink 0.8s infinite;
  color: #666;
  font-size: 12px;
}

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

#scene-spinner {
  display: none;
  width: 20px;
  height: 20px;
  margin: 8px auto 24px;
}

#scene-spinner.active { display: block; }

#scene-spinner svg {
  width: 20px;
  height: 20px;
  animation: spin 2s linear infinite;
}

@keyframes spin { from{transform:rotate(0deg)} to{transform:rotate(360deg)} }

#choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 28px 24px;
}

.choice-btn {
  background: transparent;
  border: 0.5px solid #333;
  color: #888;
  padding: 12px 16px;
  font-family: 'Noto Serif JP', serif;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
  line-height: 1.7;
}

.choice-btn:hover {
  border-color: #666;
  color: #c8c0b0;
  background: rgba(255,255,255,0.03);
}

.choice-btn:disabled { opacity: 0.3; cursor: default; }

#free-input-area {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-top: 4px;
  width: 100%;
}

#free-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0.5px solid #2a2a2a;
  color: #888;
  padding: 11px 14px;
  font-family: 'Noto Serif JP', serif;
  font-size: 13px;
  border-radius: 2px;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.7;
}

#free-input:focus { border-color: #444; color: #b8b0a0; }
#free-input::placeholder { color: #555; font-size: 12px; }
#free-input:disabled { opacity: 0.3; }

#free-submit {
  background: transparent;
  border: 0.5px solid #444;
  color: #666;
  padding: 11px 14px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
  white-space: nowrap;
  letter-spacing: 0.1em;
}

#free-submit:hover { border-color: #555; color: #888; }
#free-submit:disabled { opacity: 0.3; cursor: default; }

#loading-indicator {
  display: none;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  color: #444;
  padding: 8px 28px 16px;
  letter-spacing: 0.1em;
}

#loading-indicator.active { display: block; }

#turn-counter {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  color: #555;
  padding: 0 28px 16px;
  letter-spacing: 0.15em;
  transition: color 1s ease;
}

.fade-in { animation: fadeIn 0.6s ease-in; }
@keyframes fadeIn { from{opacity:0} to{opacity:1} }

/* スタート画面 */
#start-screen {
  position: absolute;
  inset: 0;
  background: #0a0a0a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  gap: 8px;
}

#start-screen h1 {
  font-size: 28px;
  font-weight: 300;
  color: #c8c0b0;
  letter-spacing: 0.3em;
  margin-bottom: 8px;
}

#start-screen p {
  font-size: 12px;
  color: #888;
  letter-spacing: 0.2em;
  margin-bottom: 32px;
}

#login-btn {
  background: transparent;
  border: 0.5px solid #555;
  color: #999;
  padding: 10px 28px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  cursor: pointer;
  letter-spacing: 0.15em;
  transition: all 0.3s;
  margin-bottom: 8px;
}

#login-btn:hover { border-color: #999; color: #c8c0b0; }

#start-btn {
  background: transparent;
  border: 0.5px solid #666;
  color: #aaa;
  padding: 12px 32px;
  font-family: 'Noto Serif JP', serif;
  font-size: 13px;
  cursor: pointer;
  letter-spacing: 0.2em;
  transition: all 0.3s;
}

#start-btn:hover { border-color: #aaa; color: #c8c0b0; }

#protagonist-name {
  font-size: 11px;
  color: #666;
  letter-spacing: 0.15em;
}

#user-info {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  color: #aaa;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

#api-key-area {
  padding: 0 28px 16px;
  width: 100%;
  max-width: 320px;
}

#api-key-area label {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  color: #777;
  letter-spacing: 0.15em;
  display: block;
  margin-bottom: 6px;
}

#api-key-input {
  width: 100%;
  background: transparent;
  border: 0.5px solid #2a2a2a;
  color: #666;
  padding: 8px 12px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  border-radius: 2px;
  outline: none;
  transition: border-color 0.2s;
}

#api-key-input:focus { border-color: #444; color: #888; }

#error-msg {
  display: none;
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  color: #6a3030;
  padding: 4px 28px 8px;
  letter-spacing: 0.1em;
}

#error-msg.active { display: block; }

/* エンディング画面 */
#ending-screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background: #0a0a0a;
  z-index: 9999;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  font-family: 'Noto Serif JP', serif;
  color: #c8c0b0;
}

#ending-screen.active {
  display: block !important;
}

#ending-inner {
  max-width: 480px;
  margin: 0 auto;
  padding: 40px 28px 80px;
  min-height: 100vh;
}

#ending-label {
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.25em;
  color: #777;
  margin-bottom: 32px;
  display: block;
}

#ending-text {
  font-size: 14px;
  line-height: 2.2;
  color: #b8b0a0;
  display: block;
  margin-bottom: 24px;
}

#ending-text.typing::after {
  content: '▋';
  animation: blink 0.8s infinite;
  color: #666;
  font-size: 12px;
}

#ending-footer {
  margin-top: 48px;
  display: none;
}

#ending-footer.active {
  display: block;
}

#ending-footer hr {
  border: none;
  border-top: 0.5px solid #2a2a2a;
  margin-bottom: 24px;
}

#ending-title {
  font-size: 11px;
  font-family: 'Share Tech Mono', monospace;
  color: #777;
  letter-spacing: 0.2em;
  margin-bottom: 8px;
}

#ending-subtitle {
  font-size: 22px;
  font-weight: 300;
  color: #a89890;
  letter-spacing: 0.1em;
  margin-bottom: 32px;
}

#restart-btn {
  background: transparent;
  border: 0.5px solid #444;
  color: #888;
  padding: 10px 24px;
  font-family: 'Noto Serif JP', serif;
  font-size: 12px;
  cursor: pointer;
  letter-spacing: 0.2em;
  transition: all 0.3s;
}

#restart-btn:hover { border-color: #777; color: #c8c0b0; }

/* フェーズによる雰囲気変化 */
.phase-2 #phase-label { color: #c05050; }
.phase-2 #turn-counter { color: #7a3535; }
.phase-2 .choice-btn { border-color: #5a2a2a; color: #c08080; }
.phase-2 .choice-btn:hover { border-color: #aa4040; color: #e0a0a0; }

.phase-3 #phase-label { color: #e03030; }
.phase-3 #turn-counter { color: #aa2525; }
.phase-3 #scene-text { color: #c8a090; }
.phase-3 .choice-btn { border-color: #7a1a1a; color: #cc6060; }
.phase-3 .choice-btn:hover { border-color: #cc2020; color: #ff9090; }

@keyframes flicker {
  0%,100%{opacity:1} 92%{opacity:1} 93%{opacity:0.7} 94%{opacity:1} 97%{opacity:0.8} 98%{opacity:1}
}

.phase-3 #silhouette-area { animation: flicker 4s infinite; }