:root {
  --bg: #12151d;
  --bg-soft: #181d29;
  --panel: #1c2231;
  --line: #2a3244;
  --text: #e7ecf5;
  --muted: #8b97ad;
  --accent: #e5a3a3;
  --accent-soft: #f3c9c9;
  --user-bubble: #33405c;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* 类选择器里的 display 会盖掉浏览器默认的 [hidden]，必须显式兜底 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.7;
}

button { font-family: inherit; cursor: pointer; }

.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
  overflow: hidden;
  /* clip 让它彻底不是滚动容器，避免焦点跳转把顶部面板顶出视野 */
  overflow: clip;
}

/* ---------- 左侧舞台 ---------- */

.stage-panel {
  background: linear-gradient(180deg, #1a2030 0%, #151a26 100%);
  border-right: 1px solid var(--line);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.portrait-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 0%, #2b3448 0%, #171c28 100%);
  aspect-ratio: 3 / 4;
}

.portrait { position: absolute; inset: 0; }
.portrait svg, .portrait img { width: 100%; height: 100%; display: block; object-fit: cover; object-position: top center; }

.portrait svg { animation: breathe 4.2s ease-in-out infinite; transform-origin: 50% 100%; }
.portrait.emotion-happy svg { animation-duration: 2.6s; }
.portrait.emotion-angry svg { animation: shake 0.5s ease-in-out 2; }
.portrait.emotion-surprised svg { animation: pop 0.6s ease-out; }
.portrait.emotion-sad svg { animation-duration: 6s; }

@keyframes breathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-6px) scale(1.012); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}
@keyframes pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.portrait-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(70% 55% at 50% 18%, rgba(229, 163, 163, 0.28) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.6s ease;
}
.portrait-glow.on { opacity: 1; }

.char-meta h1 { margin: 0; font-size: 20px; letter-spacing: 1px; }
.char-meta p { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.6; }

.affinity { position: relative; }
.affinity-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12.5px; color: var(--muted); letter-spacing: 1px;
}
.affinity-value { font-size: 17px; color: var(--accent-soft); font-weight: 600; }
.affinity-track {
  height: 8px; border-radius: 99px; background: #262e40; overflow: hidden; margin: 8px 0 10px;
}
.affinity-fill {
  height: 100%; width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, #8ea2c9 0%, #e5a3a3 60%, #f0c39a 100%);
  transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

.badge-row { display: flex; gap: 8px; }
.where-line {
  margin-top: 8px; font-size: 12.5px; color: #9aa6bd;
  display: flex; align-items: center; gap: 6px;
}
.where-line::before { content: '◎'; color: #6f7d99; font-size: 11px; }
.badge {
  font-size: 12px; padding: 3px 10px; border-radius: 99px;
  border: 1px solid var(--line); color: var(--muted); background: #1f2634;
}
.badge.stage { color: var(--accent-soft); border-color: #4a3a44; }
.badge.stage.flash { animation: flash 1.1s ease; }
@keyframes flash {
  0%, 100% { background: #1f2634; }
  30%      { background: #4a3a44; }
}

.delta-float {
  position: absolute; right: 2px; top: 34px;
  font-size: 15px; font-weight: 600; opacity: 0; pointer-events: none;
}
.delta-float.up { color: #8fd8a8; animation: floatUp 1.5s ease forwards; }
.delta-float.down { color: #e08b8b; animation: floatUp 1.5s ease forwards; }
@keyframes floatUp {
  0%   { opacity: 0; transform: translateY(6px); }
  25%  { opacity: 1; transform: translateY(-2px); }
  100% { opacity: 0; transform: translateY(-22px); }
}

.panel-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.panel-actions button.wide { grid-column: 1 / -1; }
.panel-actions button {
  padding: 8px 10px; border-radius: 10px; font-size: 13px;
  background: #222a3a; color: var(--text); border: 1px solid var(--line);
  transition: background 0.18s, border-color 0.18s;
}
.panel-actions button:hover { background: #2b3549; border-color: #3b475f; }

.provider-tag { margin: auto 0 0; font-size: 11.5px; color: #5f6a80; text-align: center; }
.provider-tag.warn { color: #d8a86a; }

/* ---------- 右侧聊天 ---------- */

.chat-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }

.chat-log {
  flex: 1; overflow-y: auto; padding: 26px clamp(16px, 5vw, 64px) 12px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}

.row { display: flex; }
.row.user { justify-content: flex-end; }

.bubble {
  max-width: min(680px, 82%);
  padding: 11px 15px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  animation: rise 0.28s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.row.assistant .bubble {
  background: var(--panel); border: 1px solid var(--line);
  border-top-left-radius: 4px;
}
.row.user .bubble {
  background: var(--user-bubble); border-top-right-radius: 4px;
}

.bubble .act { color: var(--muted); font-style: italic; }

.notice {
  align-self: center; max-width: 620px; text-align: center;
  font-size: 13px; color: #b9c3d6;
  background: #1a2130; border: 1px dashed #38445c;
  border-radius: 12px; padding: 9px 16px;
  animation: rise 0.4s ease;
}
.notice .notice-title { display: block; font-size: 11.5px; color: var(--accent); letter-spacing: 2px; margin-bottom: 3px; }

.typing { display: inline-flex; gap: 4px; align-items: center; height: 1.2em; }
.typing i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

.ended-banner {
  margin: 0 clamp(16px, 5vw, 64px) 6px;
  padding: 10px 16px; border-radius: 10px; font-size: 13.5px;
  background: #241f2c; border: 1px solid #3d3348; color: #ddd0e2;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.ended-banner button {
  background: transparent; border: 1px solid #574a63; color: #e6d8ec;
  border-radius: 8px; padding: 4px 12px; font-size: 13px;
}

.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 12px clamp(16px, 5vw, 64px) 20px;
  border-top: 1px solid #1e2431;
}
.composer textarea {
  flex: 1; resize: none; max-height: 160px;
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 14px; font-family: inherit; font-size: 15px; line-height: 1.6;
  outline: none; transition: border-color 0.18s;
}
.composer textarea:focus { border-color: #46567a; }
.composer button {
  background: linear-gradient(135deg, #6d7fa8 0%, #a8788c 100%);
  color: #fff; border: none; border-radius: 12px;
  padding: 12px 22px; font-size: 14.5px; letter-spacing: 2px;
  transition: filter 0.18s, opacity 0.18s;
}
.composer button.ghost {
  background: #222a3a; color: var(--text); border: 1px solid var(--line);
  padding: 12px 16px; letter-spacing: 1px;
}
.composer button.ghost:hover:not(:disabled) { background: #2b3549; filter: none; }
.composer button:hover:not(:disabled) { filter: brightness(1.12); }
.composer button:disabled, .composer textarea:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- 弹窗 ---------- */

.overlay {
  position: fixed; inset: 0; background: rgba(8, 10, 15, 0.72);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  z-index: 20; backdrop-filter: blur(3px);
}
.dialog {
  width: min(560px, 100%); max-height: 86vh; overflow-y: auto;
  background: #1a2030; border: 1px solid var(--line);
  border-radius: 16px; padding: 18px 20px 20px;
}
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; font-size: 16px; letter-spacing: 2px; font-weight: 600; }
.icon-btn {
  background: transparent; border: none; color: var(--muted);
  font-size: 22px; line-height: 1; padding: 2px 6px; border-radius: 6px;
}
.icon-btn:hover { color: var(--text); background: #232c3d; }

.dialog-body { margin-top: 14px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field em { font-style: normal; color: #66718a; font-size: 11.5px; margin-left: 4px; }
.field input[type="text"], .field input[type="password"], .field select {
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font-size: 14px; font-family: inherit; outline: none;
}
.field input:focus, .field select:focus { border-color: #46567a; }
.field input[type="range"] { accent-color: #a8788c; }
.dialog-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.confirm-actions { display: flex; gap: 8px; flex: none; }
.confirm-text { margin: 0; font-size: 14px; color: #b9c3d6; }
.hint { font-size: 12.5px; color: #7d8aa3; }

button.primary {
  background: linear-gradient(135deg, #6d7fa8 0%, #a8788c 100%);
  color: #fff; border: none; border-radius: 10px; padding: 9px 20px; font-size: 14px;
}
button.primary:hover { filter: brightness(1.12); }
button.ghost {
  background: #222a3a; color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 16px; font-size: 13.5px;
}
button.ghost:hover { background: #2b3549; }
a.ghost { color: var(--text); text-decoration: none; }
a.ghost:hover { background: #2b3549; }

/* 设置面板里的行内组合 */
.inline-row { display: flex; gap: 8px; }
.inline-row input {
  flex: 1; background: var(--bg-soft); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font-size: 14px; font-family: inherit; outline: none;
}
.inline-row button { flex: none; }
.account-line, .usage-line { margin: 0; font-size: 12px; color: #66718a; }

.slot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: #1f2634; border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px;
}
.slot-info { font-size: 13px; color: var(--muted); }
.slot-info b { display: block; color: var(--text); font-size: 13.5px; font-weight: 600; margin-bottom: 2px; }
.slot-actions { display: flex; gap: 8px; }
.slot-actions button { padding: 6px 14px; font-size: 13px; }
.slot-actions button:disabled { opacity: 0.35; cursor: not-allowed; }

.undo-head { margin: 20px 0 4px; font-size: 13px; color: var(--text); font-weight: 600; }
.undo-note { margin: 0 0 10px; font-size: 12px; color: var(--muted); }
.undo-list { display: flex; flex-direction: column; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: #2b2434; border: 1px solid #4a3a44; color: #eadfe8;
  padding: 9px 18px; border-radius: 10px; font-size: 13.5px; z-index: 30;
  max-width: 80vw; text-align: center;
}

/* ---------- 地图 ---------- */

.map-hint { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.map-canvas {
  background: #161b26;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.map-svg { display: block; width: 100%; height: auto; }
.map-node { cursor: pointer; }
.map-node circle, .map-node rect, .map-node path { transition: opacity 0.2s; }
.map-node:hover circle:first-of-type { opacity: 0.75; }
.map-node.locked { cursor: not-allowed; }
.map-node.current .map-ping { animation: mapPing 2s ease-out infinite; transform-origin: center; }
@keyframes mapPing {
  0%   { r: 5; opacity: 0.9; }
  100% { r: 8; opacity: 0; }
}

/* ---------- 窄屏 ---------- */

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); height: 100vh; }
  .stage-panel {
    border-right: none; border-bottom: 1px solid var(--line);
    display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px 12px; padding: 12px;
    align-items: center;
  }
  .portrait-wrap { grid-row: span 3; aspect-ratio: 3 / 4; }
  .char-meta h1 { font-size: 17px; }
  .char-meta p { display: none; }
  .affinity-track { margin: 6px 0 8px; }
  .badge { padding: 2px 8px; font-size: 11.5px; }
  .panel-actions { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .panel-actions button { padding: 6px 4px; font-size: 12px; }
  .provider-tag { display: none; }
  .bubble { max-width: 88%; }
  .chat-panel { min-height: 0; }
  .chat-log { padding: 16px 14px 8px; }
  .composer { padding: 10px 14px 14px; gap: 6px; }
  .composer button { padding: 10px 12px; font-size: 13px; letter-spacing: 1px; }
  .composer button.ghost { padding: 10px 12px; }
}

/* ---------- 礼物 ---------- */

.gift-list { display: flex; flex-direction: column; gap: 10px; }
.gift-item {
  display: flex; align-items: center; gap: 12px;
  background: #1f2634; border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px;
}
.gift-info { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.gift-info b { font-size: 14px; font-weight: 600; }
.gift-info span { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.gift-item button { flex: none; padding: 8px 18px; font-size: 13.5px; }

/* ---------- 剧本选择 ---------- */

.script-grid { display: flex; flex-direction: column; gap: 10px; }
.script-card {
  display: flex; align-items: stretch; gap: 14px; text-align: left;
  background: #1f2634; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; cursor: pointer; font-family: inherit; color: var(--text);
  transition: border-color 0.18s, background 0.18s;
}
.script-card:hover { background: #252d3f; }
.script-card.on { border-color: #a8788c; background: #2b2434; }
.script-cover {
  flex: none; width: 96px; aspect-ratio: 16 / 10; border-radius: 8px; overflow: hidden;
  background: #141926; display: flex; align-items: center; justify-content: center;
}
.script-cover img { width: 100%; height: 100%; object-fit: cover; }
.script-cover-empty { font-size: 26px; color: #3b475f; }
.script-text { display: flex; flex-direction: column; gap: 4px; justify-content: center; min-width: 0; }
.script-text b { font-size: 14.5px; font-weight: 600; }
.script-text span { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* 礼物图标 */
.gift-icon {
  flex: none; width: 44px; height: 44px; border-radius: 9px; object-fit: cover;
  background: #141926;
}


/* ---------- CG 插画 ---------- */

.cg-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(8, 10, 15, 0.92);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; backdrop-filter: blur(4px);
  animation: cgIn 0.35s ease;
}
@keyframes cgIn { from { opacity: 0; } to { opacity: 1; } }

.cg-frame {
  margin: 0; max-width: min(880px, 100%); max-height: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.cg-frame img {
  max-width: 100%; max-height: 62vh; object-fit: contain;
  border-radius: 14px; border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
.cg-caption { text-align: center; max-width: 640px; }
.cg-caption b { display: block; font-size: 15px; letter-spacing: 2px; color: var(--accent-soft); margin-bottom: 8px; }
.cg-caption p { margin: 0; font-size: 14.5px; line-height: 1.9; color: #d8dfee; }
.cg-close { padding: 9px 40px; letter-spacing: 3px; }


/* ---------- 信任 / 紧张 ---------- */

.axis-row {
  display: grid; grid-template-columns: 34px 1fr 26px;
  align-items: center; gap: 8px; margin-top: 7px;
}
.axis-label { font-size: 11.5px; color: #7d8aa3; }
.axis-num { font-size: 11.5px; color: #7d8aa3; text-align: right; font-variant-numeric: tabular-nums; }
.axis-track { height: 4px; border-radius: 99px; background: #262e40; overflow: hidden; }
.axis-fill {
  height: 100%; width: 0; border-radius: 99px;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.axis-fill.trust { background: linear-gradient(90deg, #6d8fb8, #9ec9e8); }
.axis-fill.tension { background: linear-gradient(90deg, #8a6a6a, #d98b7a); }
