/* ---- 主题 ---- */
:root, [data-theme="strawberry"] {
  --bg: linear-gradient(160deg, #fff3f5 0%, #ffe3ec 45%, #fdf3e4 100%);
  --glass: rgba(255, 255, 255, 0.52); --border: rgba(255, 255, 255, 0.9);
  --text: #3b2f33; --muted: #8c7a80; --accent: #ec7598; --soft: rgba(236, 117, 152, 0.14);
  --shadow: rgba(80, 40, 60, 0.08); --input: rgba(255, 255, 255, 0.6);
  color-scheme: light;
}
[data-theme="matcha"] {
  --bg: linear-gradient(160deg, #f6f2e6 0%, #e4efd9 50%, #f5ecdd 100%);
  --glass: rgba(255, 255, 255, 0.5); --border: rgba(255, 255, 255, 0.88);
  --text: #33362b; --muted: #7f8472; --accent: #5f9a6b; --soft: rgba(95, 154, 107, 0.14);
}
[data-theme="soda"] {
  --bg: linear-gradient(160deg, #eef8ff 0%, #dcecff 50%, #f4efff 100%);
  --glass: rgba(255, 255, 255, 0.5); --border: rgba(255, 255, 255, 0.9);
  --text: #2b3340; --muted: #76829a; --accent: #4f8fe0; --soft: rgba(79, 143, 224, 0.14);
}
[data-theme="night"] {
  --bg: linear-gradient(160deg, #1c1f33 0%, #2a2442 55%, #182a3a 100%);
  --glass: rgba(255, 255, 255, 0.08); --border: rgba(255, 255, 255, 0.16);
  --text: #f1eef8; --muted: #a39fb8; --accent: #b9a2e6; --soft: rgba(185, 162, 230, 0.18);
  --shadow: rgba(0, 0, 0, 0.3); --input: rgba(255, 255, 255, 0.08);
  color-scheme: dark;
}

/* ---- 基础 ---- */
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  color: var(--text); background: #fff1f3; -webkit-tap-highlight-color: transparent;
}
[data-theme="night"] body { background: #1c1f33; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
.hidden { display: none !important; }

.bg { position: fixed; inset: 0; z-index: -2; background: var(--bg); }
.bg-img { position: fixed; inset: 0; z-index: -1; background-size: cover; background-position: center; }
.bg-img.on::after { content: ""; position: absolute; inset: 0; background: var(--glass); opacity: 0.35; }

.content { max-width: 960px; margin: 0 auto; padding: 36px 16px calc(120px + env(safe-area-inset-bottom)); }

.glass {
  background: var(--glass);
  border: 1px solid var(--border);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 4px 18px var(--shadow);
}

h1.title { font-size: 30px; font-weight: 700; margin: 0; letter-spacing: 1px; }
.subtitle { font-size: 14px; color: var(--muted); margin: 6px 0 0; }
.section-title { font-size: 17px; font-weight: 700; margin: 24px 0 12px; display: flex; align-items: center; gap: 8px; }
.section-title .count { font-size: 12px; font-weight: 400; color: var(--muted); }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.pill { border-radius: 999px; padding: 9px 16px; font-size: 14px; text-align: center; }
.btn { display: block; width: 100%; border-radius: 999px; padding: 12px 0; font-size: 15px; font-weight: 600; text-align: center; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-danger { color: #e5484d; }
.btn:disabled { opacity: 0.6; }

.search-box { display: flex; align-items: center; gap: 8px; border-radius: 999px; padding: 0 16px; height: 48px; margin-top: 18px; }
.search-box svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
.search-box input { flex: 1; min-width: 0; border: none; outline: none; background: transparent; font-size: 15px; }
input::placeholder { color: var(--muted); }

.segments { display: flex; border-radius: 999px; padding: 4px; margin-top: 16px; }
.seg { flex: 1; text-align: center; font-size: 14px; padding: 8px 0; border-radius: 999px; color: var(--muted); border: 1px solid transparent; }
.seg.on { background: var(--soft); color: var(--text); font-weight: 600; border-color: var(--border); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip.on, .shop.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip .n { font-size: 11px; opacity: 0.7; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.shop { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 11px 6px; }

.empty-box { border-radius: 18px; padding: 36px 16px; text-align: center; color: var(--muted); font-size: 14px; border-style: dashed; margin-top: 16px; line-height: 1.8; }

/* ---- 卡片 ---- */
.card { border-radius: 18px; padding: 7px; cursor: pointer; transition: transform .15s; }
.card:hover { transform: translateY(-2px); }
.cover { width: 100%; aspect-ratio: 1; border-radius: 13px; object-fit: cover; display: block; background: var(--soft); }
.cover-empty { display: grid; place-items: center; font-size: 40px; }
.cover.cutout { object-fit: contain; padding: 8px; }
.card .info { padding: 7px 4px 3px; }
.card .shop-name { font-size: 12px; color: var(--muted); }
.card .name { font-size: 15px; font-weight: 700; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.card .bottom { display: flex; align-items: center; justify-content: space-between; margin-top: 7px; min-height: 28px; gap: 6px; }
.card .price { font-size: 17px; font-weight: 700; }
.card .price.small { font-size: 13px; }
.mini-btn { border-radius: 999px; padding: 5px 13px; font-size: 12px; }
.mini-btn.btn-accent { padding: 6px 14px; }
.card { position: relative; }
.card.retired .cover { filter: grayscale(0.7); opacity: 0.7; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.card .badge { position: absolute; top: 14px; left: 14px; z-index: 1; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(0, 0, 0, 0.55); color: #fff; }
.card .check { position: absolute; top: 14px; right: 14px; z-index: 1; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; background: rgba(255, 255, 255, 0.8); color: transparent; border: 2px solid var(--muted); }
.card .check.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.nth { font-size: 12px; font-weight: 400; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--text); display: inline-flex; align-items: center; gap: 4px; }
.card .tag:hover { background: var(--accent); color: #fff; }
.notes { margin: 8px 0 0; font-size: 12px; line-height: 1.5; }
.notes dt { color: var(--muted); margin-top: 4px; }
.notes dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.notes .none { color: var(--muted); }

/* ---- 底部导航 ---- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  width: min(560px, calc(100% - 24px)); height: 66px; padding: 5px;
  display: flex; border-radius: 33px; z-index: 10;
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border-radius: 28px; color: var(--muted); font-size: 12px; border: 1px solid transparent; }
.tab svg { width: 23px; height: 23px; }
.tab.on { background: var(--soft); border-color: var(--border); color: var(--text); font-weight: 600; }

/* ---- 弹窗 / 表单 ---- */
dialog { border: none; padding: 0; color: var(--text); background: transparent; max-width: none; max-height: none; }
dialog::backdrop { background: rgba(20, 10, 20, 0.35); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.sheet { width: min(520px, 100%); height: 100%; margin: 0 auto; }
.sheet-inner { min-height: 100%; background: var(--bg); padding: 20px 16px 40px; }
@media (min-width: 600px) {
  .sheet { height: auto; max-height: calc(100% - 48px); margin: 24px auto; border-radius: 24px; overflow: auto; }
}
.back { font-size: 15px; padding: 4px 0; margin-bottom: 8px; }

.photo { margin-top: 16px; border-radius: 20px; aspect-ratio: 1; max-height: 340px; width: 100%; overflow: hidden; display: grid; place-items: center; color: var(--muted); }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo img.cutout { object-fit: contain; padding: 16px; background: var(--soft); }
.photo-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 32px; }
.photo-empty span { font-size: 14px; }
.link-btn { font-size: 13px; color: var(--muted); }
.right .link-btn + .link-btn { margin-left: 14px; }

/* ---- 裁剪 ---- */
.crop-dlg { margin: auto; }
.crop-body { width: min(520px, calc(100vw - 24px)); border-radius: 24px; padding: 16px; background: var(--bg); text-align: center; }
.crop-title { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
/* 四周留 14px，框贴着图片边时角上的圆点也不会被裁掉 */
.crop-stage { display: inline-block; max-width: 100%; overflow: hidden; border-radius: 12px; padding: 14px; touch-action: none; user-select: none; -webkit-user-select: none; }
.crop-inner { position: relative; }
.crop-stage img { display: block; max-width: 100%; max-height: 60vh; }
.crop-box { position: absolute; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6); outline: 2px solid #fff; cursor: move; }
.crop-box::before, .crop-box::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.crop-box::before { border-left: 1px solid rgba(255, 255, 255, 0.4); border-right: 1px solid rgba(255, 255, 255, 0.4); left: 33.3%; right: 33.3%; }
.crop-box::after { border-top: 1px solid rgba(255, 255, 255, 0.4); border-bottom: 1px solid rgba(255, 255, 255, 0.4); top: 33.3%; bottom: 33.3%; }
.handle { position: absolute; width: 26px; height: 26px; z-index: 1; }
.handle::after { content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); left: 6px; top: 6px; }
.handle[data-h="nw"] { left: -13px; top: -13px; cursor: nwse-resize; }
.handle[data-h="ne"] { right: -13px; top: -13px; cursor: nesw-resize; }
.handle[data-h="sw"] { left: -13px; bottom: -13px; cursor: nesw-resize; }
.handle[data-h="se"] { right: -13px; bottom: -13px; cursor: nwse-resize; }
.crop-actions { display: flex; gap: 8px; margin-top: 14px; }
.crop-actions .pill { flex: 1; }
.right { text-align: right; margin-top: 6px; }

.form { border-radius: 20px; padding: 4px 16px; margin-top: 14px; }
.field { display: flex; align-items: center; gap: 10px; padding: 13px 0; border-bottom: 1px solid var(--soft); font-size: 15px; }
.field:last-child { border-bottom: none; }
.field.column { flex-direction: column; align-items: stretch; gap: 6px; }
.field > span.label { width: 72px; flex-shrink: 0; color: var(--muted); font-size: 14px; }
.field input:not([type="range"]) { flex: 1; min-width: 0; border: none; outline: none; background: transparent; font-size: 15px; padding: 2px 0; }
.field.column > span { color: var(--muted); font-size: 14px; }
.field textarea { border: none; outline: none; background: transparent; font: inherit; font-size: 15px; resize: vertical; padding: 2px 0; }
.label-row { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 14px; }
.toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.toggle { border-radius: 999px; padding: 6px 14px; font-size: 14px; background: var(--input); border: 1px solid var(--soft); }
.toggle.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.tag-input { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tag-input #fTags { display: contents; }
.tag-input .tag { font-size: 13px; padding: 4px 6px 4px 10px; }
.tag-input .tag button { font-size: 14px; line-height: 1; color: var(--muted); padding: 0 2px; }
.field .tag-input input { min-width: 120px; }
.hint { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.field a, .field .act { color: var(--accent); font-size: 13px; text-decoration: none; flex-shrink: 0; }
.field select { flex: 1; min-width: 0; border: none; outline: none; background: transparent; font-size: 15px; padding: 2px 0; }
.field .toggles + input { flex: 1; min-width: 0; border: none; outline: none; background: transparent; font-size: 14px; }
.muted { color: var(--muted); font-size: 12px; font-weight: 400; }
.field .act.muted { color: var(--muted); }
.unit { margin-top: 12px; }
.unit.is-retired { opacity: 0.85; }
.unit.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 4px 18px var(--shadow); } }
.unit-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 0 2px; font-size: 14px; }
.err { color: #e5484d; font-size: 13px; margin-top: 10px; text-align: center; }
.err:empty { display: none; }

/* ---- 展柜：位置、批量移动 ---- */
.head-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.pill.small { padding: 6px 14px; font-size: 13px; }
.select-bar {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 11;
  bottom: calc(env(safe-area-inset-bottom) + 86px); width: min(560px, calc(100% - 24px));
  display: flex; align-items: center; gap: 8px; border-radius: 999px; padding: 8px 10px 8px 16px; font-size: 13px;
  background: var(--bg);
}
.select-bar #selCount { flex-shrink: 0; }
body.selecting .content { padding-bottom: calc(190px + env(safe-area-inset-bottom)); }
.select-bar select { flex: 1; min-width: 0; border: 1px solid var(--soft); border-radius: 999px; padding: 5px 8px; background: var(--input); font-size: 13px; }

/* ---- 我的日历 ---- */
.month-head { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }
.month-head .pill { padding: 6px 16px; font-size: 16px; }
.month { border-radius: 20px; padding: 10px; margin-top: 10px; }
.week, .mgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.week { font-size: 12px; color: var(--muted); padding-bottom: 6px; }
.mday { aspect-ratio: 1 / 1.1; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 14px; border: 1px solid transparent; }
.mday i { font-style: normal; font-size: 11px; line-height: 1; min-height: 11px; }
.mday.today span { color: var(--accent); font-weight: 700; }
.mday.on { background: var(--soft); border-color: var(--border); }
.legend { font-size: 12px; color: var(--muted); margin: 10px 2px 0; }
.event { display: flex; align-items: center; gap: 10px; width: 100%; border-radius: 16px; padding: 12px 14px; margin-bottom: 8px; font-size: 14px; text-align: left; }
.event .icon { font-size: 18px; }
.event .muted { margin-left: auto; }

/* ---- 设置 ---- */
.tiles { margin-top: 20px; grid-template-columns: 1fr 1fr; }
.tile { border-radius: 24px; height: 104px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font-size: 16px; font-weight: 700; }
.tile .emoji { font-size: 24px; font-weight: 400; }
.panel { border-radius: 24px; padding: 18px 16px; margin-top: 14px; }
.panel-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; }
.themes { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.theme { border-radius: 16px; padding: 10px; display: flex; align-items: center; gap: 10px; text-align: left; }
.theme.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--soft); }
.swatch { width: 36px; height: 36px; border-radius: 11px; flex-shrink: 0; border: 1px solid var(--border); }
.theme-name { font-size: 15px; }
.theme-desc { font-size: 11px; color: var(--muted); margin-top: 2px; }
.line { display: flex; justify-content: space-between; align-items: center; padding: 11px 0; font-size: 14px; border-bottom: 1px solid var(--soft); width: 100%; }
.line .value { color: var(--muted); }
.link-btn.danger { color: #e5484d; }
.loc-add { display: flex; gap: 8px; margin-top: 10px; }
.loc-add input { flex: 1; min-width: 0; border: 1px solid var(--soft); border-radius: 999px; padding: 7px 14px; background: var(--input); outline: none; font-size: 14px; }
.stats { display: flex; gap: 8px; margin-top: 16px; }
.stat { flex: 1; border-radius: 16px; padding: 11px 0; display: flex; flex-direction: column; align-items: center; }
.stat b { font-size: 17px; color: var(--accent); }
.stat span { font-size: 11px; color: var(--muted); margin-top: 2px; }
.info-body { padding: 20px; border-radius: 20px; width: min(420px, calc(100vw - 32px)); background: var(--bg); line-height: 1.7; font-size: 14px; }
.info-body h3 { margin: 0 0 8px; }
