/* ============================================================
   个人状态记录 · PWA 样式
   移动优先，自动跟随系统深浅色
   ============================================================ */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f4;
  --border: #e3e6ec;
  --border-strong: #cdd3dd;
  --text: #16191f;
  --text-dim: #6b7280;
  --text-faint: #9aa1ad;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eceafe;
  --accent-text: #ffffff;
  --ok: #0d9488;
  --ok-soft: #d9f6f1;
  --warn: #d97706;
  --warn-soft: #fef1dc;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);
  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --nav-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #171a20;
    --surface-2: #1d212a;
    --surface-3: #262b35;
    --border: #2a2f3a;
    --border-strong: #3a4150;
    --text: #e9ecf1;
    --text-dim: #9aa3b2;
    --text-faint: #6d7686;
    --accent: #7c86ff;
    --accent-hover: #929aff;
    --accent-soft: #232744;
    --accent-text: #0e1014;
    --ok: #2dd4bf;
    --ok-soft: #10312e;
    --warn: #fbbf24;
    --warn-soft: #33280f;
    --danger: #f87171;
    --danger-soft: #35191a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.55);
  }
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: var(--accent);
  text-decoration: none;
}

/* ---------------------------- 布局 ---------------------------- */
#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 17px;
  font-weight: 650;
  margin: 0;
  letter-spacing: -0.2px;
}

.topbar .sub {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 400;
  margin-top: 1px;
}

.topbar .spacer {
  flex: 1;
}

main {
  flex: 1;
  padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 24px);
}

.bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  max-width: 720px;
  margin: 0 auto;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottomnav button {
  flex: 1;
  height: var(--nav-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 500;
  transition: color 0.15s;
}

.bottomnav button svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.8;
}

.bottomnav button.active {
  color: var(--accent);
}

/* ---------------------------- 卡片 ---------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.card-head h2 {
  font-size: 14px;
  font-weight: 650;
  margin: 0;
  letter-spacing: -0.1px;
}

.card-head .spacer {
  flex: 1;
}

.group-title {
  font-size: 12px;
  font-weight: 650;
  color: var(--text-dim);
  text-transform: none;
  letter-spacing: 0.4px;
  margin: 20px 4px 9px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.group-title:first-child {
  margin-top: 4px;
}

.group-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------------------------- 表单控件 ---------------------------- */
.field-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
}

.field-row + .field-row {
  border-top: 1px solid var(--border);
}

.field-label {
  flex: 1;
  min-width: 0;
}

.field-label .name {
  font-size: 14.5px;
  font-weight: 500;
  display: block;
}

.field-label .hint {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 1px;
  display: block;
}

.field-control {
  flex-shrink: 0;
}

/* 清空单项的小按钮 */
.clr-btn {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-faint);
  font-size: 10px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.14s;
}

.clr-btn:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.field-row:not(.stack) .field-label {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.field-row.stack .field-label .clr-btn {
  margin-left: auto;
}

/* 竖排字段（评分 / 自由输入用）：标签在上，控件占满整行 */
.field-row.stack {
  flex-direction: column;
  align-items: stretch;
  gap: 9px;
}

.field-row.stack .field-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.field-row.stack .field-label .hint {
  margin-top: 0;
}

.scale.stretch button {
  flex: 1;
  width: auto;
  min-width: 34px;
}

.day-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.day-nav button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text-dim);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.day-nav button:hover {
  background: var(--border);
}

.day-nav .d {
  font-size: 13px;
  font-weight: 620;
  min-width: 96px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.chart-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.chart-title .n {
  font-size: 14px;
  font-weight: 620;
}

.chart-title .v {
  font-size: 12.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.chart-title .spacer {
  flex: 1;
}

.sub-label {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.token-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.55;
}

.hr {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

.code-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--text-dim);
  white-space: pre;
  margin: 8px 0 0;
}

.actions-inline {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.draggable-handle {
  color: var(--text-faint);
  font-size: 15px;
  cursor: grab;
  user-select: none;
  padding-right: 2px;
}


/* 评分选择器 */
.scale {
  display: flex;
  gap: 5px;
}

.scale button {
  width: 38px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 600;
  border: 1.5px solid transparent;
  transition: all 0.14s;
}

.scale button:hover {
  background: var(--border);
}

.scale button.on {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.scale.compact button {
  width: 30px;
  height: 30px;
  font-size: 12.5px;
  border-radius: 7px;
}

/* 是/否 */
.toggle {
  display: inline-flex;
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.toggle button {
  padding: 7px 15px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 560;
  color: var(--text-dim);
  transition: all 0.15s;
}

.toggle button.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.toggle button.on.yes {
  color: var(--accent);
}

/* 步进器 */
.stepper {
  display: inline-flex;
  align-items: center;
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.stepper button {
  width: 38px;
  height: 40px;
  font-size: 19px;
  color: var(--text-dim);
  line-height: 1;
}

.stepper button:active {
  background: var(--border);
}

.stepper .val {
  min-width: 46px;
  text-align: center;
  font-size: 15px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.stepper .val.empty {
  color: var(--text-faint);
  font-weight: 400;
}

/* 「打」飞机按钮 */
.plane-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface-3);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.plane-btn:active {
  transform: scale(0.88) rotate(-12deg);
}

.plane-btn.on {
  border-color: var(--accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 45%, transparent);
}

.plane-val {
  min-width: 2.4ch;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* 输入框 */
input[type="text"],
input[type="number"],
input[type="password"],
input[type="date"],
select,
textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14.5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  resize: vertical;
  min-height: 74px;
  line-height: 1.6;
}

.compact-input {
  width: 84px;
  text-align: center;
}

label.lbl {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text);
  font-size: 14px;
  font-weight: 560;
  transition: all 0.15s;
  border: 1px solid transparent;
}

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

.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-dim);
}

.btn.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn.sm {
  padding: 7px 11px;
  font-size: 12.5px;
}

.btn.block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* 徽标 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2.5px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 620;
  background: var(--surface-3);
  color: var(--text-dim);
}

.badge.accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

/* 统计小卡 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
}

.stat .n {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}

.stat .l {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* 列表项 */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}

.list-item + .list-item {
  border-top: 1px solid var(--border);
}

.list-item .main {
  flex: 1;
  min-width: 0;
}

.list-item .t {
  font-size: 14px;
  font-weight: 560;
}

.list-item .s {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  word-break: break-all;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}

/* 空状态 */
.empty {
  text-align: center;
  padding: 34px 16px;
  color: var(--text-faint);
  font-size: 13.5px;
}

.empty .big {
  font-size: 32px;
  margin-bottom: 10px;
}

/* 登录页 */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  max-width: 420px;
  margin: 0 auto;
}

.auth-logo {
  width: 62px;
  height: 62px;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 29px;
  margin: 0 auto 18px;
  box-shadow: var(--shadow-lg);
}

.auth-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin: 0 0 6px;
}

.auth-sub {
  text-align: center;
  color: var(--text-dim);
  font-size: 13.5px;
  margin: 0 0 26px;
}

.tabs {
  display: flex;
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 20px;
}

.tabs button {
  flex: 1;
  padding: 9px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 560;
  color: var(--text-dim);
  transition: all 0.15s;
}

.tabs button.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.form-group {
  margin-bottom: 14px;
}

/* Toast */
#toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 22px);
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: min(92vw, 420px);
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 11px;
  font-size: 13.5px;
  font-weight: 520;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.22s ease;
  max-width: 100%;
  text-align: center;
}

.toast.err {
  background: var(--danger);
  color: #fff;
}

.toast.ok {
  background: var(--ok);
  color: #fff;
}

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

/* 图表 */
.chart-box {
  position: relative;
  width: 100%;
}

.chart-box svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.legend {
  display: flex;
  gap: 14px;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 8px;
  flex-wrap: wrap;
}

.legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -1px;
}

/* 热力图 */
.heatmap {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr);
  gap: 3px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.heatmap .cell {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--surface-3);
}

.heatmap .cell[data-l="1"] {
  background: color-mix(in srgb, var(--accent) 28%, var(--surface-3));
}
.heatmap .cell[data-l="2"] {
  background: color-mix(in srgb, var(--accent) 52%, var(--surface-3));
}
.heatmap .cell[data-l="3"] {
  background: color-mix(in srgb, var(--accent) 76%, var(--surface-3));
}
.heatmap .cell[data-l="4"] {
  background: var(--accent);
}

/* 弹层 */
.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.5);
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.18s ease;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 720px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 18px calc(env(safe-area-inset-bottom, 0px) + 22px);
  max-height: 88vh;
  overflow-y: auto;
  animation: sheet-up 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes sheet-up {
  from {
    transform: translateY(100%);
  }
}

.sheet h3 {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 680;
  letter-spacing: -0.2px;
}

.sheet .desc {
  color: var(--text-dim);
  font-size: 12.5px;
  margin-bottom: 18px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.spin {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-faint);
}

.saved-hint {
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
  min-height: 18px;
  transition: color 0.2s;
}

.saved-hint.act {
  color: var(--ok);
}

@media (min-width: 640px) {
  body {
    font-size: 15.5px;
  }
  main {
    padding: 20px 20px 40px;
  }
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
