@import url("https://fonts.googleapis.com/css2?family=ZCOOL+XiaoWei&family=Noto+Sans+SC:wght@400;500;700&family=JetBrains+Mono:wght@400;500&display=swap");

:root {
  /* —— 色板：宣纸 + 墨 + 印泥 —— */
  --paper: #f3ede0;
  --paper-deep: #e8dfcb;
  --paper-line: #d9cdb0;
  --ink: #2a2420;
  --ink-soft: #6b6255;
  --ink-faint: #9c927e;
  --seal: #b23b2e;
  --seal-deep: #8c2a20;
  --bamboo: #5c6b47;
  --gold: #b8892b;
  --gold-glow: #e8c468;

  --font-display: "ZCOOL XiaoWei", "Noto Serif SC", serif;
  --font-body: "Noto Sans SC", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --radius: 10px;
  --shadow-card: 0 2px 0 var(--paper-line), 0 6px 16px rgba(42, 36, 32, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background-image: radial-gradient(
      circle at 20% 10%,
      rgba(178, 59, 46, 0.04),
      transparent 40%
    ),
    radial-gradient(circle at 85% 80%, rgba(92, 107, 71, 0.05), transparent 45%);
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* —— 顶部栏 —— */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(to bottom, var(--paper) 80%, transparent);
  backdrop-filter: blur(2px);
}

.brand {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 2px;
  color: var(--ink);
}

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 10px;
  background: var(--seal);
  color: var(--paper);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 2px 6px rgba(178, 59, 46, 0.35);
  transform: rotate(-2deg);
}

.streak-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold-glow);
}

/* —— 主体区域 —— */
main {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 18px 100px;
}

.view {
  display: none;
}
.view.active {
  display: block;
  animation: fade-in 0.25s ease;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ================= 签到页 ================= */

.qian-tube-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 0 10px;
}

.qian-tube {
  width: 120px;
  height: auto;
  filter: drop-shadow(0 8px 14px rgba(42, 36, 32, 0.18));
}

.draw-date {
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-faint);
}

.draw-btn {
  margin-top: 22px;
  padding: 14px 46px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 6px;
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 6px;
  position: relative;
  box-shadow: 0 4px 0 #14100d, 0 8px 16px rgba(0, 0, 0, 0.2);
  transition: transform 0.08s ease;
}
.draw-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #14100d, 0 3px 8px rgba(0, 0, 0, 0.2);
}
.draw-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.draw-btn::before,
.draw-btn::after {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: rgba(243, 237, 224, 0.35);
}
.draw-btn::before {
  left: 10px;
}
.draw-btn::after {
  right: 10px;
}

.today-hint {
  margin-top: 16px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.7;
}

/* —— 抽到的卡片区 —— */
.cards-row {
  margin-top: 26px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 14px;
}

.qian-card {
  position: relative;
  background: var(--paper-deep);
  border: 1px solid var(--paper-line);
  border-radius: var(--radius);
  padding: 16px 14px 14px;
  min-height: 150px;
  box-shadow: var(--shadow-card);
  opacity: 0;
  transform: translateY(14px) rotateX(-25deg);
  transform-origin: top center;
  animation: card-reveal 0.55s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

@keyframes card-reveal {
  to {
    opacity: 1;
    transform: none;
  }
}

.qian-card .cat {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--bamboo);
  letter-spacing: 1px;
}

.qian-card .name {
  margin-top: 6px;
  font-family: var(--font-display);
  font-size: 19px;
  color: var(--ink);
}

.qian-card .flavor {
  margin-top: 8px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-soft);
}

/* 印章：揭晓后盖上去的不规则朱红章 */
.seal-stamp {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 42px;
  height: 42px;
  background: var(--seal);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  clip-path: polygon(
    8% 2%, 22% 0%, 40% 4%, 58% 0%, 76% 3%, 94% 0%, 100% 16%,
    97% 34%, 100% 52%, 96% 70%, 100% 88%, 88% 100%, 70% 97%,
    52% 100%, 34% 96%, 16% 100%, 0% 84%, 3% 66%, 0% 48%,
    4% 30%, 0% 14%
  );
  opacity: 0;
  transform: scale(1.7) rotate(-14deg);
  animation: stamp-hit 0.35s cubic-bezier(0.3, 1.5, 0.4, 1) forwards;
  animation-delay: 0.4s;
  box-shadow: 0 1px 3px rgba(140, 42, 32, 0.5);
}

@keyframes stamp-hit {
  0% {
    opacity: 0;
    transform: scale(2.1) rotate(-18deg);
  }
  60% {
    opacity: 0.95;
  }
  100% {
    opacity: 0.92;
    transform: scale(1) rotate(-8deg);
  }
}

/* 隐藏款：旋转金色描边 + 呼吸光晕
   —— 之前用 filter:hue-rotate 直接套在整张卡片上，连卡片里的墨色文字也会跟着变色，
   看起来像色彩故障而不是"描边旋转"。改成用 ::before 单独做一层圆环，只转这一层。 */
.qian-card.hidden {
  position: relative;
  z-index: 0;
  background: var(--paper-deep);
  border: 2px solid transparent;
  animation: card-reveal 0.55s cubic-bezier(0.2, 0.8, 0.3, 1) forwards,
    glow-breathe 2.4s ease-in-out infinite;
}

.qian-card.hidden::before {
  content: "";
  position: absolute;
  inset: -2px;
  z-index: -1;
  border-radius: inherit;
  padding: 2px;
  background: conic-gradient(var(--gold), var(--gold-glow), var(--seal), var(--gold));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: spin-ring 5s linear infinite;
}

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

@keyframes glow-breathe {
  0%,
  100% {
    box-shadow: var(--shadow-card), 0 0 0px rgba(232, 196, 104, 0.4);
  }
  50% {
    box-shadow: var(--shadow-card), 0 0 22px rgba(232, 196, 104, 0.65);
  }
}

.qian-card.hidden .cat::before {
  content: "隐 · ";
  color: var(--gold);
}

/* ================= 图鉴页 ================= */

.collection-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 18px 0 20px;
}

.collection-head h2 {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0;
}

.collection-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
}

.category-filter {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 14px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--paper-line);
  scrollbar-width: none;
}

.category-filter::-webkit-scrollbar {
  display: none;
}

.category-chip {
  flex: 0 0 auto;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--paper-line);
  background: var(--paper-deep);
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 12.5px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.category-chip .count {
  margin-left: 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  opacity: 0.75;
}

.category-chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.timeline {
  position: relative;
  padding-left: 96px;
}

.timeline::before {
  content: "";
  position: absolute;
  left: 76px;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: var(--paper-line);
}

.timeline-day {
  position: relative;
  margin-bottom: 22px;
}

.timeline-date-badge {
  position: absolute;
  left: -90px;
  top: -3px;
  width: 70px;
  height: 54px;
}

.timeline-date-badge svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.timeline-dot {
  position: absolute;
  left: -20px;
  top: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--paper);
}

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

.timeline-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--paper-deep);
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.timeline-item:hover,
.timeline-item.open {
  background: var(--paper);
  border-color: var(--bamboo);
}

.timeline-item.hidden {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold) inset;
}

.timeline-item.hidden:hover,
.timeline-item.hidden.open {
  box-shadow: 0 0 0 1px var(--gold) inset, 0 0 12px rgba(232, 196, 104, 0.45);
}

/* 悬浮/点击后弹出的签文描述——纸片轻轻展开的感觉，而不是生硬的浏览器 title 提示 */
.item-popover {
  position: absolute;
  left: 8px;
  right: 8px;
  top: calc(100% + 6px);
  z-index: 20;
  background: var(--paper);
  border: 1px solid var(--paper-line);
  border-left: 3px solid var(--seal);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  box-shadow: var(--shadow-card);
  opacity: 0;
  transform: translateY(-4px) scale(0.97);
  transform-origin: top center;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.timeline-item.open .item-popover {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

@media (hover: hover) and (pointer: fine) {
  .timeline-item:hover .item-popover {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }
}

.item-popover::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 18px;
  width: 8px;
  height: 8px;
  background: var(--paper);
  border-left: 1px solid var(--paper-line);
  border-top: 1px solid var(--paper-line);
  transform: rotate(45deg);
}

.item-popover .empty-flavor {
  color: var(--ink-faint);
  font-style: italic;
}

.timeline-item .name {
  font-weight: 500;
}

.timeline-item .cat {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
}

.repeat-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-faint);
  background: var(--paper-line);
  border-radius: 999px;
  padding: 1px 7px;
  line-height: 1.5;
}

.milestone {
  position: relative;
  margin: 4px 0 22px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.milestone .timeline-dot {
  background: var(--gold);
}

.milestone-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px dashed var(--gold);
  border-radius: 999px;
  color: var(--gold);
  font-size: 12px;
  font-family: var(--font-mono);
}

.empty-state {
  margin-top: 60px;
  text-align: center;
  color: var(--ink-faint);
  font-size: 13px;
  line-height: 1.8;
}

/* ================= 设置页 ================= */

.settings-list {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-item {
  background: var(--paper-deep);
  border: 1px solid var(--paper-line);
  border-radius: var(--radius);
  padding: 16px;
}

.settings-item h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 16px;
}

.settings-item p {
  margin: 0 0 12px;
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.6;
}

.settings-item button,
.settings-item label.file-btn {
  display: inline-block;
  padding: 9px 18px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 6px;
  font-size: 13px;
}

.settings-item.danger {
  border-color: var(--seal);
}
.settings-item.danger button {
  background: var(--seal);
}

.settings-item input[type="file"] {
  display: none;
}

.settings-note {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--ink-faint);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%) translateY(10px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.update-banner {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%) translateY(10px);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 12px 10px 18px;
  border-radius: 999px;
  font-size: 12.5px;
  box-shadow: var(--shadow-card);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
}
.update-banner.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.update-banner button {
  background: var(--gold);
  color: var(--ink);
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

/* ================= 底部 Tab 栏 ================= */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--paper);
  border-top: 1px solid var(--paper-line);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 10;
}

.tabbar button {
  flex: 1;
  border: none;
  background: none;
  padding: 12px 0 10px;
  font-family: var(--font-body);
  font-size: 12.5px;
  color: var(--ink-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.tabbar button .glyph {
  font-family: var(--font-display);
  font-size: 18px;
  color: inherit;
}

.tabbar button.active {
  color: var(--seal);
}

/* ================= 无障碍 / 减少动效 ================= */

:focus-visible {
  outline: 2px solid var(--seal);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 380px) {
  .brand {
    font-size: 19px;
  }
  main {
    padding-left: 14px;
    padding-right: 14px;
  }
}
