:root {
  --bg: #0a0a14;
  --surface: #141425;
  --surface-hover: #1c1c34;
  --text: #e8e6f0;
  --text-dim: #7a7898;
  --accent: #6c5ce7;
  --accent-bright: #a29bfe;
  --danger: #e17055;
  --success: #00b894;
  --glow: rgba(108, 92, 231, 0.15);
  --radius: 14px;
  --radius-sm: 8px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* --- Tabs --- */
#tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 28px;
}

#tabs button {
  flex: 1;
  padding: 10px 0;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
}

#tabs button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px rgba(108, 92, 231, 0.4);
}

#tabs button:not([aria-pressed="true"]):hover {
  color: var(--text);
  background: var(--surface-hover);
}

#tabs button:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

/* --- Views --- */
.view {
  display: none;
  flex-direction: column;
  align-items: center;
  flex: 1;
  justify-content: center;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.view.active {
  display: flex;
  opacity: 1;
  transform: translateY(0);
}

/* --- Time Display --- */
.time-display {
  font-size: clamp(4rem, 16vw, 6rem);
  font-weight: 200;
  letter-spacing: 4px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin-bottom: 8px;
  text-shadow: 0 0 40px var(--glow);
}

.time-display .colon {
  opacity: 0.5;
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0.2; }
}

.seconds-bar {
  width: min(260px, 70vw);
  height: 4px;
  background: var(--surface);
  border-radius: 2px;
  overflow: hidden;
  margin: 4px 0;
}

#seconds-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  border-radius: 2px;
  width: 0%;
  transition: width 0.1s linear;
}

.seconds-digits {
  font-size: 1.2rem;
  font-weight: 300;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  height: 1.6em;
}

.ampm {
  font-size: 0.9rem;
  color: var(--accent-bright);
  font-weight: 500;
  margin-top: -2px;
  height: 1.2em;
}

.date-display {
  font-size: 1rem;
  color: var(--text-dim);
  font-weight: 400;
  margin-top: 12px;
  letter-spacing: 0.5px;
}

/* --- Stopwatch --- */
.sw-ms {
  font-weight: 300;
  font-size: 0.65em;
  opacity: 0.6;
  vertical-align: bottom;
}

/* --- Laps --- */
.lap-list {
  width: min(280px, 80vw);
  flex: 1;
  overflow-y: auto;
  margin-top: 24px;
  padding-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.lap-list::-webkit-scrollbar { display: none; }

.lap-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  background: var(--surface);
  border-radius: var(--radius-sm);
}

.lap-item:first-child {
  color: var(--accent-bright);
}

/* --- Controls --- */
.controls {
  display: flex;
  gap: 12px;
  margin-top: 32px;
}

.ctrl {
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.3px;
}

.ctrl:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

.ctrl.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 20px rgba(108, 92, 231, 0.35);
}

.ctrl.primary:hover {
  background: #7c6ef0;
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(108, 92, 231, 0.5);
}

.ctrl.primary:active {
  transform: translateY(0);
  box-shadow: 0 2px 12px rgba(108, 92, 231, 0.3);
}

.ctrl.secondary {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.06);
}

.ctrl.secondary:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* --- Timer --- */
.timer-input-row {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.timer-input-row label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.timer-input-row label input {
  width: 64px;
  padding: 12px 8px;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 300;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color 0.2s;
}

.timer-input-row label input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--glow);
}

.timer-input-row label span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  font-weight: 600;
}

.hidden { display: none !important; }

/* --- Timer Done --- */
#timer-done {
  text-align: center;
}

.done-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.done-label {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--accent-bright);
}

/* --- Pause Overlay --- */
#pause-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  cursor: pointer;
}

#pause-overlay p {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--accent-bright);
  letter-spacing: 2px;
}

/* --- Scrollbar for lap list --- */
.lap-list {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-hover) transparent;
}

/* --- Responsive --- */
@media (max-width: 360px) {
  #app { padding: 14px 10px; }
  .time-display { font-size: 3.2rem; letter-spacing: 2px; }
  .ctrl { padding: 12px 24px; font-size: 14px; }
  .timer-input-row label input { width: 56px; font-size: 1.3rem; }
}

@media (min-width: 600px) {
  #app { padding: 32px 24px; }
  .lap-list { gap: 4px; }
}
