:root {
  --bg: #0f0e17;
  --surface: #1a1925;
  --surface-2: #232132;
  --text: #e8e6f0;
  --muted: #9b97b3;
  --accent: #f0a35e;      /* 火把暖光 */
  --accent-2: #7f5af0;    /* 魔法紫 */
  --player: #2a2740;
  --danger: #e5484d;
  --radius: 14px;
  --app-h: 100dvh;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

.hidden { display: none !important; }

.screen {
  height: var(--app-h);
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- 登录 ---------- */
#login {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(120% 80% at 50% 0%, #1b1830 0%, var(--bg) 70%);
}
.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  padding: 32px 24px calc(28px + env(safe-area-inset-bottom));
}
.login-card .logo { font-size: 54px; line-height: 1; margin-bottom: 8px; }
.login-card h1 { margin: 6px 0 4px; font-size: 26px; letter-spacing: 2px; }
.login-card .sub { color: var(--muted); margin: 0 0 26px; font-size: 14px; }
#password {
  width: 100%;
  font-size: 16px;
  padding: 14px 16px;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  margin-bottom: 14px;
  outline: none;
}
#password:focus { border-color: var(--accent-2); }
#loginBtn {
  width: 100%;
  font-size: 17px;
  letter-spacing: 4px;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
#loginBtn:active { transform: scale(0.98); }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 12px; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 10px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-2);
  flex: none;
}
.topbar .title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  width: 40px; height: 40px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- 对话区 ---------- */
.transcript {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.msg { max-width: 100%; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg.gm .narrative {
  font-size: 17px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  color: #ece9f5;
  font-family: Georgia, "Songti SC", "SimSun", serif;
}
.msg.gm .narrative.streaming::after {
  content: "▋";
  color: var(--accent);
  margin-left: 1px;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.msg.player {
  align-self: flex-end;
  background: var(--player);
  color: #d9d6ee;
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  font-size: 15px;
  line-height: 1.5;
  max-width: 82%;
  word-break: break-word;
  border: 1px solid #34304d;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 30px;
}
.empty .big { font-size: 46px; margin-bottom: 10px; }
.empty button {
  margin-top: 18px;
  padding: 12px 22px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- 输入区 ---------- */
.composer {
  flex: none;
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
.choices { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.choices:empty { display: none; }
.choice {
  text-align: left;
  padding: 12px 14px;
  border: 1px solid #3a3654;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.choice:active { background: #2c2942; border-color: var(--accent); }
.choice .num { color: var(--accent); font-weight: 700; margin-right: 8px; }

.input-row { display: flex; align-items: flex-end; gap: 8px; }
#input {
  flex: 1;
  font-size: 16px;            /* >=16px 防 iOS 自动放大 */
  line-height: 1.4;
  padding: 11px 14px;
  max-height: 120px;
  border: 1px solid var(--surface-2);
  border-radius: 18px;
  background: var(--bg);
  color: var(--text);
  resize: none;
  outline: none;
  font-family: inherit;
}
#input:focus { border-color: var(--accent-2); }
.send {
  flex: none;
  width: 44px; height: 44px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.send:disabled { opacity: 0.45; }
.send:active:not(:disabled) { transform: scale(0.94); }

/* ---------- 抽屉 ---------- */
.drawer { position: fixed; inset: 0; z-index: 30; }
.drawer-mask { position: absolute; inset: 0; background: rgba(0,0,0,0.55); animation: fade 0.2s; }
.drawer-panel {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: min(86%, 380px);
  background: var(--surface);
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
  overflow-y: auto;
  animation: slideIn 0.22s ease;
  border-right: 1px solid var(--surface-2);
}
@keyframes slideIn { from { transform: translateX(-100%); } to { transform: none; } }

.drawer-panel h2 { font-size: 18px; margin: 4px 0 16px; }
.drawer-panel .section-label { color: var(--muted); font-size: 13px; margin: 18px 0 8px; }

.scenario-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.scenario {
  text-align: left;
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 14px 12px;
  color: var(--text);
  cursor: pointer;
}
.scenario:active { border-color: var(--accent); }
.scenario .emoji { font-size: 26px; }
.scenario .name { font-weight: 600; margin-top: 6px; font-size: 15px; }
.scenario .desc { color: var(--muted); font-size: 12px; margin-top: 3px; line-height: 1.4; }

#customPremise {
  width: 100%; margin-top: 10px; font-size: 16px; padding: 12px;
  border: 1px solid var(--surface-2); border-radius: 12px;
  background: var(--bg); color: var(--text); resize: none; outline: none;
  font-family: inherit;
}

.session-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-radius: 12px; background: var(--surface-2);
  margin-bottom: 8px; cursor: pointer;
}
.session-item:active { background: #2c2942; }
.session-item .meta { flex: 1; min-width: 0; }
.session-item .s-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .s-time { color: var(--muted); font-size: 12px; margin-top: 2px; }
.session-item .del {
  flex: none; border: none; background: transparent; color: var(--muted);
  font-size: 16px; padding: 6px; cursor: pointer;
}
.session-item .del:active { color: var(--danger); }
.empty-list { color: var(--muted); font-size: 14px; padding: 10px 2px; }
