/* CSS Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Light theme (default) */
  --bg: #ffffff;
  --fg: #1a1a1a;
  --fg-muted: #666666;
  --border: #e0e0e0;
  --btn-primary-bg: #000000;
  --btn-primary-fg: #ffffff;
  --btn-secondary-bg: #f5f5f5;
  --btn-secondary-fg: #1a1a1a;
  --btn-hover: #333333;
  --shadow: rgba(0, 0, 0, 0.1);
  --focus-ring: rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --fg: #f5f5f5;
    --fg-muted: #a0a0a0;
    --border: #2a2a2a;
    --btn-primary-bg: #ffffff;
    --btn-primary-fg: #000000;
    --btn-secondary-bg: #1a1a1a;
    --btn-secondary-fg: #f5f5f5;
    --btn-hover: #cccccc;
    --shadow: rgba(255, 255, 255, 0.05);
    --focus-ring: rgba(255, 255, 255, 0.4);
  }
}

/* Manual theme overrides */
[data-theme="light"] {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --fg-muted: #666666;
  --border: #e0e0e0;
  --btn-primary-bg: #000000;
  --btn-primary-fg: #ffffff;
  --btn-secondary-bg: #f5f5f5;
  --btn-secondary-fg: #1a1a1a;
  --btn-hover: #333333;
  --shadow: rgba(0, 0, 0, 0.1);
  --focus-ring: rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --fg: #f5f5f5;
  --fg-muted: #a0a0a0;
  --border: #2a2a2a;
  --btn-primary-bg: #ffffff;
  --btn-primary-fg: #000000;
  --btn-secondary-bg: #1a1a1a;
  --btn-secondary-fg: #f5f5f5;
  --btn-hover: #cccccc;
  --shadow: rgba(255, 255, 255, 0.05);
  --focus-ring: rgba(255, 255, 255, 0.4);
}

/* Typography */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  transition: background 0.2s ease, color 0.2s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Layout */
.container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 5vw, 3rem);
  max-width: 480px;
  margin: 0 auto;
}

.header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: clamp(2rem, 8vh, 4rem);
}

.controls-right {
  display: flex;
  gap: 0.5rem;
}

/* Timer Display */
.timer-wrapper {
  width: 100%;
  margin-bottom: clamp(2rem, 8vh, 3rem);
  position: relative;
}

.timer-display {
  font-size: clamp(2.5rem, 12vw, 5rem);
  font-weight: 300;
  letter-spacing: -0.02em;
  text-align: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  padding: clamp(1rem, 4vw, 2rem);
  border-radius: 1rem;
  transition: background 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timer-display:hover {
  background: var(--btn-secondary-bg);
}

.timer-display:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 4px;
}

.time-main {
  font-variant-numeric: tabular-nums;
}

.time-ms {
  font-size: 0.6em;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

/* Time Editor */
.time-editor {
  width: 100%;
  font-size: clamp(2rem, 10vw, 4rem);
  font-weight: 300;
  text-align: center;
  background: var(--btn-secondary-bg);
  color: var(--fg);
  border: 2px solid var(--border);
  border-radius: 1rem;
  padding: clamp(1rem, 4vw, 2rem);
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}

.time-editor:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-color: var(--btn-primary-bg);
}

.edit-hint {
  position: absolute;
  bottom: -1.5rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: var(--fg-muted);
  white-space: nowrap;
}

/* Buttons */
button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 4px;
}

.btn {
  padding: clamp(0.75rem, 3vw, 1rem) clamp(1.5rem, 6vw, 2.5rem);
  border-radius: 2rem;
  font-weight: 500;
  box-shadow: 0 2px 8px var(--shadow);
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  min-width: clamp(120px, 30vw, 160px);
}

.btn-primary:hover {
  background: var(--btn-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px var(--shadow);
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-fg);
  min-width: clamp(100px, 25vw, 130px);
}

.btn-secondary:hover {
  background: var(--border);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow);
}

.btn-secondary:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px var(--shadow);
}

.button-group {
  display: flex;
  gap: 1rem;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

/* Small icon buttons */
.icon-btn,
.mode-toggle {
  background: var(--btn-secondary-bg);
  color: var(--fg);
  padding: 0.5rem 0.75rem;
  border-radius: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.icon-btn:hover,
.mode-toggle:hover {
  background: var(--border);
}

.mode-toggle {
  padding: 0.5rem 1rem;
}

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Animations */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

.pulsing {
  animation: pulse 1s ease-in-out infinite;
}

/* Fullscreen styles */
:fullscreen .container,
:-webkit-full-screen .container,
:-moz-full-screen .container,
:-ms-fullscreen .container {
  max-width: 100%;
  padding: clamp(2rem, 10vh, 6rem);
}

/* Mobile adjustments */
@media (max-width: 480px) {
  .button-group {
    flex-direction: column;
    align-items: stretch;
  }

  .btn {
    width: 100%;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn {
    border: 2px solid currentColor;
  }

  .timer-display:hover {
    border: 2px solid var(--border);
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
