:root {
  --bg: #0f1626;
  --panel: #18223a;
  --panel-2: #1f2b48;
  --line: #2a3a5e;
  --txt: #e8edf7;
  --muted: #93a4c4;
  --accent: #5b8cff;
  --accent-2: #7c5cff;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --study: #5b8cff;
  --review: #7c5cff;
  --exercise: #34d399;
  --rest: #64748b;
  --exam: #f87171;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 800px at 80% -10%, #1c2b4d 0%, var(--bg) 55%);
  color: var(--txt);
  font: 15px/1.55 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

header {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: rgba(15, 22, 38, 0.7); backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 20;
}
header .logo { font-size: 18px; font-weight: 700; }
header .logo span { color: var(--accent); }
header .who { color: var(--muted); font-size: 13px; }
header .spacer { flex: 1; }
.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 13px; color: var(--txt); }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: #5b2b34; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.layout { display: grid; grid-template-columns: 280px 1fr 340px; gap: 16px; padding: 16px; }
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.panel h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); letter-spacing: .5px; }
.panel + .panel { margin-top: 14px; }

.countdowns { display: flex; flex-direction: column; gap: 8px; }
.cd { background: var(--panel-2); border-radius: 9px; padding: 10px 12px; }
.cd .d { font-size: 22px; font-weight: 700; color: var(--warn); }
.cd .lbl { font-size: 12px; color: var(--muted); }
.cd.overdue .d { color: var(--bad); }

.profile-mini { font-size: 13px; color: var(--muted); }
.profile-mini b { color: var(--txt); }
.subj-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 20px;
  padding: 3px 10px; font-size: 12px; }
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }

.ai-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.ai-bar .btn { flex: 0 0 auto; }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.day-col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-height: 120px; }
.day-col .dh { padding: 8px 10px; font-size: 13px; font-weight: 600; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; }
.day-col .dh .today { color: var(--accent); }
.day-col .dh .add { color: var(--muted); border: none; background: none; font-size: 16px; line-height: 1; }
.day-col .dh .add:hover { color: var(--accent); }
.blocks { padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.block { border-radius: 8px; padding: 6px 8px; font-size: 12px; border-left: 3px solid var(--study); background: var(--panel-2); position: relative; }
.block .tm { color: var(--muted); font-size: 11px; }
.block .tt { display: flex; justify-content: space-between; gap: 6px; }
.block .del { opacity: 0; color: var(--bad); border: none; background: none; font-size: 13px; padding: 0; }
.block:hover .del { opacity: .8; }
.block.k-study { border-left-color: var(--study); }
.block.k-review { border-left-color: var(--review); }
.block.k-exercise { border-left-color: var(--exercise); }
.block.k-rest { border-left-color: var(--rest); }
.block.k-exam { border-left-color: var(--exam); }
.empty-day { color: var(--muted); font-size: 12px; padding: 10px; text-align: center; }

.task { display: flex; gap: 8px; align-items: flex-start; padding: 8px; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: none; }
.task input[type=checkbox] { margin-top: 3px; accent-color: var(--accent); }
.task .body { flex: 1; }
.task .ttl { font-size: 14px; }
.task.done .ttl { text-decoration: line-through; color: var(--muted); }
.task .meta { font-size: 11px; color: var(--muted); }
.task .pri-1 { color: var(--bad); } .task .pri-3 { color: var(--muted); }
.task .rm { color: var(--muted); border: none; background: none; font-size: 13px; }
.task .rm:hover { color: var(--bad); }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.field textarea { min-height: 70px; resize: vertical; }
.row { display: flex; gap: 10px; } .row .field { flex: 1; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none;
  align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-bg.show { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  width: 540px; max-width: 100%; max-height: 88vh; overflow: auto; padding: 20px; }
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal .sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.modal .acts { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.subj-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.subj-row input { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.subj-row select { width: 110px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.subj-row .rm { color: var(--bad); border: none; background: none; }

.rationale { background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; padding: 10px;
  font-size: 13px; color: var(--muted); margin: 10px 0; }
.preview .week { margin-top: 10px; }
.advice { white-space: pre-wrap; font-size: 14px; line-height: 1.7; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 16px; z-index: 80; opacity: 0; transition: opacity .25s; }
.toast.show { opacity: 1; } .toast.bad { border-color: var(--bad); color: var(--bad); }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--muted);
  border-top-color: var(--accent); border-radius: 50%; animation: sp .8s linear infinite; vertical-align: -2px; }
@keyframes sp { to { transform: rotate(360deg); } }
.loading-overlay { text-align: center; padding: 30px; color: var(--muted); }

/* reminder banner + reflection history */
.reminder { background: linear-gradient(135deg, rgba(91,140,255,.12), rgba(124,92,255,.12));
  border: 1px solid #2c3a63; border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; font-size: 13.5px; line-height: 1.7; }
.reminder .rh { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.reminder .rh b { color: var(--accent); }
.reminder .body { white-space: pre-wrap; }
.reminder .ai { color: var(--txt); }
.reminder .pill { background: var(--panel-2); border: 1px solid var(--line); border-radius: 20px; padding: 2px 9px; font-size: 11px; }
.reminder .pill.ok { color: var(--ok); border-color: #1f4a3a; }
.reminder .pill.warn { color: var(--warn); border-color: #4a3a1f; }
.refl-history { display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow: auto; }
.refl-item { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer; font-size: 12.5px; }
.refl-item:hover { border-color: var(--accent); }
.refl-item .d { font-weight: 600; color: var(--txt); }
.refl-item .s { color: var(--muted); display: block; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* today focus + timer */
.focus-layout { display: grid; grid-template-columns: 1fr 300px; gap: 16px; }
@media (max-width: 620px) { .focus-layout { grid-template-columns: 1fr; } }
.focus-list { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.focus-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.focus-row:last-child { border-bottom: none; }
.focus-row:hover { background: var(--panel-2); }
.focus-row.active { background: rgba(91,140,255,.12); border-left: 3px solid var(--accent); padding-left: 9px; }
.focus-row input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; }
.focus-row .fr-tm { font-size: 12px; color: var(--muted); width: 110px; flex: 0 0 auto; }
.focus-row .fr-tt { flex: 1; font-size: 14px; }
.focus-row.done .fr-tt { text-decoration: line-through; color: var(--muted); }
.focus-row .fr-dur { font-size: 11px; color: var(--muted); }
.focus-empty { padding: 24px; text-align: center; color: var(--muted); }
.focus-timer { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 18px; text-align: center; position: sticky; top: 0; }
.timer-name { font-size: 13px; color: var(--muted); min-height: 36px; line-height: 1.4; max-width: 200px; margin: 0 auto; text-align: center; }
.timer-clock { font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 2px; color: var(--txt); }

/* Pomodoro-style circular countdown with glassmorphism + glow */
.focus-timer { background: rgba(24, 34, 58, .75); border: 1px solid var(--line); border-radius: 24px; padding: 22px; text-align: center; }
.focus-timer.running .ring-wrap { filter: drop-shadow(0 0 18px rgba(91, 140, 255, .35)); animation: breathe 3s ease-in-out infinite; }
.timer-clock.tick { animation: tickPop 0.18s ease-out; }
@keyframes tickPop {
  0% { transform: scale(1.12); color: var(--accent); text-shadow: 0 0 16px var(--accent); }
  100% { transform: scale(1); color: var(--txt); text-shadow: none; }
}
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.015); }
}
.ring-wrap { position: relative; width: 240px; height: 240px; margin: 0 auto 18px; display: flex; align-items: center; justify-content: center; }
.progress-ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring-dot { position: absolute; top: 50%; left: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: #fff; box-shadow: 0 0 14px 4px rgba(91,140,255,.85); pointer-events: none; transform: translate(-108px) rotate(0deg); transform-origin: 6px 6px; transition: transform 0.1s linear; }
.progress-ring circle { fill: none; stroke-width: 12; stroke-linecap: round; }
.ring-bg { stroke: var(--line); opacity: .35; }
.ring-progress { stroke-dasharray: 678.584; stroke-dashoffset: 678.584; transition: stroke-dashoffset 0.1s linear; filter: url(#glow); }
.focus-timer.ringing .ring-progress { stroke: var(--bad); animation: ringPulse .7s ease-in-out infinite; }
@keyframes ringPulse { 0%,100% { stroke-width:12; } 50% { stroke-width:16; } }
.ring-text { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 180px; height: 180px; border-radius: 50%; background: radial-gradient(circle at 50% 0%, rgba(91,140,255,.12), transparent 55%); }
.ring-text::before { content:""; position:absolute; inset:0; border-radius:50%; background: conic-gradient(from 180deg, transparent 0deg, rgba(124,92,255,.08) 120deg, transparent 240deg); animation: shimmer 4s linear infinite; }
@keyframes shimmer { to { transform: rotate(360deg); } }
.timer-acts { display: flex; gap: 10px; justify-content: center; }
.timer-acts .btn { flex: 1; padding: 10px 12px; border-radius: 12px; font-weight: 600; }
.timer-acts .btn.primary { box-shadow: 0 0 14px rgba(91,140,255,.35); }
.timer-status { min-height: 22px; font-size: 12px; color: var(--muted); margin-top: 12px; }
.auto-next { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 14px; justify-content: center; }
.auto-next input { accent-color: var(--accent); width: 15px; height: 15px; }
.summary-md { white-space: pre-wrap; line-height: 1.7; font-size: 14px; }
.summary-md h2 { color: var(--accent); margin: 14px 0 6px; font-size: 16px; }
.summary-md h2:first-child { margin-top: 0; }

.uuid-row { display: flex; gap: 8px; }
.uuid-row input, .uuid-row select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.uuid-row input[readonly] { color: var(--muted); }
.uuid-row select { flex: 1; color: var(--txt); }

@media (max-width: 760px) {
  .uuid-row { flex-direction: column; }
  .uuid-row .btn { width: 100%; }
}

/* === mobile / touch适配 ==================================================== */
@media (max-width: 760px) {
  /* 周视图：7 列改为可横向滑动，保留"一周概览"的体感 */
  .week {
    grid-template-columns: repeat(7, 132px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    gap: 6px;
  }
  .day-col { min-width: 132px; }
  /* 块删除按钮在触屏上常显（无 hover），并放大点击区 */
  .block .del { opacity: .65; padding: 2px 4px; }
  .block { padding: 7px 8px; }

  /* 头部允许换行、收窄；隐藏次要文字 */
  header { padding: 10px 12px; flex-wrap: wrap; gap: 8px 12px; }
  header .logo { font-size: 16px; }
  header .who { display: none; }

  /* 主布局：单列、收紧间距 */
  .layout { padding: 10px; gap: 12px; }
  .panel { padding: 12px; }

  /* AI 按钮条：换行、按钮等宽更易点 */
  .ai-bar { gap: 8px; }
  .ai-bar .btn { padding: 8px 11px; font-size: 14px; }

  /* 表单多列字段在小屏堆叠，避免挤 */
  .row { flex-direction: column; gap: 0; }
  .row .field { width: 100%; }

  /* 模态框：占满宽度、收紧内边距 */
  .modal-bg { padding: 10px; }
  .modal { width: 100% !important; padding: 16px; border-radius: 14px; }
  .modal .acts { flex-wrap: wrap; }
  .modal .acts .btn { flex: 1 1 auto; }

  /* 今日执行：计时器取消 sticky，放列表下方，圆环适度缩小 */
  .focus-timer { position: static; padding: 18px 12px; }
  .ring-wrap { width: 210px; height: 210px; }
  .progress-ring { width: 210px; height: 210px; }
  .ring-text { width: 150px; height: 150px; }
  .ring-dot { width: 10px; height: 10px; margin: -5px 0 0 -5px; transform-origin: 5px 5px; }
  .timer-clock { font-size: 38px; }
  .focus-row { padding: 12px; }
  .focus-row input[type=checkbox] { width: 22px; height: 22px; }
  .focus-list { max-height: 260px; }

  /* 倒计时/任务/反思触控更友好 */
  .task { padding: 10px 6px; }
  .task input[type=checkbox] { width: 20px; height: 20px; }
  .refl-item, .cd { padding: 12px; }
}
@media (max-width: 380px) {
  .week { grid-template-columns: repeat(7, 118px); }
  .day-col { min-width: 118px; }
  .ring-wrap { width: 180px; height: 180px; }
  .progress-ring { width: 180px; height: 180px; }
  .ring-text { width: 130px; height: 130px; }
  .ring-dot { width: 8px; height: 8px; margin: -4px 0 0 -4px; transform-origin: 4px 4px; }
  .timer-clock { font-size: 34px; }
}