:root {
  color-scheme: light dark;
}

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

.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;
}

html {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto',
    'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans',
    'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: light-dark(#ffffff, #1a1a1a);
  color: light-dark(#1a1a1a, #f5f5f5);
  padding: 2rem;
  transition: background-color 0.3s, color 0.3s;
}

main {
  max-width: 1200px;
  margin: 0 auto;
}

.header {
  display: flex;
  align-items: center;
  gap: 2rem;
  margin-bottom: 2rem;
}

.logo {
  width: 100px;
  height: 100px;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 4px light-dark(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.3)));
}

.theme-toggle {
  position: fixed;
  top: 2rem;
  right: 2rem;
  padding: 0.5rem 1rem;
  background: light-dark(#f0f0f0, #333);
  color: light-dark(#1a1a1a, #f5f5f5);
  border: 1px solid light-dark(#ddd, #444);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.3s, color 0.3s, border-color 0.3s;
}

.theme-toggle:hover {
  background: light-dark(#e0e0e0, #444);
  border-color: light-dark(#ccc, #555);
}

.header-text {
  flex: 1;
}

h1 {
  margin: 0 0 0.5rem 0;
  font-size: 2.5rem;
}

h2 {
  margin: 0;
  font-size: 1.2rem;
}

h3 {
  margin: 0;
}

.subtitle {
  color: light-dark(#666, #999);
  margin: 0;
  font-size: 0.95rem;
}

.panel {
  background: light-dark(#f5f5f5, #2a2a2a);
  border: 1px solid light-dark(#e0e0e0, #444);
  border-radius: 8px;
  padding: 2rem;
  margin-bottom: 2rem;
  transition: background-color 0.3s, border-color 0.3s;
}

#controls {
  position: sticky;
  top: 0;
  z-index: 10;
}

h2.panel-title {
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: light-dark(#1a1a1a, #e0e0e0);
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.tempo-fieldset {
  border: 1px solid light-dark(#ddd, #444);
  border-radius: 4px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  background: light-dark(#fafafa, #2a2a2a);
}

.tempo-fieldset legend {
  font-weight: 600;
  font-size: 0.95rem;
  color: light-dark(#555, #aaa);
  padding: 0 0.5rem;
  margin-left: -0.5rem;
}

.tempo-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1.5rem;
  margin-top: 0.5rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-group label {
  font-size: 0.875rem;
  color: light-dark(#555, #aaa);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-group input[type="checkbox"] {
  padding: 0;
  width: auto;
  height: auto;
  cursor: pointer;
}

button {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.3s;
  font-weight: 500;
}

button:hover {
  background: #0056b3;
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  background: light-dark(#ccc, #666);
  cursor: not-allowed;
  opacity: 0.6;
}

input,
select {
  padding: 0.75rem;
  font-size: 0.95rem;
  border: 1px solid light-dark(#ddd, #444);
  border-radius: 4px;
  background: light-dark(#ffffff, #333);
  color: light-dark(#1a1a1a, #f5f5f5);
  transition: background-color 0.3s, border-color 0.3s, color 0.3s;
}

input[type="range"] {
  padding: 0;
  width: 100%;
  height: 6px;
  background: light-dark(#e0e0e0, #444);
  border: none;
  border-radius: 3px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: #007bff;
  cursor: pointer;
  border-radius: 50%;
  border: 2px solid light-dark(#ffffff, #333);
  transition: background 0.3s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: #0056b3;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: #007bff;
  cursor: pointer;
  border-radius: 50%;
  border: 2px solid light-dark(#ffffff, #333);
  transition: background 0.3s;
}

input[type="range"]::-moz-range-thumb:hover {
  background: #0056b3;
}

input[type="range"]::-moz-range-track {
  background: transparent;
  border: none;
}

input:focus,
select:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.button-group {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.global-option-label {
  display: block;
  margin-top: 1rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.global-option-label input {
  margin-right: 0.5rem;
  cursor: pointer;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: light-dark(#ffffff, #1a1a1a);
  padding: 1rem;
  border-radius: 4px;
  border-left: 3px solid #007bff;
  transition: background-color 0.3s;
}

.stat-label {
  font-size: 0.75rem;
  color: light-dark(#666, #999);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  font-family: 'Monaco', 'Menlo', monospace;
  color: light-dark(#1a1a1a, #f5f5f5);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: light-dark(#ffffff, #1a1a1a);
  border: 1px solid light-dark(#e0e0e0, #444);
  border-radius: 4px;
  overflow: hidden;
  transition: background-color 0.3s, border-color 0.3s;
}

th,
td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid light-dark(#e0e0e0, #444);
  font-size: 0.875rem;
}

th {
  background: light-dark(#f5f5f5, #333);
  font-weight: 600;
  color: light-dark(#555, #aaa);
}

tr:hover {
  background: light-dark(#f9f9f9, #333);
}

tr:last-child td {
  border-bottom: none;
}

.table-container {
  overflow-x: auto;
}

.empty-state {
  text-align: center;
  padding: 2rem;
  color: light-dark(#999, #999);
}

.chart-container {
  width: 100%;
  height: 350px;
  position: relative;
  border: 1px solid light-dark(#e0e0e0, #444);
  border-radius: 4px;
  background: light-dark(#ffffff, #1a1a1a);
  padding: 1rem;
  box-sizing: border-box;
  transition: background-color 0.3s, border-color 0.3s;
}

#performance-chart {
  width: 100%;
  height: 100%;
  display: block;
}

/* Timer Creation Form */
.timer-creation-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.timer-creation-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  min-width: 150px;
}

.form-group label {
  font-size: 0.875rem;
  color: light-dark(#555, #aaa);
  font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
  padding: 0.75rem;
  font-size: 0.95rem;
  border: 1px solid light-dark(#ddd, #444);
  border-radius: 4px;
  background: light-dark(#ffffff, #333);
  color: light-dark(#1a1a1a, #f5f5f5);
}

.form-group input[type="range"] {
  padding: 0;
  width: 100%;
}

.timer-creation-row > label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: light-dark(#555, #aaa);
  cursor: pointer;
  flex: 1;
  min-width: 200px;
}

.timer-creation-row > label input[type="checkbox"] {
  cursor: pointer;
  width: auto;
  height: auto;
  padding: 0;
}

#create-timer {
  background: #28a745;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  transition: background 0.3s;
}

#create-timer:hover {
  background: #218838;
}

#create-timer:disabled {
  background: light-dark(#ccc, #666);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Multi-Timer Styles */
.timers-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.timer-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem;
  background: light-dark(#f9f9f9, #333);
  border: 1px solid light-dark(#e0e0e0, #444);
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}

.timer-tick-indicator {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 0 5px currentColor;
}

.timer-item.tick-active .timer-tick-indicator {
  animation: tick-pulse 0.15s ease-out;
}

@keyframes tick-pulse {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.5);
  }
}

.timer-item:hover {
  background: light-dark(#f0f0f0, #3a3a3a);
  border-color: #007bff;
}

.timer-item.active {
  background: light-dark(#e3f2fd, #1e3a5f);
  border-color: #007bff;
}

.timer-color-indicator {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

.timer-item-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.timer-name {
  font-weight: 500;
  color: light-dark(#1a1a1a, #e0e0e0);
  white-space: nowrap;
}

.timer-status {
  font-size: 0.875rem;
  color: light-dark(#666, #999);
}

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

.timer-item-controls button {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  border: none;
  border-radius: 3px;
  background: #007bff;
  color: white;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.timer-item-controls button:hover:not(:disabled) {
  background: #0056b3;
}

.timer-item-controls button:disabled {
  background: light-dark(#ccc, #666);
  cursor: not-allowed;
  opacity: 0.6;
}

.timer-item-controls button.remove {
  background: #dc3545;
}

.timer-item-controls button.remove:hover:not(:disabled) {
  background: #c82333;
}

.timer-details-panel {
  background: light-dark(#ffffff, #2a2a2a);
  border: 1px solid light-dark(#e0e0e0, #444);
  border-radius: 8px;
  padding: 2rem;
  margin-bottom: 2rem;
  transition: background-color 0.3s, border-color 0.3s;
}

.timer-details-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
}

.timer-detail-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.timer-detail-section h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: light-dark(#1a1a1a, #e0e0e0);
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.timer-detail-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.timer-detail-group label {
  font-size: 0.75rem;
  color: light-dark(#666, #999);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.timer-detail-value {
  padding: 0.5rem;
  font-size: 0.875rem;
  background: light-dark(#f5f5f5, #333);
  border: 1px solid light-dark(#ddd, #444);
  border-radius: 4px;
  color: light-dark(#1a1a1a, #f5f5f5);
  font-family: 'Monaco', 'Menlo', monospace;
}

.timer-detail-group input,
.timer-detail-group select {
  padding: 0.5rem;
  font-size: 0.875rem;
  border: 1px solid light-dark(#ddd, #444);
  border-radius: 4px;
  background: light-dark(#f5f5f5, #333);
  color: light-dark(#1a1a1a, #f5f5f5);
}

.timer-detail-group input:disabled,
.timer-detail-group select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.timer-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.timer-stat-card {
  background: light-dark(#f9f9f9, #333);
  padding: 0.75rem;
  border-radius: 4px;
  border-left: 2px solid #007bff;
}

.timer-stat-label {
  font-size: 0.7rem;
  color: light-dark(#666, #999);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.375rem;
}

.timer-stat-value {
  font-size: 1.125rem;
  font-weight: 600;
  font-family: 'Monaco', 'Menlo', monospace;
  color: light-dark(#1a1a1a, #f5f5f5);
}

.timer-detail-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.timer-detail-actions button {
  flex: 1;
  min-width: 80px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border: none;
  border-radius: 4px;
  background: #007bff;
  color: white;
  cursor: pointer;
  transition: background 0.3s;
  font-weight: 500;
}

.timer-detail-actions button:hover:not(:disabled) {
  background: #0056b3;
}

.timer-detail-actions button:disabled {
  background: light-dark(#ccc, #666);
  cursor: not-allowed;
  opacity: 0.6;
}

.timer-detail-actions button.remove {
  background: #dc3545;
}

.timer-detail-actions button.remove:hover:not(:disabled) {
  background: #c82333;
}

#multi-timer-chart {
  width: 100%;
  height: 100%;
  display: block;
}

#add-timer {
  background: #28a745;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.3s;
  padding: 0.75rem 1.5rem;
}

#add-timer:hover {
  background: #218838;
}

#add-timer:disabled {
  background: light-dark(#ccc, #666);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Multi-Timer Styles */
.multi-timer-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.timer-card {
  position: relative;
  background: light-dark(#f5f5f5, #2a2a2a);
  border: 2px solid light-dark(#e0e0e0, #444);
  border-radius: 8px;
  padding: 15px;
}

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

.timer-card-title {
  flex: 1;
  font-weight: bold;
  font-size: 14px;
  color: light-dark(#1a1a1a, #e0e0e0);
}

.timer-controls-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.timer-control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.timer-control-group label {
  font-size: 11px;
  color: light-dark(#666, #999);
  font-weight: 500;
}

.timer-control-group input,
.timer-control-group select {
  padding: 6px;
  font-size: 12px;
  border: 1px solid light-dark(#ddd, #444);
  border-radius: 4px;
  background: light-dark(#f5f5f5, #333);
  color: light-dark(#1a1a1a, #e0e0e0);
}

.timer-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.timer-stat {
  background: light-dark(#f9f9f9, #333);
  padding: 8px;
  border-radius: 4px;
  font-size: 12px;
  border-left: 2px solid #007bff;
}

.timer-stat-label {
  color: light-dark(#666, #999);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.timer-stat-value {
  font-weight: bold;
  font-size: 14px;
  margin-top: 2px;
  font-family: 'Monaco', 'Menlo', monospace;
  color: light-dark(#1a1a1a, #e0e0e0);
}

.timer-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.timer-actions button {
  flex: 1;
  padding: 6px;
  font-size: 11px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: #007bff;
  color: white;
  transition: background 0.2s;
  font-weight: 500;
}

.timer-actions button:hover:not(:disabled) {
  background: #0056b3;
}

.timer-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.timer-actions button.remove {
  background: #dc3545;
}

.timer-actions button.remove:hover:not(:disabled) {
  background: #c82333;
}

.add-timer-btn {
  width: 100%;
  padding: 12px;
  margin-bottom: 20px;
  background: #28a745;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  font-weight: bold;
  transition: background 0.3s;
}

.add-timer-btn:hover {
  background: #218838;
}

.add-timer-btn:disabled {
  background: light-dark(#ccc, #666);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Tick Indicator */
.timer-tick-indicator {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 0 8px 2px currentColor, inset 0 0 4px currentColor;
}

.timer-card .timer-tick-indicator {
  top: 10px;
  right: 10px;
  width: 16px;
  height: 16px;
  box-shadow: 0 0 10px 3px currentColor, inset 0 0 6px currentColor;
}

.timer-item.tick-active .timer-tick-indicator,
.timer-card.tick-active .timer-tick-indicator {
  animation: tick-pulse 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tick-pulse {
  0% {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 8px 2px currentColor, inset 0 0 4px currentColor;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(2);
    box-shadow: 0 0 15px 8px transparent, inset 0 0 0 transparent;
  }
}

/* Responsive */
@media (max-width: 1200px) {
  .multi-timer-container {
    grid-template-columns: 1fr;
  }
}
