:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6e9f0;
  --text: #1b2333;
  --muted: #6b7488;
  --primary: #3b4ce0;
  --primary-dark: #2c39b8;
  --primary-soft: #eef0fe;
  --success: #1aa672;
  --warn: #e0a106;
  --danger: #d8453b;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 6px 24px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 40px rgba(16,24,40,.12);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--primary); }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 70% -10%, #e9ecff 0%, transparent 60%),
              radial-gradient(900px 500px at 0% 110%, #e6fbf4 0%, transparent 55%), var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 18px;
  box-shadow: var(--shadow-lg); padding: 36px 32px; border: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.brand-logo {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #6b78f0); color: #fff; font-weight: 800; font-size: 17px;
}
.brand h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.auth-card h2 { font-size: 20px; margin: 24px 0 4px; }
.auth-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }

/* ---------- User picker ---------- */
.pick-list { display: grid; gap: 8px; max-height: 58vh; overflow-y: auto; padding-right: 2px; }
.pick-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 15px; font-weight: 600; color: var(--text);
  transition: border-color .15s, background .15s, transform .05s;
}
.pick-item:hover { border-color: var(--primary); background: var(--primary-soft); }
.pick-item:active { transform: translateY(1px); }
.pick-item:disabled { opacity: .55; }
.pick-avatar {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #6b78f0); color: #fff; font-size: 14px; font-weight: 700;
}
.pick-name { flex: 1; }

label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: #41495c; }
input, textarea, select {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14.5px; color: var(--text); background: var(--surface); transition: border .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { resize: vertical; min-height: 70px; line-height: 1.55; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 14.5px; font-weight: 600; background: var(--primary); color: #fff; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--primary); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b8362d; }

.draft-banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between;
  background: #fff8e6; border: 1px solid #f0dca8; color: #7a5c05;
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13.5px; margin-bottom: 16px;
}
.draft-banner .btn { flex: 0 0 auto; }

.form-msg { font-size: 13px; margin-top: 14px; min-height: 18px; }
.form-msg.error { color: var(--danger); }
.form-msg.ok { color: var(--success); }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- App shell ---------- */
.app { display: none; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 18px;
  padding: 12px 24px;
}
.topbar .brand { margin: 0; }
.topbar .brand h1 { font-size: 15.5px; }
.topbar .brand p { display: none; }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav button {
  background: transparent; border: none; padding: 9px 14px; border-radius: 9px; font-size: 14px;
  color: var(--muted); font-weight: 600;
}
.nav button.active { background: var(--primary-soft); color: var(--primary); }
.nav button:hover:not(.active) { background: var(--surface-2); color: var(--text); }
.spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.user-meta strong { display: block; font-size: 13.5px; }
.user-meta span { color: var(--muted); font-size: 12px; }

.container { max-width: 1120px; margin: 0 auto; padding: 28px 24px 60px; }
.container.full { max-width: 100%; padding-left: 32px; padding-right: 32px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h2 { font-size: 22px; margin: 0 0 4px; }
.page-head p { margin: 0; color: var(--muted); font-size: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 860px) { .cols-2, .cols-3 { grid-template-columns: 1fr; } }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 27px; font-weight: 800; margin-top: 4px; letter-spacing: -.5px; }
.stat .delta { font-size: 12.5px; font-weight: 600; margin-top: 2px; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }
.delta.flat { color: var(--muted); }

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 14px; }
.tl-item { border-left: 2px solid var(--border); padding: 0 0 4px 16px; position: relative; }
.tl-item::before {
  content: ""; position: absolute; left: -5px; top: 5px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary);
}
.tl-period { font-size: 12.5px; font-weight: 700; color: var(--primary); }
.tl-block { margin-top: 6px; }
.tl-block .tag { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.tl-block p { margin: 2px 0 8px; font-size: 13.5px; white-space: pre-wrap; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
tbody tr:hover { background: var(--surface-2); }
.score-pill {
  display: inline-block; min-width: 26px; text-align: center; padding: 2px 7px; border-radius: 7px;
  font-weight: 700; font-size: 12.5px;
}
.muted-cell { color: var(--muted); font-style: italic; }

/* Entry form */
.score-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px dashed var(--border); }
.score-row .meta strong { font-size: 14px; }
.score-row .meta span { display: block; font-size: 12px; color: var(--muted); }
.range-wrap { display: flex; align-items: center; gap: 12px; min-width: 230px; }
.range-wrap input[type=range] { width: 150px; accent-color: var(--primary); }
.range-val { width: 40px; text-align: center; font-weight: 800; font-size: 16px; }
.period-bar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 8px; }
.period-bar > div { flex: 0 0 auto; }
.period-bar label { margin: 0 0 6px; }
.period-bar select { min-width: 120px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1b2333; color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow-lg); opacity: 0; transition: all .25s; z-index: 60; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; background: var(--primary-soft); color: var(--primary); }
.badge.admin { background: #fff2d6; color: #946100; }
.badge.gray { background: var(--surface-2); color: var(--muted); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 440px; padding: 26px; }
.modal h3 { margin: 0 0 16px; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

.chart-box { position: relative; height: 300px; }
.legend-toggles { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.legend-toggles button { font-size: 12px; padding: 5px 11px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-weight: 600; }
.legend-toggles button.on { color: #fff; border-color: transparent; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 14px; }
.section-gap { margin-top: 18px; }

/* card head with actions */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-actions select { min-width: 130px; }
.entry-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* birthdays */
.bday-card { background: linear-gradient(180deg, #fff 0%, #fffaf2 100%); }
.bday-list { display: flex; flex-wrap: wrap; gap: 10px; }
.bday-item {
  display: flex; align-items: center; gap: 8px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 7px 14px; font-size: 13.5px; box-shadow: var(--shadow);
}
.bday-item span { color: var(--muted); font-size: 12.5px; }
.badge.bday-today { background: #ffe2e0; color: #b8362d; }
.badge.bday-soon { background: #fff0d6; color: #946100; }

/* overview table column sizing */
.ov-table .name-cell { white-space: nowrap; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.ov-table tbody tr:hover .name-cell { background: var(--surface-2); }
.ov-table .narr { min-width: 170px; max-width: 280px; font-size: 13px; white-space: pre-wrap; line-height: 1.55; overflow-wrap: anywhere; }

/* account modal sections */
.acct-section { margin-bottom: 4px; }
.acct-title { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.acct-divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* ---------- RESOURCES / PAS ---------- */
.res-list { display: flex; flex-direction: column; gap: 10px; }
.res-item {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--surface-2);
}
.res-main { min-width: 0; flex: 1; }
.res-title { font-weight: 700; font-size: 14.5px; }
.res-sub { font-weight: 500; color: var(--muted); }
.res-topic { font-size: 13.5px; margin-top: 3px; white-space: pre-wrap; }
.res-notes, .res-text { font-size: 13.5px; margin-top: 5px; white-space: pre-wrap; color: #2b3346; }
.res-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.res-form label { margin-top: 10px; }
.res-form input[type=file] { padding: 8px; background: var(--surface-2); }
.pas-share { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-weight: 500; cursor: pointer; }
.pas-share input { width: auto; }
a.btn { text-decoration: none; }

/* ---------- PRESENTATION MODE ---------- */
.present {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column;
  background:
    radial-gradient(1100px 650px at 82% -12%, #dfe4ff 0%, transparent 58%),
    radial-gradient(900px 600px at -5% 112%, #d6f5ea 0%, transparent 55%),
    #f5f7fc;
  color: #1b2333; font-family: "Inter", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}
.present-stage {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; justify-content: safe center;
  padding: 4vh 4vw; cursor: pointer; overflow-y: auto; overflow-x: hidden;
}
.present-stage::-webkit-scrollbar { width: 10px; }
.present-stage::-webkit-scrollbar-thumb { background: rgba(59,76,224,.25); border-radius: 8px; }
.slide { width: 100%; max-width: 100%; flex: 0 0 auto; animation: slideIn .35s ease; --ps-fs: 1; }
@keyframes slideIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* title slide */
.slide-title { text-align: center; }
.pt-logo {
  width: 96px; height: 96px; margin: 0 auto 28px; border-radius: 24px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3b4ce0, #6b78f0); font-weight: 800; font-size: 36px;
  box-shadow: 0 20px 60px rgba(59,76,224,.5);
}
.slide-title h1 { font-size: clamp(32px, 5vw, 60px); margin: 0 0 18px; font-weight: 800; letter-spacing: -1px; }
.pt-period { font-size: clamp(22px, 3vw, 34px); font-weight: 700; color: var(--primary); }
.pt-host { margin-top: 16px; font-size: clamp(16px, 2vw, 22px); color: #a5760a; font-weight: 600; }
.pt-count { margin-top: 26px; font-size: clamp(15px, 1.8vw, 20px); color: var(--muted); }
.pt-hint { margin-top: 40px; font-size: 14px; color: #9aa2b5; }

/* member slide */
.ps-head { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; margin-bottom: calc(3vh * var(--ps-fs, 1)); border-bottom: 2px solid rgba(59,76,224,.15); padding-bottom: calc(18px * var(--ps-fs, 1)); }
.ps-head h2 { font-size: calc(clamp(30px, 4.5vw, 54px) * var(--ps-fs, 1)); margin: 0; font-weight: 800; letter-spacing: -.5px; }
.ps-idx { font-size: clamp(14px, 1.6vw, 18px); color: var(--muted); white-space: nowrap; }
.ps-tiles { display: grid; grid-template-columns: repeat(7, 1fr); gap: 14px; margin-bottom: calc(3.5vh * var(--ps-fs, 1)); }
.ps-tile {
  background: #ffffff; border: 1px solid var(--border); border-radius: 16px;
  padding: calc(18px * var(--ps-fs, 1)) 8px; text-align: center; box-shadow: 0 6px 20px rgba(16,24,40,.06);
}
.ps-val { font-size: calc(clamp(28px, 4vw, 48px) * var(--ps-fs, 1)); font-weight: 800; line-height: 1; }
.ps-lbl { margin-top: 8px; font-size: calc(clamp(12px, 1.3vw, 16px) * var(--ps-fs, 1)); color: var(--muted); font-weight: 600; }
.ps-narrs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; align-items: start; }
.ps-narr { background: #ffffff; border: 1px solid var(--border); border-radius: 16px; padding: calc(20px * var(--ps-fs, 1)) 22px; box-shadow: 0 6px 20px rgba(16,24,40,.05); min-width: 0; }
.ps-tag { font-size: calc(clamp(13px, 1.4vw, 17px) * var(--ps-fs, 1)); font-weight: 700; color: var(--primary); margin-bottom: 10px; }
.ps-text {
  font-size: calc(clamp(15px, 1.7vw, 22px) * var(--ps-fs, 1)); line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: anywhere; color: #2b3346;
}
.ps-empty, .ps-summary-note { text-align: center; color: var(--muted); font-size: 20px; padding: 30px; }
.ps-summary-note { margin-top: 4vh; font-size: clamp(18px, 2vw, 26px); }

/* control bar */
.present-bar {
  display: flex; align-items: center; gap: 14px; padding: 14px 24px;
  background: rgba(255,255,255,.75); backdrop-filter: blur(10px); border-top: 1px solid var(--border);
}
.present-nav {
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--border);
  background: #fff; color: var(--primary); font-size: 24px; line-height: 1; display: grid; place-items: center;
  box-shadow: var(--shadow);
}
.present-nav:hover:not(:disabled) { background: var(--primary-soft); }
.present-nav:disabled { opacity: .35; cursor: default; }
.present-progress { flex: 1; text-align: center; font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: .5px; }
.present-exit { background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); }
.present-exit:hover { background: var(--danger); color: #fff; border-color: transparent; }

@media (max-width: 760px) {
  .ps-tiles { grid-template-columns: repeat(4, 1fr); }
  .ps-narrs { grid-template-columns: 1fr; }
}

/* ---------- MOBILE ---------- */
@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap; gap: 10px 12px; padding: 10px 14px; position: sticky;
  }
  .topbar .brand { order: 1; }
  .user-chip { order: 2; margin-left: auto; }
  #switchBtn, #logoutBtn { order: 3; }
  .nav {
    order: 4; width: 100%; margin-left: 0; overflow-x: auto; -webkit-overflow-scrolling: touch;
    border-top: 1px solid var(--border); padding-top: 8px;
  }
  .nav button { white-space: nowrap; padding: 8px 12px; font-size: 13.5px; }
  .spacer { display: none; }
  .user-meta strong { font-size: 13px; }
  .container { padding: 18px 14px 60px; }
  .page-head h2 { font-size: 19px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .value { font-size: 23px; }
  .card { padding: 16px; }
  .chart-box { height: 240px; }
  .card-head { align-items: stretch; }
  .card-actions { width: 100%; }
  .card-actions select { flex: 1; }
  .score-row { grid-template-columns: 1fr; gap: 8px; align-items: stretch; }
  .range-wrap { min-width: 0; justify-content: space-between; }
  .range-wrap input[type=range] { flex: 1; width: auto; }
  .modal { padding: 20px; }
  .auth-card { padding: 28px 22px; }
  table { font-size: 12.5px; }
  th, td { padding: 8px 9px; }
}
@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr; }
  .user-meta { display: none; }
}

/* a very long slide scrolls instead of being cut off — hint that there's more */
.present-stage.has-overflow { scroll-behavior: smooth; }
.present-stage.has-overflow::after {
  content: "↓ 还有内容，可滚动";
  position: sticky; bottom: 0; align-self: center; margin-top: 10px;
  font-size: 12.5px; color: var(--muted); background: rgba(255,255,255,.9);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px;
}
