:root {
  color-scheme: light;
  --bg: #f4f4f7;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-solid: #ffffff;
  --text: #1c1c1e;
  --muted: #74747a;
  --line: #e3e3e8;
  --accent: #ff3b30;
  --accent-soft: #fff0ee;
  --blue: #2878e3;
  --shadow: 0 18px 50px rgba(19, 28, 45, 0.12);
  --radius: 24px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 10% -10%, rgba(255, 96, 86, 0.10), transparent 35%),
    linear-gradient(180deg, #fbfbfc 0%, var(--bg) 60%);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 calc(96px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 18px clamp(14px, 3vw, 34px) 12px;
  background: rgba(249, 249, 251, 0.86);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
.brand-row, .nav-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.eyebrow { margin: 0 0 2px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .13em; }
h1 { margin: 0; font-size: clamp(30px, 7vw, 56px); line-height: 1.05; letter-spacing: -0.04em; }
.nav-row { margin-top: 14px; }

.icon-button {
  width: 42px; height: 42px; flex: 0 0 42px;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 50%;
  background: rgba(118,118,128,.10); color: #333;
  cursor: pointer;
}
.icon-button svg { width: 23px; height: 23px; fill: currentColor; }
.icon-button:active { transform: scale(.96); }

.segmented {
  display: inline-flex; align-items: center;
  padding: 3px; border-radius: 12px;
  background: rgba(118,118,128,.11);
}
.segmented button {
  min-width: 42px; height: 34px; padding: 0 13px;
  border: 0; border-radius: 9px; background: transparent;
  color: #38383b; font-weight: 700; cursor: pointer;
}
.segmented button:nth-child(2) { min-width: 58px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.segmented button:first-child, .segmented button:last-child { font-size: 25px; line-height: 1; }
.install-button {
  border: 0; border-radius: 10px; padding: 9px 13px;
  color: var(--blue); background: #eaf3ff; font-size: 13px; font-weight: 700; cursor: pointer;
}

main { padding: 12px clamp(8px, 2vw, 28px) 30px; }
.calendar-card {
  overflow: hidden;
  background: var(--surface-solid);
  border: 1px solid rgba(0,0,0,.07);
  border-radius: clamp(12px, 2vw, 22px);
  box-shadow: 0 10px 35px rgba(28, 28, 30, .06);
}
.weekday-row, .calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekday-row {
  color: #5d5d63; background: #fafafd;
  border-bottom: 1px solid var(--line);
}
.weekday-row span { padding: 11px 4px 9px; text-align: center; font-size: 13px; font-weight: 700; }
.weekday-row span:first-child, .weekday-row span:last-child { color: #9a4d49; }

.calendar-grid { grid-auto-rows: minmax(112px, auto); }
.day-cell {
  position: relative;
  min-width: 0;
  padding: 7px 5px 8px;
  background: #fff;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .15s ease;
}
.day-cell:nth-child(7n) { border-right: 0; }
.day-cell:hover { background: #fafafe; }
.day-cell.other-month { background: #f8f8fa; color: #b8b8bd; }
.day-cell.today { background: linear-gradient(180deg, var(--accent-soft), #fff 48%); }
.day-cell.selected-flash { animation: flash .5s ease; }
@keyframes flash { 50% { background: #fff4c8; } }

.day-head { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 2px; margin-bottom: 5px; }
.lunar { overflow: hidden; color: #929298; font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
.day-number {
  width: 27px; height: 27px; flex: 0 0 27px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: #2a2a2d; font-size: 14px; font-weight: 750;
}
.today .day-number { color: #fff; background: var(--accent); }
.other-month .day-number { color: #b8b8bd; }
.events { display: grid; gap: 4px; align-content: start; }
.event-pill {
  position: relative;
  width: 100%; min-width: 0;
  padding: 4px 4px 4px 8px;
  border: 0; border-radius: 6px;
  color: #2d2d31; background: #fff3c8;
  font-size: 10px; font-weight: 650; line-height: 1.25;
  text-align: left; word-break: break-word;
  cursor: pointer;
}
.event-pill::before {
  content: ""; position: absolute; left: 3px; top: 4px; bottom: 4px;
  width: 3px; border-radius: 3px; background: #ffbf00;
}
.event-pill .time { display: block; color: rgba(0,0,0,.52); font-size: 8.5px; font-variant-numeric: tabular-nums; }
.event-pill.work { background: #fff3c8; }
.event-pill.work::before { background: #ffbf00; }
.event-pill.life { background: #dcf6e7; }
.event-pill.life::before { background: #28b969; }
.event-pill.payment { background: #ffe5e2; }
.event-pill.payment::before { background: #ff453a; }
.event-pill.anniversary { background: #f3def9; }
.event-pill.anniversary::before { background: #c85ddb; }
.other-month .event-pill { opacity: .48; }

.fab {
  position: fixed; z-index: 25;
  right: max(18px, calc((100vw - 1500px) / 2 + 24px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  height: 54px; padding: 0 19px 0 15px;
  display: flex; align-items: center; gap: 8px;
  border: 0; border-radius: 27px;
  color: #fff; background: var(--accent);
  box-shadow: 0 12px 32px rgba(255,59,48,.34);
  font-weight: 750; cursor: pointer;
}
.fab svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.fab:active { transform: translateY(1px) scale(.98); }

[hidden] { display: none !important; }
.modal-backdrop {
  position: fixed; z-index: 50; inset: 0;
  display: grid; align-items: end; justify-items: center;
  padding-top: env(safe-area-inset-top);
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}
.modal {
  width: min(620px, 100%); max-height: calc(94dvh - env(safe-area-inset-top)); overflow: auto;
  padding: 8px 20px calc(22px + env(safe-area-inset-bottom));
  background: #fff; border-radius: 25px 25px 0 0;
  box-shadow: var(--shadow);
}
.modal-handle { width: 38px; height: 5px; margin: 0 auto 7px; border-radius: 3px; background: #d7d7dc; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 16px; }
.modal-header h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.modal-header .icon-button { width: 34px; height: 34px; flex-basis: 34px; font-size: 25px; font-weight: 300; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 7px; margin-bottom: 13px; }
.field > span { color: #64646a; font-size: 12px; font-weight: 700; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 11px 12px;
  border: 1px solid #dedee4; border-radius: 11px;
  outline: none; color: var(--text); background: #fafafd;
  -webkit-appearance: none; appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(40,120,227,.12); background: #fff; }
.field textarea { resize: vertical; }
.check-row { display: flex; align-items: center; gap: 8px; margin: -3px 0 15px; color: #4e4e53; font-size: 14px; font-weight: 650; }
.check-row input { width: 18px; height: 18px; accent-color: var(--blue); }
.reminder-note { margin: 0 0 14px; padding: 10px 12px; border-radius: 10px; color: #786228; background: #fff8db; font-size: 11px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.modal-actions.edit-actions { justify-content: space-between; padding-top: 6px; border-top: 1px solid var(--line); }
.button { min-height: 44px; padding: 0 17px; border: 0; border-radius: 11px; font-weight: 750; cursor: pointer; }
.button.primary { color: #fff; background: var(--blue); }
.button.secondary { color: var(--blue); background: #eaf3ff; }
.button.ghost { color: #505057; background: #f0f0f4; }
.button.danger { color: #d72c23; background: #fff0ef; }
.full-button { width: 100%; margin-top: 15px; }

.settings-modal { padding-left: 14px; padding-right: 14px; }
.settings-list { overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.settings-item {
  position: relative;
  width: 100%; min-height: 66px; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 0; border-bottom: 1px solid var(--line);
  color: var(--text); background: #fff; text-align: left; cursor: pointer;
}
.settings-item:last-child { border-bottom: 0; }
.settings-item strong, .settings-item small { display: block; }
.settings-item strong { font-size: 14px; }
.settings-item small { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.35; }
.settings-item b { color: #aaa; font-size: 22px; font-weight: 400; }
.file-item input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.privacy-card { margin-top: 14px; padding: 14px; border-radius: 14px; color: #4f5360; background: #f2f4f8; }
.privacy-card strong { font-size: 13px; }
.privacy-card p { margin: 5px 0 0; font-size: 11px; line-height: 1.5; }

.install-steps { list-style: none; margin: 2px 0 0; padding: 0; display: grid; gap: 15px; }
.install-steps li { display: grid; grid-template-columns: 30px 1fr; gap: 11px; align-items: start; }
.install-steps li > span { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--blue); font-weight: 800; }
.install-steps p { margin: 3px 0 0; color: #4e4e54; font-size: 14px; line-height: 1.55; }

.toast {
  position: fixed; z-index: 100; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  max-width: min(90vw, 460px); padding: 11px 16px;
  border-radius: 12px; color: #fff; background: rgba(35,35,38,.92);
  box-shadow: 0 8px 25px rgba(0,0,0,.2);
  font-size: 13px; font-weight: 650; line-height: 1.4;
  opacity: 0; pointer-events: none; transform: translate(-50%, 10px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 650px) {
  .topbar { padding-top: 13px; }
  .calendar-grid { grid-auto-rows: minmax(105px, auto); }
  .day-cell { padding: 6px 3px 7px; }
  .day-number { width: 24px; height: 24px; flex-basis: 24px; font-size: 13px; }
  .lunar { font-size: 8.5px; }
  .event-pill { padding-left: 7px; font-size: 9px; border-radius: 5px; }
  .event-pill .time { font-size: 8px; }
  .fab { width: 54px; padding: 0; justify-content: center; }
  .fab span { display: none; }
}

@media (max-width: 390px) {
  main { padding-left: 4px; padding-right: 4px; }
  .calendar-card { border-radius: 10px; }
  .calendar-grid { grid-auto-rows: minmax(96px, auto); }
  .weekday-row span { font-size: 12px; }
  .event-pill { font-size: 8.5px; line-height: 1.22; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
}

@media (min-width: 800px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: var(--radius); padding-bottom: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
