:root {
  --bg: #fafafa;
  --bg-elevated: #ffffff;
  --bg-muted: #f2f2f2;
  --text: #111111;
  --text-secondary: #555555;
  --text-tertiary: #888888;
  --border: #e0e0e0;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --positive: #16a34a;
  --positive-soft: rgba(22, 163, 74, 0.1);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.05);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --bg-elevated: #141414;
    --bg-muted: #1a1a1a;
    --text: #f0f0f0;
    --text-secondary: #a0a0a0;
    --text-tertiary: #666666;
    --border: #2a2a2a;
    --accent: #3b82f6;
    --accent-soft: rgba(59, 130, 246, 0.15);
    --positive: #22c55e;
    --positive-soft: rgba(34, 197, 94, 0.15);
    --warning: #f59e0b;
    --warning-soft: rgba(245, 158, 11, 0.15);
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.2);
  }
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-elevated: #141414;
  --bg-muted: #1a1a1a;
  --text: #f0f0f0;
  --text-secondary: #a0a0a0;
  --text-tertiary: #666666;
  --border: #2a2a2a;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --positive: #22c55e;
  --positive-soft: rgba(34, 197, 94, 0.15);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.15);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.2);
}

[data-theme="light"] {
  --bg: #fafafa;
  --bg-elevated: #ffffff;
  --bg-muted: #f2f2f2;
  --text: #111111;
  --text-secondary: #555555;
  --text-tertiary: #888888;
  --border: #e0e0e0;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --positive: #16a34a;
  --positive-soft: rgba(22, 163, 74, 0.1);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.1);
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.05);
}

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

html { -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.container {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-top: env(safe-area-inset-top, 0);
}

.header h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.header-icon {
  width: 32px;
  height: 32px;
  opacity: 0.7;
}

.theme-toggle {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover { background: var(--bg-elevated); }

.theme-toggle svg { width: 18px; height: 18px; }

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  background: var(--bg-muted);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 10px 6px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  text-align: center;
  white-space: nowrap;
}

.tab:hover { color: var(--text); }

.tab.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* Panels */
.panel { display: none; animation: fadeIn 0.3s ease; }
.panel.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Big clock */
.big-clock {
  text-align: center;
  margin-bottom: 24px;
}

.big-clock .time {
  font-size: 56px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.big-clock .label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Section label */
.section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

/* Toggle group */
.toggle-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.toggle-group button {
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  font-family: inherit;
}

.toggle-group button:hover {
  border-color: var(--text-secondary);
  color: var(--text);
}

.toggle-group button.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* Input */
.input-row {
  margin-bottom: 20px;
}

.input-row label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.input-row input[type="time"] {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 18px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: var(--transition);
  font-family: inherit;
}

.input-row input[type="time"]:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Cycle cards */
.cycles-list {
  margin-bottom: 20px;
}

.cycle-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: var(--transition);
  cursor: pointer;
  background: var(--bg-elevated);
  position: relative;
  overflow: hidden;
}

.cycle-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: transparent;
  transition: var(--transition);
}

.cycle-card:hover {
  border-color: var(--text-secondary);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.cycle-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow);
}

.cycle-card.selected::before {
  background: var(--accent);
}

.cycle-card.optimal .cycle-badge { background: var(--positive-soft); color: var(--positive); }
.cycle-card.good .cycle-badge { background: var(--accent-soft); color: var(--accent); }
.cycle-card.warn .cycle-badge { background: var(--warning-soft); color: var(--warning); }

.cycle-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  background: var(--bg-muted);
  color: var(--text-tertiary);
}

.cycle-info { flex: 1; }

.cycle-time {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.cycle-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.cycle-duration {
  font-size: 14px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* Timeline */
.timeline-wrap {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  margin-bottom: 20px;
}

.timeline-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.timeline {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 90px;
  padding-bottom: 24px;
  position: relative;
}

.bar {
  flex: 1;
  border-radius: 4px 4px 0 0;
  position: relative;
  transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 8px;
}

.bar::after {
  content: attr(data-label);
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  font-weight: 500;
}

.bar::before {
  content: attr(data-time);
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--text-tertiary);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
}

.bar:hover::before { opacity: 1; }

.bar:nth-child(odd) { background: var(--text); opacity: 0.9; }
.bar:nth-child(even) { background: var(--text-secondary); opacity: 0.4; }
.bar.highlight { background: var(--accent); opacity: 1; }

/* Tip box */
.tip-box {
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  margin-bottom: 20px;
}

.tip-box strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.tip-box p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Legend */
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 500;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* Breathing exercise */
.breathing-section {
  margin-top: 24px;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  text-align: center;
}

.breathing-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.breathing-subtitle {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 20px;
}

.breathing-circle {
  width: 140px;
  height: 140px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all 0.1s linear;
  position: relative;
}

.breathing-circle.active {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 30px var(--accent-soft);
}

.breathing-timer {
  font-size: 32px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.breathing-phase {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.breathing-btn {
  padding: 12px 28px;
  border: none;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  margin-top: 8px;
}

.breathing-btn:hover { opacity: 0.85; }

/* Stats */
.stats-section {
  margin-top: 24px;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.stats-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat-card {
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* Settings */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child { border-bottom: none; }

.settings-label {
  font-size: 14px;
  font-weight: 500;
}

.settings-desc {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* Install prompt */
.install-banner {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  z-index: 100;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.install-banner.show { display: flex; }

.install-text {
  font-size: 14px;
  font-weight: 500;
}

.install-btn {
  padding: 10px 20px;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.install-close {
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

/* Notification permission */
.notify-btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  font-family: inherit;
  margin-top: 12px;
}

.notify-btn:hover { border-color: var(--text-secondary); color: var(--text); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Selection */
::selection {
  background: var(--accent-soft);
  color: var(--text);
}

/* Responsive */
@media (max-width: 380px) {
  .big-clock .time { font-size: 48px; }
  .tab { font-size: 12px; padding: 8px 4px; }
  .cycle-time { font-size: 18px; }
}
