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

:root {
  /* 深色（默认） */
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #252540;
  --text: #e8e8f0;
  --text2: #8888aa;
  --accent: #4f6df5;
  --accent2: #7c5cfc;
  --danger: #f55050;
  --success: #50c878;
  --border: #252540;
  --shadow: rgba(0,0,0,0.3);
  --radius: 12px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

[data-theme="light"] {
  --bg: #f5f5f9;
  --surface: #ffffff;
  --surface2: #eef0f6;
  --text: #1a1a2e;
  --text2: #707088;
  --accent: #4f6df5;
  --accent2: #7c5cfc;
  --danger: #e74c3c;
  --success: #2ecc71;
  --border: #e0e3ec;
  --shadow: rgba(60,70,120,0.08);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f5f9;
    --surface: #ffffff;
    --surface2: #eef0f6;
    --text: #1a1a2e;
    --text2: #707088;
    --border: #e0e3ec;
    --shadow: rgba(60,70,120,0.08);
  }
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'PingFang SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  transition: background 0.2s, color 0.2s;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* Pages */
.page {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
  padding-top: calc(var(--safe-top) + 8px);
  -webkit-overflow-scrolling: touch;
}

.page.active {
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  padding: 12px 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.header h1 {
  font-size: 28px;
  font-weight: 700;
}

.btn-icon {
  background: var(--surface);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Tab Bar */
.tab-bar {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 0;
  padding-bottom: calc(8px + var(--safe-bottom));
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 10px;
  cursor: pointer;
  transition: color 0.2s;
}

.tab-item.active {
  color: var(--accent);
}

.tab-item svg {
  width: 22px;
  height: 22px;
}

/* Home Page */
.home-hint {
  text-align: center;
  color: var(--text2);
  font-size: 14px;
  padding: 16px 0 12px;
}

.home-actions {
  margin-top: 16px;
  text-align: center;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
}

.btn-secondary:active {
  background: var(--surface2);
}

/* Timer Display (only when running) */
.timer-display {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 16px;
  margin: 8px 0 16px;
  text-align: center;
  border: 1px solid var(--border);
}

.timer-time {
  font-size: 48px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
}

.timer-activity {
  color: var(--text2);
  margin-top: 8px;
  font-size: 16px;
}

.timer-controls {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  justify-content: center;
}

/* Activity Grid */
.activity-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 4px 0;
}

.activity-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 8px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}

.activity-card:active {
  transform: scale(0.96);
  background: var(--surface2);
}

.activity-card .icon {
  font-size: 30px;
}

.activity-card .name {
  font-size: 13px;
  color: var(--text);
  text-align: center;
  font-weight: 500;
}

/* Buttons */
.btn {
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
}

.btn-pause {
  background: var(--surface2);
}

.btn-stop {
  background: var(--danger);
  color: white;
}

.btn-confirm {
  background: var(--accent);
  color: white;
}

.btn-cancel {
  background: var(--surface2);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-export, .btn-import {
  width: 100%;
  background: var(--surface2);
  margin-bottom: 12px;
}

.btn-add-activity {
  width: 100%;
  background: var(--surface);
  border: 1px dashed var(--text2);
  margin-top: 12px;
}

/* Stats */
.stats-tabs {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  width: 100%;
}

.tab {
  padding: 6px 16px;
  border: none;
  border-radius: 20px;
  background: var(--surface);
  color: var(--text2);
  font-size: 14px;
  cursor: pointer;
}

.tab.active {
  background: var(--accent);
  color: white;
}

.stats-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 16px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
}

.stat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.stat-header .icon {
  font-size: 24px;
}

.stat-header .info {
  flex: 1;
  min-width: 0;
}

.stat-header .name {
  font-size: 16px;
  font-weight: 500;
}

.stat-header .meta {
  font-size: 12px;
  color: var(--text2);
  margin-top: 2px;
}

.stat-header .hours {
  font-size: 20px;
  font-weight: 600;
}

.stat-header .hours small {
  font-size: 12px;
  color: var(--text2);
  font-weight: 400;
}

.progress-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

/* History */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
}

.history-date {
  font-size: 14px;
  color: var(--text2);
  padding: 8px 0 4px;
  font-weight: 500;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.history-item .icon {
  font-size: 20px;
}

.history-item .info {
  flex: 1;
  min-width: 0;
}

.history-item .name {
  font-size: 14px;
}

.history-item .note {
  font-size: 12px;
  color: var(--text2);
}

.history-item .duration {
  font-size: 14px;
  font-weight: 500;
}

.history-item .delete-btn {
  padding: 4px 8px;
  background: none;
  border: none;
  color: var(--danger);
  font-size: 18px;
  cursor: pointer;
  opacity: 0.6;
}

/* Settings */
.settings-content {
  padding-top: 8px;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section h2 {
  font-size: 16px;
  color: var(--text2);
  margin-bottom: 12px;
}

.setting-activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
}

.setting-activity-item .icon {
  font-size: 20px;
}

.setting-activity-item .name {
  flex: 1;
  font-size: 14px;
}

.setting-activity-item .goal {
  font-size: 12px;
  color: var(--text2);
}

.theme-options {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.theme-option {
  flex: 1;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.theme-option.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  z-index: 100;
  animation: fadeIn 0.2s;
}

.modal-content {
  width: 100%;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px;
  padding-bottom: calc(24px + var(--safe-bottom));
  animation: slideUp 0.3s;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-content h2 {
  font-size: 20px;
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  color: var(--text2);
  margin-bottom: 8px;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  -webkit-appearance: none;
}

.duration-input {
  display: flex;
  align-items: center;
  gap: 8px;
}

.duration-input input {
  width: 70px;
  text-align: center;
}

.duration-input span {
  color: var(--text2);
  font-size: 14px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.modal-actions .btn {
  flex: 1;
}

/* Icon/Color Picker */
.icon-picker, .color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.icon-option, .color-option {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--surface2);
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 20px;
}

.icon-option.selected, .color-option.selected {
  border-color: var(--accent);
}

.color-option {
  border-radius: 50%;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text2);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 12px;
}
