/* ============================================================
   番茄时钟 · 样式表
   主题色由 body[data-mode] 上的 CSS 变量驱动，切换模式时
   整个界面的强调色会平滑过渡。
   ============================================================ */

/* ---------- 1. 变量与主题 ---------- */
:root {
  --bg:            #12151c;
  --bg-soft:       #1a1f29;
  --surface:       rgba(255, 255, 255, .045);
  --surface-hover: rgba(255, 255, 255, .09);
  --border:        rgba(255, 255, 255, .09);
  --border-strong: rgba(255, 255, 255, .16);

  --text:          #eef2f7;
  --text-dim:      #8d99ab;
  --text-faint:    #5e6a7c;

  --radius-sm: 10px;
  --radius:    16px;
  --radius-lg: 24px;

  --ease: cubic-bezier(.22, .8, .3, 1);
  --ring-circumference: 703.72; /* 2 * π * 112，仅作回退，JS 会重算 */
}

/* 专注 · 番茄红 */
body[data-mode="focus"] {
  --accent:      #ff6b5e;
  --accent-2:    #ffa24b;
  --accent-soft: rgba(255, 107, 94, .16);
  --accent-glow: rgba(255, 107, 94, .30);
}
/* 短休息 · 薄荷绿 */
body[data-mode="shortBreak"] {
  --accent:      #3ddc97;
  --accent-2:    #4ec0e8;
  --accent-soft: rgba(61, 220, 151, .16);
  --accent-glow: rgba(61, 220, 151, .28);
}
/* 长休息 · 静谧蓝 */
body[data-mode="longBreak"] {
  --accent:      #5b8dff;
  --accent-2:    #a78bfa;
  --accent-soft: rgba(91, 141, 255, .16);
  --accent-glow: rgba(91, 141, 255, .30);
}

/* ---------- 2. 基础重置 ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px calc(28px + env(safe-area-inset-bottom));

  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB",
               system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background-color .5s var(--ease);
}

/* 顶部随主题色变化的柔光 */
body::before {
  content: "";
  position: fixed;
  inset: -20% -20% auto -20%;
  height: 90vh;
  background: radial-gradient(ellipse at 50% 0%, var(--accent-glow) 0%, transparent 62%);
  opacity: .55;
  filter: blur(30px);
  pointer-events: none;
  transition: background .6s var(--ease);
  z-index: 0;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
kbd {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: .82em;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

/* ---------- 3. 布局骨架 ---------- */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

/* ---------- 4. 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text);
}

.brand-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 14px var(--accent-glow);
  transition: background .5s var(--ease), box-shadow .5s var(--ease);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: color .2s, background .2s, transform .2s var(--ease);
}
.icon-btn:hover { color: var(--text); background: var(--surface-hover); transform: rotate(35deg); }
.icon-btn:active { transform: scale(.94); }

/* ---------- 5. 模式切换 ---------- */
.tabs {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}

/* 滑动的高亮块 */
.tab-glider {
  position: absolute;
  top: 4px;
  left: 4px;
  height: calc(100% - 8px);
  width: calc((100% - 8px) / 3);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 16px var(--accent-glow);
  transition: transform .38s var(--ease), background .5s var(--ease), box-shadow .5s var(--ease);
  will-change: transform;
}
.tab-glider[data-index="1"] { transform: translateX(100%); }
.tab-glider[data-index="2"] { transform: translateX(200%); }

.tab {
  position: relative;
  z-index: 1;
  padding: 9px 4px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: .5px;
  color: var(--text-dim);
  transition: color .28s var(--ease);
}
.tab:hover { color: var(--text); }
.tab.is-active { color: #10131a; font-weight: 700; }

/* ---------- 6. 表盘 ---------- */
.dial {
  position: relative;
  width: min(74vw, 288px);
  aspect-ratio: 1;
  margin: 4px auto 0;
  border-radius: 50%;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .35s var(--ease);
}
.dial:hover  { transform: scale(1.018); }
.dial:active { transform: scale(.985); }
.dial:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }

/* 运行时的呼吸光晕 */
.dial::after {
  content: "";
  position: absolute;
  inset: -6%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 68%);
  opacity: 0;
  transition: opacity .6s var(--ease);
  pointer-events: none;
}
body.is-running .dial::after { opacity: .5; animation: breathe 4.6s ease-in-out infinite; }

@keyframes breathe {
  0%, 100% { transform: scale(1);    opacity: .38; }
  50%      { transform: scale(1.05); opacity: .62; }
}

.ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);   /* 让进度从 12 点方向开始 */
  overflow: visible;
}

/* SVG 渐变端点跟随主题色 */
.ring .stop-a { stop-color: var(--accent);   transition: stop-color .5s var(--ease); }
.ring .stop-b { stop-color: var(--accent-2); transition: stop-color .5s var(--ease); }

.ring-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 13;
}

.ring-progress {
  fill: none;
  stroke: url(#ringGradient);
  stroke-width: 13;
  stroke-linecap: round;
  stroke-dasharray: var(--ring-circumference);
  stroke-dashoffset: 0;         /* JS 直接改这个值 */
  filter: drop-shadow(0 0 9px var(--accent-glow));
  transition: filter .5s var(--ease);
}

/* 表盘中央文字 */
.dial-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  pointer-events: none;
}

.time {
  font-size: clamp(46px, 15vw, 60px);
  font-weight: 300;
  letter-spacing: .5px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  color: var(--text);
  transition: color .3s var(--ease);
}
body.is-running .time { color: #fff; }

.status {
  font-size: 12.5px;
  letter-spacing: 2.5px;
  color: var(--text-faint);
  transition: color .3s var(--ease);
}
body.is-running .status { color: var(--accent); }

/* 本轮进度圆点 */
.dots {
  display: flex;
  gap: 6px;
  margin-top: 3px;
}
.dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border-strong);
  transition: background .35s var(--ease), transform .35s var(--ease),
              box-shadow .35s var(--ease);
}
.dots i.is-done {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  transform: scale(1.15);
}

/* ---------- 7. 控制按钮 ---------- */
.controls {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr;
  align-items: center;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .5px;
  transition: transform .18s var(--ease), background .25s, color .25s,
              box-shadow .25s, border-color .25s;
}
.btn:active { transform: scale(.95); }

.btn-ghost {
  padding: 11px 10px;
  font-size: 13px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-primary {
  padding: 15px 20px;
  font-size: 16px;
  color: #10131a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px var(--accent-glow);
}
.btn-primary:hover {
  box-shadow: 0 10px 30px var(--accent-glow);
  filter: brightness(1.06);
}

/* ---------- 8. 统计 ---------- */
.stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px 8px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.stat b {
  font-size: 21px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat span {
  font-size: 11.5px;
  letter-spacing: 1px;
  color: var(--text-faint);
}
.stat-divider {
  width: 1px;
  height: 26px;
  background: var(--border);
}

.hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: .5px;
  margin-top: -12px;
}

/* ---------- 9. 设置面板 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 10, 14, .68);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in .22s var(--ease);
}
.overlay[hidden] { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 380px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px 22px 18px;
  border-radius: var(--radius-lg);
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
  animation: pop-in .3s var(--ease);
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(14px) scale(.96); }
  to   { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-head h2 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 2px;
}
.modal-head .icon-btn:hover { transform: rotate(90deg); }

.field-group + .field-group { margin-top: 22px; }
.field-group h3 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--text-faint);
  margin-bottom: 11px;
}

/* 数字输入行 */
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.field:last-child { border-bottom: none; }
.field label {
  font-size: 14px;
  color: var(--text-dim);
}
.field input {
  width: 84px;
  padding: 8px 11px;
  font: inherit;
  font-size: 14px;
  text-align: center;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
  transition: border-color .2s, box-shadow .2s;
  -moz-appearance: textfield;
}
.field input::-webkit-outer-spin-button,
.field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* 开关 */
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-dim);
  transition: color .2s;
}
.switch:last-child { border-bottom: none; }
.switch:hover { color: var(--text); }

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch i {
  position: relative;
  flex: none;
  width: 44px;
  height: 25px;
  border-radius: 999px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  transition: background .28s var(--ease), border-color .28s var(--ease);
}
.switch i::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--text-faint);
  transform: translateY(-50%);
  transition: transform .28s var(--ease), background .28s var(--ease);
}
.switch input:checked + i {
  background: var(--accent);
  border-color: transparent;
}
.switch input:checked + i::after {
  transform: translate(19px, -50%);
  background: #10131a;
}
.switch input:focus-visible + i {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.modal-foot {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}
.modal-foot .btn { flex: 1; }
.modal-foot .btn-primary { padding: 12px 18px; font-size: 15px; }
.modal-foot .btn-ghost { padding: 12px 18px; font-size: 13px; }

/* ---------- 10. 完成提示浮层 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  z-index: 60;
  transform: translate(-50%, 20px);
  padding: 13px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .5px;
  color: #10131a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 34px var(--accent-glow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s var(--ease), transform .3s var(--ease);
}
.toast[hidden] { display: block; }        /* 用透明度控制显隐，保留过渡 */
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 11. 小屏适配 ---------- */
@media (max-width: 380px) {
  .app { gap: 20px; }
  .stats { padding: 13px 4px; }
  .stat b { font-size: 18px; }
  .btn-ghost { font-size: 12px; padding: 10px 6px; }
  .hint { display: none; }
}

@media (max-height: 680px) {
  .hint { display: none; }
  .app { gap: 18px; }
}

/* ---------- 12. 无障碍：尊重减弱动效偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .dial:hover, .dial:active { transform: none; }
}
