:root {
  --bg: #0a0f24;
  --panel: #141d38;
  --line: rgba(125, 211, 252, 0.16);
  --accent: #7dd3fc;
  --text: #eaf1ff;
  --text-dim: rgba(234, 241, 255, 0.52);
  --btn-bg: linear-gradient(135deg, #56b8f5, #3b7be8);
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(90% 55% at 50% 0%, #1d2c55 0%, rgba(29, 44, 85, 0) 60%),
    var(--bg);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }

#scene {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  touch-action: manipulation;
}

#gear {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  right: 16px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: none;
  border: none;
  color: var(--text-dim);
  transition: color 0.2s;
}
#gear:hover, #gear:active { color: var(--text); }

#circle-wrap {
  position: relative;
  width: min(64vmin, 320px);
  aspect-ratio: 1;
}

#circle-wrap::before {
  content: "";
  position: absolute;
  inset: -16%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(125, 211, 252, 0.22), rgba(125, 211, 252, 0) 65%);
  filter: blur(14px);
  pointer-events: none;
}

#circle {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #d8f4ff 0%, #8edcff 32%, #4aa4e6 62%, #1d5c9c 100%);
  box-shadow:
    0 0 46px rgba(110, 190, 255, 0.4),
    0 0 110px rgba(80, 150, 255, 0.22);
  will-change: transform;
  transform: scale(0.6);
  transition: filter 0.25s;
}

body.paused #circle {
  box-shadow: 0 0 30px rgba(110, 190, 255, 0.2);
  filter: saturate(0.65) brightness(0.8);
}

#circle-text {
  position: absolute;
  inset: 28%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
}

#phase-label {
  font-size: clamp(17px, 5vmin, 24px);
  font-weight: 600;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: #0a2a4d;
}

#phase-count {
  font-size: clamp(14px, 4vmin, 18px);
  color: rgba(10, 42, 77, 0.72);
  font-variant-numeric: tabular-nums;
  min-height: 1.3em;
}

#timer {
  font-size: 15px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  min-height: 1.3em;
}

#hint {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 36px);
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 0.12em;
  min-height: 1.3em;
}

#backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 20, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 40;
}
#backdrop.open { opacity: 1; pointer-events: auto; }

#drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  max-width: 480px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  padding: 22px 24px calc(env(safe-area-inset-bottom, 0px) + 18px);
  transform: translateY(105%);
  transition: transform 0.3s ease-out;
}
#drawer.open { transform: translateY(0); }

#drawer h2 { font-size: 17px; margin-bottom: 18px; }
#drawer h3 { font-size: 12px; font-weight: 500; color: var(--text-dim); letter-spacing: 0.1em; margin-bottom: 10px; }
#drawer section { margin-bottom: 22px; }

#mode-options { display: grid; gap: 10px; }
.mode-option {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(125, 211, 252, 0.05);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.mode-option:hover { border-color: rgba(125, 211, 252, 0.4); }
.mode-option.selected { border-color: var(--accent); background: rgba(125, 211, 252, 0.13); }
.mode-option .name { font-size: 15px; font-weight: 600; white-space: nowrap; }
.mode-option .desc { font-size: 12px; color: var(--text-dim); text-align: right; }

.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1;
  padding: 10px 0;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(125, 211, 252, 0.05);
  color: var(--text-dim);
  font-size: 14px;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.seg button:hover { border-color: rgba(125, 211, 252, 0.4); }
.seg button.selected { border-color: var(--accent); background: rgba(125, 211, 252, 0.13); color: var(--text); }

.toggles { display: grid; gap: 4px; }
.toggles label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 4px;
  font-size: 15px;
  cursor: pointer;
}
.toggles input { width: 22px; height: 22px; accent-color: #4aa4e6; }

#drawer-done, #again {
  padding: 13px 0;
  border: none;
  border-radius: 999px;
  background: var(--btn-bg);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-indent: 0.1em;
}
#drawer-done { width: 100%; margin-top: 4px; }

#done-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(6, 10, 26, 0.66);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
#done-overlay.open { opacity: 1; pointer-events: auto; }

#done-card {
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 34px 52px 30px;
  border-radius: 22px;
  background: rgba(18, 27, 54, 0.85);
  border: 1px solid var(--line);
  transform: translateY(8px);
  transition: transform 0.4s;
}
#done-overlay.open #done-card { transform: none; }
#done-title { font-size: 24px; font-weight: 600; letter-spacing: 0.2em; text-indent: 0.2em; }
#done-detail { font-size: 14px; color: var(--text-dim); }
#again { padding: 12px 40px; margin-top: 14px; }
