:root {
  --bg: #0a0c11;
  --bg-2: #0e1118;
  --panel: rgba(255, 255, 255, 0.035);
  --panel-2: rgba(255, 255, 255, 0.06);
  --border: rgba(212, 180, 120, 0.16);
  --gold: #e8c987;
  --gold-2: #b8935a;
  --gold-soft: rgba(232, 201, 135, 0.12);
  --text: #ece9e2;
  --muted: #8b8a93;
  --danger: #e0795f;
  --radius: 14px;
  --serif: "Noto Serif SC", "Songti SC", serif;
  --sans: "Noto Sans SC", "PingFang SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(232, 201, 135, 0.08), transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, rgba(120, 140, 200, 0.06), transparent 55%),
    var(--bg);
  font-weight: 300;
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------- 登录/注册 ---------- */
.auth-gate {
  position: fixed; inset: 0; display: grid; place-items: center;
  background:
    radial-gradient(900px 500px at 50% -20%, rgba(232, 201, 135, 0.10), transparent 60%),
    linear-gradient(180deg, #0a0c11, #0c0f16);
  overflow: hidden;
}
.auth-glow {
  position: absolute; width: 600px; height: 600px; border-radius: 50%;
  background: radial-gradient(circle, rgba(232, 201, 135, 0.18), transparent 70%);
  filter: blur(40px); animation: float 8s ease-in-out infinite;
}
@keyframes float { 0%,100%{ transform: translateY(-10px);} 50%{ transform: translateY(20px);} }
.auth-card {
  position: relative; width: 380px; padding: 40px 34px 30px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 20px; backdrop-filter: blur(18px);
  box-shadow: 0 30px 80px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.05);
}
.brand { font-family: var(--serif); font-size: 40px; font-weight: 700; letter-spacing: 6px;
  background: linear-gradient(135deg, #fff, var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; text-align: center; }
.brand-en { display: block; font-family: var(--serif); font-size: 13px; letter-spacing: 2px; color: var(--gold-2); margin-top: 8px; font-weight: 500; line-height: 1.6; opacity: .9; }
.brand.small { font-size: 22px; letter-spacing: 3px; text-align: left; margin-left: 50px; }
.tagline { text-align: center; color: var(--muted); font-size: 13px; letter-spacing: 2px; margin: 10px 0 26px; }
.tabs { display: flex; gap: 8px; background: rgba(0,0,0,0.25); padding: 5px; border-radius: 12px; margin-bottom: 22px; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 10px; border-radius: 9px; font-size: 14px; transition: .25s; }
.tab.active { background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #1a1408; font-weight: 500; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  background: rgba(0,0,0,0.3); border: 1px solid var(--border); color: var(--text);
  padding: 13px 15px; border-radius: 11px; font-size: 14px; outline: none; transition: .2s;
}
.auth-form input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.hint { color: var(--muted); font-size: 12px; text-align: center; margin: 4px 0 0; }
.auth-msg { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; margin: 10px 0 0; }

.btn-gold {
  border: 0; padding: 13px; border-radius: 11px; font-size: 15px; font-weight: 500; color: #1a1408;
  background: linear-gradient(135deg, var(--gold), var(--gold-2));
  box-shadow: 0 10px 30px rgba(232, 201, 135, 0.25); transition: .25s; letter-spacing: 2px;
}
.btn-gold:hover { transform: translateY(-1px); box-shadow: 0 14px 38px rgba(232, 201, 135, 0.4); }
.btn-gold:disabled { opacity: .6; cursor: default; transform: none; }

.ai-actions { display: flex; gap: 10px; margin-top: 10px; }
.ai-actions button { flex: 1; }
.ai-clear {
  border: 0; padding: 13px; border-radius: 11px; font-size: 15px; font-weight: 500;
  color: #fff; background: #b23b3b; cursor: pointer; transition: .25s; letter-spacing: 2px;
}
.ai-clear:hover { background: #d24a4a; box-shadow: 0 10px 30px rgba(178, 59, 59, 0.35); }
.ai-chat {
  border: 0; padding: 13px; border-radius: 11px; font-size: 15px; font-weight: 500;
  color: #fff; background: #5c8d6b; cursor: pointer; transition: .25s; letter-spacing: 2px;
}
.ai-chat:hover { background: #6da37d; box-shadow: 0 10px 30px rgba(92, 141, 107, 0.35); }
.ai-chat:disabled { opacity: .6; cursor: default; transform: none; }

.ai-input-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.ai-input-hint { color: var(--muted); font-size: 12px; letter-spacing: 1px; }
.ai-reset {
  background: none; border: 1px solid var(--border); color: var(--muted);
  font-size: 12px; padding: 3px 12px; border-radius: 7px; cursor: pointer; transition: .2s;
}
.ai-reset:hover { color: #ff6b6b; border-color: #ff6b6b; }

/* ---------- 主应用 ---------- */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; flex-wrap: nowrap; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: rgba(10,12,17,0.6); backdrop-filter: blur(10px);
  overflow: hidden;
}
.doc-title {
  flex: 1 1 auto; min-width: 120px; max-width: 100%; background: transparent; border: 0; border-bottom: 1px solid transparent;
  color: var(--text); font-family: var(--serif); font-size: 18px; font-weight: 600; padding: 6px 4px; outline: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-title[readonly] { cursor: default; }
.doc-label { background: rgba(255, 77, 79, 0.15); color: #ff6b6b; border: 1px solid #ff6b6b; padding: 4px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; margin-left: 150px; }
.top-actions { margin-left: auto; display: flex; align-items: center; flex-wrap: nowrap; gap: 6px; }
.model-select {
  background: rgba(0,0,0,0.3); border: 1px solid var(--border); color: var(--text);
  padding: 6px 10px; border-radius: 8px; font-size: 14px; outline: none; min-width: 150px;
}
.model-select:focus { border-color: var(--gold); }
.ghost-btn { background: transparent; border: 1px solid var(--border); color: var(--gold); padding: 6px 12px; border-radius: 8px; font-size: 14px; transition: .2s; }
.ghost-btn:hover { background: var(--gold-soft); }
.user-chip { color: var(--muted); font-size: 14px; padding-left: 8px; border-left: 1px solid var(--border); white-space: nowrap; }
.user-chip b { color: var(--text); font-weight: 500; }
.user-chip a { color: var(--gold-2); margin-left: 6px; cursor: pointer; }
.logout-btn { color: #ff6b6b !important; font-size: 15px; font-weight: 600; }
.logout-btn:hover { color: #ff4c4c !important; text-decoration: underline; }
.credit-chip { background: var(--gold-soft); color: var(--gold); padding: 2px 8px; border-radius: 20px; font-size: 13px; margin-left: 6px; }
.credit-chip.zero { background: rgba(180, 60, 60, 0.2); color: #e08a8a; }

.layout { flex: 1; display: grid; grid-template-columns: 240px 1fr 340px; min-height: 0; }
.sidebar { border-right: 1px solid var(--border); padding: 18px 14px; background: rgba(0,0,0,0.18); overflow-y: auto; }
.side-btn { width: 100%; border: 1px dashed var(--border); background: transparent; color: var(--gold); padding: 12px; border-radius: 11px; font-size: 14px; transition: .2s; }
.side-btn:hover { background: var(--gold-soft); }
.side-label { color: var(--muted); font-size: 12px; letter-spacing: 2px; margin: 20px 0 10px; }
.project-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.project-list li { padding: 11px 12px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; transition: .2s; }
.project-list li:hover { background: var(--panel); }
.project-list li.active { background: var(--gold-soft); border-color: var(--border); }
.project-list .p-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.project-list .p-title { flex: 1; min-width: 0; font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-list .p-title:hover { color: var(--gold); }
.project-list .p-actions { display: flex; gap: 4px; opacity: 0; transition: .2s; }
.project-list li:hover .p-actions { opacity: 1; }
.project-list .p-action { background: transparent; border: 0; color: var(--muted); font-size: 13px; cursor: pointer; padding: 2px 5px; border-radius: 5px; line-height: 1; }
.project-list .p-action:hover { background: var(--gold-soft); color: var(--gold); }
.project-list .p-title-input { width: 100%; font-size: 14px; color: var(--text); background: var(--bg); border: 1px solid var(--gold); border-radius: 6px; padding: 4px 8px; outline: none; }
.project-list .p-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }

.editor-wrap { position: relative; display: flex; flex-direction: column; min-height: 0; padding: 0 28px; }
.editor-toolbar { display: flex; align-items: center; gap: 8px; padding: 16px 0 12px; }
.tool { border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 8px 15px; border-radius: 9px; font-size: 13px; transition: .2s; }
.tool:hover { background: var(--gold-soft); color: var(--gold); border-color: var(--gold); }
.tool:disabled { opacity: .4; cursor: not-allowed; background: var(--panel); color: var(--muted); border-color: var(--border); }
.spacer { flex: 1; }
.word-count, .save-state { font-size: 12px; color: var(--muted); }
.save-state.saving { color: var(--gold-2); }
.save-state.saved { color: #7fb98a; }
.editor {
  flex: 1; width: 100%; resize: none; border: 0; outline: none; background: transparent;
  color: var(--text); font-family: var(--serif); font-size: 18px; line-height: 2; font-weight: 400;
  padding: 10px 4px 40px;
}
.editor::placeholder { color: #4a4a52; }
.find-bar {
  position: absolute; top: 14px; right: 174px; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 10px; box-shadow: 0 12px 30px rgba(0,0,0,0.45);
}
.find-bar.hidden { display: none; }
.find-input { background: rgba(0,0,0,0.3); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 13px; outline: none; width: 200px; }
.find-input:focus { border-color: var(--gold); }
.find-count { font-size: 12px; color: var(--muted); min-width: 48px; text-align: center; }
.find-count.no-match { color: #ff6b6b; }
.find-nav, .find-close { border: 1px solid var(--border); background: var(--panel-2); color: var(--text); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 14px; transition: .2s; }
.find-nav:hover, .find-close:hover { border-color: var(--gold); color: var(--gold); }

.ai-panel { border-left: 1px solid var(--border); background: rgba(0,0,0,0.2); display: flex; flex-direction: column; min-height: 0; }
.ai-head { padding: 16px 18px; font-family: var(--serif); font-size: 16px; color: var(--gold); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.ai-credits { font-family: var(--sans); font-size: 12px; color: var(--muted); background: var(--gold-soft); padding: 4px 10px; border-radius: 20px; }
.ai-credits.zero { color: #e08a8a; background: rgba(180, 60, 60, 0.2); }
.ai-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.ai-empty { color: var(--muted); font-size: 13px; line-height: 1.8; }
.ai-msg { font-size: 13px; line-height: 1.8; padding: 12px 14px; border-radius: 11px; white-space: pre-wrap; }
.ai-msg.user { background: var(--gold-soft); color: var(--text); align-self: flex-end; max-width: 90%; }
.ai-msg.bot { background: var(--panel-2); border: 1px solid var(--border); }
.ai-msg .insert { display: inline-block; color: var(--gold); font-size: 12px; cursor: pointer; border: 1px solid var(--border); padding: 4px 10px; border-radius: 8px; }
.ai-msg .copy { display: inline-block; color: var(--gold); font-size: 12px; cursor: pointer; border: 1px solid var(--border); padding: 4px 10px; border-radius: 8px; }
.ai-msg .copy:hover { background: var(--gold-soft); }
.ai-msg .copy.copied { color: #7fd18b; border-color: rgba(127, 209, 139, 0.4); background: rgba(127, 209, 139, 0.12); }
.ai-msg-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* 插入位置标记浮层 */
.insert-marker { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); max-width: min(720px, 92vw); background: var(--panel); border: 1px solid var(--gold); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,0.45); padding: 12px 14px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 9999; }
.insert-marker.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.insert-marker-label { font-size: 12px; color: var(--gold); margin-bottom: 6px; letter-spacing: .3px; }
.insert-marker-text { font-size: 13px; line-height: 1.8; max-height: 220px; overflow-y: auto; white-space: pre-wrap; word-break: break-word; color: var(--text); }
.insert-marker-text .ctx { color: #ff5a5a; }
.insert-marker-text .ins { color: var(--gold); background: var(--gold-soft); border-radius: 4px; padding: 0 2px; }
.ai-input { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.ai-input textarea { background: rgba(0,0,0,0.3); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 10px; font-size: 13px; resize: none; height: 64px; outline: none; font-family: var(--sans); }
.ai-input textarea:focus { border-color: var(--gold); }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 200px 1fr; }
  .ai-panel { display: none; }
  .ai-panel.open { display: flex; position: fixed; right: 0; top: 0; bottom: 0; width: 340px; z-index: 20; }
}

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.72); backdrop-filter: blur(4px); }
.modal-card { position: relative; width: 420px; max-width: 90vw; background: linear-gradient(180deg, rgba(20,22,28,0.98), rgba(14,16,22,0.98)); border: 1px solid var(--border); border-radius: 22px; padding: 28px; box-shadow: 0 40px 100px rgba(0,0,0,0.65), inset 0 1px 0 rgba(232,201,135,0.08); }
.modal-head { font-family: var(--serif); font-size: 20px; color: var(--gold); text-align: center; margin-bottom: 22px; letter-spacing: 2px; }
.modal-body { display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: center; gap: 12px; margin-top: 24px; }
.modal-foot .btn-gold, .modal-foot .ghost-btn { padding: 11px 24px; border-radius: 11px; font-size: 14px; }
.redeem-input { width: 100%; background: rgba(0,0,0,0.35); border: 1px solid var(--border); color: var(--text); padding: 14px 16px; border-radius: 12px; font-size: 15px; outline: none; text-align: center; letter-spacing: 1px; }
.redeem-input:focus { border-color: var(--gold); box-shadow: 0 0 0 4px var(--gold-soft); }
.redeem-result { text-align: center; padding: 16px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--border); line-height: 1.8; }
.redeem-result .success { color: #7fb98a; font-weight: 600; }
.redeem-result .fail { color: #e08a8a; font-weight: 600; }
.redeem-detail { color: var(--muted); font-size: 13px; margin-top: 6px; }
.contact-body { align-items: center; }
.contact-qr { width: 200px; height: 200px; display: grid; place-items: center; background: #fff; border-radius: 12px; padding: 12px; overflow: hidden; }
.contact-qr img { max-width: 100%; max-height: 100%; }
.contact-wechat { color: var(--text); font-size: 15px; margin-top: 8px; }
.contact-wechat span { color: var(--gold); font-weight: 600; }

.modal-card.wide { width: 860px; }
.ns-card { width: 460px; max-height: 86vh; overflow-y: auto; }
.ns-body { gap: 12px; }
.ns-field { display: flex; flex-direction: column; gap: 6px; }
.ns-label { font-size: 13px; color: var(--gold); letter-spacing: 0.5px; }
.ns-input, .ns-textarea { width: 100%; background: rgba(0,0,0,0.35); border: 1px solid var(--border); color: var(--text); padding: 11px 13px; border-radius: 11px; font-size: 14px; outline: none; font-family: inherit; resize: vertical; }
.ns-input:focus, .ns-textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 4px var(--gold-soft); }
.ns-textarea { min-height: 64px; line-height: 1.6; }
.tip-content { max-height: 62vh; overflow-y: auto; padding-right: 6px; line-height: 1.75; }
.tip-content h4 { margin: 16px 0 6px; font-size: 15px; color: var(--gold, #e8c987); font-weight: 600; }
.tip-content h4:first-child { margin-top: 0; }
.tip-content p { margin: 0 0 8px; font-size: 13.5px; color: var(--text); }
.tip-content code { padding: 1px 6px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--border); font-size: 12.5px; color: var(--gold, #e8c987); }
.price-list { display: flex; flex-direction: column; gap: 12px; max-height: 62vh; overflow-y: auto; padding-right: 4px; }
.price-header { display: flex; justify-content: space-between; align-items: center; padding: 0 20px 6px; font-size: 13px; color: var(--muted); letter-spacing: 1px; }
.price-item { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--border); }
.price-item .p-info { display: flex; flex-direction: column; }
.price-item .p-name { color: var(--text); font-size: 16px; font-weight: 700; letter-spacing: 0.5px; }
.price-item .p-sale { color: var(--gold); font-weight: 700; font-size: 16px; text-align: right; line-height: 1.6; }
.price-item .p-sale small { color: var(--muted); font-size: 12px; font-weight: 400; }
.usage-list { display: flex; flex-direction: column; gap: 14px; max-height: 64vh; overflow-y: auto; }
.usage-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.usage-summary .u-box { text-align: center; padding: 14px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--border); }
.usage-summary .u-box .u-label { color: var(--muted); font-size: 12px; }
.usage-summary .u-box .u-val { color: var(--gold); font-size: 18px; font-weight: 700; margin-top: 4px; }
.usage-summary .u-box .u-sub { color: var(--muted); font-size: 11px; margin-top: 2px; }
.usage-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.usage-table th, .usage-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: center; }
.usage-table th { color: var(--muted); font-weight: 500; }
.usage-table td { color: var(--text); }
.usage-table .u-model { text-align: left; color: var(--text); font-size: 15px; font-weight: 600; }
.usage-table .u-day { color: #ffd166; }
.usage-table .u-month { color: #4dd0e1; }
.usage-table .u-total { color: #ef83b6; }
.usage-empty { text-align: center; color: var(--muted); padding: 30px; }
