:root {
  --bg: linear-gradient(135deg, #eef2ff, #e0fbfc);
  --text: #0f172a;
  --muted: #475569;
  --card: rgba(255, 255, 255, 0.75);
  --glass: rgba(255, 255, 255, 0.3);
  --border: rgba(15, 23, 42, 0.08);
  --brand: #6366f1;
  --accent: #06b6d4;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  --popover: rgba(255, 255, 255, 0.85);
  --c1: #6366f1;
  --c2: #22c55e;
  --c3: #f59e0b;
  --c4: #64748b;
}

:root.dark {
  --bg: linear-gradient(135deg, #0b1020, #0d1b2a);
  --text: #e5e7eb;
  --muted: #9ca3af;
  --card: rgba(17, 24, 39, 0.65);
  --glass: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --brand: #8b5cf6;
  --accent: #22d3ee;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --popover: rgba(17, 24, 39, 0.85);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

/* === 全局防选中处理（App 化体验） === */
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  
  /* 全局禁止选中，消灭蓝底白字 */
  user-select: none; 
  -webkit-user-select: none; 
}

/* 保护输入框，确保可以打字和选择文本 */
input, textarea, select {
  user-select: auto;
  -webkit-user-select: auto;
}
/* ==================== */

/* 等宽字体，防止数字跳动时宽度闪烁 */
.time-box span, 
.pomo-time, 
.percent, 
.date,
.popover-header {
  font-variant-numeric: tabular-nums;
  font-family: "DIN Alternate", "SF Pro Display", -apple-system, "Helvetica Neue", Arial, sans-serif;
}

.container { max-width: 1100px; padding: 24px; margin: 0 auto; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.topbar h1 { margin: 0; font-size: clamp(22px, 4vw, 32px); letter-spacing: -0.01em; font-weight: 600; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn { appearance: none; border: 1px solid var(--border); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 12px; cursor: pointer; box-shadow: var(--shadow); transition: transform 0.2s ease, box-shadow 0.2s ease; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 12px 35px rgba(0, 0, 0, 0.12); }
.btn-mini { padding: 6px 10px; border-radius: 10px; }
.btn-outline { background: transparent; }
.danger { color: #ef4444; border-color: #ef4444; }

.input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--text); transition: border-color 0.2s ease; }
.input:focus { outline: none; border-color: var(--brand); }
.input.slim { padding: 8px 10px; }
.link { color: var(--brand); text-decoration: none; margin-left: 6px; }

.hero-card { padding: 28px; border-radius: 20px; background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.glass:before { content: ""; position: absolute; inset: -120px -160px auto auto; width: 320px; height: 320px; background: radial-gradient(closest-side, var(--glass), transparent 70%); transform: rotate(25deg); }

/* =========================================
  倒计时核心 UI & 动画区域
========================================= */
.countdown { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 10px 0 8px; flex-wrap: wrap; }
.time-box { 
  display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 90px; padding: 10px 10px 6px; border-radius: 16px; background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow); 
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.time-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.12);
}

/* 渐变数字与动画基础设置 */
.time-box span { 
  font-size: clamp(44px, 10vw, 72px); font-weight: 800; letter-spacing: 0; 
  background: linear-gradient(135deg, var(--brand), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: inline-block; /* 必须保留，支持 transform 动画 */
}

/* 拦截 JS 添加的类名，触发数字跳动动画 */
.time-box span.num-animate {
  animation: tickPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

/* 定义“滑入 + 心跳缩放”物理质感动画 */
@keyframes tickPop {
  0% { opacity: 0; transform: translateY(-20px) scale(0.85); }
  50% { opacity: 1; transform: translateY(2px) scale(1.05); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.time-box small { opacity: 0.8; margin-top: -6px; }

/* 冒号对齐与呼吸灯效果 */
.colon { 
  font-size: clamp(28px, 6vw, 40px); 
  opacity: 0.6; 
  font-weight: 600; 
  padding-bottom: 12px; 
  animation: colonBlink 2s ease-in-out infinite;
}
@keyframes colonBlink {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 0.2; }
}
/* ========================================= */

.progress-wrap { position: relative; width: 160px; height: 160px; margin: 18px auto; }
.ring { width: 160px; height: 160px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(0, 0, 0, 0.08); stroke-width: 12; }
:root.dark .ring-bg { stroke: rgba(255, 255, 255, 0.12); }
.ring-fg { fill: none; stroke: var(--brand); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset 0.3s ease; }
.progress-info { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.percent { font-size: 28px; font-weight: 700; }
.sub { font-size: 12px; opacity: 0.8; margin-top: -4px; }

/* 优化：弱化底部的日期信息 */
.meta { 
  display: flex; 
  gap: 16px; 
  justify-content: center; 
  flex-wrap: wrap; 
  color: var(--muted); 
  margin-top: 18px; /* 拉开和上方进度环的距离 */
  font-size: 13px;  /* 缩小字号 */
  opacity: 0.65;    /* 降低透明度，让它变“安静” */
}

.grid { margin-top: 22px; display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 860px) { .grid { grid-template-columns: 1fr 1fr; } }

/* 优化：让底部卡片变成弹性布局，填补空白 */
.card { 
  padding: 18px; 
  border-radius: 16px; 
  background: var(--card); 
  border: 1px solid var(--border); 
  box-shadow: var(--shadow); 
  
  /* 开启上下弹性排版 */
  display: flex;
  flex-direction: column;
}

/* 优化：让寄语文字和待办列表自动撑开中间的空间，把按钮挤到最下面 */
.card p#quote, .card ul.todo { 
  flex: 1; 
  margin-bottom: 16px; 
}

.footer { margin-top: 20px; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); }

/* Compact Calendar & Popover */
.popover { position: absolute; right: 0; top: 48px; z-index: 50; background: var(--popover); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 10px; min-width: 320px; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.popover.compact { min-width: 620px; }
.popover-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-weight: 600; letter-spacing: -0.01em; }
.popover-header.wrap { flex-wrap: wrap; }
.popover-header .left, .popover-header .right { display: flex; gap: 8px; align-items: center; }

.legend { display: flex; gap: 10px; align-items: center; margin: 4px 0 6px; }
.pill { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 2px; vertical-align: middle; }
.pill.c1 { background: var(--c1); } .pill.c2 { background: var(--c2); } .pill.c3 { background: var(--c3); } .pill.c4 { background: var(--c4); }

.cal-grid.pro.small { display: grid; grid-template-columns: 48px repeat(7, 1fr); gap: 5px; }
.cal-grid .dow { text-align: center; font-weight: 600; opacity: 0.7; font-size: 12px; }
.cal-grid .wlabel { display: flex; align-items: center; justify-content: center; opacity: 0.6; font-size: 12px; }
.cal-grid .cell { background: var(--card); border: 1px solid var(--border); border-radius: 10px; min-height: 70px; position: relative; padding: 4px 4px 24px; overflow: hidden; transition: border-color 0.2s ease; }
.cal-grid .cell:hover { border-color: var(--brand); }
.cal-grid .cell.muted { opacity: 0.5; }
.cal-grid .date { position: absolute; top: 4px; left: 6px; font-weight: 700; font-size: 12px; }
.cal-grid .festival { position: absolute; top: 4px; right: 6px; font-size: 11px; opacity: 0.75; }
.cal-grid .lunar { position: absolute; top: 20px; left: 6px; font-size: 11px; opacity: 0.8; }
.cal-grid .today { outline: 2px solid var(--brand); outline-offset: -2px; }
.cal-grid .events { position: absolute; left: 4px; right: 4px; bottom: 4px; display: flex; flex-direction: column; gap: 3px; }

.event-pill { border-radius: 8px; padding: 1px 6px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-pill.c1 { background: rgba(99, 102, 241, 0.18); border: 1px solid rgba(99, 102, 241, 0.5); }
.event-pill.c2 { background: rgba(34, 197, 94, 0.18); border: 1px solid rgba(34, 197, 94, 0.5); }
.event-pill.c3 { background: rgba(245, 158, 11, 0.18); border: 1px solid rgba(245, 158, 11, 0.5); }
.event-pill.c4 { background: rgba(100, 116, 139, 0.18); border: 1px solid rgba(100, 116, 139, 0.5); }
.event-pill.more { background: transparent; border: 1px dashed var(--border); }

/* Dialogs */
dialog { border: none; border-radius: 14px; padding: 0; background: transparent; }
dialog::backdrop { background: rgba(0, 0, 0, 0.15); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.dialog-card { background: var(--card); border: 1px solid var(--border); padding: 24px; border-radius: 14px; min-width: min(92vw, 500px); box-shadow: var(--shadow); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.dialog-card .row { display: flex; gap: 10px; margin-bottom: 12px; }
.dialog-card .row .half { flex: 1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---- Pomodoro (已恢复横向对齐) ---- */
.pomo-time { margin-top: 8px; text-align: center; }
.pomo-state { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 16px; }
.pomo-controls, .pomo-controls.center { display: flex; justify-content: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.pomo-form { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: center; }
.pomo-form label { display: flex; flex-direction: column; align-items: center; }
.pomo-actions { display: flex; gap: 10px; align-items: center; }

/* ---- Todo & Quotes (已恢复横向对齐) ---- */
.quote-actions { display: flex; justify-content: flex-end; margin-top: 12px; }
.todo { list-style: none; padding: 0; margin: 12px 0; }
.todo li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; }

/* 新增：让文字占据所有的剩余空间，这样就能把删除按钮死死地推到最右边 */
.todo li span { flex: 1; word-break: break-all; }

/* 修改：将 16px 改成 18px 让点按更舒服，并加上了主题色 accent-color */
.todo li input[type="checkbox"] { margin: 0; width: 18px; height: 18px; cursor: pointer; accent-color: var(--brand); }

.todo-actions { display: flex; gap: 8px; align-items: center; width: 100%; margin-top: 12px; }
.todo-actions .input { flex: 1; margin: 0; }
.todo-actions .btn { white-space: nowrap; }

.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* 番茄钟结束闪烁效果 */
#pomo-countdown.flash .time-box span { animation: pomoFlash 0.6s linear infinite; }
@keyframes pomoFlash {
  0%, 100% { color: var(--brand); text-shadow: 0 2px 8px rgba(99, 102, 241, 0.45); }
  25% { color: var(--c2); text-shadow: 0 2px 8px rgba(34, 197, 94, 0.45); }
  50% { color: var(--c3); text-shadow: 0 2px 8px rgba(245, 158, 11, 0.45); }
  75% { color: #ef4444; text-shadow: 0 2px 8px rgba(239, 68, 68, 0.45); }
}

/* =========================================
   📱 手机端专属适配 (响应式修复) - 优化整合版
========================================= */
@media (max-width: 600px) {
  
  /* --- 1. 顶部标题与按钮区优化 (3列2行排列) --- */
  .topbar {
    flex-direction: column;
    align-items: stretch; /* 占满全宽 */
    gap: 16px; 
    margin-bottom: 20px;
  }
  
  .topbar h1 {
    text-align: center; 
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 强制分为等宽的 3 列 */
    gap: 8px; /* 按钮之间的间距 */
    width: 100%;
  }

  .top-actions .btn {
    padding: 8px 4px; /* 减小左右内边距 */
    font-size: 13px; /* 稍微缩小字号 */
    width: 100%;
    display: flex;
    justify-content: center; /* 让图标和文字在按钮内居中 */
    align-items: center;
    gap: 4px; /* 如果你有图标+文字，控制它们的间距 */
    white-space: nowrap; /* 强制文字不换行 */
  }

  /* --- 2. 倒计时数字卡片排版优化 (平分宽度，防止挤压) --- */
  .countdown {
    flex-wrap: nowrap;
    gap: 4px; /* 保持极简间距 */
    width: 100%;
    padding: 0 4px; /* 左右稍微留白，防止极端情况下贴边 */
  }

  .time-box {
    min-width: 0; /* 关键：必须清空桌面端的 min-width: 90px，允许子元素缩小 */
    flex: 1; /* 关键：让四个卡片平分可用空间 */
    max-width: 75px; /* 限制最大宽度，防止在大屏手机上显得太扁 */
    padding: 10px 2px 6px; /* 左右 padding 调小，给文字留出呼吸空间 */
    border-radius: 12px;
  }

  .time-box span {
    font-size: clamp(22px, 6vw, 36px); 
  }

  .time-box small {
    font-size: 11px;
    margin-top: 2px;
  }

  .colon {
    font-size: clamp(18px, 4vw, 24px);
    padding-bottom: 8px;
    margin: 0; /* 移除之前的负边距，避免冒号和卡片重叠 */
    display: flex;
    align-items: center;
    justify-content: center;
  }
}