:root {
  --paper: #faf7f2;
  --card: #ffffff;
  --ink: #24211d;
  --muted: #8d837a;
  --line: #ece5da;
  --accent: #d97757;
  --accent-soft: #fbeee7;
  --me: #3b82f6;
  --her: #f97316;
  --shadow: 0 10px 30px rgba(70, 55, 40, .08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--paper);
  background-image: radial-gradient(circle at 1px 1px, #ece3d5 1.1px, transparent 0);
  background-size: 24px 24px;
  color: var(--ink);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* 插画素材容器：不占位、不显示 */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

body { min-height: 100vh; }

.hidden { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- 按钮 ---------- */

.btn {
  border: 1px solid transparent;
  background: #f1ece4;
  color: var(--ink);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 14px;
  line-height: 1.2;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: #e8e1d6; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #c96848; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.ghost:hover { background: #f3ede4; }
.btn.danger { background: #fdeceb; color: #c0392b; }
.btn.danger:hover { background: #fbd9d6; }
.btn.block { width: 100%; padding: 12px; font-size: 15px; }
.btn.small { padding: 6px 10px; font-size: 13px; }

.icon-btn {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 8px;
}
.icon-btn:hover { background: #f3ede4; }

/* ---------- 口令 / 选人 ---------- */

.screen.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.panel {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}
.brand .paw { font-size: 24px; }
.brand h1 { font-size: 22px; margin: 0; letter-spacing: .5px; }

.brand-art {
  width: 46px;
  height: 50px;
  flex: 0 0 auto;
  margin-left: -4px;
}

.field { display: block; margin-bottom: 14px; }
.field .label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 16px;
  background: #fffdfa;
  color: var(--ink);
  outline: none;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 119, 87, .12);
}
.field textarea { resize: vertical; min-height: 64px; }

.err {
  color: #c0392b;
  font-size: 13px;
  min-height: 18px;
  margin: 0 0 10px;
}

.who-panel {
  position: relative;
  padding-top: 32px;
  overflow: hidden;
}

/* 大猫爪水印：压在右上角，粉色 */
.who-paw {
  position: absolute;
  right: -34px;
  top: -30px;
  width: 230px;
  height: 230px;
  transform: rotate(14deg);
  color: #eeadb8;
  z-index: 0;
  pointer-events: none;
}
.who-panel > .who-title,
.who-panel > .hint,
.who-panel > .who-row { position: relative; z-index: 1; }

.who-deco { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.who-deco svg { position: absolute; }
.who-deco svg:nth-child(1) { left: 10px; top: 9px; width: 18px; height: 18px; transform: rotate(-18deg); }

.who-title { margin: 0 0 8px; font-size: 19px; }
.hint { margin: 0 0 18px; font-size: 13px; color: var(--muted); line-height: 1.6; }

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

.who-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  padding: 14px 8px 16px;
  background: #fffdfa;
  border: 1px solid var(--line);
  border-radius: 18px;
  transition: transform .15s, border-color .15s, background .15s, box-shadow .15s;
}
.who-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(150, 110, 80, .12);
}

.who-avatar { width: 88px; height: 96px; display: block; }
.who-avatar svg { width: 100%; height: 100%; display: block; }

.who-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 1px;
}
.who-sub { font-size: 11px; color: var(--muted); letter-spacing: 1px; }

/* 换人弹窗里的猫爪水印 */
.switch-wrap {
  position: relative;
  overflow: hidden;
  padding: 4px 8px 6px;
  margin: -4px -8px 0;
}
.sheet-paw {
  position: absolute;
  right: -26px;
  top: -22px;
  width: 190px;
  height: 190px;
  transform: rotate(14deg);
  color: #eeadb8;
  z-index: 0;
  pointer-events: none;
}
.switch-wrap > h3,
.switch-wrap > .detail-line,
.switch-wrap > .who-row,
.switch-wrap > .sheet-actions {
  position: relative;
  z-index: 1;
}

/* 换人弹窗里的小按钮，和选人卡片区分开 */
.who-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 8px;
  font-size: 15px;
  background: #fffdfa;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.who-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.chip-avatar { width: 30px; height: 33px; flex: 0 0 auto; }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.me { background: var(--me); }
.dot.her { background: var(--her); }

/* ---------- 主界面 ---------- */

#main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 16px 90px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.app-title {
  font-size: 20px;
  margin: 0 0 2px;
  letter-spacing: .5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.title-leaf { width: 18px; height: 18px; flex: 0 0 auto; transform: rotate(-12deg); }
.today { margin: 0; font-size: 13px; color: var(--muted); }
.topbar-right { display: flex; gap: 8px; flex-shrink: 0; }

.tabs {
  display: flex;
  gap: 4px;
  background: #f1ece4;
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 14px;
  width: fit-content;
}
.tab {
  border: none;
  background: transparent;
  padding: 7px 18px;
  border-radius: 9px;
  font-size: 14px;
  color: var(--muted);
}
.tab.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.06); }

.layout { display: grid; grid-template-columns: 1fr; gap: 16px; margin-top: 40px; }

/* 趴在月历上沿的两个小家伙：只露上半身，下沿被卡片边框切断 */
#monthView { position: relative; }

.peek {
  position: absolute;
  right: 14px;
  bottom: 100%;
  height: 48px;
  display: flex;
  align-items: flex-start;
  gap: 2px;
  overflow: hidden;
  pointer-events: none;
  z-index: 3;
}
.peek svg { display: block; width: 56px; height: 62px; flex: 0 0 auto; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}

/* ---------- 月历 ---------- */

.month-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.month-head h2 { font-size: 16px; margin: 0; }
.month-nav { display: flex; align-items: center; gap: 2px; }

.weekdays, .grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}
.weekdays { margin-bottom: 4px; }
.weekdays span {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 0;
}

.cell {
  aspect-ratio: 1 / 1;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 13px;
  position: relative;
  padding: 2px;
  min-width: 0;
}
.cell:hover { background: #f6f1e9; }
.cell.other { color: #c9c0b5; }
.cell.today .num { color: #fff; background: var(--accent); border-radius: 50%; }
.cell.selected { border-color: var(--accent); background: var(--accent-soft); }
.cell .num {
  width: 24px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  border-radius: 50%;
  font-variant-numeric: tabular-nums;
}
.dots { display: flex; gap: 2px; height: 6px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; display: block; }
.dots i.me { background: var(--me); }
.dots i.her { background: var(--her); }

.day-panel { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- 清单 ---------- */

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.list-head h2 { font-size: 16px; margin: 0; }

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

.day-group + .day-group { margin-top: 4px; }

.day-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 0 6px;
  border-bottom: 1px dashed var(--line);
  margin-bottom: 6px;
}
.day-head .d1 { font-size: 14px; font-weight: 600; }
.day-head .d2 { font-size: 12px; color: var(--muted); }
.day-head.is-today .d1 { color: var(--accent); }
.day-head .badge {
  margin-left: auto;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
}

.ev {
  display: flex;
  gap: 10px;
  padding: 8px 8px 8px 10px;
  border-radius: 10px;
  border-left: 3px solid transparent;
  background: #fffdfa;
  width: 100%;
  text-align: left;
  margin-bottom: 4px;
}
.ev:hover { background: #f7f2ea; }
.ev.me { border-left-color: var(--me); }
.ev.her { border-left-color: var(--her); }
.ev.ghost-date { opacity: .55; }

.ev-time {
  font-size: 12px;
  color: var(--muted);
  min-width: 42px;
  padding-top: 2px;
  font-variant-numeric: tabular-nums;
}
.ev-body { min-width: 0; flex: 1; }
.ev-title { font-size: 15px; line-height: 1.35; word-break: break-word; }
.ev-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.5;
  word-break: break-word;
}
.ev-meta { font-size: 11px; color: #b3a99e; margin-top: 3px; }

/* 谁记的：固定在行尾，标题再长也不折行 */
.ev-owner {
  align-self: center;
  flex: 0 0 auto;
  margin-left: 6px;
  font-size: 11px;
  line-height: 1.7;
  padding: 1px 8px;
  border-radius: 999px;
  white-space: nowrap;
  background: #f1ece4;
  color: var(--muted);
}
.ev.me .ev-owner { background: #e8f0fe; color: #2563eb; }
.ev.her .ev-owner { background: #ffeddb; color: #c2410c; }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 22px 8px 30px;
  line-height: 1.7;
}
.empty p { margin: 0; }
.empty-art { width: 190px; max-width: 76%; height: auto; display: block; margin: 0 auto 10px; }
.empty-sub { margin-top: 4px; font-size: 12px; color: #b3a99e; }

/* ---------- 悬浮按钮 ---------- */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 8px 20px rgba(217, 119, 87, .35);
}

/* ---------- 弹层 ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(36, 33, 29, .35);
  z-index: 40;
}

.sheet {
  position: fixed;
  z-index: 50;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.sheet-inner {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  max-width: 560px;
  margin: 0 auto;
  animation: slideUp .18s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(16px); opacity: .6; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet h3 { margin: 0 0 16px; font-size: 17px; }

.form-row { margin-bottom: 12px; }
.form-row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.form-row label.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}
.seg {
  display: inline-flex;
  background: #f1ece4;
  padding: 3px;
  border-radius: 10px;
  gap: 3px;
}
.seg button {
  border: none;
  background: transparent;
  padding: 7px 16px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--muted);
}
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.06); }

.weekday-pick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.weekday-pick button {
  width: 38px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fffdfa;
  font-size: 13px;
  color: var(--muted);
}
.weekday-pick button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.sheet-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}
.sheet-actions .btn { flex: 1; padding: 12px; }

.detail-line { font-size: 14px; color: var(--muted); margin: 0 0 8px; line-height: 1.6; }
.detail-title { font-size: 18px; margin: 0 0 10px; word-break: break-word; }
.detail-note {
  background: #f8f4ee;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.65;
  margin: 12px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- 轻提示 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 8px);
  background: rgba(36, 33, 29, .9);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
  max-width: 80vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 宽屏 ---------- */

@media (min-width: 900px) {
  #main { padding: 28px 24px 60px; }
  .tabs { display: none; }
  .layout { grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); gap: 20px; align-items: start; }
  .fab { display: none; }
  .app-title { font-size: 22px; }
  .toast { bottom: 30px; }
  .sheet {
    left: 50%;
    right: auto;
    bottom: 50%;
    transform: translate(-50%, 50%);
    width: 560px;
    max-height: 86vh;
  }
  .sheet-inner {
    border-radius: 18px;
    padding: 24px;
    animation: fadeIn .16s ease-out;
  }
  @keyframes fadeIn {
    from { opacity: .5; transform: scale(.99); }
    to { opacity: 1; transform: scale(1); }
  }
}

/* 手机靠悬浮按钮加，顶栏那个只在宽屏出现，避免重复 */
#addBtnTop { display: none; }
@media (min-width: 900px) {
  #addBtnTop { display: inline-block; }
}

@media (max-width: 420px) {
  .topbar-right .btn.ghost { padding: 6px 8px; font-size: 12px; }
  .who-row { gap: 8px; }
  .who-avatar { width: 74px; height: 82px; }
  .empty-art { width: 150px; }
}