/* ===== 剧本家 Web CSS ===== */
:root {
  --bg: #0f0f1a;
  --surface: rgba(255,255,255,0.03);
  --border: rgba(255,255,255,0.06);
  --text: #e8e0f0;
  --text-dim: #a098c0;
  --muted: #6a6880;
  --accent: #a78bfa;
  --accent2: #f472b6;
  --red: #f87171;
  --green: #34d399;
  --radius: 12px;
  --grad: linear-gradient(135deg, #a78bfa, #f472b6);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --max-w: 640px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text); background: var(--bg);
  min-height: 100dvh; line-height: 1.6; font-size: 15px;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* Layout */
.app-shell { max-width: var(--max-w); margin: 0 auto; padding: 0 16px 24px; }

/* Header */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; margin: 12px 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 100px;
  position: sticky; top: 12px; z-index: 50;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.header-brand { font-size: 17px; font-weight: 800; white-space: nowrap; }
.header-nav { display: none; }
.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.user-name { font-size: 13px; font-weight: 600; }
.user-pts { font-size: 11px; color: var(--accent); background: rgba(167,139,250,0.12); padding: 3px 10px; border-radius: 100px; }

/* Bottom nav bar (mobile) */
.mobile-nav {
  display: flex; position: fixed; bottom: 0; left: 0; right: 0;
  background: rgba(15,15,26,0.95); backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border); z-index: 50; padding: 4px 0;
  padding-bottom: env(safe-area-inset-bottom, 4px);
}
.mobile-nav a {
  flex: 1; padding: 6px 4px; text-align: center;
  font-size: 11px; color: var(--text-dim); text-decoration: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.mobile-nav a .nav-icon { font-size: 18px; }
.mobile-nav a.active { color: var(--accent); }

/* Page */
.page-header { margin: 20px 0 16px; }
.page-title { font-size: 24px; font-weight: 800; }
.page-subtitle { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* Cards */
.card, .form-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}

/* Input */
.input {
  background: rgba(255,255,255,0.06); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 12px 14px; color: var(--text);
  font-size: 15px; font-family: inherit; width: 100%; outline: none;
  -webkit-appearance: none;
}
.input:focus { border-color: var(--accent); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 10px 20px; border: 1px solid var(--border); border-radius: 100px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  background: var(--surface); color: var(--text); font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--grad); color: #fff; border: none; }
.btn-primary:disabled { opacity: 0.4; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-full { width: 100%; justify-content: center; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }

/* Chips */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 9px 16px; border-radius: 100px;
  background: var(--surface); border: 1.5px solid var(--border);
  font-size: 13px; cursor: pointer; -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
.chip.active { border-color: var(--accent); background: rgba(167,139,250,0.12); color: var(--accent); }

/* Mode */
.mode-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-card {
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 16px; text-align: center; cursor: pointer; -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
.mode-card.selected { border-color: var(--accent); background: rgba(167,139,250,0.08); }
.mode-ico { font-size: 28px; margin-bottom: 6px; }
.mode-name { font-size: 14px; font-weight: 700; }
.mode-desc { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Genre grid */
.genre-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; grid-auto-rows: 1fr; }
.genre-card {
  border: 2px solid var(--border); border-radius: var(--radius); overflow: hidden;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  display: flex; flex-direction: column;
}
.genre-card.selected { border-color: var(--accent); }
.genre-cover {
  padding: 12px; min-height: 90px; display: flex; flex-direction: column;
  flex: 1;
}
.genre-icon { font-size: 24px; }
.genre-name { font-size: 14px; font-weight: 700; color: #fff; margin-top: 4px; }
.genre-desc { font-size: 11px; color: rgba(255,255,255,0.65); margin-top: auto; line-height: 1.3; padding-top: 4px; }
.genre-hot { position: absolute; top: 6px; right: 6px; font-size: 10px; }

/* NPC */
.npc-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.npc-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; display: flex; align-items: center; gap: 8px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
.npc-card:active { background: rgba(255,255,255,0.08); }
.npc-avatar { font-size: 18px; }
.npc-name { font-size: 13px; font-weight: 600; }
.npc-name.is-custom { color: var(--accent); }
.npc-arch { font-size: 11px; color: var(--muted); }
.npc-tags { display: flex; gap: 4px; margin-top: 2px; }
.npc-tag {
  font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: rgba(255,255,255,0.06); color: var(--text-dim);
}

/* Form labels */
.form-label { font-size: 12px; font-weight: 700; color: var(--text-dim); letter-spacing: 0.5px; margin-bottom: 10px; text-transform: uppercase; }
.form-hint { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.form-label-sm { font-size: 10px; margin-top: 14px; }

/* ===== Play ===== */
.play-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 8px; font-size: 13px;
}
.play-badge { padding: 3px 10px; border-radius: 100px; background: var(--grad); color: #fff; font-size: 11px; font-weight: 700; }
.play-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 8px; }
.play-msgs {
  flex: 1; overflow-y: auto; padding: 4px 0; display: flex;
  flex-direction: column; gap: 8px; margin-bottom: 8px;
  min-height: 40vh; max-height: 55vh;
}
.msg {
  padding: 10px 14px; border-radius: 14px; max-width: 90%; line-height: 1.6; font-size: 14px;
  animation: msgIn 0.2s var(--ease);
}
@keyframes msgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.msg-sys { background: rgba(167,139,250,0.12); border: 1px solid rgba(167,139,250,0.18); align-self: flex-start; }
.msg-nar { background: var(--surface); border: 1px solid var(--border); align-self: center; max-width: 95%; font-size: 13px; color: var(--text-dim); }
.msg-trn { background: rgba(251,191,36,0.08); border: 1px solid rgba(251,191,36,0.12); align-self: flex-start; }
.msg-npc { background: rgba(255,255,255,0.03); border: 1px solid var(--border); align-self: flex-start; }
.msg-npc b { color: var(--accent); }
.msg-me { background: var(--grad); color: #fff; align-self: flex-end; }
.msg-cwd { background: rgba(34,211,238,0.08); border: 1px solid rgba(34,211,238,0.12); align-self: flex-start; font-size: 13px; }
.msg-sep { text-align: center; color: var(--muted); font-size: 11px; padding: 4px 0; }
.voice-tag {
  display: inline-block; padding: 2px 8px; border-radius: 100px;
  background: rgba(167,139,250,0.1); font-size: 10px; color: var(--accent);
  cursor: pointer; margin-top: 4px;
}

/* Options */
.play-opts { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.opt-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
.opt-card:active { border-color: var(--accent); }
.opt-id {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  background: var(--grad); color: #fff; display: flex;
  align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
}
.opt-label { font-size: 14px; font-weight: 600; }

/* Input bar */
.play-bar { padding-top: 8px; border-top: 1px solid var(--border); }
.play-input { display: flex; gap: 8px; margin-bottom: 6px; }
.play-input input { flex: 1; border-radius: 100px !important; }
.btn-send {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  background: var(--grad); border: none; color: #fff; font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.btn-send:disabled { opacity: 0.3; }
.play-qb { display: flex; gap: 6px; flex-wrap: wrap; }

/* Panel */
.panel-head { font-size: 14px; font-weight: 700; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; }
.panel-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.panel-tab {
  flex: 1; padding: 6px 10px; text-align: center; border-radius: 8px;
  font-size: 12px; font-weight: 600; cursor: pointer; color: var(--text-dim);
  background: rgba(255,255,255,0.04);
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
.panel-tab.active { background: var(--grad); color: #fff; }
.attr-row { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
.attr-num { color: var(--muted); }
.bar { height: 4px; background: rgba(255,255,255,0.06); border-radius: 2px; margin-bottom: 10px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--grad); border-radius: 2px; }
.inv-item { padding: 8px 12px; background: rgba(255,255,255,0.04); border-radius: 8px; margin-bottom: 4px; font-size: 13px; }

/* Toggle switch */
.toggle {
  width: 44px; height: 24px; border-radius: 12px; flex-shrink: 0;
  background: rgba(255,255,255,0.1); position: relative;
  transition: background 0.2s;
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: left 0.2s;
}
.toggle.on::after { left: 22px; }

/* Stories */
.story-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.story-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.story-cover { height: 80px; display: flex; align-items: flex-end; padding: 14px; }
.story-cover-title { font-size: 15px; font-weight: 700; color: #fff; }
.story-meta { padding: 12px 14px; display: flex; justify-content: space-between; font-size: 12px; }
.story-actions { padding: 0 14px 14px; display: flex; gap: 6px; }

/* VIP */
.pt-card {
  background: linear-gradient(135deg, rgba(167,139,250,0.15), rgba(244,114,182,0.08));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; margin-bottom: 16px; text-align: center;
}
.pt-label { font-size: 12px; color: var(--text-dim); letter-spacing: 1px; margin-bottom: 6px; }
.pt-val { font-size: 44px; font-weight: 800; }
.recharge-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.rc-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; text-align: center; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.rc-card:active { border-color: var(--accent); }
.rc-pts { font-size: 20px; font-weight: 800; color: var(--accent); }
.rc-price { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* Table */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { padding: 8px 10px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 11px; text-align: left; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.tbl-empty { text-align: center; padding: 24px !important; color: var(--muted); }

/* Pager */
.pager { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 14px; }
.pager span { font-size: 12px; color: var(--text-dim); }
.pager button { padding: 6px 14px; border-radius: 100px; font-size: 12px; }

/* Login */
.login-box {
  max-width: 380px; margin: 60px auto; padding: 36px 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  text-align: center;
}
.login-logo {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 18px;
  background: var(--grad); display: flex; align-items: center; justify-content: center;
  font-size: 36px;
}
.login-title { font-size: 24px; font-weight: 800; margin-bottom: 4px; }
.login-desc { color: var(--muted); margin-bottom: 24px; font-size: 13px; }
.login-hint { font-size: 11px; color: var(--muted); margin-top: 12px; }
.login-hint a { color: var(--accent); text-decoration: none; font-weight: 600; }

/* Modal */
#modal { position: fixed; inset: 0; z-index: 1000; display: none; pointer-events: none; }
#modal:has(.modal-overlay) { display: block; pointer-events: auto; }
.modal-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto;
}
.modal-box {
  background: #1a1830; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; width: 92vw; max-width: 400px;
  max-height: 85vh; overflow-y: auto;
}
.modal-box h3 { font-size: 16px; margin-bottom: 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* Toast */
#toasts { position: fixed; top: 20px; right: 16px; left: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { padding: 10px 18px; border-radius: var(--radius); font-size: 13px; font-weight: 600; color: #fff; background: rgba(52,211,153,0.9); backdrop-filter: blur(8px); }
.toast-err { background: rgba(248,113,113,0.9); }

/* Empty / Loading */
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty-icon { font-size: 36px; opacity: 0.4; margin-bottom: 8px; display: block; }
.loading { text-align: center; padding: 24px; color: var(--muted); }

/* Loader */
#loadingOverlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 9998; justify-content: center; align-items: center; }
#loadingOverlay.show { display: flex; }
#loadingOverlay .spinner { width: 32px; height: 32px; border: 3px solid rgba(167,139,250,0.2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Mobile bottom spacing */
body { padding-bottom: 60px; }

/* ===== Desktop (>= 768px) ===== */
@media (min-width: 768px) {
  :root { --max-w: 1100px; }
  body { padding-bottom: 0; }
  .mobile-nav { display: none; }
  .header-nav { display: flex; gap: 2px; }
  .header-nav a {
    padding: 7px 16px; border-radius: 100px;
    font-size: 13px; color: var(--text-dim); text-decoration: none; font-weight: 500;
  }
  .header-nav a.active { color: #fff; background: var(--grad); }
  .genre-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .genre-cover { min-height: 120px; }
  .create-layout { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }
  .create-preview {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; position: sticky; top: 80px;
  }
  .story-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .play-stage { display: grid; grid-template-columns: 1fr 280px; gap: 12px; }
  .npc-grid { grid-template-columns: repeat(2, 1fr); }
}
