/* アプリ内キャラクター（きもかわ相棒）— scripts/character.js が生成する #characterStage 用 */

#characterStage {
  position: fixed;
  right: 14px;
  bottom: 16px;
  width: 64px;
  height: 64px;
  z-index: 60;
  display: block;
  pointer-events: none; /* ステージ自体はクリックを透過。子要素で個別に拾う */
}

#characterStage.hidden {
  display: none;
}

#characterStage.character-dismissed {
  display: none !important;
}

#characterStage.character-dismiss {
  animation: character-dismiss 5s ease forwards;
}

/* アバター（待機中は小さくゆらゆら、タップでピッカー） */
.character-avatar {
  position: absolute;
  right: 0;
  bottom: 0;
  pointer-events: auto;
  width: 64px;
  height: 64px;
  padding: 4px;
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 34%, #ffffff, #eef1f0);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transform-origin: bottom center;
  animation: character-bob 3.2s ease-in-out infinite;
  transition: box-shadow 0.14s ease, transform 0.08s ease;
}

#characterStage.character-dragging {
  z-index: 1200;
}

#characterStage.character-dragging .character-avatar {
  animation: none !important;
  cursor: grabbing;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.26);
}

.character-avatar:active {
  transform: scale(0.98);
}

.character-avatar svg {
  display: block;
  width: 100%;
  height: 100%;
}

@keyframes character-bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-3px) rotate(2deg); }
}

/* ひょっこり（成功時。下からポンッと跳ねて出る） */
#characterStage.character-pop .character-avatar {
  animation: character-pop 0.6s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes character-pop {
  0%   { transform: translateY(64px) scale(0.6); }
  55%  { transform: translateY(-9px) scale(1.12); }
  75%  { transform: translateY(0) scale(0.96); }
  100% { transform: translateY(0) scale(1); }
}

/* アンビエント発話（控えめ・小さく持ち上がるだけ・音なし） */
#characterStage.character-peek .character-avatar {
  animation: character-peek 0.5s ease;
}

@keyframes character-peek {
  0%   { transform: translateY(10px) scale(0.94); }
  60%  { transform: translateY(-3px) scale(1.03); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes character-dismiss {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(38px) scale(0.46); }
}

.character-trash {
  position: fixed;
  left: 50%;
  bottom: max(18px, calc(env(safe-area-inset-bottom, 0px) + 14px));
  z-index: 1180;
  display: grid;
  place-items: center;
  width: 66px;
  height: 66px;
  border: 2px solid #efb4b4;
  border-radius: 50%;
  background: #fff8f8;
  color: #b42318;
  box-shadow: 0 14px 34px rgba(127, 29, 29, 0.22);
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
  transition: background-color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.character-trash[hidden] {
  display: none;
}

.character-trash.is-active {
  border-color: #dc2626;
  background: #fee2e2;
  box-shadow: 0 18px 42px rgba(185, 28, 28, 0.34);
  transform: translateX(-50%) translateY(-4px) scale(1.08);
}

/* セリフ吹き出し */
.character-bubble {
  position: absolute;
  right: 0;
  bottom: 72px;
  pointer-events: none;
  box-sizing: border-box;
  width: max-content;
  min-width: 156px;
  max-width: min(240px, calc(100vw - 32px));
  padding: 8px 12px;
  background: #ffffff;
  color: #243b36;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  word-break: keep-all;
  overflow-wrap: break-word;
  border: 2px solid var(--char-theme, #0f766e);
  border-radius: var(--radius);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14);
  animation: character-bubble-in 0.28s ease;
}

.character-bubble[hidden] {
  display: none;
}

.character-bubble::after {
  content: '';
  position: absolute;
  right: 22px;
  bottom: -8px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-right: 2px solid var(--char-theme, #0f766e);
  border-bottom: 2px solid var(--char-theme, #0f766e);
  transform: rotate(45deg);
}

#characterStage.character-left-side .character-bubble {
  left: 0;
  right: auto;
}

#characterStage.character-left-side .character-bubble::after {
  left: 22px;
  right: auto;
  border-right: 0;
  border-left: 2px solid var(--char-theme, #0f766e);
}

#characterStage.character-low-space .character-bubble {
  top: 72px;
  bottom: auto;
}

#characterStage.character-low-space .character-bubble::after {
  top: -8px;
  bottom: auto;
  transform: rotate(225deg);
}

@keyframes character-bubble-in {
  from { opacity: 0; transform: translateY(6px) scale(0.9); }
  to   { opacity: 1; transform: none; }
}

.character-settings-section {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  border: 1px solid var(--line, #e3e6e5);
  border-radius: var(--control-radius);
  padding: 9px 11px;
  background: #ffffff;
}

.character-settings-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.character-settings-heading h3 {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

.character-settings-heading span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.character-pick-row {
  display: flex;
  gap: 8px;
}

.character-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 56px;
  padding: 6px 4px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: #f6f8f7;
  cursor: pointer;
  transition: background-color 0.14s ease, border-color 0.14s ease, transform 0.08s ease;
}

.character-pick:active {
  transform: scale(0.98);
}

.character-pick.active {
  border-color: var(--char-theme, #0f766e);
  background: #ecfdf3;
}

.character-pick-art {
  width: 40px;
  height: 40px;
}

.character-pick-art svg {
  display: block;
  width: 100%;
  height: 100%;
}

.character-pick-name {
  font-size: 11px;
  font-weight: 800;
  color: #243b36;
}

.character-restore-button {
  justify-self: start;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid #cbdad5;
  border-radius: var(--control-radius);
  background: #f6f8f7;
  color: #143d36;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: background-color 0.14s ease, border-color 0.14s ease, transform 0.08s ease;
}

.character-restore-button:active {
  transform: scale(0.98);
}

.character-restore-button[hidden] {
  display: none;
}

.character-results-thanks {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 10px 0 0;
  padding: 6px 4px;
  border: 0;
  border-radius: var(--control-radius);
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
  opacity: 0.86;
  transition: opacity 0.14s ease, transform 0.08s ease;
}

.character-results-thanks:active {
  transform: scale(0.99);
}

.character-results-thanks[hidden] {
  display: none;
}

.character-results-art {
  width: 40px;
  height: 40px;
  opacity: 0.78;
}

.character-results-art svg {
  display: block;
  width: 100%;
  height: 100%;
}

.character-results-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.character-results-message {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
  .character-avatar { animation: none; }
  #characterStage.character-pop .character-avatar { animation: none; }
  #characterStage.character-peek .character-avatar { animation: none; }
  #characterStage.character-dismiss { animation: none; }
}
