:root {
  --bg: #121316;
  --card-bg: #1c1e24;
  --card-border: #2e323b;
  --text: #f0f2f5;
  --text-muted: #8b92a0;
  --accent: #f59e0b;
  --accent-glow: rgba(245, 158, 11, 0.25);
  --btn-bg: #2a2e39;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}

body.mode-pet {
  --accent: #ec4899;
  --accent-glow: rgba(236, 72, 153, 0.25);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
  transition: background-color 0.3s;
}

.container {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.header-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.app-title { font-size: 1.1rem; font-weight: 700; }

.mode-toggle {
  display: flex;
  background: #121316;
  border-radius: 999px;
  padding: 4px;
  border: 1px solid var(--card-border);
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn.active { background: var(--accent); color: #121316; box-shadow: 0 2px 10px var(--accent-glow); }

.timer-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 28px;
  padding: 32px 24px;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.bubble-box {
  min-height: 90px;
  background: #14161a;
  border: 1px dashed var(--accent);
  border-radius: 16px;
  padding: 14px 18px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  transition: all 0.3s;
  position: relative;
}

.bubble-box::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 8px 8px 0;
  border-style: solid;
  border-color: #14161a transparent transparent;
}

.timer-display {
  font-size: clamp(3rem, 12vw, 4rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 0 0 24px var(--accent-glow);
  margin: 10px 0 26px;
  user-select: none;
}

.controls { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.btn {
  border: none;
  outline: none;
  padding: 14px 26px;
  border-radius: 16px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  touch-action: manipulation;
}

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

.btn-primary {
  background: var(--accent);
  color: #121316;
  box-shadow: 0 4px 15px var(--accent-glow);
  flex: 1;
  max-width: 220px;
  justify-content: center;
}

.btn-secondary { background: var(--btn-bg); color: var(--text); border: 1px solid var(--card-border); }
.btn-stop { background: #ef4444; color: white; box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3); }

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.modal-overlay.active { display: flex; }

.modal-card {
  background: #1c1e24;
  border: 2px solid var(--accent);
  border-radius: 24px;
  padding: 28px 24px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 10px 40px var(--accent-glow);
}

@keyframes popIn { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-title { font-size: 1.4rem; font-weight: 800; color: var(--accent); margin-bottom: 12px; }
.modal-body { font-size: 1.05rem; line-height: 1.6; color: var(--text); margin-bottom: 24px; word-break: break-word; }

.modal-btn {
  width: 100%;
  background: var(--accent);
  color: #121316;
  padding: 14px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 1rem;
  border: none;
  cursor: pointer;
}

.history-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 24px 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.calendar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.calendar-title { font-weight: 700; font-size: 1.05rem; }
.calendar-nav { display: flex; gap: 8px; align-items: center; }

.nav-btn {
  background: #121316;
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 4px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.week-day { color: var(--text-muted); font-size: 0.8rem; font-weight: 600; padding: 6px 0; }

.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #15171b;
  border: 1px solid transparent;
  cursor: pointer;
  position: relative;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.cal-day.empty { background: transparent; cursor: default; }
.cal-day.today { border-color: var(--text-muted); }
.cal-day.has-data { background: rgba(245, 158, 11, 0.15); border-color: var(--accent); color: var(--accent); font-weight: 700; }
body.mode-pet .cal-day.has-data { background: rgba(236, 72, 153, 0.15); }

.cal-day .dot-badge { font-size: 0.62rem; color: var(--text-muted); margin-top: 2px; line-height: 1; }
.cal-day.has-data .dot-badge { color: var(--accent); }

.day-details {
  margin-top: 18px;
  background: #14161a;
  border-radius: 14px;
  padding: 14px;
  font-size: 0.9rem;
  border: 1px solid var(--card-border);
  display: none;
  line-height: 1.6;
}
.day-details.active { display: block; }

.total-summary { margin-top: 16px; text-align: center; font-size: 0.85rem; color: var(--text-muted); }
.total-highlight { color: var(--accent); font-weight: 700; font-size: 1.05rem; }

#confetti-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  pointer-events: none;
  z-index: 999;
}

.key-gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 2000;
}

.key-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 32px 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  line-height: 1.7;
}

.key-title { font-size: 1.3rem; font-weight: 800; margin-bottom: 14px; color: var(--accent); }
.key-card code { background: #14161a; padding: 2px 8px; border-radius: 6px; color: var(--accent); word-break: break-all; }
.key-hint { color: var(--text-muted); font-size: 0.85rem; margin-top: 12px; }
