/* ============================================================
   番茄时钟 · 样式表
   手机端优先，桌面端居中放大
   ============================================================ */

/* ---------- 变量 ---------- */
:root {
  --bg:        #0f1116;
  --surface:   #171a21;
  --surface-2: #1e222b;
  --text:      #e8ecf1;
  --muted:     #8b95a5;
  --faint:     #5c6675;
  --line:      rgba(255, 255, 255, .08);
  --line-2:    rgba(255, 255, 255, .14);

  --radius:    18px;
  --radius-sm: 12px;

  --accent:      #ff6b5a;
  --accent-2:    #ff9f43;
  --accent-soft: rgba(255, 107, 90, .12);
  --glow:        rgba(255, 107, 90, .45);

  --ease: cubic-bezier(.2, .8, .3, 1);
}

/* 三种模式各一套配色，切换时整页过渡 */
body[data-mode="work"] {
  --accent:      #ff6b5a;
  --accent-2:    #ff9f43;
  --accent-soft: rgba(255, 107, 90, .12);
  --glow:        rgba(255, 107, 90, .45);
}
body[data-mode="short"] {
  --accent:      #3ddc97;
  --accent-2:    #7ef0c0;
  --accent-soft: rgba(61, 220, 151, .12);
  --glow:        rgba(61, 220, 151, .40);
}
body[data-mode="long"] {
  --accent:      #4ea8ff;
  --accent-2:    #7cc4ff;
  --accent-soft: rgba(78, 168, 255, .12);
  --glow:        rgba(78, 168, 255, .40);
}

/* ---------- 基础 ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB",
               "Source Han Sans SC", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  /* 计时器不该被误手势打断 */
  overflow-x: hidden;
  transition: background .5s var(--ease);
}

/* 顶部的模式光晕，跟随 accent 变色 */
body::before {
  content: "";
  position: fixed;
  inset: -30% 0 auto 0;
  height: 70vh;
  background: radial-gradient(ellipse at 50% 0%, var(--glow), transparent 62%);
  opacity: .28;
  pointer-events: none;
  transition: background .5s var(--ease);
  z-index: 0;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
svg { display: block; }

/* 键盘焦点环 */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ---------- 布局骨架 ---------- */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 430px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 22px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* ---------- 顶栏 ---------- */
.head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.head__brand { display: flex; align-items: center; gap: 9px; }

.head__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--glow);
  transition: background .4s var(--ease), box-shadow .4s var(--ease);
}

.head h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .4px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--muted);
  transition: color .2s, background .2s, transform .2s var(--ease);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { color: var(--text); background: var(--surface); }
.icon-btn:active { transform: scale(.92); }
.icon-btn--sm { width: 32px; height: 32px; }
.icon-btn--sm svg { width: 17px; height: 17px; }

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

.mode {
  padding: 9px 0;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  transition: color .25s, background .25s var(--ease);
}

.mode.is-active {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 4px 16px -4px var(--glow);
}

@media (hover: hover) {
  .mode:not(.is-active):hover { color: var(--text); background: var(--surface-2); }
}

/* ---------- 表盘 ---------- */
.dial {
  position: relative;
  width: min(76vw, 300px);
  aspect-ratio: 1 / 1;
  margin: 6px auto 0;
  flex-shrink: 0;
}

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

.ring__track {
  fill: none;
  stroke: var(--line);
  stroke-width: 13;
}

.ring__bar {
  fill: none;
  stroke: var(--accent);
  stroke-width: 13;
  stroke-linecap: round;
  filter: drop-shadow(0 0 10px var(--glow));
  transition: stroke .4s var(--ease), filter .4s var(--ease);
}

/* 暂停时环变暗，一眼看出没在跑 */
body.is-paused .ring__bar { opacity: .35; }

.dial__inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
}

.dial__time {
  font-size: clamp(48px, 16vw, 62px);
  font-weight: 300;
  letter-spacing: 1px;
  line-height: 1;
  /* 等宽数字，秒数跳动时宽度不抖 */
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.dial__label {
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 1.6px;
}

/* 最后 10 秒轻微脉冲 */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .55; }
}
body.is-ending .dial__time { animation: pulse 1s ease-in-out infinite; }

/* ---------- 进度圆点 ---------- */
.dots {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 10px;
}

.dots__item {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-2);
  transition: background .35s var(--ease), transform .35s var(--ease),
              box-shadow .35s var(--ease);
}

.dots__item.is-done {
  background: var(--accent);
  box-shadow: 0 0 10px var(--glow);
}

.dots__item.is-current { transform: scale(1.5); }

/* ---------- 控制按钮 ---------- */
.controls {
  width: 100%;
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  gap: 10px;
  align-items: stretch;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius);
  font-size: 14px;
  transition: transform .18s var(--ease), background .2s, color .2s,
              box-shadow .25s var(--ease), border-color .2s;
}

.btn svg { width: 17px; height: 17px; }

.btn--ghost {
  flex-direction: column;
  gap: 3px;
  min-height: 62px;
  font-size: 11.5px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
}
.btn--ghost:hover { color: var(--text); background: var(--surface-2); border-color: var(--line-2); }

.btn--primary {
  min-height: 62px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 2px;
  color: #fff;
  background: linear-gradient(140deg, var(--accent-2), var(--accent));
  box-shadow: 0 10px 28px -10px var(--glow);
}
.btn--primary:hover { box-shadow: 0 14px 34px -10px var(--glow); }

.btn:active { transform: scale(.97); }

/* ---------- 统计与提示 ---------- */
.stat {
  font-size: 13px;
  color: var(--muted);
}
.stat strong {
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: color .4s var(--ease);
}

.hint {
  margin-top: auto;
  padding-top: 8px;
  font-size: 11px;
  color: var(--faint);
  letter-spacing: .3px;
  text-align: center;
}

/* 触屏设备上隐藏键盘提示 */
@media (hover: none) and (pointer: coarse) {
  .hint { display: none; }
}

/* ---------- 设置面板 ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }

.sheet__mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade .25s var(--ease) both;
}

.sheet__body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--line-2);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .5);
  animation: slideUp .32s var(--ease) both;
  padding-bottom: env(safe-area-inset-bottom);
}

@keyframes fade { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(100%); } }

.sheet__grab {
  width: 38px;
  height: 4px;
  margin: 10px auto 0;
  border-radius: 999px;
  background: var(--line-2);
  flex-shrink: 0;
}

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px 6px;
  flex-shrink: 0;
}
.sheet__head h2 { font-size: 16px; font-weight: 600; }

.sheet__content {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 20px 24px;
}

.group + .group { margin-top: 22px; }

.group__title {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 1.4px;
  color: var(--faint);
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* 设置行 */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }

.row__label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 14.5px;
}

.row__label small {
  font-size: 11.5px;
  color: var(--faint);
  line-height: 1.45;
}

.row--toggle { cursor: pointer; }

/* 数值步进器 */
.stepper {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  flex-shrink: 0;
}

.stepper__btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  transition: background .18s, color .18s, transform .12s var(--ease);
}
.stepper__btn:hover { background: rgba(255, 255, 255, .07); color: var(--text); }
.stepper__btn:active { transform: scale(.88); }
.stepper__btn:disabled { opacity: .3; cursor: not-allowed; }
.stepper__btn:disabled:hover { background: none; color: var(--muted); }

.stepper__val {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  min-width: 54px;
  font-variant-numeric: tabular-nums;
}
.stepper__val b { font-size: 15.5px; font-weight: 600; }
.stepper__val i { font-size: 11px; font-style: normal; color: var(--faint); }

/* 开关 */
.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  cursor: pointer;
  transition: background .25s var(--ease), border-color .25s var(--ease);
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .25s var(--ease), background .25s var(--ease);
}

.switch:checked {
  background: var(--accent);
  border-color: transparent;
}
.switch:checked::after {
  transform: translateX(20px);
  background: #fff;
}

.btn--reset-all {
  width: 100%;
  margin-top: 20px;
  padding: 13px;
  font-size: 13.5px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.btn--reset-all:hover { color: var(--text); border-color: var(--line-2); }
.btn--reset-all:active { transform: scale(.98); }

/* ---------- 结束时的整屏柔光提示 ---------- */
.flash {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  background: radial-gradient(circle at 50% 42%, var(--glow), transparent 55%);
  animation: flashOut 1.1s var(--ease) both;
}
@keyframes flashOut {
  0%   { opacity: .75; }
  100% { opacity: 0; }
}

/* ---------- 桌面端微调 ---------- */
@media (min-width: 560px) {
  .app { gap: 24px; padding-top: 40px; }
  .dial { width: 310px; }
  .sheet__body {
    left: 50%;
    bottom: 50%;
    transform: translate(-50%, 50%);
    width: 100%;
    max-width: 420px;
    border-radius: 22px;
    border: 1px solid var(--line-2);
    padding-bottom: 0;
    animation: popIn .28s var(--ease) both;
  }
  @keyframes popIn {
    from { opacity: 0; transform: translate(-50%, 50%) scale(.96); }
  }
  .sheet__grab { display: none; }
}

/* 矮屏（横屏手机）压缩表盘 */
@media (max-height: 620px) {
  .dial { width: min(52vh, 240px); }
  .app { gap: 14px; }
}

/* ---------- 尊重系统的减少动效设置 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
