:root {
  --bg: #0f0f13;
  --surface: #1a1a22;
  --surface2: #24242f;
  --border: #2e2e3a;
  --text: #f0f0f5;
  --muted: #8888a0;
  --accent: #f4a896;
  --accent-dim: #e8b4bc;
  --danger: #f87171;
  --success: #86efac;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
}

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

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* 弹窗打开时锁住背景，避免 iOS 背后滚动与横向位移 */
html.overlay-open,
body.overlay-open {
  overflow: hidden;
  overscroll-behavior: none;
}

body.overlay-open {
  position: fixed;
  width: 100%;
  left: 0;
  right: 0;
}

.hidden { display: none !important; }

#login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 0%, #2a1f24 0%, var(--bg) 60%);
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  padding: 40px 32px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.logo { font-size: 48px; margin-bottom: 12px; }
.login-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.subtitle { color: var(--muted); font-size: 14px; margin-bottom: 28px; }

.login-card input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 16px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }

.error { color: var(--danger); font-size: 13px; margin-top: 12px; }

.btn {
  padding: 12px 24px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s, opacity .15s;
  font-family: inherit;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: #1a1014; }
.btn.primary:hover { background: var(--accent-dim); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.ghost:hover { color: var(--text); border-color: var(--muted); }
.btn.sm {
  padding: 10px 16px;
  font-size: 14px;
  min-height: 44px;
}
.btn-icon {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}
.btn-icon:active { background: rgba(255, 255, 255, .06); }

.login-card .btn { width: 100%; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  position: sticky;
  top: 0;
  background: rgba(15, 15, 19, .92);
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

.header-left { display: flex; align-items: center; gap: 10px; }
.logo-sm { font-size: 22px; }
.header h1 { font-size: 18px; font-weight: 600; }
.header-actions { display: flex; gap: 8px; }

#app {
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}

.profile-banner {
  margin: 12px 20px 0;
  padding: 12px 14px;
  background: rgba(248,113,113,.12);
  border: 1px solid rgba(248,113,113,.35);
  border-radius: 12px;
  font-size: 13px;
  color: var(--text);
}
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  margin-left: 6px;
  font-family: inherit;
  padding: 8px 4px;
  min-height: 44px;
  vertical-align: middle;
}

.hero-card {
  margin: 16px 20px;
  padding: 24px 20px;
  background: linear-gradient(135deg, #2a2228, var(--surface));
  border: 1px solid rgba(244,168,150,.25);
  border-radius: var(--radius);
  text-align: center;
}

.hero-week {
  font-size: 42px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}

.hero-sub {
  margin-top: 8px;
  font-size: 14px;
  color: var(--muted);
}

.progress-track {
  margin-top: 18px;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 3px;
  transition: width .4s ease;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 0 20px 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 10px;
  text-align: center;
}

.kpi-card.accent {
  background: linear-gradient(135deg, #2a2228, #1a1a22);
  border-color: rgba(244,168,150,.3);
}

.kpi-click { cursor: pointer; }
.kpi-click:active { transform: scale(.98); }

.kpi-label { display: block; font-size: 11px; color: var(--muted); letter-spacing: .04em; margin-bottom: 6px; }
.kpi-value { display: block; font-size: 20px; font-weight: 700; }
.kpi-value-sm {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  white-space: pre-line;
}
.kpi-card.accent .kpi-value { color: var(--accent); }

.card {
  margin: 0 20px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card h2 { font-size: 15px; font-weight: 600; color: var(--muted); margin-bottom: 16px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-head h2 { margin-bottom: 0; }

.overdue-hint {
  font-size: 12px;
  color: var(--danger);
}

.chart-wrap { position: relative; height: 220px; }

.milestone-list { display: flex; flex-direction: column; gap: 10px; }

.ms-item {
  display: grid;
  grid-template-columns: 4px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: var(--surface2);
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
  color: inherit;
}
.ms-item:active { opacity: .9; }

.ms-bar {
  align-self: stretch;
  border-radius: 2px;
  background: var(--border);
}
.ms-item.status-due .ms-bar { background: var(--accent); }
.ms-item.status-overdue .ms-bar { background: var(--danger); }
.ms-item.status-done .ms-bar { background: var(--success); }

.ms-body { min-width: 0; }
.ms-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.ms-meta { font-size: 12px; color: var(--muted); }
.ms-result-preview {
  font-size: 12px;
  color: var(--text);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ms-action {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}
.ms-item.status-done .ms-action { color: var(--success); }

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.compare-cell { min-width: 0; }

.compare-cell-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
  text-align: center;
}

.compare-side-img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.compare-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  color: var(--muted);
  font-size: 14px;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .92);
}

.lightbox-stage {
  position: relative;
  z-index: 1;
  max-width: 100%;
  max-height: 85vh;
  touch-action: pan-y pinch-zoom;
}

.lightbox-img {
  display: block;
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
  user-select: none;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 44px;
  height: 64px;
  border: none;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 32px;
  cursor: pointer;
  border-radius: 8px;
}
.lightbox-prev { left: 12px; }
.lightbox-next { right: 12px; }

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1;
  background: rgba(255, 255, 255, .12);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}

.lightbox-caption {
  position: absolute;
  bottom: 24px;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 255, 255, .7);
  font-size: 14px;
  z-index: 1;
}

.gallery-strip-wrap {
  margin: 0 -20px;
  padding: 0 20px;
}

.gallery-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 10px;
}

.gallery-item {
  flex: 0 0 auto;
  width: 140px;
  scroll-snap-align: start;
}

.gallery-item img {
  width: 140px;
  height: 186px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  display: block;
}

.gallery-date {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  text-align: center;
}

.gallery-weight {
  display: block;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  text-align: center;
  margin-top: 2px;
}

.timeline-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
  padding: 4px;
  background: var(--surface2);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.timeline-tab {
  padding: 10px 12px;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.timeline-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}

.timeline-tab .tab-count {
  font-weight: 500;
  color: var(--muted);
  font-size: 12px;
  margin-left: 4px;
}

.timeline-tab.active .tab-count {
  color: var(--accent);
}

.timeline { display: flex; flex-direction: column; gap: 12px; }

.timeline-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--surface2);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.timeline-date { text-align: center; }
.timeline-day { font-size: 22px; font-weight: 700; line-height: 1; }
.timeline-month { font-size: 11px; color: var(--muted); }

.timeline-body { min-width: 0; }
.timeline-kind {
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 4px;
}
.timeline-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.timeline-weight { font-size: 18px; font-weight: 600; color: var(--accent); margin-bottom: 6px; }
.timeline-photos { display: flex; gap: 8px; flex-wrap: wrap; }
.timeline-photos img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}
.timeline-note { font-size: 13px; color: var(--muted); margin-top: 6px; }
.timeline-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.timeline-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(244,168,150,.15);
  color: var(--accent-dim);
}

.timeline-edit {
  margin-top: 8px;
  padding: 10px 14px;
  font-size: 14px;
  min-height: 44px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}

.empty { text-align: center; color: var(--muted); padding: 24px 0; font-size: 14px; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 250;
  pointer-events: none;
}

.sheet:not(.hidden) {
  pointer-events: auto;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(0, 0, 0, .55);
  touch-action: none;
}

.sheet-content {
  position: fixed;
  z-index: 251;
  left: 50%;
  bottom: 0;
  width: min(100%, 720px);
  transform: translateX(-50%);
  max-height: 85vh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  overscroll-behavior-x: none;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
}

.sheet-scroll { max-height: none; }

.sheet-content h2 { font-size: 16px; margin-bottom: 12px; color: var(--muted); }

.sheet-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 0;
  min-height: 48px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-family: inherit;
}
.sheet-item.danger { color: var(--danger); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
}

.modal:not(.hidden) {
  pointer-events: auto;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, .6);
  touch-action: none;
}

.modal-content {
  position: fixed;
  z-index: 201;
  left: 50%;
  bottom: 0;
  width: min(100%, 720px);
  transform: translateX(-50%);
  max-height: 85vh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  overscroll-behavior-x: none;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
}

@media (min-width: 640px) {
  .modal-content,
  .sheet-content {
    top: 50%;
    bottom: auto;
    max-height: min(85vh, 640px);
    transform: translate(-50%, -50%);
    border-radius: var(--radius);
    border: 1px solid var(--border);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 18px; font-weight: 600; color: var(--text); margin: 0; }

#entry-form label,
#profile-form label,
#milestone-form label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}

#entry-form input[type="date"],
#entry-form input[type="number"],
#entry-form textarea,
#profile-form input:not([type="checkbox"]):not([type="hidden"]),
#profile-form textarea,
#milestone-form input:not([type="checkbox"]):not([type="hidden"]),
#milestone-form textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 4px 0;
}

.switch-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  line-height: 1.4;
}

.ios-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 32px;
  flex-shrink: 0;
}

.ios-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.ios-switch-slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 32px;
  transition: background 0.2s, border-color 0.2s;
}

.ios-switch-slider::before {
  content: '';
  position: absolute;
  width: 26px;
  height: 26px;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  transition: transform 0.2s;
}

.ios-switch input:checked + .ios-switch-slider {
  background: var(--accent);
  border-color: var(--accent-dim);
}

.ios-switch input:checked + .ios-switch-slider::before {
  transform: translate(20px, -50%);
}

.ms-window { font-size: 13px; color: var(--muted); margin-bottom: 12px; }

.photo-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.photo-row-single { grid-template-columns: 1fr; max-width: 50%; margin-left: auto; margin-right: auto; }
.photo-upload input { display: none; }
.upload-field-label {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 8px;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.report-grid:empty {
  display: none;
}

.report-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface2);
}

.report-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
}

.report-thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}

.ms-report-add {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.ms-report-add input {
  display: none;
}

.ms-report-add-btn {
  display: inline-block;
  padding: 12px 20px;
  min-height: 44px;
  border-radius: 12px;
  border: 2px dashed var(--border);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  width: min(100%, 320px);
  text-align: center;
}

.ms-report-add-btn:active {
  border-color: var(--accent);
  color: var(--accent);
}

.modal-content .btn:active,
.sheet-content .btn:active,
.tag-chip:active {
  transform: none;
}

.photo-box {
  aspect-ratio: 1;
  border: 2px dashed var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  overflow: hidden;
  font-size: 13px;
  color: var(--muted);
}
.photo-box img { width: 100%; height: 100%; object-fit: cover; }
.photo-icon { font-size: 28px; }

.tag-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tag-chip {
  padding: 10px 14px;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.tag-chip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(244,168,150,.12);
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 8px;
}

.form-actions-bar {
  justify-content: center;
  margin-top: 16px;
}

.form-actions-bar .btn {
  flex: 1;
  max-width: none;
  min-height: 48px;
}

.btn-delete-entry {
  width: 100%;
  margin-top: 8px;
  color: var(--danger);
  border-color: rgba(248, 113, 113, .35);
}

.modal-content .form-actions,
.sheet-content .form-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: linear-gradient(to top, var(--surface) 85%, transparent);
  padding-top: 16px;
  padding-bottom: 4px;
  margin-top: 12px;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 14px;
  flex-shrink: 0;
}

.settings-hint {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.45;
}

.settings-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0 16px;
}

.settings-switch {
  margin-bottom: 12px !important;
}

#settings-form label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}

#settings-form input[type="password"],
#settings-form input[type="url"],
#settings-form input[type="text"],
#settings-form input[type="number"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

#settings-form select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

.time-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.time-row input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

.time-row span {
  color: var(--muted);
  font-size: 18px;
}

.settings-actions .btn.ghost {
  flex: 1;
}

@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  #kpi-next-wrap { grid-column: 1 / -1; }
}
