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

:root {
  --bg: #0a0a0a;
  --surface: #1a1a1a;
  --primary: #00d4aa;
  --primary-dim: rgba(0, 212, 170, 0.15);
  --accent: #ff6b6b;
  --text: #ffffff;
  --text-dim: #888888;
  --danger: #ff4757;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  width: 100%;
  max-width: 480px;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

.header {
  padding: 16px 20px;
  display: flex;
  justify-content: center;
}

.mode-btn {
  background: var(--surface);
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.mode-btn:active {
  background: #2a2a2a;
}

.mode-icon {
  font-size: 12px;
}

.mode-text {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 40px;
}

.breath-container {
  position: relative;
  width: 280px;
  height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.breath-ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border: 3px solid var(--primary-dim);
  border-radius: 50%;
  transition: transform 4s ease-in-out, border-color 0.3s;
}

.breath-ring.inhale {
  transform: scale(1.08);
  border-color: var(--primary);
}

.breath-ring.exhale {
  transform: scale(1);
}

.timer-display {
  font-size: 72px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  letter-spacing: -2px;
  transition: color 0.3s;
}

.timer-display.warning {
  color: var(--accent);
}

.timer-display.running {
  color: var(--primary);
}

.breath-text {
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 8px;
  height: 20px;
}

.controls {
  display: flex;
  gap: 16px;
}

.btn {
  min-width: 120px;
  min-height: 56px;
  border: none;
  border-radius: 28px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.btn-primary {
  background: var(--primary);
  color: var(--bg);
  min-width: 160px;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  min-width: 56px;
  font-size: 24px;
}

.presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.preset {
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}

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

.preset.active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-dim);
}

.stats {
  display: flex;
  gap: 32px;
  padding: 16px 24px;
  background: var(--surface);
  border-radius: 16px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-dim);
}

.mode-selector {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) scale(0.95);
  background: var(--surface);
  border-radius: 16px;
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
  z-index: 100;
  min-width: 200px;
}

.mode-selector.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) scale(1);
}

.mode-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.mode-option:active {
  background: #2a2a2a;
}

.mode-option.selected {
  background: var(--primary-dim);
}

.mode-emoji {
  font-size: 20px;
}

.custom-time-modal {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
  z-index: 200;
}

.custom-time-modal.show {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  width: 280px;
  text-align: center;
}

.modal-content h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

.custom-input-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}

.custom-input-group input {
  width: 100px;
  background: var(--bg);
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-size: 24px;
  color: var(--text);
  text-align: center;
  -moz-appearance: textfield;
}

.custom-input-group input::-webkit-outer-spin-button,
.custom-input-group input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.modal-buttons .btn {
  min-width: 100px;
  min-height: 48px;
  font-size: 16px;
}

.completion-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
  z-index: 300;
}

.completion-overlay.show {
  opacity: 1;
  visibility: visible;
}

.completion-content {
  text-align: center;
  position: relative;
}

.completion-icon {
  font-size: 80px;
  margin-bottom: 16px;
}

.completion-time {
  font-size: 48px;
  font-weight: 200;
  color: var(--primary);
  margin-bottom: 4px;
}

.completion-stats {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.completion-stats.perfect {
  color: var(--primary);
}

.completion-message {
  font-size: 18px;
  color: var(--text-dim);
  margin-bottom: 32px;
}

.confetti {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  pointer-events: none;
}

.confetti-particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: confetti-fall 1.5s ease-out forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) scale(0);
    opacity: 0;
  }
}

.checkpoint {
  position: absolute;
  bottom: 30%;
  font-size: 14px;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.3s;
  text-align: center;
  width: 100%;
}

.checkpoint.show {
  animation: checkpoint-pulse 2s ease-out;
}

@keyframes checkpoint-pulse {
  0%, 100% { opacity: 0; }
  20%, 80% { opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(-50%) translateX(0); }
  25% { transform: translateX(-50%) translateX(-5px); }
  75% { transform: translateX(-50%) translateX(5px); }
}

body {
  user-select: none;
  -webkit-user-select: none;
}

.mode-selector, .custom-time-modal, .completion-overlay {
  touch-action: manipulation;
}

.stat-clickable {
  cursor: pointer;
}

.stat-clickable:active {
  opacity: 0.7;
}

.history-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
  z-index: 400;
}

.history-overlay.show {
  opacity: 1;
  visibility: visible;
}

.history-content {
  width: 100%;
  max-width: 480px;
  max-height: 70vh;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.history-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.history-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 28px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.history-list {
  overflow-y: auto;
  flex: 1;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #2a2a2a;
}

.history-item:last-child {
  border-bottom: none;
}

.history-item-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item-date {
  font-size: 14px;
  color: var(--text);
}

.history-item-mode {
  font-size: 12px;
  color: var(--text-dim);
}

.history-item-right {
  text-align: right;
}

.history-item-duration {
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
}

.history-item-pause {
  font-size: 12px;
  color: var(--text-dim);
}

.history-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 0;
  font-size: 14px;
}

.history-tabs {
  display: flex;
  gap: 8px;
}

.history-tab {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s;
}

.history-tab.active {
  background: var(--primary-dim);
  color: var(--primary);
}

.leaderboard-type-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.leaderboard-type-btn {
  background: var(--bg);
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.leaderboard-type-btn.active {
  background: var(--primary);
  color: var(--bg);
}

.leaderboard-list {
  overflow-y: auto;
  flex: 1;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #2a2a2a;
}

.leaderboard-item:last-child {
  border-bottom: none;
}

.leaderboard-rank {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  background: var(--surface);
}

.leaderboard-rank.top-1 {
  background: linear-gradient(135deg, #ffd700, #ffaa00);
  color: #000;
}

.leaderboard-rank.top-2 {
  background: linear-gradient(135deg, #c0c0c0, #a0a0a0);
  color: #000;
}

.leaderboard-rank.top-3 {
  background: linear-gradient(135deg, #cd7f32, #a0522d);
  color: #fff;
}

.leaderboard-info {
  flex: 1;
}

.leaderboard-nickname {
  font-size: 14px;
  color: var(--text);
}

.leaderboard-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
}

.leaderboard-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 0;
  font-size: 14px;
}
