/* ============ 基础 ============ */
:root {
  color-scheme: light dark;

  /* 日间：浅底深字 */
  --bg: #f4f4f8;
  --card: #ffffff;
  --card2: #f5f6fa;      /* 输入框等"凹槽" */
  --raise: #ffffff;
  --chip: #ebedf4;       /* 分段控件、小按钮等"胶囊" */
  --line: #e4e4ec;
  --ring: #c8c8d6;
  --text: #15151d;
  --dim: #55556a;
  --faint: #6f6f85;
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, .3);
  --accent-glow: rgba(79, 70, 229, .28);
  --on-accent: #ffffff;
  --danger: #d92d20;
  --ok: #0f9d4f;
  --scrim: rgba(18, 18, 28, .38);
  --shadow: 0 1px 2px rgba(18, 18, 28, .05), 0 6px 18px rgba(18, 18, 28, .06);
  --shadow-lg: 0 14px 40px rgba(18, 18, 28, .16);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --rail: 64px;          /* 时刻表时间列宽，勾选圆圈正好落在时刻线上 */
}

/* 夜间：跟随系统。所有次要文字都抬亮了一档，暗底上不再糊成一片 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b12;
    --card: #17171f;
    --card2: #1e1e29;
    --raise: #1b1b26;
    --chip: #202030;
    --line: #2c2c3c;
    --ring: #44445a;
    --text: #f4f4f9;
    --dim: #a7a7ba;
    --faint: #8c8ca4;
    --accent: #6366f1;
    --accent-soft: rgba(99, 102, 241, .38);
    --accent-glow: rgba(99, 102, 241, .38);
    --on-accent: #ffffff;
    --danger: #ff6157;
    --ok: #30d158;
    --scrim: rgba(0, 0, 0, .6);
    --shadow: none;
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }

/* ============ 布局 ============ */
.app {
  min-height: 100dvh;
  padding: calc(var(--safe-t) + 20px) 20px calc(var(--safe-b) + 96px);
  max-width: 560px;
  margin: 0 auto;
}

/* ============ 顶部日期 ============ */
.topbar {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 6px;
  margin-bottom: 26px;
}

.nav {
  width: 40px; height: 40px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--dim);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.nav:active { background: var(--card); color: var(--text); }

.datelabel { text-align: center; }

.d-main {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  width: 100%;
}
.d-main span:first-child { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.d-main .week { font-size: 13px; color: var(--dim); }

.d-sub {
  margin: 2px 0 6px;
  font-size: 12.5px;
  color: var(--dim);
  min-height: 15px;
}

.bar {
  height: 3px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
  transition: width .35s cubic-bezier(.2, .8, .2, 1);
}

/* ============ 区块 ============ */
.block { margin-bottom: 28px; }

.sec {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--dim);
  margin: 0 0 10px;
  padding-left: 2px;
}
.sec .count { color: var(--dim); font-weight: 400; letter-spacing: 0; }

.sec-add {
  margin-left: auto;
  width: 28px; height: 28px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: var(--chip);
  color: var(--dim);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.sec-add:active { background: var(--accent); color: var(--on-accent); }

.empty {
  color: var(--dim);
  font-size: 14px;
  margin: 6px 0 0;
  padding-left: 2px;
}
.empty[hidden] { display: none; }

/* ============ 左右滑动删除 ============ */
.swipe {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  margin-bottom: 8px;
  list-style: none;
}

.under {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: flex-end;
  align-items: stretch;
  background: var(--danger);
  border-radius: 16px;
}
.under button {
  width: 92px;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.face {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 16px;
  transition: transform .22s cubic-bezier(.2, .8, .2, 1);
  will-change: transform;
  z-index: 1;
}
.swipe.open .face { transform: translateX(-92px); }

/* ============ 时刻表 ============ */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}
.timeline::before {
  content: "";
  position: absolute;
  left: calc(var(--rail) + 21px);   /* 落在勾选圆圈的中心上 */
  top: 16px;
  bottom: 16px;
  width: 1.5px;
  background: linear-gradient(180deg, var(--line), transparent);
}

.ev .face {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  align-items: stretch;
}

.ev .t {
  padding: 15px 8px 15px 0;
  text-align: right;
  position: relative;
  min-width: 0;
}
.ev .t b {
  display: block;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.ev .t i {
  display: block;
  font-style: normal;
  font-size: 11px;
  color: var(--faint);
  margin-top: 1px;
}

.ev .c {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: center;
  padding: 14px 16px 14px 8px;
  min-width: 0;
}
/* 完成态：只把文字压暗，卡片本身保持不透明，否则会透出底下的红色删除层 */
.ev.done .t b { color: var(--faint); }
.ev.done .title { color: var(--faint); text-decoration: line-through; }
.ev.done .meta { opacity: .65; }

/* 现在 */
.now {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  align-items: center;
  margin: 2px 0 6px;
  list-style: none;
}
.now .t {
  text-align: right;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--danger);
  padding-right: 6px;
}
.now .l {
  position: relative;
  height: 1px;
  background: linear-gradient(90deg, var(--danger), transparent);
}
.now .l::before {
  content: "";
  position: absolute;
  left: 18px; top: -3px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--danger);
}

/* ============ 待办 ============ */
.todo-list { list-style: none; margin: 0; padding: 0; }

.todo .face {
  display: grid;
  grid-template-columns: 26px 1fr;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}

.check {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--ring);
  background: transparent;
  padding: 0;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  flex: none;
}
.check:active { transform: scale(.88); }
.todo.done .check,
.ev.done .check {
  background: var(--accent) center / 13px no-repeat
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'><path d='M4 12.5 9.5 18 20 6.5'/></svg>");
  border-color: var(--accent);
}
.todo.done .title { color: var(--faint); text-decoration: line-through; }

/* 日程和待办共用同一个勾选框 */

.title { font-size: 15px; line-height: 1.35; word-break: break-word; }

.meta {
  font-size: 12px;
  color: var(--dim);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.meta a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-soft);
  padding-bottom: 1px;
}
.meta .note {
  color: var(--dim);
  display: block;
  width: 100%;
  margin-top: 2px;
  white-space: pre-wrap;
  word-break: break-word;
}

.tip {
  margin-top: 4px;
  font-size: 12px;
  color: var(--faint);
  text-align: center;
}

/* ============ 悬浮按钮 ============ */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--safe-b) + 22px);
  width: 58px; height: 58px;
  border: 0;
  border-radius: 20px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 30px var(--accent-glow);
  transition: transform .12s, box-shadow .15s;
  z-index: 10;
}
.fab:active { transform: scale(.93); box-shadow: 0 4px 14px var(--accent-glow); }

/* ============ 编辑面板 ============ */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: fade .16s ease-out;
}
.sheet[hidden] { display: none; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.sheet-card {
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--raise);
  box-shadow: var(--shadow-lg);
  border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(var(--safe-b) + 18px);
  animation: rise .26s cubic-bezier(.2, .8, .2, 1);
}
@keyframes rise { from { transform: translateY(100%) } to { transform: none } }

.grab {
  width: 38px; height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 0 auto 16px;
}

/* 类型切换 */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--chip);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 18px;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--dim);
  font-size: 14px;
  font-weight: 600;
  padding: 9px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.seg button.on { background: var(--accent); color: var(--on-accent); }

/* 时间 */
.times {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.times[hidden] { display: none; }

.times label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
}
.times label span { font-size: 13px; color: var(--dim); }
.times input[type="time"] {
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding: 0;
  outline: none;
  min-width: 0;
  flex: 1;
}
.times input[type="time"]::-webkit-date-and-time-value { text-align: right; }

/* 字段 */
.field {
  width: 100%;
  display: block;
  margin-bottom: 10px;
  padding: 13px 14px;
  font-size: 16px;               /* <16px 时 iOS 会自动放大 */
  color: var(--text);
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  resize: none;
  font-family: inherit;
  transition: border-color .15s;
}
.field::placeholder { color: var(--faint); }
.field:focus { border-color: var(--accent); }
textarea.field { line-height: 1.45; }

.loc { display: flex; gap: 8px; align-items: stretch; margin-bottom: 10px; }
.loc .field { flex: 1; min-width: 0; margin-bottom: 0; }

.mini {
  flex: 0 0 46px;
  height: auto;
  border: 1px solid var(--line);
  background: var(--card2);
  border-radius: 12px;
  font-size: 17px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color .15s, background .15s;
}
.mini:active { border-color: var(--accent); }
.mini.ok { border-color: var(--ok); background: rgba(48, 209, 88, .12); }

.actions {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 10px;
  margin-top: 8px;
}
.ghost, .primary, .danger {
  border: 0;
  border-radius: 14px;
  padding: 15px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.ghost { background: var(--chip); color: var(--dim); }
.primary { background: var(--accent); color: var(--on-accent); }
.primary:active, .ghost:active { opacity: .82; }

.danger {
  width: 100%;
  margin-top: 10px;
  background: transparent;
  color: var(--danger);
  font-weight: 500;
  font-size: 15px;
}
.danger[hidden] { display: none; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 24px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 40px);
  background: var(--raise);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 30px var(--shadow-lg);
  z-index: 60;
  animation: pop .18s ease-out;
}
.toast[hidden] { display: none; }

.toast-btn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px) } to { opacity: 1; transform: translateX(-50%) } }

/* ============ 给 Netlify 免费版徽标让位 ============ */
/* 它会在页面末尾注入一个 <script data-nf-variant>，右下角浮一个小徽标，
   正好压住悬浮按钮。:has() 只在这个脚本存在时才生效，换别家托管不受影响。 */
body:has(script[data-nf-variant]) .fab {
  bottom: calc(var(--safe-b) + 88px);
}
body:has(script[data-nf-variant]) .toast {
  bottom: calc(var(--safe-b) + 90px);
}

/* ============ 适配 ============ */
@media (display-mode: standalone) {
  .app { padding-top: calc(var(--safe-t) + 12px); }
}

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