/* ============================================================
 * components.css — 共用 UI 元件樣式
 * AI許願師－iPAS AI考證大冒險
 * ------------------------------------------------------------
 * 對應 js/ui/components.js 的元件：
 *   血條/EXP條、RPG對話框、嘉泰老師解析框、答題選項卡、
 *   傷害數字、Combo徽章、星星評價、Toast、Modal、稱號chip
 * ============================================================ */

/* ---------- 血條 / EXP 條 ---------- */
.ui-bar {
  position: relative;
  width: 100%;
  height: 18px;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 9px;
  overflow: hidden;
}
.ui-bar__ghost,               /* 白色殘影條：扣血時慢速跟上，打擊感來源 */
.ui-bar__fill {
  position: absolute;
  inset: 0;
  border-radius: 7px;
  transform-origin: left center;
}
.ui-bar__ghost {
  background: rgba(255, 255, 255, 0.65);
  transition: width 0.7s ease 0.25s;   /* 延遲後慢慢追上實際值 */
}
.ui-bar__fill {
  transition: width 0.25s ease;
}
.ui-bar--hp .ui-bar__fill {
  background: linear-gradient(180deg, #ff8ba0, var(--hp) 60%, #c22546);
  box-shadow: 0 0 10px rgba(255, 84, 112, 0.7);
}
.ui-bar--hp.ui-bar--low .ui-bar__fill {  /* 低血量警告閃爍 */
  animation: hp-low-blink 0.8s ease-in-out infinite;
}
@keyframes hp-low-blink {
  50% { filter: brightness(1.6); }
}
.ui-bar--exp .ui-bar__fill {
  background: linear-gradient(180deg, #fff3b8, var(--exp) 60%, #d9a800);
  box-shadow: 0 0 10px rgba(255, 213, 74, 0.7);
}
.ui-bar--boss {
  height: 26px;
  border-color: rgba(255, 84, 112, 0.6);
}
.ui-bar--boss .ui-bar__fill {
  background: linear-gradient(180deg, #d98bff, var(--neon-purple) 60%, #6a2fc9);
  box-shadow: 0 0 14px rgba(165, 107, 255, 0.8);
}
/* 條上文字（例：120 / 150） */
.ui-bar__text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  z-index: 1;
}
/* 受擊晃動（掛在血條外框上） */
.ui-bar--shake {
  animation: bar-shake 0.4s ease;
}
@keyframes bar-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}
/* 條的標籤列（名字 + 數值） */
.ui-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ui-bar-row__label {
  min-width: 3.5em;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

/* ---------- RPG 對話框（打字機） ---------- */
.rpg-dialog {
  position: fixed;
  left: 50%;
  bottom: 56px;
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 32px));
  z-index: 7;
  display: flex;
  gap: 14px;
  padding: 16px 18px;
  background: var(--bg-panel);
  border: 2px solid var(--neon-cyan);
  border-radius: var(--radius);
  box-shadow: var(--glow-cyan), 0 8px 30px rgba(0, 0, 0, 0.6);
  animation: dialog-in 0.25s ease both;
  cursor: pointer;
}
@keyframes dialog-in {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.rpg-dialog__portrait {
  flex: 0 0 72px;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: var(--bg-mid);
  overflow: hidden;
}
.rpg-dialog__portrait svg { width: 100%; height: 100%; }
/* 官方插畫（teacher.png 為全身立繪）：小頭像自動放大裁切到臉部特寫 */
.rpg-dialog__portrait .teacher-img,
.teacher-box__avatar .teacher-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(2);
  transform-origin: 50% 24%;   /* 對準插畫臉部位置 */
}
/* 真人照片(已預先裁成方形臉部特寫)：填滿圓框、置中，不需放大 */
.teacher-box__avatar .teacher-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 40%;
}
.rpg-dialog__body { flex: 1; min-width: 0; }
.rpg-dialog__name {
  display: inline-block;
  margin-bottom: 6px;
  padding: 2px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--bg-deep);
  background: var(--gold);
  border-radius: 999px;
  box-shadow: var(--glow-gold);
}
.rpg-dialog__text {
  min-height: 3em;
  line-height: 1.7;
  font-size: 0.98rem;
}
/* 「按此繼續」▼ 指示，打完字才顯示 */
.rpg-dialog__next {
  position: absolute;
  right: 14px;
  bottom: 8px;
  color: var(--neon-cyan);
  font-size: 0.8rem;
  opacity: 0;
  animation: next-bounce 0.9s ease-in-out infinite;
}
.rpg-dialog--done .rpg-dialog__next { opacity: 1; }
@keyframes next-bounce {
  50% { transform: translateY(4px); }
}

/* ---------- 嘉泰老師白話解析框 ---------- */
.teacher-box-backdrop {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 18, 0.82); /* 加深底色取代 backdrop-filter（效能考量，見 base.css .panel 註解） */
  animation: fade-in 0.25s ease both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.teacher-box {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  background: var(--bg-panel);
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  box-shadow: var(--glow-gold), 0 12px 40px rgba(0, 0, 0, 0.7);
  animation: teacher-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes teacher-pop {
  from { opacity: 0; transform: scale(0.85) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.teacher-box__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 213, 74, 0.35);
}
.teacher-box__avatar {
  width: 56px;
  height: 56px;
  flex-shrink: 0;   /* 在 flex header 內不被壓縮（真人照為方形，避免被擠成細條） */
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: var(--bg-mid);
  overflow: hidden;
  box-shadow: var(--glow-gold);
}
.teacher-box__avatar svg { width: 100%; height: 100%; }
.teacher-box__title {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--gold);
  text-shadow: var(--glow-gold);
  letter-spacing: 0.1em;
}
.teacher-box__subtitle {
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.15em;
}
.teacher-box__content { padding: 16px 20px; }
.teacher-box__section-label {
  display: inline-block;
  margin-bottom: 8px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
  letter-spacing: 0.1em;
}
.teacher-box__explain .teacher-box__section-label {
  color: var(--bg-deep);
  background: var(--success);
}
.teacher-box__trap .teacher-box__section-label {
  color: #fff;
  background: var(--danger);
}
.teacher-box__explain,
.teacher-box__trap {
  margin-bottom: 14px;
  line-height: 1.85;
  font-size: 0.95rem;
}
.teacher-box__trap {
  padding: 12px 14px;
  background: rgba(255, 84, 112, 0.1);
  border: 1px solid rgba(255, 84, 112, 0.4);
  border-radius: var(--radius-sm);
}
.teacher-box__footer {
  padding: 0 20px 18px;
  text-align: center;
}

/* ---------- 答題選項卡 ---------- */
.answer-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.6;
  text-align: left;
  color: var(--text-main);
  background: var(--bg-panel);
  border: 2px solid rgba(77, 141, 255, 0.45);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.answer-option:hover:not(:disabled) {
  transform: translateX(6px);
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-cyan);
}
.answer-option:disabled { cursor: default; opacity: 0.85; }
.answer-option__key {
  flex: 0 0 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: var(--neon-cyan);
  background: rgba(41, 230, 255, 0.12);
  border: 1px solid rgba(41, 230, 255, 0.5);
  border-radius: 8px;
}
/* 答對：綠色亮起 */
.answer-option--correct {
  border-color: var(--success) !important;
  background: rgba(61, 255, 160, 0.12);
  box-shadow: 0 0 14px rgba(61, 255, 160, 0.6) !important;
  animation: correct-pulse 0.45s ease;
}
.answer-option--correct .answer-option__key {
  color: var(--bg-deep);
  background: var(--success);
  border-color: var(--success);
}
@keyframes correct-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); }
  100% { transform: scale(1); }
}
/* 答錯：紅色搖頭 */
.answer-option--wrong {
  border-color: var(--danger) !important;
  background: rgba(255, 84, 112, 0.12);
  animation: wrong-shake 0.45s ease;
}
.answer-option--wrong .answer-option__key {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}
@keyframes wrong-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}
/* 被技能「提示詞魔法」刪去的選項 */
.answer-option--eliminated {
  opacity: 0.25;
  filter: grayscale(1);
  pointer-events: none;
  text-decoration: line-through;
}

/* ---------- 傷害數字（漂浮） ---------- */
.damage-num {
  position: fixed;
  z-index: 6;
  font-size: 2rem;
  font-weight: 900;
  pointer-events: none;
  animation: dmg-float 0.9s ease-out both;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}
.damage-num--player { color: var(--neon-cyan); }   /* 打 Boss 的傷害 */
.damage-num--enemy  { color: var(--danger); }      /* 玩家受傷 */
.damage-num--heal   { color: var(--success); }
.damage-num--crit {                                 /* Combo 高倍率暴擊 */
  font-size: 2.8rem;
  color: var(--gold);
  text-shadow: var(--glow-gold);
}
@keyframes dmg-float {
  0%   { opacity: 0; transform: translateY(0) scale(0.6); }
  15%  { opacity: 1; transform: translateY(-14px) scale(1.15); }
  100% { opacity: 0; transform: translateY(-70px) scale(1); }
}

/* ---------- Combo 徽章 ---------- */
.combo-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}
.combo-badge__num {
  font-size: 2.4rem;
  font-weight: 900;
  color: var(--gold);
  text-shadow: var(--glow-gold);
}
.combo-badge__label {
  font-size: 0.7rem;
  letter-spacing: 0.35em;
  color: var(--text-dim);
}
.combo-badge--pop .combo-badge__num {
  animation: combo-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes combo-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.5); }
  100% { transform: scale(1); }
}

/* ---------- 星星評價 ---------- */
.stars { display: inline-flex; gap: 10px; }
.stars__star {
  font-size: 2.2rem;
  color: rgba(255, 255, 255, 0.15);
  transition: color 0.2s;
}
.stars__star--on {
  color: var(--gold);
  text-shadow: var(--glow-gold);
  animation: star-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes star-pop {
  0% { transform: scale(0) rotate(-30deg); }
  60% { transform: scale(1.4) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}

/* ---------- Toast 通知 ---------- */
#toast-root {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 10px 22px;
  font-size: 0.9rem;
  font-weight: 700;
  background: var(--bg-panel);
  border: 1px solid var(--neon-cyan);
  border-radius: 999px;
  box-shadow: var(--glow-cyan);
  animation: toast-in 0.3s ease both;
}
.toast--gold { border-color: var(--gold); box-shadow: var(--glow-gold); color: var(--gold); }
.toast--danger { border-color: var(--danger); box-shadow: 0 0 12px rgba(255,84,112,0.6); color: var(--danger); }
.toast--out { animation: toast-out 0.3s ease both; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-16px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateY(-16px); }
}

/* ---------- Modal 確認框 ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 18, 0.7);
  animation: fade-in 0.2s ease both;
}
.modal {
  width: min(420px, calc(100vw - 40px));
  padding: 24px;
  text-align: center;
  animation: teacher-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.modal__title {
  margin-bottom: 12px;
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--neon-cyan);
}
.modal__text {
  margin-bottom: 20px;
  color: var(--text-dim);
  line-height: 1.7;
}
.modal__actions { display: flex; gap: 12px; justify-content: center; }

/* ---------- 稱號 / 勳章 chip ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  border-radius: 999px;
  border: 1px solid var(--neon-purple);
  color: var(--neon-purple);
  background: rgba(165, 107, 255, 0.1);
}
.chip--gold { border-color: var(--gold); color: var(--gold); background: rgba(255, 213, 74, 0.1); }
.chip--cyan { border-color: var(--neon-cyan); color: var(--neon-cyan); background: rgba(41, 230, 255, 0.1); }

/* ---------- 雷達圖容器 ---------- */
.radar-chart svg { display: block; }
.radar-chart .radar-area {
  fill: rgba(41, 230, 255, 0.25);
  stroke: var(--neon-cyan);
  stroke-width: 2;
  filter: drop-shadow(0 0 6px rgba(41, 230, 255, 0.8));
}
.radar-chart .radar-grid {
  fill: none;
  stroke: rgba(143, 162, 204, 0.25);
  stroke-width: 1;
}
.radar-chart .radar-label {
  fill: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
}
