/* ============================================================
   PromptLab Lite — 「暗房」主题
   暖黑底 · 米白文字 · 琥珀橙强调 · 衬线标题 + 等宽标签
   ============================================================ */

:root {
  --bg: #141110;
  --bg-raise: #1d1815;
  --bg-raise-2: #262019;
  --ink: #eae2d3;
  --ink-dim: #9b9184;
  --ink-faint: #6b6257;
  --line: rgba(234, 226, 211, 0.13);
  --line-soft: rgba(234, 226, 211, 0.07);
  --amber: #e08a2e;
  --amber-hot: #f0a04b;
  --amber-deep: #8a4f14;
  --danger: #cf5f4e;
  --serif: Georgia, 'Times New Roman', 'Songti SC', 'SimSun', serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas, Menlo, monospace;
  --sans: -apple-system, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  --radius: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { color-scheme: dark; }

body {
  background: var(--bg);
  background-image: radial-gradient(1100px 500px at 70% -10%, rgba(224, 138, 46, 0.07), transparent 60%);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--amber-deep); color: var(--ink); }

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line-soft);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
}

.wordmark-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 14px rgba(224, 138, 46, 0.8);
}

.wordmark-text {
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: 0.4px;
}
.wordmark-text em { color: var(--amber); font-style: italic; }

.topnav { display: flex; gap: 4px; }

.topnav a {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-decoration: none;
  color: var(--ink-dim);
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.topnav a:hover { color: var(--ink); }
.topnav a.active { color: var(--amber-hot); border-color: var(--line); }

main { max-width: 1060px; margin: 0 auto; padding: 36px 32px 80px; }

/* ---------- 通用 ---------- */

.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 26px; }

.page-title { font-family: var(--serif); font-size: 30px; font-weight: 400; letter-spacing: 0.5px; }

.page-kicker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--amber);
  text-transform: uppercase;
  display: block;
  margin-bottom: 6px;
}

.btn {
  font-family: var(--mono);
  font-size: 12.5px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--bg-raise-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.btn:hover { border-color: var(--amber-deep); background: #2d251c; }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--amber-deep); border-color: var(--amber-deep); color: #fff2e0; }
.btn-primary:hover { background: #a05f1c; border-color: var(--amber); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-dim); }
.btn-ghost:hover { color: var(--ink); background: var(--bg-raise); border-color: var(--line-soft); }

.btn-danger:hover { border-color: var(--danger); color: var(--danger); }

.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 56px 24px;
  text-align: center;
  color: var(--ink-dim);
  font-size: 14px;
}
.empty .btn { margin-top: 16px; }

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-raise-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--amber);
  color: var(--ink);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13.5px;
  z-index: 1000;
  animation: rise 0.25s ease;
}
.toast.error { border-left-color: var(--danger); }

@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- 画廊 ---------- */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 22px;
}

.card {
  position: relative;
  background: var(--bg-raise);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s, box-shadow 0.18s;
  animation: card-in 0.4s ease backwards;
}
.card:nth-child(2) { animation-delay: 0.05s; }
.card:nth-child(3) { animation-delay: 0.1s; }
.card:nth-child(4) { animation-delay: 0.15s; }
.card:nth-child(5) { animation-delay: 0.2s; }
.card:nth-child(n + 6) { animation-delay: 0.25s; }

@keyframes card-in { from { opacity: 0; transform: translateY(10px); } }

.card:hover {
  transform: translateY(-3px);
  border-color: var(--amber-deep);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
}

.card-cover {
  aspect-ratio: 4 / 3;
  width: 100%;
  object-fit: cover;
  display: block;
  filter: saturate(0.92);
}

.card-cover-fallback {
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 52px;
  color: rgba(234, 226, 211, 0.82);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

.card-body { padding: 13px 15px 15px; border-top: 1px solid var(--line-soft); }

.card-name {
  font-family: var(--serif);
  font-size: 16.5px;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-model {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--amber);
}
.card-model.unbound { color: var(--danger); }

.card-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.card:hover .card-actions { opacity: 1; }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: rgba(20, 17, 16, 0.82);
  backdrop-filter: blur(4px);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.icon-btn:hover { border-color: var(--amber); color: var(--amber-hot); }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.card-new {
  border: 1px dashed var(--line);
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 240px;
  color: var(--ink-dim);
  font-size: 14px;
}
.card-new:hover { color: var(--amber-hot); border-color: var(--amber-deep); box-shadow: none; }
.card-new .plus { font-size: 34px; font-weight: 200; line-height: 1; }

/* ---------- 表单 ---------- */

.form-panel {
  background: var(--bg-raise);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 640px;
}

.field { margin-bottom: 20px; }

.field label {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 7px;
}
.field label .opt { color: var(--ink-faint); text-transform: none; letter-spacing: 0.04em; }

.field input[type='text'],
.field input[type='password'],
.field input[type='email'],
.field input[type='number'],
.field select,
.field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
}
.field textarea { font-family: var(--mono); font-size: 13px; line-height: 1.55; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--amber-deep); }
.field input::placeholder, .field textarea::placeholder { color: var(--ink-faint); }
.field input[type='number'] { appearance: textfield; -moz-appearance: textfield; }
.field input[type='number']::-webkit-outer-spin-button,
.field input[type='number']::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.form-actions { display: flex; gap: 10px; margin-top: 26px; }

.cover-picker { display: flex; align-items: center; gap: 14px; }
.cover-preview {
  width: 132px;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  border: 1px solid var(--line);
  object-fit: cover;
  background: var(--bg);
}
.cover-preview.blank {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-faint);
  font-size: 12px;
}

/* ---------- 模型端点列表 ---------- */

.model-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 30px; }

.model-row {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--bg-raise);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 15px 20px;
}

.model-row .m-name { font-family: var(--serif); font-size: 16px; min-width: 130px; }
.model-row .m-meta { flex: 1; font-family: var(--mono); font-size: 12px; color: var(--ink-dim); overflow: hidden; }
.model-row .m-meta .m-id { color: var(--amber); }
.model-row .m-actions { display: flex; gap: 8px; }

/* ---------- 聊天 ---------- */

.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 150px); max-width: 820px; margin: 0 auto; }

.chat-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.chat-cover { width: 52px; height: 52px; border-radius: 9px; object-fit: cover; border: 1px solid var(--line); }
.chat-cover-fallback {
  width: 52px; height: 52px; border-radius: 9px; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 22px;
}

.chat-title { flex: 1; }
.chat-title h2 { font-family: var(--serif); font-size: 19px; font-weight: 400; }
.chat-title .sub { font-family: var(--mono); font-size: 11px; color: var(--amber); letter-spacing: 0.08em; }

.chat-scroll { flex: 1; overflow-y: auto; padding: 24px 4px; display: flex; flex-direction: column; gap: 18px; }

.msg { display: flex; flex-direction: column; max-width: 82%; animation: rise2 0.2s ease; }
@keyframes rise2 { from { opacity: 0; transform: translateY(6px); } }

.msg .who {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 5px;
}

.msg .bubble {
  padding: 11px 15px;
  border-radius: 12px;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.user .bubble { background: var(--amber-deep); color: #fdf2e2; border-bottom-right-radius: 4px; }

.msg.assistant { align-self: flex-start; }
.msg.assistant .bubble {
  background: var(--bg-raise);
  border: 1px solid var(--line-soft);
  border-bottom-left-radius: 4px;
}
.msg.assistant.preset .who::after { content: ' · 预置'; color: var(--amber); }

.msg .think {
  max-width: 100%;
  margin-bottom: 6px;
  border: 1px dashed var(--line-soft);
  border-radius: 10px;
  background: transparent;
  font-size: 13px;
  color: var(--ink-dim);
}
.msg .think summary {
  cursor: pointer;
  padding: 6px 12px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-faint);
  user-select: none;
  list-style: none;
}
.msg .think summary::-webkit-details-marker { display: none; }
.msg .think summary::before { content: '▸ '; }
.msg .think[open] summary::before { content: '▾ '; }
.msg .think summary:hover { color: var(--ink-dim); }
.msg .think .think-body {
  padding: 0 12px 10px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
  line-height: 1.55;
}

.msg.error .bubble { border-color: var(--danger); color: var(--danger); background: transparent; }

.cursor-blink { display: inline-block; width: 8px; height: 15px; background: var(--amber); vertical-align: -2px; margin-left: 2px; animation: blink 0.9s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.chat-inputbar { display: flex; gap: 10px; padding-top: 16px; border-top: 1px solid var(--line-soft); }

.chat-inputbar textarea {
  flex: 1;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14.5px;
  padding: 11px 14px;
  resize: none;
  outline: none;
  max-height: 160px;
}
.chat-inputbar textarea:focus { border-color: var(--amber-deep); }

@media (max-width: 640px) {
  main { padding: 20px 16px 60px; }
  .topbar { padding: 14px 16px; }
  .model-row { flex-wrap: wrap; }
  .chat-wrap { height: calc(100vh - 130px); }
}

/* ---------- 顶栏用户区 / 登录页 ---------- */

.topnav[hidden] { display: none; }
.topnav-user {
  margin-left: 14px;
  padding-left: 14px;
  border-left: 1px solid var(--line-soft);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-dim);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  align-self: center;
}
.topnav #logout { padding: 6px 10px; font-size: 13px; }

.auth-wrap { max-width: 400px; margin: 8vh auto 0; }
.auth-wrap .page-head { margin-bottom: 18px; }
.auth-wrap .form-panel { margin: 0; }
.auth-switch { margin-top: 18px; font-size: 13px; color: var(--ink-dim); text-align: center; }
.auth-switch a { color: var(--amber); cursor: pointer; }
.auth-switch a:hover { color: var(--amber-hot); }
.auth-note { font-size: 12px; color: var(--ink-faint); margin-top: 22px; line-height: 1.6; text-align: center; }

@media (max-width: 640px) {
  .topnav-user { display: none; }
}
